1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenu, wxMenuBar classes
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "menu.h"
22 class WXDLLEXPORT wxMenuItem
;
23 class WXDLLEXPORT wxMenuBar
;
24 class WXDLLEXPORT wxMenu
;
26 WXDLLEXPORT_DATA(extern const char*) wxEmptyString
;
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
31 class WXDLLEXPORT wxMenu
: public wxEvtHandler
33 DECLARE_DYNAMIC_CLASS(wxMenu
)
37 wxMenu(const wxString
& title
= wxEmptyString
, const wxFunction func
= NULL
);
41 // append items to the menu
43 void AppendSeparator();
45 void Append(int id
, const wxString
& Label
, const wxString
& helpString
= wxEmptyString
,
46 bool checkable
= FALSE
);
48 void Append(int id
, const wxString
& Label
, wxMenu
*SubMenu
,
49 const wxString
& helpString
= wxEmptyString
);
50 // the most generic form (create wxMenuItem first and use it's functions)
51 void Append(wxMenuItem
*pItem
);
52 // insert a break in the menu
58 void Enable(int id
, bool Flag
);
59 bool Enabled(int id
) const;
60 inline bool IsEnabled(int id
) const { return Enabled(id
); };
61 void Check(int id
, bool Flag
);
62 bool Checked(int id
) const;
63 inline bool IsChecked(int id
) const { return IsChecked(id
); };
66 inline void SetClientData(void* clientData
) { m_clientData
= clientData
; }
67 inline void* GetClientData() const { return m_clientData
; }
71 void SetTitle(const wxString
& label
);
72 const wxString
GetTitle() const;
74 void SetLabel(int id
, const wxString
& label
);
75 wxString
GetLabel(int id
) const;
77 virtual void SetHelpString(int id
, const wxString
& helpString
);
78 virtual wxString
GetHelpString(int id
) const ;
81 // Finds the item id matching the given string, -1 if not found.
82 virtual int FindItem(const wxString
& itemString
) const ;
83 // Find wxMenuItem by ID, and item's menu too if itemMenu is !NULL.
84 wxMenuItem
*FindItemForId(int itemId
, wxMenu
**itemMenu
= NULL
) const;
86 void ProcessCommand(wxCommandEvent
& event
);
87 inline void Callback(const wxFunction func
) { m_callback
= func
; }
89 virtual void SetParent(wxEvtHandler
*parent
) { m_parent
= parent
; }
90 inline void SetEventHandler(wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
91 inline wxEvtHandler
*GetEventHandler() { return m_eventHandler
; }
93 inline wxList
& GetItems() const { return (wxList
&) m_menuItems
; }
95 void SetInvokingWindow(wxWindow
*pWin
) { m_pInvokingWindow
= pWin
; }
96 wxWindow
* GetInvokingWindow() const { return m_pInvokingWindow
; }
98 bool MacMenuSelect(wxEvtHandler
* handler
, long when
, int macMenuId
, int macMenuItemNum
) ;
100 wxFunction m_callback
;
104 wxMenuBar
* m_menuBar
;
106 wxEvtHandler
* m_parent
;
107 wxEvtHandler
* m_eventHandler
;
108 wxWindow
* m_pInvokingWindow
;
111 MenuHandle m_macMenuHandle
;
113 bool m_macMenuEnabled
;
115 // void MacSetTitle(const wxString& title);
116 int MacGetIndexFromId( int id
) ;
117 int MacGetIndexFromItem( wxMenuItem
*pItem
) ;
118 void MacEnableMenu( bool bDoEnable
) ;
120 static short s_macNextMenuId
;
125 // ----------------------------------------------------------------------------
126 // Menu Bar (a la Windows)
127 // ----------------------------------------------------------------------------
128 class WXDLLEXPORT wxFrame
;
129 class WXDLLEXPORT wxMenuBar
: public wxEvtHandler
131 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
134 wxMenuBar(int n
, wxMenu
*menus
[], const wxString titles
[]);
137 void Append(wxMenu
*menu
, const wxString
& title
);
138 // Must only be used AFTER menu has been attached to frame,
139 // otherwise use individual menus to enable/disable items
140 void Enable(int Id
, bool Flag
);
141 bool Enabled(int Id
) const ;
142 inline bool IsEnabled(int Id
) const { return Enabled(Id
); };
143 void EnableTop(int pos
, bool Flag
);
144 void Check(int id
, bool Flag
);
145 bool Checked(int id
) const ;
146 inline bool IsChecked(int Id
) const { return Checked(Id
); };
147 void SetLabel(int id
, const wxString
& label
) ;
148 wxString
GetLabel(int id
) const ;
149 void SetLabelTop(int pos
, const wxString
& label
) ;
150 wxString
GetLabelTop(int pos
) const ;
151 virtual void Delete(wxMenu
*menu
, int index
= 0); /* Menu not destroyed */
152 virtual bool OnAppend(wxMenu
*menu
, const char *title
);
153 virtual bool OnDelete(wxMenu
*menu
, int index
);
155 virtual void SetHelpString(int Id
, const wxString
& helpString
);
156 virtual wxString
GetHelpString(int Id
) const ;
158 virtual int FindMenuItem(const wxString
& menuString
, const wxString
& itemString
) const ;
160 // Find wxMenuItem for item ID, and return item's
161 // menu too if itemMenu is non-NULL.
162 wxMenuItem
*FindItemForId(int itemId
, wxMenu
**menuForItem
= NULL
) const ;
164 inline void SetEventHandler(wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
165 inline wxEvtHandler
*GetEventHandler() { return m_eventHandler
; }
167 inline int GetMenuCount() const { return m_menuCount
; }
168 inline wxMenu
* GetMenu(int i
) const { return m_menus
[i
]; }
170 void MacInstallMenuBar() ;
171 void MacMenuSelect(wxEvtHandler
* handler
, long when
, int macMenuId
, int macMenuItemNum
) ;
174 wxEvtHandler
* m_eventHandler
;
178 wxFrame
* m_menuBarFrame
;
180 static wxMenuBar
* s_macInstalledMenuBar
;
183 #endif // _WX_MENU_H_