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 #ifndef __WXUNIVERSAL__
84 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxWindow
)
87 // ============================================================================
89 // ============================================================================
91 // ----------------------------------------------------------------------------
92 // static class members
93 // ----------------------------------------------------------------------------
96 #if wxUSE_NATIVE_STATUSBAR
97 bool wxFrameMSW::m_useNativeStatusBar
= TRUE
;
99 bool wxFrameMSW::m_useNativeStatusBar
= FALSE
;
101 #endif // wxUSE_NATIVE_STATUSBAR
103 // ----------------------------------------------------------------------------
104 // creation/destruction
105 // ----------------------------------------------------------------------------
107 void wxFrameMSW::Init()
110 m_maximizeOnShow
= FALSE
;
116 // Data to save/restore when calling ShowFullScreen
118 m_fsOldWindowStyle
= 0;
119 m_fsStatusBarFields
= 0;
120 m_fsStatusBarHeight
= 0;
121 m_fsToolBarHeight
= 0;
123 m_fsIsMaximized
= FALSE
;
124 m_fsIsShowing
= FALSE
;
126 m_winLastFocused
= (wxWindow
*)NULL
;
128 // unlike (almost?) all other windows, frames are created hidden
132 bool wxFrameMSW::Create(wxWindow
*parent
,
134 const wxString
& title
,
138 const wxString
& name
)
141 m_windowStyle
= style
;
143 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
148 m_windowId
= (int)NewControlId();
150 if (parent
) parent
->AddChild(this);
159 wxTopLevelWindows
.Append(this);
161 // the frame must have NULL parent HWND or it would be always on top of its
162 // parent which is not what we usually want (in fact, we only want it for
163 // frames with the special wxFRAME_TOOL_WINDOW style handled elsewhere)
164 MSWCreate(m_windowId
, NULL
, wxFrameClassName
, this, title
,
165 x
, y
, width
, height
, style
);
167 wxModelessWindows
.Append(this);
172 wxFrameMSW::~wxFrameMSW()
174 m_isBeingDeleted
= TRUE
;
175 wxTopLevelWindows
.DeleteObject(this);
177 // the ~wxToolBar() code relies on the previous line to be executed before
178 // this one, i.e. the frame should remove itself from wxTopLevelWindows
179 // before destorying its toolbar
182 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
184 wxTheApp
->SetTopWindow(NULL
);
186 if (wxTheApp
->GetExitOnFrameDelete())
192 wxModelessWindows
.DeleteObject(this);
194 // For some reason, wxWindows can activate another task altogether
195 // when a frame is destroyed after a modal dialog has been invoked.
196 // Try to bring the parent to the top.
197 // MT:Only do this if this frame is currently the active window, else weird
198 // things start to happen
199 if ( wxGetActiveWindow() == this )
200 if (GetParent() && GetParent()->GetHWND())
201 ::BringWindowToTop((HWND
) GetParent()->GetHWND());
204 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
205 void wxFrameMSW::DoGetClientSize(int *x
, int *y
) const
208 ::GetClientRect(GetHwnd(), &rect
);
211 if ( GetStatusBar() && GetStatusBar()->IsShown() )
213 int statusX
, statusY
;
214 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
215 rect
.bottom
-= statusY
;
217 #endif // wxUSE_STATUSBAR
219 wxPoint
pt(GetClientAreaOrigin());
229 // Set the client size (i.e. leave the calculation of borders etc.
231 void wxFrameMSW::DoSetClientSize(int width
, int height
)
233 HWND hWnd
= GetHwnd();
236 ::GetClientRect(hWnd
, &rectClient
);
239 ::GetWindowRect(hWnd
, &rectTotal
);
241 // Find the difference between the entire window (title bar and all)
242 // and the client area; add this to the new client size to move the
244 width
+= rectTotal
.right
- rectTotal
.left
- rectClient
.right
;
245 height
+= rectTotal
.bottom
- rectTotal
.top
- rectClient
.bottom
;
248 wxStatusBar
*statbar
= GetStatusBar();
249 if ( statbar
&& statbar
->IsShown() )
251 // leave enough space for the status bar
252 height
+= statbar
->GetSize().y
;
254 #endif // wxUSE_STATUSBAR
256 // note that this takes the toolbar into account
257 wxPoint pt
= GetClientAreaOrigin();
261 if ( !::MoveWindow(hWnd
, rectTotal
.left
, rectTotal
.top
,
262 width
, height
, TRUE
/* redraw */) )
264 wxLogLastError(_T("MoveWindow"));
267 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
268 event
.SetEventObject(this);
269 GetEventHandler()->ProcessEvent(event
);
272 void wxFrameMSW::DoGetSize(int *width
, int *height
) const
275 ::GetWindowRect(GetHwnd(), &rect
);
277 *width
= rect
.right
- rect
.left
;
278 *height
= rect
.bottom
- rect
.top
;
281 void wxFrameMSW::DoGetPosition(int *x
, int *y
) const
284 ::GetWindowRect(GetHwnd(), &rect
);
290 // ----------------------------------------------------------------------------
291 // variations around ::ShowWindow()
292 // ----------------------------------------------------------------------------
294 void wxFrameMSW::DoShowWindow(int nShowCmd
)
296 ::ShowWindow(GetHwnd(), nShowCmd
);
298 m_iconized
= nShowCmd
== SW_MINIMIZE
;
301 bool wxFrameMSW::Show(bool show
)
303 // don't use wxWindow version as we want to call DoShowWindow()
304 if ( !wxWindowBase::Show(show
) )
310 if ( m_maximizeOnShow
)
313 nShowCmd
= SW_MAXIMIZE
;
315 m_maximizeOnShow
= FALSE
;
327 DoShowWindow(nShowCmd
);
331 ::BringWindowToTop(GetHwnd());
333 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
334 event
.SetEventObject( this );
335 GetEventHandler()->ProcessEvent(event
);
339 // Try to highlight the correct window (the parent)
342 HWND hWndParent
= GetHwndOf(GetParent());
344 ::BringWindowToTop(hWndParent
);
351 void wxFrameMSW::Iconize(bool iconize
)
353 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
356 void wxFrameMSW::Maximize(bool maximize
)
360 // just maximize it directly
361 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
365 // we can't maximize the hidden frame because it shows it as well, so
366 // just remember that we should do it later in this case
367 m_maximizeOnShow
= TRUE
;
371 void wxFrameMSW::Restore()
373 DoShowWindow(SW_RESTORE
);
376 bool wxFrameMSW::IsIconized() const
378 #ifdef __WXMICROWIN__
382 ((wxFrameMSW
*)this)->m_iconized
= (::IsIconic(GetHwnd()) != 0);
388 bool wxFrameMSW::IsMaximized() const
390 #ifdef __WXMICROWIN__
394 return (::IsZoomed(GetHwnd()) != 0);
398 void wxFrameMSW::SetIcon(const wxIcon
& icon
)
400 wxFrameBase::SetIcon(icon
);
402 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
405 SendMessage(GetHwnd(), WM_SETICON
,
406 (WPARAM
)TRUE
, (LPARAM
)(HICON
) m_icon
.GetHICON());
411 // generate an artificial resize event
412 void wxFrameMSW::SendSizeEvent()
416 ::GetWindowRect(GetHwnd(), &r
);
418 if ( !::GetWindowRect(GetHwnd(), &r
) )
420 wxLogLastError(_T("GetWindowRect"));
426 (void)::PostMessage(GetHwnd(), WM_SIZE
,
427 IsMaximized() ? SIZE_MAXIMIZED
: SIZE_RESTORED
,
428 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
433 wxStatusBar
*wxFrameMSW::OnCreateStatusBar(int number
,
436 const wxString
& name
)
438 wxStatusBar
*statusBar
= NULL
;
440 #if wxUSE_NATIVE_STATUSBAR
441 if ( !UsesNativeStatusBar() )
443 statusBar
= (wxStatusBar
*)new wxStatusBarGeneric(this, id
, style
);
448 statusBar
= new wxStatusBar(this, id
, style
, name
);
451 // Set the height according to the font and the border size
452 wxClientDC
dc(statusBar
);
453 dc
.SetFont(statusBar
->GetFont());
456 dc
.GetTextExtent(_T("X"), NULL
, &y
);
458 int height
= (int)( (11*y
)/10 + 2*statusBar
->GetBorderY());
460 statusBar
->SetSize(-1, -1, -1, height
);
462 statusBar
->SetFieldsCount(number
);
467 void wxFrameMSW::PositionStatusBar()
469 if ( !m_frameStatusBar
)
473 GetClientSize(&w
, &h
);
475 m_frameStatusBar
->GetSize(&sw
, &sh
);
477 // Since we wish the status bar to be directly under the client area,
478 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
479 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
481 #endif // wxUSE_STATUSBAR
483 #if wxUSE_MENUS_NATIVE
485 void wxFrameMSW::AttachMenuBar(wxMenuBar
*menubar
)
487 wxFrameBase::AttachMenuBar(menubar
);
491 // actually remove the menu from the frame
492 m_hMenu
= (WXHMENU
)0;
493 InternalSetMenuBar();
495 else // set new non NULL menu bar
497 // Can set a menubar several times.
498 if ( menubar
->GetHMenu() )
500 m_hMenu
= menubar
->GetHMenu();
504 m_hMenu
= menubar
->Create();
508 wxFAIL_MSG( _T("failed to create menu bar") );
513 InternalSetMenuBar();
517 void wxFrameMSW::InternalSetMenuBar()
519 #ifndef __WXMICROWIN__
520 if ( !::SetMenu(GetHwnd(), (HMENU
)m_hMenu
) )
522 wxLogLastError(wxT("SetMenu"));
527 #endif // wxUSE_MENUS_NATIVE
529 // Responds to colour changes, and passes event on to children.
530 void wxFrameMSW::OnSysColourChanged(wxSysColourChangedEvent
& event
)
532 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
536 if ( m_frameStatusBar
)
538 wxSysColourChangedEvent event2
;
539 event2
.SetEventObject( m_frameStatusBar
);
540 m_frameStatusBar
->GetEventHandler()->ProcessEvent(event2
);
542 #endif // wxUSE_STATUSBAR
544 // Propagate the event to the non-top-level children
545 wxWindow::OnSysColourChanged(event
);
548 // Pass TRUE to show full screen, FALSE to restore.
549 bool wxFrameMSW::ShowFullScreen(bool show
, long style
)
556 m_fsIsShowing
= TRUE
;
560 wxToolBar
*theToolBar
= GetToolBar();
562 theToolBar
->GetSize(NULL
, &m_fsToolBarHeight
);
564 // zap the toolbar, menubar, and statusbar
566 if ((style
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
568 theToolBar
->SetSize(-1,0);
569 theToolBar
->Show(FALSE
);
571 #endif // wxUSE_TOOLBAR
573 #ifndef __WXMICROWIN__
574 if (style
& wxFULLSCREEN_NOMENUBAR
)
575 SetMenu((HWND
)GetHWND(), (HMENU
) NULL
);
579 wxStatusBar
*theStatusBar
= GetStatusBar();
581 theStatusBar
->GetSize(NULL
, &m_fsStatusBarHeight
);
583 // Save the number of fields in the statusbar
584 if ((style
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
586 //m_fsStatusBarFields = theStatusBar->GetFieldsCount();
587 //SetStatusBar((wxStatusBar*) NULL);
588 //delete theStatusBar;
589 theStatusBar
->Show(FALSE
);
592 m_fsStatusBarFields
= 0;
593 #endif // wxUSE_STATUSBAR
595 // zap the frame borders
597 // save the 'normal' window style
598 m_fsOldWindowStyle
= GetWindowLong((HWND
)GetHWND(), GWL_STYLE
);
600 // save the old position, width & height, maximize state
601 m_fsOldSize
= GetRect();
602 m_fsIsMaximized
= IsMaximized();
604 // decide which window style flags to turn off
605 LONG newStyle
= m_fsOldWindowStyle
;
608 if (style
& wxFULLSCREEN_NOBORDER
)
609 offFlags
|= WS_BORDER
;
610 if (style
& wxFULLSCREEN_NOCAPTION
)
611 offFlags
|= (WS_CAPTION
| WS_SYSMENU
);
613 newStyle
&= (~offFlags
);
615 // change our window style to be compatible with full-screen mode
616 SetWindowLong((HWND
)GetHWND(), GWL_STYLE
, newStyle
);
618 // resize to the size of the desktop
622 ::GetWindowRect(GetDesktopWindow(), &rect
);
623 width
= rect
.right
- rect
.left
;
624 height
= rect
.bottom
- rect
.top
;
626 SetSize(width
, height
);
628 // now flush the window style cache and actually go full-screen
629 SetWindowPos((HWND
)GetHWND(), HWND_TOP
, 0, 0, width
, height
, SWP_FRAMECHANGED
);
631 wxSizeEvent
event(wxSize(width
, height
), GetId());
632 GetEventHandler()->ProcessEvent(event
);
641 m_fsIsShowing
= FALSE
;
644 wxToolBar
*theToolBar
= GetToolBar();
646 // restore the toolbar, menubar, and statusbar
647 if (theToolBar
&& (m_fsStyle
& wxFULLSCREEN_NOTOOLBAR
))
649 theToolBar
->SetSize(-1, m_fsToolBarHeight
);
650 theToolBar
->Show(TRUE
);
652 #endif // wxUSE_TOOLBAR
655 if ( m_fsStyle
& wxFULLSCREEN_NOSTATUSBAR
)
657 //CreateStatusBar(m_fsStatusBarFields);
660 GetStatusBar()->Show(TRUE
);
664 #endif // wxUSE_STATUSBAR
666 #ifndef __WXMICROWIN__
667 if ((m_fsStyle
& wxFULLSCREEN_NOMENUBAR
) && (m_hMenu
!= 0))
668 SetMenu((HWND
)GetHWND(), (HMENU
)m_hMenu
);
671 Maximize(m_fsIsMaximized
);
672 SetWindowLong((HWND
)GetHWND(),GWL_STYLE
, m_fsOldWindowStyle
);
673 SetWindowPos((HWND
)GetHWND(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
674 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
685 bool wxFrameMSW::MSWCreate(int id
, wxWindow
*parent
, const wxChar
*wclass
, wxWindow
*wx_win
, const wxChar
*title
,
686 int x
, int y
, int width
, int height
, long style
)
689 m_defaultIcon
= (WXHICON
) (wxSTD_FRAME_ICON
? wxSTD_FRAME_ICON
: wxDEFAULT_FRAME_ICON
);
691 // If child windows aren't properly drawn initially, WS_CLIPCHILDREN
692 // could be the culprit. But without it, you can get a lot of flicker.
695 if ( style
& wxCAPTION
)
697 if ( style
& wxFRAME_TOOL_WINDOW
)
698 msflags
|= WS_POPUPWINDOW
;
700 msflags
|= WS_OVERLAPPED
;
707 if (style
& wxMINIMIZE_BOX
)
708 msflags
|= WS_MINIMIZEBOX
;
709 if (style
& wxMAXIMIZE_BOX
)
710 msflags
|= WS_MAXIMIZEBOX
;
711 if (style
& wxTHICK_FRAME
)
712 msflags
|= WS_THICKFRAME
;
713 if (style
& wxSYSTEM_MENU
)
714 msflags
|= WS_SYSMENU
;
715 if ( style
& wxMINIMIZE
)
716 msflags
|= WS_MINIMIZE
;
717 if (style
& wxMAXIMIZE
)
718 msflags
|= WS_MAXIMIZE
;
719 if (style
& wxCAPTION
)
720 msflags
|= WS_CAPTION
;
721 if (style
& wxCLIP_CHILDREN
)
722 msflags
|= WS_CLIPCHILDREN
;
724 // Keep this in wxFrameMSW because it saves recoding this function
726 #if wxUSE_ITSY_BITSY && !defined(__WIN32__)
727 if (style
& wxTINY_CAPTION_VERT
)
728 msflags
|= IBS_VERTCAPTION
;
729 if (style
& wxTINY_CAPTION_HORIZ
)
730 msflags
|= IBS_HORZCAPTION
;
732 if (style
& wxTINY_CAPTION_VERT
)
733 msflags
|= WS_CAPTION
;
734 if (style
& wxTINY_CAPTION_HORIZ
)
735 msflags
|= WS_CAPTION
;
737 if ((style
& wxTHICK_FRAME
) == 0)
738 msflags
|= WS_BORDER
;
740 WXDWORD extendedStyle
= MakeExtendedStyle(style
);
742 // make all frames appear in the win9x shell taskbar unless
743 // wxFRAME_TOOL_WINDOW or wxFRAME_NO_TASKBAR is given - without giving them
744 // WS_EX_APPWINDOW style, the child (i.e. owned) frames wouldn't appear in it
745 #if !defined(__WIN16__) && !defined(__SC__)
746 if ( (style
& wxFRAME_TOOL_WINDOW
) ||
747 (style
& wxFRAME_NO_TASKBAR
) )
748 extendedStyle
|= WS_EX_TOOLWINDOW
;
749 else if ( !(style
& wxFRAME_NO_TASKBAR
) )
750 extendedStyle
|= WS_EX_APPWINDOW
;
753 if (style
& wxSTAY_ON_TOP
)
754 extendedStyle
|= WS_EX_TOPMOST
;
757 if (m_exStyle
& wxFRAME_EX_CONTEXTHELP
)
758 extendedStyle
|= WS_EX_CONTEXTHELP
;
762 if ( !wxWindow::MSWCreate(id
, parent
, wclass
, wx_win
, title
, x
, y
, width
, height
,
763 msflags
, NULL
, extendedStyle
) )
766 // Seems to be necessary if we use WS_POPUP
767 // style instead of WS_OVERLAPPED
768 if (width
> -1 && height
> -1)
769 ::PostMessage(GetHwnd(), WM_SIZE
, SIZE_RESTORED
, MAKELPARAM(width
, height
));
774 // Default activation behaviour - set the focus for the first child
776 void wxFrameMSW::OnActivate(wxActivateEvent
& event
)
778 if ( event
.GetActive() )
780 // restore focus to the child which was last focused
781 wxLogTrace(_T("focus"), _T("wxFrameMSW %08x activated."), m_hWnd
);
783 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
790 wxSetFocusToChild(parent
, &m_winLastFocused
);
794 // remember the last focused child if it is our child
795 m_winLastFocused
= FindFocus();
797 // so we NULL it out if it's a child from some other frame
798 wxWindow
*win
= m_winLastFocused
;
801 if ( win
->IsTopLevel() )
805 m_winLastFocused
= NULL
;
811 win
= win
->GetParent();
814 wxLogTrace(_T("focus"),
815 _T("wxFrameMSW %08x deactivated, last focused: %08x."),
817 m_winLastFocused
? GetHwndOf(m_winLastFocused
)
824 // ----------------------------------------------------------------------------
825 // tool/status bar stuff
826 // ----------------------------------------------------------------------------
830 wxToolBar
* wxFrameMSW::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
832 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
837 return m_frameToolBar
;
840 void wxFrameMSW::PositionToolBar()
843 ::GetClientRect(GetHwnd(), &rect
);
846 if ( GetStatusBar() )
848 int statusX
, statusY
;
849 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
850 rect
.bottom
-= statusY
;
852 #endif // wxUSE_STATUSBAR
854 if ( GetToolBar() && GetToolBar()->IsShown() )
857 GetToolBar()->GetSize(&tw
, &th
);
859 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
868 // Use the 'real' MSW position here
869 GetToolBar()->SetSize(0, 0, tw
, th
, wxSIZE_NO_ADJUSTMENTS
);
872 #endif // wxUSE_TOOLBAR
874 // ----------------------------------------------------------------------------
875 // frame state (iconized/maximized/...)
876 // ----------------------------------------------------------------------------
878 // propagate our state change to all child frames: this allows us to emulate X
879 // Windows behaviour where child frames float independently of the parent one
880 // on the desktop, but are iconized/restored with it
881 void wxFrameMSW::IconizeChildFrames(bool bIconize
)
883 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
885 node
= node
->GetNext() )
887 wxWindow
*win
= node
->GetData();
889 // iconizing the frames with this style under Win95 shell puts them at
890 // the bottom of the screen (as the MDI children) instead of making
891 // them appear in the taskbar because they are, by virtue of this
892 // style, not managed by the taskbar - instead leave Windows take care
895 if ( win
->GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
899 // the child MDI frames are a special case and should not be touched by
900 // the parent frame - instead, they are managed by the user
901 wxFrameMSW
*frame
= wxDynamicCast(win
, wxFrame
);
903 #if wxUSE_MDI_ARCHITECTURE
904 && !wxDynamicCast(frame
, wxMDIChildFrame
)
905 #endif // wxUSE_MDI_ARCHITECTURE
908 frame
->Iconize(bIconize
);
913 // ===========================================================================
914 // message processing
915 // ===========================================================================
917 // ---------------------------------------------------------------------------
919 // ---------------------------------------------------------------------------
921 bool wxFrameMSW::MSWTranslateMessage(WXMSG
* pMsg
)
923 if ( wxWindow::MSWTranslateMessage(pMsg
) )
926 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
927 // try the menu bar accels
928 wxMenuBar
*menuBar
= GetMenuBar();
932 const wxAcceleratorTable
& acceleratorTable
= menuBar
->GetAccelTable();
933 return acceleratorTable
.Translate(this, pMsg
);
936 #endif // wxUSE_MENUS && wxUSE_ACCEL
939 // ---------------------------------------------------------------------------
940 // our private (non virtual) message handlers
941 // ---------------------------------------------------------------------------
943 bool wxFrameMSW::HandlePaint()
946 if ( GetUpdateRect(GetHwnd(), &rect
, FALSE
) )
948 #ifndef __WXMICROWIN__
951 HICON hIcon
= m_icon
.Ok() ? GetHiconOf(m_icon
)
952 : (HICON
)m_defaultIcon
;
954 // Hold a pointer to the dc so long as the OnPaint() message
955 // is being processed
957 HDC hdc
= ::BeginPaint(GetHwnd(), &ps
);
959 // Erase background before painting or we get white background
960 MSWDefWindowProc(WM_ICONERASEBKGND
, (WORD
)(LONG
)ps
.hdc
, 0L);
965 ::GetClientRect(GetHwnd(), &rect
);
967 // FIXME: why hardcoded?
968 static const int icon_width
= 32;
969 static const int icon_height
= 32;
971 int icon_x
= (int)((rect
.right
- icon_width
)/2);
972 int icon_y
= (int)((rect
.bottom
- icon_height
)/2);
974 ::DrawIcon(hdc
, icon_x
, icon_y
, hIcon
);
977 ::EndPaint(GetHwnd(), &ps
);
984 return wxWindow::HandlePaint();
989 // nothing to paint - processed
994 bool wxFrameMSW::HandleSize(int x
, int y
, WXUINT id
)
996 bool processed
= FALSE
;
997 #ifndef __WXMICROWIN__
1002 // only do it it if we were iconized before, otherwise resizing the
1003 // parent frame has a curious side effect of bringing it under it's
1008 // restore all child frames too
1009 IconizeChildFrames(FALSE
);
1011 (void)SendIconizeEvent(FALSE
);
1015 case SIZEFULLSCREEN
:
1020 // iconize all child frames too
1021 IconizeChildFrames(TRUE
);
1023 (void)SendIconizeEvent();
1033 PositionStatusBar();
1034 #endif // wxUSE_STATUSBAR
1038 #endif // wxUSE_TOOLBAR
1040 wxSizeEvent
event(wxSize(x
, y
), m_windowId
);
1041 event
.SetEventObject( this );
1042 processed
= GetEventHandler()->ProcessEvent(event
);
1048 bool wxFrameMSW::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
1052 // In case it's e.g. a toolbar.
1053 wxWindow
*win
= wxFindWinFromHandle(control
);
1055 return win
->MSWCommand(cmd
, id
);
1058 // handle here commands from menus and accelerators
1059 if ( cmd
== 0 || cmd
== 1 )
1061 #if wxUSE_MENUS_NATIVE
1062 if ( wxCurrentPopupMenu
)
1064 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
1065 wxCurrentPopupMenu
= NULL
;
1067 return popupMenu
->MSWCommand(cmd
, id
);
1069 #endif // wxUSE_MENUS_NATIVE
1071 if ( ProcessCommand(id
) )
1080 bool wxFrameMSW::HandleMenuSelect(WXWORD nItem
, WXWORD flags
, WXHMENU hMenu
)
1083 if ( flags
== 0xFFFF && hMenu
== 0 )
1085 // menu was removed from screen
1088 #ifndef __WXMICROWIN__
1089 else if ( !(flags
& MF_POPUP
) && !(flags
& MF_SEPARATOR
) )
1097 // don't give hints for separators (doesn't make sense) nor for the
1098 // items opening popup menus (they don't have them anyhow) but do clear
1099 // the status line - otherwise, we would be left with the help message
1100 // for the previous item which doesn't apply any more
1101 wxStatusBar
*statbar
= GetStatusBar();
1104 statbar
->SetStatusText(wxEmptyString
);
1106 #endif // wxUSE_STATUSBAR
1111 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, item
);
1112 event
.SetEventObject( this );
1114 return GetEventHandler()->ProcessEvent(event
);
1117 // ---------------------------------------------------------------------------
1118 // the window proc for wxFrameMSW
1119 // ---------------------------------------------------------------------------
1121 long wxFrameMSW::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1124 bool processed
= FALSE
;
1129 // if we can't close, tell the system that we processed the
1130 // message - otherwise it would close us
1131 processed
= !Close();
1138 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
1141 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
1145 #ifndef __WXMICROWIN__
1150 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
1152 processed
= HandleMenuSelect(item
, flags
, hmenu
);
1158 processed
= HandlePaint();
1161 #ifndef __WXMICROWIN__
1162 case WM_QUERYDRAGICON
:
1164 HICON hIcon
= m_icon
.Ok() ? GetHiconOf(m_icon
)
1165 : (HICON
)(m_defaultIcon
);
1167 processed
= rc
!= 0;
1173 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
1178 rc
= wxWindow::MSWWindowProc(message
, wParam
, lParam
);