1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenu, wxMenuBar classes
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 class WXDLLIMPEXP_FWD_CORE wxFrame
;
17 #include "wx/arrstr.h"
19 // ----------------------------------------------------------------------------
21 // ----------------------------------------------------------------------------
23 class WXDLLIMPEXP_FWD_CORE wxMenuImpl
;
25 class WXDLLIMPEXP_CORE wxMenu
: public wxMenuBase
29 wxMenu(const wxString
& title
, long style
= 0)
30 : wxMenuBase(title
, style
) { Init(); }
32 wxMenu(long style
= 0) : wxMenuBase(style
) { Init(); }
36 virtual void Attach(wxMenuBarBase
*menubar
) ;
40 virtual void SetTitle(const wxString
& title
);
42 bool ProcessCommand(wxCommandEvent
& event
);
44 // get the menu handle
45 WXHMENU
GetHMenu() const ;
47 // implementation only from now on
48 // -------------------------------
50 bool HandleCommandUpdateStatus( wxMenuItem
* menuItem
, wxWindow
* senderWindow
= NULL
);
51 bool HandleCommandProcess( wxMenuItem
* menuItem
, wxWindow
* senderWindow
= NULL
);
52 void HandleMenuItemHighlighted( wxMenuItem
* menuItem
);
53 void HandleMenuOpened();
54 void HandleMenuClosed();
56 wxMenuImpl
* GetPeer() { return m_peer
; }
58 // make sure we can veto
59 void SetAllowRearrange( bool allow
);
60 bool AllowRearrange() const { return m_allowRearrange
; }
62 // if a menu is used purely for internal implementation reasons (eg wxChoice)
63 // we don't want native menu events being triggered
64 void SetNoEventsMode( bool noEvents
);
65 bool GetNoEventsMode() const { return m_noEventsMode
; }
67 // hide special menu items like exit, preferences etc
68 // that are expected in the app menu
71 bool DoHandleMenuEvent( wxEvent
& evt
);
72 virtual wxMenuItem
* DoAppend(wxMenuItem
*item
);
73 virtual wxMenuItem
* DoInsert(size_t pos
, wxMenuItem
*item
);
74 virtual wxMenuItem
* DoRemove(wxMenuItem
*item
);
77 // common part of all ctors
80 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
81 bool DoInsertOrAppend(wxMenuItem
*item
, size_t pos
= (size_t)-1);
83 // terminate the current radio group, if any
86 // if TRUE, insert a breal before appending the next item
89 // in this menu rearranging of menu items (esp hiding) is allowed
90 bool m_allowRearrange
;
92 // don't trigger native events
95 // the position of the first item in the current radio group or -1
96 int m_startRadioGroup
;
100 DECLARE_DYNAMIC_CLASS(wxMenu
)
103 #if wxOSX_USE_COCOA_OR_CARBON
105 // the iphone only has popup-menus
107 // ----------------------------------------------------------------------------
108 // Menu Bar (a la Windows)
109 // ----------------------------------------------------------------------------
111 class WXDLLIMPEXP_CORE wxMenuBar
: public wxMenuBarBase
115 // default constructor
118 wxMenuBar(long style
);
119 // menubar takes ownership of the menus arrays but copies the titles
120 wxMenuBar(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
= 0);
121 virtual ~wxMenuBar();
123 // menubar construction
124 virtual bool Append( wxMenu
*menu
, const wxString
&title
);
125 virtual bool Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
);
126 virtual wxMenu
*Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
);
127 virtual wxMenu
*Remove(size_t pos
);
129 virtual int FindMenuItem(const wxString
& menuString
,
130 const wxString
& itemString
) const;
131 virtual wxMenuItem
* FindItem( int id
, wxMenu
**menu
= NULL
) const;
133 virtual void EnableTop( size_t pos
, bool flag
);
134 virtual void SetMenuLabel( size_t pos
, const wxString
& label
);
135 virtual wxString
GetMenuLabel( size_t pos
) const;
136 virtual bool Enable( bool enable
= true );
137 // for virtual function hiding
138 virtual void Enable( int itemid
, bool enable
)
140 wxMenuBarBase::Enable( itemid
, enable
);
143 // implementation from now on
144 int FindMenu(const wxString
& title
);
147 // returns TRUE if we're attached to a frame
148 bool IsAttached() const { return m_menuBarFrame
!= NULL
; }
149 // get the frame we live in
150 wxFrame
*GetFrame() const { return m_menuBarFrame
; }
152 void Attach(wxFrame
*frame
);
154 // if the menubar is modified, the display is not updated automatically,
155 // call this function to update it (m_menuBarFrame should be !NULL)
156 void Refresh(bool eraseBackground
= true, const wxRect
*rect
= NULL
);
158 static void SetAutoWindowMenu( bool enable
) { s_macAutoWindowMenu
= enable
; }
159 static bool GetAutoWindowMenu() { return s_macAutoWindowMenu
; }
161 void MacInstallMenuBar() ;
162 static wxMenuBar
* MacGetInstalledMenuBar() { return s_macInstalledMenuBar
; }
163 static void MacSetCommonMenuBar(wxMenuBar
* menubar
) { s_macCommonMenuBar
=menubar
; }
164 static wxMenuBar
* MacGetCommonMenuBar() { return s_macCommonMenuBar
; }
167 static WXHMENU
MacGetWindowMenuHMenu() { return s_macWindowMenuHandle
; }
169 // common part of all ctors
172 wxArrayString m_titles
;
173 static bool s_macAutoWindowMenu
;
174 static WXHMENU s_macWindowMenuHandle
;
177 static wxMenuBar
* s_macInstalledMenuBar
;
178 static wxMenuBar
* s_macCommonMenuBar
;
183 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
188 #endif // _WX_MENU_H_