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