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
;
97 memset(&m_vSwp
, 0, sizeof(SWP
));
98 memset(&m_vSwpClient
, 0, sizeof(SWP
));
99 memset(&m_vSwpTitleBar
, 0, sizeof(SWP
));
100 memset(&m_vSwpMenuBar
, 0, sizeof(SWP
));
101 memset(&m_vSwpHScroll
, 0, sizeof(SWP
));
102 memset(&m_vSwpVScroll
, 0, sizeof(SWP
));
103 memset(&m_vSwpStatusBar
, 0, sizeof(SWP
));
104 memset(&m_vSwpToolBar
, 0, sizeof(SWP
));
105 } // end of wxFrame::Init
107 bool wxFrame::Create(
110 , const wxString
& rsTitle
111 , const wxPoint
& rPos
112 , const wxSize
& rSize
114 , const wxString
& rsName
119 int nWidth
= rSize
.x
;
120 int nHeight
= rSize
.y
;
123 m_windowStyle
= lulStyle
;
124 m_frameMenuBar
= NULL
;
125 m_frameToolBar
= NULL
;
126 m_frameStatusBar
= NULL
;
128 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
133 m_windowId
= (int)NewControlId();
136 pParent
->AddChild(this);
140 if ((m_windowStyle
& wxFRAME_FLOAT_ON_PARENT
) == 0)
144 wxTopLevelWindows
.Append(this);
146 OS2Create( m_windowId
158 wxModelessWindows
.Append(this);
160 } // end of wxFrame::Create
164 m_isBeingDeleted
= TRUE
;
165 wxTopLevelWindows
.DeleteObject(this);
169 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
171 wxTheApp
->SetTopWindow(NULL
);
173 if (wxTheApp
->GetExitOnFrameDelete())
175 ::WinPostMsg(m_hFrame
, WM_QUIT
, 0, 0);
178 wxModelessWindows
.DeleteObject(this);
181 // For some reason, wxWindows can activate another task altogether
182 // when a frame is destroyed after a modal dialog has been invoked.
183 // Try to bring the parent to the top.
185 // MT:Only do this if this frame is currently the active window, else weird
186 // things start to happen.
188 if (wxGetActiveWindow() == this)
190 if (GetParent() && GetParent()->GetHWND())
192 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
202 } // end of wxFrame::~wxFrame
205 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
207 void wxFrame::DoGetClientSize(
213 // OS/2 PM's coordinates go from bottom-left not
214 // top-left thus the += instead of the -=
219 // PM has no GetClientRect that inherantly knows about the client window
220 // We have to explicitly go fetch it!
222 ::WinQueryWindowRect(GetHwnd(), &vRect
);
225 if ( GetStatusBar() )
230 GetStatusBar()->GetClientSize( &nStatusX
233 vRect
.yBottom
+= nStatusY
;
235 #endif // wxUSE_STATUSBAR
237 wxPoint
vPoint(GetClientAreaOrigin());
239 vRect
.yBottom
+= vPoint
.y
;
240 vRect
.xRight
-= vPoint
.x
;
246 } // end of wxFrame::DoGetClientSize
249 // Set the client size (i.e. leave the calculation of borders etc.
252 void wxFrame::DoSetClientSize(
257 HWND hWnd
= GetHwnd();
261 ::WinQueryWindowRect(GetHwnd(), &vRect
);
263 ::WinQueryWindowRect(m_hFrame
, &vRect2
);
266 // Find the difference between the entire window (title bar and all)
267 // and the client area; add this to the new client size to move the
268 // window. Remember OS/2's backwards y coord system!
270 int nActualWidth
= vRect2
.xRight
- vRect2
.xLeft
- vRect
.xRight
+ nWidth
;
271 int nActualHeight
= vRect2
.yTop
+ vRect2
.yTop
- vRect
.yTop
+ nHeight
;
274 if ( GetStatusBar() )
279 GetStatusBar()->GetClientSize( &nStatusX
282 nActualHeight
+= nStatusY
;
284 #endif // wxUSE_STATUSBAR
286 wxPoint
vPoint(GetClientAreaOrigin());
287 nActualWidth
+= vPoint
.y
;
288 nActualHeight
+= vPoint
.x
;
292 vPointl
.x
= vRect2
.xLeft
;
293 vPoint
.y
= vRect2
.yTop
;
295 ::WinSetWindowPos( m_hFrame
301 ,SWP_MOVE
| SWP_SIZE
| SWP_SHOW
304 wxSizeEvent
vEvent( wxSize( nWidth
309 vEvent
.SetEventObject(this);
310 GetEventHandler()->ProcessEvent(vEvent
);
311 } // end of wxFrame::DoSetClientSize
313 void wxFrame::DoGetSize(
320 ::WinQueryWindowRect(m_hFrame
, &vRect
);
321 *pWidth
= vRect
.xRight
- vRect
.xLeft
;
322 *pHeight
= vRect
.yTop
- vRect
.yBottom
;
323 } // end of wxFrame::DoGetSize
325 void wxFrame::DoGetPosition(
333 ::WinQueryWindowRect(m_hFrame
, &vRect
);
334 vPoint
.x
= vRect
.xLeft
;
337 // OS/2 is backwards [WIN32 it is vRect.yTop]
339 vPoint
.y
= vRect
.yBottom
;
343 } // end of wxFrame::DoGetPosition
345 // ----------------------------------------------------------------------------
346 // variations around ::ShowWindow()
347 // ----------------------------------------------------------------------------
349 void wxFrame::DoShowWindow(
353 HWND hClient
= NULLHANDLE
;
357 // Reset the window position
359 WinQueryWindowPos(m_hFrame
, &vSwp
);
360 WinSetWindowPos( GetHwnd()
366 ,SWP_SIZE
| SWP_MOVE
| SWP_ACTIVATE
368 ::WinShowWindow(m_hFrame
, (BOOL
)bShowCmd
);
369 ::WinShowWindow(GetHwnd(), (BOOL
)bShowCmd
);
370 } // end of wxFrame::DoShowWindow
378 DoShowWindow((int)bShow
);
382 wxActivateEvent
vEvent(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
384 ::WinQueryWindowPos(m_hFrame
, &vSwp
);
385 m_bIconized
= vSwp
.fl
& SWP_MINIMIZE
;
386 ::WinEnableWindow(m_hFrame
, TRUE
);
387 vEvent
.SetEventObject(this);
388 GetEventHandler()->ProcessEvent(vEvent
);
393 // Try to highlight the correct window (the parent)
397 HWND hWndParent
= GetHwndOf(GetParent());
399 ::WinQueryWindowPos(hWndParent
, &vSwp
);
400 m_bIconized
= vSwp
.fl
& SWP_MINIMIZE
;
402 ::WinSetWindowPos( hWndParent
408 ,SWP_ZORDER
| SWP_ACTIVATE
| SWP_SHOW
| SWP_MOVE
410 ::WinEnableWindow(hWndParent
, TRUE
);
414 } // end of wxFrame::Show
416 void wxFrame::Iconize(
420 DoShowWindow(bIconize
? SWP_MINIMIZE
: SWP_RESTORE
);
421 } // end of wxFrame::Iconize
423 void wxFrame::Maximize(
426 DoShowWindow(bMaximize
? SWP_MAXIMIZE
: SWP_RESTORE
);
427 } // end of wxFrame::Maximize
429 void wxFrame::Restore()
431 DoShowWindow(SWP_RESTORE
);
432 } // end of wxFrame::Restore
434 bool wxFrame::IsIconized() const
439 ::WinQueryWindowPos(GetHwnd(), &vSwp
);
441 if (vSwp
.fl
& SWP_MINIMIZE
)
442 ((wxFrame
*)this)->m_bIconized
= TRUE
;
444 ((wxFrame
*)this)->m_bIconized
= FALSE
;
446 } // end of wxFrame::IsIconized
449 bool wxFrame::IsMaximized() const
454 ::WinQueryWindowPos(m_hFrame
, &vSwp
);
455 return (vSwp
.fl
& SWP_MAXIMIZE
);
456 } // end of wxFrame::IsMaximized
458 void wxFrame::SetIcon(
462 wxFrameBase::SetIcon(rIcon
);
464 if ((m_icon
.GetHICON()) != NULLHANDLE
)
466 ::WinSendMsg( m_hFrame
468 ,(MPARAM
)((HPOINTER
)m_icon
.GetHICON())
471 ::WinSendMsg( m_hFrame
477 } // end of wxFrame::SetIcon
480 wxStatusBar
* wxFrame::OnCreateStatusBar(
484 , const wxString
& rName
487 wxStatusBar
* pStatusBar
= NULL
;
493 pStatusBar
= wxFrameBase::OnCreateStatusBar( nNumber
499 // The default parent set for the Statusbar is m_hWnd which, of course,
500 // is the handle to the client window of the frame. We don't want that,
501 // so we have to set the parent to actually be the Frame.
503 hWnd
= pStatusBar
->GetHWND();
504 if (!::WinSetParent(hWnd
, m_hFrame
, FALSE
))
506 vError
= ::WinGetLastError(vHabmain
);
507 sError
= wxPMErrorToStr(vError
);
508 wxLogError("Error setting parent for statusbar. Error: %s\n", sError
);
513 // Also we need to reset it positioning to enable the SHOW attribute
515 if (!::WinQueryWindowPos((HWND
)pStatusBar
->GetHWND(), &vSwp
))
517 vError
= ::WinGetLastError(vHabmain
);
518 sError
= wxPMErrorToStr(vError
);
519 wxLogError("Error querying frame for statusbar position. Error: %s\n", sError
);
522 if (!::WinSetWindowPos( (HWND
)pStatusBar
->GetHWND()
528 ,SWP_SIZE
| SWP_MOVE
| SWP_SHOW
| SWP_ZORDER
531 vError
= ::WinGetLastError(vHabmain
);
532 sError
= wxPMErrorToStr(vError
);
533 wxLogError("Error setting statusbar position. Error: %s\n", sError
);
537 } // end of wxFrame::OnCreateStatusBar
539 void wxFrame::PositionStatusBar()
546 // Native status bar positions itself
548 if (m_frameStatusBar
)
557 ::WinQueryWindowRect(GetHwnd(), &vRect
);
558 nWidth
= vRect
.xRight
- vRect
.xLeft
;
559 nHeight
= vRect
.yTop
- vRect
.yBottom
;
561 m_frameStatusBar
->GetSize( &nStatbarWidth
566 // Since we wish the status bar to be directly under the client area,
567 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
569 m_frameStatusBar
->SetSize( 0
574 if (!::WinQueryWindowPos(m_frameStatusBar
->GetHWND(), &vSwp
))
576 vError
= ::WinGetLastError(vHabmain
);
577 sError
= wxPMErrorToStr(vError
);
578 wxLogError("Error setting parent for submenu. Error: %s\n", sError
);
581 if (!::WinSetWindowPos( m_frameStatusBar
->GetHWND()
587 ,SWP_SIZE
| SWP_MOVE
| SWP_SHOW
| SWP_ZORDER
590 vError
= ::WinGetLastError(vHabmain
);
591 sError
= wxPMErrorToStr(vError
);
592 wxLogError("Error setting parent for submenu. Error: %s\n", sError
);
596 } // end of wxFrame::PositionStatusBar
597 #endif // wxUSE_STATUSBAR
599 void wxFrame::DetachMenuBar()
603 m_frameMenuBar
->Detach();
604 m_frameMenuBar
= NULL
;
606 } // end of wxFrame::DetachMenuBar
608 void wxFrame::SetMenuBar(
614 HWND hClient
= NULLHANDLE
;
615 HWND hFrame
= NULLHANDLE
;
616 HWND hTitlebar
= NULLHANDLE
;
617 HWND hHScroll
= NULLHANDLE
;
618 HWND hVScroll
= NULLHANDLE
;
619 HWND hMenuBar
= NULLHANDLE
;
632 m_frameMenuBar
= NULL
;
634 // Can set a menubar several times.
635 // TODO: how to prevent a memory leak if you have a currently-unattached
636 // menubar? wxWindows assumes that the frame will delete the menu (otherwise
637 // there are problems for MDI).
638 if (pMenuBar
->GetHMenu())
640 m_hMenu
= pMenuBar
->GetHMenu();
646 m_hMenu
= pMenuBar
->Create();
653 // Set the parent and owner of the menubar to be the frame
655 if (!::WinSetParent(m_hMenu
, m_hFrame
, FALSE
))
657 vError
= ::WinGetLastError(vHabmain
);
658 sError
= wxPMErrorToStr(vError
);
659 wxLogError("Error setting parent for submenu. Error: %s\n", sError
);
662 if (!::WinSetOwner(m_hMenu
, m_hFrame
))
664 vError
= ::WinGetLastError(vHabmain
);
665 sError
= wxPMErrorToStr(vError
);
666 wxLogError("Error setting parent for submenu. Error: %s\n", sError
);
668 InternalSetMenuBar();
670 m_frameMenuBar
= pMenuBar
;
671 pMenuBar
->Attach(this);
674 // Now resize the client to fit the new frame
676 WinQueryWindowPos(m_hFrame
, &vSwp
);
677 hTitlebar
= WinWindowFromID(m_hFrame
, FID_TITLEBAR
);
678 WinQueryWindowPos(hTitlebar
, &vSwpTitlebar
);
679 hHScroll
= WinWindowFromID(m_hFrame
, FID_HORZSCROLL
);
680 WinQueryWindowPos(hHScroll
, &vSwpHScroll
);
681 hVScroll
= WinWindowFromID(m_hFrame
, FID_VERTSCROLL
);
682 WinQueryWindowPos(hVScroll
, &vSwpVScroll
);
683 hMenuBar
= WinWindowFromID(m_hFrame
, FID_MENU
);
684 WinQueryWindowPos(hMenuBar
, &vSwpMenu
);
685 WinSetWindowPos( GetHwnd()
688 ,(SV_CYSIZEBORDER
/2) + vSwpHScroll
.cy
/2
689 ,vSwp
.cx
- ((SV_CXSIZEBORDER
+ 1) + vSwpVScroll
.cx
)
690 ,vSwp
.cy
- ((SV_CYSIZEBORDER
+ 1) + vSwpTitlebar
.cy
+ vSwpMenu
.cy
+ vSwpHScroll
.cy
/2)
693 } // end of wxFrame::SetMenuBar
695 void wxFrame::InternalSetMenuBar()
697 WinSendMsg((HWND
)m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
698 } // end of wxFrame::InternalSetMenuBar
701 // Responds to colour changes, and passes event on to children
703 void wxFrame::OnSysColourChanged(
704 wxSysColourChangedEvent
& rEvent
707 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
710 if (m_frameStatusBar
)
712 wxSysColourChangedEvent vEvent2
;
714 vEvent2
.SetEventObject(m_frameStatusBar
);
715 m_frameStatusBar
->GetEventHandler()->ProcessEvent(vEvent2
);
719 // Propagate the event to the non-top-level children
721 wxWindow::OnSysColourChanged(rEvent
);
722 } // end of wxFrame::OnSysColourChanged
724 // Pass TRUE to show full screen, FALSE to restore.
725 bool wxFrame::ShowFullScreen(
737 m_fsIsShowing = TRUE;
740 wxToolBar *theToolBar = GetToolBar();
741 wxStatusBar *theStatusBar = GetStatusBar();
746 theToolBar->GetSize(&dummyWidth, &m_fsToolBarHeight);
748 theStatusBar->GetSize(&dummyWidth, &m_fsStatusBarHeight);
750 // zap the toolbar, menubar, and statusbar
752 if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
754 theToolBar->SetSize(-1,0);
755 theToolBar->Show(FALSE);
758 if (style & wxFULLSCREEN_NOMENUBAR)
759 SetMenu((HWND)GetHWND(), (HMENU) NULL);
761 // Save the number of fields in the statusbar
762 if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
764 m_fsStatusBarFields = theStatusBar->GetFieldsCount();
765 SetStatusBar((wxStatusBar*) NULL);
769 m_fsStatusBarFields = 0;
771 // zap the frame borders
773 // save the 'normal' window style
774 m_fsOldWindowStyle = GetWindowLong((HWND)GetHWND(), GWL_STYLE);
776 // save the old position, width & height, maximize state
777 m_fsOldSize = GetRect();
778 m_fsIsMaximized = IsMaximized();
780 // decide which window style flags to turn off
781 LONG newStyle = m_fsOldWindowStyle;
784 if (style & wxFULLSCREEN_NOBORDER)
785 offFlags |= WS_BORDER;
786 if (style & wxFULLSCREEN_NOCAPTION)
787 offFlags |= (WS_CAPTION | WS_SYSMENU);
789 newStyle &= (~offFlags);
791 // change our window style to be compatible with full-screen mode
792 SetWindowLong((HWND)GetHWND(), GWL_STYLE, newStyle);
794 // resize to the size of the desktop
798 ::GetWindowRect(GetDesktopWindow(), &rect);
799 width = rect.right - rect.left;
800 height = rect.bottom - rect.top;
802 SetSize(width, height);
804 // now flush the window style cache and actually go full-screen
805 SetWindowPos((HWND)GetHWND(), HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED);
807 wxSizeEvent event(wxSize(width, height), GetId());
808 GetEventHandler()->ProcessEvent(event);
817 m_fsIsShowing = FALSE;
819 wxToolBar *theToolBar = GetToolBar();
821 // restore the toolbar, menubar, and statusbar
822 if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR))
824 theToolBar->SetSize(-1, m_fsToolBarHeight);
825 theToolBar->Show(TRUE);
828 if ((m_fsStyle & wxFULLSCREEN_NOSTATUSBAR) && (m_fsStatusBarFields > 0))
830 CreateStatusBar(m_fsStatusBarFields);
834 if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0))
835 SetMenu((HWND)GetHWND(), (HMENU)m_hMenu);
837 Maximize(m_fsIsMaximized);
838 SetWindowLong((HWND)GetHWND(),GWL_STYLE, m_fsOldWindowStyle);
839 SetWindowPos((HWND)GetHWND(),HWND_TOP,m_fsOldSize.x, m_fsOldSize.y,
840 m_fsOldSize.width, m_fsOldSize.height, SWP_FRAMECHANGED);
846 } // end of wxFrame::ShowFullScreen
851 bool wxFrame::OS2Create(
854 , const wxChar
* zWclass
856 , const wxChar
* zTitle
864 ULONG ulCreateFlags
= 0L;
865 ULONG ulStyleFlags
= 0L;
866 ULONG ulExtraFlags
= 0L;
867 FRAMECDATA vFrameCtlData
;
868 HWND hParent
= NULLHANDLE
;
869 HWND hClient
= NULLHANDLE
;
870 HWND hFrame
= NULLHANDLE
;
871 HWND hTitlebar
= NULLHANDLE
;
872 HWND hHScroll
= NULLHANDLE
;
873 HWND hVScroll
= NULLHANDLE
;
878 m_hDefaultIcon
= (WXHICON
) (wxSTD_FRAME_ICON
? wxSTD_FRAME_ICON
: wxDEFAULT_FRAME_ICON
);
881 hParent
= GetWinHwnd(pParent
);
883 hParent
= HWND_DESKTOP
;
885 if (ulStyle
== wxDEFAULT_FRAME_STYLE
)
886 ulCreateFlags
= FCF_SIZEBORDER
| FCF_TITLEBAR
| FCF_SYSMENU
|
887 FCF_MINMAX
| FCF_TASKLIST
;
890 if ((ulStyle
& wxCAPTION
) == wxCAPTION
)
891 ulCreateFlags
= FCF_TASKLIST
;
893 ulCreateFlags
= FCF_NOMOVEWITHOWNER
;
895 if ((ulStyle
& wxVSCROLL
) == wxVSCROLL
)
896 ulCreateFlags
|= FCF_VERTSCROLL
;
897 if ((ulStyle
& wxHSCROLL
) == wxHSCROLL
)
898 ulCreateFlags
|= FCF_HORZSCROLL
;
899 if (ulStyle
& wxMINIMIZE_BOX
)
900 ulCreateFlags
|= FCF_MINBUTTON
;
901 if (ulStyle
& wxMAXIMIZE_BOX
)
902 ulCreateFlags
|= FCF_MAXBUTTON
;
903 if (ulStyle
& wxTHICK_FRAME
)
904 ulCreateFlags
|= FCF_DLGBORDER
;
905 if (ulStyle
& wxSYSTEM_MENU
)
906 ulCreateFlags
|= FCF_SYSMENU
;
907 if (ulStyle
& wxCAPTION
)
908 ulCreateFlags
|= FCF_TASKLIST
;
909 if (ulStyle
& wxCLIP_CHILDREN
)
911 // Invalid for frame windows under PM
914 if (ulStyle
& wxTINY_CAPTION_VERT
)
915 ulCreateFlags
|= FCF_TASKLIST
;
916 if (ulStyle
& wxTINY_CAPTION_HORIZ
)
917 ulCreateFlags
|= FCF_TASKLIST
;
919 if ((ulStyle
& wxTHICK_FRAME
) == 0)
920 ulCreateFlags
|= FCF_BORDER
;
921 if (ulStyle
& wxFRAME_TOOL_WINDOW
)
922 ulExtraFlags
= kFrameToolWindow
;
924 if (ulStyle
& wxSTAY_ON_TOP
)
925 ulCreateFlags
|= FCF_SYSMODAL
;
927 if ((ulStyle
& wxMINIMIZE
) || (ulStyle
& wxICONIZE
))
928 ulStyleFlags
|= WS_MINIMIZED
;
929 if (ulStyle
& wxMAXIMIZE
)
930 ulStyleFlags
|= WS_MAXIMIZED
;
933 // Clear the visible flag, we always call show
935 ulStyleFlags
&= (unsigned long)~WS_VISIBLE
;
939 // Set the frame control block
941 vFrameCtlData
.cb
= sizeof(vFrameCtlData
);
942 vFrameCtlData
.flCreateFlags
= ulCreateFlags
;
943 vFrameCtlData
.hmodResources
= 0L;
944 vFrameCtlData
.idResources
= 0;
947 // Create the frame window
949 if ((m_hFrame
= ::WinCreateWindow( hParent
// Frame is parent
950 ,WC_FRAME
// standard frame class
951 ,(PSZ
)zTitle
// Window title
953 ,0, 0, 0, 0 // Window position
957 ,(PVOID
)&vFrameCtlData
// Creation data
958 ,NULL
// Window Pres Params
964 if (!wxWindow::OS2Create( m_hFrame
974 ,(unsigned long)FID_CLIENT
983 // Now size everything. If adding a menu the client will need to be resized.
985 if (!::WinSetWindowPos( m_hFrame
991 ,SWP_SIZE
| SWP_MOVE
| SWP_ACTIVATE
| SWP_ZORDER
995 uCtlCount
= SHORT1FROMMP(::WinSendMsg(m_hFrame
, WM_FORMATFRAME
, (MPARAM
)vSwp
, (MPARAM
)vRect
));
996 for (int i
= 0; i
< uCtlCount
; i
++)
998 if (vSwp
[i
].hwnd
== m_hFrame
)
999 memcpy(&m_vSwp
, &vSwp
[i
], sizeof(SWP
));
1000 else if (vSwp
[i
].hwnd
== m_hVScroll
)
1001 memcpy(&m_vSwpVScroll
, &vSwp
[i
], sizeof(SWP
));
1002 else if (vSwp
[i
].hwnd
== m_hHScroll
)
1003 memcpy(&m_vSwpVScroll
, &vSwp
[i
], sizeof(SWP
));
1004 else if (vSwp
[i
].hwnd
== m_hTitleBar
)
1005 memcpy(&m_vSwpTitleBar
, &vSwp
[i
], sizeof(SWP
));
1009 // Now set the size of the client
1011 WinSetWindowPos( hClient
1014 ,(SV_CYSIZEBORDER
/2) + m_vSwpHScroll
.cy
/2
1015 ,m_vSwp
.cx
- ((SV_CXSIZEBORDER
+ 1) + m_vSwpVScroll
.cx
)
1016 ,m_vSwp
.cy
- ((SV_CYSIZEBORDER
+ 1) + m_vSwpTitleBar
.cy
+ m_vSwpHScroll
.cy
/2)
1017 ,SWP_SIZE
| SWP_MOVE
1021 // Set the client window's background, otherwise it is transparent!
1024 } // end of wxFrame::OS2Create
1027 // Default activation behaviour - set the focus for the first child
1030 void wxFrame::OnActivate(
1031 wxActivateEvent
& rEvent
1034 for (wxWindowList::Node
* pNode
= GetChildren().GetFirst();
1036 pNode
= pNode
->GetNext())
1038 // FIXME all this is totally bogus - we need to do the same as wxPanel,
1039 // but how to do it without duplicating the code?
1042 wxWindow
* pChild
= pNode
->GetData();
1044 if (!pChild
->IsTopLevel()
1046 && !wxDynamicCast(pChild
, wxToolBar
)
1047 #endif // wxUSE_TOOLBAR
1049 && !wxDynamicCast(pChild
, wxStatusBar
)
1050 #endif // wxUSE_STATUSBAR
1057 } // end of wxFrame::OnActivate
1059 // ----------------------------------------------------------------------------
1060 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1061 // from the client area, so the client area is what's really available for the
1063 // ----------------------------------------------------------------------------
1065 // Checks if there is a toolbar, and returns the first free client position
1066 wxPoint
wxFrame::GetClientAreaOrigin() const
1068 wxPoint
vPoint(0, 0);
1075 GetToolBar()->GetSize( &nWidth
1079 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
1085 // PM is backwards from windows
1086 vPoint
.y
+= nHeight
;
1090 } // end of wxFrame::GetClientAreaOrigin
1092 // ----------------------------------------------------------------------------
1093 // tool/status bar stuff
1094 // ----------------------------------------------------------------------------
1098 wxToolBar
* wxFrame::CreateToolBar(
1101 , const wxString
& rName
1104 if (wxFrameBase::CreateToolBar( lStyle
1111 return m_frameToolBar
;
1112 } // end of wxFrame::CreateToolBar
1114 void wxFrame::PositionToolBar()
1119 ::WinQueryWindowRect(GetHwnd(), &vRect
);
1127 GetStatusBar()->GetClientSize( &nStatusX
1130 // PM is backwards from windows
1131 vRect
.yBottom
+= nStatusY
;
1133 #endif // wxUSE_STATUSBAR
1140 GetToolBar()->GetSize( &nToolbarWidth
1144 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
1146 nToolbarHeight
= vRect
.yBottom
;
1150 nToolbarWidth
= vRect
.xRight
;
1154 // Use the 'real' PM position here
1156 GetToolBar()->SetSize( 0
1160 ,wxSIZE_NO_ADJUSTMENTS
1163 } // end of wxFrame::PositionToolBar
1164 #endif // wxUSE_TOOLBAR
1166 // ----------------------------------------------------------------------------
1167 // frame state (iconized/maximized/...)
1168 // ----------------------------------------------------------------------------
1171 // propagate our state change to all child frames: this allows us to emulate X
1172 // Windows behaviour where child frames float independently of the parent one
1173 // on the desktop, but are iconized/restored with it
1175 void wxFrame::IconizeChildFrames(
1179 for (wxWindowList::Node
* pNode
= GetChildren().GetFirst();
1181 pNode
= pNode
->GetNext() )
1183 wxWindow
* pWin
= pNode
->GetData();
1185 if (pWin
->IsKindOf(CLASSINFO(wxFrame
)) )
1187 ((wxFrame
*)pWin
)->Iconize(bIconize
);
1190 } // end of wxFrame::IconizeChildFrames
1192 // ===========================================================================
1193 // message processing
1194 // ===========================================================================
1196 // ---------------------------------------------------------------------------
1198 // ---------------------------------------------------------------------------
1199 bool wxFrame::OS2TranslateMessage(
1204 // try the menu bar accels
1206 wxMenuBar
* pMenuBar
= GetMenuBar();
1211 const wxAcceleratorTable
& rAcceleratorTable
= pMenuBar
->GetAccelTable();
1212 return rAcceleratorTable
.Translate(m_hFrame
, pMsg
);
1213 } // end of wxFrame::OS2TranslateMessage
1215 // ---------------------------------------------------------------------------
1216 // our private (non virtual) message handlers
1217 // ---------------------------------------------------------------------------
1218 bool wxFrame::HandlePaint()
1222 if (::WinQueryUpdateRect(m_hFrame
, &vRect
))
1227 // Icons in PM are the same as "pointers"
1232 hIcon
= (HPOINTER
)::WinSendMsg(m_hFrame
, WM_QUERYICON
, 0L, 0L);
1234 hIcon
= (HPOINTER
)m_hDefaultIcon
;
1237 // Hold a pointer to the dc so long as the OnPaint() message
1238 // is being processed
1241 HPS hPs
= ::WinBeginPaint(m_hFrame
, NULLHANDLE
, &vRect2
);
1244 // Erase background before painting or we get white background
1246 OS2DefWindowProc(WM_ERASEBACKGROUND
, (MPARAM
)hPs
, (MPARAM
)&vRect2
);
1253 ::WinQueryWindowRect(GetHwnd(), &vRect3
);
1255 static const int nIconWidth
= 32;
1256 static const int nIconHeight
= 32;
1257 int nIconX
= (int)((vRect3
.xRight
- nIconWidth
)/2);
1258 int nIconY
= (int)((vRect3
.yBottom
+ nIconHeight
)/2);
1260 ::WinDrawPointer(hPs
, nIconX
, nIconY
, hIcon
, DP_NORMAL
);
1270 hPS
= WinBeginPaint(GetHwnd(), 0L, &vRect
);
1271 WinFillRect(hPS
, &vRect
, SYSCLR_WINDOW
);
1274 return wxWindow::HandlePaint();
1279 // nothing to paint - processed
1283 } // end of wxFrame::HandlePaint
1285 bool wxFrame::HandleSize(
1291 bool bProcessed
= FALSE
;
1297 // Only do it it if we were iconized before, otherwise resizing the
1298 // parent frame has a curious side effect of bringing it under it's
1304 // restore all child frames too
1306 IconizeChildFrames(FALSE
);
1313 m_bIconized
= FALSE
;
1318 // Iconize all child frames too
1320 IconizeChildFrames(TRUE
);
1328 // forward WM_SIZE to status bar control
1330 #if wxUSE_NATIVE_STATUSBAR
1331 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
1333 wxSizeEvent
vEvent( wxSize( nX
1336 ,m_frameStatusBar
->GetId()
1339 vEvent
.SetEventObject(m_frameStatusBar
);
1340 m_frameStatusBar
->OnSize(vEvent
);
1342 #endif // wxUSE_NATIVE_STATUSBAR
1344 PositionStatusBar();
1346 wxSizeEvent
vEvent( wxSize( nX
1352 vEvent
.SetEventObject(this);
1353 bProcessed
= GetEventHandler()->ProcessEvent(vEvent
);
1356 } // end of wxFrame::HandleSize
1358 bool wxFrame::HandleCommand(
1367 // In case it's e.g. a toolbar.
1369 wxWindow
* pWin
= wxFindWinFromHandle(hControl
);
1372 return pWin
->OS2Command( nCmd
1378 // Handle here commands from menus and accelerators
1380 if (nCmd
== 0 || nCmd
== 1)
1382 if (wxCurrentPopupMenu
)
1384 wxMenu
* pPopupMenu
= wxCurrentPopupMenu
;
1386 wxCurrentPopupMenu
= NULL
;
1388 return pPopupMenu
->OS2Command( nCmd
1393 if (ProcessCommand(nId
))
1399 } // end of wxFrame::HandleCommand
1401 bool wxFrame::HandleMenuSelect(
1409 if (nFlags
== 0xFFFF && hMenu
== 0)
1412 // Menu was removed from screen
1416 else if (!(nFlags
& MIS_SUBMENU
) && !(nFlags
& MIS_SEPARATOR
))
1423 // Don't give hints for separators (doesn't make sense) nor for the
1424 // items opening popup menus (they don't have them anyhow)
1428 wxMenuEvent
vEvent(wxEVT_MENU_HIGHLIGHT
, nMenuItem
);
1430 vEvent
.SetEventObject(this);
1431 return GetEventHandler()->ProcessEvent(vEvent
);
1432 } // end of wxFrame::HandleMenuSelect
1434 // ---------------------------------------------------------------------------
1435 // the window proc for wxFrame
1436 // ---------------------------------------------------------------------------
1438 MRESULT
wxFrame::OS2WindowProc(
1445 bool bProcessed
= FALSE
;
1451 // If we can't close, tell the system that we processed the
1452 // message - otherwise it would close us
1454 bProcessed
= !Close();
1463 UnpackCommand( (WXWPARAM
)wParam
1469 bProcessed
= HandleCommand( wId
1482 UnpackMenuSelect( wParam
1488 bProcessed
= HandleMenuSelect( wItem
1496 bProcessed
= HandlePaint();
1499 case WM_ERASEBACKGROUND
:
1501 // Return TRUE to request PM to paint the window background
1502 // in SYSCLR_WINDOW.
1505 mRc
= (MRESULT
)(TRUE
);
1508 case CM_QUERYDRAGIMAGE
:
1513 hIcon
= (HPOINTER
)::WinSendMsg(m_hFrame
, WM_QUERYICON
, 0L, 0L);
1515 hIcon
= (HPOINTER
)m_hDefaultIcon
;
1516 mRc
= (MRESULT
)hIcon
;
1517 bProcessed
= mRc
!= 0;
1522 bProcessed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), (WXUINT
)wParam
);
1527 mRc
= wxWindow::OS2WindowProc( uMessage
1532 } // wxFrame::OS2WindowProc