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 void ProcessCommand(wxCommandEvent
& event
);
89 inline void Callback(const wxFunction func
) { m_callback
= func
; }
91 virtual void SetParent(wxEvtHandler
*parent
) { m_parent
= parent
; }
92 inline void SetEventHandler(wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
93 inline wxEvtHandler
*GetEventHandler() { return m_eventHandler
; }
95 inline wxList
& GetItems() const { return (wxList
&) m_menuItems
; }
98 inline WXWidget
GetButtonWidget() const { return m_buttonWidget
; }
99 inline void SetButtonWidget(WXWidget buttonWidget
) { m_buttonWidget
= buttonWidget
; }
100 inline WXWidget
GetMainWidget() const { return m_menuWidget
; }
101 inline wxMenu
* GetParent() const { return m_menuParent
; }
102 inline int GetId() const { return m_menuId
; }
103 inline void SetId(int id
) { m_menuId
= id
; }
104 inline void SetMenuBar(wxMenuBar
* menuBar
) { m_menuBar
= menuBar
; }
105 inline wxMenuBar
* GetMenuBar() const { return m_menuBar
; }
107 void CreatePopup (WXWidget logicalParent
, int x
, int y
);
108 void DestroyPopup (void);
109 void ShowPopup (int x
, int y
);
110 void HidePopup (void);
112 WXWidget
CreateMenu(wxMenuBar
*menuBar
, WXWidget parent
, wxMenu
*topMenu
,
113 const wxString
& title
= "", bool isPulldown
= FALSE
);
115 // For popups, need to destroy, then recreate menu for a different (or
116 // possibly same) window, since the parent may change.
117 void DestroyMenu(bool full
);
118 WXWidget
FindMenuItem(int id
, wxMenuItem
**it
= NULL
) const;
120 const wxColour
& GetBackgroundColour() const { return m_backgroundColour
; }
121 const wxColour
& GetForegroundColour() const { return m_foregroundColour
; }
122 const wxFont
& GetFont() const { return m_font
; }
124 void SetBackgroundColour(const wxColour
& colour
);
125 void SetForegroundColour(const wxColour
& colour
);
126 void SetFont(const wxFont
& colour
);
127 void ChangeFont(bool keepOriginalSize
= FALSE
);
130 wxFunction m_callback
;
134 wxMenuBar
* m_menuBar
;
136 wxEvtHandler
* m_parent
;
137 wxEvtHandler
* m_eventHandler
;
142 WXWidget m_menuWidget
;
143 WXWidget m_popupShell
; // For holding the popup shell widget
144 WXWidget m_buttonWidget
; // The actual string, so we can grey it etc.
146 wxMenu
* m_topLevelMenu
;
147 wxMenu
* m_menuParent
;
148 bool m_ownedByMenuBar
;
149 wxColour m_foregroundColour
;
150 wxColour m_backgroundColour
;
154 // ----------------------------------------------------------------------------
155 // Menu Bar (a la Windows)
156 // ----------------------------------------------------------------------------
157 class WXDLLEXPORT wxFrame
;
158 class WXDLLEXPORT wxMenuBar
: public wxEvtHandler
160 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
163 wxMenuBar(int n
, wxMenu
*menus
[], const wxString titles
[]);
166 void Append(wxMenu
*menu
, const wxString
& title
);
167 // Must only be used AFTER menu has been attached to frame,
168 // otherwise use individual menus to enable/disable items
169 void Enable(int Id
, bool Flag
);
170 bool Enabled(int Id
) const ;
171 inline bool IsEnabled(int Id
) const { return Enabled(Id
); };
172 void EnableTop(int pos
, bool Flag
);
173 void Check(int id
, bool Flag
);
174 bool Checked(int id
) const ;
175 inline bool IsChecked(int Id
) const { return Checked(Id
); };
176 void SetLabel(int id
, const wxString
& label
) ;
177 wxString
GetLabel(int id
) const ;
178 void SetLabelTop(int pos
, const wxString
& label
) ;
179 wxString
GetLabelTop(int pos
) const ;
180 virtual void Delete(wxMenu
*menu
, int index
= 0); /* Menu not destroyed */
181 virtual bool OnAppend(wxMenu
*menu
, const char *title
);
182 virtual bool OnDelete(wxMenu
*menu
, int index
);
184 virtual void SetHelpString(int Id
, const wxString
& helpString
);
185 virtual wxString
GetHelpString(int Id
) const ;
187 virtual int FindMenuItem(const wxString
& menuString
, const wxString
& itemString
) const ;
189 // Find wxMenuItem for item ID, and return item's
190 // menu too if itemMenu is non-NULL.
191 wxMenuItem
*FindItemForId(int itemId
, wxMenu
**menuForItem
= NULL
) const ;
193 inline void SetEventHandler(wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
194 inline wxEvtHandler
*GetEventHandler() { return m_eventHandler
; }
196 inline int GetMenuCount() const { return m_menuCount
; }
197 inline wxMenu
* GetMenu(int i
) const { return m_menus
[i
]; }
200 inline wxFrame
* GetMenuBarFrame() const { return m_menuBarFrame
; }
201 inline void SetMenuBarFrame(wxFrame
* frame
) { m_menuBarFrame
= frame
; }
202 inline WXWidget
GetMainWidget() const { return m_mainWidget
; }
203 inline void SetMainWidget(WXWidget widget
) { m_mainWidget
= widget
; }
206 bool CreateMenuBar(wxFrame
* frame
);
208 // Destroy menubar, but keep data structures intact so we can recreate it.
209 bool DestroyMenuBar();
211 const wxColour
& GetBackgroundColour() const { return m_backgroundColour
; }
212 const wxColour
& GetForegroundColour() const { return m_foregroundColour
; }
213 const wxFont
& GetFont() const { return m_font
; }
215 void SetBackgroundColour(const wxColour
& colour
);
216 void SetForegroundColour(const wxColour
& colour
);
217 void SetFont(const wxFont
& colour
);
218 void ChangeFont(bool keepOriginalSize
= FALSE
);
221 wxEvtHandler
* m_eventHandler
;
225 wxFrame
* m_menuBarFrame
;
228 WXWidget m_mainWidget
;
230 wxColour m_foregroundColour
;
231 wxColour m_backgroundColour
;
235 #endif // _WX_MENU_H_