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