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 wxMenu(const wxString
& title
= wxEmptyString
, const wxFunction func
= NULL
);
43 // append items to the menu
45 void AppendSeparator();
47 void Append(int id
, const wxString
& Label
, const wxString
& helpString
= wxEmptyString
,
48 bool checkable
= FALSE
);
50 void Append(int id
, const wxString
& Label
, wxMenu
*SubMenu
,
51 const wxString
& helpString
= wxEmptyString
);
52 // the most generic form (create wxMenuItem first and use it's functions)
53 void Append(wxMenuItem
*pItem
);
54 // insert a break in the menu
60 void Enable(int id
, bool Flag
);
61 bool Enabled(int id
) const;
62 inline bool IsEnabled(int id
) const { return Enabled(id
); };
63 void Check(int id
, bool Flag
);
64 bool Checked(int id
) const;
65 inline bool IsChecked(int id
) const { return IsChecked(id
); };
68 inline void SetClientData(void* clientData
) { m_clientData
= clientData
; }
69 inline void* GetClientData() const { return m_clientData
; }
73 void SetTitle(const wxString
& label
);
74 const wxString
GetTitle() const;
76 void SetLabel(int id
, const wxString
& label
);
77 wxString
GetLabel(int id
) const;
79 virtual void SetHelpString(int id
, const wxString
& helpString
);
80 virtual wxString
GetHelpString(int id
) const ;
83 // Finds the item id matching the given string, -1 if not found.
84 virtual int FindItem(const wxString
& itemString
) const ;
85 // Find wxMenuItem by ID, and item's menu too if itemMenu is !NULL.
86 wxMenuItem
*FindItemForId(int itemId
, wxMenu
**itemMenu
= NULL
) const;
88 // Updates the UI for a menu and all submenus recursively.
89 // source is the object that has the update event handlers
90 // defined for it. If NULL, the menu or associated window
92 void UpdateUI(wxEvtHandler
* source
= (wxEvtHandler
*) NULL
);
94 void ProcessCommand(wxCommandEvent
& event
);
95 inline void Callback(const wxFunction func
) { m_callback
= func
; }
97 virtual void SetParent(wxEvtHandler
*parent
) { m_parent
= parent
; }
98 inline void SetEventHandler(wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
99 inline wxEvtHandler
*GetEventHandler() { return m_eventHandler
; }
101 inline wxList
& GetItems() const { return (wxList
&) m_menuItems
; }
103 void SetInvokingWindow(wxWindow
*pWin
) { m_pInvokingWindow
= pWin
; }
104 wxWindow
*GetInvokingWindow() const { return m_pInvokingWindow
; }
107 inline WXWidget
GetButtonWidget() const { return m_buttonWidget
; }
108 inline void SetButtonWidget(WXWidget buttonWidget
) { m_buttonWidget
= buttonWidget
; }
109 inline WXWidget
GetMainWidget() const { return m_menuWidget
; }
110 inline wxMenu
* GetParent() const { return m_menuParent
; }
111 inline int GetId() const { return m_menuId
; }
112 inline void SetId(int id
) { m_menuId
= id
; }
113 inline void SetMenuBar(wxMenuBar
* menuBar
) { m_menuBar
= menuBar
; }
114 inline wxMenuBar
* GetMenuBar() const { return m_menuBar
; }
116 void CreatePopup (WXWidget logicalParent
, int x
, int y
);
117 void DestroyPopup (void);
118 void ShowPopup (int x
, int y
);
119 void HidePopup (void);
121 WXWidget
CreateMenu(wxMenuBar
*menuBar
, WXWidget parent
, wxMenu
*topMenu
,
122 const wxString
& title
= "", bool isPulldown
= FALSE
);
124 // For popups, need to destroy, then recreate menu for a different (or
125 // possibly same) window, since the parent may change.
126 void DestroyMenu(bool full
);
127 WXWidget
FindMenuItem(int id
, wxMenuItem
**it
= NULL
) const;
129 const wxColour
& GetBackgroundColour() const { return m_backgroundColour
; }
130 const wxColour
& GetForegroundColour() const { return m_foregroundColour
; }
131 const wxFont
& GetFont() const { return m_font
; }
133 void SetBackgroundColour(const wxColour
& colour
);
134 void SetForegroundColour(const wxColour
& colour
);
135 void SetFont(const wxFont
& colour
);
136 void ChangeFont(bool keepOriginalSize
= FALSE
);
139 wxFunction m_callback
;
143 wxMenuBar
* m_menuBar
;
145 wxEvtHandler
* m_parent
;
146 wxEvtHandler
* m_eventHandler
;
148 wxWindow
* m_pInvokingWindow
;
152 WXWidget m_menuWidget
;
153 WXWidget m_popupShell
; // For holding the popup shell widget
154 WXWidget m_buttonWidget
; // The actual string, so we can grey it etc.
156 wxMenu
* m_topLevelMenu
;
157 wxMenu
* m_menuParent
;
158 bool m_ownedByMenuBar
;
159 wxColour m_foregroundColour
;
160 wxColour m_backgroundColour
;
164 // ----------------------------------------------------------------------------
165 // Menu Bar (a la Windows)
166 // ----------------------------------------------------------------------------
167 class WXDLLEXPORT wxFrame
;
168 class WXDLLEXPORT wxMenuBar
: public wxEvtHandler
170 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
172 wxMenuBar( long style
);
174 wxMenuBar(int n
, wxMenu
*menus
[], const wxString titles
[]);
177 void Append(wxMenu
*menu
, const wxString
& title
);
178 // Must only be used AFTER menu has been attached to frame,
179 // otherwise use individual menus to enable/disable items
180 void Enable(int Id
, bool Flag
);
181 bool Enabled(int Id
) const ;
182 inline bool IsEnabled(int Id
) const { return Enabled(Id
); };
183 void EnableTop(int pos
, bool Flag
);
184 void Check(int id
, bool Flag
);
185 bool Checked(int id
) const ;
186 inline bool IsChecked(int Id
) const { return Checked(Id
); };
187 void SetLabel(int id
, const wxString
& label
) ;
188 wxString
GetLabel(int id
) const ;
189 void SetLabelTop(int pos
, const wxString
& label
) ;
190 wxString
GetLabelTop(int pos
) const ;
191 virtual void Delete(wxMenu
*menu
, int index
= 0); /* Menu not destroyed */
192 virtual bool OnAppend(wxMenu
*menu
, const char *title
);
193 virtual bool OnDelete(wxMenu
*menu
, int index
);
195 virtual void SetHelpString(int Id
, const wxString
& helpString
);
196 virtual wxString
GetHelpString(int Id
) const ;
198 virtual int FindMenuItem(const wxString
& menuString
, const wxString
& itemString
) const ;
200 // Find wxMenuItem for item ID, and return item's
201 // menu too if itemMenu is non-NULL.
202 wxMenuItem
*FindItemForId(int itemId
, wxMenu
**menuForItem
= NULL
) const ;
204 inline void SetEventHandler(wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
205 inline wxEvtHandler
*GetEventHandler() { return m_eventHandler
; }
207 inline int GetMenuCount() const { return m_menuCount
; }
208 inline wxMenu
* GetMenu(int i
) const { return m_menus
[i
]; }
211 inline wxFrame
* GetMenuBarFrame() const { return m_menuBarFrame
; }
212 inline void SetMenuBarFrame(wxFrame
* frame
) { m_menuBarFrame
= frame
; }
213 inline WXWidget
GetMainWidget() const { return m_mainWidget
; }
214 inline void SetMainWidget(WXWidget widget
) { m_mainWidget
= widget
; }
217 bool CreateMenuBar(wxFrame
* frame
);
219 // Destroy menubar, but keep data structures intact so we can recreate it.
220 bool DestroyMenuBar();
222 const wxColour
& GetBackgroundColour() const { return m_backgroundColour
; }
223 const wxColour
& GetForegroundColour() const { return m_foregroundColour
; }
224 const wxFont
& GetFont() const { return m_font
; }
226 void SetBackgroundColour(const wxColour
& colour
);
227 void SetForegroundColour(const wxColour
& colour
);
228 void SetFont(const wxFont
& colour
);
229 void ChangeFont(bool keepOriginalSize
= FALSE
);
232 wxEvtHandler
* m_eventHandler
;
236 wxFrame
* m_menuBarFrame
;
239 WXWidget m_mainWidget
;
241 wxColour m_foregroundColour
;
242 wxColour m_backgroundColour
;
246 #endif // _WX_MENU_H_