1 /******************************************************************************** 2 * * 3 * O p t i o n M e n u * 4 * * 5 ********************************************************************************* 6 * Copyright (C) 1997,2021 by Jeroen van der Zijp. All Rights Reserved. * 7 ********************************************************************************* 8 * This library is free software; you can redistribute it and/or modify * 9 * it under the terms of the GNU Lesser General Public License as published by * 10 * the Free Software Foundation; either version 3 of the License, or * 11 * (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 * 16 * GNU Lesser General Public License for more details. * 17 * * 18 * You should have received a copy of the GNU Lesser General Public License * 19 * along with this program. If not, see <http://www.gnu.org/licenses/> * 20 ********************************************************************************/ 21 #ifndef FXOPTIONMENU_H 22 #define FXOPTIONMENU_H 23 24 #ifndef FXLABEL_H 25 #include "FXLabel.h" 26 #endif 27 28 namespace FX { 29 30 31 class FXPopup; 32 33 34 /// Option Menu Button flags 35 enum { 36 OPTIONMENU_TOOLBAR = 0x00800000, /// Toolbar style button [flat look] 37 OPTIONMENU_NOGLYPH = 0x01000000, /// Do not display a glyph 38 }; 39 40 41 /// Option Menu Button 42 class FXAPI FXOption : public FXLabel { 43 FXDECLARE(FXOption) 44 protected: 45 FXColor selbackColor; 46 FXColor seltextColor; 47 protected: 48 FXOption(); 49 private: 50 FXOption(const FXOption&); 51 FXOption &operator=(const FXOption&); 52 public: 53 long onPaint(FXObject*,FXSelector,void*); 54 long onEnter(FXObject*,FXSelector,void*); 55 long onLeave(FXObject*,FXSelector,void*); 56 long onLeftBtnPress(FXObject*,FXSelector,void*); 57 long onLeftBtnRelease(FXObject*,FXSelector,void*); 58 long onKeyPress(FXObject*,FXSelector,void*); 59 long onKeyRelease(FXObject*,FXSelector,void*); 60 long onHotKeyPress(FXObject*,FXSelector,void*); 61 long onHotKeyRelease(FXObject*,FXSelector,void*); 62 public: 63 64 /// Constructor 65 FXOption(FXComposite* p,const FXString& text,FXIcon* ic=NULL,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=JUSTIFY_NORMAL|ICON_BEFORE_TEXT,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); 66 67 /// Return default width 68 virtual FXint getDefaultWidth(); 69 70 /// Return default height 71 virtual FXint getDefaultHeight(); 72 73 /// Returns true because a menu button can receive focus 74 virtual FXbool canFocus() const; 75 76 /// Set focus to this window 77 virtual void setFocus(); 78 79 /// Remove the focus from this window 80 virtual void killFocus(); 81 82 /// Return the selection background color 83 void setSelBackColor(FXColor clr); 84 85 /// Return the selection background color getSelBackColor()86 FXColor getSelBackColor() const { return selbackColor; } 87 88 /// Return the selection text color 89 void setSelTextColor(FXColor clr); 90 91 /// Return the selection text color getSelTextColor()92 FXColor getSelTextColor() const { return seltextColor; } 93 94 /// Destructor 95 virtual ~FXOption(); 96 }; 97 98 99 100 /// Option Menu 101 class FXAPI FXOptionMenu : public FXLabel { 102 FXDECLARE(FXOptionMenu) 103 protected: 104 FXPopup *pane; 105 FXOption *current; 106 protected: FXOptionMenu()107 FXOptionMenu(){} 108 private: 109 FXOptionMenu(const FXOptionMenu&); 110 FXOptionMenu &operator=(const FXOptionMenu&); 111 public: 112 long onPaint(FXObject*,FXSelector,void*); 113 long onLeftBtnPress(FXObject*,FXSelector,void*); 114 long onLeftBtnRelease(FXObject*,FXSelector,void*); 115 long onEnter(FXObject*,FXSelector,void*); 116 long onLeave(FXObject*,FXSelector,void*); 117 long onFocusIn(FXObject*,FXSelector,void*); 118 long onFocusOut(FXObject*,FXSelector,void*); 119 long onMotion(FXObject*,FXSelector,void*); 120 long onKeyPress(FXObject*,FXSelector,void*); 121 long onKeyRelease(FXObject*,FXSelector,void*); 122 long onCmdPost(FXObject*,FXSelector,void*); 123 long onCmdUnpost(FXObject*,FXSelector,void*); 124 long onQueryHelp(FXObject*,FXSelector,void*); 125 long onQueryTip(FXObject*,FXSelector,void*); 126 long onCmdSetValue(FXObject*,FXSelector,void*); 127 long onCmdSetIntValue(FXObject*,FXSelector,void*); 128 long onCmdGetIntValue(FXObject*,FXSelector,void*); 129 long onMouseWheel(FXObject*,FXSelector,void*); 130 public: 131 132 /// Constructor 133 FXOptionMenu(FXComposite* p,FXPopup* pup=NULL,FXuint opts=JUSTIFY_NORMAL|ICON_BEFORE_TEXT,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); 134 135 /// Create server-side resources 136 virtual void create(); 137 138 /// Detach server-side resources 139 virtual void detach(); 140 141 /// Delete server-side resources 142 virtual void destroy(); 143 144 /// Perform layout 145 virtual void layout(); 146 147 /// Remove the focus from this window 148 virtual void killFocus(); 149 150 /// Return default width 151 virtual FXint getDefaultWidth(); 152 153 /// Return default height 154 virtual FXint getDefaultHeight(); 155 156 /// Return true if the position is logically in the pane 157 virtual FXbool contains(FXint parentx,FXint parenty) const; 158 159 /// Return the option item at the given index 160 FXOption *getItem(FXint index) const; 161 162 /// Set the current option 163 void setCurrent(FXOption *win,FXbool notify=false); 164 165 /// Return the current option getCurrent()166 FXOption* getCurrent() const { return current; } 167 168 /// Set the current option number 169 void setCurrentNo(FXint no,FXbool notify=false); 170 171 /// Get the current option number 172 FXint getCurrentNo() const; 173 174 /// Get number of options 175 FXint getNumOptions() const; 176 177 /// Set the pane which will be popped up 178 void setMenu(FXPopup *pup); 179 180 /// Return the pane which is poppup up getMenu()181 FXPopup* getMenu() const { return pane; } 182 183 /// Returns true because a option menu can receive focus 184 virtual FXbool canFocus() const; 185 186 /// Return true if popped up 187 FXbool isPopped() const; 188 189 /// Save option menu to a stream 190 virtual void save(FXStream& store) const; 191 192 /// Load option menu from a stream 193 virtual void load(FXStream& store); 194 195 /// Destructor 196 virtual ~FXOptionMenu(); 197 }; 198 199 } 200 201 #endif 202