1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenu, wxMenuBar classes
8 // Copyright: (c) AUTHOR
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
);
53 bool ProcessCommand(wxCommandEvent
& event
);
55 #if WXWIN_COMPATIBILITY
56 wxMenu(const wxString
& title
, const wxFunction func
)
61 #endif // WXWIN_COMPATIBILITY
63 // implementation only from now on
64 // -------------------------------
66 bool MacMenuSelect(wxEvtHandler
* handler
, long when
, int macMenuId
, int macMenuItemNum
) ;
67 int MacGetIndexFromId( int id
) ;
68 int MacGetIndexFromItem( wxMenuItem
*pItem
) ;
69 void MacEnableMenu( bool bDoEnable
) ;
71 // semi-private accessors
72 // get the window which contains this menu
73 wxWindow
*GetWindow() const;
74 // get the menu handle
75 WXHMENU
GetHMenu() const { return m_hMenu
; }
77 short MacGetMenuId() { return m_macMenuId
; }
79 // called by wxMenuBar to build its accel table from the accels of all menus
80 bool HasAccels() const { return !m_accels
.IsEmpty(); }
81 size_t GetAccelCount() const { return m_accels
.GetCount(); }
82 size_t CopyAccels(wxAcceleratorEntry
*accels
) const;
84 // called by wxMenuItem when its accels changes
85 void UpdateAccel(wxMenuItem
*item
);
87 // helper used by wxMenu itself (returns the index in m_accels)
88 int FindAccel(int id
) const;
92 // common part of all ctors
95 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
96 bool DoInsertOrAppend(wxMenuItem
*item
, size_t pos
= (size_t)-1);
98 // if TRUE, insert a breal before appending the next item
101 // the menu handle of this menu
106 static short s_macNextMenuId
;
108 // the accelerators for our menu items
109 wxAcceleratorArray m_accels
;
110 #endif // wxUSE_ACCEL
112 DECLARE_DYNAMIC_CLASS(wxMenu
)
115 // ----------------------------------------------------------------------------
116 // Menu Bar (a la Windows)
117 // ----------------------------------------------------------------------------
119 class WXDLLEXPORT wxMenuBar
: public wxMenuBarBase
123 // default constructor
126 wxMenuBar(long style
);
127 // menubar takes ownership of the menus arrays but copies the titles
128 wxMenuBar(int n
, wxMenu
*menus
[], const wxString titles
[]);
129 virtual ~wxMenuBar();
131 // menubar construction
132 virtual bool Append( wxMenu
*menu
, const wxString
&title
);
133 virtual bool Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
);
134 virtual wxMenu
*Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
);
135 virtual wxMenu
*Remove(size_t pos
);
137 virtual int FindMenuItem(const wxString
& menuString
,
138 const wxString
& itemString
) const;
139 virtual wxMenuItem
* FindItem( int id
, wxMenu
**menu
= NULL
) const;
141 virtual void EnableTop( size_t pos
, bool flag
);
142 virtual void SetLabelTop( size_t pos
, const wxString
& label
);
143 virtual wxString
GetLabelTop( size_t pos
) const;
145 // compatibility: these functions are deprecated
146 #if WXWIN_COMPATIBILITY
147 void SetEventHandler(wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
148 wxEvtHandler
*GetEventHandler() { return m_eventHandler
; }
150 bool Enabled(int id
) const { return IsEnabled(id
); }
151 bool Checked(int id
) const { return IsChecked(id
); }
152 #endif // WXWIN_COMPATIBILITY
154 // implementation from now on
156 int FindMenu(const wxString
& title
);
159 // returns TRUE if we're attached to a frame
160 bool IsAttached() const { return m_menuBarFrame
!= NULL
; }
161 // get the frame we live in
162 wxFrame
*GetFrame() const { return m_menuBarFrame
; }
164 void Attach(wxFrame
*frame
);
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 // if the menubar is modified, the display is not updated automatically,
175 // call this function to update it (m_menuBarFrame should be !NULL)
176 void Refresh(bool eraseBackground
= TRUE
, const wxRect
*rect
= (const wxRect
*) NULL
);
178 void MacInstallMenuBar() ;
179 void MacMenuSelect(wxEvtHandler
* handler
, long when
, int macMenuId
, int macMenuItemNum
) ;
180 static wxMenuBar
* MacGetInstalledMenuBar() { return s_macInstalledMenuBar
; }
183 // common part of all ctors
186 #if WXWIN_COMPATIBILITY
187 wxEvtHandler
*m_eventHandler
;
188 #endif // WXWIN_COMPATIBILITY
190 wxArrayString m_titles
;
193 // the accelerator table for all accelerators in all our menus
194 wxAcceleratorTable m_accelTable
;
195 #endif // wxUSE_ACCEL
198 static wxMenuBar
* s_macInstalledMenuBar
;
200 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
203 #endif // _WX_MENU_H_