1 /////////////////////////////////////////////////////////////////////////////
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
17 #include "wx/object.h"
18 #include "wx/dynarray.h"
21 #include "wx/string.h"
30 #include "wx/dialog.h"
31 #include "wx/settings.h"
32 #include "wx/dcclient.h"
35 #include "wx/os2/private.h"
38 #include "wx/statusbr.h"
39 #include "wx/generic/statusbr.h"
40 #endif // wxUSE_STATUSBAR
43 #include "wx/toolbar.h"
44 #endif // wxUSE_TOOLBAR
46 #include "wx/menuitem.h"
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 extern wxWindowList wxModelessWindows
;
54 extern wxList WXDLLEXPORT wxPendingDelete
;
55 extern wxChar wxFrameClassName
[];
57 #if wxUSE_MENUS_NATIVE
58 extern wxMenu
*wxCurrentPopupMenu
;
61 extern void wxAssociateWinWithHandle( HWND hWnd
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
70 EVT_ACTIVATE(wxFrame::OnActivate
)
71 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
74 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxWindow
)
76 // ============================================================================
78 // ============================================================================
80 // ----------------------------------------------------------------------------
81 // static class members
82 // ----------------------------------------------------------------------------
85 #if wxUSE_NATIVE_STATUSBAR
86 bool wxFrame::m_bUseNativeStatusBar
= TRUE
;
88 bool wxFrame::m_bUseNativeStatusBar
= FALSE
;
91 #endif //wxUSE_STATUSBAR
93 // ----------------------------------------------------------------------------
94 // creation/destruction
95 // ----------------------------------------------------------------------------
104 // Data to save/restore when calling ShowFullScreen
106 m_lFsOldWindowStyle
= 0L;
107 m_nFsStatusBarFields
= 0;
108 m_nFsStatusBarHeight
= 0;
109 m_nFsToolBarHeight
= 0;
110 m_bFsIsMaximized
= FALSE
;
111 m_bFsIsShowing
= FALSE
;
113 m_pWinLastFocused
= (wxWindow
*)NULL
;
123 memset(&m_vSwp
, 0, sizeof(SWP
));
124 memset(&m_vSwpClient
, 0, sizeof(SWP
));
125 memset(&m_vSwpTitleBar
, 0, sizeof(SWP
));
126 memset(&m_vSwpMenuBar
, 0, sizeof(SWP
));
127 memset(&m_vSwpHScroll
, 0, sizeof(SWP
));
128 memset(&m_vSwpVScroll
, 0, sizeof(SWP
));
129 memset(&m_vSwpStatusBar
, 0, sizeof(SWP
));
130 memset(&m_vSwpToolBar
, 0, sizeof(SWP
));
131 } // end of wxFrame::Init
133 bool wxFrame::Create(
136 , const wxString
& rsTitle
137 , const wxPoint
& rPos
138 , const wxSize
& rSize
140 , const wxString
& rsName
145 int nWidth
= rSize
.x
;
146 int nHeight
= rSize
.y
;
150 m_windowStyle
= lulStyle
;
151 m_frameMenuBar
= NULL
;
153 m_frameToolBar
= NULL
;
154 #endif //wxUSE_TOOLBAR
157 m_frameStatusBar
= NULL
;
158 #endif //wxUSE_STATUSBAR
160 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
165 m_windowId
= (int)NewControlId();
168 pParent
->AddChild(this);
172 if ((m_windowStyle
& wxFRAME_FLOAT_ON_PARENT
) == 0)
175 bOk
= OS2Create( m_windowId
189 wxTopLevelWindows
.Append(this);
190 wxModelessWindows
.Append(this);
193 } // end of wxFrame::Create
197 m_isBeingDeleted
= TRUE
;
199 wxTopLevelWindows
.DeleteObject(this);
203 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
205 wxTheApp
->SetTopWindow(NULL
);
207 if (wxTheApp
->GetExitOnFrameDelete())
209 ::WinPostMsg(NULL
, WM_QUIT
, 0, 0);
213 wxModelessWindows
.DeleteObject(this);
216 // For some reason, wxWindows can activate another task altogether
217 // when a frame is destroyed after a modal dialog has been invoked.
218 // Try to bring the parent to the top.
220 // MT:Only do this if this frame is currently the active window, else weird
221 // things start to happen.
223 if (wxGetActiveWindow() == this)
225 if (GetParent() && GetParent()->GetHWND())
227 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
237 } // end of wxFrame::~wxFrame
240 // IF we have child controls in the Frame's client we need to alter
241 // the y position, because, OS/2 controls are positioned relative to
242 // wxWindows orgin (top left) not the OS/2 origin (bottom left)
243 void wxFrame::AlterChildPos()
246 // OS/2 is the only OS concerned about this
248 wxWindow
* pChild
= NULL
;
249 wxControl
* pCtrl
= NULL
;
253 ::WinQueryWindowRect(GetHwnd(), &vRect
);
254 for (wxWindowList::Node
* pNode
= GetChildren().GetFirst();
256 pNode
= pNode
->GetNext())
258 wxWindow
* pChild
= pNode
->GetData();
260 ::WinQueryWindowPos(pChild
->GetHWND(), &vSwp
);
261 vSwp
.y
+= (vRect
.yTop
- m_vSwpClient
.cy
);
262 if (pChild
->IsKindOf(CLASSINFO(wxControl
)))
264 pCtrl
= wxDynamicCast(pChild
, wxControl
);
266 // Must deal with controls that have margins like ENTRYFIELD. The SWP
267 // struct of such a control will have and origin offset from its intended
268 // position by the width of the margins.
270 vSwp
.y
-= pCtrl
->GetYComp();
271 vSwp
.x
-= pCtrl
->GetXComp();
273 ::WinSetWindowPos( pChild
->GetHWND()
281 ::WinQueryWindowPos(pChild
->GetHWND(), &vSwp
);
284 } // end of wxFrame::AlterChildPos
287 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
289 void wxFrame::DoGetClientSize(
295 ::WinQueryWindowRect(GetHwnd(), &vRect
);
298 // No need to use statusbar code as in WIN32 as the FORMATFRAME
299 // window procedure ensures PM knows about the new frame client
300 // size internally. A ::WinQueryWindowRect is all that is needed!
304 *pX
= vRect
.xRight
- vRect
.xLeft
;
306 *pY
= vRect
.yTop
- vRect
.yBottom
;
307 } // end of wxFrame::DoGetClientSize
310 // Set the client size (i.e. leave the calculation of borders etc.
313 void wxFrame::DoSetClientSize(
318 HWND hWnd
= GetHwnd();
322 ::WinQueryWindowRect(GetHwnd(), &vRect
);
323 ::WinQueryWindowRect(GetHwnd(), &vRect2
);
326 // Find the difference between the entire window (title bar and all)
327 // and the client area; add this to the new client size to move the
328 // window. Remember OS/2's backwards y coord system!
330 int nActualWidth
= vRect2
.xRight
- vRect2
.xLeft
- vRect
.xRight
;
331 int nActualHeight
= vRect2
.yTop
+ vRect2
.yTop
- vRect
.yTop
;
334 wxStatusBar
* pStatusBar
= GetStatusBar();
336 if (pStatusBar
&& pStatusBar
->IsShown())
338 nActualHeight
+= pStatusBar
->GetSize().y
;
341 #endif // wxUSE_STATUSBAR
343 wxPoint
vPoint(GetClientAreaOrigin());
345 nActualWidth
+= vPoint
.x
;
346 nActualHeight
+= vPoint
.y
;
350 vPointl
.x
= vRect2
.xLeft
;
351 vPointl
.y
= vRect2
.yTop
;
353 ::WinSetWindowPos( hWnd
359 ,SWP_MOVE
| SWP_SIZE
| SWP_SHOW
362 wxSizeEvent
vEvent( wxSize( nWidth
367 vEvent
.SetEventObject(this);
368 GetEventHandler()->ProcessEvent(vEvent
);
369 } // end of wxFrame::DoSetClientSize
371 void wxFrame::DoGetSize(
378 ::WinQueryWindowRect(m_hFrame
, &vRect
);
379 *pWidth
= vRect
.xRight
- vRect
.xLeft
;
380 *pHeight
= vRect
.yTop
- vRect
.yBottom
;
381 } // end of wxFrame::DoGetSize
383 void wxFrame::DoGetPosition(
391 ::WinQueryWindowRect(m_hFrame
, &vRect
);
393 *pX
= vRect
.xRight
- vRect
.xLeft
;
394 *pY
= vRect
.yTop
- vRect
.yBottom
;
395 } // end of wxFrame::DoGetPosition
397 // ----------------------------------------------------------------------------
398 // variations around ::ShowWindow()
399 // ----------------------------------------------------------------------------
401 void wxFrame::DoShowWindow(
405 ::WinShowWindow(m_hFrame
, (BOOL
)bShowCmd
);
406 m_bIconized
= bShowCmd
== SWP_MINIMIZE
;
407 } // end of wxFrame::DoShowWindow
425 DoShowWindow(nShowCmd
);
429 wxActivateEvent
vEvent(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
431 ::WinQueryWindowPos(m_hFrame
, &vSwp
);
432 m_bIconized
= vSwp
.fl
& SWP_MINIMIZE
;
433 ::WinQueryWindowPos(m_hWnd
, &m_vSwpClient
);
434 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0);
435 ::WinEnableWindow(m_hFrame
, TRUE
);
436 vEvent
.SetEventObject(this);
437 GetEventHandler()->ProcessEvent(vEvent
);
442 // Try to highlight the correct window (the parent)
446 HWND hWndParent
= GetHwndOf(GetParent());
448 ::WinQueryWindowPos(hWndParent
, &vSwp
);
449 m_bIconized
= vSwp
.fl
& SWP_MINIMIZE
;
451 ::WinSetWindowPos( hWndParent
457 ,SWP_ZORDER
| SWP_ACTIVATE
| SWP_SHOW
| SWP_MOVE
459 ::WinEnableWindow(hWndParent
, TRUE
);
463 } // end of wxFrame::Show
465 void wxFrame::Iconize(
469 DoShowWindow(bIconize
? SWP_MINIMIZE
: SWP_RESTORE
);
470 } // end of wxFrame::Iconize
472 void wxFrame::Maximize(
475 DoShowWindow(bMaximize
? SWP_MAXIMIZE
: SWP_RESTORE
);
476 } // end of wxFrame::Maximize
478 void wxFrame::Restore()
480 DoShowWindow(SWP_RESTORE
);
481 } // end of wxFrame::Restore
483 bool wxFrame::IsIconized() const
487 ::WinQueryWindowPos(m_hFrame
, &vSwp
);
489 if (vSwp
.fl
& SWP_MINIMIZE
)
490 ((wxFrame
*)this)->m_bIconized
= TRUE
;
492 ((wxFrame
*)this)->m_bIconized
= FALSE
;
494 } // end of wxFrame::IsIconized
497 bool wxFrame::IsMaximized() const
502 ::WinQueryWindowPos(m_hFrame
, &vSwp
);
503 return (vSwp
.fl
& SWP_MAXIMIZE
);
504 } // end of wxFrame::IsMaximized
506 void wxFrame::SetIcon(
510 wxFrameBase::SetIcon(rIcon
);
512 if ((m_icon
.GetHICON()) != NULLHANDLE
)
514 ::WinSendMsg( m_hFrame
516 ,(MPARAM
)((HPOINTER
)m_icon
.GetHICON())
519 ::WinSendMsg( m_hFrame
525 } // end of wxFrame::SetIcon
528 wxStatusBar
* wxFrame::OnCreateStatusBar(
532 , const wxString
& rName
535 wxStatusBar
* pStatusBar
= NULL
;
540 pStatusBar
= wxFrameBase::OnCreateStatusBar( nNumber
549 ::WinSetParent( pStatusBar
->GetHWND()
553 ::WinSetOwner( pStatusBar
->GetHWND()
559 if(::WinIsWindowShowing(m_hFrame
))
560 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0);
563 } // end of wxFrame::OnCreateStatusBar
565 void wxFrame::PositionStatusBar()
572 // Native status bar positions itself
574 if (m_frameStatusBar
)
584 ::WinQueryWindowRect(m_hFrame
, &vRect
);
586 ::WinMapWindowPoints(m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRect
, 2);
588 ::WinCalcFrameRect(m_hFrame
, &vRect
, TRUE
);
589 nWidth
= vRect
.xRight
- vRect
.xLeft
;
590 nY
= nY
- (vRect
.yBottom
- vFRect
.yBottom
);
592 m_frameStatusBar
->GetSize( &nStatbarWidth
596 nY
= nY
- nStatbarHeight
;
598 // Since we wish the status bar to be directly under the client area,
599 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
601 m_frameStatusBar
->SetSize( vRect
.xLeft
- vFRect
.xLeft
606 if (!::WinQueryWindowPos(m_frameStatusBar
->GetHWND(), &vSwp
))
608 vError
= ::WinGetLastError(vHabmain
);
609 sError
= wxPMErrorToStr(vError
);
610 wxLogError("Error setting parent for StautsBar. Error: %s\n", sError
);
614 } // end of wxFrame::PositionStatusBar
615 #endif // wxUSE_STATUSBAR
617 #if wxUSE_MENUS_NATIVE
618 void wxFrame::DetachMenuBar()
622 m_frameMenuBar
->Detach();
623 m_frameMenuBar
= NULL
;
625 } // end of wxFrame::DetachMenuBar
627 void wxFrame::SetMenuBar(
633 HWND hTitlebar
= NULLHANDLE
;
634 HWND hHScroll
= NULLHANDLE
;
635 HWND hVScroll
= NULLHANDLE
;
636 HWND hMenuBar
= NULLHANDLE
;
648 // Actually remove the menu from the frame
650 m_hMenu
= (WXHMENU
)0;
651 InternalSetMenuBar();
653 else // set new non NULL menu bar
655 m_frameMenuBar
= NULL
;
658 // Can set a menubar several times.
659 // TODO: how to prevent a memory leak if you have a currently-unattached
660 // menubar? wxWindows assumes that the frame will delete the menu (otherwise
661 // there are problems for MDI).
663 if (pMenuBar
->GetHMenu())
665 m_hMenu
= pMenuBar
->GetHMenu();
670 m_hMenu
= pMenuBar
->Create();
674 InternalSetMenuBar();
675 m_frameMenuBar
= pMenuBar
;
676 pMenuBar
->Attach((wxFrame
*)this);
678 } // end of wxFrame::SetMenuBar
680 void wxFrame::AttachMenuBar(
684 wxFrameBase::AttachMenuBar(pMenubar
);
686 m_frameMenuBar
= pMenubar
;
691 // Actually remove the menu from the frame
693 m_hMenu
= (WXHMENU
)0;
694 InternalSetMenuBar();
696 else // Set new non NULL menu bar
699 // Can set a menubar several times.
701 if (pMenubar
->GetHMenu())
703 m_hMenu
= pMenubar
->GetHMenu();
707 if (pMenubar
->IsAttached())
710 m_hMenu
= pMenubar
->Create();
715 InternalSetMenuBar();
717 } // end of wxFrame::AttachMenuBar
719 void wxFrame::InternalSetMenuBar()
724 // Set the parent and owner of the menubar to be the frame
726 if (!::WinSetParent(m_hMenu
, m_hFrame
, FALSE
))
728 vError
= ::WinGetLastError(vHabmain
);
729 sError
= wxPMErrorToStr(vError
);
730 wxLogError("Error setting parent for submenu. Error: %s\n", sError
);
733 if (!::WinSetOwner(m_hMenu
, m_hFrame
))
735 vError
= ::WinGetLastError(vHabmain
);
736 sError
= wxPMErrorToStr(vError
);
737 wxLogError("Error setting parent for submenu. Error: %s\n", sError
);
739 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
740 } // end of wxFrame::InternalSetMenuBar
741 #endif // wxUSE_MENUS_NATIVE
744 // Responds to colour changes, and passes event on to children
746 void wxFrame::OnSysColourChanged(
747 wxSysColourChangedEvent
& rEvent
750 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
754 if (m_frameStatusBar
)
756 wxSysColourChangedEvent vEvent2
;
758 vEvent2
.SetEventObject(m_frameStatusBar
);
759 m_frameStatusBar
->GetEventHandler()->ProcessEvent(vEvent2
);
761 #endif //wxUSE_STATUSBAR
764 // Propagate the event to the non-top-level children
766 wxWindow::OnSysColourChanged(rEvent
);
767 } // end of wxFrame::OnSysColourChanged
769 // Pass TRUE to show full screen, FALSE to restore.
770 bool wxFrame::ShowFullScreen(
780 m_bFsIsShowing
= TRUE
;
784 wxToolBar
* pTheToolBar
= GetToolBar();
785 #endif //wxUSE_TOOLBAR
788 wxStatusBar
* pTheStatusBar
= GetStatusBar();
789 #endif //wxUSE_STATUSBAR
795 pTheToolBar
->GetSize(&nDummyWidth
, &m_nFsToolBarHeight
);
796 #endif //wxUSE_TOOLBAR
800 pTheStatusBar
->GetSize(&nDummyWidth
, &m_nFsStatusBarHeight
);
801 #endif //wxUSE_STATUSBAR
805 // Zap the toolbar, menubar, and statusbar
807 if ((lStyle
& wxFULLSCREEN_NOTOOLBAR
) && pTheToolBar
)
809 pTheToolBar
->SetSize(-1,0);
810 pTheToolBar
->Show(FALSE
);
812 #endif //wxUSE_TOOLBAR
814 if (lStyle
& wxFULLSCREEN_NOMENUBAR
)
816 ::WinSetParent(m_hMenu
, m_hFrame
, FALSE
);
817 ::WinSetOwner(m_hMenu
, m_hFrame
);
818 ::WinSendMsg((HWND
)m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
823 // Save the number of fields in the statusbar
825 if ((lStyle
& wxFULLSCREEN_NOSTATUSBAR
) && pTheStatusBar
)
827 m_nFsStatusBarFields
= pTheStatusBar
->GetFieldsCount();
828 SetStatusBar((wxStatusBar
*) NULL
);
829 delete pTheStatusBar
;
832 m_nFsStatusBarFields
= 0;
833 #endif //wxUSE_STATUSBAR
836 // Zap the frame borders
840 // Save the 'normal' window style
842 m_lFsOldWindowStyle
= ::WinQueryWindowULong(m_hFrame
, QWL_STYLE
);
845 // Save the old position, width & height, maximize state
847 m_vFsOldSize
= GetRect();
848 m_bFsIsMaximized
= IsMaximized();
851 // Decide which window style flags to turn off
853 LONG lNewStyle
= m_lFsOldWindowStyle
;
856 if (lStyle
& wxFULLSCREEN_NOBORDER
)
857 lOffFlags
|= FCF_BORDER
;
858 if (lStyle
& wxFULLSCREEN_NOCAPTION
)
859 lOffFlags
|= (FCF_TASKLIST
| FCF_SYSMENU
);
861 lNewStyle
&= (~lOffFlags
);
864 // Change our window style to be compatible with full-screen mode
866 ::WinSetWindowULong((HWND
)m_hFrame
, QWL_STYLE
, (ULONG
)lNewStyle
);
869 // Resize to the size of the desktop
875 ::WinQueryWindowRect(HWND_DESKTOP
, &vRect
);
876 nWidth
= vRect
.xRight
- vRect
.xLeft
;
878 // Rmember OS/2 is backwards!
880 nHeight
= vRect
.yTop
- vRect
.yBottom
;
887 // Now flush the window style cache and actually go full-screen
889 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
898 wxSizeEvent
vEvent( wxSize( nWidth
904 GetEventHandler()->ProcessEvent(vEvent
);
912 m_bFsIsShowing
= FALSE
;
915 wxToolBar
* pTheToolBar
= GetToolBar();
918 // Restore the toolbar, menubar, and statusbar
920 if (pTheToolBar
&& (m_lFsStyle
& wxFULLSCREEN_NOTOOLBAR
))
922 pTheToolBar
->SetSize(-1, m_nFsToolBarHeight
);
923 pTheToolBar
->Show(TRUE
);
925 #endif //wxUSE_TOOLBAR
928 if ((m_lFsStyle
& wxFULLSCREEN_NOSTATUSBAR
) && (m_nFsStatusBarFields
> 0))
930 CreateStatusBar(m_nFsStatusBarFields
);
931 // PositionStatusBar();
933 #endif //wxUSE_STATUSBAR
935 if ((m_lFsStyle
& wxFULLSCREEN_NOMENUBAR
) && (m_hMenu
!= 0))
937 ::WinSetParent(m_hMenu
, m_hFrame
, FALSE
);
938 ::WinSetOwner(m_hMenu
, m_hFrame
);
939 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
941 Maximize(m_bFsIsMaximized
);
943 ::WinSetWindowULong( m_hFrame
945 ,(ULONG
)m_lFsOldWindowStyle
947 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
957 } // end of wxFrame::ShowFullScreen
962 bool wxFrame::OS2Create(
965 , const wxChar
* zWclass
967 , const wxChar
* zTitle
975 ULONG ulCreateFlags
= 0L;
976 ULONG ulStyleFlags
= 0L;
977 ULONG ulExtraFlags
= 0L;
978 FRAMECDATA vFrameCtlData
;
979 HWND hParent
= NULLHANDLE
;
980 HWND hTitlebar
= NULLHANDLE
;
981 HWND hHScroll
= NULLHANDLE
;
982 HWND hVScroll
= NULLHANDLE
;
983 HWND hFrame
= NULLHANDLE
;
984 HWND hClient
= NULLHANDLE
;
991 m_hDefaultIcon
= (WXHICON
) (wxSTD_FRAME_ICON
? wxSTD_FRAME_ICON
: wxDEFAULT_FRAME_ICON
);
994 hParent
= GetWinHwnd(pParent
);
996 hParent
= HWND_DESKTOP
;
998 if (ulStyle
== wxDEFAULT_FRAME_STYLE
)
999 ulCreateFlags
= FCF_SIZEBORDER
| FCF_TITLEBAR
| FCF_SYSMENU
|
1000 FCF_MINMAX
| FCF_TASKLIST
;
1003 if ((ulStyle
& wxCAPTION
) == wxCAPTION
)
1004 ulCreateFlags
= FCF_TASKLIST
;
1006 ulCreateFlags
= FCF_NOMOVEWITHOWNER
;
1008 if ((ulStyle
& wxVSCROLL
) == wxVSCROLL
)
1009 ulCreateFlags
|= FCF_VERTSCROLL
;
1010 if ((ulStyle
& wxHSCROLL
) == wxHSCROLL
)
1011 ulCreateFlags
|= FCF_HORZSCROLL
;
1012 if (ulStyle
& wxMINIMIZE_BOX
)
1013 ulCreateFlags
|= FCF_MINBUTTON
;
1014 if (ulStyle
& wxMAXIMIZE_BOX
)
1015 ulCreateFlags
|= FCF_MAXBUTTON
;
1016 if (ulStyle
& wxTHICK_FRAME
)
1017 ulCreateFlags
|= FCF_DLGBORDER
;
1018 if (ulStyle
& wxSYSTEM_MENU
)
1019 ulCreateFlags
|= FCF_SYSMENU
;
1020 if (ulStyle
& wxCAPTION
)
1021 ulCreateFlags
|= FCF_TASKLIST
;
1022 if (ulStyle
& wxCLIP_CHILDREN
)
1024 // Invalid for frame windows under PM
1027 if (ulStyle
& wxTINY_CAPTION_VERT
)
1028 ulCreateFlags
|= FCF_TASKLIST
;
1029 if (ulStyle
& wxTINY_CAPTION_HORIZ
)
1030 ulCreateFlags
|= FCF_TASKLIST
;
1032 if ((ulStyle
& wxTHICK_FRAME
) == 0)
1033 ulCreateFlags
|= FCF_BORDER
;
1034 if (ulStyle
& wxFRAME_TOOL_WINDOW
)
1035 ulExtraFlags
= kFrameToolWindow
;
1037 if (ulStyle
& wxSTAY_ON_TOP
)
1038 ulCreateFlags
|= FCF_SYSMODAL
;
1040 if ((ulStyle
& wxMINIMIZE
) || (ulStyle
& wxICONIZE
))
1041 ulStyleFlags
|= WS_MINIMIZED
;
1042 if (ulStyle
& wxMAXIMIZE
)
1043 ulStyleFlags
|= WS_MAXIMIZED
;
1046 // Clear the visible flag, we always call show
1048 ulStyleFlags
&= (unsigned long)~WS_VISIBLE
;
1049 m_bIconized
= FALSE
;
1052 // Set the frame control block
1054 vFrameCtlData
.cb
= sizeof(vFrameCtlData
);
1055 vFrameCtlData
.flCreateFlags
= ulCreateFlags
;
1056 vFrameCtlData
.hmodResources
= 0L;
1057 vFrameCtlData
.idResources
= 0;
1060 // Create the frame window: We break ranks with other ports now
1061 // and instead of calling down into the base wxWindow class' OS2Create
1062 // we do all our own stuff here. We will set the needed pieces
1063 // of wxWindow manually, here.
1066 hFrame
= ::WinCreateStdWindow( hParent
1067 ,ulStyleFlags
// frame-window style
1068 ,&ulCreateFlags
// window style
1069 ,(PSZ
)zWclass
// class name
1070 ,(PSZ
)zTitle
// window title
1071 ,0L // default client style
1072 ,NULLHANDLE
// resource in executable file
1074 ,&hClient
// receives client window handle
1078 vError
= ::WinGetLastError(vHabmain
);
1079 sError
= wxPMErrorToStr(vError
);
1080 wxLogError("Error creating frame. Error: %s\n", sError
);
1085 // wxWindow class' m_hWnd set here and needed associations
1089 wxAssociateWinWithHandle(m_hWnd
, this);
1090 wxAssociateWinWithHandle(m_hFrame
, this);
1092 m_backgroundColour
.Set(wxString("GREY"));
1094 LONG lColor
= (LONG
)m_backgroundColour
.GetPixel();
1096 if (!::WinSetPresParam( m_hWnd
1102 vError
= ::WinGetLastError(vHabmain
);
1103 sError
= wxPMErrorToStr(vError
);
1104 wxLogError("Error creating frame. Error: %s\n", sError
);
1109 // Now need to subclass window. Instead of calling the SubClassWin in wxWindow
1110 // we manually subclass here because we don't want to use the main wxWndProc
1113 m_fnOldWndProc
= (WXFARPROC
) ::WinSubclassWindow(m_hFrame
, (PFNWP
)wxFrameMainWndProc
);
1116 // Now size everything. If adding a menu the client will need to be resized.
1121 nY
= pParent
->GetSize().y
- (nY
+ nHeight
);
1127 ::WinQueryWindowRect(HWND_DESKTOP
, &vRect
);
1128 nY
= vRect
.yTop
- (nY
+ nHeight
);
1130 if (!::WinSetWindowPos( m_hFrame
1136 ,SWP_SIZE
| SWP_MOVE
| SWP_ACTIVATE
| SWP_ZORDER
1139 vError
= ::WinGetLastError(vHabmain
);
1140 sError
= wxPMErrorToStr(vError
);
1141 wxLogError("Error sizing frame. Error: %s\n", sError
);
1145 } // end of wxFrame::OS2Create
1148 // Default activation behaviour - set the focus for the first child
1151 void wxFrame::OnActivate(
1152 wxActivateEvent
& rEvent
1155 if ( rEvent
.GetActive() )
1157 // restore focus to the child which was last focused
1158 wxLogTrace(_T("focus"), _T("wxFrame %08x activated."), m_hWnd
);
1160 wxWindow
* pParent
= m_pWinLastFocused
? m_pWinLastFocused
->GetParent()
1167 wxSetFocusToChild( pParent
1171 else // deactivating
1174 // Remember the last focused child if it is our child
1176 m_pWinLastFocused
= FindFocus();
1178 for (wxWindowList::Node
* pNode
= GetChildren().GetFirst();
1180 pNode
= pNode
->GetNext())
1182 // FIXME all this is totally bogus - we need to do the same as wxPanel,
1183 // but how to do it without duplicating the code?
1186 wxWindow
* pChild
= pNode
->GetData();
1188 if (!pChild
->IsTopLevel()
1190 && !wxDynamicCast(pChild
, wxToolBar
)
1191 #endif // wxUSE_TOOLBAR
1193 && !wxDynamicCast(pChild
, wxStatusBar
)
1194 #endif // wxUSE_STATUSBAR
1202 } // end of wxFrame::OnActivate
1204 // ----------------------------------------------------------------------------
1205 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1206 // from the client area, so the client area is what's really available for the
1208 // ----------------------------------------------------------------------------
1210 // Checks if there is a toolbar, and returns the first free client position
1211 wxPoint
wxFrame::GetClientAreaOrigin() const
1213 wxPoint
vPoint(0, 0);
1221 GetToolBar()->GetSize( &nWidth
1225 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
1231 // PM is backwards from windows
1232 vPoint
.y
+= nHeight
;
1235 #endif //wxUSE_TOOLBAR
1237 } // end of wxFrame::GetClientAreaOrigin
1239 // ----------------------------------------------------------------------------
1240 // tool/status bar stuff
1241 // ----------------------------------------------------------------------------
1245 wxToolBar
* wxFrame::CreateToolBar(
1248 , const wxString
& rName
1251 if (wxFrameBase::CreateToolBar( lStyle
1258 return m_frameToolBar
;
1259 } // end of wxFrame::CreateToolBar
1261 void wxFrame::PositionToolBar()
1266 ::WinQueryWindowRect(GetHwnd(), &vRect
);
1274 GetStatusBar()->GetClientSize( &nStatusX
1277 // PM is backwards from windows
1278 vRect
.yBottom
+= nStatusY
;
1280 #endif // wxUSE_STATUSBAR
1282 if ( m_frameToolBar
)
1287 m_frameToolBar
->GetSize( &nToolbarWidth
1291 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
1293 nToolbarHeight
= vRect
.yBottom
;
1297 nToolbarWidth
= vRect
.xRight
;
1301 // Use the 'real' PM position here
1303 GetToolBar()->SetSize( 0
1307 ,wxSIZE_NO_ADJUSTMENTS
1310 } // end of wxFrame::PositionToolBar
1311 #endif // wxUSE_TOOLBAR
1313 // ----------------------------------------------------------------------------
1314 // frame state (iconized/maximized/...)
1315 // ----------------------------------------------------------------------------
1318 // propagate our state change to all child frames: this allows us to emulate X
1319 // Windows behaviour where child frames float independently of the parent one
1320 // on the desktop, but are iconized/restored with it
1322 void wxFrame::IconizeChildFrames(
1326 for (wxWindowList::Node
* pNode
= GetChildren().GetFirst();
1328 pNode
= pNode
->GetNext() )
1330 wxWindow
* pWin
= pNode
->GetData();
1332 if (pWin
->IsKindOf(CLASSINFO(wxFrame
)) )
1334 ((wxFrame
*)pWin
)->Iconize(bIconize
);
1337 } // end of wxFrame::IconizeChildFrames
1339 // ===========================================================================
1340 // message processing
1341 // ===========================================================================
1343 // ---------------------------------------------------------------------------
1345 // ---------------------------------------------------------------------------
1346 bool wxFrame::OS2TranslateMessage(
1351 // try the menu bar accels
1353 wxMenuBar
* pMenuBar
= GetMenuBar();
1358 #if wxUSE_ACCEL && wxUSE_MENUS_NATIVE
1359 const wxAcceleratorTable
& rAcceleratorTable
= pMenuBar
->GetAccelTable();
1360 return rAcceleratorTable
.Translate(GetHWND(), pMsg
);
1363 #endif //wxUSE_ACCEL
1364 } // end of wxFrame::OS2TranslateMessage
1366 // ---------------------------------------------------------------------------
1367 // our private (non virtual) message handlers
1368 // ---------------------------------------------------------------------------
1369 bool wxFrame::HandlePaint()
1373 if (::WinQueryUpdateRect(GetHWND(), &vRect
))
1378 // Icons in PM are the same as "pointers"
1383 hIcon
= (HPOINTER
)::WinSendMsg(m_hFrame
, WM_QUERYICON
, 0L, 0L);
1385 hIcon
= (HPOINTER
)m_hDefaultIcon
;
1388 // Hold a pointer to the dc so long as the OnPaint() message
1389 // is being processed
1392 HPS hPs
= ::WinBeginPaint(GetHwnd(), NULLHANDLE
, &vRect2
);
1395 // Erase background before painting or we get white background
1397 OS2DefWindowProc(WM_ERASEBACKGROUND
, (MPARAM
)hPs
, (MPARAM
)&vRect2
);
1404 ::WinQueryWindowRect(GetHwnd(), &vRect3
);
1406 static const int nIconWidth
= 32;
1407 static const int nIconHeight
= 32;
1408 int nIconX
= (int)((vRect3
.xRight
- nIconWidth
)/2);
1409 int nIconY
= (int)((vRect3
.yBottom
+ nIconHeight
)/2);
1411 ::WinDrawPointer(hPs
, nIconX
, nIconY
, hIcon
, DP_NORMAL
);
1418 if (!wxWindow::HandlePaint())
1423 hPS
= ::WinBeginPaint( GetHwnd()
1429 ::GpiCreateLogColorTable( hPS
1433 ,(LONG
)wxTheColourDatabase
->m_nSize
1434 ,(PLONG
)wxTheColourDatabase
->m_palTable
1436 ::GpiCreateLogColorTable( hPS
1446 ,GetBackgroundColour().GetPixel()
1456 // nothing to paint - processed
1460 } // end of wxFrame::HandlePaint
1462 bool wxFrame::HandleSize(
1468 bool bProcessed
= FALSE
;
1474 // Only do it it if we were iconized before, otherwise resizing the
1475 // parent frame has a curious side effect of bringing it under it's
1481 // restore all child frames too
1483 IconizeChildFrames(FALSE
);
1484 (void)SendIconizeEvent(FALSE
);
1491 m_bIconized
= FALSE
;
1496 // Iconize all child frames too
1498 IconizeChildFrames(TRUE
);
1499 (void)SendIconizeEvent();
1507 // forward WM_SIZE to status bar control
1509 #if wxUSE_NATIVE_STATUSBAR
1510 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
1512 wxSizeEvent
vEvent( wxSize( nX
1515 ,m_frameStatusBar
->GetId()
1518 vEvent
.SetEventObject(m_frameStatusBar
);
1519 m_frameStatusBar
->OnSize(vEvent
);
1521 #endif // wxUSE_NATIVE_STATUSBAR
1523 PositionStatusBar();
1526 #endif // wxUSE_TOOLBAR
1528 wxSizeEvent
vEvent( wxSize( nX
1534 vEvent
.SetEventObject(this);
1535 bProcessed
= GetEventHandler()->ProcessEvent(vEvent
);
1539 } // end of wxFrame::HandleSize
1541 bool wxFrame::HandleCommand(
1550 // In case it's e.g. a toolbar.
1552 wxWindow
* pWin
= wxFindWinFromHandle(hControl
);
1555 return pWin
->OS2Command( nCmd
1561 // Handle here commands from menus and accelerators
1563 if (nCmd
== CMDSRC_MENU
|| nCmd
== CMDSRC_ACCELERATOR
)
1565 #if wxUSE_MENUS_NATIVE
1566 if (wxCurrentPopupMenu
)
1568 wxMenu
* pPopupMenu
= wxCurrentPopupMenu
;
1570 wxCurrentPopupMenu
= NULL
;
1572 return pPopupMenu
->OS2Command( nCmd
1579 if (ProcessCommand(nId
))
1585 } // end of wxFrame::HandleCommand
1587 bool wxFrame::HandleMenuSelect(
1598 rc
= ::WinSendMsg(hMenu
, MM_QUERYITEM
, MPFROM2SHORT(nItem
, TRUE
), (MPARAM
)&mItem
);
1600 if(rc
&& !(mItem
.afStyle
& (MIS_SUBMENU
| MIS_SEPARATOR
)))
1602 wxMenuEvent
vEvent(wxEVT_MENU_HIGHLIGHT
, nItem
);
1604 vEvent
.SetEventObject(this);
1605 GetEventHandler()->ProcessEvent(vEvent
); // return value would be ignored by PM
1609 } // end of wxFrame::HandleMenuSelect
1611 // ---------------------------------------------------------------------------
1612 // Main Frame window proc
1613 // ---------------------------------------------------------------------------
1614 MRESULT EXPENTRY
wxFrameMainWndProc(
1621 MRESULT rc
= (MRESULT
)0;
1622 bool bProcessed
= FALSE
;
1623 wxFrame
* pWnd
= NULL
;
1625 pWnd
= (wxFrame
*) wxFindWinFromHandle((WXHWND
) hWnd
);
1628 case WM_QUERYFRAMECTLCOUNT
:
1629 if(pWnd
&& pWnd
->m_fnOldWndProc
)
1631 USHORT uItemCount
= SHORT1FROMMR(pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
));
1633 rc
= MRFROMSHORT(uItemCount
);
1637 case WM_FORMATFRAME
:
1638 /////////////////////////////////////////////////////////////////////////////////
1639 // Applications that subclass frame controls may find that the frame is already
1640 // subclassed the number of frame controls is variable.
1641 // The WM_FORMATFRAME and WM_QUERYFRAMECTLCOUNT messages must always be
1642 // subclassed by calling the previous window procedure and modifying its result.
1643 ////////////////////////////////////////////////////////////////////////////////
1653 pSWP
= (PSWP
)PVOIDFROMMP(wParam
);
1654 nItemCount
= SHORT1FROMMR(pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
));
1655 if(pWnd
->m_frameStatusBar
)
1657 ::WinQueryWindowRect(pWnd
->m_frameStatusBar
->GetHWND(), &vRstb
);
1658 pWnd
->m_frameStatusBar
->GetSize(NULL
, &nHeight
);
1659 ::WinQueryWindowRect(pWnd
->m_hFrame
, &vRectl
);
1660 ::WinMapWindowPoints(pWnd
->m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRectl
, 2);
1662 ::WinCalcFrameRect(pWnd
->m_hFrame
, &vRectl
, TRUE
);
1664 vSwpStb
.x
= vRectl
.xLeft
- vRstb
.xLeft
;
1665 vSwpStb
.y
= vRectl
.yBottom
- vRstb
.yBottom
;
1666 vSwpStb
.cx
= vRectl
.xRight
- vRectl
.xLeft
- 1; //?? -1 ??
1667 vSwpStb
.cy
= nHeight
;
1668 vSwpStb
.fl
= SWP_SIZE
|SWP_MOVE
| SWP_SHOW
;
1669 vSwpStb
.hwnd
= pWnd
->m_frameStatusBar
->GetHWND();
1670 vSwpStb
.hwndInsertBehind
= HWND_TOP
;
1672 ::WinQueryWindowRect(pWnd
->m_hFrame
, &vRectl
);
1673 ::WinMapWindowPoints(pWnd
->m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRectl
, 2);
1674 ::WinCalcFrameRect(pWnd
->m_hFrame
, &vRectl
, TRUE
);
1675 ::WinMapWindowPoints(HWND_DESKTOP
, pWnd
->m_hFrame
, (PPOINTL
)&vRectl
, 2);
1676 for(i
= 0; i
< nItemCount
; i
++)
1678 if(pWnd
->m_hWnd
&& pSWP
[i
].hwnd
== pWnd
->m_hWnd
)
1680 pSWP
[i
].x
= vRectl
.xLeft
;
1681 pSWP
[i
].y
= vRectl
.yBottom
+ nHeight
;
1682 pSWP
[i
].cx
= vRectl
.xRight
- vRectl
.xLeft
;
1683 pSWP
[i
].cy
= vRectl
.yTop
- vRectl
.yBottom
- nHeight
;
1684 pSWP
[i
].fl
= SWP_SIZE
| SWP_MOVE
| SWP_SHOW
;
1685 pSWP
[i
].hwndInsertBehind
= HWND_TOP
;
1689 rc
= MRFROMSHORT(nItemCount
);
1694 if(pWnd
&& pWnd
->m_fnOldWndProc
)
1695 rc
= pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
);
1697 rc
= ::WinDefWindowProc(hWnd
, ulMsg
, wParam
, lParam
);
1700 } // end of wxFrameMainWndProc
1702 MRESULT EXPENTRY
wxFrameWndProc(
1710 // Trace all ulMsgs - useful for the debugging
1713 wxFrame
* pWnd
= NULL
;
1715 parentHwnd
= WinQueryWindow(hWnd
,QW_PARENT
);
1716 pWnd
= (wxFrame
*) wxFindWinFromHandle((WXHWND
) hWnd
);
1719 // When we get the first message for the HWND we just created, we associate
1720 // it with wxWindow stored in wxWndHook
1723 MRESULT rc
= (MRESULT
)0;
1724 bool bProcessed
= FALSE
;
1727 // Stop right here if we don't have a valid handle in our wxWindow object.
1729 if (pWnd
&& !pWnd
->GetHWND())
1731 pWnd
->SetHWND((WXHWND
) hWnd
);
1732 rc
= pWnd
->OS2DefWindowProc(ulMsg
, wParam
, lParam
);
1738 rc
= pWnd
->OS2WindowProc(ulMsg
, wParam
, lParam
);
1740 rc
= ::WinDefWindowProc(hWnd
, ulMsg
, wParam
, lParam
);
1743 } // end of wxFrameWndProc
1745 MRESULT
wxFrame::OS2WindowProc(
1752 bool bProcessed
= FALSE
;
1758 // If we can't close, tell the system that we processed the
1759 // message - otherwise it would close us
1761 bProcessed
= !Close();
1765 bProcessed
= HandlePaint();
1766 mRc
= (MRESULT
)FALSE
;
1769 case WM_ERASEBACKGROUND
:
1771 // Returning TRUE to requests PM to paint the window background
1772 // in SYSCLR_WINDOW. We capture this here because the PS returned
1773 // in Frames is the PS for the whole frame, which we can't really
1774 // use at all. If you want to paint a different background, do it
1775 // in an OnPaint using a wxPaintDC.
1777 mRc
= (MRESULT
)(TRUE
);
1786 UnpackCommand( (WXWPARAM
)wParam
1793 bProcessed
= HandleCommand( wId
1806 UnpackMenuSelect( wParam
1812 bProcessed
= HandleMenuSelect( wItem
1816 mRc
= (MRESULT
)TRUE
;
1822 SHORT nScxold
= SHORT1FROMMP(wParam
); // Old horizontal size.
1823 SHORT nScyold
= SHORT2FROMMP(wParam
); // Old vertical size.
1824 SHORT nScxnew
= SHORT1FROMMP(lParam
); // New horizontal size.
1825 SHORT nScynew
= SHORT2FROMMP(lParam
); // New vertical size.
1827 lParam
= MRFROM2SHORT( nScxnew
- 20
1831 bProcessed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), (WXUINT
)wParam
);
1832 mRc
= (MRESULT
)FALSE
;
1835 case CM_QUERYDRAGIMAGE
:
1840 hIcon
= (HPOINTER
)::WinSendMsg(GetHWND(), WM_QUERYICON
, 0L, 0L);
1842 hIcon
= (HPOINTER
)m_hDefaultIcon
;
1843 mRc
= (MRESULT
)hIcon
;
1844 bProcessed
= mRc
!= 0;
1850 mRc
= wxWindow::OS2WindowProc( uMessage
1854 return (MRESULT
)mRc
;
1855 } // wxFrame::OS2WindowProc
1857 void wxFrame::SetClient(WXHWND c_Hwnd
)
1859 // Duh...nothing to do under OS/2
1862 void wxFrame::SetClient(
1866 wxWindow
* pOldClient
= this->GetClient();
1867 bool bClientHasFocus
= pOldClient
&& (pOldClient
== wxWindow::FindFocus());
1869 if(pOldClient
== pWindow
) // nothing to do
1871 if(pWindow
== NULL
) // just need to remove old client
1873 if(pOldClient
== NULL
) // nothing to do
1876 if(bClientHasFocus
)
1879 pOldClient
->Enable( FALSE
);
1880 pOldClient
->Show( FALSE
);
1881 ::WinSetWindowUShort(pOldClient
->GetHWND(), QWS_ID
, (USHORT
)pOldClient
->GetId());
1882 // to avoid OS/2 bug need to update frame
1883 ::WinSendMsg((HWND
)this->GetFrame(), WM_UPDATEFRAME
, (MPARAM
)~0, 0);
1888 // Else need to change client
1893 ::WinEnableWindowUpdate((HWND
)GetHWND(), FALSE
);
1896 pOldClient
->Enable(FALSE
);
1897 pOldClient
->Show(FALSE
);
1898 ::WinSetWindowUShort(pOldClient
->GetHWND(), QWS_ID
, (USHORT
)pOldClient
->GetId());
1900 pWindow
->Reparent(this);
1901 ::WinSetWindowUShort(pWindow
->GetHWND(), QWS_ID
, FID_CLIENT
);
1902 ::WinEnableWindowUpdate((HWND
)GetHWND(), TRUE
);
1904 pWindow
->Show(); // ensure client is showing
1905 if( this->IsShown() )
1908 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0);
1912 wxWindow
* wxFrame::GetClient()
1914 return wxFindWinFromHandle((WXHWND
)::WinWindowFromID(m_hFrame
, FID_CLIENT
));