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