]> git.saurik.com Git - wxWidgets.git/blob - include/wx/stubs/menu.h
Rewrote wxNotebook, incl. PAGE_CHANGING event
[wxWidgets.git] / include / wx / stubs / menu.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: menu.h
3 // Purpose: wxMenu, wxMenuBar classes
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
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"
21
22 class WXDLLEXPORT wxMenuItem;
23 class WXDLLEXPORT wxMenuBar;
24 class WXDLLEXPORT wxMenu;
25
26 WXDLLEXPORT_DATA(extern const char*) wxEmptyString;
27
28 // ----------------------------------------------------------------------------
29 // Menu
30 // ----------------------------------------------------------------------------
31 class WXDLLEXPORT wxMenu: public wxEvtHandler
32 {
33 DECLARE_DYNAMIC_CLASS(wxMenu)
34
35 public:
36 // ctor & dtor
37 wxMenu(const wxString& title = wxEmptyString, const wxFunction func = NULL);
38 ~wxMenu();
39
40 // construct menu
41 // append items to the menu
42 // separator line
43 void AppendSeparator();
44 // normal item
45 void Append(int id, const wxString& Label, const wxString& helpString = wxEmptyString,
46 bool checkable = FALSE);
47 // a submenu
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
53 void Break();
54 // delete an item
55 void Delete(int id);
56
57 // menu item control
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); };
64
65 // Client data
66 inline void SetClientData(void* clientData) { m_clientData = clientData; }
67 inline void* GetClientData() const { return m_clientData; }
68
69 void SetInvokingWindow(wxWindow *pWin) { m_pInvokingWindow = pWin; }
70 wxWindow *GetInvokingWindow() const { return m_pInvokingWindow; }
71
72 // item properties
73 // title
74 void SetTitle(const wxString& label);
75 const wxString GetTitle() const;
76 // label
77 void SetLabel(int id, const wxString& label);
78 wxString GetLabel(int id) const;
79 // help string
80 virtual void SetHelpString(int id, const wxString& helpString);
81 virtual wxString GetHelpString(int id) const ;
82
83 // find item
84 // Finds the item id matching the given string, -1 if not found.
85 virtual int FindItem(const wxString& itemString) const ;
86 // Find wxMenuItem by ID, and item's menu too if itemMenu is !NULL.
87 wxMenuItem *FindItemForId(int itemId, wxMenu **itemMenu = NULL) const;
88
89 void ProcessCommand(wxCommandEvent& event);
90 inline void Callback(const wxFunction func) { m_callback = func; }
91
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
98 virtual void SetParent(wxEvtHandler *parent) { m_parent = parent; }
99 inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
100 inline wxEvtHandler *GetEventHandler() { return m_eventHandler; }
101
102 inline wxList& GetItems() const { return (wxList&) m_menuItems; }
103
104 public:
105 wxFunction m_callback;
106
107 int m_noItems;
108 wxString m_title;
109 wxMenuBar * m_menuBar;
110 wxList m_menuItems;
111 wxEvtHandler * m_parent;
112 wxEvtHandler * m_eventHandler;
113 void* m_clientData;
114 wxWindow* m_pInvokingWindow;
115 };
116
117 // ----------------------------------------------------------------------------
118 // Menu Bar (a la Windows)
119 // ----------------------------------------------------------------------------
120 class WXDLLEXPORT wxFrame;
121 class WXDLLEXPORT wxMenuBar: public wxEvtHandler
122 {
123 DECLARE_DYNAMIC_CLASS(wxMenuBar)
124
125 wxMenuBar();
126 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
127 ~wxMenuBar();
128
129 void Append(wxMenu *menu, const wxString& title);
130 // Must only be used AFTER menu has been attached to frame,
131 // otherwise use individual menus to enable/disable items
132 void Enable(int Id, bool Flag);
133 bool Enabled(int Id) const ;
134 inline bool IsEnabled(int Id) const { return Enabled(Id); };
135 void EnableTop(int pos, bool Flag);
136 void Check(int id, bool Flag);
137 bool Checked(int id) const ;
138 inline bool IsChecked(int Id) const { return Checked(Id); };
139 void SetLabel(int id, const wxString& label) ;
140 wxString GetLabel(int id) const ;
141 void SetLabelTop(int pos, const wxString& label) ;
142 wxString GetLabelTop(int pos) const ;
143 virtual void Delete(wxMenu *menu, int index = 0); /* Menu not destroyed */
144 virtual bool OnAppend(wxMenu *menu, const char *title);
145 virtual bool OnDelete(wxMenu *menu, int index);
146
147 virtual void SetHelpString(int Id, const wxString& helpString);
148 virtual wxString GetHelpString(int Id) const ;
149
150 virtual int FindMenuItem(const wxString& menuString, const wxString& itemString) const ;
151
152 // Find wxMenuItem for item ID, and return item's
153 // menu too if itemMenu is non-NULL.
154 wxMenuItem *FindItemForId(int itemId, wxMenu **menuForItem = NULL) const ;
155
156 inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
157 inline wxEvtHandler *GetEventHandler() { return m_eventHandler; }
158
159 inline int GetMenuCount() const { return m_menuCount; }
160 inline wxMenu* GetMenu(int i) const { return m_menus[i]; }
161
162 public:
163 wxEvtHandler * m_eventHandler;
164 int m_menuCount;
165 wxMenu ** m_menus;
166 wxString * m_titles;
167 wxFrame * m_menuBarFrame;
168 /* TODO: data that represents the actual menubar when created.
169 */
170 };
171
172 #endif // _WX_MENU_H_