]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gtk/menu.h
minor fixes
[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
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
1e133b7d 92 // implementation only
c626a8b7
VZ
93 wxList& GetMenus() { return m_menus; }
94
1e133b7d
RR
95 GtkAccelGroup *m_accel;
96 GtkItemFactory *m_factory;
97
98private:
99 wxList m_menus;
100 GtkWidget *m_menubar;
c801d85f
KB
101};
102
103//-----------------------------------------------------------------------------
104// wxMenu
105//-----------------------------------------------------------------------------
106
c626a8b7 107class wxMenu : public wxEvtHandler
c801d85f 108{
c626a8b7 109 DECLARE_DYNAMIC_CLASS(wxMenu)
83885a39
VZ
110
111public:
c626a8b7
VZ
112 wxMenu( const wxString& title = wxEmptyString,
113 const wxFunction func = (wxFunction) NULL );
034be888 114 ~wxMenu();
c626a8b7
VZ
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() { }
83885a39
VZ
128
129 // find item by name/id
c626a8b7
VZ
130 int FindItem( const wxString itemString ) const;
131 wxMenuItem *FindItem( int id ) const;
83885a39
VZ
132
133 // get/set item's state
c626a8b7
VZ
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
1e133b7d 177 // implementation GTK only
034be888
RR
178 GtkWidget *m_menu; // GtkMenu
179 GtkWidget *m_owner;
034be888
RR
180 GtkAccelGroup *m_accel;
181 GtkItemFactory *m_factory;
c626a8b7
VZ
182
183private:
1e133b7d 184
c626a8b7
VZ
185 wxString m_title;
186 wxList m_items;
187 wxWindow *m_invokingWindow;
188 wxFunction m_callback;
189 wxEvtHandler *m_eventHandler;
190 void *m_clientData;
c801d85f
KB
191};
192
193#endif // __GTKMENUH__