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 m_frameMenuBar
= NULL
;
144 #endif // wxUSE_MENUS
146 m_frameToolBar
= NULL
;
147 #endif // wxUSE_TOOLBAR
149 m_frameStatusBar
= NULL
;
150 #endif // wxUSE_STATUSBAR
152 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
157 m_windowId
= (int)NewControlId();
159 if (parent
) parent
->AddChild(this);
168 wxTopLevelWindows
.Append(this);
170 MSWCreate(m_windowId
, parent
, wxFrameClassName
, this, title
,
171 x
, y
, width
, height
, style
);
173 wxModelessWindows
.Append(this);
178 wxFrameMSW::~wxFrameMSW()
180 m_isBeingDeleted
= TRUE
;
181 wxTopLevelWindows
.DeleteObject(this);
183 // the ~wxToolBar() code relies on the previous line to be executed before
184 // this one, i.e. the frame should remove itself from wxTopLevelWindows
185 // before destorying its toolbar
188 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
190 wxTheApp
->SetTopWindow(NULL
);
192 if (wxTheApp
->GetExitOnFrameDelete())
198 wxModelessWindows
.DeleteObject(this);
200 // For some reason, wxWindows can activate another task altogether
201 // when a frame is destroyed after a modal dialog has been invoked.
202 // Try to bring the parent to the top.
203 // MT:Only do this if this frame is currently the active window, else weird
204 // things start to happen
205 if ( wxGetActiveWindow() == this )
206 if (GetParent() && GetParent()->GetHWND())
207 ::BringWindowToTop((HWND
) GetParent()->GetHWND());
210 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
211 void wxFrameMSW::DoGetClientSize(int *x
, int *y
) const
214 ::GetClientRect(GetHwnd(), &rect
);
217 if ( GetStatusBar() && GetStatusBar()->IsShown() )
219 int statusX
, statusY
;
220 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
221 rect
.bottom
-= statusY
;
223 #endif // wxUSE_STATUSBAR
225 wxPoint
pt(GetClientAreaOrigin());
235 // Set the client size (i.e. leave the calculation of borders etc.
237 void wxFrameMSW::DoSetClientSize(int width
, int height
)
239 HWND hWnd
= GetHwnd();
242 ::GetClientRect(hWnd
, &rectClient
);
245 ::GetWindowRect(hWnd
, &rectTotal
);
247 // Find the difference between the entire window (title bar and all)
248 // and the client area; add this to the new client size to move the
250 width
+= rectTotal
.right
- rectTotal
.left
- rectClient
.right
;
251 height
+= rectTotal
.bottom
- rectTotal
.top
- rectClient
.bottom
;
254 wxStatusBar
*statbar
= GetStatusBar();
255 if ( statbar
&& statbar
->IsShown() )
257 // leave enough space for the status bar
258 height
+= statbar
->GetSize().y
;
260 #endif // wxUSE_STATUSBAR
262 // note that this takes the toolbar into account
263 wxPoint pt
= GetClientAreaOrigin();
267 if ( !::MoveWindow(hWnd
, rectTotal
.left
, rectTotal
.top
,
268 width
, height
, TRUE
/* redraw */) )
270 wxLogLastError(_T("MoveWindow"));
273 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
274 event
.SetEventObject(this);
275 GetEventHandler()->ProcessEvent(event
);
278 void wxFrameMSW::DoGetSize(int *width
, int *height
) const
281 ::GetWindowRect(GetHwnd(), &rect
);
283 *width
= rect
.right
- rect
.left
;
284 *height
= rect
.bottom
- rect
.top
;
287 void wxFrameMSW::DoGetPosition(int *x
, int *y
) const
290 ::GetWindowRect(GetHwnd(), &rect
);
296 // ----------------------------------------------------------------------------
297 // variations around ::ShowWindow()
298 // ----------------------------------------------------------------------------
300 void wxFrameMSW::DoShowWindow(int nShowCmd
)
302 ::ShowWindow(GetHwnd(), nShowCmd
);
304 m_iconized
= nShowCmd
== SW_MINIMIZE
;
307 bool wxFrameMSW::Show(bool show
)
309 // don't use wxWindow version as we want to call DoShowWindow()
310 if ( !wxWindowBase::Show(show
) )
316 if ( m_maximizeOnShow
)
319 nShowCmd
= SW_MAXIMIZE
;
321 m_maximizeOnShow
= FALSE
;
333 DoShowWindow(nShowCmd
);
337 ::BringWindowToTop(GetHwnd());
339 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
340 event
.SetEventObject( this );
341 GetEventHandler()->ProcessEvent(event
);
345 // Try to highlight the correct window (the parent)
348 HWND hWndParent
= GetHwndOf(GetParent());
350 ::BringWindowToTop(hWndParent
);
357 void wxFrameMSW::Iconize(bool iconize
)
359 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
362 void wxFrameMSW::Maximize(bool maximize
)
366 // just maximize it directly
367 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
371 // we can't maximize the hidden frame because it shows it as well, so
372 // just remember that we should do it later in this case
373 m_maximizeOnShow
= TRUE
;
377 void wxFrameMSW::Restore()
379 DoShowWindow(SW_RESTORE
);
382 bool wxFrameMSW::IsIconized() const
384 #ifdef __WXMICROWIN__
388 ((wxFrameMSW
*)this)->m_iconized
= (::IsIconic(GetHwnd()) != 0);
394 bool wxFrameMSW::IsMaximized() const
396 #ifdef __WXMICROWIN__
400 return (::IsZoomed(GetHwnd()) != 0);
404 void wxFrameMSW::SetIcon(const wxIcon
& icon
)
406 wxFrameBase::SetIcon(icon
);
408 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
411 SendMessage(GetHwnd(), WM_SETICON
,
412 (WPARAM
)TRUE
, (LPARAM
)(HICON
) m_icon
.GetHICON());
417 // generate an artificial resize event
418 void wxFrameMSW::SendSizeEvent()
422 ::GetWindowRect(GetHwnd(), &r
);
424 if ( !::GetWindowRect(GetHwnd(), &r
) )
426 wxLogLastError(_T("GetWindowRect"));
432 (void)::PostMessage(GetHwnd(), WM_SIZE
,
433 IsMaximized() ? SIZE_MAXIMIZED
: SIZE_RESTORED
,
434 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
439 wxStatusBar
*wxFrameMSW::OnCreateStatusBar(int number
,
442 const wxString
& name
)
444 wxStatusBar
*statusBar
= NULL
;
446 #if wxUSE_NATIVE_STATUSBAR
447 if ( !UsesNativeStatusBar() )
449 statusBar
= (wxStatusBar
*)new wxStatusBarGeneric(this, id
, style
);
454 statusBar
= new wxStatusBar(this, id
, style
, name
);
457 // Set the height according to the font and the border size
458 wxClientDC
dc(statusBar
);
459 dc
.SetFont(statusBar
->GetFont());
462 dc
.GetTextExtent(_T("X"), NULL
, &y
);
464 int height
= (int)( (11*y
)/10 + 2*statusBar
->GetBorderY());
466 statusBar
->SetSize(-1, -1, -1, height
);
468 statusBar
->SetFieldsCount(number
);
473 void wxFrameMSW::PositionStatusBar()
475 if ( !m_frameStatusBar
)
479 GetClientSize(&w
, &h
);
481 m_frameStatusBar
->GetSize(&sw
, &sh
);
483 // Since we wish the status bar to be directly under the client area,
484 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
485 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
487 #endif // wxUSE_STATUSBAR
489 #if wxUSE_MENUS_NATIVE
491 void wxFrameMSW::AttachMenuBar(wxMenuBar
*menubar
)
495 // actually remove the menu from the frame
496 m_hMenu
= (WXHMENU
)0;
497 InternalSetMenuBar();
499 else // set new non NULL menu bar
501 // Can set a menubar several times.
502 if ( menubar
->GetHMenu() )
504 m_hMenu
= menubar
->GetHMenu();
508 if ( menubar
->IsAttached() )
511 m_hMenu
= menubar
->Create();
517 InternalSetMenuBar();
521 void wxFrameMSW::InternalSetMenuBar()
523 #ifndef __WXMICROWIN__
524 if ( !::SetMenu(GetHwnd(), (HMENU
)m_hMenu
) )
526 wxLogLastError(wxT("SetMenu"));
531 #endif // wxUSE_MENUS_NATIVE
533 // Responds to colour changes, and passes event on to children.
534 void wxFrameMSW::OnSysColourChanged(wxSysColourChangedEvent
& event
)
536 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
540 if ( m_frameStatusBar
)
542 wxSysColourChangedEvent event2
;
543 event2
.SetEventObject( m_frameStatusBar
);
544 m_frameStatusBar
->GetEventHandler()->ProcessEvent(event2
);
546 #endif // wxUSE_STATUSBAR
548 // Propagate the event to the non-top-level children
549 wxWindow::OnSysColourChanged(event
);
552 // Pass TRUE to show full screen, FALSE to restore.
553 bool wxFrameMSW::ShowFullScreen(bool show
, long style
)
560 m_fsIsShowing
= TRUE
;
564 wxToolBar
*theToolBar
= GetToolBar();
566 theToolBar
->GetSize(NULL
, &m_fsToolBarHeight
);
568 // zap the toolbar, menubar, and statusbar
570 if ((style
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
572 theToolBar
->SetSize(-1,0);
573 theToolBar
->Show(FALSE
);
575 #endif // wxUSE_TOOLBAR
577 #ifndef __WXMICROWIN__
578 if (style
& wxFULLSCREEN_NOMENUBAR
)
579 SetMenu((HWND
)GetHWND(), (HMENU
) NULL
);
583 wxStatusBar
*theStatusBar
= GetStatusBar();
585 theStatusBar
->GetSize(NULL
, &m_fsStatusBarHeight
);
587 // Save the number of fields in the statusbar
588 if ((style
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
590 //m_fsStatusBarFields = theStatusBar->GetFieldsCount();
591 //SetStatusBar((wxStatusBar*) NULL);
592 //delete theStatusBar;
593 theStatusBar
->Show(FALSE
);
596 m_fsStatusBarFields
= 0;
597 #endif // wxUSE_STATUSBAR
599 // zap the frame borders
601 // save the 'normal' window style
602 m_fsOldWindowStyle
= GetWindowLong((HWND
)GetHWND(), GWL_STYLE
);
604 // save the old position, width & height, maximize state
605 m_fsOldSize
= GetRect();
606 m_fsIsMaximized
= IsMaximized();
608 // decide which window style flags to turn off
609 LONG newStyle
= m_fsOldWindowStyle
;
612 if (style
& wxFULLSCREEN_NOBORDER
)
613 offFlags
|= WS_BORDER
;
614 if (style
& wxFULLSCREEN_NOCAPTION
)
615 offFlags
|= (WS_CAPTION
| WS_SYSMENU
);
617 newStyle
&= (~offFlags
);
619 // change our window style to be compatible with full-screen mode
620 SetWindowLong((HWND
)GetHWND(), GWL_STYLE
, newStyle
);
622 // resize to the size of the desktop
626 ::GetWindowRect(GetDesktopWindow(), &rect
);
627 width
= rect
.right
- rect
.left
;
628 height
= rect
.bottom
- rect
.top
;
630 SetSize(width
, height
);
632 // now flush the window style cache and actually go full-screen
633 SetWindowPos((HWND
)GetHWND(), HWND_TOP
, 0, 0, width
, height
, SWP_FRAMECHANGED
);
635 wxSizeEvent
event(wxSize(width
, height
), GetId());
636 GetEventHandler()->ProcessEvent(event
);
645 m_fsIsShowing
= FALSE
;
648 wxToolBar
*theToolBar
= GetToolBar();
650 // restore the toolbar, menubar, and statusbar
651 if (theToolBar
&& (m_fsStyle
& wxFULLSCREEN_NOTOOLBAR
))
653 theToolBar
->SetSize(-1, m_fsToolBarHeight
);
654 theToolBar
->Show(TRUE
);
656 #endif // wxUSE_TOOLBAR
659 if ( m_fsStyle
& wxFULLSCREEN_NOSTATUSBAR
)
661 //CreateStatusBar(m_fsStatusBarFields);
664 GetStatusBar()->Show(TRUE
);
668 #endif // wxUSE_STATUSBAR
670 #ifndef __WXMICROWIN__
671 if ((m_fsStyle
& wxFULLSCREEN_NOMENUBAR
) && (m_hMenu
!= 0))
672 SetMenu((HWND
)GetHWND(), (HMENU
)m_hMenu
);
675 Maximize(m_fsIsMaximized
);
676 SetWindowLong((HWND
)GetHWND(),GWL_STYLE
, m_fsOldWindowStyle
);
677 SetWindowPos((HWND
)GetHWND(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
678 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
689 bool wxFrameMSW::MSWCreate(int id
, wxWindow
*parent
, const wxChar
*wclass
, wxWindow
*wx_win
, const wxChar
*title
,
690 int x
, int y
, int width
, int height
, long style
)
693 m_defaultIcon
= (WXHICON
) (wxSTD_FRAME_ICON
? wxSTD_FRAME_ICON
: wxDEFAULT_FRAME_ICON
);
695 // If child windows aren't properly drawn initially, WS_CLIPCHILDREN
696 // could be the culprit. But without it, you can get a lot of flicker.
699 if ( style
& wxCAPTION
)
701 if ( style
& wxFRAME_TOOL_WINDOW
)
702 msflags
|= WS_POPUPWINDOW
;
704 msflags
|= WS_OVERLAPPED
;
711 if (style
& wxMINIMIZE_BOX
)
712 msflags
|= WS_MINIMIZEBOX
;
713 if (style
& wxMAXIMIZE_BOX
)
714 msflags
|= WS_MAXIMIZEBOX
;
715 if (style
& wxTHICK_FRAME
)
716 msflags
|= WS_THICKFRAME
;
717 if (style
& wxSYSTEM_MENU
)
718 msflags
|= WS_SYSMENU
;
719 if ( style
& wxMINIMIZE
)
720 msflags
|= WS_MINIMIZE
;
721 if (style
& wxMAXIMIZE
)
722 msflags
|= WS_MAXIMIZE
;
723 if (style
& wxCAPTION
)
724 msflags
|= WS_CAPTION
;
725 if (style
& wxCLIP_CHILDREN
)
726 msflags
|= WS_CLIPCHILDREN
;
728 // Keep this in wxFrameMSW because it saves recoding this function
730 #if wxUSE_ITSY_BITSY && !defined(__WIN32__)
731 if (style
& wxTINY_CAPTION_VERT
)
732 msflags
|= IBS_VERTCAPTION
;
733 if (style
& wxTINY_CAPTION_HORIZ
)
734 msflags
|= IBS_HORZCAPTION
;
736 if (style
& wxTINY_CAPTION_VERT
)
737 msflags
|= WS_CAPTION
;
738 if (style
& wxTINY_CAPTION_HORIZ
)
739 msflags
|= WS_CAPTION
;
741 if ((style
& wxTHICK_FRAME
) == 0)
742 msflags
|= WS_BORDER
;
744 WXDWORD extendedStyle
= MakeExtendedStyle(style
);
746 // make all frames appear in the win9x shell taskbar unless
747 // wxFRAME_TOOL_WINDOW or wxFRAME_NO_TASKBAR is given - without giving them
748 // WS_EX_APPWINDOW style, the child (i.e. owned) frames wouldn't appear in it
749 #if !defined(__WIN16__) && !defined(__SC__)
750 if ( (style
& wxFRAME_TOOL_WINDOW
) ||
751 (style
& wxFRAME_NO_TASKBAR
) )
752 extendedStyle
|= WS_EX_TOOLWINDOW
;
753 else if ( !(style
& wxFRAME_NO_TASKBAR
) )
754 extendedStyle
|= WS_EX_APPWINDOW
;
757 if (style
& wxSTAY_ON_TOP
)
758 extendedStyle
|= WS_EX_TOPMOST
;
761 if (m_exStyle
& wxFRAME_EX_CONTEXTHELP
)
762 extendedStyle
|= WS_EX_CONTEXTHELP
;
766 if ( !wxWindow::MSWCreate(id
, parent
, wclass
, wx_win
, title
, x
, y
, width
, height
,
767 msflags
, NULL
, extendedStyle
) )
770 // Seems to be necessary if we use WS_POPUP
771 // style instead of WS_OVERLAPPED
772 if (width
> -1 && height
> -1)
773 ::PostMessage(GetHwnd(), WM_SIZE
, SIZE_RESTORED
, MAKELPARAM(width
, height
));
778 // Default activation behaviour - set the focus for the first child
780 void wxFrameMSW::OnActivate(wxActivateEvent
& event
)
782 if ( event
.GetActive() )
784 // restore focus to the child which was last focused
785 wxLogTrace(_T("focus"), _T("wxFrameMSW %08x activated."), m_hWnd
);
787 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
794 wxSetFocusToChild(parent
, &m_winLastFocused
);
798 // remember the last focused child if it is our child
799 m_winLastFocused
= FindFocus();
801 // so we NULL it out if it's a child from some other frame
802 wxWindow
*win
= m_winLastFocused
;
805 if ( win
->IsTopLevel() )
809 m_winLastFocused
= NULL
;
815 win
= win
->GetParent();
818 wxLogTrace(_T("focus"),
819 _T("wxFrameMSW %08x deactivated, last focused: %08x."),
821 m_winLastFocused
? GetHwndOf(m_winLastFocused
)
828 // ----------------------------------------------------------------------------
829 // tool/status bar stuff
830 // ----------------------------------------------------------------------------
834 wxToolBar
* wxFrameMSW::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
836 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
841 return m_frameToolBar
;
844 void wxFrameMSW::PositionToolBar()
847 ::GetClientRect(GetHwnd(), &rect
);
850 if ( GetStatusBar() )
852 int statusX
, statusY
;
853 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
854 rect
.bottom
-= statusY
;
856 #endif // wxUSE_STATUSBAR
858 if ( GetToolBar() && GetToolBar()->IsShown() )
861 GetToolBar()->GetSize(&tw
, &th
);
863 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
872 // Use the 'real' MSW position here
873 GetToolBar()->SetSize(0, 0, tw
, th
, wxSIZE_NO_ADJUSTMENTS
);
876 #endif // wxUSE_TOOLBAR
878 // ----------------------------------------------------------------------------
879 // frame state (iconized/maximized/...)
880 // ----------------------------------------------------------------------------
882 // propagate our state change to all child frames: this allows us to emulate X
883 // Windows behaviour where child frames float independently of the parent one
884 // on the desktop, but are iconized/restored with it
885 void wxFrameMSW::IconizeChildFrames(bool bIconize
)
887 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
889 node
= node
->GetNext() )
891 wxWindow
*win
= node
->GetData();
893 // iconizing the frames with this style under Win95 shell puts them at
894 // the bottom of the screen (as the MDI children) instead of making
895 // them appear in the taskbar because they are, by virtue of this
896 // style, not managed by the taskbar - instead leave Windows take care
899 if ( win
->GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
903 // the child MDI frames are a special case and should not be touched by
904 // the parent frame - instead, they are managed by the user
905 wxFrameMSW
*frame
= wxDynamicCast(win
, wxFrame
);
907 #if wxUSE_MDI_ARCHITECTURE
908 && !wxDynamicCast(frame
, wxMDIChildFrame
)
909 #endif // wxUSE_MDI_ARCHITECTURE
912 frame
->Iconize(bIconize
);
917 // ===========================================================================
918 // message processing
919 // ===========================================================================
921 // ---------------------------------------------------------------------------
923 // ---------------------------------------------------------------------------
925 bool wxFrameMSW::MSWTranslateMessage(WXMSG
* pMsg
)
927 if ( wxWindow::MSWTranslateMessage(pMsg
) )
930 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
931 // try the menu bar accels
932 wxMenuBar
*menuBar
= GetMenuBar();
936 const wxAcceleratorTable
& acceleratorTable
= menuBar
->GetAccelTable();
937 return acceleratorTable
.Translate(this, pMsg
);
940 #endif // wxUSE_MENUS && wxUSE_ACCEL
943 // ---------------------------------------------------------------------------
944 // our private (non virtual) message handlers
945 // ---------------------------------------------------------------------------
947 bool wxFrameMSW::HandlePaint()
950 if ( GetUpdateRect(GetHwnd(), &rect
, FALSE
) )
952 #ifndef __WXMICROWIN__
955 HICON hIcon
= m_icon
.Ok() ? GetHiconOf(m_icon
)
956 : (HICON
)m_defaultIcon
;
958 // Hold a pointer to the dc so long as the OnPaint() message
959 // is being processed
961 HDC hdc
= ::BeginPaint(GetHwnd(), &ps
);
963 // Erase background before painting or we get white background
964 MSWDefWindowProc(WM_ICONERASEBKGND
, (WORD
)(LONG
)ps
.hdc
, 0L);
969 ::GetClientRect(GetHwnd(), &rect
);
971 // FIXME: why hardcoded?
972 static const int icon_width
= 32;
973 static const int icon_height
= 32;
975 int icon_x
= (int)((rect
.right
- icon_width
)/2);
976 int icon_y
= (int)((rect
.bottom
- icon_height
)/2);
978 ::DrawIcon(hdc
, icon_x
, icon_y
, hIcon
);
981 ::EndPaint(GetHwnd(), &ps
);
988 return wxWindow::HandlePaint();
993 // nothing to paint - processed
998 bool wxFrameMSW::HandleSize(int x
, int y
, WXUINT id
)
1000 bool processed
= FALSE
;
1001 #ifndef __WXMICROWIN__
1006 // only do it it if we were iconized before, otherwise resizing the
1007 // parent frame has a curious side effect of bringing it under it's
1012 // restore all child frames too
1013 IconizeChildFrames(FALSE
);
1015 (void)SendIconizeEvent(FALSE
);
1019 case SIZEFULLSCREEN
:
1024 // iconize all child frames too
1025 IconizeChildFrames(TRUE
);
1027 (void)SendIconizeEvent();
1037 PositionStatusBar();
1038 #endif // wxUSE_STATUSBAR
1042 #endif // wxUSE_TOOLBAR
1044 wxSizeEvent
event(wxSize(x
, y
), m_windowId
);
1045 event
.SetEventObject( this );
1046 processed
= GetEventHandler()->ProcessEvent(event
);
1052 bool wxFrameMSW::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
1056 // In case it's e.g. a toolbar.
1057 wxWindow
*win
= wxFindWinFromHandle(control
);
1059 return win
->MSWCommand(cmd
, id
);
1062 // handle here commands from menus and accelerators
1063 if ( cmd
== 0 || cmd
== 1 )
1065 #if wxUSE_MENUS_NATIVE
1066 if ( wxCurrentPopupMenu
)
1068 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
1069 wxCurrentPopupMenu
= NULL
;
1071 return popupMenu
->MSWCommand(cmd
, id
);
1073 #endif // wxUSE_MENUS_NATIVE
1075 if ( ProcessCommand(id
) )
1084 bool wxFrameMSW::HandleMenuSelect(WXWORD nItem
, WXWORD flags
, WXHMENU hMenu
)
1087 if ( flags
== 0xFFFF && hMenu
== 0 )
1089 // menu was removed from screen
1092 #ifndef __WXMICROWIN__
1093 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
);
1149 #ifndef __WXMICROWIN__
1154 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
1156 processed
= HandleMenuSelect(item
, flags
, hmenu
);
1162 processed
= HandlePaint();
1165 #ifndef __WXMICROWIN__
1166 case WM_QUERYDRAGICON
:
1168 HICON hIcon
= m_icon
.Ok() ? GetHiconOf(m_icon
)
1169 : (HICON
)(m_defaultIcon
);
1171 processed
= rc
!= 0;
1177 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
1182 rc
= wxWindow::MSWWindowProc(message
, wParam
, lParam
);