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 virtual void Attach(wxMenuBarBase
*menubar
) ;
38 virtual void SetTitle(const wxString
& title
);
41 bool ProcessCommand(wxCommandEvent
& event
);
43 // implementation only from now on
44 // -------------------------------
46 int MacGetIndexFromId( int id
) ;
47 int MacGetIndexFromItem( wxMenuItem
*pItem
) ;
48 void MacEnableMenu( bool bDoEnable
) ;
49 // MacOS needs to know about submenus somewhere within this menu
50 // before it can be displayed , also hide special menu items like preferences
51 // that are handled by the OS
52 void MacBeforeDisplay( bool isSubMenu
) ;
53 // undo all changes from the MacBeforeDisplay call
54 void MacAfterDisplay( bool isSubMenu
) ;
56 // semi-private accessors
57 // get the window which contains this menu
58 wxWindow
*GetWindow() const;
59 // get the menu handle
60 WXHMENU
GetHMenu() const { return m_hMenu
; }
62 short MacGetMenuId() { return m_macMenuId
; }
65 virtual wxMenuItem
* DoAppend(wxMenuItem
*item
);
66 virtual wxMenuItem
* DoInsert(size_t pos
, wxMenuItem
*item
);
67 virtual wxMenuItem
* DoRemove(wxMenuItem
*item
);
70 // common part of all ctors
73 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
74 bool DoInsertOrAppend(wxMenuItem
*item
, size_t pos
= (size_t)-1);
76 // terminate the current radio group, if any
79 // if TRUE, insert a breal before appending the next item
82 // the position of the first item in the current radio group or -1
83 int m_startRadioGroup
;
85 // the menu handle of this menu
90 static short s_macNextMenuId
;
92 DECLARE_DYNAMIC_CLASS(wxMenu
)
95 // ----------------------------------------------------------------------------
96 // Menu Bar (a la Windows)
97 // ----------------------------------------------------------------------------
99 class WXDLLEXPORT wxMenuBar
: public wxMenuBarBase
103 // default constructor
106 wxMenuBar(long style
);
107 // menubar takes ownership of the menus arrays but copies the titles
108 wxMenuBar(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
= 0);
109 virtual ~wxMenuBar();
111 // menubar construction
112 virtual bool Append( wxMenu
*menu
, const wxString
&title
);
113 virtual bool Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
);
114 virtual wxMenu
*Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
);
115 virtual wxMenu
*Remove(size_t pos
);
117 virtual int FindMenuItem(const wxString
& menuString
,
118 const wxString
& itemString
) const;
119 virtual wxMenuItem
* FindItem( int id
, wxMenu
**menu
= NULL
) const;
121 virtual void EnableTop( size_t pos
, bool flag
);
122 virtual void SetLabelTop( size_t pos
, const wxString
& label
);
123 virtual wxString
GetLabelTop( size_t pos
) const;
124 virtual bool Enable( bool enable
= TRUE
);
125 // for virtual function hiding
126 virtual void Enable( int itemid
, bool enable
)
128 wxMenuBarBase::Enable( itemid
, enable
);
131 // implementation from now on
133 int FindMenu(const wxString
& title
);
136 // returns TRUE if we're attached to a frame
137 bool IsAttached() const { return m_menuBarFrame
!= NULL
; }
138 // get the frame we live in
139 wxFrame
*GetFrame() const { return m_menuBarFrame
; }
141 void Attach(wxFrame
*frame
);
143 // clear the invoking window for all menus and submenus
144 void UnsetInvokingWindow() ;
146 // set the invoking window for all menus and submenus
147 void SetInvokingWindow( wxFrame
* frame
) ;
149 // if the menubar is modified, the display is not updated automatically,
150 // call this function to update it (m_menuBarFrame should be !NULL)
151 void Refresh(bool eraseBackground
= TRUE
, const wxRect
*rect
= (const wxRect
*) NULL
);
153 static void SetAutoWindowMenu( bool enable
) { s_macAutoWindowMenu
= enable
; }
154 static bool GetAutoWindowMenu() { return s_macAutoWindowMenu
; }
156 void MacInstallMenuBar() ;
157 static wxMenuBar
* MacGetInstalledMenuBar() { return s_macInstalledMenuBar
; }
158 static void MacSetCommonMenuBar(wxMenuBar
* menubar
) { s_macCommonMenuBar
=menubar
; }
159 static wxMenuBar
* MacGetCommonMenuBar() { return s_macCommonMenuBar
; }
162 static WXHMENU
MacGetWindowMenuHMenu() { return s_macWindowMenuHandle
; }
164 // common part of all ctors
166 wxWindow
*m_invokingWindow
;
168 wxArrayString m_titles
;
169 static bool s_macAutoWindowMenu
;
170 static WXHMENU s_macWindowMenuHandle
;
173 static wxMenuBar
* s_macInstalledMenuBar
;
174 static wxMenuBar
* s_macCommonMenuBar
;
176 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
179 #endif // _WX_MENU_H_