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 #include "wx/generic/statusbr.h" 
  41 // ---------------------------------------------------------------------------- 
  43 // ---------------------------------------------------------------------------- 
  45 #if wxUSE_MENUS_NATIVE 
  46 extern wxMenu 
*wxCurrentPopupMenu
; 
  49 // ---------------------------------------------------------------------------- 
  51 // ---------------------------------------------------------------------------- 
  53 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
) 
  54     EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
) 
  57 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxWindow
) 
  59 // ============================================================================ 
  61 // ============================================================================ 
  63 // ---------------------------------------------------------------------------- 
  64 // static class members 
  65 // ---------------------------------------------------------------------------- 
  68 #if wxUSE_NATIVE_STATUSBAR 
  69     bool wxFrame::m_bUseNativeStatusBar 
= true; 
  71     bool wxFrame::m_bUseNativeStatusBar 
= false; 
  74 #endif //wxUSE_STATUSBAR 
  76 // ---------------------------------------------------------------------------- 
  77 // creation/destruction 
  78 // ---------------------------------------------------------------------------- 
  82     m_nFsStatusBarFields 
= 0; 
  83     m_nFsStatusBarHeight 
= 0; 
  84     m_nFsToolBarHeight   
= 0; 
  86     m_bWasMinimized      
= false; 
  89     m_frameMenuBar   
= NULL
; 
  90     m_frameToolBar   
= NULL
; 
  91     m_frameStatusBar 
= NULL
; 
  93     m_hTitleBar 
= NULLHANDLE
; 
  94     m_hHScroll  
= NULLHANDLE
; 
  95     m_hVScroll  
= NULLHANDLE
; 
 100     memset(&m_vSwpTitleBar
, 0, sizeof(SWP
)); 
 101     memset(&m_vSwpMenuBar
, 0, sizeof(SWP
)); 
 102     memset(&m_vSwpHScroll
, 0, sizeof(SWP
)); 
 103     memset(&m_vSwpVScroll
, 0, sizeof(SWP
)); 
 104     memset(&m_vSwpStatusBar
, 0, sizeof(SWP
)); 
 105     memset(&m_vSwpToolBar
, 0, sizeof(SWP
)); 
 108 } // end of wxFrame::Init 
 110 bool wxFrame::Create( wxWindow
*       pParent
, 
 112                       const wxString
& rsTitle
, 
 116                       const wxString
& rsName 
) 
 118     if (!wxTopLevelWindow::Create( pParent
 
 128 } // end of wxFrame::Create 
 132     m_isBeingDeleted 
= true; 
 134 } // end of wxFrame::~wxFrame 
 137 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. 
 139 void wxFrame::DoGetClientSize( 
 144     wxTopLevelWindow::DoGetClientSize( pX
 
 148     // No need to use statusbar code as in WIN32 as the FORMATFRAME 
 149     // window procedure ensures PM knows about the new frame client 
 150     // size internally.  A ::WinQueryWindowRect (that is called in 
 151     // wxWindow's GetClient size from above) is all that is needed! 
 153 } // end of wxFrame::DoGetClientSize 
 156 // Set the client size (i.e. leave the calculation of borders etc. 
 159 void wxFrame::DoSetClientSize( 
 165     // Statusbars are not part of the OS/2 Client but parent frame 
 166     // so no statusbar consideration 
 168     wxTopLevelWindow::DoSetClientSize( nWidth
 
 171 } // end of wxFrame::DoSetClientSize 
 173 // ---------------------------------------------------------------------------- 
 174 // wxFrame: various geometry-related functions 
 175 // ---------------------------------------------------------------------------- 
 177 void wxFrame::Raise() 
 179     wxFrameBase::Raise(); 
 180     ::WinSetWindowPos( (HWND
) GetParent()->GetHWND() 
 191 wxStatusBar
* wxFrame::OnCreateStatusBar( 
 195 , const wxString
&                   rName
 
 198     wxStatusBar
*                    pStatusBar 
= NULL
; 
 201     pStatusBar 
= wxFrameBase::OnCreateStatusBar( nNumber
 
 210     wxClientDC                      
vDC(pStatusBar
); 
 214     // Set the height according to the font and the border size 
 216     vDC
.SetFont(pStatusBar
->GetFont()); // Screws up the menues for some reason 
 217     vDC
.GetTextExtent( wxT("X") 
 222     int                             nHeight 
= ((11 * nY
) / 10 + 2 * pStatusBar
->GetBorderY()); 
 224     pStatusBar
->SetSize( wxDefaultCoord
 
 230     ::WinSetParent( pStatusBar
->GetHWND(), m_hFrame
, FALSE 
); 
 231     ::WinSetOwner( pStatusBar
->GetHWND(), m_hFrame
); 
 235     if(::WinIsWindowShowing(m_hFrame
)) 
 236         ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0); 
 239 } // end of wxFrame::OnCreateStatusBar 
 241 void wxFrame::PositionStatusBar() 
 248     // Native status bar positions itself 
 250     if (m_frameStatusBar
) 
 259         ::WinQueryWindowRect(m_hFrame
, &vRect
); 
 261         ::WinMapWindowPoints(m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRect
, 2); 
 263         ::WinCalcFrameRect(m_hFrame
, &vRect
, TRUE
); 
 264         nWidth 
= vRect
.xRight 
- vRect
.xLeft
; 
 265         nY 
= nY 
- (vRect
.yBottom 
- vFRect
.yBottom
); 
 267         m_frameStatusBar
->GetSize( &nStatbarWidth
 
 271         nY
= nY 
- nStatbarHeight
; 
 273         // Since we wish the status bar to be directly under the client area, 
 274         // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. 
 276         m_frameStatusBar
->SetSize( vRect
.xLeft 
- vFRect
.xLeft
 
 281         if (!::WinQueryWindowPos(m_frameStatusBar
->GetHWND(), &vSwp
)) 
 283             vError 
= ::WinGetLastError(vHabmain
); 
 284             sError 
= wxPMErrorToStr(vError
); 
 285             wxLogError(_T("Error setting parent for StatusBar. Error: %s\n"), sError
.c_str()); 
 289 } // end of wxFrame::PositionStatusBar 
 290 #endif // wxUSE_STATUSBAR 
 293 wxToolBar
* wxFrame::OnCreateToolBar( long lStyle
, wxWindowID vId
, const wxString
& rsName 
) 
 295     wxToolBar
*                      pToolBar 
= wxFrameBase::OnCreateToolBar( lStyle
 
 300     ::WinSetParent( pToolBar
->GetHWND(), m_hFrame
, FALSE
); 
 301     ::WinSetOwner( pToolBar
->GetHWND(), m_hFrame
); 
 303 } // end of WinGuiBase_CFrame::OnCreateToolBar 
 306 #if wxUSE_MENUS_NATIVE 
 307 void wxFrame::DetachMenuBar() 
 311         m_frameMenuBar
->Detach(); 
 312         m_frameMenuBar 
= NULL
; 
 314 } // end of wxFrame::DetachMenuBar 
 316 void wxFrame::SetMenuBar( 
 327         // Actually remove the menu from the frame 
 329         m_hMenu 
= (WXHMENU
)0; 
 330         InternalSetMenuBar(); 
 332     else // set new non NULL menu bar 
 334         m_frameMenuBar 
= NULL
; 
 337         // Can set a menubar several times. 
 338         // TODO: how to prevent a memory leak if you have a currently-unattached 
 339         // menubar? wxWidgets assumes that the frame will delete the menu (otherwise 
 340         // there are problems for MDI). 
 342         if (pMenuBar
->GetHMenu()) 
 344             m_hMenu 
= pMenuBar
->GetHMenu(); 
 349             m_hMenu 
= pMenuBar
->Create(); 
 353         InternalSetMenuBar(); 
 354         m_frameMenuBar 
= pMenuBar
; 
 355         pMenuBar
->Attach((wxFrame
*)this); 
 357 } // end of wxFrame::SetMenuBar 
 359 void wxFrame::AttachMenuBar( 
 363     wxFrameBase::AttachMenuBar(pMenubar
); 
 365     m_frameMenuBar 
= pMenubar
; 
 370         // Actually remove the menu from the frame 
 372         m_hMenu 
= (WXHMENU
)0; 
 373         InternalSetMenuBar(); 
 375     else // Set new non NULL menu bar 
 378         // Can set a menubar several times. 
 380         if (pMenubar
->GetHMenu()) 
 382             m_hMenu 
= pMenubar
->GetHMenu(); 
 386             if (pMenubar
->IsAttached()) 
 389             m_hMenu 
= pMenubar
->Create(); 
 394         InternalSetMenuBar(); 
 396 } // end of wxFrame::AttachMenuBar 
 398 void wxFrame::InternalSetMenuBar() 
 403     // Set the parent and owner of the menubar to be the frame 
 405     if (!::WinSetParent(m_hMenu
, m_hFrame
, FALSE
)) 
 407         vError 
= ::WinGetLastError(vHabmain
); 
 408         sError 
= wxPMErrorToStr(vError
); 
 409         wxLogError(_T("Error setting parent for submenu. Error: %s\n"), sError
.c_str()); 
 412     if (!::WinSetOwner(m_hMenu
, m_hFrame
)) 
 414         vError 
= ::WinGetLastError(vHabmain
); 
 415         sError 
= wxPMErrorToStr(vError
); 
 416         wxLogError(_T("Error setting parent for submenu. Error: %s\n"), sError
.c_str()); 
 418     ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0); 
 419 } // end of wxFrame::InternalSetMenuBar 
 420 #endif // wxUSE_MENUS_NATIVE 
 423 // Responds to colour changes, and passes event on to children 
 425 void wxFrame::OnSysColourChanged( 
 426   wxSysColourChangedEvent
&          rEvent
 
 429     SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
)); 
 433     if (m_frameStatusBar
) 
 435         wxSysColourChangedEvent     vEvent2
; 
 437         vEvent2
.SetEventObject(m_frameStatusBar
); 
 438         m_frameStatusBar
->GetEventHandler()->ProcessEvent(vEvent2
); 
 440 #endif //wxUSE_STATUSBAR 
 443     // Propagate the event to the non-top-level children 
 445     wxWindow::OnSysColourChanged(rEvent
); 
 446 } // end of wxFrame::OnSysColourChanged 
 448 // Pass true to show full screen, false to restore. 
 449 bool wxFrame::ShowFullScreen( bool bShow
, long lStyle 
) 
 456         m_bFsIsShowing 
= true; 
 460         wxToolBar
*                  pTheToolBar 
= GetToolBar(); 
 461 #endif //wxUSE_TOOLBAR 
 464         wxStatusBar
*                pTheStatusBar 
= GetStatusBar(); 
 465 #endif //wxUSE_STATUSBAR 
 471             pTheToolBar
->GetSize(&nDummyWidth
, &m_nFsToolBarHeight
); 
 472 #endif //wxUSE_TOOLBAR 
 476             pTheStatusBar
->GetSize(&nDummyWidth
, &m_nFsStatusBarHeight
); 
 477 #endif //wxUSE_STATUSBAR 
 481         // Zap the toolbar, menubar, and statusbar 
 483         if ((lStyle 
& wxFULLSCREEN_NOTOOLBAR
) && pTheToolBar
) 
 485             pTheToolBar
->SetSize(wxDefaultCoord
,0); 
 486             pTheToolBar
->Show(false); 
 488 #endif //wxUSE_TOOLBAR 
 490         if (lStyle 
& wxFULLSCREEN_NOMENUBAR
) 
 492             ::WinSetParent(m_hMenu
, m_hFrame
, FALSE
); 
 493             ::WinSetOwner(m_hMenu
, m_hFrame
); 
 494             ::WinSendMsg((HWND
)m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0); 
 499         // Save the number of fields in the statusbar 
 501         if ((lStyle 
& wxFULLSCREEN_NOSTATUSBAR
) && pTheStatusBar
) 
 503             m_nFsStatusBarFields 
= pTheStatusBar
->GetFieldsCount(); 
 504             SetStatusBar((wxStatusBar
*) NULL
); 
 505             delete pTheStatusBar
; 
 508             m_nFsStatusBarFields 
= 0; 
 509 #endif //wxUSE_STATUSBAR 
 512         // Zap the frame borders 
 516         // Save the 'normal' window style 
 518         m_lFsOldWindowStyle 
= ::WinQueryWindowULong(m_hFrame
, QWL_STYLE
); 
 521         // Save the old position, width & height, maximize state 
 523         m_vFsOldSize 
= GetRect(); 
 524         m_bFsIsMaximized 
= IsMaximized(); 
 527         // Decide which window style flags to turn off 
 529         LONG lNewStyle 
= m_lFsOldWindowStyle
; 
 532         if (lStyle 
& wxFULLSCREEN_NOBORDER
) 
 533             lOffFlags 
|= FCF_BORDER
; 
 534         if (lStyle 
& wxFULLSCREEN_NOCAPTION
) 
 535             lOffFlags 
|= (FCF_TASKLIST 
| FCF_SYSMENU
); 
 537         lNewStyle 
&= (~lOffFlags
); 
 540         // Change our window style to be compatible with full-screen mode 
 542         ::WinSetWindowULong((HWND
)m_hFrame
, QWL_STYLE
, (ULONG
)lNewStyle
); 
 545         // Resize to the size of the desktop 
 551         ::WinQueryWindowRect(HWND_DESKTOP
, &vRect
); 
 552         nWidth 
= vRect
.xRight 
- vRect
.xLeft
; 
 554         // Remember OS/2 is backwards! 
 556         nHeight 
= vRect
.yTop 
- vRect
.yBottom
; 
 558         SetSize( nWidth
, nHeight
); 
 561         // Now flush the window style cache and actually go full-screen 
 563         ::WinSetWindowPos( (HWND
) GetParent()->GetHWND() 
 572         wxSize 
sz( nWidth
, nHeight 
); 
 573         wxSizeEvent 
vEvent( sz
, GetId() ); 
 575         GetEventHandler()->ProcessEvent(vEvent
); 
 583         m_bFsIsShowing 
= false; 
 586         wxToolBar
*                  pTheToolBar 
= GetToolBar(); 
 589         // Restore the toolbar, menubar, and statusbar 
 591         if (pTheToolBar 
&& (m_lFsStyle 
& wxFULLSCREEN_NOTOOLBAR
)) 
 593             pTheToolBar
->SetSize(wxDefaultCoord
, m_nFsToolBarHeight
); 
 594             pTheToolBar
->Show(true); 
 596 #endif //wxUSE_TOOLBAR 
 599         if ((m_lFsStyle 
& wxFULLSCREEN_NOSTATUSBAR
) && (m_nFsStatusBarFields 
> 0)) 
 601             CreateStatusBar(m_nFsStatusBarFields
); 
 602 //          PositionStatusBar(); 
 604 #endif //wxUSE_STATUSBAR 
 606         if ((m_lFsStyle 
& wxFULLSCREEN_NOMENUBAR
) && (m_hMenu 
!= 0)) 
 608             ::WinSetParent(m_hMenu
, m_hFrame
, FALSE
); 
 609             ::WinSetOwner(m_hMenu
, m_hFrame
); 
 610             ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0); 
 612         Maximize(m_bFsIsMaximized
); 
 614         ::WinSetWindowULong( m_hFrame
 
 616                             ,(ULONG
)m_lFsOldWindowStyle
 
 618         ::WinSetWindowPos( (HWND
) GetParent()->GetHWND() 
 627     return wxFrameBase::ShowFullScreen(bShow
, lStyle
); 
 628 } // end of wxFrame::ShowFullScreen 
 633 // ---------------------------------------------------------------------------- 
 634 // wxFrame size management: we exclude the areas taken by menu/status/toolbars 
 635 // from the client area, so the client area is what's really available for the 
 637 // ---------------------------------------------------------------------------- 
 639 // Checks if there is a toolbar, and returns the first free client position 
 640 wxPoint 
wxFrame::GetClientAreaOrigin() const 
 642     wxPoint                         vPoint 
= wxTopLevelWindow::GetClientAreaOrigin(); 
 645     // In OS/2 the toolbar and statusbar are frame extensions so there is no 
 646     // adjustment.  The client is supposedly resized for a toolbar in OS/2 
 647     // as it is for the status bar. 
 650 } // end of wxFrame::GetClientAreaOrigin 
 652 // ---------------------------------------------------------------------------- 
 653 // tool/status bar stuff 
 654 // ---------------------------------------------------------------------------- 
 658 wxToolBar
* wxFrame::CreateToolBar( 
 661 , const wxString
&                   rName
 
 664     if (wxFrameBase::CreateToolBar( lStyle
 
 671     return m_frameToolBar
; 
 672 } // end of wxFrame::CreateToolBar 
 674 void wxFrame::PositionToolBar() 
 676     wxToolBar
*                      pToolBar 
= GetToolBar(); 
 689     ::WinQueryWindowRect(m_hFrame
, &vRect
); 
 690     vPos
.y 
= (wxCoord
)vRect
.yTop
; 
 691     ::WinMapWindowPoints(m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRect
, 2); 
 693     ::WinCalcFrameRect(m_hFrame
, &vRect
, TRUE
); 
 695     vPos
.y 
= (wxCoord
)(vFRect
.yTop 
- vRect
.yTop
); 
 696     pToolBar
->GetSize( &vTWidth
 
 700     if (pToolBar
->GetWindowStyleFlag() & wxTB_HORIZONTAL
) 
 702         vWidth 
= (wxCoord
)(vRect
.xRight 
- vRect
.xLeft
); 
 703         pToolBar
->SetSize( vRect
.xLeft 
- vFRect
.xLeft
 
 712         wxCoord                     vSheight 
= 0; 
 714         if (m_frameStatusBar
) 
 715             m_frameStatusBar
->GetSize( &vSwidth
 
 718         vHeight 
= (wxCoord
)(vRect
.yTop 
- vRect
.yBottom
); 
 719         pToolBar
->SetSize( vRect
.xLeft 
- vFRect
.xLeft
 
 725     if( ::WinIsWindowShowing(m_hFrame
) ) 
 726         ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0); 
 727 } // end of wxFrame::PositionToolBar 
 728 #endif // wxUSE_TOOLBAR 
 730 // ---------------------------------------------------------------------------- 
 731 // frame state (iconized/maximized/...) 
 732 // ---------------------------------------------------------------------------- 
 735 // propagate our state change to all child frames: this allows us to emulate X 
 736 // Windows behaviour where child frames float independently of the parent one 
 737 // on the desktop, but are iconized/restored with it 
 739 void wxFrame::IconizeChildFrames( bool WXUNUSED(bIconize
) ) 
 741   // FIXME: Generic MDI does not use Frames for the Childs, so this does _not_ 
 742   //        work. Possibly, the right thing is simply to eliminate this 
 743   //        functions and all the calls to it from within this file. 
 745     for (wxWindowList::Node
* pNode 
= GetChildren().GetFirst(); 
 747          pNode 
= pNode
->GetNext() ) 
 749         wxWindow
*                   pWin 
= pNode
->GetData(); 
 750         wxFrame
*                    pFrame 
= wxDynamicCast(pWin
, wxFrame
); 
 753 #if wxUSE_MDI_ARCHITECTURE 
 754                 && !wxDynamicCast(pFrame
, wxMDIChildFrame
) 
 755 #endif // wxUSE_MDI_ARCHITECTURE 
 759             // We don't want to restore the child frames which had been 
 760             // iconized even before we were iconized, so save the child frame 
 761             // status when iconizing the parent frame and check it when 
 766                 pFrame
->m_bWasMinimized 
= pFrame
->IsIconized(); 
 770             // This test works for both iconizing and restoring 
 772             if (!pFrame
->m_bWasMinimized
) 
 773                 pFrame
->Iconize(bIconize
); 
 777 } // end of wxFrame::IconizeChildFrames 
 779 WXHICON 
wxFrame::GetDefaultIcon() const 
 781     return (WXHICON
)(wxSTD_FRAME_ICON 
? wxSTD_FRAME_ICON
 
 782                                       : wxDEFAULT_FRAME_ICON
); 
 784 // =========================================================================== 
 785 // message processing 
 786 // =========================================================================== 
 788 // --------------------------------------------------------------------------- 
 790 // --------------------------------------------------------------------------- 
 791 bool wxFrame::OS2TranslateMessage( WXMSG
* pMsg 
) 
 794     // try the menu bar accels 
 796     wxMenuBar
* pMenuBar 
= GetMenuBar(); 
 801 #if wxUSE_ACCEL && wxUSE_MENUS_NATIVE 
 802     const wxAcceleratorTable
&       rAcceleratorTable 
= pMenuBar
->GetAccelTable(); 
 803     return rAcceleratorTable
.Translate(GetHWND(), pMsg
); 
 807 } // end of wxFrame::OS2TranslateMessage 
 809 // --------------------------------------------------------------------------- 
 810 // our private (non virtual) message handlers 
 811 // --------------------------------------------------------------------------- 
 812 bool wxFrame::HandlePaint() 
 816     if (::WinQueryUpdateRect(GetHWND(), &vRect
)) 
 821             // Icons in PM are the same as "pointers" 
 823             const wxIcon
&           vIcon 
= GetIcon(); 
 827                 hIcon 
= (HPOINTER
)::WinSendMsg(m_hFrame
, WM_QUERYICON
, 0L, 0L); 
 829                 hIcon 
= (HPOINTER
)m_hDefaultIcon
; 
 832             // Hold a pointer to the dc so long as the OnPaint() message 
 833             // is being processed 
 836             HPS                     hPs 
= ::WinBeginPaint(GetHwnd(), NULLHANDLE
, &vRect2
); 
 839             // Erase background before painting or we get white background 
 841             OS2DefWindowProc(WM_ERASEBACKGROUND
, (MPARAM
)hPs
, (MPARAM
)&vRect2
); 
 847                 ::WinQueryWindowRect(GetHwnd(), &vRect3
); 
 849                 static const int    nIconWidth 
= 32; 
 850                 static const int    nIconHeight 
= 32; 
 851                 int                 nIconX 
= (int)((vRect3
.xRight 
- nIconWidth
)/2); 
 852                 int                 nIconY 
= (int)((vRect3
.yBottom 
+ nIconHeight
)/2); 
 854                 ::WinDrawPointer(hPs
, nIconX
, nIconY
, hIcon
, DP_NORMAL
); 
 860             if (!wxWindow::HandlePaint()) 
 865                 hPS 
= ::WinBeginPaint( GetHwnd() 
 871                     ::GpiCreateLogColorTable( hPS
 
 875                                              ,(LONG
)wxTheColourDatabase
->m_nSize
 
 876                                              ,(PLONG
)wxTheColourDatabase
->m_palTable
 
 878                     ::GpiCreateLogColorTable( hPS
 
 888                                   ,GetBackgroundColour().GetPixel() 
 897 } // end of wxFrame::HandlePaint 
 899 bool wxFrame::HandleSize( int nX
, int nY
, WXUINT nId 
) 
 901     bool bProcessed 
= false; 
 907             // Only do it it if we were iconized before, otherwise resizing the 
 908             // parent frame has a curious side effect of bringing it under it's 
 914             // restore all child frames too 
 916             IconizeChildFrames(false); 
 917             (void)SendIconizeEvent(false); 
 929             // Iconize all child frames too 
 931             IconizeChildFrames(true); 
 932             (void)SendIconizeEvent(); 
 940         // forward WM_SIZE to status bar control 
 942 #if wxUSE_NATIVE_STATUSBAR 
 943         if (m_frameStatusBar 
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
))) 
 945             wxSizeEvent             
vEvent( wxSize( nX
 
 948                                            ,m_frameStatusBar
->GetId() 
 951             vEvent
.SetEventObject(m_frameStatusBar
); 
 952             m_frameStatusBar
->OnSize(vEvent
); 
 954 #endif // wxUSE_NATIVE_STATUSBAR 
 959 #endif // wxUSE_TOOLBAR 
 961         bProcessed 
= wxWindow::HandleSize( nX
 
 967 } // end of wxFrame::HandleSize 
 969 bool wxFrame::HandleCommand( WXWORD nId
, 
 976         // In case it's e.g. a toolbar. 
 978         wxWindow
*                   pWin 
= wxFindWinFromHandle(hControl
); 
 981             return pWin
->OS2Command( nCmd
, nId 
); 
 985     // Handle here commands from menus and accelerators 
 987     if (nCmd 
== CMDSRC_MENU 
|| nCmd 
== CMDSRC_ACCELERATOR
) 
 989 #if wxUSE_MENUS_NATIVE 
 990         if (wxCurrentPopupMenu
) 
 992             wxMenu
*                 pPopupMenu 
= wxCurrentPopupMenu
; 
 994             wxCurrentPopupMenu 
= NULL
; 
 996             return pPopupMenu
->OS2Command( nCmd
, nId 
); 
1000         if (ProcessCommand(nId
)) 
1006 } // end of wxFrame::HandleCommand 
1008 bool wxFrame::HandleMenuSelect( WXWORD nItem
, 
1017         rc 
= ::WinSendMsg(hMenu
, MM_QUERYITEM
, MPFROM2SHORT(nItem
, TRUE
), (MPARAM
)&mItem
); 
1019         if(rc 
&& !(mItem
.afStyle 
& (MIS_SUBMENU 
| MIS_SEPARATOR
))) 
1021             wxMenuEvent                     
vEvent(wxEVT_MENU_HIGHLIGHT
, nItem
); 
1023             vEvent
.SetEventObject(this); 
1024             GetEventHandler()->ProcessEvent(vEvent
); // return value would be ignored by PM 
1028             DoGiveHelp(wxEmptyString
, false); 
1033 } // end of wxFrame::HandleMenuSelect 
1035 // --------------------------------------------------------------------------- 
1036 // Main Frame window proc 
1037 // --------------------------------------------------------------------------- 
1038 MRESULT EXPENTRY 
wxFrameMainWndProc( HWND   hWnd
, 
1043     MRESULT  rc 
= (MRESULT
)0; 
1044     bool     bProcessed 
= false; 
1045     wxFrame
* pWnd  
= NULL
; 
1047     pWnd 
= (wxFrame
*) wxFindWinFromHandle((WXHWND
) hWnd
); 
1050         case WM_QUERYFRAMECTLCOUNT
: 
1051             if(pWnd 
&& pWnd
->m_fnOldWndProc
) 
1053                 USHORT              uItemCount 
= SHORT1FROMMR(pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
)); 
1055                 rc 
= MRFROMSHORT(uItemCount
); 
1059         case WM_FORMATFRAME
: 
1060 ///////////////////////////////////////////////////////////////////////////////// 
1061 // Applications that subclass frame controls may find that the frame is already 
1062 // subclassed the number of frame controls is variable. 
1063 // The WM_FORMATFRAME and WM_QUERYFRAMECTLCOUNT messages must always be 
1064 // subclassed by calling the previous window procedure and modifying its result. 
1065 //////////////////////////////////////////////////////////////////////////////// 
1077                 pSWP 
= (PSWP
)PVOIDFROMMP(wParam
); 
1078                 nItemCount 
= SHORT1FROMMR(pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
)); 
1079                 if(pWnd
->m_frameStatusBar
) 
1081                     ::WinQueryWindowRect(pWnd
->m_frameStatusBar
->GetHWND(), &vRstb
); 
1082                     pWnd
->m_frameStatusBar
->GetSize(NULL
, &nHeight
); 
1084                 if(pWnd
->m_frameToolBar
) 
1086                     ::WinQueryWindowRect(pWnd
->m_frameToolBar
->GetHWND(), &vRtlb
); 
1087                     pWnd
->m_frameToolBar
->GetSize(&nWidth
, &nHeight2
); 
1089                 ::WinQueryWindowRect(pWnd
->m_hFrame
, &vRectl
); 
1090                 ::WinMapWindowPoints(pWnd
->m_hFrame
, HWND_DESKTOP
, (PPOINTL
)&vRectl
, 2); 
1091                 ::WinCalcFrameRect(pWnd
->m_hFrame
, &vRectl
, TRUE
); 
1092                 ::WinMapWindowPoints(HWND_DESKTOP
, pWnd
->m_hFrame
, (PPOINTL
)&vRectl
, 2); 
1093                 for(i 
= 0; i 
< nItemCount
; i
++) 
1095                     if(pWnd
->m_hWnd 
&& pSWP
[i
].hwnd 
== pWnd
->m_hWnd
) 
1097                         if (pWnd
->m_frameToolBar 
&& pWnd
->m_frameToolBar
->GetWindowStyleFlag() & wxTB_HORIZONTAL
) 
1099                             pSWP
[i
].x    
= vRectl
.xLeft
; 
1100                             pSWP
[i
].y    
= vRectl
.yBottom 
+ nHeight
; 
1101                             pSWP
[i
].cx   
= vRectl
.xRight 
- vRectl
.xLeft
; 
1102                             pSWP
[i
].cy   
= vRectl
.yTop 
- vRectl
.yBottom 
- (nHeight 
+ nHeight2
); 
1106                             pSWP
[i
].x    
= vRectl
.xLeft 
+ nWidth
; 
1107                             pSWP
[i
].y    
= vRectl
.yBottom 
+ nHeight
; 
1108                             pSWP
[i
].cx   
= vRectl
.xRight 
- (vRectl
.xLeft 
+ nWidth
); 
1109                             pSWP
[i
].cy   
= vRectl
.yTop 
- vRectl
.yBottom 
- nHeight
; 
1111                         pSWP
[i
].fl   
= SWP_SIZE 
| SWP_MOVE 
| SWP_SHOW
; 
1112                         pSWP
[i
].hwndInsertBehind 
= HWND_TOP
; 
1116                 rc 
= MRFROMSHORT(nItemCount
); 
1121             if(pWnd 
&& pWnd
->m_fnOldWndProc
) 
1122                 rc 
= pWnd
->m_fnOldWndProc(hWnd
, ulMsg
, wParam
, lParam
); 
1124                 rc 
= ::WinDefWindowProc(hWnd
, ulMsg
, wParam
, lParam
); 
1127 } // end of wxFrameMainWndProc 
1129 MRESULT EXPENTRY 
wxFrameWndProc( 
1137     // Trace all ulMsgs - useful for the debugging 
1140     wxFrame
*                        pWnd  
= NULL
; 
1142     parentHwnd  
= WinQueryWindow(hWnd
,QW_PARENT
); 
1143     pWnd 
= (wxFrame
*) wxFindWinFromHandle((WXHWND
) hWnd
); 
1146     // When we get the first message for the HWND we just created, we associate 
1147     // it with wxWindow stored in wxWndHook 
1150     MRESULT                         rc 
= (MRESULT
)0; 
1153     // Stop right here if we don't have a valid handle in our wxWindow object. 
1155     if (pWnd 
&& !pWnd
->GetHWND()) 
1157         pWnd
->SetHWND((WXHWND
) hWnd
); 
1158         rc 
= pWnd
->OS2DefWindowProc(ulMsg
, wParam
, lParam 
); 
1164             rc 
= pWnd
->OS2WindowProc(ulMsg
, wParam
, lParam
); 
1166             rc 
= ::WinDefWindowProc(hWnd
, ulMsg
, wParam
, lParam
); 
1169 } // end of wxFrameWndProc 
1171 MRESULT 
wxFrame::OS2WindowProc( WXUINT uMessage
, 
1176     bool    bProcessed 
= false; 
1182             // If we can't close, tell the system that we processed the 
1183             // message - otherwise it would close us 
1185             bProcessed 
= !Close(); 
1189             bProcessed 
= HandlePaint(); 
1190             mRc 
= (MRESULT
)FALSE
; 
1193          case WM_ERASEBACKGROUND
: 
1195             // Returning TRUE to requests PM to paint the window background 
1196             // in SYSCLR_WINDOW. We capture this here because the PS returned 
1197             // in Frames is the PS for the whole frame, which we can't really 
1198             // use at all. If you want to paint a different background, do it 
1199             // in an OnPaint using a wxPaintDC. 
1201             mRc 
= (MRESULT
)(TRUE
); 
1210                 UnpackCommand( (WXWPARAM
)wParam
 
1217                 bProcessed 
= HandleCommand( wId
 
1230                 UnpackMenuSelect( wParam
 
1236                 bProcessed 
= HandleMenuSelect( wItem
 
1240                 mRc 
= (MRESULT
)TRUE
; 
1246                 SHORT               nScxnew 
= SHORT1FROMMP(lParam
); // New horizontal size. 
1247                 SHORT               nScynew 
= SHORT2FROMMP(lParam
); // New vertical size. 
1249                 lParam 
= MRFROM2SHORT( nScxnew 
- 20 
1253             bProcessed 
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), (WXUINT
)wParam
); 
1254             mRc 
= (MRESULT
)FALSE
; 
1257         case CM_QUERYDRAGIMAGE
: 
1259                 const wxIcon
&           vIcon 
= GetIcon(); 
1263                     hIcon 
= (HPOINTER
)::WinSendMsg(GetHWND(), WM_QUERYICON
, 0L, 0L); 
1265                     hIcon 
= (HPOINTER
)m_hDefaultIcon
; 
1266                 mRc 
= (MRESULT
)hIcon
; 
1267                 bProcessed 
= mRc 
!= 0; 
1273         mRc 
= wxWindow::OS2WindowProc( uMessage
 
1277     return (MRESULT
)mRc
; 
1278 } // wxFrame::OS2WindowProc 
1280 void wxFrame::SetClient(WXHWND 
WXUNUSED(c_Hwnd
)) 
1282    // Duh...nothing to do under OS/2 
1285 void wxFrame::SetClient( wxWindow
* pWindow 
) 
1287     wxWindow
* pOldClient      
= this->GetClient(); 
1288     bool      bClientHasFocus 
= pOldClient 
&& (pOldClient 
== wxWindow::FindFocus()); 
1290     if(pOldClient 
== pWindow
)  // nothing to do 
1292     if(pWindow 
== NULL
) // just need to remove old client 
1294         if(pOldClient 
== NULL
) // nothing to do 
1297         if(bClientHasFocus 
) 
1300         pOldClient
->Enable( false ); 
1301         pOldClient
->Show( false ); 
1302         ::WinSetWindowUShort(pOldClient
->GetHWND(), QWS_ID
, (USHORT
)pOldClient
->GetId()); 
1303         // to avoid OS/2 bug need to update frame 
1304         ::WinSendMsg((HWND
)this->GetFrame(), WM_UPDATEFRAME
, (MPARAM
)~0, 0); 
1309     // Else need to change client 
1314     ::WinEnableWindowUpdate((HWND
)GetHWND(), FALSE
); 
1317         pOldClient
->Enable(false); 
1318         pOldClient
->Show(false); 
1319         ::WinSetWindowUShort(pOldClient
->GetHWND(), QWS_ID
, (USHORT
)pOldClient
->GetId()); 
1321     pWindow
->Reparent(this); 
1322     ::WinSetWindowUShort(pWindow
->GetHWND(), QWS_ID
, FID_CLIENT
); 
1323     ::WinEnableWindowUpdate((HWND
)GetHWND(), TRUE
); 
1325     pWindow
->Show();   // ensure client is showing 
1326     if( this->IsShown() ) 
1329         ::WinSendMsg(m_hFrame
, WM_UPDATEFRAME
, (MPARAM
)~0, 0); 
1333 wxWindow
* wxFrame::GetClient() 
1335     return wxFindWinFromHandle((WXHWND
)::WinWindowFromID(m_hFrame
, FID_CLIENT
)); 
1338 void wxFrame::SendSizeEvent() 
1342         RECTL                       vRect 
= wxGetWindowRect(GetHwnd()); 
1344         ::WinPostMsg( GetHwnd() 
1346                      ,MPFROM2SHORT( vRect
.xRight 
- vRect
.xLeft
 
1347                                    ,vRect
.xRight 
- vRect
.xLeft
 
1349                      ,MPFROM2SHORT( vRect
.yTop 
- vRect
.yBottom
 
1350                                    ,vRect
.yTop 
- vRect
.yBottom