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