]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
3dfac970 | 2 | // Name: wx/gtk/menu.h |
c801d85f KB |
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 | ||
c801d85f KB |
10 | #ifndef __GTKMENUH__ |
11 | #define __GTKMENUH__ | |
12 | ||
13 | #ifdef __GNUG__ | |
3dfac970 | 14 | #pragma interface "menu.h" |
c801d85f KB |
15 | #endif |
16 | ||
c801d85f KB |
17 | //----------------------------------------------------------------------------- |
18 | // wxMenuBar | |
19 | //----------------------------------------------------------------------------- | |
20 | ||
3dfac970 | 21 | class wxMenuBar : public wxMenuBarBase |
c801d85f | 22 | { |
83885a39 | 23 | public: |
c626a8b7 VZ |
24 | // ctors |
25 | wxMenuBar(); | |
26 | wxMenuBar(long style); | |
27 | wxMenuBar(int n, wxMenu *menus[], const wxString titles[]); | |
3dfac970 | 28 | virtual ~wxMenuBar(); |
c626a8b7 | 29 | |
3dfac970 VZ |
30 | // implement base class (pure) virtuals |
31 | virtual bool Append( wxMenu *menu, const wxString &title ); | |
32 | virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title); | |
33 | virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title); | |
34 | virtual wxMenu *Remove(size_t pos); | |
c626a8b7 | 35 | |
c626a8b7 VZ |
36 | virtual int FindMenuItem(const wxString& menuString, |
37 | const wxString& itemString) const; | |
3dfac970 | 38 | virtual wxMenuItem* FindItem( int id, wxMenu **menu = NULL ) const; |
c626a8b7 | 39 | |
3dfac970 VZ |
40 | virtual void EnableTop( size_t pos, bool flag ); |
41 | virtual void SetLabelTop( size_t pos, const wxString& label ); | |
42 | virtual wxString GetLabelTop( size_t pos ) const; | |
b908d224 | 43 | |
3dfac970 | 44 | // implementation only from now on |
5bd9e519 RR |
45 | void SetInvokingWindow( wxWindow *win ); |
46 | void UnsetInvokingWindow( wxWindow *win ); | |
c626a8b7 | 47 | |
1e133b7d RR |
48 | GtkAccelGroup *m_accel; |
49 | GtkItemFactory *m_factory; | |
1e133b7d | 50 | GtkWidget *m_menubar; |
ae53c98c | 51 | long m_style; |
9c884972 | 52 | wxWindow *m_invokingWindow; |
3dfac970 VZ |
53 | |
54 | #if 0 // seems to be unused (VZ) | |
55 | wxMenuList& GetMenus() { return m_menus; } | |
56 | #endif // 0 | |
57 | ||
58 | private: | |
59 | DECLARE_DYNAMIC_CLASS(wxMenuBar) | |
c801d85f KB |
60 | }; |
61 | ||
62 | //----------------------------------------------------------------------------- | |
63 | // wxMenu | |
64 | //----------------------------------------------------------------------------- | |
65 | ||
c626a8b7 | 66 | class wxMenu : public wxEvtHandler |
c801d85f | 67 | { |
c626a8b7 | 68 | DECLARE_DYNAMIC_CLASS(wxMenu) |
83885a39 VZ |
69 | |
70 | public: | |
b908d224 VZ |
71 | wxMenu( const wxString& title, const wxFunction func) |
72 | { | |
73 | Init(title, 0, func); | |
74 | } | |
b62c3631 RR |
75 | wxMenu( long style ) |
76 | { | |
77 | Init( wxEmptyString, style ); | |
78 | } | |
b908d224 VZ |
79 | wxMenu( const wxString& title = wxEmptyString, long style = 0 ) |
80 | { | |
1ecffbff | 81 | Init(title, style); |
b908d224 VZ |
82 | } |
83 | ||
034be888 | 84 | ~wxMenu(); |
c626a8b7 | 85 | |
d1b15f03 | 86 | // title |
c626a8b7 VZ |
87 | void SetTitle(const wxString& label); |
88 | const wxString GetTitle() const; | |
3dfac970 | 89 | |
d1b15f03 | 90 | // menu creation |
c626a8b7 VZ |
91 | void AppendSeparator(); |
92 | void Append(int id, const wxString &item, | |
93 | const wxString &helpStr = "", bool checkable = FALSE); | |
94 | void Append(int id, const wxString &item, | |
95 | wxMenu *subMenu, const wxString &helpStr = "" ); | |
96 | void Append(wxMenuItem *pItem); | |
97 | void Break() { } | |
83885a39 | 98 | |
d1b15f03 RR |
99 | // delete item. don't delete the wxMenu if it's a submenu |
100 | void Delete( int id ); | |
101 | ||
83885a39 | 102 | // find item by name/id |
c626a8b7 VZ |
103 | int FindItem( const wxString itemString ) const; |
104 | wxMenuItem *FindItem( int id ) const; | |
83885a39 VZ |
105 | |
106 | // get/set item's state | |
c626a8b7 VZ |
107 | void Enable( int id, bool enable ); |
108 | bool IsEnabled( int id ) const; | |
109 | void Check( int id, bool check ); | |
110 | bool IsChecked( int id ) const; | |
111 | ||
112 | void SetLabel( int id, const wxString &label ); | |
113 | wxString GetLabel( int id ) const; | |
114 | ||
115 | // helpstring | |
116 | virtual void SetHelpString(int id, const wxString& helpString); | |
117 | virtual wxString GetHelpString(int id) const ; | |
118 | ||
119 | // accessors | |
120 | wxList& GetItems() { return m_items; } | |
121 | ||
122 | void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; } | |
123 | wxEvtHandler *GetEventHandler() { return m_eventHandler; } | |
124 | ||
125 | void SetClientData( void* clientData ) { m_clientData = clientData; } | |
126 | void* GetClientData() const { return m_clientData; } | |
127 | ||
128 | // Updates the UI for a menu and all submenus recursively. | |
129 | // source is the object that has the update event handlers | |
130 | // defined for it. If NULL, the menu or associated window | |
131 | // will be used. | |
132 | void UpdateUI(wxEvtHandler* source = (wxEvtHandler*) NULL); | |
133 | ||
134 | wxMenuItem *FindItemForId( int id ) const { return FindItem( id ); } | |
135 | ||
c626a8b7 VZ |
136 | wxFunction GetCallback() const { return m_callback; } |
137 | void Callback(const wxFunction func) { m_callback = func; } | |
33961d59 RR |
138 | wxFunction m_callback; |
139 | ||
140 | #ifdef WXWIN_COMPATIBILITY | |
c626a8b7 VZ |
141 | |
142 | // compatibility: these functions are deprecated | |
143 | bool Enabled(int id) const { return IsEnabled(id); } | |
144 | bool Checked(int id) const { return IsChecked(id); } | |
b908d224 | 145 | |
c626a8b7 VZ |
146 | #endif // WXWIN_COMPATIBILITY |
147 | ||
148 | // implementation | |
149 | int FindMenuIdByMenuItem( GtkWidget *menuItem ) const; | |
150 | void SetInvokingWindow( wxWindow *win ); | |
151 | wxWindow *GetInvokingWindow(); | |
152 | ||
1e133b7d | 153 | // implementation GTK only |
034be888 RR |
154 | GtkWidget *m_menu; // GtkMenu |
155 | GtkWidget *m_owner; | |
034be888 RR |
156 | GtkAccelGroup *m_accel; |
157 | GtkItemFactory *m_factory; | |
c626a8b7 | 158 | |
ae53c98c | 159 | // used by wxMenuBar |
b908d224 VZ |
160 | long GetStyle(void) const { return m_style; } |
161 | ||
162 | private: | |
ae53c98c KB |
163 | // common code for both constructors: |
164 | void Init( const wxString& title, | |
3dfac970 | 165 | long style, |
33961d59 | 166 | const wxFunction func = (wxFunction) NULL ); |
1e133b7d | 167 | |
c626a8b7 VZ |
168 | wxString m_title; |
169 | wxList m_items; | |
170 | wxWindow *m_invokingWindow; | |
c626a8b7 VZ |
171 | wxEvtHandler *m_eventHandler; |
172 | void *m_clientData; | |
ae53c98c | 173 | long m_style; |
c801d85f KB |
174 | }; |
175 | ||
176 | #endif // __GTKMENUH__ |