1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/motif/menu.h
3 // Purpose: wxMenu, wxMenuBar classes
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_MOTIF_MENU_H_
12 #define _WX_MOTIF_MENU_H_
14 #include "wx/colour.h"
16 #include "wx/arrstr.h"
18 class WXDLLIMPEXP_FWD_CORE wxFrame
;
20 // ----------------------------------------------------------------------------
22 // ----------------------------------------------------------------------------
24 class WXDLLIMPEXP_CORE wxMenu
: public wxMenuBase
28 wxMenu(const wxString
& title
, long style
= 0)
29 : wxMenuBase(title
, style
) { Init(); }
31 wxMenu(long style
= 0) : wxMenuBase(style
) { Init(); }
35 // implement base class virtuals
36 virtual wxMenuItem
* DoAppend(wxMenuItem
*item
);
37 virtual wxMenuItem
* DoInsert(size_t pos
, wxMenuItem
*item
);
38 virtual wxMenuItem
* DoRemove(wxMenuItem
*item
);
42 virtual void SetTitle(const wxString
& title
);
44 bool ProcessCommand(wxCommandEvent
& event
);
47 WXWidget
GetButtonWidget() const { return m_buttonWidget
; }
48 void SetButtonWidget(WXWidget buttonWidget
) { m_buttonWidget
= buttonWidget
; }
50 WXWidget
GetMainWidget() const { return m_menuWidget
; }
52 int GetId() const { return m_menuId
; }
53 void SetId(int id
) { m_menuId
= id
; }
55 void SetMenuBar(wxMenuBar
* menuBar
) { m_menuBar
= menuBar
; }
56 wxMenuBar
* GetMenuBar() const { return m_menuBar
; }
58 void CreatePopup(WXWidget logicalParent
, int x
, int y
);
60 void ShowPopup(int x
, int y
);
63 WXWidget
CreateMenu(wxMenuBar
*menuBar
, WXWidget parent
, wxMenu
*topMenu
,
64 size_t index
, const wxString
& title
= wxEmptyString
,
65 bool isPulldown
= false);
67 // For popups, need to destroy, then recreate menu for a different (or
68 // possibly same) window, since the parent may change.
69 void DestroyMenu(bool full
);
70 WXWidget
FindMenuItem(int id
, wxMenuItem
**it
= NULL
) const;
72 const wxColour
& GetBackgroundColour() const { return m_backgroundColour
; }
73 const wxColour
& GetForegroundColour() const { return m_foregroundColour
; }
74 const wxFont
& GetFont() const { return m_font
; }
76 void SetBackgroundColour(const wxColour
& colour
);
77 void SetForegroundColour(const wxColour
& colour
);
78 void SetFont(const wxFont
& colour
);
79 void ChangeFont(bool keepOriginalSize
= false);
81 WXWidget
GetHandle() const { return m_menuWidget
; }
83 bool IsTearOff() const { return (m_style
& wxMENU_TEAROFF
) != 0; }
85 void DestroyWidgetAndDetach();
87 // Motif-specific data
89 WXWidget m_menuWidget
;
90 WXWidget m_popupShell
; // For holding the popup shell widget
91 WXWidget m_buttonWidget
; // The actual string, so we can grey it etc.
93 wxMenu
* m_topLevelMenu
;
94 bool m_ownedByMenuBar
;
95 wxColour m_foregroundColour
;
96 wxColour m_backgroundColour
;
100 // common code for both constructors:
103 DECLARE_DYNAMIC_CLASS(wxMenu
)
106 // ----------------------------------------------------------------------------
108 // ----------------------------------------------------------------------------
110 class WXDLLIMPEXP_CORE wxMenuBar
: public wxMenuBarBase
113 wxMenuBar() { Init(); }
114 wxMenuBar(long WXUNUSED(style
)) { Init(); }
115 wxMenuBar(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
= 0);
116 wxMenuBar(size_t n
, wxMenu
*menus
[], const wxArrayString
& titles
, long style
= 0);
117 virtual ~wxMenuBar();
119 // implement base class (pure) virtuals
120 // ------------------------------------
122 virtual bool Append( wxMenu
*menu
, const wxString
&title
);
123 virtual bool Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
);
124 virtual wxMenu
*Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
);
125 virtual wxMenu
*Remove(size_t pos
);
127 virtual int FindMenuItem(const wxString
& menuString
,
128 const wxString
& itemString
) const;
129 virtual wxMenuItem
* FindItem( int id
, wxMenu
**menu
= NULL
) const;
131 virtual void EnableTop( size_t pos
, bool flag
);
132 virtual void SetMenuLabel( size_t pos
, const wxString
& label
);
133 virtual wxString
GetMenuLabel( size_t pos
) const;
135 // implementation only from now on
136 // -------------------------------
138 wxFrame
* GetMenuBarFrame() const { return m_menuBarFrame
; }
139 void SetMenuBarFrame(wxFrame
* frame
) { m_menuBarFrame
= frame
; }
140 WXWidget
GetMainWidget() const { return m_mainWidget
; }
141 void SetMainWidget(WXWidget widget
) { m_mainWidget
= widget
; }
144 bool CreateMenuBar(wxFrame
* frame
);
146 // Destroy menubar, but keep data structures intact so we can recreate it.
147 bool DestroyMenuBar();
149 const wxColour
& GetBackgroundColour() const { return m_backgroundColour
; }
150 const wxColour
& GetForegroundColour() const { return m_foregroundColour
; }
151 const wxFont
& GetFont() const { return m_font
; }
153 virtual bool SetBackgroundColour(const wxColour
& colour
);
154 virtual bool SetForegroundColour(const wxColour
& colour
);
155 virtual bool SetFont(const wxFont
& colour
);
156 void ChangeFont(bool keepOriginalSize
= false);
159 // common part of all ctors
162 wxArrayString m_titles
;
163 wxFrame
*m_menuBarFrame
;
165 WXWidget m_mainWidget
;
167 wxColour m_foregroundColour
;
168 wxColour m_backgroundColour
;
171 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
174 #endif // _WX_MOTIF_MENU_H_