]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mac/menu.h
Removed obsolete wxDate and wxTime classes.
[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
49#if WXWIN_COMPATIBILITY
50 wxMenu(const wxString& title, const wxFunction func)
51 : wxMenuBase(title)
52 {
53 Callback(func);
54 }
55#endif // WXWIN_COMPATIBILITY
56
57 // implementation only from now on
58 // -------------------------------
59
e40298d5
JS
60 int MacGetIndexFromId( int id ) ;
61 int MacGetIndexFromItem( wxMenuItem *pItem ) ;
62 void MacEnableMenu( bool bDoEnable ) ;
578dc950
SC
63 // MacOS needs to know about submenus somewhere within this menu
64 // before it can be displayed , also hide special menu items like preferences
65 // that are handled by the OS
66 void MacBeforeDisplay( bool isSubMenu ) ;
67 // undo all changes from the MacBeforeDisplay call
68 void MacAfterDisplay( bool isSubMenu ) ;
e7549107
SC
69
70 // semi-private accessors
71 // get the window which contains this menu
72 wxWindow *GetWindow() const;
73 // get the menu handle
74 WXHMENU GetHMenu() const { return m_hMenu; }
75
e40298d5 76 short MacGetMenuId() { return m_macMenuId ; }
e7549107
SC
77
78private:
79 // common part of all ctors
80 void Init();
81
82 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
83 bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1);
84
f3fb0a07
SC
85 // terminate the current radio group, if any
86 void EndRadioGroup();
87
e7549107
SC
88 // if TRUE, insert a breal before appending the next item
89 bool m_doBreak;
90
f3fb0a07
SC
91 // the position of the first item in the current radio group or -1
92 int m_startRadioGroup;
93
e7549107
SC
94 // the menu handle of this menu
95 WXHMENU m_hMenu;
96
e40298d5 97 short m_macMenuId;
e7549107 98
e40298d5 99 static short s_macNextMenuId ;
e7549107
SC
100
101 DECLARE_DYNAMIC_CLASS(wxMenu)
0dbd6262
SC
102};
103
104// ----------------------------------------------------------------------------
105// Menu Bar (a la Windows)
106// ----------------------------------------------------------------------------
e7549107
SC
107
108class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
0dbd6262 109{
e7549107
SC
110public:
111 // ctors & dtor
112 // default constructor
113 wxMenuBar();
114 // unused under MSW
115 wxMenuBar(long style);
116 // menubar takes ownership of the menus arrays but copies the titles
117 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
118 virtual ~wxMenuBar();
119
120 // menubar construction
121 virtual bool Append( wxMenu *menu, const wxString &title );
122 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
123 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
124 virtual wxMenu *Remove(size_t pos);
125
126 virtual int FindMenuItem(const wxString& menuString,
127 const wxString& itemString) const;
128 virtual wxMenuItem* FindItem( int id, wxMenu **menu = NULL ) const;
129
130 virtual void EnableTop( size_t pos, bool flag );
131 virtual void SetLabelTop( size_t pos, const wxString& label );
132 virtual wxString GetLabelTop( size_t pos ) const;
133
134 // compatibility: these functions are deprecated
135#if WXWIN_COMPATIBILITY
136 void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
137 wxEvtHandler *GetEventHandler() { return m_eventHandler; }
138
139 bool Enabled(int id) const { return IsEnabled(id); }
140 bool Checked(int id) const { return IsChecked(id); }
141#endif // WXWIN_COMPATIBILITY
142
143 // implementation from now on
144 WXHMENU Create();
145 int FindMenu(const wxString& title);
146 void Detach();
147
148 // returns TRUE if we're attached to a frame
149 bool IsAttached() const { return m_menuBarFrame != NULL; }
150 // get the frame we live in
151 wxFrame *GetFrame() const { return m_menuBarFrame; }
152 // attach to a frame
153 void Attach(wxFrame *frame);
154
e40298d5
JS
155 // clear the invoking window for all menus and submenus
156 void UnsetInvokingWindow() ;
2b5f62a0 157
e40298d5
JS
158 // set the invoking window for all menus and submenus
159 void SetInvokingWindow( wxFrame* frame ) ;
e7549107
SC
160
161 // if the menubar is modified, the display is not updated automatically,
162 // call this function to update it (m_menuBarFrame should be !NULL)
6d6da89c 163 void Refresh(bool eraseBackground = TRUE, const wxRect *rect = (const wxRect *) NULL);
0dbd6262 164
519cb848 165 void MacInstallMenuBar() ;
e7549107
SC
166 static wxMenuBar* MacGetInstalledMenuBar() { return s_macInstalledMenuBar ; }
167
168protected:
169 // common part of all ctors
170 void Init();
f3fb0a07 171 wxWindow *m_invokingWindow;
519cb848 172
e7549107
SC
173#if WXWIN_COMPATIBILITY
174 wxEvtHandler *m_eventHandler;
175#endif // WXWIN_COMPATIBILITY
519cb848 176
e7549107
SC
177 wxArrayString m_titles;
178
e7549107 179private:
e40298d5 180 static wxMenuBar* s_macInstalledMenuBar ;
e7549107
SC
181
182 DECLARE_DYNAMIC_CLASS(wxMenuBar)
0dbd6262
SC
183};
184
185#endif // _WX_MENU_H_