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 // ============================================================================
57 // ============================================================================
59 // ----------------------------------------------------------------------------
60 // static class members
61 // ----------------------------------------------------------------------------
64 #if wxUSE_NATIVE_STATUSBAR
65 bool wxFrame::m_bUseNativeStatusBar
= true;
67 bool wxFrame::m_bUseNativeStatusBar
= false;
70 #endif //wxUSE_STATUSBAR
72 // ----------------------------------------------------------------------------
73 // creation/destruction
74 // ----------------------------------------------------------------------------
78 m_nFsStatusBarFields
= 0;
79 m_nFsStatusBarHeight
= 0;
80 m_nFsToolBarHeight
= 0;
82 m_bWasMinimized
= false;
85 m_frameMenuBar
= NULL
;
86 m_frameToolBar
= NULL
;
87 m_frameStatusBar
= NULL
;
89 m_hTitleBar
= NULLHANDLE
;
90 m_hHScroll
= NULLHANDLE
;
91 m_hVScroll
= NULLHANDLE
;
96 memset(&m_vSwpTitleBar
, 0, sizeof(SWP
));
97 memset(&m_vSwpMenuBar
, 0, sizeof(SWP
));
98 memset(&m_vSwpHScroll
, 0, sizeof(SWP
));
99 memset(&m_vSwpVScroll
, 0, sizeof(SWP
));
100 memset(&m_vSwpStatusBar
, 0, sizeof(SWP
));
101 memset(&m_vSwpToolBar
, 0, sizeof(SWP
));
104 } // end of wxFrame::Init
106 bool wxFrame::Create( wxWindow
* pParent
,
108 const wxString
& rsTitle
,
112 const wxString
& rsName
)
114 if (!wxTopLevelWindow::Create( pParent
124 } // end of wxFrame::Create
131 } // end of wxFrame::~wxFrame
134 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
136 void wxFrame::DoGetClientSize(
141 wxTopLevelWindow::DoGetClientSize( pX
145 // No need to use statusbar code as in WIN32 as the FORMATFRAME
146 // window procedure ensures PM knows about the new frame client
147 // size internally. A ::WinQueryWindowRect (that is called in
148 // wxWindow's GetClient size from above) is all that is needed!
150 } // end of wxFrame::DoGetClientSize
153 // Set the client size (i.e. leave the calculation of borders etc.
156 void wxFrame::DoSetClientSize(
162 // Statusbars are not part of the OS/2 Client but parent frame
163 // so no statusbar consideration
165 wxTopLevelWindow::DoSetClientSize( nWidth
168 } // end of wxFrame::DoSetClientSize
170 // ----------------------------------------------------------------------------
171 // wxFrame: various geometry-related functions
172 // ----------------------------------------------------------------------------
174 void wxFrame::Raise()
176 wxFrameBase::Raise();
177 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
188 wxStatusBar
* wxFrame::OnCreateStatusBar(
192 , const wxString
& rName
195 wxStatusBar
* pStatusBar
= NULL
;
198 pStatusBar
= wxFrameBase::OnCreateStatusBar( nNumber
207 wxClientDC
vDC(pStatusBar
);
211 // Set the height according to the font and the border size
213 vDC
.SetFont(pStatusBar
->GetFont()); // Screws up the menues for some reason
214 vDC
.GetTextExtent( wxT("X")
219 int nHeight
= ((11 * nY
) / 10 + 2 * pStatusBar
->GetBorderY());
221 pStatusBar
->SetSize( wxDefaultCoord
227 ::WinSetParent( pStatusBar
->GetHWND(), m_hFrame
, FALSE
);
228 ::WinSetOwner( pStatusBar
->GetHWND(), m_hFrame
);
232 if(::WinIsWindowShowing(m_hFrame
))
233 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0);
236 } // end of wxFrame::OnCreateStatusBar
238 void wxFrame::PositionStatusBar()
245 // Native status bar positions itself
247 if (m_frameStatusBar
)
256 ::WinQueryWindowRect(m_hFrame
, &vRect
);
258 ::WinMapWindowPoints(m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRect
, 2);
260 ::WinCalcFrameRect(m_hFrame
, &vRect
, TRUE
);
261 nWidth
= vRect
.xRight
- vRect
.xLeft
;
262 nY
= nY
- (vRect
.yBottom
- vFRect
.yBottom
);
264 m_frameStatusBar
->GetSize( &nStatbarWidth
268 nY
= nY
- nStatbarHeight
;
270 // Since we wish the status bar to be directly under the client area,
271 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
273 m_frameStatusBar
->SetSize( vRect
.xLeft
- vFRect
.xLeft
278 if (!::WinQueryWindowPos(m_frameStatusBar
->GetHWND(), &vSwp
))
280 vError
= ::WinGetLastError(vHabmain
);
281 sError
= wxPMErrorToStr(vError
);
282 wxLogError(wxT("Error setting parent for StatusBar. Error: %s\n"), sError
.c_str());
286 } // end of wxFrame::PositionStatusBar
287 #endif // wxUSE_STATUSBAR
290 wxToolBar
* wxFrame::OnCreateToolBar( long lStyle
, wxWindowID vId
, const wxString
& rsName
)
292 wxToolBar
* pToolBar
= wxFrameBase::OnCreateToolBar( lStyle
297 ::WinSetParent( pToolBar
->GetHWND(), m_hFrame
, FALSE
);
298 ::WinSetOwner( pToolBar
->GetHWND(), m_hFrame
);
300 } // end of WinGuiBase_CFrame::OnCreateToolBar
303 #if wxUSE_MENUS_NATIVE
304 void wxFrame::DetachMenuBar()
308 m_frameMenuBar
->Detach();
309 m_frameMenuBar
= NULL
;
311 } // end of wxFrame::DetachMenuBar
313 void wxFrame::SetMenuBar(
324 // Actually remove the menu from the frame
326 m_hMenu
= (WXHMENU
)0;
327 InternalSetMenuBar();
329 else // set new non NULL menu bar
331 m_frameMenuBar
= NULL
;
334 // Can set a menubar several times.
335 // TODO: how to prevent a memory leak if you have a currently-unattached
336 // menubar? wxWidgets assumes that the frame will delete the menu (otherwise
337 // there are problems for MDI).
339 if (pMenuBar
->GetHMenu())
341 m_hMenu
= pMenuBar
->GetHMenu();
346 m_hMenu
= pMenuBar
->Create();
350 InternalSetMenuBar();
351 m_frameMenuBar
= pMenuBar
;
352 pMenuBar
->Attach((wxFrame
*)this);
354 } // end of wxFrame::SetMenuBar
356 void wxFrame::AttachMenuBar(
360 wxFrameBase::AttachMenuBar(pMenubar
);
362 m_frameMenuBar
= pMenubar
;
367 // Actually remove the menu from the frame
369 m_hMenu
= (WXHMENU
)0;
370 InternalSetMenuBar();
372 else // Set new non NULL menu bar
375 // Can set a menubar several times.
377 if (pMenubar
->GetHMenu())
379 m_hMenu
= pMenubar
->GetHMenu();
383 if (pMenubar
->IsAttached())
386 m_hMenu
= pMenubar
->Create();
391 InternalSetMenuBar();
393 } // end of wxFrame::AttachMenuBar
395 void wxFrame::InternalSetMenuBar()
400 // Set the parent and owner of the menubar to be the frame
402 if (!::WinSetParent(m_hMenu
, m_hFrame
, FALSE
))
404 vError
= ::WinGetLastError(vHabmain
);
405 sError
= wxPMErrorToStr(vError
);
406 wxLogError(wxT("Error setting parent for submenu. Error: %s\n"), sError
.c_str());
409 if (!::WinSetOwner(m_hMenu
, m_hFrame
))
411 vError
= ::WinGetLastError(vHabmain
);
412 sError
= wxPMErrorToStr(vError
);
413 wxLogError(wxT("Error setting parent for submenu. Error: %s\n"), sError
.c_str());
415 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
416 } // end of wxFrame::InternalSetMenuBar
417 #endif // wxUSE_MENUS_NATIVE
420 // Responds to colour changes, and passes event on to children
422 void wxFrame::OnSysColourChanged(
423 wxSysColourChangedEvent
& rEvent
426 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
430 if (m_frameStatusBar
)
432 wxSysColourChangedEvent vEvent2
;
434 vEvent2
.SetEventObject(m_frameStatusBar
);
435 m_frameStatusBar
->HandleWindowEvent(vEvent2
);
437 #endif //wxUSE_STATUSBAR
440 // Propagate the event to the non-top-level children
442 wxWindow::OnSysColourChanged(rEvent
);
443 } // end of wxFrame::OnSysColourChanged
445 // Pass true to show full screen, false to restore.
446 bool wxFrame::ShowFullScreen( bool bShow
, long lStyle
)
453 m_bFsIsShowing
= true;
457 wxToolBar
* pTheToolBar
= GetToolBar();
458 #endif //wxUSE_TOOLBAR
461 wxStatusBar
* pTheStatusBar
= GetStatusBar();
462 #endif //wxUSE_STATUSBAR
468 pTheToolBar
->GetSize(&nDummyWidth
, &m_nFsToolBarHeight
);
469 #endif //wxUSE_TOOLBAR
473 pTheStatusBar
->GetSize(&nDummyWidth
, &m_nFsStatusBarHeight
);
474 #endif //wxUSE_STATUSBAR
478 // Zap the toolbar, menubar, and statusbar
480 if ((lStyle
& wxFULLSCREEN_NOTOOLBAR
) && pTheToolBar
)
482 pTheToolBar
->SetSize(wxDefaultCoord
,0);
483 pTheToolBar
->Show(false);
485 #endif //wxUSE_TOOLBAR
487 if (lStyle
& wxFULLSCREEN_NOMENUBAR
)
489 ::WinSetParent(m_hMenu
, m_hFrame
, FALSE
);
490 ::WinSetOwner(m_hMenu
, m_hFrame
);
491 ::WinSendMsg((HWND
)m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
496 // Save the number of fields in the statusbar
498 if ((lStyle
& wxFULLSCREEN_NOSTATUSBAR
) && pTheStatusBar
)
500 m_nFsStatusBarFields
= pTheStatusBar
->GetFieldsCount();
502 delete pTheStatusBar
;
505 m_nFsStatusBarFields
= 0;
506 #endif //wxUSE_STATUSBAR
509 // Zap the frame borders
513 // Save the 'normal' window style
515 m_lFsOldWindowStyle
= ::WinQueryWindowULong(m_hFrame
, QWL_STYLE
);
518 // Save the old position, width & height, maximize state
520 m_vFsOldSize
= GetRect();
521 m_bFsIsMaximized
= IsMaximized();
524 // Decide which window style flags to turn off
526 LONG lNewStyle
= m_lFsOldWindowStyle
;
529 if (lStyle
& wxFULLSCREEN_NOBORDER
)
530 lOffFlags
|= FCF_BORDER
;
531 if (lStyle
& wxFULLSCREEN_NOCAPTION
)
532 lOffFlags
|= (FCF_TASKLIST
| FCF_SYSMENU
);
534 lNewStyle
&= (~lOffFlags
);
537 // Change our window style to be compatible with full-screen mode
539 ::WinSetWindowULong((HWND
)m_hFrame
, QWL_STYLE
, (ULONG
)lNewStyle
);
542 // Resize to the size of the desktop
548 ::WinQueryWindowRect(HWND_DESKTOP
, &vRect
);
549 nWidth
= vRect
.xRight
- vRect
.xLeft
;
551 // Remember OS/2 is backwards!
553 nHeight
= vRect
.yTop
- vRect
.yBottom
;
555 SetSize( nWidth
, nHeight
);
558 // Now flush the window style cache and actually go full-screen
560 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
569 wxSize
sz( nWidth
, nHeight
);
570 wxSizeEvent
vEvent( sz
, GetId() );
572 HandleWindowEvent(vEvent
);
580 m_bFsIsShowing
= false;
583 wxToolBar
* pTheToolBar
= GetToolBar();
586 // Restore the toolbar, menubar, and statusbar
588 if (pTheToolBar
&& (m_lFsStyle
& wxFULLSCREEN_NOTOOLBAR
))
590 pTheToolBar
->SetSize(wxDefaultCoord
, m_nFsToolBarHeight
);
591 pTheToolBar
->Show(true);
593 #endif //wxUSE_TOOLBAR
596 if ((m_lFsStyle
& wxFULLSCREEN_NOSTATUSBAR
) && (m_nFsStatusBarFields
> 0))
598 CreateStatusBar(m_nFsStatusBarFields
);
599 // PositionStatusBar();
601 #endif //wxUSE_STATUSBAR
603 if ((m_lFsStyle
& wxFULLSCREEN_NOMENUBAR
) && (m_hMenu
!= 0))
605 ::WinSetParent(m_hMenu
, m_hFrame
, FALSE
);
606 ::WinSetOwner(m_hMenu
, m_hFrame
);
607 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
609 Maximize(m_bFsIsMaximized
);
611 ::WinSetWindowULong( m_hFrame
613 ,(ULONG
)m_lFsOldWindowStyle
615 ::WinSetWindowPos( (HWND
) GetParent()->GetHWND()
624 return wxFrameBase::ShowFullScreen(bShow
, lStyle
);
625 } // end of wxFrame::ShowFullScreen
630 // ----------------------------------------------------------------------------
631 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
632 // from the client area, so the client area is what's really available for the
634 // ----------------------------------------------------------------------------
636 // Checks if there is a toolbar, and returns the first free client position
637 wxPoint
wxFrame::GetClientAreaOrigin() const
639 wxPoint vPoint
= wxTopLevelWindow::GetClientAreaOrigin();
642 // In OS/2 the toolbar and statusbar are frame extensions so there is no
643 // adjustment. The client is supposedly resized for a toolbar in OS/2
644 // as it is for the status bar.
647 } // end of wxFrame::GetClientAreaOrigin
649 // ----------------------------------------------------------------------------
650 // tool/status bar stuff
651 // ----------------------------------------------------------------------------
655 wxToolBar
* wxFrame::CreateToolBar(
658 , const wxString
& rName
661 if (wxFrameBase::CreateToolBar( lStyle
668 return m_frameToolBar
;
669 } // end of wxFrame::CreateToolBar
671 void wxFrame::PositionToolBar()
673 wxToolBar
* pToolBar
= GetToolBar();
686 ::WinQueryWindowRect(m_hFrame
, &vRect
);
687 vPos
.y
= (wxCoord
)vRect
.yTop
;
688 ::WinMapWindowPoints(m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRect
, 2);
690 ::WinCalcFrameRect(m_hFrame
, &vRect
, TRUE
);
692 vPos
.y
= (wxCoord
)(vFRect
.yTop
- vRect
.yTop
);
693 pToolBar
->GetSize( &vTWidth
697 if (pToolBar
->GetWindowStyleFlag() & wxTB_TOP
)
699 vWidth
= (wxCoord
)(vRect
.xRight
- vRect
.xLeft
);
700 pToolBar
->SetSize( vRect
.xLeft
- vFRect
.xLeft
706 else if (pToolBar
->GetWindowStyleFlag() & wxTB_BOTTOM
)
709 wxCoord vSheight
= 0;
711 if (m_frameStatusBar
)
712 m_frameStatusBar
->GetSize( &vSwidth
715 vWidth
= (wxCoord
)(vRect
.xRight
- vRect
.xLeft
);
716 pToolBar
->SetSize( vRect
.xLeft
- vFRect
.xLeft
717 ,vFRect
.yTop
- vRect
.yBottom
- vTHeight
- vSheight
722 else if (pToolBar
->GetWindowStyleFlag() & wxTB_LEFT
)
725 wxCoord vSheight
= 0;
727 if (m_frameStatusBar
)
728 m_frameStatusBar
->GetSize( &vSwidth
731 vHeight
= (wxCoord
)(vRect
.yTop
- vRect
.yBottom
);
732 pToolBar
->SetSize( vRect
.xLeft
- vRect
.xLeft
741 wxCoord vSheight
= 0;
743 if (m_frameStatusBar
)
744 m_frameStatusBar
->GetSize( &vSwidth
747 vHeight
= (wxCoord
)(vRect
.yTop
- vRect
.yBottom
);
748 pToolBar
->SetSize( vRect
.xRight
- vFRect
.xLeft
- vTWidth
754 if( ::WinIsWindowShowing(m_hFrame
) )
755 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0);
756 } // end of wxFrame::PositionToolBar
757 #endif // wxUSE_TOOLBAR
759 // ----------------------------------------------------------------------------
760 // frame state (iconized/maximized/...)
761 // ----------------------------------------------------------------------------
764 // propagate our state change to all child frames: this allows us to emulate X
765 // Windows behaviour where child frames float independently of the parent one
766 // on the desktop, but are iconized/restored with it
768 void wxFrame::IconizeChildFrames( bool WXUNUSED(bIconize
) )
770 // FIXME: Generic MDI does not use Frames for the Childs, so this does _not_
771 // work. Possibly, the right thing is simply to eliminate this
772 // functions and all the calls to it from within this file.
774 for (wxWindowList::Node
* pNode
= GetChildren().GetFirst();
776 pNode
= pNode
->GetNext() )
778 wxWindow
* pWin
= pNode
->GetData();
779 wxFrame
* pFrame
= wxDynamicCast(pWin
, wxFrame
);
782 #if wxUSE_MDI_ARCHITECTURE
783 && !wxDynamicCast(pFrame
, wxMDIChildFrame
)
784 #endif // wxUSE_MDI_ARCHITECTURE
788 // We don't want to restore the child frames which had been
789 // iconized even before we were iconized, so save the child frame
790 // status when iconizing the parent frame and check it when
795 pFrame
->m_bWasMinimized
= pFrame
->IsIconized();
799 // This test works for both iconizing and restoring
801 if (!pFrame
->m_bWasMinimized
)
802 pFrame
->Iconize(bIconize
);
806 } // end of wxFrame::IconizeChildFrames
808 WXHICON
wxFrame::GetDefaultIcon() const
810 return (WXHICON
)(wxSTD_FRAME_ICON
? wxSTD_FRAME_ICON
811 : wxDEFAULT_FRAME_ICON
);
813 // ===========================================================================
814 // message processing
815 // ===========================================================================
817 // ---------------------------------------------------------------------------
819 // ---------------------------------------------------------------------------
820 bool wxFrame::OS2TranslateMessage( WXMSG
* pMsg
)
823 // try the menu bar accels
825 wxMenuBar
* pMenuBar
= GetMenuBar();
830 #if wxUSE_ACCEL && wxUSE_MENUS_NATIVE
831 const wxAcceleratorTable
& rAcceleratorTable
= pMenuBar
->GetAccelTable();
832 return rAcceleratorTable
.Translate(GetHWND(), pMsg
);
836 } // end of wxFrame::OS2TranslateMessage
838 // ---------------------------------------------------------------------------
839 // our private (non virtual) message handlers
840 // ---------------------------------------------------------------------------
841 bool wxFrame::HandlePaint()
845 if (::WinQueryUpdateRect(GetHWND(), &vRect
))
850 // Icons in PM are the same as "pointers"
852 const wxIcon
& vIcon
= GetIcon();
856 hIcon
= (HPOINTER
)::WinSendMsg(m_hFrame
, WM_QUERYICON
, 0L, 0L);
858 hIcon
= (HPOINTER
)m_hDefaultIcon
;
861 // Hold a pointer to the dc so long as the OnPaint() message
862 // is being processed
865 HPS hPs
= ::WinBeginPaint(GetHwnd(), NULLHANDLE
, &vRect2
);
868 // Erase background before painting or we get white background
870 OS2DefWindowProc(WM_ERASEBACKGROUND
, (MPARAM
)hPs
, (MPARAM
)&vRect2
);
876 ::WinQueryWindowRect(GetHwnd(), &vRect3
);
878 static const int nIconWidth
= 32;
879 static const int nIconHeight
= 32;
880 int nIconX
= (int)((vRect3
.xRight
- nIconWidth
)/2);
881 int nIconY
= (int)((vRect3
.yBottom
+ nIconHeight
)/2);
883 ::WinDrawPointer(hPs
, nIconX
, nIconY
, hIcon
, DP_NORMAL
);
889 if (!wxWindow::HandlePaint())
894 hPS
= ::WinBeginPaint( GetHwnd()
900 ::GpiCreateLogColorTable( hPS
904 ,(LONG
)wxTheColourDatabase
->m_nSize
905 ,(PLONG
)wxTheColourDatabase
->m_palTable
907 ::GpiCreateLogColorTable( hPS
917 ,GetBackgroundColour().GetPixel()
926 } // end of wxFrame::HandlePaint
928 bool wxFrame::HandleSize( int nX
, int nY
, WXUINT nId
)
930 bool bProcessed
= false;
936 // Only do it it if we were iconized before, otherwise resizing the
937 // parent frame has a curious side effect of bringing it under it's
943 // restore all child frames too
945 IconizeChildFrames(false);
946 (void)SendIconizeEvent(false);
958 // Iconize all child frames too
960 IconizeChildFrames(true);
961 (void)SendIconizeEvent();
969 // forward WM_SIZE to status bar control
971 #if wxUSE_NATIVE_STATUSBAR
972 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
974 wxSizeEvent
vEvent( wxSize( nX
977 ,m_frameStatusBar
->GetId()
980 vEvent
.SetEventObject(m_frameStatusBar
);
981 m_frameStatusBar
->OnSize(vEvent
);
983 #endif // wxUSE_NATIVE_STATUSBAR
988 #endif // wxUSE_TOOLBAR
990 bProcessed
= wxWindow::HandleSize( nX
996 } // end of wxFrame::HandleSize
998 bool wxFrame::HandleCommand( WXWORD nId
,
1005 // In case it's e.g. a toolbar.
1007 wxWindow
* pWin
= wxFindWinFromHandle(hControl
);
1010 return pWin
->OS2Command( nCmd
, nId
);
1014 // Handle here commands from menus and accelerators
1016 if (nCmd
== CMDSRC_MENU
|| nCmd
== CMDSRC_ACCELERATOR
)
1018 #if wxUSE_MENUS_NATIVE
1019 if (wxCurrentPopupMenu
)
1021 wxMenu
* pPopupMenu
= wxCurrentPopupMenu
;
1023 wxCurrentPopupMenu
= NULL
;
1025 return pPopupMenu
->OS2Command( nCmd
, nId
);
1029 if (ProcessCommand(nId
))
1035 } // end of wxFrame::HandleCommand
1037 bool wxFrame::HandleMenuSelect( WXWORD nItem
,
1046 rc
= ::WinSendMsg(hMenu
, MM_QUERYITEM
, MPFROM2SHORT(nItem
, TRUE
), (MPARAM
)&mItem
);
1048 if(rc
&& !(mItem
.afStyle
& (MIS_SUBMENU
| MIS_SEPARATOR
)))
1050 wxMenuEvent
vEvent(wxEVT_MENU_HIGHLIGHT
, nItem
);
1052 vEvent
.SetEventObject(this);
1053 HandleWindowEvent(vEvent
); // return value would be ignored by PM
1057 DoGiveHelp(wxEmptyString
, true);
1062 } // end of wxFrame::HandleMenuSelect
1064 // ---------------------------------------------------------------------------
1065 // Main Frame window proc
1066 // ---------------------------------------------------------------------------
1067 MRESULT EXPENTRY
wxFrameMainWndProc( HWND hWnd
,
1072 MRESULT rc
= (MRESULT
)0;
1073 bool bProcessed
= false;
1074 wxFrame
* pWnd
= NULL
;
1076 pWnd
= (wxFrame
*) wxFindWinFromHandle((WXHWND
) hWnd
);
1079 case WM_QUERYFRAMECTLCOUNT
:
1080 if(pWnd
&& pWnd
->m_fnOldWndProc
)
1082 USHORT uItemCount
= SHORT1FROMMR(pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
));
1084 rc
= MRFROMSHORT(uItemCount
);
1088 case WM_FORMATFRAME
:
1089 /////////////////////////////////////////////////////////////////////////////////
1090 // Applications that subclass frame controls may find that the frame is already
1091 // subclassed the number of frame controls is variable.
1092 // The WM_FORMATFRAME and WM_QUERYFRAMECTLCOUNT messages must always be
1093 // subclassed by calling the previous window procedure and modifying its result.
1094 ////////////////////////////////////////////////////////////////////////////////
1106 pSWP
= (PSWP
)PVOIDFROMMP(wParam
);
1107 nItemCount
= SHORT1FROMMR(pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
));
1108 if(pWnd
->m_frameStatusBar
)
1110 ::WinQueryWindowRect(pWnd
->m_frameStatusBar
->GetHWND(), &vRstb
);
1111 pWnd
->m_frameStatusBar
->GetSize(NULL
, &nHeight
);
1113 if(pWnd
->m_frameToolBar
)
1115 ::WinQueryWindowRect(pWnd
->m_frameToolBar
->GetHWND(), &vRtlb
);
1116 pWnd
->m_frameToolBar
->GetSize(&nWidth
, &nHeight2
);
1118 ::WinQueryWindowRect(pWnd
->m_hFrame
, &vRectl
);
1119 ::WinMapWindowPoints(pWnd
->m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRectl
, 2);
1120 ::WinCalcFrameRect(pWnd
->m_hFrame
, &vRectl
, TRUE
);
1121 ::WinMapWindowPoints(HWND_DESKTOP
, pWnd
->m_hFrame
, (PPOINTL
)&vRectl
, 2);
1122 for(i
= 0; i
< nItemCount
; i
++)
1124 if(pWnd
->m_hWnd
&& pSWP
[i
].hwnd
== pWnd
->m_hWnd
)
1126 if (pWnd
->m_frameToolBar
&& pWnd
->m_frameToolBar
->GetWindowStyleFlag() & wxTB_TOP
)
1128 pSWP
[i
].x
= vRectl
.xLeft
;
1129 pSWP
[i
].y
= vRectl
.yBottom
+ nHeight
;
1130 pSWP
[i
].cx
= vRectl
.xRight
- vRectl
.xLeft
;
1131 pSWP
[i
].cy
= vRectl
.yTop
- vRectl
.yBottom
- (nHeight
+ nHeight2
);
1133 else if (pWnd
->m_frameToolBar
&& pWnd
->m_frameToolBar
->GetWindowStyleFlag() & wxTB_BOTTOM
)
1135 pSWP
[i
].x
= vRectl
.xLeft
;
1136 pSWP
[i
].y
= vRectl
.yBottom
+ nHeight
+ nHeight2
;
1137 pSWP
[i
].cx
= vRectl
.xRight
- vRectl
.xLeft
;
1138 pSWP
[i
].cy
= vRectl
.yTop
- vRectl
.yBottom
- (nHeight
+ nHeight2
);
1140 else if (pWnd
->m_frameToolBar
&& pWnd
->m_frameToolBar
->GetWindowStyleFlag() & wxTB_LEFT
)
1142 pSWP
[i
].x
= vRectl
.xLeft
+ nWidth
;
1143 pSWP
[i
].y
= vRectl
.yBottom
+ nHeight
;
1144 pSWP
[i
].cx
= vRectl
.xRight
- (vRectl
.xLeft
+ nWidth
);
1145 pSWP
[i
].cy
= vRectl
.yTop
- vRectl
.yBottom
- nHeight
;
1149 pSWP
[i
].x
= vRectl
.xLeft
;
1150 pSWP
[i
].y
= vRectl
.yBottom
+ nHeight
;
1151 pSWP
[i
].cx
= vRectl
.xRight
- (vRectl
.xLeft
+ nWidth
);
1152 pSWP
[i
].cy
= vRectl
.yTop
- vRectl
.yBottom
- nHeight
;
1154 pSWP
[i
].fl
= SWP_SIZE
| SWP_MOVE
| SWP_SHOW
;
1155 pSWP
[i
].hwndInsertBehind
= HWND_TOP
;
1159 rc
= MRFROMSHORT(nItemCount
);
1164 if(pWnd
&& pWnd
->m_fnOldWndProc
)
1165 rc
= pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
);
1167 rc
= ::WinDefWindowProc(hWnd
, ulMsg
, wParam
, lParam
);
1170 } // end of wxFrameMainWndProc
1172 MRESULT EXPENTRY
wxFrameWndProc(
1180 // Trace all ulMsgs - useful for the debugging
1183 wxFrame
* pWnd
= NULL
;
1185 parentHwnd
= WinQueryWindow(hWnd
,QW_PARENT
);
1186 pWnd
= (wxFrame
*) wxFindWinFromHandle((WXHWND
) hWnd
);
1189 // When we get the first message for the HWND we just created, we associate
1190 // it with wxWindow stored in wxWndHook
1193 MRESULT rc
= (MRESULT
)0;
1196 // Stop right here if we don't have a valid handle in our wxWindow object.
1198 if (pWnd
&& !pWnd
->GetHWND())
1200 pWnd
->SetHWND((WXHWND
) hWnd
);
1201 rc
= pWnd
->OS2DefWindowProc(ulMsg
, wParam
, lParam
);
1207 rc
= pWnd
->OS2WindowProc(ulMsg
, wParam
, lParam
);
1209 rc
= ::WinDefWindowProc(hWnd
, ulMsg
, wParam
, lParam
);
1212 } // end of wxFrameWndProc
1214 MRESULT
wxFrame::OS2WindowProc( WXUINT uMessage
,
1219 bool bProcessed
= false;
1225 // If we can't close, tell the system that we processed the
1226 // message - otherwise it would close us
1228 bProcessed
= !Close();
1232 bProcessed
= HandlePaint();
1233 mRc
= (MRESULT
)FALSE
;
1236 case WM_ERASEBACKGROUND
:
1238 // Returning TRUE to requests PM to paint the window background
1239 // in SYSCLR_WINDOW. We capture this here because the PS returned
1240 // in Frames is the PS for the whole frame, which we can't really
1241 // use at all. If you want to paint a different background, do it
1242 // in an OnPaint using a wxPaintDC.
1244 mRc
= (MRESULT
)(TRUE
);
1253 UnpackCommand( (WXWPARAM
)wParam
1260 bProcessed
= HandleCommand( wId
1273 UnpackMenuSelect( wParam
1279 bProcessed
= HandleMenuSelect( wItem
1283 mRc
= (MRESULT
)TRUE
;
1289 SHORT nScxnew
= SHORT1FROMMP(lParam
); // New horizontal size.
1290 SHORT nScynew
= SHORT2FROMMP(lParam
); // New vertical size.
1292 lParam
= MRFROM2SHORT( nScxnew
- 20
1296 bProcessed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), (WXUINT
)wParam
);
1297 mRc
= (MRESULT
)FALSE
;
1300 case CM_QUERYDRAGIMAGE
:
1302 const wxIcon
& vIcon
= GetIcon();
1306 hIcon
= (HPOINTER
)::WinSendMsg(GetHWND(), WM_QUERYICON
, 0L, 0L);
1308 hIcon
= (HPOINTER
)m_hDefaultIcon
;
1309 mRc
= (MRESULT
)hIcon
;
1310 bProcessed
= mRc
!= 0;
1316 mRc
= wxWindow::OS2WindowProc( uMessage
1320 return (MRESULT
)mRc
;
1321 } // wxFrame::OS2WindowProc
1323 void wxFrame::SetClient(WXHWND
WXUNUSED(c_Hwnd
))
1325 // Duh...nothing to do under OS/2
1328 void wxFrame::SetClient( wxWindow
* pWindow
)
1330 wxWindow
* pOldClient
= this->GetClient();
1331 bool bClientHasFocus
= pOldClient
&& (pOldClient
== wxWindow::FindFocus());
1333 if(pOldClient
== pWindow
) // nothing to do
1335 if(pWindow
== NULL
) // just need to remove old client
1337 if(pOldClient
== NULL
) // nothing to do
1340 if(bClientHasFocus
)
1343 pOldClient
->Enable( false );
1344 pOldClient
->Show( false );
1345 ::WinSetWindowUShort(pOldClient
->GetHWND(), QWS_ID
, (USHORT
)pOldClient
->GetId());
1346 // to avoid OS/2 bug need to update frame
1347 ::WinSendMsg((HWND
)this->GetFrame(), WM_UPDATEFRAME
, (MPARAM
)~0, 0);
1352 // Else need to change client
1357 ::WinEnableWindowUpdate((HWND
)GetHWND(), FALSE
);
1360 pOldClient
->Enable(false);
1361 pOldClient
->Show(false);
1362 ::WinSetWindowUShort(pOldClient
->GetHWND(), QWS_ID
, (USHORT
)pOldClient
->GetId());
1364 pWindow
->Reparent(this);
1365 ::WinSetWindowUShort(pWindow
->GetHWND(), QWS_ID
, FID_CLIENT
);
1366 ::WinEnableWindowUpdate((HWND
)GetHWND(), TRUE
);
1368 pWindow
->Show(); // ensure client is showing
1369 if( this->IsShown() )
1372 ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0);
1376 wxWindow
* wxFrame::GetClient()
1378 return wxFindWinFromHandle((WXHWND
)::WinWindowFromID(m_hFrame
, FID_CLIENT
));