1 /////////////////////////////////////////////////////////////////////////////
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/dialog.h"
22 #include "wx/settings.h"
23 #include "wx/dcclient.h"
26 #include "wx/os2/private.h"
29 #include "wx/statusbr.h"
30 #include "wx/generic/statusbr.h"
31 #endif // wxUSE_STATUSBAR
34 #include "wx/toolbar.h"
35 #endif // wxUSE_TOOLBAR
37 #include "wx/menuitem.h"
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 extern wxWindowList wxModelessWindows
;
45 extern wxList WXDLLEXPORT wxPendingDelete
;
46 extern wxChar wxFrameClassName
[];
47 extern wxMenu
*wxCurrentPopupMenu
;
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
54 EVT_ACTIVATE(wxFrame::OnActivate
)
55 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
58 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxWindow
)
60 // ============================================================================
62 // ============================================================================
64 // ----------------------------------------------------------------------------
65 // static class members
66 // ----------------------------------------------------------------------------
68 #if wxUSE_NATIVE_STATUSBAR
69 bool wxFrame::m_bUseNativeStatusBar
= TRUE
;
71 bool wxFrame::m_bUseNativeStatusBar
= FALSE
;
74 // ----------------------------------------------------------------------------
75 // creation/destruction
76 // ----------------------------------------------------------------------------
85 // Data to save/restore when calling ShowFullScreen
87 m_lFsOldWindowStyle
= 0L;
88 m_nFsStatusBarFields
= 0;
89 m_nFsStatusBarHeight
= 0;
90 m_nFsToolBarHeight
= 0;
91 m_bFsIsMaximized
= FALSE
;
92 m_bFsIsShowing
= FALSE
;
93 } // end of wxFrame::Init
98 , const wxString
& rsTitle
100 , const wxSize
& rSize
102 , const wxString
& rsName
107 int nWidth
= rSize
.x
;
108 int nHeight
= rSize
.y
;
111 m_windowStyle
= lulStyle
;
112 m_frameMenuBar
= NULL
;
113 m_frameToolBar
= NULL
;
114 m_frameStatusBar
= NULL
;
116 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
121 m_windowId
= (int)NewControlId();
124 pParent
->AddChild(this);
128 if ((m_windowStyle
& wxFRAME_FLOAT_ON_PARENT
) == 0)
132 wxTopLevelWindows
.Append(this);
134 OS2Create( m_windowId
146 wxModelessWindows
.Append(this);
148 } // end of wxFrame::Create
152 m_isBeingDeleted
= TRUE
;
153 wxTopLevelWindows
.DeleteObject(this);
157 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
159 wxTheApp
->SetTopWindow(NULL
);
161 if (wxTheApp
->GetExitOnFrameDelete())
163 ::WinPostMsg(GetHwnd(), WM_QUIT
, 0, 0);
166 wxModelessWindows
.DeleteObject(this);
169 // For some reason, wxWindows can activate another task altogether
170 // when a frame is destroyed after a modal dialog has been invoked.
171 // Try to bring the parent to the top.
173 // MT:Only do this if this frame is currently the active window, else weird
174 // things start to happen.
176 if (wxGetActiveWindow() == this)
178 if (GetParent() && GetParent()->GetHWND())
180 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
190 } // end of wxFrame::~wxFrame
193 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
195 void wxFrame::DoGetClientSize(
201 // OS/2 PM's coordinates go from bottom-left not
202 // top-left thus the += instead of the -=
208 // PM has no GetClientRect that inherantly knows about the client window
209 // We have to explicitly go fetch it!
211 hWndClient
= ::WinWindowFromID(GetHwnd(), FID_CLIENT
);
212 ::WinQueryWindowRect(hWndClient
, &vRect
);
215 if ( GetStatusBar() )
220 GetStatusBar()->GetClientSize( &nStatusX
223 vRect
.yBottom
+= nStatusY
;
225 #endif // wxUSE_STATUSBAR
227 wxPoint
vPoint(GetClientAreaOrigin());
229 vRect
.yBottom
+= vPoint
.y
;
230 vRect
.xRight
-= vPoint
.x
;
236 } // end of wxFrame::DoGetClientSize
239 // Set the client size (i.e. leave the calculation of borders etc.
242 void wxFrame::DoSetClientSize(
247 HWND hWnd
= GetHwnd();
252 hWndClient
= ::WinWindowFromID(GetHwnd(), FID_CLIENT
);
253 ::WinQueryWindowRect(hWndClient
, &vRect
);
255 ::WinQueryWindowRect(hWnd
, &vRect2
);
258 // Find the difference between the entire window (title bar and all)
259 // and the client area; add this to the new client size to move the
260 // window. Remember OS/2's backwards y coord system!
262 int nActualWidth
= vRect2
.xRight
- vRect2
.xLeft
- vRect
.xRight
+ nWidth
;
263 int nActualHeight
= vRect2
.yTop
+ vRect2
.yTop
- vRect
.yTop
+ nHeight
;
266 if ( GetStatusBar() )
271 GetStatusBar()->GetClientSize( &nStatusX
274 nActualHeight
+= nStatusY
;
276 #endif // wxUSE_STATUSBAR
278 wxPoint
vPoint(GetClientAreaOrigin());
279 nActualWidth
+= vPoint
.y
;
280 nActualHeight
+= vPoint
.x
;
284 vPointl
.x
= vRect2
.xLeft
;
285 vPoint
.y
= vRect2
.yTop
;
287 ::WinSetWindowPos( hWnd
293 ,SWP_MOVE
| SWP_SIZE
| SWP_SHOW
296 wxSizeEvent
vEvent( wxSize( nWidth
301 vEvent
.SetEventObject(this);
302 GetEventHandler()->ProcessEvent(vEvent
);
303 } // end of wxFrame::DoSetClientSize
305 void wxFrame::DoGetSize(
312 ::WinQueryWindowRect(GetHwnd(), &vRect
);
313 *pWidth
= vRect
.xRight
- vRect
.xLeft
;
314 *pHeight
= vRect
.yTop
- vRect
.yBottom
;
315 } // end of wxFrame::DoGetSize
317 void wxFrame::DoGetPosition(
325 ::WinQueryWindowRect(GetHwnd(), &vRect
);
326 vPoint
.x
= vRect
.xLeft
;
329 // OS/2 is backwards [WIN32 it is vRect.yTop]
331 vPoint
.y
= vRect
.yBottom
;
335 } // end of wxFrame::DoGetPosition
337 // ----------------------------------------------------------------------------
338 // variations around ::ShowWindow()
339 // ----------------------------------------------------------------------------
341 void wxFrame::DoShowWindow(
346 HWND hTitlebar
= NULLHANDLE
;
347 HWND hHScroll
= NULLHANDLE
;
348 HWND hVScroll
= NULLHANDLE
;
349 HWND hMenuBar
= NULLHANDLE
;
357 // Send anything to initialize the frame
359 WinQueryWindowPos(GetHwnd(), &vSwp
);
360 hClient
= WinWindowFromID(GetHwnd(), FID_CLIENT
);
361 hTitlebar
= WinWindowFromID(GetHwnd(), FID_TITLEBAR
);
362 WinQueryWindowPos(hTitlebar
, &vSwpTitlebar
);
363 hHScroll
= WinWindowFromID(GetHwnd(), FID_HORZSCROLL
);
364 WinQueryWindowPos(hHScroll
, &vSwpHScroll
);
365 hVScroll
= WinWindowFromID(GetHwnd(), FID_VERTSCROLL
);
366 WinQueryWindowPos(hVScroll
, &vSwpVScroll
);
367 hMenuBar
= WinWindowFromID(GetHwnd(), FID_MENU
);
368 WinQueryWindowPos(hMenuBar
, &vSwpMenu
);
369 WinSetWindowPos( hClient
372 ,(SV_CYSIZEBORDER
- 1) + vSwpHScroll
.cy
373 ,vSwp
.cx
- ((SV_CXSIZEBORDER
* 2) + vSwpVScroll
.cx
)
374 ,vSwp
.cy
- ((SV_CYSIZEBORDER
* 2) + 1 + vSwpTitlebar
.cy
+ vSwpMenu
.cy
+ vSwpHScroll
.cy
)
377 ::WinShowWindow(GetHwnd(), (BOOL
)bShowCmd
);
378 ::WinShowWindow(hClient
, (BOOL
)bShowCmd
);
379 } // end of wxFrame::DoShowWindow
387 DoShowWindow((int)bShow
);
391 wxActivateEvent
vEvent(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
393 ::WinQueryWindowPos(GetHwnd(), &vSwp
);
394 m_bIconized
= vSwp
.fl
& SWP_MINIMIZE
;
395 ::WinEnableWindow(GetHwnd(), TRUE
);
396 vEvent
.SetEventObject(this);
397 GetEventHandler()->ProcessEvent(vEvent
);
402 // Try to highlight the correct window (the parent)
406 HWND hWndParent
= GetHwndOf(GetParent());
408 ::WinQueryWindowPos(hWndParent
, &vSwp
);
409 m_bIconized
= vSwp
.fl
& SWP_MINIMIZE
;
411 ::WinSetWindowPos( hWndParent
417 ,SWP_ZORDER
| SWP_ACTIVATE
| SWP_SHOW
| SWP_MOVE
419 ::WinEnableWindow(hWndParent
, TRUE
);
423 } // end of wxFrame::Show
425 void wxFrame::Iconize(
429 DoShowWindow(bIconize
? SWP_MINIMIZE
: SWP_RESTORE
);
430 } // end of wxFrame::Iconize
432 void wxFrame::Maximize(
435 DoShowWindow(bMaximize
? SWP_MAXIMIZE
: SWP_RESTORE
);
436 } // end of wxFrame::Maximize
438 void wxFrame::Restore()
440 DoShowWindow(SWP_RESTORE
);
441 } // end of wxFrame::Restore
443 bool wxFrame::IsIconized() const
448 ::WinQueryWindowPos(GetHwnd(), &vSwp
);
450 if (vSwp
.fl
& SWP_MINIMIZE
)
451 ((wxFrame
*)this)->m_bIconized
= TRUE
;
453 ((wxFrame
*)this)->m_bIconized
= FALSE
;
455 } // end of wxFrame::IsIconized
458 bool wxFrame::IsMaximized() const
463 ::WinQueryWindowPos(GetHwnd(), &vSwp
);
464 return (vSwp
.fl
& SWP_MAXIMIZE
);
465 } // end of wxFrame::IsMaximized
467 void wxFrame::SetIcon(
471 wxFrameBase::SetIcon(rIcon
);
473 if ((m_icon
.GetHICON()) != NULLHANDLE
)
475 ::WinSendMsg( GetHwnd()
477 ,(MPARAM
)((HPOINTER
)m_icon
.GetHICON())
480 ::WinSendMsg( GetHwnd()
486 } // end of wxFrame::SetIcon
489 wxStatusBar
* wxFrame::OnCreateStatusBar(
493 , const wxString
& rName
496 wxStatusBar
* pStatusBar
= NULL
;
498 pStatusBar
= wxFrameBase::OnCreateStatusBar( nNumber
504 } // end of wxFrame::OnCreateStatusBar
506 void wxFrame::PositionStatusBar()
509 // Native status bar positions itself
511 if (m_frameStatusBar
)
520 hWndClient
= ::WinWindowFromID(GetHwnd(), FID_CLIENT
);
521 ::WinQueryWindowRect(hWndClient
, &vRect
);
522 nWidth
= vRect
.xRight
- vRect
.xLeft
;
523 nHeight
= vRect
.yTop
- vRect
.yBottom
;
525 m_frameStatusBar
->GetSize( &nStatbarWidth
530 // Since we wish the status bar to be directly under the client area,
531 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
533 m_frameStatusBar
->SetSize( 0
539 } // end of wxFrame::PositionStatusBar
540 #endif // wxUSE_STATUSBAR
542 void wxFrame::DetachMenuBar()
546 m_frameMenuBar
->Detach();
547 m_frameMenuBar
= NULL
;
549 } // end of wxFrame::DetachMenuBar
551 void wxFrame::SetMenuBar(
561 m_frameMenuBar
= NULL
;
563 // Can set a menubar several times.
564 // TODO: how to prevent a memory leak if you have a currently-unattached
565 // menubar? wxWindows assumes that the frame will delete the menu (otherwise
566 // there are problems for MDI).
567 if (pMenuBar
->GetHMenu())
569 m_hMenu
= pMenuBar
->GetHMenu();
575 m_hMenu
= pMenuBar
->Create();
581 InternalSetMenuBar();
583 m_frameMenuBar
= pMenuBar
;
584 pMenuBar
->Attach(this);
585 } // end of wxFrame::SetMenuBar
587 void wxFrame::InternalSetMenuBar()
589 WinSendMsg((HWND
)GetHwnd(), WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
590 } // end of wxFrame::InternalSetMenuBar
593 // Responds to colour changes, and passes event on to children
595 void wxFrame::OnSysColourChanged(
596 wxSysColourChangedEvent
& rEvent
599 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
602 if (m_frameStatusBar
)
604 wxSysColourChangedEvent vEvent2
;
606 vEvent2
.SetEventObject(m_frameStatusBar
);
607 m_frameStatusBar
->GetEventHandler()->ProcessEvent(vEvent2
);
611 // Propagate the event to the non-top-level children
613 wxWindow::OnSysColourChanged(rEvent
);
614 } // end of wxFrame::OnSysColourChanged
616 // Pass TRUE to show full screen, FALSE to restore.
617 bool wxFrame::ShowFullScreen(
629 m_fsIsShowing = TRUE;
632 wxToolBar *theToolBar = GetToolBar();
633 wxStatusBar *theStatusBar = GetStatusBar();
638 theToolBar->GetSize(&dummyWidth, &m_fsToolBarHeight);
640 theStatusBar->GetSize(&dummyWidth, &m_fsStatusBarHeight);
642 // zap the toolbar, menubar, and statusbar
644 if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
646 theToolBar->SetSize(-1,0);
647 theToolBar->Show(FALSE);
650 if (style & wxFULLSCREEN_NOMENUBAR)
651 SetMenu((HWND)GetHWND(), (HMENU) NULL);
653 // Save the number of fields in the statusbar
654 if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
656 m_fsStatusBarFields = theStatusBar->GetFieldsCount();
657 SetStatusBar((wxStatusBar*) NULL);
661 m_fsStatusBarFields = 0;
663 // zap the frame borders
665 // save the 'normal' window style
666 m_fsOldWindowStyle = GetWindowLong((HWND)GetHWND(), GWL_STYLE);
668 // save the old position, width & height, maximize state
669 m_fsOldSize = GetRect();
670 m_fsIsMaximized = IsMaximized();
672 // decide which window style flags to turn off
673 LONG newStyle = m_fsOldWindowStyle;
676 if (style & wxFULLSCREEN_NOBORDER)
677 offFlags |= WS_BORDER;
678 if (style & wxFULLSCREEN_NOCAPTION)
679 offFlags |= (WS_CAPTION | WS_SYSMENU);
681 newStyle &= (~offFlags);
683 // change our window style to be compatible with full-screen mode
684 SetWindowLong((HWND)GetHWND(), GWL_STYLE, newStyle);
686 // resize to the size of the desktop
690 ::GetWindowRect(GetDesktopWindow(), &rect);
691 width = rect.right - rect.left;
692 height = rect.bottom - rect.top;
694 SetSize(width, height);
696 // now flush the window style cache and actually go full-screen
697 SetWindowPos((HWND)GetHWND(), HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED);
699 wxSizeEvent event(wxSize(width, height), GetId());
700 GetEventHandler()->ProcessEvent(event);
709 m_fsIsShowing = FALSE;
711 wxToolBar *theToolBar = GetToolBar();
713 // restore the toolbar, menubar, and statusbar
714 if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR))
716 theToolBar->SetSize(-1, m_fsToolBarHeight);
717 theToolBar->Show(TRUE);
720 if ((m_fsStyle & wxFULLSCREEN_NOSTATUSBAR) && (m_fsStatusBarFields > 0))
722 CreateStatusBar(m_fsStatusBarFields);
726 if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0))
727 SetMenu((HWND)GetHWND(), (HMENU)m_hMenu);
729 Maximize(m_fsIsMaximized);
730 SetWindowLong((HWND)GetHWND(),GWL_STYLE, m_fsOldWindowStyle);
731 SetWindowPos((HWND)GetHWND(),HWND_TOP,m_fsOldSize.x, m_fsOldSize.y,
732 m_fsOldSize.width, m_fsOldSize.height, SWP_FRAMECHANGED);
738 } // end of wxFrame::ShowFullScreen
743 bool wxFrame::OS2Create(
746 , const wxChar
* zWclass
748 , const wxChar
* zTitle
756 ULONG ulCreateFlags
= 0L;
757 ULONG ulStyleFlags
= 0L;
758 ULONG ulExtraFlags
= 0L;
759 FRAMECDATA vFrameCtlData
;
760 HWND hParent
= NULLHANDLE
;
761 HWND hClient
= NULLHANDLE
;
762 HWND hTitlebar
= NULLHANDLE
;
763 HWND hHScroll
= NULLHANDLE
;
764 HWND hVScroll
= NULLHANDLE
;
765 HWND hMenuBar
= NULLHANDLE
;
766 HWND hMenu1
= NULLHANDLE
;
767 HWND hMenu2
= NULLHANDLE
;
768 HWND hFrame
= NULLHANDLE
;
776 m_hDefaultIcon
= (WXHICON
) (wxSTD_FRAME_ICON
? wxSTD_FRAME_ICON
: wxDEFAULT_FRAME_ICON
);
777 memset(&vSwp
, '\0', sizeof(SWP
));
778 memset(&vSwpTitlebar
, '\0', sizeof(SWP
));
779 memset(&vSwpVScroll
, '\0', sizeof(SWP
));
780 memset(&vSwpHScroll
, '\0', sizeof(SWP
));
783 hParent
= GetWinHwnd(pParent
);
785 hParent
= HWND_DESKTOP
;
787 if (ulStyle
== wxDEFAULT_FRAME_STYLE
)
788 ulCreateFlags
= FCF_SIZEBORDER
| FCF_TITLEBAR
| FCF_SYSMENU
|
789 FCF_MINMAX
| FCF_VERTSCROLL
| FCF_HORZSCROLL
| FCF_TASKLIST
;
792 if ((ulStyle
& wxCAPTION
) == wxCAPTION
)
793 ulCreateFlags
= FCF_TASKLIST
;
795 ulCreateFlags
= FCF_NOMOVEWITHOWNER
;
797 if (ulStyle
& wxMINIMIZE_BOX
)
798 ulCreateFlags
|= FCF_MINBUTTON
;
799 if (ulStyle
& wxMAXIMIZE_BOX
)
800 ulCreateFlags
|= FCF_MAXBUTTON
;
801 if (ulStyle
& wxTHICK_FRAME
)
802 ulCreateFlags
|= FCF_DLGBORDER
;
803 if (ulStyle
& wxSYSTEM_MENU
)
804 ulCreateFlags
|= FCF_SYSMENU
;
805 if (ulStyle
& wxCAPTION
)
806 ulCreateFlags
|= FCF_TASKLIST
;
807 if (ulStyle
& wxCLIP_CHILDREN
)
809 // Invalid for frame windows under PM
812 if (ulStyle
& wxTINY_CAPTION_VERT
)
813 ulCreateFlags
|= FCF_TASKLIST
;
814 if (ulStyle
& wxTINY_CAPTION_HORIZ
)
815 ulCreateFlags
|= FCF_TASKLIST
;
817 if ((ulStyle
& wxTHICK_FRAME
) == 0)
818 ulCreateFlags
|= FCF_BORDER
;
819 if (ulStyle
& wxFRAME_TOOL_WINDOW
)
820 ulExtraFlags
= kFrameToolWindow
;
822 if (ulStyle
& wxSTAY_ON_TOP
)
823 ulCreateFlags
|= FCF_SYSMODAL
;
825 if ((ulStyle
& wxMINIMIZE
) || (ulStyle
& wxICONIZE
))
826 ulStyleFlags
|= WS_MINIMIZED
;
827 if (ulStyle
& wxMAXIMIZE
)
828 ulStyleFlags
|= WS_MAXIMIZED
;
831 // Clear the visible flag, we always call show
833 ulStyleFlags
&= (unsigned long)~WS_VISIBLE
;
837 // Set the frame control block
839 vFrameCtlData
.cb
= sizeof(vFrameCtlData
);
840 vFrameCtlData
.flCreateFlags
= ulCreateFlags
;
841 vFrameCtlData
.hmodResources
= 0L;
842 vFrameCtlData
.idResources
= 0;
845 // Create the frame window
847 if (!wxWindow::OS2Create( hParent
858 ,(void*)&vFrameCtlData
866 // Create the client window. We must call the API from here rather than
867 // the static base class create because we need a separate handle
869 if ((hClient
= ::WinCreateWindow( hFrame
// Frame is parent
871 ,NULL
// Window title
873 ,0, 0, 0, 0 // Window position
876 ,FID_CLIENT
// standard client ID
877 ,NULL
// Creation data
878 ,NULL
// Window Pres Params
884 // Send anything to initialize the frame
888 ,(MPARAM
)FCF_TASKLIST
893 // Now size everything. If adding a menu the client will need to be resized.
895 if (!::WinSetWindowPos( hFrame
901 ,SWP_SIZE
| SWP_MOVE
| SWP_ACTIVATE
905 WinQueryWindowPos(hFrame
, &vSwp
);
908 // Set the client window's background, otherwise it is transparent!
910 wxColour vColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
);
912 vRgb
.bRed
= (BYTE
)vColour
.Red();
913 vRgb
.bGreen
= (BYTE
)vColour
.Green();
914 vRgb
.bBlue
= (BYTE
)vColour
.Blue();
915 WinSetPresParam( hClient
920 if (ulCreateFlags
& FCF_TITLEBAR
)
922 hTitlebar
= WinWindowFromID(hFrame
, FID_TITLEBAR
);
923 WinQueryWindowPos(hTitlebar
, &vSwpTitlebar
);
925 if (ulCreateFlags
& FCF_HORZSCROLL
)
927 hHScroll
= WinWindowFromID(hFrame
, FID_HORZSCROLL
);
928 WinQueryWindowPos(hHScroll
, &vSwpHScroll
);
930 if (ulCreateFlags
& FCF_VERTSCROLL
)
932 hVScroll
= WinWindowFromID(hFrame
, FID_VERTSCROLL
);
933 WinQueryWindowPos(hVScroll
, &vSwpVScroll
);
935 if (!::WinSetWindowPos( hClient
938 ,(SV_CYSIZEBORDER
- 1) + vSwpHScroll
.cy
939 ,vSwp
.cx
- ((SV_CXSIZEBORDER
* 2) + vSwpVScroll
.cx
)
940 ,vSwp
.cy
- ((SV_CYSIZEBORDER
* 2) + 1 + vSwpTitlebar
.cy
+ vSwpHScroll
.cy
)
944 WinQueryWindowPos(hClient
, &vSwp
);
945 ::WinShowWindow(hClient
, TRUE
);
947 } // end of wxFrame::OS2Create
950 // Default activation behaviour - set the focus for the first child
953 void wxFrame::OnActivate(
954 wxActivateEvent
& rEvent
957 for (wxWindowList::Node
* pNode
= GetChildren().GetFirst();
959 pNode
= pNode
->GetNext())
961 // FIXME all this is totally bogus - we need to do the same as wxPanel,
962 // but how to do it without duplicating the code?
965 wxWindow
* pChild
= pNode
->GetData();
967 if (!pChild
->IsTopLevel()
969 && !wxDynamicCast(pChild
, wxToolBar
)
970 #endif // wxUSE_TOOLBAR
972 && !wxDynamicCast(pChild
, wxStatusBar
)
973 #endif // wxUSE_STATUSBAR
980 } // end of wxFrame::OnActivate
982 // ----------------------------------------------------------------------------
983 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
984 // from the client area, so the client area is what's really available for the
986 // ----------------------------------------------------------------------------
988 // Checks if there is a toolbar, and returns the first free client position
989 wxPoint
wxFrame::GetClientAreaOrigin() const
991 wxPoint
vPoint(0, 0);
998 GetToolBar()->GetSize( &nWidth
1002 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
1008 // PM is backwards from windows
1009 vPoint
.y
+= nHeight
;
1013 } // end of wxFrame::GetClientAreaOrigin
1015 // ----------------------------------------------------------------------------
1016 // tool/status bar stuff
1017 // ----------------------------------------------------------------------------
1021 wxToolBar
* wxFrame::CreateToolBar(
1024 , const wxString
& rName
1027 if (wxFrameBase::CreateToolBar( lStyle
1034 return m_frameToolBar
;
1035 } // end of wxFrame::CreateToolBar
1037 void wxFrame::PositionToolBar()
1042 hWndClient
= ::WinWindowFromID(GetHwnd(), FID_CLIENT
);
1043 ::WinQueryWindowRect(hWndClient
, &vRect
);
1051 GetStatusBar()->GetClientSize( &nStatusX
1054 // PM is backwards from windows
1055 vRect
.yBottom
+= nStatusY
;
1057 #endif // wxUSE_STATUSBAR
1064 GetToolBar()->GetSize( &nToolbarWidth
1068 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
1070 nToolbarHeight
= vRect
.yBottom
;
1074 nToolbarWidth
= vRect
.xRight
;
1078 // Use the 'real' PM position here
1080 GetToolBar()->SetSize( 0
1084 ,wxSIZE_NO_ADJUSTMENTS
1087 } // end of wxFrame::PositionToolBar
1088 #endif // wxUSE_TOOLBAR
1090 // ----------------------------------------------------------------------------
1091 // frame state (iconized/maximized/...)
1092 // ----------------------------------------------------------------------------
1095 // propagate our state change to all child frames: this allows us to emulate X
1096 // Windows behaviour where child frames float independently of the parent one
1097 // on the desktop, but are iconized/restored with it
1099 void wxFrame::IconizeChildFrames(
1103 for (wxWindowList::Node
* pNode
= GetChildren().GetFirst();
1105 pNode
= pNode
->GetNext() )
1107 wxWindow
* pWin
= pNode
->GetData();
1109 if (pWin
->IsKindOf(CLASSINFO(wxFrame
)) )
1111 ((wxFrame
*)pWin
)->Iconize(bIconize
);
1114 } // end of wxFrame::IconizeChildFrames
1116 // ===========================================================================
1117 // message processing
1118 // ===========================================================================
1120 // ---------------------------------------------------------------------------
1122 // ---------------------------------------------------------------------------
1123 bool wxFrame::OS2TranslateMessage(
1127 if (wxWindow::OS2TranslateMessage(pMsg
))
1130 // try the menu bar accels
1132 wxMenuBar
* pMenuBar
= GetMenuBar();
1137 const wxAcceleratorTable
& rAcceleratorTable
= pMenuBar
->GetAccelTable();
1138 return rAcceleratorTable
.Translate(this, pMsg
);
1139 } // end of wxFrame::OS2TranslateMessage
1141 // ---------------------------------------------------------------------------
1142 // our private (non virtual) message handlers
1143 // ---------------------------------------------------------------------------
1144 bool wxFrame::HandlePaint()
1148 if (::WinQueryUpdateRect(GetHwnd(), &vRect
))
1153 // Icons in PM are the same as "pointers"
1158 hIcon
= (HPOINTER
)::WinSendMsg(GetHwnd(), WM_QUERYICON
, 0L, 0L);
1160 hIcon
= (HPOINTER
)m_hDefaultIcon
;
1163 // Hold a pointer to the dc so long as the OnPaint() message
1164 // is being processed
1167 HPS hPs
= ::WinBeginPaint(GetHwnd(), NULLHANDLE
, &vRect2
);
1170 // Erase background before painting or we get white background
1172 OS2DefWindowProc(WM_ERASEBACKGROUND
, (MPARAM
)hPs
, (MPARAM
)&vRect2
);
1179 hWndClient
= ::WinWindowFromID(GetHwnd(), FID_CLIENT
);
1180 ::WinQueryWindowRect(hWndClient
, &vRect3
);
1182 static const int nIconWidth
= 32;
1183 static const int nIconHeight
= 32;
1184 int nIconX
= (int)((vRect3
.xRight
- nIconWidth
)/2);
1185 int nIconY
= (int)((vRect3
.yBottom
+ nIconHeight
)/2);
1187 ::WinDrawPointer(hPs
, nIconX
, nIconY
, hIcon
, DP_NORMAL
);
1194 return wxWindow::HandlePaint();
1199 // nothing to paint - processed
1203 } // end of wxFrame::HandlePaint
1205 bool wxFrame::HandleSize(
1211 bool bProcessed
= FALSE
;
1217 // Only do it it if we were iconized before, otherwise resizing the
1218 // parent frame has a curious side effect of bringing it under it's
1224 // restore all child frames too
1226 IconizeChildFrames(FALSE
);
1233 m_bIconized
= FALSE
;
1238 // Iconize all child frames too
1240 IconizeChildFrames(TRUE
);
1248 // forward WM_SIZE to status bar control
1250 #if wxUSE_NATIVE_STATUSBAR
1251 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
1253 wxSizeEvent
vEvent( wxSize( nX
1256 ,m_frameStatusBar
->GetId()
1259 vEvent
.SetEventObject(m_frameStatusBar
);
1260 m_frameStatusBar
->OnSize(vEvent
);
1262 #endif // wxUSE_NATIVE_STATUSBAR
1264 PositionStatusBar();
1266 wxSizeEvent
vEvent( wxSize( nX
1272 vEvent
.SetEventObject(this);
1273 bProcessed
= GetEventHandler()->ProcessEvent(vEvent
);
1276 } // end of wxFrame::HandleSize
1278 bool wxFrame::HandleCommand(
1287 // In case it's e.g. a toolbar.
1289 wxWindow
* pWin
= wxFindWinFromHandle(hControl
);
1292 return pWin
->OS2Command( nCmd
1298 // Handle here commands from menus and accelerators
1300 if (nCmd
== 0 || nCmd
== 1)
1302 if (wxCurrentPopupMenu
)
1304 wxMenu
* pPopupMenu
= wxCurrentPopupMenu
;
1306 wxCurrentPopupMenu
= NULL
;
1308 return pPopupMenu
->OS2Command( nCmd
1313 if (ProcessCommand(nId
))
1319 } // end of wxFrame::HandleCommand
1321 bool wxFrame::HandleMenuSelect(
1329 if (nFlags
== 0xFFFF && hMenu
== 0)
1332 // Menu was removed from screen
1336 else if (!(nFlags
& MIS_SUBMENU
) && !(nFlags
& MIS_SEPARATOR
))
1343 // Don't give hints for separators (doesn't make sense) nor for the
1344 // items opening popup menus (they don't have them anyhow)
1348 wxMenuEvent
vEvent(wxEVT_MENU_HIGHLIGHT
, nMenuItem
);
1350 vEvent
.SetEventObject(this);
1351 return GetEventHandler()->ProcessEvent(vEvent
);
1352 } // end of wxFrame::HandleMenuSelect
1354 // ---------------------------------------------------------------------------
1355 // the window proc for wxFrame
1356 // ---------------------------------------------------------------------------
1358 MRESULT
wxFrame::OS2WindowProc(
1365 bool bProcessed
= FALSE
;
1371 // If we can't close, tell the system that we processed the
1372 // message - otherwise it would close us
1374 bProcessed
= !Close();
1383 UnpackCommand( (WXWPARAM
)wParam
1389 bProcessed
= HandleCommand( wId
1402 UnpackMenuSelect( wParam
1408 bProcessed
= HandleMenuSelect( wItem
1416 bProcessed
= HandlePaint();
1419 case CM_QUERYDRAGIMAGE
:
1424 hIcon
= (HPOINTER
)::WinSendMsg(GetHwnd(), WM_QUERYICON
, 0L, 0L);
1426 hIcon
= (HPOINTER
)m_hDefaultIcon
;
1427 mRc
= (MRESULT
)hIcon
;
1428 bProcessed
= mRc
!= 0;
1433 bProcessed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), (WXUINT
)wParam
);
1438 mRc
= wxWindow::OS2WindowProc( uMessage
1443 } // wxFrame::OS2WindowProc