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