]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/menu.h
no message
[wxWidgets.git] / include / wx / msw / menu.h
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 _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); /* If it's a submenu, menu is not destroyed. VZ: why? */
56
57 // Client data
58 inline void SetClientData(void* clientData) { m_clientData = clientData; }
59 inline void* GetClientData() const { return m_clientData; }
60
61 // menu item control
62 void Enable(int id, bool Flag);
63 bool Enabled(int id) const;
64 inline bool IsEnabled(int id) const { return Enabled(id); };
65 void Check(int id, bool Flag);
66 bool Checked(int id) const;
67 inline bool IsChecked(int id) const { return Checked(id); };
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, NOT_FOUND 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 // IMPLEMENTATION
96 bool MSWCommand(WXUINT param, WXWORD id);
97
98 void SetInvokingWindow(wxWindow *pWin) { m_pInvokingWindow = pWin; }
99 wxWindow *GetInvokingWindow() const { return m_pInvokingWindow; }
100
101 // semi-private accessors
102 // get the window which contains this menu
103 wxWindow *GetWindow() const;
104 // get the menu handle
105 WXHMENU GetHMenu() const;
106
107 private:
108 bool m_doBreak ;
109
110 public:
111 // This is used when m_hMenu is NULL because we don't want to
112 // delete it in ~wxMenu (it's been added to a parent menu).
113 // But we'll still need the handle for other purposes.
114 // Might be better to have a flag saying whether it's deleteable or not.
115 WXHMENU m_savehMenu ; // Used for Enable() on popup
116 WXHMENU m_hMenu;
117 wxFunction m_callback;
118
119 int m_noItems;
120 wxString m_title;
121 wxMenu * m_topLevelMenu;
122 wxMenuBar * m_menuBar;
123 wxList m_menuItems;
124 wxEvtHandler * m_parent;
125 wxEvtHandler * m_eventHandler;
126 wxWindow *m_pInvokingWindow;
127 void* m_clientData;
128 };
129
130 // ----------------------------------------------------------------------------
131 // Menu Bar (a la Windows)
132 // ----------------------------------------------------------------------------
133 class WXDLLEXPORT wxFrame;
134 class WXDLLEXPORT wxMenuBar: public wxEvtHandler
135 {
136 DECLARE_DYNAMIC_CLASS(wxMenuBar)
137
138 public:
139 wxMenuBar();
140 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
141 ~wxMenuBar();
142
143 void Append(wxMenu *menu, const wxString& title);
144 // Must only be used AFTER menu has been attached to frame,
145 // otherwise use individual menus to enable/disable items
146 void Enable(int Id, bool Flag);
147 bool Enabled(int Id) const ;
148 inline bool IsEnabled(int Id) const { return Enabled(Id); };
149 void EnableTop(int pos, bool Flag);
150 void Check(int id, bool Flag);
151 bool Checked(int id) const ;
152 inline bool IsChecked(int Id) const { return Checked(Id); };
153 void SetLabel(int id, const wxString& label) ;
154 wxString GetLabel(int id) const ;
155 void SetLabelTop(int pos, const wxString& label) ;
156 wxString GetLabelTop(int pos) const ;
157 virtual void Delete(wxMenu *menu, int index = 0); /* Menu not destroyed */
158 virtual bool OnAppend(wxMenu *menu, const char *title);
159 virtual bool OnDelete(wxMenu *menu, int index);
160
161 virtual void SetHelpString(int Id, const wxString& helpString);
162 virtual wxString GetHelpString(int Id) const ;
163
164 virtual int FindMenuItem(const wxString& menuString, const wxString& itemString) const ;
165
166 // Find wxMenuItem for item ID, and return item's
167 // menu too if itemMenu is non-NULL.
168 wxMenuItem *FindItemForId(int itemId, wxMenu **menuForItem = NULL) const ;
169
170 inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
171 inline wxEvtHandler *GetEventHandler() { return m_eventHandler; }
172
173 inline int GetMenuCount() const { return m_menuCount; }
174 inline wxMenu* GetMenu(int i) const { return m_menus[i]; }
175
176 public:
177 wxEvtHandler * m_eventHandler;
178 int m_menuCount;
179 wxMenu ** m_menus;
180 wxString * m_titles;
181 wxFrame * m_menuBarFrame;
182 WXHMENU m_hMenu;
183 };
184
185 #endif // _WX_MENU_H_