]>
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 | ||
28953245 SC |
55 | // ---------------------------------------------------------------------------- |
56 | // XTI | |
57 | // ---------------------------------------------------------------------------- | |
58 | ||
59 | wxDEFINE_FLAGS( wxFrameStyle ) | |
60 | wxBEGIN_FLAGS( wxFrameStyle ) | |
61 | // new style border flags, we put them first to | |
62 | // use them for streaming out | |
63 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) | |
64 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
65 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
66 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
67 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
68 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
69 | ||
70 | // old style border flags | |
71 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) | |
72 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
73 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
74 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
75 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
76 | wxFLAGS_MEMBER(wxBORDER) | |
77 | ||
78 | // standard window styles | |
79 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) | |
80 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
81 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
82 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
83 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) | |
84 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) | |
85 | wxFLAGS_MEMBER(wxVSCROLL) | |
86 | wxFLAGS_MEMBER(wxHSCROLL) | |
87 | ||
88 | // frame styles | |
89 | wxFLAGS_MEMBER(wxSTAY_ON_TOP) | |
90 | wxFLAGS_MEMBER(wxCAPTION) | |
91 | #if WXWIN_COMPATIBILITY_2_6 | |
92 | wxFLAGS_MEMBER(wxTHICK_FRAME) | |
93 | #endif // WXWIN_COMPATIBILITY_2_6 | |
94 | wxFLAGS_MEMBER(wxSYSTEM_MENU) | |
95 | wxFLAGS_MEMBER(wxRESIZE_BORDER) | |
96 | #if WXWIN_COMPATIBILITY_2_6 | |
97 | wxFLAGS_MEMBER(wxRESIZE_BOX) | |
98 | #endif // WXWIN_COMPATIBILITY_2_6 | |
99 | wxFLAGS_MEMBER(wxCLOSE_BOX) | |
100 | wxFLAGS_MEMBER(wxMAXIMIZE_BOX) | |
101 | wxFLAGS_MEMBER(wxMINIMIZE_BOX) | |
102 | ||
103 | wxFLAGS_MEMBER(wxFRAME_TOOL_WINDOW) | |
104 | wxFLAGS_MEMBER(wxFRAME_FLOAT_ON_PARENT) | |
105 | ||
106 | wxFLAGS_MEMBER(wxFRAME_SHAPED) | |
107 | wxEND_FLAGS( wxFrameStyle ) | |
108 | ||
109 | wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxFrame, wxTopLevelWindow, "wx/frame.h") | |
110 | ||
111 | wxBEGIN_PROPERTIES_TABLE(wxFrame) | |
112 | wxEVENT_PROPERTY( Menu, wxEVT_COMMAND_MENU_SELECTED, wxCommandEvent) | |
113 | ||
114 | wxPROPERTY( Title,wxString, SetTitle, GetTitle, wxString(), 0 /*flags*/, \ | |
115 | wxT("Helpstring"), wxT("group")) | |
116 | wxPROPERTY_FLAGS( WindowStyle, wxFrameStyle, long, SetWindowStyleFlag, \ | |
117 | GetWindowStyleFlag, wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, \ | |
118 | wxT("Helpstring"), wxT("group")) // style | |
119 | wxPROPERTY( MenuBar, wxMenuBar *, SetMenuBar, GetMenuBar, wxEMPTY_PARAMETER_VALUE, \ | |
120 | 0 /*flags*/, wxT("Helpstring"), wxT("group")) | |
121 | wxEND_PROPERTIES_TABLE() | |
122 | ||
123 | wxEMPTY_HANDLERS_TABLE(wxFrame) | |
124 | ||
125 | wxCONSTRUCTOR_6( wxFrame, wxWindow*, Parent, wxWindowID, Id, wxString, Title, \ | |
126 | wxPoint, Position, wxSize, Size, long, WindowStyle) | |
127 | ||
7c0ea335 VZ |
128 | // ---------------------------------------------------------------------------- |
129 | // construction/destruction | |
130 | // ---------------------------------------------------------------------------- | |
131 | ||
132 | wxFrameBase::wxFrameBase() | |
133 | { | |
1e6feb95 | 134 | #if wxUSE_MENUS |
7c0ea335 | 135 | m_frameMenuBar = NULL; |
1e6feb95 | 136 | #endif // wxUSE_MENUS |
7c0ea335 VZ |
137 | |
138 | #if wxUSE_TOOLBAR | |
139 | m_frameToolBar = NULL; | |
140 | #endif // wxUSE_TOOLBAR | |
141 | ||
142 | #if wxUSE_STATUSBAR | |
143 | m_frameStatusBar = NULL; | |
144 | #endif // wxUSE_STATUSBAR | |
1f361cdd MB |
145 | |
146 | m_statusBarPane = 0; | |
7c0ea335 VZ |
147 | } |
148 | ||
799ea011 GD |
149 | wxFrameBase::~wxFrameBase() |
150 | { | |
151 | // this destructor is required for Darwin | |
152 | } | |
153 | ||
7c0ea335 VZ |
154 | wxFrame *wxFrameBase::New(wxWindow *parent, |
155 | wxWindowID id, | |
156 | const wxString& title, | |
157 | const wxPoint& pos, | |
158 | const wxSize& size, | |
159 | long style, | |
160 | const wxString& name) | |
161 | { | |
162 | return new wxFrame(parent, id, title, pos, size, style, name); | |
163 | } | |
164 | ||
165 | void wxFrameBase::DeleteAllBars() | |
166 | { | |
1e6feb95 | 167 | #if wxUSE_MENUS |
5276b0a5 | 168 | wxDELETE(m_frameMenuBar); |
1e6feb95 | 169 | #endif // wxUSE_MENUS |
7c0ea335 VZ |
170 | |
171 | #if wxUSE_STATUSBAR | |
5276b0a5 | 172 | wxDELETE(m_frameStatusBar); |
7c0ea335 VZ |
173 | #endif // wxUSE_STATUSBAR |
174 | ||
175 | #if wxUSE_TOOLBAR | |
5276b0a5 | 176 | wxDELETE(m_frameToolBar); |
7c0ea335 VZ |
177 | #endif // wxUSE_TOOLBAR |
178 | } | |
179 | ||
1e6feb95 VZ |
180 | bool wxFrameBase::IsOneOfBars(const wxWindow *win) const |
181 | { | |
182 | #if wxUSE_MENUS | |
183 | if ( win == GetMenuBar() ) | |
d1b20379 | 184 | return true; |
1e6feb95 VZ |
185 | #endif // wxUSE_MENUS |
186 | ||
187 | #if wxUSE_STATUSBAR | |
188 | if ( win == GetStatusBar() ) | |
d1b20379 | 189 | return true; |
1e6feb95 VZ |
190 | #endif // wxUSE_STATUSBAR |
191 | ||
192 | #if wxUSE_TOOLBAR | |
193 | if ( win == GetToolBar() ) | |
d1b20379 | 194 | return true; |
1e6feb95 VZ |
195 | #endif // wxUSE_TOOLBAR |
196 | ||
8d22935d VZ |
197 | wxUnusedVar(win); |
198 | ||
d1b20379 | 199 | return false; |
1e6feb95 VZ |
200 | } |
201 | ||
1c4f8f8d VZ |
202 | // ---------------------------------------------------------------------------- |
203 | // wxFrame size management: we exclude the areas taken by menu/status/toolbars | |
204 | // from the client area, so the client area is what's really available for the | |
205 | // frame contents | |
206 | // ---------------------------------------------------------------------------- | |
207 | ||
208 | // get the origin of the client area in the client coordinates | |
209 | wxPoint wxFrameBase::GetClientAreaOrigin() const | |
210 | { | |
7d9f12f3 | 211 | wxPoint pt = wxTopLevelWindow::GetClientAreaOrigin(); |
1c4f8f8d | 212 | |
a9928e9d | 213 | #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) |
d4597e13 VZ |
214 | wxToolBar *toolbar = GetToolBar(); |
215 | if ( toolbar && toolbar->IsShown() ) | |
1c4f8f8d VZ |
216 | { |
217 | int w, h; | |
d4597e13 | 218 | toolbar->GetSize(&w, &h); |
1c4f8f8d | 219 | |
d4597e13 | 220 | if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) |
1c4f8f8d VZ |
221 | { |
222 | pt.x += w; | |
223 | } | |
224 | else | |
225 | { | |
226 | pt.y += h; | |
227 | } | |
228 | } | |
229 | #endif // wxUSE_TOOLBAR | |
230 | ||
231 | return pt; | |
232 | } | |
233 | ||
7c0ea335 VZ |
234 | // ---------------------------------------------------------------------------- |
235 | // misc | |
236 | // ---------------------------------------------------------------------------- | |
237 | ||
a6ac49b1 VZ |
238 | #if wxUSE_MENUS |
239 | ||
7c0ea335 VZ |
240 | bool wxFrameBase::ProcessCommand(int id) |
241 | { | |
242 | wxMenuBar *bar = GetMenuBar(); | |
243 | if ( !bar ) | |
d1b20379 | 244 | return false; |
7c0ea335 | 245 | |
a6ac49b1 VZ |
246 | wxMenuItem *item = bar->FindItem(id); |
247 | if ( !item ) | |
248 | return false; | |
249 | ||
250 | return ProcessCommand(item); | |
251 | } | |
252 | ||
253 | bool wxFrameBase::ProcessCommand(wxMenuItem *item) | |
254 | { | |
255 | wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, item->GetId()); | |
3ca6a5f0 BP |
256 | commandEvent.SetEventObject(this); |
257 | ||
a6ac49b1 VZ |
258 | if (!item->IsEnabled()) |
259 | return true; | |
d4597e13 | 260 | |
a6ac49b1 VZ |
261 | if ((item->GetKind() == wxITEM_RADIO) && item->IsChecked() ) |
262 | return true; | |
26c36d75 | 263 | |
a6ac49b1 VZ |
264 | if (item->IsCheckable()) |
265 | { | |
266 | item->Toggle(); | |
0472ece7 | 267 | |
a6ac49b1 VZ |
268 | // use the new value |
269 | commandEvent.SetInt(item->IsChecked()); | |
3ca6a5f0 | 270 | } |
7c0ea335 | 271 | |
e047f594 | 272 | return HandleWindowEvent(commandEvent); |
7c0ea335 VZ |
273 | } |
274 | ||
a6ac49b1 VZ |
275 | #endif // wxUSE_MENUS |
276 | ||
e39af974 JS |
277 | // Do the UI update processing for this window. This is |
278 | // provided for the application to call if it wants to | |
279 | // force a UI update, particularly for the menus and toolbar. | |
280 | void wxFrameBase::UpdateWindowUI(long flags) | |
281 | { | |
282 | wxWindowBase::UpdateWindowUI(flags); | |
a62848fd | 283 | |
e39af974 JS |
284 | #if wxUSE_TOOLBAR |
285 | if (GetToolBar()) | |
286 | GetToolBar()->UpdateWindowUI(flags); | |
287 | #endif | |
288 | ||
289 | #if wxUSE_MENUS | |
290 | if (GetMenuBar()) | |
291 | { | |
a2289551 VZ |
292 | // If coming from an idle event, we only want to update the menus if |
293 | // we're in the wxUSE_IDLEMENUUPDATES configuration, otherwise they | |
294 | // will be update when the menu is opened later | |
295 | #if !wxUSE_IDLEMENUUPDATES | |
296 | if ( !(flags & wxUPDATE_UI_FROMIDLE) ) | |
297 | #endif // wxUSE_IDLEMENUUPDATES | |
e39af974 JS |
298 | DoMenuUpdates(); |
299 | } | |
96ac065f | 300 | #endif // wxUSE_MENUS |
e39af974 JS |
301 | } |
302 | ||
7c0ea335 | 303 | // ---------------------------------------------------------------------------- |
96ac065f | 304 | // event handlers for status bar updates from menus |
7c0ea335 VZ |
305 | // ---------------------------------------------------------------------------- |
306 | ||
96ac065f VZ |
307 | #if wxUSE_MENUS && wxUSE_STATUSBAR |
308 | ||
7c0ea335 VZ |
309 | void wxFrameBase::OnMenuHighlight(wxMenuEvent& event) |
310 | { | |
311 | #if wxUSE_STATUSBAR | |
722ed5be | 312 | (void)ShowMenuHelp(event.GetMenuId()); |
7c0ea335 VZ |
313 | #endif // wxUSE_STATUSBAR |
314 | } | |
315 | ||
96ac065f VZ |
316 | void wxFrameBase::OnMenuOpen(wxMenuEvent& event) |
317 | { | |
a2289551 VZ |
318 | #if wxUSE_IDLEMENUUPDATES |
319 | wxUnusedVar(event); | |
320 | #else // !wxUSE_IDLEMENUUPDATES | |
321 | // as we didn't update the menus from idle time, do it now | |
96ac065f | 322 | DoMenuUpdates(event.GetMenu()); |
a2289551 | 323 | #endif // wxUSE_IDLEMENUUPDATES/!wxUSE_IDLEMENUUPDATES |
96ac065f VZ |
324 | } |
325 | ||
326 | void wxFrameBase::OnMenuClose(wxMenuEvent& WXUNUSED(event)) | |
327 | { | |
6d99eb3e | 328 | DoGiveHelp(wxEmptyString, false); |
96ac065f VZ |
329 | } |
330 | ||
331 | #endif // wxUSE_MENUS && wxUSE_STATUSBAR | |
332 | ||
e39af974 JS |
333 | // Implement internal behaviour (menu updating on some platforms) |
334 | void wxFrameBase::OnInternalIdle() | |
6522713c | 335 | { |
e2b6d07d | 336 | wxTopLevelWindow::OnInternalIdle(); |
a62848fd | 337 | |
0b30bb0b | 338 | #if wxUSE_MENUS && wxUSE_IDLEMENUUPDATES |
e39af974 | 339 | if (wxUpdateUIEvent::CanUpdate(this)) |
0b30bb0b JS |
340 | DoMenuUpdates(); |
341 | #endif | |
342 | } | |
343 | ||
7c0ea335 VZ |
344 | // ---------------------------------------------------------------------------- |
345 | // status bar stuff | |
346 | // ---------------------------------------------------------------------------- | |
347 | ||
348 | #if wxUSE_STATUSBAR | |
349 | ||
350 | wxStatusBar* wxFrameBase::CreateStatusBar(int number, | |
351 | long style, | |
352 | wxWindowID id, | |
353 | const wxString& name) | |
354 | { | |
355 | // the main status bar can only be created once (or else it should be | |
356 | // deleted before calling CreateStatusBar() again) | |
d3b9f782 | 357 | wxCHECK_MSG( !m_frameStatusBar, NULL, |
7c0ea335 VZ |
358 | wxT("recreating status bar in wxFrame") ); |
359 | ||
a4f01f05 | 360 | SetStatusBar(OnCreateStatusBar(number, style, id, name)); |
7c0ea335 VZ |
361 | |
362 | return m_frameStatusBar; | |
363 | } | |
364 | ||
365 | wxStatusBar *wxFrameBase::OnCreateStatusBar(int number, | |
366 | long style, | |
367 | wxWindowID id, | |
368 | const wxString& name) | |
369 | { | |
ed791986 | 370 | wxStatusBar *statusBar = new wxStatusBar(this, id, style, name); |
7c0ea335 | 371 | |
7c0ea335 VZ |
372 | statusBar->SetFieldsCount(number); |
373 | ||
374 | return statusBar; | |
375 | } | |
376 | ||
377 | void wxFrameBase::SetStatusText(const wxString& text, int number) | |
378 | { | |
7c0ea335 VZ |
379 | wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set text for") ); |
380 | ||
381 | m_frameStatusBar->SetStatusText(text, number); | |
382 | } | |
383 | ||
384 | void wxFrameBase::SetStatusWidths(int n, const int widths_field[] ) | |
385 | { | |
7c0ea335 VZ |
386 | wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set widths for") ); |
387 | ||
388 | m_frameStatusBar->SetStatusWidths(n, widths_field); | |
389 | ||
390 | PositionStatusBar(); | |
391 | } | |
392 | ||
1f361cdd | 393 | void wxFrameBase::PushStatusText(const wxString& text, int number) |
f6bcfd97 | 394 | { |
1f361cdd MB |
395 | wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set text for") ); |
396 | ||
397 | m_frameStatusBar->PushStatusText(text, number); | |
398 | } | |
f6bcfd97 | 399 | |
1f361cdd MB |
400 | void wxFrameBase::PopStatusText(int number) |
401 | { | |
402 | wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set text for") ); | |
403 | ||
404 | m_frameStatusBar->PopStatusText(number); | |
405 | } | |
406 | ||
722ed5be | 407 | bool wxFrameBase::ShowMenuHelp(int menuId) |
1f361cdd MB |
408 | { |
409 | #if wxUSE_MENUS | |
f6bcfd97 | 410 | // if no help string found, we will clear the status bar text |
29c7962a VZ |
411 | // |
412 | // NB: wxID_NONE is used for (sub)menus themselves by wxMSW | |
f6bcfd97 | 413 | wxString helpString; |
29c7962a | 414 | if ( menuId != wxID_SEPARATOR && menuId != wxID_NONE ) |
f6bcfd97 | 415 | { |
10816efb | 416 | const wxMenuItem * const item = FindItemInMenuBar(menuId); |
fa7134b0 | 417 | if ( item && !item->IsSeparator() ) |
10816efb VZ |
418 | helpString = item->GetHelp(); |
419 | ||
420 | // notice that it's ok if we don't find the item because it might | |
421 | // belong to the popup menu, so don't assert here | |
f6bcfd97 BP |
422 | } |
423 | ||
6d99eb3e | 424 | DoGiveHelp(helpString, true); |
f6bcfd97 | 425 | |
1729813a | 426 | return !helpString.empty(); |
3379ed37 | 427 | #else // !wxUSE_MENUS |
d1b20379 | 428 | return false; |
3379ed37 | 429 | #endif // wxUSE_MENUS/!wxUSE_MENUS |
f6bcfd97 BP |
430 | } |
431 | ||
a4f01f05 VZ |
432 | void wxFrameBase::SetStatusBar(wxStatusBar *statBar) |
433 | { | |
434 | bool hadBar = m_frameStatusBar != NULL; | |
435 | m_frameStatusBar = statBar; | |
436 | ||
437 | if ( (m_frameStatusBar != NULL) != hadBar ) | |
438 | { | |
439 | PositionStatusBar(); | |
440 | ||
441 | DoLayout(); | |
442 | } | |
443 | } | |
444 | ||
7c0ea335 VZ |
445 | #endif // wxUSE_STATUSBAR |
446 | ||
f257ac87 | 447 | #if wxUSE_MENUS || wxUSE_TOOLBAR |
6d99eb3e | 448 | void wxFrameBase::DoGiveHelp(const wxString& help, bool show) |
c60a36d5 VZ |
449 | { |
450 | #if wxUSE_STATUSBAR | |
96ac065f VZ |
451 | if ( m_statusBarPane < 0 ) |
452 | { | |
453 | // status bar messages disabled | |
454 | return; | |
455 | } | |
456 | ||
457 | wxStatusBar *statbar = GetStatusBar(); | |
458 | if ( !statbar ) | |
459 | return; | |
460 | ||
6d99eb3e VZ |
461 | wxString text; |
462 | if ( show ) | |
4cbc928a | 463 | { |
6d99eb3e VZ |
464 | // remember the old status bar text if this is the first time we're |
465 | // called since the menu has been opened as we're going to overwrite it | |
466 | // in our DoGiveHelp() and we want to restore it when the menu is | |
467 | // closed | |
468 | // | |
469 | // note that it would be logical to do this in OnMenuOpen() but under | |
470 | // MSW we get an EVT_MENU_HIGHLIGHT before EVT_MENU_OPEN, strangely | |
471 | // enough, and so this doesn't work and instead we use the ugly trick | |
472 | // with using special m_oldStatusText value as "menu opened" (but it is | |
473 | // arguably better than adding yet another member variable to wxFrame | |
474 | // on all platforms) | |
96ac065f VZ |
475 | if ( m_oldStatusText.empty() ) |
476 | { | |
6d99eb3e VZ |
477 | m_oldStatusText = statbar->GetStatusText(m_statusBarPane); |
478 | if ( m_oldStatusText.empty() ) | |
479 | { | |
480 | // use special value to prevent us from doing this the next time | |
9a83f860 | 481 | m_oldStatusText += wxT('\0'); |
6d99eb3e | 482 | } |
96ac065f | 483 | } |
6d99eb3e | 484 | |
f0f03f32 | 485 | m_lastHelpShown = |
6d99eb3e VZ |
486 | text = help; |
487 | } | |
488 | else // hide help, restore the original text | |
489 | { | |
f0f03f32 VZ |
490 | // clear the last shown help string but remember its value |
491 | wxString lastHelpShown; | |
492 | lastHelpShown.swap(m_lastHelpShown); | |
493 | ||
494 | // also clear the old status text but remember it too to restore it | |
495 | // below | |
496 | text.swap(m_oldStatusText); | |
497 | ||
498 | if ( statbar->GetStatusText(m_statusBarPane) != lastHelpShown ) | |
499 | { | |
500 | // if the text was changed with an explicit SetStatusText() call | |
501 | // from the user code in the meanwhile, do not overwrite it with | |
502 | // the old status bar contents -- this is almost certainly not what | |
503 | // the user expects and would be very hard to avoid from user code | |
504 | return; | |
505 | } | |
96ac065f | 506 | } |
c60a36d5 | 507 | |
6d99eb3e | 508 | statbar->SetStatusText(text, m_statusBarPane); |
f428e6c5 | 509 | #else |
3b257996 | 510 | wxUnusedVar(help); |
f428e6c5 | 511 | wxUnusedVar(show); |
c60a36d5 VZ |
512 | #endif // wxUSE_STATUSBAR |
513 | } | |
f257ac87 | 514 | #endif // wxUSE_MENUS || wxUSE_TOOLBAR |
c60a36d5 VZ |
515 | |
516 | ||
7c0ea335 VZ |
517 | // ---------------------------------------------------------------------------- |
518 | // toolbar stuff | |
519 | // ---------------------------------------------------------------------------- | |
520 | ||
521 | #if wxUSE_TOOLBAR | |
522 | ||
523 | wxToolBar* wxFrameBase::CreateToolBar(long style, | |
524 | wxWindowID id, | |
525 | const wxString& name) | |
526 | { | |
6a17b868 | 527 | // the main toolbar can't be recreated (unless it was explicitly deleted |
7c0ea335 | 528 | // before) |
d3b9f782 | 529 | wxCHECK_MSG( !m_frameToolBar, NULL, |
7c0ea335 VZ |
530 | wxT("recreating toolbar in wxFrame") ); |
531 | ||
f9dae779 VZ |
532 | if ( style == -1 ) |
533 | { | |
534 | // use default style | |
535 | // | |
536 | // NB: we don't specify the default value in the method declaration | |
537 | // because | |
538 | // a) this allows us to have different defaults for different | |
539 | // platforms (even if we don't have them right now) | |
540 | // b) we don't need to include wx/toolbar.h in the header then | |
541 | style = wxBORDER_NONE | wxTB_HORIZONTAL | wxTB_FLAT; | |
542 | } | |
543 | ||
a4f01f05 | 544 | SetToolBar(OnCreateToolBar(style, id, name)); |
7c0ea335 VZ |
545 | |
546 | return m_frameToolBar; | |
547 | } | |
548 | ||
549 | wxToolBar* wxFrameBase::OnCreateToolBar(long style, | |
550 | wxWindowID id, | |
551 | const wxString& name) | |
552 | { | |
a9102b36 JS |
553 | #if defined(__WXWINCE__) && defined(__POCKETPC__) |
554 | return new wxToolMenuBar(this, id, | |
555 | wxDefaultPosition, wxDefaultSize, | |
556 | style, name); | |
557 | #else | |
7c0ea335 VZ |
558 | return new wxToolBar(this, id, |
559 | wxDefaultPosition, wxDefaultSize, | |
560 | style, name); | |
a9102b36 | 561 | #endif |
7c0ea335 VZ |
562 | } |
563 | ||
a4f01f05 VZ |
564 | void wxFrameBase::SetToolBar(wxToolBar *toolbar) |
565 | { | |
62f6be44 | 566 | if ( (toolbar != NULL) != (m_frameToolBar != NULL) ) |
a4f01f05 | 567 | { |
62f6be44 VZ |
568 | // the toolbar visibility must have changed so we need to both position |
569 | // the toolbar itself (if it appeared) and to relayout the frame | |
570 | // contents in any case | |
571 | ||
572 | if ( toolbar ) | |
573 | { | |
574 | // we need to assign it to m_frameToolBar for PositionToolBar() to | |
575 | // do anything | |
576 | m_frameToolBar = toolbar; | |
577 | PositionToolBar(); | |
578 | } | |
579 | //else: tricky: do not reset m_frameToolBar yet as otherwise DoLayout() | |
580 | // wouldn't recognize the (still existing) toolbar as one of our | |
581 | // bars and wouldn't layout the single child of the frame correctly | |
582 | ||
583 | ||
584 | // and this is even more tricky: we want DoLayout() to recognize the | |
585 | // old toolbar for the purpose of not counting it among our non-bar | |
586 | // children but we don't want to reserve any more space for it so we | |
587 | // temporarily hide it | |
588 | if ( m_frameToolBar ) | |
589 | m_frameToolBar->Hide(); | |
a4f01f05 VZ |
590 | |
591 | DoLayout(); | |
62f6be44 VZ |
592 | |
593 | if ( m_frameToolBar ) | |
594 | m_frameToolBar->Show(); | |
a4f01f05 | 595 | } |
62f6be44 VZ |
596 | |
597 | // this might have been already done above but it's simpler to just always | |
598 | // do it unconditionally instead of testing for whether we already did it | |
599 | m_frameToolBar = toolbar; | |
a4f01f05 VZ |
600 | } |
601 | ||
7c0ea335 VZ |
602 | #endif // wxUSE_TOOLBAR |
603 | ||
604 | // ---------------------------------------------------------------------------- | |
6522713c | 605 | // menus |
7c0ea335 VZ |
606 | // ---------------------------------------------------------------------------- |
607 | ||
1e6feb95 VZ |
608 | #if wxUSE_MENUS |
609 | ||
63fec618 | 610 | // update all menus |
92f1a59c | 611 | void wxFrameBase::DoMenuUpdates(wxMenu* menu) |
63fec618 | 612 | { |
92f1a59c | 613 | if (menu) |
4d538595 DS |
614 | { |
615 | wxEvtHandler* source = GetEventHandler(); | |
92f1a59c | 616 | menu->UpdateUI(source); |
4d538595 DS |
617 | } |
618 | else | |
54517652 | 619 | { |
4d538595 DS |
620 | wxMenuBar* bar = GetMenuBar(); |
621 | if (bar != NULL) | |
622 | bar->UpdateMenus(); | |
63fec618 | 623 | } |
63fec618 | 624 | } |
1e6feb95 | 625 | |
6522713c VZ |
626 | void wxFrameBase::DetachMenuBar() |
627 | { | |
628 | if ( m_frameMenuBar ) | |
629 | { | |
630 | m_frameMenuBar->Detach(); | |
631 | m_frameMenuBar = NULL; | |
632 | } | |
633 | } | |
634 | ||
635 | void wxFrameBase::AttachMenuBar(wxMenuBar *menubar) | |
636 | { | |
637 | if ( menubar ) | |
638 | { | |
6522713c | 639 | menubar->Attach((wxFrame *)this); |
3dbe38c3 | 640 | m_frameMenuBar = menubar; |
6522713c VZ |
641 | } |
642 | } | |
643 | ||
644 | void wxFrameBase::SetMenuBar(wxMenuBar *menubar) | |
645 | { | |
646 | if ( menubar == GetMenuBar() ) | |
647 | { | |
648 | // nothing to do | |
649 | return; | |
650 | } | |
651 | ||
652 | DetachMenuBar(); | |
653 | ||
a96b4743 | 654 | this->AttachMenuBar(menubar); |
6522713c VZ |
655 | } |
656 | ||
79f9ea05 | 657 | wxMenuItem *wxFrameBase::FindItemInMenuBar(int menuId) const |
10816efb VZ |
658 | { |
659 | const wxMenuBar * const menuBar = GetMenuBar(); | |
660 | ||
661 | return menuBar ? menuBar->FindItem(menuId) : NULL; | |
662 | } | |
663 | ||
1e6feb95 | 664 | #endif // wxUSE_MENUS |