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