1 /******************************************************************************** 2 * * 3 * B u t t o n W i d g e t * 4 * * 5 ********************************************************************************* 6 * Copyright (C) 1997,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: FXButton.h 3297 2015-12-14 20:30:04Z arthurcnorman $ * 23 ********************************************************************************/ 24 #ifndef FXBUTTON_H 25 #define FXBUTTON_H 26 27 #ifndef FXLABEL_H 28 #include "FXLabel.h" 29 #endif 30 31 namespace FX { 32 33 34 /// Button state bits 35 enum { 36 STATE_UP = 0, /// Button is up 37 STATE_DOWN = 1, /// Button is down 38 STATE_ENGAGED = 2, /// Button is engaged 39 STATE_UNCHECKED = STATE_UP, /// Same as STATE_UP (used for check buttons or radio buttons) 40 STATE_CHECKED = STATE_ENGAGED /// Same as STATE_ENGAGED (used for check buttons or radio buttons) 41 }; 42 43 44 /// Button flags 45 enum { 46 BUTTON_AUTOGRAY = 0x00800000, /// Automatically gray out when not updated 47 BUTTON_AUTOHIDE = 0x01000000, /// Automatically hide button when not updated 48 BUTTON_TOOLBAR = 0x02000000, /// Toolbar style button [flat look] 49 BUTTON_DEFAULT = 0x04000000, /// May become default button when receiving focus 50 BUTTON_INITIAL = 0x08000000, /// This button is the initial default button 51 BUTTON_NORMAL = (FRAME_RAISED|FRAME_THICK|JUSTIFY_NORMAL|ICON_BEFORE_TEXT) 52 }; 53 54 55 /** 56 * A button provides a push button, with optional icon and/or text label. 57 * When pressed, the button widget sends a SEL_COMMAND to its target. 58 * Passing the BUTTON_TOOLBAR style option gives buttons a "flat" look, and 59 * causes the edge of the button to be raised when the cursor moves over it. 60 * Passing BUTTON_DEFAULT allows the button to become the default button in 61 * a dialog, when the focus moves to it. The default widget in a dialog 62 * is the widget which will accept the RETURN key when it is pressed. 63 * The BUTTON_INITIAL flag makes the button the default widget when the 64 * focus moves to a widget which can not itself be a default widget. 65 * There should be only a single button in the dialog which is the 66 * initial default; typically this is the OK or CLOSE button. 67 * The option BUTTON_AUTOGRAY (BUTTON_AUTOHIDE) causes the button to be grayed 68 * out (hidden) if its handler does not respond to the SEL_UPDATE message. 69 * This is useful when messages are delegated, for example when using a 70 * multiple document interface, where the ultimaye destination of a message 71 * can be changed. 72 */ 73 class FXAPI FXButton : public FXLabel { 74 FXDECLARE(FXButton) 75 protected: 76 FXuchar state; 77 protected: 78 FXButton(); 79 private: 80 FXButton(const FXButton&); 81 FXButton& operator=(const FXButton&); 82 public: 83 long onPaint(FXObject*,FXSelector,void*); 84 long onUpdate(FXObject*,FXSelector,void*); 85 long onEnter(FXObject*,FXSelector,void*); 86 long onLeave(FXObject*,FXSelector,void*); 87 long onFocusIn(FXObject*,FXSelector,void*); 88 long onFocusOut(FXObject*,FXSelector,void*); 89 long onUngrabbed(FXObject*,FXSelector,void*); 90 long onLeftBtnPress(FXObject*,FXSelector,void*); 91 long onLeftBtnRelease(FXObject*,FXSelector,void*); 92 long onKeyPress(FXObject*,FXSelector,void*); 93 long onKeyRelease(FXObject*,FXSelector,void*); 94 long onHotKeyPress(FXObject*,FXSelector,void*); 95 long onHotKeyRelease(FXObject*,FXSelector,void*); 96 long onCheck(FXObject*,FXSelector,void*); 97 long onUncheck(FXObject*,FXSelector,void*); 98 long onCmdSetValue(FXObject*,FXSelector,void*); 99 long onCmdSetIntValue(FXObject*,FXSelector,void*); 100 long onCmdGetIntValue(FXObject*,FXSelector,void*); 101 public: 102 103 /// Construct button with text and icon 104 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); 105 106 /// Returns true because a button can receive focus 107 virtual bool canFocus() const; 108 109 /// Move the focus to this window 110 virtual void setFocus(); 111 112 /// Remove the focus from this window 113 virtual void killFocus(); 114 115 /// Set as default button 116 virtual void setDefault(FXbool enable=TRUE); 117 118 /// Set the button state 119 void setState(FXuint s); 120 121 /// Get the button state getState()122 FXuint getState() const { return state; } 123 124 /// Set the button style flags 125 void setButtonStyle(FXuint style); 126 127 /// Get the button style flags 128 FXuint getButtonStyle() const; 129 130 }; 131 132 } 133 134 #endif 135