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

FXButton.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                           B u t t o n   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: FXButton.h,v 1.38 2006/01/22 17:57:59 fox Exp $                          *
00023 ********************************************************************************/
00024 #ifndef FXBUTTON_H
00025 #define FXBUTTON_H
00026 
00027 #ifndef FXLABEL_H
00028 #include "FXLabel.h"
00029 #endif
00030 
00031 namespace FX {
00032 
00033 
00034 /// Button state bits
00035 enum {
00036   STATE_UP        = 0,      /// Button is up
00037   STATE_DOWN      = 1,      /// Button is down
00038   STATE_ENGAGED   = 2,      /// Button is engaged
00039   STATE_UNCHECKED = STATE_UP,   /// Same as STATE_UP (used for check buttons or radio buttons)
00040   STATE_CHECKED   = STATE_ENGAGED /// Same as STATE_ENGAGED (used for check buttons or radio buttons)
00041   };
00042 
00043 
00044 /// Button flags
00045 enum {
00046   BUTTON_AUTOGRAY  = 0x00800000,  /// Automatically gray out when not updated
00047   BUTTON_AUTOHIDE  = 0x01000000,  /// Automatically hide button when not updated
00048   BUTTON_TOOLBAR   = 0x02000000,  /// Toolbar style button [flat look]
00049   BUTTON_DEFAULT   = 0x04000000,  /// May become default button when receiving focus
00050   BUTTON_INITIAL   = 0x08000000,  /// This button is the initial default button
00051   BUTTON_NORMAL    = (FRAME_RAISED|FRAME_THICK|JUSTIFY_NORMAL|ICON_BEFORE_TEXT)
00052   };
00053 
00054 
00055 /**
00056 * A button provides a push button, with optional icon and/or text label.
00057 * When pressed, the button widget sends a SEL_COMMAND to its target.
00058 * Passing the BUTTON_TOOLBAR style option gives buttons a "flat" look, and
00059 * causes the edge of the button to be raised when the cursor moves over it.
00060 * Passing BUTTON_DEFAULT allows the button to become the default button in
00061 * a dialog, when the focus moves to it.  The default widget in a dialog
00062 * is the widget which will accept the RETURN key when it is pressed.
00063 * The BUTTON_INITIAL flag makes the button the default widget when the
00064 * focus moves to a widget which can not itself be a default widget.
00065 * There should be only a single button in the dialog which is the
00066 * initial default; typically this is the OK or CLOSE button.
00067 * The option BUTTON_AUTOGRAY (BUTTON_AUTOHIDE) causes the button to be grayed
00068 * out (hidden) if its handler does not respond to the SEL_UPDATE message.
00069 * This is useful when messages are delegated, for example when using a
00070 * multiple document interface, where the ultimaye destination of a message
00071 * can be changed.
00072 */
00073 class FXAPI FXButton : public FXLabel {
00074   FXDECLARE(FXButton)
00075 protected:
00076   FXuchar  state;
00077 protected:
00078   FXButton();
00079 private:
00080   FXButton(const FXButton&);
00081   FXButton& operator=(const FXButton&);
00082 public:
00083   long onPaint(FXObject*,FXSelector,void*);
00084   long onUpdate(FXObject*,FXSelector,void*);
00085   long onEnter(FXObject*,FXSelector,void*);
00086   long onLeave(FXObject*,FXSelector,void*);
00087   long onFocusIn(FXObject*,FXSelector,void*);
00088   long onFocusOut(FXObject*,FXSelector,void*);
00089   long onUngrabbed(FXObject*,FXSelector,void*);
00090   long onLeftBtnPress(FXObject*,FXSelector,void*);
00091   long onLeftBtnRelease(FXObject*,FXSelector,void*);
00092   long onKeyPress(FXObject*,FXSelector,void*);
00093   long onKeyRelease(FXObject*,FXSelector,void*);
00094   long onHotKeyPress(FXObject*,FXSelector,void*);
00095   long onHotKeyRelease(FXObject*,FXSelector,void*);
00096   long onCheck(FXObject*,FXSelector,void*);
00097   long onUncheck(FXObject*,FXSelector,void*);
00098   long onCmdSetValue(FXObject*,FXSelector,void*);
00099   long onCmdSetIntValue(FXObject*,FXSelector,void*);
00100   long onCmdGetIntValue(FXObject*,FXSelector,void*);
00101 public:
00102 
00103   /// Construct button with text and icon
00104   FXButton(FXComposite* p,const FXString& text,FXIcon* ic=NULL,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=BUTTON_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);
00105 
00106   /// Returns true because a button can receive focus
00107   virtual bool canFocus() const;
00108 
00109   /// Move the focus to this window
00110   virtual void setFocus();
00111 
00112   /// Remove the focus from this window
00113   virtual void killFocus();
00114 
00115   /// Set as default button
00116   virtual void setDefault(FXbool enable=TRUE);
00117 
00118   /// Set the button state
00119   void setState(FXuint s);
00120 
00121   /// Get the button state
00122   FXuint getState() const { return state; }
00123 
00124   /// Set the button style flags
00125   void setButtonStyle(FXuint style);
00126 
00127   /// Get the button style flags
00128   FXuint getButtonStyle() const;
00129 
00130   };
00131 
00132 }
00133 
00134 #endif

Copyright © 1997-2005 Jeroen van der Zijp