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(); }
38 virtual void SetTitle(const wxString
& title
);
40 bool ProcessCommand(wxCommandEvent
& event
);
42 // get the menu handle
43 WXHMENU
GetHMenu() const ;
45 // implementation only from now on
46 // -------------------------------
48 bool HandleCommandUpdateStatus( wxMenuItem
* menuItem
, wxWindow
* senderWindow
= NULL
);
49 bool HandleCommandProcess( wxMenuItem
* menuItem
, wxWindow
* senderWindow
= NULL
);
50 void HandleMenuItemHighlighted( wxMenuItem
* menuItem
);
51 void HandleMenuOpened();
52 void HandleMenuClosed();
54 wxMenuImpl
* GetPeer() { return m_peer
; }
56 // make sure we can veto
57 void SetAllowRearrange( bool allow
);
58 bool AllowRearrange() const { return m_allowRearrange
; }
60 // if a menu is used purely for internal implementation reasons (eg wxChoice)
61 // we don't want native menu events being triggered
62 void SetNoEventsMode( bool noEvents
);
63 bool GetNoEventsMode() const { return m_noEventsMode
; }
65 // hide special menu items like exit, preferences etc
66 // that are expected in the app menu
69 bool DoHandleMenuEvent( wxEvent
& evt
);
70 virtual wxMenuItem
* DoAppend(wxMenuItem
*item
);
71 virtual wxMenuItem
* DoInsert(size_t pos
, wxMenuItem
*item
);
72 virtual wxMenuItem
* DoRemove(wxMenuItem
*item
);
75 // common part of all ctors
78 // common part of Do{Append,Insert}(): behaves as Append if pos == -1
79 bool DoInsertOrAppend(wxMenuItem
*item
, size_t pos
= (size_t)-1);
81 // Common part of HandleMenu{Opened,Closed}().
82 void DoHandleMenuOpenedOrClosed(wxEventType evtType
);
85 // if TRUE, insert a break before appending the next item
88 // in this menu rearranging of menu items (esp hiding) is allowed
89 bool m_allowRearrange
;
91 // don't trigger native events
96 DECLARE_DYNAMIC_CLASS(wxMenu
)
99 #if wxOSX_USE_COCOA_OR_CARBON
101 // the iphone only has popup-menus
103 // ----------------------------------------------------------------------------
104 // Menu Bar (a la Windows)
105 // ----------------------------------------------------------------------------
107 class WXDLLIMPEXP_CORE wxMenuBar
: public wxMenuBarBase
111 // default constructor
114 wxMenuBar(long style
);
115 // menubar takes ownership of the menus arrays but copies the titles
116 wxMenuBar(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
= 0);
117 virtual ~wxMenuBar();
119 // menubar construction
120 virtual bool Append( wxMenu
*menu
, const wxString
&title
);
121 virtual bool Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
);
122 virtual wxMenu
*Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
);
123 virtual wxMenu
*Remove(size_t pos
);
125 virtual void EnableTop( size_t pos
, bool flag
);
126 virtual bool IsEnabledTop(size_t pos
) const;
127 virtual void SetMenuLabel( size_t pos
, const wxString
& label
);
128 virtual wxString
GetMenuLabel( size_t pos
) const;
129 virtual bool Enable( bool enable
= true );
130 // for virtual function hiding
131 virtual void Enable( int itemid
, bool enable
)
133 wxMenuBarBase::Enable( itemid
, enable
);
136 // implementation from now on
139 // returns TRUE if we're attached to a frame
140 bool IsAttached() const { return m_menuBarFrame
!= NULL
; }
141 // get the frame we live in
142 wxFrame
*GetFrame() const { return m_menuBarFrame
; }
144 void Attach(wxFrame
*frame
);
146 // if the menubar is modified, the display is not updated automatically,
147 // call this function to update it (m_menuBarFrame should be !NULL)
148 void Refresh(bool eraseBackground
= true, const wxRect
*rect
= NULL
);
150 static void SetAutoWindowMenu( bool enable
) { s_macAutoWindowMenu
= enable
; }
151 static bool GetAutoWindowMenu() { return s_macAutoWindowMenu
; }
153 void MacInstallMenuBar() ;
154 static wxMenuBar
* MacGetInstalledMenuBar() { return s_macInstalledMenuBar
; }
155 static void MacSetCommonMenuBar(wxMenuBar
* menubar
) { s_macCommonMenuBar
=menubar
; }
156 static wxMenuBar
* MacGetCommonMenuBar() { return s_macCommonMenuBar
; }
159 static WXHMENU
MacGetWindowMenuHMenu() { return s_macWindowMenuHandle
; }
161 // common part of all ctors
164 static bool s_macAutoWindowMenu
;
165 static WXHMENU s_macWindowMenuHandle
;
168 static wxMenuBar
* s_macInstalledMenuBar
;
169 static wxMenuBar
* s_macCommonMenuBar
;
174 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
179 #endif // _WX_MENU_H_