]>
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;
132 // only for wxMenuBar
133 void Attach(wxMenuBar
*menubar
);
139 // This is used when m_hMenu is NULL because we don't want to
140 // delete it in ~wxMenu (it's been added to a parent menu).
141 // But we'll still need the handle for other purposes.
142 // Might be better to have a flag saying whether it's deleteable or not.
143 WXHMENU m_savehMenu
; // Used for Enable() on popup
145 wxFunction m_callback
;
149 wxMenu
* m_topLevelMenu
;
150 wxMenuBar
* m_menuBar
;
152 wxEvtHandler
* m_parent
;
153 wxEvtHandler
* m_eventHandler
;
154 wxWindow
*m_pInvokingWindow
;
158 // ----------------------------------------------------------------------------
159 // Menu Bar (a la Windows)
160 // ----------------------------------------------------------------------------
162 class WXDLLEXPORT wxMenuBar
: public wxEvtHandler
164 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
168 // default constructor
171 wxMenuBar(long style
);
172 // menubar takes ownership of the menus arrays but copies the titles
173 wxMenuBar(int n
, wxMenu
*menus
[], const wxString titles
[]);
174 virtual ~wxMenuBar();
176 // menubar construction
178 void Append(wxMenu
*menu
, const wxString
& title
);
179 virtual void Delete(wxMenu
*menu
, int index
= 0); /* Menu not destroyed */
182 // NB: must only be used AFTER menu has been attached to frame,
183 // otherwise use individual menus to enable/disable items
185 void Enable(int id
, bool enable
);
186 // TRUE if item enabled
187 bool IsEnabled(int id
) const;
189 void EnableTop(int pos
, bool enable
);
191 // works only with checkable items
192 void Check(int id
, bool check
);
194 bool IsChecked(int id
) const;
196 void SetLabel(int id
, const wxString
& label
) ;
197 wxString
GetLabel(int id
) const ;
199 virtual void SetHelpString(int id
, const wxString
& helpString
);
200 virtual wxString
GetHelpString(int id
) const ;
202 void SetLabelTop(int pos
, const wxString
& label
) ;
203 wxString
GetLabelTop(int pos
) const ;
205 // notifications: return FALSE to prevent the menu from being
207 virtual bool OnAppend(wxMenu
*menu
, const char *title
);
208 virtual bool OnDelete(wxMenu
*menu
, int index
);
211 // by menu and item names, returns wxNOT_FOUND if not found
212 virtual int FindMenuItem(const wxString
& menuString
,
213 const wxString
& itemString
) const;
214 // returns NULL if not found
215 wxMenuItem
* FindItem(int id
) const { return FindItemForId(id
); }
216 // returns NULL if not found, fills menuForItem if !NULL
217 wxMenuItem
*FindItemForId(int itemId
, wxMenu
**menuForItem
= NULL
) const;
220 int GetMenuCount() const { return m_menuCount
; }
221 wxMenu
*GetMenu(int i
) const { return m_menus
[i
]; }
223 void SetEventHandler(wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
224 wxEvtHandler
*GetEventHandler() { return m_eventHandler
; }
226 #ifdef WXWIN_COMPATIBILITY
227 // compatibility: these functions are deprecated
228 bool Enabled(int id
) const { return IsEnabled(id
); }
229 bool Checked(int id
) const { return IsChecked(id
); }
230 #endif // WXWIN_COMPATIBILITY
233 // returns TRUE if we're attached to a frame
234 bool IsAttached() const { return m_menuBarFrame
!= NULL
; }
235 // get the frame we live in
236 wxFrame
*GetFrame() const { return m_menuBarFrame
; }
238 void Attach(wxFrame
*frame
)
240 wxASSERT_MSG( !m_menuBarFrame
, "menubar already attached!" );
242 m_menuBarFrame
= frame
;
244 // get the menu handle
245 WXHMENU
GetHMenu() const { return m_hMenu
; }
248 // common part of all ctors
251 // if the menubar is modified, the display is not updated automatically,
252 // call this function to update it (m_menuBarFrame should be !NULL)
255 wxEvtHandler
*m_eventHandler
;
259 wxFrame
*m_menuBarFrame
;
263 #endif // _WX_MENU_H_