]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: menu.h | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
58614078 RR |
5 | // Id: $Id$ |
6 | // Copyright: (c) 1998 Robert Roebling, Julian Smart | |
83885a39 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | ||
11 | #ifndef __GTKMENUH__ | |
12 | #define __GTKMENUH__ | |
13 | ||
14 | #ifdef __GNUG__ | |
15 | #pragma interface | |
16 | #endif | |
17 | ||
18 | #include "wx/defs.h" | |
19 | #include "wx/object.h" | |
20 | #include "wx/list.h" | |
21 | #include "wx/window.h" | |
6ca41e57 | 22 | #include "wx/menuitem.h" |
c801d85f KB |
23 | |
24 | //----------------------------------------------------------------------------- | |
25 | // classes | |
26 | //----------------------------------------------------------------------------- | |
27 | ||
28 | class wxMenuBar; | |
29 | class wxMenuItem; | |
30 | class wxMenu; | |
31 | ||
e2414cbe RR |
32 | //----------------------------------------------------------------------------- |
33 | // const | |
34 | //----------------------------------------------------------------------------- | |
35 | ||
36 | #define ID_SEPARATOR (-1) | |
37 | ||
c801d85f KB |
38 | //----------------------------------------------------------------------------- |
39 | // wxMenuBar | |
40 | //----------------------------------------------------------------------------- | |
41 | ||
c626a8b7 | 42 | class wxMenuBar : public wxWindow |
c801d85f | 43 | { |
c626a8b7 | 44 | DECLARE_DYNAMIC_CLASS(wxMenuBar) |
83885a39 VZ |
45 | |
46 | public: | |
c626a8b7 VZ |
47 | // ctors |
48 | wxMenuBar(); | |
49 | wxMenuBar(long style); | |
50 | wxMenuBar(int n, wxMenu *menus[], const wxString titles[]); | |
1e133b7d | 51 | ~wxMenuBar(); |
c626a8b7 VZ |
52 | |
53 | // menubar construction | |
54 | void Append( wxMenu *menu, const wxString &title ); | |
55 | ||
56 | // item search | |
57 | // by menu and item names, returns wxNOT_FOUND if not found | |
58 | virtual int FindMenuItem(const wxString& menuString, | |
59 | const wxString& itemString) const; | |
60 | // returns NULL if not found | |
61 | wxMenuItem* FindItem( int id ) const; | |
62 | // returns NULL if not found, fills menuForItem if !NULL | |
63 | wxMenuItem *FindItemForId(int itemId, wxMenu **menuForItem = NULL) const; | |
64 | ||
65 | // state control | |
66 | void Check( int id, bool check ); | |
67 | bool IsChecked( int id ) const; | |
68 | void Enable( int id, bool enable ); | |
69 | bool IsEnabled( int id ) const; | |
70 | ||
c626a8b7 | 71 | void SetLabel( int id, const wxString &label ); |
0de9b5b2 RR |
72 | wxString GetLabel( int id ) const; |
73 | wxString GetLabel() const { return wxWindow::GetLabel(); } | |
c626a8b7 VZ |
74 | |
75 | void EnableTop( int pos, bool flag ); | |
76 | void SetLabelTop( int pos, const wxString& label ); | |
77 | wxString GetLabelTop( int pos ) const; | |
78 | ||
79 | virtual void SetHelpString( int id, const wxString& helpString ); | |
80 | virtual wxString GetHelpString( int id ) const; | |
81 | ||
82 | int GetMenuCount() const { return m_menus.Number(); } | |
83 | wxMenu *GetMenu( int n ) const { return (wxMenu *)m_menus.Nth(n)->Data(); } | |
84 | ||
85 | #ifdef WXWIN_COMPATIBILITY | |
86 | // compatibility: these functions are deprecated | |
87 | bool Enabled(int id) const { return IsEnabled(id); } | |
88 | bool Checked(int id) const { return IsChecked(id); } | |
89 | ||
90 | wxMenuItem* FindMenuItemById( int id ) const { return FindItem(id); } | |
91 | #endif // WXWIN_COMPATIBILITY | |
92 | ||
1e133b7d | 93 | // implementation only |
c626a8b7 | 94 | wxList& GetMenus() { return m_menus; } |
5bd9e519 RR |
95 | |
96 | void SetInvokingWindow( wxWindow *win ); | |
97 | void UnsetInvokingWindow( wxWindow *win ); | |
c626a8b7 | 98 | |
1e133b7d RR |
99 | GtkAccelGroup *m_accel; |
100 | GtkItemFactory *m_factory; | |
1e133b7d RR |
101 | wxList m_menus; |
102 | GtkWidget *m_menubar; | |
c801d85f KB |
103 | }; |
104 | ||
105 | //----------------------------------------------------------------------------- | |
106 | // wxMenu | |
107 | //----------------------------------------------------------------------------- | |
108 | ||
c626a8b7 | 109 | class wxMenu : public wxEvtHandler |
c801d85f | 110 | { |
c626a8b7 | 111 | DECLARE_DYNAMIC_CLASS(wxMenu) |
83885a39 VZ |
112 | |
113 | public: | |
c626a8b7 VZ |
114 | wxMenu( const wxString& title = wxEmptyString, |
115 | const wxFunction func = (wxFunction) NULL ); | |
034be888 | 116 | ~wxMenu(); |
c626a8b7 VZ |
117 | |
118 | // operations | |
119 | // title | |
120 | void SetTitle(const wxString& label); | |
121 | const wxString GetTitle() const; | |
122 | // menu creation | |
123 | void AppendSeparator(); | |
124 | void Append(int id, const wxString &item, | |
125 | const wxString &helpStr = "", bool checkable = FALSE); | |
126 | void Append(int id, const wxString &item, | |
127 | wxMenu *subMenu, const wxString &helpStr = "" ); | |
128 | void Append(wxMenuItem *pItem); | |
129 | void Break() { } | |
83885a39 VZ |
130 | |
131 | // find item by name/id | |
c626a8b7 VZ |
132 | int FindItem( const wxString itemString ) const; |
133 | wxMenuItem *FindItem( int id ) const; | |
83885a39 VZ |
134 | |
135 | // get/set item's state | |
c626a8b7 VZ |
136 | void Enable( int id, bool enable ); |
137 | bool IsEnabled( int id ) const; | |
138 | void Check( int id, bool check ); | |
139 | bool IsChecked( int id ) const; | |
140 | ||
141 | void SetLabel( int id, const wxString &label ); | |
142 | wxString GetLabel( int id ) const; | |
143 | ||
144 | // helpstring | |
145 | virtual void SetHelpString(int id, const wxString& helpString); | |
146 | virtual wxString GetHelpString(int id) const ; | |
147 | ||
148 | // accessors | |
149 | wxList& GetItems() { return m_items; } | |
150 | ||
151 | void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; } | |
152 | wxEvtHandler *GetEventHandler() { return m_eventHandler; } | |
153 | ||
154 | void SetClientData( void* clientData ) { m_clientData = clientData; } | |
155 | void* GetClientData() const { return m_clientData; } | |
156 | ||
157 | // Updates the UI for a menu and all submenus recursively. | |
158 | // source is the object that has the update event handlers | |
159 | // defined for it. If NULL, the menu or associated window | |
160 | // will be used. | |
161 | void UpdateUI(wxEvtHandler* source = (wxEvtHandler*) NULL); | |
162 | ||
163 | wxMenuItem *FindItemForId( int id ) const { return FindItem( id ); } | |
164 | ||
165 | #ifdef WXWIN_COMPATIBILITY | |
166 | wxFunction GetCallback() const { return m_callback; } | |
167 | void Callback(const wxFunction func) { m_callback = func; } | |
168 | ||
169 | // compatibility: these functions are deprecated | |
170 | bool Enabled(int id) const { return IsEnabled(id); } | |
171 | bool Checked(int id) const { return IsChecked(id); } | |
172 | #endif // WXWIN_COMPATIBILITY | |
173 | ||
174 | // implementation | |
175 | int FindMenuIdByMenuItem( GtkWidget *menuItem ) const; | |
176 | void SetInvokingWindow( wxWindow *win ); | |
177 | wxWindow *GetInvokingWindow(); | |
178 | ||
1e133b7d | 179 | // implementation GTK only |
034be888 RR |
180 | GtkWidget *m_menu; // GtkMenu |
181 | GtkWidget *m_owner; | |
034be888 RR |
182 | GtkAccelGroup *m_accel; |
183 | GtkItemFactory *m_factory; | |
c626a8b7 VZ |
184 | |
185 | private: | |
1e133b7d | 186 | |
c626a8b7 VZ |
187 | wxString m_title; |
188 | wxList m_items; | |
189 | wxWindow *m_invokingWindow; | |
190 | wxFunction m_callback; | |
191 | wxEvtHandler *m_eventHandler; | |
192 | void *m_clientData; | |
c801d85f KB |
193 | }; |
194 | ||
195 | #endif // __GTKMENUH__ |