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.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 
00039 enum {
00040   HEADER_BUTTON     = 0x00008000,     
00041   HEADER_HORIZONTAL = 0,              
00042   HEADER_VERTICAL   = 0x00010000,     
00043   HEADER_TRACKING   = 0x00020000,     
00044   HEADER_RESIZE     = 0x00040000,     
00045   HEADER_NORMAL     = HEADER_HORIZONTAL|FRAME_NORMAL
00046   };
00047 
00048 
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,     
00069     ARROW_UP   = 1,     
00070     ARROW_DOWN = 2,     
00071     PRESSED    = 4,     
00072     RIGHT      = 8,     
00073     LEFT       = 16,    
00074     CENTER_X   = 0,     
00075     TOP        = 32,    
00076     BOTTOM     = 64,    
00077     CENTER_Y   = 0,     
00078     BEFORE     = 128,   
00079     AFTER      = 256,   
00080     ABOVE      = 512,   
00081     BELOW      = 1024   
00082     };
00083 public:
00084 
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 
00089   virtual void setText(const FXString& txt);
00090 
00092   const FXString& getText() const { return label; }
00093 
00095   virtual void setIcon(FXIcon* icn);
00096 
00098   FXIcon* getIcon() const { return icon; }
00099 
00101   void setData(void* ptr){ data=ptr; }
00102 
00104   void* getData() const { return data; }
00105 
00107   void setSize(FXint s){ size=s; }
00108 
00110   FXint getSize() const { return size; }
00111 
00113   void setPos(FXint p){ pos=p; }
00114 
00116   FXint getPos() const { return pos; }
00117 
00119   void setArrowDir(FXbool dir=MAYBE);
00120 
00122   FXbool getArrowDir() const;
00123 
00125   void setJustify(FXuint justify=LEFT|CENTER_Y);
00126 
00128   FXuint getJustify() const { return state&(RIGHT|LEFT|TOP|BOTTOM); }
00129 
00131   void setIconPosition(FXuint mode=BEFORE);
00132 
00134   FXuint getIconPosition() const { return state&(BEFORE|AFTER|ABOVE|BELOW); }
00135 
00137   void setPressed(FXbool pressed);
00138 
00140   FXbool isPressed() const { return (state&PRESSED)!=0; }
00141 
00143   virtual FXint getWidth(const FXHeader* header) const;
00144 
00146   virtual FXint getHeight(const FXHeader* header) const;
00147 
00149   virtual void create();
00150 
00152   virtual void detach();
00153 
00155   virtual void destroy();
00156 
00158   virtual void save(FXStream& store) const;
00159   virtual void load(FXStream& store);
00160 
00162   virtual ~FXHeaderItem(){}
00163   };
00164 
00165 
00167 typedef FXObjectListOf<FXHeaderItem> FXHeaderItemList;
00168 
00169 
00170 #ifdef _MSC_VER
00171 #pragma warning(push)
00172 #pragma warning(disable: 4251)
00173 #endif
00174 
00194 class FXAPI FXHeader : public FXFrame {
00195   FXDECLARE(FXHeader)
00196 protected:
00197   FXHeaderItemList items;   // Item list
00198   FXColor          textColor;   // Text color
00199   FXFont          *font;    // Text font
00200   FXString         help;    // Help text
00201   FXint            pos;     // Scroll position
00202   FXint            active;  // Active button
00203   FXint            activepos;   // Position of active item
00204   FXint            activesize;  // Size of active item
00205   FXint            offset;  // Offset where split grabbed
00206 protected:
00207   FXHeader();
00208   void drawSplit(FXint pos);
00209   virtual FXHeaderItem *createItem(const FXString& text,FXIcon* icon,FXint size,void* ptr);
00210 private:
00211   FXHeader(const FXHeader&);
00212   FXHeader &operator=(const FXHeader&);
00213 public:
00214   long onPaint(FXObject*,FXSelector,void*);
00215   long onLeftBtnPress(FXObject*,FXSelector,void*);
00216   long onLeftBtnRelease(FXObject*,FXSelector,void*);
00217   long onUngrabbed(FXObject*,FXSelector,void*);
00218   long onMotion(FXObject*,FXSelector,void*);
00219   long onTipTimer(FXObject*,FXSelector,void*);
00220   long onQueryTip(FXObject*,FXSelector,void*);
00221   long onQueryHelp(FXObject*,FXSelector,void*);
00222 public:
00223 
00225   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);
00226 
00228   virtual void create();
00229 
00231   virtual void detach();
00232 
00234   virtual void layout();
00235 
00237   FXint getNumItems() const { return items.no(); }
00238 
00240   FXint getTotalSize() const;
00241 
00243   virtual FXint getDefaultWidth();
00244 
00246   virtual FXint getDefaultHeight();
00247 
00249   void setPosition(FXint pos);
00250 
00252   FXint getPosition() const { return pos; }
00253 
00259   FXint getItemAt(FXint coord) const;
00260 
00262   FXHeaderItem *getItem(FXint index) const;
00263 
00265   FXint setItem(FXint index,FXHeaderItem* item,FXbool notify=FALSE);
00266 
00268   FXint setItem(FXint index,const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE);
00269 
00271   FXint fillItems(const FXchar** strings,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE);
00272 
00274   FXint fillItems(const FXString& strings,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE);
00275 
00277   FXint insertItem(FXint index,FXHeaderItem* item,FXbool notify=FALSE);
00278 
00280   FXint insertItem(FXint index,const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE);
00281 
00283   FXint appendItem(FXHeaderItem* item,FXbool notify=FALSE);
00284 
00286   FXint appendItem(const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE);
00287 
00289   FXint prependItem(FXHeaderItem* item,FXbool notify=FALSE);
00290 
00292   FXint prependItem(const FXString& text,FXIcon *icon=NULL,FXint size=0,void* ptr=NULL,FXbool notify=FALSE);
00293 
00295   FXHeaderItem* extractItem(FXint index,FXbool notify=FALSE);
00296 
00298   void removeItem(FXint index,FXbool notify=FALSE);
00299 
00301   void clearItems(FXbool notify=FALSE);
00302 
00304   void setItemText(FXint index,const FXString& text);
00305 
00307   FXString getItemText(FXint index) const;
00308 
00310   void setItemIcon(FXint index,FXIcon* icon);
00311 
00313   FXIcon* getItemIcon(FXint index) const;
00314 
00316   void setItemSize(FXint index,FXint size);
00317 
00319   FXint getItemSize(FXint index) const;
00320 
00322   FXint getItemOffset(FXint index) const;
00323 
00325   void setItemData(FXint index,void* ptr);
00326 
00328   void* getItemData(FXint index) const;
00329 
00331   void setArrowDir(FXint index,FXbool dir=MAYBE);
00332 
00334   FXbool getArrowDir(FXint index) const;
00335 
00343   void setItemJustify(FXint index,FXuint justify);
00344 
00346   FXuint getItemJustify(FXint index) const;
00347 
00355   void setItemIconPosition(FXint index,FXuint mode);
00356 
00358   FXuint getItemIconPosition(FXint index) const;
00359 
00361   void setItemPressed(FXint index,FXbool pressed=TRUE);
00362 
00364   FXbool isItemPressed(FXint index) const;
00365 
00367   void makeItemVisible(FXint index);
00368 
00370   void updateItem(FXint index) const;
00371 
00373   void setFont(FXFont* fnt);
00374 
00376   FXFont* getFont() const { return font; }
00377 
00379   FXColor getTextColor() const { return textColor; }
00380 
00382   void setTextColor(FXColor clr);
00383 
00385   void setHeaderStyle(FXuint style);
00386 
00388   FXuint getHeaderStyle() const;
00389 
00391   void setHelpText(const FXString& text);
00392 
00394   const FXString& getHelpText() const { return help; }
00395 
00397   virtual void save(FXStream& store) const;
00398 
00400   virtual void load(FXStream& store);
00401 
00403   virtual ~FXHeader();
00404   };
00405 
00406 #ifdef _MSC_VER
00407 #pragma warning(pop)
00408 #endif
00409 
00410 }
00411 
00412 #endif

(C) 2002-2009 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Nov 20 18:31:22 2009 for TnFOX by doxygen v1.4.7