]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/menu.h
Added CTRL-TAB navigation to notebook
[wxWidgets.git] / include / wx / msw / menu.h
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: menu.h
3// Purpose: wxMenu, wxMenuBar classes
4// Author: Julian Smart
5// Modified by: Vadim Zeitlin (wxMenuItem is now in separate file)
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
a3622daa 9// Licence: wxWindows license
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
bbcdf8bc
JS
12#ifndef _WX_MENU_H_
13#define _WX_MENU_H_
2bda0e17
KB
14
15#ifdef __GNUG__
16#pragma interface "menu.h"
17#endif
18
19#include "wx/defs.h"
20#include "wx/event.h"
21
bbcdf8bc
JS
22class WXDLLEXPORT wxMenuItem;
23class WXDLLEXPORT wxMenuBar;
24class WXDLLEXPORT wxMenu;
2bda0e17
KB
25
26WXDLLEXPORT_DATA(extern const char*) wxEmptyString;
27
28// ----------------------------------------------------------------------------
29// Menu
30// ----------------------------------------------------------------------------
31class WXDLLEXPORT wxMenu: public wxEvtHandler
32{
33 DECLARE_DYNAMIC_CLASS(wxMenu)
34
35public:
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
b5279053 48 void Append(int id, const wxString& Label, wxMenu *SubMenu,
2bda0e17
KB
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); /* If it's a submenu, menu is not destroyed. VZ: why? */
56
3dd4e4e0
JS
57 // Client data
58 inline void SetClientData(void* clientData) { m_clientData = clientData; }
59 inline void* GetClientData() const { return m_clientData; }
60
2bda0e17
KB
61 // menu item control
62 void Enable(int id, bool Flag);
63 bool Enabled(int id) const;
64 inline bool IsEnabled(int id) const { return Enabled(id); };
65 void Check(int id, bool Flag);
66 bool Checked(int id) const;
a3622daa 67 inline bool IsChecked(int id) const { return Checked(id); };
2bda0e17
KB
68
69 // item properties
70 // title
71 void SetTitle(const wxString& label);
f7387de5 72 const wxString GetTitle() const;
2bda0e17
KB
73 // label
74 void SetLabel(int id, const wxString& label);
75 wxString GetLabel(int id) const;
76 // help string
debe6624
JS
77 virtual void SetHelpString(int id, const wxString& helpString);
78 virtual wxString GetHelpString(int id) const ;
2bda0e17
KB
79
80 // find item
3c67202d 81 // Finds the item id matching the given string, wxNOT_FOUND if not found.
2bda0e17
KB
82 virtual int FindItem(const wxString& itemString) const ;
83 // Find wxMenuItem by ID, and item's menu too if itemMenu is !NULL.
debe6624 84 wxMenuItem *FindItemForId(int itemId, wxMenu **itemMenu = NULL) const;
2bda0e17 85
631f1bfe
JS
86 // Updates the UI for a menu and all submenus recursively.
87 // source is the object that has the update event handlers
88 // defined for it. If NULL, the menu or associated window
89 // will be used.
90 void UpdateUI(wxEvtHandler* source = (wxEvtHandler*) NULL);
91
2bda0e17
KB
92 void ProcessCommand(wxCommandEvent& event);
93 inline void Callback(const wxFunction func) { m_callback = func; }
94
95 virtual void SetParent(wxEvtHandler *parent) { m_parent = parent; }
96 inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
a3622daa 97 inline wxEvtHandler *GetEventHandler() { return m_eventHandler; }
2bda0e17 98
527fc629
JS
99 inline wxList& GetItems() const { return (wxList&) m_menuItems; }
100
2bda0e17 101 // IMPLEMENTATION
debe6624 102 bool MSWCommand(WXUINT param, WXWORD id);
2bda0e17
KB
103
104 void SetInvokingWindow(wxWindow *pWin) { m_pInvokingWindow = pWin; }
105 wxWindow *GetInvokingWindow() const { return m_pInvokingWindow; }
106
107 // semi-private accessors
108 // get the window which contains this menu
109 wxWindow *GetWindow() const;
110 // get the menu handle
111 WXHMENU GetHMenu() const;
112
113private:
114 bool m_doBreak ;
115
116public:
117 // This is used when m_hMenu is NULL because we don't want to
118 // delete it in ~wxMenu (it's been added to a parent menu).
119 // But we'll still need the handle for other purposes.
120 // Might be better to have a flag saying whether it's deleteable or not.
121 WXHMENU m_savehMenu ; // Used for Enable() on popup
122 WXHMENU m_hMenu;
123 wxFunction m_callback;
124
125 int m_noItems;
126 wxString m_title;
127 wxMenu * m_topLevelMenu;
128 wxMenuBar * m_menuBar;
129 wxList m_menuItems;
130 wxEvtHandler * m_parent;
131 wxEvtHandler * m_eventHandler;
132 wxWindow *m_pInvokingWindow;
3dd4e4e0 133 void* m_clientData;
2bda0e17
KB
134};
135
136// ----------------------------------------------------------------------------
137// Menu Bar (a la Windows)
138// ----------------------------------------------------------------------------
bbcdf8bc 139class WXDLLEXPORT wxFrame;
2bda0e17
KB
140class WXDLLEXPORT wxMenuBar: public wxEvtHandler
141{
142 DECLARE_DYNAMIC_CLASS(wxMenuBar)
143
a3622daa
VZ
144public:
145 wxMenuBar();
debe6624 146 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
a3622daa 147 ~wxMenuBar();
2bda0e17
KB
148
149 void Append(wxMenu *menu, const wxString& title);
150 // Must only be used AFTER menu has been attached to frame,
151 // otherwise use individual menus to enable/disable items
debe6624
JS
152 void Enable(int Id, bool Flag);
153 bool Enabled(int Id) const ;
154 inline bool IsEnabled(int Id) const { return Enabled(Id); };
155 void EnableTop(int pos, bool Flag);
156 void Check(int id, bool Flag);
157 bool Checked(int id) const ;
158 inline bool IsChecked(int Id) const { return Checked(Id); };
159 void SetLabel(int id, const wxString& label) ;
160 wxString GetLabel(int id) const ;
161 void SetLabelTop(int pos, const wxString& label) ;
162 wxString GetLabelTop(int pos) const ;
163 virtual void Delete(wxMenu *menu, int index = 0); /* Menu not destroyed */
2bda0e17 164 virtual bool OnAppend(wxMenu *menu, const char *title);
debe6624 165 virtual bool OnDelete(wxMenu *menu, int index);
2bda0e17 166
debe6624
JS
167 virtual void SetHelpString(int Id, const wxString& helpString);
168 virtual wxString GetHelpString(int Id) const ;
2bda0e17
KB
169
170 virtual int FindMenuItem(const wxString& menuString, const wxString& itemString) const ;
171
172 // Find wxMenuItem for item ID, and return item's
173 // menu too if itemMenu is non-NULL.
debe6624 174 wxMenuItem *FindItemForId(int itemId, wxMenu **menuForItem = NULL) const ;
2bda0e17
KB
175
176 inline void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
a3622daa 177 inline wxEvtHandler *GetEventHandler() { return m_eventHandler; }
2bda0e17 178
527fc629
JS
179 inline int GetMenuCount() const { return m_menuCount; }
180 inline wxMenu* GetMenu(int i) const { return m_menus[i]; }
181
2bda0e17
KB
182 public:
183 wxEvtHandler * m_eventHandler;
184 int m_menuCount;
185 wxMenu ** m_menus;
186 wxString * m_titles;
187 wxFrame * m_menuBarFrame;
188 WXHMENU m_hMenu;
189};
190
bbcdf8bc 191#endif // _WX_MENU_H_