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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "menu.h"
21 #include "wx/dynarray.h"
23 WX_DEFINE_EXPORTED_ARRAY(wxAcceleratorEntry
*, wxAcceleratorArray
);
26 class WXDLLEXPORT wxFrame
;
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 class WXDLLEXPORT wxMenu
: public wxMenuBase
36 wxMenu(const wxString
& title
, long style
= 0)
37 : wxMenuBase(title
, style
) { Init(); }
39 wxMenu(long style
= 0) : wxMenuBase(style
) { Init(); }
43 // implement base class virtuals
44 virtual bool DoAppend(wxMenuItem
*item
);
45 virtual bool DoInsert(size_t pos
, wxMenuItem
*item
);
46 virtual wxMenuItem
*DoRemove(wxMenuItem
*item
);
50 virtual void SetTitle(const wxString
& title
);
52 // deprecated functions
53 #if wxUSE_MENU_CALLBACK
54 wxMenu(const wxString
& title
, const wxFunction func
)
61 #endif // wxUSE_MENU_CALLBACK
63 // implementation only from now on
64 // -------------------------------
66 virtual void Attach(wxMenuBarBase
*menubar
);
68 bool MSWCommand(WXUINT param
, WXWORD id
);
70 // semi-private accessors
71 // get the window which contains this menu
72 wxWindow
*GetWindow() const;
73 // get the menu handle
74 WXHMENU
GetHMenu() const { return m_hMenu
; }
77 // called by wxMenuBar to build its accel table from the accels of all menus
78 bool HasAccels() const { return !m_accels
.IsEmpty(); }
79 size_t GetAccelCount() const { return m_accels
.GetCount(); }
80 size_t CopyAccels(wxAcceleratorEntry
*accels
) const;
82 // called by wxMenuItem when its accels changes
83 void UpdateAccel(wxMenuItem
*item
);
85 // helper used by wxMenu itself (returns the index in m_accels)
86 int FindAccel(int id
) const;
90 // common part of all ctors
93 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
94 bool DoInsertOrAppend(wxMenuItem
*item
, size_t pos
= (size_t)-1);
96 // terminate the current radio group, if any
99 // if TRUE, insert a breal before appending the next item
102 // the position of the first item in the current radio group or -1
103 int m_startRadioGroup
;
105 // the menu handle of this menu
109 // the accelerators for our menu items
110 wxAcceleratorArray m_accels
;
111 #endif // wxUSE_ACCEL
113 DECLARE_DYNAMIC_CLASS(wxMenu
)
116 // ----------------------------------------------------------------------------
117 // Menu Bar (a la Windows)
118 // ----------------------------------------------------------------------------
120 class WXDLLEXPORT wxMenuBar
: public wxMenuBarBase
124 // default constructor
127 wxMenuBar(long style
);
128 // menubar takes ownership of the menus arrays but copies the titles
129 wxMenuBar(int n
, wxMenu
*menus
[], const wxString titles
[]);
130 virtual ~wxMenuBar();
132 // menubar construction
133 virtual bool Append( wxMenu
*menu
, const wxString
&title
);
134 virtual bool Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
);
135 virtual wxMenu
*Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
);
136 virtual wxMenu
*Remove(size_t pos
);
138 virtual void EnableTop( size_t pos
, bool flag
);
139 virtual void SetLabelTop( size_t pos
, const wxString
& label
);
140 virtual wxString
GetLabelTop( size_t pos
) const;
142 // compatibility: these functions are deprecated
143 #if WXWIN_COMPATIBILITY
144 void SetEventHandler(wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
145 wxEvtHandler
*GetEventHandler() { return m_eventHandler
; }
147 bool Enabled(int id
) const { return IsEnabled(id
); }
148 bool Checked(int id
) const { return IsChecked(id
); }
149 #endif // WXWIN_COMPATIBILITY
151 // implementation from now on
153 virtual void Detach();
154 virtual void Attach(wxFrame
*frame
);
157 // get the accel table for all the menus
158 const wxAcceleratorTable
& GetAccelTable() const { return m_accelTable
; }
160 // update the accel table (must be called after adding/deletign a menu)
161 void RebuildAccelTable();
162 #endif // wxUSE_ACCEL
164 // get the menu handle
165 WXHMENU
GetHMenu() const { return m_hMenu
; }
167 // if the menubar is modified, the display is not updated automatically,
168 // call this function to update it (m_menuBarFrame should be !NULL)
172 // common part of all ctors
175 #if WXWIN_COMPATIBILITY
176 wxEvtHandler
*m_eventHandler
;
177 #endif // WXWIN_COMPATIBILITY
179 wxArrayString m_titles
;
184 // the accelerator table for all accelerators in all our menus
185 wxAcceleratorTable m_accelTable
;
186 #endif // wxUSE_ACCEL
189 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
192 #endif // _WX_MENU_H_