]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gtk1/menu.h
Much more aggressive for intercepting events and
[wxWidgets.git] / include / wx / gtk1 / menu.h
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: menu.h
3// Purpose:
4// Author: Robert Roebling
5// Created: 01/02/97
6// Id:
7// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
83885a39 8// Licence: wxWindows licence
c801d85f
KB
9/////////////////////////////////////////////////////////////////////////////
10
11
12#ifndef __GTKMENUH__
13#define __GTKMENUH__
14
15#ifdef __GNUG__
16#pragma interface
17#endif
18
19#include "wx/defs.h"
20#include "wx/object.h"
21#include "wx/list.h"
22#include "wx/window.h"
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
42class wxMenuBar: public wxWindow
43{
83885a39
VZ
44DECLARE_DYNAMIC_CLASS(wxMenuBar)
45
46public:
47 wxMenuBar();
48 void Append( wxMenu *menu, const wxString &title );
49
50 int FindMenuItem( const wxString &menuString, const wxString &itemString ) const;
51 wxMenuItem* FindMenuItemById( int id ) const;
54ff4a70
RR
52
53 void Check( int id, bool check );
54 bool Checked( int id ) const;
55 void Enable( int id, bool enable );
56 bool Enabled( int id ) const;
57 inline bool IsEnabled(int Id) const { return Enabled(Id); };
58 inline bool IsChecked(int Id) const { return Checked(Id); };
83885a39
VZ
59
60 int GetMenuCount() const { return m_menus.Number(); }
61 wxMenu *GetMenu(int n) const { return (wxMenu *)m_menus.Nth(n)->Data(); }
62
83885a39
VZ
63 wxList m_menus;
64 GtkWidget *m_menubar;
c801d85f
KB
65};
66
67//-----------------------------------------------------------------------------
68// wxMenu
69//-----------------------------------------------------------------------------
70
71class wxMenuItem: public wxObject
72{
83885a39
VZ
73DECLARE_DYNAMIC_CLASS(wxMenuItem)
74
75public:
76 wxMenuItem();
77
78 // accessors
79 // id
80 void SetId(int id) { m_id = id; }
81 int GetId() const { return m_id; }
82 bool IsSeparator() const { return m_id == ID_SEPARATOR; }
83
84 // the item's text
85 void SetText(const wxString& str);
86 const wxString& GetText() const { return m_text; }
87
88 // what kind of menu item we are
89 void SetCheckable(bool checkable) { m_isCheckMenu = checkable; }
90 bool IsCheckable() const { return m_isCheckMenu; }
91 void SetSubMenu(wxMenu *menu) { m_subMenu = menu; }
92 wxMenu *GetSubMenu() const { return m_subMenu; }
93 bool IsSubMenu() const { return m_subMenu != NULL; }
94
95 // state
a9c96bcc 96 void Enable( bool enable = TRUE );
83885a39 97 bool IsEnabled() const { return m_isEnabled; }
c33c4050 98 void Check( bool check = TRUE );
83885a39
VZ
99 bool IsChecked() const;
100
101 // help string (displayed in the status bar by default)
c33c4050
RR
102 void SetHelp(const wxString& str) { m_helpStr = str; }
103 const wxString& GetHelp() const { return m_helpStr; }
83885a39
VZ
104
105 // implementation
106 void SetMenuItem(GtkWidget *menuItem) { m_menuItem = menuItem; }
107 GtkWidget *GetMenuItem() const { return m_menuItem; }
108
109private:
110 int m_id;
111 wxString m_text;
112 bool m_isCheckMenu;
113 bool m_isChecked;
114 bool m_isEnabled;
115 wxMenu *m_subMenu;
116 wxString m_helpStr;
117
118 GtkWidget *m_menuItem; // GtkMenuItem
c801d85f
KB
119};
120
121class wxMenu: public wxEvtHandler
122{
83885a39
VZ
123DECLARE_DYNAMIC_CLASS(wxMenu)
124
125public:
126 // construction
c67daf87 127 wxMenu( const wxString& title = wxEmptyString, const wxFunction func = (wxFunction) NULL );
83885a39
VZ
128
129 // operations
c2dd8380
GL
130 // title
131 void SetTitle(const wxString& label);
132 const wxString GetTitle() const;
83885a39
VZ
133 // menu creation
134 void AppendSeparator();
135 void Append(int id, const wxString &item,
136 const wxString &helpStr = "", bool checkable = FALSE);
137 void Append(int id, const wxString &item,
138 wxMenu *subMenu, const wxString &helpStr = "" );
139 void Break() {};
140
141 // find item by name/id
142 int FindItem( const wxString itemString ) const;
c33c4050
RR
143 wxMenuItem *FindItem( int id ) const;
144 wxMenuItem *FindItemForId( int id ) const { return FindItem( id ); }
83885a39
VZ
145
146 // get/set item's state
147 void Enable( int id, bool enable );
148 bool IsEnabled( int id ) const;
149 void Check( int id, bool check );
150 bool IsChecked( int id ) const;
151
152 void SetLabel( int id, const wxString &label );
c33c4050 153 wxString GetLabel(int id) const;
83885a39 154
c33c4050
RR
155 // helpstring
156 virtual void SetHelpString(int id, const wxString& helpString);
157 virtual wxString GetHelpString(int id) const ;
158
83885a39
VZ
159 // accessors
160 wxList& GetItems() { return m_items; }
161
6de97a3b
RR
162 inline void Callback(const wxFunction func) { m_callback = func; }
163
164 inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
165 inline wxEvtHandler *GetEventHandler() { return m_eventHandler; }
166
83885a39
VZ
167public:
168 int FindMenuIdByMenuItem( GtkWidget *menuItem ) const;
169 void SetInvokingWindow( wxWindow *win );
170 wxWindow *GetInvokingWindow();
171
6de97a3b
RR
172 wxString m_title;
173 wxList m_items;
174 wxWindow *m_invokingWindow;
175 wxFunction m_callback;
176 wxEvtHandler *m_eventHandler;
83885a39 177
6de97a3b 178 GtkWidget *m_menu; // GtkMenu
c801d85f
KB
179};
180
181#endif // __GTKMENUH__