1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenu, wxMenuBar classes
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 class WXDLLEXPORT wxFrame
;
17 #include "wx/arrstr.h"
19 // ----------------------------------------------------------------------------
21 // ----------------------------------------------------------------------------
23 class WXDLLEXPORT wxMenu
: public wxMenuBase
27 wxMenu(const wxString
& title
, long style
= 0)
28 : wxMenuBase(title
, style
) { Init(); }
30 wxMenu(long style
= 0) : wxMenuBase(style
) { Init(); }
34 // implement base class virtuals
35 virtual wxMenuItem
* DoAppend(wxMenuItem
*item
);
36 virtual wxMenuItem
* DoInsert(size_t pos
, wxMenuItem
*item
);
37 virtual wxMenuItem
* DoRemove(wxMenuItem
*item
);
38 virtual void Attach(wxMenuBarBase
*menubar
) ;
42 virtual void SetTitle(const wxString
& title
);
45 bool ProcessCommand(wxCommandEvent
& event
);
47 // implementation only from now on
48 // -------------------------------
50 int MacGetIndexFromId( int id
) ;
51 int MacGetIndexFromItem( wxMenuItem
*pItem
) ;
52 void MacEnableMenu( bool bDoEnable
) ;
53 // MacOS needs to know about submenus somewhere within this menu
54 // before it can be displayed , also hide special menu items like preferences
55 // that are handled by the OS
56 void MacBeforeDisplay( bool isSubMenu
) ;
57 // undo all changes from the MacBeforeDisplay call
58 void MacAfterDisplay( bool isSubMenu
) ;
60 // semi-private accessors
61 // get the window which contains this menu
62 wxWindow
*GetWindow() const;
63 // get the menu handle
64 WXHMENU
GetHMenu() const { return m_hMenu
; }
66 short MacGetMenuId() { return m_macMenuId
; }
69 // common part of all ctors
72 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
73 bool DoInsertOrAppend(wxMenuItem
*item
, size_t pos
= (size_t)-1);
75 // terminate the current radio group, if any
78 // if TRUE, insert a breal before appending the next item
81 // the position of the first item in the current radio group or -1
82 int m_startRadioGroup
;
84 // the menu handle of this menu
89 static short s_macNextMenuId
;
91 DECLARE_DYNAMIC_CLASS(wxMenu
)
94 // ----------------------------------------------------------------------------
95 // Menu Bar (a la Windows)
96 // ----------------------------------------------------------------------------
98 class WXDLLEXPORT wxMenuBar
: public wxMenuBarBase
102 // default constructor
105 wxMenuBar(long style
);
106 // menubar takes ownership of the menus arrays but copies the titles
107 wxMenuBar(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
= 0);
108 virtual ~wxMenuBar();
110 // menubar construction
111 virtual bool Append( wxMenu
*menu
, const wxString
&title
);
112 virtual bool Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
);
113 virtual wxMenu
*Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
);
114 virtual wxMenu
*Remove(size_t pos
);
116 virtual int FindMenuItem(const wxString
& menuString
,
117 const wxString
& itemString
) const;
118 virtual wxMenuItem
* FindItem( int id
, wxMenu
**menu
= NULL
) const;
120 virtual void EnableTop( size_t pos
, bool flag
);
121 virtual void SetLabelTop( size_t pos
, const wxString
& label
);
122 virtual wxString
GetLabelTop( size_t pos
) const;
123 virtual bool Enable( bool enable
= TRUE
);
124 // for virtual function hiding
125 virtual void Enable( int itemid
, bool enable
)
127 wxMenuBarBase::Enable( itemid
, enable
);
130 // implementation from now on
132 int FindMenu(const wxString
& title
);
135 // returns TRUE if we're attached to a frame
136 bool IsAttached() const { return m_menuBarFrame
!= NULL
; }
137 // get the frame we live in
138 wxFrame
*GetFrame() const { return m_menuBarFrame
; }
140 void Attach(wxFrame
*frame
);
142 // clear the invoking window for all menus and submenus
143 void UnsetInvokingWindow() ;
145 // set the invoking window for all menus and submenus
146 void SetInvokingWindow( wxFrame
* frame
) ;
148 // if the menubar is modified, the display is not updated automatically,
149 // call this function to update it (m_menuBarFrame should be !NULL)
150 void Refresh(bool eraseBackground
= TRUE
, const wxRect
*rect
= (const wxRect
*) NULL
);
152 static void SetAutoWindowMenu( bool enable
) { s_macAutoWindowMenu
= enable
; }
153 static bool GetAutoWindowMenu() { return s_macAutoWindowMenu
; }
155 void MacInstallMenuBar() ;
156 static wxMenuBar
* MacGetInstalledMenuBar() { return s_macInstalledMenuBar
; }
157 static void MacSetCommonMenuBar(wxMenuBar
* menubar
) { s_macCommonMenuBar
=menubar
; }
158 static wxMenuBar
* MacGetCommonMenuBar() { return s_macCommonMenuBar
; }
161 static WXHMENU
MacGetWindowMenuHMenu() { return s_macWindowMenuHandle
; }
163 // common part of all ctors
165 wxWindow
*m_invokingWindow
;
167 wxArrayString m_titles
;
168 static bool s_macAutoWindowMenu
;
169 static WXHMENU s_macWindowMenuHandle
;
172 static wxMenuBar
* s_macInstalledMenuBar
;
173 static wxMenuBar
* s_macCommonMenuBar
;
175 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
178 #endif // _WX_MENU_H_