1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenu, wxMenuBar classes
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
17 #include "wx/dynarray.h"
19 WX_DEFINE_EXPORTED_ARRAY(wxAcceleratorEntry
*, wxAcceleratorArray
);
22 class WXDLLEXPORT wxFrame
;
24 // ----------------------------------------------------------------------------
26 // ----------------------------------------------------------------------------
28 class WXDLLEXPORT wxMenu
: public wxMenuBase
32 wxMenu(const wxString
& title
, long style
= 0)
33 : wxMenuBase(title
, style
) { Init(); }
35 wxMenu(long style
= 0) : wxMenuBase(style
) { Init(); }
39 // implement base class virtuals
40 virtual bool DoAppend(wxMenuItem
*item
);
41 virtual bool DoInsert(size_t pos
, wxMenuItem
*item
);
42 virtual wxMenuItem
*DoRemove(wxMenuItem
*item
);
46 virtual void SetTitle(const wxString
& title
);
49 bool ProcessCommand(wxCommandEvent
& event
);
51 #if WXWIN_COMPATIBILITY
52 wxMenu(const wxString
& title
, const wxFunction func
)
57 #endif // WXWIN_COMPATIBILITY
59 // implementation only from now on
60 // -------------------------------
62 bool OS2Command(WXUINT param
, WXWORD id
);
64 // semi-private accessors
65 // get the window which contains this menu
66 wxWindow
*GetWindow() const;
67 // get the menu handle
68 WXHMENU
GetHMenu() const { return m_hMenu
; }
70 // attach/detach menu to/from wxMenuBar
71 void Attach(wxMenuBar
*menubar
);
75 // called by wxMenuBar to build its accel table from the accels of all menus
76 bool HasAccels() const { return !m_accels
.IsEmpty(); }
77 size_t GetAccelCount() const { return m_accels
.GetCount(); }
78 size_t CopyAccels(wxAcceleratorEntry
*accels
) const;
80 // called by wxMenuItem when its accels changes
81 void UpdateAccel(wxMenuItem
*item
);
83 // helper used by wxMenu itself (returns the index in m_accels)
84 int FindAccel(int id
) const;
88 // common part of all ctors
91 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
92 bool DoInsertOrAppend(wxMenuItem
*item
, size_t pos
= (size_t)-1);
94 // if TRUE, insert a breal before appending the next item
97 // the menu handle of this menu
101 // the accelerators for our menu items
102 wxAcceleratorArray m_accels
;
103 #endif // wxUSE_ACCEL
105 DECLARE_DYNAMIC_CLASS(wxMenu
)
108 // ----------------------------------------------------------------------------
109 // Menu Bar (a la Windows)
110 // ----------------------------------------------------------------------------
112 class WXDLLEXPORT wxMenuBar
: public wxMenuBarBase
116 // default constructor
119 wxMenuBar(long style
);
120 // menubar takes ownership of the menus arrays but copies the titles
121 wxMenuBar(int n
, wxMenu
*menus
[], const wxString titles
[]);
122 virtual ~wxMenuBar();
124 // menubar construction
125 virtual bool Append( wxMenu
*menu
, const wxString
&title
);
126 virtual bool Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
);
127 virtual wxMenu
*Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
);
128 virtual wxMenu
*Remove(size_t pos
);
130 virtual int FindMenuItem(const wxString
& menuString
,
131 const wxString
& itemString
) const;
132 virtual wxMenuItem
* FindItem( int id
, wxMenu
**menu
= NULL
) const;
134 virtual void EnableTop( size_t pos
, bool flag
);
135 virtual void SetLabelTop( size_t pos
, const wxString
& label
);
136 virtual wxString
GetLabelTop( size_t pos
) const;
138 // compatibility: these functions are deprecated
139 #if WXWIN_COMPATIBILITY
140 void SetEventHandler(wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
141 wxEvtHandler
*GetEventHandler() { return m_eventHandler
; }
143 bool Enabled(int id
) const { return IsEnabled(id
); }
144 bool Checked(int id
) const { return IsChecked(id
); }
145 #endif // WXWIN_COMPATIBILITY
147 // implementation from now on
149 int FindMenu(const wxString
& title
);
152 // returns TRUE if we're attached to a frame
153 bool IsAttached() const { return m_menuBarFrame
!= NULL
; }
154 // get the frame we live in
155 wxFrame
*GetFrame() const { return m_menuBarFrame
; }
157 void Attach(wxFrame
*frame
);
160 // get the accel table for all the menus
161 const wxAcceleratorTable
& GetAccelTable() const { return m_accelTable
; }
163 // update the accel table (must be called after adding/deletign a menu)
164 void RebuildAccelTable();
165 #endif // wxUSE_ACCEL
167 // get the menu handle
168 WXHMENU
GetHMenu() const { return m_hMenu
; }
170 // if the menubar is modified, the display is not updated automatically,
171 // call this function to update it (m_menuBarFrame should be !NULL)
172 void Refresh( bool eraseBackground
= TRUE
173 ,const wxRect
*rect
= (const wxRect
*) NULL
177 // common part of all ctors
180 #if WXWIN_COMPATIBILITY
181 wxEvtHandler
*m_eventHandler
;
182 #endif // WXWIN_COMPATIBILITY
184 wxArrayString m_titles
;
186 wxFrame
*m_menuBarFrame
;
190 // the accelerator table for all accelerators in all our menus
191 wxAcceleratorTable m_accelTable
;
192 #endif // wxUSE_ACCEL
195 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
198 #endif // _WX_MENU_H_