1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenu, wxMenuBar classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_MOTIF_MENU_H_
13 #define _WX_MOTIF_MENU_H_
16 #pragma interface "menu.h"
19 #include "wx/colour.h"
24 // ----------------------------------------------------------------------------
26 // ----------------------------------------------------------------------------
28 class wxMenu
: public wxEvtHandler
30 DECLARE_DYNAMIC_CLASS(wxMenu
)
34 #ifdef WXWIN_COMPATIBILITY
35 wxMenu( const wxString
& title
, const wxFunction func
)
39 #endif // WXWIN_COMPATIBILITY
40 wxMenu( const wxString
& title
= wxEmptyString
, long style
= 0 )
47 // append items to the menu
49 void AppendSeparator();
51 void Append(int id
, const wxString
& Label
, const wxString
& helpString
= wxEmptyString
,
52 bool checkable
= FALSE
);
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
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
); };
72 void SetClientData(void* clientData
) { m_clientData
= clientData
; }
73 void* GetClientData() const { return m_clientData
; }
77 void SetTitle(const wxString
& label
);
78 const wxString
GetTitle() const;
80 void SetLabel(int id
, const wxString
& label
);
81 wxString
GetLabel(int id
) const;
83 virtual void SetHelpString(int id
, const wxString
& helpString
);
84 virtual wxString
GetHelpString(int id
) const ;
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;
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
96 void UpdateUI(wxEvtHandler
* source
= (wxEvtHandler
*) NULL
);
98 void ProcessCommand(wxCommandEvent
& event
);
100 #ifdef WXWIN_COMPATIBILITY
101 void Callback(const wxFunction func
) { m_callback
= func
; }
102 #endif // WXWIN_COMPATIBILITY
104 void SetEventHandler(wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
105 wxEvtHandler
*GetEventHandler() { return m_eventHandler
; }
107 wxList
& GetItems() const { return (wxList
&) m_menuItems
; }
109 void SetInvokingWindow(wxWindow
*pWin
) { m_pInvokingWindow
= pWin
; }
110 wxWindow
*GetInvokingWindow() const { return m_pInvokingWindow
; }
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
; }
122 void CreatePopup (WXWidget logicalParent
, int x
, int y
);
123 void DestroyPopup (void);
124 void ShowPopup (int x
, int y
);
125 void HidePopup (void);
127 WXWidget
CreateMenu(wxMenuBar
*menuBar
, WXWidget parent
, wxMenu
*topMenu
,
128 const wxString
& title
= "", bool isPulldown
= FALSE
);
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;
135 const wxColour
& GetBackgroundColour() const { return m_backgroundColour
; }
136 const wxColour
& GetForegroundColour() const { return m_foregroundColour
; }
137 const wxFont
& GetFont() const { return m_font
; }
139 void SetBackgroundColour(const wxColour
& colour
);
140 void SetForegroundColour(const wxColour
& colour
);
141 void SetFont(const wxFont
& colour
);
142 void ChangeFont(bool keepOriginalSize
= FALSE
);
144 // implementation from now on
145 WXWidget
GetHandle() const { return m_menuWidget
; }
146 bool IsTearOff() const { return (m_style
& wxMENU_TEAROFF
) != 0; }
149 #ifdef WXWIN_COMPATIBILITY
150 wxFunction m_callback
;
151 #endif // WXWIN_COMPATIBILITY
155 wxMenuBar
* m_menuBar
;
157 wxEvtHandler
* m_eventHandler
;
159 wxWindow
* m_pInvokingWindow
;
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.
169 wxMenu
* m_topLevelMenu
;
170 wxMenu
* m_menuParent
;
171 bool m_ownedByMenuBar
;
172 wxColour m_foregroundColour
;
173 wxColour m_backgroundColour
;
177 // common code for both constructors:
178 void Init( const wxString
& title
,
180 #ifdef WXWIN_COMPATIBILITY
181 , const wxFunction func
= (wxFunction
) NULL
186 // ----------------------------------------------------------------------------
188 // ----------------------------------------------------------------------------
190 class wxMenuBar
: public wxMenuBarBase
193 wxMenuBar() { Init(); }
194 wxMenuBar(long WXUNUSED(style
)) { Init(); }
195 wxMenuBar(int n
, wxMenu
*menus
[], const wxString titles
[]);
196 virtual ~wxMenuBar();
198 // implement base class (pure) virtuals
199 // ------------------------------------
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
);
206 virtual int FindMenuItem(const wxString
& menuString
,
207 const wxString
& itemString
) const;
208 virtual wxMenuItem
* FindItem( int id
, wxMenu
**menu
= NULL
) const;
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;
214 // implementation only from now on
215 // -------------------------------
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
; }
223 bool CreateMenuBar(wxFrame
* frame
);
225 // Destroy menubar, but keep data structures intact so we can recreate it.
226 bool DestroyMenuBar();
228 const wxColour
& GetBackgroundColour() const { return m_backgroundColour
; }
229 const wxColour
& GetForegroundColour() const { return m_foregroundColour
; }
230 const wxFont
& GetFont() const { return m_font
; }
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
);
238 // common part of all ctors
241 wxArrayString m_titles
;
242 wxFrame
*m_menuBarFrame
;
244 WXWidget m_mainWidget
;
246 wxColour m_foregroundColour
;
247 wxColour m_backgroundColour
;
250 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
253 #endif // _WX_MOTIF_MENU_H_