1 /********************************************************************************
2 *                                                                               *
3 *                        L i s t   B o x   W i d g e t                          *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 1997,2005 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: FXListBox.h,v 1.38.2.1 2005/04/10 03:24:47 fox Exp $                         *
23 ********************************************************************************/
24 #ifndef FXLISTBOX_H
25 #define FXLISTBOX_H
26 
27 #ifndef FXPACKER_H
28 #include "FXPacker.h"
29 #endif
30 
31 namespace FX {
32 
33 
34 /// List Box styles
35 enum {
36   LISTBOX_NORMAL         = 0          // Normal style
37   };
38 
39 
40 class FXButton;
41 class FXMenuButton;
42 class FXList;
43 class FXPopup;
44 
45 
46 /**
47 * The List Box is a control to select one of a list of options.  It looks
48 * similar to a Combo Box except that List Box yields integer numbers only.
49 * When an option is selected, List Box will send an SEL_COMMAND with the
50 * index of the opton.  While manipulating the list, it may send SEL_CHANGED
51 * messages to indicate which option the cursor is hovering over.
52 * The List Box is able to receive ID_GETINTVALUE and ID_SETINTVALUE which
53 * will retrieve the current option or change the selected option.
54 */
55 class FXAPI FXListBox : public FXPacker {
56   FXDECLARE(FXListBox)
57 protected:
58   FXButton      *field;
59   FXMenuButton  *button;
60   FXList        *list;
61   FXPopup       *pane;
62 protected:
FXListBox()63   FXListBox(){}
64 private:
65   FXListBox(const FXListBox&);
66   FXListBox &operator=(const FXListBox&);
67 public:
68   long onFocusUp(FXObject*,FXSelector,void*);
69   long onFocusDown(FXObject*,FXSelector,void*);
70   long onFocusSelf(FXObject*,FXSelector,void*);
71   long onFieldButton(FXObject*,FXSelector,void*);
72   long onListUpdate(FXObject*,FXSelector,void*);
73   long onListChanged(FXObject*,FXSelector,void*);
74   long onListClicked(FXObject*,FXSelector,void*);
75   long onCmdSetValue(FXObject*,FXSelector,void*);
76   long onCmdGetIntValue(FXObject*,FXSelector,void*);
77   long onCmdSetIntValue(FXObject*,FXSelector,void*);
78 public:
79   enum {
80     ID_LIST=FXPacker::ID_LAST,
81     ID_FIELD,
82     ID_LAST
83     };
84 public:
85 
86   /// Constructor
87   FXListBox(FXComposite *p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=FRAME_SUNKEN|FRAME_THICK|LISTBOX_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);
88 
89   /// Create server-side resources
90   virtual void create();
91 
92   /// Detach server-side resources
93   virtual void detach();
94 
95   /// Destroy server-side resources
96   virtual void destroy();
97 
98   /// Perform layout
99   virtual void layout();
100 
101   /// Enable drive box
102   virtual void enable();
103 
104   /// Disable drive box
105   virtual void disable();
106 
107   /// Return default width
108   virtual FXint getDefaultWidth();
109 
110   /// Return default height
111   virtual FXint getDefaultHeight();
112 
113   /// Return the number of items in the list
114   FXint getNumItems() const;
115 
116   /// Return the number of visible items
117   FXint getNumVisible() const;
118 
119   /// Set the number of visible items
120   void setNumVisible(FXint nvis);
121 
122   /// Return true if current item
123   FXbool isItemCurrent(FXint index) const;
124 
125   /// Set the current item (index is zero-based)
126   virtual void setCurrentItem(FXint index);
127 
128   /// Get the current item's index
129   FXint getCurrentItem() const;
130 
131   /// Return the item at the given index
132   FXString getItem(FXint index) const;
133 
134   /// Replace the item at index
135   FXint setItem(FXint index,const FXString& text,FXIcon* icon=NULL,void* ptr=NULL);
136 
137   /// Fill list box by appending items from array of strings
138   FXint fillItems(const FXchar** strings,FXIcon* icon=NULL,void* ptr=NULL);
139 
140   /// Fill list box by appending items from newline separated strings
141   FXint fillItems(const FXString& strings,FXIcon* icon=NULL,void* ptr=NULL);
142 
143   /// Insert a new item at index
144   FXint insertItem(FXint index,const FXString& text,FXIcon* icon=NULL,void* ptr=NULL);
145 
146   /// Add an item to the end of the list
147   FXint appendItem(const FXString& text,FXIcon* icon=NULL,void* ptr=NULL);
148 
149   /// Prepend an item to the list
150   FXint prependItem(const FXString& text,FXIcon* icon=NULL,void* ptr=NULL);
151 
152   /// Move item from oldindex to newindex
153   FXint moveItem(FXint newindex,FXint oldindex);
154 
155   /// Remove this item from the list
156   void removeItem(FXint index);
157 
158   /// Remove all items from the list
159   void clearItems();
160 
161   /**
162   * Search items by name, beginning from item start.  If the start
163   * item is -1 the search will start at the first item in the list.
164   * Flags may be SEARCH_FORWARD or SEARCH_BACKWARD to control the
165   * search direction; this can be combined with SEARCH_NOWRAP or SEARCH_WRAP
166   * to control whether the search wraps at the start or end of the list.
167   * The option SEARCH_IGNORECASE causes a case-insensitive match.  Finally,
168   * passing SEARCH_PREFIX causes searching for a prefix of the item name.
169   * Return -1 if no matching item is found.
170   */
171   FXint findItem(const FXString& text,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
172 
173   /**
174   * Search items by associated user data, beginning from item start. If the
175   * start item is -1 the search will start at the first item in the list.
176   * Flags may be SEARCH_FORWARD or SEARCH_BACKWARD to control the
177   * search direction; this can be combined with SEARCH_NOWRAP or SEARCH_WRAP
178   * to control whether the search wraps at the start or end of the list.
179   */
180   FXint findItemByData(const void *ptr,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
181 
182   /// Set text for specified item
183   void setItemText(FXint index,const FXString& text);
184 
185   /// Get text for specified item
186   FXString getItemText(FXint index) const;
187 
188   /// Change item icon, deleting old one if it was owned
189   void setItemIcon(FXint index,FXIcon* icon,FXbool owned=FALSE);
190 
191   /// Return icon of item at index
192   FXIcon* getItemIcon(FXint index) const;
193 
194   /// Set data pointer for specified item
195   void setItemData(FXint index,void* ptr) const;
196 
197   /// Get data pointer for specified item
198   void* getItemData(FXint index) const;
199 
200   /// Is the pane shown
201   FXbool isPaneShown() const;
202 
203   /// Sort items using current sort function
204   void sortItems();
205 
206   /// Set text font
207   void setFont(FXFont* fnt);
208 
209   /// Get text font
210   FXFont* getFont() const;
211 
212   /// Set window background color
213   virtual void setBackColor(FXColor clr);
214 
215   /// Get background color
216   FXColor getBackColor() const;
217 
218   /// Change text color
219   void setTextColor(FXColor clr);
220 
221   /// Return text color
222   FXColor getTextColor() const;
223 
224   /// Change selected background color
225   void setSelBackColor(FXColor clr);
226 
227   /// Return selected background color
228   FXColor getSelBackColor() const;
229 
230   /// Change selected text color
231   void setSelTextColor(FXColor clr);
232 
233   /// Return selected text color
234   FXColor getSelTextColor() const;
235 
236   /// Return sort function
237   FXListSortFunc getSortFunc() const;
238 
239   /// Change sort function
240   void setSortFunc(FXListSortFunc func);
241 
242   /// Set the combobox help text
243   void setHelpText(const FXString& txt);
244 
245   /// Get the combobox help text
246   const FXString& getHelpText() const;
247 
248   /// Set the tool tip message for this combobox
249   void setTipText(const FXString& txt);
250 
251   /// Get the tool tip message for this combobox
252   const FXString& getTipText() const;
253 
254   /// Save combobox to a stream
255   virtual void save(FXStream& store) const;
256 
257   /// Load combobox from a stream
258   virtual void load(FXStream& store);
259 
260   /// Destructor
261   virtual ~FXListBox();
262   };
263 
264 }
265 
266 #endif
267