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

FXList.h

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

Copyright © 1997-2005 Jeroen van der Zijp