From 819b30e937d227d1458ecc22b09ef994ebe7e17e Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 19 May 2021 14:47:19 +0200 Subject: tdf#142367 Writer crashes when opening docx regression from commit 5aa60be574ece81b27c8f63e6e809871c694dba0 fix leak in VCLXWindow Make SwAnnotationWin follow the same pattern as all the other code and return a custom accessibility object instead of trying to override the toolkit peer object. Change-Id: Ifa3a5da2fbbf082e6bb05281cc9d354d6ec3ba03 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115805 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sw/inc/AnnotationWin.hxx | 3 +++ sw/source/uibase/docvw/AnnotationWin.cxx | 1 + sw/source/uibase/docvw/AnnotationWin2.cxx | 15 +++++++++------ 3 files changed, 13 insertions(+), 6 deletions(-) (limited to 'sw') diff --git a/sw/inc/AnnotationWin.hxx b/sw/inc/AnnotationWin.hxx index f1ba8a499589..6cf6760aeb2b 100644 --- a/sw/inc/AnnotationWin.hxx +++ b/sw/inc/AnnotationWin.hxx @@ -49,6 +49,7 @@ namespace sw::sidebarwindows { class SidebarTextControl; class AnchorOverlayObject; class ShadowOverlayObject; + class SidebarWinAccessible; } @@ -271,6 +272,8 @@ class SAL_DLLPUBLIC_RTTI SwAnnotationWin : public InterimItemWindow SwFormatField* mpFormatField; SwPostItField* mpField; + + rtl::Reference mxSidebarWinAccessible; }; } // end of namespace sw::annotation diff --git a/sw/source/uibase/docvw/AnnotationWin.cxx b/sw/source/uibase/docvw/AnnotationWin.cxx index 49ea845944b8..e354a62204a8 100644 --- a/sw/source/uibase/docvw/AnnotationWin.cxx +++ b/sw/source/uibase/docvw/AnnotationWin.cxx @@ -62,6 +62,7 @@ #include "AnchorOverlayObject.hxx" #include "OverlayRanges.hxx" #include "SidebarTxtControl.hxx" +#include "SidebarWinAcc.hxx" #include diff --git a/sw/source/uibase/docvw/AnnotationWin2.cxx b/sw/source/uibase/docvw/AnnotationWin2.cxx index f463bf7597f1..b2604377e2e0 100644 --- a/sw/source/uibase/docvw/AnnotationWin2.cxx +++ b/sw/source/uibase/docvw/AnnotationWin2.cxx @@ -1376,8 +1376,8 @@ void SwAnnotationWin::ChangeSidebarItem( SwSidebarItem const & rSidebarItem ) mrSidebarItem = rSidebarItem; mpAnchorFrame = mrSidebarItem.maLayoutInfo.mpAnchorFrame; - if (SidebarWinAccessible* pAcc = dynamic_cast(GetWindowPeer())) - pAcc->ChangeSidebarItem( mrSidebarItem ); + if (mxSidebarWinAccessible) + mxSidebarWinAccessible->ChangeSidebarItem( mrSidebarItem ); if ( bAnchorChanged ) { @@ -1389,11 +1389,14 @@ void SwAnnotationWin::ChangeSidebarItem( SwSidebarItem const & rSidebarItem ) css::uno::Reference< css::accessibility::XAccessible > SwAnnotationWin::CreateAccessible() { - rtl::Reference pAcc( new SidebarWinAccessible( *this, + // This is rather dodgy code. Normally in CreateAccessible, if we want a custom + // object, we return a custom object, but we do no override the default toolkit + // window peer. + if (!mxSidebarWinAccessible) + mxSidebarWinAccessible = new SidebarWinAccessible( *this, mrView.GetWrtShell(), - mrSidebarItem ) ); - SetWindowPeer( pAcc, pAcc.get() ); - return pAcc; + mrSidebarItem ); + return mxSidebarWinAccessible; } } // eof of namespace sw::sidebarwindows -- cgit