]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/menu.h
wxUsleep() introduced (and documented) to try to work around usleep() bug in
[wxWidgets.git] / include / wx / gtk / 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 wxMenuBar( long style );
48 wxMenuBar();
49 void Append( wxMenu *menu, const wxString &title );
50
51 int FindMenuItem( const wxString &menuString, const wxString &itemString ) const;
52 wxMenuItem* FindMenuItemById( int id ) const;
53 inline wxMenuItem* FindItemForId( int id ) const { return FindMenuItemById( id ); }
54
55 void Check( int id, bool check );
56 bool Checked( int id ) const;
57 void Enable( int id, bool enable );
58 bool Enabled( int id ) const;
59 inline bool IsEnabled( int id ) const { return Enabled(id); }
60 inline bool IsChecked( int id ) const { return Checked(id); }
61
62 wxString GetLabel( int id ) const;
63 void SetLabel( int id, const wxString &label );
64
65 void EnableTop( int pos, bool flag );
66 void SetLabelTop( int pos, const wxString& label );
67 wxString GetLabelTop( int pos ) const;
68
69 virtual void SetHelpString( int id, const wxString& helpString );
70 virtual wxString GetHelpString( int id ) const;
71
72 inline int GetMenuCount() const { return m_menus.Number(); }
73 inline wxMenu *GetMenu( int n ) const { return (wxMenu *)m_menus.Nth(n)->Data(); }
74
75 wxList m_menus;
76 GtkWidget *m_menubar;
77 };
78
79 //-----------------------------------------------------------------------------
80 // wxMenu
81 //-----------------------------------------------------------------------------
82
83 class wxMenu: public wxEvtHandler
84 {
85 DECLARE_DYNAMIC_CLASS(wxMenu)
86
87 public:
88 // construction
89 wxMenu( const wxString& title = wxEmptyString, const wxFunction func = (wxFunction) NULL );
90
91 // operations
92 // title
93 void SetTitle(const wxString& label);
94 const wxString GetTitle() const;
95 // menu creation
96 void AppendSeparator();
97 void Append(int id, const wxString &item,
98 const wxString &helpStr = "", bool checkable = FALSE);
99 void Append(int id, const wxString &item,
100 wxMenu *subMenu, const wxString &helpStr = "" );
101 void Append(wxMenuItem *pItem);
102 void Break() {};
103
104 // find item by name/id
105 int FindItem( const wxString itemString ) const;
106 wxMenuItem *FindItem( int id ) const;
107 wxMenuItem *FindItemForId( int id ) const { return FindItem( id ); }
108
109 // get/set item's state
110 void Enable( int id, bool enable );
111 bool IsEnabled( int id ) const;
112 void Check( int id, bool check );
113 bool IsChecked( int id ) const;
114
115 void SetLabel( int id, const wxString &label );
116 wxString GetLabel( int id ) const;
117
118 // helpstring
119 virtual void SetHelpString(int id, const wxString& helpString);
120 virtual wxString GetHelpString(int id) const ;
121
122 // accessors
123 wxList& GetItems() { return m_items; }
124
125 inline void Callback(const wxFunction func) { m_callback = func; }
126
127 inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
128 inline wxEvtHandler *GetEventHandler() { return m_eventHandler; }
129
130 inline void SetClientData( void* clientData ) { m_clientData = clientData; }
131 inline void* GetClientData() const { return m_clientData; }
132
133 // Updates the UI for a menu and all submenus recursively.
134 // source is the object that has the update event handlers
135 // defined for it. If NULL, the menu or associated window
136 // will be used.
137 void UpdateUI(wxEvtHandler* source = (wxEvtHandler*) NULL);
138
139 // implementation
140
141 int FindMenuIdByMenuItem( GtkWidget *menuItem ) const;
142 void SetInvokingWindow( wxWindow *win );
143 wxWindow *GetInvokingWindow();
144
145 wxString m_title;
146 wxList m_items;
147 wxWindow *m_invokingWindow;
148 wxFunction m_callback;
149 wxEvtHandler *m_eventHandler;
150 void *m_clientData;
151
152 GtkWidget *m_menu; // GtkMenu
153 GtkWidget *m_owner;
154 };
155
156 #endif // __GTKMENUH__