1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenu, wxMenuBar classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "menu.h"
22 #include "wx/gdicmn.h"
24 class WXDLLEXPORT wxMenuItem
;
25 class WXDLLEXPORT wxMenuBar
;
26 class WXDLLEXPORT wxMenu
;
28 WXDLLEXPORT_DATA(extern const char*) wxEmptyString
;
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
33 class WXDLLEXPORT wxMenu
: public wxEvtHandler
35 DECLARE_DYNAMIC_CLASS(wxMenu
)
39 #ifdef WXWIN_COMPATIBILITY
40 wxMenu( const wxString
& title
, const wxFunction func
)
44 #endif // WXWIN_COMPATIBILITY
45 wxMenu( const wxString
& title
= wxEmptyString
, long style
= 0 )
52 // append items to the menu
54 void AppendSeparator();
56 void Append(int id
, const wxString
& Label
, const wxString
& helpString
= wxEmptyString
,
57 bool checkable
= FALSE
);
59 void Append(int id
, const wxString
& Label
, wxMenu
*SubMenu
,
60 const wxString
& helpString
= wxEmptyString
);
61 // the most generic form (create wxMenuItem first and use it's functions)
62 void Append(wxMenuItem
*pItem
);
63 // insert a break in the menu
69 void Enable(int id
, bool Flag
);
70 bool Enabled(int id
) const;
71 bool IsEnabled(int id
) const { return Enabled(id
); };
72 void Check(int id
, bool Flag
);
73 bool Checked(int id
) const;
74 bool IsChecked(int id
) const { return IsChecked(id
); };
77 void SetClientData(void* clientData
) { m_clientData
= clientData
; }
78 void* GetClientData() const { return m_clientData
; }
82 void SetTitle(const wxString
& label
);
83 const wxString
GetTitle() const;
85 void SetLabel(int id
, const wxString
& label
);
86 wxString
GetLabel(int id
) const;
88 virtual void SetHelpString(int id
, const wxString
& helpString
);
89 virtual wxString
GetHelpString(int id
) const ;
92 // Finds the item id matching the given string, -1 if not found.
93 virtual int FindItem(const wxString
& itemString
) const ;
94 // Find wxMenuItem by ID, and item's menu too if itemMenu is !NULL.
95 wxMenuItem
*FindItemForId(int itemId
, wxMenu
**itemMenu
= NULL
) const;
97 // Updates the UI for a menu and all submenus recursively.
98 // source is the object that has the update event handlers
99 // defined for it. If NULL, the menu or associated window
101 void UpdateUI(wxEvtHandler
* source
= (wxEvtHandler
*) NULL
);
103 void ProcessCommand(wxCommandEvent
& event
);
105 #ifdef WXWIN_COMPATIBILITY
106 void Callback(const wxFunction func
) { m_callback
= func
; }
107 #endif // WXWIN_COMPATIBILITY
109 virtual void SetParent(wxEvtHandler
*parent
) { m_parent
= parent
; }
110 void SetEventHandler(wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
111 wxEvtHandler
*GetEventHandler() { return m_eventHandler
; }
113 wxList
& GetItems() const { return (wxList
&) m_menuItems
; }
115 void SetInvokingWindow(wxWindow
*pWin
) { m_pInvokingWindow
= pWin
; }
116 wxWindow
*GetInvokingWindow() const { return m_pInvokingWindow
; }
119 WXWidget
GetButtonWidget() const { return m_buttonWidget
; }
120 void SetButtonWidget(WXWidget buttonWidget
) { m_buttonWidget
= buttonWidget
; }
121 WXWidget
GetMainWidget() const { return m_menuWidget
; }
122 wxMenu
* GetParent() const { return m_menuParent
; }
123 int GetId() const { return m_menuId
; }
124 void SetId(int id
) { m_menuId
= id
; }
125 void SetMenuBar(wxMenuBar
* menuBar
) { m_menuBar
= menuBar
; }
126 wxMenuBar
* GetMenuBar() const { return m_menuBar
; }
128 void CreatePopup (WXWidget logicalParent
, int x
, int y
);
129 void DestroyPopup (void);
130 void ShowPopup (int x
, int y
);
131 void HidePopup (void);
133 WXWidget
CreateMenu(wxMenuBar
*menuBar
, WXWidget parent
, wxMenu
*topMenu
,
134 const wxString
& title
= "", bool isPulldown
= FALSE
);
136 // For popups, need to destroy, then recreate menu for a different (or
137 // possibly same) window, since the parent may change.
138 void DestroyMenu(bool full
);
139 WXWidget
FindMenuItem(int id
, wxMenuItem
**it
= NULL
) const;
141 const wxColour
& GetBackgroundColour() const { return m_backgroundColour
; }
142 const wxColour
& GetForegroundColour() const { return m_foregroundColour
; }
143 const wxFont
& GetFont() const { return m_font
; }
145 void SetBackgroundColour(const wxColour
& colour
);
146 void SetForegroundColour(const wxColour
& colour
);
147 void SetFont(const wxFont
& colour
);
148 void ChangeFont(bool keepOriginalSize
= FALSE
);
150 // implementation from now on
151 WXWidget
GetHandle() const { return m_menuWidget
; }
152 bool IsTearOff() const { return (m_style
& wxMENU_TEAROFF
) != 0; }
155 #ifdef WXWIN_COMPATIBILITY
156 wxFunction m_callback
;
157 #endif // WXWIN_COMPATIBILITY
161 wxMenuBar
* m_menuBar
;
163 wxEvtHandler
* m_parent
;
164 wxEvtHandler
* m_eventHandler
;
166 wxWindow
* m_pInvokingWindow
;
172 WXWidget m_menuWidget
;
173 WXWidget m_popupShell
; // For holding the popup shell widget
174 WXWidget m_buttonWidget
; // The actual string, so we can grey it etc.
176 wxMenu
* m_topLevelMenu
;
177 wxMenu
* m_menuParent
;
178 bool m_ownedByMenuBar
;
179 wxColour m_foregroundColour
;
180 wxColour m_backgroundColour
;
184 // common code for both constructors:
185 void Init( const wxString
& title
,
187 #ifdef WXWIN_COMPATIBILITY
188 , const wxFunction func
= (wxFunction
) NULL
193 // ----------------------------------------------------------------------------
194 // Menu Bar (a la Windows)
195 // ----------------------------------------------------------------------------
197 class WXDLLEXPORT wxFrame
;
198 class WXDLLEXPORT wxMenuBar
: public wxEvtHandler
200 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
203 wxMenuBar( long style
);
205 wxMenuBar(int n
, wxMenu
*menus
[], const wxString titles
[]);
208 void Append(wxMenu
*menu
, const wxString
& title
);
209 // Must only be used AFTER menu has been attached to frame,
210 // otherwise use individual menus to enable/disable items
211 void Enable(int Id
, bool Flag
);
212 bool Enabled(int Id
) const ;
213 bool IsEnabled(int Id
) const { return Enabled(Id
); };
214 void EnableTop(int pos
, bool Flag
);
215 void Check(int id
, bool Flag
);
216 bool Checked(int id
) const ;
217 bool IsChecked(int Id
) const { return Checked(Id
); };
218 void SetLabel(int id
, const wxString
& label
) ;
219 wxString
GetLabel(int id
) const ;
220 void SetLabelTop(int pos
, const wxString
& label
) ;
221 wxString
GetLabelTop(int pos
) const ;
222 virtual void Delete(wxMenu
*menu
, int index
= 0); /* Menu not destroyed */
223 virtual bool OnAppend(wxMenu
*menu
, const char *title
);
224 virtual bool OnDelete(wxMenu
*menu
, int index
);
226 virtual void SetHelpString(int Id
, const wxString
& helpString
);
227 virtual wxString
GetHelpString(int Id
) const ;
229 virtual int FindMenuItem(const wxString
& menuString
, const wxString
& itemString
) const ;
231 // Find wxMenuItem for item ID, and return item's
232 // menu too if itemMenu is non-NULL.
233 wxMenuItem
*FindItemForId(int itemId
, wxMenu
**menuForItem
= NULL
) const ;
235 void SetEventHandler(wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
236 wxEvtHandler
*GetEventHandler() { return m_eventHandler
; }
238 int GetMenuCount() const { return m_menuCount
; }
239 wxMenu
* GetMenu(int i
) const { return m_menus
[i
]; }
242 wxFrame
* GetMenuBarFrame() const { return m_menuBarFrame
; }
243 void SetMenuBarFrame(wxFrame
* frame
) { m_menuBarFrame
= frame
; }
244 WXWidget
GetMainWidget() const { return m_mainWidget
; }
245 void SetMainWidget(WXWidget widget
) { m_mainWidget
= widget
; }
248 bool CreateMenuBar(wxFrame
* frame
);
250 // Destroy menubar, but keep data structures intact so we can recreate it.
251 bool DestroyMenuBar();
253 const wxColour
& GetBackgroundColour() const { return m_backgroundColour
; }
254 const wxColour
& GetForegroundColour() const { return m_foregroundColour
; }
255 const wxFont
& GetFont() const { return m_font
; }
257 void SetBackgroundColour(const wxColour
& colour
);
258 void SetForegroundColour(const wxColour
& colour
);
259 void SetFont(const wxFont
& colour
);
260 void ChangeFont(bool keepOriginalSize
= FALSE
);
263 wxEvtHandler
* m_eventHandler
;
267 wxFrame
* m_menuBarFrame
;
270 WXWidget m_mainWidget
;
272 wxColour m_foregroundColour
;
273 wxColour m_backgroundColour
;
277 #endif // _WX_MENU_H_