]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/motif/menu.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenu, wxMenuBar classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "menu.h"
22 class WXDLLEXPORT wxMenuItem
;
23 class WXDLLEXPORT wxMenuBar
;
24 class WXDLLEXPORT wxMenu
;
26 WXDLLEXPORT_DATA(extern const char*) wxEmptyString
;
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
31 class WXDLLEXPORT wxMenu
: public wxEvtHandler
33 DECLARE_DYNAMIC_CLASS(wxMenu
)
37 wxMenu(const wxString
& title
= wxEmptyString
, const wxFunction func
= NULL
);
41 // append items to the menu
43 void AppendSeparator();
45 void Append(int id
, const wxString
& Label
, const wxString
& helpString
= wxEmptyString
,
46 bool checkable
= FALSE
);
48 void Append(int id
, const wxString
& Label
, wxMenu
*SubMenu
,
49 const wxString
& helpString
= wxEmptyString
);
50 // the most generic form (create wxMenuItem first and use it's functions)
51 void Append(wxMenuItem
*pItem
);
52 // insert a break in the menu
58 void Enable(int id
, bool Flag
);
59 bool Enabled(int id
) const;
60 inline bool IsEnabled(int id
) const { return Enabled(id
); };
61 void Check(int id
, bool Flag
);
62 bool Checked(int id
) const;
63 inline bool IsChecked(int id
) const { return IsChecked(id
); };
67 void SetTitle(const wxString
& label
);
68 const wxString
GetTitle() const;
70 void SetLabel(int id
, const wxString
& label
);
71 wxString
GetLabel(int id
) const;
73 virtual void SetHelpString(int id
, const wxString
& helpString
);
74 virtual wxString
GetHelpString(int id
) const ;
77 // Finds the item id matching the given string, -1 if not found.
78 virtual int FindItem(const wxString
& itemString
) const ;
79 // Find wxMenuItem by ID, and item's menu too if itemMenu is !NULL.
80 wxMenuItem
*FindItemForId(int itemId
, wxMenu
**itemMenu
= NULL
) const;
82 void ProcessCommand(wxCommandEvent
& event
);
83 inline void Callback(const wxFunction func
) { m_callback
= func
; }
85 virtual void SetParent(wxEvtHandler
*parent
) { m_parent
= parent
; }
86 inline void SetEventHandler(wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
87 inline wxEvtHandler
*GetEventHandler() { return m_eventHandler
; }
89 inline wxList
& GetItems() const { return (wxList
&) m_menuItems
; }
92 inline WXWidget
GetButtonWidget() const { return m_buttonWidget
; }
93 inline void SetButtonWidget(WXWidget buttonWidget
) { m_buttonWidget
= buttonWidget
; }
94 inline WXWidget
GetMainWidget() const { return m_menuWidget
; }
95 inline wxMenu
* GetParent() const { return m_menuParent
; }
96 inline int GetId() const { return m_menuId
; }
97 inline void SetId(int id
) { m_menuId
= id
; }
98 inline void SetMenuBar(wxMenuBar
* menuBar
) { m_menuBar
= menuBar
; }
99 inline wxMenuBar
* GetMenuBar() const { return m_menuBar
; }
101 void CreatePopup (WXWidget logicalParent
, int x
, int y
);
102 void DestroyPopup (void);
103 void ShowPopup (int x
, int y
);
104 void HidePopup (void);
106 WXWidget
CreateMenu(wxMenuBar
*menuBar
, WXWidget parent
, wxMenu
*topMenu
,
107 const wxString
& title
= "", bool isPulldown
= FALSE
);
109 // For popups, need to destroy, then recreate menu for a different (or
110 // possibly same) window, since the parent may change.
111 void DestroyMenu(bool full
);
112 WXWidget
FindMenuItem(int id
, wxMenuItem
**it
= NULL
) const;
115 wxFunction m_callback
;
119 wxMenuBar
* m_menuBar
;
121 wxEvtHandler
* m_parent
;
122 wxEvtHandler
* m_eventHandler
;
126 WXWidget m_menuWidget
;
127 WXWidget m_popupShell
; // For holding the popup shell widget
128 WXWidget m_buttonWidget
; // The actual string, so we can grey it etc.
130 wxMenu
* m_topLevelMenu
;
131 wxMenu
* m_menuParent
;
132 bool m_ownedByMenuBar
;
135 // ----------------------------------------------------------------------------
136 // Menu Bar (a la Windows)
137 // ----------------------------------------------------------------------------
138 class WXDLLEXPORT wxFrame
;
139 class WXDLLEXPORT wxMenuBar
: public wxEvtHandler
141 DECLARE_DYNAMIC_CLASS(wxMenuBar
)
144 wxMenuBar(int n
, wxMenu
*menus
[], const wxString titles
[]);
147 void Append(wxMenu
*menu
, const wxString
& title
);
148 // Must only be used AFTER menu has been attached to frame,
149 // otherwise use individual menus to enable/disable items
150 void Enable(int Id
, bool Flag
);
151 bool Enabled(int Id
) const ;
152 inline bool IsEnabled(int Id
) const { return Enabled(Id
); };
153 void EnableTop(int pos
, bool Flag
);
154 void Check(int id
, bool Flag
);
155 bool Checked(int id
) const ;
156 inline bool IsChecked(int Id
) const { return Checked(Id
); };
157 void SetLabel(int id
, const wxString
& label
) ;
158 wxString
GetLabel(int id
) const ;
159 void SetLabelTop(int pos
, const wxString
& label
) ;
160 wxString
GetLabelTop(int pos
) const ;
161 virtual void Delete(wxMenu
*menu
, int index
= 0); /* Menu not destroyed */
162 virtual bool OnAppend(wxMenu
*menu
, const char *title
);
163 virtual bool OnDelete(wxMenu
*menu
, int index
);
165 virtual void SetHelpString(int Id
, const wxString
& helpString
);
166 virtual wxString
GetHelpString(int Id
) const ;
168 virtual int FindMenuItem(const wxString
& menuString
, const wxString
& itemString
) const ;
170 // Find wxMenuItem for item ID, and return item's
171 // menu too if itemMenu is non-NULL.
172 wxMenuItem
*FindItemForId(int itemId
, wxMenu
**menuForItem
= NULL
) const ;
174 inline void SetEventHandler(wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
175 inline wxEvtHandler
*GetEventHandler() { return m_eventHandler
; }
177 inline int GetMenuCount() const { return m_menuCount
; }
178 inline wxMenu
* GetMenu(int i
) const { return m_menus
[i
]; }
181 inline wxFrame
* GetMenuBarFrame() const { return m_menuBarFrame
; }
182 inline void SetMenuBarFrame(wxFrame
* frame
) { m_menuBarFrame
= frame
; }
183 inline WXWidget
GetMainWidget() const { return m_mainWidget
; }
184 inline void SetMainWidget(WXWidget widget
) { m_mainWidget
= widget
; }
187 wxEvtHandler
* m_eventHandler
;
191 wxFrame
* m_menuBarFrame
;
194 WXWidget m_mainWidget
;
198 #endif // _WX_MENU_H_