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,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: FXHeader.h,v 1.65 2005/02/06 17:20:00 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 public: 00063 enum{ 00064 ARROW_NONE = 0, /// No arrow 00065 ARROW_UP = 1, /// Arrow pointing up 00066 ARROW_DOWN = 2, /// Arrow pointing down 00067 PRESSED = 4, /// Pressed down 00068 RIGHT = 8, /// Align on right 00069 LEFT = 16, /// Align on left 00070 CENTER_X = 0, /// Aling centered horizontally (default) 00071 TOP = 32, /// Align on top 00072 BOTTOM = 64, /// Align on bottom 00073 CENTER_Y = 0, /// Aling centered vertically (default) 00074 BEFORE = 128, /// Icon before the text 00075 AFTER = 256, /// Icon after the text 00076 ABOVE = 512, /// Icon above the text 00077 BELOW = 1024 /// Icon below the text 00078 }; 00079 public: 00080 00081 /// Construct new item with given text, icon, size, and user-data 00082 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){} 00083 00084 /// Change item's text label 00085 virtual void setText(const FXString& txt); 00086 00087 /// Return item's text label 00088 const FXString& getText() const { return label; } 00089 00090 /// Change item's icon 00091 virtual void setIcon(FXIcon* icn); 00092 00093 /// Return item's icon 00094 FXIcon* getIcon() const { return icon; } 00095 00096 /// Change item's user data 00097 void setData(void* ptr){ data=ptr; } 00098 00099 /// Get item's user data 00100 void* getData() const { return data; } 00101 00102 /// Change size 00103 void setSize(FXint s){ size=s; } 00104 00105 /// Obtain current size 00106 FXint getSize() const { return size; } 00107 00108 /// Change position 00109 void setPos(FXint p){ pos=p; } 00110 00111 /// Obtain current position 00112 FXint getPos() const { return pos; } 00113 00114 /// Change sort direction (FALSE, TRUE, MAYBE) 00115 void setArrowDir(FXbool dir=MAYBE); 00116 00117 /// Return sort direction (FALSE, TRUE, MAYBE) 00118 FXbool getArrowDir() const; 00119 00120 /// Change content justification 00121 void setJustify(FXuint justify=LEFT|CENTER_Y); 00122 00123 /// Return content justification 00124 FXuint getJustify() const { return state&(RIGHT|LEFT|TOP|BOTTOM); } 00125 00126 /// Change icon position 00127 void setIconPosition(FXuint mode=BEFORE); 00128 00129 /// Return icon position 00130 FXuint getIconPosition() const { return state&(BEFORE|AFTER|ABOVE|BELOW); } 00131 00132 /// Change state to pressed 00133 void setPressed(FXbool pressed); 00134 00135 /// Return pressed state 00136 FXbool isPressed() const { return (state&PRESSED)!=0; } 00137 00138 /// Return the item's content width in the header 00139 virtual FXint getWidth(const FXHeader* header) const; 00140 00141 /// Return the item's content height in the header 00142 virtual FXint getHeight(const FXHeader* header) const; 00143 00144 /// Create server-side resources 00145 virtual void create(); 00146 00147 /// Detach from server-side resources 00148 virtual void detach(); 00149 00150 /// Destroy server-side resources 00151 virtual void destroy(); 00152 00153 /// Stream serialization 00154 virtual void save(FXStream& store) const; 00155 virtual void load(FXStream& store); 00156 00157 /// Destructor 00158 virtual ~FXHeaderItem(){} 00159 }; 00160 00161 00162 typedef FXObjectListOf<FXHeaderItem> FXHeaderItemList; 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 FXHeaderItemList items; // Item list 00188 FXColor textColor; // Text color 00189 FXFont *font; // Text font 00190 FXString help; // Help text 00191 FXint pos; // Scroll position 00192 FXint active; // Active button 00193 FXint activepos; // Position of active item 00194 FXint activesize; // Size of active item 00195 FXint offset; // Offset where split grabbed 00196 protected: 00197 FXHeader(); 00198 void drawSplit(FXint pos); 00199 virtual FXHeaderItem *createItem(const FXString& text,FXIcon* icon,FXint size,void* ptr); 00200 private: 00201 FXHeader(const FXHeader&); 00202 FXHeader &operator=(const FXHeader&); 00203 public: 00204 long onPaint(FXObject*,FXSelector,void*); 00205 long onLeftBtnPress(FXObject*,FXSelector,void*); 00206 long onLeftBtnRelease(FXObject*,FXSelector,void*); 00207 long onUngrabbed(FXObject*,FXSelector,void*); 00208 long onMotion(FXObject*,FXSelector,void*); 00209 long onTipTimer(FXObject*,FXSelector,void*); 00210 long onQueryTip(FXObject*,FXSelector,void*); 00211 long onQueryHelp(FXObject*,FXSelector,void*); 00212 public: 00213 00214 /// Construct new header control 00215 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); 00216 00217 /// Create server-side resources 00218 virtual void create(); 00219 00220 /// Detach server-side resources 00221 virtual void detach(); 00222 00223 /// Perform layout 00224 virtual void layout(); 00225 00226 /// Return number of items 00227 FXint getNumItems() const { return items.no(); } 00228 00229 /// Return total size of all items 00230 FXint getTotalSize() const; 00231 00232 /// Return default width 00233 virtual FXint getDefaultWidth(); 00234 00235 /// Return default height 00236 virtual FXint getDefaultHeight(); 00237 00238 /// Set the current position 00239 void setPosition(FXint pos); 00240 00241 /// Return the current position 00242 FXint getPosition() const { return pos; } 00243 00244 /// Return item at given index 00245 FXHeaderItem *getItem(FXint index) const; 00246 00247 /// Replace the item with a [possibly subclassed] item 00248 FXint setItem(FXint index,FXHeaderItem* item,FXbool notify=FALSE); 00249 00250 /** 00251 * Return item-index given coordinate offset, or -1 if coordinate 00252 * is before first item in header, or nitems if coordinate is after 00253 * last item in header. 00254 */ 00255 FXint getItemAt(FXint coord) const; 00256 00257 /// Replace items text, icon, and user-data pointer 00258 FXint setItem(FXint index,const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE); 00259 00260 /// Fill header by appending items from array of strings 00261 FXint fillItems(const FXchar** strings,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE); 00262 00263 /// Fill header by appending items from newline separated strings 00264 FXint fillItems(const FXString& strings,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE); 00265 00266 /// Insert a new [possibly subclassed] item at the give index 00267 FXint insertItem(FXint index,FXHeaderItem* item,FXbool notify=FALSE); 00268 00269 /// Insert item at index with given text, icon, and user-data pointer 00270 FXint insertItem(FXint index,const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE); 00271 00272 /// Append a [possibly subclassed] item to the list 00273 FXint appendItem(FXHeaderItem* item,FXbool notify=FALSE); 00274 00275 /// Append new item with given text and optional icon, and user-data pointer 00276 FXint appendItem(const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE); 00277 00278 /// Prepend a [possibly subclassed] item to the list 00279 FXint prependItem(FXHeaderItem* item,FXbool notify=FALSE); 00280 00281 /// Prepend new item with given text and optional icon, and user-data pointer 00282 FXint prependItem(const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE); 00283 00284 /// Remove item at index 00285 void removeItem(FXint index,FXbool notify=FALSE); 00286 00287 /// Remove all items 00288 void clearItems(FXbool notify=FALSE); 00289 00290 /// Change text label for item at index 00291 void setItemText(FXint index,const FXString& text); 00292 00293 /// Get text of item at index 00294 FXString getItemText(FXint index) const; 00295 00296 /// Change icon of item at index 00297 void setItemIcon(FXint index,FXIcon* icon); 00298 00299 /// Return icon of item at index 00300 FXIcon* getItemIcon(FXint index) const; 00301 00302 /// Change size of item at index 00303 void setItemSize(FXint index,FXint size); 00304 00305 /// Return size of item at index 00306 FXint getItemSize(FXint index) const; 00307 00308 /// Compute offset from the left side of item at index 00309 FXint getItemOffset(FXint index) const; 00310 00311 /// Change data of item at index 00312 void setItemData(FXint index,void* ptr); 00313 00314 /// Return data of item at index 00315 void* getItemData(FXint index) const; 00316 00317 /// Change sort direction (FALSE, TRUE, MAYBE) 00318 void setArrowDir(FXint index,FXbool dir=MAYBE); 00319 00320 /// Return sort direction (FALSE, TRUE, MAYBE) 00321 FXbool getArrowDir(FXint index) const; 00322 00323 /** 00324 * Change item justification. Horizontal justification is controlled by passing 00325 * FXHeaderItem::RIGHT, FXHeaderItem::LEFT, or FXHeaderItem::CENTER_X. 00326 * Vertical justification is controlled by FXHeaderItem::TOP, FXHeaderItem::BOTTOM, 00327 * or FXHeaderItem::CENTER_Y. 00328 * The default is a combination of FXHeaderItem::LEFT and FXHeaderItem::CENTER_Y. 00329 */ 00330 void setItemJustify(FXint index,FXuint justify); 00331 00332 /// Return item justification 00333 FXuint getItemJustify(FXint index) const; 00334 00335 /** 00336 * Change relative position of icon and text of item. 00337 * Passing FXHeaderItem::BEFORE or FXHeaderItem::AFTER places the icon 00338 * before or after the text, and passing FXHeaderItem::ABOVE or 00339 * FXHeaderItem::BELOW places it above or below the text, respectively. 00340 * The default of FXHeaderItem::BEFORE places the icon in front of the text. 00341 */ 00342 void setItemIconPosition(FXint index,FXuint mode); 00343 00344 /// Return relative icon and text position 00345 FXuint getItemIconPosition(FXint index) const; 00346 00347 /// Changed button item's pressed state 00348 void setItemPressed(FXint index,FXbool pressed=TRUE); 00349 00350 /// Return TRUE if button item is pressed in 00351 FXbool isItemPressed(FXint index) const; 00352 00353 /// Scroll to make given item visible 00354 void makeItemVisible(FXint index); 00355 00356 /// Repaint header at index 00357 void updateItem(FXint index) const; 00358 00359 /// Change text font 00360 void setFont(FXFont* fnt); 00361 00362 /// return text font 00363 FXFont* getFont() const { return font; } 00364 00365 /// Return text color 00366 FXColor getTextColor() const { return textColor; } 00367 00368 /// Change text color 00369 void setTextColor(FXColor clr); 00370 00371 /// Set header style options 00372 void setHeaderStyle(FXuint style); 00373 00374 /// Get header style options 00375 FXuint getHeaderStyle() const; 00376 00377 /// Set the status line help text for this header 00378 void setHelpText(const FXString& text); 00379 00380 /// Get the status line help text for this header 00381 const FXString& getHelpText() const { return help; } 00382 00383 /// Save header to a stream 00384 virtual void save(FXStream& store) const; 00385 00386 /// Load header from a stream 00387 virtual void load(FXStream& store); 00388 00389 /// Destructor 00390 virtual ~FXHeader(); 00391 }; 00392 00393 } 00394 00395 #endif

Copyright © 1997-2005 Jeroen van der Zijp