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
;
93 } // end of wxFrame::Init
98 , const wxString
& rsTitle
100 , const wxSize
& rSize
102 , const wxString
& rsName
107 int nWidth
= rSize
.x
;
108 int nHeight
= rSize
.y
;
111 m_windowStyle
= lulStyle
;
112 m_frameMenuBar
= NULL
;
113 m_frameToolBar
= NULL
;
114 m_frameStatusBar
= NULL
;
116 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
121 m_windowId
= (int)NewControlId();
124 pParent
->AddChild(this);
129 // We pass NULL as parent to MSWCreate because frames with parents behave
130 // very strangely under Win95 shell.
131 // Alteration by JACS: keep normal Windows behaviour (float on top of parent)
132 // with this ulStyle.
134 if ((m_windowStyle
& wxFRAME_FLOAT_ON_PARENT
) == 0)
138 wxTopLevelWindows
.Append(this);
140 OS2Create( m_windowId
152 wxModelessWindows
.Append(this);
154 } // end of wxFrame::Create
158 m_isBeingDeleted
= TRUE
;
159 wxTopLevelWindows
.DeleteObject(this);
163 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
165 wxTheApp
->SetTopWindow(NULL
);
167 if (wxTheApp
->GetExitOnFrameDelete())
169 ::WinPostMsg(GetHwnd(), WM_QUIT
, 0, 0);
172 wxModelessWindows
.DeleteObject(this);
175 // For some reason, wxWindows can activate another task altogether
176 // when a frame is destroyed after a modal dialog has been invoked.
177 // Try to bring the parent to the top.
179 // MT:Only do this if this frame is currently the active window, else weird
180 // things start to happen.
182 if (wxGetActiveWindow() == this)
184 if (GetParent() && GetParent()->GetHWND())
186 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
196 } // end of wxFrame::~wxFrame
199 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
201 void wxFrame::DoGetClientSize(
207 // OS/2 PM's coordinates go from bottom-left not
208 // top-left thus the += instead of the -=
214 // PM has no GetClientRect that inherantly knows about the client window
215 // We have to explicitly go fetch it!
217 hWndClient
= ::WinWindowFromID(GetHwnd(), FID_CLIENT
);
218 ::WinQueryWindowRect(hWndClient
, &vRect
);
221 if ( GetStatusBar() )
226 GetStatusBar()->GetClientSize( &nStatusX
229 vRect
.yBottom
+= nStatusY
;
231 #endif // wxUSE_STATUSBAR
233 wxPoint
vPoint(GetClientAreaOrigin());
235 vRect
.yBottom
+= vPoint
.y
;
236 vRect
.xRight
-= vPoint
.x
;
242 } // end of wxFrame::DoGetClientSize
245 // Set the client size (i.e. leave the calculation of borders etc.
248 void wxFrame::DoSetClientSize(
253 HWND hWnd
= GetHwnd();
258 hWndClient
= ::WinWindowFromID(GetHwnd(), FID_CLIENT
);
259 ::WinQueryWindowRect(hWndClient
, &vRect
);
261 ::WinQueryWindowRect(hWnd
, &vRect2
);
264 // Find the difference between the entire window (title bar and all)
265 // and the client area; add this to the new client size to move the
266 // window. Remember OS/2's backwards y coord system!
268 int nActualWidth
= vRect2
.xRight
- vRect2
.xLeft
- vRect
.xRight
+ nWidth
;
269 int nActualHeight
= vRect2
.yTop
+ vRect2
.yTop
- vRect
.yTop
+ nHeight
;
272 if ( GetStatusBar() )
277 GetStatusBar()->GetClientSize( &nStatusX
280 nActualHeight
+= nStatusY
;
282 #endif // wxUSE_STATUSBAR
284 wxPoint
vPoint(GetClientAreaOrigin());
285 nActualWidth
+= vPoint
.y
;
286 nActualHeight
+= vPoint
.x
;
290 vPointl
.x
= vRect2
.xLeft
;
291 vPoint
.y
= vRect2
.yTop
;
293 ::WinSetWindowPos( hWnd
299 ,SWP_MOVE
| SWP_SIZE
| SWP_SHOW
302 wxSizeEvent
vEvent( wxSize( nWidth
307 vEvent
.SetEventObject(this);
308 GetEventHandler()->ProcessEvent(vEvent
);
309 } // end of wxFrame::DoSetClientSize
311 void wxFrame::DoGetSize(
318 ::WinQueryWindowRect(GetHwnd(), &vRect
);
319 *pWidth
= vRect
.xRight
- vRect
.xLeft
;
320 *pHeight
= vRect
.yTop
- vRect
.yBottom
;
321 } // end of wxFrame::DoGetSize
323 void wxFrame::DoGetPosition(
331 ::WinQueryWindowRect(GetHwnd(), &vRect
);
332 vPoint
.x
= vRect
.xLeft
;
335 // OS/2 is backwards [WIN32 it is vRect.yTop]
337 vPoint
.y
= vRect
.yBottom
;
341 } // end of wxFrame::DoGetPosition
343 // ----------------------------------------------------------------------------
344 // variations around ::ShowWindow()
345 // ----------------------------------------------------------------------------
347 void wxFrame::DoShowWindow(
351 ::WinShowWindow(GetHwnd(), nShowCmd
);
352 m_bIconized
= nShowCmd
== SWP_MINIMIZE
;
353 } // end of wxFrame::DoShowWindow
359 DoShowWindow(bShow
? SWP_SHOW
: SWP_HIDE
);
363 wxActivateEvent
vEvent(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
365 ::WinSetWindowPos( (HWND
) GetHWND()
373 vEvent
.SetEventObject(this);
374 GetEventHandler()->ProcessEvent(vEvent
);
379 // Try to highlight the correct window (the parent)
383 HWND hWndParent
= GetHwndOf(GetParent());
386 ::WinSetWindowPos( hWndParent
397 } // end of wxFrame::Show
399 void wxFrame::Iconize(
403 DoShowWindow(bIconize
? SWP_MINIMIZE
: SWP_RESTORE
);
404 } // end of wxFrame::Iconize
406 void wxFrame::Maximize(
409 DoShowWindow(bMaximize
? SWP_MAXIMIZE
: SWP_RESTORE
);
410 } // end of wxFrame::Maximize
412 void wxFrame::Restore()
414 DoShowWindow(SWP_RESTORE
);
415 } // end of wxFrame::Restore
417 bool wxFrame::IsIconized() const
422 ::WinQueryWindowPos(GetHwnd(), &vSwp
);
424 if (vSwp
.fl
& SWP_MINIMIZE
)
425 ((wxFrame
*)this)->m_bIconized
= TRUE
;
427 ((wxFrame
*)this)->m_bIconized
= FALSE
;
429 } // end of wxFrame::IsIconized
432 bool wxFrame::IsMaximized() const
437 ::WinQueryWindowPos(GetHwnd(), &vSwp
);
438 return (vSwp
.fl
& SWP_MAXIMIZE
);
439 } // end of wxFrame::IsMaximized
441 void wxFrame::SetIcon(
445 wxFrameBase::SetIcon(rIcon
);
449 WinSendMsg( GetHwnd()
451 ,(MPARAM
)((HICON
)m_icon
.GetHICON())
455 } // end of wxFrame::SetIcon
458 wxStatusBar
* wxFrame::OnCreateStatusBar(
462 , const wxString
& rName
465 wxStatusBar
* pStatusBar
= NULL
;
467 pStatusBar
= wxFrameBase::OnCreateStatusBar( nNumber
473 } // end of wxFrame::OnCreateStatusBar
475 void wxFrame::PositionStatusBar()
478 // Native status bar positions itself
480 if (m_frameStatusBar
)
489 hWndClient
= ::WinWindowFromID(GetHwnd(), FID_CLIENT
);
490 ::WinQueryWindowRect(hWndClient
, &vRect
);
491 nWidth
= vRect
.xRight
- vRect
.xLeft
;
492 nHeight
= vRect
.yTop
- vRect
.yBottom
;
494 m_frameStatusBar
->GetSize( &nStatbarWidth
499 // Since we wish the status bar to be directly under the client area,
500 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
502 m_frameStatusBar
->SetSize( 0
508 } // end of wxFrame::PositionStatusBar
509 #endif // wxUSE_STATUSBAR
511 void wxFrame::DetachMenuBar()
515 m_frameMenuBar
->Detach();
516 m_frameMenuBar
= NULL
;
518 } // end of wxFrame::DetachMenuBar
520 void wxFrame::SetMenuBar(
530 wxCHECK_RET(!pMenuBar
->GetFrame(), wxT("this menubar is already attached"));
533 delete m_frameMenuBar
;
535 m_hMenu
= pMenuBar
->Create();
536 m_ulMenubarId
= pMenuBar
->GetMenubarId();
537 if (m_ulMenubarId
!= FID_MENU
)
539 ::WinSetWindowUShort( m_hMenu
541 ,(unsigned short)m_ulMenubarId
548 InternalSetMenuBar();
550 m_frameMenuBar
= pMenuBar
;
551 pMenuBar
->Attach(this);
552 } // end of wxFrame::SetMenuBar
554 void wxFrame::InternalSetMenuBar()
557 ::WinPostMsg( GetHwnd()
562 } // end of wxFrame::InternalSetMenuBar
565 // Responds to colour changes, and passes event on to children
567 void wxFrame::OnSysColourChanged(
568 wxSysColourChangedEvent
& rEvent
571 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
574 if (m_frameStatusBar
)
576 wxSysColourChangedEvent vEvent2
;
578 vEvent2
.SetEventObject(m_frameStatusBar
);
579 m_frameStatusBar
->GetEventHandler()->ProcessEvent(vEvent2
);
583 // Propagate the event to the non-top-level children
585 wxWindow::OnSysColourChanged(rEvent
);
586 } // end of wxFrame::OnSysColourChanged
591 bool wxFrame::OS2Create(
594 , const wxChar
* zWclass
596 , const wxChar
* zTitle
605 ULONG ulExtraFlags
= 0;
606 ULONG ulTempFlags
= FCF_TITLEBAR
|
617 m_hDefaultIcon
= (WXHICON
) (wxSTD_FRAME_ICON
? wxSTD_FRAME_ICON
: wxDEFAULT_FRAME_ICON
);
619 if ((ulStyle
& wxCAPTION
) == wxCAPTION
)
620 ulPmFlags
= FCF_TASKLIST
;
622 ulPmFlags
= FCF_NOMOVEWITHOWNER
;
624 if (ulStyle
& wxMINIMIZE_BOX
)
625 ulPmFlags
|= FCF_MINBUTTON
;
626 if (ulStyle
& wxMAXIMIZE_BOX
)
627 ulPmFlags
|= FCF_MAXBUTTON
;
628 if (ulStyle
& wxTHICK_FRAME
)
629 ulPmFlags
|= FCF_DLGBORDER
;
630 if (ulStyle
& wxSYSTEM_MENU
)
631 ulPmFlags
|= FCF_SYSMENU
;
632 if ((ulStyle
& wxMINIMIZE
) || (ulStyle
& wxICONIZE
))
633 ulPmFlags
|= WS_MINIMIZED
;
634 if (ulStyle
& wxMAXIMIZE
)
635 ulPmFlags
|= WS_MAXIMIZED
;
636 if (ulStyle
& wxCAPTION
)
637 ulPmFlags
|= FCF_TASKLIST
;
638 if (ulStyle
& wxCLIP_CHILDREN
)
640 // Invalid for frame windows under PM
644 // Keep this in wxFrame because it saves recoding this function
648 if (ulStyle
& wxTINY_CAPTION_VERT
)
649 ulExtraFlags
|= kVertCaption
;
650 if (ulStyle
& wxTINY_CAPTION_HORIZ
)
651 ulExtraFlags
|= kHorzCaption
;
653 if (ulStyle
& wxTINY_CAPTION_VERT
)
654 ulPmFlags
|= FCF_TASKLIST
;
655 if (ulStyle
& wxTINY_CAPTION_HORIZ
)
656 ulPmFlags
|= FCF_TASKLIST
;
658 if ((ulStyle
& wxTHICK_FRAME
) == 0)
659 ulPmFlags
|= FCF_BORDER
;
660 if (ulStyle
& wxFRAME_TOOL_WINDOW
)
661 ulExtraFlags
= kFrameToolWindow
;
663 if (ulStyle
& wxSTAY_ON_TOP
)
664 ulPmFlags
|= FCF_SYSMODAL
;
666 if (ulPmFlags
& ulTempFlags
)
667 ulPmFlags
= FCF_STANDARD
;
669 // Clear the visible flag, we always call show
671 ulPmFlags
&= (unsigned long)~WS_VISIBLE
;
673 if ( !wxWindow::OS2Create( nId
689 } // end of wxFrame::OS2Create
692 // Default activation behaviour - set the focus for the first child
695 void wxFrame::OnActivate(
696 wxActivateEvent
& rEvent
699 for (wxWindowList::Node
* pNode
= GetChildren().GetFirst();
701 pNode
= pNode
->GetNext())
703 // FIXME all this is totally bogus - we need to do the same as wxPanel,
704 // but how to do it without duplicating the code?
707 wxWindow
* pChild
= pNode
->GetData();
709 if (!pChild
->IsTopLevel()
711 && !wxDynamicCast(pChild
, wxToolBar
)
712 #endif // wxUSE_TOOLBAR
714 && !wxDynamicCast(pChild
, wxStatusBar
)
715 #endif // wxUSE_STATUSBAR
722 } // end of wxFrame::OnActivate
724 // ----------------------------------------------------------------------------
725 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
726 // from the client area, so the client area is what's really available for the
728 // ----------------------------------------------------------------------------
730 // Checks if there is a toolbar, and returns the first free client position
731 wxPoint
wxFrame::GetClientAreaOrigin() const
733 wxPoint
vPoint(0, 0);
740 GetToolBar()->GetSize( &nWidth
744 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
750 // PM is backwards from windows
755 } // end of wxFrame::GetClientAreaOrigin
757 // ----------------------------------------------------------------------------
758 // tool/status bar stuff
759 // ----------------------------------------------------------------------------
763 wxToolBar
* wxFrame::CreateToolBar(
766 , const wxString
& rName
769 if (wxFrameBase::CreateToolBar( lStyle
776 return m_frameToolBar
;
777 } // end of wxFrame::CreateToolBar
779 void wxFrame::PositionToolBar()
784 hWndClient
= ::WinWindowFromID(GetHwnd(), FID_CLIENT
);
785 ::WinQueryWindowRect(hWndClient
, &vRect
);
793 GetStatusBar()->GetClientSize( &nStatusX
796 // PM is backwards from windows
797 vRect
.yBottom
+= nStatusY
;
799 #endif // wxUSE_STATUSBAR
806 GetToolBar()->GetSize( &nToolbarWidth
810 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
812 nToolbarHeight
= vRect
.yBottom
;
816 nToolbarWidth
= vRect
.xRight
;
820 // Use the 'real' PM position here
822 GetToolBar()->SetSize( 0
826 ,wxSIZE_NO_ADJUSTMENTS
829 } // end of wxFrame::PositionToolBar
830 #endif // wxUSE_TOOLBAR
832 // ----------------------------------------------------------------------------
833 // frame state (iconized/maximized/...)
834 // ----------------------------------------------------------------------------
837 // propagate our state change to all child frames: this allows us to emulate X
838 // Windows behaviour where child frames float independently of the parent one
839 // on the desktop, but are iconized/restored with it
841 void wxFrame::IconizeChildFrames(
845 for (wxWindowList::Node
* pNode
= GetChildren().GetFirst();
847 pNode
= pNode
->GetNext() )
849 wxWindow
* pWin
= pNode
->GetData();
851 if (pWin
->IsKindOf(CLASSINFO(wxFrame
)) )
853 ((wxFrame
*)pWin
)->Iconize(bIconize
);
856 } // end of wxFrame::IconizeChildFrames
858 // ===========================================================================
859 // message processing
860 // ===========================================================================
862 // ---------------------------------------------------------------------------
864 // ---------------------------------------------------------------------------
865 bool wxFrame::OS2TranslateMessage(
869 if (wxWindow::OS2TranslateMessage(pMsg
))
872 // try the menu bar accels
874 wxMenuBar
* pMenuBar
= GetMenuBar();
879 const wxAcceleratorTable
& rAcceleratorTable
= pMenuBar
->GetAccelTable();
880 return rAcceleratorTable
.Translate(this, pMsg
);
881 } // end of wxFrame::OS2TranslateMessage
883 // ---------------------------------------------------------------------------
884 // our private (non virtual) message handlers
885 // ---------------------------------------------------------------------------
886 bool wxFrame::HandlePaint()
890 if (::WinQueryUpdateRect(GetHwnd(), &vRect
))
895 // Icons in PM are the same as "pointers"
900 hIcon
= (HPOINTER
)::WinSendMsg(GetHwnd(), WM_QUERYICON
, 0L, 0L);
902 hIcon
= (HPOINTER
)m_hDefaultIcon
;
905 // Hold a pointer to the dc so long as the OnPaint() message
906 // is being processed
909 HPS hPs
= ::WinBeginPaint(GetHwnd(), NULLHANDLE
, &vRect2
);
912 // Erase background before painting or we get white background
914 OS2DefWindowProc(WM_ERASEBACKGROUND
, (MPARAM
)hPs
, (MPARAM
)&vRect2
);
921 hWndClient
= ::WinWindowFromID(GetHwnd(), FID_CLIENT
);
922 ::WinQueryWindowRect(hWndClient
, &vRect3
);
924 static const int nIconWidth
= 32;
925 static const int nIconHeight
= 32;
926 int nIconX
= (int)((vRect3
.xRight
- nIconWidth
)/2);
927 int nIconY
= (int)((vRect3
.yBottom
+ nIconHeight
)/2);
929 ::WinDrawPointer(hPs
, nIconX
, nIconY
, hIcon
, DP_NORMAL
);
936 return wxWindow::HandlePaint();
941 // nothing to paint - processed
945 } // end of wxFrame::HandlePaint
947 bool wxFrame::HandleSize(
953 bool bProcessed
= FALSE
;
959 // Only do it it if we were iconized before, otherwise resizing the
960 // parent frame has a curious side effect of bringing it under it's
966 // restore all child frames too
968 IconizeChildFrames(FALSE
);
980 // Iconize all child frames too
982 IconizeChildFrames(TRUE
);
990 // forward WM_SIZE to status bar control
992 #if wxUSE_NATIVE_STATUSBAR
993 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
995 wxSizeEvent
vEvent( wxSize( nX
998 ,m_frameStatusBar
->GetId()
1001 vEvent
.SetEventObject(m_frameStatusBar
);
1002 m_frameStatusBar
->OnSize(vEvent
);
1004 #endif // wxUSE_NATIVE_STATUSBAR
1006 PositionStatusBar();
1008 wxSizeEvent
vEvent( wxSize( nX
1014 vEvent
.SetEventObject(this);
1015 bProcessed
= GetEventHandler()->ProcessEvent(vEvent
);
1018 } // end of wxFrame::HandleSize
1020 bool wxFrame::HandleCommand(
1029 // In case it's e.g. a toolbar.
1031 wxWindow
* pWin
= wxFindWinFromHandle(hControl
);
1034 return pWin
->OS2Command( nCmd
1040 // Handle here commands from menus and accelerators
1042 if (nCmd
== 0 || nCmd
== 1)
1044 if (wxCurrentPopupMenu
)
1046 wxMenu
* pPopupMenu
= wxCurrentPopupMenu
;
1048 wxCurrentPopupMenu
= NULL
;
1050 return pPopupMenu
->OS2Command( nCmd
1055 if (ProcessCommand(nId
))
1061 } // end of wxFrame::HandleCommand
1063 bool wxFrame::HandleMenuSelect(
1071 if (nFlags
== 0xFFFF && hMenu
== 0)
1074 // Menu was removed from screen
1078 else if (!(nFlags
& MIS_SUBMENU
) && !(nFlags
& MIS_SEPARATOR
))
1085 // Don't give hints for separators (doesn't make sense) nor for the
1086 // items opening popup menus (they don't have them anyhow)
1090 wxMenuEvent
vEvent(wxEVT_MENU_HIGHLIGHT
, nMenuItem
);
1092 vEvent
.SetEventObject(this);
1093 return GetEventHandler()->ProcessEvent(vEvent
);
1094 } // end of wxFrame::HandleMenuSelect
1096 // ---------------------------------------------------------------------------
1097 // the window proc for wxFrame
1098 // ---------------------------------------------------------------------------
1100 MRESULT
wxFrame::OS2WindowProc(
1107 bool bProcessed
= FALSE
;
1113 // If we can't close, tell the system that we processed the
1114 // message - otherwise it would close us
1116 bProcessed
= !Close();
1125 UnpackCommand( (WXWPARAM
)wParam
1131 bProcessed
= HandleCommand( wId
1144 UnpackMenuSelect( wParam
1150 bProcessed
= HandleMenuSelect( wItem
1158 bProcessed
= HandlePaint();
1161 case CM_QUERYDRAGIMAGE
:
1166 hIcon
= (HPOINTER
)::WinSendMsg(GetHwnd(), WM_QUERYICON
, 0L, 0L);
1168 hIcon
= (HPOINTER
)m_hDefaultIcon
;
1169 mRc
= (MRESULT
)hIcon
;
1170 bProcessed
= mRc
!= 0;
1175 bProcessed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), (WXUINT
)wParam
);
1180 mRc
= wxWindow::OS2WindowProc( uMessage
1185 } // wxFrame::OS2WindowProc