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

FXMenuButton.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * M e n u 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: FXMenuButton.h,v 1.24 2006/01/22 17:58:06 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXMENUBUTTON_H
25 #define FXMENUBUTTON_H
26 
27 #ifndef FXLABEL_H
28 #include "FXLabel.h"
29 #endif
30 
31 namespace FX {
32 
33 
34 class FXPopup;
35 
36 
37 // Menu button options
38 enum {
39  MENUBUTTON_AUTOGRAY = 0x00800000, /// Automatically gray out when no target
40  MENUBUTTON_AUTOHIDE = 0x01000000, /// Automatically hide when no target
41  MENUBUTTON_TOOLBAR = 0x02000000, /// Toolbar style
42  MENUBUTTON_DOWN = 0, /// Popup window appears below menu button
43  MENUBUTTON_UP = 0x04000000, /// Popup window appears above menu button
44  MENUBUTTON_LEFT = 0x08000000, /// Popup window to the left of the menu button
45  MENUBUTTON_RIGHT = MENUBUTTON_LEFT|MENUBUTTON_UP, /// Popup window to the right of the menu button
46  MENUBUTTON_NOARROWS = 0x10000000, /// Do not show arrows
47  MENUBUTTON_ATTACH_LEFT = 0, /// Popup attaches to the left side of the menu button
48  MENUBUTTON_ATTACH_TOP = MENUBUTTON_ATTACH_LEFT, /// Popup attaches to the top of the menu button
49  MENUBUTTON_ATTACH_RIGHT = 0x20000000, /// Popup attaches to the right side of the menu button
50  MENUBUTTON_ATTACH_BOTTOM = MENUBUTTON_ATTACH_RIGHT, /// Popup attaches to the bottom of the menu button
51  MENUBUTTON_ATTACH_CENTER = 0x40000000, /// Popup attaches to the center of the menu button
52  MENUBUTTON_ATTACH_BOTH = MENUBUTTON_ATTACH_CENTER|MENUBUTTON_ATTACH_RIGHT /// Popup attaches to both sides of the menu button
53  };
54 
55 
56 
57 /**
58 * A menu button posts a popup menu when clicked.
59 * There are many ways to control the placement where the popup will appear;
60 * first, the popup may be placed on either of the four sides relative to the
61 * menu button; this is controlled by the flags MENUBUTTON_DOWN, etc.
62 * Next, there are several attachment modes; the popup's left/bottom edge may
63 * attach to the menu button's left/top edge, or the popup's right/top edge may
64 * attach to the menu button's right/bottom edge, or both.
65 * Also, the popup may apear centered relative to the menu button.
66 * Finally, a small offset may be specified to displace the location of the
67 * popup by a few pixels so as to account for borders and so on.
68 * Normally, the menu button shows an arrow pointing to the direction where
69 * the popup is set to appear; this can be turned off by passing the option
70 * MENUBUTTON_NOARROWS.
71 */
72 class FXAPI FXMenuButton : public FXLabel {
74 protected:
75  FXPopup *pane; // Pane to pop up
76  FXint offsetx; // Shift attachment point x
77  FXint offsety; // Shift attachment point y
78  FXbool state; // Pane was popped
79 protected:
80  FXMenuButton();
81 private:
82  FXMenuButton(const FXMenuButton&);
83  FXMenuButton &operator=(const FXMenuButton&);
84 public:
85  long onPaint(FXObject*,FXSelector,void*);
86  long onUpdate(FXObject*,FXSelector,void*);
87  long onEnter(FXObject*,FXSelector,void*);
88  long onLeave(FXObject*,FXSelector,void*);
89  long onFocusIn(FXObject*,FXSelector,void*);
90  long onFocusOut(FXObject*,FXSelector,void*);
91  long onUngrabbed(FXObject*,FXSelector,void*);
92  long onMotion(FXObject*,FXSelector,void*);
93  long onLeftBtnPress(FXObject*,FXSelector,void*);
94  long onLeftBtnRelease(FXObject*,FXSelector,void*);
95  long onKeyPress(FXObject*,FXSelector,void*);
96  long onKeyRelease(FXObject*,FXSelector,void*);
97  long onHotKeyPress(FXObject*,FXSelector,void*);
98  long onHotKeyRelease(FXObject*,FXSelector,void*);
99  long onCmdPost(FXObject*,FXSelector,void*);
100  long onCmdUnpost(FXObject*,FXSelector,void*);
101 public:
102 
103  /// Constructor
105 
106  /// Create server-side resources
107  virtual void create();
108 
109  /// Detach server-side resources
110  virtual void detach();
111 
112  /// Return default width
113  virtual FXint getDefaultWidth();
114 
115  /// Return default height
116  virtual FXint getDefaultHeight();
117 
118  /// Returns true because a menu button can receive focus
119  virtual bool canFocus() const;
120 
121  /// Remove the focus from this window
122  virtual void killFocus();
123 
124  /// Return true if window logically contains the given point
125  virtual bool contains(FXint parentx,FXint parenty) const;
126 
127  /// Change the popup menu
128  void setMenu(FXPopup *pup);
129 
130  /// Return current popup menu
131  FXPopup* getMenu() const { return pane; }
132 
133  /// Set X offset where menu pops up relative to button
134  void setXOffset(FXint offx){ offsetx=offx; }
135 
136  /// Return current X offset
137  FXint getXOffset() const { return offsetx; }
138 
139  /// Set Y offset where menu pops up relative to button
140  void setYOffset(FXint offy){ offsety=offy; }
141 
142  /// Return current Y offset
143  FXint getYOffset() const { return offsety; }
144 
145  /// Change menu button style
146  void setButtonStyle(FXuint style);
147 
148  /// Get menu button style
149  FXuint getButtonStyle() const;
150 
151  /// Change popup style
152  void setPopupStyle(FXuint style);
153 
154  /// Get popup style
155  FXuint getPopupStyle() const;
156 
157  /// Change attachment
158  void setAttachment(FXuint att);
159 
160  /// Get attachment
161  FXuint getAttachment() const;
162 
163  /// Save menu button to a stream
164  virtual void save(FXStream& store) const;
165 
166  /// Load menu button from a stream
167  virtual void load(FXStream& store);
168 
169  /// Destructor
170  virtual ~FXMenuButton();
171  };
172 
173 }
174 
175 #endif
A menu button posts a popup menu when clicked.
Definition: FXMenuButton.h:79
Toolbar style.
Definition: FXMenuButton.h:44
A label widget can be used to place a text and/or icon for explanation purposes.
Definition: FXLabel.h:79
unsigned int FXuint
Definition: fxdefs.h:396
Popup window.
Definition: FXPopup.h:52
Popup window to the right of the menu button.
Definition: FXMenuButton.h:48
Definition: FXFrame.h:56
FXuint FXSelector
Association key.
Definition: FXObject.h:53
Do not show arrows.
Definition: FXMenuButton.h:49
#define FXAPI
Definition: fxdefs.h:122
FXuchar FXbool
Definition: fxdefs.h:393
Base composite.
Definition: FXComposite.h:35
#define NULL
Definition: fxdefs.h:41
Popup window to the left of the menu button.
Definition: FXMenuButton.h:47
Automatically gray out when no target.
Definition: FXMenuButton.h:42
Popup attaches to both sides of the menu button.
Definition: FXMenuButton.h:55
Definition: FX4Splitter.h:31
int FXint
Definition: fxdefs.h:397
An Icon is an image with two additional server-side resources: a shape bitmap, which is used to mask ...
Definition: FXIcon.h:45
Popup attaches to the top of the menu button.
Definition: FXMenuButton.h:51
Popup window appears below menu button.
Definition: FXMenuButton.h:45
Popup attaches to the center of the menu button.
Definition: FXMenuButton.h:54
Popup attaches to the right side of the menu button.
Definition: FXMenuButton.h:52
Popup attaches to the left side of the menu button.
Definition: FXMenuButton.h:50
Object is the base class for all objects in FOX; in order to receive messages from the user interface...
Definition: FXObject.h:166
Popup attaches to the bottom of the menu button.
Definition: FXMenuButton.h:53
Automatically hide when no target.
Definition: FXMenuButton.h:43
Popup window appears above menu button.
Definition: FXMenuButton.h:46
Icon appears before text (to its left)
Definition: FXLabel.h:41
Default justification is centered text.
Definition: FXFrame.h:39
#define FXDECLARE(classname)
Macro to set up class declaration.
Definition: FXObject.h:92
FXString provides essential string manipulation capabilities.
Definition: FXString.h:33

Copyright © 1997-2005 Jeroen van der Zijp