]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk1/menu.h
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling, Julian Smart
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
19 #include "wx/object.h"
21 #include "wx/window.h"
22 #include "wx/menuitem.h"
24 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 #define ID_SEPARATOR (-1)
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 class wxMenuBar
: public wxWindow
44 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
49 wxMenuBar(long style
);
50 wxMenuBar(int n
, wxMenu
*menus
[], const wxString titles
[]);
53 // menubar construction
54 void Append( wxMenu
*menu
, const wxString
&title
);
57 // by menu and item names, returns wxNOT_FOUND if not found
58 virtual int FindMenuItem(const wxString
& menuString
,
59 const wxString
& itemString
) const;
60 // returns NULL if not found
61 wxMenuItem
* FindItem( int id
) const;
62 // returns NULL if not found, fills menuForItem if !NULL
63 wxMenuItem
*FindItemForId(int itemId
, wxMenu
**menuForItem
= NULL
) const;
66 void Check( int id
, bool check
);
67 bool IsChecked( int id
) const;
68 void Enable( int id
, bool enable
);
69 bool IsEnabled( int id
) const;
71 void SetLabel( int id
, const wxString
&label
);
72 wxString
GetLabel( int id
) const;
73 wxString
GetLabel() const { return wxWindow::GetLabel(); }
75 void EnableTop( int pos
, bool flag
);
76 void SetLabelTop( int pos
, const wxString
& label
);
77 wxString
GetLabelTop( int pos
) const;
79 virtual void SetHelpString( int id
, const wxString
& helpString
);
80 virtual wxString
GetHelpString( int id
) const;
82 int GetMenuCount() const { return m_menus
.Number(); }
83 wxMenu
*GetMenu( int n
) const { return (wxMenu
*)m_menus
.Nth(n
)->Data(); }
85 #ifdef WXWIN_COMPATIBILITY
86 // compatibility: these functions are deprecated
87 bool Enabled(int id
) const { return IsEnabled(id
); }
88 bool Checked(int id
) const { return IsChecked(id
); }
90 wxMenuItem
* FindMenuItemById( int id
) const { return FindItem(id
); }
91 #endif // WXWIN_COMPATIBILITY
93 // implementation only
94 wxList
& GetMenus() { return m_menus
; }
96 void SetInvokingWindow( wxWindow
*win
);
97 void UnsetInvokingWindow( wxWindow
*win
);
99 GtkAccelGroup
*m_accel
;
100 GtkItemFactory
*m_factory
;
102 GtkWidget
*m_menubar
;
104 wxWindow
*m_invokingWindow
;
107 //-----------------------------------------------------------------------------
109 //-----------------------------------------------------------------------------
111 class wxMenu
: public wxEvtHandler
113 DECLARE_DYNAMIC_CLASS(wxMenu
)
116 wxMenu( const wxString
& title
, const wxFunction func
)
118 Init(title
, 0, func
);
122 Init( wxEmptyString
, style
);
124 wxMenu( const wxString
& title
= wxEmptyString
, long style
= 0 )
132 void SetTitle(const wxString
& label
);
133 const wxString
GetTitle() const;
136 void AppendSeparator();
137 void Append(int id
, const wxString
&item
,
138 const wxString
&helpStr
= "", bool checkable
= FALSE
);
139 void Append(int id
, const wxString
&item
,
140 wxMenu
*subMenu
, const wxString
&helpStr
= "" );
141 void Append(wxMenuItem
*pItem
);
144 // delete item. don't delete the wxMenu if it's a submenu
145 void Delete( int id
);
147 // find item by name/id
148 int FindItem( const wxString itemString
) const;
149 wxMenuItem
*FindItem( int id
) const;
151 // get/set item's state
152 void Enable( int id
, bool enable
);
153 bool IsEnabled( int id
) const;
154 void Check( int id
, bool check
);
155 bool IsChecked( int id
) const;
157 void SetLabel( int id
, const wxString
&label
);
158 wxString
GetLabel( int id
) const;
161 virtual void SetHelpString(int id
, const wxString
& helpString
);
162 virtual wxString
GetHelpString(int id
) const ;
165 wxList
& GetItems() { return m_items
; }
167 void SetEventHandler(wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
168 wxEvtHandler
*GetEventHandler() { return m_eventHandler
; }
170 void SetClientData( void* clientData
) { m_clientData
= clientData
; }
171 void* GetClientData() const { return m_clientData
; }
173 // Updates the UI for a menu and all submenus recursively.
174 // source is the object that has the update event handlers
175 // defined for it. If NULL, the menu or associated window
177 void UpdateUI(wxEvtHandler
* source
= (wxEvtHandler
*) NULL
);
179 wxMenuItem
*FindItemForId( int id
) const { return FindItem( id
); }
181 wxFunction
GetCallback() const { return m_callback
; }
182 void Callback(const wxFunction func
) { m_callback
= func
; }
183 wxFunction m_callback
;
185 #ifdef WXWIN_COMPATIBILITY
187 // compatibility: these functions are deprecated
188 bool Enabled(int id
) const { return IsEnabled(id
); }
189 bool Checked(int id
) const { return IsChecked(id
); }
191 #endif // WXWIN_COMPATIBILITY
194 int FindMenuIdByMenuItem( GtkWidget
*menuItem
) const;
195 void SetInvokingWindow( wxWindow
*win
);
196 wxWindow
*GetInvokingWindow();
198 // implementation GTK only
199 GtkWidget
*m_menu
; // GtkMenu
201 GtkAccelGroup
*m_accel
;
202 GtkItemFactory
*m_factory
;
205 long GetStyle(void) const { return m_style
; }
208 // common code for both constructors:
209 void Init( const wxString
& title
,
211 const wxFunction func
= (wxFunction
) NULL
);
215 wxWindow
*m_invokingWindow
;
216 wxEvtHandler
*m_eventHandler
;
221 #endif // __GTKMENUH__