]>
Commit | Line | Data |
---|---|---|
63fec618 | 1 | ///////////////////////////////////////////////////////////////////////////// |
76b49cf4 | 2 | // Name: src/common/framecmn.cpp |
63fec618 VZ |
3 | // Purpose: common (for all platforms) wxFrame functions |
4 | // Author: Julian Smart, Vadim Zeitlin | |
5 | // Created: 01/02/97 | |
439b3bf1 | 6 | // Id: $Id$ |
55d99c7a | 7 | // Copyright: (c) 1998 Robert Roebling and Julian Smart |
65571936 | 8 | // Licence: wxWindows licence |
63fec618 VZ |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
7c0ea335 VZ |
11 | // ============================================================================ |
12 | // declarations | |
13 | // ============================================================================ | |
14 | ||
15 | // ---------------------------------------------------------------------------- | |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
f701d7ab JS |
19 | // For compilers that support precompilation, includes "wx.h". |
20 | #include "wx/wxprec.h" | |
21 | ||
22 | #ifdef __BORLANDC__ | |
7c0ea335 | 23 | #pragma hdrstop |
f701d7ab JS |
24 | #endif |
25 | ||
76b49cf4 WS |
26 | #include "wx/frame.h" |
27 | ||
1e6feb95 | 28 | #ifndef WX_PRECOMP |
1e6feb95 VZ |
29 | #include "wx/menu.h" |
30 | #include "wx/menuitem.h" | |
31 | #include "wx/dcclient.h" | |
4e3e485b | 32 | #include "wx/toolbar.h" |
7c0ea335 | 33 | #include "wx/statusbr.h" |
3304646d | 34 | #endif // WX_PRECOMP |
7c0ea335 VZ |
35 | |
36 | // ---------------------------------------------------------------------------- | |
37 | // event table | |
38 | // ---------------------------------------------------------------------------- | |
39 | ||
96ac065f VZ |
40 | #if wxUSE_MENUS && wxUSE_STATUSBAR |
41 | ||
7d9f12f3 | 42 | BEGIN_EVENT_TABLE(wxFrameBase, wxTopLevelWindow) |
0b30bb0b | 43 | EVT_MENU_OPEN(wxFrameBase::OnMenuOpen) |
96ac065f VZ |
44 | EVT_MENU_CLOSE(wxFrameBase::OnMenuClose) |
45 | ||
7c0ea335 | 46 | EVT_MENU_HIGHLIGHT_ALL(wxFrameBase::OnMenuHighlight) |
7c0ea335 VZ |
47 | END_EVENT_TABLE() |
48 | ||
96ac065f VZ |
49 | #endif // wxUSE_MENUS && wxUSE_STATUSBAR |
50 | ||
7c0ea335 VZ |
51 | // ============================================================================ |
52 | // implementation | |
53 | // ============================================================================ | |
54 | ||
55 | // ---------------------------------------------------------------------------- | |
56 | // construction/destruction | |
57 | // ---------------------------------------------------------------------------- | |
58 | ||
59 | wxFrameBase::wxFrameBase() | |
60 | { | |
1e6feb95 | 61 | #if wxUSE_MENUS |
7c0ea335 | 62 | m_frameMenuBar = NULL; |
1e6feb95 | 63 | #endif // wxUSE_MENUS |
7c0ea335 VZ |
64 | |
65 | #if wxUSE_TOOLBAR | |
66 | m_frameToolBar = NULL; | |
67 | #endif // wxUSE_TOOLBAR | |
68 | ||
69 | #if wxUSE_STATUSBAR | |
70 | m_frameStatusBar = NULL; | |
71 | #endif // wxUSE_STATUSBAR | |
1f361cdd MB |
72 | |
73 | m_statusBarPane = 0; | |
7c0ea335 VZ |
74 | } |
75 | ||
799ea011 GD |
76 | wxFrameBase::~wxFrameBase() |
77 | { | |
78 | // this destructor is required for Darwin | |
79 | } | |
80 | ||
7c0ea335 VZ |
81 | wxFrame *wxFrameBase::New(wxWindow *parent, |
82 | wxWindowID id, | |
83 | const wxString& title, | |
84 | const wxPoint& pos, | |
85 | const wxSize& size, | |
86 | long style, | |
87 | const wxString& name) | |
88 | { | |
89 | return new wxFrame(parent, id, title, pos, size, style, name); | |
90 | } | |
91 | ||
92 | void wxFrameBase::DeleteAllBars() | |
93 | { | |
1e6feb95 | 94 | #if wxUSE_MENUS |
7c0ea335 VZ |
95 | if ( m_frameMenuBar ) |
96 | { | |
97 | delete m_frameMenuBar; | |
98 | m_frameMenuBar = (wxMenuBar *) NULL; | |
99 | } | |
1e6feb95 | 100 | #endif // wxUSE_MENUS |
7c0ea335 VZ |
101 | |
102 | #if wxUSE_STATUSBAR | |
103 | if ( m_frameStatusBar ) | |
104 | { | |
105 | delete m_frameStatusBar; | |
106 | m_frameStatusBar = (wxStatusBar *) NULL; | |
107 | } | |
108 | #endif // wxUSE_STATUSBAR | |
109 | ||
110 | #if wxUSE_TOOLBAR | |
111 | if ( m_frameToolBar ) | |
112 | { | |
113 | delete m_frameToolBar; | |
114 | m_frameToolBar = (wxToolBar *) NULL; | |
115 | } | |
116 | #endif // wxUSE_TOOLBAR | |
117 | } | |
118 | ||
1e6feb95 VZ |
119 | bool wxFrameBase::IsOneOfBars(const wxWindow *win) const |
120 | { | |
121 | #if wxUSE_MENUS | |
122 | if ( win == GetMenuBar() ) | |
d1b20379 | 123 | return true; |
1e6feb95 VZ |
124 | #endif // wxUSE_MENUS |
125 | ||
126 | #if wxUSE_STATUSBAR | |
127 | if ( win == GetStatusBar() ) | |
d1b20379 | 128 | return true; |
1e6feb95 VZ |
129 | #endif // wxUSE_STATUSBAR |
130 | ||
131 | #if wxUSE_TOOLBAR | |
132 | if ( win == GetToolBar() ) | |
d1b20379 | 133 | return true; |
1e6feb95 VZ |
134 | #endif // wxUSE_TOOLBAR |
135 | ||
d1b20379 | 136 | return false; |
1e6feb95 VZ |
137 | } |
138 | ||
1c4f8f8d VZ |
139 | // ---------------------------------------------------------------------------- |
140 | // wxFrame size management: we exclude the areas taken by menu/status/toolbars | |
141 | // from the client area, so the client area is what's really available for the | |
142 | // frame contents | |
143 | // ---------------------------------------------------------------------------- | |
144 | ||
145 | // get the origin of the client area in the client coordinates | |
146 | wxPoint wxFrameBase::GetClientAreaOrigin() const | |
147 | { | |
7d9f12f3 | 148 | wxPoint pt = wxTopLevelWindow::GetClientAreaOrigin(); |
1c4f8f8d | 149 | |
a9928e9d | 150 | #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) |
d4597e13 VZ |
151 | wxToolBar *toolbar = GetToolBar(); |
152 | if ( toolbar && toolbar->IsShown() ) | |
1c4f8f8d VZ |
153 | { |
154 | int w, h; | |
d4597e13 | 155 | toolbar->GetSize(&w, &h); |
1c4f8f8d | 156 | |
d4597e13 | 157 | if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) |
1c4f8f8d VZ |
158 | { |
159 | pt.x += w; | |
160 | } | |
161 | else | |
162 | { | |
163 | pt.y += h; | |
164 | } | |
165 | } | |
166 | #endif // wxUSE_TOOLBAR | |
167 | ||
168 | return pt; | |
169 | } | |
170 | ||
2b022169 RD |
171 | |
172 | void wxFrameBase::SendSizeEvent() | |
173 | { | |
174 | wxSizeEvent event( GetSize(), GetId() ); | |
175 | event.SetEventObject( this ); | |
176 | GetEventHandler()->AddPendingEvent( event ); | |
177 | } | |
178 | ||
179 | ||
7c0ea335 VZ |
180 | // ---------------------------------------------------------------------------- |
181 | // misc | |
182 | // ---------------------------------------------------------------------------- | |
183 | ||
7c0ea335 VZ |
184 | bool wxFrameBase::ProcessCommand(int id) |
185 | { | |
1e6feb95 | 186 | #if wxUSE_MENUS |
7c0ea335 VZ |
187 | wxMenuBar *bar = GetMenuBar(); |
188 | if ( !bar ) | |
d1b20379 | 189 | return false; |
7c0ea335 | 190 | |
3ca6a5f0 BP |
191 | wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id); |
192 | commandEvent.SetEventObject(this); | |
193 | ||
7c0ea335 | 194 | wxMenuItem *item = bar->FindItem(id); |
84f7908b | 195 | if (item) |
7c0ea335 | 196 | { |
84f7908b | 197 | if (!item->IsEnabled()) |
d1b20379 | 198 | return true; |
d4597e13 | 199 | |
26c36d75 WS |
200 | if ((item->GetKind() == wxITEM_RADIO) && item->IsChecked() ) |
201 | return true; | |
202 | ||
84f7908b RR |
203 | if (item->IsCheckable()) |
204 | { | |
205 | item->Toggle(); | |
0472ece7 | 206 | |
84f7908b RR |
207 | // use the new value |
208 | commandEvent.SetInt(item->IsChecked()); | |
209 | } | |
3ca6a5f0 | 210 | } |
7c0ea335 | 211 | |
a01fe3d6 | 212 | GetEventHandler()->ProcessEvent(commandEvent); |
d1b20379 | 213 | return true; |
1e6feb95 | 214 | #else // !wxUSE_MENUS |
d1b20379 | 215 | return false; |
1e6feb95 | 216 | #endif // wxUSE_MENUS/!wxUSE_MENUS |
7c0ea335 VZ |
217 | } |
218 | ||
e39af974 JS |
219 | // Do the UI update processing for this window. This is |
220 | // provided for the application to call if it wants to | |
221 | // force a UI update, particularly for the menus and toolbar. | |
222 | void wxFrameBase::UpdateWindowUI(long flags) | |
223 | { | |
224 | wxWindowBase::UpdateWindowUI(flags); | |
a62848fd | 225 | |
e39af974 JS |
226 | #if wxUSE_TOOLBAR |
227 | if (GetToolBar()) | |
228 | GetToolBar()->UpdateWindowUI(flags); | |
229 | #endif | |
230 | ||
231 | #if wxUSE_MENUS | |
232 | if (GetMenuBar()) | |
233 | { | |
234 | if ((flags & wxUPDATE_UI_FROMIDLE) && !wxUSE_IDLEMENUUPDATES) | |
235 | { | |
236 | // If coming from an idle event, we only | |
237 | // want to update the menus if we're | |
238 | // in the wxUSE_IDLEMENUUPDATES configuration: | |
239 | // so if we're not, do nothing | |
240 | } | |
241 | else | |
242 | DoMenuUpdates(); | |
243 | } | |
96ac065f | 244 | #endif // wxUSE_MENUS |
e39af974 JS |
245 | } |
246 | ||
7c0ea335 | 247 | // ---------------------------------------------------------------------------- |
96ac065f | 248 | // event handlers for status bar updates from menus |
7c0ea335 VZ |
249 | // ---------------------------------------------------------------------------- |
250 | ||
96ac065f VZ |
251 | #if wxUSE_MENUS && wxUSE_STATUSBAR |
252 | ||
7c0ea335 VZ |
253 | void wxFrameBase::OnMenuHighlight(wxMenuEvent& event) |
254 | { | |
255 | #if wxUSE_STATUSBAR | |
f6bcfd97 | 256 | (void)ShowMenuHelp(GetStatusBar(), event.GetMenuId()); |
7c0ea335 VZ |
257 | #endif // wxUSE_STATUSBAR |
258 | } | |
259 | ||
d1b20379 | 260 | #if !wxUSE_IDLEMENUUPDATES |
96ac065f | 261 | void wxFrameBase::OnMenuOpen(wxMenuEvent& event) |
d1b20379 DS |
262 | #else |
263 | void wxFrameBase::OnMenuOpen(wxMenuEvent& WXUNUSED(event)) | |
264 | #endif | |
96ac065f VZ |
265 | { |
266 | #if !wxUSE_IDLEMENUUPDATES | |
267 | DoMenuUpdates(event.GetMenu()); | |
268 | #endif // !wxUSE_IDLEMENUUPDATES | |
269 | } | |
270 | ||
271 | void wxFrameBase::OnMenuClose(wxMenuEvent& WXUNUSED(event)) | |
272 | { | |
273 | // do we have real status text to restore? | |
adbc621d | 274 | if ( !m_oldStatusText.empty() ) |
96ac065f VZ |
275 | { |
276 | if ( m_statusBarPane >= 0 ) | |
277 | { | |
278 | wxStatusBar *statbar = GetStatusBar(); | |
279 | if ( statbar ) | |
280 | statbar->SetStatusText(m_oldStatusText, m_statusBarPane); | |
281 | } | |
282 | ||
283 | m_oldStatusText.clear(); | |
284 | } | |
285 | } | |
286 | ||
287 | #endif // wxUSE_MENUS && wxUSE_STATUSBAR | |
288 | ||
e39af974 JS |
289 | // Implement internal behaviour (menu updating on some platforms) |
290 | void wxFrameBase::OnInternalIdle() | |
6522713c | 291 | { |
e2b6d07d | 292 | wxTopLevelWindow::OnInternalIdle(); |
a62848fd | 293 | |
0b30bb0b | 294 | #if wxUSE_MENUS && wxUSE_IDLEMENUUPDATES |
e39af974 | 295 | if (wxUpdateUIEvent::CanUpdate(this)) |
0b30bb0b JS |
296 | DoMenuUpdates(); |
297 | #endif | |
298 | } | |
299 | ||
7c0ea335 VZ |
300 | // ---------------------------------------------------------------------------- |
301 | // status bar stuff | |
302 | // ---------------------------------------------------------------------------- | |
303 | ||
304 | #if wxUSE_STATUSBAR | |
305 | ||
306 | wxStatusBar* wxFrameBase::CreateStatusBar(int number, | |
307 | long style, | |
308 | wxWindowID id, | |
309 | const wxString& name) | |
310 | { | |
311 | // the main status bar can only be created once (or else it should be | |
312 | // deleted before calling CreateStatusBar() again) | |
313 | wxCHECK_MSG( !m_frameStatusBar, (wxStatusBar *)NULL, | |
314 | wxT("recreating status bar in wxFrame") ); | |
315 | ||
a4f01f05 | 316 | SetStatusBar(OnCreateStatusBar(number, style, id, name)); |
7c0ea335 VZ |
317 | |
318 | return m_frameStatusBar; | |
319 | } | |
320 | ||
321 | wxStatusBar *wxFrameBase::OnCreateStatusBar(int number, | |
322 | long style, | |
323 | wxWindowID id, | |
324 | const wxString& name) | |
325 | { | |
ed791986 | 326 | wxStatusBar *statusBar = new wxStatusBar(this, id, style, name); |
7c0ea335 | 327 | |
7c0ea335 VZ |
328 | statusBar->SetFieldsCount(number); |
329 | ||
330 | return statusBar; | |
331 | } | |
332 | ||
333 | void wxFrameBase::SetStatusText(const wxString& text, int number) | |
334 | { | |
7c0ea335 VZ |
335 | wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set text for") ); |
336 | ||
337 | m_frameStatusBar->SetStatusText(text, number); | |
338 | } | |
339 | ||
340 | void wxFrameBase::SetStatusWidths(int n, const int widths_field[] ) | |
341 | { | |
7c0ea335 VZ |
342 | wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set widths for") ); |
343 | ||
344 | m_frameStatusBar->SetStatusWidths(n, widths_field); | |
345 | ||
346 | PositionStatusBar(); | |
347 | } | |
348 | ||
1f361cdd | 349 | void wxFrameBase::PushStatusText(const wxString& text, int number) |
f6bcfd97 | 350 | { |
1f361cdd MB |
351 | wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set text for") ); |
352 | ||
353 | m_frameStatusBar->PushStatusText(text, number); | |
354 | } | |
f6bcfd97 | 355 | |
1f361cdd MB |
356 | void wxFrameBase::PopStatusText(int number) |
357 | { | |
358 | wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set text for") ); | |
359 | ||
360 | m_frameStatusBar->PopStatusText(number); | |
361 | } | |
362 | ||
1f361cdd MB |
363 | bool wxFrameBase::ShowMenuHelp(wxStatusBar *WXUNUSED(statbar), int menuId) |
364 | { | |
365 | #if wxUSE_MENUS | |
f6bcfd97 BP |
366 | // if no help string found, we will clear the status bar text |
367 | wxString helpString; | |
fa36fe36 | 368 | if ( menuId != wxID_SEPARATOR && menuId != -3 /* wxID_TITLE */ ) |
f6bcfd97 BP |
369 | { |
370 | wxMenuBar *menuBar = GetMenuBar(); | |
371 | if ( menuBar ) | |
372 | { | |
373 | // it's ok if we don't find the item because it might belong | |
374 | // to the popup menu | |
375 | wxMenuItem *item = menuBar->FindItem(menuId); | |
376 | if ( item ) | |
377 | helpString = item->GetHelp(); | |
378 | } | |
379 | } | |
380 | ||
fa36fe36 | 381 | DoGiveHelp(helpString); |
f6bcfd97 | 382 | |
1729813a | 383 | return !helpString.empty(); |
3379ed37 | 384 | #else // !wxUSE_MENUS |
d1b20379 | 385 | return false; |
3379ed37 | 386 | #endif // wxUSE_MENUS/!wxUSE_MENUS |
f6bcfd97 BP |
387 | } |
388 | ||
a4f01f05 VZ |
389 | void wxFrameBase::SetStatusBar(wxStatusBar *statBar) |
390 | { | |
391 | bool hadBar = m_frameStatusBar != NULL; | |
392 | m_frameStatusBar = statBar; | |
393 | ||
394 | if ( (m_frameStatusBar != NULL) != hadBar ) | |
395 | { | |
396 | PositionStatusBar(); | |
397 | ||
398 | DoLayout(); | |
399 | } | |
400 | } | |
401 | ||
7c0ea335 VZ |
402 | #endif // wxUSE_STATUSBAR |
403 | ||
f257ac87 | 404 | #if wxUSE_MENUS || wxUSE_TOOLBAR |
fa36fe36 | 405 | void wxFrameBase::DoGiveHelp(const wxString& help) |
c60a36d5 VZ |
406 | { |
407 | #if wxUSE_STATUSBAR | |
96ac065f VZ |
408 | if ( m_statusBarPane < 0 ) |
409 | { | |
410 | // status bar messages disabled | |
411 | return; | |
412 | } | |
413 | ||
414 | wxStatusBar *statbar = GetStatusBar(); | |
415 | if ( !statbar ) | |
416 | return; | |
417 | ||
fa36fe36 VZ |
418 | // remember the old status bar text if this is the first time we're |
419 | // called since the menu has been opened as we're going to overwrite it | |
420 | // in our DoGiveHelp() and we want to restore it when the menu is | |
421 | // closed | |
422 | // | |
423 | // note that it would be logical to do this in OnMenuOpen() but under | |
424 | // MSW we get an EVT_MENU_HIGHLIGHT before EVT_MENU_OPEN, strangely | |
425 | // enough, and so this doesn't work and instead we use the ugly trick | |
426 | // with using special m_oldStatusText value as "menu opened" (but it is | |
427 | // arguably better than adding yet another member variable to wxFrame | |
428 | // on all platforms) | |
429 | if ( m_oldStatusText.empty() ) | |
4cbc928a | 430 | { |
fa36fe36 | 431 | m_oldStatusText = statbar->GetStatusText(m_statusBarPane); |
96ac065f VZ |
432 | if ( m_oldStatusText.empty() ) |
433 | { | |
fa36fe36 VZ |
434 | // use special value to prevent us from doing this the next time |
435 | m_oldStatusText += _T('\0'); | |
96ac065f VZ |
436 | } |
437 | } | |
c60a36d5 | 438 | |
96ac065f | 439 | statbar->SetStatusText(help, m_statusBarPane); |
f428e6c5 WS |
440 | #else |
441 | wxUnusedVar(text); | |
442 | wxUnusedVar(show); | |
c60a36d5 VZ |
443 | #endif // wxUSE_STATUSBAR |
444 | } | |
f257ac87 | 445 | #endif // wxUSE_MENUS || wxUSE_TOOLBAR |
c60a36d5 VZ |
446 | |
447 | ||
7c0ea335 VZ |
448 | // ---------------------------------------------------------------------------- |
449 | // toolbar stuff | |
450 | // ---------------------------------------------------------------------------- | |
451 | ||
452 | #if wxUSE_TOOLBAR | |
453 | ||
454 | wxToolBar* wxFrameBase::CreateToolBar(long style, | |
455 | wxWindowID id, | |
456 | const wxString& name) | |
457 | { | |
6a17b868 | 458 | // the main toolbar can't be recreated (unless it was explicitly deleted |
7c0ea335 VZ |
459 | // before) |
460 | wxCHECK_MSG( !m_frameToolBar, (wxToolBar *)NULL, | |
461 | wxT("recreating toolbar in wxFrame") ); | |
462 | ||
f9dae779 VZ |
463 | if ( style == -1 ) |
464 | { | |
465 | // use default style | |
466 | // | |
467 | // NB: we don't specify the default value in the method declaration | |
468 | // because | |
469 | // a) this allows us to have different defaults for different | |
470 | // platforms (even if we don't have them right now) | |
471 | // b) we don't need to include wx/toolbar.h in the header then | |
472 | style = wxBORDER_NONE | wxTB_HORIZONTAL | wxTB_FLAT; | |
473 | } | |
474 | ||
a4f01f05 | 475 | SetToolBar(OnCreateToolBar(style, id, name)); |
7c0ea335 VZ |
476 | |
477 | return m_frameToolBar; | |
478 | } | |
479 | ||
480 | wxToolBar* wxFrameBase::OnCreateToolBar(long style, | |
481 | wxWindowID id, | |
482 | const wxString& name) | |
483 | { | |
a9102b36 JS |
484 | #if defined(__WXWINCE__) && defined(__POCKETPC__) |
485 | return new wxToolMenuBar(this, id, | |
486 | wxDefaultPosition, wxDefaultSize, | |
487 | style, name); | |
488 | #else | |
7c0ea335 VZ |
489 | return new wxToolBar(this, id, |
490 | wxDefaultPosition, wxDefaultSize, | |
491 | style, name); | |
a9102b36 | 492 | #endif |
7c0ea335 VZ |
493 | } |
494 | ||
a4f01f05 VZ |
495 | void wxFrameBase::SetToolBar(wxToolBar *toolbar) |
496 | { | |
497 | bool hadBar = m_frameToolBar != NULL; | |
498 | m_frameToolBar = toolbar; | |
499 | ||
500 | if ( (m_frameToolBar != NULL) != hadBar ) | |
501 | { | |
502 | PositionToolBar(); | |
503 | ||
504 | DoLayout(); | |
505 | } | |
506 | } | |
507 | ||
7c0ea335 VZ |
508 | #endif // wxUSE_TOOLBAR |
509 | ||
510 | // ---------------------------------------------------------------------------- | |
6522713c | 511 | // menus |
7c0ea335 VZ |
512 | // ---------------------------------------------------------------------------- |
513 | ||
1e6feb95 VZ |
514 | #if wxUSE_MENUS |
515 | ||
63fec618 | 516 | // update all menus |
92f1a59c | 517 | void wxFrameBase::DoMenuUpdates(wxMenu* menu) |
63fec618 | 518 | { |
92f1a59c | 519 | if (menu) |
4d538595 DS |
520 | { |
521 | wxEvtHandler* source = GetEventHandler(); | |
92f1a59c | 522 | menu->UpdateUI(source); |
4d538595 DS |
523 | } |
524 | else | |
54517652 | 525 | { |
4d538595 DS |
526 | wxMenuBar* bar = GetMenuBar(); |
527 | if (bar != NULL) | |
528 | bar->UpdateMenus(); | |
63fec618 | 529 | } |
63fec618 | 530 | } |
1e6feb95 | 531 | |
6522713c VZ |
532 | void wxFrameBase::DetachMenuBar() |
533 | { | |
534 | if ( m_frameMenuBar ) | |
535 | { | |
536 | m_frameMenuBar->Detach(); | |
537 | m_frameMenuBar = NULL; | |
538 | } | |
539 | } | |
540 | ||
541 | void wxFrameBase::AttachMenuBar(wxMenuBar *menubar) | |
542 | { | |
543 | if ( menubar ) | |
544 | { | |
6522713c | 545 | menubar->Attach((wxFrame *)this); |
3dbe38c3 | 546 | m_frameMenuBar = menubar; |
6522713c VZ |
547 | } |
548 | } | |
549 | ||
550 | void wxFrameBase::SetMenuBar(wxMenuBar *menubar) | |
551 | { | |
552 | if ( menubar == GetMenuBar() ) | |
553 | { | |
554 | // nothing to do | |
555 | return; | |
556 | } | |
557 | ||
558 | DetachMenuBar(); | |
559 | ||
a96b4743 | 560 | this->AttachMenuBar(menubar); |
6522713c VZ |
561 | } |
562 | ||
1e6feb95 | 563 | #endif // wxUSE_MENUS |