]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk1/menu.h
9d4b13d2d0cbb429d31e3f10f2afe9f295c3d68d
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 class wxMenuBar
: public wxWindow
38 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
43 wxMenuBar(long style
);
44 wxMenuBar(int n
, wxMenu
*menus
[], const wxString titles
[]);
47 // menubar construction
48 void Append( wxMenu
*menu
, const wxString
&title
);
51 // by menu and item names, returns wxNOT_FOUND if not found
52 virtual int FindMenuItem(const wxString
& menuString
,
53 const wxString
& itemString
) const;
54 // returns NULL if not found
55 wxMenuItem
* FindItem( int id
) const;
56 // returns NULL if not found, fills menuForItem if !NULL
57 wxMenuItem
*FindItemForId(int itemId
, wxMenu
**menuForItem
= NULL
) const;
60 void Check( int id
, bool check
);
61 bool IsChecked( int id
) const;
62 void Enable( int id
, bool enable
);
63 bool IsEnabled( int id
) const;
65 void SetLabel( int id
, const wxString
&label
);
66 wxString
GetLabel( int id
) const;
67 wxString
GetLabel() const { return wxWindow::GetLabel(); }
69 void EnableTop( int pos
, bool flag
);
70 void SetLabelTop( int pos
, const wxString
& label
);
71 wxString
GetLabelTop( int pos
) const;
73 virtual void SetHelpString( int id
, const wxString
& helpString
);
74 virtual wxString
GetHelpString( int id
) const;
76 int GetMenuCount() const { return m_menus
.Number(); }
77 wxMenu
*GetMenu( int n
) const { return (wxMenu
*)m_menus
.Nth(n
)->Data(); }
79 #ifdef WXWIN_COMPATIBILITY
80 // compatibility: these functions are deprecated
81 bool Enabled(int id
) const { return IsEnabled(id
); }
82 bool Checked(int id
) const { return IsChecked(id
); }
84 wxMenuItem
* FindMenuItemById( int id
) const { return FindItem(id
); }
85 #endif // WXWIN_COMPATIBILITY
87 // implementation only
88 wxList
& GetMenus() { return m_menus
; }
90 void SetInvokingWindow( wxWindow
*win
);
91 void UnsetInvokingWindow( wxWindow
*win
);
93 GtkAccelGroup
*m_accel
;
94 GtkItemFactory
*m_factory
;
98 wxWindow
*m_invokingWindow
;
101 //-----------------------------------------------------------------------------
103 //-----------------------------------------------------------------------------
105 class wxMenu
: public wxEvtHandler
107 DECLARE_DYNAMIC_CLASS(wxMenu
)
110 wxMenu( const wxString
& title
, const wxFunction func
)
112 Init(title
, 0, func
);
116 Init( wxEmptyString
, style
);
118 wxMenu( const wxString
& title
= wxEmptyString
, long style
= 0 )
126 void SetTitle(const wxString
& label
);
127 const wxString
GetTitle() const;
130 void AppendSeparator();
131 void Append(int id
, const wxString
&item
,
132 const wxString
&helpStr
= "", bool checkable
= FALSE
);
133 void Append(int id
, const wxString
&item
,
134 wxMenu
*subMenu
, const wxString
&helpStr
= "" );
135 void Append(wxMenuItem
*pItem
);
138 // delete item. don't delete the wxMenu if it's a submenu
139 void Delete( int id
);
141 // find item by name/id
142 int FindItem( const wxString itemString
) const;
143 wxMenuItem
*FindItem( int id
) const;
145 // get/set item's state
146 void Enable( int id
, bool enable
);
147 bool IsEnabled( int id
) const;
148 void Check( int id
, bool check
);
149 bool IsChecked( int id
) const;
151 void SetLabel( int id
, const wxString
&label
);
152 wxString
GetLabel( int id
) const;
155 virtual void SetHelpString(int id
, const wxString
& helpString
);
156 virtual wxString
GetHelpString(int id
) const ;
159 wxList
& GetItems() { return m_items
; }
161 void SetEventHandler(wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
162 wxEvtHandler
*GetEventHandler() { return m_eventHandler
; }
164 void SetClientData( void* clientData
) { m_clientData
= clientData
; }
165 void* GetClientData() const { return m_clientData
; }
167 // Updates the UI for a menu and all submenus recursively.
168 // source is the object that has the update event handlers
169 // defined for it. If NULL, the menu or associated window
171 void UpdateUI(wxEvtHandler
* source
= (wxEvtHandler
*) NULL
);
173 wxMenuItem
*FindItemForId( int id
) const { return FindItem( id
); }
175 wxFunction
GetCallback() const { return m_callback
; }
176 void Callback(const wxFunction func
) { m_callback
= func
; }
177 wxFunction m_callback
;
179 #ifdef WXWIN_COMPATIBILITY
181 // compatibility: these functions are deprecated
182 bool Enabled(int id
) const { return IsEnabled(id
); }
183 bool Checked(int id
) const { return IsChecked(id
); }
185 #endif // WXWIN_COMPATIBILITY
188 int FindMenuIdByMenuItem( GtkWidget
*menuItem
) const;
189 void SetInvokingWindow( wxWindow
*win
);
190 wxWindow
*GetInvokingWindow();
192 // implementation GTK only
193 GtkWidget
*m_menu
; // GtkMenu
195 GtkAccelGroup
*m_accel
;
196 GtkItemFactory
*m_factory
;
199 long GetStyle(void) const { return m_style
; }
202 // common code for both constructors:
203 void Init( const wxString
& title
,
205 const wxFunction func
= (wxFunction
) NULL
);
209 wxWindow
*m_invokingWindow
;
210 wxEvtHandler
*m_eventHandler
;
215 #endif // __GTKMENUH__