Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
|
00001 /******************************************************************************** 00002 * * 00003 * L i s t W i d g e t * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1997,2006 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: FXList.h,v 1.88 2006/01/22 17:58:05 fox Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXLIST_H 00025 #define FXLIST_H 00026 00027 #ifndef FXSCROLLAREA_H 00028 #include "FXScrollArea.h" 00029 #endif 00030 00031 namespace FX { 00032 00033 00034 /// List styles 00035 enum { 00036 LIST_EXTENDEDSELECT = 0, /// Extended selection mode allows for drag-selection of ranges of items 00037 LIST_SINGLESELECT = 0x00100000, /// Single selection mode allows up to one item to be selected 00038 LIST_BROWSESELECT = 0x00200000, /// Browse selection mode enforces one single item to be selected at all times 00039 LIST_MULTIPLESELECT = 0x00300000, /// Multiple selection mode is used for selection of individual items 00040 LIST_AUTOSELECT = 0x00400000, /// Automatically select under cursor 00041 LIST_NORMAL = LIST_EXTENDEDSELECT 00042 }; 00043 00044 00045 class FXIcon; 00046 class FXFont; 00047 class FXList; 00048 00049 00050 /// List item 00051 class FXAPI FXListItem : public FXObject { 00052 FXDECLARE(FXListItem) 00053 friend class FXList; 00054 protected: 00055 FXString label; 00056 FXIcon *icon; 00057 void *data; 00058 FXuint state; 00059 FXint x,y; 00060 private: 00061 FXListItem(const FXListItem&); 00062 FXListItem& operator=(const FXListItem&); 00063 protected: 00064 FXListItem():icon(NULL),data(NULL),state(0),x(0),y(0){} 00065 virtual void draw(const FXList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h); 00066 virtual FXint hitItem(const FXList* list,FXint x,FXint y) const; 00067 public: 00068 enum { 00069 SELECTED = 1, /// Selected 00070 FOCUS = 2, /// Focus 00071 DISABLED = 4, /// Disabled 00072 DRAGGABLE = 8, /// Draggable 00073 ICONOWNED = 16 /// Icon owned by item 00074 }; 00075 public: 00076 00077 /// Construct new item with given text, icon, and user-data 00078 FXListItem(const FXString& text,FXIcon* ic=NULL,void* ptr=NULL):label(text),icon(ic),data(ptr),state(0),x(0),y(0){} 00079 00080 /// Change item's text label 00081 virtual void setText(const FXString& txt); 00082 00083 /// Return item's text label 00084 const FXString& getText() const { return label; } 00085 00086 /// Change item's icon, deleting the old icon if it was owned 00087 virtual void setIcon(FXIcon* icn,FXbool owned=FALSE); 00088 00089 /// Return item's icon 00090 FXIcon* getIcon() const { return icon; } 00091 00092 /// Change item's user data 00093 void setData(void* ptr){ data=ptr; } 00094 00095 /// Get item's user data 00096 void* getData() const { return data; } 00097 00098 /// Make item draw as focused 00099 virtual void setFocus(FXbool focus); 00100 00101 /// Return true if item has focus 00102 FXbool hasFocus() const { return (state&FOCUS)!=0; } 00103 00104 /// Select item 00105 virtual void setSelected(FXbool selected); 00106 00107 /// Return true if this item is selected 00108 FXbool isSelected() const { return (state&SELECTED)!=0; } 00109 00110 /// Enable or disable item 00111 virtual void setEnabled(FXbool enabled); 00112 00113 /// Return true if this item is enabled 00114 FXbool isEnabled() const { return (state&DISABLED)==0; } 00115 00116 /// Make item draggable 00117 virtual void setDraggable(FXbool draggable); 00118 00119 /// Return true if this item is draggable 00120 FXbool isDraggable() const { return (state&DRAGGABLE)!=0; } 00121 00122 /// Return width of item as drawn in list 00123 virtual FXint getWidth(const FXList* list) const; 00124 00125 /// Return height of item as drawn in list 00126 virtual FXint getHeight(const FXList* list) const; 00127 00128 /// Create server-side resources 00129 virtual void create(); 00130 00131 /// Detach server-side resources 00132 virtual void detach(); 00133 00134 /// Destroy server-side resources 00135 virtual void destroy(); 00136 00137 /// Save to stream 00138 virtual void save(FXStream& store) const; 00139 00140 /// Load from stream 00141 virtual void load(FXStream& store); 00142 00143 /// Destroy item and free icons if owned 00144 virtual ~FXListItem(); 00145 }; 00146 00147 00148 /// List item collate function 00149 typedef FXint (*FXListSortFunc)(const FXListItem*,const FXListItem*); 00150 00151 00152 typedef FXObjectListOf<FXListItem> FXListItemList; 00153 00154 00155 /** 00156 * A List Widget displays a list of items, each with a text and 00157 * optional icon. When an item's selected state changes, the list sends 00158 * a SEL_SELECTED or SEL_DESELECTED message. A change of the current 00159 * item is signified by the SEL_CHANGED message. 00160 * The list sends SEL_COMMAND messages when the user clicks on an item, 00161 * and SEL_CLICKED, SEL_DOUBLECLICKED, and SEL_TRIPLECLICKED when the user 00162 * clicks once, twice, or thrice, respectively. 00163 * When items are added, replaced, or removed, the list sends messages of 00164 * the type SEL_INSERTED, SEL_REPLACED, or SEL_DELETED. 00165 * In each of these cases, the index to the item, if any, is passed in the 00166 * 3rd argument of the message. 00167 */ 00168 class FXAPI FXList : public FXScrollArea { 00169 FXDECLARE(FXList) 00170 protected: 00171 FXListItemList items; // Item list 00172 FXint anchor; // Anchor item 00173 FXint current; // Current item 00174 FXint extent; // Extent item 00175 FXint cursor; // Cursor item 00176 FXint viewable; // Viewable item 00177 FXFont *font; // Font 00178 FXColor textColor; // Text color 00179 FXColor selbackColor; // Selected back color 00180 FXColor seltextColor; // Selected text color 00181 FXint listWidth; // List width 00182 FXint listHeight; // List height 00183 FXint visible; // Number of rows high 00184 FXString help; // Help text 00185 FXListSortFunc sortfunc; // Item sort function 00186 FXint grabx; // Grab point x 00187 FXint graby; // Grab point y 00188 FXString lookup; // Lookup string 00189 FXbool state; // State of item 00190 protected: 00191 FXList(); 00192 void recompute(); 00193 virtual FXListItem *createItem(const FXString& text,FXIcon* icon,void* ptr); 00194 private: 00195 FXList(const FXList&); 00196 FXList &operator=(const FXList&); 00197 public: 00198 long onPaint(FXObject*,FXSelector,void*); 00199 long onEnter(FXObject*,FXSelector,void*); 00200 long onLeave(FXObject*,FXSelector,void*); 00201 long onUngrabbed(FXObject*,FXSelector,void*); 00202 long onKeyPress(FXObject*,FXSelector,void*); 00203 long onKeyRelease(FXObject*,FXSelector,void*); 00204 long onLeftBtnPress(FXObject*,FXSelector,void*); 00205 long onLeftBtnRelease(FXObject*,FXSelector,void*); 00206 long onRightBtnPress(FXObject*,FXSelector,void*); 00207 long onRightBtnRelease(FXObject*,FXSelector,void*); 00208 long onMotion(FXObject*,FXSelector,void*); 00209 long onFocusIn(FXObject*,FXSelector,void*); 00210 long onFocusOut(FXObject*,FXSelector,void*); 00211 long onAutoScroll(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 onQueryTip(FXObject*,FXSelector,void*); 00217 long onQueryHelp(FXObject*,FXSelector,void*); 00218 long onTipTimer(FXObject*,FXSelector,void*); 00219 long onLookupTimer(FXObject*,FXSelector,void*); 00220 long onCmdSetValue(FXObject*,FXSelector,void*);public: 00221 long onCmdGetIntValue(FXObject*,FXSelector,void*); 00222 long onCmdSetIntValue(FXObject*,FXSelector,void*); 00223 public: 00224 static FXint ascending(const FXListItem* a,const FXListItem* b); 00225 static FXint descending(const FXListItem* a,const FXListItem* b); 00226 static FXint ascendingCase(const FXListItem* a,const FXListItem* b); 00227 static FXint descendingCase(const FXListItem* a,const FXListItem* b); 00228 public: 00229 enum { 00230 ID_LOOKUPTIMER=FXScrollArea::ID_LAST, 00231 ID_LAST 00232 }; 00233 public: 00234 00235 /// Construct a list with initially no items in it 00236 FXList(FXComposite *p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=LIST_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0); 00237 00238 /// Create server-side resources 00239 virtual void create(); 00240 00241 /// Detach server-side resources 00242 virtual void detach(); 00243 00244 /// Perform layout 00245 virtual void layout(); 00246 00247 /// Return default width 00248 virtual FXint getDefaultWidth(); 00249 00250 /// Return default height 00251 virtual FXint getDefaultHeight(); 00252 00253 /// Compute and return content width 00254 virtual FXint getContentWidth(); 00255 00256 /// Return content height 00257 virtual FXint getContentHeight(); 00258 00259 /// Recalculate layout 00260 virtual void recalc(); 00261 00262 /// List widget can receive focus 00263 virtual bool canFocus() const; 00264 00265 /// Move the focus to this window 00266 virtual void setFocus(); 00267 00268 /// Remove the focus from this window 00269 virtual void killFocus(); 00270 00271 /// Return the number of items in the list 00272 FXint getNumItems() const { return items.no(); } 00273 00274 /// Return number of visible items 00275 FXint getNumVisible() const { return visible; } 00276 00277 /// Change the number of visible items 00278 void setNumVisible(FXint nvis); 00279 00280 /// Return the item at the given index 00281 FXListItem *getItem(FXint index) const; 00282 00283 /// Replace the item with a [possibly subclassed] item 00284 FXint setItem(FXint index,FXListItem* item,FXbool notify=FALSE); 00285 00286 /// Replace items text, icon, and user-data pointer 00287 FXint setItem(FXint index,const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE); 00288 00289 /// Fill list by appending items from array of strings 00290 FXint fillItems(const FXchar** strings,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE); 00291 00292 /// Fill list by appending items from newline separated strings 00293 FXint fillItems(const FXString& strings,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE); 00294 00295 /// Insert a new [possibly subclassed] item at the give index 00296 FXint insertItem(FXint index,FXListItem* item,FXbool notify=FALSE); 00297 00298 /// Insert item at index with given text, icon, and user-data pointer 00299 FXint insertItem(FXint index,const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE); 00300 00301 /// Append a [possibly subclassed] item to the list 00302 FXint appendItem(FXListItem* item,FXbool notify=FALSE); 00303 00304 /// Append new item with given text and optional icon, and user-data pointer 00305 FXint appendItem(const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE); 00306 00307 /// Prepend a [possibly subclassed] item to the list 00308 FXint prependItem(FXListItem* item,FXbool notify=FALSE); 00309 00310 /// Prepend new item with given text and optional icon, and user-data pointer 00311 FXint prependItem(const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE); 00312 00313 /// Move item from oldindex to newindex 00314 FXint moveItem(FXint newindex,FXint oldindex,FXbool notify=FALSE); 00315 00316 /// Extract item from list 00317 FXListItem* extractItem(FXint index,FXbool notify=FALSE); 00318 00319 /// Remove item from list 00320 void removeItem(FXint index,FXbool notify=FALSE); 00321 00322 /// Remove all items from list 00323 void clearItems(FXbool notify=FALSE); 00324 00325 /// Return item width 00326 FXint getItemWidth(FXint index) const; 00327 00328 /// Return item height 00329 FXint getItemHeight(FXint index) const; 00330 00331 /// Return index of item at x,y, if any 00332 virtual FXint getItemAt(FXint x,FXint y) const; 00333 00334 /// Return item hit code: 0 no hit; 1 hit the icon; 2 hit the text 00335 FXint hitItem(FXint index,FXint x,FXint y) const; 00336 00337 /** 00338 * Search items by name, beginning from item start. If the start 00339 * item is -1 the search will start at the first item in the list. 00340 * Flags may be SEARCH_FORWARD or SEARCH_BACKWARD to control the 00341 * search direction; this can be combined with SEARCH_NOWRAP or SEARCH_WRAP 00342 * to control whether the search wraps at the start or end of the list. 00343 * The option SEARCH_IGNORECASE causes a case-insensitive match. Finally, 00344 * passing SEARCH_PREFIX causes searching for a prefix of the item name. 00345 * Return -1 if no matching item is found. 00346 */ 00347 FXint findItem(const FXString& text,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const; 00348 00349 /** 00350 * Search items by associated user data, beginning from item start. If the 00351 * start item is -1 the search will start at the first item in the list. 00352 * Flags may be SEARCH_FORWARD or SEARCH_BACKWARD to control the 00353 * search direction; this can be combined with SEARCH_NOWRAP or SEARCH_WRAP 00354 * to control whether the search wraps at the start or end of the list. 00355 */ 00356 FXint findItemByData(const void *ptr,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const; 00357 00358 /// Scroll to bring item into view 00359 virtual void makeItemVisible(FXint index); 00360 00361 /// Change item text 00362 void setItemText(FXint index,const FXString& text); 00363 00364 /// Return item text 00365 FXString getItemText(FXint index) const; 00366 00367 /// Change item icon, deleting the old icon if it was owned 00368 void setItemIcon(FXint index,FXIcon* icon,FXbool owned=FALSE); 00369 00370 /// Return item icon, if any 00371 FXIcon* getItemIcon(FXint index) const; 00372 00373 /// Change item user-data pointer 00374 void setItemData(FXint index,void* ptr); 00375 00376 /// Return item user-data pointer 00377 void* getItemData(FXint index) const; 00378 00379 /// Return TRUE if item is selected 00380 FXbool isItemSelected(FXint index) const; 00381 00382 /// Return TRUE if item is current 00383 FXbool isItemCurrent(FXint index) const; 00384 00385 /// Return TRUE if item is visible 00386 FXbool isItemVisible(FXint index) const; 00387 00388 /// Return TRUE if item is enabled 00389 FXbool isItemEnabled(FXint index) const; 00390 00391 /// Repaint item 00392 void updateItem(FXint index) const; 00393 00394 /// Enable item 00395 virtual FXbool enableItem(FXint index); 00396 00397 /// Disable item 00398 virtual FXbool disableItem(FXint index); 00399 00400 /// Select item 00401 virtual FXbool selectItem(FXint index,FXbool notify=FALSE); 00402 00403 /// Deselect item 00404 virtual FXbool deselectItem(FXint index,FXbool notify=FALSE); 00405 00406 /// Toggle item selection state 00407 virtual FXbool toggleItem(FXint index,FXbool notify=FALSE); 00408 00409 /// Extend selection from anchor item to index 00410 virtual FXbool extendSelection(FXint index,FXbool notify=FALSE); 00411 00412 /// Deselect all items 00413 virtual FXbool killSelection(FXbool notify=FALSE); 00414 00415 /// Change current item 00416 virtual void setCurrentItem(FXint index,FXbool notify=FALSE); 00417 00418 /// Return current item, if any 00419 FXint getCurrentItem() const { return current; } 00420 00421 /// Change anchor item 00422 void setAnchorItem(FXint index); 00423 00424 /// Return anchor item, if any 00425 FXint getAnchorItem() const { return anchor; } 00426 00427 /// Get item under the cursor, if any 00428 FXint getCursorItem() const { return cursor; } 00429 00430 /// Sort items using current sort function 00431 void sortItems(); 00432 00433 /// Return sort function 00434 FXListSortFunc getSortFunc() const { return sortfunc; } 00435 00436 /// Change sort function 00437 void setSortFunc(FXListSortFunc func){ sortfunc=func; } 00438 00439 /// Change text font 00440 void setFont(FXFont* fnt); 00441 00442 /// Return text font 00443 FXFont* getFont() const { return font; } 00444 00445 /// Return normal text color 00446 FXColor getTextColor() const { return textColor; } 00447 00448 /// Change normal text color 00449 void setTextColor(FXColor clr); 00450 00451 /// Return selected text background 00452 FXColor getSelBackColor() const { return selbackColor; } 00453 00454 /// Change selected text background 00455 void setSelBackColor(FXColor clr); 00456 00457 /// Return selected text color 00458 FXColor getSelTextColor() const { return seltextColor; } 00459 00460 /// Change selected text color 00461 void setSelTextColor(FXColor clr); 00462 00463 /// Return list style 00464 FXuint getListStyle() const; 00465 00466 /// Change list style 00467 void setListStyle(FXuint style); 00468 00469 /// Set the status line help text for this list 00470 void setHelpText(const FXString& text); 00471 00472 /// Get the status line help text for this list 00473 const FXString& getHelpText() const { return help; } 00474 00475 /// Save list to a stream 00476 virtual void save(FXStream& store) const; 00477 00478 /// Load list from a stream 00479 virtual void load(FXStream& store); 00480 00481 /// Destructor 00482 virtual ~FXList(); 00483 }; 00484 00485 } 00486 00487 #endif
Copyright © 1997-2005 Jeroen van der Zijp |