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
[];
56 extern wxMenu
*wxCurrentPopupMenu
;
58 extern void wxAssociateWinWithHandle( HWND hWnd
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
67 EVT_ACTIVATE(wxFrame::OnActivate
)
68 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
71 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxWindow
)
73 // ============================================================================
75 // ============================================================================
77 // ----------------------------------------------------------------------------
78 // static class members
79 // ----------------------------------------------------------------------------
82 #if wxUSE_NATIVE_STATUSBAR
83 bool wxFrame::m_bUseNativeStatusBar
= TRUE
;
85 bool wxFrame::m_bUseNativeStatusBar
= FALSE
;
88 #endif //wxUSE_STATUSBAR
90 // ----------------------------------------------------------------------------
91 // creation/destruction
92 // ----------------------------------------------------------------------------
101 // Data to save/restore when calling ShowFullScreen
103 m_lFsOldWindowStyle
= 0L;
104 m_nFsStatusBarFields
= 0;
105 m_nFsStatusBarHeight
= 0;
106 m_nFsToolBarHeight
= 0;
107 m_bFsIsMaximized
= FALSE
;
108 m_bFsIsShowing
= FALSE
;
110 m_pWinLastFocused
= (wxWindow
*)NULL
;
120 memset(&m_vSwp
, 0, sizeof(SWP
));
121 memset(&m_vSwpClient
, 0, sizeof(SWP
));
122 memset(&m_vSwpTitleBar
, 0, sizeof(SWP
));
123 memset(&m_vSwpMenuBar
, 0, sizeof(SWP
));
124 memset(&m_vSwpHScroll
, 0, sizeof(SWP
));
125 memset(&m_vSwpVScroll
, 0, sizeof(SWP
));
126 memset(&m_vSwpStatusBar
, 0, sizeof(SWP
));
127 memset(&m_vSwpToolBar
, 0, sizeof(SWP
));
128 } // end of wxFrame::Init
130 bool wxFrame::Create(
133 , const wxString
& rsTitle
134 , const wxPoint
& rPos
135 , const wxSize
& rSize
137 , const wxString
& rsName
142 int nWidth
= rSize
.x
;
143 int nHeight
= rSize
.y
;
147 m_windowStyle
= lulStyle
;
148 m_frameMenuBar
= NULL
;
150 m_frameToolBar
= NULL
;
151 #endif //wxUSE_TOOLBAR
154 m_frameStatusBar
= NULL
;
155 #endif //wxUSE_STATUSBAR
157 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
162 m_windowId
= (int)NewControlId();
165 pParent
->AddChild(this);
169 if ((m_windowStyle
& wxFRAME_FLOAT_ON_PARENT
) == 0)
172 bOk
= OS2Create( m_windowId
186 wxTopLevelWindows
.Append(this);
187 wxModelessWindows
.Append(this);
190 } // end of wxFrame::Create
194 m_isBeingDeleted
= TRUE
;
196 wxTopLevelWindows
.DeleteObject(this);
200 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
202 wxTheApp
->SetTopWindow(NULL
);
204 if (wxTheApp
->GetExitOnFrameDelete())
206 ::WinPostMsg(NULL
, WM_QUIT
, 0, 0);
210 wxModelessWindows
.DeleteObject(this);
213 // For some reason, wxWindows can activate another task altogether
214 // when a frame is destroyed after a modal dialog has been invoked.
215 // Try to bring the parent to the top.
217 // MT:Only do this if this frame is currently the active window, else weird
218 // things start to happen.
220 if (wxGetActiveWindow() == this)
222 if (GetParent() && GetParent()->GetHWND())
224 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
234 } // end of wxFrame::~wxFrame
237 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
239 void wxFrame::DoGetClientSize(
245 ::WinQueryWindowRect(GetHwnd(), &vRect
);
248 // No need to use statusbar code as in WIN32 as the FORMATFRAME
249 // window procedure ensures PM knows about the new frame client
250 // size internally. A ::WinQueryWindowRect is all that is needed!
254 *pX
= vRect
.xRight
- vRect
.xLeft
;
256 *pY
= vRect
.yTop
- vRect
.yBottom
;
257 } // end of wxFrame::DoGetClientSize
260 // Set the client size (i.e. leave the calculation of borders etc.
263 void wxFrame::DoSetClientSize(
268 HWND hWnd
= GetHwnd();
272 ::WinQueryWindowRect(GetHwnd(), &vRect
);
273 ::WinQueryWindowRect(GetHwnd(), &vRect2
);
276 // Find the difference between the entire window (title bar and all)
277 // and the client area; add this to the new client size to move the
278 // window. Remember OS/2's backwards y coord system!
280 int nActualWidth
= vRect2
.xRight
- vRect2
.xLeft
- vRect
.xRight
+ nWidth
;
281 int nActualHeight
= vRect2
.yTop
+ vRect2
.yTop
- vRect
.yTop
+ nHeight
;
284 if ( GetStatusBar() )
289 GetStatusBar()->GetClientSize( &nStatusX
292 nActualHeight
+= nStatusY
;
294 #endif // wxUSE_STATUSBAR
296 wxPoint
vPoint(GetClientAreaOrigin());
297 nActualWidth
+= vPoint
.y
;
298 nActualHeight
+= vPoint
.x
;
302 vPointl
.x
= vRect2
.xLeft
;
303 vPointl
.y
= vRect2
.yTop
;
305 ::WinSetWindowPos( hWnd
311 ,SWP_MOVE
| SWP_SIZE
| SWP_SHOW
314 wxSizeEvent
vEvent( wxSize( nWidth
319 vEvent
.SetEventObject(this);
320 GetEventHandler()->ProcessEvent(vEvent
);
321 } // end of wxFrame::DoSetClientSize
323 void wxFrame::DoGetSize(
330 ::WinQueryWindowRect(m_hFrame
, &vRect
);
331 *pWidth
= vRect
.xRight
- vRect
.xLeft
;
332 *pHeight
= vRect
.yTop
- vRect
.yBottom
;
333 } // end of wxFrame::DoGetSize
335 void wxFrame::DoGetPosition(
343 ::WinQueryWindowRect(m_hFrame
, &vRect
);
345 *pX
= vRect
.xRight
- vRect
.xLeft
;
346 *pY
= vRect
.yTop
- vRect
.yBottom
;
347 } // end of wxFrame::DoGetPosition
349 // ----------------------------------------------------------------------------
350 // variations around ::ShowWindow()
351 // ----------------------------------------------------------------------------
353 void wxFrame::DoShowWindow(
357 ::WinShowWindow(m_hFrame
, (BOOL
)bShowCmd
);
358 m_bIconized
= bShowCmd
== SWP_MINIMIZE
;
359 } // end of wxFrame::DoShowWindow
367 DoShowWindow((int)bShow
);
371 wxActivateEvent
vEvent(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
373 ::WinQueryWindowPos(m_hFrame
, &vSwp
);
374 m_bIconized
= vSwp
.fl
& SWP_MINIMIZE
;
375 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0);
376 ::WinEnableWindow(m_hFrame
, TRUE
);
377 vEvent
.SetEventObject(this);
378 GetEventHandler()->ProcessEvent(vEvent
);
383 // Try to highlight the correct window (the parent)
387 HWND hWndParent
= GetHwndOf(GetParent());
389 ::WinQueryWindowPos(hWndParent
, &vSwp
);
390 m_bIconized
= vSwp
.fl
& SWP_MINIMIZE
;
392 ::WinSetWindowPos( hWndParent
398 ,SWP_ZORDER
| SWP_ACTIVATE
| SWP_SHOW
| SWP_MOVE
400 ::WinEnableWindow(hWndParent
, TRUE
);
404 } // end of wxFrame::Show
406 void wxFrame::Iconize(
410 DoShowWindow(bIconize
? SWP_MINIMIZE
: SWP_RESTORE
);
411 } // end of wxFrame::Iconize
413 void wxFrame::Maximize(
416 DoShowWindow(bMaximize
? SWP_MAXIMIZE
: SWP_RESTORE
);
417 } // end of wxFrame::Maximize
419 void wxFrame::Restore()
421 DoShowWindow(SWP_RESTORE
);
422 } // end of wxFrame::Restore
424 bool wxFrame::IsIconized() const
428 ::WinQueryWindowPos(m_hFrame
, &vSwp
);
430 if (vSwp
.fl
& SWP_MINIMIZE
)
431 ((wxFrame
*)this)->m_bIconized
= TRUE
;
433 ((wxFrame
*)this)->m_bIconized
= FALSE
;
435 } // end of wxFrame::IsIconized
438 bool wxFrame::IsMaximized() const
443 ::WinQueryWindowPos(m_hFrame
, &vSwp
);
444 return (vSwp
.fl
& SWP_MAXIMIZE
);
445 } // end of wxFrame::IsMaximized
447 void wxFrame::SetIcon(
451 wxFrameBase::SetIcon(rIcon
);
453 if ((m_icon
.GetHICON()) != NULLHANDLE
)
455 ::WinSendMsg( m_hFrame
457 ,(MPARAM
)((HPOINTER
)m_icon
.GetHICON())
460 ::WinSendMsg( m_hFrame
466 } // end of wxFrame::SetIcon
469 wxStatusBar
* wxFrame::OnCreateStatusBar(
473 , const wxString
& rName
476 wxStatusBar
* pStatusBar
= NULL
;
481 pStatusBar
= wxFrameBase::OnCreateStatusBar( nNumber
490 ::WinSetParent( pStatusBar
->GetHWND()
494 ::WinSetOwner( pStatusBar
->GetHWND()
500 if(::WinIsWindowShowing(m_hFrame
))
501 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0);
504 } // end of wxFrame::OnCreateStatusBar
506 void wxFrame::PositionStatusBar()
513 // Native status bar positions itself
515 if (m_frameStatusBar
)
524 ::WinQueryWindowRect(m_hFrame
, &vRect
);
525 ::WinMapWindowPoints(m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRect
, 2);
527 ::WinCalcFrameRect(m_hFrame
, &vRect
, TRUE
);
528 nWidth
= vRect
.xRight
- vRect
.xLeft
;
530 m_frameStatusBar
->GetSize( &nStatbarWidth
535 // Since we wish the status bar to be directly under the client area,
536 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
538 m_frameStatusBar
->SetSize( vRect
.xLeft
- vFRect
.xLeft
539 ,vRect
.yBottom
- vFRect
.yBottom
543 if (!::WinQueryWindowPos(m_frameStatusBar
->GetHWND(), &vSwp
))
545 vError
= ::WinGetLastError(vHabmain
);
546 sError
= wxPMErrorToStr(vError
);
547 wxLogError("Error setting parent for StautsBar. Error: %s\n", sError
);
551 } // end of wxFrame::PositionStatusBar
552 #endif // wxUSE_STATUSBAR
554 void wxFrame::DetachMenuBar()
558 m_frameMenuBar
->Detach();
559 m_frameMenuBar
= NULL
;
561 } // end of wxFrame::DetachMenuBar
563 void wxFrame::SetMenuBar(
569 HWND hTitlebar
= NULLHANDLE
;
570 HWND hHScroll
= NULLHANDLE
;
571 HWND hVScroll
= NULLHANDLE
;
572 HWND hMenuBar
= NULLHANDLE
;
584 // Actually remove the menu from the frame
586 m_hMenu
= (WXHMENU
)0;
587 InternalSetMenuBar();
589 else // set new non NULL menu bar
591 m_frameMenuBar
= NULL
;
594 // Can set a menubar several times.
595 // TODO: how to prevent a memory leak if you have a currently-unattached
596 // menubar? wxWindows assumes that the frame will delete the menu (otherwise
597 // there are problems for MDI).
599 if (pMenuBar
->GetHMenu())
601 m_hMenu
= pMenuBar
->GetHMenu();
606 m_hMenu
= pMenuBar
->Create();
610 InternalSetMenuBar();
611 m_frameMenuBar
= pMenuBar
;
612 pMenuBar
->Attach(this);
614 } // end of wxFrame::SetMenuBar
616 void wxFrame::InternalSetMenuBar()
621 // Set the parent and owner of the menubar to be the frame
623 if (!::WinSetParent(m_hMenu
, m_hFrame
, FALSE
))
625 vError
= ::WinGetLastError(vHabmain
);
626 sError
= wxPMErrorToStr(vError
);
627 wxLogError("Error setting parent for submenu. Error: %s\n", sError
);
630 if (!::WinSetOwner(m_hMenu
, m_hFrame
))
632 vError
= ::WinGetLastError(vHabmain
);
633 sError
= wxPMErrorToStr(vError
);
634 wxLogError("Error setting parent for submenu. Error: %s\n", sError
);
636 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
637 } // end of wxFrame::InternalSetMenuBar
640 // Responds to colour changes, and passes event on to children
642 void wxFrame::OnSysColourChanged(
643 wxSysColourChangedEvent
& rEvent
646 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
650 if (m_frameStatusBar
)
652 wxSysColourChangedEvent vEvent2
;
654 vEvent2
.SetEventObject(m_frameStatusBar
);
655 m_frameStatusBar
->GetEventHandler()->ProcessEvent(vEvent2
);
657 #endif //wxUSE_STATUSBAR
660 // Propagate the event to the non-top-level children
662 wxWindow::OnSysColourChanged(rEvent
);
663 } // end of wxFrame::OnSysColourChanged
665 // Pass TRUE to show full screen, FALSE to restore.
666 bool wxFrame::ShowFullScreen(
676 m_bFsIsShowing
= TRUE
;
680 wxToolBar
* pTheToolBar
= GetToolBar();
681 #endif //wxUSE_TOOLBAR
684 wxStatusBar
* pTheStatusBar
= GetStatusBar();
685 #endif //wxUSE_STATUSBAR
691 pTheToolBar
->GetSize(&nDummyWidth
, &m_nFsToolBarHeight
);
692 #endif //wxUSE_TOOLBAR
696 pTheStatusBar
->GetSize(&nDummyWidth
, &m_nFsStatusBarHeight
);
697 #endif //wxUSE_STATUSBAR
701 // Zap the toolbar, menubar, and statusbar
703 if ((lStyle
& wxFULLSCREEN_NOTOOLBAR
) && pTheToolBar
)
705 pTheToolBar
->SetSize(-1,0);
706 pTheToolBar
->Show(FALSE
);
708 #endif //wxUSE_TOOLBAR
710 if (lStyle
& wxFULLSCREEN_NOMENUBAR
)
712 ::WinSetParent(m_hMenu
, m_hFrame
, FALSE
);
713 ::WinSetOwner(m_hMenu
, m_hFrame
);
714 ::WinSendMsg((HWND
)m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
719 // Save the number of fields in the statusbar
721 if ((lStyle
& wxFULLSCREEN_NOSTATUSBAR
) && pTheStatusBar
)
723 m_nFsStatusBarFields
= pTheStatusBar
->GetFieldsCount();
724 SetStatusBar((wxStatusBar
*) NULL
);
725 delete pTheStatusBar
;
728 m_nFsStatusBarFields
= 0;
729 #endif //wxUSE_STATUSBAR
732 // Zap the frame borders
736 // Save the 'normal' window style
738 m_lFsOldWindowStyle
= ::WinQueryWindowULong(m_hFrame
, QWL_STYLE
);
741 // Save the old position, width & height, maximize state
743 m_vFsOldSize
= GetRect();
744 m_bFsIsMaximized
= IsMaximized();
747 // Decide which window style flags to turn off
749 LONG lNewStyle
= m_lFsOldWindowStyle
;
752 if (lStyle
& wxFULLSCREEN_NOBORDER
)
753 lOffFlags
|= FCF_BORDER
;
754 if (lStyle
& wxFULLSCREEN_NOCAPTION
)
755 lOffFlags
|= (FCF_TASKLIST
| FCF_SYSMENU
);
757 lNewStyle
&= (~lOffFlags
);
760 // Change our window style to be compatible with full-screen mode
762 ::WinSetWindowULong((HWND
)m_hFrame
, QWL_STYLE
, (ULONG
)lNewStyle
);
765 // Resize to the size of the desktop
771 ::WinQueryWindowRect(HWND_DESKTOP
, &vRect
);
772 nWidth
= vRect
.xRight
- vRect
.xLeft
;
774 // Rmember OS/2 is backwards!
776 nHeight
= vRect
.yTop
- vRect
.yBottom
;
783 // Now flush the window style cache and actually go full-screen
785 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
794 wxSizeEvent
vEvent( wxSize( nWidth
800 GetEventHandler()->ProcessEvent(vEvent
);
808 m_bFsIsShowing
= FALSE
;
811 wxToolBar
* pTheToolBar
= GetToolBar();
814 // Restore the toolbar, menubar, and statusbar
816 if (pTheToolBar
&& (m_lFsStyle
& wxFULLSCREEN_NOTOOLBAR
))
818 pTheToolBar
->SetSize(-1, m_nFsToolBarHeight
);
819 pTheToolBar
->Show(TRUE
);
821 #endif //wxUSE_TOOLBAR
824 if ((m_lFsStyle
& wxFULLSCREEN_NOSTATUSBAR
) && (m_nFsStatusBarFields
> 0))
826 CreateStatusBar(m_nFsStatusBarFields
);
827 // PositionStatusBar();
829 #endif //wxUSE_STATUSBAR
831 if ((m_lFsStyle
& wxFULLSCREEN_NOMENUBAR
) && (m_hMenu
!= 0))
833 ::WinSetParent(m_hMenu
, m_hFrame
, FALSE
);
834 ::WinSetOwner(m_hMenu
, m_hFrame
);
835 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
837 Maximize(m_bFsIsMaximized
);
839 ::WinSetWindowULong( m_hFrame
841 ,(ULONG
)m_lFsOldWindowStyle
843 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
853 } // end of wxFrame::ShowFullScreen
858 bool wxFrame::OS2Create(
861 , const wxChar
* zWclass
863 , const wxChar
* zTitle
871 ULONG ulCreateFlags
= 0L;
872 ULONG ulStyleFlags
= 0L;
873 ULONG ulExtraFlags
= 0L;
874 FRAMECDATA vFrameCtlData
;
875 HWND hParent
= NULLHANDLE
;
876 HWND hTitlebar
= NULLHANDLE
;
877 HWND hHScroll
= NULLHANDLE
;
878 HWND hVScroll
= NULLHANDLE
;
879 HWND hFrame
= NULLHANDLE
;
880 HWND hClient
= NULLHANDLE
;
887 m_hDefaultIcon
= (WXHICON
) (wxSTD_FRAME_ICON
? wxSTD_FRAME_ICON
: wxDEFAULT_FRAME_ICON
);
890 hParent
= GetWinHwnd(pParent
);
892 hParent
= HWND_DESKTOP
;
894 if (ulStyle
== wxDEFAULT_FRAME_STYLE
)
895 ulCreateFlags
= FCF_SIZEBORDER
| FCF_TITLEBAR
| FCF_SYSMENU
|
896 FCF_MINMAX
| FCF_TASKLIST
;
899 if ((ulStyle
& wxCAPTION
) == wxCAPTION
)
900 ulCreateFlags
= FCF_TASKLIST
;
902 ulCreateFlags
= FCF_NOMOVEWITHOWNER
;
904 if ((ulStyle
& wxVSCROLL
) == wxVSCROLL
)
905 ulCreateFlags
|= FCF_VERTSCROLL
;
906 if ((ulStyle
& wxHSCROLL
) == wxHSCROLL
)
907 ulCreateFlags
|= FCF_HORZSCROLL
;
908 if (ulStyle
& wxMINIMIZE_BOX
)
909 ulCreateFlags
|= FCF_MINBUTTON
;
910 if (ulStyle
& wxMAXIMIZE_BOX
)
911 ulCreateFlags
|= FCF_MAXBUTTON
;
912 if (ulStyle
& wxTHICK_FRAME
)
913 ulCreateFlags
|= FCF_DLGBORDER
;
914 if (ulStyle
& wxSYSTEM_MENU
)
915 ulCreateFlags
|= FCF_SYSMENU
;
916 if (ulStyle
& wxCAPTION
)
917 ulCreateFlags
|= FCF_TASKLIST
;
918 if (ulStyle
& wxCLIP_CHILDREN
)
920 // Invalid for frame windows under PM
923 if (ulStyle
& wxTINY_CAPTION_VERT
)
924 ulCreateFlags
|= FCF_TASKLIST
;
925 if (ulStyle
& wxTINY_CAPTION_HORIZ
)
926 ulCreateFlags
|= FCF_TASKLIST
;
928 if ((ulStyle
& wxTHICK_FRAME
) == 0)
929 ulCreateFlags
|= FCF_BORDER
;
930 if (ulStyle
& wxFRAME_TOOL_WINDOW
)
931 ulExtraFlags
= kFrameToolWindow
;
933 if (ulStyle
& wxSTAY_ON_TOP
)
934 ulCreateFlags
|= FCF_SYSMODAL
;
936 if ((ulStyle
& wxMINIMIZE
) || (ulStyle
& wxICONIZE
))
937 ulStyleFlags
|= WS_MINIMIZED
;
938 if (ulStyle
& wxMAXIMIZE
)
939 ulStyleFlags
|= WS_MAXIMIZED
;
942 // Clear the visible flag, we always call show
944 ulStyleFlags
&= (unsigned long)~WS_VISIBLE
;
948 // Set the frame control block
950 vFrameCtlData
.cb
= sizeof(vFrameCtlData
);
951 vFrameCtlData
.flCreateFlags
= ulCreateFlags
;
952 vFrameCtlData
.hmodResources
= 0L;
953 vFrameCtlData
.idResources
= 0;
956 // Create the frame window: We break ranks with other ports now
957 // and instead of calling down into the base wxWindow class' OS2Create
958 // we do all our own stuff here. We will set the needed pieces
959 // of wxWindow manually, here.
962 hFrame
= ::WinCreateStdWindow( hParent
963 ,ulStyleFlags
// frame-window style
964 ,&ulCreateFlags
// window style
965 ,(PSZ
)zWclass
// class name
966 ,(PSZ
)zTitle
// window title
967 ,0L // default client style
968 ,NULLHANDLE
// resource in executable file
970 ,&hClient
// receives client window handle
974 vError
= ::WinGetLastError(vHabmain
);
975 sError
= wxPMErrorToStr(vError
);
976 wxLogError("Error creating frame. Error: %s\n", sError
);
981 // wxWindow class' m_hWnd set here and needed associations
985 wxAssociateWinWithHandle(m_hWnd
, this);
986 wxAssociateWinWithHandle(m_hFrame
, this);
988 m_backgroundColour
.Set(wxString("GREY"));
990 LONG lColor
= (LONG
)m_backgroundColour
.GetPixel();
992 if (!::WinSetPresParam( m_hWnd
998 vError
= ::WinGetLastError(vHabmain
);
999 sError
= wxPMErrorToStr(vError
);
1000 wxLogError("Error creating frame. Error: %s\n", sError
);
1005 // Now need to subclass window. Instead of calling the SubClassWin in wxWindow
1006 // we manually subclass here because we don't want to use the main wxWndProc
1009 m_fnOldWndProc
= (WXFARPROC
) ::WinSubclassWindow(m_hFrame
, (PFNWP
)wxFrameMainWndProc
);
1012 // Now size everything. If adding a menu the client will need to be resized.
1015 if (!::WinSetWindowPos( m_hFrame
1021 ,SWP_SIZE
| SWP_MOVE
| SWP_ACTIVATE
| SWP_ZORDER
1024 vError
= ::WinGetLastError(vHabmain
);
1025 sError
= wxPMErrorToStr(vError
);
1026 wxLogError("Error sizing frame. Error: %s\n", sError
);
1030 // We may have to be smarter here when variable sized toolbars are added!
1032 if (!::WinSetWindowPos( m_hWnd
1038 ,SWP_SIZE
| SWP_MOVE
| SWP_ACTIVATE
| SWP_ZORDER
1041 vError
= ::WinGetLastError(vHabmain
);
1042 sError
= wxPMErrorToStr(vError
);
1043 wxLogError("Error sizing client. Error: %s\n", sError
);
1047 } // end of wxFrame::OS2Create
1050 // Default activation behaviour - set the focus for the first child
1053 void wxFrame::OnActivate(
1054 wxActivateEvent
& rEvent
1057 if ( rEvent
.GetActive() )
1059 // restore focus to the child which was last focused
1060 wxLogTrace(_T("focus"), _T("wxFrame %08x activated."), m_hWnd
);
1062 wxWindow
* pParent
= m_pWinLastFocused
? m_pWinLastFocused
->GetParent()
1069 wxSetFocusToChild( pParent
1073 else // deactivating
1076 // Remember the last focused child if it is our child
1078 m_pWinLastFocused
= FindFocus();
1080 for (wxWindowList::Node
* pNode
= GetChildren().GetFirst();
1082 pNode
= pNode
->GetNext())
1084 // FIXME all this is totally bogus - we need to do the same as wxPanel,
1085 // but how to do it without duplicating the code?
1088 wxWindow
* pChild
= pNode
->GetData();
1090 if (!pChild
->IsTopLevel()
1092 && !wxDynamicCast(pChild
, wxToolBar
)
1093 #endif // wxUSE_TOOLBAR
1095 && !wxDynamicCast(pChild
, wxStatusBar
)
1096 #endif // wxUSE_STATUSBAR
1104 } // end of wxFrame::OnActivate
1106 // ----------------------------------------------------------------------------
1107 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1108 // from the client area, so the client area is what's really available for the
1110 // ----------------------------------------------------------------------------
1112 // Checks if there is a toolbar, and returns the first free client position
1113 wxPoint
wxFrame::GetClientAreaOrigin() const
1115 wxPoint
vPoint(0, 0);
1123 GetToolBar()->GetSize( &nWidth
1127 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
1133 // PM is backwards from windows
1134 vPoint
.y
+= nHeight
;
1137 #endif //wxUSE_TOOLBAR
1139 } // end of wxFrame::GetClientAreaOrigin
1141 // ----------------------------------------------------------------------------
1142 // tool/status bar stuff
1143 // ----------------------------------------------------------------------------
1147 wxToolBar
* wxFrame::CreateToolBar(
1150 , const wxString
& rName
1153 if (wxFrameBase::CreateToolBar( lStyle
1160 return m_frameToolBar
;
1161 } // end of wxFrame::CreateToolBar
1163 void wxFrame::PositionToolBar()
1168 ::WinQueryWindowRect(GetHwnd(), &vRect
);
1176 GetStatusBar()->GetClientSize( &nStatusX
1179 // PM is backwards from windows
1180 vRect
.yBottom
+= nStatusY
;
1182 #endif // wxUSE_STATUSBAR
1184 if ( m_frameToolBar
)
1189 m_frameToolBar
->GetSize( &nToolbarWidth
1193 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
1195 nToolbarHeight
= vRect
.yBottom
;
1199 nToolbarWidth
= vRect
.xRight
;
1203 // Use the 'real' PM position here
1205 GetToolBar()->SetSize( 0
1209 ,wxSIZE_NO_ADJUSTMENTS
1212 } // end of wxFrame::PositionToolBar
1213 #endif // wxUSE_TOOLBAR
1215 // ----------------------------------------------------------------------------
1216 // frame state (iconized/maximized/...)
1217 // ----------------------------------------------------------------------------
1220 // propagate our state change to all child frames: this allows us to emulate X
1221 // Windows behaviour where child frames float independently of the parent one
1222 // on the desktop, but are iconized/restored with it
1224 void wxFrame::IconizeChildFrames(
1228 for (wxWindowList::Node
* pNode
= GetChildren().GetFirst();
1230 pNode
= pNode
->GetNext() )
1232 wxWindow
* pWin
= pNode
->GetData();
1234 if (pWin
->IsKindOf(CLASSINFO(wxFrame
)) )
1236 ((wxFrame
*)pWin
)->Iconize(bIconize
);
1239 } // end of wxFrame::IconizeChildFrames
1241 // ===========================================================================
1242 // message processing
1243 // ===========================================================================
1245 // ---------------------------------------------------------------------------
1247 // ---------------------------------------------------------------------------
1248 bool wxFrame::OS2TranslateMessage(
1253 // try the menu bar accels
1255 wxMenuBar
* pMenuBar
= GetMenuBar();
1261 const wxAcceleratorTable
& rAcceleratorTable
= pMenuBar
->GetAccelTable();
1262 return rAcceleratorTable
.Translate(GetHWND(), pMsg
);
1265 #endif //wxUSE_ACCEL
1266 } // end of wxFrame::OS2TranslateMessage
1268 // ---------------------------------------------------------------------------
1269 // our private (non virtual) message handlers
1270 // ---------------------------------------------------------------------------
1271 bool wxFrame::HandlePaint()
1275 if (::WinQueryUpdateRect(GetHWND(), &vRect
))
1280 // Icons in PM are the same as "pointers"
1285 hIcon
= (HPOINTER
)::WinSendMsg(m_hFrame
, WM_QUERYICON
, 0L, 0L);
1287 hIcon
= (HPOINTER
)m_hDefaultIcon
;
1290 // Hold a pointer to the dc so long as the OnPaint() message
1291 // is being processed
1294 HPS hPs
= ::WinBeginPaint(GetHwnd(), NULLHANDLE
, &vRect2
);
1297 // Erase background before painting or we get white background
1299 OS2DefWindowProc(WM_ERASEBACKGROUND
, (MPARAM
)hPs
, (MPARAM
)&vRect2
);
1306 ::WinQueryWindowRect(GetHwnd(), &vRect3
);
1308 static const int nIconWidth
= 32;
1309 static const int nIconHeight
= 32;
1310 int nIconX
= (int)((vRect3
.xRight
- nIconWidth
)/2);
1311 int nIconY
= (int)((vRect3
.yBottom
+ nIconHeight
)/2);
1313 ::WinDrawPointer(hPs
, nIconX
, nIconY
, hIcon
, DP_NORMAL
);
1320 return(wxWindow::HandlePaint());
1325 // nothing to paint - processed
1329 } // end of wxFrame::HandlePaint
1331 bool wxFrame::HandleSize(
1337 bool bProcessed
= FALSE
;
1343 // Only do it it if we were iconized before, otherwise resizing the
1344 // parent frame has a curious side effect of bringing it under it's
1350 // restore all child frames too
1352 IconizeChildFrames(FALSE
);
1353 (void)SendIconizeEvent(FALSE
);
1360 m_bIconized
= FALSE
;
1365 // Iconize all child frames too
1367 IconizeChildFrames(TRUE
);
1368 (void)SendIconizeEvent();
1376 // forward WM_SIZE to status bar control
1378 #if wxUSE_NATIVE_STATUSBAR
1379 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
1381 wxSizeEvent
vEvent( wxSize( nX
1384 ,m_frameStatusBar
->GetId()
1387 vEvent
.SetEventObject(m_frameStatusBar
);
1388 m_frameStatusBar
->OnSize(vEvent
);
1390 #endif // wxUSE_NATIVE_STATUSBAR
1392 PositionStatusBar();
1395 #endif // wxUSE_TOOLBAR
1397 wxSizeEvent
vEvent( wxSize( nX
1403 vEvent
.SetEventObject(this);
1404 bProcessed
= GetEventHandler()->ProcessEvent(vEvent
);
1407 } // end of wxFrame::HandleSize
1409 bool wxFrame::HandleCommand(
1418 // In case it's e.g. a toolbar.
1420 wxWindow
* pWin
= wxFindWinFromHandle(hControl
);
1423 return pWin
->OS2Command( nCmd
1429 // Handle here commands from menus and accelerators
1431 if (nCmd
== CMDSRC_MENU
|| nCmd
== CMDSRC_ACCELERATOR
)
1433 if (wxCurrentPopupMenu
)
1435 wxMenu
* pPopupMenu
= wxCurrentPopupMenu
;
1437 wxCurrentPopupMenu
= NULL
;
1439 return pPopupMenu
->OS2Command( nCmd
1444 if (ProcessCommand(nId
))
1450 } // end of wxFrame::HandleCommand
1452 bool wxFrame::HandleMenuSelect(
1463 rc
= ::WinSendMsg(hMenu
, MM_QUERYITEM
, MPFROM2SHORT(nItem
, TRUE
), (MPARAM
)&mItem
);
1465 if(rc
&& !(mItem
.afStyle
& (MIS_SUBMENU
| MIS_SEPARATOR
)))
1467 wxMenuEvent
vEvent(wxEVT_MENU_HIGHLIGHT
, nItem
);
1469 vEvent
.SetEventObject(this);
1470 GetEventHandler()->ProcessEvent(vEvent
); // return value would be ignored by PM
1474 } // end of wxFrame::HandleMenuSelect
1476 // ---------------------------------------------------------------------------
1477 // Main Frame window proc
1478 // ---------------------------------------------------------------------------
1479 MRESULT EXPENTRY
wxFrameMainWndProc(
1486 MRESULT rc
= (MRESULT
)0;
1487 bool bProcessed
= FALSE
;
1488 wxFrame
* pWnd
= NULL
;
1490 pWnd
= (wxFrame
*) wxFindWinFromHandle((WXHWND
) hWnd
);
1493 case WM_QUERYFRAMECTLCOUNT
:
1494 if(pWnd
&& pWnd
->m_fnOldWndProc
)
1496 USHORT uItemCount
= SHORT1FROMMR(pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
));
1498 rc
= MRFROMSHORT(uItemCount
);
1502 case WM_FORMATFRAME
:
1503 /////////////////////////////////////////////////////////////////////////////////
1504 // Applications that subclass frame controls may find that the frame is already
1505 // subclassed the number of frame controls is variable.
1506 // The WM_FORMATFRAME and WM_QUERYFRAMECTLCOUNT messages must always be
1507 // subclassed by calling the previous window procedure and modifying its result.
1508 ////////////////////////////////////////////////////////////////////////////////
1518 pSWP
= (PSWP
)PVOIDFROMMP(wParam
);
1519 nItemCount
= SHORT1FROMMR(pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
));
1520 if(pWnd
->m_frameStatusBar
)
1522 ::WinQueryWindowRect(pWnd
->m_frameStatusBar
->GetHWND(), &vRstb
);
1523 pWnd
->m_frameStatusBar
->GetSize(NULL
, &nHeight
);
1524 ::WinQueryWindowRect(pWnd
->m_hFrame
, &vRectl
);
1525 ::WinMapWindowPoints(pWnd
->m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRectl
, 2);
1527 ::WinCalcFrameRect(pWnd
->m_hFrame
, &vRectl
, TRUE
);
1529 vSwpStb
.x
= vRectl
.xLeft
- vRstb
.xLeft
;
1530 vSwpStb
.y
= vRectl
.yBottom
- vRstb
.yBottom
;
1531 vSwpStb
.cx
= vRectl
.xRight
- vRectl
.xLeft
- 1; //?? -1 ??
1532 vSwpStb
.cy
= nHeight
;
1533 vSwpStb
.fl
= SWP_SIZE
|SWP_MOVE
| SWP_SHOW
;
1534 vSwpStb
.hwnd
= pWnd
->m_frameStatusBar
->GetHWND();
1535 vSwpStb
.hwndInsertBehind
= HWND_TOP
;
1537 ::WinQueryWindowRect(pWnd
->m_hFrame
, &vRectl
);
1538 ::WinMapWindowPoints(pWnd
->m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRectl
, 2);
1539 ::WinCalcFrameRect(pWnd
->m_hFrame
, &vRectl
, TRUE
);
1540 ::WinMapWindowPoints(HWND_DESKTOP
, pWnd
->m_hFrame
, (PPOINTL
)&vRectl
, 2);
1541 for(i
= 0; i
< nItemCount
; i
++)
1543 if(pWnd
->m_hWnd
&& pSWP
[i
].hwnd
== pWnd
->m_hWnd
)
1545 pSWP
[i
].x
= vRectl
.xLeft
;
1546 pSWP
[i
].y
= vRectl
.yBottom
+ nHeight
;
1547 pSWP
[i
].cx
= vRectl
.xRight
- vRectl
.xLeft
;
1548 pSWP
[i
].cy
= vRectl
.yTop
- vRectl
.yBottom
- nHeight
;
1549 pSWP
[i
].fl
= SWP_SIZE
| SWP_MOVE
| SWP_SHOW
;
1550 pSWP
[i
].hwndInsertBehind
= HWND_TOP
;
1554 rc
= MRFROMSHORT(nItemCount
);
1559 if(pWnd
&& pWnd
->m_fnOldWndProc
)
1560 rc
= pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
);
1562 rc
= ::WinDefWindowProc(hWnd
, ulMsg
, wParam
, lParam
);
1565 } // end of wxFrameMainWndProc
1567 MRESULT EXPENTRY
wxFrameWndProc(
1575 // Trace all ulMsgs - useful for the debugging
1578 wxFrame
* pWnd
= NULL
;
1580 parentHwnd
= WinQueryWindow(hWnd
,QW_PARENT
);
1581 pWnd
= (wxFrame
*) wxFindWinFromHandle((WXHWND
) hWnd
);
1584 // When we get the first message for the HWND we just created, we associate
1585 // it with wxWindow stored in wxWndHook
1588 MRESULT rc
= (MRESULT
)0;
1589 bool bProcessed
= FALSE
;
1592 // Stop right here if we don't have a valid handle in our wxWindow object.
1594 if (pWnd
&& !pWnd
->GetHWND())
1596 pWnd
->SetHWND((WXHWND
) hWnd
);
1597 rc
= pWnd
->OS2DefWindowProc(ulMsg
, wParam
, lParam
);
1603 rc
= pWnd
->OS2WindowProc(ulMsg
, wParam
, lParam
);
1605 rc
= ::WinDefWindowProc(hWnd
, ulMsg
, wParam
, lParam
);
1608 } // end of wxFrameWndProc
1610 MRESULT
wxFrame::OS2WindowProc(
1617 bool bProcessed
= FALSE
;
1623 // If we can't close, tell the system that we processed the
1624 // message - otherwise it would close us
1626 bProcessed
= !Close();
1630 bProcessed
= HandlePaint();
1631 mRc
= (MRESULT
)FALSE
;
1634 case WM_ERASEBACKGROUND
:
1636 // Returning TRUE to requests PM to paint the window background
1637 // in SYSCLR_WINDOW. We capture this here because the PS returned
1638 // in Frames is the PS for the whole frame, which we can't really
1639 // use at all. If you want to paint a different background, do it
1640 // in an OnPaint using a wxPaintDC.
1642 mRc
= (MRESULT
)(TRUE
);
1651 UnpackCommand( (WXWPARAM
)wParam
1658 bProcessed
= HandleCommand( wId
1671 UnpackMenuSelect( wParam
1677 bProcessed
= HandleMenuSelect( wItem
1681 mRc
= (MRESULT
)TRUE
;
1687 SHORT nScxold
= SHORT1FROMMP(wParam
); // Old horizontal size.
1688 SHORT nScyold
= SHORT2FROMMP(wParam
); // Old vertical size.
1689 SHORT nScxnew
= SHORT1FROMMP(lParam
); // New horizontal size.
1690 SHORT nScynew
= SHORT2FROMMP(lParam
); // New vertical size.
1692 lParam
= MRFROM2SHORT( nScxnew
- 20
1696 bProcessed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), (WXUINT
)wParam
);
1697 mRc
= (MRESULT
)FALSE
;
1700 case CM_QUERYDRAGIMAGE
:
1705 hIcon
= (HPOINTER
)::WinSendMsg(GetHWND(), WM_QUERYICON
, 0L, 0L);
1707 hIcon
= (HPOINTER
)m_hDefaultIcon
;
1708 mRc
= (MRESULT
)hIcon
;
1709 bProcessed
= mRc
!= 0;
1715 mRc
= wxWindow::OS2WindowProc( uMessage
1719 return (MRESULT
)mRc
;
1720 } // wxFrame::OS2WindowProc
1722 void wxFrame::SetClient(WXHWND c_Hwnd
)
1724 // Duh...nothing to do under OS/2
1727 void wxFrame::SetClient(
1731 wxWindow
* pOldClient
= this->GetClient();
1732 bool bClientHasFocus
= pOldClient
&& (pOldClient
== wxWindow::FindFocus());
1734 if(pOldClient
== pWindow
) // nothing to do
1736 if(pWindow
== NULL
) // just need to remove old client
1738 if(pOldClient
== NULL
) // nothing to do
1741 if(bClientHasFocus
)
1744 pOldClient
->Enable( FALSE
);
1745 pOldClient
->Show( FALSE
);
1746 ::WinSetWindowUShort(pOldClient
->GetHWND(), QWS_ID
, (USHORT
)pOldClient
->GetId());
1747 // to avoid OS/2 bug need to update frame
1748 ::WinSendMsg((HWND
)this->GetFrame(), WM_UPDATEFRAME
, (MPARAM
)~0, 0);
1753 // Else need to change client
1758 ::WinEnableWindowUpdate((HWND
)GetHWND(), FALSE
);
1761 pOldClient
->Enable(FALSE
);
1762 pOldClient
->Show(FALSE
);
1763 ::WinSetWindowUShort(pOldClient
->GetHWND(), QWS_ID
, (USHORT
)pOldClient
->GetId());
1765 pWindow
->Reparent(this);
1766 ::WinSetWindowUShort(pWindow
->GetHWND(), QWS_ID
, FID_CLIENT
);
1767 ::WinEnableWindowUpdate((HWND
)GetHWND(), TRUE
);
1769 pWindow
->Show(); // ensure client is showing
1770 if( this->IsShown() )
1773 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0);
1777 wxWindow
* wxFrame::GetClient()
1779 return wxFindWinFromHandle((WXHWND
)::WinWindowFromID(m_hFrame
, FID_CLIENT
));