Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXComboBox.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * C o m b o B o x W i d g e t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1997,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 *********************************************************************************
22 * $Id: FXComboBox.h,v 1.46 2006/01/27 02:07:44 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXCOMBOBOX_H
25 #define FXCOMBOBOX_H
26 
27 #ifndef FXPACKER_H
28 #include "FXPacker.h"
29 #endif
30 
31 namespace FX {
32 
33 
34 /// ComboBox styles
35 enum {
36  COMBOBOX_NO_REPLACE = 0, /// Leave the list the same
37  COMBOBOX_REPLACE = 0x00020000, /// Replace current item with typed text
38  COMBOBOX_INSERT_BEFORE = 0x00040000, /// Typed text inserted before current
39  COMBOBOX_INSERT_AFTER = 0x00060000, /// Typed text inserted after current
40  COMBOBOX_INSERT_FIRST = 0x00080000, /// Typed text inserted at begin of list
41  COMBOBOX_INSERT_LAST = 0x000A0000, /// Typed text inserted at end of list
42  COMBOBOX_STATIC = 0x00100000, /// Unchangable text box
43  COMBOBOX_NORMAL = 0 /// Can type text but list is not changed
44  };
45 
46 
47 class FXTextField;
48 class FXMenuButton;
49 class FXList;
50 class FXPopup;
51 
52 
53 /**
54 * A Combo Box provides a way to select a string from a list of strings.
55 * Unless COMBOBOX_STATIC is passed, it also allows the user to enter a new
56 * string into the text field, for example if the desired entry is not in the
57 * list of strings. Passing COMBOBOX_REPLACE, COMBOBOX_INSERT_BEFORE, COMBOBOX_INSERT_AFTER,
58 * COMBOBOX_INSERT_FIRST, or COMBOBOX_INSERT_LAST causes a newly entered text to replace the
59 * current one in the list, or be added before or after the current entry, or to be added at
60 * the beginning or end of the list.
61 * Combo Box is intended to enter text; if you need to enter a choice from a list of
62 * options, it is recommended that the List Box widget is used instead.
63 * When the text in the field is changed, a SEL_COMMAND will be send to the target.
64 * The Combo Box can also receive ID_GETSTRINGVALUE and ID_SETSTRINGVALUE and so
65 * on, which will behave similar to Text Field in that they will retrieve or update
66 * the value of the field.
67 */
68 class FXAPI FXComboBox : public FXPacker {
70 protected:
71  FXTextField *field;
72  FXMenuButton *button;
73  FXList *list;
74  FXPopup *pane;
75 protected:
76  FXComboBox(){}
77 private:
78  FXComboBox(const FXComboBox&);
79  FXComboBox &operator=(const FXComboBox&);
80 public:
81  long onFocusUp(FXObject*,FXSelector,void*);
82  long onFocusDown(FXObject*,FXSelector,void*);
83  long onFocusSelf(FXObject*,FXSelector,void*);
84  long onMouseWheel(FXObject*,FXSelector,void*);
85  long onTextButton(FXObject*,FXSelector,void*);
86  long onTextChanged(FXObject*,FXSelector,void*);
87  long onTextCommand(FXObject*,FXSelector,void*);
88  long onListClicked(FXObject*,FXSelector,void*);
89  long onFwdToText(FXObject*,FXSelector,void*);
90  long onUpdFmText(FXObject*,FXSelector,void*);
91 public:
92  enum {
93  ID_LIST=FXPacker::ID_LAST,
94  ID_TEXT,
95  ID_LAST
96  };
97 public:
98 
99  /// Construct a Combo Box widget with room to display cols columns of text
100  FXComboBox(FXComposite *p,FXint cols,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=COMBOBOX_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0,FXint pl=DEFAULT_PAD,FXint pr=DEFAULT_PAD,FXint pt=DEFAULT_PAD,FXint pb=DEFAULT_PAD);
101 
102  /// Create server-side resources
103  virtual void create();
104 
105  /// Detach server-side resources
106  virtual void detach();
107 
108  /// Destroy server-side resources
109  virtual void destroy();
110 
111  /// Enable combo box
112  virtual void enable();
113 
114  /// Disable combo box
115  virtual void disable();
116 
117  /// Return default width
118  virtual FXint getDefaultWidth();
119 
120  /// Return default height
121  virtual FXint getDefaultHeight();
122 
123  /// Perform layout
124  virtual void layout();
125 
126  /// Return true if combobox is editable
127  FXbool isEditable() const;
128 
129  /// Set editable state
130  void setEditable(FXbool edit=TRUE);
131 
132  /// Set the text
133  void setText(const FXString& text);
134 
135  /// Get the text
136  FXString getText() const;
137 
138  /// Set the number of columns
139  void setNumColumns(FXint cols);
140 
141  /// Get the number of columns
142  FXint getNumColumns() const;
143 
144  /// Change text justification mode; default is JUSTIFY_LEFT
145  void setJustify(FXuint mode);
146 
147  /// Return text justification mode
148  FXuint getJustify() const;
149 
150  /// Return the number of items in the list
151  FXint getNumItems() const;
152 
153  /// Return the number of visible items
154  FXint getNumVisible() const;
155 
156  /// Set the number of visible items in the drop down list
157  void setNumVisible(FXint nvis);
158 
159  /// Return true if current item
160  FXbool isItemCurrent(FXint index) const;
161 
162  /// Set the current item (index is zero-based)
163  void setCurrentItem(FXint index,FXbool notify=FALSE);
164 
165  /// Get the current item's index
166  FXint getCurrentItem() const;
167 
168  /// Return the item at the given index
169  FXString getItem(FXint index) const;
170 
171  /// Replace the item at index
172  FXint setItem(FXint index,const FXString& text,void* ptr=NULL);
173 
174  /// Fill combo box by appending items from array of strings
175  FXint fillItems(const FXchar** strings);
176 
177  /// Fill combo box by appending items from newline separated strings
178  FXint fillItems(const FXString& strings);
179 
180  /// Insert a new item at index
181  FXint insertItem(FXint index,const FXString& text,void* ptr=NULL);
182 
183  /// Append an item to the list
184  FXint appendItem(const FXString& text,void* ptr=NULL);
185 
186  /// Prepend an item to the list
187  FXint prependItem(const FXString& text,void* ptr=NULL);
188 
189  /// Move item from oldindex to newindex
190  FXint moveItem(FXint newindex,FXint oldindex);
191 
192  /// Remove this item from the list
193  void removeItem(FXint index);
194 
195  /// Remove all items from the list
196  void clearItems();
197 
198  /**
199  * Search items by name, beginning from item start. If the start item
200  * is -1 the search will start at the first item in the list. Flags
201  * may be SEARCH_FORWARD or SEARCH_BACKWARD to control the search
202  * direction; this can be combined with SEARCH_NOWRAP or SEARCH_WRAP
203  * to control whether the search wraps at the start or end of the list.
204  * The option SEARCH_IGNORECASE causes a case-insensitive match. Finally,
205  * passing SEARCH_PREFIX causes searching for a prefix of the item name.
206  * Return -1 if no matching item is found.
207  */
208  FXint findItem(const FXString& text,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
209 
210  /**
211  * Search items by associated user data, beginning from item start. If the
212  * start item is -1 the search will start at the first item in the list.
213  * Flags may be SEARCH_FORWARD or SEARCH_BACKWARD to control the
214  * search direction; this can be combined with SEARCH_NOWRAP or SEARCH_WRAP
215  * to control whether the search wraps at the start or end of the list.
216  */
217  FXint findItemByData(const void *ptr,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
218 
219  /// Set text for specified item
220  void setItemText(FXint index,const FXString& text);
221 
222  /// Get text for specified item
223  FXString getItemText(FXint index) const;
224 
225  /// Set data pointer for specified item
226  void setItemData(FXint index,void* ptr) const;
227 
228  /// Get data pointer for specified item
229  void* getItemData(FXint index) const;
230 
231  /// Is the pane shown
232  FXbool isPaneShown() const;
233 
234  /// Sort items using current sort function
235  void sortItems();
236 
237  /// Set text font
238  void setFont(FXFont* fnt);
239 
240  /// Get text font
241  FXFont* getFont() const;
242 
243  /// Set the combobox style.
244  void setComboStyle(FXuint mode);
245 
246  /// Get the combobox style.
247  FXuint getComboStyle() const;
248 
249  /// Set window background color
250  virtual void setBackColor(FXColor clr);
251 
252  /// Get background color
253  FXColor getBackColor() const;
254 
255  /// Change text color
256  void setTextColor(FXColor clr);
257 
258  /// Return text color
259  FXColor getTextColor() const;
260 
261  /// Change selected background color
262  void setSelBackColor(FXColor clr);
263 
264  /// Return selected background color
265  FXColor getSelBackColor() const;
266 
267  /// Change selected text color
268  void setSelTextColor(FXColor clr);
269 
270  /// Return selected text color
271  FXColor getSelTextColor() const;
272 
273  /// Return sort function
274  FXListSortFunc getSortFunc() const;
275 
276  /// Change sort function
277  void setSortFunc(FXListSortFunc func);
278 
279  /// Set the combobox help text
280  void setHelpText(const FXString& txt);
281 
282  /// Get the combobox help text
283  const FXString& getHelpText() const;
284 
285  /// Set the tool tip message for this combobox
286  void setTipText(const FXString& txt);
287 
288  /// Get the tool tip message for this combobox
289  const FXString& getTipText() const;
290 
291  /// Save combobox to a stream
292  virtual void save(FXStream& store) const;
293 
294  /// Load combobox from a stream
295  virtual void load(FXStream& store);
296 
297  /// Destructor
298  virtual ~FXComboBox();
299  };
300 
301 }
302 
303 #endif
FXint(* FXListSortFunc)(const FXListItem *, const FXListItem *)
List item collate function.
Definition: FXList.h:144
A menu button posts a popup menu when clicked.
Definition: FXMenuButton.h:79
Search forward (default)
Definition: fxdefs.h:363
char FXchar
Definition: fxdefs.h:380
#define TRUE
Definition: fxdefs.h:32
Definition: FXWindow.h:241
unsigned int FXuint
Definition: fxdefs.h:389
Popup window.
Definition: FXPopup.h:52
Typed text inserted after current.
Definition: FXComboBox.h:42
Definition: FXFrame.h:56
FXuint FXSelector
Association key.
Definition: FXObject.h:53
#define FXAPI
Definition: fxdefs.h:122
FXuchar FXbool
Definition: fxdefs.h:386
Unchangable text box.
Definition: FXComboBox.h:45
#define NULL
Definition: fxdefs.h:41
FXuint FXColor
Definition: fxdefs.h:447
Leave the list the same.
Definition: FXComboBox.h:39
Typed text inserted before current.
Definition: FXComboBox.h:41
A List Widget displays a list of items, each with a text and optional icon.
Definition: FXList.h:167
Definition: FX4Splitter.h:31
int FXint
Definition: fxdefs.h:390
Packer is a layout manager which automatically places child windows inside its area against the left...
Definition: FXPacker.h:58
A text field is a single-line text entry widget.
Definition: FXTextField.h:73
#define FALSE
Definition: fxdefs.h:35
Object is the base class for all objects in FOX; in order to receive messages from the user interface...
Definition: FXObject.h:166
Can type text but list is not changed.
Definition: FXComboBox.h:46
Wrap around to start.
Definition: fxdefs.h:366
A Combo Box provides a way to select a string from a list of strings.
Definition: FXComboBox.h:75
Typed text inserted at begin of list.
Definition: FXComboBox.h:43
Typed text inserted at end of list.
Definition: FXComboBox.h:44
#define FXDECLARE(classname)
Macro to set up class declaration.
Definition: FXObject.h:92
Replace current item with typed text.
Definition: FXComboBox.h:40

Copyright © 1997-2005 Jeroen van der Zijp