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