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