]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/menu.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenu, wxMenuBar classes
4 // Author: Julian Smart
5 // Modified by: Vadim Zeitlin (wxMenuItem is now in separate file)
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "menu.h"
22 class WXDLLEXPORT wxMenuItem
;
23 class WXDLLEXPORT wxMenuBar
;
24 class WXDLLEXPORT wxMenu
;
25 class WXDLLEXPORT wxFrame
;
27 WXDLLEXPORT_DATA(extern const char*) wxEmptyString
;
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 class WXDLLEXPORT wxMenu
: public wxEvtHandler
35 DECLARE_DYNAMIC_CLASS(wxMenu
)
39 wxMenu(const wxString
& title
= wxEmptyString
, const wxFunction func
= NULL
);
43 // append a separator to the menu
44 void AppendSeparator();
45 // append a normal item to the menu
46 void Append(int id
, const wxString
& label
,
47 const wxString
& helpString
= wxEmptyString
,
48 bool checkable
= FALSE
);
50 void Append(int id
, const wxString
& label
,
52 const wxString
& helpString
= wxEmptyString
);
53 // append anything (create wxMenuItem first)
54 void Append(wxMenuItem
*pItem
);
56 // insert a break in the menu
60 // If it's a submenu, menu is not destroyed.
61 // VZ: why? shouldn't it return "wxMenu *" then?
65 void SetClientData(void* clientData
) { m_clientData
= clientData
; }
66 void* GetClientData() const { return m_clientData
; }
69 // enable/disable item
70 void Enable(int id
, bool enable
);
72 bool IsEnabled(int id
) const;
74 // check/uncheck item - only for checkable items, of course
75 void Check(int id
, bool check
);
77 bool IsChecked(int id
) const;
81 void SetTitle(const wxString
& label
);
82 const wxString
GetTitle() const;
84 void SetLabel(int id
, const wxString
& label
);
85 wxString
GetLabel(int id
) const;
87 virtual void SetHelpString(int id
, const wxString
& helpString
);
88 virtual wxString
GetHelpString(int id
) const;
90 // get the list of items
91 wxList
& GetItems() const { return (wxList
&)m_menuItems
; }
94 // returns id of the item matching the given string or wxNOT_FOUND
95 virtual int FindItem(const wxString
& itemString
) const;
96 // returns NULL if not found
97 wxMenuItem
* FindItem(int id
) const { return FindItemForId(id
); }
98 // find wxMenuItem by ID, and item's menu too if itemMenu is !NULL
99 wxMenuItem
*FindItemForId(int itemId
, wxMenu
**itemMenu
= NULL
) const;
101 // Updates the UI for a menu and all submenus recursively. source is the
102 // object that has the update event handlers defined for it. If NULL, the
103 // menu or associated window will be used.
104 void UpdateUI(wxEvtHandler
* source
= (wxEvtHandler
*)NULL
);
106 void ProcessCommand(wxCommandEvent
& event
);
108 virtual void SetParent(wxEvtHandler
*parent
) { m_parent
= parent
; }
109 void SetEventHandler(wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
110 wxEvtHandler
*GetEventHandler() const { return m_eventHandler
; }
112 #ifdef WXWIN_COMPATIBILITY
113 void Callback(const wxFunction func
) { m_callback
= func
; }
115 // compatibility: these functions are deprecated
116 bool Enabled(int id
) const { return IsEnabled(id
); }
117 bool Checked(int id
) const { return IsChecked(id
); }
118 #endif // WXWIN_COMPATIBILITY
121 bool MSWCommand(WXUINT param
, WXWORD id
);
123 void SetInvokingWindow(wxWindow
*pWin
) { m_pInvokingWindow
= pWin
; }
124 wxWindow
*GetInvokingWindow() const { return m_pInvokingWindow
; }
126 // semi-private accessors
127 // get the window which contains this menu
128 wxWindow
*GetWindow() const;
129 // get the menu handle
130 WXHMENU
GetHMenu() const;
136 // This is used when m_hMenu is NULL because we don't want to
137 // delete it in ~wxMenu (it's been added to a parent menu).
138 // But we'll still need the handle for other purposes.
139 // Might be better to have a flag saying whether it's deleteable or not.
140 WXHMENU m_savehMenu
; // Used for Enable() on popup
142 wxFunction m_callback
;
146 wxMenu
* m_topLevelMenu
;
147 wxMenuBar
* m_menuBar
;
149 wxEvtHandler
* m_parent
;
150 wxEvtHandler
* m_eventHandler
;
151 wxWindow
*m_pInvokingWindow
;
155 // ----------------------------------------------------------------------------
156 // Menu Bar (a la Windows)
157 // ----------------------------------------------------------------------------
159 class WXDLLEXPORT wxMenuBar
: public wxEvtHandler
161 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
166 wxMenuBar(long style
);
167 wxMenuBar(int n
, wxMenu
*menus
[], const wxString titles
[]);
168 virtual ~wxMenuBar();
170 // menubar construction
171 void Append(wxMenu
*menu
, const wxString
& title
);
172 virtual void Delete(wxMenu
*menu
, int index
= 0); /* Menu not destroyed */
175 // NB: must only be used AFTER menu has been attached to frame,
176 // otherwise use individual menus to enable/disable items
178 void Enable(int id
, bool enable
);
179 // TRUE if item enabled
180 bool IsEnabled(int id
) const;
182 void EnableTop(int pos
, bool enable
);
184 // works only with checkable items
185 void Check(int id
, bool check
);
187 bool IsChecked(int id
) const;
189 void SetLabel(int id
, const wxString
& label
) ;
190 wxString
GetLabel(int id
) const ;
192 virtual void SetHelpString(int id
, const wxString
& helpString
);
193 virtual wxString
GetHelpString(int id
) const ;
195 void SetLabelTop(int pos
, const wxString
& label
) ;
196 wxString
GetLabelTop(int pos
) const ;
199 virtual bool OnAppend(wxMenu
*menu
, const char *title
);
200 virtual bool OnDelete(wxMenu
*menu
, int index
);
203 // by menu and item names, returns wxNOT_FOUND if not found
204 virtual int FindMenuItem(const wxString
& menuString
,
205 const wxString
& itemString
) const;
206 // returns NULL if not found
207 wxMenuItem
* FindItem(int id
) const { return FindItemForId(id
); }
208 // returns NULL if not found, fills menuForItem if !NULL
209 wxMenuItem
*FindItemForId(int itemId
, wxMenu
**menuForItem
= NULL
) const;
212 int GetMenuCount() const { return m_menuCount
; }
213 wxMenu
*GetMenu(int i
) const { return m_menus
[i
]; }
215 void SetEventHandler(wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
216 wxEvtHandler
*GetEventHandler() { return m_eventHandler
; }
218 #ifdef WXWIN_COMPATIBILITY
219 // compatibility: these functions are deprecated
220 bool Enabled(int id
) const { return IsEnabled(id
); }
221 bool Checked(int id
) const { return IsChecked(id
); }
222 #endif // WXWIN_COMPATIBILITY
225 wxEvtHandler
* m_eventHandler
;
229 wxFrame
* m_menuBarFrame
;
233 #endif // _WX_MENU_H_