![]() |
Main Page
Class Hierarchy
Alphabetical List
Compound List
File List
Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * C h e c k L i s t W i d g e t * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1997,2001 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: FXCheckList.h,v 1.45 2001/11/06 06:46:14 jeroen Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXCHECKLIST_H 00025 #define FXCHECKLIST_H 00026 00027 #ifndef FXSCROLLAREA_H 00028 #include <fox/FXScrollArea.h> 00029 using namespace FX; 00030 #endif 00031 namespace FXEX { 00032 00033 /// CheckList styles 00034 enum { 00035 CHECKLIST_EXTENDEDSELECT= 0, /// Extended selection mode allows for drag-selection of ranges of items 00036 CHECKLIST_SINGLESELECT = 0x00100000, /// Single selection mode allows up to one item to be selected 00037 CHECKLIST_BROWSESELECT = 0x00200000, /// Browse selection mode enforces one single item to be selected at all times 00038 CHECKLIST_MULTIPLESELECT= 0x00300000, /// Multiple selection mode is used for selection of individual items 00039 CHECKLIST_AUTOSELECT = 0x00400000, /// Automatically select under cursor 00040 CHECKLIST_NORMAL = CHECKLIST_EXTENDEDSELECT 00041 }; 00042 00043 00044 /// List item 00045 class FXAPI FXCheckListItem : public FXObject { 00046 FXDECLARE(FXCheckListItem) 00047 friend class FXCheckList; 00048 00049 protected: 00050 FXString label; 00051 FXIcon *icon; 00052 void *data; 00053 FXuint state; 00054 00055 protected: 00056 00057 /// serialisation 00058 FXCheckListItem():icon(NULL),data(NULL),state(0){} 00059 00060 /// handle drawing... 00061 virtual void draw(const FXCheckList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h); 00062 00063 /// draw focus 00064 void drawFocus(const FXCheckList* list,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const; 00065 00066 /// hanlde hit 00067 virtual FXint hitItem(const FXCheckList* list,FXint x,FXint y) const; 00068 00069 protected: 00070 /// states 00071 enum { 00072 SELECTED = 1, 00073 FOCUS = 2, 00074 DISABLED = 4, 00075 DRAGGABLE = 8, 00076 ICONOWNED = 16, 00077 CHECKED = 32 00078 }; 00079 00080 public: 00081 /// Check list item 00082 FXCheckListItem(const FXString& text,FXIcon* ic=NULL,void* ptr=NULL):label(text),icon(ic),data(ptr),state(0){} 00083 00084 /// set text to new label 00085 virtual void setText(const FXString& txt){ label=txt; } 00086 00087 /// get label text 00088 FXString getText() const { return label; } 00089 00090 /// set to new icon 00091 virtual void setIcon(FXIcon* icn){ icon=icn; } 00092 00093 /// get current icon 00094 FXIcon* getIcon() const { return icon; } 00095 00096 /// set data member 00097 void setData(void* ptr){ data=ptr; } 00098 00099 /// get data member 00100 void* getData() const { return data; } 00101 00102 /// focus control 00103 virtual void setFocus(FXbool focus); 00104 00105 /// has current focus 00106 FXbool hasFocus() const { return (state&FOCUS)!=0; } 00107 00108 /// make item selected 00109 virtual void setSelected(FXbool selected); 00110 00111 /// is item selected 00112 FXbool isSelected() const { return (state&SELECTED)!=0; } 00113 00114 /// make item checked 00115 virtual void setChecked(FXbool checked); 00116 00117 /// is item checked 00118 FXbool isChecked() const { return (state&CHECKED)!=0; } 00119 00120 /// make item enabled 00121 virtual void setEnabled(FXbool enabled); 00122 00123 /// is item enabled 00124 FXbool isEnabled() const { return (state&DISABLED)==0; } 00125 00126 /// make item draggable 00127 virtual void setDraggable(FXbool draggable); 00128 00129 /// is item draggable 00130 FXbool isDraggable() const { return (state&DRAGGABLE)!=0; } 00131 00132 /// set icon owned 00133 virtual void setIconOwned(FXuint owned=ICONOWNED); 00134 00135 /// is icon owned 00136 FXuint isIconOwned() const { return (state&ICONOWNED); } 00137 00138 /// get width of item 00139 virtual FXint getWidth(const FXCheckList* list) const; 00140 00141 /// get height of item 00142 virtual FXint getHeight(const FXCheckList* list) const; 00143 00144 /// create resources 00145 virtual void create(); 00146 00147 /// detach resources 00148 virtual void detach(); 00149 00150 /// destroy resources 00151 virtual void destroy(); 00152 00153 /// save to stream 00154 virtual void save(FXStream& store) const; 00155 00156 /// load from stream 00157 virtual void load(FXStream& store); 00158 00159 /// dtor 00160 virtual ~FXCheckListItem(); 00161 }; 00162 00163 00164 /// List item collate function 00165 typedef FXint (*FXCheckListSortFunc)(const FXCheckListItem*,const FXCheckListItem*); 00166 00167 00168 /// List Widget 00169 class FXAPI FXCheckList : public FXScrollArea { 00170 FXDECLARE(FXCheckList) 00171 00172 protected: 00173 FXCheckListItem **items; // Item list 00174 FXint nitems; // Number of items 00175 FXint anchor; // Anchor item 00176 FXint current; // Current item 00177 FXint extent; // Extent item 00178 FXint cursor; // Cursor item 00179 FXFont *font; // Font 00180 FXColor textColor; // Text color 00181 FXColor selbackColor; // Selected back color 00182 FXColor seltextColor; // Selected text color 00183 FXint itemWidth; // Item width 00184 FXint itemHeight; // Item height 00185 FXint visible; // Number of rows high 00186 FXString help; // Help text 00187 FXCheckListSortFunc sortfunc; // Item sort function 00188 FXint grabx; // Grab point x 00189 FXint graby; // Grab point y 00190 FXString lookup; // Lookup string 00191 FXbool state; // State of item 00192 00193 protected: 00194 FXCheckList(); 00195 virtual void layout(); 00196 void recompute(); 00197 virtual FXCheckListItem *createItem(const FXString& text,FXIcon* icon,void* ptr); 00198 00199 private: 00200 FXCheckList(const FXCheckList&); 00201 FXCheckList &operator=(const FXCheckList&); 00202 00203 public: 00204 long onPaint(FXObject*,FXSelector,void*); 00205 long onEnter(FXObject*,FXSelector,void*); 00206 long onLeave(FXObject*,FXSelector,void*); 00207 long onUngrabbed(FXObject*,FXSelector,void*); 00208 long onKeyPress(FXObject*,FXSelector,void*); 00209 long onKeyRelease(FXObject*,FXSelector,void*); 00210 long onLeftBtnPress(FXObject*,FXSelector,void*); 00211 long onLeftBtnRelease(FXObject*,FXSelector,void*); 00212 long onRightBtnPress(FXObject*,FXSelector,void*); 00213 long onRightBtnRelease(FXObject*,FXSelector,void*); 00214 long onMotion(FXObject*,FXSelector,void*); 00215 long onFocusIn(FXObject*,FXSelector,void*); 00216 long onFocusOut(FXObject*,FXSelector,void*); 00217 long onAutoScroll(FXObject*,FXSelector,void*); 00218 long onClicked(FXObject*,FXSelector,void*); 00219 long onDoubleClicked(FXObject*,FXSelector,void*); 00220 long onTripleClicked(FXObject*,FXSelector,void*); 00221 long onCommand(FXObject*,FXSelector,void*); 00222 long onQueryTip(FXObject*,FXSelector,void*); 00223 long onQueryHelp(FXObject*,FXSelector,void*); 00224 long onTipTimer(FXObject*,FXSelector,void*); 00225 long onLookupTimer(FXObject*,FXSelector,void*); 00226 long onCmdSetValue(FXObject*,FXSelector,void*);public: 00227 long onCmdGetIntValue(FXObject*,FXSelector,void*); 00228 long onCmdSetIntValue(FXObject*,FXSelector,void*); 00229 00230 public: 00231 static FXint ascending(const FXCheckListItem* a,const FXCheckListItem* b); 00232 static FXint descending(const FXCheckListItem* a,const FXCheckListItem* b); 00233 00234 public: 00235 enum { 00236 ID_TIPTIMER=FXScrollArea::ID_LAST, 00237 ID_LOOKUPTIMER, 00238 ID_LAST 00239 }; 00240 00241 public: 00242 /// Construct a list with nvis visible items; the list is initially empty 00243 FXCheckList(FXComposite *p,FXint nvis,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=CHECKLIST_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 /// Return default width 00252 virtual FXint getDefaultWidth(); 00253 00254 /// Return default height 00255 virtual FXint getDefaultHeight(); 00256 00257 /// Compute and return content width 00258 virtual FXint getContentWidth(); 00259 00260 /// Return content height 00261 virtual FXint getContentHeight(); 00262 00263 /// Recalculate layout 00264 virtual void recalc(); 00265 00266 /// List widget can receive focus 00267 virtual FXbool canFocus() const; 00268 00269 /// Return the number of items in the list 00270 FXint getNumItems() const { return nitems; } 00271 00272 /// Return number of visible items 00273 FXint getNumVisible() const { return visible; } 00274 00275 /// Change the number of visible items 00276 void setNumVisible(FXint nvis); 00277 00278 /// Return the item at the given index 00279 FXCheckListItem *retrieveItem(FXint index) const; 00280 00281 /// Replace the item with a [possibly subclassed] item 00282 FXint replaceItem(FXint index,FXCheckListItem* item,FXbool notify=FALSE); 00283 00284 /// Replace items text, icon, and user-data pointer 00285 FXint replaceItem(FXint index,const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE); 00286 00287 /// Insert a new [possibly subclassed] item at the give index 00288 FXint insertItem(FXint index,FXCheckListItem* item,FXbool notify=FALSE); 00289 00290 /// Insert item at index with given text, icon, and user-data pointer 00291 FXint insertItem(FXint index,const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE); 00292 00293 /// Append a [possibly subclassed] item to the list 00294 FXint appendItem(FXCheckListItem* item,FXbool notify=FALSE); 00295 00296 /// Append new item with given text and optional icon, and user-data pointer 00297 FXint appendItem(const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE); 00298 00299 /// Prepend a [possibly subclassed] item to the list 00300 FXint prependItem(FXCheckListItem* item,FXbool notify=FALSE); 00301 00302 /// Prepend new item with given text and optional icon, and user-data pointer 00303 FXint prependItem(const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE); 00304 00305 /// Remove item from list 00306 void removeItem(FXint index,FXbool notify=FALSE); 00307 00308 /// Remove all items from list 00309 void clearItems(FXbool notify=FALSE); 00310 00311 /// Return item width 00312 FXint getItemWidth() const { return itemWidth; } 00313 00314 /// Return item height 00315 FXint getItemHeight() const { return itemHeight; } 00316 00317 /// Return index of item at x,y, if any 00318 FXint getItemAt(FXint x,FXint y) const; 00319 00320 /// Return item hit code: 0 no hit; 1 hit the icon; 2 hit the text 00321 /// 3 hit the check 00322 FXint hitItem(FXint index,FXint x,FXint y) const; 00323 00324 /** 00325 * Search items for item by name, starting from start item; the 00326 * flags argument controls the search direction, and case sensitivity. 00327 */ 00328 FXint findItem(const FXString& text,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const; 00329 00330 /// Scroll to bring item into view 00331 void makeItemVisible(FXint index); 00332 00333 /// Change item text 00334 void setItemText(FXint index,const FXString& text); 00335 00336 /// Return item text 00337 FXString getItemText(FXint index) const; 00338 00339 /// Change item icon 00340 void setItemIcon(FXint index,FXIcon* icon); 00341 00342 /// Return item icon, if any 00343 FXIcon* getItemIcon(FXint index) const; 00344 00345 /// Change item user-data pointer 00346 void setItemData(FXint index,void* ptr); 00347 00348 /// Return item user-data pointer 00349 void* getItemData(FXint index) const; 00350 00351 /// Return TRUE if item is selected 00352 FXbool isItemSelected(FXint index) const; 00353 00354 /// Return TRUE if item is checked 00355 FXbool isItemChecked(FXint index) const; 00356 00357 /// Return TRUE if item is current 00358 FXbool isItemCurrent(FXint index) const; 00359 00360 /// Return TRUE if item is visible 00361 FXbool isItemVisible(FXint index) const; 00362 00363 /// Return TRUE if item is enabled 00364 FXbool isItemEnabled(FXint index) const; 00365 00366 /// Repaint item 00367 void updateItem(FXint index); 00368 00369 /// Enable item 00370 FXbool enableItem(FXint index); 00371 00372 /// Disable item 00373 FXbool disableItem(FXint index); 00374 00375 /// Select item 00376 FXbool selectItem(FXint index,FXbool notify=FALSE); 00377 00378 /// Deselect item 00379 FXbool deselectItem(FXint index,FXbool notify=FALSE); 00380 00381 /// Toggle item selection state 00382 FXbool toggleItem(FXint index,FXbool notify=FALSE); 00383 00384 /// check item 00385 FXbool checkItem(FXint index,FXbool notify=FALSE); 00386 00387 /// uncheck item 00388 FXbool uncheckItem(FXint index,FXbool notify=FALSE); 00389 00390 /// Toggle item check state 00391 FXbool toggleCheckItem(FXint index,FXbool notify=FALSE); 00392 00393 /// Change current item 00394 void setCurrentItem(FXint index,FXbool notify=FALSE); 00395 00396 /// Return current item, if any 00397 FXint getCurrentItem() const { return current; } 00398 00399 /// Change anchor item 00400 void setAnchorItem(FXint index); 00401 00402 /// Return anchor item, if any 00403 FXint getAnchorItem() const { return anchor; } 00404 00405 /// Get item under the cursor, if any 00406 FXint getCursorItem() const { return cursor; } 00407 00408 /// Extend selection from anchor item to index 00409 FXbool extendSelection(FXint index,FXbool notify=FALSE); 00410 00411 /// Deselect all items 00412 FXbool killSelection(FXbool notify=FALSE); 00413 00414 /// Sort items using current sort function 00415 void sortItems(); 00416 00417 /// Change text font 00418 void setFont(FXFont* fnt); 00419 00420 /// Return text font 00421 FXFont* getFont() const { return font; } 00422 00423 /// Return normal text color 00424 FXColor getTextColor() const { return textColor; } 00425 00426 /// Change normal text color 00427 void setTextColor(FXColor clr); 00428 00429 /// Return selected text background 00430 FXColor getSelBackColor() const { return selbackColor; } 00431 00432 /// Change selected text background 00433 void setSelBackColor(FXColor clr); 00434 00435 /// Return selected text color 00436 FXColor getSelTextColor() const { return seltextColor; } 00437 00438 /// Change selected text color 00439 void setSelTextColor(FXColor clr); 00440 00441 /// Return sort function 00442 FXCheckListSortFunc getSortFunc() const { return sortfunc; } 00443 00444 /// Change sort function 00445 void setSortFunc(FXCheckListSortFunc func){ sortfunc=func; } 00446 00447 /// Return list style 00448 FXuint getListStyle() const; 00449 00450 /// Change list style 00451 void setListStyle(FXuint style); 00452 00453 /// Set the status line help text for this list 00454 void setHelpText(const FXString& text); 00455 00456 /// Get the status line help text for this list 00457 FXString getHelpText() const { return help; } 00458 00459 /// Save list to a stream 00460 virtual void save(FXStream& store) const; 00461 00462 /// Load list from a stream 00463 virtual void load(FXStream& store); 00464 00465 /// Destructor 00466 virtual ~FXCheckList(); 00467 }; 00468 00469 } // namespace FXEX 00470 #endif // FXCHECKLIST_H