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 // implementation only from now on
53 // -------------------------------
55 virtual void Attach(wxMenuBarBase
*menubar
);
57 bool MSWCommand(WXUINT param
, WXWORD id
);
59 // semi-private accessors
60 // get the window which contains this menu
61 wxWindow
*GetWindow() const;
62 // get the menu handle
63 WXHMENU
GetHMenu() const { return m_hMenu
; }
66 // called by wxMenuBar to build its accel table from the accels of all menus
67 bool HasAccels() const { return !m_accels
.IsEmpty(); }
68 size_t GetAccelCount() const { return m_accels
.GetCount(); }
69 size_t CopyAccels(wxAcceleratorEntry
*accels
) const;
71 // called by wxMenuItem when its accels changes
72 void UpdateAccel(wxMenuItem
*item
);
74 // helper used by wxMenu itself (returns the index in m_accels)
75 int FindAccel(int id
) const;
79 // common part of all ctors
82 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
83 bool DoInsertOrAppend(wxMenuItem
*item
, size_t pos
= (size_t)-1);
85 // terminate the current radio group, if any
88 // if TRUE, insert a breal before appending the next item
91 // the position of the first item in the current radio group or -1
92 int m_startRadioGroup
;
94 // the menu handle of this menu
98 // the accelerators for our menu items
99 wxAcceleratorArray m_accels
;
100 #endif // wxUSE_ACCEL
102 DECLARE_DYNAMIC_CLASS(wxMenu
)
105 // ----------------------------------------------------------------------------
106 // Menu Bar (a la Windows)
107 // ----------------------------------------------------------------------------
109 class WXDLLEXPORT wxMenuBar
: public wxMenuBarBase
113 // default constructor
116 wxMenuBar(long style
);
117 // menubar takes ownership of the menus arrays but copies the titles
118 wxMenuBar(int n
, wxMenu
*menus
[], const wxString titles
[]);
119 virtual ~wxMenuBar();
121 // menubar construction
122 virtual bool Append( wxMenu
*menu
, const wxString
&title
);
123 virtual bool Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
);
124 virtual wxMenu
*Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
);
125 virtual wxMenu
*Remove(size_t pos
);
127 virtual void EnableTop( size_t pos
, bool flag
);
128 virtual void SetLabelTop( size_t pos
, const wxString
& label
);
129 virtual wxString
GetLabelTop( size_t pos
) const;
131 // compatibility: these functions are deprecated
132 #if WXWIN_COMPATIBILITY
133 void SetEventHandler(wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
134 wxEvtHandler
*GetEventHandler() { return m_eventHandler
; }
136 bool Enabled(int id
) const { return IsEnabled(id
); }
137 bool Checked(int id
) const { return IsChecked(id
); }
138 #endif // WXWIN_COMPATIBILITY
140 // implementation from now on
142 virtual void Detach();
143 virtual void Attach(wxFrame
*frame
);
146 // get the accel table for all the menus
147 const wxAcceleratorTable
& GetAccelTable() const { return m_accelTable
; }
149 // update the accel table (must be called after adding/deletign a menu)
150 void RebuildAccelTable();
151 #endif // wxUSE_ACCEL
153 // get the menu handle
154 WXHMENU
GetHMenu() const { return m_hMenu
; }
156 // if the menubar is modified, the display is not updated automatically,
157 // call this function to update it (m_menuBarFrame should be !NULL)
161 // common part of all ctors
164 #if WXWIN_COMPATIBILITY
165 wxEvtHandler
*m_eventHandler
;
166 #endif // WXWIN_COMPATIBILITY
168 wxArrayString m_titles
;
173 // the accelerator table for all accelerators in all our menus
174 wxAcceleratorTable m_accelTable
;
175 #endif // wxUSE_ACCEL
178 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
181 #endif // _WX_MENU_H_