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

FXIconList.h

00001 /******************************************************************************** 00002 * * 00003 * I c o n L i s t W i d g e t * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1999,2004 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 ********************************************************************************* 00022 * $Id: FXIconList.h,v 1.75 2004/02/17 21:06:02 fox Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXICONLIST_H 00025 #define FXICONLIST_H 00026 00027 #ifndef FXSCROLLAREA_H 00028 #include "FXScrollArea.h" 00029 #endif 00030 00031 namespace FX { 00032 00033 00034 /// Icon list styles 00035 enum { 00036 ICONLIST_EXTENDEDSELECT = 0, /// Extended selection mode 00037 ICONLIST_SINGLESELECT = 0x00100000, /// At most one selected item 00038 ICONLIST_BROWSESELECT = 0x00200000, /// Always exactly one selected item 00039 ICONLIST_MULTIPLESELECT = 0x00300000, /// Multiple selection mode 00040 ICONLIST_AUTOSIZE = 0x00400000, /// Automatically size item spacing 00041 ICONLIST_DETAILED = 0, /// List mode 00042 ICONLIST_MINI_ICONS = 0x00800000, /// Mini Icon mode 00043 ICONLIST_BIG_ICONS = 0x01000000, /// Big Icon mode 00044 ICONLIST_ROWS = 0, /// Row-wise mode 00045 ICONLIST_COLUMNS = 0x02000000, /// Column-wise mode 00046 ICONLIST_NORMAL = ICONLIST_EXTENDEDSELECT 00047 }; 00048 00049 00050 class FXIcon; 00051 class FXHeader; 00052 class FXFont; 00053 class FXIconList; 00054 class FXFileList; 00055 00056 00057 /// Icon item 00058 class FXAPI FXIconItem : public FXObject { 00059 FXDECLARE(FXIconItem) 00060 friend class FXIconList; 00061 friend class FXFileList; 00062 protected: 00063 FXString label; 00064 FXIcon *bigIcon; 00065 FXIcon *miniIcon; 00066 void *data; 00067 FXuint state; 00068 protected: 00069 FXIconItem():bigIcon(NULL),miniIcon(NULL),data(NULL),state(0){} 00070 virtual void draw(const FXIconList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const; 00071 virtual FXint hitItem(const FXIconList* list,FXint rx,FXint ry,FXint rw=1,FXint rh=1) const; 00072 protected: 00073 virtual void drawBigIcon(const FXIconList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const; 00074 virtual void drawMiniIcon(const FXIconList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const; 00075 virtual void drawDetails(const FXIconList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const; 00076 protected: 00077 enum { 00078 SELECTED = 1, 00079 FOCUS = 2, 00080 DISABLED = 4, 00081 DRAGGABLE = 8, 00082 BIGICONOWNED = 16, 00083 MINIICONOWNED = 32 00084 }; 00085 public: 00086 FXIconItem(const FXString& text,FXIcon* bi=NULL,FXIcon* mi=NULL,void* ptr=NULL):label(text),bigIcon(bi),miniIcon(mi),data(ptr),state(0){} 00087 virtual void setText(const FXString& txt){ label=txt; } 00088 const FXString& getText() const { return label; } 00089 virtual void setBigIcon(FXIcon* icn){ bigIcon=icn; } 00090 FXIcon* getBigIcon() const { return bigIcon; } 00091 virtual void setMiniIcon(FXIcon* icn){ miniIcon=icn; } 00092 FXIcon* getMiniIcon() const { return miniIcon; } 00093 void setData(void* ptr){ data=ptr; } 00094 void* getData() const { return data; } 00095 virtual void setFocus(FXbool focus); 00096 FXbool hasFocus() const { return (state&FOCUS)!=0; } 00097 virtual void setSelected(FXbool selected); 00098 FXbool isSelected() const { return (state&SELECTED)!=0; } 00099 virtual void setEnabled(FXbool enabled); 00100 FXbool isEnabled() const { return (state&DISABLED)==0; } 00101 virtual void setDraggable(FXbool draggable); 00102 FXbool isDraggable() const { return (state&DRAGGABLE)!=0; } 00103 virtual void setIconOwned(FXuint owned=(BIGICONOWNED|MINIICONOWNED)); 00104 FXuint isIconOwned() const { return (state&(BIGICONOWNED|MINIICONOWNED)); } 00105 virtual FXint getWidth(const FXIconList* list) const; 00106 virtual FXint getHeight(const FXIconList* list) const; 00107 virtual void create(); 00108 virtual void detach(); 00109 virtual void destroy(); 00110 virtual void save(FXStream& store) const; 00111 virtual void load(FXStream& store); 00112 virtual ~FXIconItem(); 00113 }; 00114 00115 00116 /// Icon item collate function 00117 typedef FXint (*FXIconListSortFunc)(const FXIconItem*,const FXIconItem*); 00118 00119 00120 /** 00121 * A Icon List Widget displays a list of items, each with a text and 00122 * optional icon. Icon List can display its items in essentially three 00123 * different ways; in big-icon mode, the bigger of the two icons is used 00124 * for each item, and the text is placed underneath the icon. In mini- 00125 * icon mode, the icons are listed in rows and columns, with the smaller 00126 * icon preceding the text. Finally, in detail mode the icons are listed 00127 * in a single column, and all fields of the text are shown under a 00128 * header control with one button for each subfield. 00129 * When an item's selected state changes, the icon list sends 00130 * a SEL_SELECTED or SEL_DESELECTED message. A change of the current 00131 * item is signified by the SEL_CHANGED message. 00132 * The icon list sends SEL_COMMAND messages when the user clicks on an item, 00133 * and SEL_CLICKED, SEL_DOUBLECLICKED, and SEL_TRIPLECLICKED when the user 00134 * clicks once, twice, or thrice, respectively. 00135 * When items are added, replaced, or removed, the icon list sends messages 00136 * of the type SEL_INSERTED, SEL_REPLACED, or SEL_DELETED. 00137 * In each of these cases, the index to the item, if any, is passed in the 00138 * 3rd argument of the message. 00139 */ 00140 class FXAPI FXIconList : public FXScrollArea { 00141 FXDECLARE(FXIconList) 00142 protected: 00143 FXHeader *header; // Header control 00144 FXIconItem **items; // Item list 00145 FXint nitems; // Number of items 00146 FXint nrows; // Number of rows 00147 FXint ncols; // Number of columns 00148 FXint anchor; // Anchor item 00149 FXint current; // Current item 00150 FXint extent; // Extent item 00151 FXint cursor; // Cursor item 00152 FXFont *font; // Font 00153 FXIconListSortFunc sortfunc; // Item sort function 00154 FXColor textColor; // Text color 00155 FXColor selbackColor; // Selected back color 00156 FXColor seltextColor; // Selected text color 00157 FXint itemWidth; // Item width 00158 FXint itemHeight; // Item height 00159 FXint itemSpace; // Space for item label 00160 FXint anchorx; // Rectangular selection 00161 FXint anchory; 00162 FXint currentx; 00163 FXint currenty; 00164 FXint grabx; // Grab point x 00165 FXint graby; // Grab point y 00166 FXString lookup; // Lookup string 00167 FXString help; // Help text 00168 FXbool state; // State of item 00169 protected: 00170 FXIconList(); 00171 virtual FXIconItem *createItem(const FXString& text,FXIcon *big,FXIcon* mini,void* ptr); 00172 virtual void moveContents(FXint x,FXint y); 00173 void drawLasso(FXint x0,FXint y0,FXint x1,FXint y1); 00174 void recompute(); 00175 void getrowscols(FXint& nr,FXint& nc,FXint w,FXint h) const; 00176 void lassoChanged(FXint ox,FXint oy,FXint ow,FXint oh,FXint nx,FXint ny,FXint nw,FXint nh,FXbool notify); 00177 private: 00178 FXIconList(const FXIconList&); 00179 FXIconList &operator=(const FXIconList&); 00180 public: 00181 long onPaint(FXObject*,FXSelector,void*); 00182 long onEnter(FXObject*,FXSelector,void*); 00183 long onLeave(FXObject*,FXSelector,void*); 00184 long onUngrabbed(FXObject*,FXSelector,void*); 00185 long onKeyPress(FXObject*,FXSelector,void*); 00186 long onKeyRelease(FXObject*,FXSelector,void*); 00187 long onLeftBtnPress(FXObject*,FXSelector,void*); 00188 long onLeftBtnRelease(FXObject*,FXSelector,void*); 00189 long onRightBtnPress(FXObject*,FXSelector,void*); 00190 long onRightBtnRelease(FXObject*,FXSelector,void*); 00191 long onMotion(FXObject*,FXSelector,void*); 00192 long onQueryTip(FXObject*,FXSelector,void*); 00193 long onQueryHelp(FXObject*,FXSelector,void*); 00194 long onTipTimer(FXObject*,FXSelector,void*); 00195 long onCmdSelectAll(FXObject*,FXSelector,void*); 00196 long onCmdDeselectAll(FXObject*,FXSelector,void*); 00197 long onCmdSelectInverse(FXObject*,FXSelector,void*); 00198 long onCmdArrangeByRows(FXObject*,FXSelector,void*); 00199 long onUpdArrangeByRows(FXObject*,FXSelector,void*); 00200 long onCmdArrangeByColumns(FXObject*,FXSelector,void*); 00201 long onUpdArrangeByColumns(FXObject*,FXSelector,void*); 00202 long onCmdShowDetails(FXObject*,FXSelector,void*); 00203 long onUpdShowDetails(FXObject*,FXSelector,void*); 00204 long onCmdShowBigIcons(FXObject*,FXSelector,void*); 00205 long onUpdShowBigIcons(FXObject*,FXSelector,void*); 00206 long onCmdShowMiniIcons(FXObject*,FXSelector,void*); 00207 long onUpdShowMiniIcons(FXObject*,FXSelector,void*); 00208 long onHeaderChanged(FXObject*,FXSelector,void*); 00209 long onHeaderResize(FXObject*,FXSelector,void*); 00210 long onFocusIn(FXObject*,FXSelector,void*); 00211 long onFocusOut(FXObject*,FXSelector,void*); 00212 long onClicked(FXObject*,FXSelector,void*); 00213 long onDoubleClicked(FXObject*,FXSelector,void*); 00214 long onTripleClicked(FXObject*,FXSelector,void*); 00215 long onCommand(FXObject*,FXSelector,void*); 00216 long onAutoScroll(FXObject*,FXSelector,void*); 00217 long onLookupTimer(FXObject*,FXSelector,void*); 00218 long onCmdSetValue(FXObject*,FXSelector,void*); 00219 long onCmdGetIntValue(FXObject*,FXSelector,void*); 00220 long onCmdSetIntValue(FXObject*,FXSelector,void*); 00221 public: 00222 static FXint ascending(const FXIconItem* a,const FXIconItem* b); 00223 static FXint descending(const FXIconItem* a,const FXIconItem* b); 00224 static FXint ascendingCase(const FXIconItem* a,const FXIconItem* b); 00225 static FXint descendingCase(const FXIconItem* a,const FXIconItem* b); 00226 public: 00227 enum { 00228 ID_SHOW_DETAILS=FXScrollArea::ID_LAST, 00229 ID_SHOW_MINI_ICONS, 00230 ID_SHOW_BIG_ICONS, 00231 ID_ARRANGE_BY_ROWS, 00232 ID_ARRANGE_BY_COLUMNS, 00233 ID_HEADER_CHANGE, 00234 ID_LOOKUPTIMER, 00235 ID_SELECT_ALL, 00236 ID_DESELECT_ALL, 00237 ID_SELECT_INVERSE, 00238 ID_LAST 00239 }; 00240 public: 00241 00242 /// Construct icon list with no items in it initially 00243 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); 00244 00245 /// Create server-side resources 00246 virtual void create(); 00247 00248 /// Detach server-side resources 00249 virtual void detach(); 00250 00251 /// Recalculate layout 00252 virtual void recalc(); 00253 00254 /// Perform layout 00255 virtual void layout(); 00256 00257 /// Compute and return content width 00258 virtual FXint getContentWidth(); 00259 00260 /// Return content height 00261 virtual FXint getContentHeight(); 00262 00263 /// Icon list can receive focus 00264 virtual FXbool canFocus() const; 00265 00266 /// Move the focus to this window 00267 virtual void setFocus(); 00268 00269 /// Remove the focus from this window 00270 virtual void killFocus(); 00271 00272 /// Return viewport size 00273 virtual FXint getViewportHeight(); 00274 00275 /// Resize this window to the specified width and height 00276 virtual void resize(FXint w,FXint h); 00277 00278 /// Move and resize this window in the parent's coordinates 00279 virtual void position(FXint x,FXint y,FXint w,FXint h); 00280 00281 /// Return number of items 00282 FXint getNumItems() const { return nitems; } 00283 00284 /// Return number of rows 00285 FXint getNumRows() const { return nrows; } 00286 00287 /// Return number of columns 00288 FXint getNumCols() const { return ncols; } 00289 00290 /// Return header control 00291 FXHeader* getHeader() const { return header; } 00292 00293 /// Append header with given text and optional icon 00294 void appendHeader(const FXString& text,FXIcon *icon=NULL,FXint size=1); 00295 00296 /// Remove header at index 00297 void removeHeader(FXint index); 00298 00299 /// Change text of header at index 00300 void setHeaderText(FXint index,const FXString& text); 00301 00302 /// Return text of header at index 00303 FXString getHeaderText(FXint index) const; 00304 00305 /// Change icon of header at index 00306 void setHeaderIcon(FXint index,FXIcon *icon); 00307 00308 /// Return icon of header at index 00309 FXIcon* getHeaderIcon(FXint index) const; 00310 00311 /// Change size of header at index 00312 void setHeaderSize(FXint index,FXint size); 00313 00314 /// Return width of header at index 00315 FXint getHeaderSize(FXint index) const; 00316 00317 /// Return number of headers 00318 FXint getNumHeaders() const; 00319 00320 /// Return the item at the given index 00321 FXIconItem *getItem(FXint index) const; 00322 00323 /// Replace the item with a [possibly subclassed] item 00324 FXint setItem(FXint index,FXIconItem* item,FXbool notify=FALSE); 00325 00326 /// Replace items text, icons, and user-data pointer 00327 FXint setItem(FXint index,const FXString& text,FXIcon *big=NULL,FXIcon* mini=NULL,void* ptr=NULL,FXbool notify=FALSE); 00328 00329 /// Insert a new [possibly subclassed] item at the give index 00330 FXint insertItem(FXint index,FXIconItem* item,FXbool notify=FALSE); 00331 00332 /// Insert item at index with given text, icons, and user-data pointer 00333 FXint insertItem(FXint index,const FXString& text,FXIcon *big=NULL,FXIcon* mini=NULL,void* ptr=NULL,FXbool notify=FALSE); 00334 00335 /// Append a [possibly subclassed] item to the end of the list 00336 FXint appendItem(FXIconItem* item,FXbool notify=FALSE); 00337 00338 /// Append new item with given text and optional icons, and user-data pointer 00339 FXint appendItem(const FXString& text,FXIcon *big=NULL,FXIcon* mini=NULL,void* ptr=NULL,FXbool notify=FALSE); 00340 00341 /// Prepend a [possibly subclassed] item to the end of the list 00342 FXint prependItem(FXIconItem* item,FXbool notify=FALSE); 00343 00344 /// Prepend new item with given text and optional icons, and user-data pointer 00345 FXint prependItem(const FXString& text,FXIcon *big=NULL,FXIcon* mini=NULL,void* ptr=NULL,FXbool notify=FALSE); 00346 00347 /// Move item from oldindex to newindex 00348 FXint moveItem(FXint newindex,FXint oldindex,FXbool notify=FALSE); 00349 00350 /// Remove item from list 00351 void removeItem(FXint index,FXbool notify=FALSE); 00352 00353 /// Remove all items from list 00354 void clearItems(FXbool notify=FALSE); 00355 00356 /// Return item width 00357 FXint getItemWidth() const { return itemWidth; } 00358 00359 /// Return item height 00360 FXint getItemHeight() const { return itemHeight; } 00361 00362 /// Return index of item at x,y, or -1 if none 00363 FXint getItemAt(FXint x,FXint y) const; 00364 00365 /** 00366 * Search items for item by name, starting from start item; the 00367 * flags argument controls the search direction, and case sensitivity. 00368 */ 00369 FXint findItem(const FXString& text,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const; 00370 00371 /// Scroll to make item at index visible 00372 void makeItemVisible(FXint index); 00373 00374 /// Change item text 00375 void setItemText(FXint index,const FXString& text); 00376 00377 /// Return item text 00378 FXString getItemText(FXint index) const; 00379 00380 /// Change item big icon 00381 void setItemBigIcon(FXint index,FXIcon* icon); 00382 00383 /// Return big icon of item at index 00384 FXIcon* getItemBigIcon(FXint index) const; 00385 00386 /// Change item mini icon 00387 void setItemMiniIcon(FXint index,FXIcon* icon); 00388 00389 /// Return mini icon of item at index 00390 FXIcon* getItemMiniIcon(FXint index) const; 00391 00392 /// Change item user-data pointer 00393 void setItemData(FXint index,void* ptr); 00394 00395 /// Return item user-data pointer 00396 void* getItemData(FXint index) const; 00397 00398 /// Return TRUE if item at index is selected 00399 FXbool isItemSelected(FXint index) const; 00400 00401 /// Return TRUE if item at index is current 00402 FXbool isItemCurrent(FXint index) const; 00403 00404 /// Return TRUE if item at index is visible 00405 FXbool isItemVisible(FXint index) const; 00406 00407 /// Return TRUE if item at index is enabled 00408 FXbool isItemEnabled(FXint index) const; 00409 00410 /// Return item hit code: 0 outside, 1 icon, 2 text 00411 FXint hitItem(FXint index,FXint x,FXint y,FXint ww=1,FXint hh=1) const; 00412 00413 /// Repaint item at index 00414 void updateItem(FXint index) const; 00415 00416 /// Enable item at index 00417 FXbool enableItem(FXint index); 00418 00419 /// Disable item at index 00420 FXbool disableItem(FXint index); 00421 00422 /// Select item at index 00423 virtual FXbool selectItem(FXint index,FXbool notify=FALSE); 00424 00425 /// Deselect item at index 00426 virtual FXbool deselectItem(FXint index,FXbool notify=FALSE); 00427 00428 /// Toggle item at index 00429 virtual FXbool toggleItem(FXint index,FXbool notify=FALSE); 00430 00431 /// Select items in rectangle 00432 virtual FXbool selectInRectangle(FXint x,FXint y,FXint w,FXint h,FXbool notify=FALSE); 00433 00434 /// Extend selection from anchor index to index 00435 virtual FXbool extendSelection(FXint index,FXbool notify=FALSE); 00436 00437 /// Deselect all items 00438 virtual FXbool killSelection(FXbool notify=FALSE); 00439 00440 /// Change current item index 00441 virtual void setCurrentItem(FXint index,FXbool notify=FALSE); 00442 00443 /// Return current item index, or -1 if none 00444 FXint getCurrentItem() const { return current; } 00445 00446 /// Change anchor item index 00447 void setAnchorItem(FXint index); 00448 00449 /// Return anchor item index, or -1 if none 00450 FXint getAnchorItem() const { return anchor; } 00451 00452 /// Return index of item under cursor, or -1 if none 00453 FXint getCursorItem() const { return cursor; } 00454 00455 /// Sort items 00456 void sortItems(); 00457 00458 /// Return sort function 00459 FXIconListSortFunc getSortFunc() const { return sortfunc; } 00460 00461 /// Change sort function 00462 void setSortFunc(FXIconListSortFunc func){ sortfunc=func; } 00463 00464 /// Change text font 00465 void setFont(FXFont* fnt); 00466 00467 /// Return text font 00468 FXFont* getFont() const { return font; } 00469 00470 /// Return normal text color 00471 FXColor getTextColor() const { return textColor; } 00472 00473 /// Change normal text color 00474 void setTextColor(FXColor clr); 00475 00476 /// Return selected text background 00477 FXColor getSelBackColor() const { return selbackColor; } 00478 00479 /// Change selected text background 00480 void setSelBackColor(FXColor clr); 00481 00482 /// Return selected text color 00483 FXColor getSelTextColor() const { return seltextColor; } 00484 00485 /// Change selected text color 00486 void setSelTextColor(FXColor clr); 00487 00488 /// Change maximum item space for each item 00489 void setItemSpace(FXint s); 00490 00491 /// Return maximum item space 00492 FXint getItemSpace() const { return itemSpace; } 00493 00494 /// Get the current icon list style 00495 FXuint getListStyle() const; 00496 00497 /// Set the current icon list style. 00498 void setListStyle(FXuint style); 00499 00500 /// Set the status line help text for this widget 00501 void setHelpText(const FXString& text); 00502 00503 /// Get the status line help text for this widget 00504 FXString getHelpText() const { return help; } 00505 00506 /// Save list to a stream 00507 virtual void save(FXStream& store) const; 00508 00509 /// Load list from a stream 00510 virtual void load(FXStream& store); 00511 00512 /// Destructor 00513 virtual ~FXIconList(); 00514 }; 00515 00516 } 00517 00518 #endif

Copyright © 1997-2004 Jeroen van der Zijp