![]() |
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * I c o n L i s t W i d g e t * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1999,2002 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.54 2002/01/18 22:42:53 jeroen Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXICONLIST_H 00025 #define FXICONLIST_H 00026 00027 #ifndef FXSCROLLAREA_H 00028 #include "FXScrollArea.h" 00029 #endif 00030 00031 00032 00033 /// Icon list styles 00034 enum { 00035 ICONLIST_EXTENDEDSELECT = 0, /// Extended selection mode 00036 ICONLIST_SINGLESELECT = 0x00100000, /// At most one selected item 00037 ICONLIST_BROWSESELECT = 0x00200000, /// Always exactly one selected item 00038 ICONLIST_MULTIPLESELECT = 0x00300000, /// Multiple selection mode 00039 ICONLIST_AUTOSIZE = 0x00400000, /// Automatically size item spacing 00040 ICONLIST_DETAILED = 0, /// List mode 00041 ICONLIST_MINI_ICONS = 0x00800000, /// Mini Icon mode 00042 ICONLIST_BIG_ICONS = 0x01000000, /// Big Icon mode 00043 ICONLIST_ROWS = 0, /// Row-wise mode 00044 ICONLIST_COLUMNS = 0x02000000, /// Column-wise mode 00045 ICONLIST_NORMAL = ICONLIST_EXTENDEDSELECT 00046 }; 00047 00048 00049 struct FXTimer; 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 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 /// Icon List Widget 00121 class FXAPI FXIconList : public FXScrollArea { 00122 FXDECLARE(FXIconList) 00123 protected: 00124 FXHeader *header; // Header control 00125 FXIconItem **items; // Item list 00126 FXint nitems; // Number of items 00127 FXint nrows; // Number of rows 00128 FXint ncols; // Number of columns 00129 FXint anchor; // Anchor item 00130 FXint current; // Current item 00131 FXint extent; // Extent item 00132 FXint cursor; // Cursor item 00133 FXFont *font; // Font 00134 FXIconListSortFunc sortfunc; // Item sort function 00135 FXColor textColor; // Text color 00136 FXColor selbackColor; // Selected back color 00137 FXColor seltextColor; // Selected text color 00138 FXint itemWidth; // Item width 00139 FXint itemHeight; // Item height 00140 FXint itemSpace; // Space for item label 00141 FXint anchorx; // Rectangular selection 00142 FXint anchory; 00143 FXint currentx; 00144 FXint currenty; 00145 FXint grabx; // Grab point x 00146 FXint graby; // Grab point y 00147 FXString lookup; // Lookup string 00148 FXTimer *timer; // Tip hover timer 00149 FXTimer *lookuptimer; // Lookup timer 00150 FXString help; // Help text 00151 FXbool state; // State of item 00152 protected: 00153 FXIconList(); 00154 void drawLasso(FXint x0,FXint y0,FXint x1,FXint y1); 00155 virtual void layout(); 00156 void recompute(); 00157 void getrowscols(FXint& nr,FXint& nc,FXint w,FXint h) const; 00158 virtual FXIconItem *createItem(const FXString& text,FXIcon *big,FXIcon* mini,void* ptr); 00159 void lassoChanged(FXint ox,FXint oy,FXint ow,FXint oh,FXint nx,FXint ny,FXint nw,FXint nh,FXbool notify); 00160 private: 00161 FXIconList(const FXIconList&); 00162 FXIconList &operator=(const FXIconList&); 00163 public: 00164 long onPaint(FXObject*,FXSelector,void*); 00165 long onEnter(FXObject*,FXSelector,void*); 00166 long onLeave(FXObject*,FXSelector,void*); 00167 long onUngrabbed(FXObject*,FXSelector,void*); 00168 long onKeyPress(FXObject*,FXSelector,void*); 00169 long onKeyRelease(FXObject*,FXSelector,void*); 00170 long onLeftBtnPress(FXObject*,FXSelector,void*); 00171 long onLeftBtnRelease(FXObject*,FXSelector,void*); 00172 long onRightBtnPress(FXObject*,FXSelector,void*); 00173 long onRightBtnRelease(FXObject*,FXSelector,void*); 00174 long onMotion(FXObject*,FXSelector,void*); 00175 long onQueryTip(FXObject*,FXSelector,void*); 00176 long onQueryHelp(FXObject*,FXSelector,void*); 00177 long onTipTimer(FXObject*,FXSelector,void*); 00178 long onCmdSelectAll(FXObject*,FXSelector,void*); 00179 long onCmdDeselectAll(FXObject*,FXSelector,void*); 00180 long onCmdSelectInverse(FXObject*,FXSelector,void*); 00181 long onCmdArrangeByRows(FXObject*,FXSelector,void*); 00182 long onUpdArrangeByRows(FXObject*,FXSelector,void*); 00183 long onCmdArrangeByColumns(FXObject*,FXSelector,void*); 00184 long onUpdArrangeByColumns(FXObject*,FXSelector,void*); 00185 long onCmdShowDetails(FXObject*,FXSelector,void*); 00186 long onUpdShowDetails(FXObject*,FXSelector,void*); 00187 long onCmdShowBigIcons(FXObject*,FXSelector,void*); 00188 long onUpdShowBigIcons(FXObject*,FXSelector,void*); 00189 long onCmdShowMiniIcons(FXObject*,FXSelector,void*); 00190 long onUpdShowMiniIcons(FXObject*,FXSelector,void*); 00191 long onHeaderChanged(FXObject*,FXSelector,void*); 00192 long onFocusIn(FXObject*,FXSelector,void*); 00193 long onFocusOut(FXObject*,FXSelector,void*); 00194 long onClicked(FXObject*,FXSelector,void*); 00195 long onDoubleClicked(FXObject*,FXSelector,void*); 00196 long onTripleClicked(FXObject*,FXSelector,void*); 00197 long onCommand(FXObject*,FXSelector,void*); 00198 long onAutoScroll(FXObject*,FXSelector,void*); 00199 long onLookupTimer(FXObject*,FXSelector,void*); 00200 long onCmdSetValue(FXObject*,FXSelector,void*);public: 00201 long onCmdGetIntValue(FXObject*,FXSelector,void*); 00202 long onCmdSetIntValue(FXObject*,FXSelector,void*); 00203 public: 00204 static FXint ascending(const FXIconItem* a,const FXIconItem* b); 00205 static FXint descending(const FXIconItem* a,const FXIconItem* b); 00206 public: 00207 enum { 00208 ID_SHOW_DETAILS=FXScrollArea::ID_LAST, 00209 ID_SHOW_MINI_ICONS, 00210 ID_SHOW_BIG_ICONS, 00211 ID_ARRANGE_BY_ROWS, 00212 ID_ARRANGE_BY_COLUMNS, 00213 ID_HEADER_CHANGE, 00214 ID_TIPTIMER, 00215 ID_LOOKUPTIMER, 00216 ID_SELECT_ALL, 00217 ID_DESELECT_ALL, 00218 ID_SELECT_INVERSE, 00219 ID_LAST 00220 }; 00221 public: 00222 /// Construct icon list 00223 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); 00224 00225 /// Create server-side resources 00226 virtual void create(); 00227 00228 /// Detach server-side resources 00229 virtual void detach(); 00230 00231 /// Recalculate layout 00232 virtual void recalc(); 00233 00234 /// Compute and return content width 00235 virtual FXint getContentWidth(); 00236 00237 /// Return content height 00238 virtual FXint getContentHeight(); 00239 00240 /// Icon list can receive focus 00241 virtual FXbool canFocus() const; 00242 00243 /// Move the focus to this window 00244 virtual void setFocus(); 00245 00246 /// Remove the focus from this window 00247 virtual void killFocus(); 00248 00249 /// Return viewport size 00250 virtual FXint getViewportHeight(); 00251 00252 /// Move contents to the specified position 00253 virtual void moveContents(FXint x,FXint y); 00254 00255 /// Resize this window to the specified width and height 00256 virtual void resize(FXint w,FXint h); 00257 00258 /// Move and resize this window in the parent's coordinates 00259 virtual void position(FXint x,FXint y,FXint w,FXint h); 00260 00261 /// Return number of items 00262 FXint getNumItems() const { return nitems; } 00263 00264 /// Return number of rows 00265 FXint getNumRows() const { return nrows; } 00266 00267 /// Return number of columns 00268 FXint getNumCols() const { return ncols; } 00269 00270 /// Return header control 00271 FXHeader* getHeader() const { return header; } 00272 00273 /// Append header with given text and optional icon 00274 void appendHeader(const FXString& text,FXIcon *icon=NULL,FXint size=1); 00275 00276 /// Remove header at index 00277 void removeHeader(FXint index); 00278 00279 /// Change text of header at index 00280 void setHeaderText(FXint index,const FXString& text); 00281 00282 /// Return text of header at index 00283 FXString getHeaderText(FXint index) const; 00284 00285 /// Change icon of header at index 00286 void setHeaderIcon(FXint index,FXIcon *icon); 00287 00288 /// Return icon of header at index 00289 FXIcon* getHeaderIcon(FXint index) const; 00290 00291 /// Change size of header at index 00292 void setHeaderSize(FXint index,FXint size); 00293 00294 /// Return width of header at index 00295 FXint getHeaderSize(FXint index) const; 00296 00297 /// Return number of headers 00298 FXint getNumHeaders() const; 00299 00300 /// Return the item at the given index 00301 FXIconItem *retrieveItem(FXint index) const; 00302 00303 /// Replace the item with a [possibly subclassed] item 00304 FXint replaceItem(FXint index,FXIconItem* item,FXbool notify=FALSE); 00305 00306 /// Replace items text, icons, and user-data pointer 00307 FXint replaceItem(FXint index,const FXString& text,FXIcon *big=NULL,FXIcon* mini=NULL,void* ptr=NULL,FXbool notify=FALSE); 00308 00309 /// Insert a new [possibly subclassed] item at the give index 00310 FXint insertItem(FXint index,FXIconItem* item,FXbool notify=FALSE); 00311 00312 /// Insert item at index with given text, icons, and user-data pointer 00313 FXint insertItem(FXint index,const FXString& text,FXIcon *big=NULL,FXIcon* mini=NULL,void* ptr=NULL,FXbool notify=FALSE); 00314 00315 /// Append a [possibly subclassed] item to the end of the list 00316 FXint appendItem(FXIconItem* item,FXbool notify=FALSE); 00317 00318 /// Append new item with given text and optional icons, and user-data pointer 00319 FXint appendItem(const FXString& text,FXIcon *big=NULL,FXIcon* mini=NULL,void* ptr=NULL,FXbool notify=FALSE); 00320 00321 /// Append a [possibly subclassed] item to the end of the list 00322 FXint prependItem(FXIconItem* item,FXbool notify=FALSE); 00323 00324 /// Append new item with given text and optional icons, and user-data pointer 00325 FXint prependItem(const FXString& text,FXIcon *big=NULL,FXIcon* mini=NULL,void* ptr=NULL,FXbool notify=FALSE); 00326 00327 /// Remove item from list 00328 void removeItem(FXint index,FXbool notify=FALSE); 00329 00330 /// Remove all items from list 00331 void clearItems(FXbool notify=FALSE); 00332 00333 /// Return item width 00334 FXint getItemWidth() const { return itemWidth; } 00335 00336 /// Return item height 00337 FXint getItemHeight() const { return itemHeight; } 00338 00339 /// Return index of item at x,y, or -1 if none 00340 FXint getItemAt(FXint x,FXint y) const; 00341 00342 /** 00343 * Search items for item by name, starting from start item; the 00344 * flags argument controls the search direction, and case sensitivity. 00345 */ 00346 FXint findItem(const FXString& text,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const; 00347 00348 /// Scroll to make item at index visible 00349 void makeItemVisible(FXint index); 00350 00351 /// Change item text 00352 void setItemText(FXint index,const FXString& text); 00353 00354 /// Return item text 00355 FXString getItemText(FXint index) const; 00356 00357 /// Change item big icon 00358 void setItemBigIcon(FXint index,FXIcon* icon); 00359 00360 /// Return big icon of item at index 00361 FXIcon* getItemBigIcon(FXint index) const; 00362 00363 /// Change item mini icon 00364 void setItemMiniIcon(FXint index,FXIcon* icon); 00365 00366 /// Return mini icon of item at index 00367 FXIcon* getItemMiniIcon(FXint index) const; 00368 00369 /// Change item user-data pointer 00370 void setItemData(FXint index,void* ptr); 00371 00372 /// Return item user-data pointer 00373 void* getItemData(FXint index) const; 00374 00375 /// Return TRUE if item at index is selected 00376 FXbool isItemSelected(FXint index) const; 00377 00378 /// Return TRUE if item at index is current 00379 FXbool isItemCurrent(FXint index) const; 00380 00381 /// Return TRUE if item at index is visible 00382 FXbool isItemVisible(FXint index) const; 00383 00384 /// Return TRUE if item at index is enabled 00385 FXbool isItemEnabled(FXint index) const; 00386 00387 /// Return item hit code: 0 outside, 1 icon, 2 text 00388 FXint hitItem(FXint index,FXint x,FXint y,FXint ww=1,FXint hh=1) const; 00389 00390 /// Repaint item at index 00391 void updateItem(FXint index); 00392 00393 /// Select items in rectangle 00394 FXbool selectInRectangle(FXint x,FXint y,FXint w,FXint h,FXbool notify=FALSE); 00395 00396 /// Enable item at index 00397 FXbool enableItem(FXint index); 00398 00399 /// Disable item at index 00400 FXbool disableItem(FXint index); 00401 00402 /// Select item at index 00403 FXbool selectItem(FXint index,FXbool notify=FALSE); 00404 00405 /// Deselect item at index 00406 FXbool deselectItem(FXint index,FXbool notify=FALSE); 00407 00408 /// Toggle item at index 00409 FXbool toggleItem(FXint index,FXbool notify=FALSE); 00410 00411 /// Change current item index 00412 void setCurrentItem(FXint index,FXbool notify=FALSE); 00413 00414 /// Return current item index, or -1 if none 00415 FXint getCurrentItem() const { return current; } 00416 00417 /// Change anchor item index 00418 void setAnchorItem(FXint index); 00419 00420 /// Return anchor item index, or -1 if none 00421 FXint getAnchorItem() const { return anchor; } 00422 00423 /// Return index of item under cursor, or -1 if none 00424 FXint getCursorItem() const { return cursor; } 00425 00426 /// Extend selection from anchor index to index 00427 FXbool extendSelection(FXint index,FXbool notify=FALSE); 00428 00429 /// Deselect all items 00430 FXbool killSelection(FXbool notify=FALSE); 00431 00432 /// Sort items 00433 void sortItems(); 00434 00435 /// Change text font 00436 void setFont(FXFont* fnt); 00437 00438 /// Return text font 00439 FXFont* getFont() const { return font; } 00440 00441 /// Return normal text color 00442 FXColor getTextColor() const { return textColor; } 00443 00444 /// Change normal text color 00445 void setTextColor(FXColor clr); 00446 00447 /// Return selected text background 00448 FXColor getSelBackColor() const { return selbackColor; } 00449 00450 /// Change selected text background 00451 void setSelBackColor(FXColor clr); 00452 00453 /// Return selected text color 00454 FXColor getSelTextColor() const { return seltextColor; } 00455 00456 /// Change selected text color 00457 void setSelTextColor(FXColor clr); 00458 00459 /// Change maximum item space for each item 00460 void setItemSpace(FXint s); 00461 00462 /// Return maximum item space 00463 FXint getItemSpace() const { return itemSpace; } 00464 00465 /// Return sort function 00466 FXIconListSortFunc getSortFunc() const { return sortfunc; } 00467 00468 /// Change sort function 00469 void setSortFunc(FXIconListSortFunc func){ sortfunc=func; } 00470 00471 /// Get the current icon list style 00472 FXuint getListStyle() const; 00473 00474 /// Set the current icon list style. 00475 void setListStyle(FXuint style); 00476 00477 /// Set the status line help text for this widget 00478 void setHelpText(const FXString& text); 00479 00480 /// Get the status line help text for this widget 00481 FXString getHelpText() const { return help; } 00482 00483 /// Save list to a stream 00484 virtual void save(FXStream& store) const; 00485 00486 /// Load list from a stream 00487 virtual void load(FXStream& store); 00488 00489 /// Destructor 00490 virtual ~FXIconList(); 00491 }; 00492 00493 00494 00495 #endif