diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-09-13 11:29:37 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-09-15 06:08:27 +0200 |
commit | 96bd77de5ad7b7a13f7e48e0f95c05ef49255aa0 (patch) | |
tree | 4c79c57712124a8589c9e6579b6ec7fec9200c3b /sw | |
parent | 3f65724ec5fc92d5a0078a99932358ef7091435c (diff) |
Use <comphelper/servicehelper.hxx> implementing XUnoTunnel part 5
- Revise uses of getSomething to use getFromUnoTunnel
Where that is impossible, use getSomething_cast to unify casting,
and minimize number of places doing low-level transformations.
The change keeps the existing tunnel references that last for the
duration of the pointers' life, because sometimes destroying such
reference may destroy the pointed object, and result in use after
free.
Change-Id: I291c33223582c34cd2c763aa8aacf0ae899ca4c0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122101
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sw')
25 files changed, 89 insertions, 277 deletions
diff --git a/sw/source/core/unocore/unobkm.cxx b/sw/source/core/unocore/unobkm.cxx index bea687b818fc..d7f6d706343a 100644 --- a/sw/source/core/unocore/unobkm.cxx +++ b/sw/source/core/unocore/unobkm.cxx @@ -218,14 +218,9 @@ void SwXBookmark::attachToRangeEx( const uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY); - SwXTextRange* pRange = nullptr; - OTextCursorHelper* pCursor = nullptr; - if(xRangeTunnel.is()) - { - pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel); - pCursor = + SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel); + OTextCursorHelper* pCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xRangeTunnel); - } SwDoc *const pDoc = pRange ? &pRange->GetDoc() : (pCursor ? pCursor->GetDoc() : nullptr); diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx index 1506cb7fb41f..1ed8ec3a5d2e 100644 --- a/sw/source/core/unocore/unodraw.cxx +++ b/sw/source/core/unocore/unodraw.cxx @@ -360,10 +360,7 @@ uno::Reference< drawing::XShape > SwFmDrawPage::CreateShape( SdrObject *pObj ) c } uno::Reference< XUnoTunnel > xShapeTunnel(xRet, uno::UNO_QUERY); //don't create an SwXShape if it already exists - rtl::Reference<SwXShape> pShape; - if(xShapeTunnel.is()) - pShape = reinterpret_cast< SwXShape * >( - sal::static_int_cast< sal_IntPtr >( xShapeTunnel->getSomething(SwXShape::getUnoTunnelId()) )); + rtl::Reference<SwXShape> pShape = comphelper::getFromUnoTunnel<SwXShape>(xShapeTunnel); if(!pShape) { xShapeTunnel = nullptr; @@ -558,15 +555,8 @@ void SwXDrawPage::add(const uno::Reference< drawing::XShape > & xShape) if(!m_pDoc) throw uno::RuntimeException(); uno::Reference< lang::XUnoTunnel > xShapeTunnel(xShape, uno::UNO_QUERY); - SwXShape* pShape = nullptr; - SvxShape* pSvxShape = nullptr; - if(xShapeTunnel.is()) - { - pShape = reinterpret_cast< SwXShape * >( - sal::static_int_cast< sal_IntPtr >( xShapeTunnel->getSomething(SwXShape::getUnoTunnelId()) )); - pSvxShape = reinterpret_cast< SvxShape * >( - sal::static_int_cast< sal_IntPtr >( xShapeTunnel->getSomething(SvxShape::getUnoTunnelId()) )); - } + SwXShape* pShape = comphelper::getFromUnoTunnel<SwXShape>(xShapeTunnel); + SvxShape* pSvxShape = comphelper::getFromUnoTunnel<SvxShape>(xShapeTunnel); // this is not a writer shape if(!pShape) @@ -2022,32 +2012,16 @@ void SwXShape::attach(const uno::Reference< text::XTextRange > & xTextRange) uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY); if(xRangeTunnel.is()) { - SwXTextRange* pRange = nullptr; - OTextCursorHelper* pCursor = nullptr; - SwXTextPortion* pPortion = nullptr; - SwXText* pText = nullptr; - SwXParagraph* pParagraph = nullptr; - - pRange = reinterpret_cast< SwXTextRange * >( - sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXTextRange::getUnoTunnelId()) )); - pText = reinterpret_cast< SwXText * >( - sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXText::getUnoTunnelId()) )); - pCursor = reinterpret_cast< OTextCursorHelper * >( - sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( OTextCursorHelper::getUnoTunnelId()) )); - pPortion = reinterpret_cast< SwXTextPortion * >( - sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXTextPortion::getUnoTunnelId()) )); - pParagraph = reinterpret_cast< SwXParagraph * >( - sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXParagraph::getUnoTunnelId( ) ) ) ); - - if (pRange) + if (auto pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel)) pDoc = &pRange->GetDoc(); - else if (pText) + else if (auto pText = comphelper::getFromUnoTunnel<SwXText>(xRangeTunnel)) pDoc = pText->GetDoc(); - else if (pCursor) + else if (auto pCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xRangeTunnel)) pDoc = pCursor->GetDoc(); - else if (pPortion) + else if (auto pPortion = comphelper::getFromUnoTunnel<SwXTextPortion>(xRangeTunnel)) pDoc = &pPortion->GetCursor().GetDoc(); - else if (pParagraph && pParagraph->GetTextNode()) + else if (auto pParagraph = comphelper::getFromUnoTunnel<SwXParagraph>(xRangeTunnel); + pParagraph && pParagraph->GetTextNode()) pDoc = &pParagraph->GetTextNode()->GetDoc(); } @@ -2743,15 +2717,11 @@ void SwXGroupShape::add( const uno::Reference< XShape >& xShape ) uno::Reference<lang::XUnoTunnel> xTunnel(xShape, uno::UNO_QUERY); - SwXShape* pSwShape = nullptr; - if(xShape.is()) - pSwShape = reinterpret_cast< SwXShape * >( - sal::static_int_cast< sal_IntPtr >( xTunnel->getSomething(SwXShape::getUnoTunnelId()) )); + SwXShape* pSwShape = comphelper::getFromUnoTunnel<SwXShape>(xTunnel); if(!(pSwShape && pSwShape->m_bDescriptor)) return; - SvxShape* pAddShape = reinterpret_cast< SvxShape * >( - sal::static_int_cast< sal_IntPtr >( xTunnel->getSomething(SvxShape::getUnoTunnelId()) )); + SvxShape* pAddShape = comphelper::getFromUnoTunnel<SvxShape>(xTunnel); if(pAddShape) { SdrObject* pObj = pAddShape->GetSdrObject(); diff --git a/sw/source/core/unocore/unofield.cxx b/sw/source/core/unocore/unofield.cxx index 6e3e86f8f651..a68a3b167b85 100644 --- a/sw/source/core/unocore/unofield.cxx +++ b/sw/source/core/unocore/unofield.cxx @@ -1266,10 +1266,7 @@ void SwXTextField::TransmuteLeadToInputField(SwSetExpField & rField) uno::Reference<text::XTextField> const xField( rField.GetFormatField()->GetXTextField()); SwXTextField *const pXField = xField.is() - ? reinterpret_cast<SwXTextField*>( - sal::static_int_cast<sal_IntPtr>( - uno::Reference<lang::XUnoTunnel>(xField, uno::UNO_QUERY_THROW) - ->getSomething(getUnoTunnelId()))) + ? comphelper::getFromUnoTunnel<SwXTextField>(uno::Reference<lang::XUnoTunnel>(xField, uno::UNO_QUERY_THROW)) : nullptr; if (pXField) pXField->m_pImpl->SetFormatField(nullptr, nullptr); @@ -1296,7 +1293,7 @@ void SwXTextField::TransmuteLeadToInputField(SwSetExpField & rField) SwFormatField const& rNewFormat(pNewAttr->GetFormatField()); assert(rNewFormat.Which() == (static_cast<SwSetExpField const*>(rNewFormat.GetField())->GetInputFlag() ? RES_TXTATR_INPUTFIELD : RES_TXTATR_FIELD)); assert(static_cast<SwSetExpField const*>(rNewFormat.GetField())->GetInputFlag() == (dynamic_cast<SwTextInputField const*>(pNewAttr) != nullptr)); - if (xField.is()) + if (pXField) { pXField->m_pImpl->SetFormatField(const_cast<SwFormatField*>(&rNewFormat), &rNode.GetDoc()); const_cast<SwFormatField&>(rNewFormat).SetXTextField(xField); @@ -1313,8 +1310,7 @@ void SAL_CALL SwXTextField::attachTextFieldMaster( uno::Reference< lang::XUnoTunnel > xMasterTunnel(xFieldMaster, uno::UNO_QUERY); if (!xMasterTunnel.is()) throw lang::IllegalArgumentException(); - SwXFieldMaster* pMaster = reinterpret_cast< SwXFieldMaster * >( - sal::static_int_cast< sal_IntPtr >( xMasterTunnel->getSomething( SwXFieldMaster::getUnoTunnelId()) )); + SwXFieldMaster* pMaster = comphelper::getFromUnoTunnel<SwXFieldMaster>(xMasterTunnel); SwFieldType* pFieldType = pMaster ? pMaster->GetFieldType() : nullptr; if (!pFieldType || @@ -1356,15 +1352,8 @@ void SAL_CALL SwXTextField::attach( if (m_pImpl->IsDescriptor()) { uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY); - SwXTextRange* pRange = nullptr; - OTextCursorHelper* pCursor = nullptr; - if(xRangeTunnel.is()) - { - pRange = reinterpret_cast< SwXTextRange * >( - sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXTextRange::getUnoTunnelId()) )); - pCursor = reinterpret_cast< OTextCursorHelper * >( - sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( OTextCursorHelper::getUnoTunnelId()) )); - } + SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel); + OTextCursorHelper* pCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xRangeTunnel); SwDoc* pDoc = pRange ? &pRange->GetDoc() : pCursor ? pCursor->GetDoc() : nullptr; // if a FieldMaster was attached, then the document is already fixed! diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx index a3cb0ff14d6f..02886fbb7b76 100644 --- a/sw/source/core/unocore/unoframe.cxx +++ b/sw/source/core/unocore/unoframe.cxx @@ -2688,15 +2688,8 @@ void SwXFrame::attachToRange(uno::Reference<text::XTextRange> const& xTextRange, if(!IsDescriptor()) throw uno::RuntimeException(); uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY); - SwXTextRange* pRange = nullptr; - OTextCursorHelper* pCursor = nullptr; - if(xRangeTunnel.is()) - { - pRange = reinterpret_cast< SwXTextRange * >( - sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXTextRange::getUnoTunnelId()) )); - pCursor = reinterpret_cast< OTextCursorHelper * >( - sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( OTextCursorHelper::getUnoTunnelId()) )); - } + SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel); + OTextCursorHelper* pCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xRangeTunnel); SwDoc* pDoc = pRange ? &pRange->GetDoc() : pCursor ? pCursor->GetDoc() : nullptr; if(!pDoc) diff --git a/sw/source/core/unocore/unoobj.cxx b/sw/source/core/unocore/unoobj.cxx index f964d386ccd8..86439e0dc3a2 100644 --- a/sw/source/core/unocore/unoobj.cxx +++ b/sw/source/core/unocore/unoobj.cxx @@ -1040,14 +1040,8 @@ SwXTextCursor::gotoRange( SwUnoCursor & rOwnCursor( GetCursorOrThrow() ); uno::Reference<lang::XUnoTunnel> xRangeTunnel( xRange, uno::UNO_QUERY); - SwXTextRange* pRange = nullptr; - OTextCursorHelper* pCursor = nullptr; - if(xRangeTunnel.is()) - { - pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel); - pCursor = - comphelper::getFromUnoTunnel<OTextCursorHelper>(xRangeTunnel); - } + SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel); + OTextCursorHelper* pCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xRangeTunnel); if (!pRange && !pCursor) { diff --git a/sw/source/core/unocore/unoobj2.cxx b/sw/source/core/unocore/unoobj2.cxx index b9bd6dc9cd10..a70dbb5722bd 100644 --- a/sw/source/core/unocore/unoobj2.cxx +++ b/sw/source/core/unocore/unoobj2.cxx @@ -1111,24 +1111,13 @@ bool XTextRangeToSwPaM( SwUnoInternalPaM & rToFill, bool bRet = false; uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY); - SwXTextRange* pRange = nullptr; - OTextCursorHelper* pCursor = nullptr; - SwXTextPortion* pPortion = nullptr; - SwXText* pText = nullptr; - SwXParagraph* pPara = nullptr; - SwXHeadFootText* pHeadText = nullptr; - if(xRangeTunnel.is()) - { - pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel); - pCursor = - comphelper::getFromUnoTunnel<OTextCursorHelper>(xRangeTunnel); - pPortion= - comphelper::getFromUnoTunnel<SwXTextPortion>(xRangeTunnel); - pText = comphelper::getFromUnoTunnel<SwXText>(xRangeTunnel); - pPara = comphelper::getFromUnoTunnel<SwXParagraph>(xRangeTunnel); - if (eMode == TextRangeMode::AllowTableNode) - pHeadText = dynamic_cast<SwXHeadFootText*>(pText); - } + SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel); + OTextCursorHelper* pCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xRangeTunnel); + SwXTextPortion* pPortion = comphelper::getFromUnoTunnel<SwXTextPortion>(xRangeTunnel); + SwXText* pText = comphelper::getFromUnoTunnel<SwXText>(xRangeTunnel); + SwXParagraph* pPara = comphelper::getFromUnoTunnel<SwXParagraph>(xRangeTunnel); + SwXHeadFootText* pHeadText + = eMode == TextRangeMode::AllowTableNode ? dynamic_cast<SwXHeadFootText*>(pText) : nullptr; // if it's a text then create a temporary cursor there and re-use // the pCursor variable diff --git a/sw/source/core/unocore/unorefmk.cxx b/sw/source/core/unocore/unorefmk.cxx index 3b6ec7c0049f..fd656af16a36 100644 --- a/sw/source/core/unocore/unorefmk.cxx +++ b/sw/source/core/unocore/unorefmk.cxx @@ -275,14 +275,8 @@ SwXReferenceMark::attach(const uno::Reference< text::XTextRange > & xTextRange) throw uno::RuntimeException(); } uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY); - SwXTextRange* pRange = nullptr; - OTextCursorHelper* pCursor = nullptr; - if(xRangeTunnel.is()) - { - pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel); - pCursor = - comphelper::getFromUnoTunnel<OTextCursorHelper>(xRangeTunnel); - } + SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel); + OTextCursorHelper* pCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xRangeTunnel); SwDoc *const pDocument = pRange ? &pRange->GetDoc() : (pCursor ? pCursor->GetDoc() : nullptr); if (!pDocument) diff --git a/sw/source/core/unocore/unosect.cxx b/sw/source/core/unocore/unosect.cxx index 599089da5604..a93a90b7e097 100644 --- a/sw/source/core/unocore/unosect.cxx +++ b/sw/source/core/unocore/unosect.cxx @@ -282,14 +282,8 @@ SwXTextSection::attach(const uno::Reference< text::XTextRange > & xTextRange) } uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY); - SwXTextRange* pRange = nullptr; - OTextCursorHelper* pCursor = nullptr; - if(xRangeTunnel.is()) - { - pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel); - pCursor = - comphelper::getFromUnoTunnel<OTextCursorHelper>(xRangeTunnel); - } + SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel); + OTextCursorHelper* pCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xRangeTunnel); SwDoc *const pDoc = pRange ? &pRange->GetDoc() : (pCursor ? pCursor->GetDoc() : nullptr); diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 3182cb2b9ac7..0a93658920a1 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -966,13 +966,7 @@ void XStyleFamily::insertByName(const OUString& rName, const uno::Any& rElement) else { uno::Reference<lang::XUnoTunnel> xStyleTunnel = rElement.get<uno::Reference<lang::XUnoTunnel>>(); - SwXStyle* pNewStyle = nullptr; - if(xStyleTunnel.is()) - { - pNewStyle = reinterpret_cast< SwXStyle * >( - sal::static_int_cast< sal_IntPtr >( xStyleTunnel->getSomething( SwXStyle::getUnoTunnelId()) )); - } - + SwXStyle* pNewStyle = comphelper::getFromUnoTunnel<SwXStyle>(xStyleTunnel); if (!pNewStyle || !pNewStyle->IsDescriptor() || pNewStyle->GetFamily() != m_rEntry.m_eFamily) throw lang::IllegalArgumentException(); @@ -1729,7 +1723,7 @@ void SwXStyle::SetPropertyValue<FN_UNO_NUM_RULES>(const SfxItemPropertyMapEntry& if(!rValue.has<uno::Reference<container::XIndexReplace>>() || !rValue.has<uno::Reference<lang::XUnoTunnel>>()) throw lang::IllegalArgumentException(); auto xNumberTunnel(rValue.get<uno::Reference<lang::XUnoTunnel>>()); - SwXNumberingRules* pSwXRules = reinterpret_cast<SwXNumberingRules*>(sal::static_int_cast<sal_IntPtr>(xNumberTunnel->getSomething(SwXNumberingRules::getUnoTunnelId()))); + SwXNumberingRules* pSwXRules = comphelper::getFromUnoTunnel<SwXNumberingRules>(xNumberTunnel); if(!pSwXRules) return; SwNumRule aSetRule(*pSwXRules->GetNumRule()); diff --git a/sw/source/core/unocore/unotbl.cxx b/sw/source/core/unocore/unotbl.cxx index e746623f6a06..c0048eff38e1 100644 --- a/sw/source/core/unocore/unotbl.cxx +++ b/sw/source/core/unocore/unotbl.cxx @@ -2096,15 +2096,8 @@ SwXTextTable::attach(const uno::Reference<text::XTextRange> & xTextRange) throw uno::RuntimeException("SwXTextTable: already attached to range.", static_cast<cppu::OWeakObject*>(this)); uno::Reference<XUnoTunnel> xRangeTunnel(xTextRange, uno::UNO_QUERY); - SwXTextRange* pRange(nullptr); - OTextCursorHelper* pCursor(nullptr); - if(xRangeTunnel.is()) - { - pRange = reinterpret_cast<SwXTextRange*>( - sal::static_int_cast<sal_IntPtr>(xRangeTunnel->getSomething(SwXTextRange::getUnoTunnelId()))); - pCursor = reinterpret_cast<OTextCursorHelper*>( - sal::static_int_cast<sal_IntPtr>(xRangeTunnel->getSomething(OTextCursorHelper::getUnoTunnelId()))); - } + SwXTextRange* pRange(comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel)); + OTextCursorHelper* pCursor(comphelper::getFromUnoTunnel<OTextCursorHelper>(xRangeTunnel)); SwDoc* pDoc = pRange ? &pRange->GetDoc() : pCursor ? pCursor->GetDoc() : nullptr; if (!pDoc || !m_pImpl->m_nRows || !m_pImpl->m_nColumns) throw lang::IllegalArgumentException(); diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx index 9062b949dd3d..82f9a00e6cde 100644 --- a/sw/source/core/unocore/unotext.cxx +++ b/sw/source/core/unocore/unotext.cxx @@ -2255,9 +2255,7 @@ SwXText::copyText( uno::Reference<lang::XUnoTunnel> const xSourceTunnel(xSource, uno::UNO_QUERY); - SwXText const*const pSource( xSourceTunnel.is() - ? comphelper::getFromUnoTunnel<SwXText>(xSourceTunnel) - : nullptr); + SwXText const* const pSource(comphelper::getFromUnoTunnel<SwXText>(xSourceTunnel)); uno::Reference< text::XText > const xText(xSource, uno::UNO_QUERY_THROW); uno::Reference< text::XTextCursor > const xCursor = diff --git a/sw/source/core/unocore/unotextmarkup.cxx b/sw/source/core/unocore/unotextmarkup.cxx index 7d544d1cbd2e..ae5e05181224 100644 --- a/sw/source/core/unocore/unotextmarkup.cxx +++ b/sw/source/core/unocore/unotextmarkup.cxx @@ -105,16 +105,7 @@ void SAL_CALL SwXTextMarkup::commitTextRangeMarkup(::sal_Int32 nType, const OUSt if(!xRangeTunnel.is()) return; - SwXTextRange* pRange = nullptr; - OTextCursorHelper* pCursor = nullptr; - - if(xRangeTunnel.is()) - { - pRange = reinterpret_cast<SwXTextRange*>( sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething(SwXTextRange::getUnoTunnelId()))); - pCursor = reinterpret_cast<OTextCursorHelper*>( sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething(OTextCursorHelper::getUnoTunnelId()))); - } - - if (pRange) + if (auto pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel)) { SwDoc& rDoc = pRange->GetDoc(); @@ -127,7 +118,7 @@ void SAL_CALL SwXTextMarkup::commitTextRangeMarkup(::sal_Int32 nType, const OUSt commitStringMarkup (nType, aIdentifier, startPos->nContent.GetIndex(), endPos->nContent.GetIndex() - startPos->nContent.GetIndex(), xMarkupInfoContainer); } - else if (pCursor) + else if (auto pCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xRangeTunnel)) { SwPaM & rPam(*pCursor->GetPaM()); diff --git a/sw/source/filter/xml/xmlexp.cxx b/sw/source/filter/xml/xmlexp.cxx index f0255f7833f2..437a1a9c76f6 100644 --- a/sw/source/filter/xml/xmlexp.cxx +++ b/sw/source/filter/xml/xmlexp.cxx @@ -501,8 +501,7 @@ SwDoc* SwXMLExport::getDoc() Reference < XText > xText = xTextDoc->getText(); Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY); assert( xTextTunnel.is()); - SwXText *pText = reinterpret_cast< SwXText *>( - sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() ))); + SwXText* pText = comphelper::getFromUnoTunnel<SwXText>(xTextTunnel); assert( pText != nullptr ); m_pDoc = pText->GetDoc(); assert( m_pDoc != nullptr ); diff --git a/sw/source/filter/xml/xmlimp.cxx b/sw/source/filter/xml/xmlimp.cxx index 6bfdcf0f0698..eea1ca435720 100644 --- a/sw/source/filter/xml/xmlimp.cxx +++ b/sw/source/filter/xml/xmlimp.cxx @@ -374,12 +374,7 @@ sal_Int64 SAL_CALL SwXMLImport::getSomething( const Sequence< sal_Int8 >& rId ) static OTextCursorHelper *lcl_xml_GetSwXTextCursor( const Reference < XTextCursor >& rTextCursor ) { - Reference<XUnoTunnel> xCursorTunnel( rTextCursor, UNO_QUERY ); - OSL_ENSURE( xCursorTunnel.is(), "missing XUnoTunnel for Cursor" ); - if( !xCursorTunnel.is() ) - return nullptr; - OTextCursorHelper *pTextCursor = reinterpret_cast< OTextCursorHelper *>( - sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() ))); + OTextCursorHelper* pTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(rTextCursor); OSL_ENSURE( pTextCursor, "SwXTextCursor missing" ); return pTextCursor; } @@ -648,8 +643,7 @@ void SwXMLImport::endDocument() Reference<XUnoTunnel> xCursorTunnel( GetTextImport()->GetCursor(), UNO_QUERY); assert(xCursorTunnel.is() && "missing XUnoTunnel for Cursor"); - OTextCursorHelper *pTextCursor = reinterpret_cast< OTextCursorHelper *>( - sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() ))); + OTextCursorHelper* pTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xCursorTunnel); assert(pTextCursor && "SwXTextCursor missing"); SwPaM *pPaM = pTextCursor->GetPaM(); if( IsInsertMode() && m_pSttNdIdx->GetIndex() ) @@ -1655,8 +1649,7 @@ SwDoc* SwXMLImport::getDoc() Reference < XText > xText = xTextDoc->getText(); Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY); assert( xTextTunnel.is()); - SwXText *pText = reinterpret_cast< SwXText *>( - sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() ))); + SwXText* pText = comphelper::getFromUnoTunnel<SwXText>(xTextTunnel); assert( pText != nullptr ); m_pDoc = pText->GetDoc(); assert( m_pDoc != nullptr ); diff --git a/sw/source/filter/xml/xmltble.cxx b/sw/source/filter/xml/xmltble.cxx index 4787961efcb4..3a3409cd1b46 100644 --- a/sw/source/filter/xml/xmltble.cxx +++ b/sw/source/filter/xml/xmltble.cxx @@ -1212,14 +1212,8 @@ void SwXMLTextParagraphExport::exportTable( OSL_ENSURE( xTextTable.is(), "text table missing" ); if( xTextTable.is() ) { - SwXTextTable *pXTable = nullptr; Reference<XUnoTunnel> xTableTunnel( rTextContent, UNO_QUERY); - if( xTableTunnel.is() ) - { - pXTable = reinterpret_cast< SwXTextTable * >( - sal::static_int_cast< sal_IntPtr >( xTableTunnel->getSomething( SwXTextTable::getUnoTunnelId() ))); - OSL_ENSURE( pXTable, "SwXTextTable missing" ); - } + SwXTextTable* pXTable = comphelper::getFromUnoTunnel<SwXTextTable>(xTableTunnel); if( pXTable ) { SwFrameFormat *const pFormat = pXTable->GetFrameFormat(); diff --git a/sw/source/filter/xml/xmltbli.cxx b/sw/source/filter/xml/xmltbli.cxx index 439c7df0f631..a071ce35ec67 100644 --- a/sw/source/filter/xml/xmltbli.cxx +++ b/sw/source/filter/xml/xmltbli.cxx @@ -595,8 +595,7 @@ void SwXMLTableCellContext_Impl::endFastElement(sal_Int32 ) // Until we have an API for copying we have to use the core. Reference<XUnoTunnel> xSrcCursorTunnel( xSrcTextCursor, UNO_QUERY); assert(xSrcCursorTunnel.is() && "missing XUnoTunnel for Cursor"); - OTextCursorHelper *pSrcTextCursor = reinterpret_cast< OTextCursorHelper * >( - sal::static_int_cast< sal_IntPtr >( xSrcCursorTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() ))); + OTextCursorHelper *pSrcTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xSrcTextCursor); assert(pSrcTextCursor && "SwXTextCursor missing"); SwDoc *pDoc = pSrcTextCursor->GetDoc(); const SwPaM *pSrcPaM = pSrcTextCursor->GetPaM(); @@ -608,8 +607,7 @@ void SwXMLTableCellContext_Impl::endFastElement(sal_Int32 ) Reference<XUnoTunnel> xDstCursorTunnel( GetImport().GetTextImport()->GetCursor(), UNO_QUERY); assert(xDstCursorTunnel.is() && "missing XUnoTunnel for Cursor"); - OTextCursorHelper *pDstTextCursor = reinterpret_cast< OTextCursorHelper * >( - sal::static_int_cast< sal_IntPtr >( xDstCursorTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )) ); + OTextCursorHelper *pDstTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(GetImport().GetTextImport()->GetCursor()); assert(pDstTextCursor && "SwXTextCursor missing"); SwPaM aSrcPaM(*pSrcPaM->GetMark(), *pSrcPaM->GetPoint()); SwPosition aDstPos( *pDstTextCursor->GetPaM()->GetPoint() ); @@ -1220,13 +1218,7 @@ SwXMLTableContext::SwXMLTableContext( SwXMLImport& rImport, // xml:id for RDF metadata GetImport().SetXmlId(xTable, sXmlId); - Reference<XUnoTunnel> xTableTunnel( xTable, UNO_QUERY); - if( xTableTunnel.is() ) - { - pXTable = reinterpret_cast< SwXTextTable * >( - sal::static_int_cast< sal_IntPtr >( xTableTunnel->getSomething( SwXTextTable::getUnoTunnelId() ))); - OSL_ENSURE( pXTable, "SwXTextTable missing" ); - } + pXTable = comphelper::getFromUnoTunnel<SwXTextTable>(xTable); Reference < XCellRange > xCellRange( xTable, UNO_QUERY ); Reference < XCell > xCell = xCellRange->getCellByPosition( 0, 0 ); @@ -2698,8 +2690,7 @@ const SwStartNode *SwXMLTableContext::InsertTableSection( Reference<XUnoTunnel> xCursorTunnel( GetImport().GetTextImport()->GetCursor(), UNO_QUERY); OSL_ENSURE( xCursorTunnel.is(), "missing XUnoTunnel for Cursor" ); - OTextCursorHelper *pTextCursor = reinterpret_cast< OTextCursorHelper * >( - sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() ))); + OTextCursorHelper *pTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xCursorTunnel); OSL_ENSURE( pTextCursor, "SwXTextCursor missing" ); if( m_bFirstSection ) diff --git a/sw/source/filter/xml/xmltexte.cxx b/sw/source/filter/xml/xmltexte.cxx index 0210db520e6d..e5b8dc181aef 100644 --- a/sw/source/filter/xml/xmltexte.cxx +++ b/sw/source/filter/xml/xmltexte.cxx @@ -72,8 +72,7 @@ SwNoTextNode *SwXMLTextParagraphExport::GetNoTextNode( { Reference<XUnoTunnel> xCursorTunnel( rPropSet, UNO_QUERY ); assert(xCursorTunnel.is() && "missing XUnoTunnel for embedded"); - SwXFrame *pFrame = reinterpret_cast< SwXFrame * >( - sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( SwXFrame::getUnoTunnelId() ))); + SwXFrame* pFrame = comphelper::getFromUnoTunnel<SwXFrame>(xCursorTunnel); assert(pFrame && "SwXFrame missing"); SwFrameFormat *pFrameFormat = pFrame->GetFrameFormat(); const SwFormatContent& rContent = pFrameFormat->GetContent(); diff --git a/sw/source/filter/xml/xmltexti.cxx b/sw/source/filter/xml/xmltexti.cxx index 0c10b3ba9eb0..f73ef35be731 100644 --- a/sw/source/filter/xml/xmltexti.cxx +++ b/sw/source/filter/xml/xmltexti.cxx @@ -191,8 +191,7 @@ bool SwXMLTextImportHelper::IsInHeaderFooter() const uno::Reference<XUnoTunnel> xCursorTunnel( const_cast<SwXMLTextImportHelper *>(this)->GetCursor(), UNO_QUERY ); assert(xCursorTunnel.is() && "missing XUnoTunnel for Cursor"); - OTextCursorHelper *pTextCursor = reinterpret_cast< OTextCursorHelper * >( - sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() ))); + OTextCursorHelper* pTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xCursorTunnel); SAL_WARN_IF(!pTextCursor, "sw.uno", "SwXTextCursor missing"); SwDoc *pDoc = pTextCursor ? pTextCursor->GetDoc() : nullptr; @@ -235,8 +234,7 @@ uno::Reference< XPropertySet > SwXMLTextImportHelper::createAndInsertOLEObject( uno::Reference<XUnoTunnel> xCursorTunnel( GetCursor(), UNO_QUERY ); assert(xCursorTunnel.is() && "missing XUnoTunnel for Cursor"); - OTextCursorHelper *pTextCursor = reinterpret_cast< OTextCursorHelper * >( - sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() ))); + OTextCursorHelper* pTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xCursorTunnel); SAL_WARN_IF(!pTextCursor, "sw.uno", "SwXTextCursor missing"); SwDoc *pDoc = SwImport::GetDocFromXMLImport( rImport ); @@ -547,8 +545,7 @@ uno::Reference< XPropertySet > SwXMLTextImportHelper::createAndInsertOOoLink( uno::Reference<XUnoTunnel> xCursorTunnel( GetCursor(), UNO_QUERY ); assert(xCursorTunnel.is() && "missing XUnoTunnel for Cursor"); - OTextCursorHelper *pTextCursor = reinterpret_cast< OTextCursorHelper * >( - sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() ))); + OTextCursorHelper* pTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xCursorTunnel); OSL_ENSURE( pTextCursor, "SwXTextCursor missing" ); SwDoc *pDoc = SwImport::GetDocFromXMLImport( rImport ); @@ -639,8 +636,7 @@ uno::Reference< XPropertySet > SwXMLTextImportHelper::createAndInsertApplet( uno::Reference < XPropertySet > xPropSet; uno::Reference<XUnoTunnel> xCursorTunnel( GetCursor(), UNO_QUERY ); assert(xCursorTunnel.is() && "missing XUnoTunnel for Cursor"); - OTextCursorHelper *pTextCursor = reinterpret_cast< OTextCursorHelper * >( - sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() ))); + OTextCursorHelper* pTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xCursorTunnel); OSL_ENSURE( pTextCursor, "SwXTextCursor missing" ); SwDoc *pDoc = pTextCursor->GetDoc(); @@ -685,8 +681,7 @@ uno::Reference< XPropertySet > SwXMLTextImportHelper::createAndInsertPlugin( uno::Reference < XPropertySet > xPropSet; uno::Reference<XUnoTunnel> xCursorTunnel( GetCursor(), UNO_QUERY ); assert(xCursorTunnel.is() && "missing XUnoTunnel for Cursor"); - OTextCursorHelper *pTextCursor = reinterpret_cast< OTextCursorHelper * >( - sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() ))); + OTextCursorHelper* pTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xCursorTunnel); OSL_ENSURE( pTextCursor, "SwXTextCursor missing" ); SwDoc *pDoc = pTextCursor->GetDoc(); @@ -766,8 +761,7 @@ uno::Reference< XPropertySet > SwXMLTextImportHelper::createAndInsertFloatingFra uno::Reference < XPropertySet > xPropSet; uno::Reference<XUnoTunnel> xCursorTunnel( GetCursor(), UNO_QUERY ); assert(xCursorTunnel.is() && "missing XUnoTunnel for Cursor"); - OTextCursorHelper *pTextCursor = reinterpret_cast< OTextCursorHelper * >( - sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() ))); + OTextCursorHelper* pTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xCursorTunnel); OSL_ENSURE( pTextCursor, "SwXTextCursor missing" ); SwDoc *pDoc = pTextCursor->GetDoc(); @@ -916,8 +910,7 @@ void SwXMLTextImportHelper::endAppletOrPlugin( uno::Reference<XUnoTunnel> xCursorTunnel( rPropSet, UNO_QUERY ); assert(xCursorTunnel.is() && "missing XUnoTunnel for embedded"); - SwXFrame *pFrame = reinterpret_cast< SwXFrame * >( - sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( SwXFrame::getUnoTunnelId() ))); + SwXFrame* pFrame = comphelper::getFromUnoTunnel<SwXFrame>(xCursorTunnel); OSL_ENSURE( pFrame, "SwXFrame missing" ); SwFrameFormat *pFrameFormat = pFrame->GetFrameFormat(); const SwFormatContent& rContent = pFrameFormat->GetContent(); diff --git a/sw/source/ui/vba/vbatablehelper.cxx b/sw/source/ui/vba/vbatablehelper.cxx index e3627af148e0..c6b031d1b4be 100644 --- a/sw/source/ui/vba/vbatablehelper.cxx +++ b/sw/source/ui/vba/vbatablehelper.cxx @@ -35,7 +35,7 @@ SwVbaTableHelper::SwVbaTableHelper( const uno::Reference< text::XTextTable >& xT SwTable* SwVbaTableHelper::GetSwTable( const uno::Reference< text::XTextTable >& xTextTable ) { uno::Reference< lang::XUnoTunnel > xTunnel( xTextTable, uno::UNO_QUERY_THROW ); - SwXTextTable* pXTextTable = reinterpret_cast< SwXTextTable * >( sal::static_int_cast< sal_IntPtr >(xTunnel->getSomething(SwXTextTable::getUnoTunnelId()))); + SwXTextTable* pXTextTable = comphelper::getFromUnoTunnel<SwXTextTable>(xTunnel); if( !pXTextTable ) throw uno::RuntimeException(); diff --git a/sw/source/ui/vba/wordvbahelper.cxx b/sw/source/ui/vba/wordvbahelper.cxx index 6587502073e3..1468fd160e2f 100644 --- a/sw/source/ui/vba/wordvbahelper.cxx +++ b/sw/source/ui/vba/wordvbahelper.cxx @@ -41,7 +41,7 @@ namespace ooo::vba::word SwDocShell* getDocShell( const uno::Reference< frame::XModel>& xModel ) { uno::Reference< lang::XUnoTunnel > xTunnel( xModel, uno::UNO_QUERY_THROW ); - SwXTextDocument* pXDoc = reinterpret_cast< SwXTextDocument * >( sal::static_int_cast< sal_IntPtr >(xTunnel->getSomething(SwXTextDocument::getUnoTunnelId()))); + SwXTextDocument* pXDoc = comphelper::getFromUnoTunnel<SwXTextDocument>(xTunnel); return pXDoc ? pXDoc->GetDocShell() : nullptr; } diff --git a/sw/source/uibase/misc/glosdoc.cxx b/sw/source/uibase/misc/glosdoc.cxx index d5cafd27703b..d147505edbdd 100644 --- a/sw/source/uibase/misc/glosdoc.cxx +++ b/sw/source/uibase/misc/glosdoc.cxx @@ -593,7 +593,7 @@ Reference< text::XAutoTextEntry > SwGlossaries::GetAutoTextEntry( SwXAutoTextEntry* pEntry = nullptr; if ( xEntryTunnel.is() ) - pEntry = reinterpret_cast< SwXAutoTextEntry* >( xEntryTunnel->getSomething( SwXAutoTextEntry::getUnoTunnelId() ) ); + pEntry = comphelper::getFromUnoTunnel<SwXAutoTextEntry>(xEntryTunnel); else { // the object is dead in the meantime -> remove from cache diff --git a/sw/source/uibase/uno/unoatxt.cxx b/sw/source/uibase/uno/unoatxt.cxx index f93592628c1e..28a12c6a67c1 100644 --- a/sw/source/uibase/uno/unoatxt.cxx +++ b/sw/source/uibase/uno/unoatxt.cxx @@ -329,15 +329,8 @@ uno::Reference< text::XAutoTextEntry > SwXAutoTextGroup::insertNewByName(const if (pGlosGroup && !pGlosGroup->GetError()) { uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY); - SwXTextRange* pxRange = nullptr; - OTextCursorHelper* pxCursor = nullptr; - if(xRangeTunnel.is()) - { - pxRange = reinterpret_cast<SwXTextRange*>(xRangeTunnel->getSomething( - SwXTextRange::getUnoTunnelId())); - pxCursor = reinterpret_cast<OTextCursorHelper*>(xRangeTunnel->getSomething( - OTextCursorHelper::getUnoTunnelId())); - } + SwXTextRange* pxRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel); + OTextCursorHelper* pxCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xRangeTunnel); OUString sOnlyText; OUString* pOnlyText = nullptr; @@ -855,20 +848,12 @@ void SwXAutoTextEntry::applyTo(const uno::Reference< text::XTextRange > & xTextR // This means that we would reflect any changes which were done to the AutoText by foreign instances // in the meantime + // The reference to the tunnel is needed during the whole call, likely because it could be a + // different object, not xTextRange itself, and the reference guards it from preliminary death uno::Reference<lang::XUnoTunnel> xTunnel( xTextRange, uno::UNO_QUERY); - SwXTextRange* pRange = nullptr; - OTextCursorHelper* pCursor = nullptr; - SwXText *pText = nullptr; - - if(xTunnel.is()) - { - pRange = reinterpret_cast < SwXTextRange* > - ( xTunnel->getSomething( SwXTextRange::getUnoTunnelId() ) ); - pCursor = reinterpret_cast < OTextCursorHelper*> - ( xTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() ) ); - pText = reinterpret_cast < SwXText* > - ( xTunnel->getSomething( SwXText::getUnoTunnelId() ) ); - } + SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xTunnel); + OTextCursorHelper* pCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xTunnel); + SwXText *pText = comphelper::getFromUnoTunnel<SwXText>(xTunnel); SwDoc* pDoc = nullptr; if (pRange) @@ -878,13 +863,9 @@ void SwXAutoTextEntry::applyTo(const uno::Reference< text::XTextRange > & xTextR else if ( pText && pText->GetDoc() ) { xTunnel.set(pText->getStart(), uno::UNO_QUERY); - if (xTunnel.is()) - { - pCursor = reinterpret_cast < OTextCursorHelper* > - ( xTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() ) ); - if (pCursor) - pDoc = pText->GetDoc(); - } + pCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xTunnel); + if (pCursor) + pDoc = pText->GetDoc(); } if(!pDoc) diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index 403b7d33e3b2..23c337284c01 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -433,14 +433,10 @@ void SwXTextDocument::GetNumberFormatter() { const uno::Type& rTunnelType = cppu::UnoType<XUnoTunnel>::get(); Any aNumTunnel = m_xNumFormatAgg->queryAggregation(rTunnelType); - SvNumberFormatsSupplierObj* pNumFormat = nullptr; Reference< XUnoTunnel > xNumTunnel; - if(aNumTunnel >>= xNumTunnel) - { - pNumFormat = reinterpret_cast<SvNumberFormatsSupplierObj*>( - xNumTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId())); - - } + aNumTunnel >>= xNumTunnel; + SvNumberFormatsSupplierObj* pNumFormat + = comphelper::getFromUnoTunnel<SvNumberFormatsSupplierObj>(xNumTunnel); OSL_ENSURE(pNumFormat, "No number formatter available"); if (pNumFormat && !pNumFormat->GetNumberFormatter()) pNumFormat->SetNumberFormatter(m_pDocShell->GetDoc()->GetNumberFormatter()); @@ -687,15 +683,12 @@ sal_Int32 SwXTextDocument::replaceAll(const Reference< util::XSearchDescriptor > { SolarMutexGuard aGuard; Reference< XUnoTunnel > xDescTunnel(xDesc, UNO_QUERY_THROW); - if(!IsValid() || !xDescTunnel->getSomething(SwXTextSearch::getUnoTunnelId())) + SwXTextSearch* pSearch; + if (!IsValid() || !(pSearch = comphelper::getFromUnoTunnel<SwXTextSearch>(xDescTunnel))) throw DisposedException("", static_cast< XTextDocument* >(this)); Reference< XTextCursor > xCursor; auto pUnoCursor(CreateCursorForSearch(xCursor)); - - const SwXTextSearch* pSearch = reinterpret_cast<const SwXTextSearch*>( - xDescTunnel->getSomething(SwXTextSearch::getUnoTunnelId())); - int eRanges(FindRanges::InBody|FindRanges::InSelAll); i18nutil::SearchOptions2 aSearchOpt; @@ -778,12 +771,7 @@ SwUnoCursor* SwXTextDocument::FindAny(const Reference< util::XSearchDescriptor > if(xLastResult.is()) { Reference<XUnoTunnel> xCursorTunnel( xLastResult, UNO_QUERY); - OTextCursorHelper* pPosCursor = nullptr; - if(xCursorTunnel.is()) - { - pPosCursor = reinterpret_cast<OTextCursorHelper*>(xCursorTunnel->getSomething( - OTextCursorHelper::getUnoTunnelId())); - } + OTextCursorHelper* pPosCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xCursorTunnel); SwPaM* pCursor = pPosCursor ? pPosCursor->GetPaM() : nullptr; if(pCursor) { @@ -792,12 +780,7 @@ SwUnoCursor* SwXTextDocument::FindAny(const Reference< util::XSearchDescriptor > } else { - SwXTextRange* pRange = nullptr; - if(xCursorTunnel.is()) - { - pRange = reinterpret_cast<SwXTextRange*>(xCursorTunnel->getSomething( - SwXTextRange::getUnoTunnelId())); - } + SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xCursorTunnel); if(!pRange) return nullptr; pRange->GetPositions(*pUnoCursor); @@ -1388,14 +1371,13 @@ void SwXTextDocument::Invalidate() { const uno::Type& rTunnelType = cppu::UnoType<XUnoTunnel>::get(); Any aNumTunnel = m_xNumFormatAgg->queryAggregation(rTunnelType); - SvNumberFormatsSupplierObj* pNumFormat = nullptr; Reference< XUnoTunnel > xNumTunnel; - if(aNumTunnel >>= xNumTunnel) - { - pNumFormat = reinterpret_cast<SvNumberFormatsSupplierObj*>( - xNumTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId())); + aNumTunnel >>= xNumTunnel; + SvNumberFormatsSupplierObj* pNumFormat + = comphelper::getFromUnoTunnel<SvNumberFormatsSupplierObj>(xNumTunnel); + OSL_ENSURE(pNumFormat, "No number formatter available"); + if (pNumFormat) pNumFormat->SetNumberFormatter(nullptr); - } OSL_ENSURE(pNumFormat, "No number formatter available"); } InitNewDoc(); @@ -1449,14 +1431,10 @@ void SwXTextDocument::InitNewDoc() { const uno::Type& rTunnelType = cppu::UnoType<XUnoTunnel>::get(); Any aNumTunnel = m_xNumFormatAgg->queryAggregation(rTunnelType); - SvNumberFormatsSupplierObj* pNumFormat = nullptr; Reference< XUnoTunnel > xNumTunnel; - if(aNumTunnel >>= xNumTunnel) - { - pNumFormat = reinterpret_cast<SvNumberFormatsSupplierObj*>( - xNumTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId())); - - } + aNumTunnel >>= xNumTunnel; + SvNumberFormatsSupplierObj* pNumFormat + = comphelper::getFromUnoTunnel<SvNumberFormatsSupplierObj>(xNumTunnel); OSL_ENSURE(pNumFormat, "No number formatter available"); if (pNumFormat) pNumFormat->SetNumberFormatter(nullptr); diff --git a/sw/source/uibase/uno/unotxvw.cxx b/sw/source/uibase/uno/unotxvw.cxx index dc24b31c55fd..fc6891adc277 100644 --- a/sw/source/uibase/uno/unotxvw.cxx +++ b/sw/source/uibase/uno/unotxvw.cxx @@ -1069,18 +1069,9 @@ void SwXTextViewCursor::gotoRange( } uno::Reference<lang::XUnoTunnel> xRangeTunnel( xRange, uno::UNO_QUERY); - SwXTextRange* pRange = nullptr; - SwXParagraph* pPara = nullptr; - OTextCursorHelper* pCursor = nullptr; - if(xRangeTunnel.is()) - { - pRange = reinterpret_cast<SwXTextRange*>(xRangeTunnel->getSomething( - SwXTextRange::getUnoTunnelId())); - pCursor = reinterpret_cast<OTextCursorHelper*>(xRangeTunnel->getSomething( - OTextCursorHelper::getUnoTunnelId())); - pPara = reinterpret_cast<SwXParagraph*>(xRangeTunnel->getSomething( - SwXParagraph::getUnoTunnelId())); - } + SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel); + SwXParagraph* pPara = comphelper::getFromUnoTunnel<SwXParagraph>(xRangeTunnel); + OTextCursorHelper* pCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xRangeTunnel); const FrameTypeFlags nFrameType = rSh.GetFrameType(nullptr,true); diff --git a/sw/source/uibase/utlui/unotools.cxx b/sw/source/uibase/utlui/unotools.cxx index 492934146674..73edc7e540f1 100644 --- a/sw/source/uibase/utlui/unotools.cxx +++ b/sw/source/uibase/utlui/unotools.cxx @@ -431,8 +431,7 @@ void SwOneExampleFrame::ClearDocument() if( !xTunnel.is() ) return; - OTextCursorHelper* pCursor = reinterpret_cast<OTextCursorHelper*>(xTunnel->getSomething( - OTextCursorHelper::getUnoTunnelId()) ); + OTextCursorHelper* pCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xTunnel); if( pCursor ) { SwDoc* pDoc = pCursor->GetDoc(); |