]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/msw/frame.cpp | |
3 | // Purpose: wxFrame | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | // For compilers that support precompilation, includes "wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | #include "wx/frame.h" | |
28 | ||
29 | #ifndef WX_PRECOMP | |
30 | #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly" | |
31 | #include "wx/app.h" | |
32 | #include "wx/menu.h" | |
33 | #include "wx/utils.h" | |
34 | #include "wx/dialog.h" | |
35 | #include "wx/settings.h" | |
36 | #include "wx/dcclient.h" | |
37 | #include "wx/mdi.h" | |
38 | #include "wx/panel.h" | |
39 | #include "wx/log.h" | |
40 | #include "wx/toolbar.h" | |
41 | #include "wx/statusbr.h" | |
42 | #include "wx/menuitem.h" | |
43 | #endif // WX_PRECOMP | |
44 | ||
45 | #include "wx/msw/private.h" | |
46 | ||
47 | #if defined(__POCKETPC__) || defined(__SMARTPHONE__) | |
48 | #include <ole2.h> | |
49 | #include <aygshell.h> | |
50 | #include "wx/msw/winundef.h" | |
51 | #endif | |
52 | ||
53 | #include "wx/generic/statusbr.h" | |
54 | ||
55 | #ifdef __WXUNIVERSAL__ | |
56 | #include "wx/univ/theme.h" | |
57 | #include "wx/univ/colschem.h" | |
58 | #endif // __WXUNIVERSAL__ | |
59 | ||
60 | // ---------------------------------------------------------------------------- | |
61 | // globals | |
62 | // ---------------------------------------------------------------------------- | |
63 | ||
64 | #if wxUSE_MENUS_NATIVE | |
65 | extern wxMenu *wxCurrentPopupMenu; | |
66 | #endif // wxUSE_MENUS_NATIVE | |
67 | ||
68 | // ---------------------------------------------------------------------------- | |
69 | // event tables | |
70 | // ---------------------------------------------------------------------------- | |
71 | ||
72 | BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) | |
73 | EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) | |
74 | END_EVENT_TABLE() | |
75 | ||
76 | #if wxUSE_EXTENDED_RTTI | |
77 | WX_DEFINE_FLAGS( wxFrameStyle ) | |
78 | ||
79 | wxBEGIN_FLAGS( wxFrameStyle ) | |
80 | // new style border flags, we put them first to | |
81 | // use them for streaming out | |
82 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) | |
83 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
84 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
85 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
86 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
87 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
88 | ||
89 | // old style border flags | |
90 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) | |
91 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
92 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
93 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
94 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
95 | wxFLAGS_MEMBER(wxBORDER) | |
96 | ||
97 | // standard window styles | |
98 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) | |
99 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
100 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
101 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
102 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) | |
103 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) | |
104 | wxFLAGS_MEMBER(wxVSCROLL) | |
105 | wxFLAGS_MEMBER(wxHSCROLL) | |
106 | ||
107 | // frame styles | |
108 | wxFLAGS_MEMBER(wxSTAY_ON_TOP) | |
109 | wxFLAGS_MEMBER(wxCAPTION) | |
110 | #if WXWIN_COMPATIBILITY_2_6 | |
111 | wxFLAGS_MEMBER(wxTHICK_FRAME) | |
112 | #endif // WXWIN_COMPATIBILITY_2_6 | |
113 | wxFLAGS_MEMBER(wxSYSTEM_MENU) | |
114 | wxFLAGS_MEMBER(wxRESIZE_BORDER) | |
115 | #if WXWIN_COMPATIBILITY_2_6 | |
116 | wxFLAGS_MEMBER(wxRESIZE_BOX) | |
117 | #endif // WXWIN_COMPATIBILITY_2_6 | |
118 | wxFLAGS_MEMBER(wxCLOSE_BOX) | |
119 | wxFLAGS_MEMBER(wxMAXIMIZE_BOX) | |
120 | wxFLAGS_MEMBER(wxMINIMIZE_BOX) | |
121 | ||
122 | wxFLAGS_MEMBER(wxFRAME_TOOL_WINDOW) | |
123 | wxFLAGS_MEMBER(wxFRAME_FLOAT_ON_PARENT) | |
124 | ||
125 | wxFLAGS_MEMBER(wxFRAME_SHAPED) | |
126 | ||
127 | wxEND_FLAGS( wxFrameStyle ) | |
128 | ||
129 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxFrame, wxTopLevelWindow,"wx/frame.h") | |
130 | ||
131 | wxBEGIN_PROPERTIES_TABLE(wxFrame) | |
132 | wxEVENT_PROPERTY( Menu , wxEVT_COMMAND_MENU_SELECTED , wxCommandEvent) | |
133 | ||
134 | wxPROPERTY( Title,wxString, SetTitle, GetTitle, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
135 | wxPROPERTY_FLAGS( WindowStyle , wxFrameStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style | |
136 | wxPROPERTY( MenuBar , wxMenuBar * , SetMenuBar , GetMenuBar , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
137 | wxEND_PROPERTIES_TABLE() | |
138 | ||
139 | wxBEGIN_HANDLERS_TABLE(wxFrame) | |
140 | wxEND_HANDLERS_TABLE() | |
141 | ||
142 | wxCONSTRUCTOR_6( wxFrame , wxWindow* , Parent , wxWindowID , Id , wxString , Title , wxPoint , Position , wxSize , Size , long , WindowStyle) | |
143 | ||
144 | #else | |
145 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow) | |
146 | #endif | |
147 | ||
148 | // ============================================================================ | |
149 | // implementation | |
150 | // ============================================================================ | |
151 | ||
152 | // ---------------------------------------------------------------------------- | |
153 | // static class members | |
154 | // ---------------------------------------------------------------------------- | |
155 | ||
156 | #if wxUSE_STATUSBAR | |
157 | #if wxUSE_NATIVE_STATUSBAR | |
158 | bool wxFrame::m_useNativeStatusBar = true; | |
159 | #else | |
160 | bool wxFrame::m_useNativeStatusBar = false; | |
161 | #endif | |
162 | #endif // wxUSE_NATIVE_STATUSBAR | |
163 | ||
164 | // ---------------------------------------------------------------------------- | |
165 | // creation/destruction | |
166 | // ---------------------------------------------------------------------------- | |
167 | ||
168 | void wxFrame::Init() | |
169 | { | |
170 | #if wxUSE_MENUS | |
171 | m_hMenu = NULL; | |
172 | #endif // wxUSE_MENUS | |
173 | ||
174 | #if wxUSE_TOOLTIPS | |
175 | m_hwndToolTip = 0; | |
176 | #endif | |
177 | ||
178 | m_wasMinimized = false; | |
179 | } | |
180 | ||
181 | bool wxFrame::Create(wxWindow *parent, | |
182 | wxWindowID id, | |
183 | const wxString& title, | |
184 | const wxPoint& pos, | |
185 | const wxSize& size, | |
186 | long style, | |
187 | const wxString& name) | |
188 | { | |
189 | if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) ) | |
190 | return false; | |
191 | ||
192 | SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); | |
193 | ||
194 | #if defined(__SMARTPHONE__) | |
195 | SetLeftMenu(wxID_EXIT, _("Done")); | |
196 | #endif | |
197 | ||
198 | #if wxUSE_ACCEL && defined(__POCKETPC__) | |
199 | // The guidelines state that Ctrl+Q should quit the app. | |
200 | // Let's define an accelerator table to send wxID_EXIT. | |
201 | wxAcceleratorEntry entries[1]; | |
202 | entries[0].Set(wxACCEL_CTRL, 'Q', wxID_EXIT); | |
203 | wxAcceleratorTable accel(1, entries); | |
204 | SetAcceleratorTable(accel); | |
205 | #endif // wxUSE_ACCEL && __POCKETPC__ | |
206 | ||
207 | return true; | |
208 | } | |
209 | ||
210 | wxFrame::~wxFrame() | |
211 | { | |
212 | SendDestroyEvent(); | |
213 | ||
214 | DeleteAllBars(); | |
215 | } | |
216 | ||
217 | // ---------------------------------------------------------------------------- | |
218 | // wxFrame client size calculations | |
219 | // ---------------------------------------------------------------------------- | |
220 | ||
221 | void wxFrame::DoSetClientSize(int width, int height) | |
222 | { | |
223 | // leave enough space for the status bar if we have (and show) it | |
224 | #if wxUSE_STATUSBAR | |
225 | wxStatusBar *statbar = GetStatusBar(); | |
226 | if ( statbar && statbar->IsShown() ) | |
227 | { | |
228 | height += statbar->GetSize().y; | |
229 | } | |
230 | #endif // wxUSE_STATUSBAR | |
231 | ||
232 | // call GetClientAreaOrigin() to take the toolbar into account | |
233 | wxPoint pt = GetClientAreaOrigin(); | |
234 | width += pt.x; | |
235 | height += pt.y; | |
236 | ||
237 | #if wxUSE_TOOLBAR | |
238 | wxToolBar * const toolbar = GetToolBar(); | |
239 | if ( toolbar ) | |
240 | { | |
241 | if ( toolbar->HasFlag(wxTB_RIGHT | wxTB_BOTTOM) ) | |
242 | { | |
243 | const wxSize sizeTB = toolbar->GetSize(); | |
244 | if ( toolbar->HasFlag(wxTB_RIGHT) ) | |
245 | width -= sizeTB.x; | |
246 | else // wxTB_BOTTOM | |
247 | height -= sizeTB.y; | |
248 | } | |
249 | //else: toolbar already taken into account by GetClientAreaOrigin() | |
250 | } | |
251 | #endif // wxUSE_TOOLBAR | |
252 | ||
253 | wxTopLevelWindow::DoSetClientSize(width, height); | |
254 | } | |
255 | ||
256 | // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. | |
257 | void wxFrame::DoGetClientSize(int *x, int *y) const | |
258 | { | |
259 | wxTopLevelWindow::DoGetClientSize(x, y); | |
260 | ||
261 | // account for the possible toolbar | |
262 | wxPoint pt = GetClientAreaOrigin(); | |
263 | if ( x ) | |
264 | *x -= pt.x; | |
265 | ||
266 | if ( y ) | |
267 | *y -= pt.y; | |
268 | ||
269 | #if wxUSE_TOOLBAR | |
270 | wxToolBar * const toolbar = GetToolBar(); | |
271 | if ( toolbar ) | |
272 | { | |
273 | if ( toolbar->HasFlag(wxTB_RIGHT | wxTB_BOTTOM) ) | |
274 | { | |
275 | const wxSize sizeTB = toolbar->GetSize(); | |
276 | if ( toolbar->HasFlag(wxTB_RIGHT) ) | |
277 | { | |
278 | if ( x ) | |
279 | *x -= sizeTB.x; | |
280 | } | |
281 | else // wxTB_BOTTOM | |
282 | { | |
283 | if ( y ) | |
284 | *y -= sizeTB.y; | |
285 | } | |
286 | } | |
287 | //else: toolbar already taken into account by GetClientAreaOrigin() | |
288 | } | |
289 | #endif // wxUSE_TOOLBAR | |
290 | ||
291 | #if wxUSE_STATUSBAR | |
292 | // adjust client area height to take the status bar into account | |
293 | if ( y ) | |
294 | { | |
295 | wxStatusBar *statbar = GetStatusBar(); | |
296 | if ( statbar && statbar->IsShown() ) | |
297 | { | |
298 | *y -= statbar->GetClientSize().y; | |
299 | } | |
300 | } | |
301 | #endif // wxUSE_STATUSBAR | |
302 | } | |
303 | ||
304 | // ---------------------------------------------------------------------------- | |
305 | // wxFrame: various geometry-related functions | |
306 | // ---------------------------------------------------------------------------- | |
307 | ||
308 | void wxFrame::Raise() | |
309 | { | |
310 | ::SetForegroundWindow(GetHwnd()); | |
311 | } | |
312 | ||
313 | // generate an artificial resize event | |
314 | void wxFrame::SendSizeEvent(int flags) | |
315 | { | |
316 | if ( !m_iconized ) | |
317 | { | |
318 | RECT r = wxGetWindowRect(GetHwnd()); | |
319 | ||
320 | if ( flags & wxSEND_EVENT_POST ) | |
321 | { | |
322 | ::PostMessage(GetHwnd(), WM_SIZE, | |
323 | IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED, | |
324 | MAKELPARAM(r.right - r.left, r.bottom - r.top)); | |
325 | } | |
326 | else // send it | |
327 | { | |
328 | ::SendMessage(GetHwnd(), WM_SIZE, | |
329 | IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED, | |
330 | MAKELPARAM(r.right - r.left, r.bottom - r.top)); | |
331 | } | |
332 | } | |
333 | } | |
334 | ||
335 | #if wxUSE_STATUSBAR | |
336 | wxStatusBar *wxFrame::OnCreateStatusBar(int number, | |
337 | long style, | |
338 | wxWindowID id, | |
339 | const wxString& name) | |
340 | { | |
341 | wxStatusBar *statusBar wxDUMMY_INITIALIZE(NULL); | |
342 | ||
343 | #if wxUSE_NATIVE_STATUSBAR | |
344 | if ( !UsesNativeStatusBar() ) | |
345 | { | |
346 | statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style); | |
347 | } | |
348 | else | |
349 | #endif | |
350 | { | |
351 | statusBar = new wxStatusBar(this, id, style, name); | |
352 | } | |
353 | ||
354 | statusBar->SetFieldsCount(number); | |
355 | ||
356 | return statusBar; | |
357 | } | |
358 | ||
359 | void wxFrame::PositionStatusBar() | |
360 | { | |
361 | if ( !m_frameStatusBar || !m_frameStatusBar->IsShown() ) | |
362 | return; | |
363 | ||
364 | int w, h; | |
365 | GetClientSize(&w, &h); | |
366 | ||
367 | int sw, sh; | |
368 | m_frameStatusBar->GetSize(&sw, &sh); | |
369 | ||
370 | int x = 0; | |
371 | #if wxUSE_TOOLBAR | |
372 | wxToolBar * const toolbar = GetToolBar(); | |
373 | if ( toolbar && !toolbar->HasFlag(wxTB_TOP) ) | |
374 | { | |
375 | const wxSize sizeTB = toolbar->GetSize(); | |
376 | ||
377 | if ( toolbar->HasFlag(wxTB_LEFT | wxTB_RIGHT) ) | |
378 | { | |
379 | if ( toolbar->HasFlag(wxTB_LEFT) ) | |
380 | x -= sizeTB.x; | |
381 | ||
382 | w += sizeTB.x; | |
383 | } | |
384 | else // wxTB_BOTTOM | |
385 | { | |
386 | // we need to position the status bar below the toolbar | |
387 | h += sizeTB.y; | |
388 | } | |
389 | } | |
390 | //else: no adjustments necessary for the toolbar on top | |
391 | #endif // wxUSE_TOOLBAR | |
392 | ||
393 | // Since we wish the status bar to be directly under the client area, | |
394 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
395 | m_frameStatusBar->SetSize(x, h, w, sh); | |
396 | } | |
397 | ||
398 | #endif // wxUSE_STATUSBAR | |
399 | ||
400 | #if wxUSE_MENUS_NATIVE | |
401 | ||
402 | void wxFrame::AttachMenuBar(wxMenuBar *menubar) | |
403 | { | |
404 | #if defined(__SMARTPHONE__) && defined(__WXWINCE__) | |
405 | ||
406 | wxMenu *autoMenu = NULL; | |
407 | ||
408 | if( menubar->GetMenuCount() == 1 ) | |
409 | { | |
410 | autoMenu = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar->GetMenu(0)); | |
411 | SetRightMenu(wxID_ANY, menubar->GetMenuLabel(0), autoMenu); | |
412 | } | |
413 | else | |
414 | { | |
415 | autoMenu = new wxMenu; | |
416 | ||
417 | for( size_t n = 0; n < menubar->GetMenuCount(); n++ ) | |
418 | { | |
419 | wxMenu *item = menubar->GetMenu(n); | |
420 | wxString label = menubar->GetMenuLabel(n); | |
421 | wxMenu *new_item = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item); | |
422 | autoMenu->Append(wxID_ANY, label, new_item); | |
423 | } | |
424 | ||
425 | SetRightMenu(wxID_ANY, _("Menu"), autoMenu); | |
426 | } | |
427 | ||
428 | #elif defined(WINCE_WITHOUT_COMMANDBAR) | |
429 | if (!GetToolBar()) | |
430 | { | |
431 | wxToolMenuBar* toolBar = new wxToolMenuBar(this, wxID_ANY, | |
432 | wxDefaultPosition, wxDefaultSize, | |
433 | wxBORDER_NONE | wxTB_HORIZONTAL, | |
434 | wxToolBarNameStr, menubar); | |
435 | SetToolBar(toolBar); | |
436 | menubar->SetToolBar(toolBar); | |
437 | } | |
438 | ||
439 | // When the main window is created using CW_USEDEFAULT the height of the | |
440 | // menubar is not taken into account, so we resize it afterwards if a | |
441 | // menubar is present | |
442 | HWND hwndMenuBar = SHFindMenuBar(GetHwnd()); | |
443 | if ( hwndMenuBar ) | |
444 | { | |
445 | RECT mbRect; | |
446 | ::GetWindowRect(hwndMenuBar, &mbRect); | |
447 | const int menuHeight = mbRect.bottom - mbRect.top; | |
448 | ||
449 | RECT rc; | |
450 | ::GetWindowRect(GetHwnd(), &rc); | |
451 | // adjust for menu / titlebar height | |
452 | rc.bottom -= (2*menuHeight-1); | |
453 | ||
454 | ::MoveWindow(Gethwnd(), rc.left, rc.top, rc.right, rc.bottom, FALSE); | |
455 | } | |
456 | #endif | |
457 | ||
458 | wxFrameBase::AttachMenuBar(menubar); | |
459 | ||
460 | if ( !menubar ) | |
461 | { | |
462 | // actually remove the menu from the frame | |
463 | m_hMenu = (WXHMENU)0; | |
464 | InternalSetMenuBar(); | |
465 | } | |
466 | else // set new non NULL menu bar | |
467 | { | |
468 | #if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR) | |
469 | // Can set a menubar several times. | |
470 | if ( menubar->GetHMenu() ) | |
471 | { | |
472 | m_hMenu = menubar->GetHMenu(); | |
473 | } | |
474 | else // no HMENU yet | |
475 | { | |
476 | m_hMenu = menubar->Create(); | |
477 | ||
478 | if ( !m_hMenu ) | |
479 | { | |
480 | wxFAIL_MSG( wxT("failed to create menu bar") ); | |
481 | return; | |
482 | } | |
483 | } | |
484 | #endif | |
485 | InternalSetMenuBar(); | |
486 | } | |
487 | } | |
488 | ||
489 | void wxFrame::InternalSetMenuBar() | |
490 | { | |
491 | #if defined(__WXMICROWIN__) || defined(__WXWINCE__) | |
492 | // Nothing | |
493 | #else | |
494 | if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) ) | |
495 | { | |
496 | wxLogLastError(wxT("SetMenu")); | |
497 | } | |
498 | #endif | |
499 | } | |
500 | ||
501 | #endif // wxUSE_MENUS_NATIVE | |
502 | ||
503 | // Responds to colour changes, and passes event on to children. | |
504 | void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) | |
505 | { | |
506 | SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); | |
507 | Refresh(); | |
508 | ||
509 | #if wxUSE_STATUSBAR | |
510 | if ( m_frameStatusBar ) | |
511 | { | |
512 | wxSysColourChangedEvent event2; | |
513 | event2.SetEventObject( m_frameStatusBar ); | |
514 | m_frameStatusBar->HandleWindowEvent(event2); | |
515 | } | |
516 | #endif // wxUSE_STATUSBAR | |
517 | ||
518 | // Propagate the event to the non-top-level children | |
519 | wxWindow::OnSysColourChanged(event); | |
520 | } | |
521 | ||
522 | // Pass true to show full screen, false to restore. | |
523 | bool wxFrame::ShowFullScreen(bool show, long style) | |
524 | { | |
525 | // TODO-CE: add support for CE | |
526 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) | |
527 | if ( IsFullScreen() == show ) | |
528 | return false; | |
529 | ||
530 | if (show) | |
531 | { | |
532 | // zap the toolbar, menubar, and statusbar if needed | |
533 | // | |
534 | // TODO: hide commandbar for WINCE_WITH_COMMANDBAR | |
535 | #if wxUSE_TOOLBAR | |
536 | wxToolBar *theToolBar = GetToolBar(); | |
537 | ||
538 | if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar) | |
539 | { | |
540 | if ( theToolBar->IsShown() ) | |
541 | { | |
542 | theToolBar->SetSize(wxDefaultCoord,0); | |
543 | theToolBar->Show(false); | |
544 | } | |
545 | else // prevent it from being restored later | |
546 | { | |
547 | style &= ~wxFULLSCREEN_NOTOOLBAR; | |
548 | } | |
549 | } | |
550 | #endif // wxUSE_TOOLBAR | |
551 | ||
552 | if (style & wxFULLSCREEN_NOMENUBAR) | |
553 | SetMenu((HWND)GetHWND(), (HMENU) NULL); | |
554 | ||
555 | #if wxUSE_STATUSBAR | |
556 | wxStatusBar *theStatusBar = GetStatusBar(); | |
557 | ||
558 | // Save the number of fields in the statusbar | |
559 | if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar) | |
560 | { | |
561 | if ( theStatusBar->IsShown() ) | |
562 | theStatusBar->Show(false); | |
563 | else | |
564 | style &= ~wxFULLSCREEN_NOSTATUSBAR; | |
565 | } | |
566 | #endif // wxUSE_STATUSBAR | |
567 | } | |
568 | else // restore to normal | |
569 | { | |
570 | // restore the toolbar, menubar, and statusbar if we had hid them | |
571 | #if wxUSE_TOOLBAR | |
572 | wxToolBar *theToolBar = GetToolBar(); | |
573 | ||
574 | if ((m_fsStyle & wxFULLSCREEN_NOTOOLBAR) && theToolBar) | |
575 | { | |
576 | theToolBar->Show(true); | |
577 | } | |
578 | #endif // wxUSE_TOOLBAR | |
579 | ||
580 | #if wxUSE_MENUS | |
581 | if (m_fsStyle & wxFULLSCREEN_NOMENUBAR) | |
582 | { | |
583 | const WXHMENU hmenu = MSWGetActiveMenu(); | |
584 | if ( hmenu ) | |
585 | ::SetMenu(GetHwnd(), (HMENU)hmenu); | |
586 | } | |
587 | #endif // wxUSE_MENUS | |
588 | ||
589 | #if wxUSE_STATUSBAR | |
590 | wxStatusBar *theStatusBar = GetStatusBar(); | |
591 | ||
592 | if ((m_fsStyle & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar) | |
593 | { | |
594 | theStatusBar->Show(true); | |
595 | PositionStatusBar(); | |
596 | } | |
597 | #endif // wxUSE_STATUSBAR | |
598 | } | |
599 | #endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__) | |
600 | ||
601 | return wxFrameBase::ShowFullScreen(show, style); | |
602 | } | |
603 | ||
604 | // ---------------------------------------------------------------------------- | |
605 | // tool/status bar stuff | |
606 | // ---------------------------------------------------------------------------- | |
607 | ||
608 | #if wxUSE_TOOLBAR | |
609 | ||
610 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) | |
611 | { | |
612 | #if defined(WINCE_WITHOUT_COMMANDBAR) | |
613 | // We may already have a toolbar from calling SetMenuBar. | |
614 | if (GetToolBar()) | |
615 | return GetToolBar(); | |
616 | #endif | |
617 | if ( wxFrameBase::CreateToolBar(style, id, name) ) | |
618 | { | |
619 | PositionToolBar(); | |
620 | } | |
621 | ||
622 | return m_frameToolBar; | |
623 | } | |
624 | ||
625 | void wxFrame::PositionToolBar() | |
626 | { | |
627 | // TODO: we want to do something different in WinCE, because the toolbar | |
628 | // should be associated with the commandbar, instead of being | |
629 | // independent window. | |
630 | #if !defined(WINCE_WITHOUT_COMMANDBAR) | |
631 | wxToolBar *toolbar = GetToolBar(); | |
632 | if ( toolbar && toolbar->IsShown() ) | |
633 | { | |
634 | // don't call our (or even wxTopLevelWindow) version because we want | |
635 | // the real (full) client area size, not excluding the tool/status bar | |
636 | int width, height; | |
637 | wxWindow::DoGetClientSize(&width, &height); | |
638 | ||
639 | #if wxUSE_STATUSBAR | |
640 | wxStatusBar *statbar = GetStatusBar(); | |
641 | if ( statbar && statbar->IsShown() ) | |
642 | { | |
643 | height -= statbar->GetClientSize().y; | |
644 | } | |
645 | #endif // wxUSE_STATUSBAR | |
646 | ||
647 | int tx, ty, tw, th; | |
648 | toolbar->GetPosition( &tx, &ty ); | |
649 | toolbar->GetSize( &tw, &th ); | |
650 | ||
651 | int x, y; | |
652 | if ( toolbar->HasFlag(wxTB_BOTTOM) ) | |
653 | { | |
654 | x = 0; | |
655 | y = height - th; | |
656 | } | |
657 | else if ( toolbar->HasFlag(wxTB_RIGHT) ) | |
658 | { | |
659 | x = width - tw; | |
660 | y = 0; | |
661 | } | |
662 | else // left or top | |
663 | { | |
664 | x = 0; | |
665 | y = 0; | |
666 | } | |
667 | ||
668 | #if defined(WINCE_WITH_COMMANDBAR) | |
669 | // We're using a commandbar - so we have to allow for it. | |
670 | if (GetMenuBar() && GetMenuBar()->GetCommandBar()) | |
671 | { | |
672 | RECT rect; | |
673 | ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect); | |
674 | y = rect.bottom - rect.top; | |
675 | } | |
676 | #endif // WINCE_WITH_COMMANDBAR | |
677 | ||
678 | if ( toolbar->HasFlag(wxTB_BOTTOM) ) | |
679 | { | |
680 | if ( ty < 0 && ( -ty == th ) ) | |
681 | ty = height - th; | |
682 | if ( tx < 0 && (-tx == tw ) ) | |
683 | tx = 0; | |
684 | } | |
685 | else if ( toolbar->HasFlag(wxTB_RIGHT) ) | |
686 | { | |
687 | if( ty < 0 && ( -ty == th ) ) | |
688 | ty = 0; | |
689 | if( tx < 0 && ( -tx == tw ) ) | |
690 | tx = width - tw; | |
691 | } | |
692 | else // left or top | |
693 | { | |
694 | if (ty < 0 && (-ty == th)) | |
695 | ty = 0; | |
696 | if (tx < 0 && (-tx == tw)) | |
697 | tx = 0; | |
698 | } | |
699 | ||
700 | int desiredW = tw; | |
701 | int desiredH = th; | |
702 | ||
703 | if ( toolbar->IsVertical() ) | |
704 | { | |
705 | desiredH = height; | |
706 | } | |
707 | else | |
708 | { | |
709 | desiredW = width; | |
710 | } | |
711 | ||
712 | // use the 'real' MSW position here, don't offset relativly to the | |
713 | // client area origin | |
714 | ||
715 | // Optimise such that we don't have to always resize the toolbar | |
716 | // when the frame changes, otherwise we'll get a lot of flicker. | |
717 | bool heightChanging wxDUMMY_INITIALIZE(true); | |
718 | bool widthChanging wxDUMMY_INITIALIZE(true); | |
719 | ||
720 | if ( toolbar->IsVertical() ) | |
721 | { | |
722 | // It's OK if the current height is greater than what can be shown. | |
723 | heightChanging = (desiredH > th) ; | |
724 | widthChanging = (desiredW != tw) ; | |
725 | ||
726 | // The next time around, we may not have to set the size | |
727 | if (heightChanging) | |
728 | desiredH = desiredH + 200; | |
729 | } | |
730 | else | |
731 | { | |
732 | // It's OK if the current width is greater than what can be shown. | |
733 | widthChanging = (desiredW > tw) ; | |
734 | heightChanging = (desiredH != th) ; | |
735 | ||
736 | // The next time around, we may not have to set the size | |
737 | if (widthChanging) | |
738 | desiredW = desiredW + 200; | |
739 | } | |
740 | ||
741 | if (tx != 0 || ty != 0 || widthChanging || heightChanging) | |
742 | toolbar->SetSize(x, y, desiredW, desiredH, wxSIZE_NO_ADJUSTMENTS); | |
743 | ||
744 | } | |
745 | #endif // !WINCE_WITH_COMMANDBAR | |
746 | } | |
747 | ||
748 | #endif // wxUSE_TOOLBAR | |
749 | ||
750 | // ---------------------------------------------------------------------------- | |
751 | // frame state (iconized/maximized/...) | |
752 | // ---------------------------------------------------------------------------- | |
753 | ||
754 | // propagate our state change to all child frames: this allows us to emulate X | |
755 | // Windows behaviour where child frames float independently of the parent one | |
756 | // on the desktop, but are iconized/restored with it | |
757 | void wxFrame::IconizeChildFrames(bool bIconize) | |
758 | { | |
759 | m_iconized = bIconize; | |
760 | ||
761 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
762 | node; | |
763 | node = node->GetNext() ) | |
764 | { | |
765 | wxWindow *win = node->GetData(); | |
766 | ||
767 | // iconizing the frames with this style under Win95 shell puts them at | |
768 | // the bottom of the screen (as the MDI children) instead of making | |
769 | // them appear in the taskbar because they are, by virtue of this | |
770 | // style, not managed by the taskbar - instead leave Windows take care | |
771 | // of them | |
772 | if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW ) | |
773 | continue; | |
774 | ||
775 | // the child MDI frames are a special case and should not be touched by | |
776 | // the parent frame - instead, they are managed by the user | |
777 | wxFrame *frame = wxDynamicCast(win, wxFrame); | |
778 | if ( frame | |
779 | #if wxUSE_MDI_ARCHITECTURE | |
780 | && !frame->IsMDIChild() | |
781 | #endif // wxUSE_MDI_ARCHITECTURE | |
782 | ) | |
783 | { | |
784 | // we don't want to restore the child frames which had been | |
785 | // iconized even before we were iconized, so save the child frame | |
786 | // status when iconizing the parent frame and check it when | |
787 | // restoring it | |
788 | if ( bIconize ) | |
789 | { | |
790 | frame->m_wasMinimized = frame->IsIconized(); | |
791 | } | |
792 | ||
793 | // note that we shouldn't touch the hidden frames neither because | |
794 | // iconizing/restoring them would show them as a side effect | |
795 | if ( !frame->m_wasMinimized && frame->IsShown() ) | |
796 | frame->Iconize(bIconize); | |
797 | } | |
798 | } | |
799 | } | |
800 | ||
801 | WXHICON wxFrame::GetDefaultIcon() const | |
802 | { | |
803 | // we don't have any standard icons (any more) | |
804 | return (WXHICON)0; | |
805 | } | |
806 | ||
807 | // =========================================================================== | |
808 | // message processing | |
809 | // =========================================================================== | |
810 | ||
811 | // --------------------------------------------------------------------------- | |
812 | // preprocessing | |
813 | // --------------------------------------------------------------------------- | |
814 | ||
815 | bool wxFrame::MSWDoTranslateMessage(wxFrame *frame, WXMSG *pMsg) | |
816 | { | |
817 | if ( wxWindow::MSWTranslateMessage(pMsg) ) | |
818 | return true; | |
819 | ||
820 | #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__) | |
821 | // try the menu bar accelerators | |
822 | wxMenuBar *menuBar = GetMenuBar(); | |
823 | if ( menuBar && menuBar->GetAcceleratorTable()->Translate(frame, pMsg) ) | |
824 | return true; | |
825 | #endif // wxUSE_MENUS && wxUSE_ACCEL | |
826 | ||
827 | return false; | |
828 | } | |
829 | ||
830 | // --------------------------------------------------------------------------- | |
831 | // our private (non virtual) message handlers | |
832 | // --------------------------------------------------------------------------- | |
833 | ||
834 | bool wxFrame::HandleSize(int WXUNUSED(x), int WXUNUSED(y), WXUINT id) | |
835 | { | |
836 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) | |
837 | switch ( id ) | |
838 | { | |
839 | case SIZE_RESTORED: | |
840 | case SIZE_MAXIMIZED: | |
841 | // only do it it if we were iconized before, otherwise resizing the | |
842 | // parent frame has a curious side effect of bringing it under it's | |
843 | // children | |
844 | if ( !m_iconized ) | |
845 | break; | |
846 | ||
847 | // restore all child frames too | |
848 | IconizeChildFrames(false); | |
849 | ||
850 | (void)SendIconizeEvent(false); | |
851 | break; | |
852 | ||
853 | case SIZE_MINIMIZED: | |
854 | // iconize all child frames too | |
855 | IconizeChildFrames(true); | |
856 | break; | |
857 | } | |
858 | #else | |
859 | wxUnusedVar(id); | |
860 | #endif // !__WXWINCE__ | |
861 | ||
862 | if ( !m_iconized ) | |
863 | { | |
864 | #if wxUSE_STATUSBAR | |
865 | PositionStatusBar(); | |
866 | #endif // wxUSE_STATUSBAR | |
867 | ||
868 | #if wxUSE_TOOLBAR | |
869 | PositionToolBar(); | |
870 | #endif // wxUSE_TOOLBAR | |
871 | ||
872 | #if defined(WINCE_WITH_COMMANDBAR) | |
873 | // Position the menu command bar | |
874 | if (GetMenuBar() && GetMenuBar()->GetCommandBar()) | |
875 | { | |
876 | RECT rect; | |
877 | ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect); | |
878 | wxSize clientSz = GetClientSize(); | |
879 | ||
880 | if ( !::MoveWindow((HWND) GetMenuBar()->GetCommandBar(), 0, 0, clientSz.x, rect.bottom - rect.top, true ) ) | |
881 | { | |
882 | wxLogLastError(wxT("MoveWindow")); | |
883 | } | |
884 | ||
885 | } | |
886 | #endif // WINCE_WITH_COMMANDBAR | |
887 | } | |
888 | ||
889 | // call the base class version to generate the appropriate events | |
890 | return false; | |
891 | } | |
892 | ||
893 | bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control) | |
894 | { | |
895 | #if wxUSE_MENUS | |
896 | ||
897 | #if defined(WINCE_WITHOUT_COMMANDBAR) | |
898 | if (GetToolBar() && GetToolBar()->FindById(id)) | |
899 | return GetToolBar()->MSWCommand(cmd, id); | |
900 | #endif | |
901 | ||
902 | // we only need to handle the menu and accelerator commands from the items | |
903 | // of our menu bar, base wxWindow class already handles the rest | |
904 | if ( !control && (cmd == 0 /* menu */ || cmd == 1 /* accel */) ) | |
905 | { | |
906 | #if wxUSE_MENUS_NATIVE | |
907 | if ( !wxCurrentPopupMenu ) | |
908 | #endif // wxUSE_MENUS_NATIVE | |
909 | { | |
910 | wxMenuItem * const mitem = FindItemInMenuBar((signed short)id); | |
911 | if ( mitem ) | |
912 | return ProcessCommand(mitem); | |
913 | } | |
914 | } | |
915 | #endif // wxUSE_MENUS | |
916 | ||
917 | return wxFrameBase::HandleCommand(id, cmd, control);; | |
918 | } | |
919 | ||
920 | #if wxUSE_MENUS | |
921 | ||
922 | bool | |
923 | wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU WXUNUSED(hMenu)) | |
924 | { | |
925 | // WM_MENUSELECT is generated for both normal items and menus, including | |
926 | // the top level menus of the menu bar, which can't be represented using | |
927 | // any valid identifier in wxMenuEvent so use -1 for them | |
928 | // the menu highlight events for n | |
929 | const int item = flags & (MF_POPUP | MF_SEPARATOR) ? -1 : nItem; | |
930 | ||
931 | wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item); | |
932 | event.SetEventObject(this); | |
933 | ||
934 | if ( HandleWindowEvent(event) ) | |
935 | return true; | |
936 | ||
937 | // by default, i.e. if the event wasn't handled above, clear the status bar | |
938 | // text when an item which can't have any associated help string in wx API | |
939 | // is selected | |
940 | if ( item == -1 ) | |
941 | DoGiveHelp(wxEmptyString, true); | |
942 | ||
943 | return false; | |
944 | } | |
945 | ||
946 | bool wxFrame::HandleMenuLoop(const wxEventType& evtType, WXWORD isPopup) | |
947 | { | |
948 | // we don't have the menu id here, so we use the id to specify if the event | |
949 | // was from a popup menu or a normal one | |
950 | wxMenuEvent event(evtType, isPopup ? -1 : 0); | |
951 | event.SetEventObject(this); | |
952 | ||
953 | return HandleWindowEvent(event); | |
954 | } | |
955 | ||
956 | bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu) | |
957 | { | |
958 | wxMenu* menu = NULL; | |
959 | if (GetMenuBar()) | |
960 | { | |
961 | int nCount = GetMenuBar()->GetMenuCount(); | |
962 | for (int n = 0; n < nCount; n++) | |
963 | { | |
964 | if (GetMenuBar()->GetMenu(n)->GetHMenu() == hMenu) | |
965 | { | |
966 | menu = GetMenuBar()->GetMenu(n); | |
967 | break; | |
968 | } | |
969 | } | |
970 | } | |
971 | ||
972 | wxMenuEvent event(wxEVT_MENU_OPEN, 0, menu); | |
973 | event.SetEventObject(this); | |
974 | ||
975 | return HandleWindowEvent(event); | |
976 | } | |
977 | ||
978 | #endif // wxUSE_MENUS | |
979 | ||
980 | // --------------------------------------------------------------------------- | |
981 | // the window proc for wxFrame | |
982 | // --------------------------------------------------------------------------- | |
983 | ||
984 | WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) | |
985 | { | |
986 | WXLRESULT rc = 0; | |
987 | bool processed = false; | |
988 | ||
989 | switch ( message ) | |
990 | { | |
991 | case WM_CLOSE: | |
992 | // if we can't close, tell the system that we processed the | |
993 | // message - otherwise it would close us | |
994 | processed = !Close(); | |
995 | break; | |
996 | ||
997 | case WM_SIZE: | |
998 | processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam); | |
999 | break; | |
1000 | ||
1001 | case WM_COMMAND: | |
1002 | { | |
1003 | WORD id, cmd; | |
1004 | WXHWND hwnd; | |
1005 | UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam, | |
1006 | &id, &hwnd, &cmd); | |
1007 | ||
1008 | HandleCommand(id, cmd, (WXHWND)hwnd); | |
1009 | ||
1010 | // don't pass WM_COMMAND to the base class whether we processed | |
1011 | // it or not because we did generate an event for it (our | |
1012 | // HandleCommand() calls the base class version) and we must | |
1013 | // not do it again or the handlers which skip the event would | |
1014 | // be called twice | |
1015 | processed = true; | |
1016 | } | |
1017 | break; | |
1018 | ||
1019 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) | |
1020 | #if wxUSE_MENUS | |
1021 | case WM_INITMENUPOPUP: | |
1022 | processed = HandleInitMenuPopup((WXHMENU) wParam); | |
1023 | break; | |
1024 | ||
1025 | case WM_MENUSELECT: | |
1026 | { | |
1027 | WXWORD item, flags; | |
1028 | WXHMENU hmenu; | |
1029 | UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu); | |
1030 | ||
1031 | processed = HandleMenuSelect(item, flags, hmenu); | |
1032 | } | |
1033 | break; | |
1034 | ||
1035 | case WM_EXITMENULOOP: | |
1036 | processed = HandleMenuLoop(wxEVT_MENU_CLOSE, (WXWORD)wParam); | |
1037 | break; | |
1038 | #endif // wxUSE_MENUS | |
1039 | ||
1040 | case WM_QUERYDRAGICON: | |
1041 | { | |
1042 | const wxIcon& icon = GetIcon(); | |
1043 | HICON hIcon = icon.Ok() ? GetHiconOf(icon) | |
1044 | : (HICON)GetDefaultIcon(); | |
1045 | rc = (WXLRESULT)hIcon; | |
1046 | processed = rc != 0; | |
1047 | } | |
1048 | break; | |
1049 | #endif // !__WXMICROWIN__ | |
1050 | } | |
1051 | ||
1052 | if ( !processed ) | |
1053 | rc = wxFrameBase::MSWWindowProc(message, wParam, lParam); | |
1054 | ||
1055 | return rc; | |
1056 | } | |
1057 | ||
1058 | // ---------------------------------------------------------------------------- | |
1059 | // wxFrame size management: we exclude the areas taken by menu/status/toolbars | |
1060 | // from the client area, so the client area is what's really available for the | |
1061 | // frame contents | |
1062 | // ---------------------------------------------------------------------------- | |
1063 | ||
1064 | // get the origin of the client area in the client coordinates | |
1065 | wxPoint wxFrame::GetClientAreaOrigin() const | |
1066 | { | |
1067 | wxPoint pt = wxTopLevelWindow::GetClientAreaOrigin(); | |
1068 | ||
1069 | #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \ | |
1070 | (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__))) | |
1071 | wxToolBar * const toolbar = GetToolBar(); | |
1072 | if ( toolbar && toolbar->IsShown() ) | |
1073 | { | |
1074 | const wxSize sizeTB = toolbar->GetSize(); | |
1075 | ||
1076 | if ( toolbar->HasFlag(wxTB_TOP) ) | |
1077 | { | |
1078 | pt.y += sizeTB.y; | |
1079 | } | |
1080 | else if ( toolbar->HasFlag(wxTB_LEFT) ) | |
1081 | { | |
1082 | pt.x += sizeTB.x; | |
1083 | } | |
1084 | } | |
1085 | #endif // wxUSE_TOOLBAR | |
1086 | ||
1087 | #if defined(WINCE_WITH_COMMANDBAR) | |
1088 | if (GetMenuBar() && GetMenuBar()->GetCommandBar()) | |
1089 | { | |
1090 | RECT rect; | |
1091 | ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect); | |
1092 | pt.y += (rect.bottom - rect.top); | |
1093 | } | |
1094 | #endif | |
1095 | ||
1096 | return pt; | |
1097 | } |