1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenu, wxMenuBar classes
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #if defined(__GNUG__) && !defined(__APPLE__)
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 int MacGetIndexFromId( int id
) ;
67 int MacGetIndexFromItem( wxMenuItem
*pItem
) ;
68 void MacEnableMenu( bool bDoEnable
) ;
70 // semi-private accessors
71 // get the window which contains this menu
72 wxWindow
*GetWindow() const;
73 // get the menu handle
74 WXHMENU
GetHMenu() const { return m_hMenu
; }
76 short MacGetMenuId() { return m_macMenuId
; }
78 // called by wxMenuBar to build its accel table from the accels of all menus
79 bool HasAccels() const { return !m_accels
.IsEmpty(); }
80 size_t GetAccelCount() const { return m_accels
.GetCount(); }
81 size_t CopyAccels(wxAcceleratorEntry
*accels
) const;
83 // called by wxMenuItem when its accels changes
84 void UpdateAccel(wxMenuItem
*item
);
86 // helper used by wxMenu itself (returns the index in m_accels)
87 int FindAccel(int id
) const;
91 // common part of all ctors
94 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
95 bool DoInsertOrAppend(wxMenuItem
*item
, size_t pos
= (size_t)-1);
97 // if TRUE, insert a breal before appending the next item
100 // the menu handle of this menu
105 static short s_macNextMenuId
;
107 // the accelerators for our menu items
108 wxAcceleratorArray m_accels
;
109 #endif // wxUSE_ACCEL
111 DECLARE_DYNAMIC_CLASS(wxMenu
)
114 // ----------------------------------------------------------------------------
115 // Menu Bar (a la Windows)
116 // ----------------------------------------------------------------------------
118 class WXDLLEXPORT wxMenuBar
: public wxMenuBarBase
122 // default constructor
125 wxMenuBar(long style
);
126 // menubar takes ownership of the menus arrays but copies the titles
127 wxMenuBar(int n
, wxMenu
*menus
[], const wxString titles
[]);
128 virtual ~wxMenuBar();
130 // menubar construction
131 virtual bool Append( wxMenu
*menu
, const wxString
&title
);
132 virtual bool Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
);
133 virtual wxMenu
*Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
);
134 virtual wxMenu
*Remove(size_t pos
);
136 virtual int FindMenuItem(const wxString
& menuString
,
137 const wxString
& itemString
) const;
138 virtual wxMenuItem
* FindItem( int id
, wxMenu
**menu
= NULL
) const;
140 virtual void EnableTop( size_t pos
, bool flag
);
141 virtual void SetLabelTop( size_t pos
, const wxString
& label
);
142 virtual wxString
GetLabelTop( size_t pos
) const;
144 // compatibility: these functions are deprecated
145 #if WXWIN_COMPATIBILITY
146 void SetEventHandler(wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
147 wxEvtHandler
*GetEventHandler() { return m_eventHandler
; }
149 bool Enabled(int id
) const { return IsEnabled(id
); }
150 bool Checked(int id
) const { return IsChecked(id
); }
151 #endif // WXWIN_COMPATIBILITY
153 // implementation from now on
155 int FindMenu(const wxString
& title
);
158 // returns TRUE if we're attached to a frame
159 bool IsAttached() const { return m_menuBarFrame
!= NULL
; }
160 // get the frame we live in
161 wxFrame
*GetFrame() const { return m_menuBarFrame
; }
163 void Attach(wxFrame
*frame
);
165 // clear the invoking window for all menus and submenus
166 void UnsetInvokingWindow() ;
168 // set the invoking window for all menus and submenus
169 void SetInvokingWindow( wxFrame
* frame
) ;
171 // get the accel table for all the menus
172 const wxAcceleratorTable
& GetAccelTable() const { return m_accelTable
; }
174 // update the accel table (must be called after adding/deletign a menu)
175 void RebuildAccelTable();
176 #endif // wxUSE_ACCEL
178 // if the menubar is modified, the display is not updated automatically,
179 // call this function to update it (m_menuBarFrame should be !NULL)
180 void Refresh(bool eraseBackground
= TRUE
, const wxRect
*rect
= (const wxRect
*) NULL
);
182 void MacInstallMenuBar() ;
183 static wxMenuBar
* MacGetInstalledMenuBar() { return s_macInstalledMenuBar
; }
186 // common part of all ctors
189 #if WXWIN_COMPATIBILITY
190 wxEvtHandler
*m_eventHandler
;
191 #endif // WXWIN_COMPATIBILITY
193 wxArrayString m_titles
;
196 // the accelerator table for all accelerators in all our menus
197 wxAcceleratorTable m_accelTable
;
198 #endif // wxUSE_ACCEL
201 static wxMenuBar
* s_macInstalledMenuBar
;
203 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
206 #endif // _WX_MENU_H_