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

FXHeader.h

00001 /******************************************************************************** 00002 * * 00003 * H e a d e r W i d g e t * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1997,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: FXHeader.h,v 1.57 2004/02/08 17:17:33 fox Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXHEADER_H 00025 #define FXHEADER_H 00026 00027 #ifndef FXFRAME_H 00028 #include "FXFrame.h" 00029 #endif 00030 00031 namespace FX { 00032 00033 class FXIcon; 00034 class FXFont; 00035 class FXHeader; 00036 00037 00038 /// Header style options 00039 enum { 00040 HEADER_BUTTON = 0x00008000, /// Button style can be clicked 00041 HEADER_HORIZONTAL = 0, /// Horizontal header control (default) 00042 HEADER_VERTICAL = 0x00010000, /// Vertical header control 00043 HEADER_TRACKING = 0x00020000, /// Tracks continuously while moving 00044 HEADER_NORMAL = HEADER_HORIZONTAL|FRAME_NORMAL 00045 }; 00046 00047 00048 /// Header item 00049 class FXAPI FXHeaderItem : public FXObject { 00050 FXDECLARE(FXHeaderItem) 00051 friend class FXHeader; 00052 protected: 00053 FXString label; // Text of item 00054 FXIcon *icon; // Icon of item 00055 void *data; // Item user data pointer 00056 FXint size; // Item size 00057 FXint pos; // Item position 00058 FXuint state; // Item state flags 00059 protected: 00060 FXHeaderItem(){} 00061 virtual void draw(const FXHeader* header,FXDC& dc,FXint x,FXint y,FXint w,FXint h); 00062 protected: 00063 enum{ 00064 ARROW_NONE = 0, 00065 ARROW_UP = 0x00000001, 00066 ARROW_DOWN = 0x00000002, 00067 PRESSED = 0x00000004 00068 }; 00069 public: 00070 enum{ 00071 RIGHT = 0x00000008, /// Align on right 00072 LEFT = 0x00000010, /// Align on left 00073 CENTER_X = 0, /// Aling centered horizontally (default) 00074 TOP = 0x00000020, /// Align on top 00075 BOTTOM = 0x00000040, /// Align on bottom 00076 CENTER_Y = 0, /// Aling centered vertically (default) 00077 BEFORE = 0x00000080, /// Icon before the text 00078 AFTER = 0x00000100, /// Icon after the text 00079 ABOVE = 0x00000200, /// Icon above the text 00080 BELOW = 0x00000400 /// Icon below the text 00081 }; 00082 public: 00083 00084 /// Construct new item with given text, icon, size, and user-data 00085 FXHeaderItem(const FXString& text,FXIcon* ic=NULL,FXint s=0,void* ptr=NULL):label(text),icon(ic),data(ptr),size(s),pos(0),state(FXHeaderItem::LEFT|FXHeaderItem::BEFORE){} 00086 00087 /// Change item's text label 00088 virtual void setText(const FXString& txt){ label=txt; } 00089 00090 /// Return item's text label 00091 const FXString& getText() const { return label; } 00092 00093 /// Change item's icon 00094 virtual void setIcon(FXIcon* icn){ icon=icn; } 00095 00096 /// Return item's icon 00097 FXIcon* getIcon() const { return icon; } 00098 00099 /// Change item's user data 00100 void setData(void* ptr){ data=ptr; } 00101 00102 /// Get item's user data 00103 void* getData() const { return data; } 00104 00105 /// Change size 00106 void setSize(FXint s){ size=s; } 00107 00108 /// Obtain current size 00109 FXint getSize() const { return size; } 00110 00111 /// Change position 00112 void setPos(FXint p){ pos=p; } 00113 00114 /// Obtain current position 00115 FXint getPos() const { return pos; } 00116 00117 /// Change sort direction (FALSE, TRUE, MAYBE) 00118 void setArrowDir(FXbool dir=MAYBE); 00119 00120 /// Return sort direction (FALSE, TRUE, MAYBE) 00121 FXbool getArrowDir() const; 00122 00123 /// Change content justification 00124 void setJustify(FXuint justify); 00125 00126 /// Return content justification 00127 FXuint getJustify() const { return state&(RIGHT|LEFT|TOP|BOTTOM); } 00128 00129 /// Change icon position 00130 void setIconPosition(FXuint mode); 00131 00132 /// Return icon position 00133 FXuint getIconPosition() const { return state&(BEFORE|AFTER|ABOVE|BELOW); } 00134 00135 /// Change state to pressed 00136 void setPressed(FXbool pressed); 00137 00138 /// Return pressed state 00139 FXbool isPressed() const { return (state&PRESSED)!=0; } 00140 00141 /// Return the item's content width in the header 00142 virtual FXint getWidth(const FXHeader* header) const; 00143 00144 /// Return the item's content height in the header 00145 virtual FXint getHeight(const FXHeader* header) const; 00146 00147 /// Create server-side resources 00148 virtual void create(); 00149 00150 /// Detach from server-side resources 00151 virtual void detach(); 00152 00153 /// Destroy server-side resources 00154 virtual void destroy(); 00155 00156 /// Stream serialization 00157 virtual void save(FXStream& store) const; 00158 virtual void load(FXStream& store); 00159 00160 /// Destructor 00161 virtual ~FXHeaderItem(){} 00162 }; 00163 00164 00165 /** 00166 * Header control may be placed over a table or list to provide a resizable 00167 * captions above a number of columns. 00168 * Each caption comprises a label and an optional icon; in addition, an arrow 00169 * may be shown to indicate whether the items in that column are sorted, and 00170 * if so, whether they are sorted in increasing or decreasing order. 00171 * Each caption can be interactively resized. During the resizing, if the 00172 * HEADER_TRACKING was specified, the header control sends a SEL_CHANGED message 00173 * to its target, with the message data set to the caption number being resized, 00174 * of the type FXint. 00175 * If the HEADER_TRACKING was not specified the SEL_CHANGED message is sent at 00176 * the end of the resizing operation. 00177 * Clicking on a caption causes a message of type SEL_COMMAND to be sent to the 00178 * target, with the message data set to the caption number being clicked. 00179 * A single click on a split causes a message of type SEL_CLICKED to be sent to the 00180 * target; a typical response to this message would be to adjust the size of 00181 * the split to fit the contents displayed underneath it. 00182 * The contents may be scrolled by calling setPosition(). 00183 */ 00184 class FXAPI FXHeader : public FXFrame { 00185 FXDECLARE(FXHeader) 00186 protected: 00187 FXHeaderItem **items; // Item list 00188 FXint nitems; // Number of items 00189 FXColor textColor; // Text color 00190 FXFont *font; // Text font 00191 FXString help; // Help text 00192 FXint pos; // Scroll position 00193 FXint active; // Active button 00194 FXint activepos; // Position of active item 00195 FXint activesize; // Size of active item 00196 FXint offset; // Offset where split grabbed 00197 protected: 00198 FXHeader(); 00199 void drawSplit(FXint pos); 00200 virtual FXHeaderItem *createItem(const FXString& text,FXIcon* icon,FXint size,void* ptr); 00201 private: 00202 FXHeader(const FXHeader&); 00203 FXHeader &operator=(const FXHeader&); 00204 public: 00205 long onPaint(FXObject*,FXSelector,void*); 00206 long onLeftBtnPress(FXObject*,FXSelector,void*); 00207 long onLeftBtnRelease(FXObject*,FXSelector,void*); 00208 long onUngrabbed(FXObject*,FXSelector,void*); 00209 long onMotion(FXObject*,FXSelector,void*); 00210 long onTipTimer(FXObject*,FXSelector,void*); 00211 long onQueryTip(FXObject*,FXSelector,void*); 00212 long onQueryHelp(FXObject*,FXSelector,void*); 00213 public: 00214 00215 /// Construct new header control 00216 FXHeader(FXComposite* p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=HEADER_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0,FXint pl=DEFAULT_PAD,FXint pr=DEFAULT_PAD,FXint pt=DEFAULT_PAD,FXint pb=DEFAULT_PAD); 00217 00218 /// Create server-side resources 00219 virtual void create(); 00220 00221 /// Detach server-side resources 00222 virtual void detach(); 00223 00224 /// Perform layout 00225 virtual void layout(); 00226 00227 /// Return number of items 00228 FXint getNumItems() const { return nitems; } 00229 00230 /// Return total size of all items 00231 FXint getTotalSize() const; 00232 00233 /// Return default width 00234 virtual FXint getDefaultWidth(); 00235 00236 /// Return default height 00237 virtual FXint getDefaultHeight(); 00238 00239 /// Set the current position 00240 void setPosition(FXint p); 00241 00242 /// Return the current position 00243 FXint getPosition() const { return pos; } 00244 00245 /// Return item at given index 00246 FXHeaderItem *getItem(FXint index) const; 00247 00248 /// Replace the item with a [possibly subclassed] item 00249 FXint setItem(FXint index,FXHeaderItem* item,FXbool notify=FALSE); 00250 00251 /** 00252 * Return item-index given coordinate offset, or -1 if coordinate 00253 * is before first item in header, or nitems if coordinate is after 00254 * last item in header. 00255 */ 00256 FXint getItemAt(FXint coord) const; 00257 00258 /// Replace items text, icon, and user-data pointer 00259 FXint setItem(FXint index,const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE); 00260 00261 /// Insert a new [possibly subclassed] item at the give index 00262 FXint insertItem(FXint index,FXHeaderItem* item,FXbool notify=FALSE); 00263 00264 /// Insert item at index with given text, icon, and user-data pointer 00265 FXint insertItem(FXint index,const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE); 00266 00267 /// Append a [possibly subclassed] item to the list 00268 FXint appendItem(FXHeaderItem* item,FXbool notify=FALSE); 00269 00270 /// Append new item with given text and optional icon, and user-data pointer 00271 FXint appendItem(const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE); 00272 00273 /// Prepend a [possibly subclassed] item to the list 00274 FXint prependItem(FXHeaderItem* item,FXbool notify=FALSE); 00275 00276 /// Prepend new item with given text and optional icon, and user-data pointer 00277 FXint prependItem(const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE); 00278 00279 /// Remove item at index 00280 void removeItem(FXint index,FXbool notify=FALSE); 00281 00282 /// Remove all items 00283 void clearItems(FXbool notify=FALSE); 00284 00285 /// Change text label for item at index 00286 void setItemText(FXint index,const FXString& text); 00287 00288 /// Get text of item at index 00289 FXString getItemText(FXint index) const; 00290 00291 /// Change icon of item at index 00292 void setItemIcon(FXint index,FXIcon* icon); 00293 00294 /// Return icon of item at index 00295 FXIcon* getItemIcon(FXint index) const; 00296 00297 /// Change size of item at index 00298 void setItemSize(FXint index,FXint size); 00299 00300 /// Return size of item at index 00301 FXint getItemSize(FXint index) const; 00302 00303 /// Compute offset from the left side of item at index 00304 FXint getItemOffset(FXint index) const; 00305 00306 /// Change data of item at index 00307 void setItemData(FXint index,void* ptr); 00308 00309 /// Return data of item at index 00310 void* getItemData(FXint index) const; 00311 00312 /// Change sort direction (FALSE, TRUE, MAYBE) 00313 void setArrowDir(FXint index,FXbool dir=MAYBE); 00314 00315 /// Return sort direction (FALSE, TRUE, MAYBE) 00316 FXbool getArrowDir(FXint index) const; 00317 00318 /// Change item justification 00319 void setItemJustify(FXint index,FXuint justify); 00320 00321 /// Return item justification 00322 FXuint getItemJustify(FXint index) const; 00323 00324 /// Change relative position of icon and text of item 00325 void setItemIconPosition(FXint index,FXuint mode); 00326 00327 /// Return relative icon and text position 00328 FXuint getItemIconPosition(FXint index) const; 00329 00330 /// Changed button item's pressed state 00331 void setItemPressed(FXint index,FXbool pressed=TRUE); 00332 00333 /// Return TRUE if button item is pressed in 00334 FXbool isItemPressed(FXint index) const; 00335 00336 /// Scroll to make given item visible 00337 void makeItemVisible(FXint index); 00338 00339 /// Repaint header at index 00340 void updateItem(FXint index) const; 00341 00342 /// Change text font 00343 void setFont(FXFont* fnt); 00344 00345 /// return text font 00346 FXFont* getFont() const { return font; } 00347 00348 /// Return text color 00349 FXColor getTextColor() const { return textColor; } 00350 00351 /// Change text color 00352 void setTextColor(FXColor clr); 00353 00354 /// Set header style options 00355 void setHeaderStyle(FXuint style); 00356 00357 /// Get header style options 00358 FXuint getHeaderStyle() const; 00359 00360 /// Set the status line help text for this header 00361 void setHelpText(const FXString& text); 00362 00363 /// Get the status line help text for this header 00364 FXString getHelpText() const { return help; } 00365 00366 /// Save header to a stream 00367 virtual void save(FXStream& store) const; 00368 00369 /// Load header from a stream 00370 virtual void load(FXStream& store); 00371 00372 /// Destructor 00373 virtual ~FXHeader(); 00374 }; 00375 00376 } 00377 00378 #endif

Copyright © 1997-2004 Jeroen van der Zijp