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 // ============================================================================
87 // ============================================================================
89 // ----------------------------------------------------------------------------
90 // static class members
91 // ----------------------------------------------------------------------------
94 #if wxUSE_NATIVE_STATUSBAR
95 bool wxFrameMSW::m_useNativeStatusBar
= TRUE
;
97 bool wxFrameMSW::m_useNativeStatusBar
= FALSE
;
99 #endif // wxUSE_NATIVE_STATUSBAR
101 // ----------------------------------------------------------------------------
102 // creation/destruction
103 // ----------------------------------------------------------------------------
105 void wxFrameMSW::Init()
108 m_maximizeOnShow
= FALSE
;
114 // Data to save/restore when calling ShowFullScreen
116 m_fsOldWindowStyle
= 0;
117 m_fsStatusBarFields
= 0;
118 m_fsStatusBarHeight
= 0;
119 m_fsToolBarHeight
= 0;
121 m_fsIsMaximized
= FALSE
;
122 m_fsIsShowing
= FALSE
;
124 m_winLastFocused
= (wxWindow
*)NULL
;
126 // unlike (almost?) all other windows, frames are created hidden
130 bool wxFrameMSW::Create(wxWindow
*parent
,
132 const wxString
& title
,
136 const wxString
& name
)
139 m_windowStyle
= style
;
141 m_frameMenuBar
= NULL
;
142 #endif // wxUSE_MENUS
144 m_frameToolBar
= NULL
;
145 #endif // wxUSE_TOOLBAR
147 m_frameStatusBar
= NULL
;
148 #endif // wxUSE_STATUSBAR
150 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
155 m_windowId
= (int)NewControlId();
157 if (parent
) parent
->AddChild(this);
166 wxTopLevelWindows
.Append(this);
168 MSWCreate(m_windowId
, parent
, wxFrameClassName
, this, title
,
169 x
, y
, width
, height
, style
);
171 wxModelessWindows
.Append(this);
176 wxFrameMSW::~wxFrameMSW()
178 m_isBeingDeleted
= TRUE
;
179 wxTopLevelWindows
.DeleteObject(this);
181 // the ~wxToolBar() code relies on the previous line to be executed before
182 // this one, i.e. the frame should remove itself from wxTopLevelWindows
183 // before destorying its toolbar
186 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
188 wxTheApp
->SetTopWindow(NULL
);
190 if (wxTheApp
->GetExitOnFrameDelete())
196 wxModelessWindows
.DeleteObject(this);
198 // For some reason, wxWindows can activate another task altogether
199 // when a frame is destroyed after a modal dialog has been invoked.
200 // Try to bring the parent to the top.
201 // MT:Only do this if this frame is currently the active window, else weird
202 // things start to happen
203 if ( wxGetActiveWindow() == this )
204 if (GetParent() && GetParent()->GetHWND())
205 ::BringWindowToTop((HWND
) GetParent()->GetHWND());
208 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
209 void wxFrameMSW::DoGetClientSize(int *x
, int *y
) const
212 ::GetClientRect(GetHwnd(), &rect
);
215 if ( GetStatusBar() && GetStatusBar()->IsShown() )
217 int statusX
, statusY
;
218 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
219 rect
.bottom
-= statusY
;
221 #endif // wxUSE_STATUSBAR
223 wxPoint
pt(GetClientAreaOrigin());
233 // Set the client size (i.e. leave the calculation of borders etc.
235 void wxFrameMSW::DoSetClientSize(int width
, int height
)
237 HWND hWnd
= GetHwnd();
240 ::GetClientRect(hWnd
, &rectClient
);
243 ::GetWindowRect(hWnd
, &rectTotal
);
245 // Find the difference between the entire window (title bar and all)
246 // and the client area; add this to the new client size to move the
248 width
+= rectTotal
.right
- rectTotal
.left
- rectClient
.right
;
249 height
+= rectTotal
.bottom
- rectTotal
.top
- rectClient
.bottom
;
252 wxStatusBar
*statbar
= GetStatusBar();
253 if ( statbar
&& statbar
->IsShown() )
255 // leave enough space for the status bar
256 height
+= statbar
->GetSize().y
;
258 #endif // wxUSE_STATUSBAR
260 // note that this takes the toolbar into account
261 wxPoint pt
= GetClientAreaOrigin();
265 if ( !::MoveWindow(hWnd
, rectTotal
.left
, rectTotal
.top
,
266 width
, height
, TRUE
/* redraw */) )
268 wxLogLastError(_T("MoveWindow"));
271 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
272 event
.SetEventObject(this);
273 GetEventHandler()->ProcessEvent(event
);
276 void wxFrameMSW::DoGetSize(int *width
, int *height
) const
279 ::GetWindowRect(GetHwnd(), &rect
);
281 *width
= rect
.right
- rect
.left
;
282 *height
= rect
.bottom
- rect
.top
;
285 void wxFrameMSW::DoGetPosition(int *x
, int *y
) const
288 ::GetWindowRect(GetHwnd(), &rect
);
294 // ----------------------------------------------------------------------------
295 // variations around ::ShowWindow()
296 // ----------------------------------------------------------------------------
298 void wxFrameMSW::DoShowWindow(int nShowCmd
)
300 ::ShowWindow(GetHwnd(), nShowCmd
);
302 m_iconized
= nShowCmd
== SW_MINIMIZE
;
305 bool wxFrameMSW::Show(bool show
)
307 // don't use wxWindow version as we want to call DoShowWindow()
308 if ( !wxWindowBase::Show(show
) )
314 if ( m_maximizeOnShow
)
317 nShowCmd
= SW_MAXIMIZE
;
319 m_maximizeOnShow
= FALSE
;
331 DoShowWindow(nShowCmd
);
335 ::BringWindowToTop(GetHwnd());
337 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
338 event
.SetEventObject( this );
339 GetEventHandler()->ProcessEvent(event
);
343 // Try to highlight the correct window (the parent)
346 HWND hWndParent
= GetHwndOf(GetParent());
348 ::BringWindowToTop(hWndParent
);
355 void wxFrameMSW::Iconize(bool iconize
)
357 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
360 void wxFrameMSW::Maximize(bool maximize
)
364 // just maximize it directly
365 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
369 // we can't maximize the hidden frame because it shows it as well, so
370 // just remember that we should do it later in this case
371 m_maximizeOnShow
= TRUE
;
375 void wxFrameMSW::Restore()
377 DoShowWindow(SW_RESTORE
);
380 bool wxFrameMSW::IsIconized() const
382 ((wxFrameMSW
*)this)->m_iconized
= (::IsIconic(GetHwnd()) != 0);
387 bool wxFrameMSW::IsMaximized() const
389 return (::IsZoomed(GetHwnd()) != 0);
392 void wxFrameMSW::SetIcon(const wxIcon
& icon
)
394 wxFrameBase::SetIcon(icon
);
396 #if defined(__WIN95__)
399 SendMessage(GetHwnd(), WM_SETICON
,
400 (WPARAM
)TRUE
, (LPARAM
)(HICON
) m_icon
.GetHICON());
405 // generate an artificial resize event
406 void wxFrame::SendSizeEvent()
410 ::GetWindowRect(GetHwnd(), &r
);
412 if ( !::GetWindowRect(GetHwnd(), &r
) )
414 wxLogLastError(_T("GetWindowRect"));
420 (void)::PostMessage(GetHwnd(), WM_SIZE
,
421 IsMaximized() ? SIZE_MAXIMIZED
: SIZE_RESTORED
,
422 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
427 wxStatusBar
*wxFrameMSW::OnCreateStatusBar(int number
,
430 const wxString
& name
)
432 wxStatusBar
*statusBar
= NULL
;
434 #if wxUSE_NATIVE_STATUSBAR
435 if ( !UsesNativeStatusBar() )
437 statusBar
= (wxStatusBar
*)new wxStatusBarGeneric(this, id
, style
);
442 statusBar
= new wxStatusBar(this, id
, style
, name
);
445 // Set the height according to the font and the border size
446 wxClientDC
dc(statusBar
);
447 dc
.SetFont(statusBar
->GetFont());
450 dc
.GetTextExtent(_T("X"), NULL
, &y
);
452 int height
= (int)( (11*y
)/10 + 2*statusBar
->GetBorderY());
454 statusBar
->SetSize(-1, -1, -1, height
);
456 statusBar
->SetFieldsCount(number
);
461 void wxFrameMSW::PositionStatusBar()
463 if ( !m_frameStatusBar
)
467 GetClientSize(&w
, &h
);
469 m_frameStatusBar
->GetSize(&sw
, &sh
);
471 // Since we wish the status bar to be directly under the client area,
472 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
473 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
475 #endif // wxUSE_STATUSBAR
477 void wxFrameMSW::DetachMenuBar()
480 if ( m_frameMenuBar
)
482 m_frameMenuBar
->Detach();
483 m_frameMenuBar
= NULL
;
485 #endif // wxUSE_MENUS
488 void wxFrameMSW::SetMenuBar(wxMenuBar
*menubar
)
491 // detach the old menu bar in any case
494 #if wxUSE_MENUS_NATIVE
497 // actually remove the menu from the frame
498 m_hMenu
= (WXHMENU
)0;
499 InternalSetMenuBar();
501 else // set new non NULL menu bar
503 // Can set a menubar several times.
504 if ( menubar
->GetHMenu() )
506 m_hMenu
= menubar
->GetHMenu();
510 if (menubar
->IsAttached())
513 m_hMenu
= menubar
->Create();
519 InternalSetMenuBar();
521 #endif // wxUSE_MENUS_NATIVE
525 m_frameMenuBar
= menubar
;
526 menubar
->Attach((wxFrame
*)this);
528 #endif // wxUSE_MENUS
531 #if wxUSE_MENUS_NATIVE
533 void wxFrameMSW::InternalSetMenuBar()
535 if ( !::SetMenu(GetHwnd(), (HMENU
)m_hMenu
) )
537 wxLogLastError(wxT("SetMenu"));
541 #endif // wxUSE_MENUS_NATIVE
543 // Responds to colour changes, and passes event on to children.
544 void wxFrameMSW::OnSysColourChanged(wxSysColourChangedEvent
& event
)
546 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
550 if ( m_frameStatusBar
)
552 wxSysColourChangedEvent event2
;
553 event2
.SetEventObject( m_frameStatusBar
);
554 m_frameStatusBar
->GetEventHandler()->ProcessEvent(event2
);
556 #endif // wxUSE_STATUSBAR
558 // Propagate the event to the non-top-level children
559 wxWindow::OnSysColourChanged(event
);
562 // Pass TRUE to show full screen, FALSE to restore.
563 bool wxFrameMSW::ShowFullScreen(bool show
, long style
)
570 m_fsIsShowing
= TRUE
;
574 wxToolBar
*theToolBar
= GetToolBar();
576 theToolBar
->GetSize(NULL
, &m_fsToolBarHeight
);
578 // zap the toolbar, menubar, and statusbar
580 if ((style
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
582 theToolBar
->SetSize(-1,0);
583 theToolBar
->Show(FALSE
);
585 #endif // wxUSE_TOOLBAR
587 if (style
& wxFULLSCREEN_NOMENUBAR
)
588 SetMenu((HWND
)GetHWND(), (HMENU
) NULL
);
591 wxStatusBar
*theStatusBar
= GetStatusBar();
593 theStatusBar
->GetSize(NULL
, &m_fsStatusBarHeight
);
595 // Save the number of fields in the statusbar
596 if ((style
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
598 //m_fsStatusBarFields = theStatusBar->GetFieldsCount();
599 //SetStatusBar((wxStatusBar*) NULL);
600 //delete theStatusBar;
601 theStatusBar
->Show(FALSE
);
604 m_fsStatusBarFields
= 0;
605 #endif // wxUSE_STATUSBAR
607 // zap the frame borders
609 // save the 'normal' window style
610 m_fsOldWindowStyle
= GetWindowLong((HWND
)GetHWND(), GWL_STYLE
);
612 // save the old position, width & height, maximize state
613 m_fsOldSize
= GetRect();
614 m_fsIsMaximized
= IsMaximized();
616 // decide which window style flags to turn off
617 LONG newStyle
= m_fsOldWindowStyle
;
620 if (style
& wxFULLSCREEN_NOBORDER
)
621 offFlags
|= WS_BORDER
;
622 if (style
& wxFULLSCREEN_NOCAPTION
)
623 offFlags
|= (WS_CAPTION
| WS_SYSMENU
);
625 newStyle
&= (~offFlags
);
627 // change our window style to be compatible with full-screen mode
628 SetWindowLong((HWND
)GetHWND(), GWL_STYLE
, newStyle
);
630 // resize to the size of the desktop
634 ::GetWindowRect(GetDesktopWindow(), &rect
);
635 width
= rect
.right
- rect
.left
;
636 height
= rect
.bottom
- rect
.top
;
638 SetSize(width
, height
);
640 // now flush the window style cache and actually go full-screen
641 SetWindowPos((HWND
)GetHWND(), HWND_TOP
, 0, 0, width
, height
, SWP_FRAMECHANGED
);
643 wxSizeEvent
event(wxSize(width
, height
), GetId());
644 GetEventHandler()->ProcessEvent(event
);
653 m_fsIsShowing
= FALSE
;
656 wxToolBar
*theToolBar
= GetToolBar();
658 // restore the toolbar, menubar, and statusbar
659 if (theToolBar
&& (m_fsStyle
& wxFULLSCREEN_NOTOOLBAR
))
661 theToolBar
->SetSize(-1, m_fsToolBarHeight
);
662 theToolBar
->Show(TRUE
);
664 #endif // wxUSE_TOOLBAR
667 if ( m_fsStyle
& wxFULLSCREEN_NOSTATUSBAR
)
669 //CreateStatusBar(m_fsStatusBarFields);
672 GetStatusBar()->Show(TRUE
);
676 #endif // wxUSE_STATUSBAR
678 if ((m_fsStyle
& wxFULLSCREEN_NOMENUBAR
) && (m_hMenu
!= 0))
679 SetMenu((HWND
)GetHWND(), (HMENU
)m_hMenu
);
681 Maximize(m_fsIsMaximized
);
682 SetWindowLong((HWND
)GetHWND(),GWL_STYLE
, m_fsOldWindowStyle
);
683 SetWindowPos((HWND
)GetHWND(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
684 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
695 bool wxFrameMSW::MSWCreate(int id
, wxWindow
*parent
, const wxChar
*wclass
, wxWindow
*wx_win
, const wxChar
*title
,
696 int x
, int y
, int width
, int height
, long style
)
699 m_defaultIcon
= (WXHICON
) (wxSTD_FRAME_ICON
? wxSTD_FRAME_ICON
: wxDEFAULT_FRAME_ICON
);
701 // If child windows aren't properly drawn initially, WS_CLIPCHILDREN
702 // could be the culprit. But without it, you can get a lot of flicker.
705 if ( style
& wxCAPTION
)
707 if ( style
& wxFRAME_TOOL_WINDOW
)
708 msflags
|= WS_POPUPWINDOW
;
710 msflags
|= WS_OVERLAPPED
;
717 if (style
& wxMINIMIZE_BOX
)
718 msflags
|= WS_MINIMIZEBOX
;
719 if (style
& wxMAXIMIZE_BOX
)
720 msflags
|= WS_MAXIMIZEBOX
;
721 if (style
& wxTHICK_FRAME
)
722 msflags
|= WS_THICKFRAME
;
723 if (style
& wxSYSTEM_MENU
)
724 msflags
|= WS_SYSMENU
;
725 if ( style
& wxMINIMIZE
)
726 msflags
|= WS_MINIMIZE
;
727 if (style
& wxMAXIMIZE
)
728 msflags
|= WS_MAXIMIZE
;
729 if (style
& wxCAPTION
)
730 msflags
|= WS_CAPTION
;
731 if (style
& wxCLIP_CHILDREN
)
732 msflags
|= WS_CLIPCHILDREN
;
734 // Keep this in wxFrameMSW because it saves recoding this function
736 #if wxUSE_ITSY_BITSY && !defined(__WIN32__)
737 if (style
& wxTINY_CAPTION_VERT
)
738 msflags
|= IBS_VERTCAPTION
;
739 if (style
& wxTINY_CAPTION_HORIZ
)
740 msflags
|= IBS_HORZCAPTION
;
742 if (style
& wxTINY_CAPTION_VERT
)
743 msflags
|= WS_CAPTION
;
744 if (style
& wxTINY_CAPTION_HORIZ
)
745 msflags
|= WS_CAPTION
;
747 if ((style
& wxTHICK_FRAME
) == 0)
748 msflags
|= WS_BORDER
;
750 WXDWORD extendedStyle
= MakeExtendedStyle(style
);
752 // make all frames appear in the win9x shell taskbar unless
753 // wxFRAME_TOOL_WINDOW or wxFRAME_NO_TASKBAR is given - without giving them
754 // WS_EX_APPWINDOW style, the child (i.e. owned) frames wouldn't appear in it
755 #if !defined(__WIN16__) && !defined(__SC__)
756 if ( (style
& wxFRAME_TOOL_WINDOW
) ||
757 (style
& wxFRAME_NO_TASKBAR
) )
758 extendedStyle
|= WS_EX_TOOLWINDOW
;
759 else if ( !(style
& wxFRAME_NO_TASKBAR
) )
760 extendedStyle
|= WS_EX_APPWINDOW
;
763 if (style
& wxSTAY_ON_TOP
)
764 extendedStyle
|= WS_EX_TOPMOST
;
767 if (m_exStyle
& wxFRAME_EX_CONTEXTHELP
)
768 extendedStyle
|= WS_EX_CONTEXTHELP
;
772 if ( !wxWindow::MSWCreate(id
, parent
, wclass
, wx_win
, title
, x
, y
, width
, height
,
773 msflags
, NULL
, extendedStyle
) )
776 // Seems to be necessary if we use WS_POPUP
777 // style instead of WS_OVERLAPPED
778 if (width
> -1 && height
> -1)
779 ::PostMessage(GetHwnd(), WM_SIZE
, SIZE_RESTORED
, MAKELPARAM(width
, height
));
784 // Default activation behaviour - set the focus for the first child
786 void wxFrameMSW::OnActivate(wxActivateEvent
& event
)
788 if ( event
.GetActive() )
790 // restore focus to the child which was last focused
791 wxLogTrace(_T("focus"), _T("wxFrameMSW %08x activated."), m_hWnd
);
793 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
800 wxSetFocusToChild(parent
, &m_winLastFocused
);
804 // remember the last focused child if it is our child
805 m_winLastFocused
= FindFocus();
807 // so we NULL it out if it's a child from some other frame
808 wxWindow
*win
= m_winLastFocused
;
811 if ( win
->IsTopLevel() )
815 m_winLastFocused
= NULL
;
821 win
= win
->GetParent();
824 wxLogTrace(_T("focus"),
825 _T("wxFrameMSW %08x deactivated, last focused: %08x."),
827 m_winLastFocused
? GetHwndOf(m_winLastFocused
)
834 // ----------------------------------------------------------------------------
835 // tool/status bar stuff
836 // ----------------------------------------------------------------------------
840 wxToolBar
* wxFrameMSW::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
842 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
847 return m_frameToolBar
;
850 void wxFrameMSW::PositionToolBar()
853 ::GetClientRect(GetHwnd(), &rect
);
856 if ( GetStatusBar() )
858 int statusX
, statusY
;
859 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
860 rect
.bottom
-= statusY
;
862 #endif // wxUSE_STATUSBAR
864 if ( GetToolBar() && GetToolBar()->IsShown() )
867 GetToolBar()->GetSize(&tw
, &th
);
869 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
878 // Use the 'real' MSW position here
879 GetToolBar()->SetSize(0, 0, tw
, th
, wxSIZE_NO_ADJUSTMENTS
);
882 #endif // wxUSE_TOOLBAR
884 // ----------------------------------------------------------------------------
885 // frame state (iconized/maximized/...)
886 // ----------------------------------------------------------------------------
888 // propagate our state change to all child frames: this allows us to emulate X
889 // Windows behaviour where child frames float independently of the parent one
890 // on the desktop, but are iconized/restored with it
891 void wxFrameMSW::IconizeChildFrames(bool bIconize
)
893 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
895 node
= node
->GetNext() )
897 wxWindow
*win
= node
->GetData();
899 // iconizing the frames with this style under Win95 shell puts them at
900 // the bottom of the screen (as the MDI children) instead of making
901 // them appear in the taskbar because they are, by virtue of this
902 // style, not managed by the taskbar - instead leave Windows take care
905 if ( win
->GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
909 // the child MDI frames are a special case and should not be touched by
910 // the parent frame - instead, they are managed by the user
911 wxFrameMSW
*frame
= wxDynamicCast(win
, wxFrameMSW
);
913 #if wxUSE_MDI_ARCHITECTURE
914 && !wxDynamicCast(frame
, wxMDIChildFrame
)
915 #endif // wxUSE_MDI_ARCHITECTURE
918 frame
->Iconize(bIconize
);
923 // ===========================================================================
924 // message processing
925 // ===========================================================================
927 // ---------------------------------------------------------------------------
929 // ---------------------------------------------------------------------------
931 bool wxFrameMSW::MSWTranslateMessage(WXMSG
* pMsg
)
933 if ( wxWindow::MSWTranslateMessage(pMsg
) )
936 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
937 // try the menu bar accels
938 wxMenuBar
*menuBar
= GetMenuBar();
942 const wxAcceleratorTable
& acceleratorTable
= menuBar
->GetAccelTable();
943 return acceleratorTable
.Translate(this, pMsg
);
946 #endif // wxUSE_MENUS && wxUSE_ACCEL
949 // ---------------------------------------------------------------------------
950 // our private (non virtual) message handlers
951 // ---------------------------------------------------------------------------
953 bool wxFrameMSW::HandlePaint()
956 if ( GetUpdateRect(GetHwnd(), &rect
, FALSE
) )
960 HICON hIcon
= m_icon
.Ok() ? GetHiconOf(m_icon
)
961 : (HICON
)m_defaultIcon
;
963 // Hold a pointer to the dc so long as the OnPaint() message
964 // is being processed
966 HDC hdc
= ::BeginPaint(GetHwnd(), &ps
);
968 // Erase background before painting or we get white background
969 MSWDefWindowProc(WM_ICONERASEBKGND
, (WORD
)(LONG
)ps
.hdc
, 0L);
974 ::GetClientRect(GetHwnd(), &rect
);
976 // FIXME: why hardcoded?
977 static const int icon_width
= 32;
978 static const int icon_height
= 32;
980 int icon_x
= (int)((rect
.right
- icon_width
)/2);
981 int icon_y
= (int)((rect
.bottom
- icon_height
)/2);
983 ::DrawIcon(hdc
, icon_x
, icon_y
, hIcon
);
986 ::EndPaint(GetHwnd(), &ps
);
992 return wxWindow::HandlePaint();
997 // nothing to paint - processed
1002 bool wxFrameMSW::HandleSize(int x
, int y
, WXUINT id
)
1004 bool processed
= FALSE
;
1009 // only do it it if we were iconized before, otherwise resizing the
1010 // parent frame has a curious side effect of bringing it under it's
1015 // restore all child frames too
1016 IconizeChildFrames(FALSE
);
1018 (void)SendIconizeEvent(FALSE
);
1022 case SIZEFULLSCREEN
:
1027 // iconize all child frames too
1028 IconizeChildFrames(TRUE
);
1030 (void)SendIconizeEvent();
1039 PositionStatusBar();
1040 #endif // wxUSE_STATUSBAR
1044 #endif // wxUSE_TOOLBAR
1046 wxSizeEvent
event(wxSize(x
, y
), m_windowId
);
1047 event
.SetEventObject( this );
1048 processed
= GetEventHandler()->ProcessEvent(event
);
1054 bool wxFrameMSW::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
1058 // In case it's e.g. a toolbar.
1059 wxWindow
*win
= wxFindWinFromHandle(control
);
1061 return win
->MSWCommand(cmd
, id
);
1064 // handle here commands from menus and accelerators
1065 if ( cmd
== 0 || cmd
== 1 )
1067 #if wxUSE_MENUS_NATIVE
1068 if ( wxCurrentPopupMenu
)
1070 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
1071 wxCurrentPopupMenu
= NULL
;
1073 return popupMenu
->MSWCommand(cmd
, id
);
1075 #endif // wxUSE_MENUS_NATIVE
1077 if ( ProcessCommand(id
) )
1086 bool wxFrameMSW::HandleMenuSelect(WXWORD nItem
, WXWORD flags
, WXHMENU hMenu
)
1089 if ( flags
== 0xFFFF && hMenu
== 0 )
1091 // menu was removed from screen
1094 else if ( !(flags
& MF_POPUP
) && !(flags
& MF_SEPARATOR
) )
1101 // don't give hints for separators (doesn't make sense) nor for the
1102 // items opening popup menus (they don't have them anyhow) but do clear
1103 // the status line - otherwise, we would be left with the help message
1104 // for the previous item which doesn't apply any more
1105 wxStatusBar
*statbar
= GetStatusBar();
1108 statbar
->SetStatusText(wxEmptyString
);
1110 #endif // wxUSE_STATUSBAR
1115 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, item
);
1116 event
.SetEventObject( this );
1118 return GetEventHandler()->ProcessEvent(event
);
1121 // ---------------------------------------------------------------------------
1122 // the window proc for wxFrameMSW
1123 // ---------------------------------------------------------------------------
1125 long wxFrameMSW::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1128 bool processed
= FALSE
;
1133 // if we can't close, tell the system that we processed the
1134 // message - otherwise it would close us
1135 processed
= !Close();
1142 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
1145 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
1153 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
1155 processed
= HandleMenuSelect(item
, flags
, hmenu
);
1160 processed
= HandlePaint();
1163 case WM_QUERYDRAGICON
:
1165 HICON hIcon
= m_icon
.Ok() ? GetHiconOf(m_icon
)
1166 : (HICON
)(m_defaultIcon
);
1168 processed
= rc
!= 0;
1173 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
1178 rc
= wxWindow::MSWWindowProc(message
, wParam
, lParam
);