]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/menu.h
GetHandle() added (back)
[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 // 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 wxString GetLabel( int id ) const;
72 void SetLabel( int id, const wxString &label );
73
74 void EnableTop( int pos, bool flag );
75 void SetLabelTop( int pos, const wxString& label );
76 wxString GetLabelTop( int pos ) const;
77
78 virtual void SetHelpString( int id, const wxString& helpString );
79 virtual wxString GetHelpString( int id ) const;
80
81 int GetMenuCount() const { return m_menus.Number(); }
82 wxMenu *GetMenu( int n ) const { return (wxMenu *)m_menus.Nth(n)->Data(); }
83
84 #ifdef WXWIN_COMPATIBILITY
85 // compatibility: these functions are deprecated
86 bool Enabled(int id) const { return IsEnabled(id); }
87 bool Checked(int id) const { return IsChecked(id); }
88
89 wxMenuItem* FindMenuItemById( int id ) const { return FindItem(id); }
90 #endif // WXWIN_COMPATIBILITY
91
92 // implementation only
93 wxList& GetMenus() { return m_menus; }
94
95 GtkAccelGroup *m_accel;
96 GtkItemFactory *m_factory;
97
98 private:
99 wxList m_menus;
100 GtkWidget *m_menubar;
101 };
102
103 //-----------------------------------------------------------------------------
104 // wxMenu
105 //-----------------------------------------------------------------------------
106
107 class wxMenu : public wxEvtHandler
108 {
109 DECLARE_DYNAMIC_CLASS(wxMenu)
110
111 public:
112 wxMenu( const wxString& title = wxEmptyString,
113 const wxFunction func = (wxFunction) NULL );
114 ~wxMenu();
115
116 // operations
117 // title
118 void SetTitle(const wxString& label);
119 const wxString GetTitle() const;
120 // menu creation
121 void AppendSeparator();
122 void Append(int id, const wxString &item,
123 const wxString &helpStr = "", bool checkable = FALSE);
124 void Append(int id, const wxString &item,
125 wxMenu *subMenu, const wxString &helpStr = "" );
126 void Append(wxMenuItem *pItem);
127 void Break() { }
128
129 // find item by name/id
130 int FindItem( const wxString itemString ) const;
131 wxMenuItem *FindItem( int id ) const;
132
133 // get/set item's state
134 void Enable( int id, bool enable );
135 bool IsEnabled( int id ) const;
136 void Check( int id, bool check );
137 bool IsChecked( int id ) const;
138
139 void SetLabel( int id, const wxString &label );
140 wxString GetLabel( int id ) const;
141
142 // helpstring
143 virtual void SetHelpString(int id, const wxString& helpString);
144 virtual wxString GetHelpString(int id) const ;
145
146 // accessors
147 wxList& GetItems() { return m_items; }
148
149 void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
150 wxEvtHandler *GetEventHandler() { return m_eventHandler; }
151
152 void SetClientData( void* clientData ) { m_clientData = clientData; }
153 void* GetClientData() const { return m_clientData; }
154
155 // Updates the UI for a menu and all submenus recursively.
156 // source is the object that has the update event handlers
157 // defined for it. If NULL, the menu or associated window
158 // will be used.
159 void UpdateUI(wxEvtHandler* source = (wxEvtHandler*) NULL);
160
161 wxMenuItem *FindItemForId( int id ) const { return FindItem( id ); }
162
163 #ifdef WXWIN_COMPATIBILITY
164 wxFunction GetCallback() const { return m_callback; }
165 void Callback(const wxFunction func) { m_callback = func; }
166
167 // compatibility: these functions are deprecated
168 bool Enabled(int id) const { return IsEnabled(id); }
169 bool Checked(int id) const { return IsChecked(id); }
170 #endif // WXWIN_COMPATIBILITY
171
172 // implementation
173 int FindMenuIdByMenuItem( GtkWidget *menuItem ) const;
174 void SetInvokingWindow( wxWindow *win );
175 wxWindow *GetInvokingWindow();
176
177 // implementation GTK only
178 GtkWidget *m_menu; // GtkMenu
179 GtkWidget *m_owner;
180 GtkAccelGroup *m_accel;
181 GtkItemFactory *m_factory;
182
183 private:
184
185 wxString m_title;
186 wxList m_items;
187 wxWindow *m_invokingWindow;
188 wxFunction m_callback;
189 wxEvtHandler *m_eventHandler;
190 void *m_clientData;
191 };
192
193 #endif // __GTKMENUH__