]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk1/menu.h
wxGTK::wxSpinCtrl API synchronised with wxMSW
[wxWidgets.git] / include / wx / gtk1 / menu.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/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 #ifndef __GTKMENUH__
11 #define __GTKMENUH__
12
13 #ifdef __GNUG__
14 #pragma interface "menu.h"
15 #endif
16
17 //-----------------------------------------------------------------------------
18 // wxMenuBar
19 //-----------------------------------------------------------------------------
20
21 class wxMenuBar : public wxMenuBarBase
22 {
23 public:
24 // ctors
25 wxMenuBar();
26 wxMenuBar(long style);
27 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
28 virtual ~wxMenuBar();
29
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);
35
36 virtual int FindMenuItem(const wxString& menuString,
37 const wxString& itemString) const;
38 virtual wxMenuItem* FindItem( int id, wxMenu **menu = NULL ) const;
39
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;
43
44 // implementation only from now on
45 void SetInvokingWindow( wxWindow *win );
46 void UnsetInvokingWindow( wxWindow *win );
47
48 GtkAccelGroup *m_accel;
49 GtkItemFactory *m_factory;
50 GtkWidget *m_menubar;
51 long m_style;
52 wxWindow *m_invokingWindow;
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)
60 };
61
62 //-----------------------------------------------------------------------------
63 // wxMenu
64 //-----------------------------------------------------------------------------
65
66 class wxMenu : public wxEvtHandler
67 {
68 DECLARE_DYNAMIC_CLASS(wxMenu)
69
70 public:
71 wxMenu( const wxString& title, const wxFunction func)
72 {
73 Init(title, 0, func);
74 }
75 wxMenu( long style )
76 {
77 Init( wxEmptyString, style );
78 }
79 wxMenu( const wxString& title = wxEmptyString, long style = 0 )
80 {
81 Init(title, style);
82 }
83
84 ~wxMenu();
85
86 // title
87 void SetTitle(const wxString& label);
88 const wxString GetTitle() const;
89
90 // menu creation
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() { }
98
99 // delete item. don't delete the wxMenu if it's a submenu
100 void Delete( int id );
101
102 // find item by name/id
103 int FindItem( const wxString itemString ) const;
104 wxMenuItem *FindItem( int id ) const;
105
106 // get/set item's state
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
136 wxFunction GetCallback() const { return m_callback; }
137 void Callback(const wxFunction func) { m_callback = func; }
138 wxFunction m_callback;
139
140 #ifdef WXWIN_COMPATIBILITY
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); }
145
146 #endif // WXWIN_COMPATIBILITY
147
148 // implementation
149 int FindMenuIdByMenuItem( GtkWidget *menuItem ) const;
150 void SetInvokingWindow( wxWindow *win );
151 wxWindow *GetInvokingWindow();
152
153 // implementation GTK only
154 GtkWidget *m_menu; // GtkMenu
155 GtkWidget *m_owner;
156 GtkAccelGroup *m_accel;
157 GtkItemFactory *m_factory;
158
159 // used by wxMenuBar
160 long GetStyle(void) const { return m_style; }
161
162 private:
163 // common code for both constructors:
164 void Init( const wxString& title,
165 long style,
166 const wxFunction func = (wxFunction) NULL );
167
168 wxString m_title;
169 wxList m_items;
170 wxWindow *m_invokingWindow;
171 wxEvtHandler *m_eventHandler;
172 void *m_clientData;
173 long m_style;
174 };
175
176 #endif // __GTKMENUH__