1 /********************************************************************************
2 *                                                                               *
3 *                   T o g g l e    B u t t o n    W i d g e t                   *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 1998,2006 by Jeroen van der Zijp.   All Rights Reserved.        *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or                 *
9 * modify it under the terms of the GNU Lesser General Public                    *
10 * License as published by the Free Software Foundation; either                  *
11 * version 2.1 of the License, or (at your option) any later version.            *
12 *                                                                               *
13 * This library is distributed in the hope that it will be useful,               *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
16 * Lesser General Public License for more details.                               *
17 *                                                                               *
18 * You should have received a copy of the GNU Lesser General Public              *
19 * License along with this library; if not, write to the Free Software           *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
21 *********************************************************************************
22 * $Id: FXToggleButton.h,v 1.30 2006/01/22 17:58:11 fox Exp $                    *
23 ********************************************************************************/
24 #ifndef FXTOGGLEBUTTON_H
25 #define FXTOGGLEBUTTON_H
26 
27 #ifndef FXLABEL_H
28 #include "FXLabel.h"
29 #endif
30 
31 namespace FX {
32 
33 
34 /// Toggle button flags
35 enum {
36   TOGGLEBUTTON_AUTOGRAY = 0x00800000,       /// Automatically gray out when not updated
37   TOGGLEBUTTON_AUTOHIDE = 0x01000000,       /// Automatically hide toggle button when not updated
38   TOGGLEBUTTON_TOOLBAR  = 0x02000000,       /// Toolbar style toggle button [flat look]
39   TOGGLEBUTTON_KEEPSTATE= 0x04000000,       /// Draw button according to state
40   TOGGLEBUTTON_NORMAL   = FRAME_RAISED|FRAME_THICK|JUSTIFY_NORMAL|ICON_BEFORE_TEXT
41   };
42 
43 
44 /**
45 * The toggle button provides a two-state button, which toggles between the
46 * on and the off state each time it is pressed.  For each state, the toggle
47 * button has a unique icon and text label.
48 * When pressed, the button widget sends a SEL_COMMAND to its target, with the
49 * message data set to the current state of the toggle button, of the type FXbool.
50 */
51 class FXAPI FXToggleButton : public FXLabel {
52   FXDECLARE(FXToggleButton)
53 protected:
54   FXString  altlabel;
55   FXIcon   *alticon;
56   FXHotKey  althotkey;
57   FXint     althotoff;
58   FXString  alttip;
59   FXString  althelp;
60   FXbool    state;
61   FXbool    down;
62 protected:
63   FXToggleButton();
64   void press(FXbool dn);
65 private:
66   FXToggleButton(const FXToggleButton&);
67   FXToggleButton& operator=(const FXToggleButton&);
68 public:
69   long onPaint(FXObject*,FXSelector,void*);
70   long onUpdate(FXObject*,FXSelector,void*);
71   long onEnter(FXObject*,FXSelector,void*);
72   long onLeave(FXObject*,FXSelector,void*);
73   long onFocusIn(FXObject*,FXSelector,void*);
74   long onFocusOut(FXObject*,FXSelector,void*);
75   long onUngrabbed(FXObject*,FXSelector,void*);
76   long onLeftBtnPress(FXObject*,FXSelector,void*);
77   long onLeftBtnRelease(FXObject*,FXSelector,void*);
78   long onKeyPress(FXObject*,FXSelector,void*);
79   long onKeyRelease(FXObject*,FXSelector,void*);
80   long onHotKeyPress(FXObject*,FXSelector,void*);
81   long onHotKeyRelease(FXObject*,FXSelector,void*);
82   long onCheck(FXObject*,FXSelector,void*);
83   long onUncheck(FXObject*,FXSelector,void*);
84   long onQueryHelp(FXObject*,FXSelector,void*);
85   long onQueryTip(FXObject*,FXSelector,void*);
86   long onCmdSetValue(FXObject*,FXSelector,void*);
87   long onCmdSetIntValue(FXObject*,FXSelector,void*);
88   long onCmdGetIntValue(FXObject*,FXSelector,void*);
89 public:
90 
91   /// Construct toggle button with two text labels, and two icons, one for each state
92   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);
93 
94   /// Create server-side resources
95   virtual void create();
96 
97   /// Detach server-side resources
98   virtual void detach();
99 
100   /// Returns true because a toggle button can receive focus
101   virtual bool canFocus() const;
102 
103   /// Get default width
104   virtual FXint getDefaultWidth();
105 
106   /// Get default height
107   virtual FXint getDefaultHeight();
108 
109   /// Change alternate text shown when toggled
110   void setAltText(const FXString& text);
111 
112   /// Return alternate text
getAltText()113   FXString getAltText() const { return altlabel; }
114 
115   /// Change alternate icon shown when toggled
116   void setAltIcon(FXIcon* ic);
117 
118   /// Return alternate icon
getAltIcon()119   FXIcon* getAltIcon() const { return alticon; }
120 
121   /// Change toggled state
122   void setState(FXbool s=TRUE,FXbool notify=FALSE);
123 
124   /// return toggled state
getState()125   FXbool getState() const { return state; }
126 
127   /// Change alternate help text shown when toggled
128   void setAltHelpText(const FXString& text);
129 
130   /// Return alternate help text
getAltHelpText()131   FXString getAltHelpText() const { return althelp; }
132 
133   /// Change alternate tip text shown when toggled
134   void setAltTipText(const FXString& text);
135 
136   /// Return alternate tip text
getAltTipText()137   FXString getAltTipText() const { return alttip; }
138 
139   /// Set the toggle button style flags
140   void setToggleStyle(FXuint style);
141 
142   /// Get the toggle button style flags
143   FXuint getToggleStyle() const;
144 
145   /// Save toggle button to a stream
146   virtual void save(FXStream& store) const;
147 
148   /// Load toggle button from a stream
149   virtual void load(FXStream& store);
150 
151   /// Destructor
152   virtual ~FXToggleButton();
153   };
154 
155 }
156 
157 #endif
158