]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gtk/menu.h
More DnD.
[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 94 wxList& GetMenus() { return m_menus; }
b908d224 95
5bd9e519
RR
96 void SetInvokingWindow( wxWindow *win );
97 void UnsetInvokingWindow( wxWindow *win );
c626a8b7 98
1e133b7d
RR
99 GtkAccelGroup *m_accel;
100 GtkItemFactory *m_factory;
1e133b7d
RR
101 wxList m_menus;
102 GtkWidget *m_menubar;
ae53c98c 103 long m_style;
9c884972 104 wxWindow *m_invokingWindow;
c801d85f
KB
105};
106
107//-----------------------------------------------------------------------------
108// wxMenu
109//-----------------------------------------------------------------------------
110
c626a8b7 111class wxMenu : public wxEvtHandler
c801d85f 112{
c626a8b7 113 DECLARE_DYNAMIC_CLASS(wxMenu)
83885a39
VZ
114
115public:
b908d224
VZ
116 wxMenu( const wxString& title, const wxFunction func)
117 {
118 Init(title, 0, func);
119 }
b62c3631
RR
120 wxMenu( long style )
121 {
122 Init( wxEmptyString, style );
123 }
b908d224
VZ
124 wxMenu( const wxString& title = wxEmptyString, long style = 0 )
125 {
1ecffbff 126 Init(title, style);
b908d224
VZ
127 }
128
034be888 129 ~wxMenu();
c626a8b7 130
d1b15f03 131 // title
c626a8b7
VZ
132 void SetTitle(const wxString& label);
133 const wxString GetTitle() const;
d1b15f03
RR
134
135 // menu creation
c626a8b7
VZ
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() { }
83885a39 143
d1b15f03
RR
144 // delete item. don't delete the wxMenu if it's a submenu
145 void Delete( int id );
146
83885a39 147 // find item by name/id
c626a8b7
VZ
148 int FindItem( const wxString itemString ) const;
149 wxMenuItem *FindItem( int id ) const;
83885a39
VZ
150
151 // get/set item's state
c626a8b7
VZ
152 void Enable( int id, bool enable );
153 bool IsEnabled( int id ) const;
154 void Check( int id, bool check );
155 bool IsChecked( int id ) const;
156
157 void SetLabel( int id, const wxString &label );
158 wxString GetLabel( int id ) const;
159
160 // helpstring
161 virtual void SetHelpString(int id, const wxString& helpString);
162 virtual wxString GetHelpString(int id) const ;
163
164 // accessors
165 wxList& GetItems() { return m_items; }
166
167 void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
168 wxEvtHandler *GetEventHandler() { return m_eventHandler; }
169
170 void SetClientData( void* clientData ) { m_clientData = clientData; }
171 void* GetClientData() const { return m_clientData; }
172
173 // Updates the UI for a menu and all submenus recursively.
174 // source is the object that has the update event handlers
175 // defined for it. If NULL, the menu or associated window
176 // will be used.
177 void UpdateUI(wxEvtHandler* source = (wxEvtHandler*) NULL);
178
179 wxMenuItem *FindItemForId( int id ) const { return FindItem( id ); }
180
c626a8b7
VZ
181 wxFunction GetCallback() const { return m_callback; }
182 void Callback(const wxFunction func) { m_callback = func; }
33961d59
RR
183 wxFunction m_callback;
184
185#ifdef WXWIN_COMPATIBILITY
c626a8b7
VZ
186
187 // compatibility: these functions are deprecated
188 bool Enabled(int id) const { return IsEnabled(id); }
189 bool Checked(int id) const { return IsChecked(id); }
b908d224 190
c626a8b7
VZ
191#endif // WXWIN_COMPATIBILITY
192
193 // implementation
194 int FindMenuIdByMenuItem( GtkWidget *menuItem ) const;
195 void SetInvokingWindow( wxWindow *win );
196 wxWindow *GetInvokingWindow();
197
1e133b7d 198 // implementation GTK only
034be888
RR
199 GtkWidget *m_menu; // GtkMenu
200 GtkWidget *m_owner;
034be888
RR
201 GtkAccelGroup *m_accel;
202 GtkItemFactory *m_factory;
c626a8b7 203
ae53c98c 204 // used by wxMenuBar
b908d224
VZ
205 long GetStyle(void) const { return m_style; }
206
207private:
ae53c98c
KB
208 // common code for both constructors:
209 void Init( const wxString& title,
33961d59
RR
210 long style,
211 const wxFunction func = (wxFunction) NULL );
1e133b7d 212
c626a8b7
VZ
213 wxString m_title;
214 wxList m_items;
215 wxWindow *m_invokingWindow;
c626a8b7
VZ
216 wxEvtHandler *m_eventHandler;
217 void *m_clientData;
ae53c98c 218 long m_style;
c801d85f
KB
219};
220
221#endif // __GTKMENUH__