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