1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
|
/********************************************************************************
* *
* T r e e L i s t B o x W i d g e t *
* *
*********************************************************************************
* Copyright (C) 1999,2022 by Jeroen van der Zijp. All Rights Reserved. *
*********************************************************************************
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/> *
********************************************************************************/
#ifndef FXTREELISTBOX_H
#define FXTREELISTBOX_H
#ifndef FXPACKER_H
#include "FXPacker.h"
#endif
namespace FX {
/// Tree List Box styles
enum {
TREELISTBOX_NORMAL = 0 /// Normal style
};
class FXButton;
class FXMenuButton;
class FXTreeList;
class FXPopup;
/**
* The Tree List Box behaves very much like a List Box, except that
* it supports a hierarchical, tree structured display of the items.
* When an item is selected it issues a SEL_COMMAND message with the
* pointer to the item. While manipulating the tree list, it may send
* SEL_CHANGED messages to indicate which item the cursor is hovering over.
* When items are added, replaced, or removed, the list sends messages of
* the type SEL_INSERTED, SEL_REPLACED, or SEL_DELETED, with the pointer to
* the affected item as argument.
*/
class FXAPI FXTreeListBox : public FXPacker {
FXDECLARE(FXTreeListBox)
protected:
FXButton *field;
FXMenuButton *button;
FXTreeList *tree;
FXPopup *pane;
protected:
FXTreeListBox(){}
private:
FXTreeListBox(const FXTreeListBox&);
FXTreeListBox& operator=(const FXTreeListBox&);
public:
long onFocusUp(FXObject*,FXSelector,void*);
long onFocusDown(FXObject*,FXSelector,void*);
long onFocusSelf(FXObject*,FXSelector,void*);
long onMouseWheel(FXObject*,FXSelector,void*);
long onFieldButton(FXObject*,FXSelector,void*);
long onTreeUpdate(FXObject*,FXSelector,void*);
long onTreeForward(FXObject*,FXSelector,void*);
long onTreeClicked(FXObject*,FXSelector,void*);
long onTreeCommand(FXObject*,FXSelector,void*);
public:
enum{
ID_TREE=FXPacker::ID_LAST,
ID_FIELD,
ID_LAST
};
public:
/// Construct tree list box
FXTreeListBox(FXComposite *p,FXObject* tgt=nullptr,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);
/// Create server-side resources
virtual void create();
/// Detach server-side resources
virtual void detach();
/// Destroy server-side resources
virtual void destroy();
/// Perform layout
virtual void layout();
/// Enable widget
virtual void enable();
/// Disable widget
virtual void disable();
/// Return default with
virtual FXint getDefaultWidth();
/// Return default height
virtual FXint getDefaultHeight();
/// Return number of items
FXint getNumItems() const;
/// Return number of visible items
FXint getNumVisible() const;
/// Set number of visible items to determine default height
void setNumVisible(FXint nvis);
/// Return first top-level item
FXTreeItem* getFirstItem() const;
/// Return last top-level item
FXTreeItem* getLastItem() const;
/// Return true if item is the current item
FXbool isItemCurrent(const FXTreeItem* item) const;
/// Change current item
virtual void setCurrentItem(FXTreeItem* item,FXbool notify=false);
/// Return current item
FXTreeItem* getCurrentItem() const;
/// Fill tree list box by appending items from array of strings
FXint fillItems(FXTreeItem* father,const FXchar *const *strings,FXIcon* oi=nullptr,FXIcon* ci=nullptr,FXptr ptr=nullptr,FXbool notify=false);
/// Fill tree list box by appending items from array of strings
FXint fillItems(FXTreeItem* father,const FXString* strings,FXIcon* oi=nullptr,FXIcon* ci=nullptr,FXptr ptr=nullptr,FXbool notify=false);
/// Fill tree list box by appending items from newline separated strings
FXint fillItems(FXTreeItem* father,const FXString& strings,FXIcon* oi=nullptr,FXIcon* ci=nullptr,FXptr ptr=nullptr,FXbool notify=false);
/// Replace the original item orig with new [possibly subclassed] item
FXTreeItem* setItem(FXTreeItem* orig,FXTreeItem* item,FXbool notify=false);
/// Insert [possibly subclassed] item under father before other item
FXTreeItem* insertItem(FXTreeItem* other,FXTreeItem* father,FXTreeItem* item,FXbool notify=false);
/// Insert item with given text and optional icons, and user-data pointer under father before other item
FXTreeItem* insertItem(FXTreeItem* other,FXTreeItem* father,const FXString& text,FXIcon* oi=nullptr,FXIcon* ci=nullptr,FXptr ptr=nullptr,FXbool notify=false);
/// Append [possibly subclassed] item as last child of father
FXTreeItem* appendItem(FXTreeItem* father,FXTreeItem* item,FXbool notify=false);
/// Append item with given text and optional icons, and user-data pointer as last child of father
FXTreeItem* appendItem(FXTreeItem* father,const FXString& text,FXIcon* oi=nullptr,FXIcon* ci=nullptr,FXptr ptr=nullptr,FXbool notify=false);
/// Prepend [possibly subclassed] item as first child of father
FXTreeItem* prependItem(FXTreeItem* father,FXTreeItem* item,FXbool notify=false);
/// Prepend item with given text and optional icons, and user-data pointer as first child of father
FXTreeItem* prependItem(FXTreeItem* father,const FXString& text,FXIcon* oi=nullptr,FXIcon* ci=nullptr,FXptr ptr=nullptr,FXbool notify=false);
/// Move item under father before other item
FXTreeItem *moveItem(FXTreeItem* other,FXTreeItem* father,FXTreeItem* item);
/// Extract item
FXTreeItem* extractItem(FXTreeItem* item,FXbool notify=false);
/// Remove item
void removeItem(FXTreeItem* item,FXbool notify=false);
/// Remove all items in range [fm...to]
void removeItems(FXTreeItem* fm,FXTreeItem* to,FXbool notify=false);
/// Remove all items from list
void clearItems(FXbool notify=false);
/**
* Search items by name, beginning from item start. If the
* start item is NULL the search will start at the first, top-most item
* in the list. Flags may be SEARCH_FORWARD or SEARCH_BACKWARD to control
* the search direction; this can be combined with SEARCH_NOWRAP or SEARCH_WRAP
* to control whether the search wraps at the start or end of the list.
* The option SEARCH_IGNORECASE causes a case-insensitive match. Finally,
* passing SEARCH_PREFIX causes searching for a prefix of the item name.
* Return NULL if no matching item is found.
*/
FXTreeItem* findItem(const FXString& string,FXTreeItem* start=nullptr,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
/**
* Search items by associated user data, beginning from item start. If the
* start item is NULL the search will start at the first, top-most item
* in the list. Flags may be SEARCH_FORWARD or SEARCH_BACKWARD to control
* the search direction; this can be combined with SEARCH_NOWRAP or SEARCH_WRAP
* to control whether the search wraps at the start or end of the list.
*/
FXTreeItem* findItemByData(FXptr ptr,FXTreeItem* start=nullptr,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
/// Change item label
void setItemText(FXTreeItem* item,const FXString& text);
/// Return item label
FXString getItemText(const FXTreeItem* item) const;
/// Change item's open icon, delete old one if it was owned
void setItemOpenIcon(FXTreeItem* item,FXIcon* icon,FXbool owned=false);
/// Return item's open icon
FXIcon* getItemOpenIcon(const FXTreeItem* item) const;
/// Change item's closed icon, delete old one if it was owned
void setItemClosedIcon(FXTreeItem* item,FXIcon* icon,FXbool owned=false);
/// Return item's closed icon
FXIcon* getItemClosedIcon(const FXTreeItem* item) const;
/// Change item's user data
void setItemData(FXTreeItem* item,FXptr ptr) const;
/// Return item's user data
FXptr getItemData(const FXTreeItem* item) const;
/// Return true if item is leaf-item, i.e. has no children
FXbool isItemLeaf(const FXTreeItem* item) const;
/// Return true if item is enabled
FXbool isItemEnabled(const FXTreeItem* item) const;
/// Enable item
FXbool enableItem(FXTreeItem* item);
/// Disable item
FXbool disableItem(FXTreeItem* item);
/// Show or hide menu
void showMenu(FXbool shw);
/// Is the menu pane shown
FXbool isMenuShown() const;
/// Sort all items recursively
void sortItems();
/// Sort the toplevel items with the sort function
void sortRootItems();
/// Sort child items of item
void sortChildItems(FXTreeItem* item);
/// Change font
void setFont(FXFont* fnt);
/// Return font
FXFont* getFont() const;
/// Change list style
void setListStyle(FXuint style);
/// Return list style
FXuint getListStyle() const;
/// Change popup pane shrinkwrap mode
void setShrinkWrap(FXbool flag);
/// Return popup pane shrinkwrap mode
FXbool getShrinkWrap() const;
/// Return item sort function
FXTreeListSortFunc getSortFunc() const;
/// Change item sort function
void setSortFunc(FXTreeListSortFunc func);
/// Change help text
void setHelpText(const FXString& txt);
/// Return help text
const FXString& getHelpText() const;
/// Change tip text
void setTipText(const FXString& txt);
/// Return tip text
const FXString& getTipText() const;
/// Save object to a stream
virtual void save(FXStream& store) const;
/// Load object from a stream
virtual void load(FXStream& store);
/// Destructor
virtual ~FXTreeListBox();
};
}
#endif
|