]>
Commit | Line | Data |
---|---|---|
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 | ||
22 | class WXDLLEXPORT wxMenuItem; | |
23 | class WXDLLEXPORT wxMenuBar; | |
24 | class WXDLLEXPORT wxMenu; | |
25 | ||
26 | WXDLLEXPORT_DATA(extern const char*) wxEmptyString; | |
27 | ||
28 | // ---------------------------------------------------------------------------- | |
29 | // Menu | |
30 | // ---------------------------------------------------------------------------- | |
31 | class WXDLLEXPORT wxMenu: public wxEvtHandler | |
32 | { | |
33 | DECLARE_DYNAMIC_CLASS(wxMenu) | |
34 | ||
35 | public: | |
36 | // ctor & dtor | |
37 | wxMenu(const wxString& title = wxEmptyString, const wxFunction func = NULL); | |
38 | ~wxMenu(); | |
39 | ||
40 | // construct menu | |
41 | // append items to the menu | |
42 | // separator line | |
43 | void AppendSeparator(); | |
44 | // normal item | |
45 | void Append(int id, const wxString& Label, const wxString& helpString = wxEmptyString, | |
46 | bool checkable = FALSE); | |
47 | // a submenu | |
48 | void Append(int id, const wxString& Label, wxMenu *SubMenu, | |
49 | const wxString& helpString = wxEmptyString); | |
50 | // the most generic form (create wxMenuItem first and use it's functions) | |
51 | void Append(wxMenuItem *pItem); | |
52 | // insert a break in the menu | |
53 | void Break(); | |
54 | // delete an item | |
55 | void Delete(int id); | |
56 | ||
57 | // menu item control | |
58 | void Enable(int id, bool Flag); | |
59 | bool Enabled(int id) const; | |
60 | inline bool IsEnabled(int id) const { return Enabled(id); }; | |
61 | void Check(int id, bool Flag); | |
62 | bool Checked(int id) const; | |
63 | inline bool IsChecked(int id) const { return IsChecked(id); }; | |
64 | ||
65 | // Client data | |
66 | inline void SetClientData(void* clientData) { m_clientData = clientData; } | |
67 | inline void* GetClientData() const { return m_clientData; } | |
68 | ||
69 | // item properties | |
70 | // title | |
71 | void SetTitle(const wxString& label); | |
72 | const wxString GetTitle() const; | |
73 | // label | |
74 | void SetLabel(int id, const wxString& label); | |
75 | wxString GetLabel(int id) const; | |
76 | // help string | |
77 | virtual void SetHelpString(int id, const wxString& helpString); | |
78 | virtual wxString GetHelpString(int id) const ; | |
79 | ||
80 | // find item | |
81 | // Finds the item id matching the given string, -1 if not found. | |
82 | virtual int FindItem(const wxString& itemString) const ; | |
83 | // Find wxMenuItem by ID, and item's menu too if itemMenu is !NULL. | |
84 | wxMenuItem *FindItemForId(int itemId, wxMenu **itemMenu = NULL) const; | |
85 | ||
86 | void ProcessCommand(wxCommandEvent& event); | |
87 | inline void Callback(const wxFunction func) { m_callback = func; } | |
88 | ||
89 | virtual void SetParent(wxEvtHandler *parent) { m_parent = parent; } | |
90 | inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; } | |
91 | inline wxEvtHandler *GetEventHandler() { return m_eventHandler; } | |
92 | ||
93 | inline wxList& GetItems() const { return (wxList&) m_menuItems; } | |
94 | ||
95 | //// Motif-specific | |
96 | inline WXWidget GetButtonWidget() const { return m_buttonWidget; } | |
97 | inline void SetButtonWidget(WXWidget buttonWidget) { m_buttonWidget = buttonWidget; } | |
98 | inline WXWidget GetMainWidget() const { return m_menuWidget; } | |
99 | inline wxMenu* GetParent() const { return m_menuParent; } | |
100 | inline int GetId() const { return m_menuId; } | |
101 | inline void SetId(int id) { m_menuId = id; } | |
102 | inline void SetMenuBar(wxMenuBar* menuBar) { m_menuBar = menuBar; } | |
103 | inline wxMenuBar* GetMenuBar() const { return m_menuBar; } | |
104 | ||
105 | void CreatePopup (WXWidget logicalParent, int x, int y); | |
106 | void DestroyPopup (void); | |
107 | void ShowPopup (int x, int y); | |
108 | void HidePopup (void); | |
109 | ||
110 | WXWidget CreateMenu(wxMenuBar *menuBar, WXWidget parent, wxMenu *topMenu, | |
111 | const wxString& title = "", bool isPulldown = FALSE); | |
112 | ||
113 | // For popups, need to destroy, then recreate menu for a different (or | |
114 | // possibly same) window, since the parent may change. | |
115 | void DestroyMenu(bool full); | |
116 | WXWidget FindMenuItem(int id, wxMenuItem **it = NULL) const; | |
117 | ||
118 | public: | |
119 | wxFunction m_callback; | |
120 | ||
121 | int m_noItems; | |
122 | wxString m_title; | |
123 | wxMenuBar * m_menuBar; | |
124 | wxList m_menuItems; | |
125 | wxEvtHandler * m_parent; | |
126 | wxEvtHandler * m_eventHandler; | |
127 | void* m_clientData; | |
128 | ||
129 | //// Motif-specific | |
130 | int m_numColumns; | |
131 | WXWidget m_menuWidget; | |
132 | WXWidget m_popupShell; // For holding the popup shell widget | |
133 | WXWidget m_buttonWidget; // The actual string, so we can grey it etc. | |
134 | int m_menuId; | |
135 | wxMenu* m_topLevelMenu ; | |
136 | wxMenu* m_menuParent; | |
137 | bool m_ownedByMenuBar; | |
138 | }; | |
139 | ||
140 | // ---------------------------------------------------------------------------- | |
141 | // Menu Bar (a la Windows) | |
142 | // ---------------------------------------------------------------------------- | |
143 | class WXDLLEXPORT wxFrame; | |
144 | class WXDLLEXPORT wxMenuBar: public wxEvtHandler | |
145 | { | |
146 | DECLARE_DYNAMIC_CLASS(wxMenuBar) | |
147 | ||
148 | wxMenuBar(); | |
149 | wxMenuBar(int n, wxMenu *menus[], const wxString titles[]); | |
150 | ~wxMenuBar(); | |
151 | ||
152 | void Append(wxMenu *menu, const wxString& title); | |
153 | // Must only be used AFTER menu has been attached to frame, | |
154 | // otherwise use individual menus to enable/disable items | |
155 | void Enable(int Id, bool Flag); | |
156 | bool Enabled(int Id) const ; | |
157 | inline bool IsEnabled(int Id) const { return Enabled(Id); }; | |
158 | void EnableTop(int pos, bool Flag); | |
159 | void Check(int id, bool Flag); | |
160 | bool Checked(int id) const ; | |
161 | inline bool IsChecked(int Id) const { return Checked(Id); }; | |
162 | void SetLabel(int id, const wxString& label) ; | |
163 | wxString GetLabel(int id) const ; | |
164 | void SetLabelTop(int pos, const wxString& label) ; | |
165 | wxString GetLabelTop(int pos) const ; | |
166 | virtual void Delete(wxMenu *menu, int index = 0); /* Menu not destroyed */ | |
167 | virtual bool OnAppend(wxMenu *menu, const char *title); | |
168 | virtual bool OnDelete(wxMenu *menu, int index); | |
169 | ||
170 | virtual void SetHelpString(int Id, const wxString& helpString); | |
171 | virtual wxString GetHelpString(int Id) const ; | |
172 | ||
173 | virtual int FindMenuItem(const wxString& menuString, const wxString& itemString) const ; | |
174 | ||
175 | // Find wxMenuItem for item ID, and return item's | |
176 | // menu too if itemMenu is non-NULL. | |
177 | wxMenuItem *FindItemForId(int itemId, wxMenu **menuForItem = NULL) const ; | |
178 | ||
179 | inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; } | |
180 | inline wxEvtHandler *GetEventHandler() { return m_eventHandler; } | |
181 | ||
182 | inline int GetMenuCount() const { return m_menuCount; } | |
183 | inline wxMenu* GetMenu(int i) const { return m_menus[i]; } | |
184 | ||
185 | //// Motif-specific | |
186 | inline wxFrame* GetMenuBarFrame() const { return m_menuBarFrame; } | |
187 | inline void SetMenuBarFrame(wxFrame* frame) { m_menuBarFrame = frame; } | |
188 | inline WXWidget GetMainWidget() const { return m_mainWidget; } | |
189 | inline void SetMainWidget(WXWidget widget) { m_mainWidget = widget; } | |
190 | ||
191 | public: | |
192 | wxEvtHandler * m_eventHandler; | |
193 | int m_menuCount; | |
194 | wxMenu ** m_menus; | |
195 | wxString * m_titles; | |
196 | wxFrame * m_menuBarFrame; | |
197 | ||
198 | //// Motif-specific | |
199 | WXWidget m_mainWidget; | |
200 | ||
201 | }; | |
202 | ||
203 | #endif // _WX_MENU_H_ |