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"
21 #include "wx/dialog.h"
22 #include "wx/settings.h"
23 #include "wx/dcclient.h"
26 #include "wx/os2/private.h"
29 #include "wx/statusbr.h"
30 #include "wx/generic/statusbr.h"
31 #endif // wxUSE_STATUSBAR
34 #include "wx/toolbar.h"
35 #endif // wxUSE_TOOLBAR
37 #include "wx/menuitem.h"
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 extern wxWindowList wxModelessWindows
;
45 extern wxList WXDLLEXPORT wxPendingDelete
;
46 extern wxChar wxFrameClassName
[];
47 extern wxMenu
*wxCurrentPopupMenu
;
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
54 EVT_ACTIVATE(wxFrame::OnActivate
)
55 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
58 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxWindow
)
60 // ============================================================================
62 // ============================================================================
64 // ----------------------------------------------------------------------------
65 // static class members
66 // ----------------------------------------------------------------------------
68 #if wxUSE_NATIVE_STATUSBAR
69 bool wxFrame::m_bUseNativeStatusBar
= TRUE
;
71 bool wxFrame::m_bUseNativeStatusBar
= FALSE
;
74 // ----------------------------------------------------------------------------
75 // creation/destruction
76 // ----------------------------------------------------------------------------
85 // Data to save/restore when calling ShowFullScreen
87 m_lFsOldWindowStyle
= 0L;
88 m_nFsStatusBarFields
= 0;
89 m_nFsStatusBarHeight
= 0;
90 m_nFsToolBarHeight
= 0;
91 m_bFsIsMaximized
= FALSE
;
92 m_bFsIsShowing
= FALSE
;
94 m_pWinLastFocused
= (wxWindow
*)NULL
;
99 memset(&m_vSwp
, 0, sizeof(SWP
));
100 memset(&m_vSwpClient
, 0, sizeof(SWP
));
101 memset(&m_vSwpTitleBar
, 0, sizeof(SWP
));
102 memset(&m_vSwpMenuBar
, 0, sizeof(SWP
));
103 memset(&m_vSwpHScroll
, 0, sizeof(SWP
));
104 memset(&m_vSwpVScroll
, 0, sizeof(SWP
));
105 memset(&m_vSwpStatusBar
, 0, sizeof(SWP
));
106 memset(&m_vSwpToolBar
, 0, sizeof(SWP
));
107 } // end of wxFrame::Init
109 bool wxFrame::Create(
112 , const wxString
& rsTitle
113 , const wxPoint
& rPos
114 , const wxSize
& rSize
116 , const wxString
& rsName
121 int nWidth
= rSize
.x
;
122 int nHeight
= rSize
.y
;
125 m_windowStyle
= lulStyle
;
126 m_frameMenuBar
= NULL
;
127 m_frameToolBar
= NULL
;
128 m_frameStatusBar
= NULL
;
130 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
135 m_windowId
= (int)NewControlId();
138 pParent
->AddChild(this);
142 if ((m_windowStyle
& wxFRAME_FLOAT_ON_PARENT
) == 0)
146 wxTopLevelWindows
.Append(this);
148 OS2Create( m_windowId
160 wxModelessWindows
.Append(this);
162 } // end of wxFrame::Create
166 m_isBeingDeleted
= TRUE
;
168 wxTopLevelWindows
.DeleteObject(this);
172 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
174 wxTheApp
->SetTopWindow(NULL
);
176 if (wxTheApp
->GetExitOnFrameDelete())
178 ::WinPostMsg(NULL
, WM_QUIT
, 0, 0);
181 wxModelessWindows
.DeleteObject(this);
184 // For some reason, wxWindows can activate another task altogether
185 // when a frame is destroyed after a modal dialog has been invoked.
186 // Try to bring the parent to the top.
188 // MT:Only do this if this frame is currently the active window, else weird
189 // things start to happen.
191 if (wxGetActiveWindow() == this)
193 if (GetParent() && GetParent()->GetHWND())
195 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
205 } // end of wxFrame::~wxFrame
208 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
210 void wxFrame::DoGetClientSize(
216 // OS/2 PM's coordinates go from bottom-left not
217 // top-left thus the += instead of the -=
222 // PM has no GetClientRect that inherantly knows about the client window
223 // We have to explicitly go fetch it!
225 ::WinQueryWindowRect(GetHwnd(), &vRect
);
228 if ( GetStatusBar() )
233 GetStatusBar()->GetClientSize( &nStatusX
236 vRect
.yBottom
+= nStatusY
;
238 #endif // wxUSE_STATUSBAR
240 wxPoint
vPoint(GetClientAreaOrigin());
242 vRect
.yBottom
+= vPoint
.y
;
243 vRect
.xRight
-= vPoint
.x
;
249 } // end of wxFrame::DoGetClientSize
252 // Set the client size (i.e. leave the calculation of borders etc.
255 void wxFrame::DoSetClientSize(
260 HWND hWnd
= GetHwnd();
264 ::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(GetHWND(), &vRect
);
324 *pWidth
= vRect
.xRight
- vRect
.xLeft
;
325 *pHeight
= vRect
.yTop
- vRect
.yBottom
;
326 } // end of wxFrame::DoGetSize
328 void wxFrame::DoGetPosition(
336 ::WinQueryWindowRect(GetHWND(), &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(GetHWND(), (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(GetHWND(), &vSwp
);
373 m_bIconized
= vSwp
.fl
& SWP_MINIMIZE
;
374 ::WinEnableWindow(GetHWND(), TRUE
);
375 vEvent
.SetEventObject(this);
376 GetEventHandler()->ProcessEvent(vEvent
);
381 // Try to highlight the correct window (the parent)
385 HWND hWndParent
= GetHwndOf(GetParent());
387 ::WinQueryWindowPos(hWndParent
, &vSwp
);
388 m_bIconized
= vSwp
.fl
& SWP_MINIMIZE
;
390 ::WinSetWindowPos( hWndParent
396 ,SWP_ZORDER
| SWP_ACTIVATE
| SWP_SHOW
| SWP_MOVE
398 ::WinEnableWindow(hWndParent
, TRUE
);
402 } // end of wxFrame::Show
404 void wxFrame::Iconize(
408 DoShowWindow(bIconize
? SWP_MINIMIZE
: SWP_RESTORE
);
409 } // end of wxFrame::Iconize
411 void wxFrame::Maximize(
414 DoShowWindow(bMaximize
? SWP_MAXIMIZE
: SWP_RESTORE
);
415 } // end of wxFrame::Maximize
417 void wxFrame::Restore()
419 DoShowWindow(SWP_RESTORE
);
420 } // end of wxFrame::Restore
422 bool wxFrame::IsIconized() const
426 ::WinQueryWindowPos(GetHwnd(), &vSwp
);
428 if (vSwp
.fl
& SWP_MINIMIZE
)
429 ((wxFrame
*)this)->m_bIconized
= TRUE
;
431 ((wxFrame
*)this)->m_bIconized
= FALSE
;
433 } // end of wxFrame::IsIconized
436 bool wxFrame::IsMaximized() const
441 ::WinQueryWindowPos(GetHWND(), &vSwp
);
442 return (vSwp
.fl
& SWP_MAXIMIZE
);
443 } // end of wxFrame::IsMaximized
445 void wxFrame::SetIcon(
449 wxFrameBase::SetIcon(rIcon
);
451 if ((m_icon
.GetHICON()) != NULLHANDLE
)
453 ::WinSendMsg( GetHWND()
455 ,(MPARAM
)((HPOINTER
)m_icon
.GetHICON())
458 ::WinSendMsg( GetHWND()
464 } // end of wxFrame::SetIcon
467 wxStatusBar
* wxFrame::OnCreateStatusBar(
471 , const wxString
& rName
474 wxStatusBar
* pStatusBar
= NULL
;
480 pStatusBar
= wxFrameBase::OnCreateStatusBar( nNumber
486 // The default parent set for the Statusbar is m_hWnd which, of course,
487 // is the handle to the client window of the frame. We don't want that,
488 // so we have to set the parent to actually be the Frame.
490 hWnd
= pStatusBar
->GetHWND();
491 if (!::WinSetParent(hWnd
, GetHWND(), FALSE
))
493 vError
= ::WinGetLastError(vHabmain
);
494 sError
= wxPMErrorToStr(vError
);
495 wxLogError("Error setting parent for statusbar. Error: %s\n", sError
);
500 // Also we need to reset it positioning to enable the SHOW attribute
502 if (!::WinQueryWindowPos((HWND
)pStatusBar
->GetHWND(), &vSwp
))
504 vError
= ::WinGetLastError(vHabmain
);
505 sError
= wxPMErrorToStr(vError
);
506 wxLogError("Error querying frame for statusbar position. Error: %s\n", sError
);
509 if (!::WinSetWindowPos( (HWND
)pStatusBar
->GetHWND()
515 ,SWP_SIZE
| SWP_MOVE
| SWP_SHOW
| SWP_ZORDER
518 vError
= ::WinGetLastError(vHabmain
);
519 sError
= wxPMErrorToStr(vError
);
520 wxLogError("Error setting statusbar position. Error: %s\n", sError
);
524 } // end of wxFrame::OnCreateStatusBar
526 void wxFrame::PositionStatusBar()
533 // Native status bar positions itself
535 if (m_frameStatusBar
)
544 ::WinQueryWindowRect(GetHwnd(), &vRect
);
545 nWidth
= vRect
.xRight
- vRect
.xLeft
;
546 nHeight
= vRect
.yTop
- vRect
.yBottom
;
548 m_frameStatusBar
->GetSize( &nStatbarWidth
553 // Since we wish the status bar to be directly under the client area,
554 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
556 m_frameStatusBar
->SetSize( 0
561 if (!::WinQueryWindowPos(m_frameStatusBar
->GetHWND(), &vSwp
))
563 vError
= ::WinGetLastError(vHabmain
);
564 sError
= wxPMErrorToStr(vError
);
565 wxLogError("Error setting parent for submenu. Error: %s\n", sError
);
568 if (!::WinSetWindowPos( m_frameStatusBar
->GetHWND()
574 ,SWP_SIZE
| SWP_MOVE
| SWP_SHOW
| SWP_ZORDER
577 vError
= ::WinGetLastError(vHabmain
);
578 sError
= wxPMErrorToStr(vError
);
579 wxLogError("Error setting parent for submenu. Error: %s\n", sError
);
583 } // end of wxFrame::PositionStatusBar
584 #endif // wxUSE_STATUSBAR
586 void wxFrame::DetachMenuBar()
590 m_frameMenuBar
->Detach();
591 m_frameMenuBar
= NULL
;
593 } // end of wxFrame::DetachMenuBar
595 void wxFrame::SetMenuBar(
601 HWND hClient
= NULLHANDLE
;
602 HWND hFrame
= NULLHANDLE
;
603 HWND hTitlebar
= NULLHANDLE
;
604 HWND hHScroll
= NULLHANDLE
;
605 HWND hVScroll
= NULLHANDLE
;
606 HWND hMenuBar
= NULLHANDLE
;
618 // Actually remove the menu from the frame
620 m_hMenu
= (WXHMENU
)0;
621 InternalSetMenuBar();
623 else // set new non NULL menu bar
625 m_frameMenuBar
= NULL
;
628 // Can set a menubar several times.
629 // TODO: how to prevent a memory leak if you have a currently-unattached
630 // menubar? wxWindows assumes that the frame will delete the menu (otherwise
631 // there are problems for MDI).
633 if (pMenuBar
->GetHMenu())
635 m_hMenu
= pMenuBar
->GetHMenu();
640 m_hMenu
= pMenuBar
->Create();
644 InternalSetMenuBar();
645 m_frameMenuBar
= pMenuBar
;
646 pMenuBar
->Attach(this);
650 // Now resize the client to fit the new frame
652 WinQueryWindowPos(GetHWND(), &vSwp
);
653 hTitlebar
= WinWindowFromID(GetHWND(), FID_TITLEBAR
);
654 WinQueryWindowPos(hTitlebar
, &vSwpTitlebar
);
655 hHScroll
= WinWindowFromID(GetHWND(), FID_HORZSCROLL
);
656 WinQueryWindowPos(hHScroll
, &vSwpHScroll
);
657 hVScroll
= WinWindowFromID(GetHWND(), FID_VERTSCROLL
);
658 WinQueryWindowPos(hVScroll
, &vSwpVScroll
);
659 hMenuBar
= WinWindowFromID(GetHWND(), FID_MENU
);
660 WinQueryWindowPos(hMenuBar
, &vSwpMenu
);
661 WinSetWindowPos( GetHwnd()
664 ,(SV_CYSIZEBORDER
/2) + vSwpHScroll
.cy
/2
665 ,vSwp
.cx
- ((SV_CXSIZEBORDER
+ 1) + vSwpVScroll
.cx
)
666 ,vSwp
.cy
- ((SV_CYSIZEBORDER
+ 1) + vSwpTitlebar
.cy
+ vSwpMenu
.cy
+ vSwpHScroll
.cy
/2)
669 } // end of wxFrame::SetMenuBar
671 void wxFrame::InternalSetMenuBar()
676 // Set the parent and owner of the menubar to be the frame
678 if (!::WinSetParent(m_hMenu
, GetHWND(), FALSE
))
680 vError
= ::WinGetLastError(vHabmain
);
681 sError
= wxPMErrorToStr(vError
);
682 wxLogError("Error setting parent for submenu. Error: %s\n", sError
);
685 if (!::WinSetOwner(m_hMenu
, GetHWND()))
687 vError
= ::WinGetLastError(vHabmain
);
688 sError
= wxPMErrorToStr(vError
);
689 wxLogError("Error setting parent for submenu. Error: %s\n", sError
);
691 WinSendMsg((HWND
)GetHWND(), WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
692 } // end of wxFrame::InternalSetMenuBar
695 // Responds to colour changes, and passes event on to children
697 void wxFrame::OnSysColourChanged(
698 wxSysColourChangedEvent
& rEvent
701 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
704 if (m_frameStatusBar
)
706 wxSysColourChangedEvent vEvent2
;
708 vEvent2
.SetEventObject(m_frameStatusBar
);
709 m_frameStatusBar
->GetEventHandler()->ProcessEvent(vEvent2
);
713 // Propagate the event to the non-top-level children
715 wxWindow::OnSysColourChanged(rEvent
);
716 } // end of wxFrame::OnSysColourChanged
718 // Pass TRUE to show full screen, FALSE to restore.
719 bool wxFrame::ShowFullScreen(
729 m_bFsIsShowing
= TRUE
;
732 wxToolBar
* pTheToolBar
= GetToolBar();
733 wxStatusBar
* pTheStatusBar
= GetStatusBar();
738 pTheToolBar
->GetSize(&nDummyWidth
, &m_nFsToolBarHeight
);
740 pTheStatusBar
->GetSize(&nDummyWidth
, &m_nFsStatusBarHeight
);
743 // Zap the toolbar, menubar, and statusbar
745 if ((lStyle
& wxFULLSCREEN_NOTOOLBAR
) && pTheToolBar
)
747 pTheToolBar
->SetSize(-1,0);
748 pTheToolBar
->Show(FALSE
);
751 if (lStyle
& wxFULLSCREEN_NOMENUBAR
)
753 ::WinSetParent(m_hMenu
, GetHWND(), FALSE
);
754 ::WinSetOwner(m_hMenu
, GetHWND());
755 ::WinSendMsg((HWND
)GetHWND(), WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
759 // Save the number of fields in the statusbar
761 if ((lStyle
& wxFULLSCREEN_NOSTATUSBAR
) && pTheStatusBar
)
763 m_nFsStatusBarFields
= pTheStatusBar
->GetFieldsCount();
764 SetStatusBar((wxStatusBar
*) NULL
);
765 delete pTheStatusBar
;
768 m_nFsStatusBarFields
= 0;
771 // Zap the frame borders
775 // Save the 'normal' window style
777 m_lFsOldWindowStyle
= ::WinQueryWindowULong((HWND
)GetHWND(), QWL_STYLE
);
780 // Save the old position, width & height, maximize state
782 m_vFsOldSize
= GetRect();
783 m_bFsIsMaximized
= IsMaximized();
786 // Decide which window style flags to turn off
788 LONG lNewStyle
= m_lFsOldWindowStyle
;
791 if (lStyle
& wxFULLSCREEN_NOBORDER
)
792 lOffFlags
|= FCF_BORDER
;
793 if (lStyle
& wxFULLSCREEN_NOCAPTION
)
794 lOffFlags
|= (FCF_TASKLIST
| FCF_SYSMENU
);
796 lNewStyle
&= (~lOffFlags
);
799 // Change our window style to be compatible with full-screen mode
801 ::WinSetWindowULong((HWND
)GetHWND(), QWL_STYLE
, (ULONG
)lNewStyle
);
804 // Resize to the size of the desktop
810 ::WinQueryWindowRect(HWND_DESKTOP
, &vRect
);
811 nWidth
= vRect
.xRight
- vRect
.xLeft
;
813 // Rmember OS/2 is backwards!
815 nHeight
= vRect
.yTop
- vRect
.yBottom
;
822 // Now flush the window style cache and actually go full-screen
824 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
833 wxSizeEvent
vEvent( wxSize( nWidth
839 GetEventHandler()->ProcessEvent(vEvent
);
847 m_bFsIsShowing
= FALSE
;
849 wxToolBar
* pTheToolBar
= GetToolBar();
852 // Restore the toolbar, menubar, and statusbar
854 if (pTheToolBar
&& (m_lFsStyle
& wxFULLSCREEN_NOTOOLBAR
))
856 pTheToolBar
->SetSize(-1, m_nFsToolBarHeight
);
857 pTheToolBar
->Show(TRUE
);
860 if ((m_lFsStyle
& wxFULLSCREEN_NOSTATUSBAR
) && (m_nFsStatusBarFields
> 0))
862 CreateStatusBar(m_nFsStatusBarFields
);
866 if ((m_lFsStyle
& wxFULLSCREEN_NOMENUBAR
) && (m_hMenu
!= 0))
868 ::WinSetParent(m_hMenu
, GetHWND(), FALSE
);
869 ::WinSetOwner(m_hMenu
, GetHWND());
870 ::WinSendMsg((HWND
)GetHWND(), WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
872 Maximize(m_bFsIsMaximized
);
874 ::WinSetWindowULong( (HWND
)GetHWND()
876 ,(ULONG
)m_lFsOldWindowStyle
878 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
888 } // end of wxFrame::ShowFullScreen
893 bool wxFrame::OS2Create(
896 , const wxChar
* zWclass
898 , const wxChar
* zTitle
906 ULONG ulCreateFlags
= 0L;
907 ULONG ulStyleFlags
= 0L;
908 ULONG ulExtraFlags
= 0L;
909 FRAMECDATA vFrameCtlData
;
910 HWND hParent
= NULLHANDLE
;
911 HWND hClient
= NULLHANDLE
;
912 HWND hFrame
= NULLHANDLE
;
913 HWND hTitlebar
= NULLHANDLE
;
914 HWND hHScroll
= NULLHANDLE
;
915 HWND hVScroll
= NULLHANDLE
;
920 m_hDefaultIcon
= (WXHICON
) (wxSTD_FRAME_ICON
? wxSTD_FRAME_ICON
: wxDEFAULT_FRAME_ICON
);
923 hParent
= GetWinHwnd(pParent
);
925 hParent
= HWND_DESKTOP
;
927 if (ulStyle
== wxDEFAULT_FRAME_STYLE
)
928 ulCreateFlags
= FCF_SIZEBORDER
| FCF_TITLEBAR
| FCF_SYSMENU
|
929 FCF_MINMAX
| FCF_TASKLIST
;
932 if ((ulStyle
& wxCAPTION
) == wxCAPTION
)
933 ulCreateFlags
= FCF_TASKLIST
;
935 ulCreateFlags
= FCF_NOMOVEWITHOWNER
;
937 if ((ulStyle
& wxVSCROLL
) == wxVSCROLL
)
938 ulCreateFlags
|= FCF_VERTSCROLL
;
939 if ((ulStyle
& wxHSCROLL
) == wxHSCROLL
)
940 ulCreateFlags
|= FCF_HORZSCROLL
;
941 if (ulStyle
& wxMINIMIZE_BOX
)
942 ulCreateFlags
|= FCF_MINBUTTON
;
943 if (ulStyle
& wxMAXIMIZE_BOX
)
944 ulCreateFlags
|= FCF_MAXBUTTON
;
945 if (ulStyle
& wxTHICK_FRAME
)
946 ulCreateFlags
|= FCF_DLGBORDER
;
947 if (ulStyle
& wxSYSTEM_MENU
)
948 ulCreateFlags
|= FCF_SYSMENU
;
949 if (ulStyle
& wxCAPTION
)
950 ulCreateFlags
|= FCF_TASKLIST
;
951 if (ulStyle
& wxCLIP_CHILDREN
)
953 // Invalid for frame windows under PM
956 if (ulStyle
& wxTINY_CAPTION_VERT
)
957 ulCreateFlags
|= FCF_TASKLIST
;
958 if (ulStyle
& wxTINY_CAPTION_HORIZ
)
959 ulCreateFlags
|= FCF_TASKLIST
;
961 if ((ulStyle
& wxTHICK_FRAME
) == 0)
962 ulCreateFlags
|= FCF_BORDER
;
963 if (ulStyle
& wxFRAME_TOOL_WINDOW
)
964 ulExtraFlags
= kFrameToolWindow
;
966 if (ulStyle
& wxSTAY_ON_TOP
)
967 ulCreateFlags
|= FCF_SYSMODAL
;
969 if ((ulStyle
& wxMINIMIZE
) || (ulStyle
& wxICONIZE
))
970 ulStyleFlags
|= WS_MINIMIZED
;
971 if (ulStyle
& wxMAXIMIZE
)
972 ulStyleFlags
|= WS_MAXIMIZED
;
975 // Clear the visible flag, we always call show
977 ulStyleFlags
&= (unsigned long)~WS_VISIBLE
;
981 // Set the frame control block
983 vFrameCtlData
.cb
= sizeof(vFrameCtlData
);
984 vFrameCtlData
.flCreateFlags
= ulCreateFlags
;
985 vFrameCtlData
.hmodResources
= 0L;
986 vFrameCtlData
.idResources
= 0;
989 // Create the frame window
992 if (!wxWindow::OS2Create( hParent
1000 ,(PVOID
)&vFrameCtlData
1008 // Now size everything. If adding a menu the client will need to be resized.
1011 if (!::WinSetWindowPos( GetHWND()
1017 ,SWP_SIZE
| SWP_MOVE
| SWP_ACTIVATE
| SWP_ZORDER
1021 uCtlCount
= SHORT1FROMMP(::WinSendMsg(GetHWND(), WM_FORMATFRAME
, (MPARAM
)vSwp
, (MPARAM
)vRect
));
1022 for (int i
= 0; i
< uCtlCount
; i
++)
1024 if (vSwp
[i
].hwnd
== GetHWND())
1025 memcpy(&m_vSwp
, &vSwp
[i
], sizeof(SWP
));
1026 else if (vSwp
[i
].hwnd
== m_hVScroll
)
1027 memcpy(&m_vSwpVScroll
, &vSwp
[i
], sizeof(SWP
));
1028 else if (vSwp
[i
].hwnd
== m_hHScroll
)
1029 memcpy(&m_vSwpVScroll
, &vSwp
[i
], sizeof(SWP
));
1030 else if (vSwp
[i
].hwnd
== m_hTitleBar
)
1031 memcpy(&m_vSwpTitleBar
, &vSwp
[i
], sizeof(SWP
));
1034 } // end of wxFrame::OS2Create
1037 // Default activation behaviour - set the focus for the first child
1040 void wxFrame::OnActivate(
1041 wxActivateEvent
& rEvent
1044 for (wxWindowList::Node
* pNode
= GetChildren().GetFirst();
1046 pNode
= pNode
->GetNext())
1048 // FIXME all this is totally bogus - we need to do the same as wxPanel,
1049 // but how to do it without duplicating the code?
1052 wxWindow
* pChild
= pNode
->GetData();
1054 if (!pChild
->IsTopLevel()
1056 && !wxDynamicCast(pChild
, wxToolBar
)
1057 #endif // wxUSE_TOOLBAR
1059 && !wxDynamicCast(pChild
, wxStatusBar
)
1060 #endif // wxUSE_STATUSBAR
1067 } // end of wxFrame::OnActivate
1069 // ----------------------------------------------------------------------------
1070 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1071 // from the client area, so the client area is what's really available for the
1073 // ----------------------------------------------------------------------------
1075 // Checks if there is a toolbar, and returns the first free client position
1076 wxPoint
wxFrame::GetClientAreaOrigin() const
1078 wxPoint
vPoint(0, 0);
1085 GetToolBar()->GetSize( &nWidth
1089 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
1095 // PM is backwards from windows
1096 vPoint
.y
+= nHeight
;
1100 } // end of wxFrame::GetClientAreaOrigin
1102 // ----------------------------------------------------------------------------
1103 // tool/status bar stuff
1104 // ----------------------------------------------------------------------------
1108 wxToolBar
* wxFrame::CreateToolBar(
1111 , const wxString
& rName
1114 if (wxFrameBase::CreateToolBar( lStyle
1121 return m_frameToolBar
;
1122 } // end of wxFrame::CreateToolBar
1124 void wxFrame::PositionToolBar()
1129 ::WinQueryWindowRect(GetHwnd(), &vRect
);
1137 GetStatusBar()->GetClientSize( &nStatusX
1140 // PM is backwards from windows
1141 vRect
.yBottom
+= nStatusY
;
1143 #endif // wxUSE_STATUSBAR
1150 GetToolBar()->GetSize( &nToolbarWidth
1154 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
1156 nToolbarHeight
= vRect
.yBottom
;
1160 nToolbarWidth
= vRect
.xRight
;
1164 // Use the 'real' PM position here
1166 GetToolBar()->SetSize( 0
1170 ,wxSIZE_NO_ADJUSTMENTS
1173 } // end of wxFrame::PositionToolBar
1174 #endif // wxUSE_TOOLBAR
1176 // ----------------------------------------------------------------------------
1177 // frame state (iconized/maximized/...)
1178 // ----------------------------------------------------------------------------
1181 // propagate our state change to all child frames: this allows us to emulate X
1182 // Windows behaviour where child frames float independently of the parent one
1183 // on the desktop, but are iconized/restored with it
1185 void wxFrame::IconizeChildFrames(
1189 for (wxWindowList::Node
* pNode
= GetChildren().GetFirst();
1191 pNode
= pNode
->GetNext() )
1193 wxWindow
* pWin
= pNode
->GetData();
1195 if (pWin
->IsKindOf(CLASSINFO(wxFrame
)) )
1197 ((wxFrame
*)pWin
)->Iconize(bIconize
);
1200 } // end of wxFrame::IconizeChildFrames
1202 // ===========================================================================
1203 // message processing
1204 // ===========================================================================
1206 // ---------------------------------------------------------------------------
1208 // ---------------------------------------------------------------------------
1209 bool wxFrame::OS2TranslateMessage(
1214 // try the menu bar accels
1216 wxMenuBar
* pMenuBar
= GetMenuBar();
1221 const wxAcceleratorTable
& rAcceleratorTable
= pMenuBar
->GetAccelTable();
1222 return rAcceleratorTable
.Translate(GetHWND(), pMsg
);
1223 } // end of wxFrame::OS2TranslateMessage
1225 // ---------------------------------------------------------------------------
1226 // our private (non virtual) message handlers
1227 // ---------------------------------------------------------------------------
1228 bool wxFrame::HandlePaint()
1232 if (::WinQueryUpdateRect(GetHWND(), &vRect
))
1237 // Icons in PM are the same as "pointers"
1242 hIcon
= (HPOINTER
)::WinSendMsg(GetHWND(), WM_QUERYICON
, 0L, 0L);
1244 hIcon
= (HPOINTER
)m_hDefaultIcon
;
1247 // Hold a pointer to the dc so long as the OnPaint() message
1248 // is being processed
1251 HPS hPs
= ::WinBeginPaint(GetHwnd(), NULLHANDLE
, &vRect2
);
1254 // Erase background before painting or we get white background
1256 OS2DefWindowProc(WM_ERASEBACKGROUND
, (MPARAM
)hPs
, (MPARAM
)&vRect2
);
1263 ::WinQueryWindowRect(GetHwnd(), &vRect3
);
1265 static const int nIconWidth
= 32;
1266 static const int nIconHeight
= 32;
1267 int nIconX
= (int)((vRect3
.xRight
- nIconWidth
)/2);
1268 int nIconY
= (int)((vRect3
.yBottom
+ nIconHeight
)/2);
1270 ::WinDrawPointer(hPs
, nIconX
, nIconY
, hIcon
, DP_NORMAL
);
1277 /* DosBeep(500,500);
1281 hPS = WinBeginPaint(GetHwnd(), 0L, &vRect);
1282 WinFillRect(hPS, &vRect, SYSCLR_WINDOW);
1285 return wxWindow::HandlePaint();
1290 // nothing to paint - processed
1294 } // end of wxFrame::HandlePaint
1296 bool wxFrame::HandleSize(
1302 bool bProcessed
= FALSE
;
1308 // Only do it it if we were iconized before, otherwise resizing the
1309 // parent frame has a curious side effect of bringing it under it's
1315 // restore all child frames too
1317 IconizeChildFrames(FALSE
);
1324 m_bIconized
= FALSE
;
1329 // Iconize all child frames too
1331 IconizeChildFrames(TRUE
);
1339 // forward WM_SIZE to status bar control
1341 #if wxUSE_NATIVE_STATUSBAR
1342 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
1344 wxSizeEvent
vEvent( wxSize( nX
1347 ,m_frameStatusBar
->GetId()
1350 vEvent
.SetEventObject(m_frameStatusBar
);
1351 m_frameStatusBar
->OnSize(vEvent
);
1353 #endif // wxUSE_NATIVE_STATUSBAR
1355 PositionStatusBar();
1357 wxSizeEvent
vEvent( wxSize( nX
1363 vEvent
.SetEventObject(this);
1364 bProcessed
= GetEventHandler()->ProcessEvent(vEvent
);
1367 } // end of wxFrame::HandleSize
1369 bool wxFrame::HandleCommand(
1378 // In case it's e.g. a toolbar.
1380 wxWindow
* pWin
= wxFindWinFromHandle(hControl
);
1383 return pWin
->OS2Command( nCmd
1389 // Handle here commands from menus and accelerators
1391 if (nCmd
== 0 || nCmd
== 1)
1393 if (wxCurrentPopupMenu
)
1395 wxMenu
* pPopupMenu
= wxCurrentPopupMenu
;
1397 wxCurrentPopupMenu
= NULL
;
1399 return pPopupMenu
->OS2Command( nCmd
1404 if (ProcessCommand(nId
))
1410 } // end of wxFrame::HandleCommand
1412 bool wxFrame::HandleMenuSelect(
1420 /* This is wrong section according to IBM's documentation
1421 if (nFlags == 0xFFFF && hMenu == 0)
1424 // Menu was removed from screen
1428 else if (!(nFlags & MIS_SUBMENU) && !(nFlags & MIS_SEPARATOR))
1435 // Don't give hints for separators (doesn't make sense) nor for the
1436 // items opening popup menus (they don't have them anyhow)
1447 rc
= WinSendMsg(hMenu
, MM_QUERYITEM
, MPFROM2SHORT(nItem
, TRUE
), (MPARAM
)&mItem
);
1449 if(rc
&& !(mItem
.afStyle
& (MIS_SUBMENU
| MIS_SEPARATOR
)))
1451 wxMenuEvent
vEvent(wxEVT_MENU_HIGHLIGHT
, nItem
);
1453 vEvent
.SetEventObject(this);
1454 GetEventHandler()->ProcessEvent(vEvent
); // return value would be ignored by PM
1458 } // end of wxFrame::HandleMenuSelect
1460 // ---------------------------------------------------------------------------
1461 // the window proc for wxFrame
1462 // ---------------------------------------------------------------------------
1464 MRESULT
wxFrame::OS2WindowProc(
1471 bool bProcessed
= FALSE
;
1477 // If we can't close, tell the system that we processed the
1478 // message - otherwise it would close us
1480 bProcessed
= !Close();
1489 UnpackCommand( (WXWPARAM
)wParam
1495 bProcessed
= HandleCommand( wId
1508 UnpackMenuSelect( wParam
1514 bProcessed
= HandleMenuSelect( wItem
1518 mRc
= (MRESULT
)TRUE
;
1523 bProcessed
= HandlePaint();
1526 case WM_ERASEBACKGROUND
:
1528 // Return TRUE to request PM to paint the window background
1529 // in SYSCLR_WINDOW.
1532 mRc
= (MRESULT
)(TRUE
);
1535 case CM_QUERYDRAGIMAGE
:
1540 hIcon
= (HPOINTER
)::WinSendMsg(GetHWND(), WM_QUERYICON
, 0L, 0L);
1542 hIcon
= (HPOINTER
)m_hDefaultIcon
;
1543 mRc
= (MRESULT
)hIcon
;
1544 bProcessed
= mRc
!= 0;
1549 bProcessed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), (WXUINT
)wParam
);
1554 mRc
= wxWindow::OS2WindowProc( uMessage
1558 return (MRESULT
)mRc
;
1559 } // wxFrame::OS2WindowProc