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