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"
17 #include "wx/object.h"
18 #include "wx/dynarray.h"
21 #include "wx/string.h"
30 #include "wx/dialog.h"
31 #include "wx/settings.h"
32 #include "wx/dcclient.h"
35 #include "wx/os2/private.h"
38 #include "wx/statusbr.h"
39 #include "wx/generic/statusbr.h"
40 #endif // wxUSE_STATUSBAR
43 #include "wx/toolbar.h"
44 #endif // wxUSE_TOOLBAR
46 #include "wx/menuitem.h"
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 extern wxWindowList wxModelessWindows
;
54 extern wxList WXDLLEXPORT wxPendingDelete
;
55 extern wxChar wxFrameClassName
[];
57 #if wxUSE_MENUS_NATIVE
58 extern wxMenu
*wxCurrentPopupMenu
;
61 extern void wxAssociateWinWithHandle( HWND hWnd
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
70 EVT_ACTIVATE(wxFrame::OnActivate
)
71 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
74 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxWindow
)
76 // ============================================================================
78 // ============================================================================
80 // ----------------------------------------------------------------------------
81 // static class members
82 // ----------------------------------------------------------------------------
85 #if wxUSE_NATIVE_STATUSBAR
86 bool wxFrame::m_bUseNativeStatusBar
= TRUE
;
88 bool wxFrame::m_bUseNativeStatusBar
= FALSE
;
91 #endif //wxUSE_STATUSBAR
93 // ----------------------------------------------------------------------------
94 // creation/destruction
95 // ----------------------------------------------------------------------------
104 // Data to save/restore when calling ShowFullScreen
106 m_lFsOldWindowStyle
= 0L;
107 m_nFsStatusBarFields
= 0;
108 m_nFsStatusBarHeight
= 0;
109 m_nFsToolBarHeight
= 0;
110 m_bFsIsMaximized
= FALSE
;
111 m_bFsIsShowing
= FALSE
;
113 m_pWinLastFocused
= (wxWindow
*)NULL
;
123 memset(&m_vSwp
, 0, sizeof(SWP
));
124 memset(&m_vSwpClient
, 0, sizeof(SWP
));
125 memset(&m_vSwpTitleBar
, 0, sizeof(SWP
));
126 memset(&m_vSwpMenuBar
, 0, sizeof(SWP
));
127 memset(&m_vSwpHScroll
, 0, sizeof(SWP
));
128 memset(&m_vSwpVScroll
, 0, sizeof(SWP
));
129 memset(&m_vSwpStatusBar
, 0, sizeof(SWP
));
130 memset(&m_vSwpToolBar
, 0, sizeof(SWP
));
131 } // end of wxFrame::Init
133 bool wxFrame::Create(
136 , const wxString
& rsTitle
137 , const wxPoint
& rPos
138 , const wxSize
& rSize
140 , const wxString
& rsName
145 int nWidth
= rSize
.x
;
146 int nHeight
= rSize
.y
;
150 m_windowStyle
= lulStyle
;
151 m_frameMenuBar
= NULL
;
153 m_frameToolBar
= NULL
;
154 #endif //wxUSE_TOOLBAR
157 m_frameStatusBar
= NULL
;
158 #endif //wxUSE_STATUSBAR
160 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
165 m_windowId
= (int)NewControlId();
168 pParent
->AddChild(this);
172 if ((m_windowStyle
& wxFRAME_FLOAT_ON_PARENT
) == 0)
175 bOk
= OS2Create( m_windowId
189 wxTopLevelWindows
.Append(this);
190 wxModelessWindows
.Append(this);
193 } // end of wxFrame::Create
197 m_isBeingDeleted
= TRUE
;
199 wxTopLevelWindows
.DeleteObject(this);
203 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
205 wxTheApp
->SetTopWindow(NULL
);
207 if (wxTheApp
->GetExitOnFrameDelete())
209 ::WinPostMsg(NULL
, WM_QUIT
, 0, 0);
213 wxModelessWindows
.DeleteObject(this);
216 // For some reason, wxWindows can activate another task altogether
217 // when a frame is destroyed after a modal dialog has been invoked.
218 // Try to bring the parent to the top.
220 // MT:Only do this if this frame is currently the active window, else weird
221 // things start to happen.
223 if (wxGetActiveWindow() == this)
225 if (GetParent() && GetParent()->GetHWND())
227 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
237 } // end of wxFrame::~wxFrame
240 // IF we have child controls in the Frame's client we need to alter
241 // the y position, because, OS/2 controls are positioned relative to
242 // wxWindows orgin (top left) not the OS/2 origin (bottom left)
243 void wxFrame::AlterChildPos()
246 // OS/2 is the only OS concerned about this
248 wxWindow
* pChild
= NULL
;
249 wxControl
* pCtrl
= NULL
;
253 ::WinQueryWindowRect(GetHwnd(), &vRect
);
254 for (wxWindowList::Node
* pNode
= GetChildren().GetFirst();
256 pNode
= pNode
->GetNext())
258 wxWindow
* pChild
= pNode
->GetData();
260 ::WinQueryWindowPos(pChild
->GetHWND(), &vSwp
);
261 vSwp
.y
+= (vRect
.yTop
- m_vSwpClient
.cy
);
262 if (pChild
->IsKindOf(CLASSINFO(wxControl
)))
264 pCtrl
= wxDynamicCast(pChild
, wxControl
);
266 // Must deal with controls that have margins like ENTRYFIELD. The SWP
267 // struct of such a control will have and origin offset from its intended
268 // position by the width of the margins.
270 vSwp
.y
-= pCtrl
->GetYComp();
271 vSwp
.x
-= pCtrl
->GetXComp();
273 ::WinSetWindowPos( pChild
->GetHWND()
281 ::WinQueryWindowPos(pChild
->GetHWND(), &vSwp
);
284 } // end of wxFrame::AlterChildPos
287 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
289 void wxFrame::DoGetClientSize(
295 ::WinQueryWindowRect(GetHwnd(), &vRect
);
298 // No need to use statusbar code as in WIN32 as the FORMATFRAME
299 // window procedure ensures PM knows about the new frame client
300 // size internally. A ::WinQueryWindowRect is all that is needed!
304 *pX
= vRect
.xRight
- vRect
.xLeft
;
306 *pY
= vRect
.yTop
- vRect
.yBottom
;
307 } // end of wxFrame::DoGetClientSize
310 // Set the client size (i.e. leave the calculation of borders etc.
313 void wxFrame::DoSetClientSize(
318 HWND hWnd
= GetHwnd();
322 ::WinQueryWindowRect(GetHwnd(), &vRect
);
323 ::WinQueryWindowRect(GetHwnd(), &vRect2
);
326 // Find the difference between the entire window (title bar and all)
327 // and the client area; add this to the new client size to move the
328 // window. Remember OS/2's backwards y coord system!
330 int nActualWidth
= vRect2
.xRight
- vRect2
.xLeft
- vRect
.xRight
+ nWidth
;
331 int nActualHeight
= vRect2
.yTop
+ vRect2
.yTop
- vRect
.yTop
+ nHeight
;
334 if ( GetStatusBar() )
339 GetStatusBar()->GetClientSize( &nStatusX
342 nActualHeight
+= nStatusY
;
344 #endif // wxUSE_STATUSBAR
346 wxPoint
vPoint(GetClientAreaOrigin());
347 nActualWidth
+= vPoint
.y
;
348 nActualHeight
+= vPoint
.x
;
352 vPointl
.x
= vRect2
.xLeft
;
353 vPointl
.y
= vRect2
.yTop
;
355 ::WinSetWindowPos( hWnd
361 ,SWP_MOVE
| SWP_SIZE
| SWP_SHOW
364 wxSizeEvent
vEvent( wxSize( nWidth
369 vEvent
.SetEventObject(this);
370 GetEventHandler()->ProcessEvent(vEvent
);
371 } // end of wxFrame::DoSetClientSize
373 void wxFrame::DoGetSize(
380 ::WinQueryWindowRect(m_hFrame
, &vRect
);
381 *pWidth
= vRect
.xRight
- vRect
.xLeft
;
382 *pHeight
= vRect
.yTop
- vRect
.yBottom
;
383 } // end of wxFrame::DoGetSize
385 void wxFrame::DoGetPosition(
393 ::WinQueryWindowRect(m_hFrame
, &vRect
);
395 *pX
= vRect
.xRight
- vRect
.xLeft
;
396 *pY
= vRect
.yTop
- vRect
.yBottom
;
397 } // end of wxFrame::DoGetPosition
399 // ----------------------------------------------------------------------------
400 // variations around ::ShowWindow()
401 // ----------------------------------------------------------------------------
403 void wxFrame::DoShowWindow(
407 ::WinShowWindow(m_hFrame
, (BOOL
)bShowCmd
);
408 m_bIconized
= bShowCmd
== SWP_MINIMIZE
;
409 } // end of wxFrame::DoShowWindow
417 DoShowWindow((int)bShow
);
421 wxActivateEvent
vEvent(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
423 ::WinQueryWindowPos(m_hFrame
, &vSwp
);
424 m_bIconized
= vSwp
.fl
& SWP_MINIMIZE
;
425 ::WinQueryWindowPos(m_hWnd
, &m_vSwpClient
);
426 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0);
427 ::WinEnableWindow(m_hFrame
, TRUE
);
428 vEvent
.SetEventObject(this);
429 GetEventHandler()->ProcessEvent(vEvent
);
434 // Try to highlight the correct window (the parent)
438 HWND hWndParent
= GetHwndOf(GetParent());
440 ::WinQueryWindowPos(hWndParent
, &vSwp
);
441 m_bIconized
= vSwp
.fl
& SWP_MINIMIZE
;
443 ::WinSetWindowPos( hWndParent
449 ,SWP_ZORDER
| SWP_ACTIVATE
| SWP_SHOW
| SWP_MOVE
451 ::WinEnableWindow(hWndParent
, TRUE
);
455 } // end of wxFrame::Show
457 void wxFrame::Iconize(
461 DoShowWindow(bIconize
? SWP_MINIMIZE
: SWP_RESTORE
);
462 } // end of wxFrame::Iconize
464 void wxFrame::Maximize(
467 DoShowWindow(bMaximize
? SWP_MAXIMIZE
: SWP_RESTORE
);
468 } // end of wxFrame::Maximize
470 void wxFrame::Restore()
472 DoShowWindow(SWP_RESTORE
);
473 } // end of wxFrame::Restore
475 bool wxFrame::IsIconized() const
479 ::WinQueryWindowPos(m_hFrame
, &vSwp
);
481 if (vSwp
.fl
& SWP_MINIMIZE
)
482 ((wxFrame
*)this)->m_bIconized
= TRUE
;
484 ((wxFrame
*)this)->m_bIconized
= FALSE
;
486 } // end of wxFrame::IsIconized
489 bool wxFrame::IsMaximized() const
494 ::WinQueryWindowPos(m_hFrame
, &vSwp
);
495 return (vSwp
.fl
& SWP_MAXIMIZE
);
496 } // end of wxFrame::IsMaximized
498 void wxFrame::SetIcon(
502 wxFrameBase::SetIcon(rIcon
);
504 if ((m_icon
.GetHICON()) != NULLHANDLE
)
506 ::WinSendMsg( m_hFrame
508 ,(MPARAM
)((HPOINTER
)m_icon
.GetHICON())
511 ::WinSendMsg( m_hFrame
517 } // end of wxFrame::SetIcon
520 wxStatusBar
* wxFrame::OnCreateStatusBar(
524 , const wxString
& rName
527 wxStatusBar
* pStatusBar
= NULL
;
532 pStatusBar
= wxFrameBase::OnCreateStatusBar( nNumber
541 ::WinSetParent( pStatusBar
->GetHWND()
545 ::WinSetOwner( pStatusBar
->GetHWND()
551 if(::WinIsWindowShowing(m_hFrame
))
552 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0);
555 } // end of wxFrame::OnCreateStatusBar
557 void wxFrame::PositionStatusBar()
564 // Native status bar positions itself
566 if (m_frameStatusBar
)
576 ::WinQueryWindowRect(m_hFrame
, &vRect
);
578 ::WinMapWindowPoints(m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRect
, 2);
580 ::WinCalcFrameRect(m_hFrame
, &vRect
, TRUE
);
581 nWidth
= vRect
.xRight
- vRect
.xLeft
;
582 nY
= nY
- (vRect
.yBottom
- vFRect
.yBottom
);
584 m_frameStatusBar
->GetSize( &nStatbarWidth
588 nY
= nY
- nStatbarHeight
;
590 // Since we wish the status bar to be directly under the client area,
591 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
593 m_frameStatusBar
->SetSize( vRect
.xLeft
- vFRect
.xLeft
598 if (!::WinQueryWindowPos(m_frameStatusBar
->GetHWND(), &vSwp
))
600 vError
= ::WinGetLastError(vHabmain
);
601 sError
= wxPMErrorToStr(vError
);
602 wxLogError("Error setting parent for StautsBar. Error: %s\n", sError
);
606 } // end of wxFrame::PositionStatusBar
607 #endif // wxUSE_STATUSBAR
609 #if wxUSE_MENUS_NATIVE
610 void wxFrame::DetachMenuBar()
614 m_frameMenuBar
->Detach();
615 m_frameMenuBar
= NULL
;
617 } // end of wxFrame::DetachMenuBar
619 void wxFrame::SetMenuBar(
625 HWND hTitlebar
= NULLHANDLE
;
626 HWND hHScroll
= NULLHANDLE
;
627 HWND hVScroll
= NULLHANDLE
;
628 HWND hMenuBar
= NULLHANDLE
;
640 // Actually remove the menu from the frame
642 m_hMenu
= (WXHMENU
)0;
643 InternalSetMenuBar();
645 else // set new non NULL menu bar
647 m_frameMenuBar
= NULL
;
650 // Can set a menubar several times.
651 // TODO: how to prevent a memory leak if you have a currently-unattached
652 // menubar? wxWindows assumes that the frame will delete the menu (otherwise
653 // there are problems for MDI).
655 if (pMenuBar
->GetHMenu())
657 m_hMenu
= pMenuBar
->GetHMenu();
662 m_hMenu
= pMenuBar
->Create();
666 InternalSetMenuBar();
667 m_frameMenuBar
= pMenuBar
;
668 pMenuBar
->Attach((wxFrame
*)this);
670 } // end of wxFrame::SetMenuBar
672 void wxFrame::AttachMenuBar(
676 wxFrameBase::AttachMenuBar(pMenubar
);
678 m_frameMenuBar
= pMenubar
;
683 // Actually remove the menu from the frame
685 m_hMenu
= (WXHMENU
)0;
686 InternalSetMenuBar();
688 else // Set new non NULL menu bar
691 // Can set a menubar several times.
693 if (pMenubar
->GetHMenu())
695 m_hMenu
= pMenubar
->GetHMenu();
699 if (pMenubar
->IsAttached())
702 m_hMenu
= pMenubar
->Create();
707 InternalSetMenuBar();
709 } // end of wxFrame::AttachMenuBar
711 void wxFrame::InternalSetMenuBar()
716 // Set the parent and owner of the menubar to be the frame
718 if (!::WinSetParent(m_hMenu
, m_hFrame
, FALSE
))
720 vError
= ::WinGetLastError(vHabmain
);
721 sError
= wxPMErrorToStr(vError
);
722 wxLogError("Error setting parent for submenu. Error: %s\n", sError
);
725 if (!::WinSetOwner(m_hMenu
, m_hFrame
))
727 vError
= ::WinGetLastError(vHabmain
);
728 sError
= wxPMErrorToStr(vError
);
729 wxLogError("Error setting parent for submenu. Error: %s\n", sError
);
731 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
732 } // end of wxFrame::InternalSetMenuBar
733 #endif // wxUSE_MENUS_NATIVE
736 // Responds to colour changes, and passes event on to children
738 void wxFrame::OnSysColourChanged(
739 wxSysColourChangedEvent
& rEvent
742 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
746 if (m_frameStatusBar
)
748 wxSysColourChangedEvent vEvent2
;
750 vEvent2
.SetEventObject(m_frameStatusBar
);
751 m_frameStatusBar
->GetEventHandler()->ProcessEvent(vEvent2
);
753 #endif //wxUSE_STATUSBAR
756 // Propagate the event to the non-top-level children
758 wxWindow::OnSysColourChanged(rEvent
);
759 } // end of wxFrame::OnSysColourChanged
761 // Pass TRUE to show full screen, FALSE to restore.
762 bool wxFrame::ShowFullScreen(
772 m_bFsIsShowing
= TRUE
;
776 wxToolBar
* pTheToolBar
= GetToolBar();
777 #endif //wxUSE_TOOLBAR
780 wxStatusBar
* pTheStatusBar
= GetStatusBar();
781 #endif //wxUSE_STATUSBAR
787 pTheToolBar
->GetSize(&nDummyWidth
, &m_nFsToolBarHeight
);
788 #endif //wxUSE_TOOLBAR
792 pTheStatusBar
->GetSize(&nDummyWidth
, &m_nFsStatusBarHeight
);
793 #endif //wxUSE_STATUSBAR
797 // Zap the toolbar, menubar, and statusbar
799 if ((lStyle
& wxFULLSCREEN_NOTOOLBAR
) && pTheToolBar
)
801 pTheToolBar
->SetSize(-1,0);
802 pTheToolBar
->Show(FALSE
);
804 #endif //wxUSE_TOOLBAR
806 if (lStyle
& wxFULLSCREEN_NOMENUBAR
)
808 ::WinSetParent(m_hMenu
, m_hFrame
, FALSE
);
809 ::WinSetOwner(m_hMenu
, m_hFrame
);
810 ::WinSendMsg((HWND
)m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
815 // Save the number of fields in the statusbar
817 if ((lStyle
& wxFULLSCREEN_NOSTATUSBAR
) && pTheStatusBar
)
819 m_nFsStatusBarFields
= pTheStatusBar
->GetFieldsCount();
820 SetStatusBar((wxStatusBar
*) NULL
);
821 delete pTheStatusBar
;
824 m_nFsStatusBarFields
= 0;
825 #endif //wxUSE_STATUSBAR
828 // Zap the frame borders
832 // Save the 'normal' window style
834 m_lFsOldWindowStyle
= ::WinQueryWindowULong(m_hFrame
, QWL_STYLE
);
837 // Save the old position, width & height, maximize state
839 m_vFsOldSize
= GetRect();
840 m_bFsIsMaximized
= IsMaximized();
843 // Decide which window style flags to turn off
845 LONG lNewStyle
= m_lFsOldWindowStyle
;
848 if (lStyle
& wxFULLSCREEN_NOBORDER
)
849 lOffFlags
|= FCF_BORDER
;
850 if (lStyle
& wxFULLSCREEN_NOCAPTION
)
851 lOffFlags
|= (FCF_TASKLIST
| FCF_SYSMENU
);
853 lNewStyle
&= (~lOffFlags
);
856 // Change our window style to be compatible with full-screen mode
858 ::WinSetWindowULong((HWND
)m_hFrame
, QWL_STYLE
, (ULONG
)lNewStyle
);
861 // Resize to the size of the desktop
867 ::WinQueryWindowRect(HWND_DESKTOP
, &vRect
);
868 nWidth
= vRect
.xRight
- vRect
.xLeft
;
870 // Rmember OS/2 is backwards!
872 nHeight
= vRect
.yTop
- vRect
.yBottom
;
879 // Now flush the window style cache and actually go full-screen
881 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
890 wxSizeEvent
vEvent( wxSize( nWidth
896 GetEventHandler()->ProcessEvent(vEvent
);
904 m_bFsIsShowing
= FALSE
;
907 wxToolBar
* pTheToolBar
= GetToolBar();
910 // Restore the toolbar, menubar, and statusbar
912 if (pTheToolBar
&& (m_lFsStyle
& wxFULLSCREEN_NOTOOLBAR
))
914 pTheToolBar
->SetSize(-1, m_nFsToolBarHeight
);
915 pTheToolBar
->Show(TRUE
);
917 #endif //wxUSE_TOOLBAR
920 if ((m_lFsStyle
& wxFULLSCREEN_NOSTATUSBAR
) && (m_nFsStatusBarFields
> 0))
922 CreateStatusBar(m_nFsStatusBarFields
);
923 // PositionStatusBar();
925 #endif //wxUSE_STATUSBAR
927 if ((m_lFsStyle
& wxFULLSCREEN_NOMENUBAR
) && (m_hMenu
!= 0))
929 ::WinSetParent(m_hMenu
, m_hFrame
, FALSE
);
930 ::WinSetOwner(m_hMenu
, m_hFrame
);
931 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
933 Maximize(m_bFsIsMaximized
);
935 ::WinSetWindowULong( m_hFrame
937 ,(ULONG
)m_lFsOldWindowStyle
939 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
949 } // end of wxFrame::ShowFullScreen
954 bool wxFrame::OS2Create(
957 , const wxChar
* zWclass
959 , const wxChar
* zTitle
967 ULONG ulCreateFlags
= 0L;
968 ULONG ulStyleFlags
= 0L;
969 ULONG ulExtraFlags
= 0L;
970 FRAMECDATA vFrameCtlData
;
971 HWND hParent
= NULLHANDLE
;
972 HWND hTitlebar
= NULLHANDLE
;
973 HWND hHScroll
= NULLHANDLE
;
974 HWND hVScroll
= NULLHANDLE
;
975 HWND hFrame
= NULLHANDLE
;
976 HWND hClient
= NULLHANDLE
;
983 m_hDefaultIcon
= (WXHICON
) (wxSTD_FRAME_ICON
? wxSTD_FRAME_ICON
: wxDEFAULT_FRAME_ICON
);
986 hParent
= GetWinHwnd(pParent
);
988 hParent
= HWND_DESKTOP
;
990 if (ulStyle
== wxDEFAULT_FRAME_STYLE
)
991 ulCreateFlags
= FCF_SIZEBORDER
| FCF_TITLEBAR
| FCF_SYSMENU
|
992 FCF_MINMAX
| FCF_TASKLIST
;
995 if ((ulStyle
& wxCAPTION
) == wxCAPTION
)
996 ulCreateFlags
= FCF_TASKLIST
;
998 ulCreateFlags
= FCF_NOMOVEWITHOWNER
;
1000 if ((ulStyle
& wxVSCROLL
) == wxVSCROLL
)
1001 ulCreateFlags
|= FCF_VERTSCROLL
;
1002 if ((ulStyle
& wxHSCROLL
) == wxHSCROLL
)
1003 ulCreateFlags
|= FCF_HORZSCROLL
;
1004 if (ulStyle
& wxMINIMIZE_BOX
)
1005 ulCreateFlags
|= FCF_MINBUTTON
;
1006 if (ulStyle
& wxMAXIMIZE_BOX
)
1007 ulCreateFlags
|= FCF_MAXBUTTON
;
1008 if (ulStyle
& wxTHICK_FRAME
)
1009 ulCreateFlags
|= FCF_DLGBORDER
;
1010 if (ulStyle
& wxSYSTEM_MENU
)
1011 ulCreateFlags
|= FCF_SYSMENU
;
1012 if (ulStyle
& wxCAPTION
)
1013 ulCreateFlags
|= FCF_TASKLIST
;
1014 if (ulStyle
& wxCLIP_CHILDREN
)
1016 // Invalid for frame windows under PM
1019 if (ulStyle
& wxTINY_CAPTION_VERT
)
1020 ulCreateFlags
|= FCF_TASKLIST
;
1021 if (ulStyle
& wxTINY_CAPTION_HORIZ
)
1022 ulCreateFlags
|= FCF_TASKLIST
;
1024 if ((ulStyle
& wxTHICK_FRAME
) == 0)
1025 ulCreateFlags
|= FCF_BORDER
;
1026 if (ulStyle
& wxFRAME_TOOL_WINDOW
)
1027 ulExtraFlags
= kFrameToolWindow
;
1029 if (ulStyle
& wxSTAY_ON_TOP
)
1030 ulCreateFlags
|= FCF_SYSMODAL
;
1032 if ((ulStyle
& wxMINIMIZE
) || (ulStyle
& wxICONIZE
))
1033 ulStyleFlags
|= WS_MINIMIZED
;
1034 if (ulStyle
& wxMAXIMIZE
)
1035 ulStyleFlags
|= WS_MAXIMIZED
;
1038 // Clear the visible flag, we always call show
1040 ulStyleFlags
&= (unsigned long)~WS_VISIBLE
;
1041 m_bIconized
= FALSE
;
1044 // Set the frame control block
1046 vFrameCtlData
.cb
= sizeof(vFrameCtlData
);
1047 vFrameCtlData
.flCreateFlags
= ulCreateFlags
;
1048 vFrameCtlData
.hmodResources
= 0L;
1049 vFrameCtlData
.idResources
= 0;
1052 // Create the frame window: We break ranks with other ports now
1053 // and instead of calling down into the base wxWindow class' OS2Create
1054 // we do all our own stuff here. We will set the needed pieces
1055 // of wxWindow manually, here.
1058 hFrame
= ::WinCreateStdWindow( hParent
1059 ,ulStyleFlags
// frame-window style
1060 ,&ulCreateFlags
// window style
1061 ,(PSZ
)zWclass
// class name
1062 ,(PSZ
)zTitle
// window title
1063 ,0L // default client style
1064 ,NULLHANDLE
// resource in executable file
1066 ,&hClient
// receives client window handle
1070 vError
= ::WinGetLastError(vHabmain
);
1071 sError
= wxPMErrorToStr(vError
);
1072 wxLogError("Error creating frame. Error: %s\n", sError
);
1077 // wxWindow class' m_hWnd set here and needed associations
1081 wxAssociateWinWithHandle(m_hWnd
, this);
1082 wxAssociateWinWithHandle(m_hFrame
, this);
1084 m_backgroundColour
.Set(wxString("GREY"));
1086 LONG lColor
= (LONG
)m_backgroundColour
.GetPixel();
1088 if (!::WinSetPresParam( m_hWnd
1094 vError
= ::WinGetLastError(vHabmain
);
1095 sError
= wxPMErrorToStr(vError
);
1096 wxLogError("Error creating frame. Error: %s\n", sError
);
1101 // Now need to subclass window. Instead of calling the SubClassWin in wxWindow
1102 // we manually subclass here because we don't want to use the main wxWndProc
1105 m_fnOldWndProc
= (WXFARPROC
) ::WinSubclassWindow(m_hFrame
, (PFNWP
)wxFrameMainWndProc
);
1108 // Now size everything. If adding a menu the client will need to be resized.
1113 nY
= pParent
->GetSize().y
- (nY
+ nHeight
);
1119 ::WinQueryWindowRect(HWND_DESKTOP
, &vRect
);
1120 nY
= vRect
.yTop
- (nY
+ nHeight
);
1122 if (!::WinSetWindowPos( m_hFrame
1128 ,SWP_SIZE
| SWP_MOVE
| SWP_ACTIVATE
| SWP_ZORDER
1131 vError
= ::WinGetLastError(vHabmain
);
1132 sError
= wxPMErrorToStr(vError
);
1133 wxLogError("Error sizing frame. Error: %s\n", sError
);
1137 } // end of wxFrame::OS2Create
1140 // Default activation behaviour - set the focus for the first child
1143 void wxFrame::OnActivate(
1144 wxActivateEvent
& rEvent
1147 if ( rEvent
.GetActive() )
1149 // restore focus to the child which was last focused
1150 wxLogTrace(_T("focus"), _T("wxFrame %08x activated."), m_hWnd
);
1152 wxWindow
* pParent
= m_pWinLastFocused
? m_pWinLastFocused
->GetParent()
1159 wxSetFocusToChild( pParent
1163 else // deactivating
1166 // Remember the last focused child if it is our child
1168 m_pWinLastFocused
= FindFocus();
1170 for (wxWindowList::Node
* pNode
= GetChildren().GetFirst();
1172 pNode
= pNode
->GetNext())
1174 // FIXME all this is totally bogus - we need to do the same as wxPanel,
1175 // but how to do it without duplicating the code?
1178 wxWindow
* pChild
= pNode
->GetData();
1180 if (!pChild
->IsTopLevel()
1182 && !wxDynamicCast(pChild
, wxToolBar
)
1183 #endif // wxUSE_TOOLBAR
1185 && !wxDynamicCast(pChild
, wxStatusBar
)
1186 #endif // wxUSE_STATUSBAR
1194 } // end of wxFrame::OnActivate
1196 // ----------------------------------------------------------------------------
1197 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1198 // from the client area, so the client area is what's really available for the
1200 // ----------------------------------------------------------------------------
1202 // Checks if there is a toolbar, and returns the first free client position
1203 wxPoint
wxFrame::GetClientAreaOrigin() const
1205 wxPoint
vPoint(0, 0);
1213 GetToolBar()->GetSize( &nWidth
1217 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
1223 // PM is backwards from windows
1224 vPoint
.y
+= nHeight
;
1227 #endif //wxUSE_TOOLBAR
1229 } // end of wxFrame::GetClientAreaOrigin
1231 // ----------------------------------------------------------------------------
1232 // tool/status bar stuff
1233 // ----------------------------------------------------------------------------
1237 wxToolBar
* wxFrame::CreateToolBar(
1240 , const wxString
& rName
1243 if (wxFrameBase::CreateToolBar( lStyle
1250 return m_frameToolBar
;
1251 } // end of wxFrame::CreateToolBar
1253 void wxFrame::PositionToolBar()
1258 ::WinQueryWindowRect(GetHwnd(), &vRect
);
1266 GetStatusBar()->GetClientSize( &nStatusX
1269 // PM is backwards from windows
1270 vRect
.yBottom
+= nStatusY
;
1272 #endif // wxUSE_STATUSBAR
1274 if ( m_frameToolBar
)
1279 m_frameToolBar
->GetSize( &nToolbarWidth
1283 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
1285 nToolbarHeight
= vRect
.yBottom
;
1289 nToolbarWidth
= vRect
.xRight
;
1293 // Use the 'real' PM position here
1295 GetToolBar()->SetSize( 0
1299 ,wxSIZE_NO_ADJUSTMENTS
1302 } // end of wxFrame::PositionToolBar
1303 #endif // wxUSE_TOOLBAR
1305 // ----------------------------------------------------------------------------
1306 // frame state (iconized/maximized/...)
1307 // ----------------------------------------------------------------------------
1310 // propagate our state change to all child frames: this allows us to emulate X
1311 // Windows behaviour where child frames float independently of the parent one
1312 // on the desktop, but are iconized/restored with it
1314 void wxFrame::IconizeChildFrames(
1318 for (wxWindowList::Node
* pNode
= GetChildren().GetFirst();
1320 pNode
= pNode
->GetNext() )
1322 wxWindow
* pWin
= pNode
->GetData();
1324 if (pWin
->IsKindOf(CLASSINFO(wxFrame
)) )
1326 ((wxFrame
*)pWin
)->Iconize(bIconize
);
1329 } // end of wxFrame::IconizeChildFrames
1331 // ===========================================================================
1332 // message processing
1333 // ===========================================================================
1335 // ---------------------------------------------------------------------------
1337 // ---------------------------------------------------------------------------
1338 bool wxFrame::OS2TranslateMessage(
1343 // try the menu bar accels
1345 wxMenuBar
* pMenuBar
= GetMenuBar();
1350 #if wxUSE_ACCEL && wxUSE_MENUS_NATIVE
1351 const wxAcceleratorTable
& rAcceleratorTable
= pMenuBar
->GetAccelTable();
1352 return rAcceleratorTable
.Translate(GetHWND(), pMsg
);
1355 #endif //wxUSE_ACCEL
1356 } // end of wxFrame::OS2TranslateMessage
1358 // ---------------------------------------------------------------------------
1359 // our private (non virtual) message handlers
1360 // ---------------------------------------------------------------------------
1361 bool wxFrame::HandlePaint()
1365 if (::WinQueryUpdateRect(GetHWND(), &vRect
))
1370 // Icons in PM are the same as "pointers"
1375 hIcon
= (HPOINTER
)::WinSendMsg(m_hFrame
, WM_QUERYICON
, 0L, 0L);
1377 hIcon
= (HPOINTER
)m_hDefaultIcon
;
1380 // Hold a pointer to the dc so long as the OnPaint() message
1381 // is being processed
1384 HPS hPs
= ::WinBeginPaint(GetHwnd(), NULLHANDLE
, &vRect2
);
1387 // Erase background before painting or we get white background
1389 OS2DefWindowProc(WM_ERASEBACKGROUND
, (MPARAM
)hPs
, (MPARAM
)&vRect2
);
1396 ::WinQueryWindowRect(GetHwnd(), &vRect3
);
1398 static const int nIconWidth
= 32;
1399 static const int nIconHeight
= 32;
1400 int nIconX
= (int)((vRect3
.xRight
- nIconWidth
)/2);
1401 int nIconY
= (int)((vRect3
.yBottom
+ nIconHeight
)/2);
1403 ::WinDrawPointer(hPs
, nIconX
, nIconY
, hIcon
, DP_NORMAL
);
1410 return(wxWindow::HandlePaint());
1415 // nothing to paint - processed
1419 } // end of wxFrame::HandlePaint
1421 bool wxFrame::HandleSize(
1427 bool bProcessed
= FALSE
;
1433 // Only do it it if we were iconized before, otherwise resizing the
1434 // parent frame has a curious side effect of bringing it under it's
1440 // restore all child frames too
1442 IconizeChildFrames(FALSE
);
1443 (void)SendIconizeEvent(FALSE
);
1450 m_bIconized
= FALSE
;
1455 // Iconize all child frames too
1457 IconizeChildFrames(TRUE
);
1458 (void)SendIconizeEvent();
1466 // forward WM_SIZE to status bar control
1468 #if wxUSE_NATIVE_STATUSBAR
1469 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
1471 wxSizeEvent
vEvent( wxSize( nX
1474 ,m_frameStatusBar
->GetId()
1477 vEvent
.SetEventObject(m_frameStatusBar
);
1478 m_frameStatusBar
->OnSize(vEvent
);
1480 #endif // wxUSE_NATIVE_STATUSBAR
1482 PositionStatusBar();
1485 #endif // wxUSE_TOOLBAR
1487 wxSizeEvent
vEvent( wxSize( nX
1493 vEvent
.SetEventObject(this);
1494 bProcessed
= GetEventHandler()->ProcessEvent(vEvent
);
1498 } // end of wxFrame::HandleSize
1500 bool wxFrame::HandleCommand(
1509 // In case it's e.g. a toolbar.
1511 wxWindow
* pWin
= wxFindWinFromHandle(hControl
);
1514 return pWin
->OS2Command( nCmd
1520 // Handle here commands from menus and accelerators
1522 if (nCmd
== CMDSRC_MENU
|| nCmd
== CMDSRC_ACCELERATOR
)
1524 #if wxUSE_MENUS_NATIVE
1525 if (wxCurrentPopupMenu
)
1527 wxMenu
* pPopupMenu
= wxCurrentPopupMenu
;
1529 wxCurrentPopupMenu
= NULL
;
1531 return pPopupMenu
->OS2Command( nCmd
1538 if (ProcessCommand(nId
))
1544 } // end of wxFrame::HandleCommand
1546 bool wxFrame::HandleMenuSelect(
1557 rc
= ::WinSendMsg(hMenu
, MM_QUERYITEM
, MPFROM2SHORT(nItem
, TRUE
), (MPARAM
)&mItem
);
1559 if(rc
&& !(mItem
.afStyle
& (MIS_SUBMENU
| MIS_SEPARATOR
)))
1561 wxMenuEvent
vEvent(wxEVT_MENU_HIGHLIGHT
, nItem
);
1563 vEvent
.SetEventObject(this);
1564 GetEventHandler()->ProcessEvent(vEvent
); // return value would be ignored by PM
1568 } // end of wxFrame::HandleMenuSelect
1570 // ---------------------------------------------------------------------------
1571 // Main Frame window proc
1572 // ---------------------------------------------------------------------------
1573 MRESULT EXPENTRY
wxFrameMainWndProc(
1580 MRESULT rc
= (MRESULT
)0;
1581 bool bProcessed
= FALSE
;
1582 wxFrame
* pWnd
= NULL
;
1584 pWnd
= (wxFrame
*) wxFindWinFromHandle((WXHWND
) hWnd
);
1587 case WM_QUERYFRAMECTLCOUNT
:
1588 if(pWnd
&& pWnd
->m_fnOldWndProc
)
1590 USHORT uItemCount
= SHORT1FROMMR(pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
));
1592 rc
= MRFROMSHORT(uItemCount
);
1596 case WM_FORMATFRAME
:
1597 /////////////////////////////////////////////////////////////////////////////////
1598 // Applications that subclass frame controls may find that the frame is already
1599 // subclassed the number of frame controls is variable.
1600 // The WM_FORMATFRAME and WM_QUERYFRAMECTLCOUNT messages must always be
1601 // subclassed by calling the previous window procedure and modifying its result.
1602 ////////////////////////////////////////////////////////////////////////////////
1612 pSWP
= (PSWP
)PVOIDFROMMP(wParam
);
1613 nItemCount
= SHORT1FROMMR(pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
));
1614 if(pWnd
->m_frameStatusBar
)
1616 ::WinQueryWindowRect(pWnd
->m_frameStatusBar
->GetHWND(), &vRstb
);
1617 pWnd
->m_frameStatusBar
->GetSize(NULL
, &nHeight
);
1618 ::WinQueryWindowRect(pWnd
->m_hFrame
, &vRectl
);
1619 ::WinMapWindowPoints(pWnd
->m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRectl
, 2);
1621 ::WinCalcFrameRect(pWnd
->m_hFrame
, &vRectl
, TRUE
);
1623 vSwpStb
.x
= vRectl
.xLeft
- vRstb
.xLeft
;
1624 vSwpStb
.y
= vRectl
.yBottom
- vRstb
.yBottom
;
1625 vSwpStb
.cx
= vRectl
.xRight
- vRectl
.xLeft
- 1; //?? -1 ??
1626 vSwpStb
.cy
= nHeight
;
1627 vSwpStb
.fl
= SWP_SIZE
|SWP_MOVE
| SWP_SHOW
;
1628 vSwpStb
.hwnd
= pWnd
->m_frameStatusBar
->GetHWND();
1629 vSwpStb
.hwndInsertBehind
= HWND_TOP
;
1631 ::WinQueryWindowRect(pWnd
->m_hFrame
, &vRectl
);
1632 ::WinMapWindowPoints(pWnd
->m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRectl
, 2);
1633 ::WinCalcFrameRect(pWnd
->m_hFrame
, &vRectl
, TRUE
);
1634 ::WinMapWindowPoints(HWND_DESKTOP
, pWnd
->m_hFrame
, (PPOINTL
)&vRectl
, 2);
1635 for(i
= 0; i
< nItemCount
; i
++)
1637 if(pWnd
->m_hWnd
&& pSWP
[i
].hwnd
== pWnd
->m_hWnd
)
1639 pSWP
[i
].x
= vRectl
.xLeft
;
1640 pSWP
[i
].y
= vRectl
.yBottom
+ nHeight
;
1641 pSWP
[i
].cx
= vRectl
.xRight
- vRectl
.xLeft
;
1642 pSWP
[i
].cy
= vRectl
.yTop
- vRectl
.yBottom
- nHeight
;
1643 pSWP
[i
].fl
= SWP_SIZE
| SWP_MOVE
| SWP_SHOW
;
1644 pSWP
[i
].hwndInsertBehind
= HWND_TOP
;
1648 rc
= MRFROMSHORT(nItemCount
);
1653 if(pWnd
&& pWnd
->m_fnOldWndProc
)
1654 rc
= pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
);
1656 rc
= ::WinDefWindowProc(hWnd
, ulMsg
, wParam
, lParam
);
1659 } // end of wxFrameMainWndProc
1661 MRESULT EXPENTRY
wxFrameWndProc(
1669 // Trace all ulMsgs - useful for the debugging
1672 wxFrame
* pWnd
= NULL
;
1674 parentHwnd
= WinQueryWindow(hWnd
,QW_PARENT
);
1675 pWnd
= (wxFrame
*) wxFindWinFromHandle((WXHWND
) hWnd
);
1678 // When we get the first message for the HWND we just created, we associate
1679 // it with wxWindow stored in wxWndHook
1682 MRESULT rc
= (MRESULT
)0;
1683 bool bProcessed
= FALSE
;
1686 // Stop right here if we don't have a valid handle in our wxWindow object.
1688 if (pWnd
&& !pWnd
->GetHWND())
1690 pWnd
->SetHWND((WXHWND
) hWnd
);
1691 rc
= pWnd
->OS2DefWindowProc(ulMsg
, wParam
, lParam
);
1697 rc
= pWnd
->OS2WindowProc(ulMsg
, wParam
, lParam
);
1699 rc
= ::WinDefWindowProc(hWnd
, ulMsg
, wParam
, lParam
);
1702 } // end of wxFrameWndProc
1704 MRESULT
wxFrame::OS2WindowProc(
1711 bool bProcessed
= FALSE
;
1717 // If we can't close, tell the system that we processed the
1718 // message - otherwise it would close us
1720 bProcessed
= !Close();
1724 bProcessed
= HandlePaint();
1725 mRc
= (MRESULT
)FALSE
;
1728 case WM_ERASEBACKGROUND
:
1730 // Returning TRUE to requests PM to paint the window background
1731 // in SYSCLR_WINDOW. We capture this here because the PS returned
1732 // in Frames is the PS for the whole frame, which we can't really
1733 // use at all. If you want to paint a different background, do it
1734 // in an OnPaint using a wxPaintDC.
1736 mRc
= (MRESULT
)(TRUE
);
1745 UnpackCommand( (WXWPARAM
)wParam
1752 bProcessed
= HandleCommand( wId
1765 UnpackMenuSelect( wParam
1771 bProcessed
= HandleMenuSelect( wItem
1775 mRc
= (MRESULT
)TRUE
;
1781 SHORT nScxold
= SHORT1FROMMP(wParam
); // Old horizontal size.
1782 SHORT nScyold
= SHORT2FROMMP(wParam
); // Old vertical size.
1783 SHORT nScxnew
= SHORT1FROMMP(lParam
); // New horizontal size.
1784 SHORT nScynew
= SHORT2FROMMP(lParam
); // New vertical size.
1786 lParam
= MRFROM2SHORT( nScxnew
- 20
1790 bProcessed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), (WXUINT
)wParam
);
1791 mRc
= (MRESULT
)FALSE
;
1794 case CM_QUERYDRAGIMAGE
:
1799 hIcon
= (HPOINTER
)::WinSendMsg(GetHWND(), WM_QUERYICON
, 0L, 0L);
1801 hIcon
= (HPOINTER
)m_hDefaultIcon
;
1802 mRc
= (MRESULT
)hIcon
;
1803 bProcessed
= mRc
!= 0;
1809 mRc
= wxWindow::OS2WindowProc( uMessage
1813 return (MRESULT
)mRc
;
1814 } // wxFrame::OS2WindowProc
1816 void wxFrame::SetClient(WXHWND c_Hwnd
)
1818 // Duh...nothing to do under OS/2
1821 void wxFrame::SetClient(
1825 wxWindow
* pOldClient
= this->GetClient();
1826 bool bClientHasFocus
= pOldClient
&& (pOldClient
== wxWindow::FindFocus());
1828 if(pOldClient
== pWindow
) // nothing to do
1830 if(pWindow
== NULL
) // just need to remove old client
1832 if(pOldClient
== NULL
) // nothing to do
1835 if(bClientHasFocus
)
1838 pOldClient
->Enable( FALSE
);
1839 pOldClient
->Show( FALSE
);
1840 ::WinSetWindowUShort(pOldClient
->GetHWND(), QWS_ID
, (USHORT
)pOldClient
->GetId());
1841 // to avoid OS/2 bug need to update frame
1842 ::WinSendMsg((HWND
)this->GetFrame(), WM_UPDATEFRAME
, (MPARAM
)~0, 0);
1847 // Else need to change client
1852 ::WinEnableWindowUpdate((HWND
)GetHWND(), FALSE
);
1855 pOldClient
->Enable(FALSE
);
1856 pOldClient
->Show(FALSE
);
1857 ::WinSetWindowUShort(pOldClient
->GetHWND(), QWS_ID
, (USHORT
)pOldClient
->GetId());
1859 pWindow
->Reparent(this);
1860 ::WinSetWindowUShort(pWindow
->GetHWND(), QWS_ID
, FID_CLIENT
);
1861 ::WinEnableWindowUpdate((HWND
)GetHWND(), TRUE
);
1863 pWindow
->Show(); // ensure client is showing
1864 if( this->IsShown() )
1867 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0);
1871 wxWindow
* wxFrame::GetClient()
1873 return wxFindWinFromHandle((WXHWND
)::WinWindowFromID(m_hFrame
, FID_CLIENT
));