]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: msw/frame.cpp | |
3 | // Purpose: wxFrameMSW | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #ifdef __GNUG__ | |
21 | #pragma implementation "frame.h" | |
22 | #endif | |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
28 | #pragma hdrstop | |
29 | #endif | |
30 | ||
31 | #ifndef WX_PRECOMP | |
32 | #include "wx/frame.h" | |
33 | #include "wx/app.h" | |
34 | #include "wx/menu.h" | |
35 | #include "wx/utils.h" | |
36 | #include "wx/dialog.h" | |
37 | #include "wx/settings.h" | |
38 | #include "wx/dcclient.h" | |
39 | #include "wx/mdi.h" | |
40 | #include "wx/panel.h" | |
41 | #endif // WX_PRECOMP | |
42 | ||
43 | #include "wx/msw/private.h" | |
44 | ||
45 | #if wxUSE_STATUSBAR | |
46 | #include "wx/statusbr.h" | |
47 | #include "wx/generic/statusbr.h" | |
48 | #endif // wxUSE_STATUSBAR | |
49 | ||
50 | #if wxUSE_TOOLBAR | |
51 | #include "wx/toolbar.h" | |
52 | #endif // wxUSE_TOOLBAR | |
53 | ||
54 | #include "wx/menuitem.h" | |
55 | #include "wx/log.h" | |
56 | ||
57 | #ifdef __WXUNIVERSAL__ | |
58 | #include "wx/univ/theme.h" | |
59 | #include "wx/univ/colschem.h" | |
60 | #endif // __WXUNIVERSAL__ | |
61 | ||
62 | // ---------------------------------------------------------------------------- | |
63 | // globals | |
64 | // ---------------------------------------------------------------------------- | |
65 | ||
66 | extern wxWindowList wxModelessWindows; | |
67 | extern wxList WXDLLEXPORT wxPendingDelete; | |
68 | extern const wxChar *wxFrameClassName; | |
69 | ||
70 | #if wxUSE_MENUS_NATIVE | |
71 | extern wxMenu *wxCurrentPopupMenu; | |
72 | #endif // wxUSE_MENUS_NATIVE | |
73 | ||
74 | // ---------------------------------------------------------------------------- | |
75 | // event tables | |
76 | // ---------------------------------------------------------------------------- | |
77 | ||
78 | BEGIN_EVENT_TABLE(wxFrameMSW, wxFrameBase) | |
79 | EVT_ACTIVATE(wxFrameMSW::OnActivate) | |
80 | EVT_SYS_COLOUR_CHANGED(wxFrameMSW::OnSysColourChanged) | |
81 | END_EVENT_TABLE() | |
82 | ||
83 | IMPLEMENT_DYNAMIC_CLASS(wxFrameMSW, wxWindow) | |
84 | ||
85 | // ============================================================================ | |
86 | // implementation | |
87 | // ============================================================================ | |
88 | ||
89 | // ---------------------------------------------------------------------------- | |
90 | // static class members | |
91 | // ---------------------------------------------------------------------------- | |
92 | ||
93 | #if wxUSE_STATUSBAR | |
94 | #if wxUSE_NATIVE_STATUSBAR | |
95 | bool wxFrameMSW::m_useNativeStatusBar = TRUE; | |
96 | #else | |
97 | bool wxFrameMSW::m_useNativeStatusBar = FALSE; | |
98 | #endif | |
99 | #endif // wxUSE_NATIVE_STATUSBAR | |
100 | ||
101 | // ---------------------------------------------------------------------------- | |
102 | // creation/destruction | |
103 | // ---------------------------------------------------------------------------- | |
104 | ||
105 | void wxFrameMSW::Init() | |
106 | { | |
107 | m_iconized = | |
108 | m_maximizeOnShow = FALSE; | |
109 | ||
110 | #if wxUSE_TOOLTIPS | |
111 | m_hwndToolTip = 0; | |
112 | #endif | |
113 | ||
114 | // Data to save/restore when calling ShowFullScreen | |
115 | m_fsStyle = 0; | |
116 | m_fsOldWindowStyle = 0; | |
117 | m_fsStatusBarFields = 0; | |
118 | m_fsStatusBarHeight = 0; | |
119 | m_fsToolBarHeight = 0; | |
120 | // m_fsMenu = 0; | |
121 | m_fsIsMaximized = FALSE; | |
122 | m_fsIsShowing = FALSE; | |
123 | ||
124 | m_winLastFocused = (wxWindow *)NULL; | |
125 | ||
126 | // unlike (almost?) all other windows, frames are created hidden | |
127 | m_isShown = FALSE; | |
128 | } | |
129 | ||
130 | bool wxFrameMSW::Create(wxWindow *parent, | |
131 | wxWindowID id, | |
132 | const wxString& title, | |
133 | const wxPoint& pos, | |
134 | const wxSize& size, | |
135 | long style, | |
136 | const wxString& name) | |
137 | { | |
138 | SetName(name); | |
139 | m_windowStyle = style; | |
140 | #if wxUSE_MENUS | |
141 | m_frameMenuBar = NULL; | |
142 | #endif // wxUSE_MENUS | |
143 | #if wxUSE_TOOLBAR | |
144 | m_frameToolBar = NULL; | |
145 | #endif // wxUSE_TOOLBAR | |
146 | #if wxUSE_STATUSBAR | |
147 | m_frameStatusBar = NULL; | |
148 | #endif // wxUSE_STATUSBAR | |
149 | ||
150 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
151 | ||
152 | if ( id > -1 ) | |
153 | m_windowId = id; | |
154 | else | |
155 | m_windowId = (int)NewControlId(); | |
156 | ||
157 | if (parent) parent->AddChild(this); | |
158 | ||
159 | int x = pos.x; | |
160 | int y = pos.y; | |
161 | int width = size.x; | |
162 | int height = size.y; | |
163 | ||
164 | m_iconized = FALSE; | |
165 | ||
166 | wxTopLevelWindows.Append(this); | |
167 | ||
168 | MSWCreate(m_windowId, parent, wxFrameClassName, this, title, | |
169 | x, y, width, height, style); | |
170 | ||
171 | wxModelessWindows.Append(this); | |
172 | ||
173 | return TRUE; | |
174 | } | |
175 | ||
176 | wxFrameMSW::~wxFrameMSW() | |
177 | { | |
178 | m_isBeingDeleted = TRUE; | |
179 | wxTopLevelWindows.DeleteObject(this); | |
180 | ||
181 | // the ~wxToolBar() code relies on the previous line to be executed before | |
182 | // this one, i.e. the frame should remove itself from wxTopLevelWindows | |
183 | // before destorying its toolbar | |
184 | DeleteAllBars(); | |
185 | ||
186 | if (wxTheApp && (wxTopLevelWindows.Number() == 0)) | |
187 | { | |
188 | wxTheApp->SetTopWindow(NULL); | |
189 | ||
190 | if (wxTheApp->GetExitOnFrameDelete()) | |
191 | { | |
192 | PostQuitMessage(0); | |
193 | } | |
194 | } | |
195 | ||
196 | wxModelessWindows.DeleteObject(this); | |
197 | ||
198 | // For some reason, wxWindows can activate another task altogether | |
199 | // when a frame is destroyed after a modal dialog has been invoked. | |
200 | // Try to bring the parent to the top. | |
201 | // MT:Only do this if this frame is currently the active window, else weird | |
202 | // things start to happen | |
203 | if ( wxGetActiveWindow() == this ) | |
204 | if (GetParent() && GetParent()->GetHWND()) | |
205 | ::BringWindowToTop((HWND) GetParent()->GetHWND()); | |
206 | } | |
207 | ||
208 | // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. | |
209 | void wxFrameMSW::DoGetClientSize(int *x, int *y) const | |
210 | { | |
211 | RECT rect; | |
212 | ::GetClientRect(GetHwnd(), &rect); | |
213 | ||
214 | #if wxUSE_STATUSBAR | |
215 | if ( GetStatusBar() && GetStatusBar()->IsShown() ) | |
216 | { | |
217 | int statusX, statusY; | |
218 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
219 | rect.bottom -= statusY; | |
220 | } | |
221 | #endif // wxUSE_STATUSBAR | |
222 | ||
223 | wxPoint pt(GetClientAreaOrigin()); | |
224 | rect.bottom -= pt.y; | |
225 | rect.right -= pt.x; | |
226 | ||
227 | if ( x ) | |
228 | *x = rect.right; | |
229 | if ( y ) | |
230 | *y = rect.bottom; | |
231 | } | |
232 | ||
233 | // Set the client size (i.e. leave the calculation of borders etc. | |
234 | // to wxWindows) | |
235 | void wxFrameMSW::DoSetClientSize(int width, int height) | |
236 | { | |
237 | HWND hWnd = GetHwnd(); | |
238 | ||
239 | RECT rectClient; | |
240 | ::GetClientRect(hWnd, &rectClient); | |
241 | ||
242 | RECT rectTotal; | |
243 | ::GetWindowRect(hWnd, &rectTotal); | |
244 | ||
245 | // Find the difference between the entire window (title bar and all) | |
246 | // and the client area; add this to the new client size to move the | |
247 | // window | |
248 | width += rectTotal.right - rectTotal.left - rectClient.right; | |
249 | height += rectTotal.bottom - rectTotal.top - rectClient.bottom; | |
250 | ||
251 | #if wxUSE_STATUSBAR | |
252 | wxStatusBar *statbar = GetStatusBar(); | |
253 | if ( statbar && statbar->IsShown() ) | |
254 | { | |
255 | // leave enough space for the status bar | |
256 | height += statbar->GetSize().y; | |
257 | } | |
258 | #endif // wxUSE_STATUSBAR | |
259 | ||
260 | // note that this takes the toolbar into account | |
261 | wxPoint pt = GetClientAreaOrigin(); | |
262 | width += pt.x; | |
263 | height += pt.y; | |
264 | ||
265 | if ( !::MoveWindow(hWnd, rectTotal.left, rectTotal.top, | |
266 | width, height, TRUE /* redraw */) ) | |
267 | { | |
268 | wxLogLastError(_T("MoveWindow")); | |
269 | } | |
270 | ||
271 | wxSizeEvent event(wxSize(width, height), m_windowId); | |
272 | event.SetEventObject(this); | |
273 | GetEventHandler()->ProcessEvent(event); | |
274 | } | |
275 | ||
276 | void wxFrameMSW::DoGetSize(int *width, int *height) const | |
277 | { | |
278 | RECT rect; | |
279 | ::GetWindowRect(GetHwnd(), &rect); | |
280 | ||
281 | *width = rect.right - rect.left; | |
282 | *height = rect.bottom - rect.top; | |
283 | } | |
284 | ||
285 | void wxFrameMSW::DoGetPosition(int *x, int *y) const | |
286 | { | |
287 | RECT rect; | |
288 | ::GetWindowRect(GetHwnd(), &rect); | |
289 | ||
290 | *x = rect.left; | |
291 | *y = rect.top; | |
292 | } | |
293 | ||
294 | // ---------------------------------------------------------------------------- | |
295 | // variations around ::ShowWindow() | |
296 | // ---------------------------------------------------------------------------- | |
297 | ||
298 | void wxFrameMSW::DoShowWindow(int nShowCmd) | |
299 | { | |
300 | ::ShowWindow(GetHwnd(), nShowCmd); | |
301 | ||
302 | m_iconized = nShowCmd == SW_MINIMIZE; | |
303 | } | |
304 | ||
305 | bool wxFrameMSW::Show(bool show) | |
306 | { | |
307 | // don't use wxWindow version as we want to call DoShowWindow() | |
308 | if ( !wxWindowBase::Show(show) ) | |
309 | return FALSE; | |
310 | ||
311 | int nShowCmd; | |
312 | if ( show ) | |
313 | { | |
314 | if ( m_maximizeOnShow ) | |
315 | { | |
316 | // show and maximize | |
317 | nShowCmd = SW_MAXIMIZE; | |
318 | ||
319 | m_maximizeOnShow = FALSE; | |
320 | } | |
321 | else // just show | |
322 | { | |
323 | nShowCmd = SW_SHOW; | |
324 | } | |
325 | } | |
326 | else // hide | |
327 | { | |
328 | nShowCmd = SW_HIDE; | |
329 | } | |
330 | ||
331 | DoShowWindow(nShowCmd); | |
332 | ||
333 | if ( show ) | |
334 | { | |
335 | ::BringWindowToTop(GetHwnd()); | |
336 | ||
337 | wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId); | |
338 | event.SetEventObject( this ); | |
339 | GetEventHandler()->ProcessEvent(event); | |
340 | } | |
341 | else // hide | |
342 | { | |
343 | // Try to highlight the correct window (the parent) | |
344 | if ( GetParent() ) | |
345 | { | |
346 | HWND hWndParent = GetHwndOf(GetParent()); | |
347 | if (hWndParent) | |
348 | ::BringWindowToTop(hWndParent); | |
349 | } | |
350 | } | |
351 | ||
352 | return TRUE; | |
353 | } | |
354 | ||
355 | void wxFrameMSW::Iconize(bool iconize) | |
356 | { | |
357 | DoShowWindow(iconize ? SW_MINIMIZE : SW_RESTORE); | |
358 | } | |
359 | ||
360 | void wxFrameMSW::Maximize(bool maximize) | |
361 | { | |
362 | if ( IsShown() ) | |
363 | { | |
364 | // just maximize it directly | |
365 | DoShowWindow(maximize ? SW_MAXIMIZE : SW_RESTORE); | |
366 | } | |
367 | else // hidden | |
368 | { | |
369 | // we can't maximize the hidden frame because it shows it as well, so | |
370 | // just remember that we should do it later in this case | |
371 | m_maximizeOnShow = TRUE; | |
372 | } | |
373 | } | |
374 | ||
375 | void wxFrameMSW::Restore() | |
376 | { | |
377 | DoShowWindow(SW_RESTORE); | |
378 | } | |
379 | ||
380 | bool wxFrameMSW::IsIconized() const | |
381 | { | |
382 | ((wxFrameMSW *)this)->m_iconized = (::IsIconic(GetHwnd()) != 0); | |
383 | return m_iconized; | |
384 | } | |
385 | ||
386 | // Is it maximized? | |
387 | bool wxFrameMSW::IsMaximized() const | |
388 | { | |
389 | return (::IsZoomed(GetHwnd()) != 0); | |
390 | } | |
391 | ||
392 | void wxFrameMSW::SetIcon(const wxIcon& icon) | |
393 | { | |
394 | wxFrameBase::SetIcon(icon); | |
395 | ||
396 | #if defined(__WIN95__) | |
397 | if ( m_icon.Ok() ) | |
398 | { | |
399 | SendMessage(GetHwnd(), WM_SETICON, | |
400 | (WPARAM)TRUE, (LPARAM)(HICON) m_icon.GetHICON()); | |
401 | } | |
402 | #endif // __WIN95__ | |
403 | } | |
404 | ||
405 | // generate an artificial resize event | |
406 | void wxFrame::SendSizeEvent() | |
407 | { | |
408 | RECT r; | |
409 | #ifdef __WIN16__ | |
410 | ::GetWindowRect(GetHwnd(), &r); | |
411 | #else | |
412 | if ( !::GetWindowRect(GetHwnd(), &r) ) | |
413 | { | |
414 | wxLogLastError(_T("GetWindowRect")); | |
415 | } | |
416 | #endif | |
417 | ||
418 | if ( !m_iconized ) | |
419 | { | |
420 | (void)::PostMessage(GetHwnd(), WM_SIZE, | |
421 | IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED, | |
422 | MAKELPARAM(r.right - r.left, r.bottom - r.top)); | |
423 | } | |
424 | } | |
425 | ||
426 | #if wxUSE_STATUSBAR | |
427 | wxStatusBar *wxFrameMSW::OnCreateStatusBar(int number, | |
428 | long style, | |
429 | wxWindowID id, | |
430 | const wxString& name) | |
431 | { | |
432 | wxStatusBar *statusBar = NULL; | |
433 | ||
434 | #if wxUSE_NATIVE_STATUSBAR | |
435 | if ( !UsesNativeStatusBar() ) | |
436 | { | |
437 | statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style); | |
438 | } | |
439 | else | |
440 | #endif | |
441 | { | |
442 | statusBar = new wxStatusBar(this, id, style, name); | |
443 | } | |
444 | ||
445 | // Set the height according to the font and the border size | |
446 | wxClientDC dc(statusBar); | |
447 | dc.SetFont(statusBar->GetFont()); | |
448 | ||
449 | wxCoord y; | |
450 | dc.GetTextExtent(_T("X"), NULL, &y ); | |
451 | ||
452 | int height = (int)( (11*y)/10 + 2*statusBar->GetBorderY()); | |
453 | ||
454 | statusBar->SetSize(-1, -1, -1, height); | |
455 | ||
456 | statusBar->SetFieldsCount(number); | |
457 | ||
458 | return statusBar; | |
459 | } | |
460 | ||
461 | void wxFrameMSW::PositionStatusBar() | |
462 | { | |
463 | if ( !m_frameStatusBar ) | |
464 | return; | |
465 | ||
466 | int w, h; | |
467 | GetClientSize(&w, &h); | |
468 | int sw, sh; | |
469 | m_frameStatusBar->GetSize(&sw, &sh); | |
470 | ||
471 | // Since we wish the status bar to be directly under the client area, | |
472 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
473 | m_frameStatusBar->SetSize(0, h, w, sh); | |
474 | } | |
475 | #endif // wxUSE_STATUSBAR | |
476 | ||
477 | void wxFrameMSW::DetachMenuBar() | |
478 | { | |
479 | #if wxUSE_MENUS | |
480 | if ( m_frameMenuBar ) | |
481 | { | |
482 | m_frameMenuBar->Detach(); | |
483 | m_frameMenuBar = NULL; | |
484 | } | |
485 | #endif // wxUSE_MENUS | |
486 | } | |
487 | ||
488 | void wxFrameMSW::SetMenuBar(wxMenuBar *menubar) | |
489 | { | |
490 | #if wxUSE_MENUS | |
491 | // detach the old menu bar in any case | |
492 | DetachMenuBar(); | |
493 | ||
494 | #if wxUSE_MENUS_NATIVE | |
495 | if ( !menubar ) | |
496 | { | |
497 | // actually remove the menu from the frame | |
498 | m_hMenu = (WXHMENU)0; | |
499 | InternalSetMenuBar(); | |
500 | } | |
501 | else // set new non NULL menu bar | |
502 | { | |
503 | // Can set a menubar several times. | |
504 | if ( menubar->GetHMenu() ) | |
505 | { | |
506 | m_hMenu = menubar->GetHMenu(); | |
507 | } | |
508 | else | |
509 | { | |
510 | menubar->Detach(); | |
511 | ||
512 | m_hMenu = menubar->Create(); | |
513 | ||
514 | if ( !m_hMenu ) | |
515 | return; | |
516 | } | |
517 | ||
518 | InternalSetMenuBar(); | |
519 | } | |
520 | #endif // wxUSE_MENUS_NATIVE | |
521 | ||
522 | if ( menubar ) | |
523 | { | |
524 | m_frameMenuBar = menubar; | |
525 | menubar->Attach((wxFrame *)this); | |
526 | } | |
527 | #endif // wxUSE_MENUS | |
528 | } | |
529 | ||
530 | #if wxUSE_MENUS_NATIVE | |
531 | ||
532 | void wxFrameMSW::InternalSetMenuBar() | |
533 | { | |
534 | if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) ) | |
535 | { | |
536 | wxLogLastError(wxT("SetMenu")); | |
537 | } | |
538 | } | |
539 | ||
540 | #endif // wxUSE_MENUS_NATIVE | |
541 | ||
542 | // Responds to colour changes, and passes event on to children. | |
543 | void wxFrameMSW::OnSysColourChanged(wxSysColourChangedEvent& event) | |
544 | { | |
545 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
546 | Refresh(); | |
547 | ||
548 | #if wxUSE_STATUSBAR | |
549 | if ( m_frameStatusBar ) | |
550 | { | |
551 | wxSysColourChangedEvent event2; | |
552 | event2.SetEventObject( m_frameStatusBar ); | |
553 | m_frameStatusBar->GetEventHandler()->ProcessEvent(event2); | |
554 | } | |
555 | #endif // wxUSE_STATUSBAR | |
556 | ||
557 | // Propagate the event to the non-top-level children | |
558 | wxWindow::OnSysColourChanged(event); | |
559 | } | |
560 | ||
561 | // Pass TRUE to show full screen, FALSE to restore. | |
562 | bool wxFrameMSW::ShowFullScreen(bool show, long style) | |
563 | { | |
564 | if (show) | |
565 | { | |
566 | if (IsFullScreen()) | |
567 | return FALSE; | |
568 | ||
569 | m_fsIsShowing = TRUE; | |
570 | m_fsStyle = style; | |
571 | ||
572 | #if wxUSE_TOOLBAR | |
573 | wxToolBar *theToolBar = GetToolBar(); | |
574 | if (theToolBar) | |
575 | theToolBar->GetSize(NULL, &m_fsToolBarHeight); | |
576 | ||
577 | // zap the toolbar, menubar, and statusbar | |
578 | ||
579 | if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar) | |
580 | { | |
581 | theToolBar->SetSize(-1,0); | |
582 | theToolBar->Show(FALSE); | |
583 | } | |
584 | #endif // wxUSE_TOOLBAR | |
585 | ||
586 | if (style & wxFULLSCREEN_NOMENUBAR) | |
587 | SetMenu((HWND)GetHWND(), (HMENU) NULL); | |
588 | ||
589 | #if wxUSE_STATUSBAR | |
590 | wxStatusBar *theStatusBar = GetStatusBar(); | |
591 | if (theStatusBar) | |
592 | theStatusBar->GetSize(NULL, &m_fsStatusBarHeight); | |
593 | ||
594 | // Save the number of fields in the statusbar | |
595 | if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar) | |
596 | { | |
597 | //m_fsStatusBarFields = theStatusBar->GetFieldsCount(); | |
598 | //SetStatusBar((wxStatusBar*) NULL); | |
599 | //delete theStatusBar; | |
600 | theStatusBar->Show(FALSE); | |
601 | } | |
602 | else | |
603 | m_fsStatusBarFields = 0; | |
604 | #endif // wxUSE_STATUSBAR | |
605 | ||
606 | // zap the frame borders | |
607 | ||
608 | // save the 'normal' window style | |
609 | m_fsOldWindowStyle = GetWindowLong((HWND)GetHWND(), GWL_STYLE); | |
610 | ||
611 | // save the old position, width & height, maximize state | |
612 | m_fsOldSize = GetRect(); | |
613 | m_fsIsMaximized = IsMaximized(); | |
614 | ||
615 | // decide which window style flags to turn off | |
616 | LONG newStyle = m_fsOldWindowStyle; | |
617 | LONG offFlags = 0; | |
618 | ||
619 | if (style & wxFULLSCREEN_NOBORDER) | |
620 | offFlags |= WS_BORDER; | |
621 | if (style & wxFULLSCREEN_NOCAPTION) | |
622 | offFlags |= (WS_CAPTION | WS_SYSMENU); | |
623 | ||
624 | newStyle &= (~offFlags); | |
625 | ||
626 | // change our window style to be compatible with full-screen mode | |
627 | SetWindowLong((HWND)GetHWND(), GWL_STYLE, newStyle); | |
628 | ||
629 | // resize to the size of the desktop | |
630 | int width, height; | |
631 | ||
632 | RECT rect; | |
633 | ::GetWindowRect(GetDesktopWindow(), &rect); | |
634 | width = rect.right - rect.left; | |
635 | height = rect.bottom - rect.top; | |
636 | ||
637 | SetSize(width, height); | |
638 | ||
639 | // now flush the window style cache and actually go full-screen | |
640 | SetWindowPos((HWND)GetHWND(), HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED); | |
641 | ||
642 | wxSizeEvent event(wxSize(width, height), GetId()); | |
643 | GetEventHandler()->ProcessEvent(event); | |
644 | ||
645 | return TRUE; | |
646 | } | |
647 | else | |
648 | { | |
649 | if (!IsFullScreen()) | |
650 | return FALSE; | |
651 | ||
652 | m_fsIsShowing = FALSE; | |
653 | ||
654 | #if wxUSE_TOOLBAR | |
655 | wxToolBar *theToolBar = GetToolBar(); | |
656 | ||
657 | // restore the toolbar, menubar, and statusbar | |
658 | if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR)) | |
659 | { | |
660 | theToolBar->SetSize(-1, m_fsToolBarHeight); | |
661 | theToolBar->Show(TRUE); | |
662 | } | |
663 | #endif // wxUSE_TOOLBAR | |
664 | ||
665 | #if wxUSE_STATUSBAR | |
666 | if ( m_fsStyle & wxFULLSCREEN_NOSTATUSBAR ) | |
667 | { | |
668 | //CreateStatusBar(m_fsStatusBarFields); | |
669 | if (GetStatusBar()) | |
670 | { | |
671 | GetStatusBar()->Show(TRUE); | |
672 | PositionStatusBar(); | |
673 | } | |
674 | } | |
675 | #endif // wxUSE_STATUSBAR | |
676 | ||
677 | if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0)) | |
678 | SetMenu((HWND)GetHWND(), (HMENU)m_hMenu); | |
679 | ||
680 | Maximize(m_fsIsMaximized); | |
681 | SetWindowLong((HWND)GetHWND(),GWL_STYLE, m_fsOldWindowStyle); | |
682 | SetWindowPos((HWND)GetHWND(),HWND_TOP,m_fsOldSize.x, m_fsOldSize.y, | |
683 | m_fsOldSize.width, m_fsOldSize.height, SWP_FRAMECHANGED); | |
684 | ||
685 | return TRUE; | |
686 | } | |
687 | } | |
688 | ||
689 | /* | |
690 | * Frame window | |
691 | * | |
692 | */ | |
693 | ||
694 | bool wxFrameMSW::MSWCreate(int id, wxWindow *parent, const wxChar *wclass, wxWindow *wx_win, const wxChar *title, | |
695 | int x, int y, int width, int height, long style) | |
696 | ||
697 | { | |
698 | m_defaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON); | |
699 | ||
700 | // If child windows aren't properly drawn initially, WS_CLIPCHILDREN | |
701 | // could be the culprit. But without it, you can get a lot of flicker. | |
702 | ||
703 | DWORD msflags = 0; | |
704 | if ( style & wxCAPTION ) | |
705 | { | |
706 | if ( style & wxFRAME_TOOL_WINDOW ) | |
707 | msflags |= WS_POPUPWINDOW; | |
708 | else | |
709 | msflags |= WS_OVERLAPPED; | |
710 | } | |
711 | else | |
712 | { | |
713 | msflags |= WS_POPUP; | |
714 | } | |
715 | ||
716 | if (style & wxMINIMIZE_BOX) | |
717 | msflags |= WS_MINIMIZEBOX; | |
718 | if (style & wxMAXIMIZE_BOX) | |
719 | msflags |= WS_MAXIMIZEBOX; | |
720 | if (style & wxTHICK_FRAME) | |
721 | msflags |= WS_THICKFRAME; | |
722 | if (style & wxSYSTEM_MENU) | |
723 | msflags |= WS_SYSMENU; | |
724 | if ( style & wxMINIMIZE ) | |
725 | msflags |= WS_MINIMIZE; | |
726 | if (style & wxMAXIMIZE) | |
727 | msflags |= WS_MAXIMIZE; | |
728 | if (style & wxCAPTION) | |
729 | msflags |= WS_CAPTION; | |
730 | if (style & wxCLIP_CHILDREN) | |
731 | msflags |= WS_CLIPCHILDREN; | |
732 | ||
733 | // Keep this in wxFrameMSW because it saves recoding this function | |
734 | // in wxTinyFrame | |
735 | #if wxUSE_ITSY_BITSY && !defined(__WIN32__) | |
736 | if (style & wxTINY_CAPTION_VERT) | |
737 | msflags |= IBS_VERTCAPTION; | |
738 | if (style & wxTINY_CAPTION_HORIZ) | |
739 | msflags |= IBS_HORZCAPTION; | |
740 | #else | |
741 | if (style & wxTINY_CAPTION_VERT) | |
742 | msflags |= WS_CAPTION; | |
743 | if (style & wxTINY_CAPTION_HORIZ) | |
744 | msflags |= WS_CAPTION; | |
745 | #endif | |
746 | if ((style & wxTHICK_FRAME) == 0) | |
747 | msflags |= WS_BORDER; | |
748 | ||
749 | WXDWORD extendedStyle = MakeExtendedStyle(style); | |
750 | ||
751 | // make all frames appear in the win9x shell taskbar unless | |
752 | // wxFRAME_TOOL_WINDOW or wxFRAME_NO_TASKBAR is given - without giving them | |
753 | // WS_EX_APPWINDOW style, the child (i.e. owned) frames wouldn't appear in it | |
754 | #if !defined(__WIN16__) && !defined(__SC__) | |
755 | if ( (style & wxFRAME_TOOL_WINDOW) || | |
756 | (style & wxFRAME_NO_TASKBAR) ) | |
757 | extendedStyle |= WS_EX_TOOLWINDOW; | |
758 | else if ( !(style & wxFRAME_NO_TASKBAR) ) | |
759 | extendedStyle |= WS_EX_APPWINDOW; | |
760 | #endif | |
761 | ||
762 | if (style & wxSTAY_ON_TOP) | |
763 | extendedStyle |= WS_EX_TOPMOST; | |
764 | ||
765 | #ifndef __WIN16__ | |
766 | if (m_exStyle & wxFRAME_EX_CONTEXTHELP) | |
767 | extendedStyle |= WS_EX_CONTEXTHELP; | |
768 | #endif | |
769 | ||
770 | m_iconized = FALSE; | |
771 | if ( !wxWindow::MSWCreate(id, parent, wclass, wx_win, title, x, y, width, height, | |
772 | msflags, NULL, extendedStyle) ) | |
773 | return FALSE; | |
774 | ||
775 | // Seems to be necessary if we use WS_POPUP | |
776 | // style instead of WS_OVERLAPPED | |
777 | if (width > -1 && height > -1) | |
778 | ::PostMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(width, height)); | |
779 | ||
780 | return TRUE; | |
781 | } | |
782 | ||
783 | // Default activation behaviour - set the focus for the first child | |
784 | // subwindow found. | |
785 | void wxFrameMSW::OnActivate(wxActivateEvent& event) | |
786 | { | |
787 | if ( event.GetActive() ) | |
788 | { | |
789 | // restore focus to the child which was last focused | |
790 | wxLogTrace(_T("focus"), _T("wxFrameMSW %08x activated."), m_hWnd); | |
791 | ||
792 | wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent() | |
793 | : NULL; | |
794 | if ( !parent ) | |
795 | { | |
796 | parent = this; | |
797 | } | |
798 | ||
799 | wxSetFocusToChild(parent, &m_winLastFocused); | |
800 | } | |
801 | else // deactivating | |
802 | { | |
803 | // remember the last focused child if it is our child | |
804 | m_winLastFocused = FindFocus(); | |
805 | ||
806 | // so we NULL it out if it's a child from some other frame | |
807 | wxWindow *win = m_winLastFocused; | |
808 | while ( win ) | |
809 | { | |
810 | if ( win->IsTopLevel() ) | |
811 | { | |
812 | if ( win != this ) | |
813 | { | |
814 | m_winLastFocused = NULL; | |
815 | } | |
816 | ||
817 | break; | |
818 | } | |
819 | ||
820 | win = win->GetParent(); | |
821 | } | |
822 | ||
823 | wxLogTrace(_T("focus"), | |
824 | _T("wxFrameMSW %08x deactivated, last focused: %08x."), | |
825 | m_hWnd, | |
826 | m_winLastFocused ? GetHwndOf(m_winLastFocused) | |
827 | : NULL); | |
828 | ||
829 | event.Skip(); | |
830 | } | |
831 | } | |
832 | ||
833 | // ---------------------------------------------------------------------------- | |
834 | // tool/status bar stuff | |
835 | // ---------------------------------------------------------------------------- | |
836 | ||
837 | #if wxUSE_TOOLBAR | |
838 | ||
839 | wxToolBar* wxFrameMSW::CreateToolBar(long style, wxWindowID id, const wxString& name) | |
840 | { | |
841 | if ( wxFrameBase::CreateToolBar(style, id, name) ) | |
842 | { | |
843 | PositionToolBar(); | |
844 | } | |
845 | ||
846 | return m_frameToolBar; | |
847 | } | |
848 | ||
849 | void wxFrameMSW::PositionToolBar() | |
850 | { | |
851 | RECT rect; | |
852 | ::GetClientRect(GetHwnd(), &rect); | |
853 | ||
854 | #if wxUSE_STATUSBAR | |
855 | if ( GetStatusBar() ) | |
856 | { | |
857 | int statusX, statusY; | |
858 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
859 | rect.bottom -= statusY; | |
860 | } | |
861 | #endif // wxUSE_STATUSBAR | |
862 | ||
863 | if ( GetToolBar() && GetToolBar()->IsShown() ) | |
864 | { | |
865 | int tw, th; | |
866 | GetToolBar()->GetSize(&tw, &th); | |
867 | ||
868 | if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL ) | |
869 | { | |
870 | th = rect.bottom; | |
871 | } | |
872 | else | |
873 | { | |
874 | tw = rect.right; | |
875 | } | |
876 | ||
877 | // Use the 'real' MSW position here | |
878 | GetToolBar()->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS); | |
879 | } | |
880 | } | |
881 | #endif // wxUSE_TOOLBAR | |
882 | ||
883 | // ---------------------------------------------------------------------------- | |
884 | // frame state (iconized/maximized/...) | |
885 | // ---------------------------------------------------------------------------- | |
886 | ||
887 | // propagate our state change to all child frames: this allows us to emulate X | |
888 | // Windows behaviour where child frames float independently of the parent one | |
889 | // on the desktop, but are iconized/restored with it | |
890 | void wxFrameMSW::IconizeChildFrames(bool bIconize) | |
891 | { | |
892 | for ( wxWindowList::Node *node = GetChildren().GetFirst(); | |
893 | node; | |
894 | node = node->GetNext() ) | |
895 | { | |
896 | wxWindow *win = node->GetData(); | |
897 | ||
898 | // iconizing the frames with this style under Win95 shell puts them at | |
899 | // the bottom of the screen (as the MDI children) instead of making | |
900 | // them appear in the taskbar because they are, by virtue of this | |
901 | // style, not managed by the taskbar - instead leave Windows take care | |
902 | // of them | |
903 | #ifdef __WIN95__ | |
904 | if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW ) | |
905 | continue; | |
906 | #endif // Win95 | |
907 | ||
908 | // the child MDI frames are a special case and should not be touched by | |
909 | // the parent frame - instead, they are managed by the user | |
910 | wxFrameMSW *frame = wxDynamicCast(win, wxFrameMSW); | |
911 | if ( frame | |
912 | #if wxUSE_MDI_ARCHITECTURE | |
913 | && !wxDynamicCast(frame, wxMDIChildFrame) | |
914 | #endif // wxUSE_MDI_ARCHITECTURE | |
915 | ) | |
916 | { | |
917 | frame->Iconize(bIconize); | |
918 | } | |
919 | } | |
920 | } | |
921 | ||
922 | // =========================================================================== | |
923 | // message processing | |
924 | // =========================================================================== | |
925 | ||
926 | // --------------------------------------------------------------------------- | |
927 | // preprocessing | |
928 | // --------------------------------------------------------------------------- | |
929 | ||
930 | bool wxFrameMSW::MSWTranslateMessage(WXMSG* pMsg) | |
931 | { | |
932 | if ( wxWindow::MSWTranslateMessage(pMsg) ) | |
933 | return TRUE; | |
934 | ||
935 | #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__) | |
936 | // try the menu bar accels | |
937 | wxMenuBar *menuBar = GetMenuBar(); | |
938 | if ( !menuBar ) | |
939 | return FALSE; | |
940 | ||
941 | const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable(); | |
942 | return acceleratorTable.Translate(this, pMsg); | |
943 | #else | |
944 | return FALSE; | |
945 | #endif // wxUSE_MENUS && wxUSE_ACCEL | |
946 | } | |
947 | ||
948 | // --------------------------------------------------------------------------- | |
949 | // our private (non virtual) message handlers | |
950 | // --------------------------------------------------------------------------- | |
951 | ||
952 | bool wxFrameMSW::HandlePaint() | |
953 | { | |
954 | RECT rect; | |
955 | if ( GetUpdateRect(GetHwnd(), &rect, FALSE) ) | |
956 | { | |
957 | if ( m_iconized ) | |
958 | { | |
959 | HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon) | |
960 | : (HICON)m_defaultIcon; | |
961 | ||
962 | // Hold a pointer to the dc so long as the OnPaint() message | |
963 | // is being processed | |
964 | PAINTSTRUCT ps; | |
965 | HDC hdc = ::BeginPaint(GetHwnd(), &ps); | |
966 | ||
967 | // Erase background before painting or we get white background | |
968 | MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L); | |
969 | ||
970 | if ( hIcon ) | |
971 | { | |
972 | RECT rect; | |
973 | ::GetClientRect(GetHwnd(), &rect); | |
974 | ||
975 | // FIXME: why hardcoded? | |
976 | static const int icon_width = 32; | |
977 | static const int icon_height = 32; | |
978 | ||
979 | int icon_x = (int)((rect.right - icon_width)/2); | |
980 | int icon_y = (int)((rect.bottom - icon_height)/2); | |
981 | ||
982 | ::DrawIcon(hdc, icon_x, icon_y, hIcon); | |
983 | } | |
984 | ||
985 | ::EndPaint(GetHwnd(), &ps); | |
986 | ||
987 | return TRUE; | |
988 | } | |
989 | else | |
990 | { | |
991 | return wxWindow::HandlePaint(); | |
992 | } | |
993 | } | |
994 | else | |
995 | { | |
996 | // nothing to paint - processed | |
997 | return TRUE; | |
998 | } | |
999 | } | |
1000 | ||
1001 | bool wxFrameMSW::HandleSize(int x, int y, WXUINT id) | |
1002 | { | |
1003 | bool processed = FALSE; | |
1004 | ||
1005 | switch ( id ) | |
1006 | { | |
1007 | case SIZENORMAL: | |
1008 | // only do it it if we were iconized before, otherwise resizing the | |
1009 | // parent frame has a curious side effect of bringing it under it's | |
1010 | // children | |
1011 | if ( !m_iconized ) | |
1012 | break; | |
1013 | ||
1014 | // restore all child frames too | |
1015 | IconizeChildFrames(FALSE); | |
1016 | ||
1017 | (void)SendIconizeEvent(FALSE); | |
1018 | ||
1019 | // fall through | |
1020 | ||
1021 | case SIZEFULLSCREEN: | |
1022 | m_iconized = FALSE; | |
1023 | break; | |
1024 | ||
1025 | case SIZEICONIC: | |
1026 | // iconize all child frames too | |
1027 | IconizeChildFrames(TRUE); | |
1028 | ||
1029 | (void)SendIconizeEvent(); | |
1030 | ||
1031 | m_iconized = TRUE; | |
1032 | break; | |
1033 | } | |
1034 | ||
1035 | if ( !m_iconized ) | |
1036 | { | |
1037 | #if wxUSE_STATUSBAR | |
1038 | PositionStatusBar(); | |
1039 | #endif // wxUSE_STATUSBAR | |
1040 | ||
1041 | #if wxUSE_TOOLBAR | |
1042 | PositionToolBar(); | |
1043 | #endif // wxUSE_TOOLBAR | |
1044 | ||
1045 | wxSizeEvent event(wxSize(x, y), m_windowId); | |
1046 | event.SetEventObject( this ); | |
1047 | processed = GetEventHandler()->ProcessEvent(event); | |
1048 | } | |
1049 | ||
1050 | return processed; | |
1051 | } | |
1052 | ||
1053 | bool wxFrameMSW::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control) | |
1054 | { | |
1055 | if ( control ) | |
1056 | { | |
1057 | // In case it's e.g. a toolbar. | |
1058 | wxWindow *win = wxFindWinFromHandle(control); | |
1059 | if ( win ) | |
1060 | return win->MSWCommand(cmd, id); | |
1061 | } | |
1062 | ||
1063 | // handle here commands from menus and accelerators | |
1064 | if ( cmd == 0 || cmd == 1 ) | |
1065 | { | |
1066 | #if wxUSE_MENUS_NATIVE | |
1067 | if ( wxCurrentPopupMenu ) | |
1068 | { | |
1069 | wxMenu *popupMenu = wxCurrentPopupMenu; | |
1070 | wxCurrentPopupMenu = NULL; | |
1071 | ||
1072 | return popupMenu->MSWCommand(cmd, id); | |
1073 | } | |
1074 | #endif // wxUSE_MENUS_NATIVE | |
1075 | ||
1076 | if ( ProcessCommand(id) ) | |
1077 | { | |
1078 | return TRUE; | |
1079 | } | |
1080 | } | |
1081 | ||
1082 | return FALSE; | |
1083 | } | |
1084 | ||
1085 | bool wxFrameMSW::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu) | |
1086 | { | |
1087 | int item; | |
1088 | if ( flags == 0xFFFF && hMenu == 0 ) | |
1089 | { | |
1090 | // menu was removed from screen | |
1091 | item = -1; | |
1092 | } | |
1093 | else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) ) | |
1094 | { | |
1095 | item = nItem; | |
1096 | } | |
1097 | else | |
1098 | { | |
1099 | #if wxUSE_STATUSBAR | |
1100 | // don't give hints for separators (doesn't make sense) nor for the | |
1101 | // items opening popup menus (they don't have them anyhow) but do clear | |
1102 | // the status line - otherwise, we would be left with the help message | |
1103 | // for the previous item which doesn't apply any more | |
1104 | wxStatusBar *statbar = GetStatusBar(); | |
1105 | if ( statbar ) | |
1106 | { | |
1107 | statbar->SetStatusText(wxEmptyString); | |
1108 | } | |
1109 | #endif // wxUSE_STATUSBAR | |
1110 | ||
1111 | return FALSE; | |
1112 | } | |
1113 | ||
1114 | wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item); | |
1115 | event.SetEventObject( this ); | |
1116 | ||
1117 | return GetEventHandler()->ProcessEvent(event); | |
1118 | } | |
1119 | ||
1120 | // --------------------------------------------------------------------------- | |
1121 | // the window proc for wxFrameMSW | |
1122 | // --------------------------------------------------------------------------- | |
1123 | ||
1124 | long wxFrameMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) | |
1125 | { | |
1126 | long rc = 0; | |
1127 | bool processed = FALSE; | |
1128 | ||
1129 | switch ( message ) | |
1130 | { | |
1131 | case WM_CLOSE: | |
1132 | // if we can't close, tell the system that we processed the | |
1133 | // message - otherwise it would close us | |
1134 | processed = !Close(); | |
1135 | break; | |
1136 | ||
1137 | case WM_COMMAND: | |
1138 | { | |
1139 | WORD id, cmd; | |
1140 | WXHWND hwnd; | |
1141 | UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam, | |
1142 | &id, &hwnd, &cmd); | |
1143 | ||
1144 | processed = HandleCommand(id, cmd, (WXHWND)hwnd); | |
1145 | } | |
1146 | break; | |
1147 | ||
1148 | case WM_MENUSELECT: | |
1149 | { | |
1150 | WXWORD item, flags; | |
1151 | WXHMENU hmenu; | |
1152 | UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu); | |
1153 | ||
1154 | processed = HandleMenuSelect(item, flags, hmenu); | |
1155 | } | |
1156 | break; | |
1157 | ||
1158 | case WM_PAINT: | |
1159 | processed = HandlePaint(); | |
1160 | break; | |
1161 | ||
1162 | case WM_QUERYDRAGICON: | |
1163 | { | |
1164 | HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon) | |
1165 | : (HICON)(m_defaultIcon); | |
1166 | rc = (long)hIcon; | |
1167 | processed = rc != 0; | |
1168 | } | |
1169 | break; | |
1170 | ||
1171 | case WM_SIZE: | |
1172 | processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam); | |
1173 | break; | |
1174 | } | |
1175 | ||
1176 | if ( !processed ) | |
1177 | rc = wxWindow::MSWWindowProc(message, wParam, lParam); | |
1178 | ||
1179 | return rc; | |
1180 | } | |
1181 |