]> git.saurik.com Git - wxWidgets.git/blame - include/wx/motif/menu.h
Added some makefiles to HTML samples; added help.ico for wxHTML;
[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
9874b4ee
VZ
12#ifndef _WX_MOTIF_MENU_H_
13#define _WX_MOTIF_MENU_H_
9b6dbb09
JS
14
15#ifdef __GNUG__
9874b4ee 16 #pragma interface "menu.h"
9b6dbb09
JS
17#endif
18
9874b4ee 19#include "wx/colour.h"
94b49b93 20#include "wx/font.h"
9b6dbb09 21
9874b4ee 22class wxFrame;
9b6dbb09
JS
23
24// ----------------------------------------------------------------------------
25// Menu
26// ----------------------------------------------------------------------------
9874b4ee
VZ
27
28class wxMenu : public wxEvtHandler
9b6dbb09
JS
29{
30 DECLARE_DYNAMIC_CLASS(wxMenu)
31
32public:
33 // ctor & dtor
ee31c392
VZ
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();
9b6dbb09
JS
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
ee31c392 54 void Append(int id, const wxString& Label, wxMenu *SubMenu,
9b6dbb09
JS
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;
ee31c392 66 bool IsEnabled(int id) const { return Enabled(id); };
9b6dbb09
JS
67 void Check(int id, bool Flag);
68 bool Checked(int id) const;
ee31c392 69 bool IsChecked(int id) const { return IsChecked(id); };
9b6dbb09 70
3dd4e4e0 71 // Client data
ee31c392
VZ
72 void SetClientData(void* clientData) { m_clientData = clientData; }
73 void* GetClientData() const { return m_clientData; }
3dd4e4e0 74
9b6dbb09
JS
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
631f1bfe
JS
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
9b6dbb09 98 void ProcessCommand(wxCommandEvent& event);
ee31c392
VZ
99
100#ifdef WXWIN_COMPATIBILITY
101 void Callback(const wxFunction func) { m_callback = func; }
102#endif // WXWIN_COMPATIBILITY
9b6dbb09 103
ee31c392
VZ
104 void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
105 wxEvtHandler *GetEventHandler() { return m_eventHandler; }
9b6dbb09 106
ee31c392 107 wxList& GetItems() const { return (wxList&) m_menuItems; }
9b6dbb09 108
631f1bfe
JS
109 void SetInvokingWindow(wxWindow *pWin) { m_pInvokingWindow = pWin; }
110 wxWindow *GetInvokingWindow() const { return m_pInvokingWindow; }
111
9b6dbb09 112 //// Motif-specific
ee31c392
VZ
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; }
50414e24
JS
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
94b49b93
JS
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
ee31c392
VZ
144 // implementation from now on
145 WXWidget GetHandle() const { return m_menuWidget; }
146 bool IsTearOff() const { return (m_style & wxMENU_TEAROFF) != 0; }
147
9b6dbb09 148public:
ee31c392 149#ifdef WXWIN_COMPATIBILITY
9b6dbb09 150 wxFunction m_callback;
ee31c392 151#endif // WXWIN_COMPATIBILITY
9b6dbb09
JS
152
153 int m_noItems;
154 wxString m_title;
155 wxMenuBar * m_menuBar;
156 wxList m_menuItems;
9b6dbb09 157 wxEvtHandler * m_eventHandler;
3dd4e4e0 158 void* m_clientData;
631f1bfe 159 wxWindow* m_pInvokingWindow;
9b6dbb09 160
ee31c392
VZ
161 long m_style;
162
9b6dbb09
JS
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;
50414e24 169 wxMenu* m_topLevelMenu ;
9b6dbb09
JS
170 wxMenu* m_menuParent;
171 bool m_ownedByMenuBar;
94b49b93
JS
172 wxColour m_foregroundColour;
173 wxColour m_backgroundColour;
174 wxFont m_font;
ee31c392
VZ
175
176private:
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 );
9b6dbb09
JS
184};
185
186// ----------------------------------------------------------------------------
9874b4ee 187// Menu Bar
9b6dbb09 188// ----------------------------------------------------------------------------
ee31c392 189
9874b4ee 190class wxMenuBar : public wxMenuBarBase
9b6dbb09 191{
ee31c392 192public:
9874b4ee
VZ
193 wxMenuBar() { Init(); }
194 wxMenuBar(long WXUNUSED(style)) { Init(); }
ee31c392 195 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
9874b4ee
VZ
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
ee31c392
VZ
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
9874b4ee
VZ
232 virtual bool SetBackgroundColour(const wxColour& colour);
233 virtual bool SetForegroundColour(const wxColour& colour);
234 virtual bool SetFont(const wxFont& colour);
ee31c392 235 void ChangeFont(bool keepOriginalSize = FALSE);
50414e24 236
ee31c392 237public:
9874b4ee
VZ
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)
9b6dbb09
JS
251};
252
9874b4ee 253#endif // _WX_MOTIF_MENU_H_