]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: menu.h | |
3 | // Purpose: wxMenu, wxMenuBar classes | |
75f11ad7 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
75f11ad7 | 6 | // Created: 10/10/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
75f11ad7 DW |
8 | // Copyright: (c) David Webster |
9 | // Licence: wxWindows licence | |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_MENU_H_ | |
13 | #define _WX_MENU_H_ | |
14 | ||
75f11ad7 | 15 | #if wxUSE_ACCEL |
e92f266c DW |
16 | #include "wx/accel.h" |
17 | #include "wx/dynarray.h" | |
18 | ||
19 | WX_DEFINE_EXPORTED_ARRAY(wxAcceleratorEntry *, wxAcceleratorArray); | |
75f11ad7 | 20 | #endif // wxUSE_ACCEL |
0e320a79 | 21 | |
75f11ad7 | 22 | class WXDLLEXPORT wxFrame; |
0e320a79 | 23 | |
0e320a79 DW |
24 | // ---------------------------------------------------------------------------- |
25 | // Menu | |
26 | // ---------------------------------------------------------------------------- | |
0e320a79 | 27 | |
e92f266c DW |
28 | class WXDLLEXPORT wxMenu : public wxMenuBase |
29 | { | |
0e320a79 | 30 | public: |
e92f266c DW |
31 | // ctors & dtor |
32 | wxMenu(const wxString& title, long style = 0) | |
33 | : wxMenuBase(title, style) { Init(); } | |
75f11ad7 | 34 | |
e92f266c | 35 | wxMenu(long style = 0) : wxMenuBase(style) { Init(); } |
75f11ad7 DW |
36 | |
37 | virtual ~wxMenu(); | |
38 | ||
e92f266c DW |
39 | // implement base class virtuals |
40 | virtual bool DoAppend(wxMenuItem *item); | |
41 | virtual bool DoInsert(size_t pos, wxMenuItem *item); | |
42 | virtual wxMenuItem *DoRemove(wxMenuItem *item); | |
43 | ||
44 | virtual void Break(); | |
45 | ||
46 | virtual void SetTitle(const wxString& title); | |
75f11ad7 | 47 | |
e92f266c | 48 | // OS2-specific |
75f11ad7 DW |
49 | bool ProcessCommand(wxCommandEvent& event); |
50 | ||
e92f266c DW |
51 | #if WXWIN_COMPATIBILITY |
52 | wxMenu(const wxString& title, const wxFunction func) | |
53 | : wxMenuBase(title) | |
54 | { | |
55 | Callback(func); | |
56 | } | |
57 | #endif // WXWIN_COMPATIBILITY | |
58 | ||
59 | // implementation only from now on | |
60 | // ------------------------------- | |
75f11ad7 | 61 | |
75f11ad7 DW |
62 | bool OS2Command(WXUINT param, WXWORD id); |
63 | ||
75f11ad7 DW |
64 | // semi-private accessors |
65 | // get the window which contains this menu | |
66 | wxWindow *GetWindow() const; | |
67 | // get the menu handle | |
e92f266c | 68 | WXHMENU GetHMenu() const { return m_hMenu; } |
75f11ad7 | 69 | |
e92f266c | 70 | // attach/detach menu to/from wxMenuBar |
75f11ad7 DW |
71 | void Attach(wxMenuBar *menubar); |
72 | void Detach(); | |
73 | ||
74 | #if wxUSE_ACCEL | |
e92f266c DW |
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(); } | |
75f11ad7 | 78 | size_t CopyAccels(wxAcceleratorEntry *accels) const; |
75f11ad7 | 79 | |
e92f266c DW |
80 | // called by wxMenuItem when its accels changes |
81 | void UpdateAccel(wxMenuItem *item); | |
75f11ad7 | 82 | |
e92f266c DW |
83 | // helper used by wxMenu itself (returns the index in m_accels) |
84 | int FindAccel(int id) const; | |
85 | #endif // wxUSE_ACCEL | |
75f11ad7 DW |
86 | |
87 | private: | |
88 | // common part of all ctors | |
e92f266c DW |
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; | |
75f11ad7 DW |
99 | |
100 | #if wxUSE_ACCEL | |
e92f266c DW |
101 | // the accelerators for our menu items |
102 | wxAcceleratorArray m_accels; | |
75f11ad7 | 103 | #endif // wxUSE_ACCEL |
e92f266c DW |
104 | |
105 | DECLARE_DYNAMIC_CLASS(wxMenu) | |
0e320a79 DW |
106 | }; |
107 | ||
108 | // ---------------------------------------------------------------------------- | |
109 | // Menu Bar (a la Windows) | |
110 | // ---------------------------------------------------------------------------- | |
75f11ad7 | 111 | |
e92f266c | 112 | class WXDLLEXPORT wxMenuBar : public wxMenuBarBase |
0e320a79 | 113 | { |
75f11ad7 DW |
114 | public: |
115 | // ctors & dtor | |
116 | // default constructor | |
117 | wxMenuBar(); | |
e92f266c | 118 | // unused under OS2 |
75f11ad7 DW |
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 | |
e92f266c DW |
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 | ||
75f11ad7 DW |
130 | virtual int FindMenuItem(const wxString& menuString, |
131 | const wxString& itemString) const; | |
e92f266c | 132 | virtual wxMenuItem* FindItem( int id, wxMenu **menu = NULL ) const; |
75f11ad7 | 133 | |
e92f266c DW |
134 | virtual void EnableTop( size_t pos, bool flag ); |
135 | virtual void SetLabelTop( size_t pos, const wxString& label ); | |
136 | virtual wxString GetLabelTop( size_t pos ) const; | |
75f11ad7 | 137 | |
75f11ad7 | 138 | // compatibility: these functions are deprecated |
e92f266c DW |
139 | #if WXWIN_COMPATIBILITY |
140 | void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; } | |
141 | wxEvtHandler *GetEventHandler() { return m_eventHandler; } | |
142 | ||
143 | bool Enabled(int id) const { return IsEnabled(id); } | |
144 | bool Checked(int id) const { return IsChecked(id); } | |
75f11ad7 DW |
145 | #endif // WXWIN_COMPATIBILITY |
146 | ||
e92f266c DW |
147 | // implementation from now on |
148 | WXHMENU Create(); | |
149 | int FindMenu(const wxString& title); | |
150 | void Detach(); | |
151 | ||
75f11ad7 | 152 | // returns TRUE if we're attached to a frame |
e92f266c | 153 | bool IsAttached() const { return m_menuBarFrame != NULL; } |
75f11ad7 | 154 | // get the frame we live in |
e92f266c | 155 | wxFrame *GetFrame() const { return m_menuBarFrame; } |
75f11ad7 DW |
156 | // attach to a frame |
157 | void Attach(wxFrame *frame); | |
158 | ||
159 | #if wxUSE_ACCEL | |
e92f266c DW |
160 | // get the accel table for all the menus |
161 | const wxAcceleratorTable& GetAccelTable() const { return m_accelTable; } | |
162 | ||
163 | // update the accel table (must be called after adding/deletign a menu) | |
164 | void RebuildAccelTable(); | |
75f11ad7 DW |
165 | #endif // wxUSE_ACCEL |
166 | ||
167 | // get the menu handle | |
e92f266c | 168 | WXHMENU GetHMenu() const { return m_hMenu; } |
75f11ad7 DW |
169 | |
170 | // if the menubar is modified, the display is not updated automatically, | |
171 | // call this function to update it (m_menuBarFrame should be !NULL) | |
e92f266c DW |
172 | void Refresh( bool eraseBackground = TRUE |
173 | ,const wxRect *rect = (const wxRect *) NULL | |
174 | ); | |
75f11ad7 DW |
175 | |
176 | protected: | |
177 | // common part of all ctors | |
178 | void Init(); | |
179 | ||
e92f266c | 180 | #if WXWIN_COMPATIBILITY |
75f11ad7 | 181 | wxEvtHandler *m_eventHandler; |
e92f266c DW |
182 | #endif // WXWIN_COMPATIBILITY |
183 | ||
184 | wxArrayString m_titles; | |
185 | ||
75f11ad7 DW |
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 | |
e92f266c DW |
193 | |
194 | private: | |
195 | DECLARE_DYNAMIC_CLASS(wxMenuBar) | |
0e320a79 DW |
196 | }; |
197 | ||
198 | #endif // _WX_MENU_H_ |