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_NO_PTR(wxAcceleratorEntry
*, wxAcceleratorArray
);
26 class WXDLLEXPORT wxFrame
;
28 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
29 class WXDLLEXPORT wxToolBar
;
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 class WXDLLEXPORT wxMenu
: public wxMenuBase
40 wxMenu(const wxString
& title
, long style
= 0)
41 : wxMenuBase(title
, style
) { Init(); }
43 wxMenu(long style
= 0) : wxMenuBase(style
) { Init(); }
47 // implement base class virtuals
48 virtual bool DoAppend(wxMenuItem
*item
);
49 virtual bool DoInsert(size_t pos
, wxMenuItem
*item
);
50 virtual wxMenuItem
*DoRemove(wxMenuItem
*item
);
54 virtual void SetTitle(const wxString
& title
);
56 // deprecated functions
57 #if wxUSE_MENU_CALLBACK
58 wxMenu(const wxString
& title
, const wxFunction func
)
65 #endif // wxUSE_MENU_CALLBACK
67 // implementation only from now on
68 // -------------------------------
70 virtual void Attach(wxMenuBarBase
*menubar
);
72 bool MSWCommand(WXUINT param
, WXWORD id
);
74 // semi-private accessors
75 // get the window which contains this menu
76 wxWindow
*GetWindow() const;
77 // get the menu handle
78 WXHMENU
GetHMenu() const { return m_hMenu
; }
81 // called by wxMenuBar to build its accel table from the accels of all menus
82 bool HasAccels() const { return !m_accels
.IsEmpty(); }
83 size_t GetAccelCount() const { return m_accels
.GetCount(); }
84 size_t CopyAccels(wxAcceleratorEntry
*accels
) const;
86 // called by wxMenuItem when its accels changes
87 void UpdateAccel(wxMenuItem
*item
);
89 // helper used by wxMenu itself (returns the index in m_accels)
90 int FindAccel(int id
) const;
94 // common part of all ctors
97 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
98 bool DoInsertOrAppend(wxMenuItem
*item
, size_t pos
= (size_t)-1);
100 // terminate the current radio group, if any
101 void EndRadioGroup();
103 // if TRUE, insert a breal before appending the next item
106 // the position of the first item in the current radio group or -1
107 int m_startRadioGroup
;
109 // the menu handle of this menu
113 // the accelerators for our menu items
114 wxAcceleratorArray m_accels
;
115 #endif // wxUSE_ACCEL
117 DECLARE_DYNAMIC_CLASS(wxMenu
)
120 // ----------------------------------------------------------------------------
121 // Menu Bar (a la Windows)
122 // ----------------------------------------------------------------------------
124 class WXDLLEXPORT wxMenuBar
: public wxMenuBarBase
128 // default constructor
131 wxMenuBar(long style
);
132 // menubar takes ownership of the menus arrays but copies the titles
133 wxMenuBar(int n
, wxMenu
*menus
[], const wxString titles
[]);
134 virtual ~wxMenuBar();
136 // menubar construction
137 virtual bool Append( wxMenu
*menu
, const wxString
&title
);
138 virtual bool Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
);
139 virtual wxMenu
*Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
);
140 virtual wxMenu
*Remove(size_t pos
);
142 virtual void EnableTop( size_t pos
, bool flag
);
143 virtual void SetLabelTop( size_t pos
, const wxString
& label
);
144 virtual wxString
GetLabelTop( size_t pos
) const;
146 // compatibility: these functions are deprecated
147 #if WXWIN_COMPATIBILITY
148 void SetEventHandler(wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
149 wxEvtHandler
*GetEventHandler() { return m_eventHandler
; }
151 bool Enabled(int id
) const { return IsEnabled(id
); }
152 bool Checked(int id
) const { return IsChecked(id
); }
153 #endif // WXWIN_COMPATIBILITY
155 // implementation from now on
157 virtual void Detach();
158 virtual void Attach(wxFrame
*frame
);
160 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
161 // Under WinCE, a menubar is owned by the frame's toolbar
162 void SetToolBar(wxToolBar
* toolBar
) { m_toolBar
= toolBar
; }
163 wxToolBar
* GetToolBar() const { return m_toolBar
; }
167 // get the accel table for all the menus
168 const wxAcceleratorTable
& GetAccelTable() const { return m_accelTable
; }
170 // update the accel table (must be called after adding/deletign a menu)
171 void RebuildAccelTable();
172 #endif // wxUSE_ACCEL
174 // get the menu handle
175 WXHMENU
GetHMenu() const { return m_hMenu
; }
177 // if the menubar is modified, the display is not updated automatically,
178 // call this function to update it (m_menuBarFrame should be !NULL)
181 // To avoid compile warning
182 void Refresh( bool eraseBackground
,
183 const wxRect
*rect
= (const wxRect
*) NULL
) { wxWindow::Refresh(eraseBackground
, rect
); }
186 // common part of all ctors
189 #if WXWIN_COMPATIBILITY
190 wxEvtHandler
*m_eventHandler
;
191 #endif // WXWIN_COMPATIBILITY
193 wxArrayString m_titles
;
198 // the accelerator table for all accelerators in all our menus
199 wxAcceleratorTable m_accelTable
;
200 #endif // wxUSE_ACCEL
202 #if defined(__WXWINCE__) && wxUSE_TOOLBAR
203 wxToolBar
* m_toolBar
;
207 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
210 #endif // _WX_MENU_H_