1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/frame.cpp
4 // Author: David Webster
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
15 #include "wx/object.h"
16 #include "wx/dynarray.h"
19 #include "wx/string.h"
27 #include "wx/dialog.h"
28 #include "wx/settings.h"
29 #include "wx/dcclient.h"
31 #include "wx/toolbar.h"
32 #include "wx/statusbr.h"
33 #include "wx/menuitem.h"
36 #include "wx/os2/private.h"
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 #if wxUSE_MENUS_NATIVE
43 extern wxMenu
*wxCurrentPopupMenu
;
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
51 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
54 // ============================================================================
56 // ============================================================================
58 // ----------------------------------------------------------------------------
59 // static class members
60 // ----------------------------------------------------------------------------
63 #if wxUSE_NATIVE_STATUSBAR
64 bool wxFrame::m_bUseNativeStatusBar
= true;
66 bool wxFrame::m_bUseNativeStatusBar
= false;
69 #endif //wxUSE_STATUSBAR
71 // ----------------------------------------------------------------------------
72 // creation/destruction
73 // ----------------------------------------------------------------------------
77 m_nFsStatusBarFields
= 0;
78 m_nFsStatusBarHeight
= 0;
79 m_nFsToolBarHeight
= 0;
81 m_bWasMinimized
= false;
84 m_frameMenuBar
= NULL
;
85 m_frameToolBar
= NULL
;
86 m_frameStatusBar
= NULL
;
88 m_hTitleBar
= NULLHANDLE
;
89 m_hHScroll
= NULLHANDLE
;
90 m_hVScroll
= NULLHANDLE
;
95 memset(&m_vSwpTitleBar
, 0, sizeof(SWP
));
96 memset(&m_vSwpMenuBar
, 0, sizeof(SWP
));
97 memset(&m_vSwpHScroll
, 0, sizeof(SWP
));
98 memset(&m_vSwpVScroll
, 0, sizeof(SWP
));
99 memset(&m_vSwpStatusBar
, 0, sizeof(SWP
));
100 memset(&m_vSwpToolBar
, 0, sizeof(SWP
));
103 } // end of wxFrame::Init
105 bool wxFrame::Create( wxWindow
* pParent
,
107 const wxString
& rsTitle
,
111 const wxString
& rsName
)
113 if (!wxTopLevelWindow::Create( pParent
123 } // end of wxFrame::Create
130 } // end of wxFrame::~wxFrame
133 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
135 void wxFrame::DoGetClientSize(
140 wxTopLevelWindow::DoGetClientSize( pX
144 // No need to use statusbar code as in WIN32 as the FORMATFRAME
145 // window procedure ensures PM knows about the new frame client
146 // size internally. A ::WinQueryWindowRect (that is called in
147 // wxWindow's GetClient size from above) is all that is needed!
149 } // end of wxFrame::DoGetClientSize
152 // Set the client size (i.e. leave the calculation of borders etc.
155 void wxFrame::DoSetClientSize(
161 // Statusbars are not part of the OS/2 Client but parent frame
162 // so no statusbar consideration
164 wxTopLevelWindow::DoSetClientSize( nWidth
167 } // end of wxFrame::DoSetClientSize
169 // ----------------------------------------------------------------------------
170 // wxFrame: various geometry-related functions
171 // ----------------------------------------------------------------------------
173 void wxFrame::Raise()
175 wxFrameBase::Raise();
176 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
187 wxStatusBar
* wxFrame::OnCreateStatusBar(
191 , const wxString
& rName
194 wxStatusBar
* pStatusBar
= NULL
;
197 pStatusBar
= wxFrameBase::OnCreateStatusBar( nNumber
206 wxClientDC
vDC(pStatusBar
);
210 // Set the height according to the font and the border size
212 vDC
.SetFont(pStatusBar
->GetFont()); // Screws up the menues for some reason
213 vDC
.GetTextExtent( wxT("X")
218 int nHeight
= ((11 * nY
) / 10 + 2 * pStatusBar
->GetBorderY());
220 pStatusBar
->SetSize( wxDefaultCoord
226 ::WinSetParent( pStatusBar
->GetHWND(), m_hFrame
, FALSE
);
227 ::WinSetOwner( pStatusBar
->GetHWND(), m_hFrame
);
231 if(::WinIsWindowShowing(m_hFrame
))
232 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0);
235 } // end of wxFrame::OnCreateStatusBar
237 void wxFrame::PositionStatusBar()
244 // Native status bar positions itself
246 if (m_frameStatusBar
)
255 ::WinQueryWindowRect(m_hFrame
, &vRect
);
257 ::WinMapWindowPoints(m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRect
, 2);
259 ::WinCalcFrameRect(m_hFrame
, &vRect
, TRUE
);
260 nWidth
= vRect
.xRight
- vRect
.xLeft
;
261 nY
= nY
- (vRect
.yBottom
- vFRect
.yBottom
);
263 m_frameStatusBar
->GetSize( &nStatbarWidth
267 nY
= nY
- nStatbarHeight
;
269 // Since we wish the status bar to be directly under the client area,
270 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
272 m_frameStatusBar
->SetSize( vRect
.xLeft
- vFRect
.xLeft
277 if (!::WinQueryWindowPos(m_frameStatusBar
->GetHWND(), &vSwp
))
279 vError
= ::WinGetLastError(vHabmain
);
280 sError
= wxPMErrorToStr(vError
);
281 wxLogError(wxT("Error setting parent for StatusBar. Error: %s\n"), sError
.c_str());
285 } // end of wxFrame::PositionStatusBar
286 #endif // wxUSE_STATUSBAR
289 wxToolBar
* wxFrame::OnCreateToolBar( long lStyle
, wxWindowID vId
, const wxString
& rsName
)
291 wxToolBar
* pToolBar
= wxFrameBase::OnCreateToolBar( lStyle
296 ::WinSetParent( pToolBar
->GetHWND(), m_hFrame
, FALSE
);
297 ::WinSetOwner( pToolBar
->GetHWND(), m_hFrame
);
299 } // end of WinGuiBase_CFrame::OnCreateToolBar
302 #if wxUSE_MENUS_NATIVE
303 void wxFrame::DetachMenuBar()
307 m_frameMenuBar
->Detach();
308 m_frameMenuBar
= NULL
;
310 } // end of wxFrame::DetachMenuBar
312 void wxFrame::SetMenuBar(
323 // Actually remove the menu from the frame
325 m_hMenu
= (WXHMENU
)0;
326 InternalSetMenuBar();
328 else // set new non NULL menu bar
330 m_frameMenuBar
= NULL
;
333 // Can set a menubar several times.
334 // TODO: how to prevent a memory leak if you have a currently-unattached
335 // menubar? wxWidgets assumes that the frame will delete the menu (otherwise
336 // there are problems for MDI).
338 if (pMenuBar
->GetHMenu())
340 m_hMenu
= pMenuBar
->GetHMenu();
345 m_hMenu
= pMenuBar
->Create();
349 InternalSetMenuBar();
350 m_frameMenuBar
= pMenuBar
;
351 pMenuBar
->Attach((wxFrame
*)this);
353 } // end of wxFrame::SetMenuBar
355 void wxFrame::AttachMenuBar(
359 wxFrameBase::AttachMenuBar(pMenubar
);
361 m_frameMenuBar
= pMenubar
;
366 // Actually remove the menu from the frame
368 m_hMenu
= (WXHMENU
)0;
369 InternalSetMenuBar();
371 else // Set new non NULL menu bar
374 // Can set a menubar several times.
376 if (pMenubar
->GetHMenu())
378 m_hMenu
= pMenubar
->GetHMenu();
382 if (pMenubar
->IsAttached())
385 m_hMenu
= pMenubar
->Create();
390 InternalSetMenuBar();
392 } // end of wxFrame::AttachMenuBar
394 void wxFrame::InternalSetMenuBar()
399 // Set the parent and owner of the menubar to be the frame
401 if (!::WinSetParent(m_hMenu
, m_hFrame
, FALSE
))
403 vError
= ::WinGetLastError(vHabmain
);
404 sError
= wxPMErrorToStr(vError
);
405 wxLogError(wxT("Error setting parent for submenu. Error: %s\n"), sError
.c_str());
408 if (!::WinSetOwner(m_hMenu
, m_hFrame
))
410 vError
= ::WinGetLastError(vHabmain
);
411 sError
= wxPMErrorToStr(vError
);
412 wxLogError(wxT("Error setting parent for submenu. Error: %s\n"), sError
.c_str());
414 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
415 } // end of wxFrame::InternalSetMenuBar
416 #endif // wxUSE_MENUS_NATIVE
419 // Responds to colour changes, and passes event on to children
421 void wxFrame::OnSysColourChanged(
422 wxSysColourChangedEvent
& rEvent
425 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
429 if (m_frameStatusBar
)
431 wxSysColourChangedEvent vEvent2
;
433 vEvent2
.SetEventObject(m_frameStatusBar
);
434 m_frameStatusBar
->HandleWindowEvent(vEvent2
);
436 #endif //wxUSE_STATUSBAR
439 // Propagate the event to the non-top-level children
441 wxWindow::OnSysColourChanged(rEvent
);
442 } // end of wxFrame::OnSysColourChanged
444 // Pass true to show full screen, false to restore.
445 bool wxFrame::ShowFullScreen( bool bShow
, long lStyle
)
452 m_bFsIsShowing
= true;
456 wxToolBar
* pTheToolBar
= GetToolBar();
457 #endif //wxUSE_TOOLBAR
460 wxStatusBar
* pTheStatusBar
= GetStatusBar();
461 #endif //wxUSE_STATUSBAR
467 pTheToolBar
->GetSize(&nDummyWidth
, &m_nFsToolBarHeight
);
468 #endif //wxUSE_TOOLBAR
472 pTheStatusBar
->GetSize(&nDummyWidth
, &m_nFsStatusBarHeight
);
473 #endif //wxUSE_STATUSBAR
477 // Zap the toolbar, menubar, and statusbar
479 if ((lStyle
& wxFULLSCREEN_NOTOOLBAR
) && pTheToolBar
)
481 pTheToolBar
->SetSize(wxDefaultCoord
,0);
482 pTheToolBar
->Show(false);
484 #endif //wxUSE_TOOLBAR
486 if (lStyle
& wxFULLSCREEN_NOMENUBAR
)
488 ::WinSetParent(m_hMenu
, m_hFrame
, FALSE
);
489 ::WinSetOwner(m_hMenu
, m_hFrame
);
490 ::WinSendMsg((HWND
)m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
495 // Save the number of fields in the statusbar
497 if ((lStyle
& wxFULLSCREEN_NOSTATUSBAR
) && pTheStatusBar
)
499 m_nFsStatusBarFields
= pTheStatusBar
->GetFieldsCount();
501 delete pTheStatusBar
;
504 m_nFsStatusBarFields
= 0;
505 #endif //wxUSE_STATUSBAR
508 // Zap the frame borders
512 // Save the 'normal' window style
514 m_lFsOldWindowStyle
= ::WinQueryWindowULong(m_hFrame
, QWL_STYLE
);
517 // Save the old position, width & height, maximize state
519 m_vFsOldSize
= GetRect();
520 m_bFsIsMaximized
= IsMaximized();
523 // Decide which window style flags to turn off
525 LONG lNewStyle
= m_lFsOldWindowStyle
;
528 if (lStyle
& wxFULLSCREEN_NOBORDER
)
529 lOffFlags
|= FCF_BORDER
;
530 if (lStyle
& wxFULLSCREEN_NOCAPTION
)
531 lOffFlags
|= (FCF_TASKLIST
| FCF_SYSMENU
);
533 lNewStyle
&= (~lOffFlags
);
536 // Change our window style to be compatible with full-screen mode
538 ::WinSetWindowULong((HWND
)m_hFrame
, QWL_STYLE
, (ULONG
)lNewStyle
);
541 // Resize to the size of the desktop
547 ::WinQueryWindowRect(HWND_DESKTOP
, &vRect
);
548 nWidth
= vRect
.xRight
- vRect
.xLeft
;
550 // Remember OS/2 is backwards!
552 nHeight
= vRect
.yTop
- vRect
.yBottom
;
554 SetSize( nWidth
, nHeight
);
557 // Now flush the window style cache and actually go full-screen
559 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
568 wxSize
sz( nWidth
, nHeight
);
569 wxSizeEvent
vEvent( sz
, GetId() );
571 HandleWindowEvent(vEvent
);
579 m_bFsIsShowing
= false;
582 wxToolBar
* pTheToolBar
= GetToolBar();
585 // Restore the toolbar, menubar, and statusbar
587 if (pTheToolBar
&& (m_lFsStyle
& wxFULLSCREEN_NOTOOLBAR
))
589 pTheToolBar
->SetSize(wxDefaultCoord
, m_nFsToolBarHeight
);
590 pTheToolBar
->Show(true);
592 #endif //wxUSE_TOOLBAR
595 if ((m_lFsStyle
& wxFULLSCREEN_NOSTATUSBAR
) && (m_nFsStatusBarFields
> 0))
597 CreateStatusBar(m_nFsStatusBarFields
);
598 // PositionStatusBar();
600 #endif //wxUSE_STATUSBAR
602 if ((m_lFsStyle
& wxFULLSCREEN_NOMENUBAR
) && (m_hMenu
!= 0))
604 ::WinSetParent(m_hMenu
, m_hFrame
, FALSE
);
605 ::WinSetOwner(m_hMenu
, m_hFrame
);
606 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
608 Maximize(m_bFsIsMaximized
);
610 ::WinSetWindowULong( m_hFrame
612 ,(ULONG
)m_lFsOldWindowStyle
614 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
623 return wxFrameBase::ShowFullScreen(bShow
, lStyle
);
624 } // end of wxFrame::ShowFullScreen
629 // ----------------------------------------------------------------------------
630 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
631 // from the client area, so the client area is what's really available for the
633 // ----------------------------------------------------------------------------
635 // Checks if there is a toolbar, and returns the first free client position
636 wxPoint
wxFrame::GetClientAreaOrigin() const
638 wxPoint vPoint
= wxTopLevelWindow::GetClientAreaOrigin();
641 // In OS/2 the toolbar and statusbar are frame extensions so there is no
642 // adjustment. The client is supposedly resized for a toolbar in OS/2
643 // as it is for the status bar.
646 } // end of wxFrame::GetClientAreaOrigin
648 // ----------------------------------------------------------------------------
649 // tool/status bar stuff
650 // ----------------------------------------------------------------------------
654 wxToolBar
* wxFrame::CreateToolBar(
657 , const wxString
& rName
660 if (wxFrameBase::CreateToolBar( lStyle
667 return m_frameToolBar
;
668 } // end of wxFrame::CreateToolBar
670 void wxFrame::PositionToolBar()
672 wxToolBar
* pToolBar
= GetToolBar();
685 ::WinQueryWindowRect(m_hFrame
, &vRect
);
686 vPos
.y
= (wxCoord
)vRect
.yTop
;
687 ::WinMapWindowPoints(m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRect
, 2);
689 ::WinCalcFrameRect(m_hFrame
, &vRect
, TRUE
);
691 vPos
.y
= (wxCoord
)(vFRect
.yTop
- vRect
.yTop
);
692 pToolBar
->GetSize( &vTWidth
696 if (pToolBar
->GetWindowStyleFlag() & wxTB_TOP
)
698 vWidth
= (wxCoord
)(vRect
.xRight
- vRect
.xLeft
);
699 pToolBar
->SetSize( vRect
.xLeft
- vFRect
.xLeft
705 else if (pToolBar
->GetWindowStyleFlag() & wxTB_BOTTOM
)
708 wxCoord vSheight
= 0;
710 if (m_frameStatusBar
)
711 m_frameStatusBar
->GetSize( &vSwidth
714 vWidth
= (wxCoord
)(vRect
.xRight
- vRect
.xLeft
);
715 pToolBar
->SetSize( vRect
.xLeft
- vFRect
.xLeft
716 ,vFRect
.yTop
- vRect
.yBottom
- vTHeight
- vSheight
721 else if (pToolBar
->GetWindowStyleFlag() & wxTB_LEFT
)
724 wxCoord vSheight
= 0;
726 if (m_frameStatusBar
)
727 m_frameStatusBar
->GetSize( &vSwidth
730 vHeight
= (wxCoord
)(vRect
.yTop
- vRect
.yBottom
);
731 pToolBar
->SetSize( vRect
.xLeft
- vRect
.xLeft
740 wxCoord vSheight
= 0;
742 if (m_frameStatusBar
)
743 m_frameStatusBar
->GetSize( &vSwidth
746 vHeight
= (wxCoord
)(vRect
.yTop
- vRect
.yBottom
);
747 pToolBar
->SetSize( vRect
.xRight
- vFRect
.xLeft
- vTWidth
753 if( ::WinIsWindowShowing(m_hFrame
) )
754 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0);
755 } // end of wxFrame::PositionToolBar
756 #endif // wxUSE_TOOLBAR
758 // ----------------------------------------------------------------------------
759 // frame state (iconized/maximized/...)
760 // ----------------------------------------------------------------------------
763 // propagate our state change to all child frames: this allows us to emulate X
764 // Windows behaviour where child frames float independently of the parent one
765 // on the desktop, but are iconized/restored with it
767 void wxFrame::IconizeChildFrames( bool WXUNUSED(bIconize
) )
769 // FIXME: Generic MDI does not use Frames for the Childs, so this does _not_
770 // work. Possibly, the right thing is simply to eliminate this
771 // functions and all the calls to it from within this file.
773 for (wxWindowList::Node
* pNode
= GetChildren().GetFirst();
775 pNode
= pNode
->GetNext() )
777 wxWindow
* pWin
= pNode
->GetData();
778 wxFrame
* pFrame
= wxDynamicCast(pWin
, wxFrame
);
781 #if wxUSE_MDI_ARCHITECTURE
782 && !wxDynamicCast(pFrame
, wxMDIChildFrame
)
783 #endif // wxUSE_MDI_ARCHITECTURE
787 // We don't want to restore the child frames which had been
788 // iconized even before we were iconized, so save the child frame
789 // status when iconizing the parent frame and check it when
794 pFrame
->m_bWasMinimized
= pFrame
->IsIconized();
798 // This test works for both iconizing and restoring
800 if (!pFrame
->m_bWasMinimized
)
801 pFrame
->Iconize(bIconize
);
805 } // end of wxFrame::IconizeChildFrames
807 WXHICON
wxFrame::GetDefaultIcon() const
809 return (WXHICON
)(wxSTD_FRAME_ICON
? wxSTD_FRAME_ICON
810 : wxDEFAULT_FRAME_ICON
);
812 // ===========================================================================
813 // message processing
814 // ===========================================================================
816 // ---------------------------------------------------------------------------
818 // ---------------------------------------------------------------------------
819 bool wxFrame::OS2TranslateMessage( WXMSG
* pMsg
)
822 // try the menu bar accels
824 wxMenuBar
* pMenuBar
= GetMenuBar();
829 #if wxUSE_ACCEL && wxUSE_MENUS_NATIVE
830 const wxAcceleratorTable
& rAcceleratorTable
= pMenuBar
->GetAccelTable();
831 return rAcceleratorTable
.Translate(GetHWND(), pMsg
);
835 } // end of wxFrame::OS2TranslateMessage
837 // ---------------------------------------------------------------------------
838 // our private (non virtual) message handlers
839 // ---------------------------------------------------------------------------
840 bool wxFrame::HandlePaint()
844 if (::WinQueryUpdateRect(GetHWND(), &vRect
))
849 // Icons in PM are the same as "pointers"
851 const wxIcon
& vIcon
= GetIcon();
855 hIcon
= (HPOINTER
)::WinSendMsg(m_hFrame
, WM_QUERYICON
, 0L, 0L);
857 hIcon
= (HPOINTER
)m_hDefaultIcon
;
860 // Hold a pointer to the dc so long as the OnPaint() message
861 // is being processed
864 HPS hPs
= ::WinBeginPaint(GetHwnd(), NULLHANDLE
, &vRect2
);
867 // Erase background before painting or we get white background
869 OS2DefWindowProc(WM_ERASEBACKGROUND
, (MPARAM
)hPs
, (MPARAM
)&vRect2
);
875 ::WinQueryWindowRect(GetHwnd(), &vRect3
);
877 static const int nIconWidth
= 32;
878 static const int nIconHeight
= 32;
879 int nIconX
= (int)((vRect3
.xRight
- nIconWidth
)/2);
880 int nIconY
= (int)((vRect3
.yBottom
+ nIconHeight
)/2);
882 ::WinDrawPointer(hPs
, nIconX
, nIconY
, hIcon
, DP_NORMAL
);
888 if (!wxWindow::HandlePaint())
893 hPS
= ::WinBeginPaint( GetHwnd()
899 ::GpiCreateLogColorTable( hPS
903 ,(LONG
)wxTheColourDatabase
->m_nSize
904 ,(PLONG
)wxTheColourDatabase
->m_palTable
906 ::GpiCreateLogColorTable( hPS
916 ,GetBackgroundColour().GetPixel()
925 } // end of wxFrame::HandlePaint
927 bool wxFrame::HandleSize( int nX
, int nY
, WXUINT nId
)
929 bool bProcessed
= false;
935 // Only do it it if we were iconized before, otherwise resizing the
936 // parent frame has a curious side effect of bringing it under it's
942 // restore all child frames too
944 IconizeChildFrames(false);
945 (void)SendIconizeEvent(false);
957 // Iconize all child frames too
959 IconizeChildFrames(true);
960 (void)SendIconizeEvent();
968 // forward WM_SIZE to status bar control
970 #if wxUSE_NATIVE_STATUSBAR
971 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
973 wxSizeEvent
vEvent( wxSize( nX
976 ,m_frameStatusBar
->GetId()
979 vEvent
.SetEventObject(m_frameStatusBar
);
980 m_frameStatusBar
->OnSize(vEvent
);
982 #endif // wxUSE_NATIVE_STATUSBAR
987 #endif // wxUSE_TOOLBAR
989 bProcessed
= wxWindow::HandleSize( nX
995 } // end of wxFrame::HandleSize
997 bool wxFrame::HandleCommand( WXWORD nId
,
1004 // In case it's e.g. a toolbar.
1006 wxWindow
* pWin
= wxFindWinFromHandle(hControl
);
1009 return pWin
->OS2Command( nCmd
, nId
);
1013 // Handle here commands from menus and accelerators
1015 if (nCmd
== CMDSRC_MENU
|| nCmd
== CMDSRC_ACCELERATOR
)
1017 #if wxUSE_MENUS_NATIVE
1018 if (wxCurrentPopupMenu
)
1020 wxMenu
* pPopupMenu
= wxCurrentPopupMenu
;
1022 wxCurrentPopupMenu
= NULL
;
1024 return pPopupMenu
->OS2Command( nCmd
, nId
);
1028 if (ProcessCommand(nId
))
1034 } // end of wxFrame::HandleCommand
1036 bool wxFrame::HandleMenuSelect( WXWORD nItem
,
1045 rc
= ::WinSendMsg(hMenu
, MM_QUERYITEM
, MPFROM2SHORT(nItem
, TRUE
), (MPARAM
)&mItem
);
1047 if(rc
&& !(mItem
.afStyle
& (MIS_SUBMENU
| MIS_SEPARATOR
)))
1049 wxMenuEvent
vEvent(wxEVT_MENU_HIGHLIGHT
, nItem
);
1051 vEvent
.SetEventObject(this);
1052 HandleWindowEvent(vEvent
); // return value would be ignored by PM
1056 DoGiveHelp(wxEmptyString
, true);
1061 } // end of wxFrame::HandleMenuSelect
1063 // ---------------------------------------------------------------------------
1064 // Main Frame window proc
1065 // ---------------------------------------------------------------------------
1066 MRESULT EXPENTRY
wxFrameMainWndProc( HWND hWnd
,
1071 MRESULT rc
= (MRESULT
)0;
1072 bool bProcessed
= false;
1074 wxFrame
* pWnd
= (wxFrame
*) wxFindWinFromHandle((WXHWND
) hWnd
);
1077 case WM_QUERYFRAMECTLCOUNT
:
1078 if(pWnd
&& pWnd
->m_fnOldWndProc
)
1080 USHORT uItemCount
= SHORT1FROMMR(pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
));
1082 rc
= MRFROMSHORT(uItemCount
);
1086 case WM_FORMATFRAME
:
1087 /////////////////////////////////////////////////////////////////////////////////
1088 // Applications that subclass frame controls may find that the frame is already
1089 // subclassed the number of frame controls is variable.
1090 // The WM_FORMATFRAME and WM_QUERYFRAMECTLCOUNT messages must always be
1091 // subclassed by calling the previous window procedure and modifying its result.
1092 ////////////////////////////////////////////////////////////////////////////////
1104 pSWP
= (PSWP
)PVOIDFROMMP(wParam
);
1105 nItemCount
= SHORT1FROMMR(pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
));
1106 if(pWnd
->m_frameStatusBar
)
1108 ::WinQueryWindowRect(pWnd
->m_frameStatusBar
->GetHWND(), &vRstb
);
1109 pWnd
->m_frameStatusBar
->GetSize(NULL
, &nHeight
);
1111 if(pWnd
->m_frameToolBar
)
1113 ::WinQueryWindowRect(pWnd
->m_frameToolBar
->GetHWND(), &vRtlb
);
1114 pWnd
->m_frameToolBar
->GetSize(&nWidth
, &nHeight2
);
1116 ::WinQueryWindowRect(pWnd
->m_hFrame
, &vRectl
);
1117 ::WinMapWindowPoints(pWnd
->m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRectl
, 2);
1118 ::WinCalcFrameRect(pWnd
->m_hFrame
, &vRectl
, TRUE
);
1119 ::WinMapWindowPoints(HWND_DESKTOP
, pWnd
->m_hFrame
, (PPOINTL
)&vRectl
, 2);
1120 for(i
= 0; i
< nItemCount
; i
++)
1122 if(pWnd
->m_hWnd
&& pSWP
[i
].hwnd
== pWnd
->m_hWnd
)
1124 if (pWnd
->m_frameToolBar
&& pWnd
->m_frameToolBar
->GetWindowStyleFlag() & wxTB_TOP
)
1126 pSWP
[i
].x
= vRectl
.xLeft
;
1127 pSWP
[i
].y
= vRectl
.yBottom
+ nHeight
;
1128 pSWP
[i
].cx
= vRectl
.xRight
- vRectl
.xLeft
;
1129 pSWP
[i
].cy
= vRectl
.yTop
- vRectl
.yBottom
- (nHeight
+ nHeight2
);
1131 else if (pWnd
->m_frameToolBar
&& pWnd
->m_frameToolBar
->GetWindowStyleFlag() & wxTB_BOTTOM
)
1133 pSWP
[i
].x
= vRectl
.xLeft
;
1134 pSWP
[i
].y
= vRectl
.yBottom
+ nHeight
+ nHeight2
;
1135 pSWP
[i
].cx
= vRectl
.xRight
- vRectl
.xLeft
;
1136 pSWP
[i
].cy
= vRectl
.yTop
- vRectl
.yBottom
- (nHeight
+ nHeight2
);
1138 else if (pWnd
->m_frameToolBar
&& pWnd
->m_frameToolBar
->GetWindowStyleFlag() & wxTB_LEFT
)
1140 pSWP
[i
].x
= vRectl
.xLeft
+ nWidth
;
1141 pSWP
[i
].y
= vRectl
.yBottom
+ nHeight
;
1142 pSWP
[i
].cx
= vRectl
.xRight
- (vRectl
.xLeft
+ nWidth
);
1143 pSWP
[i
].cy
= vRectl
.yTop
- vRectl
.yBottom
- nHeight
;
1147 pSWP
[i
].x
= vRectl
.xLeft
;
1148 pSWP
[i
].y
= vRectl
.yBottom
+ nHeight
;
1149 pSWP
[i
].cx
= vRectl
.xRight
- (vRectl
.xLeft
+ nWidth
);
1150 pSWP
[i
].cy
= vRectl
.yTop
- vRectl
.yBottom
- nHeight
;
1152 pSWP
[i
].fl
= SWP_SIZE
| SWP_MOVE
| SWP_SHOW
;
1153 pSWP
[i
].hwndInsertBehind
= HWND_TOP
;
1157 rc
= MRFROMSHORT(nItemCount
);
1162 if(pWnd
&& pWnd
->m_fnOldWndProc
)
1163 rc
= pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
);
1165 rc
= ::WinDefWindowProc(hWnd
, ulMsg
, wParam
, lParam
);
1168 } // end of wxFrameMainWndProc
1170 MRESULT EXPENTRY
wxFrameWndProc(
1178 // Trace all ulMsgs - useful for the debugging
1181 wxFrame
* pWnd
= NULL
;
1183 parentHwnd
= WinQueryWindow(hWnd
,QW_PARENT
);
1184 pWnd
= (wxFrame
*) wxFindWinFromHandle((WXHWND
) hWnd
);
1187 // When we get the first message for the HWND we just created, we associate
1188 // it with wxWindow stored in wxWndHook
1191 MRESULT rc
= (MRESULT
)0;
1194 // Stop right here if we don't have a valid handle in our wxWindow object.
1196 if (pWnd
&& !pWnd
->GetHWND())
1198 pWnd
->SetHWND((WXHWND
) hWnd
);
1199 rc
= pWnd
->OS2DefWindowProc(ulMsg
, wParam
, lParam
);
1205 rc
= pWnd
->OS2WindowProc(ulMsg
, wParam
, lParam
);
1207 rc
= ::WinDefWindowProc(hWnd
, ulMsg
, wParam
, lParam
);
1210 } // end of wxFrameWndProc
1212 MRESULT
wxFrame::OS2WindowProc( WXUINT uMessage
,
1217 bool bProcessed
= false;
1223 // If we can't close, tell the system that we processed the
1224 // message - otherwise it would close us
1226 bProcessed
= !Close();
1230 bProcessed
= HandlePaint();
1231 mRc
= (MRESULT
)FALSE
;
1234 case WM_ERASEBACKGROUND
:
1236 // Returning TRUE to requests PM to paint the window background
1237 // in SYSCLR_WINDOW. We capture this here because the PS returned
1238 // in Frames is the PS for the whole frame, which we can't really
1239 // use at all. If you want to paint a different background, do it
1240 // in an OnPaint using a wxPaintDC.
1242 mRc
= (MRESULT
)(TRUE
);
1251 UnpackCommand( (WXWPARAM
)wParam
1258 bProcessed
= HandleCommand( wId
1271 UnpackMenuSelect( wParam
1277 bProcessed
= HandleMenuSelect( wItem
1281 mRc
= (MRESULT
)TRUE
;
1287 SHORT nScxnew
= SHORT1FROMMP(lParam
); // New horizontal size.
1288 SHORT nScynew
= SHORT2FROMMP(lParam
); // New vertical size.
1290 lParam
= MRFROM2SHORT( nScxnew
- 20
1294 bProcessed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), (WXUINT
)wParam
);
1295 mRc
= (MRESULT
)FALSE
;
1298 case CM_QUERYDRAGIMAGE
:
1300 const wxIcon
& vIcon
= GetIcon();
1304 hIcon
= (HPOINTER
)::WinSendMsg(GetHWND(), WM_QUERYICON
, 0L, 0L);
1306 hIcon
= (HPOINTER
)m_hDefaultIcon
;
1307 mRc
= (MRESULT
)hIcon
;
1308 bProcessed
= mRc
!= 0;
1314 mRc
= wxWindow::OS2WindowProc( uMessage
1318 return (MRESULT
)mRc
;
1319 } // wxFrame::OS2WindowProc
1321 void wxFrame::SetClient(WXHWND
WXUNUSED(c_Hwnd
))
1323 // Duh...nothing to do under OS/2
1326 void wxFrame::SetClient( wxWindow
* pWindow
)
1328 wxWindow
* pOldClient
= this->GetClient();
1329 bool bClientHasFocus
= pOldClient
&& (pOldClient
== wxWindow::FindFocus());
1331 if(pOldClient
== pWindow
) // nothing to do
1333 if(pWindow
== NULL
) // just need to remove old client
1335 if(pOldClient
== NULL
) // nothing to do
1338 if(bClientHasFocus
)
1341 pOldClient
->Enable( false );
1342 pOldClient
->Show( false );
1343 ::WinSetWindowUShort(pOldClient
->GetHWND(), QWS_ID
, (USHORT
)pOldClient
->GetId());
1344 // to avoid OS/2 bug need to update frame
1345 ::WinSendMsg((HWND
)this->GetFrame(), WM_UPDATEFRAME
, (MPARAM
)~0, 0);
1350 // Else need to change client
1355 ::WinEnableWindowUpdate((HWND
)GetHWND(), FALSE
);
1358 pOldClient
->Enable(false);
1359 pOldClient
->Show(false);
1360 ::WinSetWindowUShort(pOldClient
->GetHWND(), QWS_ID
, (USHORT
)pOldClient
->GetId());
1362 pWindow
->Reparent(this);
1363 ::WinSetWindowUShort(pWindow
->GetHWND(), QWS_ID
, FID_CLIENT
);
1364 ::WinEnableWindowUpdate((HWND
)GetHWND(), TRUE
);
1366 pWindow
->Show(); // ensure client is showing
1367 if( this->IsShown() )
1370 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0);
1374 wxWindow
* wxFrame::GetClient()
1376 return wxFindWinFromHandle((WXHWND
)::WinWindowFromID(m_hFrame
, FID_CLIENT
));