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
);
247 *pX
= vRect
.xRight
- vRect
.xLeft
;
249 *pY
= vRect
.yTop
- vRect
.yBottom
;
250 } // end of wxFrame::DoGetClientSize
253 // Set the client size (i.e. leave the calculation of borders etc.
256 void wxFrame::DoSetClientSize(
261 HWND hWnd
= GetHwnd();
265 ::WinQueryWindowRect(GetHwnd(), &vRect
);
266 ::WinQueryWindowRect(GetHwnd(), &vRect2
);
269 // Find the difference between the entire window (title bar and all)
270 // and the client area; add this to the new client size to move the
271 // window. Remember OS/2's backwards y coord system!
273 int nActualWidth
= vRect2
.xRight
- vRect2
.xLeft
- vRect
.xRight
+ nWidth
;
274 int nActualHeight
= vRect2
.yTop
+ vRect2
.yTop
- vRect
.yTop
+ nHeight
;
277 if ( GetStatusBar() )
282 GetStatusBar()->GetClientSize( &nStatusX
285 nActualHeight
+= nStatusY
;
287 #endif // wxUSE_STATUSBAR
289 wxPoint
vPoint(GetClientAreaOrigin());
290 nActualWidth
+= vPoint
.y
;
291 nActualHeight
+= vPoint
.x
;
295 vPointl
.x
= vRect2
.xLeft
;
296 vPointl
.y
= vRect2
.yTop
;
298 ::WinSetWindowPos( hWnd
304 ,SWP_MOVE
| SWP_SIZE
| SWP_SHOW
307 wxSizeEvent
vEvent( wxSize( nWidth
312 vEvent
.SetEventObject(this);
313 GetEventHandler()->ProcessEvent(vEvent
);
314 } // end of wxFrame::DoSetClientSize
316 void wxFrame::DoGetSize(
323 ::WinQueryWindowRect(m_hFrame
, &vRect
);
324 *pWidth
= vRect
.xRight
- vRect
.xLeft
;
325 *pHeight
= vRect
.yTop
- vRect
.yBottom
;
326 } // end of wxFrame::DoGetSize
328 void wxFrame::DoGetPosition(
336 ::WinQueryWindowRect(m_hFrame
, &vRect
);
337 vPoint
.x
= vRect
.xLeft
;
340 // OS/2 is backwards [WIN32 it is vRect.yTop]
342 vPoint
.y
= vRect
.yBottom
;
346 } // end of wxFrame::DoGetPosition
348 // ----------------------------------------------------------------------------
349 // variations around ::ShowWindow()
350 // ----------------------------------------------------------------------------
352 void wxFrame::DoShowWindow(
356 ::WinShowWindow(m_hFrame
, (BOOL
)bShowCmd
);
357 m_bIconized
= bShowCmd
== SWP_MINIMIZE
;
358 } // end of wxFrame::DoShowWindow
366 DoShowWindow((int)bShow
);
370 wxActivateEvent
vEvent(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
372 ::WinQueryWindowPos(m_hFrame
, &vSwp
);
373 m_bIconized
= vSwp
.fl
& SWP_MINIMIZE
;
374 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0);
375 ::WinEnableWindow(m_hFrame
, TRUE
);
376 vEvent
.SetEventObject(this);
377 GetEventHandler()->ProcessEvent(vEvent
);
382 // Try to highlight the correct window (the parent)
386 HWND hWndParent
= GetHwndOf(GetParent());
388 ::WinQueryWindowPos(hWndParent
, &vSwp
);
389 m_bIconized
= vSwp
.fl
& SWP_MINIMIZE
;
391 ::WinSetWindowPos( hWndParent
397 ,SWP_ZORDER
| SWP_ACTIVATE
| SWP_SHOW
| SWP_MOVE
399 ::WinEnableWindow(hWndParent
, TRUE
);
403 } // end of wxFrame::Show
405 void wxFrame::Iconize(
409 DoShowWindow(bIconize
? SWP_MINIMIZE
: SWP_RESTORE
);
410 } // end of wxFrame::Iconize
412 void wxFrame::Maximize(
415 DoShowWindow(bMaximize
? SWP_MAXIMIZE
: SWP_RESTORE
);
416 } // end of wxFrame::Maximize
418 void wxFrame::Restore()
420 DoShowWindow(SWP_RESTORE
);
421 } // end of wxFrame::Restore
423 bool wxFrame::IsIconized() const
427 ::WinQueryWindowPos(m_hFrame
, &vSwp
);
429 if (vSwp
.fl
& SWP_MINIMIZE
)
430 ((wxFrame
*)this)->m_bIconized
= TRUE
;
432 ((wxFrame
*)this)->m_bIconized
= FALSE
;
434 } // end of wxFrame::IsIconized
437 bool wxFrame::IsMaximized() const
442 ::WinQueryWindowPos(m_hFrame
, &vSwp
);
443 return (vSwp
.fl
& SWP_MAXIMIZE
);
444 } // end of wxFrame::IsMaximized
446 void wxFrame::SetIcon(
450 wxFrameBase::SetIcon(rIcon
);
452 if ((m_icon
.GetHICON()) != NULLHANDLE
)
454 ::WinSendMsg( m_hFrame
456 ,(MPARAM
)((HPOINTER
)m_icon
.GetHICON())
459 ::WinSendMsg( m_hFrame
465 } // end of wxFrame::SetIcon
468 wxStatusBar
* wxFrame::OnCreateStatusBar(
472 , const wxString
& rName
475 wxStatusBar
* pStatusBar
= NULL
;
480 pStatusBar
= wxFrameBase::OnCreateStatusBar( nNumber
489 ::WinSetParent( pStatusBar
->GetHWND()
493 ::WinSetOwner( pStatusBar
->GetHWND()
499 if(::WinIsWindowShowing(m_hFrame
))
500 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0);
503 } // end of wxFrame::OnCreateStatusBar
505 void wxFrame::PositionStatusBar()
512 // Native status bar positions itself
514 if (m_frameStatusBar
)
523 ::WinQueryWindowRect(m_hFrame
, &vRect
);
524 ::WinMapWindowPoints(m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRect
, 2);
526 ::WinCalcFrameRect(m_hFrame
, &vRect
, TRUE
);
527 nWidth
= vRect
.xRight
- vRect
.xLeft
;
529 m_frameStatusBar
->GetSize( &nStatbarWidth
534 // Since we wish the status bar to be directly under the client area,
535 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
537 m_frameStatusBar
->SetSize( vRect
.xLeft
- vFRect
.xLeft
538 ,vRect
.yBottom
- vFRect
.yBottom
542 if (!::WinQueryWindowPos(m_frameStatusBar
->GetHWND(), &vSwp
))
544 vError
= ::WinGetLastError(vHabmain
);
545 sError
= wxPMErrorToStr(vError
);
546 wxLogError("Error setting parent for StautsBar. Error: %s\n", sError
);
550 } // end of wxFrame::PositionStatusBar
551 #endif // wxUSE_STATUSBAR
553 void wxFrame::DetachMenuBar()
557 m_frameMenuBar
->Detach();
558 m_frameMenuBar
= NULL
;
560 } // end of wxFrame::DetachMenuBar
562 void wxFrame::SetMenuBar(
568 HWND hTitlebar
= NULLHANDLE
;
569 HWND hHScroll
= NULLHANDLE
;
570 HWND hVScroll
= NULLHANDLE
;
571 HWND hMenuBar
= NULLHANDLE
;
583 // Actually remove the menu from the frame
585 m_hMenu
= (WXHMENU
)0;
586 InternalSetMenuBar();
588 else // set new non NULL menu bar
590 m_frameMenuBar
= NULL
;
593 // Can set a menubar several times.
594 // TODO: how to prevent a memory leak if you have a currently-unattached
595 // menubar? wxWindows assumes that the frame will delete the menu (otherwise
596 // there are problems for MDI).
598 if (pMenuBar
->GetHMenu())
600 m_hMenu
= pMenuBar
->GetHMenu();
605 m_hMenu
= pMenuBar
->Create();
609 InternalSetMenuBar();
610 m_frameMenuBar
= pMenuBar
;
611 pMenuBar
->Attach(this);
613 } // end of wxFrame::SetMenuBar
615 void wxFrame::InternalSetMenuBar()
620 // Set the parent and owner of the menubar to be the frame
622 if (!::WinSetParent(m_hMenu
, m_hFrame
, FALSE
))
624 vError
= ::WinGetLastError(vHabmain
);
625 sError
= wxPMErrorToStr(vError
);
626 wxLogError("Error setting parent for submenu. Error: %s\n", sError
);
629 if (!::WinSetOwner(m_hMenu
, m_hFrame
))
631 vError
= ::WinGetLastError(vHabmain
);
632 sError
= wxPMErrorToStr(vError
);
633 wxLogError("Error setting parent for submenu. Error: %s\n", sError
);
635 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
636 } // end of wxFrame::InternalSetMenuBar
639 // Responds to colour changes, and passes event on to children
641 void wxFrame::OnSysColourChanged(
642 wxSysColourChangedEvent
& rEvent
645 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
649 if (m_frameStatusBar
)
651 wxSysColourChangedEvent vEvent2
;
653 vEvent2
.SetEventObject(m_frameStatusBar
);
654 m_frameStatusBar
->GetEventHandler()->ProcessEvent(vEvent2
);
656 #endif //wxUSE_STATUSBAR
659 // Propagate the event to the non-top-level children
661 wxWindow::OnSysColourChanged(rEvent
);
662 } // end of wxFrame::OnSysColourChanged
664 // Pass TRUE to show full screen, FALSE to restore.
665 bool wxFrame::ShowFullScreen(
675 m_bFsIsShowing
= TRUE
;
679 wxToolBar
* pTheToolBar
= GetToolBar();
680 #endif //wxUSE_TOOLBAR
683 wxStatusBar
* pTheStatusBar
= GetStatusBar();
684 #endif //wxUSE_STATUSBAR
690 pTheToolBar
->GetSize(&nDummyWidth
, &m_nFsToolBarHeight
);
691 #endif //wxUSE_TOOLBAR
695 pTheStatusBar
->GetSize(&nDummyWidth
, &m_nFsStatusBarHeight
);
696 #endif //wxUSE_STATUSBAR
700 // Zap the toolbar, menubar, and statusbar
702 if ((lStyle
& wxFULLSCREEN_NOTOOLBAR
) && pTheToolBar
)
704 pTheToolBar
->SetSize(-1,0);
705 pTheToolBar
->Show(FALSE
);
707 #endif //wxUSE_TOOLBAR
709 if (lStyle
& wxFULLSCREEN_NOMENUBAR
)
711 ::WinSetParent(m_hMenu
, m_hFrame
, FALSE
);
712 ::WinSetOwner(m_hMenu
, m_hFrame
);
713 ::WinSendMsg((HWND
)m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
718 // Save the number of fields in the statusbar
720 if ((lStyle
& wxFULLSCREEN_NOSTATUSBAR
) && pTheStatusBar
)
722 m_nFsStatusBarFields
= pTheStatusBar
->GetFieldsCount();
723 SetStatusBar((wxStatusBar
*) NULL
);
724 delete pTheStatusBar
;
727 m_nFsStatusBarFields
= 0;
728 #endif //wxUSE_STATUSBAR
731 // Zap the frame borders
735 // Save the 'normal' window style
737 m_lFsOldWindowStyle
= ::WinQueryWindowULong(m_hFrame
, QWL_STYLE
);
740 // Save the old position, width & height, maximize state
742 m_vFsOldSize
= GetRect();
743 m_bFsIsMaximized
= IsMaximized();
746 // Decide which window style flags to turn off
748 LONG lNewStyle
= m_lFsOldWindowStyle
;
751 if (lStyle
& wxFULLSCREEN_NOBORDER
)
752 lOffFlags
|= FCF_BORDER
;
753 if (lStyle
& wxFULLSCREEN_NOCAPTION
)
754 lOffFlags
|= (FCF_TASKLIST
| FCF_SYSMENU
);
756 lNewStyle
&= (~lOffFlags
);
759 // Change our window style to be compatible with full-screen mode
761 ::WinSetWindowULong((HWND
)m_hFrame
, QWL_STYLE
, (ULONG
)lNewStyle
);
764 // Resize to the size of the desktop
770 ::WinQueryWindowRect(HWND_DESKTOP
, &vRect
);
771 nWidth
= vRect
.xRight
- vRect
.xLeft
;
773 // Rmember OS/2 is backwards!
775 nHeight
= vRect
.yTop
- vRect
.yBottom
;
782 // Now flush the window style cache and actually go full-screen
784 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
793 wxSizeEvent
vEvent( wxSize( nWidth
799 GetEventHandler()->ProcessEvent(vEvent
);
807 m_bFsIsShowing
= FALSE
;
810 wxToolBar
* pTheToolBar
= GetToolBar();
813 // Restore the toolbar, menubar, and statusbar
815 if (pTheToolBar
&& (m_lFsStyle
& wxFULLSCREEN_NOTOOLBAR
))
817 pTheToolBar
->SetSize(-1, m_nFsToolBarHeight
);
818 pTheToolBar
->Show(TRUE
);
820 #endif //wxUSE_TOOLBAR
823 if ((m_lFsStyle
& wxFULLSCREEN_NOSTATUSBAR
) && (m_nFsStatusBarFields
> 0))
825 CreateStatusBar(m_nFsStatusBarFields
);
826 // PositionStatusBar();
828 #endif //wxUSE_STATUSBAR
830 if ((m_lFsStyle
& wxFULLSCREEN_NOMENUBAR
) && (m_hMenu
!= 0))
832 ::WinSetParent(m_hMenu
, m_hFrame
, FALSE
);
833 ::WinSetOwner(m_hMenu
, m_hFrame
);
834 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
836 Maximize(m_bFsIsMaximized
);
838 ::WinSetWindowULong( m_hFrame
840 ,(ULONG
)m_lFsOldWindowStyle
842 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
852 } // end of wxFrame::ShowFullScreen
857 bool wxFrame::OS2Create(
860 , const wxChar
* zWclass
862 , const wxChar
* zTitle
870 ULONG ulCreateFlags
= 0L;
871 ULONG ulStyleFlags
= 0L;
872 ULONG ulExtraFlags
= 0L;
873 FRAMECDATA vFrameCtlData
;
874 HWND hParent
= NULLHANDLE
;
875 HWND hTitlebar
= NULLHANDLE
;
876 HWND hHScroll
= NULLHANDLE
;
877 HWND hVScroll
= NULLHANDLE
;
878 HWND hFrame
= NULLHANDLE
;
879 HWND hClient
= NULLHANDLE
;
886 m_hDefaultIcon
= (WXHICON
) (wxSTD_FRAME_ICON
? wxSTD_FRAME_ICON
: wxDEFAULT_FRAME_ICON
);
889 hParent
= GetWinHwnd(pParent
);
891 hParent
= HWND_DESKTOP
;
893 if (ulStyle
== wxDEFAULT_FRAME_STYLE
)
894 ulCreateFlags
= FCF_SIZEBORDER
| FCF_TITLEBAR
| FCF_SYSMENU
|
895 FCF_MINMAX
| FCF_TASKLIST
;
898 if ((ulStyle
& wxCAPTION
) == wxCAPTION
)
899 ulCreateFlags
= FCF_TASKLIST
;
901 ulCreateFlags
= FCF_NOMOVEWITHOWNER
;
903 if ((ulStyle
& wxVSCROLL
) == wxVSCROLL
)
904 ulCreateFlags
|= FCF_VERTSCROLL
;
905 if ((ulStyle
& wxHSCROLL
) == wxHSCROLL
)
906 ulCreateFlags
|= FCF_HORZSCROLL
;
907 if (ulStyle
& wxMINIMIZE_BOX
)
908 ulCreateFlags
|= FCF_MINBUTTON
;
909 if (ulStyle
& wxMAXIMIZE_BOX
)
910 ulCreateFlags
|= FCF_MAXBUTTON
;
911 if (ulStyle
& wxTHICK_FRAME
)
912 ulCreateFlags
|= FCF_DLGBORDER
;
913 if (ulStyle
& wxSYSTEM_MENU
)
914 ulCreateFlags
|= FCF_SYSMENU
;
915 if (ulStyle
& wxCAPTION
)
916 ulCreateFlags
|= FCF_TASKLIST
;
917 if (ulStyle
& wxCLIP_CHILDREN
)
919 // Invalid for frame windows under PM
922 if (ulStyle
& wxTINY_CAPTION_VERT
)
923 ulCreateFlags
|= FCF_TASKLIST
;
924 if (ulStyle
& wxTINY_CAPTION_HORIZ
)
925 ulCreateFlags
|= FCF_TASKLIST
;
927 if ((ulStyle
& wxTHICK_FRAME
) == 0)
928 ulCreateFlags
|= FCF_BORDER
;
929 if (ulStyle
& wxFRAME_TOOL_WINDOW
)
930 ulExtraFlags
= kFrameToolWindow
;
932 if (ulStyle
& wxSTAY_ON_TOP
)
933 ulCreateFlags
|= FCF_SYSMODAL
;
935 if ((ulStyle
& wxMINIMIZE
) || (ulStyle
& wxICONIZE
))
936 ulStyleFlags
|= WS_MINIMIZED
;
937 if (ulStyle
& wxMAXIMIZE
)
938 ulStyleFlags
|= WS_MAXIMIZED
;
941 // Clear the visible flag, we always call show
943 ulStyleFlags
&= (unsigned long)~WS_VISIBLE
;
947 // Set the frame control block
949 vFrameCtlData
.cb
= sizeof(vFrameCtlData
);
950 vFrameCtlData
.flCreateFlags
= ulCreateFlags
;
951 vFrameCtlData
.hmodResources
= 0L;
952 vFrameCtlData
.idResources
= 0;
955 // Create the frame window: We break ranks with other ports now
956 // and instead of calling down into the base wxWindow class' OS2Create
957 // we do all our own stuff here. We will set the needed pieces
958 // of wxWindow manually, here.
961 hFrame
= ::WinCreateStdWindow( hParent
962 ,ulStyleFlags
// frame-window style
963 ,&ulCreateFlags
// window style
964 ,(PSZ
)zWclass
// class name
965 ,(PSZ
)zTitle
// window title
966 ,0L // default client style
967 ,NULLHANDLE
// resource in executable file
969 ,&hClient
// receives client window handle
973 vError
= ::WinGetLastError(vHabmain
);
974 sError
= wxPMErrorToStr(vError
);
975 wxLogError("Error creating frame. Error: %s\n", sError
);
980 // wxWindow class' m_hWnd set here and needed associations
984 wxAssociateWinWithHandle(m_hWnd
, this);
985 wxAssociateWinWithHandle(m_hFrame
, this);
988 // Now need to subclass window. Instead of calling the SubClassWin in wxWindow
989 // we manually subclass here because we don't want to use the main wxWndProc
992 m_fnOldWndProc
= (WXFARPROC
) ::WinSubclassWindow(m_hFrame
, (PFNWP
)wxFrameMainWndProc
);
995 // Now size everything. If adding a menu the client will need to be resized.
998 if (!::WinSetWindowPos( m_hFrame
1004 ,SWP_SIZE
| SWP_MOVE
| SWP_ACTIVATE
| SWP_ZORDER
1007 vError
= ::WinGetLastError(vHabmain
);
1008 sError
= wxPMErrorToStr(vError
);
1009 wxLogError("Error sizing frame. Error: %s\n", sError
);
1013 // We may have to be smarter here when variable sized toolbars are added!
1015 if (!::WinSetWindowPos( m_hWnd
1021 ,SWP_SIZE
| SWP_MOVE
| SWP_ACTIVATE
| SWP_ZORDER
1024 vError
= ::WinGetLastError(vHabmain
);
1025 sError
= wxPMErrorToStr(vError
);
1026 wxLogError("Error sizing client. Error: %s\n", sError
);
1030 } // end of wxFrame::OS2Create
1033 // Default activation behaviour - set the focus for the first child
1036 void wxFrame::OnActivate(
1037 wxActivateEvent
& rEvent
1040 for (wxWindowList::Node
* pNode
= GetChildren().GetFirst();
1042 pNode
= pNode
->GetNext())
1044 // FIXME all this is totally bogus - we need to do the same as wxPanel,
1045 // but how to do it without duplicating the code?
1048 wxWindow
* pChild
= pNode
->GetData();
1050 if (!pChild
->IsTopLevel()
1052 && !wxDynamicCast(pChild
, wxToolBar
)
1053 #endif // wxUSE_TOOLBAR
1055 && !wxDynamicCast(pChild
, wxStatusBar
)
1056 #endif // wxUSE_STATUSBAR
1063 } // end of wxFrame::OnActivate
1065 // ----------------------------------------------------------------------------
1066 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1067 // from the client area, so the client area is what's really available for the
1069 // ----------------------------------------------------------------------------
1071 // Checks if there is a toolbar, and returns the first free client position
1072 wxPoint
wxFrame::GetClientAreaOrigin() const
1074 wxPoint
vPoint(0, 0);
1082 GetToolBar()->GetSize( &nWidth
1086 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
1092 // PM is backwards from windows
1093 vPoint
.y
+= nHeight
;
1096 #endif //wxUSE_TOOLBAR
1098 } // end of wxFrame::GetClientAreaOrigin
1100 // ----------------------------------------------------------------------------
1101 // tool/status bar stuff
1102 // ----------------------------------------------------------------------------
1106 wxToolBar
* wxFrame::CreateToolBar(
1109 , const wxString
& rName
1112 if (wxFrameBase::CreateToolBar( lStyle
1119 return m_frameToolBar
;
1120 } // end of wxFrame::CreateToolBar
1122 void wxFrame::PositionToolBar()
1127 ::WinQueryWindowRect(GetHwnd(), &vRect
);
1135 GetStatusBar()->GetClientSize( &nStatusX
1138 // PM is backwards from windows
1139 vRect
.yBottom
+= nStatusY
;
1141 #endif // wxUSE_STATUSBAR
1148 GetToolBar()->GetSize( &nToolbarWidth
1152 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
1154 nToolbarHeight
= vRect
.yBottom
;
1158 nToolbarWidth
= vRect
.xRight
;
1162 // Use the 'real' PM position here
1164 GetToolBar()->SetSize( 0
1168 ,wxSIZE_NO_ADJUSTMENTS
1171 } // end of wxFrame::PositionToolBar
1172 #endif // wxUSE_TOOLBAR
1174 // ----------------------------------------------------------------------------
1175 // frame state (iconized/maximized/...)
1176 // ----------------------------------------------------------------------------
1179 // propagate our state change to all child frames: this allows us to emulate X
1180 // Windows behaviour where child frames float independently of the parent one
1181 // on the desktop, but are iconized/restored with it
1183 void wxFrame::IconizeChildFrames(
1187 for (wxWindowList::Node
* pNode
= GetChildren().GetFirst();
1189 pNode
= pNode
->GetNext() )
1191 wxWindow
* pWin
= pNode
->GetData();
1193 if (pWin
->IsKindOf(CLASSINFO(wxFrame
)) )
1195 ((wxFrame
*)pWin
)->Iconize(bIconize
);
1198 } // end of wxFrame::IconizeChildFrames
1200 // ===========================================================================
1201 // message processing
1202 // ===========================================================================
1204 // ---------------------------------------------------------------------------
1206 // ---------------------------------------------------------------------------
1207 bool wxFrame::OS2TranslateMessage(
1212 // try the menu bar accels
1214 wxMenuBar
* pMenuBar
= GetMenuBar();
1220 const wxAcceleratorTable
& rAcceleratorTable
= pMenuBar
->GetAccelTable();
1221 return rAcceleratorTable
.Translate(GetHWND(), pMsg
);
1224 #endif //wxUSE_ACCEL
1225 } // end of wxFrame::OS2TranslateMessage
1227 // ---------------------------------------------------------------------------
1228 // our private (non virtual) message handlers
1229 // ---------------------------------------------------------------------------
1230 bool wxFrame::HandlePaint()
1234 if (::WinQueryUpdateRect(GetHWND(), &vRect
))
1239 // Icons in PM are the same as "pointers"
1244 hIcon
= (HPOINTER
)::WinSendMsg(m_hFrame
, WM_QUERYICON
, 0L, 0L);
1246 hIcon
= (HPOINTER
)m_hDefaultIcon
;
1249 // Hold a pointer to the dc so long as the OnPaint() message
1250 // is being processed
1253 HPS hPs
= ::WinBeginPaint(GetHwnd(), NULLHANDLE
, &vRect2
);
1256 // Erase background before painting or we get white background
1258 OS2DefWindowProc(WM_ERASEBACKGROUND
, (MPARAM
)hPs
, (MPARAM
)&vRect2
);
1265 ::WinQueryWindowRect(GetHwnd(), &vRect3
);
1267 static const int nIconWidth
= 32;
1268 static const int nIconHeight
= 32;
1269 int nIconX
= (int)((vRect3
.xRight
- nIconWidth
)/2);
1270 int nIconY
= (int)((vRect3
.yBottom
+ nIconHeight
)/2);
1272 ::WinDrawPointer(hPs
, nIconX
, nIconY
, hIcon
, DP_NORMAL
);
1279 wxWindow::HandlePaint();
1285 // nothing to paint - processed
1289 } // end of wxFrame::HandlePaint
1291 bool wxFrame::HandleSize(
1297 bool bProcessed
= FALSE
;
1303 // Only do it it if we were iconized before, otherwise resizing the
1304 // parent frame has a curious side effect of bringing it under it's
1310 // restore all child frames too
1312 IconizeChildFrames(FALSE
);
1319 m_bIconized
= FALSE
;
1324 // Iconize all child frames too
1326 IconizeChildFrames(TRUE
);
1334 // forward WM_SIZE to status bar control
1336 #if wxUSE_NATIVE_STATUSBAR
1337 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
1339 wxSizeEvent
vEvent( wxSize( nX
1342 ,m_frameStatusBar
->GetId()
1345 vEvent
.SetEventObject(m_frameStatusBar
);
1346 m_frameStatusBar
->OnSize(vEvent
);
1348 #endif // wxUSE_NATIVE_STATUSBAR
1350 PositionStatusBar();
1353 #endif // wxUSE_TOOLBAR
1355 wxSizeEvent
vEvent( wxSize( nX
1361 vEvent
.SetEventObject(this);
1362 bProcessed
= GetEventHandler()->ProcessEvent(vEvent
);
1365 } // end of wxFrame::HandleSize
1367 bool wxFrame::HandleCommand(
1376 // In case it's e.g. a toolbar.
1378 wxWindow
* pWin
= wxFindWinFromHandle(hControl
);
1381 return pWin
->OS2Command( nCmd
1387 // Handle here commands from menus and accelerators
1389 if (nCmd
== CMDSRC_MENU
|| nCmd
== CMDSRC_ACCELERATOR
)
1391 if (wxCurrentPopupMenu
)
1393 wxMenu
* pPopupMenu
= wxCurrentPopupMenu
;
1395 wxCurrentPopupMenu
= NULL
;
1397 return pPopupMenu
->OS2Command( nCmd
1402 if (ProcessCommand(nId
))
1408 } // end of wxFrame::HandleCommand
1410 bool wxFrame::HandleMenuSelect(
1421 rc
= ::WinSendMsg(hMenu
, MM_QUERYITEM
, MPFROM2SHORT(nItem
, TRUE
), (MPARAM
)&mItem
);
1423 if(rc
&& !(mItem
.afStyle
& (MIS_SUBMENU
| MIS_SEPARATOR
)))
1425 wxMenuEvent
vEvent(wxEVT_MENU_HIGHLIGHT
, nItem
);
1427 vEvent
.SetEventObject(this);
1428 GetEventHandler()->ProcessEvent(vEvent
); // return value would be ignored by PM
1432 } // end of wxFrame::HandleMenuSelect
1434 // ---------------------------------------------------------------------------
1435 // Main Frame window proc
1436 // ---------------------------------------------------------------------------
1437 MRESULT EXPENTRY
wxFrameMainWndProc(
1444 MRESULT rc
= (MRESULT
)0;
1445 bool bProcessed
= FALSE
;
1446 wxFrame
* pWnd
= NULL
;
1448 pWnd
= (wxFrame
*) wxFindWinFromHandle((WXHWND
) hWnd
);
1451 case WM_QUERYFRAMECTLCOUNT
:
1452 if(pWnd
&& pWnd
->m_fnOldWndProc
)
1454 USHORT uItemCount
= SHORT1FROMMR(pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
));
1456 rc
= MRFROMSHORT(uItemCount
);
1460 case WM_FORMATFRAME
:
1461 /////////////////////////////////////////////////////////////////////////////////
1462 // Applications that subclass frame controls may find that the frame is already
1463 // subclassed the number of frame controls is variable.
1464 // The WM_FORMATFRAME and WM_QUERYFRAMECTLCOUNT messages must always be
1465 // subclassed by calling the previous window procedure and modifying its result.
1466 ////////////////////////////////////////////////////////////////////////////////
1476 pSWP
= (PSWP
)PVOIDFROMMP(wParam
);
1477 nItemCount
= SHORT1FROMMR(pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
));
1478 if(pWnd
->m_frameStatusBar
)
1480 ::WinQueryWindowRect(pWnd
->m_frameStatusBar
->GetHWND(), &vRstb
);
1481 pWnd
->m_frameStatusBar
->GetSize(NULL
, &nHeight
);
1482 ::WinQueryWindowRect(pWnd
->m_hFrame
, &vRectl
);
1483 ::WinMapWindowPoints(pWnd
->m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRectl
, 2);
1485 ::WinCalcFrameRect(pWnd
->m_hFrame
, &vRectl
, TRUE
);
1487 vSwpStb
.x
= vRectl
.xLeft
- vRstb
.xLeft
;
1488 vSwpStb
.y
= vRectl
.yBottom
- vRstb
.yBottom
;
1489 vSwpStb
.cx
= vRectl
.xRight
- vRectl
.xLeft
- 1; //?? -1 ??
1490 vSwpStb
.cy
= nHeight
;
1491 vSwpStb
.fl
= SWP_SIZE
|SWP_MOVE
| SWP_SHOW
;
1492 vSwpStb
.hwnd
= pWnd
->m_frameStatusBar
->GetHWND();
1493 vSwpStb
.hwndInsertBehind
= HWND_TOP
;
1495 ::WinQueryWindowRect(pWnd
->m_hFrame
, &vRectl
);
1496 ::WinMapWindowPoints(pWnd
->m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRectl
, 2);
1497 ::WinCalcFrameRect(pWnd
->m_hFrame
, &vRectl
, TRUE
);
1498 ::WinMapWindowPoints(HWND_DESKTOP
, pWnd
->m_hFrame
, (PPOINTL
)&vRectl
, 2);
1499 for(i
= 0; i
< nItemCount
; i
++)
1501 if(pWnd
->m_hWnd
&& pSWP
[i
].hwnd
== pWnd
->m_hWnd
)
1503 pSWP
[i
].x
= vRectl
.xLeft
;
1504 pSWP
[i
].y
= vRectl
.yBottom
+ nHeight
;
1505 pSWP
[i
].cx
= vRectl
.xRight
- vRectl
.xLeft
;
1506 pSWP
[i
].cy
= vRectl
.yTop
- vRectl
.yBottom
- nHeight
;
1507 pSWP
[i
].fl
= SWP_SIZE
| SWP_MOVE
| SWP_SHOW
;
1508 pSWP
[i
].hwndInsertBehind
= HWND_TOP
;
1512 rc
= MRFROMSHORT(nItemCount
);
1517 if(pWnd
&& pWnd
->m_fnOldWndProc
)
1518 rc
= pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
);
1520 rc
= ::WinDefWindowProc(hWnd
, ulMsg
, wParam
, lParam
);
1523 } // end of wxFrameMainWndProc
1525 MRESULT EXPENTRY
wxFrameWndProc(
1533 // Trace all ulMsgs - useful for the debugging
1536 wxFrame
* pWnd
= NULL
;
1538 parentHwnd
= WinQueryWindow(hWnd
,QW_PARENT
);
1539 pWnd
= (wxFrame
*) wxFindWinFromHandle((WXHWND
) hWnd
);
1542 // When we get the first message for the HWND we just created, we associate
1543 // it with wxWindow stored in wxWndHook
1546 MRESULT rc
= (MRESULT
)0;
1547 bool bProcessed
= FALSE
;
1550 // Stop right here if we don't have a valid handle in our wxWindow object.
1552 if (pWnd
&& !pWnd
->GetHWND())
1554 pWnd
->SetHWND((WXHWND
) hWnd
);
1555 rc
= pWnd
->OS2DefWindowProc(ulMsg
, wParam
, lParam
);
1561 rc
= pWnd
->OS2WindowProc(ulMsg
, wParam
, lParam
);
1563 rc
= ::WinDefWindowProc(hWnd
, ulMsg
, wParam
, lParam
);
1566 } // end of wxFrameWndProc
1568 MRESULT
wxFrame::OS2WindowProc(
1575 bool bProcessed
= FALSE
;
1581 // If we can't close, tell the system that we processed the
1582 // message - otherwise it would close us
1584 bProcessed
= !Close();
1591 wxPaintEvent vEvent
;
1593 hPS
= WinBeginPaint(m_hWnd
, 0L, &vRect
);
1594 ::WinFillRect(hPS
, &vRect
, CLR_BLUE
/* SYSCLR_WINDOW */);
1597 mRc
= (MRESULT
)FALSE
;
1598 vEvent
.SetEventObject(this);
1599 GetEventHandler()->ProcessEvent(vEvent
);
1610 UnpackCommand( (WXWPARAM
)wParam
1617 bProcessed
= HandleCommand( wId
1630 UnpackMenuSelect( wParam
1636 bProcessed
= HandleMenuSelect( wItem
1640 mRc
= (MRESULT
)TRUE
;
1646 SHORT nScxold
= SHORT1FROMMP(wParam
); // Old horizontal size.
1647 SHORT nScyold
= SHORT2FROMMP(wParam
); // Old vertical size.
1648 SHORT nScxnew
= SHORT1FROMMP(lParam
); // New horizontal size.
1649 SHORT nScynew
= SHORT2FROMMP(lParam
); // New vertical size.
1651 lParam
= MRFROM2SHORT( nScxnew
- 20
1655 bProcessed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), (WXUINT
)wParam
);
1656 mRc
= (MRESULT
)FALSE
;
1659 case WM_ERASEBACKGROUND
:
1661 // Return TRUE to request PM to paint the window background
1662 // in SYSCLR_WINDOW.
1665 mRc
= (MRESULT
)(TRUE
);
1668 case CM_QUERYDRAGIMAGE
:
1673 hIcon
= (HPOINTER
)::WinSendMsg(GetHWND(), WM_QUERYICON
, 0L, 0L);
1675 hIcon
= (HPOINTER
)m_hDefaultIcon
;
1676 mRc
= (MRESULT
)hIcon
;
1677 bProcessed
= mRc
!= 0;
1683 mRc
= wxWindow::OS2WindowProc( uMessage
1687 return (MRESULT
)mRc
;
1688 } // wxFrame::OS2WindowProc
1690 void wxFrame::SetClient(WXHWND c_Hwnd
)
1692 // Duh...nothing to do under OS/2
1695 void wxFrame::SetClient(
1699 wxWindow
* pOldClient
= this->GetClient();
1700 bool bClientHasFocus
= pOldClient
&& (pOldClient
== wxWindow::FindFocus());
1702 if(pOldClient
== pWindow
) // nothing to do
1704 if(pWindow
== NULL
) // just need to remove old client
1706 if(pOldClient
== NULL
) // nothing to do
1709 if(bClientHasFocus
)
1712 pOldClient
->Enable( FALSE
);
1713 pOldClient
->Show( FALSE
);
1714 ::WinSetWindowUShort(pOldClient
->GetHWND(), QWS_ID
, (USHORT
)pOldClient
->GetId());
1715 // to avoid OS/2 bug need to update frame
1716 ::WinSendMsg((HWND
)this->GetFrame(), WM_UPDATEFRAME
, (MPARAM
)~0, 0);
1721 // Else need to change client
1726 ::WinEnableWindowUpdate((HWND
)GetHWND(), FALSE
);
1729 pOldClient
->Enable(FALSE
);
1730 pOldClient
->Show(FALSE
);
1731 ::WinSetWindowUShort(pOldClient
->GetHWND(), QWS_ID
, (USHORT
)pOldClient
->GetId());
1733 pWindow
->Reparent(this);
1734 ::WinSetWindowUShort(pWindow
->GetHWND(), QWS_ID
, FID_CLIENT
);
1735 ::WinEnableWindowUpdate((HWND
)GetHWND(), TRUE
);
1737 pWindow
->Show(); // ensure client is showing
1738 if( this->IsShown() )
1741 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0);
1745 wxWindow
* wxFrame::GetClient()
1747 return wxFindWinFromHandle((WXHWND
)::WinWindowFromID(m_hFrame
, FID_CLIENT
));