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