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 const wxChar
*wxFrameClassName
;
69 #if wxUSE_MENUS_NATIVE
70 extern wxMenu
*wxCurrentPopupMenu
;
71 #endif // wxUSE_MENUS_NATIVE
73 // ----------------------------------------------------------------------------
75 // ----------------------------------------------------------------------------
77 BEGIN_EVENT_TABLE(wxFrameMSW
, wxFrameBase
)
78 EVT_ACTIVATE(wxFrameMSW::OnActivate
)
79 EVT_SYS_COLOUR_CHANGED(wxFrameMSW::OnSysColourChanged
)
82 #ifndef __WXUNIVERSAL__
83 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxWindow
)
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 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
147 m_windowId
= (int)NewControlId();
149 if (parent
) parent
->AddChild(this);
158 wxTopLevelWindows
.Append(this);
160 // the frame must have NULL parent HWND or it would be always on top of its
161 // parent which is not what we usually want (in fact, we only want it for
162 // frames with the special wxFRAME_TOOL_WINDOW style handled elsewhere)
163 MSWCreate(m_windowId
, NULL
, wxFrameClassName
, this, title
,
164 x
, y
, width
, height
, style
);
166 wxModelessWindows
.Append(this);
171 wxFrameMSW::~wxFrameMSW()
173 m_isBeingDeleted
= TRUE
;
174 wxTopLevelWindows
.DeleteObject(this);
176 // the ~wxToolBar() code relies on the previous line to be executed before
177 // this one, i.e. the frame should remove itself from wxTopLevelWindows
178 // before destorying its toolbar
181 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
183 wxTheApp
->SetTopWindow(NULL
);
185 if (wxTheApp
->GetExitOnFrameDelete())
191 wxModelessWindows
.DeleteObject(this);
193 // For some reason, wxWindows can activate another task altogether
194 // when a frame is destroyed after a modal dialog has been invoked.
195 // Try to bring the parent to the top.
196 // MT:Only do this if this frame is currently the active window, else weird
197 // things start to happen
198 if ( wxGetActiveWindow() == this )
199 if (GetParent() && GetParent()->GetHWND())
200 ::BringWindowToTop((HWND
) GetParent()->GetHWND());
203 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
204 void wxFrameMSW::DoGetClientSize(int *x
, int *y
) const
207 ::GetClientRect(GetHwnd(), &rect
);
210 if ( GetStatusBar() && GetStatusBar()->IsShown() )
212 int statusX
, statusY
;
213 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
214 rect
.bottom
-= statusY
;
216 #endif // wxUSE_STATUSBAR
218 wxPoint
pt(GetClientAreaOrigin());
228 // Set the client size (i.e. leave the calculation of borders etc.
230 void wxFrameMSW::DoSetClientSize(int width
, int height
)
232 HWND hWnd
= GetHwnd();
235 ::GetClientRect(hWnd
, &rectClient
);
238 ::GetWindowRect(hWnd
, &rectTotal
);
240 // Find the difference between the entire window (title bar and all)
241 // and the client area; add this to the new client size to move the
243 width
+= rectTotal
.right
- rectTotal
.left
- rectClient
.right
;
244 height
+= rectTotal
.bottom
- rectTotal
.top
- rectClient
.bottom
;
247 wxStatusBar
*statbar
= GetStatusBar();
248 if ( statbar
&& statbar
->IsShown() )
250 // leave enough space for the status bar
251 height
+= statbar
->GetSize().y
;
253 #endif // wxUSE_STATUSBAR
255 // note that this takes the toolbar into account
256 wxPoint pt
= GetClientAreaOrigin();
260 if ( !::MoveWindow(hWnd
, rectTotal
.left
, rectTotal
.top
,
261 width
, height
, TRUE
/* redraw */) )
263 wxLogLastError(_T("MoveWindow"));
266 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
267 event
.SetEventObject(this);
268 GetEventHandler()->ProcessEvent(event
);
271 void wxFrameMSW::DoGetSize(int *width
, int *height
) const
274 ::GetWindowRect(GetHwnd(), &rect
);
276 *width
= rect
.right
- rect
.left
;
277 *height
= rect
.bottom
- rect
.top
;
280 void wxFrameMSW::DoGetPosition(int *x
, int *y
) const
283 ::GetWindowRect(GetHwnd(), &rect
);
289 // ----------------------------------------------------------------------------
290 // variations around ::ShowWindow()
291 // ----------------------------------------------------------------------------
293 void wxFrameMSW::DoShowWindow(int nShowCmd
)
295 ::ShowWindow(GetHwnd(), nShowCmd
);
297 m_iconized
= nShowCmd
== SW_MINIMIZE
;
300 bool wxFrameMSW::Show(bool show
)
302 // don't use wxWindow version as we want to call DoShowWindow()
303 if ( !wxWindowBase::Show(show
) )
309 if ( m_maximizeOnShow
)
312 nShowCmd
= SW_MAXIMIZE
;
314 m_maximizeOnShow
= FALSE
;
326 DoShowWindow(nShowCmd
);
330 ::BringWindowToTop(GetHwnd());
332 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
333 event
.SetEventObject( this );
334 GetEventHandler()->ProcessEvent(event
);
338 // Try to highlight the correct window (the parent)
341 HWND hWndParent
= GetHwndOf(GetParent());
343 ::BringWindowToTop(hWndParent
);
350 void wxFrameMSW::Raise()
353 // no SetForegroundWindow() in Win16
354 wxFrameBase::Raise();
356 ::SetForegroundWindow(GetHwnd());
360 void wxFrameMSW::Iconize(bool iconize
)
362 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
365 void wxFrameMSW::Maximize(bool maximize
)
369 // just maximize it directly
370 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
374 // we can't maximize the hidden frame because it shows it as well, so
375 // just remember that we should do it later in this case
376 m_maximizeOnShow
= TRUE
;
380 void wxFrameMSW::Restore()
382 DoShowWindow(SW_RESTORE
);
385 bool wxFrameMSW::IsIconized() const
387 #ifdef __WXMICROWIN__
391 ((wxFrameMSW
*)this)->m_iconized
= (::IsIconic(GetHwnd()) != 0);
397 bool wxFrameMSW::IsMaximized() const
399 #ifdef __WXMICROWIN__
403 return (::IsZoomed(GetHwnd()) != 0);
407 void wxFrameMSW::SetIcon(const wxIcon
& icon
)
409 wxFrameBase::SetIcon(icon
);
411 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
414 SendMessage(GetHwnd(), WM_SETICON
,
415 (WPARAM
)TRUE
, (LPARAM
)(HICON
) m_icon
.GetHICON());
420 // generate an artificial resize event
421 void wxFrameMSW::SendSizeEvent()
425 ::GetWindowRect(GetHwnd(), &r
);
427 if ( !::GetWindowRect(GetHwnd(), &r
) )
429 wxLogLastError(_T("GetWindowRect"));
435 (void)::PostMessage(GetHwnd(), WM_SIZE
,
436 IsMaximized() ? SIZE_MAXIMIZED
: SIZE_RESTORED
,
437 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
442 wxStatusBar
*wxFrameMSW::OnCreateStatusBar(int number
,
445 const wxString
& name
)
447 wxStatusBar
*statusBar
= NULL
;
449 #if wxUSE_NATIVE_STATUSBAR
450 if ( !UsesNativeStatusBar() )
452 statusBar
= (wxStatusBar
*)new wxStatusBarGeneric(this, id
, style
);
457 statusBar
= new wxStatusBar(this, id
, style
, name
);
460 // Set the height according to the font and the border size
461 wxClientDC
dc(statusBar
);
462 dc
.SetFont(statusBar
->GetFont());
465 dc
.GetTextExtent(_T("X"), NULL
, &y
);
467 int height
= (int)( (11*y
)/10 + 2*statusBar
->GetBorderY());
469 statusBar
->SetSize(-1, -1, -1, height
);
471 statusBar
->SetFieldsCount(number
);
476 void wxFrameMSW::PositionStatusBar()
478 if ( !m_frameStatusBar
)
482 GetClientSize(&w
, &h
);
484 m_frameStatusBar
->GetSize(&sw
, &sh
);
486 // Since we wish the status bar to be directly under the client area,
487 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
488 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
490 #endif // wxUSE_STATUSBAR
492 #if wxUSE_MENUS_NATIVE
494 void wxFrameMSW::AttachMenuBar(wxMenuBar
*menubar
)
496 wxFrameBase::AttachMenuBar(menubar
);
500 // actually remove the menu from the frame
501 m_hMenu
= (WXHMENU
)0;
502 InternalSetMenuBar();
504 else // set new non NULL menu bar
506 // Can set a menubar several times.
507 if ( menubar
->GetHMenu() )
509 m_hMenu
= menubar
->GetHMenu();
513 m_hMenu
= menubar
->Create();
517 wxFAIL_MSG( _T("failed to create menu bar") );
522 InternalSetMenuBar();
526 void wxFrameMSW::InternalSetMenuBar()
528 #ifndef __WXMICROWIN__
529 if ( !::SetMenu(GetHwnd(), (HMENU
)m_hMenu
) )
531 wxLogLastError(wxT("SetMenu"));
536 #endif // wxUSE_MENUS_NATIVE
538 // Responds to colour changes, and passes event on to children.
539 void wxFrameMSW::OnSysColourChanged(wxSysColourChangedEvent
& event
)
541 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
545 if ( m_frameStatusBar
)
547 wxSysColourChangedEvent event2
;
548 event2
.SetEventObject( m_frameStatusBar
);
549 m_frameStatusBar
->GetEventHandler()->ProcessEvent(event2
);
551 #endif // wxUSE_STATUSBAR
553 // Propagate the event to the non-top-level children
554 wxWindow::OnSysColourChanged(event
);
557 // Pass TRUE to show full screen, FALSE to restore.
558 bool wxFrameMSW::ShowFullScreen(bool show
, long style
)
565 m_fsIsShowing
= TRUE
;
569 wxToolBar
*theToolBar
= GetToolBar();
571 theToolBar
->GetSize(NULL
, &m_fsToolBarHeight
);
573 // zap the toolbar, menubar, and statusbar
575 if ((style
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
577 theToolBar
->SetSize(-1,0);
578 theToolBar
->Show(FALSE
);
580 #endif // wxUSE_TOOLBAR
582 #ifndef __WXMICROWIN__
583 if (style
& wxFULLSCREEN_NOMENUBAR
)
584 SetMenu((HWND
)GetHWND(), (HMENU
) NULL
);
588 wxStatusBar
*theStatusBar
= GetStatusBar();
590 theStatusBar
->GetSize(NULL
, &m_fsStatusBarHeight
);
592 // Save the number of fields in the statusbar
593 if ((style
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
595 //m_fsStatusBarFields = theStatusBar->GetFieldsCount();
596 //SetStatusBar((wxStatusBar*) NULL);
597 //delete theStatusBar;
598 theStatusBar
->Show(FALSE
);
601 m_fsStatusBarFields
= 0;
602 #endif // wxUSE_STATUSBAR
604 // zap the frame borders
606 // save the 'normal' window style
607 m_fsOldWindowStyle
= GetWindowLong((HWND
)GetHWND(), GWL_STYLE
);
609 // save the old position, width & height, maximize state
610 m_fsOldSize
= GetRect();
611 m_fsIsMaximized
= IsMaximized();
613 // decide which window style flags to turn off
614 LONG newStyle
= m_fsOldWindowStyle
;
617 if (style
& wxFULLSCREEN_NOBORDER
)
618 offFlags
|= WS_BORDER
| WS_THICKFRAME
;
619 if (style
& wxFULLSCREEN_NOCAPTION
)
620 offFlags
|= (WS_CAPTION
| WS_SYSMENU
);
622 newStyle
&= (~offFlags
);
624 // change our window style to be compatible with full-screen mode
625 SetWindowLong((HWND
)GetHWND(), GWL_STYLE
, newStyle
);
627 // resize to the size of the desktop
631 ::GetWindowRect(GetDesktopWindow(), &rect
);
632 width
= rect
.right
- rect
.left
;
633 height
= rect
.bottom
- rect
.top
;
635 SetSize(width
, height
);
637 // now flush the window style cache and actually go full-screen
638 SetWindowPos((HWND
)GetHWND(), HWND_TOP
, 0, 0, width
, height
, SWP_FRAMECHANGED
);
640 wxSizeEvent
event(wxSize(width
, height
), GetId());
641 GetEventHandler()->ProcessEvent(event
);
650 m_fsIsShowing
= FALSE
;
653 wxToolBar
*theToolBar
= GetToolBar();
655 // restore the toolbar, menubar, and statusbar
656 if (theToolBar
&& (m_fsStyle
& wxFULLSCREEN_NOTOOLBAR
))
658 theToolBar
->SetSize(-1, m_fsToolBarHeight
);
659 theToolBar
->Show(TRUE
);
661 #endif // wxUSE_TOOLBAR
664 if ( m_fsStyle
& wxFULLSCREEN_NOSTATUSBAR
)
666 //CreateStatusBar(m_fsStatusBarFields);
669 GetStatusBar()->Show(TRUE
);
673 #endif // wxUSE_STATUSBAR
675 #ifndef __WXMICROWIN__
676 if ((m_fsStyle
& wxFULLSCREEN_NOMENUBAR
) && (m_hMenu
!= 0))
677 SetMenu((HWND
)GetHWND(), (HMENU
)m_hMenu
);
680 Maximize(m_fsIsMaximized
);
681 SetWindowLong((HWND
)GetHWND(),GWL_STYLE
, m_fsOldWindowStyle
);
682 SetWindowPos((HWND
)GetHWND(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
683 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
694 bool wxFrameMSW::MSWCreate(int id
, wxWindow
*parent
, const wxChar
*wclass
, wxWindow
*wx_win
, const wxChar
*title
,
695 int x
, int y
, int width
, int height
, long style
)
698 m_defaultIcon
= (WXHICON
) (wxSTD_FRAME_ICON
? wxSTD_FRAME_ICON
: wxDEFAULT_FRAME_ICON
);
700 // If child windows aren't properly drawn initially, WS_CLIPCHILDREN
701 // could be the culprit. But without it, you can get a lot of flicker.
704 if ( style
& wxCAPTION
)
706 if ( style
& wxFRAME_TOOL_WINDOW
)
707 msflags
|= WS_POPUPWINDOW
;
709 msflags
|= WS_OVERLAPPED
;
716 if (style
& wxMINIMIZE_BOX
)
717 msflags
|= WS_MINIMIZEBOX
;
718 if (style
& wxMAXIMIZE_BOX
)
719 msflags
|= WS_MAXIMIZEBOX
;
720 if (style
& wxTHICK_FRAME
)
721 msflags
|= WS_THICKFRAME
;
722 if (style
& wxSYSTEM_MENU
)
723 msflags
|= WS_SYSMENU
;
724 if ( style
& wxMINIMIZE
)
725 msflags
|= WS_MINIMIZE
;
726 if (style
& wxMAXIMIZE
)
727 msflags
|= WS_MAXIMIZE
;
728 if (style
& wxCAPTION
)
729 msflags
|= WS_CAPTION
;
730 if (style
& wxCLIP_CHILDREN
)
731 msflags
|= WS_CLIPCHILDREN
;
733 // Keep this in wxFrameMSW because it saves recoding this function
735 #if wxUSE_ITSY_BITSY && !defined(__WIN32__)
736 if (style
& wxTINY_CAPTION_VERT
)
737 msflags
|= IBS_VERTCAPTION
;
738 if (style
& wxTINY_CAPTION_HORIZ
)
739 msflags
|= IBS_HORZCAPTION
;
741 if (style
& wxTINY_CAPTION_VERT
)
742 msflags
|= WS_CAPTION
;
743 if (style
& wxTINY_CAPTION_HORIZ
)
744 msflags
|= WS_CAPTION
;
746 if ((style
& wxTHICK_FRAME
) == 0)
747 msflags
|= WS_BORDER
;
749 WXDWORD extendedStyle
= MakeExtendedStyle(style
);
751 // make all frames appear in the win9x shell taskbar unless
752 // wxFRAME_TOOL_WINDOW or wxFRAME_NO_TASKBAR is given - without giving them
753 // WS_EX_APPWINDOW style, the child (i.e. owned) frames wouldn't appear in it
754 #if !defined(__WIN16__) && !defined(__SC__)
755 if ( (style
& wxFRAME_TOOL_WINDOW
) ||
756 (style
& wxFRAME_NO_TASKBAR
) )
757 extendedStyle
|= WS_EX_TOOLWINDOW
;
758 else if ( !(style
& wxFRAME_NO_TASKBAR
) )
759 extendedStyle
|= WS_EX_APPWINDOW
;
762 if (style
& wxSTAY_ON_TOP
)
763 extendedStyle
|= WS_EX_TOPMOST
;
766 if (m_exStyle
& wxFRAME_EX_CONTEXTHELP
)
767 extendedStyle
|= WS_EX_CONTEXTHELP
;
771 if ( !wxWindow::MSWCreate(id
, parent
, wclass
, wx_win
, title
, x
, y
, width
, height
,
772 msflags
, NULL
, extendedStyle
) )
775 // Seems to be necessary if we use WS_POPUP
776 // style instead of WS_OVERLAPPED
777 if (width
> -1 && height
> -1)
778 ::PostMessage(GetHwnd(), WM_SIZE
, SIZE_RESTORED
, MAKELPARAM(width
, height
));
783 // Default activation behaviour - set the focus for the first child
785 void wxFrameMSW::OnActivate(wxActivateEvent
& event
)
787 if ( event
.GetActive() )
789 // restore focus to the child which was last focused
790 wxLogTrace(_T("focus"), _T("wxFrameMSW %08x activated."), m_hWnd
);
792 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
799 wxSetFocusToChild(parent
, &m_winLastFocused
);
803 // remember the last focused child if it is our child
804 m_winLastFocused
= FindFocus();
806 // so we NULL it out if it's a child from some other frame
807 wxWindow
*win
= m_winLastFocused
;
810 if ( win
->IsTopLevel() )
814 m_winLastFocused
= NULL
;
820 win
= win
->GetParent();
823 wxLogTrace(_T("focus"),
824 _T("wxFrameMSW %08x deactivated, last focused: %08x."),
826 m_winLastFocused
? GetHwndOf(m_winLastFocused
)
833 // ----------------------------------------------------------------------------
834 // tool/status bar stuff
835 // ----------------------------------------------------------------------------
839 wxToolBar
* wxFrameMSW::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
841 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
846 return m_frameToolBar
;
849 void wxFrameMSW::PositionToolBar()
852 ::GetClientRect(GetHwnd(), &rect
);
855 if ( GetStatusBar() )
857 int statusX
, statusY
;
858 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
859 rect
.bottom
-= statusY
;
861 #endif // wxUSE_STATUSBAR
863 if ( GetToolBar() && GetToolBar()->IsShown() )
866 GetToolBar()->GetSize(&tw
, &th
);
868 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
877 // Use the 'real' MSW position here
878 GetToolBar()->SetSize(0, 0, tw
, th
, wxSIZE_NO_ADJUSTMENTS
);
881 #endif // wxUSE_TOOLBAR
883 // ----------------------------------------------------------------------------
884 // frame state (iconized/maximized/...)
885 // ----------------------------------------------------------------------------
887 // propagate our state change to all child frames: this allows us to emulate X
888 // Windows behaviour where child frames float independently of the parent one
889 // on the desktop, but are iconized/restored with it
890 void wxFrameMSW::IconizeChildFrames(bool bIconize
)
892 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
894 node
= node
->GetNext() )
896 wxWindow
*win
= node
->GetData();
898 // iconizing the frames with this style under Win95 shell puts them at
899 // the bottom of the screen (as the MDI children) instead of making
900 // them appear in the taskbar because they are, by virtue of this
901 // style, not managed by the taskbar - instead leave Windows take care
904 if ( win
->GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
908 // the child MDI frames are a special case and should not be touched by
909 // the parent frame - instead, they are managed by the user
910 wxFrameMSW
*frame
= wxDynamicCast(win
, wxFrame
);
912 #if wxUSE_MDI_ARCHITECTURE
913 && !wxDynamicCast(frame
, wxMDIChildFrame
)
914 #endif // wxUSE_MDI_ARCHITECTURE
917 frame
->Iconize(bIconize
);
922 // ===========================================================================
923 // message processing
924 // ===========================================================================
926 // ---------------------------------------------------------------------------
928 // ---------------------------------------------------------------------------
930 bool wxFrameMSW::MSWTranslateMessage(WXMSG
* pMsg
)
932 if ( wxWindow::MSWTranslateMessage(pMsg
) )
935 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
936 // try the menu bar accels
937 wxMenuBar
*menuBar
= GetMenuBar();
941 const wxAcceleratorTable
& acceleratorTable
= menuBar
->GetAccelTable();
942 return acceleratorTable
.Translate(this, pMsg
);
945 #endif // wxUSE_MENUS && wxUSE_ACCEL
948 // ---------------------------------------------------------------------------
949 // our private (non virtual) message handlers
950 // ---------------------------------------------------------------------------
952 bool wxFrameMSW::HandlePaint()
955 if ( GetUpdateRect(GetHwnd(), &rect
, FALSE
) )
957 #ifndef __WXMICROWIN__
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
);
993 return wxWindow::HandlePaint();
998 // nothing to paint - processed
1003 bool wxFrameMSW::HandleSize(int x
, int y
, WXUINT id
)
1005 bool processed
= FALSE
;
1006 #ifndef __WXMICROWIN__
1011 // only do it it if we were iconized before, otherwise resizing the
1012 // parent frame has a curious side effect of bringing it under it's
1017 // restore all child frames too
1018 IconizeChildFrames(FALSE
);
1020 (void)SendIconizeEvent(FALSE
);
1024 case SIZEFULLSCREEN
:
1029 // iconize all child frames too
1030 IconizeChildFrames(TRUE
);
1032 (void)SendIconizeEvent();
1042 PositionStatusBar();
1043 #endif // wxUSE_STATUSBAR
1047 #endif // wxUSE_TOOLBAR
1049 wxSizeEvent
event(wxSize(x
, y
), m_windowId
);
1050 event
.SetEventObject( this );
1051 processed
= GetEventHandler()->ProcessEvent(event
);
1057 bool wxFrameMSW::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
1061 // In case it's e.g. a toolbar.
1062 wxWindow
*win
= wxFindWinFromHandle(control
);
1064 return win
->MSWCommand(cmd
, id
);
1067 // handle here commands from menus and accelerators
1068 if ( cmd
== 0 || cmd
== 1 )
1070 #if wxUSE_MENUS_NATIVE
1071 if ( wxCurrentPopupMenu
)
1073 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
1074 wxCurrentPopupMenu
= NULL
;
1076 return popupMenu
->MSWCommand(cmd
, id
);
1078 #endif // wxUSE_MENUS_NATIVE
1080 if ( ProcessCommand(id
) )
1089 bool wxFrameMSW::HandleMenuSelect(WXWORD nItem
, WXWORD flags
, WXHMENU hMenu
)
1092 if ( flags
== 0xFFFF && hMenu
== 0 )
1094 // menu was removed from screen
1097 #ifndef __WXMICROWIN__
1098 else if ( !(flags
& MF_POPUP
) && !(flags
& MF_SEPARATOR
) )
1106 // don't give hints for separators (doesn't make sense) nor for the
1107 // items opening popup menus (they don't have them anyhow) but do clear
1108 // the status line - otherwise, we would be left with the help message
1109 // for the previous item which doesn't apply any more
1110 wxStatusBar
*statbar
= GetStatusBar();
1113 statbar
->SetStatusText(wxEmptyString
);
1115 #endif // wxUSE_STATUSBAR
1120 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, item
);
1121 event
.SetEventObject( this );
1123 return GetEventHandler()->ProcessEvent(event
);
1126 // ---------------------------------------------------------------------------
1127 // the window proc for wxFrameMSW
1128 // ---------------------------------------------------------------------------
1130 long wxFrameMSW::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1133 bool processed
= FALSE
;
1138 // if we can't close, tell the system that we processed the
1139 // message - otherwise it would close us
1140 processed
= !Close();
1147 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
1150 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
1154 #ifndef __WXMICROWIN__
1159 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
1161 processed
= HandleMenuSelect(item
, flags
, hmenu
);
1167 processed
= HandlePaint();
1170 #ifndef __WXMICROWIN__
1171 case WM_QUERYDRAGICON
:
1173 HICON hIcon
= m_icon
.Ok() ? GetHiconOf(m_icon
)
1174 : (HICON
)(m_defaultIcon
);
1176 processed
= rc
!= 0;
1182 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
1187 rc
= wxWindow::MSWWindowProc(message
, wParam
, lParam
);