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,2009 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (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                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 *********************************************************************************
00021 * $Id: FXHeader.h,v 1.86 2009/01/06 13:07:24 fox Exp $                          *
00022 ********************************************************************************/
00023 #ifndef FXHEADER_H
00024 #define FXHEADER_H
00025 
00026 #ifndef FXFRAME_H
00027 #include "FXFrame.h"
00028 #endif
00029 
00030 namespace FX {
00031 
00032 class FXIcon;
00033 class FXFont;
00034 class FXHeader;
00035 
00036 
00037 /// Header style options
00038 enum {
00039   HEADER_BUTTON     = 0x00008000,     /// Button style can be clicked
00040   HEADER_HORIZONTAL = 0,              /// Horizontal header control (default)
00041   HEADER_VERTICAL   = 0x00010000,     /// Vertical header control
00042   HEADER_TRACKING   = 0x00020000,     /// Tracks continuously while moving
00043   HEADER_RESIZE     = 0x00040000,     /// Allow resizing sections
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   FXString  tip;        // Tooltip of item
00055   FXIcon   *icon;       // Icon of item
00056   void     *data;       // User data pointer
00057   FXint     size;       // Item size
00058   FXint     pos;        // Item position
00059   FXuint    state;      // 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) const;
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);
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   /// Set the tool tip message for this item
00095   void setTipText(const FXString& text){ tip=text; }
00096 
00097   /// Get the tool tip message for this item
00098   const FXString& getTipText() const { return tip; }
00099 
00100   /// Change item's icon
00101   virtual void setIcon(FXIcon* icn);
00102 
00103   /// Return item's icon
00104   FXIcon* getIcon() const { return icon; }
00105 
00106   /// Change item's user data
00107   void setData(void* ptr){ data=ptr; }
00108 
00109   /// Get item's user data
00110   void* getData() const { return data; }
00111 
00112   /// Change size
00113   void setSize(FXint s){ size=s; }
00114 
00115   /// Obtain current size
00116   FXint getSize() const { return size; }
00117 
00118   /// Change position
00119   void setPos(FXint p){ pos=p; }
00120 
00121   /// Obtain current position
00122   FXint getPos() const { return pos; }
00123 
00124   /// Change sort direction (ARROW_NONE, ARROW_UP, ARROW_DOWN)
00125   void setArrowDir(FXuint dir=ARROW_NONE);
00126 
00127   /// Return sort direction (ARROW_NONE, ARROW_UP, ARROW_DOWN)
00128   FXuint getArrowDir() const;
00129 
00130   /// Change content justification
00131   void setJustify(FXuint justify=LEFT|CENTER_Y);
00132 
00133   /// Return content justification
00134   FXuint getJustify() const;
00135 
00136   /// Change icon position
00137   void setIconPosition(FXuint mode=BEFORE);
00138 
00139   /// Return icon position
00140   FXuint getIconPosition() const;
00141 
00142   /// Change state to pressed
00143   void setPressed(FXbool pressed);
00144 
00145   /// Return pressed state
00146   FXbool isPressed() const;
00147 
00148   /// Return the item's content width in the header
00149   virtual FXint getWidth(const FXHeader* header) const;
00150 
00151   /// Return the item's content height in the header
00152   virtual FXint getHeight(const FXHeader* header) const;
00153 
00154   /// Create server-side resources
00155   virtual void create();
00156 
00157   /// Detach from server-side resources
00158   virtual void detach();
00159 
00160   /// Destroy server-side resources
00161   virtual void destroy();
00162 
00163   /// Stream serialization
00164   virtual void save(FXStream& store) const;
00165   virtual void load(FXStream& store);
00166 
00167   /// Destructor
00168   virtual ~FXHeaderItem(){}
00169   };
00170 
00171 
00172 /// List of FXHeaderItem's
00173 typedef FXObjectListOf<FXHeaderItem> FXHeaderItemList;
00174 
00175 
00176 /**
00177 * Header control may be placed over a table or list to provide a resizable
00178 * captions above a number of columns.
00179 * Each caption comprises a label and an optional icon; in addition, an arrow
00180 * may be shown to indicate whether the items in that column are sorted, and
00181 * if so, whether they are sorted in increasing or decreasing order.
00182 * Each caption can be interactively resized.  During the resizing, if the
00183 * HEADER_TRACKING was specified, the header control sends a SEL_CHANGED message
00184 * to its target, with the message data set to the caption number being resized,
00185 * of the type FXint.
00186 * If the HEADER_TRACKING was not specified the SEL_CHANGED message is sent at
00187 * the end of the resizing operation.
00188 * Clicking on a caption causes a message of type SEL_COMMAND to be sent to the
00189 * target, with the message data set to the caption number being clicked.
00190 * A single click on a split causes a message of type SEL_CLICKED to be sent to the
00191 * target; a typical response to this message would be to adjust the size of
00192 * the split to fit the contents displayed underneath it.
00193 * The contents may be scrolled by calling setPosition().
00194 */
00195 class FXAPI FXHeader : public FXFrame {
00196   FXDECLARE(FXHeader)
00197 protected:
00198   FXHeaderItemList items; // Item list
00199   FXColor          textColor; // Text color
00200   FXFont          *font;  // Text font
00201   FXString         help;  // Help text
00202   FXint            pos;   // Scroll position
00203   FXint            active;  // Active button
00204   FXint            activepos; // Position of active item
00205   FXint            activesize;  // Size of active item
00206   FXint            offset;  // Offset where split grabbed
00207 protected:
00208   FXHeader();
00209   void drawSplit(FXint pos);
00210   virtual FXHeaderItem *createItem(const FXString& text,FXIcon* icon,FXint size,void* ptr);
00211 private:
00212   FXHeader(const FXHeader&);
00213   FXHeader &operator=(const FXHeader&);
00214 public:
00215   long onPaint(FXObject*,FXSelector,void*);
00216   long onLeftBtnPress(FXObject*,FXSelector,void*);
00217   long onLeftBtnRelease(FXObject*,FXSelector,void*);
00218   long onUngrabbed(FXObject*,FXSelector,void*);
00219   long onMotion(FXObject*,FXSelector,void*);
00220   long onTipTimer(FXObject*,FXSelector,void*);
00221   long onQueryTip(FXObject*,FXSelector,void*);
00222   long onQueryHelp(FXObject*,FXSelector,void*);
00223 public:
00224 
00225   /// Construct new header control
00226   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);
00227 
00228   /// Create server-side resources
00229   virtual void create();
00230 
00231   /// Detach server-side resources
00232   virtual void detach();
00233 
00234   /// Perform layout
00235   virtual void layout();
00236 
00237   /// Return number of items
00238   FXint getNumItems() const { return items.no(); }
00239 
00240   /// Return total size of all items
00241   FXint getTotalSize() const;
00242 
00243   /// Return default width
00244   virtual FXint getDefaultWidth();
00245 
00246   /// Return default height
00247   virtual FXint getDefaultHeight();
00248 
00249   /// Set the current position
00250   void setPosition(FXint pos);
00251 
00252   /// Return the current position
00253   FXint getPosition() const { return pos; }
00254 
00255   /**
00256   * Return item-index given coordinate offset, or -1 if coordinate
00257   * is before first item in header, or nitems if coordinate is after
00258   * last item in header.
00259   */
00260   FXint getItemAt(FXint coord) const;
00261 
00262   /// Return item at given index
00263   FXHeaderItem *getItem(FXint index) const;
00264 
00265   /// Replace the item with a [possibly subclassed] item
00266   FXint setItem(FXint index,FXHeaderItem* item,FXbool notify=false);
00267 
00268   /// Replace items text, icon, and user-data pointer
00269   FXint setItem(FXint index,const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=false);
00270 
00271   /// Fill header by appending items from array of strings
00272   FXint fillItems(const FXchar** strings,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=false);
00273 
00274   /// Fill header by appending items from newline separated strings
00275   FXint fillItems(const FXString& strings,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=false);
00276 
00277   /// Insert a new [possibly subclassed] item at the give index
00278   FXint insertItem(FXint index,FXHeaderItem* item,FXbool notify=false);
00279 
00280   /// Insert item at index with given text, icon, and user-data pointer
00281   FXint insertItem(FXint index,const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=false);
00282 
00283   /// Append a [possibly subclassed] item to the list
00284   FXint appendItem(FXHeaderItem* item,FXbool notify=false);
00285 
00286   /// Append new item with given text and optional icon, and user-data pointer
00287   FXint appendItem(const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=false);
00288 
00289   /// Prepend a [possibly subclassed] item to the list
00290   FXint prependItem(FXHeaderItem* item,FXbool notify=false);
00291 
00292   /// Prepend new item with given text and optional icon, and user-data pointer
00293   FXint prependItem(const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=false);
00294 
00295   /// Extract item from list
00296   FXHeaderItem* extractItem(FXint index,FXbool notify=false);
00297 
00298   /// Remove item at index
00299   void removeItem(FXint index,FXbool notify=false);
00300 
00301   /// Remove all items
00302   void clearItems(FXbool notify=false);
00303 
00304   /// Change text label for item at index
00305   void setItemText(FXint index,const FXString& text);
00306 
00307   /// Get text of item at index
00308   FXString getItemText(FXint index) const;
00309 
00310   /// Change tool tip message for item at index
00311   void setItemTipText(FXint index,const FXString& text);
00312 
00313   /// Get tool tip message of item at index
00314   FXString getItemTipText(FXint index) const;
00315 
00316   /// Change icon of item at index
00317   void setItemIcon(FXint index,FXIcon* icon);
00318 
00319   /// Return icon of item at index
00320   FXIcon* getItemIcon(FXint index) const;
00321 
00322   /// Change size of item at index
00323   void setItemSize(FXint index,FXint size);
00324 
00325   /// Return size of item at index
00326   FXint getItemSize(FXint index) const;
00327 
00328   /// Compute offset from the left side of item at index
00329   FXint getItemOffset(FXint index) const;
00330 
00331   /// Change data of item at index
00332   void setItemData(FXint index,void* ptr);
00333 
00334   /// Return data of item at index
00335   void* getItemData(FXint index) const;
00336 
00337   /// Change sort direction (ARROW_NONE, ARROW_UP, ARROW_DOWN)
00338   void setArrowDir(FXint index,FXuint dir=FXHeaderItem::ARROW_NONE);
00339 
00340   /// Return sort direction (ARROW_NONE, ARROW_UP, ARROW_DOWN)
00341   FXuint getArrowDir(FXint index) const;
00342 
00343   /**
00344   * Change item justification.  Horizontal justification is controlled by passing
00345   * FXHeaderItem::RIGHT, FXHeaderItem::LEFT, or FXHeaderItem::CENTER_X.
00346   * Vertical justification is controlled by FXHeaderItem::TOP, FXHeaderItem::BOTTOM,
00347   * or FXHeaderItem::CENTER_Y.
00348   * The default is a combination of FXHeaderItem::LEFT and FXHeaderItem::CENTER_Y.
00349   */
00350   void setItemJustify(FXint index,FXuint justify);
00351 
00352   /// Return item justification
00353   FXuint getItemJustify(FXint index) const;
00354 
00355   /**
00356   * Change relative position of icon and text of item.
00357   * Passing FXHeaderItem::BEFORE or FXHeaderItem::AFTER places the icon
00358   * before or after the text, and passing FXHeaderItem::ABOVE or
00359   * FXHeaderItem::BELOW places it above or below the text, respectively.
00360   * The default of FXHeaderItem::BEFORE places the icon in front of the text.
00361   */
00362   void setItemIconPosition(FXint index,FXuint mode);
00363 
00364   /// Return relative icon and text position
00365   FXuint getItemIconPosition(FXint index) const;
00366 
00367   /// Changed button item's pressed state
00368   void setItemPressed(FXint index,FXbool pressed=true);
00369 
00370   /// Return true if button item is pressed in
00371   FXbool isItemPressed(FXint index) const;
00372 
00373   /// Scroll to make given item visible
00374   void makeItemVisible(FXint index);
00375 
00376   /// Repaint header at index
00377   void updateItem(FXint index) const;
00378 
00379   /// Change text font
00380   void setFont(FXFont* fnt);
00381 
00382   /// return text font
00383   FXFont* getFont() const { return font; }
00384 
00385   /// Return text color
00386   FXColor getTextColor() const { return textColor; }
00387 
00388   /// Change text color
00389   void setTextColor(FXColor clr);
00390 
00391   /// Set header style options
00392   void setHeaderStyle(FXuint style);
00393 
00394   /// Get header style options
00395   FXuint getHeaderStyle() const;
00396 
00397   /// Set the status line help text for this header
00398   void setHelpText(const FXString& text);
00399 
00400   /// Get the status line help text for this header
00401   const FXString& getHelpText() const { return help; }
00402 
00403   /// Save header to a stream
00404   virtual void save(FXStream& store) const;
00405 
00406   /// Load header from a stream
00407   virtual void load(FXStream& store);
00408 
00409   /// Destructor
00410   virtual ~FXHeader();
00411   };
00412 
00413 }
00414 
00415 #endif

Copyright © 1997-2009 Jeroen van der Zijp