1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "frame.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/dcclient.h"
43 #include "wx/msw/private.h"
46 #include "wx/statusbr.h"
47 #include "wx/generic/statusbr.h"
48 #endif // wxUSE_STATUSBAR
51 #include "wx/toolbar.h"
52 #endif // wxUSE_TOOLBAR
54 #include "wx/menuitem.h"
57 #ifdef __WXUNIVERSAL__
58 #include "wx/univ/theme.h"
59 #include "wx/univ/colschem.h"
60 #endif // __WXUNIVERSAL__
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 extern wxWindowList wxModelessWindows
;
67 extern wxList WXDLLEXPORT wxPendingDelete
;
68 extern const wxChar
*wxFrameClassName
;
70 #if wxUSE_MENUS_NATIVE
71 extern wxMenu
*wxCurrentPopupMenu
;
72 #endif // wxUSE_MENUS_NATIVE
74 // ----------------------------------------------------------------------------
76 // ----------------------------------------------------------------------------
78 BEGIN_EVENT_TABLE(wxFrameMSW
, wxFrameBase
)
79 EVT_ACTIVATE(wxFrameMSW::OnActivate
)
80 EVT_SYS_COLOUR_CHANGED(wxFrameMSW::OnSysColourChanged
)
83 IMPLEMENT_DYNAMIC_CLASS(wxFrameMSW
, wxWindow
)
84 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxFrameMSW
)
86 // ============================================================================
88 // ============================================================================
90 // ----------------------------------------------------------------------------
91 // static class members
92 // ----------------------------------------------------------------------------
95 #if wxUSE_NATIVE_STATUSBAR
96 bool wxFrameMSW::m_useNativeStatusBar
= TRUE
;
98 bool wxFrameMSW::m_useNativeStatusBar
= FALSE
;
100 #endif // wxUSE_NATIVE_STATUSBAR
102 // ----------------------------------------------------------------------------
103 // creation/destruction
104 // ----------------------------------------------------------------------------
106 void wxFrameMSW::Init()
109 m_maximizeOnShow
= FALSE
;
115 // Data to save/restore when calling ShowFullScreen
117 m_fsOldWindowStyle
= 0;
118 m_fsStatusBarFields
= 0;
119 m_fsStatusBarHeight
= 0;
120 m_fsToolBarHeight
= 0;
122 m_fsIsMaximized
= FALSE
;
123 m_fsIsShowing
= FALSE
;
125 m_winLastFocused
= (wxWindow
*)NULL
;
127 // unlike (almost?) all other windows, frames are created hidden
131 bool wxFrameMSW::Create(wxWindow
*parent
,
133 const wxString
& title
,
137 const wxString
& name
)
140 m_windowStyle
= style
;
142 m_frameMenuBar
= NULL
;
143 #endif // wxUSE_MENUS
145 m_frameToolBar
= NULL
;
146 #endif // wxUSE_TOOLBAR
148 m_frameStatusBar
= NULL
;
149 #endif // wxUSE_STATUSBAR
151 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
156 m_windowId
= (int)NewControlId();
158 if (parent
) parent
->AddChild(this);
167 wxTopLevelWindows
.Append(this);
169 MSWCreate(m_windowId
, parent
, wxFrameClassName
, this, title
,
170 x
, y
, width
, height
, style
);
172 wxModelessWindows
.Append(this);
177 wxFrameMSW::~wxFrameMSW()
179 m_isBeingDeleted
= TRUE
;
180 wxTopLevelWindows
.DeleteObject(this);
182 // the ~wxToolBar() code relies on the previous line to be executed before
183 // this one, i.e. the frame should remove itself from wxTopLevelWindows
184 // before destorying its toolbar
187 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
189 wxTheApp
->SetTopWindow(NULL
);
191 if (wxTheApp
->GetExitOnFrameDelete())
197 wxModelessWindows
.DeleteObject(this);
199 // For some reason, wxWindows can activate another task altogether
200 // when a frame is destroyed after a modal dialog has been invoked.
201 // Try to bring the parent to the top.
202 // MT:Only do this if this frame is currently the active window, else weird
203 // things start to happen
204 if ( wxGetActiveWindow() == this )
205 if (GetParent() && GetParent()->GetHWND())
206 ::BringWindowToTop((HWND
) GetParent()->GetHWND());
209 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
210 void wxFrameMSW::DoGetClientSize(int *x
, int *y
) const
213 ::GetClientRect(GetHwnd(), &rect
);
216 if ( GetStatusBar() && GetStatusBar()->IsShown() )
218 int statusX
, statusY
;
219 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
220 rect
.bottom
-= statusY
;
222 #endif // wxUSE_STATUSBAR
224 wxPoint
pt(GetClientAreaOrigin());
234 // Set the client size (i.e. leave the calculation of borders etc.
236 void wxFrameMSW::DoSetClientSize(int width
, int height
)
238 HWND hWnd
= GetHwnd();
241 ::GetClientRect(hWnd
, &rectClient
);
244 ::GetWindowRect(hWnd
, &rectTotal
);
246 // Find the difference between the entire window (title bar and all)
247 // and the client area; add this to the new client size to move the
249 width
+= rectTotal
.right
- rectTotal
.left
- rectClient
.right
;
250 height
+= rectTotal
.bottom
- rectTotal
.top
- rectClient
.bottom
;
253 wxStatusBar
*statbar
= GetStatusBar();
254 if ( statbar
&& statbar
->IsShown() )
256 // leave enough space for the status bar
257 height
+= statbar
->GetSize().y
;
259 #endif // wxUSE_STATUSBAR
261 // note that this takes the toolbar into account
262 wxPoint pt
= GetClientAreaOrigin();
266 if ( !::MoveWindow(hWnd
, rectTotal
.left
, rectTotal
.top
,
267 width
, height
, TRUE
/* redraw */) )
269 wxLogLastError(_T("MoveWindow"));
272 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
273 event
.SetEventObject(this);
274 GetEventHandler()->ProcessEvent(event
);
277 void wxFrameMSW::DoGetSize(int *width
, int *height
) const
280 ::GetWindowRect(GetHwnd(), &rect
);
282 *width
= rect
.right
- rect
.left
;
283 *height
= rect
.bottom
- rect
.top
;
286 void wxFrameMSW::DoGetPosition(int *x
, int *y
) const
289 ::GetWindowRect(GetHwnd(), &rect
);
295 // ----------------------------------------------------------------------------
296 // variations around ::ShowWindow()
297 // ----------------------------------------------------------------------------
299 void wxFrameMSW::DoShowWindow(int nShowCmd
)
301 ::ShowWindow(GetHwnd(), nShowCmd
);
303 m_iconized
= nShowCmd
== SW_MINIMIZE
;
306 bool wxFrameMSW::Show(bool show
)
308 // don't use wxWindow version as we want to call DoShowWindow()
309 if ( !wxWindowBase::Show(show
) )
315 if ( m_maximizeOnShow
)
318 nShowCmd
= SW_MAXIMIZE
;
320 m_maximizeOnShow
= FALSE
;
332 DoShowWindow(nShowCmd
);
336 ::BringWindowToTop(GetHwnd());
338 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
339 event
.SetEventObject( this );
340 GetEventHandler()->ProcessEvent(event
);
344 // Try to highlight the correct window (the parent)
347 HWND hWndParent
= GetHwndOf(GetParent());
349 ::BringWindowToTop(hWndParent
);
356 void wxFrameMSW::Iconize(bool iconize
)
358 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
361 void wxFrameMSW::Maximize(bool maximize
)
365 // just maximize it directly
366 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
370 // we can't maximize the hidden frame because it shows it as well, so
371 // just remember that we should do it later in this case
372 m_maximizeOnShow
= TRUE
;
376 void wxFrameMSW::Restore()
378 DoShowWindow(SW_RESTORE
);
381 bool wxFrameMSW::IsIconized() const
383 ((wxFrameMSW
*)this)->m_iconized
= (::IsIconic(GetHwnd()) != 0);
388 bool wxFrameMSW::IsMaximized() const
390 return (::IsZoomed(GetHwnd()) != 0);
393 void wxFrameMSW::SetIcon(const wxIcon
& icon
)
395 wxFrameBase::SetIcon(icon
);
397 #if defined(__WIN95__)
400 SendMessage(GetHwnd(), WM_SETICON
,
401 (WPARAM
)TRUE
, (LPARAM
)(HICON
) m_icon
.GetHICON());
406 // generate an artificial resize event
407 void wxFrameMSW::SendSizeEvent()
411 ::GetWindowRect(GetHwnd(), &r
);
413 if ( !::GetWindowRect(GetHwnd(), &r
) )
415 wxLogLastError(_T("GetWindowRect"));
421 (void)::PostMessage(GetHwnd(), WM_SIZE
,
422 IsMaximized() ? SIZE_MAXIMIZED
: SIZE_RESTORED
,
423 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
428 wxStatusBar
*wxFrameMSW::OnCreateStatusBar(int number
,
431 const wxString
& name
)
433 wxStatusBar
*statusBar
= NULL
;
435 #if wxUSE_NATIVE_STATUSBAR
436 if ( !UsesNativeStatusBar() )
438 statusBar
= (wxStatusBar
*)new wxStatusBarGeneric(this, id
, style
);
443 statusBar
= new wxStatusBar(this, id
, style
, name
);
446 // Set the height according to the font and the border size
447 wxClientDC
dc(statusBar
);
448 dc
.SetFont(statusBar
->GetFont());
451 dc
.GetTextExtent(_T("X"), NULL
, &y
);
453 int height
= (int)( (11*y
)/10 + 2*statusBar
->GetBorderY());
455 statusBar
->SetSize(-1, -1, -1, height
);
457 statusBar
->SetFieldsCount(number
);
462 void wxFrameMSW::PositionStatusBar()
464 if ( !m_frameStatusBar
)
468 GetClientSize(&w
, &h
);
470 m_frameStatusBar
->GetSize(&sw
, &sh
);
472 // Since we wish the status bar to be directly under the client area,
473 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
474 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
476 #endif // wxUSE_STATUSBAR
478 void wxFrameMSW::DetachMenuBar()
481 if ( m_frameMenuBar
)
483 m_frameMenuBar
->Detach();
484 m_frameMenuBar
= NULL
;
486 #endif // wxUSE_MENUS
489 void wxFrameMSW::SetMenuBar(wxMenuBar
*menubar
)
492 // detach the old menu bar in any case
495 #if wxUSE_MENUS_NATIVE
498 // actually remove the menu from the frame
499 m_hMenu
= (WXHMENU
)0;
500 InternalSetMenuBar();
502 else // set new non NULL menu bar
504 // Can set a menubar several times.
505 if ( menubar
->GetHMenu() )
507 m_hMenu
= menubar
->GetHMenu();
511 if (menubar
->IsAttached())
514 m_hMenu
= menubar
->Create();
520 InternalSetMenuBar();
522 #endif // wxUSE_MENUS_NATIVE
526 m_frameMenuBar
= menubar
;
527 menubar
->Attach((wxFrame
*)this);
529 #endif // wxUSE_MENUS
532 #if wxUSE_MENUS_NATIVE
534 void wxFrameMSW::InternalSetMenuBar()
536 if ( !::SetMenu(GetHwnd(), (HMENU
)m_hMenu
) )
538 wxLogLastError(wxT("SetMenu"));
542 #endif // wxUSE_MENUS_NATIVE
544 // Responds to colour changes, and passes event on to children.
545 void wxFrameMSW::OnSysColourChanged(wxSysColourChangedEvent
& event
)
547 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
551 if ( m_frameStatusBar
)
553 wxSysColourChangedEvent event2
;
554 event2
.SetEventObject( m_frameStatusBar
);
555 m_frameStatusBar
->GetEventHandler()->ProcessEvent(event2
);
557 #endif // wxUSE_STATUSBAR
559 // Propagate the event to the non-top-level children
560 wxWindow::OnSysColourChanged(event
);
563 // Pass TRUE to show full screen, FALSE to restore.
564 bool wxFrameMSW::ShowFullScreen(bool show
, long style
)
571 m_fsIsShowing
= TRUE
;
575 wxToolBar
*theToolBar
= GetToolBar();
577 theToolBar
->GetSize(NULL
, &m_fsToolBarHeight
);
579 // zap the toolbar, menubar, and statusbar
581 if ((style
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
583 theToolBar
->SetSize(-1,0);
584 theToolBar
->Show(FALSE
);
586 #endif // wxUSE_TOOLBAR
588 if (style
& wxFULLSCREEN_NOMENUBAR
)
589 SetMenu((HWND
)GetHWND(), (HMENU
) NULL
);
592 wxStatusBar
*theStatusBar
= GetStatusBar();
594 theStatusBar
->GetSize(NULL
, &m_fsStatusBarHeight
);
596 // Save the number of fields in the statusbar
597 if ((style
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
599 //m_fsStatusBarFields = theStatusBar->GetFieldsCount();
600 //SetStatusBar((wxStatusBar*) NULL);
601 //delete theStatusBar;
602 theStatusBar
->Show(FALSE
);
605 m_fsStatusBarFields
= 0;
606 #endif // wxUSE_STATUSBAR
608 // zap the frame borders
610 // save the 'normal' window style
611 m_fsOldWindowStyle
= GetWindowLong((HWND
)GetHWND(), GWL_STYLE
);
613 // save the old position, width & height, maximize state
614 m_fsOldSize
= GetRect();
615 m_fsIsMaximized
= IsMaximized();
617 // decide which window style flags to turn off
618 LONG newStyle
= m_fsOldWindowStyle
;
621 if (style
& wxFULLSCREEN_NOBORDER
)
622 offFlags
|= WS_BORDER
;
623 if (style
& wxFULLSCREEN_NOCAPTION
)
624 offFlags
|= (WS_CAPTION
| WS_SYSMENU
);
626 newStyle
&= (~offFlags
);
628 // change our window style to be compatible with full-screen mode
629 SetWindowLong((HWND
)GetHWND(), GWL_STYLE
, newStyle
);
631 // resize to the size of the desktop
635 ::GetWindowRect(GetDesktopWindow(), &rect
);
636 width
= rect
.right
- rect
.left
;
637 height
= rect
.bottom
- rect
.top
;
639 SetSize(width
, height
);
641 // now flush the window style cache and actually go full-screen
642 SetWindowPos((HWND
)GetHWND(), HWND_TOP
, 0, 0, width
, height
, SWP_FRAMECHANGED
);
644 wxSizeEvent
event(wxSize(width
, height
), GetId());
645 GetEventHandler()->ProcessEvent(event
);
654 m_fsIsShowing
= FALSE
;
657 wxToolBar
*theToolBar
= GetToolBar();
659 // restore the toolbar, menubar, and statusbar
660 if (theToolBar
&& (m_fsStyle
& wxFULLSCREEN_NOTOOLBAR
))
662 theToolBar
->SetSize(-1, m_fsToolBarHeight
);
663 theToolBar
->Show(TRUE
);
665 #endif // wxUSE_TOOLBAR
668 if ( m_fsStyle
& wxFULLSCREEN_NOSTATUSBAR
)
670 //CreateStatusBar(m_fsStatusBarFields);
673 GetStatusBar()->Show(TRUE
);
677 #endif // wxUSE_STATUSBAR
679 if ((m_fsStyle
& wxFULLSCREEN_NOMENUBAR
) && (m_hMenu
!= 0))
680 SetMenu((HWND
)GetHWND(), (HMENU
)m_hMenu
);
682 Maximize(m_fsIsMaximized
);
683 SetWindowLong((HWND
)GetHWND(),GWL_STYLE
, m_fsOldWindowStyle
);
684 SetWindowPos((HWND
)GetHWND(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
685 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
696 bool wxFrameMSW::MSWCreate(int id
, wxWindow
*parent
, const wxChar
*wclass
, wxWindow
*wx_win
, const wxChar
*title
,
697 int x
, int y
, int width
, int height
, long style
)
700 m_defaultIcon
= (WXHICON
) (wxSTD_FRAME_ICON
? wxSTD_FRAME_ICON
: wxDEFAULT_FRAME_ICON
);
702 // If child windows aren't properly drawn initially, WS_CLIPCHILDREN
703 // could be the culprit. But without it, you can get a lot of flicker.
706 if ( style
& wxCAPTION
)
708 if ( style
& wxFRAME_TOOL_WINDOW
)
709 msflags
|= WS_POPUPWINDOW
;
711 msflags
|= WS_OVERLAPPED
;
718 if (style
& wxMINIMIZE_BOX
)
719 msflags
|= WS_MINIMIZEBOX
;
720 if (style
& wxMAXIMIZE_BOX
)
721 msflags
|= WS_MAXIMIZEBOX
;
722 if (style
& wxTHICK_FRAME
)
723 msflags
|= WS_THICKFRAME
;
724 if (style
& wxSYSTEM_MENU
)
725 msflags
|= WS_SYSMENU
;
726 if ( style
& wxMINIMIZE
)
727 msflags
|= WS_MINIMIZE
;
728 if (style
& wxMAXIMIZE
)
729 msflags
|= WS_MAXIMIZE
;
730 if (style
& wxCAPTION
)
731 msflags
|= WS_CAPTION
;
732 if (style
& wxCLIP_CHILDREN
)
733 msflags
|= WS_CLIPCHILDREN
;
735 // Keep this in wxFrameMSW because it saves recoding this function
737 #if wxUSE_ITSY_BITSY && !defined(__WIN32__)
738 if (style
& wxTINY_CAPTION_VERT
)
739 msflags
|= IBS_VERTCAPTION
;
740 if (style
& wxTINY_CAPTION_HORIZ
)
741 msflags
|= IBS_HORZCAPTION
;
743 if (style
& wxTINY_CAPTION_VERT
)
744 msflags
|= WS_CAPTION
;
745 if (style
& wxTINY_CAPTION_HORIZ
)
746 msflags
|= WS_CAPTION
;
748 if ((style
& wxTHICK_FRAME
) == 0)
749 msflags
|= WS_BORDER
;
751 WXDWORD extendedStyle
= MakeExtendedStyle(style
);
753 // make all frames appear in the win9x shell taskbar unless
754 // wxFRAME_TOOL_WINDOW or wxFRAME_NO_TASKBAR is given - without giving them
755 // WS_EX_APPWINDOW style, the child (i.e. owned) frames wouldn't appear in it
756 #if !defined(__WIN16__) && !defined(__SC__)
757 if ( (style
& wxFRAME_TOOL_WINDOW
) ||
758 (style
& wxFRAME_NO_TASKBAR
) )
759 extendedStyle
|= WS_EX_TOOLWINDOW
;
760 else if ( !(style
& wxFRAME_NO_TASKBAR
) )
761 extendedStyle
|= WS_EX_APPWINDOW
;
764 if (style
& wxSTAY_ON_TOP
)
765 extendedStyle
|= WS_EX_TOPMOST
;
768 if (m_exStyle
& wxFRAME_EX_CONTEXTHELP
)
769 extendedStyle
|= WS_EX_CONTEXTHELP
;
773 if ( !wxWindow::MSWCreate(id
, parent
, wclass
, wx_win
, title
, x
, y
, width
, height
,
774 msflags
, NULL
, extendedStyle
) )
777 // Seems to be necessary if we use WS_POPUP
778 // style instead of WS_OVERLAPPED
779 if (width
> -1 && height
> -1)
780 ::PostMessage(GetHwnd(), WM_SIZE
, SIZE_RESTORED
, MAKELPARAM(width
, height
));
785 // Default activation behaviour - set the focus for the first child
787 void wxFrameMSW::OnActivate(wxActivateEvent
& event
)
789 if ( event
.GetActive() )
791 // restore focus to the child which was last focused
792 wxLogTrace(_T("focus"), _T("wxFrameMSW %08x activated."), m_hWnd
);
794 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
801 wxSetFocusToChild(parent
, &m_winLastFocused
);
805 // remember the last focused child if it is our child
806 m_winLastFocused
= FindFocus();
808 // so we NULL it out if it's a child from some other frame
809 wxWindow
*win
= m_winLastFocused
;
812 if ( win
->IsTopLevel() )
816 m_winLastFocused
= NULL
;
822 win
= win
->GetParent();
825 wxLogTrace(_T("focus"),
826 _T("wxFrameMSW %08x deactivated, last focused: %08x."),
828 m_winLastFocused
? GetHwndOf(m_winLastFocused
)
835 // ----------------------------------------------------------------------------
836 // tool/status bar stuff
837 // ----------------------------------------------------------------------------
841 wxToolBar
* wxFrameMSW::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
843 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
848 return m_frameToolBar
;
851 void wxFrameMSW::PositionToolBar()
854 ::GetClientRect(GetHwnd(), &rect
);
857 if ( GetStatusBar() )
859 int statusX
, statusY
;
860 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
861 rect
.bottom
-= statusY
;
863 #endif // wxUSE_STATUSBAR
865 if ( GetToolBar() && GetToolBar()->IsShown() )
868 GetToolBar()->GetSize(&tw
, &th
);
870 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
879 // Use the 'real' MSW position here
880 GetToolBar()->SetSize(0, 0, tw
, th
, wxSIZE_NO_ADJUSTMENTS
);
883 #endif // wxUSE_TOOLBAR
885 // ----------------------------------------------------------------------------
886 // frame state (iconized/maximized/...)
887 // ----------------------------------------------------------------------------
889 // propagate our state change to all child frames: this allows us to emulate X
890 // Windows behaviour where child frames float independently of the parent one
891 // on the desktop, but are iconized/restored with it
892 void wxFrameMSW::IconizeChildFrames(bool bIconize
)
894 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
896 node
= node
->GetNext() )
898 wxWindow
*win
= node
->GetData();
900 // iconizing the frames with this style under Win95 shell puts them at
901 // the bottom of the screen (as the MDI children) instead of making
902 // them appear in the taskbar because they are, by virtue of this
903 // style, not managed by the taskbar - instead leave Windows take care
906 if ( win
->GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
910 // the child MDI frames are a special case and should not be touched by
911 // the parent frame - instead, they are managed by the user
912 wxFrameMSW
*frame
= wxDynamicCast(win
, wxFrameMSW
);
914 #if wxUSE_MDI_ARCHITECTURE
915 && !wxDynamicCast(frame
, wxMDIChildFrame
)
916 #endif // wxUSE_MDI_ARCHITECTURE
919 frame
->Iconize(bIconize
);
924 // ===========================================================================
925 // message processing
926 // ===========================================================================
928 // ---------------------------------------------------------------------------
930 // ---------------------------------------------------------------------------
932 bool wxFrameMSW::MSWTranslateMessage(WXMSG
* pMsg
)
934 if ( wxWindow::MSWTranslateMessage(pMsg
) )
937 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
938 // try the menu bar accels
939 wxMenuBar
*menuBar
= GetMenuBar();
943 const wxAcceleratorTable
& acceleratorTable
= menuBar
->GetAccelTable();
944 return acceleratorTable
.Translate(this, pMsg
);
947 #endif // wxUSE_MENUS && wxUSE_ACCEL
950 // ---------------------------------------------------------------------------
951 // our private (non virtual) message handlers
952 // ---------------------------------------------------------------------------
954 bool wxFrameMSW::HandlePaint()
957 if ( GetUpdateRect(GetHwnd(), &rect
, FALSE
) )
961 HICON hIcon
= m_icon
.Ok() ? GetHiconOf(m_icon
)
962 : (HICON
)m_defaultIcon
;
964 // Hold a pointer to the dc so long as the OnPaint() message
965 // is being processed
967 HDC hdc
= ::BeginPaint(GetHwnd(), &ps
);
969 // Erase background before painting or we get white background
970 MSWDefWindowProc(WM_ICONERASEBKGND
, (WORD
)(LONG
)ps
.hdc
, 0L);
975 ::GetClientRect(GetHwnd(), &rect
);
977 // FIXME: why hardcoded?
978 static const int icon_width
= 32;
979 static const int icon_height
= 32;
981 int icon_x
= (int)((rect
.right
- icon_width
)/2);
982 int icon_y
= (int)((rect
.bottom
- icon_height
)/2);
984 ::DrawIcon(hdc
, icon_x
, icon_y
, hIcon
);
987 ::EndPaint(GetHwnd(), &ps
);
993 return wxWindow::HandlePaint();
998 // nothing to paint - processed
1003 bool wxFrameMSW::HandleSize(int x
, int y
, WXUINT id
)
1005 bool processed
= FALSE
;
1010 // only do it it if we were iconized before, otherwise resizing the
1011 // parent frame has a curious side effect of bringing it under it's
1016 // restore all child frames too
1017 IconizeChildFrames(FALSE
);
1019 (void)SendIconizeEvent(FALSE
);
1023 case SIZEFULLSCREEN
:
1028 // iconize all child frames too
1029 IconizeChildFrames(TRUE
);
1031 (void)SendIconizeEvent();
1040 PositionStatusBar();
1041 #endif // wxUSE_STATUSBAR
1045 #endif // wxUSE_TOOLBAR
1047 wxSizeEvent
event(wxSize(x
, y
), m_windowId
);
1048 event
.SetEventObject( this );
1049 processed
= GetEventHandler()->ProcessEvent(event
);
1055 bool wxFrameMSW::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
1059 // In case it's e.g. a toolbar.
1060 wxWindow
*win
= wxFindWinFromHandle(control
);
1062 return win
->MSWCommand(cmd
, id
);
1065 // handle here commands from menus and accelerators
1066 if ( cmd
== 0 || cmd
== 1 )
1068 #if wxUSE_MENUS_NATIVE
1069 if ( wxCurrentPopupMenu
)
1071 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
1072 wxCurrentPopupMenu
= NULL
;
1074 return popupMenu
->MSWCommand(cmd
, id
);
1076 #endif // wxUSE_MENUS_NATIVE
1078 if ( ProcessCommand(id
) )
1087 bool wxFrameMSW::HandleMenuSelect(WXWORD nItem
, WXWORD flags
, WXHMENU hMenu
)
1090 if ( flags
== 0xFFFF && hMenu
== 0 )
1092 // menu was removed from screen
1095 else if ( !(flags
& MF_POPUP
) && !(flags
& MF_SEPARATOR
) )
1102 // don't give hints for separators (doesn't make sense) nor for the
1103 // items opening popup menus (they don't have them anyhow) but do clear
1104 // the status line - otherwise, we would be left with the help message
1105 // for the previous item which doesn't apply any more
1106 wxStatusBar
*statbar
= GetStatusBar();
1109 statbar
->SetStatusText(wxEmptyString
);
1111 #endif // wxUSE_STATUSBAR
1116 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, item
);
1117 event
.SetEventObject( this );
1119 return GetEventHandler()->ProcessEvent(event
);
1122 // ---------------------------------------------------------------------------
1123 // the window proc for wxFrameMSW
1124 // ---------------------------------------------------------------------------
1126 long wxFrameMSW::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1129 bool processed
= FALSE
;
1134 // if we can't close, tell the system that we processed the
1135 // message - otherwise it would close us
1136 processed
= !Close();
1143 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
1146 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
1154 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
1156 processed
= HandleMenuSelect(item
, flags
, hmenu
);
1161 processed
= HandlePaint();
1164 case WM_QUERYDRAGICON
:
1166 HICON hIcon
= m_icon
.Ok() ? GetHiconOf(m_icon
)
1167 : (HICON
)(m_defaultIcon
);
1169 processed
= rc
!= 0;
1174 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
1179 rc
= wxWindow::MSWWindowProc(message
, wParam
, lParam
);