]>
Commit | Line | Data |
---|---|---|
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 | ||
23 | //----------------------------------------------------------------------------- | |
24 | // classes | |
25 | //----------------------------------------------------------------------------- | |
26 | ||
27 | class wxMenuBar; | |
28 | class wxMenuItem; | |
29 | class wxMenu; | |
30 | ||
31 | //----------------------------------------------------------------------------- | |
32 | // const | |
33 | //----------------------------------------------------------------------------- | |
34 | ||
35 | #define ID_SEPARATOR (-1) | |
36 | ||
37 | //----------------------------------------------------------------------------- | |
38 | // wxMenuBar | |
39 | //----------------------------------------------------------------------------- | |
40 | ||
41 | class wxMenuBar: public wxWindow | |
42 | { | |
43 | DECLARE_DYNAMIC_CLASS(wxMenuBar) | |
44 | ||
45 | public: | |
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; | |
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); }; | |
58 | ||
59 | int GetMenuCount() const { return m_menus.Number(); } | |
60 | wxMenu *GetMenu(int n) const { return (wxMenu *)m_menus.Nth(n)->Data(); } | |
61 | ||
62 | wxList m_menus; | |
63 | GtkWidget *m_menubar; | |
64 | }; | |
65 | ||
66 | //----------------------------------------------------------------------------- | |
67 | // wxMenu | |
68 | //----------------------------------------------------------------------------- | |
69 | ||
70 | class wxMenuItem: public wxObject | |
71 | { | |
72 | DECLARE_DYNAMIC_CLASS(wxMenuItem) | |
73 | ||
74 | public: | |
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 | |
95 | void Enable( bool enable = TRUE ); | |
96 | bool IsEnabled() const { return m_isEnabled; } | |
97 | void Check( bool check = TRUE ); | |
98 | bool IsChecked() const; | |
99 | ||
100 | // help string (displayed in the status bar by default) | |
101 | void SetHelp(const wxString& str) { m_helpStr = str; } | |
102 | const wxString& GetHelp() const { return m_helpStr; } | |
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 = wxEmptyString, const wxFunction func = (wxFunction) NULL ); | |
127 | ||
128 | // operations | |
129 | // title | |
130 | void SetTitle(const wxString& label); | |
131 | const wxString GetTitle() const; | |
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; | |
142 | wxMenuItem *FindItem( int id ) const; | |
143 | wxMenuItem *FindItemForId( int id ) const { return FindItem( id ); } | |
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 ); | |
152 | wxString GetLabel(int id) const; | |
153 | ||
154 | // helpstring | |
155 | virtual void SetHelpString(int id, const wxString& helpString); | |
156 | virtual wxString GetHelpString(int id) const ; | |
157 | ||
158 | // accessors | |
159 | wxList& GetItems() { return m_items; } | |
160 | ||
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 | ||
166 | public: | |
167 | int FindMenuIdByMenuItem( GtkWidget *menuItem ) const; | |
168 | void SetInvokingWindow( wxWindow *win ); | |
169 | wxWindow *GetInvokingWindow(); | |
170 | ||
171 | wxString m_title; | |
172 | wxList m_items; | |
173 | wxWindow *m_invokingWindow; | |
174 | wxFunction m_callback; | |
175 | wxEvtHandler *m_eventHandler; | |
176 | ||
177 | GtkWidget *m_menu; // GtkMenu | |
178 | }; | |
179 | ||
180 | #endif // __GTKMENUH__ |