]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/menu.h
Watcom C++ fixup in tbar95.cpp; removed WXWIN_COMPATIBILITY for 'old' menu
[wxWidgets.git] / include / wx / msw / menu.h
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
9 // Licence: wxWindows license
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 #if wxUSE_ACCEL
20 #include "wx/accel.h"
21 #include "wx/dynarray.h"
22
23 WX_DEFINE_EXPORTED_ARRAY(wxAcceleratorEntry *, wxAcceleratorArray);
24 #endif // wxUSE_ACCEL
25
26 class WXDLLEXPORT wxFrame;
27
28 // ----------------------------------------------------------------------------
29 // Menu
30 // ----------------------------------------------------------------------------
31
32 class WXDLLEXPORT wxMenu : public wxMenuBase
33 {
34 public:
35 // ctors & dtor
36 wxMenu(const wxString& title, long style = 0)
37 : wxMenuBase(title, style) { Init(); }
38
39 wxMenu(long style = 0) : wxMenuBase(style) { Init(); }
40
41 virtual ~wxMenu();
42
43 // implement base class virtuals
44 virtual bool DoAppend(wxMenuItem *item);
45 virtual bool DoInsert(size_t pos, wxMenuItem *item);
46 virtual wxMenuItem *DoRemove(wxMenuItem *item);
47
48 virtual void Break();
49
50 virtual void SetTitle(const wxString& title);
51
52 // MSW-specific
53 bool ProcessCommand(wxCommandEvent& event);
54
55 wxMenu(const wxString& title, const wxFunction func)
56 : wxMenuBase(title)
57 {
58 Callback(func);
59 }
60
61 // implementation only from now on
62 // -------------------------------
63
64 bool MSWCommand(WXUINT param, WXWORD id);
65
66 // semi-private accessors
67 // get the window which contains this menu
68 wxWindow *GetWindow() const;
69 // get the menu handle
70 WXHMENU GetHMenu() const { return m_hMenu; }
71
72 // attach/detach menu to/from wxMenuBar
73 void Attach(wxMenuBar *menubar);
74 void Detach();
75
76 #if wxUSE_ACCEL
77 // called by wxMenuBar to build its accel table from the accels of all menus
78 bool HasAccels() const { return !m_accels.IsEmpty(); }
79 size_t GetAccelCount() const { return m_accels.GetCount(); }
80 size_t CopyAccels(wxAcceleratorEntry *accels) const;
81
82 // called by wxMenuItem when its accels changes
83 void UpdateAccel(wxMenuItem *item);
84
85 // helper used by wxMenu itself (returns the index in m_accels)
86 int FindAccel(int id) const;
87 #endif // wxUSE_ACCEL
88
89 private:
90 // common part of all ctors
91 void Init();
92
93 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
94 bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1);
95
96 // if TRUE, insert a breal before appending the next item
97 bool m_doBreak;
98
99 // the menu handle of this menu
100 WXHMENU m_hMenu;
101
102 #if wxUSE_ACCEL
103 // the accelerators for our menu items
104 wxAcceleratorArray m_accels;
105 #endif // wxUSE_ACCEL
106
107 DECLARE_DYNAMIC_CLASS(wxMenu)
108 };
109
110 // ----------------------------------------------------------------------------
111 // Menu Bar (a la Windows)
112 // ----------------------------------------------------------------------------
113
114 class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
115 {
116 public:
117 // ctors & dtor
118 // default constructor
119 wxMenuBar();
120 // unused under MSW
121 wxMenuBar(long style);
122 // menubar takes ownership of the menus arrays but copies the titles
123 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
124 virtual ~wxMenuBar();
125
126 // menubar construction
127 virtual bool Append( wxMenu *menu, const wxString &title );
128 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
129 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
130 virtual wxMenu *Remove(size_t pos);
131
132 virtual int FindMenuItem(const wxString& menuString,
133 const wxString& itemString) const;
134 virtual wxMenuItem* FindItem( int id, wxMenu **menu = NULL ) const;
135
136 virtual void EnableTop( size_t pos, bool flag );
137 virtual void SetLabelTop( size_t pos, const wxString& label );
138 virtual wxString GetLabelTop( size_t pos ) const;
139
140 // compatibility: these functions are deprecated
141 #if WXWIN_COMPATIBILITY
142 void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
143 wxEvtHandler *GetEventHandler() { return m_eventHandler; }
144
145 bool Enabled(int id) const { return IsEnabled(id); }
146 bool Checked(int id) const { return IsChecked(id); }
147 #endif // WXWIN_COMPATIBILITY
148
149 // implementation from now on
150 WXHMENU Create();
151 int FindMenu(const wxString& title);
152 void Detach();
153
154 // returns TRUE if we're attached to a frame
155 bool IsAttached() const { return m_menuBarFrame != NULL; }
156 // get the frame we live in
157 wxFrame *GetFrame() const { return m_menuBarFrame; }
158 // attach to a frame
159 void Attach(wxFrame *frame);
160
161 #if wxUSE_ACCEL
162 // get the accel table for all the menus
163 const wxAcceleratorTable& GetAccelTable() const { return m_accelTable; }
164
165 // update the accel table (must be called after adding/deletign a menu)
166 void RebuildAccelTable();
167 #endif // wxUSE_ACCEL
168
169 // get the menu handle
170 WXHMENU GetHMenu() const { return m_hMenu; }
171
172 // if the menubar is modified, the display is not updated automatically,
173 // call this function to update it (m_menuBarFrame should be !NULL)
174 void Refresh();
175
176 protected:
177 // common part of all ctors
178 void Init();
179
180 #if WXWIN_COMPATIBILITY
181 wxEvtHandler *m_eventHandler;
182 #endif // WXWIN_COMPATIBILITY
183
184 wxArrayString m_titles;
185
186 wxFrame *m_menuBarFrame;
187 WXHMENU m_hMenu;
188
189 #if wxUSE_ACCEL
190 // the accelerator table for all accelerators in all our menus
191 wxAcceleratorTable m_accelTable;
192 #endif // wxUSE_ACCEL
193
194 private:
195 DECLARE_DYNAMIC_CLASS(wxMenuBar)
196 };
197
198 #endif // _WX_MENU_H_