1. wxMenu{Item|Bar} modifications for wxMotif
[wxWidgets.git] / include / wx / motif / menu.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: menu.h
3 // Purpose: wxMenu, wxMenuBar classes
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 17/09/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_MOTIF_MENU_H_
13 #define _WX_MOTIF_MENU_H_
14
15 #ifdef __GNUG__
16 #pragma interface "menu.h"
17 #endif
18
19 #include "wx/colour.h"
20 #include "wx/font.h"
21
22 class wxFrame;
23
24 // ----------------------------------------------------------------------------
25 // Menu
26 // ----------------------------------------------------------------------------
27
28 class wxMenu : public wxEvtHandler
29 {
30 DECLARE_DYNAMIC_CLASS(wxMenu)
31
32 public:
33 // ctor & dtor
34 #ifdef WXWIN_COMPATIBILITY
35 wxMenu( const wxString& title, const wxFunction func)
36 {
37 Init(title, 0, func);
38 }
39 #endif // WXWIN_COMPATIBILITY
40 wxMenu( const wxString& title = wxEmptyString, long style = 0 )
41 {
42 Init(title, style);
43 }
44 virtual ~wxMenu();
45
46 // construct menu
47 // append items to the menu
48 // separator line
49 void AppendSeparator();
50 // normal item
51 void Append(int id, const wxString& Label, const wxString& helpString = wxEmptyString,
52 bool checkable = FALSE);
53 // a submenu
54 void Append(int id, const wxString& Label, wxMenu *SubMenu,
55 const wxString& helpString = wxEmptyString);
56 // the most generic form (create wxMenuItem first and use it's functions)
57 void Append(wxMenuItem *pItem);
58 // insert a break in the menu
59 void Break();
60 // delete an item
61 void Delete(int id);
62
63 // menu item control
64 void Enable(int id, bool Flag);
65 bool Enabled(int id) const;
66 bool IsEnabled(int id) const { return Enabled(id); };
67 void Check(int id, bool Flag);
68 bool Checked(int id) const;
69 bool IsChecked(int id) const { return IsChecked(id); };
70
71 // Client data
72 void SetClientData(void* clientData) { m_clientData = clientData; }
73 void* GetClientData() const { return m_clientData; }
74
75 // item properties
76 // title
77 void SetTitle(const wxString& label);
78 const wxString GetTitle() const;
79 // label
80 void SetLabel(int id, const wxString& label);
81 wxString GetLabel(int id) const;
82 // help string
83 virtual void SetHelpString(int id, const wxString& helpString);
84 virtual wxString GetHelpString(int id) const ;
85
86 // find item
87 // Finds the item id matching the given string, -1 if not found.
88 virtual int FindItem(const wxString& itemString) const ;
89 // Find wxMenuItem by ID, and item's menu too if itemMenu is !NULL.
90 wxMenuItem *FindItemForId(int itemId, wxMenu **itemMenu = NULL) const;
91
92 // Updates the UI for a menu and all submenus recursively.
93 // source is the object that has the update event handlers
94 // defined for it. If NULL, the menu or associated window
95 // will be used.
96 void UpdateUI(wxEvtHandler* source = (wxEvtHandler*) NULL);
97
98 void ProcessCommand(wxCommandEvent& event);
99
100 #ifdef WXWIN_COMPATIBILITY
101 void Callback(const wxFunction func) { m_callback = func; }
102 #endif // WXWIN_COMPATIBILITY
103
104 void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
105 wxEvtHandler *GetEventHandler() { return m_eventHandler; }
106
107 wxList& GetItems() const { return (wxList&) m_menuItems; }
108
109 void SetInvokingWindow(wxWindow *pWin) { m_pInvokingWindow = pWin; }
110 wxWindow *GetInvokingWindow() const { return m_pInvokingWindow; }
111
112 //// Motif-specific
113 WXWidget GetButtonWidget() const { return m_buttonWidget; }
114 void SetButtonWidget(WXWidget buttonWidget) { m_buttonWidget = buttonWidget; }
115 WXWidget GetMainWidget() const { return m_menuWidget; }
116 wxMenu* GetParent() const { return m_menuParent; }
117 int GetId() const { return m_menuId; }
118 void SetId(int id) { m_menuId = id; }
119 void SetMenuBar(wxMenuBar* menuBar) { m_menuBar = menuBar; }
120 wxMenuBar* GetMenuBar() const { return m_menuBar; }
121
122 void CreatePopup (WXWidget logicalParent, int x, int y);
123 void DestroyPopup (void);
124 void ShowPopup (int x, int y);
125 void HidePopup (void);
126
127 WXWidget CreateMenu(wxMenuBar *menuBar, WXWidget parent, wxMenu *topMenu,
128 const wxString& title = "", bool isPulldown = FALSE);
129
130 // For popups, need to destroy, then recreate menu for a different (or
131 // possibly same) window, since the parent may change.
132 void DestroyMenu(bool full);
133 WXWidget FindMenuItem(int id, wxMenuItem **it = NULL) const;
134
135 const wxColour& GetBackgroundColour() const { return m_backgroundColour; }
136 const wxColour& GetForegroundColour() const { return m_foregroundColour; }
137 const wxFont& GetFont() const { return m_font; }
138
139 void SetBackgroundColour(const wxColour& colour);
140 void SetForegroundColour(const wxColour& colour);
141 void SetFont(const wxFont& colour);
142 void ChangeFont(bool keepOriginalSize = FALSE);
143
144 // implementation from now on
145 WXWidget GetHandle() const { return m_menuWidget; }
146 bool IsTearOff() const { return (m_style & wxMENU_TEAROFF) != 0; }
147
148 public:
149 #ifdef WXWIN_COMPATIBILITY
150 wxFunction m_callback;
151 #endif // WXWIN_COMPATIBILITY
152
153 int m_noItems;
154 wxString m_title;
155 wxMenuBar * m_menuBar;
156 wxList m_menuItems;
157 wxEvtHandler * m_eventHandler;
158 void* m_clientData;
159 wxWindow* m_pInvokingWindow;
160
161 long m_style;
162
163 //// Motif-specific
164 int m_numColumns;
165 WXWidget m_menuWidget;
166 WXWidget m_popupShell; // For holding the popup shell widget
167 WXWidget m_buttonWidget; // The actual string, so we can grey it etc.
168 int m_menuId;
169 wxMenu* m_topLevelMenu ;
170 wxMenu* m_menuParent;
171 bool m_ownedByMenuBar;
172 wxColour m_foregroundColour;
173 wxColour m_backgroundColour;
174 wxFont m_font;
175
176 private:
177 // common code for both constructors:
178 void Init( const wxString& title,
179 long style
180 #ifdef WXWIN_COMPATIBILITY
181 , const wxFunction func = (wxFunction) NULL
182 #endif
183 );
184 };
185
186 // ----------------------------------------------------------------------------
187 // Menu Bar
188 // ----------------------------------------------------------------------------
189
190 class wxMenuBar : public wxMenuBarBase
191 {
192 public:
193 wxMenuBar() { Init(); }
194 wxMenuBar(long WXUNUSED(style)) { Init(); }
195 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
196 virtual ~wxMenuBar();
197
198 // implement base class (pure) virtuals
199 // ------------------------------------
200
201 virtual bool Append( wxMenu *menu, const wxString &title );
202 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
203 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
204 virtual wxMenu *Remove(size_t pos);
205
206 virtual int FindMenuItem(const wxString& menuString,
207 const wxString& itemString) const;
208 virtual wxMenuItem* FindItem( int id, wxMenu **menu = NULL ) const;
209
210 virtual void EnableTop( size_t pos, bool flag );
211 virtual void SetLabelTop( size_t pos, const wxString& label );
212 virtual wxString GetLabelTop( size_t pos ) const;
213
214 // implementation only from now on
215 // -------------------------------
216
217 wxFrame* GetMenuBarFrame() const { return m_menuBarFrame; }
218 void SetMenuBarFrame(wxFrame* frame) { m_menuBarFrame = frame; }
219 WXWidget GetMainWidget() const { return m_mainWidget; }
220 void SetMainWidget(WXWidget widget) { m_mainWidget = widget; }
221
222 // Create menubar
223 bool CreateMenuBar(wxFrame* frame);
224
225 // Destroy menubar, but keep data structures intact so we can recreate it.
226 bool DestroyMenuBar();
227
228 const wxColour& GetBackgroundColour() const { return m_backgroundColour; }
229 const wxColour& GetForegroundColour() const { return m_foregroundColour; }
230 const wxFont& GetFont() const { return m_font; }
231
232 virtual bool SetBackgroundColour(const wxColour& colour);
233 virtual bool SetForegroundColour(const wxColour& colour);
234 virtual bool SetFont(const wxFont& colour);
235 void ChangeFont(bool keepOriginalSize = FALSE);
236
237 public:
238 // common part of all ctors
239 void Init();
240
241 wxArrayString m_titles;
242 wxFrame *m_menuBarFrame;
243
244 WXWidget m_mainWidget;
245
246 wxColour m_foregroundColour;
247 wxColour m_backgroundColour;
248 wxFont m_font;
249
250 DECLARE_DYNAMIC_CLASS(wxMenuBar)
251 };
252
253 #endif // _WX_MOTIF_MENU_H_