]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk1/menu.h
removed a few objects whose sources have been moved
[wxWidgets.git] / include / wx / gtk1 / menu.h
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 #include "wx/menuitem.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 // ctors
48 wxMenuBar();
49 wxMenuBar(long style);
50 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
51
52 // menubar construction
53 void Append( wxMenu *menu, const wxString &title );
54
55 // item search
56 // by menu and item names, returns wxNOT_FOUND if not found
57 virtual int FindMenuItem(const wxString& menuString,
58 const wxString& itemString) const;
59 // returns NULL if not found
60 wxMenuItem* FindItem( int id ) const;
61 // returns NULL if not found, fills menuForItem if !NULL
62 wxMenuItem *FindItemForId(int itemId, wxMenu **menuForItem = NULL) const;
63
64 // state control
65 void Check( int id, bool check );
66 bool IsChecked( int id ) const;
67 void Enable( int id, bool enable );
68 bool IsEnabled( int id ) const;
69
70 wxString GetLabel( int id ) const;
71 void SetLabel( int id, const wxString &label );
72
73 void EnableTop( int pos, bool flag );
74 void SetLabelTop( int pos, const wxString& label );
75 wxString GetLabelTop( int pos ) const;
76
77 virtual void SetHelpString( int id, const wxString& helpString );
78 virtual wxString GetHelpString( int id ) const;
79
80 int GetMenuCount() const { return m_menus.Number(); }
81 wxMenu *GetMenu( int n ) const { return (wxMenu *)m_menus.Nth(n)->Data(); }
82
83 #ifdef WXWIN_COMPATIBILITY
84 // compatibility: these functions are deprecated
85 bool Enabled(int id) const { return IsEnabled(id); }
86 bool Checked(int id) const { return IsChecked(id); }
87
88 wxMenuItem* FindMenuItemById( int id ) const { return FindItem(id); }
89 #endif // WXWIN_COMPATIBILITY
90
91 // implementation
92 wxList& GetMenus() { return m_menus; }
93
94 protected:
95 wxList m_menus;
96 GtkWidget *m_menubar;
97 };
98
99 //-----------------------------------------------------------------------------
100 // wxMenu
101 //-----------------------------------------------------------------------------
102
103 class wxMenu : public wxEvtHandler
104 {
105 DECLARE_DYNAMIC_CLASS(wxMenu)
106
107 public:
108 // construction
109 wxMenu( const wxString& title = wxEmptyString,
110 const wxFunction func = (wxFunction) NULL );
111
112 // operations
113 // title
114 void SetTitle(const wxString& label);
115 const wxString GetTitle() const;
116 // menu creation
117 void AppendSeparator();
118 void Append(int id, const wxString &item,
119 const wxString &helpStr = "", bool checkable = FALSE);
120 void Append(int id, const wxString &item,
121 wxMenu *subMenu, const wxString &helpStr = "" );
122 void Append(wxMenuItem *pItem);
123 void Break() { }
124
125 // find item by name/id
126 int FindItem( const wxString itemString ) const;
127 wxMenuItem *FindItem( int id ) const;
128
129 // get/set item's state
130 void Enable( int id, bool enable );
131 bool IsEnabled( int id ) const;
132 void Check( int id, bool check );
133 bool IsChecked( int id ) const;
134
135 void SetLabel( int id, const wxString &label );
136 wxString GetLabel( int id ) const;
137
138 // helpstring
139 virtual void SetHelpString(int id, const wxString& helpString);
140 virtual wxString GetHelpString(int id) const ;
141
142 // accessors
143 wxList& GetItems() { return m_items; }
144
145 void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
146 wxEvtHandler *GetEventHandler() { return m_eventHandler; }
147
148 void SetClientData( void* clientData ) { m_clientData = clientData; }
149 void* GetClientData() const { return m_clientData; }
150
151 // Updates the UI for a menu and all submenus recursively.
152 // source is the object that has the update event handlers
153 // defined for it. If NULL, the menu or associated window
154 // will be used.
155 void UpdateUI(wxEvtHandler* source = (wxEvtHandler*) NULL);
156
157 wxMenuItem *FindItemForId( int id ) const { return FindItem( id ); }
158
159 #ifdef WXWIN_COMPATIBILITY
160 wxFunction GetCallback() const { return m_callback; }
161 void Callback(const wxFunction func) { m_callback = func; }
162
163 // compatibility: these functions are deprecated
164 bool Enabled(int id) const { return IsEnabled(id); }
165 bool Checked(int id) const { return IsChecked(id); }
166 #endif // WXWIN_COMPATIBILITY
167
168 // implementation
169 int FindMenuIdByMenuItem( GtkWidget *menuItem ) const;
170 void SetInvokingWindow( wxWindow *win );
171 wxWindow *GetInvokingWindow();
172
173 // implementation only
174 GtkWidget *m_menu; // GtkMenu
175 GtkWidget *m_owner;
176
177 private:
178 wxString m_title;
179 wxList m_items;
180 wxWindow *m_invokingWindow;
181 wxFunction m_callback;
182 wxEvtHandler *m_eventHandler;
183 void *m_clientData;
184 };
185
186 #endif // __GTKMENUH__