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