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,2002 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.31 2002/09/30 13:06:56 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 struct FXTimer;
00034 class FXIcon;
00035 class FXFont;
00036 class FXHeader;
00037 
00038 
00039 /// Header style options
00040 enum {
00041   HEADER_BUTTON     = 0x00008000,     /// Button style can be clicked
00042   HEADER_HORIZONTAL = 0,              /// Horizontal header control (default)
00043   HEADER_VERTICAL   = 0x00010000,     /// Vertical header control
00044   HEADER_TRACKING   = 0x00020000,     /// Tracks continuously while moving
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;
00055   FXIcon   *icon;
00056   FXint     size;
00057   void     *data;
00058   FXbool    arrow;
00059 protected:
00060   FXHeaderItem(){}
00061   virtual void draw(const FXHeader* header,FXDC& dc,FXint x,FXint y,FXint w,FXint h);
00062 public:
00063 
00064   /// Construct new item with given text, icon, size, and user-data
00065   FXHeaderItem(const FXString& text,FXIcon* ic=NULL,FXint s=0,void* ptr=NULL):label(text),icon(ic),size(s),data(ptr),arrow(MAYBE){}
00066 
00067   /// Change item's text label
00068   virtual void setText(const FXString& txt){ label=txt; }
00069 
00070   /// Return item's text label
00071   const FXString& getText() const { return label; }
00072 
00073   /// Change item's icon
00074   virtual void setIcon(FXIcon* icn){ icon=icn; }
00075 
00076   /// Return item's icon
00077   FXIcon* getIcon() const { return icon; }
00078 
00079   /// Change item's user data
00080   void setData(void* ptr){ data=ptr; }
00081 
00082   /// Get item's user data
00083   void* getData() const { return data; }
00084 
00085   /// Change size
00086   void setSize(FXint s){ size=s; }
00087 
00088   /// Obtain current size
00089   FXint getSize() const { return size; }
00090 
00091   /// Change sort direction (FALSE, TRUE, MAYBE)
00092   void setArrowDir(FXuint dir=MAYBE){ arrow=dir; }
00093 
00094   /// Return sort direction (FALSE, TRUE, MAYBE)
00095   FXuint getArrowDir() const { return arrow; }
00096 
00097   /// Return the item's width in the header
00098   virtual FXint getWidth(const FXHeader* header) const;
00099 
00100   /// Return the item's height in the header
00101   virtual FXint getHeight(const FXHeader* header) const;
00102 
00103   /// Create server-side resources
00104   virtual void create();
00105 
00106   /// Detach from server-side resources
00107   virtual void detach();
00108 
00109   /// Destroy server-side resources
00110   virtual void destroy();
00111 
00112   /// Stream serialization
00113   virtual void save(FXStream& store) const;
00114   virtual void load(FXStream& store);
00115 
00116   /// Destructor
00117   virtual ~FXHeaderItem(){}
00118   };
00119 
00120 
00121 /**
00122 * Header control may be placed over a table or list to provide a resizable
00123 * captions above a number of columns.
00124 * Each caption comprises a label and an optional icon; in addition, an arrow
00125 * may be shown to indicate whether the items in that column are sorted, and
00126 * if so, whether they are sorted in increasing or decreasing order.
00127 * Each caption can be interactively resized.  During the resizing, if the
00128 * HEADER_TRACKING was specified, the header control sends a SEL_CHANGED message
00129 * to its target, with the message data set to the caption number being resized,
00130 * of the type FXint.
00131 * If the HEADER_TRACKING was not specified the SEL_CHANGED message is sent at
00132 * the end of the resizing operation.
00133 * Clicking on a caption causes a message of type SEL_COMMAND to be sent to the
00134 * target, with the message data set to the caption number being clicked.
00135 */
00136 class FXAPI FXHeader : public FXFrame {
00137   FXDECLARE(FXHeader)
00138 protected:
00139   FXHeaderItem **items;               // Item list
00140   FXint          nitems;              // Number of items
00141   FXColor        textColor;           // Text color
00142   FXFont*        font;                // Text font
00143   FXTimer       *timer;               // Tip hover timer
00144   FXString       help;                // Help text
00145   FXbool         state;               // Button state
00146   FXint          active;              // Active button
00147   FXint          activepos;           // Position of active item
00148   FXint          activesize;          // Size of active item
00149   FXint          off;
00150 protected:
00151   FXHeader();
00152   void drawSplit(FXint pos);
00153   virtual FXHeaderItem *createItem(const FXString& text,FXIcon* icon,FXint size,void* ptr);
00154   virtual void layout();
00155 private:
00156   FXHeader(const FXHeader&);
00157   FXHeader &operator=(const FXHeader&);
00158 public:
00159   long onPaint(FXObject*,FXSelector,void*);
00160   long onLeftBtnPress(FXObject*,FXSelector,void*);
00161   long onLeftBtnRelease(FXObject*,FXSelector,void*);
00162   long onUngrabbed(FXObject*,FXSelector,void*);
00163   long onMotion(FXObject*,FXSelector,void*);
00164   long onTipTimer(FXObject*,FXSelector,void*);
00165   long onQueryTip(FXObject*,FXSelector,void*);
00166   long onQueryHelp(FXObject*,FXSelector,void*);
00167 public:
00168   enum {
00169     ID_TIPTIMER=FXFrame::ID_LAST,
00170     ID_LAST
00171     };
00172 public:
00173 
00174   /// Construct new header control
00175   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);
00176 
00177   /// Create server-side resources
00178   virtual void create();
00179 
00180   /// Detach server-side resources
00181   virtual void detach();
00182 
00183   /// Return number of items
00184   FXint getNumItems() const { return nitems; }
00185 
00186   /// Return default width
00187   virtual FXint getDefaultWidth();
00188 
00189   /// Return default height
00190   virtual FXint getDefaultHeight();
00191 
00192   /// Return item at given index
00193   FXHeaderItem *getItem(FXint index) const;
00194 
00195   /// Replace the item with a [possibly subclassed] item
00196   FXint setItem(FXint index,FXHeaderItem* item,FXbool notify=FALSE);
00197 
00198   /// Replace items text, icon, and user-data pointer
00199   FXint setItem(FXint index,const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE);
00200 
00201   /// Insert a new [possibly subclassed] item at the give index
00202   FXint insertItem(FXint index,FXHeaderItem* item,FXbool notify=FALSE);
00203 
00204   /// Insert item at index with given text, icon, and user-data pointer
00205   FXint insertItem(FXint index,const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE);
00206 
00207   /// Append a [possibly subclassed] item to the list
00208   FXint appendItem(FXHeaderItem* item,FXbool notify=FALSE);
00209 
00210   /// Append new item with given text and optional icon, and user-data pointer
00211   FXint appendItem(const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE);
00212 
00213   /// Prepend a [possibly subclassed] item to the list
00214   FXint prependItem(FXHeaderItem* item,FXbool notify=FALSE);
00215 
00216   /// Prepend new item with given text and optional icon, and user-data pointer
00217   FXint prependItem(const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE);
00218 
00219   /// Remove item at index
00220   void removeItem(FXint index,FXbool notify=FALSE);
00221 
00222   /// Remove all items
00223   void clearItems(FXbool notify=FALSE);
00224 
00225   /// Return item-index given pixel-offset from left
00226   FXint getItemAt(FXint offset) const;
00227 
00228   /// Change text label for item at index
00229   void setItemText(FXint index,const FXString& text);
00230 
00231   /// Get text of item at index
00232   FXString getItemText(FXint index) const;
00233 
00234   /// Change icon of item at index
00235   void setItemIcon(FXint index,FXIcon* icon);
00236 
00237   /// Return icon of item at index
00238   FXIcon* getItemIcon(FXint index) const;
00239 
00240   /// Change size of item at index
00241   void setItemSize(FXint index,FXint size);
00242 
00243   /// Return size of item at index
00244   FXint getItemSize(FXint index) const;
00245 
00246   /// Compute offset from the left side of item at index
00247   FXint getItemOffset(FXint index) const;
00248 
00249   /// Change data of item at index
00250   void setItemData(FXint index,void* ptr);
00251 
00252   /// Return data of item at index
00253   void* getItemData(FXint index) const;
00254 
00255   /// Change sort direction (FALSE, TRUE, MAYBE)
00256   void setArrowDir(FXint index,FXbool dir=MAYBE);
00257 
00258   /// Return sort direction (FALSE, TRUE, MAYBE)
00259   FXbool getArrowDir(FXint index) const;
00260 
00261   /// Change text font
00262   void setFont(FXFont* fnt);
00263 
00264   /// return text font
00265   FXFont* getFont() const { return font; }
00266 
00267   /// Return text color
00268   FXColor getTextColor() const { return textColor; }
00269 
00270   /// Change text color
00271   void setTextColor(FXColor clr);
00272 
00273   /// Set header style options
00274   void setHeaderStyle(FXuint style);
00275 
00276   /// Get header style options
00277   FXuint getHeaderStyle() const;
00278 
00279   /// Set the status line help text for this header
00280   void setHelpText(const FXString& text);
00281 
00282   /// Get the status line help text for this header
00283   const FXString& getHelpText() const { return help; }
00284 
00285   /// Save header to a stream
00286   virtual void save(FXStream& store) const;
00287 
00288   /// Load header from a stream
00289   virtual void load(FXStream& store);
00290 
00291   /// Destructor
00292   virtual ~FXHeader();
00293   };
00294 
00295 }
00296 
00297 #endif