]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk1/menu.h
Implemented tearoff menus, please see my posting to wxwin-developers.
[wxWidgets.git] / include / wx / gtk1 / 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 // const
34 //-----------------------------------------------------------------------------
35
36 #define ID_SEPARATOR (-1)
37
38 //-----------------------------------------------------------------------------
39 // wxMenuBar
40 //-----------------------------------------------------------------------------
41
42 class wxMenuBar : public wxWindow
43 {
44 DECLARE_DYNAMIC_CLASS(wxMenuBar)
45
46 public:
47 // ctors
48 wxMenuBar();
49 wxMenuBar(long style);
50 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
51 ~wxMenuBar();
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
71 void SetLabel( int id, const wxString &label );
72 wxString GetLabel( int id ) const;
73 wxString GetLabel() const { return wxWindow::GetLabel(); }
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
93 // implementation only
94 wxList& GetMenus() { return m_menus; }
95
96 void SetInvokingWindow( wxWindow *win );
97 void UnsetInvokingWindow( wxWindow *win );
98
99 GtkAccelGroup *m_accel;
100 GtkItemFactory *m_factory;
101 wxList m_menus;
102 GtkWidget *m_menubar;
103 long m_style;
104 };
105
106 //-----------------------------------------------------------------------------
107 // wxMenu
108 //-----------------------------------------------------------------------------
109
110 class wxMenu : public wxEvtHandler
111 {
112 DECLARE_DYNAMIC_CLASS(wxMenu)
113
114 public:
115 wxMenu( const wxString& title = wxEmptyString,
116 const wxFunction func = (wxFunction) NULL,
117 long style = 0);
118 wxMenu( long style );
119 ~wxMenu();
120
121 // operations
122 // title
123 void SetTitle(const wxString& label);
124 const wxString GetTitle() const;
125 // menu creation
126 void AppendSeparator();
127 void Append(int id, const wxString &item,
128 const wxString &helpStr = "", bool checkable = FALSE);
129 void Append(int id, const wxString &item,
130 wxMenu *subMenu, const wxString &helpStr = "" );
131 void Append(wxMenuItem *pItem);
132 void Break() { }
133
134 // find item by name/id
135 int FindItem( const wxString itemString ) const;
136 wxMenuItem *FindItem( int id ) const;
137
138 // get/set item's state
139 void Enable( int id, bool enable );
140 bool IsEnabled( int id ) const;
141 void Check( int id, bool check );
142 bool IsChecked( int id ) const;
143
144 void SetLabel( int id, const wxString &label );
145 wxString GetLabel( int id ) const;
146
147 // helpstring
148 virtual void SetHelpString(int id, const wxString& helpString);
149 virtual wxString GetHelpString(int id) const ;
150
151 // accessors
152 wxList& GetItems() { return m_items; }
153
154 void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
155 wxEvtHandler *GetEventHandler() { return m_eventHandler; }
156
157 void SetClientData( void* clientData ) { m_clientData = clientData; }
158 void* GetClientData() const { return m_clientData; }
159
160 // Updates the UI for a menu and all submenus recursively.
161 // source is the object that has the update event handlers
162 // defined for it. If NULL, the menu or associated window
163 // will be used.
164 void UpdateUI(wxEvtHandler* source = (wxEvtHandler*) NULL);
165
166 wxMenuItem *FindItemForId( int id ) const { return FindItem( id ); }
167
168 #ifdef WXWIN_COMPATIBILITY
169 wxFunction GetCallback() const { return m_callback; }
170 void Callback(const wxFunction func) { m_callback = func; }
171
172 // compatibility: these functions are deprecated
173 bool Enabled(int id) const { return IsEnabled(id); }
174 bool Checked(int id) const { return IsChecked(id); }
175 #endif // WXWIN_COMPATIBILITY
176
177 // implementation
178 int FindMenuIdByMenuItem( GtkWidget *menuItem ) const;
179 void SetInvokingWindow( wxWindow *win );
180 wxWindow *GetInvokingWindow();
181
182 // implementation GTK only
183 GtkWidget *m_menu; // GtkMenu
184 GtkWidget *m_owner;
185 GtkAccelGroup *m_accel;
186 GtkItemFactory *m_factory;
187
188 // used by wxMenuBar
189 inline long GetStyle(void) const { return m_style; }
190 private:
191 // common code for both constructors:
192 void Init( const wxString& title,
193 const wxFunction func,
194 long style);
195
196 wxString m_title;
197 wxList m_items;
198 wxWindow *m_invokingWindow;
199 wxFunction m_callback;
200 wxEvtHandler *m_eventHandler;
201 void *m_clientData;
202 long m_style;
203 };
204
205 #endif // __GTKMENUH__