]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mac/menu.h
added support for gcc precompiled headers
[wxWidgets.git] / include / wx / mac / menu.h
CommitLineData
0dbd6262
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: menu.h
3// Purpose: wxMenu, wxMenuBar classes
a31a5f85 4// Author: Stefan Csomor
0dbd6262 5// Modified by:
a31a5f85 6// Created: 1998-01-01
0dbd6262 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
e40298d5 9// Licence: wxWindows licence
0dbd6262
SC
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_MENU_H_
13#define _WX_MENU_H_
14
af49c4b8 15#if defined(__GNUG__) && !defined(__APPLE__)
0dbd6262
SC
16#pragma interface "menu.h"
17#endif
18
e7549107 19class WXDLLEXPORT wxFrame;
0dbd6262
SC
20
21// ----------------------------------------------------------------------------
22// Menu
23// ----------------------------------------------------------------------------
0dbd6262 24
e7549107
SC
25class WXDLLEXPORT wxMenu : public wxMenuBase
26{
0dbd6262 27public:
e7549107
SC
28 // ctors & dtor
29 wxMenu(const wxString& title, long style = 0)
30 : wxMenuBase(title, style) { Init(); }
519cb848 31
e7549107
SC
32 wxMenu(long style = 0) : wxMenuBase(style) { Init(); }
33
34 virtual ~wxMenu();
35
36 // implement base class virtuals
37 virtual bool DoAppend(wxMenuItem *item);
38 virtual bool DoInsert(size_t pos, wxMenuItem *item);
39 virtual wxMenuItem *DoRemove(wxMenuItem *item);
f3fb0a07 40 virtual void Attach(wxMenuBarBase *menubar) ;
e7549107
SC
41
42 virtual void Break();
43
44 virtual void SetTitle(const wxString& title);
45
46 // MSW-specific
47 bool ProcessCommand(wxCommandEvent& event);
48
e7549107
SC
49 // implementation only from now on
50 // -------------------------------
51
e40298d5
JS
52 int MacGetIndexFromId( int id ) ;
53 int MacGetIndexFromItem( wxMenuItem *pItem ) ;
54 void MacEnableMenu( bool bDoEnable ) ;
578dc950
SC
55 // MacOS needs to know about submenus somewhere within this menu
56 // before it can be displayed , also hide special menu items like preferences
57 // that are handled by the OS
58 void MacBeforeDisplay( bool isSubMenu ) ;
59 // undo all changes from the MacBeforeDisplay call
60 void MacAfterDisplay( bool isSubMenu ) ;
e7549107
SC
61
62 // semi-private accessors
63 // get the window which contains this menu
64 wxWindow *GetWindow() const;
65 // get the menu handle
66 WXHMENU GetHMenu() const { return m_hMenu; }
67
e40298d5 68 short MacGetMenuId() { return m_macMenuId ; }
e7549107
SC
69
70private:
71 // common part of all ctors
72 void Init();
73
74 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
75 bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1);
76
f3fb0a07
SC
77 // terminate the current radio group, if any
78 void EndRadioGroup();
79
e7549107
SC
80 // if TRUE, insert a breal before appending the next item
81 bool m_doBreak;
82
f3fb0a07
SC
83 // the position of the first item in the current radio group or -1
84 int m_startRadioGroup;
85
e7549107
SC
86 // the menu handle of this menu
87 WXHMENU m_hMenu;
88
e40298d5 89 short m_macMenuId;
e7549107 90
e40298d5 91 static short s_macNextMenuId ;
e7549107
SC
92
93 DECLARE_DYNAMIC_CLASS(wxMenu)
0dbd6262
SC
94};
95
96// ----------------------------------------------------------------------------
97// Menu Bar (a la Windows)
98// ----------------------------------------------------------------------------
e7549107
SC
99
100class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
0dbd6262 101{
e7549107
SC
102public:
103 // ctors & dtor
104 // default constructor
105 wxMenuBar();
106 // unused under MSW
107 wxMenuBar(long style);
108 // menubar takes ownership of the menus arrays but copies the titles
109 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
110 virtual ~wxMenuBar();
111
112 // menubar construction
113 virtual bool Append( wxMenu *menu, const wxString &title );
114 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
115 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
116 virtual wxMenu *Remove(size_t pos);
117
118 virtual int FindMenuItem(const wxString& menuString,
119 const wxString& itemString) const;
120 virtual wxMenuItem* FindItem( int id, wxMenu **menu = NULL ) const;
121
122 virtual void EnableTop( size_t pos, bool flag );
123 virtual void SetLabelTop( size_t pos, const wxString& label );
124 virtual wxString GetLabelTop( size_t pos ) const;
125
126 // compatibility: these functions are deprecated
127#if WXWIN_COMPATIBILITY
128 void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
129 wxEvtHandler *GetEventHandler() { return m_eventHandler; }
130
131 bool Enabled(int id) const { return IsEnabled(id); }
132 bool Checked(int id) const { return IsChecked(id); }
133#endif // WXWIN_COMPATIBILITY
134
135 // implementation from now on
136 WXHMENU Create();
137 int FindMenu(const wxString& title);
138 void Detach();
139
140 // returns TRUE if we're attached to a frame
141 bool IsAttached() const { return m_menuBarFrame != NULL; }
142 // get the frame we live in
143 wxFrame *GetFrame() const { return m_menuBarFrame; }
144 // attach to a frame
145 void Attach(wxFrame *frame);
146
e40298d5
JS
147 // clear the invoking window for all menus and submenus
148 void UnsetInvokingWindow() ;
2b5f62a0 149
e40298d5
JS
150 // set the invoking window for all menus and submenus
151 void SetInvokingWindow( wxFrame* frame ) ;
e7549107
SC
152
153 // if the menubar is modified, the display is not updated automatically,
154 // call this function to update it (m_menuBarFrame should be !NULL)
6d6da89c 155 void Refresh(bool eraseBackground = TRUE, const wxRect *rect = (const wxRect *) NULL);
0dbd6262 156
519cb848 157 void MacInstallMenuBar() ;
e7549107 158 static wxMenuBar* MacGetInstalledMenuBar() { return s_macInstalledMenuBar ; }
1b1d2207
DE
159 static void MacSetCommonMenuBar(wxMenuBar* menubar) { s_macCommonMenuBar=menubar; }
160 static wxMenuBar* MacGetCommonMenuBar() { return s_macCommonMenuBar; }
e7549107
SC
161
162protected:
163 // common part of all ctors
164 void Init();
f3fb0a07 165 wxWindow *m_invokingWindow;
519cb848 166
e7549107
SC
167#if WXWIN_COMPATIBILITY
168 wxEvtHandler *m_eventHandler;
169#endif // WXWIN_COMPATIBILITY
519cb848 170
e7549107
SC
171 wxArrayString m_titles;
172
e7549107 173private:
e40298d5 174 static wxMenuBar* s_macInstalledMenuBar ;
1b1d2207 175 static wxMenuBar* s_macCommonMenuBar ;
e7549107
SC
176
177 DECLARE_DYNAMIC_CLASS(wxMenuBar)
0dbd6262
SC
178};
179
180#endif // _WX_MENU_H_