diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2024-07-08 10:36:04 +0500 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2024-07-09 05:46:19 +0200 |
commit | 493b8ab997d543cb133d3896559f4a733186d659 (patch) | |
tree | 6373eb49ef38667ffc17ea9a6889a97fcae87b5e | |
parent | 6a54d08e6e52623f9769d17d7ea7390052cb275b (diff) |
Simplify comphelper::query_aggregation
Change-Id: Id673c27e21c6706367f2effc92bbea61c83a5482
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170133
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r-- | dbaccess/source/core/api/RowSet.cxx | 18 | ||||
-rw-r--r-- | forms/source/component/Button.cxx | 12 | ||||
-rw-r--r-- | forms/source/component/Columns.cxx | 18 | ||||
-rw-r--r-- | forms/source/component/DatabaseForm.cxx | 47 | ||||
-rw-r--r-- | forms/source/component/Edit.cxx | 3 | ||||
-rw-r--r-- | forms/source/component/FormComponent.cxx | 34 | ||||
-rw-r--r-- | forms/source/component/FormattedField.cxx | 5 | ||||
-rw-r--r-- | forms/source/component/FormattedFieldWrapper.cxx | 9 | ||||
-rw-r--r-- | forms/source/component/ImageButton.cxx | 4 | ||||
-rw-r--r-- | forms/source/component/ImageControl.cxx | 4 | ||||
-rw-r--r-- | forms/source/component/ListBox.cxx | 3 | ||||
-rw-r--r-- | forms/source/component/cloneable.cxx | 3 | ||||
-rw-r--r-- | forms/source/richtext/richtextmodel.cxx | 3 | ||||
-rw-r--r-- | include/comphelper/uno3.hxx | 13 | ||||
-rw-r--r-- | reportdesign/source/core/api/ReportDefinition.cxx | 12 | ||||
-rw-r--r-- | reportdesign/source/core/inc/Tools.hxx | 8 | ||||
-rw-r--r-- | toolkit/source/controls/geometrycontrolmodel.cxx | 3 |
17 files changed, 68 insertions, 131 deletions
diff --git a/dbaccess/source/core/api/RowSet.cxx b/dbaccess/source/core/api/RowSet.cxx index 609ebc36ce95..46c4984f7439 100644 --- a/dbaccess/source/core/api/RowSet.cxx +++ b/dbaccess/source/core/api/RowSet.cxx @@ -461,11 +461,7 @@ void SAL_CALL ORowSet::disposing() // remove myself as dispose listener Reference< XComponent > xComponent(m_xActiveConnection, UNO_QUERY); if (xComponent.is()) - { - Reference<XEventListener> xEvt; - query_aggregation(this,xEvt); - xComponent->removeEventListener(xEvt); - } + xComponent->removeEventListener(query_aggregation<XEventListener>(this)); m_aActiveConnection = Any(); // the any contains a reference too if(m_bOwnConnection) @@ -546,11 +542,7 @@ void ORowSet::setActiveConnection( Reference< XConnection > const & _rxNewConn, // remove the event listener for the old connection Reference< XComponent > xComponent(m_xActiveConnection, UNO_QUERY); if (xComponent.is()) - { - Reference<XEventListener> xListener; - query_aggregation(this, xListener); - xComponent->removeEventListener(xListener); - } + xComponent->removeEventListener(query_aggregation<XEventListener>(this)); // if we owned the connection, remember it for later disposing if(m_bOwnConnection) @@ -575,11 +567,7 @@ void ORowSet::setActiveConnection( Reference< XConnection > const & _rxNewConn, // register as event listener for the new connection xComponent.set(m_xActiveConnection,UNO_QUERY); if (xComponent.is()) - { - Reference<XEventListener> xListener; - query_aggregation(this, xListener); - xComponent->addEventListener(xListener); - } + xComponent->addEventListener(query_aggregation<XEventListener>(this)); } // css::XEventListener diff --git a/forms/source/component/Button.cxx b/forms/source/component/Button.cxx index 58a6627119ed..652978d3c715 100644 --- a/forms/source/component/Button.cxx +++ b/forms/source/component/Button.cxx @@ -373,9 +373,7 @@ OButtonControl::OButtonControl(const Reference<XComponentContext>& _rxFactory) osl_atomic_increment(&m_refCount); { // Register as ActionListener - Reference<XButton> xButton; - query_aggregation( m_xAggregate, xButton); - if (xButton.is()) + if (auto xButton = query_aggregation<XButton>(m_xAggregate)) xButton->addActionListener(this); } // For Listener: refcount at one @@ -517,9 +515,7 @@ void OButtonControl::actionPerformed_Impl( bool _bNotifyListener, const css::awt void OButtonControl::setLabel(const OUString& Label) { - Reference<XButton> xButton; - query_aggregation( m_xAggregate, xButton ); - if (xButton.is()) + if (auto xButton = query_aggregation<XButton>(m_xAggregate)) xButton->setLabel(Label); } @@ -531,9 +527,7 @@ void SAL_CALL OButtonControl::setActionCommand(const OUString& _rCommand) m_aActionCommand = _rCommand; } - Reference<XButton> xButton; - query_aggregation( m_xAggregate, xButton); - if (xButton.is()) + if (auto xButton = query_aggregation<XButton>(m_xAggregate)) xButton->setActionCommand(_rCommand); } diff --git a/forms/source/component/Columns.cxx b/forms/source/component/Columns.cxx index 1ba457d567a7..f628f30891e1 100644 --- a/forms/source/component/Columns.cxx +++ b/forms/source/component/Columns.cxx @@ -124,8 +124,7 @@ sal_Int64 SAL_CALL OGridColumn::getSomething( const Sequence<sal_Int8>& _rIdenti } else { - Reference< XUnoTunnel > xAggTunnel; - if ( query_aggregation( m_xAggregate, xAggTunnel ) ) + if (auto xAggTunnel = query_aggregation<XUnoTunnel>(m_xAggregate)) return xAggTunnel->getSomething( _rIdentifier ); } return nReturn; @@ -150,8 +149,7 @@ Sequence<Type> SAL_CALL OGridColumn::getTypes() // but re-add their base class(es) aTypes.addType( cppu::UnoType<XChild>::get() ); - Reference< XTypeProvider > xProv; - if ( query_aggregation( m_xAggregate, xProv )) + if (auto xProv = query_aggregation<XTypeProvider>(m_xAggregate)) aTypes.addTypes( xProv->getTypes() ); aTypes.removeType( cppu::UnoType<XTextRange>::get() ); @@ -264,8 +262,7 @@ void SAL_CALL OGridColumn::disposing(const EventObject& _rSource) { OPropertySetAggregationHelper::disposing(_rSource); - Reference<XEventListener> xEvtLstner; - if (query_aggregation(m_xAggregate, xEvtLstner)) + if (auto xEvtLstner = query_aggregation<XEventListener>(m_xAggregate)) xEvtLstner->disposing(_rSource); } @@ -276,8 +273,7 @@ void OGridColumn::disposing() OGridColumn_BASE::disposing(); OPropertySetAggregationHelper::disposing(); - Reference<XComponent> xComp; - if (query_aggregation(m_xAggregate, xComp)) + if (auto xComp = query_aggregation<XComponent>(m_xAggregate)) xComp->dispose(); } @@ -467,8 +463,7 @@ void OGridColumn::write(const Reference<XObjectOutputStream>& _rxOutStream) sal_Int32 nLen = 0; _rxOutStream->writeLong(nLen); - Reference<XPersistObject> xPersist; - if (query_aggregation(m_xAggregate, xPersist)) + if (auto xPersist = query_aggregation<XPersistObject>(m_xAggregate)) xPersist->write(_rxOutStream); // Calculate the length @@ -514,8 +509,7 @@ void OGridColumn::read(const Reference<XObjectInputStream>& _rxInStream) { Reference<XMarkableStream> xMark(_rxInStream, UNO_QUERY); sal_Int32 nMark = xMark->createMark(); - Reference<XPersistObject> xPersist; - if (query_aggregation(m_xAggregate, xPersist)) + if (auto xPersist = query_aggregation<XPersistObject>(m_xAggregate)) xPersist->read(_rxInStream); xMark->jumpToMark(nMark); diff --git a/forms/source/component/DatabaseForm.cxx b/forms/source/component/DatabaseForm.cxx index 868b6bd19f11..14ee051073a8 100644 --- a/forms/source/component/DatabaseForm.cxx +++ b/forms/source/component/DatabaseForm.cxx @@ -176,8 +176,7 @@ Sequence<Type> SAL_CALL ODatabaseForm::getTypes() { // ask the aggregate Sequence<Type> aAggregateTypes; - Reference<XTypeProvider> xAggregateTypes; - if (query_aggregation(m_xAggregate, xAggregateTypes)) + if (auto xAggregateTypes = query_aggregation<XTypeProvider>(m_xAggregate)) aAggregateTypes = xAggregateTypes->getTypes(); Sequence< Type > aRet = concatSequences( @@ -1181,8 +1180,7 @@ bool ODatabaseForm::executeRowSet(::osl::ResettableMutexGuard& _rClearForNotifie // move on the insert row of set // resetting must be done later, after the load events have been posted // see: moveToInsertRow and load , reload - Reference<XResultSetUpdate> xUpdate; - if (query_aggregation( m_xAggregate, xUpdate)) + if (auto xUpdate = query_aggregation<XResultSetUpdate>(m_xAggregate)) xUpdate->moveToInsertRow(); } } @@ -1234,8 +1232,7 @@ void ODatabaseForm::disposing() m_xAggregateAsRowSet->removeRowSetListener(this); // dispose the active connection - Reference<XComponent> xAggregationComponent; - if (query_aggregation(m_xAggregate, xAggregationComponent)) + if (auto xAggregationComponent = query_aggregation<XComponent>(m_xAggregate)) xAggregationComponent->dispose(); m_aPropertyBagHelper.dispose(); @@ -2510,8 +2507,7 @@ void SAL_CALL ODatabaseForm::disposing(const EventObject& Source) // does the disposing come from the aggregate ? if (m_xAggregate.is()) { // no -> forward it - css::uno::Reference<css::lang::XEventListener> xListener; - if (query_aggregation(m_xAggregate, xListener)) + if (auto xListener = query_aggregation<css::lang::XEventListener>(m_xAggregate)) xListener->disposing(Source); } } @@ -2879,9 +2875,7 @@ void SAL_CALL ODatabaseForm::unload() try { // close the aggregate - Reference<XCloseable> xCloseable; - query_aggregation( m_xAggregate, xCloseable); - if (xCloseable.is()) + if (auto xCloseable = query_aggregation<XCloseable>(m_xAggregate)) xCloseable->close(); } catch(const SQLException&) @@ -3175,8 +3169,7 @@ void SAL_CALL ODatabaseForm::addRowSetApproveListener(const Reference<XRowSetApp // do we have to multiplex ? if (m_aRowSetApproveListeners.getLength() == 1) { - Reference<XRowSetApproveBroadcaster> xBroadcaster; - if (query_aggregation( m_xAggregate, xBroadcaster)) + if (auto xBroadcaster = query_aggregation<XRowSetApproveBroadcaster>(m_xAggregate)) { Reference<XRowSetApproveListener> xListener(static_cast<XRowSetApproveListener*>(this)); xBroadcaster->addRowSetApproveListener(xListener); @@ -3192,8 +3185,7 @@ void SAL_CALL ODatabaseForm::removeRowSetApproveListener(const Reference<XRowSet m_aRowSetApproveListeners.removeInterface(_rListener); if ( m_aRowSetApproveListeners.getLength() == 0 ) { - Reference<XRowSetApproveBroadcaster> xBroadcaster; - if (query_aggregation( m_xAggregate, xBroadcaster)) + if (auto xBroadcaster = query_aggregation<XRowSetApproveBroadcaster>(m_xAggregate)) { Reference<XRowSetApproveListener> xListener(static_cast<XRowSetApproveListener*>(this)); xBroadcaster->removeRowSetApproveListener(xListener); @@ -3407,8 +3399,7 @@ void SAL_CALL ODatabaseForm::insertRow() { try { - Reference<XResultSetUpdate> xUpdate; - if (query_aggregation( m_xAggregate, xUpdate)) + if (auto xUpdate = query_aggregation<XResultSetUpdate>(m_xAggregate)) xUpdate->insertRow(); } catch(const RowSetVetoException&) @@ -3427,8 +3418,7 @@ void SAL_CALL ODatabaseForm::updateRow() { try { - Reference<XResultSetUpdate> xUpdate; - if (query_aggregation( m_xAggregate, xUpdate)) + if (auto xUpdate = query_aggregation<XResultSetUpdate>(m_xAggregate)) xUpdate->updateRow(); } catch(const RowSetVetoException&) @@ -3447,8 +3437,7 @@ void SAL_CALL ODatabaseForm::deleteRow() { try { - Reference<XResultSetUpdate> xUpdate; - if (query_aggregation( m_xAggregate, xUpdate)) + if (auto xUpdate = query_aggregation<XResultSetUpdate>(m_xAggregate)) xUpdate->deleteRow(); } catch(const RowSetVetoException&) @@ -3467,8 +3456,7 @@ void SAL_CALL ODatabaseForm::cancelRowUpdates() { try { - Reference<XResultSetUpdate> xUpdate; - if (query_aggregation( m_xAggregate, xUpdate)) + if (auto xUpdate = query_aggregation<XResultSetUpdate>(m_xAggregate)) xUpdate->cancelRowUpdates(); } catch(const RowSetVetoException&) @@ -3485,8 +3473,8 @@ void SAL_CALL ODatabaseForm::cancelRowUpdates() void SAL_CALL ODatabaseForm::moveToInsertRow() { - Reference<XResultSetUpdate> xUpdate; - if (!query_aggregation( m_xAggregate, xUpdate)) + auto xUpdate = query_aggregation<XResultSetUpdate>(m_xAggregate); + if (!xUpdate) return; // _always_ move to the insert row @@ -3520,8 +3508,7 @@ void SAL_CALL ODatabaseForm::moveToInsertRow() void SAL_CALL ODatabaseForm::moveToCurrentRow() { - Reference<XResultSetUpdate> xUpdate; - if (query_aggregation( m_xAggregate, xUpdate)) + if (auto xUpdate = query_aggregation<XResultSetUpdate>(m_xAggregate)) xUpdate->moveToCurrentRow(); } @@ -3531,8 +3518,7 @@ Sequence<sal_Int32> SAL_CALL ODatabaseForm::deleteRows(const Sequence<Any>& rows { try { - Reference<XDeleteRows> xDelete; - if (query_aggregation( m_xAggregate, xDelete)) + if (auto xDelete = query_aggregation<XDeleteRows>(m_xAggregate)) return xDelete->deleteRows(rows); } catch(const RowSetVetoException&) @@ -3716,8 +3702,7 @@ Sequence< OUString > SAL_CALL ODatabaseForm::getSupportedServiceNames() { // the services of our aggregate Sequence< OUString > aServices; - Reference< XServiceInfo > xInfo; - if (query_aggregation(m_xAggregate, xInfo)) + if (auto xInfo = query_aggregation<XServiceInfo>(m_xAggregate)) aServices = xInfo->getSupportedServiceNames(); // concat without own services diff --git a/forms/source/component/Edit.cxx b/forms/source/component/Edit.cxx index 2812e7a2aa27..e4d477bdd020 100644 --- a/forms/source/component/Edit.cxx +++ b/forms/source/component/Edit.cxx @@ -83,8 +83,7 @@ OEditControl::OEditControl(const Reference<XComponentContext>& _rxFactory) osl_atomic_increment(&m_refCount); { - Reference<XWindow> xComp; - if (query_aggregation(m_xAggregate, xComp)) + if (auto xComp = query_aggregation<XWindow>(m_xAggregate)) { xComp->addFocusListener(this); xComp->addKeyListener(this); diff --git a/forms/source/component/FormComponent.cxx b/forms/source/component/FormComponent.cxx index d2ca58dd5c0c..4e134a4fec55 100644 --- a/forms/source/component/FormComponent.cxx +++ b/forms/source/component/FormComponent.cxx @@ -181,8 +181,7 @@ Sequence<Type> SAL_CALL OControl::getTypes() { TypeBag aTypes( _getTypes() ); - Reference< XTypeProvider > xProv; - if ( query_aggregation( m_xAggregate, xProv ) ) + if (auto xProv = query_aggregation<XTypeProvider>(m_xAggregate)) aTypes.addTypes( xProv->getTypes() ); return aTypes.getTypes(); @@ -200,8 +199,7 @@ void OControl::disposing() m_aWindowStateGuard.attach( nullptr, nullptr ); - Reference< XComponent > xComp; - if (query_aggregation(m_xAggregate, xComp)) + if (auto xComp = query_aggregation<XComponent>(m_xAggregate)) xComp->dispose(); } @@ -214,8 +212,7 @@ sal_Bool SAL_CALL OControl::supportsService(const OUString& _rsServiceName) Sequence< OUString > OControl::getAggregateServiceNames() const { Sequence< OUString > aAggServices; - Reference< XServiceInfo > xInfo; - if ( query_aggregation( m_xAggregate, xInfo ) ) + if (auto xInfo = query_aggregation<XServiceInfo>(m_xAggregate)) aAggServices = xInfo->getSupportedServiceNames(); return aAggServices; @@ -230,14 +227,12 @@ Sequence<OUString> SAL_CALL OControl::getSupportedServiceNames() // XEventListener void SAL_CALL OControl::disposing(const css::lang::EventObject& _rEvent) { - Reference< XInterface > xAggAsIface; - query_aggregation(m_xAggregate, xAggAsIface); + auto xAggAsIface = query_aggregation<XInterface>(m_xAggregate); // does the disposing come from the aggregate? if (xAggAsIface != Reference< XInterface >(_rEvent.Source, UNO_QUERY)) { // no -> forward it - Reference<css::lang::XEventListener> xListener; - if (query_aggregation(m_xAggregate, xListener)) + if (auto xListener = query_aggregation<css::lang::XEventListener>(m_xAggregate)) xListener->disposing(_rEvent); } } @@ -414,9 +409,7 @@ Sequence<Type> SAL_CALL OControlModel::getTypes() { TypeBag aTypes( _getTypes() ); - Reference< XTypeProvider > xProv; - - if ( query_aggregation( m_xAggregate, xProv ) ) + if (auto xProv = query_aggregation<XTypeProvider>(m_xAggregate)) aTypes.addTypes( xProv->getTypes() ); return aTypes.getTypes(); @@ -669,8 +662,7 @@ sal_Bool SAL_CALL OControlModel::supportsService(const OUString& _rServiceName) Sequence< OUString > OControlModel::getAggregateServiceNames() const { Sequence< OUString > aAggServices; - Reference< XServiceInfo > xInfo; - if ( query_aggregation( m_xAggregate, xInfo ) ) + if (auto xInfo = query_aggregation<XServiceInfo>(m_xAggregate)) aAggServices = xInfo->getSupportedServiceNames(); return aAggServices; } @@ -699,8 +691,7 @@ void SAL_CALL OControlModel::disposing(const css::lang::EventObject& _rSource) } else { - Reference<css::lang::XEventListener> xEvtLst; - if (query_aggregation(m_xAggregate, xEvtLst)) + if (auto xEvtLst = query_aggregation<css::lang::XEventListener>(m_xAggregate)) { osl::MutexGuard aGuard(m_aMutex); xEvtLst->disposing(_rSource); @@ -713,8 +704,7 @@ void OControlModel::disposing() { OPropertySetAggregationHelper::disposing(); - Reference<css::lang::XComponent> xComp; - if (query_aggregation(m_xAggregate, xComp)) + if (auto xComp = query_aggregation<css::lang::XComponent>(m_xAggregate)) xComp->dispose(); setParent(Reference<XFormComponent>()); @@ -724,15 +714,13 @@ void OControlModel::disposing() void OControlModel::writeAggregate( const Reference< XObjectOutputStream >& _rxOutStream ) const { - Reference< XPersistObject > xPersist; - if ( query_aggregation( m_xAggregate, xPersist ) ) + if (auto xPersist = query_aggregation<XPersistObject>(m_xAggregate)) xPersist->write( _rxOutStream ); } void OControlModel::readAggregate( const Reference< XObjectInputStream >& _rxInStream ) { - Reference< XPersistObject > xPersist; - if ( query_aggregation( m_xAggregate, xPersist ) ) + if (auto xPersist = query_aggregation<XPersistObject>(m_xAggregate)) xPersist->read( _rxInStream ); } diff --git a/forms/source/component/FormattedField.cxx b/forms/source/component/FormattedField.cxx index 67485c654f87..33d698c6de26 100644 --- a/forms/source/component/FormattedField.cxx +++ b/forms/source/component/FormattedField.cxx @@ -157,11 +157,8 @@ OFormattedControl::OFormattedControl(const Reference<XComponentContext>& _rxFact { osl_atomic_increment(&m_refCount); { - Reference<XWindow> xComp; - if (query_aggregation(m_xAggregate, xComp)) - { + if (auto xComp = query_aggregation<XWindow>(m_xAggregate)) xComp->addKeyListener(this); - } } osl_atomic_decrement(&m_refCount); } diff --git a/forms/source/component/FormattedFieldWrapper.cxx b/forms/source/component/FormattedFieldWrapper.cxx index 8b7f9a17c204..5f68eece2bd6 100644 --- a/forms/source/component/FormattedFieldWrapper.cxx +++ b/forms/source/component/FormattedFieldWrapper.cxx @@ -84,8 +84,7 @@ Reference< XCloneable > SAL_CALL OFormattedFieldWrapper::createClone() rtl::Reference< OFormattedFieldWrapper > xRef(new OFormattedFieldWrapper(m_xContext, m_implementationName)); - Reference< XCloneable > xCloneAccess; - query_aggregation( m_xAggregate, xCloneAccess ); + auto xCloneAccess = query_aggregation<XCloneable>(m_xAggregate); // clone the aggregate if ( xCloneAccess.is() ) @@ -198,8 +197,7 @@ void SAL_CALL OFormattedFieldWrapper::write(const Reference<XObjectOutputStream> // if we act as real edit field, we can simple forward this write request if (!m_xFormattedPart.is()) { - Reference<XPersistObject> xAggregatePersistence; - query_aggregation(m_xAggregate, xAggregatePersistence); + auto xAggregatePersistence = query_aggregation<XPersistObject>(m_xAggregate); DBG_ASSERT(xAggregatePersistence.is(), "OFormattedFieldWrapper::write : don't know how to handle this : can't write !"); // oops ... We gave an XPersistObject interface to the caller but now we aren't an XPersistObject ... if (xAggregatePersistence.is()) @@ -257,8 +255,7 @@ void SAL_CALL OFormattedFieldWrapper::read(const Reference<XObjectInputStream>& xInMarkable->deleteMark(nBeforeEditPart); } - Reference<XPersistObject> xAggregatePersistence; - query_aggregation(m_xAggregate, xAggregatePersistence); + auto xAggregatePersistence = query_aggregation<XPersistObject>(m_xAggregate); DBG_ASSERT(xAggregatePersistence.is(), "OFormattedFieldWrapper::read : don't know how to handle this : can't read !"); // oops ... We gave an XPersistObject interface to the caller but now we aren't an XPersistObject ... diff --git a/forms/source/component/ImageButton.cxx b/forms/source/component/ImageButton.cxx index 1dd66ca0dbdc..b15a81c1e46c 100644 --- a/forms/source/component/ImageButton.cxx +++ b/forms/source/component/ImageButton.cxx @@ -176,9 +176,7 @@ OImageButtonControl::OImageButtonControl(const Reference<XComponentContext>& _rx osl_atomic_increment(&m_refCount); { // Register as MouseListener - Reference< awt::XWindow > xComp; - query_aggregation( m_xAggregate, xComp); - if (xComp.is()) + if (auto xComp = query_aggregation<awt::XWindow>(m_xAggregate)) xComp->addMouseListener( static_cast< awt::XMouseListener* >( this ) ); } osl_atomic_decrement(&m_refCount); diff --git a/forms/source/component/ImageControl.cxx b/forms/source/component/ImageControl.cxx index 542783faca5e..ba999944a2d1 100644 --- a/forms/source/component/ImageControl.cxx +++ b/forms/source/component/ImageControl.cxx @@ -683,9 +683,7 @@ OImageControlControl::OImageControlControl(const Reference<XComponentContext>& _ osl_atomic_increment(&m_refCount); { // Add as Focus- and MouseListener - Reference< XWindow > xComp; - query_aggregation( m_xAggregate, xComp ); - if ( xComp.is() ) + if (auto xComp = query_aggregation<XWindow>(m_xAggregate)) xComp->addMouseListener( this ); } osl_atomic_decrement(&m_refCount); diff --git a/forms/source/component/ListBox.cxx b/forms/source/component/ListBox.cxx index 33647f0ceb96..f828a768882a 100644 --- a/forms/source/component/ListBox.cxx +++ b/forms/source/component/ListBox.cxx @@ -1818,8 +1818,7 @@ namespace frm osl_atomic_increment(&m_refCount); { // Register as FocusListener - Reference<XWindow> xComp; - if (query_aggregation(m_xAggregate, xComp)) + if (auto xComp = query_aggregation<XWindow>(m_xAggregate)) xComp->addFocusListener(this); // Register as ItemListener diff --git a/forms/source/component/cloneable.cxx b/forms/source/component/cloneable.cxx index 9770019c238d..7f14daf3924f 100644 --- a/forms/source/component/cloneable.cxx +++ b/forms/source/component/cloneable.cxx @@ -37,10 +37,9 @@ namespace frm Reference< XAggregation > OCloneableAggregation::createAggregateClone( const OCloneableAggregation* _pOriginal ) { - Reference< XCloneable > xAggregateCloneable; // will be the aggregate's XCloneable Reference< XAggregation > xAggregateClone; // will be the aggregate's clone - if ( query_aggregation( _pOriginal->m_xAggregate, xAggregateCloneable ) ) + if (auto xAggregateCloneable = query_aggregation<XCloneable>(_pOriginal->m_xAggregate)) { xAggregateClone.set(xAggregateCloneable->createClone(), css::uno::UNO_QUERY); DBG_ASSERT( xAggregateClone.is(), "OCloneableAggregation::createAggregateClone: invalid clone returned by the aggregate!" ); diff --git a/forms/source/richtext/richtextmodel.cxx b/forms/source/richtext/richtextmodel.cxx index bc2e920b1932..8ef6d5973b74 100644 --- a/forms/source/richtext/richtextmodel.cxx +++ b/forms/source/richtext/richtextmodel.cxx @@ -589,8 +589,7 @@ namespace frm if (comphelper::isUnoTunnelId<ORichTextModel>(_rId)) return comphelper::getSomething_cast(m_pEngine.get()); // Note returning a different type - Reference< XUnoTunnel > xAggTunnel; - if ( query_aggregation( m_xAggregate, xAggTunnel ) ) + if (auto xAggTunnel = query_aggregation<XUnoTunnel>(m_xAggregate)) return xAggTunnel->getSomething( _rId ); return 0; diff --git a/include/comphelper/uno3.hxx b/include/comphelper/uno3.hxx index 517398fd757e..757823d68465 100644 --- a/include/comphelper/uno3.hxx +++ b/include/comphelper/uno3.hxx @@ -161,6 +161,19 @@ namespace comphelper } return _rxOut.is(); } + + /** ask for an iface of an aggregated object + usage:<br/> + if (auto xFoo = query_aggregation<XFoo>(xAggregatedObject))<br/> + ... + */ + template <class iface> + css::uno::Reference<iface> query_aggregation(const css::uno::Reference< css::uno::XAggregation >& _rxAggregate) + { + css::uno::Reference<iface> _rxOut; + query_aggregation(_rxAggregate, _rxOut); + return _rxOut; + } } // namespace comphelper diff --git a/reportdesign/source/core/api/ReportDefinition.cxx b/reportdesign/source/core/api/ReportDefinition.cxx index eeaba1dd644d..81f71af56127 100644 --- a/reportdesign/source/core/api/ReportDefinition.cxx +++ b/reportdesign/source/core/api/ReportDefinition.cxx @@ -997,9 +997,7 @@ void SAL_CALL OReportDefinition::removeVetoableChangeListener( const OUString& P uno::Reference< uno::XInterface > SAL_CALL OReportDefinition::getParent( ) { ::osl::MutexGuard aGuard(m_aMutex); - uno::Reference< container::XChild > xChild; - comphelper::query_aggregation(m_aProps->m_xProxy,xChild); - if ( xChild.is() ) + if (auto xChild = comphelper::query_aggregation<container::XChild>(m_aProps->m_xProxy)) return xChild->getParent(); return m_pImpl->m_xParent; } @@ -1009,9 +1007,7 @@ void SAL_CALL OReportDefinition::setParent( const uno::Reference< uno::XInterfac ::osl::MutexGuard aGuard(m_aMutex); m_aProps->m_xParent = uno::Reference< container::XChild >(Parent,uno::UNO_QUERY); m_pImpl->m_xParent = Parent; - uno::Reference< container::XChild > xChild; - comphelper::query_aggregation(m_aProps->m_xProxy,xChild); - if ( xChild.is() ) + if (auto xChild = comphelper::query_aggregation<container::XChild>(m_aProps->m_xProxy)) xChild->setParent(Parent); } @@ -1947,9 +1943,7 @@ sal_Int64 SAL_CALL OReportDefinition::getSomething( const uno::Sequence< sal_Int } if ( !nRet ) { - uno::Reference< lang::XUnoTunnel> xTunnel; - ::comphelper::query_aggregation(m_aProps->m_xProxy,xTunnel); - if ( xTunnel.is() ) + if (auto xTunnel = comphelper::query_aggregation<lang::XUnoTunnel>(m_aProps->m_xProxy)) nRet = xTunnel->getSomething(rId); } diff --git a/reportdesign/source/core/inc/Tools.hxx b/reportdesign/source/core/inc/Tools.hxx index 3e0a699cef21..85094b45440e 100644 --- a/reportdesign/source/core/inc/Tools.hxx +++ b/reportdesign/source/core/inc/Tools.hxx @@ -132,17 +132,13 @@ namespace reportdesign { ::osl::MutexGuard aGuard(_pShape->m_aMutex); _pShape->m_aProps.aComponent.m_xParent = css::uno::Reference< css::container::XChild >(Parent,css::uno::UNO_QUERY); - css::uno::Reference< css::container::XChild > xChild; - comphelper::query_aggregation(_pShape->m_aProps.aComponent.m_xProxy,xChild); - if ( xChild.is() ) + if (auto xChild = comphelper::query_aggregation<css::container::XChild>(_pShape->m_aProps.aComponent.m_xProxy)) xChild->setParent(Parent); } template<typename T> static css::uno::Reference< css::uno::XInterface > getParent( T* _pShape ) { ::osl::MutexGuard aGuard(_pShape->m_aMutex); - css::uno::Reference< css::container::XChild > xChild; - comphelper::query_aggregation(_pShape->m_aProps.aComponent.m_xProxy,xChild); - if ( xChild.is() ) + if (auto xChild = comphelper::query_aggregation<css::container::XChild>(_pShape->m_aProps.aComponent.m_xProxy)) return xChild->getParent(); return _pShape->m_aProps.aComponent.m_xParent; } diff --git a/toolkit/source/controls/geometrycontrolmodel.cxx b/toolkit/source/controls/geometrycontrolmodel.cxx index b5fb16cfe5d7..5d079dc9ee90 100644 --- a/toolkit/source/controls/geometrycontrolmodel.cxx +++ b/toolkit/source/controls/geometrycontrolmodel.cxx @@ -429,8 +429,7 @@ constexpr OUStringLiteral GCM_PROPERTY_RESOURCERESOLVER = u"ResourceResolver"; OGCM_Base::disposing(); OPropertySetAggregationHelper::disposing(); - Reference<XComponent> xComp; - if ( query_aggregation( m_xAggregate, xComp ) ) + if (auto xComp = query_aggregation<XComponent>(m_xAggregate)) xComp->dispose(); } |