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