1 /******************************************************************************** 2 * * 3 * I c o n L i s t 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: FXIconList.h 3297 2015-12-14 20:30:04Z arthurcnorman $ * 23 ********************************************************************************/ 24 #ifndef FXICONLIST_H 25 #define FXICONLIST_H 26 27 #ifndef FXSCROLLAREA_H 28 #include "FXScrollArea.h" 29 #endif 30 31 namespace FX { 32 33 34 /// Icon list styles 35 enum { 36 ICONLIST_EXTENDEDSELECT = 0, /// Extended selection mode 37 ICONLIST_SINGLESELECT = 0x00100000, /// At most one selected item 38 ICONLIST_BROWSESELECT = 0x00200000, /// Always exactly one selected item 39 ICONLIST_MULTIPLESELECT = 0x00300000, /// Multiple selection mode 40 ICONLIST_AUTOSIZE = 0x00400000, /// Automatically size item spacing 41 ICONLIST_DETAILED = 0, /// List mode 42 ICONLIST_MINI_ICONS = 0x00800000, /// Mini Icon mode 43 ICONLIST_BIG_ICONS = 0x01000000, /// Big Icon mode 44 ICONLIST_ROWS = 0, /// Row-wise mode 45 ICONLIST_COLUMNS = 0x02000000, /// Column-wise mode 46 ICONLIST_NORMAL = ICONLIST_EXTENDEDSELECT 47 }; 48 49 50 class FXIcon; 51 class FXHeader; 52 class FXFont; 53 class FXIconList; 54 class FXFileList; 55 56 57 /// Icon item 58 class FXAPI FXIconItem : public FXObject { 59 FXDECLARE(FXIconItem) 60 friend class FXIconList; 61 friend class FXFileList; 62 protected: 63 FXString label; 64 FXIcon *bigIcon; 65 FXIcon *miniIcon; 66 void *data; 67 FXuint state; 68 private: 69 FXIconItem(const FXIconItem&); 70 FXIconItem& operator=(const FXIconItem&); 71 protected: FXIconItem()72 FXIconItem():bigIcon(NULL),miniIcon(NULL),data(NULL),state(0){} 73 virtual void draw(const FXIconList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const; 74 virtual FXint hitItem(const FXIconList* list,FXint rx,FXint ry,FXint rw=1,FXint rh=1) const; 75 protected: 76 virtual void drawBigIcon(const FXIconList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const; 77 virtual void drawMiniIcon(const FXIconList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const; 78 virtual void drawDetails(const FXIconList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const; 79 public: 80 enum { 81 SELECTED = 1, /// Selected 82 FOCUS = 2, /// Focus 83 DISABLED = 4, /// Disabled 84 DRAGGABLE = 8, /// Draggable 85 BIGICONOWNED = 16, /// Big icon owned by item 86 MINIICONOWNED = 32 /// Mini icon owned by item 87 }; 88 public: 89 90 /// Construct new item with given text, icons, and user-data label(text)91 FXIconItem(const FXString& text,FXIcon* bi=NULL,FXIcon* mi=NULL,void* ptr=NULL):label(text),bigIcon(bi),miniIcon(mi),data(ptr),state(0){} 92 93 /// Change item's text label 94 virtual void setText(const FXString& txt); 95 96 /// Return item's text label getText()97 const FXString& getText() const { return label; } 98 99 /// Change item's big icon, deleting the old icon if it was owned 100 virtual void setBigIcon(FXIcon* icn,FXbool owned=FALSE); 101 102 /// Return item's big icon getBigIcon()103 FXIcon* getBigIcon() const { return bigIcon; } 104 105 /// Change item's mini icon, deleting the old icon if it was owned 106 virtual void setMiniIcon(FXIcon* icn,FXbool owned=FALSE); 107 108 /// Return item's mini icon getMiniIcon()109 FXIcon* getMiniIcon() const { return miniIcon; } 110 111 /// Change item's user data setData(void * ptr)112 void setData(void* ptr){ data=ptr; } 113 114 /// Get item's user data getData()115 void* getData() const { return data; } 116 117 /// Make item draw as focused 118 virtual void setFocus(FXbool focus); 119 120 /// Return true if item has focus hasFocus()121 FXbool hasFocus() const { return (state&FOCUS)!=0; } 122 123 /// Select item 124 virtual void setSelected(FXbool selected); 125 126 /// Return true if this item is selected isSelected()127 FXbool isSelected() const { return (state&SELECTED)!=0; } 128 129 /// Enable or disable item 130 virtual void setEnabled(FXbool enabled); 131 132 /// Return true if this item is enabled isEnabled()133 FXbool isEnabled() const { return (state&DISABLED)==0; } 134 135 /// Make item draggable 136 virtual void setDraggable(FXbool draggable); 137 138 /// Return true if this item is draggable isDraggable()139 FXbool isDraggable() const { return (state&DRAGGABLE)!=0; } 140 141 /// Return width of item as drawn in list 142 virtual FXint getWidth(const FXIconList* list) const; 143 144 /// Return height of item as drawn in list 145 virtual FXint getHeight(const FXIconList* list) const; 146 147 /// Create server-side resources 148 virtual void create(); 149 150 /// Detach server-side resources 151 virtual void detach(); 152 153 /// Destroy server-side resources 154 virtual void destroy(); 155 156 /// Save to stream 157 virtual void save(FXStream& store) const; 158 159 /// Load from stream 160 virtual void load(FXStream& store); 161 162 /// Destroy item and free icons if owned 163 virtual ~FXIconItem(); 164 }; 165 166 167 /// Icon item collate function 168 typedef FXint (*FXIconListSortFunc)(const FXIconItem*,const FXIconItem*); 169 170 171 /// List of FXIconItem's 172 typedef FXObjectListOf<FXIconItem> FXIconItemList; 173 174 175 /** 176 * A Icon List Widget displays a list of items, each with a text and 177 * optional icon. Icon List can display its items in essentially three 178 * different ways; in big-icon mode, the bigger of the two icons is used 179 * for each item, and the text is placed underneath the icon. In mini- 180 * icon mode, the icons are listed in rows and columns, with the smaller 181 * icon preceding the text. Finally, in detail mode the icons are listed 182 * in a single column, and all fields of the text are shown under a 183 * header control with one button for each subfield. 184 * When an item's selected state changes, the icon list sends 185 * a SEL_SELECTED or SEL_DESELECTED message. A change of the current 186 * item is signified by the SEL_CHANGED message. 187 * The icon list sends SEL_COMMAND messages when the user clicks on an item, 188 * and SEL_CLICKED, SEL_DOUBLECLICKED, and SEL_TRIPLECLICKED when the user 189 * clicks once, twice, or thrice, respectively. 190 * When items are added, replaced, or removed, the icon list sends messages 191 * of the type SEL_INSERTED, SEL_REPLACED, or SEL_DELETED. 192 * In each of these cases, the index to the item, if any, is passed in the 193 * 3rd argument of the message. 194 */ 195 class FXAPI FXIconList : public FXScrollArea { 196 FXDECLARE(FXIconList) 197 protected: 198 FXHeader *header; // Header control 199 FXIconItemList items; // Item list 200 FXint nrows; // Number of rows 201 FXint ncols; // Number of columns 202 FXint anchor; // Anchor item 203 FXint current; // Current item 204 FXint extent; // Extent item 205 FXint cursor; // Cursor item 206 FXint viewable; // Visible item 207 FXFont *font; // Font 208 FXIconListSortFunc sortfunc; // Item sort function 209 FXColor textColor; // Text color 210 FXColor selbackColor; // Selected back color 211 FXColor seltextColor; // Selected text color 212 FXint itemWidth; // Item width 213 FXint itemHeight; // Item height 214 FXint itemSpace; // Space for item label 215 FXint anchorx; // Rectangular selection 216 FXint anchory; 217 FXint currentx; 218 FXint currenty; 219 FXint grabx; // Grab point x 220 FXint graby; // Grab point y 221 FXString lookup; // Lookup string 222 FXString help; // Help text 223 FXbool state; // State of item 224 protected: 225 FXIconList(); 226 void recompute(); 227 void getrowscols(FXint& nr,FXint& nc,FXint w,FXint h) const; 228 void drawLasso(FXint x0,FXint y0,FXint x1,FXint y1); 229 void lassoChanged(FXint ox,FXint oy,FXint ow,FXint oh,FXint nx,FXint ny,FXint nw,FXint nh,FXbool notify); 230 virtual void moveContents(FXint x,FXint y); 231 virtual FXIconItem *createItem(const FXString& text,FXIcon *big,FXIcon* mini,void* ptr); 232 static FXint compareSection(const FXchar *p,const FXchar* q,FXint s); 233 static FXint compareSectionCase(const FXchar *p,const FXchar* q,FXint s); 234 private: 235 FXIconList(const FXIconList&); 236 FXIconList &operator=(const FXIconList&); 237 public: 238 long onPaint(FXObject*,FXSelector,void*); 239 long onEnter(FXObject*,FXSelector,void*); 240 long onLeave(FXObject*,FXSelector,void*); 241 long onUngrabbed(FXObject*,FXSelector,void*); 242 long onKeyPress(FXObject*,FXSelector,void*); 243 long onKeyRelease(FXObject*,FXSelector,void*); 244 long onLeftBtnPress(FXObject*,FXSelector,void*); 245 long onLeftBtnRelease(FXObject*,FXSelector,void*); 246 long onRightBtnPress(FXObject*,FXSelector,void*); 247 long onRightBtnRelease(FXObject*,FXSelector,void*); 248 long onMotion(FXObject*,FXSelector,void*); 249 long onQueryTip(FXObject*,FXSelector,void*); 250 long onQueryHelp(FXObject*,FXSelector,void*); 251 long onTipTimer(FXObject*,FXSelector,void*); 252 long onCmdSelectAll(FXObject*,FXSelector,void*); 253 long onCmdDeselectAll(FXObject*,FXSelector,void*); 254 long onCmdSelectInverse(FXObject*,FXSelector,void*); 255 long onCmdArrangeByRows(FXObject*,FXSelector,void*); 256 long onUpdArrangeByRows(FXObject*,FXSelector,void*); 257 long onCmdArrangeByColumns(FXObject*,FXSelector,void*); 258 long onUpdArrangeByColumns(FXObject*,FXSelector,void*); 259 long onCmdShowDetails(FXObject*,FXSelector,void*); 260 long onUpdShowDetails(FXObject*,FXSelector,void*); 261 long onCmdShowBigIcons(FXObject*,FXSelector,void*); 262 long onUpdShowBigIcons(FXObject*,FXSelector,void*); 263 long onCmdShowMiniIcons(FXObject*,FXSelector,void*); 264 long onUpdShowMiniIcons(FXObject*,FXSelector,void*); 265 long onHeaderChanged(FXObject*,FXSelector,void*); 266 long onHeaderResize(FXObject*,FXSelector,void*); 267 long onFocusIn(FXObject*,FXSelector,void*); 268 long onFocusOut(FXObject*,FXSelector,void*); 269 long onClicked(FXObject*,FXSelector,void*); 270 long onDoubleClicked(FXObject*,FXSelector,void*); 271 long onTripleClicked(FXObject*,FXSelector,void*); 272 long onCommand(FXObject*,FXSelector,void*); 273 long onAutoScroll(FXObject*,FXSelector,void*); 274 long onLookupTimer(FXObject*,FXSelector,void*); 275 long onCmdSetValue(FXObject*,FXSelector,void*); 276 long onCmdGetIntValue(FXObject*,FXSelector,void*); 277 long onCmdSetIntValue(FXObject*,FXSelector,void*); 278 public: 279 static FXint ascending(const FXIconItem* a,const FXIconItem* b); 280 static FXint descending(const FXIconItem* a,const FXIconItem* b); 281 static FXint ascendingCase(const FXIconItem* a,const FXIconItem* b); 282 static FXint descendingCase(const FXIconItem* a,const FXIconItem* b); 283 public: 284 enum { 285 ID_SHOW_DETAILS=FXScrollArea::ID_LAST, 286 ID_SHOW_MINI_ICONS, 287 ID_SHOW_BIG_ICONS, 288 ID_ARRANGE_BY_ROWS, 289 ID_ARRANGE_BY_COLUMNS, 290 ID_HEADER_CHANGE, 291 ID_LOOKUPTIMER, 292 ID_SELECT_ALL, 293 ID_DESELECT_ALL, 294 ID_SELECT_INVERSE, 295 ID_LAST 296 }; 297 public: 298 299 /// Construct icon list with no items in it initially 300 FXIconList(FXComposite *p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=ICONLIST_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0); 301 302 /// Create server-side resources 303 virtual void create(); 304 305 /// Detach server-side resources 306 virtual void detach(); 307 308 /// Recalculate layout 309 virtual void recalc(); 310 311 /// Perform layout 312 virtual void layout(); 313 314 /// Compute and return content width 315 virtual FXint getContentWidth(); 316 317 /// Return content height 318 virtual FXint getContentHeight(); 319 320 /// Icon list can receive focus 321 virtual bool canFocus() const; 322 323 /// Move the focus to this window 324 virtual void setFocus(); 325 326 /// Remove the focus from this window 327 virtual void killFocus(); 328 329 /// Return viewport size 330 virtual FXint getViewportHeight(); 331 332 /// Resize this window to the specified width and height 333 virtual void resize(FXint w,FXint h); 334 335 /// Move and resize this window in the parent's coordinates 336 virtual void position(FXint x,FXint y,FXint w,FXint h); 337 338 /// Return number of items getNumItems()339 FXint getNumItems() const { return items.no(); } 340 341 /// Return number of rows getNumRows()342 FXint getNumRows() const { return nrows; } 343 344 /// Return number of columns getNumCols()345 FXint getNumCols() const { return ncols; } 346 347 /// Return header control getHeader()348 FXHeader* getHeader() const { return header; } 349 350 /// Set headers from array of strings 351 void setHeaders(const FXchar** strings,FXint size=1); 352 353 /// Set headers from newline separated strings 354 void setHeaders(const FXString& strings,FXint size=1); 355 356 /// Append header with given text and optional icon 357 void appendHeader(const FXString& text,FXIcon *icon=NULL,FXint size=1); 358 359 /// Remove header at index 360 void removeHeader(FXint index); 361 362 /// Change text of header at index 363 void setHeaderText(FXint index,const FXString& text); 364 365 /// Return text of header at index 366 FXString getHeaderText(FXint index) const; 367 368 /// Change icon of header at index 369 void setHeaderIcon(FXint index,FXIcon *icon); 370 371 /// Return icon of header at index 372 FXIcon* getHeaderIcon(FXint index) const; 373 374 /// Change size of header at index 375 void setHeaderSize(FXint index,FXint size); 376 377 /// Return width of header at index 378 FXint getHeaderSize(FXint index) const; 379 380 /// Return number of headers 381 FXint getNumHeaders() const; 382 383 /// Return the item at the given index 384 FXIconItem *getItem(FXint index) const; 385 386 /// Replace the item with a [possibly subclassed] item 387 FXint setItem(FXint index,FXIconItem* item,FXbool notify=FALSE); 388 389 /// Replace items text, icons, and user-data pointer 390 FXint setItem(FXint index,const FXString& text,FXIcon *big=NULL,FXIcon* mini=NULL,void* ptr=NULL,FXbool notify=FALSE); 391 392 /// Fill list by appending items from array of strings 393 FXint fillItems(const FXchar** strings,FXIcon *big=NULL,FXIcon* mini=NULL,void* ptr=NULL,FXbool notify=FALSE); 394 395 /// Fill list by appending items from newline separated strings 396 FXint fillItems(const FXString& strings,FXIcon *big=NULL,FXIcon* mini=NULL,void* ptr=NULL,FXbool notify=FALSE); 397 398 /// Insert a new [possibly subclassed] item at the give index 399 FXint insertItem(FXint index,FXIconItem* item,FXbool notify=FALSE); 400 401 /// Insert item at index with given text, icons, and user-data pointer 402 FXint insertItem(FXint index,const FXString& text,FXIcon *big=NULL,FXIcon* mini=NULL,void* ptr=NULL,FXbool notify=FALSE); 403 404 /// Append a [possibly subclassed] item to the end of the list 405 FXint appendItem(FXIconItem* item,FXbool notify=FALSE); 406 407 /// Append new item with given text and optional icons, and user-data pointer 408 FXint appendItem(const FXString& text,FXIcon *big=NULL,FXIcon* mini=NULL,void* ptr=NULL,FXbool notify=FALSE); 409 410 /// Prepend a [possibly subclassed] item to the end of the list 411 FXint prependItem(FXIconItem* item,FXbool notify=FALSE); 412 413 /// Prepend new item with given text and optional icons, and user-data pointer 414 FXint prependItem(const FXString& text,FXIcon *big=NULL,FXIcon* mini=NULL,void* ptr=NULL,FXbool notify=FALSE); 415 416 /// Move item from oldindex to newindex 417 FXint moveItem(FXint newindex,FXint oldindex,FXbool notify=FALSE); 418 419 /// Extract item from list 420 FXIconItem* extractItem(FXint index,FXbool notify=FALSE); 421 422 /// Remove item from list 423 void removeItem(FXint index,FXbool notify=FALSE); 424 425 /// Remove all items from list 426 void clearItems(FXbool notify=FALSE); 427 428 /// Return item width getItemWidth()429 FXint getItemWidth() const { return itemWidth; } 430 431 /// Return item height getItemHeight()432 FXint getItemHeight() const { return itemHeight; } 433 434 /// Return index of item at x,y, or -1 if none 435 virtual FXint getItemAt(FXint x,FXint y) const; 436 437 /** 438 * Search items by name, beginning from item start. If the start 439 * item is -1 the search will start at the first item in the list. 440 * Flags may be SEARCH_FORWARD or SEARCH_BACKWARD to control the 441 * search direction; this can be combined with SEARCH_NOWRAP or SEARCH_WRAP 442 * to control whether the search wraps at the start or end of the list. 443 * The option SEARCH_IGNORECASE causes a case-insensitive match. Finally, 444 * passing SEARCH_PREFIX causes searching for a prefix of the item name. 445 * Return -1 if no matching item is found. 446 */ 447 FXint findItem(const FXString& text,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const; 448 449 /** 450 * Search items by associated user data, beginning from item start. If the 451 * start item is -1 the search will start at the first item in the list. 452 * Flags may be SEARCH_FORWARD or SEARCH_BACKWARD to control the 453 * search direction; this can be combined with SEARCH_NOWRAP or SEARCH_WRAP 454 * to control whether the search wraps at the start or end of the list. 455 */ 456 FXint findItemByData(const void *ptr,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const; 457 458 /// Scroll to make item at index visible 459 virtual void makeItemVisible(FXint index); 460 461 /// Change item text 462 void setItemText(FXint index,const FXString& text); 463 464 /// Return item text 465 FXString getItemText(FXint index) const; 466 467 /// Change item big icon 468 void setItemBigIcon(FXint index,FXIcon* icon,FXbool owned=FALSE); 469 470 /// Return big icon of item at index 471 FXIcon* getItemBigIcon(FXint index) const; 472 473 /// Change item mini icon 474 void setItemMiniIcon(FXint index,FXIcon* icon,FXbool owned=FALSE); 475 476 /// Return mini icon of item at index 477 FXIcon* getItemMiniIcon(FXint index) const; 478 479 /// Change item user-data pointer 480 void setItemData(FXint index,void* ptr); 481 482 /// Return item user-data pointer 483 void* getItemData(FXint index) const; 484 485 /// Return TRUE if item at index is selected 486 FXbool isItemSelected(FXint index) const; 487 488 /// Return TRUE if item at index is current 489 FXbool isItemCurrent(FXint index) const; 490 491 /// Return TRUE if item at index is visible 492 FXbool isItemVisible(FXint index) const; 493 494 /// Return TRUE if item at index is enabled 495 FXbool isItemEnabled(FXint index) const; 496 497 /// Return item hit code: 0 outside, 1 icon, 2 text 498 FXint hitItem(FXint index,FXint x,FXint y,FXint ww=1,FXint hh=1) const; 499 500 /// Repaint item at index 501 void updateItem(FXint index) const; 502 503 /// Enable item at index 504 virtual FXbool enableItem(FXint index); 505 506 /// Disable item at index 507 virtual FXbool disableItem(FXint index); 508 509 /// Select item at index 510 virtual FXbool selectItem(FXint index,FXbool notify=FALSE); 511 512 /// Deselect item at index 513 virtual FXbool deselectItem(FXint index,FXbool notify=FALSE); 514 515 /// Toggle item at index 516 virtual FXbool toggleItem(FXint index,FXbool notify=FALSE); 517 518 /// Select items in rectangle 519 virtual FXbool selectInRectangle(FXint x,FXint y,FXint w,FXint h,FXbool notify=FALSE); 520 521 /// Extend selection from anchor index to index 522 virtual FXbool extendSelection(FXint index,FXbool notify=FALSE); 523 524 /// Deselect all items 525 virtual FXbool killSelection(FXbool notify=FALSE); 526 527 /// Change current item index 528 virtual void setCurrentItem(FXint index,FXbool notify=FALSE); 529 530 /// Return current item index, or -1 if none getCurrentItem()531 FXint getCurrentItem() const { return current; } 532 533 /// Change anchor item index 534 void setAnchorItem(FXint index); 535 536 /// Return anchor item index, or -1 if none getAnchorItem()537 FXint getAnchorItem() const { return anchor; } 538 539 /// Return index of item under cursor, or -1 if none getCursorItem()540 FXint getCursorItem() const { return cursor; } 541 542 /// Sort items 543 void sortItems(); 544 545 /// Return sort function getSortFunc()546 FXIconListSortFunc getSortFunc() const { return sortfunc; } 547 548 /// Change sort function setSortFunc(FXIconListSortFunc func)549 void setSortFunc(FXIconListSortFunc func){ sortfunc=func; } 550 551 /// Change text font 552 void setFont(FXFont* fnt); 553 554 /// Return text font getFont()555 FXFont* getFont() const { return font; } 556 557 /// Return normal text color getTextColor()558 FXColor getTextColor() const { return textColor; } 559 560 /// Change normal text color 561 void setTextColor(FXColor clr); 562 563 /// Return selected text background getSelBackColor()564 FXColor getSelBackColor() const { return selbackColor; } 565 566 /// Change selected text background 567 void setSelBackColor(FXColor clr); 568 569 /// Return selected text color getSelTextColor()570 FXColor getSelTextColor() const { return seltextColor; } 571 572 /// Change selected text color 573 void setSelTextColor(FXColor clr); 574 575 /// Change maximum item space for each item 576 void setItemSpace(FXint s); 577 578 /// Return maximum item space getItemSpace()579 FXint getItemSpace() const { return itemSpace; } 580 581 /// Get the current icon list style 582 FXuint getListStyle() const; 583 584 /// Set the current icon list style. 585 void setListStyle(FXuint style); 586 587 /// Set the status line help text for this widget 588 void setHelpText(const FXString& text); 589 590 /// Get the status line help text for this widget getHelpText()591 const FXString& getHelpText() const { return help; } 592 593 /// Save list to a stream 594 virtual void save(FXStream& store) const; 595 596 /// Load list from a stream 597 virtual void load(FXStream& store); 598 599 /// Destructor 600 virtual ~FXIconList(); 601 }; 602 603 } 604 605 #endif 606