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"
37 #include "wx/dialog.h"
38 #include "wx/settings.h"
39 #include "wx/dcclient.h"
44 #include "wx/msw/private.h"
47 #include "wx/statusbr.h"
48 #include "wx/generic/statusbr.h"
49 #endif // wxUSE_STATUSBAR
52 #include "wx/toolbar.h"
53 #endif // wxUSE_TOOLBAR
55 #include "wx/menuitem.h"
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
62 extern wxWindowList wxModelessWindows
;
63 extern wxList WXDLLEXPORT wxPendingDelete
;
64 extern const wxChar
*wxFrameClassName
;
65 extern wxMenu
*wxCurrentPopupMenu
;
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
71 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
72 EVT_ACTIVATE(wxFrame::OnActivate
)
73 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
76 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxWindow
)
78 // ============================================================================
80 // ============================================================================
82 // ----------------------------------------------------------------------------
83 // static class members
84 // ----------------------------------------------------------------------------
86 #if wxUSE_NATIVE_STATUSBAR
87 bool wxFrame::m_useNativeStatusBar
= TRUE
;
89 bool wxFrame::m_useNativeStatusBar
= FALSE
;
92 // ----------------------------------------------------------------------------
93 // creation/destruction
94 // ----------------------------------------------------------------------------
99 m_maximizeOnShow
= FALSE
;
105 // Data to save/restore when calling ShowFullScreen
107 m_fsOldWindowStyle
= 0;
108 m_fsStatusBarFields
= 0;
109 m_fsStatusBarHeight
= 0;
110 m_fsToolBarHeight
= 0;
112 m_fsIsMaximized
= FALSE
;
113 m_fsIsShowing
= FALSE
;
115 m_winLastFocused
= (wxWindow
*)NULL
;
117 // unlike (almost?) all other windows, frames are created hidden
121 bool wxFrame::Create(wxWindow
*parent
,
123 const wxString
& title
,
127 const wxString
& name
)
130 m_windowStyle
= style
;
131 m_frameMenuBar
= NULL
;
132 m_frameToolBar
= NULL
;
133 m_frameStatusBar
= NULL
;
135 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
140 m_windowId
= (int)NewControlId();
142 if (parent
) parent
->AddChild(this);
151 wxTopLevelWindows
.Append(this);
153 MSWCreate(m_windowId
, parent
, wxFrameClassName
, this, title
,
154 x
, y
, width
, height
, style
);
156 wxModelessWindows
.Append(this);
163 m_isBeingDeleted
= TRUE
;
164 wxTopLevelWindows
.DeleteObject(this);
166 // the ~wxToolBar() code relies on the previous line to be executed before
167 // this one, i.e. the frame should remove itself from wxTopLevelWindows
168 // before destorying its toolbar
171 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
173 wxTheApp
->SetTopWindow(NULL
);
175 if (wxTheApp
->GetExitOnFrameDelete())
181 wxModelessWindows
.DeleteObject(this);
183 // For some reason, wxWindows can activate another task altogether
184 // when a frame is destroyed after a modal dialog has been invoked.
185 // Try to bring the parent to the top.
186 // MT:Only do this if this frame is currently the active window, else weird
187 // things start to happen
188 if ( wxGetActiveWindow() == this )
189 if (GetParent() && GetParent()->GetHWND())
190 ::BringWindowToTop((HWND
) GetParent()->GetHWND());
193 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
194 void wxFrame::DoGetClientSize(int *x
, int *y
) const
197 ::GetClientRect(GetHwnd(), &rect
);
200 if ( GetStatusBar() && GetStatusBar()->IsShown() )
202 int statusX
, statusY
;
203 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
204 rect
.bottom
-= statusY
;
206 #endif // wxUSE_STATUSBAR
208 wxPoint
pt(GetClientAreaOrigin());
218 // Set the client size (i.e. leave the calculation of borders etc.
220 void wxFrame::DoSetClientSize(int width
, int height
)
222 HWND hWnd
= GetHwnd();
225 ::GetClientRect(hWnd
, &rect
);
228 GetWindowRect(hWnd
, &rect2
);
230 // Find the difference between the entire window (title bar and all)
231 // and the client area; add this to the new client size to move the
233 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
234 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
237 if ( GetStatusBar() && GetStatusBar()->IsShown())
239 int statusX
, statusY
;
240 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
241 actual_height
+= statusY
;
243 #endif // wxUSE_STATUSBAR
245 wxPoint
pt(GetClientAreaOrigin());
246 actual_width
+= pt
.y
;
247 actual_height
+= pt
.x
;
250 point
.x
= rect2
.left
;
253 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
255 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
256 event
.SetEventObject( this );
257 GetEventHandler()->ProcessEvent(event
);
260 void wxFrame::DoGetSize(int *width
, int *height
) const
263 GetWindowRect(GetHwnd(), &rect
);
264 *width
= rect
.right
- rect
.left
;
265 *height
= rect
.bottom
- rect
.top
;
268 void wxFrame::DoGetPosition(int *x
, int *y
) const
271 GetWindowRect(GetHwnd(), &rect
);
280 // ----------------------------------------------------------------------------
281 // variations around ::ShowWindow()
282 // ----------------------------------------------------------------------------
284 void wxFrame::DoShowWindow(int nShowCmd
)
286 ::ShowWindow(GetHwnd(), nShowCmd
);
288 m_iconized
= nShowCmd
== SW_MINIMIZE
;
291 bool wxFrame::Show(bool show
)
293 // don't use wxWindow version as we want to call DoShowWindow()
294 if ( !wxWindowBase::Show(show
) )
300 if ( m_maximizeOnShow
)
303 nShowCmd
= SW_MAXIMIZE
;
305 m_maximizeOnShow
= FALSE
;
317 DoShowWindow(nShowCmd
);
321 ::BringWindowToTop(GetHwnd());
323 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
324 event
.SetEventObject( this );
325 GetEventHandler()->ProcessEvent(event
);
329 // Try to highlight the correct window (the parent)
332 HWND hWndParent
= GetHwndOf(GetParent());
334 ::BringWindowToTop(hWndParent
);
341 void wxFrame::Iconize(bool iconize
)
343 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
346 void wxFrame::Maximize(bool maximize
)
350 // just maximize it directly
351 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
355 // we can't maximize the hidden frame because it shows it as well, so
356 // just remember that we should do it later in this case
357 m_maximizeOnShow
= TRUE
;
361 void wxFrame::Restore()
363 DoShowWindow(SW_RESTORE
);
366 bool wxFrame::IsIconized() const
368 ((wxFrame
*)this)->m_iconized
= (::IsIconic(GetHwnd()) != 0);
373 bool wxFrame::IsMaximized() const
375 return (::IsZoomed(GetHwnd()) != 0);
378 void wxFrame::SetIcon(const wxIcon
& icon
)
380 wxFrameBase::SetIcon(icon
);
382 #if defined(__WIN95__)
385 SendMessage(GetHwnd(), WM_SETICON
,
386 (WPARAM
)TRUE
, (LPARAM
)(HICON
) m_icon
.GetHICON());
391 // generate an artificial resize event
392 void wxFrame::SendSizeEvent()
396 ::GetWindowRect(GetHwnd(), &r
);
398 if ( !::GetWindowRect(GetHwnd(), &r
) )
400 wxLogLastError(_T("GetWindowRect"));
406 (void)::PostMessage(GetHwnd(), WM_SIZE
,
407 IsMaximized() ? SIZE_MAXIMIZED
: SIZE_RESTORED
,
408 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
413 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
,
416 const wxString
& name
)
418 wxStatusBar
*statusBar
= NULL
;
420 #if wxUSE_NATIVE_STATUSBAR
421 if ( !UsesNativeStatusBar() )
423 statusBar
= (wxStatusBar
*)new wxStatusBarGeneric(this, id
, style
);
428 statusBar
= new wxStatusBar(this, id
, style
, name
);
431 // Set the height according to the font and the border size
432 wxClientDC
dc(statusBar
);
433 dc
.SetFont(statusBar
->GetFont());
436 dc
.GetTextExtent(_T("X"), NULL
, &y
);
438 int height
= (int)( (11*y
)/10 + 2*statusBar
->GetBorderY());
440 statusBar
->SetSize(-1, -1, -1, height
);
442 statusBar
->SetFieldsCount(number
);
447 void wxFrame::PositionStatusBar()
449 if ( !m_frameStatusBar
)
453 GetClientSize(&w
, &h
);
455 m_frameStatusBar
->GetSize(&sw
, &sh
);
457 // Since we wish the status bar to be directly under the client area,
458 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
459 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
461 #endif // wxUSE_STATUSBAR
463 void wxFrame::DetachMenuBar()
465 if ( m_frameMenuBar
)
467 m_frameMenuBar
->Detach();
468 m_frameMenuBar
= NULL
;
472 void wxFrame::SetMenuBar(wxMenuBar
*menubar
)
478 // actually remove the menu from the frame
479 m_hMenu
= (WXHMENU
)0;
480 InternalSetMenuBar();
482 else // set new non NULL menu bar
484 m_frameMenuBar
= NULL
;
486 // Can set a menubar several times.
487 // TODO: how to prevent a memory leak if you have a currently-unattached
488 // menubar? wxWindows assumes that the frame will delete the menu (otherwise
489 // there are problems for MDI).
490 if ( menubar
->GetHMenu() )
492 m_hMenu
= menubar
->GetHMenu();
498 m_hMenu
= menubar
->Create();
504 InternalSetMenuBar();
506 m_frameMenuBar
= menubar
;
507 menubar
->Attach(this);
511 void wxFrame::InternalSetMenuBar()
513 if ( !::SetMenu(GetHwnd(), (HMENU
)m_hMenu
) )
515 wxLogLastError(wxT("SetMenu"));
519 // Responds to colour changes, and passes event on to children.
520 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
522 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
525 if ( m_frameStatusBar
)
527 wxSysColourChangedEvent event2
;
528 event2
.SetEventObject( m_frameStatusBar
);
529 m_frameStatusBar
->GetEventHandler()->ProcessEvent(event2
);
532 // Propagate the event to the non-top-level children
533 wxWindow::OnSysColourChanged(event
);
536 // Pass TRUE to show full screen, FALSE to restore.
537 bool wxFrame::ShowFullScreen(bool show
, long style
)
544 m_fsIsShowing
= TRUE
;
547 wxToolBar
*theToolBar
= GetToolBar();
548 wxStatusBar
*theStatusBar
= GetStatusBar();
553 theToolBar
->GetSize(&dummyWidth
, &m_fsToolBarHeight
);
555 theStatusBar
->GetSize(&dummyWidth
, &m_fsStatusBarHeight
);
557 // zap the toolbar, menubar, and statusbar
559 if ((style
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
561 theToolBar
->SetSize(-1,0);
562 theToolBar
->Show(FALSE
);
565 if (style
& wxFULLSCREEN_NOMENUBAR
)
566 SetMenu((HWND
)GetHWND(), (HMENU
) NULL
);
568 // Save the number of fields in the statusbar
569 if ((style
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
571 //m_fsStatusBarFields = theStatusBar->GetFieldsCount();
572 //SetStatusBar((wxStatusBar*) NULL);
573 //delete theStatusBar;
574 theStatusBar
->Show(FALSE
);
577 m_fsStatusBarFields
= 0;
579 // zap the frame borders
581 // save the 'normal' window style
582 m_fsOldWindowStyle
= GetWindowLong((HWND
)GetHWND(), GWL_STYLE
);
584 // save the old position, width & height, maximize state
585 m_fsOldSize
= GetRect();
586 m_fsIsMaximized
= IsMaximized();
588 // decide which window style flags to turn off
589 LONG newStyle
= m_fsOldWindowStyle
;
592 if (style
& wxFULLSCREEN_NOBORDER
)
593 offFlags
|= WS_BORDER
;
594 if (style
& wxFULLSCREEN_NOCAPTION
)
595 offFlags
|= (WS_CAPTION
| WS_SYSMENU
);
597 newStyle
&= (~offFlags
);
599 // change our window style to be compatible with full-screen mode
600 SetWindowLong((HWND
)GetHWND(), GWL_STYLE
, newStyle
);
602 // resize to the size of the desktop
606 ::GetWindowRect(GetDesktopWindow(), &rect
);
607 width
= rect
.right
- rect
.left
;
608 height
= rect
.bottom
- rect
.top
;
610 SetSize(width
, height
);
612 // now flush the window style cache and actually go full-screen
613 SetWindowPos((HWND
)GetHWND(), HWND_TOP
, 0, 0, width
, height
, SWP_FRAMECHANGED
);
615 wxSizeEvent
event(wxSize(width
, height
), GetId());
616 GetEventHandler()->ProcessEvent(event
);
625 m_fsIsShowing
= FALSE
;
627 wxToolBar
*theToolBar
= GetToolBar();
629 // restore the toolbar, menubar, and statusbar
630 if (theToolBar
&& (m_fsStyle
& wxFULLSCREEN_NOTOOLBAR
))
632 theToolBar
->SetSize(-1, m_fsToolBarHeight
);
633 theToolBar
->Show(TRUE
);
636 if ((m_fsStyle
& wxFULLSCREEN_NOSTATUSBAR
)) // && (m_fsStatusBarFields > 0))
638 //CreateStatusBar(m_fsStatusBarFields);
641 GetStatusBar()->Show(TRUE
);
646 if ((m_fsStyle
& wxFULLSCREEN_NOMENUBAR
) && (m_hMenu
!= 0))
647 SetMenu((HWND
)GetHWND(), (HMENU
)m_hMenu
);
649 Maximize(m_fsIsMaximized
);
650 SetWindowLong((HWND
)GetHWND(),GWL_STYLE
, m_fsOldWindowStyle
);
651 SetWindowPos((HWND
)GetHWND(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
652 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
663 bool wxFrame::MSWCreate(int id
, wxWindow
*parent
, const wxChar
*wclass
, wxWindow
*wx_win
, const wxChar
*title
,
664 int x
, int y
, int width
, int height
, long style
)
667 m_defaultIcon
= (WXHICON
) (wxSTD_FRAME_ICON
? wxSTD_FRAME_ICON
: wxDEFAULT_FRAME_ICON
);
669 // If child windows aren't properly drawn initially, WS_CLIPCHILDREN
670 // could be the culprit. But without it, you can get a lot of flicker.
673 if ( style
& wxCAPTION
)
675 if ( style
& wxFRAME_TOOL_WINDOW
)
676 msflags
|= WS_POPUPWINDOW
;
678 msflags
|= WS_OVERLAPPED
;
685 if (style
& wxMINIMIZE_BOX
)
686 msflags
|= WS_MINIMIZEBOX
;
687 if (style
& wxMAXIMIZE_BOX
)
688 msflags
|= WS_MAXIMIZEBOX
;
689 if (style
& wxTHICK_FRAME
)
690 msflags
|= WS_THICKFRAME
;
691 if (style
& wxSYSTEM_MENU
)
692 msflags
|= WS_SYSMENU
;
693 if ( style
& wxMINIMIZE
)
694 msflags
|= WS_MINIMIZE
;
695 if (style
& wxMAXIMIZE
)
696 msflags
|= WS_MAXIMIZE
;
697 if (style
& wxCAPTION
)
698 msflags
|= WS_CAPTION
;
699 if (style
& wxCLIP_CHILDREN
)
700 msflags
|= WS_CLIPCHILDREN
;
702 // Keep this in wxFrame because it saves recoding this function
704 #if wxUSE_ITSY_BITSY && !defined(__WIN32__)
705 if (style
& wxTINY_CAPTION_VERT
)
706 msflags
|= IBS_VERTCAPTION
;
707 if (style
& wxTINY_CAPTION_HORIZ
)
708 msflags
|= IBS_HORZCAPTION
;
710 if (style
& wxTINY_CAPTION_VERT
)
711 msflags
|= WS_CAPTION
;
712 if (style
& wxTINY_CAPTION_HORIZ
)
713 msflags
|= WS_CAPTION
;
715 if ((style
& wxTHICK_FRAME
) == 0)
716 msflags
|= WS_BORDER
;
718 WXDWORD extendedStyle
= MakeExtendedStyle(style
);
720 // make all frames appear in the win9x shell taskbar unless
721 // wxFRAME_TOOL_WINDOW or wxFRAME_NO_TASKBAR is given - without giving them
722 // WS_EX_APPWINDOW style, the child (i.e. owned) frames wouldn't appear in it
723 #if !defined(__WIN16__) && !defined(__SC__)
724 if ( (style
& wxFRAME_TOOL_WINDOW
) ||
725 (style
& wxFRAME_NO_TASKBAR
) )
726 extendedStyle
|= WS_EX_TOOLWINDOW
;
727 else if ( !(style
& wxFRAME_NO_TASKBAR
) )
728 extendedStyle
|= WS_EX_APPWINDOW
;
731 if (style
& wxSTAY_ON_TOP
)
732 extendedStyle
|= WS_EX_TOPMOST
;
735 if (m_exStyle
& wxFRAME_EX_CONTEXTHELP
)
736 extendedStyle
|= WS_EX_CONTEXTHELP
;
740 if ( !wxWindow::MSWCreate(id
, parent
, wclass
, wx_win
, title
, x
, y
, width
, height
,
741 msflags
, NULL
, extendedStyle
) )
744 // Seems to be necessary if we use WS_POPUP
745 // style instead of WS_OVERLAPPED
746 if (width
> -1 && height
> -1)
747 ::PostMessage(GetHwnd(), WM_SIZE
, SIZE_RESTORED
, MAKELPARAM(width
, height
));
752 // Default activation behaviour - set the focus for the first child
754 void wxFrame::OnActivate(wxActivateEvent
& event
)
756 if ( event
.GetActive() )
758 // restore focus to the child which was last focused
759 wxLogTrace(_T("focus"), _T("wxFrame %08x activated."), m_hWnd
);
761 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
768 wxSetFocusToChild(parent
, &m_winLastFocused
);
772 // remember the last focused child if it is our child
773 m_winLastFocused
= FindFocus();
775 // so we NULL it out if it's a child from some other frame
776 wxWindow
*win
= m_winLastFocused
;
779 if ( win
->IsTopLevel() )
783 m_winLastFocused
= NULL
;
789 win
= win
->GetParent();
792 wxLogTrace(_T("focus"),
793 _T("wxFrame %08x deactivated, last focused: %08x."),
795 m_winLastFocused
? GetHwndOf(m_winLastFocused
)
802 // ----------------------------------------------------------------------------
803 // tool/status bar stuff
804 // ----------------------------------------------------------------------------
808 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
810 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
815 return m_frameToolBar
;
818 void wxFrame::PositionToolBar()
821 ::GetClientRect(GetHwnd(), &rect
);
824 if ( GetStatusBar() )
826 int statusX
, statusY
;
827 GetStatusBar()->GetClientSize(&statusX
, &statusY
);
828 rect
.bottom
-= statusY
;
830 #endif // wxUSE_STATUSBAR
832 if ( GetToolBar() && GetToolBar()->IsShown() )
835 GetToolBar()->GetSize(&tw
, &th
);
837 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
846 // Use the 'real' MSW position here
847 GetToolBar()->SetSize(0, 0, tw
, th
, wxSIZE_NO_ADJUSTMENTS
);
850 #endif // wxUSE_TOOLBAR
852 // ----------------------------------------------------------------------------
853 // frame state (iconized/maximized/...)
854 // ----------------------------------------------------------------------------
856 // propagate our state change to all child frames: this allows us to emulate X
857 // Windows behaviour where child frames float independently of the parent one
858 // on the desktop, but are iconized/restored with it
859 void wxFrame::IconizeChildFrames(bool bIconize
)
861 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
863 node
= node
->GetNext() )
865 wxWindow
*win
= node
->GetData();
867 // iconizing the frames with this style under Win95 shell puts them at
868 // the bottom of the screen (as the MDI children) instead of making
869 // them appear in the taskbar because they are, by virtue of this
870 // style, not managed by the taskbar - instead leave Windows take care
873 if ( win
->GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
877 // the child MDI frames are a special case and should not be touched by
878 // the parent frame - instead, they are managed by the user
879 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
880 if ( frame
&& !frame
->IsMDIChild() )
882 frame
->Iconize(bIconize
);
887 // ===========================================================================
888 // message processing
889 // ===========================================================================
891 // ---------------------------------------------------------------------------
893 // ---------------------------------------------------------------------------
895 bool wxFrame::MSWTranslateMessage(WXMSG
* pMsg
)
897 if ( wxWindow::MSWTranslateMessage(pMsg
) )
900 // try the menu bar accels
901 wxMenuBar
*menuBar
= GetMenuBar();
905 const wxAcceleratorTable
& acceleratorTable
= menuBar
->GetAccelTable();
906 return acceleratorTable
.Translate(this, pMsg
);
909 // ---------------------------------------------------------------------------
910 // our private (non virtual) message handlers
911 // ---------------------------------------------------------------------------
913 bool wxFrame::HandlePaint()
916 if ( GetUpdateRect(GetHwnd(), &rect
, FALSE
) )
920 HICON hIcon
= m_icon
.Ok() ? GetHiconOf(m_icon
)
921 : (HICON
)m_defaultIcon
;
923 // Hold a pointer to the dc so long as the OnPaint() message
924 // is being processed
926 HDC hdc
= ::BeginPaint(GetHwnd(), &ps
);
928 // Erase background before painting or we get white background
929 MSWDefWindowProc(WM_ICONERASEBKGND
, (WORD
)(LONG
)ps
.hdc
, 0L);
934 ::GetClientRect(GetHwnd(), &rect
);
936 // FIXME: why hardcoded?
937 static const int icon_width
= 32;
938 static const int icon_height
= 32;
940 int icon_x
= (int)((rect
.right
- icon_width
)/2);
941 int icon_y
= (int)((rect
.bottom
- icon_height
)/2);
943 ::DrawIcon(hdc
, icon_x
, icon_y
, hIcon
);
946 ::EndPaint(GetHwnd(), &ps
);
952 return wxWindow::HandlePaint();
957 // nothing to paint - processed
962 bool wxFrame::HandleSize(int x
, int y
, WXUINT id
)
964 bool processed
= FALSE
;
969 // only do it it if we were iconized before, otherwise resizing the
970 // parent frame has a curious side effect of bringing it under it's
975 // restore all child frames too
976 IconizeChildFrames(FALSE
);
985 // iconize all child frames too
986 IconizeChildFrames(TRUE
);
997 wxSizeEvent
event(wxSize(x
, y
), m_windowId
);
998 event
.SetEventObject( this );
999 processed
= GetEventHandler()->ProcessEvent(event
);
1005 bool wxFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
1009 // In case it's e.g. a toolbar.
1010 wxWindow
*win
= wxFindWinFromHandle(control
);
1012 return win
->MSWCommand(cmd
, id
);
1015 // handle here commands from menus and accelerators
1016 if ( cmd
== 0 || cmd
== 1 )
1018 if ( wxCurrentPopupMenu
)
1020 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
1021 wxCurrentPopupMenu
= NULL
;
1023 return popupMenu
->MSWCommand(cmd
, id
);
1026 if ( ProcessCommand(id
) )
1035 bool wxFrame::HandleMenuSelect(WXWORD nItem
, WXWORD flags
, WXHMENU hMenu
)
1038 if ( flags
== 0xFFFF && hMenu
== 0 )
1040 // menu was removed from screen
1043 else if ( !(flags
& MF_POPUP
) && !(flags
& MF_SEPARATOR
) )
1049 // don't give hints for separators (doesn't make sense) nor for the
1050 // items opening popup menus (they don't have them anyhow) but do clear
1051 // the status line - otherwise, we would be left with the help message
1052 // for the previous item which doesn't apply any more
1053 wxStatusBar
*statbar
= GetStatusBar();
1056 statbar
->SetStatusText(wxEmptyString
);
1062 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, item
);
1063 event
.SetEventObject( this );
1065 return GetEventHandler()->ProcessEvent(event
);
1068 // ---------------------------------------------------------------------------
1069 // the window proc for wxFrame
1070 // ---------------------------------------------------------------------------
1072 long wxFrame::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1075 bool processed
= FALSE
;
1080 // if we can't close, tell the system that we processed the
1081 // message - otherwise it would close us
1082 processed
= !Close();
1089 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
1092 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
1100 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
1102 processed
= HandleMenuSelect(item
, flags
, hmenu
);
1107 processed
= HandlePaint();
1110 case WM_QUERYDRAGICON
:
1112 HICON hIcon
= m_icon
.Ok() ? GetHiconOf(m_icon
)
1113 : (HICON
)(m_defaultIcon
);
1115 processed
= rc
!= 0;
1120 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
1125 rc
= wxWindow::MSWWindowProc(message
, wParam
, lParam
);