]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/menu.h
wxTREE_INSERT_XXX constants were incorrectly defined (and so inserting the
[wxWidgets.git] / include / wx / gtk / menu.h
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
8 // Licence: wxWindows licence
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
28 class wxMenuBar;
29 class wxMenuItem;
30 class wxMenu;
31
32 //-----------------------------------------------------------------------------
33 // const
34 //-----------------------------------------------------------------------------
35
36 #define ID_SEPARATOR (-1)
37
38 //-----------------------------------------------------------------------------
39 // wxMenuBar
40 //-----------------------------------------------------------------------------
41
42 class wxMenuBar: public wxWindow
43 {
44 DECLARE_DYNAMIC_CLASS(wxMenuBar)
45
46 public:
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;
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); };
59
60 int GetMenuCount() const { return m_menus.Number(); }
61 wxMenu *GetMenu(int n) const { return (wxMenu *)m_menus.Nth(n)->Data(); }
62
63 wxList m_menus;
64 GtkWidget *m_menubar;
65 };
66
67 //-----------------------------------------------------------------------------
68 // wxMenu
69 //-----------------------------------------------------------------------------
70
71 class wxMenuItem: public wxObject
72 {
73 DECLARE_DYNAMIC_CLASS(wxMenuItem)
74
75 public:
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
96 void Enable(bool enable = TRUE) { m_isEnabled = enable; }
97 bool IsEnabled() const { return m_isEnabled; }
98 void Check(bool check = TRUE);
99 bool IsChecked() const;
100
101 // help string (displayed in the status bar by default)
102 void SetHelpString(const wxString& str) { m_helpStr = str; }
103
104 // implementation
105 void SetMenuItem(GtkWidget *menuItem) { m_menuItem = menuItem; }
106 GtkWidget *GetMenuItem() const { return m_menuItem; }
107
108 private:
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
118 };
119
120 class wxMenu: public wxEvtHandler
121 {
122 DECLARE_DYNAMIC_CLASS(wxMenu)
123
124 public:
125 // construction
126 wxMenu( const wxString &title = "" );
127
128 // operations
129 // menu creation
130 void AppendSeparator();
131 void Append(int id, const wxString &item,
132 const wxString &helpStr = "", bool checkable = FALSE);
133 void Append(int id, const wxString &item,
134 wxMenu *subMenu, const wxString &helpStr = "" );
135 void Break() {};
136
137 // find item by name/id
138 int FindItem( const wxString itemString ) const;
139 wxMenuItem *FindItem(int id) const;
140
141 // get/set item's state
142 void Enable( int id, bool enable );
143 bool IsEnabled( int id ) const;
144 void Check( int id, bool check );
145 bool IsChecked( int id ) const;
146
147 void SetLabel( int id, const wxString &label );
148
149 // accessors
150 wxList& GetItems() { return m_items; }
151
152 public:
153 int FindMenuIdByMenuItem( GtkWidget *menuItem ) const;
154 void SetInvokingWindow( wxWindow *win );
155 wxWindow *GetInvokingWindow();
156
157 wxString m_title;
158 wxList m_items;
159 wxWindow *m_invokingWindow;
160
161 GtkWidget *m_menu; // GtkMenu
162 };
163
164 #endif // __GTKMENUH__