1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenu, wxMenuBar classes
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
14 class WXDLLIMPEXP_FWD_CORE wxFrame
;
16 #include "wx/arrstr.h"
18 // ----------------------------------------------------------------------------
20 // ----------------------------------------------------------------------------
22 class WXDLLIMPEXP_FWD_CORE wxMenuImpl
;
24 class WXDLLIMPEXP_CORE wxMenu
: public wxMenuBase
28 wxMenu(const wxString
& title
, long style
= 0)
29 : wxMenuBase(title
, style
) { Init(); }
31 wxMenu(long style
= 0) : wxMenuBase(style
) { Init(); }
37 virtual void SetTitle(const wxString
& title
);
39 bool ProcessCommand(wxCommandEvent
& event
);
41 // get the menu handle
42 WXHMENU
GetHMenu() const ;
44 // implementation only from now on
45 // -------------------------------
47 bool HandleCommandUpdateStatus( wxMenuItem
* menuItem
, wxWindow
* senderWindow
= NULL
);
48 bool HandleCommandProcess( wxMenuItem
* menuItem
, wxWindow
* senderWindow
= NULL
);
49 void HandleMenuItemHighlighted( wxMenuItem
* menuItem
);
50 void HandleMenuOpened();
51 void HandleMenuClosed();
53 wxMenuImpl
* GetPeer() { return m_peer
; }
55 // make sure we can veto
56 void SetAllowRearrange( bool allow
);
57 bool AllowRearrange() const { return m_allowRearrange
; }
59 // if a menu is used purely for internal implementation reasons (eg wxChoice)
60 // we don't want native menu events being triggered
61 void SetNoEventsMode( bool noEvents
);
62 bool GetNoEventsMode() const { return m_noEventsMode
; }
64 // hide special menu items like exit, preferences etc
65 // that are expected in the app menu
68 bool DoHandleMenuEvent( wxEvent
& evt
);
69 virtual wxMenuItem
* DoAppend(wxMenuItem
*item
);
70 virtual wxMenuItem
* DoInsert(size_t pos
, wxMenuItem
*item
);
71 virtual wxMenuItem
* DoRemove(wxMenuItem
*item
);
74 // common part of all ctors
77 // common part of Do{Append,Insert}(): behaves as Append if pos == -1
78 bool DoInsertOrAppend(wxMenuItem
*item
, size_t pos
= (size_t)-1);
80 // Common part of HandleMenu{Opened,Closed}().
81 void DoHandleMenuOpenedOrClosed(wxEventType evtType
);
84 // if TRUE, insert a break before appending the next item
87 // in this menu rearranging of menu items (esp hiding) is allowed
88 bool m_allowRearrange
;
90 // don't trigger native events
95 DECLARE_DYNAMIC_CLASS(wxMenu
)
98 #if wxOSX_USE_COCOA_OR_CARBON
100 // the iphone only has popup-menus
102 // ----------------------------------------------------------------------------
103 // Menu Bar (a la Windows)
104 // ----------------------------------------------------------------------------
106 class WXDLLIMPEXP_CORE wxMenuBar
: public wxMenuBarBase
110 // default constructor
113 wxMenuBar(long style
);
114 // menubar takes ownership of the menus arrays but copies the titles
115 wxMenuBar(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
= 0);
116 virtual ~wxMenuBar();
118 // menubar construction
119 virtual bool Append( wxMenu
*menu
, const wxString
&title
);
120 virtual bool Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
);
121 virtual wxMenu
*Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
);
122 virtual wxMenu
*Remove(size_t pos
);
124 virtual void EnableTop( size_t pos
, bool flag
);
125 virtual bool IsEnabledTop(size_t pos
) const;
126 virtual void SetMenuLabel( size_t pos
, const wxString
& label
);
127 virtual wxString
GetMenuLabel( size_t pos
) const;
128 virtual bool Enable( bool enable
= true );
129 // for virtual function hiding
130 virtual void Enable( int itemid
, bool enable
)
132 wxMenuBarBase::Enable( itemid
, enable
);
135 // implementation from now on
138 // returns TRUE if we're attached to a frame
139 bool IsAttached() const { return m_menuBarFrame
!= NULL
; }
140 // get the frame we live in
141 wxFrame
*GetFrame() const { return m_menuBarFrame
; }
143 void Attach(wxFrame
*frame
);
145 // if the menubar is modified, the display is not updated automatically,
146 // call this function to update it (m_menuBarFrame should be !NULL)
147 void Refresh(bool eraseBackground
= true, const wxRect
*rect
= NULL
);
149 static void SetAutoWindowMenu( bool enable
) { s_macAutoWindowMenu
= enable
; }
150 static bool GetAutoWindowMenu() { return s_macAutoWindowMenu
; }
152 void MacInstallMenuBar() ;
153 static wxMenuBar
* MacGetInstalledMenuBar() { return s_macInstalledMenuBar
; }
154 static void MacSetCommonMenuBar(wxMenuBar
* menubar
) { s_macCommonMenuBar
=menubar
; }
155 static wxMenuBar
* MacGetCommonMenuBar() { return s_macCommonMenuBar
; }
158 static WXHMENU
MacGetWindowMenuHMenu() { return s_macWindowMenuHandle
; }
160 // common part of all ctors
163 static bool s_macAutoWindowMenu
;
164 static WXHMENU s_macWindowMenuHandle
;
167 static wxMenuBar
* s_macInstalledMenuBar
;
168 static wxMenuBar
* s_macCommonMenuBar
;
173 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
178 #endif // _WX_MENU_H_