Some doc corrections (added blank lines at end of docs); corrected Forty sample
[wxWidgets.git] / include / wx / motif / menu.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: menu.h
3 // Purpose: wxMenu, wxMenuBar classes
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 17/09/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_MENU_H_
13 #define _WX_MENU_H_
14
15 #ifdef __GNUG__
16 #pragma interface "menu.h"
17 #endif
18
19 #include "wx/defs.h"
20 #include "wx/event.h"
21 #include "wx/font.h"
22 #include "wx/gdicmn.h"
23
24 class WXDLLEXPORT wxMenuItem;
25 class WXDLLEXPORT wxMenuBar;
26 class WXDLLEXPORT wxMenu;
27
28 WXDLLEXPORT_DATA(extern const char*) wxEmptyString;
29
30 // ----------------------------------------------------------------------------
31 // Menu
32 // ----------------------------------------------------------------------------
33 class WXDLLEXPORT wxMenu: public wxEvtHandler
34 {
35 DECLARE_DYNAMIC_CLASS(wxMenu)
36
37 public:
38 // ctor & dtor
39 wxMenu(const wxString& title = wxEmptyString, const wxFunction func = NULL);
40 ~wxMenu();
41
42 // construct menu
43 // append items to the menu
44 // separator line
45 void AppendSeparator();
46 // normal item
47 void Append(int id, const wxString& Label, const wxString& helpString = wxEmptyString,
48 bool checkable = FALSE);
49 // a submenu
50 void Append(int id, const wxString& Label, wxMenu *SubMenu,
51 const wxString& helpString = wxEmptyString);
52 // the most generic form (create wxMenuItem first and use it's functions)
53 void Append(wxMenuItem *pItem);
54 // insert a break in the menu
55 void Break();
56 // delete an item
57 void Delete(int id);
58
59 // menu item control
60 void Enable(int id, bool Flag);
61 bool Enabled(int id) const;
62 inline bool IsEnabled(int id) const { return Enabled(id); };
63 void Check(int id, bool Flag);
64 bool Checked(int id) const;
65 inline bool IsChecked(int id) const { return IsChecked(id); };
66
67 // Client data
68 inline void SetClientData(void* clientData) { m_clientData = clientData; }
69 inline void* GetClientData() const { return m_clientData; }
70
71 // item properties
72 // title
73 void SetTitle(const wxString& label);
74 const wxString GetTitle() const;
75 // label
76 void SetLabel(int id, const wxString& label);
77 wxString GetLabel(int id) const;
78 // help string
79 virtual void SetHelpString(int id, const wxString& helpString);
80 virtual wxString GetHelpString(int id) const ;
81
82 // find item
83 // Finds the item id matching the given string, -1 if not found.
84 virtual int FindItem(const wxString& itemString) const ;
85 // Find wxMenuItem by ID, and item's menu too if itemMenu is !NULL.
86 wxMenuItem *FindItemForId(int itemId, wxMenu **itemMenu = NULL) const;
87
88 // Updates the UI for a menu and all submenus recursively.
89 // source is the object that has the update event handlers
90 // defined for it. If NULL, the menu or associated window
91 // will be used.
92 void UpdateUI(wxEvtHandler* source = (wxEvtHandler*) NULL);
93
94 void ProcessCommand(wxCommandEvent& event);
95 inline void Callback(const wxFunction func) { m_callback = func; }
96
97 virtual void SetParent(wxEvtHandler *parent) { m_parent = parent; }
98 inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
99 inline wxEvtHandler *GetEventHandler() { return m_eventHandler; }
100
101 inline wxList& GetItems() const { return (wxList&) m_menuItems; }
102
103 void SetInvokingWindow(wxWindow *pWin) { m_pInvokingWindow = pWin; }
104 wxWindow *GetInvokingWindow() const { return m_pInvokingWindow; }
105
106 //// Motif-specific
107 inline WXWidget GetButtonWidget() const { return m_buttonWidget; }
108 inline void SetButtonWidget(WXWidget buttonWidget) { m_buttonWidget = buttonWidget; }
109 inline WXWidget GetMainWidget() const { return m_menuWidget; }
110 inline wxMenu* GetParent() const { return m_menuParent; }
111 inline int GetId() const { return m_menuId; }
112 inline void SetId(int id) { m_menuId = id; }
113 inline void SetMenuBar(wxMenuBar* menuBar) { m_menuBar = menuBar; }
114 inline wxMenuBar* GetMenuBar() const { return m_menuBar; }
115
116 void CreatePopup (WXWidget logicalParent, int x, int y);
117 void DestroyPopup (void);
118 void ShowPopup (int x, int y);
119 void HidePopup (void);
120
121 WXWidget CreateMenu(wxMenuBar *menuBar, WXWidget parent, wxMenu *topMenu,
122 const wxString& title = "", bool isPulldown = FALSE);
123
124 // For popups, need to destroy, then recreate menu for a different (or
125 // possibly same) window, since the parent may change.
126 void DestroyMenu(bool full);
127 WXWidget FindMenuItem(int id, wxMenuItem **it = NULL) const;
128
129 const wxColour& GetBackgroundColour() const { return m_backgroundColour; }
130 const wxColour& GetForegroundColour() const { return m_foregroundColour; }
131 const wxFont& GetFont() const { return m_font; }
132
133 void SetBackgroundColour(const wxColour& colour);
134 void SetForegroundColour(const wxColour& colour);
135 void SetFont(const wxFont& colour);
136 void ChangeFont(bool keepOriginalSize = FALSE);
137
138 public:
139 wxFunction m_callback;
140
141 int m_noItems;
142 wxString m_title;
143 wxMenuBar * m_menuBar;
144 wxList m_menuItems;
145 wxEvtHandler * m_parent;
146 wxEvtHandler * m_eventHandler;
147 void* m_clientData;
148 wxWindow* m_pInvokingWindow;
149
150 //// Motif-specific
151 int m_numColumns;
152 WXWidget m_menuWidget;
153 WXWidget m_popupShell; // For holding the popup shell widget
154 WXWidget m_buttonWidget; // The actual string, so we can grey it etc.
155 int m_menuId;
156 wxMenu* m_topLevelMenu ;
157 wxMenu* m_menuParent;
158 bool m_ownedByMenuBar;
159 wxColour m_foregroundColour;
160 wxColour m_backgroundColour;
161 wxFont m_font;
162 };
163
164 // ----------------------------------------------------------------------------
165 // Menu Bar (a la Windows)
166 // ----------------------------------------------------------------------------
167 class WXDLLEXPORT wxFrame;
168 class WXDLLEXPORT wxMenuBar: public wxEvtHandler
169 {
170 DECLARE_DYNAMIC_CLASS(wxMenuBar)
171
172 wxMenuBar( long style );
173 wxMenuBar();
174 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
175 ~wxMenuBar();
176
177 void Append(wxMenu *menu, const wxString& title);
178 // Must only be used AFTER menu has been attached to frame,
179 // otherwise use individual menus to enable/disable items
180 void Enable(int Id, bool Flag);
181 bool Enabled(int Id) const ;
182 inline bool IsEnabled(int Id) const { return Enabled(Id); };
183 void EnableTop(int pos, bool Flag);
184 void Check(int id, bool Flag);
185 bool Checked(int id) const ;
186 inline bool IsChecked(int Id) const { return Checked(Id); };
187 void SetLabel(int id, const wxString& label) ;
188 wxString GetLabel(int id) const ;
189 void SetLabelTop(int pos, const wxString& label) ;
190 wxString GetLabelTop(int pos) const ;
191 virtual void Delete(wxMenu *menu, int index = 0); /* Menu not destroyed */
192 virtual bool OnAppend(wxMenu *menu, const char *title);
193 virtual bool OnDelete(wxMenu *menu, int index);
194
195 virtual void SetHelpString(int Id, const wxString& helpString);
196 virtual wxString GetHelpString(int Id) const ;
197
198 virtual int FindMenuItem(const wxString& menuString, const wxString& itemString) const ;
199
200 // Find wxMenuItem for item ID, and return item's
201 // menu too if itemMenu is non-NULL.
202 wxMenuItem *FindItemForId(int itemId, wxMenu **menuForItem = NULL) const ;
203
204 inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
205 inline wxEvtHandler *GetEventHandler() { return m_eventHandler; }
206
207 inline int GetMenuCount() const { return m_menuCount; }
208 inline wxMenu* GetMenu(int i) const { return m_menus[i]; }
209
210 //// Motif-specific
211 inline wxFrame* GetMenuBarFrame() const { return m_menuBarFrame; }
212 inline void SetMenuBarFrame(wxFrame* frame) { m_menuBarFrame = frame; }
213 inline WXWidget GetMainWidget() const { return m_mainWidget; }
214 inline void SetMainWidget(WXWidget widget) { m_mainWidget = widget; }
215
216 // Create menubar
217 bool CreateMenuBar(wxFrame* frame);
218
219 // Destroy menubar, but keep data structures intact so we can recreate it.
220 bool DestroyMenuBar();
221
222 const wxColour& GetBackgroundColour() const { return m_backgroundColour; }
223 const wxColour& GetForegroundColour() const { return m_foregroundColour; }
224 const wxFont& GetFont() const { return m_font; }
225
226 void SetBackgroundColour(const wxColour& colour);
227 void SetForegroundColour(const wxColour& colour);
228 void SetFont(const wxFont& colour);
229 void ChangeFont(bool keepOriginalSize = FALSE);
230
231 public:
232 wxEvtHandler * m_eventHandler;
233 int m_menuCount;
234 wxMenu ** m_menus;
235 wxString * m_titles;
236 wxFrame * m_menuBarFrame;
237
238 //// Motif-specific
239 WXWidget m_mainWidget;
240
241 wxColour m_foregroundColour;
242 wxColour m_backgroundColour;
243 wxFont m_font;
244 };
245
246 #endif // _WX_MENU_H_