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