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 #ifdef __WXMICROWIN__
387 ((wxFrameMSW
*)this)->m_iconized
= (::IsIconic(GetHwnd()) != 0);
393 bool wxFrameMSW::IsMaximized() const
395 #ifdef __WXMICROWIN__
399 return (::IsZoomed(GetHwnd()) != 0);
403 void wxFrameMSW::SetIcon(const wxIcon
& icon
)
405 wxFrameBase::SetIcon(icon
);
407 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
410 SendMessage(GetHwnd(), WM_SETICON
,
411 (WPARAM
)TRUE
, (LPARAM
)(HICON
) m_icon
.GetHICON());
416 // generate an artificial resize event
417 void wxFrameMSW::SendSizeEvent()
421 ::GetWindowRect(GetHwnd(), &r
);
423 if ( !::GetWindowRect(GetHwnd(), &r
) )
425 wxLogLastError(_T("GetWindowRect"));
431 (void)::PostMessage(GetHwnd(), WM_SIZE
,
432 IsMaximized() ? SIZE_MAXIMIZED
: SIZE_RESTORED
,
433 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
438 wxStatusBar
*wxFrameMSW::OnCreateStatusBar(int number
,
441 const wxString
& name
)
443 wxStatusBar
*statusBar
= NULL
;
445 #if wxUSE_NATIVE_STATUSBAR
446 if ( !UsesNativeStatusBar() )
448 statusBar
= (wxStatusBar
*)new wxStatusBarGeneric(this, id
, style
);
453 statusBar
= new wxStatusBar(this, id
, style
, name
);
456 // Set the height according to the font and the border size
457 wxClientDC
dc(statusBar
);
458 dc
.SetFont(statusBar
->GetFont());
461 dc
.GetTextExtent(_T("X"), NULL
, &y
);
463 int height
= (int)( (11*y
)/10 + 2*statusBar
->GetBorderY());
465 statusBar
->SetSize(-1, -1, -1, height
);
467 statusBar
->SetFieldsCount(number
);
472 void wxFrameMSW::PositionStatusBar()
474 if ( !m_frameStatusBar
)
478 GetClientSize(&w
, &h
);
480 m_frameStatusBar
->GetSize(&sw
, &sh
);
482 // Since we wish the status bar to be directly under the client area,
483 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
484 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
486 #endif // wxUSE_STATUSBAR
488 void wxFrameMSW::DetachMenuBar()
491 if ( m_frameMenuBar
)
493 m_frameMenuBar
->Detach();
494 m_frameMenuBar
= NULL
;
496 #endif // wxUSE_MENUS
499 void wxFrameMSW::SetMenuBar(wxMenuBar
*menubar
)
502 // detach the old menu bar in any case
505 #if wxUSE_MENUS_NATIVE
508 // actually remove the menu from the frame
509 m_hMenu
= (WXHMENU
)0;
510 InternalSetMenuBar();
512 else // set new non NULL menu bar
514 // Can set a menubar several times.
515 if ( menubar
->GetHMenu() )
517 m_hMenu
= menubar
->GetHMenu();
521 if (menubar
->IsAttached())
524 m_hMenu
= menubar
->Create();
530 InternalSetMenuBar();
532 #endif // wxUSE_MENUS_NATIVE
536 m_frameMenuBar
= menubar
;
537 menubar
->Attach((wxFrame
*)this);
539 #endif // wxUSE_MENUS
542 #if wxUSE_MENUS_NATIVE
544 void wxFrameMSW::InternalSetMenuBar()
546 #ifndef __WXMICROWIN__
547 if ( !::SetMenu(GetHwnd(), (HMENU
)m_hMenu
) )
549 wxLogLastError(wxT("SetMenu"));
554 #endif // wxUSE_MENUS_NATIVE
556 // Responds to colour changes, and passes event on to children.
557 void wxFrameMSW::OnSysColourChanged(wxSysColourChangedEvent
& event
)
559 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
563 if ( m_frameStatusBar
)
565 wxSysColourChangedEvent event2
;
566 event2
.SetEventObject( m_frameStatusBar
);
567 m_frameStatusBar
->GetEventHandler()->ProcessEvent(event2
);
569 #endif // wxUSE_STATUSBAR
571 // Propagate the event to the non-top-level children
572 wxWindow::OnSysColourChanged(event
);
575 // Pass TRUE to show full screen, FALSE to restore.
576 bool wxFrameMSW::ShowFullScreen(bool show
, long style
)
583 m_fsIsShowing
= TRUE
;
587 wxToolBar
*theToolBar
= GetToolBar();
589 theToolBar
->GetSize(NULL
, &m_fsToolBarHeight
);
591 // zap the toolbar, menubar, and statusbar
593 if ((style
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
595 theToolBar
->SetSize(-1,0);
596 theToolBar
->Show(FALSE
);
598 #endif // wxUSE_TOOLBAR
600 #ifndef __WXMICROWIN__
601 if (style
& wxFULLSCREEN_NOMENUBAR
)
602 SetMenu((HWND
)GetHWND(), (HMENU
) NULL
);
606 wxStatusBar
*theStatusBar
= GetStatusBar();
608 theStatusBar
->GetSize(NULL
, &m_fsStatusBarHeight
);
610 // Save the number of fields in the statusbar
611 if ((style
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
613 //m_fsStatusBarFields = theStatusBar->GetFieldsCount();
614 //SetStatusBar((wxStatusBar*) NULL);
615 //delete theStatusBar;
616 theStatusBar
->Show(FALSE
);
619 m_fsStatusBarFields
= 0;
620 #endif // wxUSE_STATUSBAR
622 // zap the frame borders
624 // save the 'normal' window style
625 m_fsOldWindowStyle
= GetWindowLong((HWND
)GetHWND(), GWL_STYLE
);
627 // save the old position, width & height, maximize state
628 m_fsOldSize
= GetRect();
629 m_fsIsMaximized
= IsMaximized();
631 // decide which window style flags to turn off
632 LONG newStyle
= m_fsOldWindowStyle
;
635 if (style
& wxFULLSCREEN_NOBORDER
)
636 offFlags
|= WS_BORDER
;
637 if (style
& wxFULLSCREEN_NOCAPTION
)
638 offFlags
|= (WS_CAPTION
| WS_SYSMENU
);
640 newStyle
&= (~offFlags
);
642 // change our window style to be compatible with full-screen mode
643 SetWindowLong((HWND
)GetHWND(), GWL_STYLE
, newStyle
);
645 // resize to the size of the desktop
649 ::GetWindowRect(GetDesktopWindow(), &rect
);
650 width
= rect
.right
- rect
.left
;
651 height
= rect
.bottom
- rect
.top
;
653 SetSize(width
, height
);
655 // now flush the window style cache and actually go full-screen
656 SetWindowPos((HWND
)GetHWND(), HWND_TOP
, 0, 0, width
, height
, SWP_FRAMECHANGED
);
658 wxSizeEvent
event(wxSize(width
, height
), GetId());
659 GetEventHandler()->ProcessEvent(event
);
668 m_fsIsShowing
= FALSE
;
671 wxToolBar
*theToolBar
= GetToolBar();
673 // restore the toolbar, menubar, and statusbar
674 if (theToolBar
&& (m_fsStyle
& wxFULLSCREEN_NOTOOLBAR
))
676 theToolBar
->SetSize(-1, m_fsToolBarHeight
);
677 theToolBar
->Show(TRUE
);
679 #endif // wxUSE_TOOLBAR
682 if ( m_fsStyle
& wxFULLSCREEN_NOSTATUSBAR
)
684 //CreateStatusBar(m_fsStatusBarFields);
687 GetStatusBar()->Show(TRUE
);
691 #endif // wxUSE_STATUSBAR
693 #ifndef __WXMICROWIN__
694 if ((m_fsStyle
& wxFULLSCREEN_NOMENUBAR
) && (m_hMenu
!= 0))
695 SetMenu((HWND
)GetHWND(), (HMENU
)m_hMenu
);
698 Maximize(m_fsIsMaximized
);
699 SetWindowLong((HWND
)GetHWND(),GWL_STYLE
, m_fsOldWindowStyle
);
700 SetWindowPos((HWND
)GetHWND(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
701 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
712 bool wxFrameMSW::MSWCreate(int id
, wxWindow
*parent
, const wxChar
*wclass
, wxWindow
*wx_win
, const wxChar
*title
,
713 int x
, int y
, int width
, int height
, long style
)
716 m_defaultIcon
= (WXHICON
) (wxSTD_FRAME_ICON
? wxSTD_FRAME_ICON
: wxDEFAULT_FRAME_ICON
);
718 // If child windows aren't properly drawn initially, WS_CLIPCHILDREN
719 // could be the culprit. But without it, you can get a lot of flicker.
722 if ( style
& wxCAPTION
)
724 if ( style
& wxFRAME_TOOL_WINDOW
)
725 msflags
|= WS_POPUPWINDOW
;
727 msflags
|= WS_OVERLAPPED
;
734 if (style
& wxMINIMIZE_BOX
)
735 msflags
|= WS_MINIMIZEBOX
;
736 if (style
& wxMAXIMIZE_BOX
)
737 msflags
|= WS_MAXIMIZEBOX
;
738 if (style
& wxTHICK_FRAME
)
739 msflags
|= WS_THICKFRAME
;
740 if (style
& wxSYSTEM_MENU
)
741 msflags
|= WS_SYSMENU
;
742 if ( style
& wxMINIMIZE
)
743 msflags
|= WS_MINIMIZE
;
744 if (style
& wxMAXIMIZE
)
745 msflags
|= WS_MAXIMIZE
;
746 if (style
& wxCAPTION
)
747 msflags
|= WS_CAPTION
;
748 if (style
& wxCLIP_CHILDREN
)
749 msflags
|= WS_CLIPCHILDREN
;
751 // Keep this in wxFrameMSW because it saves recoding this function
753 #if wxUSE_ITSY_BITSY && !defined(__WIN32__)
754 if (style
& wxTINY_CAPTION_VERT
)
755 msflags
|= IBS_VERTCAPTION
;
756 if (style
& wxTINY_CAPTION_HORIZ
)
757 msflags
|= IBS_HORZCAPTION
;
759 if (style
& wxTINY_CAPTION_VERT
)
760 msflags
|= WS_CAPTION
;
761 if (style
& wxTINY_CAPTION_HORIZ
)
762 msflags
|= WS_CAPTION
;
764 if ((style
& wxTHICK_FRAME
) == 0)
765 msflags
|= WS_BORDER
;
767 WXDWORD extendedStyle
= MakeExtendedStyle(style
);
769 // make all frames appear in the win9x shell taskbar unless
770 // wxFRAME_TOOL_WINDOW or wxFRAME_NO_TASKBAR is given - without giving them
771 // WS_EX_APPWINDOW style, the child (i.e. owned) frames wouldn't appear in it
772 #if !defined(__WIN16__) && !defined(__SC__)
773 if ( (style
& wxFRAME_TOOL_WINDOW
) ||
774 (style
& wxFRAME_NO_TASKBAR
) )
775 extendedStyle
|= WS_EX_TOOLWINDOW
;
776 else if ( !(style
& wxFRAME_NO_TASKBAR
) )
777 extendedStyle
|= WS_EX_APPWINDOW
;
780 if (style
& wxSTAY_ON_TOP
)
781 extendedStyle
|= WS_EX_TOPMOST
;
784 if (m_exStyle
& wxFRAME_EX_CONTEXTHELP
)
785 extendedStyle
|= WS_EX_CONTEXTHELP
;
789 if ( !wxWindow::MSWCreate(id
, parent
, wclass
, wx_win
, title
, x
, y
, width
, height
,
790 msflags
, NULL
, extendedStyle
) )
793 // Seems to be necessary if we use WS_POPUP
794 // style instead of WS_OVERLAPPED
795 if (width
> -1 && height
> -1)
796 ::PostMessage(GetHwnd(), WM_SIZE
, SIZE_RESTORED
, MAKELPARAM(width
, height
));
801 // Default activation behaviour - set the focus for the first child
803 void wxFrameMSW::OnActivate(wxActivateEvent
& event
)
805 if ( event
.GetActive() )
807 // restore focus to the child which was last focused
808 wxLogTrace(_T("focus"), _T("wxFrameMSW %08x activated."), m_hWnd
);
810 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
817 wxSetFocusToChild(parent
, &m_winLastFocused
);
821 // remember the last focused child if it is our child
822 m_winLastFocused
= FindFocus();
824 // so we NULL it out if it's a child from some other frame
825 wxWindow
*win
= m_winLastFocused
;
828 if ( win
->IsTopLevel() )
832 m_winLastFocused
= NULL
;
838 win
= win
->GetParent();
841 wxLogTrace(_T("focus"),
842 _T("wxFrameMSW %08x deactivated, last focused: %08x."),
844 m_winLastFocused
? GetHwndOf(m_winLastFocused
)
851 // ----------------------------------------------------------------------------
852 // tool/status bar stuff
853 // ----------------------------------------------------------------------------
857 wxToolBar
* wxFrameMSW::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
859 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
864 return m_frameToolBar
;
867 void wxFrameMSW::PositionToolBar()
870 ::GetClientRect(GetHwnd(), &rect
);
873 if ( GetStatusBar() )
875 int statusX
, statusY
;
876 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
877 rect
.bottom
-= statusY
;
879 #endif // wxUSE_STATUSBAR
881 if ( GetToolBar() && GetToolBar()->IsShown() )
884 GetToolBar()->GetSize(&tw
, &th
);
886 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
895 // Use the 'real' MSW position here
896 GetToolBar()->SetSize(0, 0, tw
, th
, wxSIZE_NO_ADJUSTMENTS
);
899 #endif // wxUSE_TOOLBAR
901 // ----------------------------------------------------------------------------
902 // frame state (iconized/maximized/...)
903 // ----------------------------------------------------------------------------
905 // propagate our state change to all child frames: this allows us to emulate X
906 // Windows behaviour where child frames float independently of the parent one
907 // on the desktop, but are iconized/restored with it
908 void wxFrameMSW::IconizeChildFrames(bool bIconize
)
910 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
912 node
= node
->GetNext() )
914 wxWindow
*win
= node
->GetData();
916 // iconizing the frames with this style under Win95 shell puts them at
917 // the bottom of the screen (as the MDI children) instead of making
918 // them appear in the taskbar because they are, by virtue of this
919 // style, not managed by the taskbar - instead leave Windows take care
922 if ( win
->GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
926 // the child MDI frames are a special case and should not be touched by
927 // the parent frame - instead, they are managed by the user
928 wxFrameMSW
*frame
= wxDynamicCast(win
, wxFrameMSW
);
930 #if wxUSE_MDI_ARCHITECTURE
931 && !wxDynamicCast(frame
, wxMDIChildFrame
)
932 #endif // wxUSE_MDI_ARCHITECTURE
935 frame
->Iconize(bIconize
);
940 // ===========================================================================
941 // message processing
942 // ===========================================================================
944 // ---------------------------------------------------------------------------
946 // ---------------------------------------------------------------------------
948 bool wxFrameMSW::MSWTranslateMessage(WXMSG
* pMsg
)
950 if ( wxWindow::MSWTranslateMessage(pMsg
) )
953 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
954 // try the menu bar accels
955 wxMenuBar
*menuBar
= GetMenuBar();
959 const wxAcceleratorTable
& acceleratorTable
= menuBar
->GetAccelTable();
960 return acceleratorTable
.Translate(this, pMsg
);
963 #endif // wxUSE_MENUS && wxUSE_ACCEL
966 // ---------------------------------------------------------------------------
967 // our private (non virtual) message handlers
968 // ---------------------------------------------------------------------------
970 bool wxFrameMSW::HandlePaint()
973 if ( GetUpdateRect(GetHwnd(), &rect
, FALSE
) )
975 #ifndef __WXMICROWIN__
978 HICON hIcon
= m_icon
.Ok() ? GetHiconOf(m_icon
)
979 : (HICON
)m_defaultIcon
;
981 // Hold a pointer to the dc so long as the OnPaint() message
982 // is being processed
984 HDC hdc
= ::BeginPaint(GetHwnd(), &ps
);
986 // Erase background before painting or we get white background
987 MSWDefWindowProc(WM_ICONERASEBKGND
, (WORD
)(LONG
)ps
.hdc
, 0L);
992 ::GetClientRect(GetHwnd(), &rect
);
994 // FIXME: why hardcoded?
995 static const int icon_width
= 32;
996 static const int icon_height
= 32;
998 int icon_x
= (int)((rect
.right
- icon_width
)/2);
999 int icon_y
= (int)((rect
.bottom
- icon_height
)/2);
1001 ::DrawIcon(hdc
, icon_x
, icon_y
, hIcon
);
1004 ::EndPaint(GetHwnd(), &ps
);
1011 return wxWindow::HandlePaint();
1016 // nothing to paint - processed
1021 bool wxFrameMSW::HandleSize(int x
, int y
, WXUINT id
)
1023 bool processed
= FALSE
;
1024 #ifndef __WXMICROWIN__
1029 // only do it it if we were iconized before, otherwise resizing the
1030 // parent frame has a curious side effect of bringing it under it's
1035 // restore all child frames too
1036 IconizeChildFrames(FALSE
);
1038 (void)SendIconizeEvent(FALSE
);
1042 case SIZEFULLSCREEN
:
1047 // iconize all child frames too
1048 IconizeChildFrames(TRUE
);
1050 (void)SendIconizeEvent();
1060 PositionStatusBar();
1061 #endif // wxUSE_STATUSBAR
1065 #endif // wxUSE_TOOLBAR
1067 wxSizeEvent
event(wxSize(x
, y
), m_windowId
);
1068 event
.SetEventObject( this );
1069 processed
= GetEventHandler()->ProcessEvent(event
);
1075 bool wxFrameMSW::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
1079 // In case it's e.g. a toolbar.
1080 wxWindow
*win
= wxFindWinFromHandle(control
);
1082 return win
->MSWCommand(cmd
, id
);
1085 // handle here commands from menus and accelerators
1086 if ( cmd
== 0 || cmd
== 1 )
1088 #if wxUSE_MENUS_NATIVE
1089 if ( wxCurrentPopupMenu
)
1091 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
1092 wxCurrentPopupMenu
= NULL
;
1094 return popupMenu
->MSWCommand(cmd
, id
);
1096 #endif // wxUSE_MENUS_NATIVE
1098 if ( ProcessCommand(id
) )
1107 bool wxFrameMSW::HandleMenuSelect(WXWORD nItem
, WXWORD flags
, WXHMENU hMenu
)
1110 if ( flags
== 0xFFFF && hMenu
== 0 )
1112 // menu was removed from screen
1115 #ifndef __WXMICROWIN__
1116 else if ( !(flags
& MF_POPUP
) && !(flags
& MF_SEPARATOR
) )
1124 // don't give hints for separators (doesn't make sense) nor for the
1125 // items opening popup menus (they don't have them anyhow) but do clear
1126 // the status line - otherwise, we would be left with the help message
1127 // for the previous item which doesn't apply any more
1128 wxStatusBar
*statbar
= GetStatusBar();
1131 statbar
->SetStatusText(wxEmptyString
);
1133 #endif // wxUSE_STATUSBAR
1138 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, item
);
1139 event
.SetEventObject( this );
1141 return GetEventHandler()->ProcessEvent(event
);
1144 // ---------------------------------------------------------------------------
1145 // the window proc for wxFrameMSW
1146 // ---------------------------------------------------------------------------
1148 long wxFrameMSW::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1151 bool processed
= FALSE
;
1156 // if we can't close, tell the system that we processed the
1157 // message - otherwise it would close us
1158 processed
= !Close();
1165 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
1168 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
1172 #ifndef __WXMICROWIN__
1177 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
1179 processed
= HandleMenuSelect(item
, flags
, hmenu
);
1185 processed
= HandlePaint();
1188 #ifndef __WXMICROWIN__
1189 case WM_QUERYDRAGICON
:
1191 HICON hIcon
= m_icon
.Ok() ? GetHiconOf(m_icon
)
1192 : (HICON
)(m_defaultIcon
);
1194 processed
= rc
!= 0;
1200 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
1205 rc
= wxWindow::MSWWindowProc(message
, wParam
, lParam
);