]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: menu.h | |
3 | // Purpose: wxMenu, wxMenuBar classes | |
4 | // Author: Julian Smart | |
5 | // Modified by: Vadim Zeitlin (wxMenuItem is now in separate file) | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef __MENUH__ | |
13 | #define __MENUH__ | |
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 wxMenuItem; | |
23 | class wxMenuBar; | |
24 | class 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); /* If it's a submenu, menu is not destroyed. VZ: why? */ | |
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 | // item properties | |
66 | // title | |
67 | void SetTitle(const wxString& label); | |
68 | const wxString& GetTitle() const; | |
69 | // label | |
70 | void SetLabel(int id, const wxString& label); | |
71 | wxString GetLabel(int id) const; | |
72 | // help string | |
debe6624 JS |
73 | virtual void SetHelpString(int id, const wxString& helpString); |
74 | virtual wxString GetHelpString(int id) const ; | |
2bda0e17 KB |
75 | |
76 | // find item | |
77 | // Finds the item id matching the given string, NOT_FOUND if not found. | |
78 | virtual int FindItem(const wxString& itemString) const ; | |
79 | // Find wxMenuItem by ID, and item's menu too if itemMenu is !NULL. | |
debe6624 | 80 | wxMenuItem *FindItemForId(int itemId, wxMenu **itemMenu = NULL) const; |
2bda0e17 KB |
81 | |
82 | void ProcessCommand(wxCommandEvent& event); | |
83 | inline void Callback(const wxFunction func) { m_callback = func; } | |
84 | ||
85 | virtual void SetParent(wxEvtHandler *parent) { m_parent = parent; } | |
86 | inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; } | |
87 | inline wxEvtHandler *GetEventHandler(void) { return m_eventHandler; } | |
88 | ||
527fc629 JS |
89 | inline wxList& GetItems() const { return (wxList&) m_menuItems; } |
90 | ||
2bda0e17 | 91 | // IMPLEMENTATION |
debe6624 | 92 | bool MSWCommand(WXUINT param, WXWORD id); |
2bda0e17 KB |
93 | |
94 | void SetInvokingWindow(wxWindow *pWin) { m_pInvokingWindow = pWin; } | |
95 | wxWindow *GetInvokingWindow() const { return m_pInvokingWindow; } | |
96 | ||
97 | // semi-private accessors | |
98 | // get the window which contains this menu | |
99 | wxWindow *GetWindow() const; | |
100 | // get the menu handle | |
101 | WXHMENU GetHMenu() const; | |
102 | ||
103 | private: | |
104 | bool m_doBreak ; | |
105 | ||
106 | public: | |
107 | // This is used when m_hMenu is NULL because we don't want to | |
108 | // delete it in ~wxMenu (it's been added to a parent menu). | |
109 | // But we'll still need the handle for other purposes. | |
110 | // Might be better to have a flag saying whether it's deleteable or not. | |
111 | WXHMENU m_savehMenu ; // Used for Enable() on popup | |
112 | WXHMENU m_hMenu; | |
113 | wxFunction m_callback; | |
114 | ||
115 | int m_noItems; | |
116 | wxString m_title; | |
117 | wxMenu * m_topLevelMenu; | |
118 | wxMenuBar * m_menuBar; | |
119 | wxList m_menuItems; | |
120 | wxEvtHandler * m_parent; | |
121 | wxEvtHandler * m_eventHandler; | |
122 | wxWindow *m_pInvokingWindow; | |
123 | }; | |
124 | ||
125 | // ---------------------------------------------------------------------------- | |
126 | // Menu Bar (a la Windows) | |
127 | // ---------------------------------------------------------------------------- | |
128 | class wxFrame; | |
129 | class WXDLLEXPORT wxMenuBar: public wxEvtHandler | |
130 | { | |
131 | DECLARE_DYNAMIC_CLASS(wxMenuBar) | |
132 | ||
133 | wxMenuBar(void); | |
debe6624 | 134 | wxMenuBar(int n, wxMenu *menus[], const wxString titles[]); |
2bda0e17 KB |
135 | ~wxMenuBar(void); |
136 | ||
137 | void Append(wxMenu *menu, const wxString& title); | |
138 | // Must only be used AFTER menu has been attached to frame, | |
139 | // otherwise use individual menus to enable/disable items | |
debe6624 JS |
140 | void Enable(int Id, bool Flag); |
141 | bool Enabled(int Id) const ; | |
142 | inline bool IsEnabled(int Id) const { return Enabled(Id); }; | |
143 | void EnableTop(int pos, bool Flag); | |
144 | void Check(int id, bool Flag); | |
145 | bool Checked(int id) const ; | |
146 | inline bool IsChecked(int Id) const { return Checked(Id); }; | |
147 | void SetLabel(int id, const wxString& label) ; | |
148 | wxString GetLabel(int id) const ; | |
149 | void SetLabelTop(int pos, const wxString& label) ; | |
150 | wxString GetLabelTop(int pos) const ; | |
151 | virtual void Delete(wxMenu *menu, int index = 0); /* Menu not destroyed */ | |
2bda0e17 | 152 | virtual bool OnAppend(wxMenu *menu, const char *title); |
debe6624 | 153 | virtual bool OnDelete(wxMenu *menu, int index); |
2bda0e17 | 154 | |
debe6624 JS |
155 | virtual void SetHelpString(int Id, const wxString& helpString); |
156 | virtual wxString GetHelpString(int Id) const ; | |
2bda0e17 KB |
157 | |
158 | virtual int FindMenuItem(const wxString& menuString, const wxString& itemString) const ; | |
159 | ||
160 | // Find wxMenuItem for item ID, and return item's | |
161 | // menu too if itemMenu is non-NULL. | |
debe6624 | 162 | wxMenuItem *FindItemForId(int itemId, wxMenu **menuForItem = NULL) const ; |
2bda0e17 KB |
163 | |
164 | inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; } | |
165 | inline wxEvtHandler *GetEventHandler(void) { return m_eventHandler; } | |
166 | ||
527fc629 JS |
167 | inline int GetMenuCount() const { return m_menuCount; } |
168 | inline wxMenu* GetMenu(int i) const { return m_menus[i]; } | |
169 | ||
2bda0e17 KB |
170 | public: |
171 | wxEvtHandler * m_eventHandler; | |
172 | int m_menuCount; | |
173 | wxMenu ** m_menus; | |
174 | wxString * m_titles; | |
175 | wxFrame * m_menuBarFrame; | |
176 | WXHMENU m_hMenu; | |
177 | }; | |
178 | ||
179 | #endif // __MENUH__ |