]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/menu.h
decouple wxTLW,Frame::ShowFullScreen in wxMSW
[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 // deprecated functions
53 #if wxUSE_MENU_CALLBACK
54 wxMenu(const wxString& title, const wxFunction func)
55 : wxMenuBase(title)
56 {
57 Init();
58
59 Callback(func);
60 }
61 #endif // wxUSE_MENU_CALLBACK
62
63 // implementation only from now on
64 // -------------------------------
65
66 bool MSWCommand(WXUINT param, WXWORD id);
67
68 // semi-private accessors
69 // get the window which contains this menu
70 wxWindow *GetWindow() const;
71 // get the menu handle
72 WXHMENU GetHMenu() const { return m_hMenu; }
73
74 #if wxUSE_ACCEL
75 // called by wxMenuBar to build its accel table from the accels of all menus
76 bool HasAccels() const { return !m_accels.IsEmpty(); }
77 size_t GetAccelCount() const { return m_accels.GetCount(); }
78 size_t CopyAccels(wxAcceleratorEntry *accels) const;
79
80 // called by wxMenuItem when its accels changes
81 void UpdateAccel(wxMenuItem *item);
82
83 // helper used by wxMenu itself (returns the index in m_accels)
84 int FindAccel(int id) const;
85 #endif // wxUSE_ACCEL
86
87 private:
88 // common part of all ctors
89 void Init();
90
91 // common part of Append/Insert (behaves as Append is pos == (size_t)-1)
92 bool DoInsertOrAppend(wxMenuItem *item, size_t pos = (size_t)-1);
93
94 // if TRUE, insert a breal before appending the next item
95 bool m_doBreak;
96
97 // the menu handle of this menu
98 WXHMENU m_hMenu;
99
100 #if wxUSE_ACCEL
101 // the accelerators for our menu items
102 wxAcceleratorArray m_accels;
103 #endif // wxUSE_ACCEL
104
105 DECLARE_DYNAMIC_CLASS(wxMenu)
106 };
107
108 // ----------------------------------------------------------------------------
109 // Menu Bar (a la Windows)
110 // ----------------------------------------------------------------------------
111
112 class WXDLLEXPORT wxMenuBar : public wxMenuBarBase
113 {
114 public:
115 // ctors & dtor
116 // default constructor
117 wxMenuBar();
118 // unused under MSW
119 wxMenuBar(long style);
120 // menubar takes ownership of the menus arrays but copies the titles
121 wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
122 virtual ~wxMenuBar();
123
124 // menubar construction
125 virtual bool Append( wxMenu *menu, const wxString &title );
126 virtual bool Insert(size_t pos, wxMenu *menu, const wxString& title);
127 virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
128 virtual wxMenu *Remove(size_t pos);
129
130 virtual void EnableTop( size_t pos, bool flag );
131 virtual void SetLabelTop( size_t pos, const wxString& label );
132 virtual wxString GetLabelTop( size_t pos ) const;
133
134 // compatibility: these functions are deprecated
135 #if WXWIN_COMPATIBILITY
136 void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; }
137 wxEvtHandler *GetEventHandler() { return m_eventHandler; }
138
139 bool Enabled(int id) const { return IsEnabled(id); }
140 bool Checked(int id) const { return IsChecked(id); }
141 #endif // WXWIN_COMPATIBILITY
142
143 // implementation from now on
144 WXHMENU Create();
145 virtual void Detach();
146 virtual void Attach(wxFrame *frame);
147
148 #if wxUSE_ACCEL
149 // get the accel table for all the menus
150 const wxAcceleratorTable& GetAccelTable() const { return m_accelTable; }
151
152 // update the accel table (must be called after adding/deletign a menu)
153 void RebuildAccelTable();
154 #endif // wxUSE_ACCEL
155
156 // get the menu handle
157 WXHMENU GetHMenu() const { return m_hMenu; }
158
159 // if the menubar is modified, the display is not updated automatically,
160 // call this function to update it (m_menuBarFrame should be !NULL)
161 void Refresh();
162
163 protected:
164 // common part of all ctors
165 void Init();
166
167 #if WXWIN_COMPATIBILITY
168 wxEvtHandler *m_eventHandler;
169 #endif // WXWIN_COMPATIBILITY
170
171 wxArrayString m_titles;
172
173 WXHMENU m_hMenu;
174
175 #if wxUSE_ACCEL
176 // the accelerator table for all accelerators in all our menus
177 wxAcceleratorTable m_accelTable;
178 #endif // wxUSE_ACCEL
179
180 private:
181 DECLARE_DYNAMIC_CLASS(wxMenuBar)
182 };
183
184 #endif // _WX_MENU_H_