1 /******************************************************************************** 2 * * 3 * T r e e L i s t B o x W i d g e t * 4 * * 5 ********************************************************************************* 6 * Copyright (C) 1999,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: FXTreeListBox.h,v 1.41 2006/01/22 17:58:11 fox Exp $ * 23 ********************************************************************************/ 24 #ifndef FXTREELISTBOX_H 25 #define FXTREELISTBOX_H 26 27 #ifndef FXPACKER_H 28 #include "FXPacker.h" 29 #endif 30 31 namespace FX { 32 33 34 /// Tree List Box styles 35 enum { 36 TREELISTBOX_NORMAL = 0 /// Normal style 37 }; 38 39 40 class FXButton; 41 class FXMenuButton; 42 class FXTreeList; 43 class FXPopup; 44 45 46 /** 47 * The Tree List Box behaves very much like a List Box, except that 48 * it supports a hierarchical, tree structured display of the items. 49 * When an item is selected it issues a SEL_COMMAND message with the 50 * pointer to the item. While manipulating the tree list, it may send 51 * SEL_CHANGED messages to indicate which item the cursor is hovering over. 52 */ 53 class FXAPI FXTreeListBox : public FXPacker { 54 FXDECLARE(FXTreeListBox) 55 protected: 56 FXButton *field; 57 FXMenuButton *button; 58 FXTreeList *tree; 59 FXPopup *pane; 60 protected: FXTreeListBox()61 FXTreeListBox(){} 62 private: 63 FXTreeListBox(const FXTreeListBox&); 64 FXTreeListBox& operator=(const FXTreeListBox&); 65 public: 66 long onFocusUp(FXObject*,FXSelector,void*); 67 long onFocusDown(FXObject*,FXSelector,void*); 68 long onFocusSelf(FXObject*,FXSelector,void*); 69 long onMouseWheel(FXObject*,FXSelector,void*); 70 long onFieldButton(FXObject*,FXSelector,void*); 71 long onTreeUpdate(FXObject*,FXSelector,void*); 72 long onTreeChanged(FXObject*,FXSelector,void*); 73 long onTreeClicked(FXObject*,FXSelector,void*); 74 public: 75 enum{ 76 ID_TREE=FXPacker::ID_LAST, 77 ID_FIELD, 78 ID_LAST 79 }; 80 public: 81 82 /// Construct tree list box 83 FXTreeListBox(FXComposite *p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=FRAME_SUNKEN|FRAME_THICK|TREELISTBOX_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); 84 85 /// Create server-side resources 86 virtual void create(); 87 88 /// Detach server-side resources 89 virtual void detach(); 90 91 /// Destroy server-side resources 92 virtual void destroy(); 93 94 /// Perform layout 95 virtual void layout(); 96 97 /// Enable widget 98 virtual void enable(); 99 100 /// Disable widget 101 virtual void disable(); 102 103 /// Return default with 104 virtual FXint getDefaultWidth(); 105 106 /// Return default height 107 virtual FXint getDefaultHeight(); 108 109 /// Return number of items 110 FXint getNumItems() const; 111 112 /// Return number of visible items 113 FXint getNumVisible() const; 114 115 /// Set number of visible items to determine default height 116 void setNumVisible(FXint nvis); 117 118 /// Return first top-level item 119 FXTreeItem* getFirstItem() const; 120 121 /// Return last top-level item 122 FXTreeItem* getLastItem() const; 123 124 /// Fill tree list box by appending items from array of strings 125 FXint fillItems(FXTreeItem* father,const FXchar** strings,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL); 126 127 /// Fill tree list box by appending items from newline separated strings 128 FXint fillItems(FXTreeItem* father,const FXString& strings,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL); 129 130 /// Insert [possibly subclassed] item under father before other item 131 FXTreeItem* insertItem(FXTreeItem* other,FXTreeItem* father,FXTreeItem* item); 132 133 /// Insert item with given text and optional icons, and user-data pointer under father before other item 134 FXTreeItem* insertItem(FXTreeItem* other,FXTreeItem* father,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL); 135 136 /// Append [possibly subclassed] item as last child of father 137 FXTreeItem* appendItem(FXTreeItem* father,FXTreeItem* item); 138 139 /// Append item with given text and optional icons, and user-data pointer as last child of father 140 FXTreeItem* appendItem(FXTreeItem* father,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL); 141 142 /// Prepend [possibly subclassed] item as first child of father 143 FXTreeItem* prependItem(FXTreeItem* father,FXTreeItem* item); 144 145 /// Prepend item with given text and optional icons, and user-data pointer as first child of father 146 FXTreeItem* prependItem(FXTreeItem* father,const FXString& text,FXIcon* oi=NULL,FXIcon* ci=NULL,void* ptr=NULL); 147 148 /// Move item under father before other item 149 FXTreeItem *moveItem(FXTreeItem* other,FXTreeItem* father,FXTreeItem* item); 150 151 /// Extract item 152 FXTreeItem* extractItem(FXTreeItem* item); 153 154 /// Remove item 155 void removeItem(FXTreeItem* item); 156 157 /// Remove all items in range [fm...to] 158 void removeItems(FXTreeItem* fm,FXTreeItem* to); 159 160 /// Remove all items from list 161 void clearItems(); 162 163 /** 164 * Search items by name, beginning from item start. If the 165 * start item is NULL the search will start at the first, top-most item 166 * in the list. Flags may be SEARCH_FORWARD or SEARCH_BACKWARD to control 167 * the search direction; this can be combined with SEARCH_NOWRAP or SEARCH_WRAP 168 * to control whether the search wraps at the start or end of the list. 169 * The option SEARCH_IGNORECASE causes a case-insensitive match. Finally, 170 * passing SEARCH_PREFIX causes searching for a prefix of the item name. 171 * Return NULL if no matching item is found. 172 */ 173 FXTreeItem* findItem(const FXString& text,FXTreeItem* start=NULL,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const; 174 175 /** 176 * Search items by associated user data, beginning from item start. If the 177 * start item is NULL the search will start at the first, top-most item 178 * in the list. Flags may be SEARCH_FORWARD or SEARCH_BACKWARD to control 179 * the search direction; this can be combined with SEARCH_NOWRAP or SEARCH_WRAP 180 * to control whether the search wraps at the start or end of the list. 181 */ 182 FXTreeItem* findItemByData(const void *ptr,FXTreeItem* start=NULL,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const; 183 184 /// Return TRUE if item is the current item 185 FXbool isItemCurrent(const FXTreeItem* item) const; 186 187 /// Return TRUE if item is leaf-item, i.e. has no children 188 FXbool isItemLeaf(const FXTreeItem* item) const; 189 190 /// Sort the toplevel items with the sort function 191 void sortRootItems(); 192 193 /// Sort all items recursively 194 void sortItems(); 195 196 /// Sort child items of item 197 void sortChildItems(FXTreeItem* item); 198 199 /// Change current item 200 virtual void setCurrentItem(FXTreeItem* item,FXbool notify=FALSE); 201 202 /// Return current item 203 FXTreeItem* getCurrentItem() const; 204 205 /// Change item label 206 void setItemText(FXTreeItem* item,const FXString& text); 207 208 /// Return item label 209 FXString getItemText(const FXTreeItem* item) const; 210 211 /// Change item's open icon, delete old one if it was owned 212 void setItemOpenIcon(FXTreeItem* item,FXIcon* icon,FXbool owned=FALSE); 213 214 /// Return item's open icon 215 FXIcon* getItemOpenIcon(const FXTreeItem* item) const; 216 217 /// Change item's closed icon, delete old one if it was owned 218 void setItemClosedIcon(FXTreeItem* item,FXIcon* icon,FXbool owned=FALSE); 219 220 /// Return item's closed icon 221 FXIcon* getItemClosedIcon(const FXTreeItem* item) const; 222 223 /// Change item's user data 224 void setItemData(FXTreeItem* item,void* ptr) const; 225 226 /// Return item's user data 227 void* getItemData(const FXTreeItem* item) const; 228 229 /// Return item sort function 230 FXTreeListSortFunc getSortFunc() const; 231 232 /// Change item sort function 233 void setSortFunc(FXTreeListSortFunc func); 234 235 /// Is the pane shown 236 FXbool isPaneShown() const; 237 238 /// Change font 239 void setFont(FXFont* fnt); 240 241 /// Return font 242 FXFont* getFont() const; 243 244 /// Return list style 245 FXuint getListStyle() const; 246 247 /// Change list style 248 void setListStyle(FXuint style); 249 250 /// Change help text 251 void setHelpText(const FXString& txt); 252 253 /// Return help text 254 const FXString& getHelpText() const; 255 256 /// Change tip text 257 void setTipText(const FXString& txt); 258 259 /// Return tip text 260 const FXString& getTipText() const; 261 262 /// Save object to a stream 263 virtual void save(FXStream& store) const; 264 265 /// Load object from a stream 266 virtual void load(FXStream& store); 267 268 /// Destructor 269 virtual ~FXTreeListBox(); 270 }; 271 272 } 273 274 #endif 275