X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/744c594651e4456776f1428a58db11a3e188ce6c..b8ea299a7e88d570be50a05e0c7a80190d9b24b4:/src/os2/window.cpp diff --git a/src/os2/window.cpp b/src/os2/window.cpp index c41347074c..33862da5f0 100644 --- a/src/os2/window.cpp +++ b/src/os2/window.cpp @@ -51,6 +51,8 @@ #include #endif +#include "wx/os2/dcclient.h" + #if wxUSE_OWNER_DRAWN #include "wx/ownerdrw.h" #endif @@ -121,7 +123,7 @@ QMSG s_currentMsg; #if wxUSE_MENUS_NATIVE -wxMenu* wxCurrentPopupMenu = NULL; +extern wxMenu* wxCurrentPopupMenu; #endif // wxUSE_MENUS_NATIVE // --------------------------------------------------------------------------- @@ -295,7 +297,6 @@ void wxWindowOS2::Init() m_bUseCtl3D = false; m_bMouseInWindow = false; m_bLastKeydownProcessed = false; - m_pChildrenDisabled = NULL; // // wxWnd @@ -333,7 +334,7 @@ void wxWindowOS2::Init() // wxWindowOS2::~wxWindowOS2() { - m_isBeingDeleted = true; + SendDestroyEvent(); for (wxWindow* pWin = GetParent(); pWin; pWin = pWin->GetParent()) { @@ -351,13 +352,14 @@ wxWindowOS2::~wxWindowOS2() if (m_hWnd) { if(!::WinDestroyWindow(GetHWND())) + { wxLogLastError(wxT("DestroyWindow")); + } // // remove hWnd <-> wxWindow association // wxRemoveHandleAssociation(this); } - delete m_pChildrenDisabled; } // end of wxWindowOS2::~wxWindowOS2 // real construction (Init() must have been called before!) @@ -384,7 +386,7 @@ bool wxWindowOS2::Create( wxWindow* pParent, // static box // wxASSERT_MSG( !wxDynamicCast(pParent, wxStaticBox), - _T("wxStaticBox can't be used as a window parent!") ); + wxT("wxStaticBox can't be used as a window parent!") ); #endif // wxUSE_STATBOX // Ensure groupbox backgrounds are painted @@ -454,7 +456,7 @@ bool wxWindowOS2::Create( wxWindow* pParent, void wxWindowOS2::SetFocus() { HWND hWnd = GetHwnd(); - wxCHECK_RET( hWnd, _T("can't set focus to invalid window") ); + wxCHECK_RET( hWnd, wxT("can't set focus to invalid window") ); if (hWnd) ::WinSetFocus(HWND_DESKTOP, hWnd); @@ -479,70 +481,12 @@ wxWindow* wxWindowBase::DoFindFocus() return NULL; } // wxWindowBase::DoFindFocus -bool wxWindowOS2::Enable( bool bEnable ) +void wxWindowOS2::DoEnable( bool bEnable ) { - if (!wxWindowBase::Enable(bEnable)) - return false; - HWND hWnd = GetHwnd(); - if ( hWnd ) ::WinEnableWindow(hWnd, (BOOL)bEnable); - - // - // The logic below doesn't apply to the top level windows -- otherwise - // showing a modal dialog would result in total greying out (and ungreying - // out later) of everything which would be really ugly - // - if (IsTopLevel()) - return true; - - wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); - - while (node) - { - wxWindow* pChild = node->GetData(); - - if (bEnable) - { - // - // Enable the child back unless it had been disabled before us - // - if (!m_pChildrenDisabled || !m_pChildrenDisabled->Find(pChild)) - pChild->Enable(); - } - else // we're being disabled - { - if (pChild->IsEnabled()) - { - // - // Disable it as children shouldn't stay enabled while the - // parent is not - // - pChild->Disable(); - } - else // child already disabled, remember it - { - // - // Have we created the list of disabled children already? - // - if (!m_pChildrenDisabled) - m_pChildrenDisabled = new wxWindowList; - m_pChildrenDisabled->Append(pChild); - } - } - node = node->GetNext(); - } - if (bEnable && m_pChildrenDisabled) - { - // - // We don't need this list any more, don't keep unused memory - // - delete m_pChildrenDisabled; - m_pChildrenDisabled = NULL; - } - return true; -} // end of wxWindowOS2::Enable +} bool wxWindowOS2::Show( bool bShow ) { @@ -572,7 +516,7 @@ void wxWindowOS2::Lower() void wxWindowOS2::SetLabel( const wxString& label ) { - ::WinSetWindowText(GetHwnd(), (PSZ)label.c_str()); + ::WinSetWindowText(GetHwnd(), label.c_str()); } // end of wxWindowOS2::SetLabel wxString wxWindowOS2::GetLabel() const @@ -603,7 +547,7 @@ void wxWindowOS2::DoReleaseMouse() /* static */ wxWindow* wxWindowBase::GetCapture() { HWND hwnd = ::WinQueryCapture(HWND_DESKTOP); - return hwnd ? wxFindWinFromHandle((WXHWND)hwnd) : (wxWindow *)NULL; + return hwnd ? wxFindWinFromHandle((WXHWND)hwnd) : NULL; } // end of wxWindowBase::GetCapture bool wxWindowOS2::SetFont( const wxFont& rFont ) @@ -1142,7 +1086,7 @@ void wxWindowOS2::OnIdle( ,vPoint.y ,nState ); - (void)GetEventHandler()->ProcessEvent(rEvent); + (void)HandleWindowEvent(rEvent); } } if (wxUpdateUIEvent::CanUpdate(this)) @@ -1152,7 +1096,7 @@ void wxWindowOS2::OnIdle( // // Set this window to be the child of 'parent'. // -bool wxWindowOS2::Reparent( wxWindow* pParent) +bool wxWindowOS2::Reparent( wxWindowBase* pParent) { if (!wxWindowBase::Reparent(pParent)) return false; @@ -1169,12 +1113,12 @@ void wxWindowOS2::Update() ::WinUpdateWindow(GetHwnd()); } // end of wxWindowOS2::Update -void wxWindowOS2::Freeze() +void wxWindowOS2::DoFreeze() { ::WinSendMsg(GetHwnd(), WM_VRNDISABLED, (MPARAM)0, (MPARAM)0); } // end of wxWindowOS2::Freeze -void wxWindowOS2::Thaw() +void wxWindowOS2::DoThaw() { ::WinSendMsg(GetHwnd(), WM_VRNENABLED, (MPARAM)TRUE, (MPARAM)0); @@ -1680,7 +1624,7 @@ void wxWindowOS2::DoSetClientSize( int nWidth, wxSize size( nWidth, nHeight ); wxSizeEvent vEvent( size, m_windowId ); vEvent.SetEventObject(this); - GetEventHandler()->ProcessEvent(vEvent); + HandleWindowEvent(vEvent); } // end of wxWindowOS2::DoSetClientSize // --------------------------------------------------------------------------- @@ -1719,12 +1663,12 @@ int wxWindowOS2::GetCharWidth() const return(vFontMetrics.lAveCharWidth); } // end of wxWindowOS2::GetCharWidth -void wxWindowOS2::GetTextExtent( const wxString& rString, - int* pX, - int* pY, - int* pDescent, - int* pExternalLeading, - const wxFont* WXUNUSED(pTheFont) ) const +void wxWindowOS2::DoGetTextExtent( const wxString& rString, + int* pX, + int* pY, + int* pDescent, + int* pExternalLeading, + const wxFont* WXUNUSED(pTheFont) ) const { POINTL avPoint[TXTBOX_COUNT]; POINTL vPtMin; @@ -1733,7 +1677,6 @@ void wxWindowOS2::GetTextExtent( const wxString& rString, int l; FONTMETRICS vFM; // metrics structure BOOL bRc = FALSE; - char* pStr; HPS hPS; hPS = ::WinGetPS(GetHwnd()); @@ -1741,14 +1684,12 @@ void wxWindowOS2::GetTextExtent( const wxString& rString, l = rString.length(); if (l > 0L) { - pStr = (PCH)rString.c_str(); - // // In world coordinates. // bRc = ::GpiQueryTextBox( hPS, l, - pStr, + (char*) rString.wx_str(), TXTBOX_COUNT,// return maximum information avPoint // array of coordinates points ); @@ -1811,7 +1752,7 @@ void wxWindowOS2::GetTextExtent( const wxString& rString, *pExternalLeading = 0; } ::WinReleasePS(hPS); -} // end of wxWindow::GetTextExtent +} // end of wxWindow::DoGetTextExtent bool wxWindowOS2::IsMouseInWindow() const { @@ -1847,11 +1788,6 @@ bool wxWindowOS2::DoPopupMenu( wxMenu* pMenu, int nX, int nY ) bool bIsWaiting = true; int nHeight; - // Protect against recursion - if (wxCurrentPopupMenu) - return false; - - pMenu->SetInvokingWindow(this); pMenu->UpdateUI(); if ( nX == -1 && nY == -1 ) @@ -1867,7 +1803,6 @@ bool wxWindowOS2::DoPopupMenu( wxMenu* pMenu, int nX, int nY ) DoGetSize(0,&nHeight); nY = nHeight - nY; } - wxCurrentPopupMenu = pMenu; ::WinPopupMenu( hWndParent ,hWndOwner @@ -1888,8 +1823,6 @@ bool wxWindowOS2::DoPopupMenu( wxMenu* pMenu, int nX, int nY ) ::WinDispatchMsg(vHabmain, (PQMSG)&vMsg); } - wxCurrentPopupMenu = NULL; - pMenu->SetInvokingWindow(NULL); return true; } // end of wxWindowOS2::DoPopupMenu #endif // wxUSE_MENUS_NATIVE @@ -2064,7 +1997,7 @@ bool wxWindowOS2::OS2ProcessMessage( WXMSG* pMsg ) vEvent.SetWindowChange(bWindowChange); vEvent.SetEventObject(this); - if (GetEventHandler()->ProcessEvent(vEvent)) + if (HandleWindowEvent(vEvent)) { wxButton* pBtn = wxDynamicCast(FindFocus(), wxButton); @@ -2418,7 +2351,7 @@ MRESULT wxWindowOS2::OS2WindowProc( WXUINT uMsg, ); if (!pWin->IsOfStandardClass()) { - if (uMsg == WM_BUTTON1DOWN && pWin->AcceptsFocus() ) + if (uMsg == WM_BUTTON1DOWN && pWin->CanAcceptFocus() ) pWin->SetFocus(); } bProcessed = pWin->HandleMouseEvent( uMsg @@ -2615,7 +2548,7 @@ MRESULT wxWindowOS2::OS2WindowProc( WXUINT uMsg, (pPage->ulPageIdNew > 0L && pPage->ulPageIdCur > 0L)) { wxWindowOS2* pWin = wxFindWinFromHandle(pPage->hwndBook); - wxNotebookEvent vEvent( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED + wxBookCtrlEvent vEvent( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED ,(int)SHORT1FROMMP(wParam) ,(int)pPage->ulPageIdNew ,(int)pPage->ulPageIdCur @@ -2920,7 +2853,7 @@ void wxAssociateWinWithHandle( { wxString Newstr(pWin->GetClassInfo()->GetClassName()); wxString Oldstr(pOldWin->GetClassInfo()->GetClassName()); - wxLogError( _T("Bug! New window of class %s has same HWND %X as old window of class %s"), + wxLogError( wxT("Bug! New window of class %s has same HWND %X as old window of class %s"), Newstr.c_str(), (int)hWnd, Oldstr.c_str() @@ -3004,6 +2937,7 @@ bool wxWindowOS2::OS2Create( PSZ zClass, long lControlId = 0L; wxWindowCreationHook vHook(this); wxString sClassName((wxChar*)zClass); + wxString sTitle(zTitle ? zTitle : wxEmptyString); OS2GetCreateWindowCoords( rPos ,rSize @@ -3031,8 +2965,8 @@ bool wxWindowOS2::OS2Create( PSZ zClass, sClassName += wxT("NR"); } m_hWnd = (WXHWND)::WinCreateWindow( (HWND)OS2GetParent() - ,(PSZ)sClassName.c_str() - ,(PSZ)(zTitle ? zTitle : wxEmptyString) + ,sClassName.c_str() + ,sTitle.c_str() ,(ULONG)dwStyle ,(LONG)0L ,(LONG)0L @@ -3065,7 +2999,7 @@ bool wxWindowOS2::OS2Create( PSZ zClass, { vError = ::WinGetLastError(vHabmain); sError = wxPMErrorToStr(vError); - wxLogError(_T("Error creating frame. Error: %s\n"), sError.c_str()); + wxLogError(wxT("Error creating frame. Error: %s\n"), sError.c_str()); return false; } SetSize( nX @@ -3089,7 +3023,7 @@ bool wxWindowOS2::HandleCreate( WXLPCREATESTRUCT WXUNUSED(vCs), { wxWindowCreateEvent vEvent((wxWindow*)this); - (void)GetEventHandler()->ProcessEvent(vEvent); + (void)HandleWindowEvent(vEvent); *pbMayCreate = true; return true; } // end of wxWindowOS2::HandleCreate @@ -3098,7 +3032,7 @@ bool wxWindowOS2::HandleDestroy() { wxWindowDestroyEvent vEvent((wxWindow*)this); vEvent.SetId(GetId()); - (void)GetEventHandler()->ProcessEvent(vEvent); + (void)HandleWindowEvent(vEvent); // // Delete our drop target if we've got one @@ -3137,7 +3071,7 @@ bool wxWindowOS2::HandleActivate( ,m_windowId ); vEvent.SetEventObject(this); - return GetEventHandler()->ProcessEvent(vEvent); + return HandleWindowEvent(vEvent); } // end of wxWindowOS2::HandleActivate bool wxWindowOS2::HandleSetFocus( WXHWND WXUNUSED(hWnd) ) @@ -3147,7 +3081,7 @@ bool wxWindowOS2::HandleSetFocus( WXHWND WXUNUSED(hWnd) ) // purposes that we got it // wxChildFocusEvent vEventFocus((wxWindow *)this); - (void)GetEventHandler()->ProcessEvent(vEventFocus); + (void)HandleWindowEvent(vEventFocus); #if wxUSE_CARET // @@ -3171,7 +3105,7 @@ bool wxWindowOS2::HandleSetFocus( WXHWND WXUNUSED(hWnd) ) wxFocusEvent vEvent(wxEVT_SET_FOCUS, m_windowId); vEvent.SetEventObject(this); - return GetEventHandler()->ProcessEvent(vEvent); + return HandleWindowEvent(vEvent); } // end of wxWindowOS2::HandleSetFocus bool wxWindowOS2::HandleKillFocus( WXHWND hWnd ) @@ -3218,7 +3152,7 @@ bool wxWindowOS2::HandleKillFocus( WXHWND hWnd ) // wxFindWinFromHandle() may return NULL, it is ok // vEvent.SetWindow(wxFindWinFromHandle(hWnd)); - return GetEventHandler()->ProcessEvent(vEvent); + return HandleWindowEvent(vEvent); } // end of wxWindowOS2::HandleKillFocus // --------------------------------------------------------------------------- @@ -3233,7 +3167,7 @@ bool wxWindowOS2::HandleShow( wxShowEvent vEvent(GetId(), bShow); vEvent.SetEventObject(this); - return GetEventHandler()->ProcessEvent(vEvent); + return HandleWindowEvent(vEvent); } // end of wxWindowOS2::HandleShow bool wxWindowOS2::HandleInitDialog( WXHWND WXUNUSED(hWndFocus) ) @@ -3241,7 +3175,7 @@ bool wxWindowOS2::HandleInitDialog( WXHWND WXUNUSED(hWndFocus) ) wxInitDialogEvent vEvent(GetId()); vEvent.SetEventObject(this); - return GetEventHandler()->ProcessEvent(vEvent); + return HandleWindowEvent(vEvent); } // end of wxWindowOS2::HandleInitDialog bool wxWindowOS2::HandleEndDrag(WXWPARAM WXUNUSED(wParam)) @@ -3268,7 +3202,7 @@ bool wxWindowOS2::OS2OnDrawItem( int vId, WXDRAWITEMSTRUCT* pItemStruct ) { #if wxUSE_OWNER_DRAWN - wxDC vDc; + wxClientDC vDc(this); #if wxUSE_MENUS_NATIVE // @@ -3287,8 +3221,10 @@ bool wxWindowOS2::OS2OnDrawItem( int vId, ,pMeasureStruct->rclItem.xRight - pMeasureStruct->rclItem.xLeft ,pMeasureStruct->rclItem.yTop - pMeasureStruct->rclItem.yBottom ); - vDc.SetHDC( hDC, false ); - vDc.SetHPS( pMeasureStruct->hps ); + + wxPMDCImpl *impl = (wxPMDCImpl*) vDc.GetImpl(); + impl->SetHDC( hDC, false ); + impl->SetHPS( pMeasureStruct->hps ); // // Load the wxWidgets Pallete and set to RGB mode // @@ -3302,7 +3238,7 @@ bool wxWindowOS2::OS2OnDrawItem( int vId, { vError = ::WinGetLastError(vHabmain); sError = wxPMErrorToStr(vError); - wxLogError(_T("Unable to set current color table (1). Error: %s\n"), sError.c_str()); + wxLogError(wxT("Unable to set current color table (1). Error: %s\n"), sError.c_str()); } // // Set the color table to RGB mode @@ -3317,7 +3253,7 @@ bool wxWindowOS2::OS2OnDrawItem( int vId, { vError = ::WinGetLastError(vHabmain); sError = wxPMErrorToStr(vError); - wxLogError(_T("Unable to set current color table (2). Error: %s\n"), sError.c_str()); + wxLogError(wxT("Unable to set current color table (2). Error: %s\n"), sError.c_str()); } wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE ); @@ -3478,7 +3414,7 @@ bool wxWindowOS2::HandleSysColorChange() wxSysColourChangedEvent vEvent; vEvent.SetEventObject(this); - return GetEventHandler()->ProcessEvent(vEvent); + return HandleWindowEvent(vEvent); } // end of wxWindowOS2::HandleSysColorChange bool wxWindowOS2::HandleCtlColor( WXHBRUSH* WXUNUSED(phBrush) ) @@ -3511,7 +3447,7 @@ bool wxWindowOS2::HandlePaletteChanged() vEvent.SetEventObject(this); vEvent.SetChangedWindow(wxFindWinFromHandle(hWndPalChange)); - return GetEventHandler()->ProcessEvent(vEvent); + return HandleWindowEvent(vEvent); } // end of wxWindowOS2::HandlePaletteChanged // @@ -3535,7 +3471,7 @@ void wxWindowOS2::OnSysColourChanged( wxSysColourChangedEvent vEvent; rEvent.SetEventObject(pWin); - pWin->GetEventHandler()->ProcessEvent(vEvent); + pWin->HandleWindowEvent(vEvent); } node = node->GetNext(); } @@ -3549,7 +3485,7 @@ void wxWindow::OnPaint ( wxPaintEvent& rEvent ) { - HDC hDC = (HDC)wxPaintDC::FindDCInCache((wxWindow*) rEvent.GetEventObject()); + HDC hDC = (HDC)wxPaintDCImpl::FindDCInCache((wxWindow*) rEvent.GetEventObject()); if (hDC != 0) { @@ -3620,7 +3556,7 @@ bool wxWindowOS2::HandlePaint() m_updateRegion = wxRegion(hRgn, hPS); vEvent.SetEventObject(this); - bProcessed = GetEventHandler()->ProcessEvent(vEvent); + bProcessed = HandleWindowEvent(vEvent); if (!bProcessed && IsKindOf(CLASSINFO(wxPanel)) && @@ -3734,25 +3670,26 @@ bool wxWindowOS2::HandleEraseBkgnd( WXHDC hDC ) if (vSwp.fl & SWP_MINIMIZE) return true; - wxDC vDC; - - vDC.m_hPS = (HPS)hDC; // this is really a PS - vDC.SetWindow((wxWindow*)this); + wxClientDC vDC(this); + wxPMDCImpl *impl = (wxPMDCImpl*) vDC.GetImpl(); + impl->SetHDC(hDC); + impl->SetHPS((HPS)hDC); // this is really a PS wxEraseEvent vEvent(m_windowId, &vDC); vEvent.SetEventObject(this); - rc = GetEventHandler()->ProcessEvent(vEvent); + rc = HandleWindowEvent(vEvent); - vDC.m_hPS = NULLHANDLE; + impl->SetHPS(NULLHANDLE); return true; } // end of wxWindowOS2::HandleEraseBkgnd void wxWindowOS2::OnEraseBackground(wxEraseEvent& rEvent) { RECTL vRect; - HPS hPS = rEvent.GetDC()->GetHPS(); + wxPMDCImpl *impl = (wxPMDCImpl*) rEvent.GetDC()->GetImpl(); + HPS hPS = impl->GetHPS(); APIRET rc; LONG lColor = m_backgroundColour.GetPixel(); @@ -3769,7 +3706,7 @@ bool wxWindowOS2::HandleMinimize() wxIconizeEvent vEvent(m_windowId); vEvent.SetEventObject(this); - return GetEventHandler()->ProcessEvent(vEvent); + return HandleWindowEvent(vEvent); } // end of wxWindowOS2::HandleMinimize bool wxWindowOS2::HandleMaximize() @@ -3777,7 +3714,7 @@ bool wxWindowOS2::HandleMaximize() wxMaximizeEvent vEvent(m_windowId); vEvent.SetEventObject(this); - return GetEventHandler()->ProcessEvent(vEvent); + return HandleWindowEvent(vEvent); } // end of wxWindowOS2::HandleMaximize bool wxWindowOS2::HandleMove( int nX, int nY ) @@ -3786,7 +3723,7 @@ bool wxWindowOS2::HandleMove( int nX, int nY ) wxMoveEvent vEvent(pt, m_windowId); vEvent.SetEventObject(this); - return GetEventHandler()->ProcessEvent(vEvent); + return HandleWindowEvent(vEvent); } // end of wxWindowOS2::HandleMove bool wxWindowOS2::HandleSize( int nWidth, @@ -3797,7 +3734,7 @@ bool wxWindowOS2::HandleSize( int nWidth, wxSizeEvent vEvent(sz, m_windowId); vEvent.SetEventObject(this); - return GetEventHandler()->ProcessEvent(vEvent); + return HandleWindowEvent(vEvent); } // end of wxWindowOS2::HandleSize bool wxWindowOS2::HandleGetMinMaxInfo( PSWP pSwp ) @@ -3942,7 +3879,7 @@ bool wxWindowOS2::HandleMouseEvent( WXUINT uMsg, ,uFlags ); - bProcessed = GetEventHandler()->ProcessEvent(vEvent); + bProcessed = HandleWindowEvent(vEvent); if (!bProcessed) { HPOINTER hCursor = (HPOINTER)GetCursor().GetHCURSOR(); @@ -3976,7 +3913,7 @@ bool wxWindowOS2::HandleMouseMove( int nX, ,uFlags ); - (void)GetEventHandler()->ProcessEvent(vEvent); + (void)HandleWindowEvent(vEvent); } return HandleMouseEvent( WM_MOUSEMOVE ,nX @@ -4098,7 +4035,7 @@ bool wxWindowOS2::HandleChar( WXWPARAM WXUNUSED(wParam), vEvent.m_controlDown = true; } - return (GetEventHandler()->ProcessEvent(vEvent)); + return (HandleWindowEvent(vEvent)); } bool wxWindowOS2::HandleKeyDown( WXWPARAM wParam, @@ -4122,7 +4059,7 @@ bool wxWindowOS2::HandleKeyDown( WXWPARAM wParam, ,(MPARAM)wParam )); - if (GetEventHandler()->ProcessEvent(vEvent)) + if (HandleWindowEvent(vEvent)) { return true; } @@ -4151,7 +4088,7 @@ bool wxWindowOS2::HandleKeyUp( WXWPARAM wParam, ,(MPARAM)wParam )); - if (GetEventHandler()->ProcessEvent(vEvent)) + if (HandleWindowEvent(vEvent)) return true; } return false; @@ -4217,7 +4154,7 @@ bool wxWindowOS2::OS2OnScroll( int nOrientation, default: return false; } - return GetEventHandler()->ProcessEvent(vEvent); + return HandleWindowEvent(vEvent); } // end of wxWindowOS2::OS2OnScroll //