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
)
85 #ifndef __WXUNIVERSAL__
86 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxFrameMSW
)
89 // ============================================================================
91 // ============================================================================
93 // ----------------------------------------------------------------------------
94 // static class members
95 // ----------------------------------------------------------------------------
98 #if wxUSE_NATIVE_STATUSBAR
99 bool wxFrameMSW::m_useNativeStatusBar
= TRUE
;
101 bool wxFrameMSW::m_useNativeStatusBar
= FALSE
;
103 #endif // wxUSE_NATIVE_STATUSBAR
105 // ----------------------------------------------------------------------------
106 // creation/destruction
107 // ----------------------------------------------------------------------------
109 void wxFrameMSW::Init()
112 m_maximizeOnShow
= FALSE
;
118 // Data to save/restore when calling ShowFullScreen
120 m_fsOldWindowStyle
= 0;
121 m_fsStatusBarFields
= 0;
122 m_fsStatusBarHeight
= 0;
123 m_fsToolBarHeight
= 0;
125 m_fsIsMaximized
= FALSE
;
126 m_fsIsShowing
= FALSE
;
128 m_winLastFocused
= (wxWindow
*)NULL
;
130 // unlike (almost?) all other windows, frames are created hidden
134 bool wxFrameMSW::Create(wxWindow
*parent
,
136 const wxString
& title
,
140 const wxString
& name
)
143 m_windowStyle
= style
;
145 m_frameMenuBar
= NULL
;
146 #endif // wxUSE_MENUS
148 m_frameToolBar
= NULL
;
149 #endif // wxUSE_TOOLBAR
151 m_frameStatusBar
= NULL
;
152 #endif // wxUSE_STATUSBAR
154 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
159 m_windowId
= (int)NewControlId();
161 if (parent
) parent
->AddChild(this);
170 wxTopLevelWindows
.Append(this);
172 MSWCreate(m_windowId
, parent
, wxFrameClassName
, this, title
,
173 x
, y
, width
, height
, style
);
175 wxModelessWindows
.Append(this);
180 wxFrameMSW::~wxFrameMSW()
182 m_isBeingDeleted
= TRUE
;
183 wxTopLevelWindows
.DeleteObject(this);
185 // the ~wxToolBar() code relies on the previous line to be executed before
186 // this one, i.e. the frame should remove itself from wxTopLevelWindows
187 // before destorying its toolbar
190 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
192 wxTheApp
->SetTopWindow(NULL
);
194 if (wxTheApp
->GetExitOnFrameDelete())
200 wxModelessWindows
.DeleteObject(this);
202 // For some reason, wxWindows can activate another task altogether
203 // when a frame is destroyed after a modal dialog has been invoked.
204 // Try to bring the parent to the top.
205 // MT:Only do this if this frame is currently the active window, else weird
206 // things start to happen
207 if ( wxGetActiveWindow() == this )
208 if (GetParent() && GetParent()->GetHWND())
209 ::BringWindowToTop((HWND
) GetParent()->GetHWND());
212 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
213 void wxFrameMSW::DoGetClientSize(int *x
, int *y
) const
216 ::GetClientRect(GetHwnd(), &rect
);
219 if ( GetStatusBar() && GetStatusBar()->IsShown() )
221 int statusX
, statusY
;
222 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
223 rect
.bottom
-= statusY
;
225 #endif // wxUSE_STATUSBAR
227 wxPoint
pt(GetClientAreaOrigin());
237 // Set the client size (i.e. leave the calculation of borders etc.
239 void wxFrameMSW::DoSetClientSize(int width
, int height
)
241 HWND hWnd
= GetHwnd();
244 ::GetClientRect(hWnd
, &rectClient
);
247 ::GetWindowRect(hWnd
, &rectTotal
);
249 // Find the difference between the entire window (title bar and all)
250 // and the client area; add this to the new client size to move the
252 width
+= rectTotal
.right
- rectTotal
.left
- rectClient
.right
;
253 height
+= rectTotal
.bottom
- rectTotal
.top
- rectClient
.bottom
;
256 wxStatusBar
*statbar
= GetStatusBar();
257 if ( statbar
&& statbar
->IsShown() )
259 // leave enough space for the status bar
260 height
+= statbar
->GetSize().y
;
262 #endif // wxUSE_STATUSBAR
264 // note that this takes the toolbar into account
265 wxPoint pt
= GetClientAreaOrigin();
269 if ( !::MoveWindow(hWnd
, rectTotal
.left
, rectTotal
.top
,
270 width
, height
, TRUE
/* redraw */) )
272 wxLogLastError(_T("MoveWindow"));
275 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
276 event
.SetEventObject(this);
277 GetEventHandler()->ProcessEvent(event
);
280 void wxFrameMSW::DoGetSize(int *width
, int *height
) const
283 ::GetWindowRect(GetHwnd(), &rect
);
285 *width
= rect
.right
- rect
.left
;
286 *height
= rect
.bottom
- rect
.top
;
289 void wxFrameMSW::DoGetPosition(int *x
, int *y
) const
292 ::GetWindowRect(GetHwnd(), &rect
);
298 // ----------------------------------------------------------------------------
299 // variations around ::ShowWindow()
300 // ----------------------------------------------------------------------------
302 void wxFrameMSW::DoShowWindow(int nShowCmd
)
304 ::ShowWindow(GetHwnd(), nShowCmd
);
306 m_iconized
= nShowCmd
== SW_MINIMIZE
;
309 bool wxFrameMSW::Show(bool show
)
311 // don't use wxWindow version as we want to call DoShowWindow()
312 if ( !wxWindowBase::Show(show
) )
318 if ( m_maximizeOnShow
)
321 nShowCmd
= SW_MAXIMIZE
;
323 m_maximizeOnShow
= FALSE
;
335 DoShowWindow(nShowCmd
);
339 ::BringWindowToTop(GetHwnd());
341 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
342 event
.SetEventObject( this );
343 GetEventHandler()->ProcessEvent(event
);
347 // Try to highlight the correct window (the parent)
350 HWND hWndParent
= GetHwndOf(GetParent());
352 ::BringWindowToTop(hWndParent
);
359 void wxFrameMSW::Iconize(bool iconize
)
361 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
364 void wxFrameMSW::Maximize(bool maximize
)
368 // just maximize it directly
369 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
373 // we can't maximize the hidden frame because it shows it as well, so
374 // just remember that we should do it later in this case
375 m_maximizeOnShow
= TRUE
;
379 void wxFrameMSW::Restore()
381 DoShowWindow(SW_RESTORE
);
384 bool wxFrameMSW::IsIconized() const
386 #ifdef __WXMICROWIN__
390 ((wxFrameMSW
*)this)->m_iconized
= (::IsIconic(GetHwnd()) != 0);
396 bool wxFrameMSW::IsMaximized() const
398 #ifdef __WXMICROWIN__
402 return (::IsZoomed(GetHwnd()) != 0);
406 void wxFrameMSW::SetIcon(const wxIcon
& icon
)
408 wxFrameBase::SetIcon(icon
);
410 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
413 SendMessage(GetHwnd(), WM_SETICON
,
414 (WPARAM
)TRUE
, (LPARAM
)(HICON
) m_icon
.GetHICON());
419 // generate an artificial resize event
420 void wxFrameMSW::SendSizeEvent()
424 ::GetWindowRect(GetHwnd(), &r
);
426 if ( !::GetWindowRect(GetHwnd(), &r
) )
428 wxLogLastError(_T("GetWindowRect"));
434 (void)::PostMessage(GetHwnd(), WM_SIZE
,
435 IsMaximized() ? SIZE_MAXIMIZED
: SIZE_RESTORED
,
436 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
441 wxStatusBar
*wxFrameMSW::OnCreateStatusBar(int number
,
444 const wxString
& name
)
446 wxStatusBar
*statusBar
= NULL
;
448 #if wxUSE_NATIVE_STATUSBAR
449 if ( !UsesNativeStatusBar() )
451 statusBar
= (wxStatusBar
*)new wxStatusBarGeneric(this, id
, style
);
456 statusBar
= new wxStatusBar(this, id
, style
, name
);
459 // Set the height according to the font and the border size
460 wxClientDC
dc(statusBar
);
461 dc
.SetFont(statusBar
->GetFont());
464 dc
.GetTextExtent(_T("X"), NULL
, &y
);
466 int height
= (int)( (11*y
)/10 + 2*statusBar
->GetBorderY());
468 statusBar
->SetSize(-1, -1, -1, height
);
470 statusBar
->SetFieldsCount(number
);
475 void wxFrameMSW::PositionStatusBar()
477 if ( !m_frameStatusBar
)
481 GetClientSize(&w
, &h
);
483 m_frameStatusBar
->GetSize(&sw
, &sh
);
485 // Since we wish the status bar to be directly under the client area,
486 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
487 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
489 #endif // wxUSE_STATUSBAR
491 void wxFrameMSW::DetachMenuBar()
494 if ( m_frameMenuBar
)
496 m_frameMenuBar
->Detach();
497 m_frameMenuBar
= NULL
;
499 #endif // wxUSE_MENUS
502 void wxFrameMSW::SetMenuBar(wxMenuBar
*menubar
)
505 // detach the old menu bar in any case
508 #if wxUSE_MENUS_NATIVE
511 // actually remove the menu from the frame
512 m_hMenu
= (WXHMENU
)0;
513 InternalSetMenuBar();
515 else // set new non NULL menu bar
517 // Can set a menubar several times.
518 if ( menubar
->GetHMenu() )
520 m_hMenu
= menubar
->GetHMenu();
524 if (menubar
->IsAttached())
527 m_hMenu
= menubar
->Create();
533 InternalSetMenuBar();
535 #endif // wxUSE_MENUS_NATIVE
539 m_frameMenuBar
= menubar
;
540 menubar
->Attach((wxFrame
*)this);
542 #endif // wxUSE_MENUS
545 #if wxUSE_MENUS_NATIVE
547 void wxFrameMSW::InternalSetMenuBar()
549 #ifndef __WXMICROWIN__
550 if ( !::SetMenu(GetHwnd(), (HMENU
)m_hMenu
) )
552 wxLogLastError(wxT("SetMenu"));
557 #endif // wxUSE_MENUS_NATIVE
559 // Responds to colour changes, and passes event on to children.
560 void wxFrameMSW::OnSysColourChanged(wxSysColourChangedEvent
& event
)
562 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
566 if ( m_frameStatusBar
)
568 wxSysColourChangedEvent event2
;
569 event2
.SetEventObject( m_frameStatusBar
);
570 m_frameStatusBar
->GetEventHandler()->ProcessEvent(event2
);
572 #endif // wxUSE_STATUSBAR
574 // Propagate the event to the non-top-level children
575 wxWindow::OnSysColourChanged(event
);
578 // Pass TRUE to show full screen, FALSE to restore.
579 bool wxFrameMSW::ShowFullScreen(bool show
, long style
)
586 m_fsIsShowing
= TRUE
;
590 wxToolBar
*theToolBar
= GetToolBar();
592 theToolBar
->GetSize(NULL
, &m_fsToolBarHeight
);
594 // zap the toolbar, menubar, and statusbar
596 if ((style
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
598 theToolBar
->SetSize(-1,0);
599 theToolBar
->Show(FALSE
);
601 #endif // wxUSE_TOOLBAR
603 #ifndef __WXMICROWIN__
604 if (style
& wxFULLSCREEN_NOMENUBAR
)
605 SetMenu((HWND
)GetHWND(), (HMENU
) NULL
);
609 wxStatusBar
*theStatusBar
= GetStatusBar();
611 theStatusBar
->GetSize(NULL
, &m_fsStatusBarHeight
);
613 // Save the number of fields in the statusbar
614 if ((style
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
616 //m_fsStatusBarFields = theStatusBar->GetFieldsCount();
617 //SetStatusBar((wxStatusBar*) NULL);
618 //delete theStatusBar;
619 theStatusBar
->Show(FALSE
);
622 m_fsStatusBarFields
= 0;
623 #endif // wxUSE_STATUSBAR
625 // zap the frame borders
627 // save the 'normal' window style
628 m_fsOldWindowStyle
= GetWindowLong((HWND
)GetHWND(), GWL_STYLE
);
630 // save the old position, width & height, maximize state
631 m_fsOldSize
= GetRect();
632 m_fsIsMaximized
= IsMaximized();
634 // decide which window style flags to turn off
635 LONG newStyle
= m_fsOldWindowStyle
;
638 if (style
& wxFULLSCREEN_NOBORDER
)
639 offFlags
|= WS_BORDER
;
640 if (style
& wxFULLSCREEN_NOCAPTION
)
641 offFlags
|= (WS_CAPTION
| WS_SYSMENU
);
643 newStyle
&= (~offFlags
);
645 // change our window style to be compatible with full-screen mode
646 SetWindowLong((HWND
)GetHWND(), GWL_STYLE
, newStyle
);
648 // resize to the size of the desktop
652 ::GetWindowRect(GetDesktopWindow(), &rect
);
653 width
= rect
.right
- rect
.left
;
654 height
= rect
.bottom
- rect
.top
;
656 SetSize(width
, height
);
658 // now flush the window style cache and actually go full-screen
659 SetWindowPos((HWND
)GetHWND(), HWND_TOP
, 0, 0, width
, height
, SWP_FRAMECHANGED
);
661 wxSizeEvent
event(wxSize(width
, height
), GetId());
662 GetEventHandler()->ProcessEvent(event
);
671 m_fsIsShowing
= FALSE
;
674 wxToolBar
*theToolBar
= GetToolBar();
676 // restore the toolbar, menubar, and statusbar
677 if (theToolBar
&& (m_fsStyle
& wxFULLSCREEN_NOTOOLBAR
))
679 theToolBar
->SetSize(-1, m_fsToolBarHeight
);
680 theToolBar
->Show(TRUE
);
682 #endif // wxUSE_TOOLBAR
685 if ( m_fsStyle
& wxFULLSCREEN_NOSTATUSBAR
)
687 //CreateStatusBar(m_fsStatusBarFields);
690 GetStatusBar()->Show(TRUE
);
694 #endif // wxUSE_STATUSBAR
696 #ifndef __WXMICROWIN__
697 if ((m_fsStyle
& wxFULLSCREEN_NOMENUBAR
) && (m_hMenu
!= 0))
698 SetMenu((HWND
)GetHWND(), (HMENU
)m_hMenu
);
701 Maximize(m_fsIsMaximized
);
702 SetWindowLong((HWND
)GetHWND(),GWL_STYLE
, m_fsOldWindowStyle
);
703 SetWindowPos((HWND
)GetHWND(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
704 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
715 bool wxFrameMSW::MSWCreate(int id
, wxWindow
*parent
, const wxChar
*wclass
, wxWindow
*wx_win
, const wxChar
*title
,
716 int x
, int y
, int width
, int height
, long style
)
719 m_defaultIcon
= (WXHICON
) (wxSTD_FRAME_ICON
? wxSTD_FRAME_ICON
: wxDEFAULT_FRAME_ICON
);
721 // If child windows aren't properly drawn initially, WS_CLIPCHILDREN
722 // could be the culprit. But without it, you can get a lot of flicker.
725 if ( style
& wxCAPTION
)
727 if ( style
& wxFRAME_TOOL_WINDOW
)
728 msflags
|= WS_POPUPWINDOW
;
730 msflags
|= WS_OVERLAPPED
;
737 if (style
& wxMINIMIZE_BOX
)
738 msflags
|= WS_MINIMIZEBOX
;
739 if (style
& wxMAXIMIZE_BOX
)
740 msflags
|= WS_MAXIMIZEBOX
;
741 if (style
& wxTHICK_FRAME
)
742 msflags
|= WS_THICKFRAME
;
743 if (style
& wxSYSTEM_MENU
)
744 msflags
|= WS_SYSMENU
;
745 if ( style
& wxMINIMIZE
)
746 msflags
|= WS_MINIMIZE
;
747 if (style
& wxMAXIMIZE
)
748 msflags
|= WS_MAXIMIZE
;
749 if (style
& wxCAPTION
)
750 msflags
|= WS_CAPTION
;
751 if (style
& wxCLIP_CHILDREN
)
752 msflags
|= WS_CLIPCHILDREN
;
754 // Keep this in wxFrameMSW because it saves recoding this function
756 #if wxUSE_ITSY_BITSY && !defined(__WIN32__)
757 if (style
& wxTINY_CAPTION_VERT
)
758 msflags
|= IBS_VERTCAPTION
;
759 if (style
& wxTINY_CAPTION_HORIZ
)
760 msflags
|= IBS_HORZCAPTION
;
762 if (style
& wxTINY_CAPTION_VERT
)
763 msflags
|= WS_CAPTION
;
764 if (style
& wxTINY_CAPTION_HORIZ
)
765 msflags
|= WS_CAPTION
;
767 if ((style
& wxTHICK_FRAME
) == 0)
768 msflags
|= WS_BORDER
;
770 WXDWORD extendedStyle
= MakeExtendedStyle(style
);
772 // make all frames appear in the win9x shell taskbar unless
773 // wxFRAME_TOOL_WINDOW or wxFRAME_NO_TASKBAR is given - without giving them
774 // WS_EX_APPWINDOW style, the child (i.e. owned) frames wouldn't appear in it
775 #if !defined(__WIN16__) && !defined(__SC__)
776 if ( (style
& wxFRAME_TOOL_WINDOW
) ||
777 (style
& wxFRAME_NO_TASKBAR
) )
778 extendedStyle
|= WS_EX_TOOLWINDOW
;
779 else if ( !(style
& wxFRAME_NO_TASKBAR
) )
780 extendedStyle
|= WS_EX_APPWINDOW
;
783 if (style
& wxSTAY_ON_TOP
)
784 extendedStyle
|= WS_EX_TOPMOST
;
787 if (m_exStyle
& wxFRAME_EX_CONTEXTHELP
)
788 extendedStyle
|= WS_EX_CONTEXTHELP
;
792 if ( !wxWindow::MSWCreate(id
, parent
, wclass
, wx_win
, title
, x
, y
, width
, height
,
793 msflags
, NULL
, extendedStyle
) )
796 // Seems to be necessary if we use WS_POPUP
797 // style instead of WS_OVERLAPPED
798 if (width
> -1 && height
> -1)
799 ::PostMessage(GetHwnd(), WM_SIZE
, SIZE_RESTORED
, MAKELPARAM(width
, height
));
804 // Default activation behaviour - set the focus for the first child
806 void wxFrameMSW::OnActivate(wxActivateEvent
& event
)
808 if ( event
.GetActive() )
810 // restore focus to the child which was last focused
811 wxLogTrace(_T("focus"), _T("wxFrameMSW %08x activated."), m_hWnd
);
813 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
820 wxSetFocusToChild(parent
, &m_winLastFocused
);
824 // remember the last focused child if it is our child
825 m_winLastFocused
= FindFocus();
827 // so we NULL it out if it's a child from some other frame
828 wxWindow
*win
= m_winLastFocused
;
831 if ( win
->IsTopLevel() )
835 m_winLastFocused
= NULL
;
841 win
= win
->GetParent();
844 wxLogTrace(_T("focus"),
845 _T("wxFrameMSW %08x deactivated, last focused: %08x."),
847 m_winLastFocused
? GetHwndOf(m_winLastFocused
)
854 // ----------------------------------------------------------------------------
855 // tool/status bar stuff
856 // ----------------------------------------------------------------------------
860 wxToolBar
* wxFrameMSW::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
862 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
867 return m_frameToolBar
;
870 void wxFrameMSW::PositionToolBar()
873 ::GetClientRect(GetHwnd(), &rect
);
876 if ( GetStatusBar() )
878 int statusX
, statusY
;
879 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
880 rect
.bottom
-= statusY
;
882 #endif // wxUSE_STATUSBAR
884 if ( GetToolBar() && GetToolBar()->IsShown() )
887 GetToolBar()->GetSize(&tw
, &th
);
889 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
898 // Use the 'real' MSW position here
899 GetToolBar()->SetSize(0, 0, tw
, th
, wxSIZE_NO_ADJUSTMENTS
);
902 #endif // wxUSE_TOOLBAR
904 // ----------------------------------------------------------------------------
905 // frame state (iconized/maximized/...)
906 // ----------------------------------------------------------------------------
908 // propagate our state change to all child frames: this allows us to emulate X
909 // Windows behaviour where child frames float independently of the parent one
910 // on the desktop, but are iconized/restored with it
911 void wxFrameMSW::IconizeChildFrames(bool bIconize
)
913 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
915 node
= node
->GetNext() )
917 wxWindow
*win
= node
->GetData();
919 // iconizing the frames with this style under Win95 shell puts them at
920 // the bottom of the screen (as the MDI children) instead of making
921 // them appear in the taskbar because they are, by virtue of this
922 // style, not managed by the taskbar - instead leave Windows take care
925 if ( win
->GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
929 // the child MDI frames are a special case and should not be touched by
930 // the parent frame - instead, they are managed by the user
931 wxFrameMSW
*frame
= wxDynamicCast(win
, wxFrameMSW
);
933 #if wxUSE_MDI_ARCHITECTURE
934 && !wxDynamicCast(frame
, wxMDIChildFrame
)
935 #endif // wxUSE_MDI_ARCHITECTURE
938 frame
->Iconize(bIconize
);
943 // ===========================================================================
944 // message processing
945 // ===========================================================================
947 // ---------------------------------------------------------------------------
949 // ---------------------------------------------------------------------------
951 bool wxFrameMSW::MSWTranslateMessage(WXMSG
* pMsg
)
953 if ( wxWindow::MSWTranslateMessage(pMsg
) )
956 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
957 // try the menu bar accels
958 wxMenuBar
*menuBar
= GetMenuBar();
962 const wxAcceleratorTable
& acceleratorTable
= menuBar
->GetAccelTable();
963 return acceleratorTable
.Translate(this, pMsg
);
966 #endif // wxUSE_MENUS && wxUSE_ACCEL
969 // ---------------------------------------------------------------------------
970 // our private (non virtual) message handlers
971 // ---------------------------------------------------------------------------
973 bool wxFrameMSW::HandlePaint()
976 if ( GetUpdateRect(GetHwnd(), &rect
, FALSE
) )
978 #ifndef __WXMICROWIN__
981 HICON hIcon
= m_icon
.Ok() ? GetHiconOf(m_icon
)
982 : (HICON
)m_defaultIcon
;
984 // Hold a pointer to the dc so long as the OnPaint() message
985 // is being processed
987 HDC hdc
= ::BeginPaint(GetHwnd(), &ps
);
989 // Erase background before painting or we get white background
990 MSWDefWindowProc(WM_ICONERASEBKGND
, (WORD
)(LONG
)ps
.hdc
, 0L);
995 ::GetClientRect(GetHwnd(), &rect
);
997 // FIXME: why hardcoded?
998 static const int icon_width
= 32;
999 static const int icon_height
= 32;
1001 int icon_x
= (int)((rect
.right
- icon_width
)/2);
1002 int icon_y
= (int)((rect
.bottom
- icon_height
)/2);
1004 ::DrawIcon(hdc
, icon_x
, icon_y
, hIcon
);
1007 ::EndPaint(GetHwnd(), &ps
);
1014 return wxWindow::HandlePaint();
1019 // nothing to paint - processed
1024 bool wxFrameMSW::HandleSize(int x
, int y
, WXUINT id
)
1026 bool processed
= FALSE
;
1027 #ifndef __WXMICROWIN__
1032 // only do it it if we were iconized before, otherwise resizing the
1033 // parent frame has a curious side effect of bringing it under it's
1038 // restore all child frames too
1039 IconizeChildFrames(FALSE
);
1041 (void)SendIconizeEvent(FALSE
);
1045 case SIZEFULLSCREEN
:
1050 // iconize all child frames too
1051 IconizeChildFrames(TRUE
);
1053 (void)SendIconizeEvent();
1063 PositionStatusBar();
1064 #endif // wxUSE_STATUSBAR
1068 #endif // wxUSE_TOOLBAR
1070 wxSizeEvent
event(wxSize(x
, y
), m_windowId
);
1071 event
.SetEventObject( this );
1072 processed
= GetEventHandler()->ProcessEvent(event
);
1078 bool wxFrameMSW::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
1082 // In case it's e.g. a toolbar.
1083 wxWindow
*win
= wxFindWinFromHandle(control
);
1085 return win
->MSWCommand(cmd
, id
);
1088 // handle here commands from menus and accelerators
1089 if ( cmd
== 0 || cmd
== 1 )
1091 #if wxUSE_MENUS_NATIVE
1092 if ( wxCurrentPopupMenu
)
1094 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
1095 wxCurrentPopupMenu
= NULL
;
1097 return popupMenu
->MSWCommand(cmd
, id
);
1099 #endif // wxUSE_MENUS_NATIVE
1101 if ( ProcessCommand(id
) )
1110 bool wxFrameMSW::HandleMenuSelect(WXWORD nItem
, WXWORD flags
, WXHMENU hMenu
)
1113 if ( flags
== 0xFFFF && hMenu
== 0 )
1115 // menu was removed from screen
1118 #ifndef __WXMICROWIN__
1119 else if ( !(flags
& MF_POPUP
) && !(flags
& MF_SEPARATOR
) )
1127 // don't give hints for separators (doesn't make sense) nor for the
1128 // items opening popup menus (they don't have them anyhow) but do clear
1129 // the status line - otherwise, we would be left with the help message
1130 // for the previous item which doesn't apply any more
1131 wxStatusBar
*statbar
= GetStatusBar();
1134 statbar
->SetStatusText(wxEmptyString
);
1136 #endif // wxUSE_STATUSBAR
1141 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, item
);
1142 event
.SetEventObject( this );
1144 return GetEventHandler()->ProcessEvent(event
);
1147 // ---------------------------------------------------------------------------
1148 // the window proc for wxFrameMSW
1149 // ---------------------------------------------------------------------------
1151 long wxFrameMSW::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1154 bool processed
= FALSE
;
1159 // if we can't close, tell the system that we processed the
1160 // message - otherwise it would close us
1161 processed
= !Close();
1168 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
1171 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
1175 #ifndef __WXMICROWIN__
1180 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
1182 processed
= HandleMenuSelect(item
, flags
, hmenu
);
1188 processed
= HandlePaint();
1191 #ifndef __WXMICROWIN__
1192 case WM_QUERYDRAGICON
:
1194 HICON hIcon
= m_icon
.Ok() ? GetHiconOf(m_icon
)
1195 : (HICON
)(m_defaultIcon
);
1197 processed
= rc
!= 0;
1203 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
1208 rc
= wxWindow::MSWWindowProc(message
, wParam
, lParam
);