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

FXHeader.h

Go to the documentation of this file.
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 2006/01/22 17:58:04 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 typedef FXObjectListOf<FXHeaderItem> FXHeaderItemList;
00167 
00168 
00169 /**
00170 * Header control may be placed over a table or list to provide a resizable
00171 * captions above a number of columns.
00172 * Each caption comprises a label and an optional icon; in addition, an arrow
00173 * may be shown to indicate whether the items in that column are sorted, and
00174 * if so, whether they are sorted in increasing or decreasing order.
00175 * Each caption can be interactively resized.  During the resizing, if the
00176 * HEADER_TRACKING was specified, the header control sends a SEL_CHANGED message
00177 * to its target, with the message data set to the caption number being resized,
00178 * of the type FXint.
00179 * If the HEADER_TRACKING was not specified the SEL_CHANGED message is sent at
00180 * the end of the resizing operation.
00181 * Clicking on a caption causes a message of type SEL_COMMAND to be sent to the
00182 * target, with the message data set to the caption number being clicked.
00183 * A single click on a split causes a message of type SEL_CLICKED to be sent to the
00184 * target; a typical response to this message would be to adjust the size of
00185 * the split to fit the contents displayed underneath it.
00186 * The contents may be scrolled by calling setPosition().
00187 */
00188 class FXAPI FXHeader : public FXFrame {
00189   FXDECLARE(FXHeader)
00190 protected:
00191   FXHeaderItemList items; // Item list
00192   FXColor          textColor; // Text color
00193   FXFont          *font;  // Text font
00194   FXString         help;  // Help text
00195   FXint            pos;   // Scroll position
00196   FXint            active;  // Active button
00197   FXint            activepos; // Position of active item
00198   FXint            activesize;  // Size of active item
00199   FXint            offset;  // Offset where split grabbed
00200 protected:
00201   FXHeader();
00202   void drawSplit(FXint pos);
00203   virtual FXHeaderItem *createItem(const FXString& text,FXIcon* icon,FXint size,void* ptr);
00204 private:
00205   FXHeader(const FXHeader&);
00206   FXHeader &operator=(const FXHeader&);
00207 public:
00208   long onPaint(FXObject*,FXSelector,void*);
00209   long onLeftBtnPress(FXObject*,FXSelector,void*);
00210   long onLeftBtnRelease(FXObject*,FXSelector,void*);
00211   long onUngrabbed(FXObject*,FXSelector,void*);
00212   long onMotion(FXObject*,FXSelector,void*);
00213   long onTipTimer(FXObject*,FXSelector,void*);
00214   long onQueryTip(FXObject*,FXSelector,void*);
00215   long onQueryHelp(FXObject*,FXSelector,void*);
00216 public:
00217 
00218   /// Construct new header control
00219   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);
00220 
00221   /// Create server-side resources
00222   virtual void create();
00223 
00224   /// Detach server-side resources
00225   virtual void detach();
00226 
00227   /// Perform layout
00228   virtual void layout();
00229 
00230   /// Return number of items
00231   FXint getNumItems() const { return items.no(); }
00232 
00233   /// Return total size of all items
00234   FXint getTotalSize() const;
00235 
00236   /// Return default width
00237   virtual FXint getDefaultWidth();
00238 
00239   /// Return default height
00240   virtual FXint getDefaultHeight();
00241 
00242   /// Set the current position
00243   void setPosition(FXint pos);
00244 
00245   /// Return the current position
00246   FXint getPosition() const { return pos; }
00247 
00248   /**
00249   * Return item-index given coordinate offset, or -1 if coordinate
00250   * is before first item in header, or nitems if coordinate is after
00251   * last item in header.
00252   */
00253   FXint getItemAt(FXint coord) const;
00254 
00255   /// Return item at given index
00256   FXHeaderItem *getItem(FXint index) const;
00257 
00258   /// Replace the item with a [possibly subclassed] item
00259   FXint setItem(FXint index,FXHeaderItem* item,FXbool notify=FALSE);
00260 
00261   /// Replace items text, icon, and user-data pointer
00262   FXint setItem(FXint index,const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE);
00263 
00264   /// Fill header by appending items from array of strings
00265   FXint fillItems(const FXchar** strings,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE);
00266 
00267   /// Fill header by appending items from newline separated strings
00268   FXint fillItems(const FXString& strings,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE);
00269 
00270   /// Insert a new [possibly subclassed] item at the give index
00271   FXint insertItem(FXint index,FXHeaderItem* item,FXbool notify=FALSE);
00272 
00273   /// Insert item at index with given text, icon, and user-data pointer
00274   FXint insertItem(FXint index,const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE);
00275 
00276   /// Append a [possibly subclassed] item to the list
00277   FXint appendItem(FXHeaderItem* item,FXbool notify=FALSE);
00278 
00279   /// Append new item with given text and optional icon, and user-data pointer
00280   FXint appendItem(const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE);
00281 
00282   /// Prepend a [possibly subclassed] item to the list
00283   FXint prependItem(FXHeaderItem* item,FXbool notify=FALSE);
00284 
00285   /// Prepend new item with given text and optional icon, and user-data pointer
00286   FXint prependItem(const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE);
00287 
00288   /// Extract item from list
00289   FXHeaderItem* extractItem(FXint index,FXbool notify=FALSE);
00290 
00291   /// Remove item at index
00292   void removeItem(FXint index,FXbool notify=FALSE);
00293 
00294   /// Remove all items
00295   void clearItems(FXbool notify=FALSE);
00296 
00297   /// Change text label for item at index
00298   void setItemText(FXint index,const FXString& text);
00299 
00300   /// Get text of item at index
00301   FXString getItemText(FXint index) const;
00302 
00303   /// Change icon of item at index
00304   void setItemIcon(FXint index,FXIcon* icon);
00305 
00306   /// Return icon of item at index
00307   FXIcon* getItemIcon(FXint index) const;
00308 
00309   /// Change size of item at index
00310   void setItemSize(FXint index,FXint size);
00311 
00312   /// Return size of item at index
00313   FXint getItemSize(FXint index) const;
00314 
00315   /// Compute offset from the left side of item at index
00316   FXint getItemOffset(FXint index) const;
00317 
00318   /// Change data of item at index
00319   void setItemData(FXint index,void* ptr);
00320 
00321   /// Return data of item at index
00322   void* getItemData(FXint index) const;
00323 
00324   /// Change sort direction (FALSE, TRUE, MAYBE)
00325   void setArrowDir(FXint index,FXbool dir=MAYBE);
00326 
00327   /// Return sort direction (FALSE, TRUE, MAYBE)
00328   FXbool getArrowDir(FXint index) const;
00329 
00330   /**
00331   * Change item justification.  Horizontal justification is controlled by passing
00332   * FXHeaderItem::RIGHT, FXHeaderItem::LEFT, or FXHeaderItem::CENTER_X.
00333   * Vertical justification is controlled by FXHeaderItem::TOP, FXHeaderItem::BOTTOM,
00334   * or FXHeaderItem::CENTER_Y.
00335   * The default is a combination of FXHeaderItem::LEFT and FXHeaderItem::CENTER_Y.
00336   */
00337   void setItemJustify(FXint index,FXuint justify);
00338 
00339   /// Return item justification
00340   FXuint getItemJustify(FXint index) const;
00341 
00342   /**
00343   * Change relative position of icon and text of item.
00344   * Passing FXHeaderItem::BEFORE or FXHeaderItem::AFTER places the icon
00345   * before or after the text, and passing FXHeaderItem::ABOVE or
00346   * FXHeaderItem::BELOW places it above or below the text, respectively.
00347   * The default of FXHeaderItem::BEFORE places the icon in front of the text.
00348   */
00349   void setItemIconPosition(FXint index,FXuint mode);
00350 
00351   /// Return relative icon and text position
00352   FXuint getItemIconPosition(FXint index) const;
00353 
00354   /// Changed button item's pressed state
00355   void setItemPressed(FXint index,FXbool pressed=TRUE);
00356 
00357   /// Return TRUE if button item is pressed in
00358   FXbool isItemPressed(FXint index) const;
00359 
00360   /// Scroll to make given item visible
00361   void makeItemVisible(FXint index);
00362 
00363   /// Repaint header at index
00364   void updateItem(FXint index) const;
00365 
00366   /// Change text font
00367   void setFont(FXFont* fnt);
00368 
00369   /// return text font
00370   FXFont* getFont() const { return font; }
00371 
00372   /// Return text color
00373   FXColor getTextColor() const { return textColor; }
00374 
00375   /// Change text color
00376   void setTextColor(FXColor clr);
00377 
00378   /// Set header style options
00379   void setHeaderStyle(FXuint style);
00380 
00381   /// Get header style options
00382   FXuint getHeaderStyle() const;
00383 
00384   /// Set the status line help text for this header
00385   void setHelpText(const FXString& text);
00386 
00387   /// Get the status line help text for this header
00388   const FXString& getHelpText() const { return help; }
00389 
00390   /// Save header to a stream
00391   virtual void save(FXStream& store) const;
00392 
00393   /// Load header from a stream
00394   virtual void load(FXStream& store);
00395 
00396   /// Destructor
00397   virtual ~FXHeader();
00398   };
00399 
00400 }
00401 
00402 #endif

Copyright © 1997-2005 Jeroen van der Zijp