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(wxFrameOS2
, wxFrameBase
)
67 EVT_ACTIVATE(wxFrameOS2::OnActivate
)
68 EVT_SYS_COLOUR_CHANGED(wxFrameOS2::OnSysColourChanged
)
71 IMPLEMENT_DYNAMIC_CLASS(wxFrameOS2
, wxWindow
)
73 #ifndef __WXUNIVERSAL__
74 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxFrameMSW
)
77 // ============================================================================
79 // ============================================================================
81 // ----------------------------------------------------------------------------
82 // static class members
83 // ----------------------------------------------------------------------------
86 #if wxUSE_NATIVE_STATUSBAR
87 bool wxFrameOS2::m_bUseNativeStatusBar
= TRUE
;
89 bool wxFrameOS2::m_bUseNativeStatusBar
= FALSE
;
92 #endif //wxUSE_STATUSBAR
94 // ----------------------------------------------------------------------------
95 // creation/destruction
96 // ----------------------------------------------------------------------------
98 void wxFrameOS2::Init()
105 // Data to save/restore when calling ShowFullScreen
107 m_lFsOldWindowStyle
= 0L;
108 m_nFsStatusBarFields
= 0;
109 m_nFsStatusBarHeight
= 0;
110 m_nFsToolBarHeight
= 0;
111 m_bFsIsMaximized
= FALSE
;
112 m_bFsIsShowing
= FALSE
;
114 m_pWinLastFocused
= (wxWindow
*)NULL
;
124 memset(&m_vSwp
, 0, sizeof(SWP
));
125 memset(&m_vSwpClient
, 0, sizeof(SWP
));
126 memset(&m_vSwpTitleBar
, 0, sizeof(SWP
));
127 memset(&m_vSwpMenuBar
, 0, sizeof(SWP
));
128 memset(&m_vSwpHScroll
, 0, sizeof(SWP
));
129 memset(&m_vSwpVScroll
, 0, sizeof(SWP
));
130 memset(&m_vSwpStatusBar
, 0, sizeof(SWP
));
131 memset(&m_vSwpToolBar
, 0, sizeof(SWP
));
132 } // end of wxFrameOS2::Init
134 bool wxFrameOS2::Create(
137 , const wxString
& rsTitle
138 , const wxPoint
& rPos
139 , const wxSize
& rSize
141 , const wxString
& rsName
146 int nWidth
= rSize
.x
;
147 int nHeight
= rSize
.y
;
151 m_windowStyle
= lulStyle
;
152 m_frameMenuBar
= NULL
;
154 m_frameToolBar
= NULL
;
155 #endif //wxUSE_TOOLBAR
158 m_frameStatusBar
= NULL
;
159 #endif //wxUSE_STATUSBAR
161 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
166 m_windowId
= (int)NewControlId();
169 pParent
->AddChild(this);
173 if ((m_windowStyle
& wxFRAME_FLOAT_ON_PARENT
) == 0)
176 bOk
= OS2Create( m_windowId
190 wxTopLevelWindows
.Append(this);
191 wxModelessWindows
.Append(this);
194 } // end of wxFrameOS2::Create
196 wxFrameOS2::~wxFrameOS2()
198 m_isBeingDeleted
= TRUE
;
200 wxTopLevelWindows
.DeleteObject(this);
204 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
206 wxTheApp
->SetTopWindow(NULL
);
208 if (wxTheApp
->GetExitOnFrameDelete())
210 ::WinPostMsg(NULL
, WM_QUIT
, 0, 0);
214 wxModelessWindows
.DeleteObject(this);
217 // For some reason, wxWindows can activate another task altogether
218 // when a frame is destroyed after a modal dialog has been invoked.
219 // Try to bring the parent to the top.
221 // MT:Only do this if this frame is currently the active window, else weird
222 // things start to happen.
224 if (wxGetActiveWindow() == this)
226 if (GetParent() && GetParent()->GetHWND())
228 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
238 } // end of wxFrameOS2::~wxFrame
241 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
243 void wxFrameOS2::DoGetClientSize(
249 ::WinQueryWindowRect(GetHwnd(), &vRect
);
252 // No need to use statusbar code as in WIN32 as the FORMATFRAME
253 // window procedure ensures PM knows about the new frame client
254 // size internally. A ::WinQueryWindowRect is all that is needed!
258 *pX
= vRect
.xRight
- vRect
.xLeft
;
260 *pY
= vRect
.yTop
- vRect
.yBottom
;
261 } // end of wxFrameOS2::DoGetClientSize
264 // Set the client size (i.e. leave the calculation of borders etc.
267 void wxFrameOS2::DoSetClientSize(
272 HWND hWnd
= GetHwnd();
276 ::WinQueryWindowRect(GetHwnd(), &vRect
);
277 ::WinQueryWindowRect(GetHwnd(), &vRect2
);
280 // Find the difference between the entire window (title bar and all)
281 // and the client area; add this to the new client size to move the
282 // window. Remember OS/2's backwards y coord system!
284 int nActualWidth
= vRect2
.xRight
- vRect2
.xLeft
- vRect
.xRight
+ nWidth
;
285 int nActualHeight
= vRect2
.yTop
+ vRect2
.yTop
- vRect
.yTop
+ nHeight
;
288 if ( GetStatusBar() )
293 GetStatusBar()->GetClientSize( &nStatusX
296 nActualHeight
+= nStatusY
;
298 #endif // wxUSE_STATUSBAR
300 wxPoint
vPoint(GetClientAreaOrigin());
301 nActualWidth
+= vPoint
.y
;
302 nActualHeight
+= vPoint
.x
;
306 vPointl
.x
= vRect2
.xLeft
;
307 vPointl
.y
= vRect2
.yTop
;
309 ::WinSetWindowPos( hWnd
315 ,SWP_MOVE
| SWP_SIZE
| SWP_SHOW
318 wxSizeEvent
vEvent( wxSize( nWidth
323 vEvent
.SetEventObject(this);
324 GetEventHandler()->ProcessEvent(vEvent
);
325 } // end of wxFrameOS2::DoSetClientSize
327 void wxFrameOS2::DoGetSize(
334 ::WinQueryWindowRect(m_hFrame
, &vRect
);
335 *pWidth
= vRect
.xRight
- vRect
.xLeft
;
336 *pHeight
= vRect
.yTop
- vRect
.yBottom
;
337 } // end of wxFrameOS2::DoGetSize
339 void wxFrameOS2::DoGetPosition(
347 ::WinQueryWindowRect(m_hFrame
, &vRect
);
349 *pX
= vRect
.xRight
- vRect
.xLeft
;
350 *pY
= vRect
.yTop
- vRect
.yBottom
;
351 } // end of wxFrameOS2::DoGetPosition
353 // ----------------------------------------------------------------------------
354 // variations around ::ShowWindow()
355 // ----------------------------------------------------------------------------
357 void wxFrameOS2::DoShowWindow(
361 ::WinShowWindow(m_hFrame
, (BOOL
)bShowCmd
);
362 m_bIconized
= bShowCmd
== SWP_MINIMIZE
;
363 } // end of wxFrameOS2::DoShowWindow
365 bool wxFrameOS2::Show(
371 DoShowWindow((int)bShow
);
375 wxActivateEvent
vEvent(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
377 ::WinQueryWindowPos(m_hFrame
, &vSwp
);
378 m_bIconized
= vSwp
.fl
& SWP_MINIMIZE
;
379 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0);
380 ::WinEnableWindow(m_hFrame
, TRUE
);
381 vEvent
.SetEventObject(this);
382 GetEventHandler()->ProcessEvent(vEvent
);
387 // Try to highlight the correct window (the parent)
391 HWND hWndParent
= GetHwndOf(GetParent());
393 ::WinQueryWindowPos(hWndParent
, &vSwp
);
394 m_bIconized
= vSwp
.fl
& SWP_MINIMIZE
;
396 ::WinSetWindowPos( hWndParent
402 ,SWP_ZORDER
| SWP_ACTIVATE
| SWP_SHOW
| SWP_MOVE
404 ::WinEnableWindow(hWndParent
, TRUE
);
408 } // end of wxFrameOS2::Show
410 void wxFrameOS2::Iconize(
414 DoShowWindow(bIconize
? SWP_MINIMIZE
: SWP_RESTORE
);
415 } // end of wxFrameOS2::Iconize
417 void wxFrameOS2::Maximize(
420 DoShowWindow(bMaximize
? SWP_MAXIMIZE
: SWP_RESTORE
);
421 } // end of wxFrameOS2::Maximize
423 void wxFrameOS2::Restore()
425 DoShowWindow(SWP_RESTORE
);
426 } // end of wxFrameOS2::Restore
428 bool wxFrameOS2::IsIconized() const
432 ::WinQueryWindowPos(m_hFrame
, &vSwp
);
434 if (vSwp
.fl
& SWP_MINIMIZE
)
435 ((wxFrame
*)this)->m_bIconized
= TRUE
;
437 ((wxFrame
*)this)->m_bIconized
= FALSE
;
439 } // end of wxFrameOS2::IsIconized
442 bool wxFrameOS2::IsMaximized() const
447 ::WinQueryWindowPos(m_hFrame
, &vSwp
);
448 return (vSwp
.fl
& SWP_MAXIMIZE
);
449 } // end of wxFrameOS2::IsMaximized
451 void wxFrameOS2::SetIcon(
455 wxFrameBase::SetIcon(rIcon
);
457 if ((m_icon
.GetHICON()) != NULLHANDLE
)
459 ::WinSendMsg( m_hFrame
461 ,(MPARAM
)((HPOINTER
)m_icon
.GetHICON())
464 ::WinSendMsg( m_hFrame
470 } // end of wxFrameOS2::SetIcon
473 wxStatusBar
* wxFrameOS2::OnCreateStatusBar(
477 , const wxString
& rName
480 wxStatusBar
* pStatusBar
= NULL
;
485 pStatusBar
= wxFrameBase::OnCreateStatusBar( nNumber
494 ::WinSetParent( pStatusBar
->GetHWND()
498 ::WinSetOwner( pStatusBar
->GetHWND()
504 if(::WinIsWindowShowing(m_hFrame
))
505 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0);
508 } // end of wxFrameOS2::OnCreateStatusBar
510 void wxFrameOS2::PositionStatusBar()
517 // Native status bar positions itself
519 if (m_frameStatusBar
)
528 ::WinQueryWindowRect(m_hFrame
, &vRect
);
529 ::WinMapWindowPoints(m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRect
, 2);
531 ::WinCalcFrameRect(m_hFrame
, &vRect
, TRUE
);
532 nWidth
= vRect
.xRight
- vRect
.xLeft
;
534 m_frameStatusBar
->GetSize( &nStatbarWidth
539 // Since we wish the status bar to be directly under the client area,
540 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
542 m_frameStatusBar
->SetSize( vRect
.xLeft
- vFRect
.xLeft
543 ,vRect
.yBottom
- vFRect
.yBottom
547 if (!::WinQueryWindowPos(m_frameStatusBar
->GetHWND(), &vSwp
))
549 vError
= ::WinGetLastError(vHabmain
);
550 sError
= wxPMErrorToStr(vError
);
551 wxLogError("Error setting parent for StautsBar. Error: %s\n", sError
);
555 } // end of wxFrameOS2::PositionStatusBar
556 #endif // wxUSE_STATUSBAR
558 void wxFrameOS2::DetachMenuBar()
562 m_frameMenuBar
->Detach();
563 m_frameMenuBar
= NULL
;
565 } // end of wxFrameOS2::DetachMenuBar
567 void wxFrameOS2::SetMenuBar(
573 HWND hTitlebar
= NULLHANDLE
;
574 HWND hHScroll
= NULLHANDLE
;
575 HWND hVScroll
= NULLHANDLE
;
576 HWND hMenuBar
= NULLHANDLE
;
588 // Actually remove the menu from the frame
590 m_hMenu
= (WXHMENU
)0;
591 InternalSetMenuBar();
593 else // set new non NULL menu bar
595 m_frameMenuBar
= NULL
;
598 // Can set a menubar several times.
599 // TODO: how to prevent a memory leak if you have a currently-unattached
600 // menubar? wxWindows assumes that the frame will delete the menu (otherwise
601 // there are problems for MDI).
603 if (pMenuBar
->GetHMenu())
605 m_hMenu
= pMenuBar
->GetHMenu();
610 m_hMenu
= pMenuBar
->Create();
614 InternalSetMenuBar();
615 m_frameMenuBar
= pMenuBar
;
616 pMenuBar
->Attach((wxFrame
*)this);
618 } // end of wxFrameOS2::SetMenuBar
620 void wxFrameOS2::InternalSetMenuBar()
625 // Set the parent and owner of the menubar to be the frame
627 if (!::WinSetParent(m_hMenu
, m_hFrame
, FALSE
))
629 vError
= ::WinGetLastError(vHabmain
);
630 sError
= wxPMErrorToStr(vError
);
631 wxLogError("Error setting parent for submenu. Error: %s\n", sError
);
634 if (!::WinSetOwner(m_hMenu
, m_hFrame
))
636 vError
= ::WinGetLastError(vHabmain
);
637 sError
= wxPMErrorToStr(vError
);
638 wxLogError("Error setting parent for submenu. Error: %s\n", sError
);
640 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
641 } // end of wxFrameOS2::InternalSetMenuBar
644 // Responds to colour changes, and passes event on to children
646 void wxFrameOS2::OnSysColourChanged(
647 wxSysColourChangedEvent
& rEvent
650 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
654 if (m_frameStatusBar
)
656 wxSysColourChangedEvent vEvent2
;
658 vEvent2
.SetEventObject(m_frameStatusBar
);
659 m_frameStatusBar
->GetEventHandler()->ProcessEvent(vEvent2
);
661 #endif //wxUSE_STATUSBAR
664 // Propagate the event to the non-top-level children
666 wxWindow::OnSysColourChanged(rEvent
);
667 } // end of wxFrameOS2::OnSysColourChanged
669 // Pass TRUE to show full screen, FALSE to restore.
670 bool wxFrameOS2::ShowFullScreen(
680 m_bFsIsShowing
= TRUE
;
684 wxToolBar
* pTheToolBar
= GetToolBar();
685 #endif //wxUSE_TOOLBAR
688 wxStatusBar
* pTheStatusBar
= GetStatusBar();
689 #endif //wxUSE_STATUSBAR
695 pTheToolBar
->GetSize(&nDummyWidth
, &m_nFsToolBarHeight
);
696 #endif //wxUSE_TOOLBAR
700 pTheStatusBar
->GetSize(&nDummyWidth
, &m_nFsStatusBarHeight
);
701 #endif //wxUSE_STATUSBAR
705 // Zap the toolbar, menubar, and statusbar
707 if ((lStyle
& wxFULLSCREEN_NOTOOLBAR
) && pTheToolBar
)
709 pTheToolBar
->SetSize(-1,0);
710 pTheToolBar
->Show(FALSE
);
712 #endif //wxUSE_TOOLBAR
714 if (lStyle
& wxFULLSCREEN_NOMENUBAR
)
716 ::WinSetParent(m_hMenu
, m_hFrame
, FALSE
);
717 ::WinSetOwner(m_hMenu
, m_hFrame
);
718 ::WinSendMsg((HWND
)m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
723 // Save the number of fields in the statusbar
725 if ((lStyle
& wxFULLSCREEN_NOSTATUSBAR
) && pTheStatusBar
)
727 m_nFsStatusBarFields
= pTheStatusBar
->GetFieldsCount();
728 SetStatusBar((wxStatusBar
*) NULL
);
729 delete pTheStatusBar
;
732 m_nFsStatusBarFields
= 0;
733 #endif //wxUSE_STATUSBAR
736 // Zap the frame borders
740 // Save the 'normal' window style
742 m_lFsOldWindowStyle
= ::WinQueryWindowULong(m_hFrame
, QWL_STYLE
);
745 // Save the old position, width & height, maximize state
747 m_vFsOldSize
= GetRect();
748 m_bFsIsMaximized
= IsMaximized();
751 // Decide which window style flags to turn off
753 LONG lNewStyle
= m_lFsOldWindowStyle
;
756 if (lStyle
& wxFULLSCREEN_NOBORDER
)
757 lOffFlags
|= FCF_BORDER
;
758 if (lStyle
& wxFULLSCREEN_NOCAPTION
)
759 lOffFlags
|= (FCF_TASKLIST
| FCF_SYSMENU
);
761 lNewStyle
&= (~lOffFlags
);
764 // Change our window style to be compatible with full-screen mode
766 ::WinSetWindowULong((HWND
)m_hFrame
, QWL_STYLE
, (ULONG
)lNewStyle
);
769 // Resize to the size of the desktop
775 ::WinQueryWindowRect(HWND_DESKTOP
, &vRect
);
776 nWidth
= vRect
.xRight
- vRect
.xLeft
;
778 // Rmember OS/2 is backwards!
780 nHeight
= vRect
.yTop
- vRect
.yBottom
;
787 // Now flush the window style cache and actually go full-screen
789 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
798 wxSizeEvent
vEvent( wxSize( nWidth
804 GetEventHandler()->ProcessEvent(vEvent
);
812 m_bFsIsShowing
= FALSE
;
815 wxToolBar
* pTheToolBar
= GetToolBar();
818 // Restore the toolbar, menubar, and statusbar
820 if (pTheToolBar
&& (m_lFsStyle
& wxFULLSCREEN_NOTOOLBAR
))
822 pTheToolBar
->SetSize(-1, m_nFsToolBarHeight
);
823 pTheToolBar
->Show(TRUE
);
825 #endif //wxUSE_TOOLBAR
828 if ((m_lFsStyle
& wxFULLSCREEN_NOSTATUSBAR
) && (m_nFsStatusBarFields
> 0))
830 CreateStatusBar(m_nFsStatusBarFields
);
831 // PositionStatusBar();
833 #endif //wxUSE_STATUSBAR
835 if ((m_lFsStyle
& wxFULLSCREEN_NOMENUBAR
) && (m_hMenu
!= 0))
837 ::WinSetParent(m_hMenu
, m_hFrame
, FALSE
);
838 ::WinSetOwner(m_hMenu
, m_hFrame
);
839 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
841 Maximize(m_bFsIsMaximized
);
843 ::WinSetWindowULong( m_hFrame
845 ,(ULONG
)m_lFsOldWindowStyle
847 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
857 } // end of wxFrameOS2::ShowFullScreen
862 bool wxFrameOS2::OS2Create(
865 , const wxChar
* zWclass
867 , const wxChar
* zTitle
875 ULONG ulCreateFlags
= 0L;
876 ULONG ulStyleFlags
= 0L;
877 ULONG ulExtraFlags
= 0L;
878 FRAMECDATA vFrameCtlData
;
879 HWND hParent
= NULLHANDLE
;
880 HWND hTitlebar
= NULLHANDLE
;
881 HWND hHScroll
= NULLHANDLE
;
882 HWND hVScroll
= NULLHANDLE
;
883 HWND hFrame
= NULLHANDLE
;
884 HWND hClient
= NULLHANDLE
;
891 m_hDefaultIcon
= (WXHICON
) (wxSTD_FRAME_ICON
? wxSTD_FRAME_ICON
: wxDEFAULT_FRAME_ICON
);
894 hParent
= GetWinHwnd(pParent
);
896 hParent
= HWND_DESKTOP
;
898 if (ulStyle
== wxDEFAULT_FRAME_STYLE
)
899 ulCreateFlags
= FCF_SIZEBORDER
| FCF_TITLEBAR
| FCF_SYSMENU
|
900 FCF_MINMAX
| FCF_TASKLIST
;
903 if ((ulStyle
& wxCAPTION
) == wxCAPTION
)
904 ulCreateFlags
= FCF_TASKLIST
;
906 ulCreateFlags
= FCF_NOMOVEWITHOWNER
;
908 if ((ulStyle
& wxVSCROLL
) == wxVSCROLL
)
909 ulCreateFlags
|= FCF_VERTSCROLL
;
910 if ((ulStyle
& wxHSCROLL
) == wxHSCROLL
)
911 ulCreateFlags
|= FCF_HORZSCROLL
;
912 if (ulStyle
& wxMINIMIZE_BOX
)
913 ulCreateFlags
|= FCF_MINBUTTON
;
914 if (ulStyle
& wxMAXIMIZE_BOX
)
915 ulCreateFlags
|= FCF_MAXBUTTON
;
916 if (ulStyle
& wxTHICK_FRAME
)
917 ulCreateFlags
|= FCF_DLGBORDER
;
918 if (ulStyle
& wxSYSTEM_MENU
)
919 ulCreateFlags
|= FCF_SYSMENU
;
920 if (ulStyle
& wxCAPTION
)
921 ulCreateFlags
|= FCF_TASKLIST
;
922 if (ulStyle
& wxCLIP_CHILDREN
)
924 // Invalid for frame windows under PM
927 if (ulStyle
& wxTINY_CAPTION_VERT
)
928 ulCreateFlags
|= FCF_TASKLIST
;
929 if (ulStyle
& wxTINY_CAPTION_HORIZ
)
930 ulCreateFlags
|= FCF_TASKLIST
;
932 if ((ulStyle
& wxTHICK_FRAME
) == 0)
933 ulCreateFlags
|= FCF_BORDER
;
934 if (ulStyle
& wxFRAME_TOOL_WINDOW
)
935 ulExtraFlags
= kFrameToolWindow
;
937 if (ulStyle
& wxSTAY_ON_TOP
)
938 ulCreateFlags
|= FCF_SYSMODAL
;
940 if ((ulStyle
& wxMINIMIZE
) || (ulStyle
& wxICONIZE
))
941 ulStyleFlags
|= WS_MINIMIZED
;
942 if (ulStyle
& wxMAXIMIZE
)
943 ulStyleFlags
|= WS_MAXIMIZED
;
946 // Clear the visible flag, we always call show
948 ulStyleFlags
&= (unsigned long)~WS_VISIBLE
;
952 // Set the frame control block
954 vFrameCtlData
.cb
= sizeof(vFrameCtlData
);
955 vFrameCtlData
.flCreateFlags
= ulCreateFlags
;
956 vFrameCtlData
.hmodResources
= 0L;
957 vFrameCtlData
.idResources
= 0;
960 // Create the frame window: We break ranks with other ports now
961 // and instead of calling down into the base wxWindow class' OS2Create
962 // we do all our own stuff here. We will set the needed pieces
963 // of wxWindow manually, here.
966 hFrame
= ::WinCreateStdWindow( hParent
967 ,ulStyleFlags
// frame-window style
968 ,&ulCreateFlags
// window style
969 ,(PSZ
)zWclass
// class name
970 ,(PSZ
)zTitle
// window title
971 ,0L // default client style
972 ,NULLHANDLE
// resource in executable file
974 ,&hClient
// receives client window handle
978 vError
= ::WinGetLastError(vHabmain
);
979 sError
= wxPMErrorToStr(vError
);
980 wxLogError("Error creating frame. Error: %s\n", sError
);
985 // wxWindow class' m_hWnd set here and needed associations
989 wxAssociateWinWithHandle(m_hWnd
, this);
990 wxAssociateWinWithHandle(m_hFrame
, this);
992 m_backgroundColour
.Set(wxString("GREY"));
994 LONG lColor
= (LONG
)m_backgroundColour
.GetPixel();
996 if (!::WinSetPresParam( m_hWnd
1002 vError
= ::WinGetLastError(vHabmain
);
1003 sError
= wxPMErrorToStr(vError
);
1004 wxLogError("Error creating frame. Error: %s\n", sError
);
1009 // Now need to subclass window. Instead of calling the SubClassWin in wxWindow
1010 // we manually subclass here because we don't want to use the main wxWndProc
1013 m_fnOldWndProc
= (WXFARPROC
) ::WinSubclassWindow(m_hFrame
, (PFNWP
)wxFrameMainWndProc
);
1016 // Now size everything. If adding a menu the client will need to be resized.
1019 if (!::WinSetWindowPos( m_hFrame
1025 ,SWP_SIZE
| SWP_MOVE
| SWP_ACTIVATE
| SWP_ZORDER
1028 vError
= ::WinGetLastError(vHabmain
);
1029 sError
= wxPMErrorToStr(vError
);
1030 wxLogError("Error sizing frame. Error: %s\n", sError
);
1034 // We may have to be smarter here when variable sized toolbars are added!
1036 if (!::WinSetWindowPos( m_hWnd
1042 ,SWP_SIZE
| SWP_MOVE
| SWP_ACTIVATE
| SWP_ZORDER
1045 vError
= ::WinGetLastError(vHabmain
);
1046 sError
= wxPMErrorToStr(vError
);
1047 wxLogError("Error sizing client. Error: %s\n", sError
);
1051 } // end of wxFrameOS2::OS2Create
1054 // Default activation behaviour - set the focus for the first child
1057 void wxFrameOS2::OnActivate(
1058 wxActivateEvent
& rEvent
1061 if ( rEvent
.GetActive() )
1063 // restore focus to the child which was last focused
1064 wxLogTrace(_T("focus"), _T("wxFrame %08x activated."), m_hWnd
);
1066 wxWindow
* pParent
= m_pWinLastFocused
? m_pWinLastFocused
->GetParent()
1073 wxSetFocusToChild( pParent
1077 else // deactivating
1080 // Remember the last focused child if it is our child
1082 m_pWinLastFocused
= FindFocus();
1084 for (wxWindowList::Node
* pNode
= GetChildren().GetFirst();
1086 pNode
= pNode
->GetNext())
1088 // FIXME all this is totally bogus - we need to do the same as wxPanel,
1089 // but how to do it without duplicating the code?
1092 wxWindow
* pChild
= pNode
->GetData();
1094 if (!pChild
->IsTopLevel()
1096 && !wxDynamicCast(pChild
, wxToolBar
)
1097 #endif // wxUSE_TOOLBAR
1099 && !wxDynamicCast(pChild
, wxStatusBar
)
1100 #endif // wxUSE_STATUSBAR
1108 } // end of wxFrameOS2::OnActivate
1110 // ----------------------------------------------------------------------------
1111 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1112 // from the client area, so the client area is what's really available for the
1114 // ----------------------------------------------------------------------------
1116 // Checks if there is a toolbar, and returns the first free client position
1117 wxPoint
wxFrameOS2::GetClientAreaOrigin() const
1119 wxPoint
vPoint(0, 0);
1127 GetToolBar()->GetSize( &nWidth
1131 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
1137 // PM is backwards from windows
1138 vPoint
.y
+= nHeight
;
1141 #endif //wxUSE_TOOLBAR
1143 } // end of wxFrameOS2::GetClientAreaOrigin
1145 // ----------------------------------------------------------------------------
1146 // tool/status bar stuff
1147 // ----------------------------------------------------------------------------
1151 wxToolBar
* wxFrameOS2::CreateToolBar(
1154 , const wxString
& rName
1157 if (wxFrameBase::CreateToolBar( lStyle
1164 return m_frameToolBar
;
1165 } // end of wxFrameOS2::CreateToolBar
1167 void wxFrameOS2::PositionToolBar()
1172 ::WinQueryWindowRect(GetHwnd(), &vRect
);
1180 GetStatusBar()->GetClientSize( &nStatusX
1183 // PM is backwards from windows
1184 vRect
.yBottom
+= nStatusY
;
1186 #endif // wxUSE_STATUSBAR
1188 if ( m_frameToolBar
)
1193 m_frameToolBar
->GetSize( &nToolbarWidth
1197 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
1199 nToolbarHeight
= vRect
.yBottom
;
1203 nToolbarWidth
= vRect
.xRight
;
1207 // Use the 'real' PM position here
1209 GetToolBar()->SetSize( 0
1213 ,wxSIZE_NO_ADJUSTMENTS
1216 } // end of wxFrameOS2::PositionToolBar
1217 #endif // wxUSE_TOOLBAR
1219 // ----------------------------------------------------------------------------
1220 // frame state (iconized/maximized/...)
1221 // ----------------------------------------------------------------------------
1224 // propagate our state change to all child frames: this allows us to emulate X
1225 // Windows behaviour where child frames float independently of the parent one
1226 // on the desktop, but are iconized/restored with it
1228 void wxFrameOS2::IconizeChildFrames(
1232 for (wxWindowList::Node
* pNode
= GetChildren().GetFirst();
1234 pNode
= pNode
->GetNext() )
1236 wxWindow
* pWin
= pNode
->GetData();
1238 if (pWin
->IsKindOf(CLASSINFO(wxFrame
)) )
1240 ((wxFrame
*)pWin
)->Iconize(bIconize
);
1243 } // end of wxFrameOS2::IconizeChildFrames
1245 // ===========================================================================
1246 // message processing
1247 // ===========================================================================
1249 // ---------------------------------------------------------------------------
1251 // ---------------------------------------------------------------------------
1252 bool wxFrameOS2::OS2TranslateMessage(
1257 // try the menu bar accels
1259 wxMenuBar
* pMenuBar
= GetMenuBar();
1265 const wxAcceleratorTable
& rAcceleratorTable
= pMenuBar
->GetAccelTable();
1266 return rAcceleratorTable
.Translate(GetHWND(), pMsg
);
1269 #endif //wxUSE_ACCEL
1270 } // end of wxFrameOS2::OS2TranslateMessage
1272 // ---------------------------------------------------------------------------
1273 // our private (non virtual) message handlers
1274 // ---------------------------------------------------------------------------
1275 bool wxFrameOS2::HandlePaint()
1279 if (::WinQueryUpdateRect(GetHWND(), &vRect
))
1284 // Icons in PM are the same as "pointers"
1289 hIcon
= (HPOINTER
)::WinSendMsg(m_hFrame
, WM_QUERYICON
, 0L, 0L);
1291 hIcon
= (HPOINTER
)m_hDefaultIcon
;
1294 // Hold a pointer to the dc so long as the OnPaint() message
1295 // is being processed
1298 HPS hPs
= ::WinBeginPaint(GetHwnd(), NULLHANDLE
, &vRect2
);
1301 // Erase background before painting or we get white background
1303 OS2DefWindowProc(WM_ERASEBACKGROUND
, (MPARAM
)hPs
, (MPARAM
)&vRect2
);
1310 ::WinQueryWindowRect(GetHwnd(), &vRect3
);
1312 static const int nIconWidth
= 32;
1313 static const int nIconHeight
= 32;
1314 int nIconX
= (int)((vRect3
.xRight
- nIconWidth
)/2);
1315 int nIconY
= (int)((vRect3
.yBottom
+ nIconHeight
)/2);
1317 ::WinDrawPointer(hPs
, nIconX
, nIconY
, hIcon
, DP_NORMAL
);
1324 return(wxWindow::HandlePaint());
1329 // nothing to paint - processed
1333 } // end of wxFrameOS2::HandlePaint
1335 bool wxFrameOS2::HandleSize(
1341 bool bProcessed
= FALSE
;
1347 // Only do it it if we were iconized before, otherwise resizing the
1348 // parent frame has a curious side effect of bringing it under it's
1354 // restore all child frames too
1356 IconizeChildFrames(FALSE
);
1357 (void)SendIconizeEvent(FALSE
);
1364 m_bIconized
= FALSE
;
1369 // Iconize all child frames too
1371 IconizeChildFrames(TRUE
);
1372 (void)SendIconizeEvent();
1380 // forward WM_SIZE to status bar control
1382 #if wxUSE_NATIVE_STATUSBAR
1383 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
1385 wxSizeEvent
vEvent( wxSize( nX
1388 ,m_frameStatusBar
->GetId()
1391 vEvent
.SetEventObject(m_frameStatusBar
);
1392 m_frameStatusBar
->OnSize(vEvent
);
1394 #endif // wxUSE_NATIVE_STATUSBAR
1396 PositionStatusBar();
1399 #endif // wxUSE_TOOLBAR
1401 wxSizeEvent
vEvent( wxSize( nX
1407 vEvent
.SetEventObject(this);
1408 bProcessed
= GetEventHandler()->ProcessEvent(vEvent
);
1411 } // end of wxFrameOS2::HandleSize
1413 bool wxFrameOS2::HandleCommand(
1422 // In case it's e.g. a toolbar.
1424 wxWindow
* pWin
= wxFindWinFromHandle(hControl
);
1427 return pWin
->OS2Command( nCmd
1433 // Handle here commands from menus and accelerators
1435 if (nCmd
== CMDSRC_MENU
|| nCmd
== CMDSRC_ACCELERATOR
)
1437 if (wxCurrentPopupMenu
)
1439 wxMenu
* pPopupMenu
= wxCurrentPopupMenu
;
1441 wxCurrentPopupMenu
= NULL
;
1443 return pPopupMenu
->OS2Command( nCmd
1448 if (ProcessCommand(nId
))
1454 } // end of wxFrameOS2::HandleCommand
1456 bool wxFrameOS2::HandleMenuSelect(
1467 rc
= ::WinSendMsg(hMenu
, MM_QUERYITEM
, MPFROM2SHORT(nItem
, TRUE
), (MPARAM
)&mItem
);
1469 if(rc
&& !(mItem
.afStyle
& (MIS_SUBMENU
| MIS_SEPARATOR
)))
1471 wxMenuEvent
vEvent(wxEVT_MENU_HIGHLIGHT
, nItem
);
1473 vEvent
.SetEventObject(this);
1474 GetEventHandler()->ProcessEvent(vEvent
); // return value would be ignored by PM
1478 } // end of wxFrameOS2::HandleMenuSelect
1480 // ---------------------------------------------------------------------------
1481 // Main Frame window proc
1482 // ---------------------------------------------------------------------------
1483 MRESULT EXPENTRY
wxFrameMainWndProc(
1490 MRESULT rc
= (MRESULT
)0;
1491 bool bProcessed
= FALSE
;
1492 wxFrame
* pWnd
= NULL
;
1494 pWnd
= (wxFrame
*) wxFindWinFromHandle((WXHWND
) hWnd
);
1497 case WM_QUERYFRAMECTLCOUNT
:
1498 if(pWnd
&& pWnd
->m_fnOldWndProc
)
1500 USHORT uItemCount
= SHORT1FROMMR(pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
));
1502 rc
= MRFROMSHORT(uItemCount
);
1506 case WM_FORMATFRAME
:
1507 /////////////////////////////////////////////////////////////////////////////////
1508 // Applications that subclass frame controls may find that the frame is already
1509 // subclassed the number of frame controls is variable.
1510 // The WM_FORMATFRAME and WM_QUERYFRAMECTLCOUNT messages must always be
1511 // subclassed by calling the previous window procedure and modifying its result.
1512 ////////////////////////////////////////////////////////////////////////////////
1522 pSWP
= (PSWP
)PVOIDFROMMP(wParam
);
1523 nItemCount
= SHORT1FROMMR(pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
));
1524 if(pWnd
->m_frameStatusBar
)
1526 ::WinQueryWindowRect(pWnd
->m_frameStatusBar
->GetHWND(), &vRstb
);
1527 pWnd
->m_frameStatusBar
->GetSize(NULL
, &nHeight
);
1528 ::WinQueryWindowRect(pWnd
->m_hFrame
, &vRectl
);
1529 ::WinMapWindowPoints(pWnd
->m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRectl
, 2);
1531 ::WinCalcFrameRect(pWnd
->m_hFrame
, &vRectl
, TRUE
);
1533 vSwpStb
.x
= vRectl
.xLeft
- vRstb
.xLeft
;
1534 vSwpStb
.y
= vRectl
.yBottom
- vRstb
.yBottom
;
1535 vSwpStb
.cx
= vRectl
.xRight
- vRectl
.xLeft
- 1; //?? -1 ??
1536 vSwpStb
.cy
= nHeight
;
1537 vSwpStb
.fl
= SWP_SIZE
|SWP_MOVE
| SWP_SHOW
;
1538 vSwpStb
.hwnd
= pWnd
->m_frameStatusBar
->GetHWND();
1539 vSwpStb
.hwndInsertBehind
= HWND_TOP
;
1541 ::WinQueryWindowRect(pWnd
->m_hFrame
, &vRectl
);
1542 ::WinMapWindowPoints(pWnd
->m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRectl
, 2);
1543 ::WinCalcFrameRect(pWnd
->m_hFrame
, &vRectl
, TRUE
);
1544 ::WinMapWindowPoints(HWND_DESKTOP
, pWnd
->m_hFrame
, (PPOINTL
)&vRectl
, 2);
1545 for(i
= 0; i
< nItemCount
; i
++)
1547 if(pWnd
->m_hWnd
&& pSWP
[i
].hwnd
== pWnd
->m_hWnd
)
1549 pSWP
[i
].x
= vRectl
.xLeft
;
1550 pSWP
[i
].y
= vRectl
.yBottom
+ nHeight
;
1551 pSWP
[i
].cx
= vRectl
.xRight
- vRectl
.xLeft
;
1552 pSWP
[i
].cy
= vRectl
.yTop
- vRectl
.yBottom
- nHeight
;
1553 pSWP
[i
].fl
= SWP_SIZE
| SWP_MOVE
| SWP_SHOW
;
1554 pSWP
[i
].hwndInsertBehind
= HWND_TOP
;
1558 rc
= MRFROMSHORT(nItemCount
);
1563 if(pWnd
&& pWnd
->m_fnOldWndProc
)
1564 rc
= pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
);
1566 rc
= ::WinDefWindowProc(hWnd
, ulMsg
, wParam
, lParam
);
1569 } // end of wxFrameMainWndProc
1571 MRESULT EXPENTRY
wxFrameWndProc(
1579 // Trace all ulMsgs - useful for the debugging
1582 wxFrame
* pWnd
= NULL
;
1584 parentHwnd
= WinQueryWindow(hWnd
,QW_PARENT
);
1585 pWnd
= (wxFrame
*) wxFindWinFromHandle((WXHWND
) hWnd
);
1588 // When we get the first message for the HWND we just created, we associate
1589 // it with wxWindow stored in wxWndHook
1592 MRESULT rc
= (MRESULT
)0;
1593 bool bProcessed
= FALSE
;
1596 // Stop right here if we don't have a valid handle in our wxWindow object.
1598 if (pWnd
&& !pWnd
->GetHWND())
1600 pWnd
->SetHWND((WXHWND
) hWnd
);
1601 rc
= pWnd
->OS2DefWindowProc(ulMsg
, wParam
, lParam
);
1607 rc
= pWnd
->OS2WindowProc(ulMsg
, wParam
, lParam
);
1609 rc
= ::WinDefWindowProc(hWnd
, ulMsg
, wParam
, lParam
);
1612 } // end of wxFrameWndProc
1614 MRESULT
wxFrameOS2::OS2WindowProc(
1621 bool bProcessed
= FALSE
;
1627 // If we can't close, tell the system that we processed the
1628 // message - otherwise it would close us
1630 bProcessed
= !Close();
1634 bProcessed
= HandlePaint();
1635 mRc
= (MRESULT
)FALSE
;
1638 case WM_ERASEBACKGROUND
:
1640 // Returning TRUE to requests PM to paint the window background
1641 // in SYSCLR_WINDOW. We capture this here because the PS returned
1642 // in Frames is the PS for the whole frame, which we can't really
1643 // use at all. If you want to paint a different background, do it
1644 // in an OnPaint using a wxPaintDC.
1646 mRc
= (MRESULT
)(TRUE
);
1655 UnpackCommand( (WXWPARAM
)wParam
1662 bProcessed
= HandleCommand( wId
1675 UnpackMenuSelect( wParam
1681 bProcessed
= HandleMenuSelect( wItem
1685 mRc
= (MRESULT
)TRUE
;
1691 SHORT nScxold
= SHORT1FROMMP(wParam
); // Old horizontal size.
1692 SHORT nScyold
= SHORT2FROMMP(wParam
); // Old vertical size.
1693 SHORT nScxnew
= SHORT1FROMMP(lParam
); // New horizontal size.
1694 SHORT nScynew
= SHORT2FROMMP(lParam
); // New vertical size.
1696 lParam
= MRFROM2SHORT( nScxnew
- 20
1700 bProcessed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), (WXUINT
)wParam
);
1701 mRc
= (MRESULT
)FALSE
;
1704 case CM_QUERYDRAGIMAGE
:
1709 hIcon
= (HPOINTER
)::WinSendMsg(GetHWND(), WM_QUERYICON
, 0L, 0L);
1711 hIcon
= (HPOINTER
)m_hDefaultIcon
;
1712 mRc
= (MRESULT
)hIcon
;
1713 bProcessed
= mRc
!= 0;
1719 mRc
= wxWindow::OS2WindowProc( uMessage
1723 return (MRESULT
)mRc
;
1724 } // wxFrameOS2::OS2WindowProc
1726 void wxFrameOS2::SetClient(WXHWND c_Hwnd
)
1728 // Duh...nothing to do under OS/2
1731 void wxFrameOS2::SetClient(
1735 wxWindow
* pOldClient
= this->GetClient();
1736 bool bClientHasFocus
= pOldClient
&& (pOldClient
== wxWindow::FindFocus());
1738 if(pOldClient
== pWindow
) // nothing to do
1740 if(pWindow
== NULL
) // just need to remove old client
1742 if(pOldClient
== NULL
) // nothing to do
1745 if(bClientHasFocus
)
1748 pOldClient
->Enable( FALSE
);
1749 pOldClient
->Show( FALSE
);
1750 ::WinSetWindowUShort(pOldClient
->GetHWND(), QWS_ID
, (USHORT
)pOldClient
->GetId());
1751 // to avoid OS/2 bug need to update frame
1752 ::WinSendMsg((HWND
)this->GetFrame(), WM_UPDATEFRAME
, (MPARAM
)~0, 0);
1757 // Else need to change client
1762 ::WinEnableWindowUpdate((HWND
)GetHWND(), FALSE
);
1765 pOldClient
->Enable(FALSE
);
1766 pOldClient
->Show(FALSE
);
1767 ::WinSetWindowUShort(pOldClient
->GetHWND(), QWS_ID
, (USHORT
)pOldClient
->GetId());
1769 pWindow
->Reparent(this);
1770 ::WinSetWindowUShort(pWindow
->GetHWND(), QWS_ID
, FID_CLIENT
);
1771 ::WinEnableWindowUpdate((HWND
)GetHWND(), TRUE
);
1773 pWindow
->Show(); // ensure client is showing
1774 if( this->IsShown() )
1777 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0);
1781 wxWindow
* wxFrameOS2::GetClient()
1783 return wxFindWinFromHandle((WXHWND
)::WinWindowFromID(m_hFrame
, FID_CLIENT
));