]> git.saurik.com Git - wxWidgets.git/blob - include/wx/motif/menu.h
wxSplitterWindow::ReplaceWindow() function added and documented
[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();
173 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
174 ~wxMenuBar();
175
176 void Append(wxMenu *menu, const wxString& title);
177 // Must only be used AFTER menu has been attached to frame,
178 // otherwise use individual menus to enable/disable items
179 void Enable(int Id, bool Flag);
180 bool Enabled(int Id) const ;
181 inline bool IsEnabled(int Id) const { return Enabled(Id); };
182 void EnableTop(int pos, bool Flag);
183 void Check(int id, bool Flag);
184 bool Checked(int id) const ;
185 inline bool IsChecked(int Id) const { return Checked(Id); };
186 void SetLabel(int id, const wxString& label) ;
187 wxString GetLabel(int id) const ;
188 void SetLabelTop(int pos, const wxString& label) ;
189 wxString GetLabelTop(int pos) const ;
190 virtual void Delete(wxMenu *menu, int index = 0); /* Menu not destroyed */
191 virtual bool OnAppend(wxMenu *menu, const char *title);
192 virtual bool OnDelete(wxMenu *menu, int index);
193
194 virtual void SetHelpString(int Id, const wxString& helpString);
195 virtual wxString GetHelpString(int Id) const ;
196
197 virtual int FindMenuItem(const wxString& menuString, const wxString& itemString) const ;
198
199 // Find wxMenuItem for item ID, and return item's
200 // menu too if itemMenu is non-NULL.
201 wxMenuItem *FindItemForId(int itemId, wxMenu **menuForItem = NULL) const ;
202
203 inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
204 inline wxEvtHandler *GetEventHandler() { return m_eventHandler; }
205
206 inline int GetMenuCount() const { return m_menuCount; }
207 inline wxMenu* GetMenu(int i) const { return m_menus[i]; }
208
209 //// Motif-specific
210 inline wxFrame* GetMenuBarFrame() const { return m_menuBarFrame; }
211 inline void SetMenuBarFrame(wxFrame* frame) { m_menuBarFrame = frame; }
212 inline WXWidget GetMainWidget() const { return m_mainWidget; }
213 inline void SetMainWidget(WXWidget widget) { m_mainWidget = widget; }
214
215 // Create menubar
216 bool CreateMenuBar(wxFrame* frame);
217
218 // Destroy menubar, but keep data structures intact so we can recreate it.
219 bool DestroyMenuBar();
220
221 const wxColour& GetBackgroundColour() const { return m_backgroundColour; }
222 const wxColour& GetForegroundColour() const { return m_foregroundColour; }
223 const wxFont& GetFont() const { return m_font; }
224
225 void SetBackgroundColour(const wxColour& colour);
226 void SetForegroundColour(const wxColour& colour);
227 void SetFont(const wxFont& colour);
228 void ChangeFont(bool keepOriginalSize = FALSE);
229
230 public:
231 wxEvtHandler * m_eventHandler;
232 int m_menuCount;
233 wxMenu ** m_menus;
234 wxString * m_titles;
235 wxFrame * m_menuBarFrame;
236
237 //// Motif-specific
238 WXWidget m_mainWidget;
239
240 wxColour m_foregroundColour;
241 wxColour m_backgroundColour;
242 wxFont m_font;
243 };
244
245 #endif // _WX_MENU_H_