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

FXToggleButton.h

00001 /********************************************************************************
00002 *                                                                               *
00003 *                   T o g g l e    B u t t o n    W i d g e t                   *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1998,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: FXToggleButton.h,v 1.22 2002/09/30 13:06:56 fox Exp $                    *
00023 ********************************************************************************/
00024 #ifndef FXTOGGLEBUTTON_H
00025 #define FXTOGGLEBUTTON_H
00026 
00027 #ifndef FXLABEL_H
00028 #include "FXLabel.h"
00029 #endif
00030 
00031 namespace FX {
00032 
00033 
00034 /// Toggle button flags
00035 enum {
00036   TOGGLEBUTTON_AUTOGRAY = 0x00800000,       /// Automatically gray out when not updated
00037   TOGGLEBUTTON_AUTOHIDE = 0x01000000,       /// Automatically hide toggle button when not updated
00038   TOGGLEBUTTON_TOOLBAR  = 0x02000000,       /// Toolbar style toggle button [flat look]
00039   TOGGLEBUTTON_NORMAL   = FRAME_RAISED|FRAME_THICK|JUSTIFY_NORMAL|ICON_BEFORE_TEXT
00040   };
00041 
00042 
00043 /**
00044 * The toggle button provides a two-state button, which toggles between the
00045 * on and the off state each time it is pressed.  For each state, the toggle
00046 * button has a unique icon and text label.
00047 * When pressed, the button widget sends a SEL_COMMAND to its target, with the
00048 * message data set to the current state of the toggle button, of the type FXbool.
00049 */
00050 class FXAPI FXToggleButton : public FXLabel {
00051   FXDECLARE(FXToggleButton)
00052 protected:
00053   FXString  altlabel;
00054   FXIcon   *alticon;
00055   FXHotKey  althotkey;
00056   FXint     althotoff;
00057   FXString  alttip;
00058   FXString  althelp;
00059   FXbool    state;
00060   FXbool    down;
00061 protected:
00062   FXToggleButton();
00063   void press(FXbool dn);
00064 private:
00065   FXToggleButton(const FXToggleButton&);
00066   FXToggleButton& operator=(const FXToggleButton&);
00067 public:
00068   long onPaint(FXObject*,FXSelector,void*);
00069   long onUpdate(FXObject*,FXSelector,void*);
00070   long onEnter(FXObject*,FXSelector,void*);
00071   long onLeave(FXObject*,FXSelector,void*);
00072   long onFocusIn(FXObject*,FXSelector,void*);
00073   long onFocusOut(FXObject*,FXSelector,void*);
00074   long onUngrabbed(FXObject*,FXSelector,void*);
00075   long onLeftBtnPress(FXObject*,FXSelector,void*);
00076   long onLeftBtnRelease(FXObject*,FXSelector,void*);
00077   long onKeyPress(FXObject*,FXSelector,void*);
00078   long onKeyRelease(FXObject*,FXSelector,void*);
00079   long onHotKeyPress(FXObject*,FXSelector,void*);
00080   long onHotKeyRelease(FXObject*,FXSelector,void*);
00081   long onCheck(FXObject*,FXSelector,void*);
00082   long onUncheck(FXObject*,FXSelector,void*);
00083   long onQueryHelp(FXObject*,FXSelector,void*);
00084   long onQueryTip(FXObject*,FXSelector,void*);
00085   long onCmdSetValue(FXObject*,FXSelector,void*);
00086   long onCmdSetIntValue(FXObject*,FXSelector,void*);
00087   long onCmdGetIntValue(FXObject*,FXSelector,void*);
00088 public:
00089 
00090   /// Construct toggle button with two text labels, and two icons, one for each state
00091   FXToggleButton(FXComposite* p,const FXString& text1,const FXString& text2,FXIcon* icon1=NULL,FXIcon* icon2=NULL,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=TOGGLEBUTTON_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);
00092 
00093   /// Create server-side resources
00094   virtual void create();
00095 
00096   /// Detach server-side resources
00097   virtual void detach();
00098 
00099   /// Returns true because a toggle button can receive focus
00100   virtual FXbool canFocus() const;
00101 
00102   /// Get default width
00103   virtual FXint getDefaultWidth();
00104 
00105   /// Get default height
00106   virtual FXint getDefaultHeight();
00107 
00108   /// Change alternate text shown when toggled
00109   void setAltText(const FXString& text);
00110 
00111   /// Return alternate text
00112   const FXString& getAltText() const { return altlabel; }
00113 
00114   /// Change alternate icon shown when toggled
00115   void setAltIcon(FXIcon* ic);
00116 
00117   /// Return alternate icon
00118   FXIcon* getAltIcon() const { return alticon; }
00119 
00120   /// Change toggled state
00121   void setState(FXbool s=TRUE);
00122 
00123   /// return toggled state
00124   FXbool getState() const { return state; }
00125 
00126   /// Change alternate help text shown when toggled
00127   void setAltHelpText(const FXString& text);
00128 
00129   /// Return alternate help text
00130   const FXString& getAltHelpText() const { return althelp; }
00131 
00132   /// Change alternate tip text shown when toggled
00133   void setAltTipText(const FXString& text);
00134 
00135   /// Return alternate tip text
00136   const FXString& getAltTipText() const { return alttip; }
00137 
00138   /// Set the toggle button style flags
00139   void setToggleStyle(FXuint style);
00140 
00141   /// Get the toggle button style flags
00142   FXuint getToggleStyle() const;
00143 
00144   /// Save toggle button to a stream
00145   virtual void save(FXStream& store) const;
00146 
00147   /// Load toggle button from a stream
00148   virtual void load(FXStream& store);
00149 
00150   /// Destructor
00151   virtual ~FXToggleButton();
00152   };
00153 
00154 }
00155 
00156 #endif