]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/classic/menu.h
On screens with restricted space, it's useful to be able to add controls
[wxWidgets.git] / include / wx / mac / classic / menu.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: menu.h
3 // Purpose: wxMenu, wxMenuBar classes
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_MENU_H_
13 #define _WX_MENU_H_
14
15 class WXDLLEXPORT wxFrame;
16
17 #include "wx/arrstr.h"
18
19 // ----------------------------------------------------------------------------
20 // Menu
21 // ----------------------------------------------------------------------------
22
23 class WXDLLEXPORT wxMenu : public wxMenuBase
24 {
25 public:
26 // ctors & dtor
27 wxMenu(const wxString& title, long style = 0)
28 : wxMenuBase(title, style) { Init(); }
29
30 wxMenu(long style = 0) : wxMenuBase(style) { Init(); }
31
32 virtual ~wxMenu();
33
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) ;
39
40 virtual void Break();
41
42 virtual void SetTitle(const wxString& title);
43
44 // MSW-specific
45 bool ProcessCommand(wxCommandEvent& event);
46
47 // implementation only from now on
48 // -------------------------------
49
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 ) ;
59
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; }
65
66 short MacGetMenuId() { return m_macMenuId ; }
67
68 private:
69 // common part of all ctors
70 void Init();
71
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);
74
75 // terminate the current radio group, if any
76 void EndRadioGroup();
77
78 // if TRUE, insert a breal before appending the next item
79 bool m_doBreak;
80
81 // the position of the first item in the current radio group or -1
82 int m_startRadioGroup;
83
84 // the menu handle of this menu
85 WXHMENU m_hMenu;
86
87 short m_macMenuId;
88
89 static short s_macNextMenuId ;
90
91 DECLARE_DYNAMIC_CLASS(wxMenu)
92 };
93
94 // ----------------------------------------------------------------------------
95 // Menu Bar (a la Windows)
96 // ----------------------------------------------------------------------------
97
98 class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
99 {
100 public:
101 // ctors & dtor
102 // default constructor
103 wxMenuBar();
104 // unused under MSW
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();
109
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);
115
116 virtual int FindMenuItem(const wxString& menuString,
117 const wxString& itemString) const;
118 virtual wxMenuItem* FindItem( int id, wxMenu **menu = NULL ) const;
119
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
124 // implementation from now on
125 WXHMENU Create();
126 int FindMenu(const wxString& title);
127 void Detach();
128
129 // returns TRUE if we're attached to a frame
130 bool IsAttached() const { return m_menuBarFrame != NULL; }
131 // get the frame we live in
132 wxFrame *GetFrame() const { return m_menuBarFrame; }
133 // attach to a frame
134 void Attach(wxFrame *frame);
135
136 // clear the invoking window for all menus and submenus
137 void UnsetInvokingWindow() ;
138
139 // set the invoking window for all menus and submenus
140 void SetInvokingWindow( wxFrame* frame ) ;
141
142 // if the menubar is modified, the display is not updated automatically,
143 // call this function to update it (m_menuBarFrame should be !NULL)
144 void Refresh(bool eraseBackground = TRUE, const wxRect *rect = (const wxRect *) NULL);
145
146 void MacInstallMenuBar() ;
147 static wxMenuBar* MacGetInstalledMenuBar() { return s_macInstalledMenuBar ; }
148 static void MacSetCommonMenuBar(wxMenuBar* menubar) { s_macCommonMenuBar=menubar; }
149 static wxMenuBar* MacGetCommonMenuBar() { return s_macCommonMenuBar; }
150
151 protected:
152 // common part of all ctors
153 void Init();
154 wxWindow *m_invokingWindow;
155
156 wxArrayString m_titles;
157
158 private:
159 static wxMenuBar* s_macInstalledMenuBar ;
160 static wxMenuBar* s_macCommonMenuBar ;
161
162 DECLARE_DYNAMIC_CLASS(wxMenuBar)
163 };
164
165 #endif // _WX_MENU_H_