]>
Commit | Line | Data |
---|---|---|
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 | ||
28 | class wxMenuBar; | |
29 | class wxMenuItem; | |
30 | class wxMenu; | |
31 | ||
e2414cbe RR |
32 | //----------------------------------------------------------------------------- |
33 | // const | |
34 | //----------------------------------------------------------------------------- | |
35 | ||
36 | #define ID_SEPARATOR (-1) | |
37 | ||
c801d85f KB |
38 | //----------------------------------------------------------------------------- |
39 | // wxMenuBar | |
40 | //----------------------------------------------------------------------------- | |
41 | ||
42 | class wxMenuBar: public wxWindow | |
43 | { | |
83885a39 VZ |
44 | DECLARE_DYNAMIC_CLASS(wxMenuBar) |
45 | ||
46 | public: | |
3502e687 | 47 | wxMenuBar( long style ); |
83885a39 VZ |
48 | wxMenuBar(); |
49 | void Append( wxMenu *menu, const wxString &title ); | |
50 | ||
51 | int FindMenuItem( const wxString &menuString, const wxString &itemString ) const; | |
52 | wxMenuItem* FindMenuItemById( int id ) const; | |
342b6a2f | 53 | inline wxMenuItem* FindItemForId( int id ) const { return FindMenuItemById( id ); } |
54ff4a70 RR |
54 | |
55 | void Check( int id, bool check ); | |
56 | bool Checked( int id ) const; | |
57 | void Enable( int id, bool enable ); | |
58 | bool Enabled( int id ) const; | |
342b6a2f RR |
59 | inline bool IsEnabled( int id ) const { return Enabled(id); } |
60 | inline bool IsChecked( int id ) const { return Checked(id); } | |
bbe0af5b RR |
61 | |
62 | wxString GetLabel( int id ) const; | |
63 | void SetLabel( int id, const wxString &label ); | |
64 | ||
65 | void EnableTop( int pos, bool flag ); | |
66 | void SetLabelTop( int pos, const wxString& label ); | |
67 | wxString GetLabelTop( int pos ) const; | |
83885a39 | 68 | |
342b6a2f RR |
69 | virtual void SetHelpString( int id, const wxString& helpString ); |
70 | virtual wxString GetHelpString( int id ) const; | |
71 | ||
72 | inline int GetMenuCount() const { return m_menus.Number(); } | |
73 | inline wxMenu *GetMenu( int n ) const { return (wxMenu *)m_menus.Nth(n)->Data(); } | |
83885a39 | 74 | |
83885a39 VZ |
75 | wxList m_menus; |
76 | GtkWidget *m_menubar; | |
c801d85f KB |
77 | }; |
78 | ||
79 | //----------------------------------------------------------------------------- | |
80 | // wxMenu | |
81 | //----------------------------------------------------------------------------- | |
82 | ||
c801d85f KB |
83 | class wxMenu: public wxEvtHandler |
84 | { | |
83885a39 VZ |
85 | DECLARE_DYNAMIC_CLASS(wxMenu) |
86 | ||
87 | public: | |
88 | // construction | |
c67daf87 | 89 | wxMenu( const wxString& title = wxEmptyString, const wxFunction func = (wxFunction) NULL ); |
83885a39 VZ |
90 | |
91 | // operations | |
c2dd8380 GL |
92 | // title |
93 | void SetTitle(const wxString& label); | |
94 | const wxString GetTitle() const; | |
83885a39 VZ |
95 | // menu creation |
96 | void AppendSeparator(); | |
97 | void Append(int id, const wxString &item, | |
98 | const wxString &helpStr = "", bool checkable = FALSE); | |
99 | void Append(int id, const wxString &item, | |
100 | wxMenu *subMenu, const wxString &helpStr = "" ); | |
101 | void Break() {}; | |
102 | ||
103 | // find item by name/id | |
104 | int FindItem( const wxString itemString ) const; | |
c33c4050 RR |
105 | wxMenuItem *FindItem( int id ) const; |
106 | wxMenuItem *FindItemForId( int id ) const { return FindItem( id ); } | |
83885a39 VZ |
107 | |
108 | // get/set item's state | |
109 | void Enable( int id, bool enable ); | |
110 | bool IsEnabled( int id ) const; | |
111 | void Check( int id, bool check ); | |
112 | bool IsChecked( int id ) const; | |
113 | ||
114 | void SetLabel( int id, const wxString &label ); | |
bbe0af5b | 115 | wxString GetLabel( int id ) const; |
83885a39 | 116 | |
c33c4050 RR |
117 | // helpstring |
118 | virtual void SetHelpString(int id, const wxString& helpString); | |
119 | virtual wxString GetHelpString(int id) const ; | |
120 | ||
83885a39 VZ |
121 | // accessors |
122 | wxList& GetItems() { return m_items; } | |
123 | ||
6de97a3b RR |
124 | inline void Callback(const wxFunction func) { m_callback = func; } |
125 | ||
126 | inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; } | |
127 | inline wxEvtHandler *GetEventHandler() { return m_eventHandler; } | |
128 | ||
41dee9d0 RR |
129 | inline void SetClientData( void* clientData ) { m_clientData = clientData; } |
130 | inline void* GetClientData() const { return m_clientData; } | |
131 | ||
631f1bfe JS |
132 | // Updates the UI for a menu and all submenus recursively. |
133 | // source is the object that has the update event handlers | |
134 | // defined for it. If NULL, the menu or associated window | |
135 | // will be used. | |
136 | void UpdateUI(wxEvtHandler* source = (wxEvtHandler*) NULL); | |
137 | ||
41dee9d0 RR |
138 | // implementation |
139 | ||
83885a39 VZ |
140 | int FindMenuIdByMenuItem( GtkWidget *menuItem ) const; |
141 | void SetInvokingWindow( wxWindow *win ); | |
142 | wxWindow *GetInvokingWindow(); | |
143 | ||
6de97a3b RR |
144 | wxString m_title; |
145 | wxList m_items; | |
146 | wxWindow *m_invokingWindow; | |
147 | wxFunction m_callback; | |
148 | wxEvtHandler *m_eventHandler; | |
41dee9d0 | 149 | void *m_clientData; |
83885a39 | 150 | |
6de97a3b | 151 | GtkWidget *m_menu; // GtkMenu |
2b1c162e | 152 | GtkWidget *m_owner; |
c801d85f KB |
153 | }; |
154 | ||
155 | #endif // __GTKMENUH__ |