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 and Markus Holzem
9 // Licence: wxWindows license
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
)
59 #endif // wxUSE_MENU_CALLBACK
62 bool ProcessCommand(wxCommandEvent
& event
);
64 // implementation only from now on
65 // -------------------------------
67 bool MSWCommand(WXUINT param
, WXWORD id
);
69 // semi-private accessors
70 // get the window which contains this menu
71 wxWindow
*GetWindow() const;
72 // get the menu handle
73 WXHMENU
GetHMenu() const { return m_hMenu
; }
75 // attach/detach menu to/from wxMenuBar
76 void Attach(wxMenuBar
*menubar
);
80 // called by wxMenuBar to build its accel table from the accels of all menus
81 bool HasAccels() const { return !m_accels
.IsEmpty(); }
82 size_t GetAccelCount() const { return m_accels
.GetCount(); }
83 size_t CopyAccels(wxAcceleratorEntry
*accels
) const;
85 // called by wxMenuItem when its accels changes
86 void UpdateAccel(wxMenuItem
*item
);
88 // helper used by wxMenu itself (returns the index in m_accels)
89 int FindAccel(int id
) const;
93 // common part of all ctors
96 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
97 bool DoInsertOrAppend(wxMenuItem
*item
, size_t pos
= (size_t)-1);
99 // if TRUE, insert a breal before appending the next item
102 // the menu handle of this menu
106 // the accelerators for our menu items
107 wxAcceleratorArray m_accels
;
108 #endif // wxUSE_ACCEL
110 DECLARE_DYNAMIC_CLASS(wxMenu
)
113 // ----------------------------------------------------------------------------
114 // Menu Bar (a la Windows)
115 // ----------------------------------------------------------------------------
117 class WXDLLEXPORT wxMenuBar
: public wxMenuBarBase
121 // default constructor
124 wxMenuBar(long style
);
125 // menubar takes ownership of the menus arrays but copies the titles
126 wxMenuBar(int n
, wxMenu
*menus
[], const wxString titles
[]);
127 virtual ~wxMenuBar();
129 // menubar construction
130 virtual bool Append( wxMenu
*menu
, const wxString
&title
);
131 virtual bool Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
);
132 virtual wxMenu
*Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
);
133 virtual wxMenu
*Remove(size_t pos
);
135 virtual int FindMenuItem(const wxString
& menuString
,
136 const wxString
& itemString
) const;
137 virtual wxMenuItem
* FindItem( int id
, wxMenu
**menu
= NULL
) const;
139 virtual void EnableTop( size_t pos
, bool flag
);
140 virtual void SetLabelTop( size_t pos
, const wxString
& label
);
141 virtual wxString
GetLabelTop( size_t pos
) const;
143 // compatibility: these functions are deprecated
144 #if WXWIN_COMPATIBILITY
145 void SetEventHandler(wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
146 wxEvtHandler
*GetEventHandler() { return m_eventHandler
; }
148 bool Enabled(int id
) const { return IsEnabled(id
); }
149 bool Checked(int id
) const { return IsChecked(id
); }
150 #endif // WXWIN_COMPATIBILITY
152 // implementation from now on
154 int FindMenu(const wxString
& title
);
157 // returns TRUE if we're attached to a frame
158 bool IsAttached() const { return m_menuBarFrame
!= NULL
; }
159 // get the frame we live in
160 wxFrame
*GetFrame() const { return m_menuBarFrame
; }
162 void Attach(wxFrame
*frame
);
165 // get the accel table for all the menus
166 const wxAcceleratorTable
& GetAccelTable() const { return m_accelTable
; }
168 // update the accel table (must be called after adding/deletign a menu)
169 void RebuildAccelTable();
170 #endif // wxUSE_ACCEL
172 // get the menu handle
173 WXHMENU
GetHMenu() const { return m_hMenu
; }
175 // if the menubar is modified, the display is not updated automatically,
176 // call this function to update it (m_menuBarFrame should be !NULL)
180 // common part of all ctors
183 #if WXWIN_COMPATIBILITY
184 wxEvtHandler
*m_eventHandler
;
185 #endif // WXWIN_COMPATIBILITY
187 wxArrayString m_titles
;
189 wxFrame
*m_menuBarFrame
;
193 // the accelerator table for all accelerators in all our menus
194 wxAcceleratorTable m_accelTable
;
195 #endif // wxUSE_ACCEL
198 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
201 #endif // _WX_MENU_H_