1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/frame.cpp
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"
16 #include "wx/object.h"
17 #include "wx/dynarray.h"
20 #include "wx/string.h"
28 #include "wx/dialog.h"
29 #include "wx/settings.h"
30 #include "wx/dcclient.h"
32 #include "wx/toolbar.h"
33 #include "wx/statusbr.h"
34 #include "wx/menuitem.h"
37 #include "wx/os2/private.h"
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 #if wxUSE_MENUS_NATIVE
44 extern wxMenu
*wxCurrentPopupMenu
;
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
52 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
55 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxWindow
)
57 // ============================================================================
59 // ============================================================================
61 // ----------------------------------------------------------------------------
62 // static class members
63 // ----------------------------------------------------------------------------
66 #if wxUSE_NATIVE_STATUSBAR
67 bool wxFrame::m_bUseNativeStatusBar
= true;
69 bool wxFrame::m_bUseNativeStatusBar
= false;
72 #endif //wxUSE_STATUSBAR
74 // ----------------------------------------------------------------------------
75 // creation/destruction
76 // ----------------------------------------------------------------------------
80 m_nFsStatusBarFields
= 0;
81 m_nFsStatusBarHeight
= 0;
82 m_nFsToolBarHeight
= 0;
84 m_bWasMinimized
= false;
87 m_frameMenuBar
= NULL
;
88 m_frameToolBar
= NULL
;
89 m_frameStatusBar
= NULL
;
91 m_hTitleBar
= NULLHANDLE
;
92 m_hHScroll
= NULLHANDLE
;
93 m_hVScroll
= NULLHANDLE
;
98 memset(&m_vSwpTitleBar
, 0, sizeof(SWP
));
99 memset(&m_vSwpMenuBar
, 0, sizeof(SWP
));
100 memset(&m_vSwpHScroll
, 0, sizeof(SWP
));
101 memset(&m_vSwpVScroll
, 0, sizeof(SWP
));
102 memset(&m_vSwpStatusBar
, 0, sizeof(SWP
));
103 memset(&m_vSwpToolBar
, 0, sizeof(SWP
));
106 } // end of wxFrame::Init
108 bool wxFrame::Create( wxWindow
* pParent
,
110 const wxString
& rsTitle
,
114 const wxString
& rsName
)
116 if (!wxTopLevelWindow::Create( pParent
126 } // end of wxFrame::Create
133 } // end of wxFrame::~wxFrame
136 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
138 void wxFrame::DoGetClientSize(
143 wxTopLevelWindow::DoGetClientSize( pX
147 // No need to use statusbar code as in WIN32 as the FORMATFRAME
148 // window procedure ensures PM knows about the new frame client
149 // size internally. A ::WinQueryWindowRect (that is called in
150 // wxWindow's GetClient size from above) is all that is needed!
152 } // end of wxFrame::DoGetClientSize
155 // Set the client size (i.e. leave the calculation of borders etc.
158 void wxFrame::DoSetClientSize(
164 // Statusbars are not part of the OS/2 Client but parent frame
165 // so no statusbar consideration
167 wxTopLevelWindow::DoSetClientSize( nWidth
170 } // end of wxFrame::DoSetClientSize
172 // ----------------------------------------------------------------------------
173 // wxFrame: various geometry-related functions
174 // ----------------------------------------------------------------------------
176 void wxFrame::Raise()
178 wxFrameBase::Raise();
179 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
190 wxStatusBar
* wxFrame::OnCreateStatusBar(
194 , const wxString
& rName
197 wxStatusBar
* pStatusBar
= NULL
;
200 pStatusBar
= wxFrameBase::OnCreateStatusBar( nNumber
209 wxClientDC
vDC(pStatusBar
);
213 // Set the height according to the font and the border size
215 vDC
.SetFont(pStatusBar
->GetFont()); // Screws up the menues for some reason
216 vDC
.GetTextExtent( wxT("X")
221 int nHeight
= ((11 * nY
) / 10 + 2 * pStatusBar
->GetBorderY());
223 pStatusBar
->SetSize( wxDefaultCoord
229 ::WinSetParent( pStatusBar
->GetHWND(), m_hFrame
, FALSE
);
230 ::WinSetOwner( pStatusBar
->GetHWND(), m_hFrame
);
234 if(::WinIsWindowShowing(m_hFrame
))
235 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0);
238 } // end of wxFrame::OnCreateStatusBar
240 void wxFrame::PositionStatusBar()
247 // Native status bar positions itself
249 if (m_frameStatusBar
)
258 ::WinQueryWindowRect(m_hFrame
, &vRect
);
260 ::WinMapWindowPoints(m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRect
, 2);
262 ::WinCalcFrameRect(m_hFrame
, &vRect
, TRUE
);
263 nWidth
= vRect
.xRight
- vRect
.xLeft
;
264 nY
= nY
- (vRect
.yBottom
- vFRect
.yBottom
);
266 m_frameStatusBar
->GetSize( &nStatbarWidth
270 nY
= nY
- nStatbarHeight
;
272 // Since we wish the status bar to be directly under the client area,
273 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
275 m_frameStatusBar
->SetSize( vRect
.xLeft
- vFRect
.xLeft
280 if (!::WinQueryWindowPos(m_frameStatusBar
->GetHWND(), &vSwp
))
282 vError
= ::WinGetLastError(vHabmain
);
283 sError
= wxPMErrorToStr(vError
);
284 wxLogError(wxT("Error setting parent for StatusBar. Error: %s\n"), sError
.c_str());
288 } // end of wxFrame::PositionStatusBar
289 #endif // wxUSE_STATUSBAR
292 wxToolBar
* wxFrame::OnCreateToolBar( long lStyle
, wxWindowID vId
, const wxString
& rsName
)
294 wxToolBar
* pToolBar
= wxFrameBase::OnCreateToolBar( lStyle
299 ::WinSetParent( pToolBar
->GetHWND(), m_hFrame
, FALSE
);
300 ::WinSetOwner( pToolBar
->GetHWND(), m_hFrame
);
302 } // end of WinGuiBase_CFrame::OnCreateToolBar
305 #if wxUSE_MENUS_NATIVE
306 void wxFrame::DetachMenuBar()
310 m_frameMenuBar
->Detach();
311 m_frameMenuBar
= NULL
;
313 } // end of wxFrame::DetachMenuBar
315 void wxFrame::SetMenuBar(
326 // Actually remove the menu from the frame
328 m_hMenu
= (WXHMENU
)0;
329 InternalSetMenuBar();
331 else // set new non NULL menu bar
333 m_frameMenuBar
= NULL
;
336 // Can set a menubar several times.
337 // TODO: how to prevent a memory leak if you have a currently-unattached
338 // menubar? wxWidgets assumes that the frame will delete the menu (otherwise
339 // there are problems for MDI).
341 if (pMenuBar
->GetHMenu())
343 m_hMenu
= pMenuBar
->GetHMenu();
348 m_hMenu
= pMenuBar
->Create();
352 InternalSetMenuBar();
353 m_frameMenuBar
= pMenuBar
;
354 pMenuBar
->Attach((wxFrame
*)this);
356 } // end of wxFrame::SetMenuBar
358 void wxFrame::AttachMenuBar(
362 wxFrameBase::AttachMenuBar(pMenubar
);
364 m_frameMenuBar
= pMenubar
;
369 // Actually remove the menu from the frame
371 m_hMenu
= (WXHMENU
)0;
372 InternalSetMenuBar();
374 else // Set new non NULL menu bar
377 // Can set a menubar several times.
379 if (pMenubar
->GetHMenu())
381 m_hMenu
= pMenubar
->GetHMenu();
385 if (pMenubar
->IsAttached())
388 m_hMenu
= pMenubar
->Create();
393 InternalSetMenuBar();
395 } // end of wxFrame::AttachMenuBar
397 void wxFrame::InternalSetMenuBar()
402 // Set the parent and owner of the menubar to be the frame
404 if (!::WinSetParent(m_hMenu
, m_hFrame
, FALSE
))
406 vError
= ::WinGetLastError(vHabmain
);
407 sError
= wxPMErrorToStr(vError
);
408 wxLogError(wxT("Error setting parent for submenu. Error: %s\n"), sError
.c_str());
411 if (!::WinSetOwner(m_hMenu
, m_hFrame
))
413 vError
= ::WinGetLastError(vHabmain
);
414 sError
= wxPMErrorToStr(vError
);
415 wxLogError(wxT("Error setting parent for submenu. Error: %s\n"), sError
.c_str());
417 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
418 } // end of wxFrame::InternalSetMenuBar
419 #endif // wxUSE_MENUS_NATIVE
422 // Responds to colour changes, and passes event on to children
424 void wxFrame::OnSysColourChanged(
425 wxSysColourChangedEvent
& rEvent
428 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
432 if (m_frameStatusBar
)
434 wxSysColourChangedEvent vEvent2
;
436 vEvent2
.SetEventObject(m_frameStatusBar
);
437 m_frameStatusBar
->HandleWindowEvent(vEvent2
);
439 #endif //wxUSE_STATUSBAR
442 // Propagate the event to the non-top-level children
444 wxWindow::OnSysColourChanged(rEvent
);
445 } // end of wxFrame::OnSysColourChanged
447 // Pass true to show full screen, false to restore.
448 bool wxFrame::ShowFullScreen( bool bShow
, long lStyle
)
455 m_bFsIsShowing
= true;
459 wxToolBar
* pTheToolBar
= GetToolBar();
460 #endif //wxUSE_TOOLBAR
463 wxStatusBar
* pTheStatusBar
= GetStatusBar();
464 #endif //wxUSE_STATUSBAR
470 pTheToolBar
->GetSize(&nDummyWidth
, &m_nFsToolBarHeight
);
471 #endif //wxUSE_TOOLBAR
475 pTheStatusBar
->GetSize(&nDummyWidth
, &m_nFsStatusBarHeight
);
476 #endif //wxUSE_STATUSBAR
480 // Zap the toolbar, menubar, and statusbar
482 if ((lStyle
& wxFULLSCREEN_NOTOOLBAR
) && pTheToolBar
)
484 pTheToolBar
->SetSize(wxDefaultCoord
,0);
485 pTheToolBar
->Show(false);
487 #endif //wxUSE_TOOLBAR
489 if (lStyle
& wxFULLSCREEN_NOMENUBAR
)
491 ::WinSetParent(m_hMenu
, m_hFrame
, FALSE
);
492 ::WinSetOwner(m_hMenu
, m_hFrame
);
493 ::WinSendMsg((HWND
)m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
498 // Save the number of fields in the statusbar
500 if ((lStyle
& wxFULLSCREEN_NOSTATUSBAR
) && pTheStatusBar
)
502 m_nFsStatusBarFields
= pTheStatusBar
->GetFieldsCount();
504 delete pTheStatusBar
;
507 m_nFsStatusBarFields
= 0;
508 #endif //wxUSE_STATUSBAR
511 // Zap the frame borders
515 // Save the 'normal' window style
517 m_lFsOldWindowStyle
= ::WinQueryWindowULong(m_hFrame
, QWL_STYLE
);
520 // Save the old position, width & height, maximize state
522 m_vFsOldSize
= GetRect();
523 m_bFsIsMaximized
= IsMaximized();
526 // Decide which window style flags to turn off
528 LONG lNewStyle
= m_lFsOldWindowStyle
;
531 if (lStyle
& wxFULLSCREEN_NOBORDER
)
532 lOffFlags
|= FCF_BORDER
;
533 if (lStyle
& wxFULLSCREEN_NOCAPTION
)
534 lOffFlags
|= (FCF_TASKLIST
| FCF_SYSMENU
);
536 lNewStyle
&= (~lOffFlags
);
539 // Change our window style to be compatible with full-screen mode
541 ::WinSetWindowULong((HWND
)m_hFrame
, QWL_STYLE
, (ULONG
)lNewStyle
);
544 // Resize to the size of the desktop
550 ::WinQueryWindowRect(HWND_DESKTOP
, &vRect
);
551 nWidth
= vRect
.xRight
- vRect
.xLeft
;
553 // Remember OS/2 is backwards!
555 nHeight
= vRect
.yTop
- vRect
.yBottom
;
557 SetSize( nWidth
, nHeight
);
560 // Now flush the window style cache and actually go full-screen
562 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
571 wxSize
sz( nWidth
, nHeight
);
572 wxSizeEvent
vEvent( sz
, GetId() );
574 HandleWindowEvent(vEvent
);
582 m_bFsIsShowing
= false;
585 wxToolBar
* pTheToolBar
= GetToolBar();
588 // Restore the toolbar, menubar, and statusbar
590 if (pTheToolBar
&& (m_lFsStyle
& wxFULLSCREEN_NOTOOLBAR
))
592 pTheToolBar
->SetSize(wxDefaultCoord
, m_nFsToolBarHeight
);
593 pTheToolBar
->Show(true);
595 #endif //wxUSE_TOOLBAR
598 if ((m_lFsStyle
& wxFULLSCREEN_NOSTATUSBAR
) && (m_nFsStatusBarFields
> 0))
600 CreateStatusBar(m_nFsStatusBarFields
);
601 // PositionStatusBar();
603 #endif //wxUSE_STATUSBAR
605 if ((m_lFsStyle
& wxFULLSCREEN_NOMENUBAR
) && (m_hMenu
!= 0))
607 ::WinSetParent(m_hMenu
, m_hFrame
, FALSE
);
608 ::WinSetOwner(m_hMenu
, m_hFrame
);
609 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
611 Maximize(m_bFsIsMaximized
);
613 ::WinSetWindowULong( m_hFrame
615 ,(ULONG
)m_lFsOldWindowStyle
617 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
626 return wxFrameBase::ShowFullScreen(bShow
, lStyle
);
627 } // end of wxFrame::ShowFullScreen
632 // ----------------------------------------------------------------------------
633 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
634 // from the client area, so the client area is what's really available for the
636 // ----------------------------------------------------------------------------
638 // Checks if there is a toolbar, and returns the first free client position
639 wxPoint
wxFrame::GetClientAreaOrigin() const
641 wxPoint vPoint
= wxTopLevelWindow::GetClientAreaOrigin();
644 // In OS/2 the toolbar and statusbar are frame extensions so there is no
645 // adjustment. The client is supposedly resized for a toolbar in OS/2
646 // as it is for the status bar.
649 } // end of wxFrame::GetClientAreaOrigin
651 // ----------------------------------------------------------------------------
652 // tool/status bar stuff
653 // ----------------------------------------------------------------------------
657 wxToolBar
* wxFrame::CreateToolBar(
660 , const wxString
& rName
663 if (wxFrameBase::CreateToolBar( lStyle
670 return m_frameToolBar
;
671 } // end of wxFrame::CreateToolBar
673 void wxFrame::PositionToolBar()
675 wxToolBar
* pToolBar
= GetToolBar();
688 ::WinQueryWindowRect(m_hFrame
, &vRect
);
689 vPos
.y
= (wxCoord
)vRect
.yTop
;
690 ::WinMapWindowPoints(m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRect
, 2);
692 ::WinCalcFrameRect(m_hFrame
, &vRect
, TRUE
);
694 vPos
.y
= (wxCoord
)(vFRect
.yTop
- vRect
.yTop
);
695 pToolBar
->GetSize( &vTWidth
699 if (pToolBar
->GetWindowStyleFlag() & wxTB_TOP
)
701 vWidth
= (wxCoord
)(vRect
.xRight
- vRect
.xLeft
);
702 pToolBar
->SetSize( vRect
.xLeft
- vFRect
.xLeft
708 else if (pToolBar
->GetWindowStyleFlag() & wxTB_BOTTOM
)
711 wxCoord vSheight
= 0;
713 if (m_frameStatusBar
)
714 m_frameStatusBar
->GetSize( &vSwidth
717 vWidth
= (wxCoord
)(vRect
.xRight
- vRect
.xLeft
);
718 pToolBar
->SetSize( vRect
.xLeft
- vFRect
.xLeft
719 ,vFRect
.yTop
- vRect
.yBottom
- vTHeight
- vSheight
724 else if (pToolBar
->GetWindowStyleFlag() & wxTB_LEFT
)
727 wxCoord vSheight
= 0;
729 if (m_frameStatusBar
)
730 m_frameStatusBar
->GetSize( &vSwidth
733 vHeight
= (wxCoord
)(vRect
.yTop
- vRect
.yBottom
);
734 pToolBar
->SetSize( vRect
.xLeft
- vRect
.xLeft
743 wxCoord vSheight
= 0;
745 if (m_frameStatusBar
)
746 m_frameStatusBar
->GetSize( &vSwidth
749 vHeight
= (wxCoord
)(vRect
.yTop
- vRect
.yBottom
);
750 pToolBar
->SetSize( vRect
.xRight
- vFRect
.xLeft
- vTWidth
756 if( ::WinIsWindowShowing(m_hFrame
) )
757 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0);
758 } // end of wxFrame::PositionToolBar
759 #endif // wxUSE_TOOLBAR
761 // ----------------------------------------------------------------------------
762 // frame state (iconized/maximized/...)
763 // ----------------------------------------------------------------------------
766 // propagate our state change to all child frames: this allows us to emulate X
767 // Windows behaviour where child frames float independently of the parent one
768 // on the desktop, but are iconized/restored with it
770 void wxFrame::IconizeChildFrames( bool WXUNUSED(bIconize
) )
772 // FIXME: Generic MDI does not use Frames for the Childs, so this does _not_
773 // work. Possibly, the right thing is simply to eliminate this
774 // functions and all the calls to it from within this file.
776 for (wxWindowList::Node
* pNode
= GetChildren().GetFirst();
778 pNode
= pNode
->GetNext() )
780 wxWindow
* pWin
= pNode
->GetData();
781 wxFrame
* pFrame
= wxDynamicCast(pWin
, wxFrame
);
784 #if wxUSE_MDI_ARCHITECTURE
785 && !wxDynamicCast(pFrame
, wxMDIChildFrame
)
786 #endif // wxUSE_MDI_ARCHITECTURE
790 // We don't want to restore the child frames which had been
791 // iconized even before we were iconized, so save the child frame
792 // status when iconizing the parent frame and check it when
797 pFrame
->m_bWasMinimized
= pFrame
->IsIconized();
801 // This test works for both iconizing and restoring
803 if (!pFrame
->m_bWasMinimized
)
804 pFrame
->Iconize(bIconize
);
808 } // end of wxFrame::IconizeChildFrames
810 WXHICON
wxFrame::GetDefaultIcon() const
812 return (WXHICON
)(wxSTD_FRAME_ICON
? wxSTD_FRAME_ICON
813 : wxDEFAULT_FRAME_ICON
);
815 // ===========================================================================
816 // message processing
817 // ===========================================================================
819 // ---------------------------------------------------------------------------
821 // ---------------------------------------------------------------------------
822 bool wxFrame::OS2TranslateMessage( WXMSG
* pMsg
)
825 // try the menu bar accels
827 wxMenuBar
* pMenuBar
= GetMenuBar();
832 #if wxUSE_ACCEL && wxUSE_MENUS_NATIVE
833 const wxAcceleratorTable
& rAcceleratorTable
= pMenuBar
->GetAccelTable();
834 return rAcceleratorTable
.Translate(GetHWND(), pMsg
);
838 } // end of wxFrame::OS2TranslateMessage
840 // ---------------------------------------------------------------------------
841 // our private (non virtual) message handlers
842 // ---------------------------------------------------------------------------
843 bool wxFrame::HandlePaint()
847 if (::WinQueryUpdateRect(GetHWND(), &vRect
))
852 // Icons in PM are the same as "pointers"
854 const wxIcon
& vIcon
= GetIcon();
858 hIcon
= (HPOINTER
)::WinSendMsg(m_hFrame
, WM_QUERYICON
, 0L, 0L);
860 hIcon
= (HPOINTER
)m_hDefaultIcon
;
863 // Hold a pointer to the dc so long as the OnPaint() message
864 // is being processed
867 HPS hPs
= ::WinBeginPaint(GetHwnd(), NULLHANDLE
, &vRect2
);
870 // Erase background before painting or we get white background
872 OS2DefWindowProc(WM_ERASEBACKGROUND
, (MPARAM
)hPs
, (MPARAM
)&vRect2
);
878 ::WinQueryWindowRect(GetHwnd(), &vRect3
);
880 static const int nIconWidth
= 32;
881 static const int nIconHeight
= 32;
882 int nIconX
= (int)((vRect3
.xRight
- nIconWidth
)/2);
883 int nIconY
= (int)((vRect3
.yBottom
+ nIconHeight
)/2);
885 ::WinDrawPointer(hPs
, nIconX
, nIconY
, hIcon
, DP_NORMAL
);
891 if (!wxWindow::HandlePaint())
896 hPS
= ::WinBeginPaint( GetHwnd()
902 ::GpiCreateLogColorTable( hPS
906 ,(LONG
)wxTheColourDatabase
->m_nSize
907 ,(PLONG
)wxTheColourDatabase
->m_palTable
909 ::GpiCreateLogColorTable( hPS
919 ,GetBackgroundColour().GetPixel()
928 } // end of wxFrame::HandlePaint
930 bool wxFrame::HandleSize( int nX
, int nY
, WXUINT nId
)
932 bool bProcessed
= false;
938 // Only do it it if we were iconized before, otherwise resizing the
939 // parent frame has a curious side effect of bringing it under it's
945 // restore all child frames too
947 IconizeChildFrames(false);
948 (void)SendIconizeEvent(false);
960 // Iconize all child frames too
962 IconizeChildFrames(true);
963 (void)SendIconizeEvent();
971 // forward WM_SIZE to status bar control
973 #if wxUSE_NATIVE_STATUSBAR
974 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
976 wxSizeEvent
vEvent( wxSize( nX
979 ,m_frameStatusBar
->GetId()
982 vEvent
.SetEventObject(m_frameStatusBar
);
983 m_frameStatusBar
->OnSize(vEvent
);
985 #endif // wxUSE_NATIVE_STATUSBAR
990 #endif // wxUSE_TOOLBAR
992 bProcessed
= wxWindow::HandleSize( nX
998 } // end of wxFrame::HandleSize
1000 bool wxFrame::HandleCommand( WXWORD nId
,
1007 // In case it's e.g. a toolbar.
1009 wxWindow
* pWin
= wxFindWinFromHandle(hControl
);
1012 return pWin
->OS2Command( nCmd
, nId
);
1016 // Handle here commands from menus and accelerators
1018 if (nCmd
== CMDSRC_MENU
|| nCmd
== CMDSRC_ACCELERATOR
)
1020 #if wxUSE_MENUS_NATIVE
1021 if (wxCurrentPopupMenu
)
1023 wxMenu
* pPopupMenu
= wxCurrentPopupMenu
;
1025 wxCurrentPopupMenu
= NULL
;
1027 return pPopupMenu
->OS2Command( nCmd
, nId
);
1031 if (ProcessCommand(nId
))
1037 } // end of wxFrame::HandleCommand
1039 bool wxFrame::HandleMenuSelect( WXWORD nItem
,
1048 rc
= ::WinSendMsg(hMenu
, MM_QUERYITEM
, MPFROM2SHORT(nItem
, TRUE
), (MPARAM
)&mItem
);
1050 if(rc
&& !(mItem
.afStyle
& (MIS_SUBMENU
| MIS_SEPARATOR
)))
1052 wxMenuEvent
vEvent(wxEVT_MENU_HIGHLIGHT
, nItem
);
1054 vEvent
.SetEventObject(this);
1055 HandleWindowEvent(vEvent
); // return value would be ignored by PM
1059 DoGiveHelp(wxEmptyString
, true);
1064 } // end of wxFrame::HandleMenuSelect
1066 // ---------------------------------------------------------------------------
1067 // Main Frame window proc
1068 // ---------------------------------------------------------------------------
1069 MRESULT EXPENTRY
wxFrameMainWndProc( HWND hWnd
,
1074 MRESULT rc
= (MRESULT
)0;
1075 bool bProcessed
= false;
1076 wxFrame
* pWnd
= NULL
;
1078 pWnd
= (wxFrame
*) wxFindWinFromHandle((WXHWND
) hWnd
);
1081 case WM_QUERYFRAMECTLCOUNT
:
1082 if(pWnd
&& pWnd
->m_fnOldWndProc
)
1084 USHORT uItemCount
= SHORT1FROMMR(pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
));
1086 rc
= MRFROMSHORT(uItemCount
);
1090 case WM_FORMATFRAME
:
1091 /////////////////////////////////////////////////////////////////////////////////
1092 // Applications that subclass frame controls may find that the frame is already
1093 // subclassed the number of frame controls is variable.
1094 // The WM_FORMATFRAME and WM_QUERYFRAMECTLCOUNT messages must always be
1095 // subclassed by calling the previous window procedure and modifying its result.
1096 ////////////////////////////////////////////////////////////////////////////////
1108 pSWP
= (PSWP
)PVOIDFROMMP(wParam
);
1109 nItemCount
= SHORT1FROMMR(pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
));
1110 if(pWnd
->m_frameStatusBar
)
1112 ::WinQueryWindowRect(pWnd
->m_frameStatusBar
->GetHWND(), &vRstb
);
1113 pWnd
->m_frameStatusBar
->GetSize(NULL
, &nHeight
);
1115 if(pWnd
->m_frameToolBar
)
1117 ::WinQueryWindowRect(pWnd
->m_frameToolBar
->GetHWND(), &vRtlb
);
1118 pWnd
->m_frameToolBar
->GetSize(&nWidth
, &nHeight2
);
1120 ::WinQueryWindowRect(pWnd
->m_hFrame
, &vRectl
);
1121 ::WinMapWindowPoints(pWnd
->m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRectl
, 2);
1122 ::WinCalcFrameRect(pWnd
->m_hFrame
, &vRectl
, TRUE
);
1123 ::WinMapWindowPoints(HWND_DESKTOP
, pWnd
->m_hFrame
, (PPOINTL
)&vRectl
, 2);
1124 for(i
= 0; i
< nItemCount
; i
++)
1126 if(pWnd
->m_hWnd
&& pSWP
[i
].hwnd
== pWnd
->m_hWnd
)
1128 if (pWnd
->m_frameToolBar
&& pWnd
->m_frameToolBar
->GetWindowStyleFlag() & wxTB_TOP
)
1130 pSWP
[i
].x
= vRectl
.xLeft
;
1131 pSWP
[i
].y
= vRectl
.yBottom
+ nHeight
;
1132 pSWP
[i
].cx
= vRectl
.xRight
- vRectl
.xLeft
;
1133 pSWP
[i
].cy
= vRectl
.yTop
- vRectl
.yBottom
- (nHeight
+ nHeight2
);
1135 else if (pWnd
->m_frameToolBar
&& pWnd
->m_frameToolBar
->GetWindowStyleFlag() & wxTB_BOTTOM
)
1137 pSWP
[i
].x
= vRectl
.xLeft
;
1138 pSWP
[i
].y
= vRectl
.yBottom
+ nHeight
+ nHeight2
;
1139 pSWP
[i
].cx
= vRectl
.xRight
- vRectl
.xLeft
;
1140 pSWP
[i
].cy
= vRectl
.yTop
- vRectl
.yBottom
- (nHeight
+ nHeight2
);
1142 else if (pWnd
->m_frameToolBar
&& pWnd
->m_frameToolBar
->GetWindowStyleFlag() & wxTB_LEFT
)
1144 pSWP
[i
].x
= vRectl
.xLeft
+ nWidth
;
1145 pSWP
[i
].y
= vRectl
.yBottom
+ nHeight
;
1146 pSWP
[i
].cx
= vRectl
.xRight
- (vRectl
.xLeft
+ nWidth
);
1147 pSWP
[i
].cy
= vRectl
.yTop
- vRectl
.yBottom
- nHeight
;
1151 pSWP
[i
].x
= vRectl
.xLeft
;
1152 pSWP
[i
].y
= vRectl
.yBottom
+ nHeight
;
1153 pSWP
[i
].cx
= vRectl
.xRight
- (vRectl
.xLeft
+ nWidth
);
1154 pSWP
[i
].cy
= vRectl
.yTop
- vRectl
.yBottom
- nHeight
;
1156 pSWP
[i
].fl
= SWP_SIZE
| SWP_MOVE
| SWP_SHOW
;
1157 pSWP
[i
].hwndInsertBehind
= HWND_TOP
;
1161 rc
= MRFROMSHORT(nItemCount
);
1166 if(pWnd
&& pWnd
->m_fnOldWndProc
)
1167 rc
= pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
);
1169 rc
= ::WinDefWindowProc(hWnd
, ulMsg
, wParam
, lParam
);
1172 } // end of wxFrameMainWndProc
1174 MRESULT EXPENTRY
wxFrameWndProc(
1182 // Trace all ulMsgs - useful for the debugging
1185 wxFrame
* pWnd
= NULL
;
1187 parentHwnd
= WinQueryWindow(hWnd
,QW_PARENT
);
1188 pWnd
= (wxFrame
*) wxFindWinFromHandle((WXHWND
) hWnd
);
1191 // When we get the first message for the HWND we just created, we associate
1192 // it with wxWindow stored in wxWndHook
1195 MRESULT rc
= (MRESULT
)0;
1198 // Stop right here if we don't have a valid handle in our wxWindow object.
1200 if (pWnd
&& !pWnd
->GetHWND())
1202 pWnd
->SetHWND((WXHWND
) hWnd
);
1203 rc
= pWnd
->OS2DefWindowProc(ulMsg
, wParam
, lParam
);
1209 rc
= pWnd
->OS2WindowProc(ulMsg
, wParam
, lParam
);
1211 rc
= ::WinDefWindowProc(hWnd
, ulMsg
, wParam
, lParam
);
1214 } // end of wxFrameWndProc
1216 MRESULT
wxFrame::OS2WindowProc( WXUINT uMessage
,
1221 bool bProcessed
= false;
1227 // If we can't close, tell the system that we processed the
1228 // message - otherwise it would close us
1230 bProcessed
= !Close();
1234 bProcessed
= HandlePaint();
1235 mRc
= (MRESULT
)FALSE
;
1238 case WM_ERASEBACKGROUND
:
1240 // Returning TRUE to requests PM to paint the window background
1241 // in SYSCLR_WINDOW. We capture this here because the PS returned
1242 // in Frames is the PS for the whole frame, which we can't really
1243 // use at all. If you want to paint a different background, do it
1244 // in an OnPaint using a wxPaintDC.
1246 mRc
= (MRESULT
)(TRUE
);
1255 UnpackCommand( (WXWPARAM
)wParam
1262 bProcessed
= HandleCommand( wId
1275 UnpackMenuSelect( wParam
1281 bProcessed
= HandleMenuSelect( wItem
1285 mRc
= (MRESULT
)TRUE
;
1291 SHORT nScxnew
= SHORT1FROMMP(lParam
); // New horizontal size.
1292 SHORT nScynew
= SHORT2FROMMP(lParam
); // New vertical size.
1294 lParam
= MRFROM2SHORT( nScxnew
- 20
1298 bProcessed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), (WXUINT
)wParam
);
1299 mRc
= (MRESULT
)FALSE
;
1302 case CM_QUERYDRAGIMAGE
:
1304 const wxIcon
& vIcon
= GetIcon();
1308 hIcon
= (HPOINTER
)::WinSendMsg(GetHWND(), WM_QUERYICON
, 0L, 0L);
1310 hIcon
= (HPOINTER
)m_hDefaultIcon
;
1311 mRc
= (MRESULT
)hIcon
;
1312 bProcessed
= mRc
!= 0;
1318 mRc
= wxWindow::OS2WindowProc( uMessage
1322 return (MRESULT
)mRc
;
1323 } // wxFrame::OS2WindowProc
1325 void wxFrame::SetClient(WXHWND
WXUNUSED(c_Hwnd
))
1327 // Duh...nothing to do under OS/2
1330 void wxFrame::SetClient( wxWindow
* pWindow
)
1332 wxWindow
* pOldClient
= this->GetClient();
1333 bool bClientHasFocus
= pOldClient
&& (pOldClient
== wxWindow::FindFocus());
1335 if(pOldClient
== pWindow
) // nothing to do
1337 if(pWindow
== NULL
) // just need to remove old client
1339 if(pOldClient
== NULL
) // nothing to do
1342 if(bClientHasFocus
)
1345 pOldClient
->Enable( false );
1346 pOldClient
->Show( false );
1347 ::WinSetWindowUShort(pOldClient
->GetHWND(), QWS_ID
, (USHORT
)pOldClient
->GetId());
1348 // to avoid OS/2 bug need to update frame
1349 ::WinSendMsg((HWND
)this->GetFrame(), WM_UPDATEFRAME
, (MPARAM
)~0, 0);
1354 // Else need to change client
1359 ::WinEnableWindowUpdate((HWND
)GetHWND(), FALSE
);
1362 pOldClient
->Enable(false);
1363 pOldClient
->Show(false);
1364 ::WinSetWindowUShort(pOldClient
->GetHWND(), QWS_ID
, (USHORT
)pOldClient
->GetId());
1366 pWindow
->Reparent(this);
1367 ::WinSetWindowUShort(pWindow
->GetHWND(), QWS_ID
, FID_CLIENT
);
1368 ::WinEnableWindowUpdate((HWND
)GetHWND(), TRUE
);
1370 pWindow
->Show(); // ensure client is showing
1371 if( this->IsShown() )
1374 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0);
1378 wxWindow
* wxFrame::GetClient()
1380 return wxFindWinFromHandle((WXHWND
)::WinWindowFromID(m_hFrame
, FID_CLIENT
));