diff options
Diffstat (limited to 'dbaccess/source/ui/browser')
-rw-r--r-- | dbaccess/source/ui/browser/AsynchronousLink.cxx | 30 | ||||
-rw-r--r-- | dbaccess/source/ui/browser/brwctrlr.cxx | 300 | ||||
-rw-r--r-- | dbaccess/source/ui/browser/brwview.cxx | 62 | ||||
-rw-r--r-- | dbaccess/source/ui/browser/dataview.cxx | 18 | ||||
-rw-r--r-- | dbaccess/source/ui/browser/dbexchange.cxx | 6 | ||||
-rw-r--r-- | dbaccess/source/ui/browser/dbloader.cxx | 67 | ||||
-rw-r--r-- | dbaccess/source/ui/browser/dbtreemodel.hxx | 5 | ||||
-rw-r--r-- | dbaccess/source/ui/browser/dsEntriesNoExp.cxx | 89 | ||||
-rw-r--r-- | dbaccess/source/ui/browser/dsbrowserDnD.cxx | 12 | ||||
-rw-r--r-- | dbaccess/source/ui/browser/exsrcbrw.cxx | 17 | ||||
-rw-r--r-- | dbaccess/source/ui/browser/formadapter.cxx | 348 | ||||
-rw-r--r-- | dbaccess/source/ui/browser/genericcontroller.cxx | 234 | ||||
-rw-r--r-- | dbaccess/source/ui/browser/sbagrid.cxx | 356 | ||||
-rw-r--r-- | dbaccess/source/ui/browser/sbamultiplex.cxx | 500 | ||||
-rw-r--r-- | dbaccess/source/ui/browser/unodatbr.cxx | 466 |
15 files changed, 1483 insertions, 1027 deletions
diff --git a/dbaccess/source/ui/browser/AsynchronousLink.cxx b/dbaccess/source/ui/browser/AsynchronousLink.cxx index c8a7e500fb95..538ea702c4ac 100644 --- a/dbaccess/source/ui/browser/AsynchronousLink.cxx +++ b/dbaccess/source/ui/browser/AsynchronousLink.cxx @@ -22,25 +22,23 @@ // OAsynchronousLink using namespace dbaui; -OAsynchronousLink::OAsynchronousLink( const Link<void*,void>& _rHandler ) - :m_aHandler(_rHandler) - ,m_aEventSafety() - ,m_aDestructionSafety() - ,m_nEventId(nullptr) +OAsynchronousLink::OAsynchronousLink(const Link<void*, void>& _rHandler) + : m_aHandler(_rHandler) + , m_nEventId(nullptr) { } OAsynchronousLink::~OAsynchronousLink() { { - ::osl::MutexGuard aEventGuard( m_aEventSafety ); - if ( m_nEventId ) + std::unique_lock aEventGuard(m_aEventSafety); + if (m_nEventId) Application::RemoveUserEvent(m_nEventId); m_nEventId = nullptr; } { - ::osl::MutexGuard aDestructionGuard( m_aDestructionSafety ); + std::unique_lock aDestructionGuard(m_aDestructionSafety); // this is just for the case we're deleted while another thread just handled the event : // if this other thread called our link while we were deleting the event here, the // link handler blocked. With leaving the above block it continued, but now we are prevented @@ -48,28 +46,28 @@ OAsynchronousLink::~OAsynchronousLink() } } -void OAsynchronousLink::Call( void* _pArgument ) +void OAsynchronousLink::Call(void* _pArgument) { - ::osl::MutexGuard aEventGuard( m_aEventSafety ); + std::unique_lock aEventGuard(m_aEventSafety); if (m_nEventId) Application::RemoveUserEvent(m_nEventId); - m_nEventId = Application::PostUserEvent( LINK( this, OAsynchronousLink, OnAsyncCall ), _pArgument ); + m_nEventId = Application::PostUserEvent(LINK(this, OAsynchronousLink, OnAsyncCall), _pArgument); } void OAsynchronousLink::CancelCall() { - ::osl::MutexGuard aEventGuard( m_aEventSafety ); - if ( m_nEventId ) - Application::RemoveUserEvent( m_nEventId ); + std::unique_lock aEventGuard(m_aEventSafety); + if (m_nEventId) + Application::RemoveUserEvent(m_nEventId); m_nEventId = nullptr; } IMPL_LINK(OAsynchronousLink, OnAsyncCall, void*, _pArg, void) { { - ::osl::MutexGuard aDestructionGuard( m_aDestructionSafety ); + std::unique_lock aDestructionGuard(m_aDestructionSafety); { - ::osl::MutexGuard aEventGuard( m_aEventSafety ); + std::unique_lock aEventGuard(m_aEventSafety); if (!m_nEventId) // our destructor deleted the event just while we are waiting for m_aEventSafety // -> get outta here diff --git a/dbaccess/source/ui/browser/brwctrlr.cxx b/dbaccess/source/ui/browser/brwctrlr.cxx index c2e175020b4e..3a3927a2dfe7 100644 --- a/dbaccess/source/ui/browser/brwctrlr.cxx +++ b/dbaccess/source/ui/browser/brwctrlr.cxx @@ -68,7 +68,7 @@ #include <sal/log.hxx> #include <svx/fmsearch.hxx> #include <svx/svxdlg.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <osl/diagnose.h> #include <vcl/svapp.hxx> #include <vcl/weld.hxx> @@ -91,27 +91,6 @@ using namespace ::dbtools; using namespace ::comphelper; using namespace ::svt; -#define HANDLE_SQL_ERRORS( action, successflag, context, message ) \ - try \ - { \ - successflag = false; \ - action; \ - successflag = true; \ - } \ - catch(SQLException& e) \ - { \ - SQLException aError = ::dbtools::prependErrorInfo(e, *this, context); \ - css::sdb::SQLErrorEvent aEvent; \ - aEvent.Reason <<= aError; \ - errorOccured(aEvent); \ - } \ - catch(Exception&) \ - { \ - DBG_UNHANDLED_EXCEPTION("dbaccess"); \ - } \ - -#define DO_SAFE( action, message ) try { action; } catch(Exception&) { SAL_WARN("dbaccess.ui",message); } ; - namespace dbaui { @@ -146,7 +125,7 @@ class SbaXDataBrowserController::FormControllerImpl css::frame::XFrameActionListener > { friend class SbaXDataBrowserController; - ::comphelper::OInterfaceContainerHelper2 m_aActivateListeners; + ::comphelper::OInterfaceContainerHelper3<css::form::XFormControllerListener> m_aActivateListeners; SbaXDataBrowserController* m_pOwner; public: @@ -417,12 +396,12 @@ void SAL_CALL SbaXDataBrowserController::FormControllerImpl::setMode( const OUSt OUString SAL_CALL SbaXDataBrowserController::FormControllerImpl::getMode( ) { - return "DataMode"; + return u"DataMode"_ustr; } Sequence< OUString > SAL_CALL SbaXDataBrowserController::FormControllerImpl::getSupportedModes( ) { - Sequence< OUString > aModes { "DataMode" }; + Sequence< OUString > aModes { u"DataMode"_ustr }; return aModes; } @@ -457,8 +436,8 @@ Sequence< Reference< css::awt::XControl > > SAL_CALL SbaXDataBrowserController:: { if (m_pOwner->getBrowserView()) { - Reference< css::awt::XControl > xGrid = m_pOwner->getBrowserView()->getGridControl(); - return Sequence< Reference< css::awt::XControl > >(&xGrid, 1); + rtl::Reference< SbaXGridControl > xGrid = m_pOwner->getBrowserView()->getGridControl(); + return { Reference< css::awt::XControl >(xGrid) }; } return Sequence< Reference< css::awt::XControl > >(); } @@ -500,7 +479,7 @@ Sequence< Type > SAL_CALL SbaXDataBrowserController::getTypes( ) { return ::comphelper::concatSequences( SbaXDataBrowserController_Base::getTypes(), - m_pFormControllerImpl->getTypes() + m_xFormControllerImpl->getTypes() ); } @@ -525,12 +504,12 @@ Any SAL_CALL SbaXDataBrowserController::queryInterface(const Type& _rType) SbaXDataBrowserController::SbaXDataBrowserController(const Reference< css::uno::XComponentContext >& _rM) :SbaXDataBrowserController_Base(_rM) ,m_nRowSetPrivileges(0) + ,m_aInvalidateClipboard("dbaui::SbaXDataBrowserController m_aInvalidateClipboard") ,m_aAsyncGetCellFocus(LINK(this, SbaXDataBrowserController, OnAsyncGetCellFocus)) ,m_aAsyncDisplayError( LINK( this, SbaXDataBrowserController, OnAsyncDisplayError ) ) ,m_sStateSaveRecord(DBA_RES(RID_STR_SAVE_CURRENT_RECORD)) ,m_sStateUndoRecord(DBA_RES(RID_STR_UNDO_MODIFY_RECORD)) - ,m_sModuleIdentifier( OUString( "com.sun.star.sdb.DataSourceBrowser" ) ) - ,m_pFormControllerImpl(nullptr) + ,m_sModuleIdentifier( u"com.sun.star.sdb.DataSourceBrowser"_ustr ) ,m_nFormActionNestingLevel(0) ,m_bLoadCanceled( false ) ,m_bCannotSelectUnfiltered( true ) @@ -538,13 +517,11 @@ SbaXDataBrowserController::SbaXDataBrowserController(const Reference< css::uno:: // create the form controller aggregate osl_atomic_increment(&m_refCount); { - m_pFormControllerImpl = new FormControllerImpl(this); - m_xFormControllerImpl = m_pFormControllerImpl; + m_xFormControllerImpl = new FormControllerImpl(this); m_xFormControllerImpl->setDelegator(*this); } osl_atomic_decrement(&m_refCount); - m_aInvalidateClipboard.SetDebugName("dbaui::SbaXDataBrowserController m_aInvalidateClipboard"); m_aInvalidateClipboard.SetInvokeHandler(LINK(this, SbaXDataBrowserController, OnInvalidateClipboard)); m_aInvalidateClipboard.SetTimeout(300); } @@ -691,24 +668,24 @@ void SbaXDataBrowserController::initFormatter() void SbaXDataBrowserController::describeSupportedFeatures() { SbaXDataBrowserController_Base::describeSupportedFeatures(); - implDescribeSupportedFeature( ".uno:FormSlots/undoRecord", ID_BROWSER_UNDORECORD, CommandGroup::CONTROLS ); - implDescribeSupportedFeature( ".uno:FormController/undoRecord", ID_BROWSER_UNDORECORD, CommandGroup::CONTROLS ); - implDescribeSupportedFeature( ".uno:RecUndo", ID_BROWSER_UNDORECORD, CommandGroup::CONTROLS ); - implDescribeSupportedFeature( ".uno:FormSlots/saveRecord", ID_BROWSER_SAVERECORD, CommandGroup::CONTROLS ); - implDescribeSupportedFeature( ".uno:FormController/saveRecord", ID_BROWSER_SAVERECORD, CommandGroup::CONTROLS ); - implDescribeSupportedFeature( ".uno:RecSave", ID_BROWSER_SAVERECORD, CommandGroup::CONTROLS ); - implDescribeSupportedFeature( ".uno:Save", ID_BROWSER_SAVERECORD, CommandGroup::DOCUMENT ); - implDescribeSupportedFeature( ".uno:RecSearch", SID_FM_SEARCH, CommandGroup::CONTROLS ); - implDescribeSupportedFeature( ".uno:AutoFilter", SID_FM_AUTOFILTER, CommandGroup::CONTROLS ); - implDescribeSupportedFeature( ".uno:Refresh", SID_FM_REFRESH, CommandGroup::CONTROLS ); - implDescribeSupportedFeature( ".uno:OrderCrit", SID_FM_ORDERCRIT, CommandGroup::CONTROLS ); - implDescribeSupportedFeature( ".uno:RemoveFilterSort", SID_FM_REMOVE_FILTER_SORT,CommandGroup::CONTROLS ); - implDescribeSupportedFeature( ".uno:FormFiltered", SID_FM_FORM_FILTERED, CommandGroup::CONTROLS ); - implDescribeSupportedFeature( ".uno:FilterCrit", SID_FM_FILTERCRIT, CommandGroup::CONTROLS ); - implDescribeSupportedFeature( ".uno:Sortup", ID_BROWSER_SORTUP, CommandGroup::CONTROLS ); - implDescribeSupportedFeature( ".uno:SortDown", ID_BROWSER_SORTDOWN, CommandGroup::CONTROLS ); - implDescribeSupportedFeature( ".uno:FormSlots/deleteRecord", SID_FM_DELETEROWS, CommandGroup::EDIT ); - implDescribeSupportedFeature( ".uno:FormSlots/insertRecord", ID_BROWSER_INSERT_ROW, CommandGroup::INSERT ); + implDescribeSupportedFeature( u".uno:FormSlots/undoRecord"_ustr, ID_BROWSER_UNDORECORD, CommandGroup::CONTROLS ); + implDescribeSupportedFeature( u".uno:FormController/undoRecord"_ustr, ID_BROWSER_UNDORECORD, CommandGroup::CONTROLS ); + implDescribeSupportedFeature( u".uno:RecUndo"_ustr, ID_BROWSER_UNDORECORD, CommandGroup::CONTROLS ); + implDescribeSupportedFeature( u".uno:FormSlots/saveRecord"_ustr, ID_BROWSER_SAVERECORD, CommandGroup::CONTROLS ); + implDescribeSupportedFeature( u".uno:FormController/saveRecord"_ustr, ID_BROWSER_SAVERECORD, CommandGroup::CONTROLS ); + implDescribeSupportedFeature( u".uno:RecSave"_ustr, ID_BROWSER_SAVERECORD, CommandGroup::CONTROLS ); + implDescribeSupportedFeature( u".uno:Save"_ustr, ID_BROWSER_SAVERECORD, CommandGroup::DOCUMENT ); + implDescribeSupportedFeature( u".uno:RecSearch"_ustr, SID_FM_SEARCH, CommandGroup::CONTROLS ); + implDescribeSupportedFeature( u".uno:AutoFilter"_ustr, SID_FM_AUTOFILTER, CommandGroup::CONTROLS ); + implDescribeSupportedFeature( u".uno:Refresh"_ustr, SID_FM_REFRESH, CommandGroup::CONTROLS ); + implDescribeSupportedFeature( u".uno:OrderCrit"_ustr, SID_FM_ORDERCRIT, CommandGroup::CONTROLS ); + implDescribeSupportedFeature( u".uno:RemoveFilterSort"_ustr, SID_FM_REMOVE_FILTER_SORT,CommandGroup::CONTROLS ); + implDescribeSupportedFeature( u".uno:FormFiltered"_ustr, SID_FM_FORM_FILTERED, CommandGroup::CONTROLS ); + implDescribeSupportedFeature( u".uno:FilterCrit"_ustr, SID_FM_FILTERCRIT, CommandGroup::CONTROLS ); + implDescribeSupportedFeature( u".uno:Sortup"_ustr, ID_BROWSER_SORTUP, CommandGroup::CONTROLS ); + implDescribeSupportedFeature( u".uno:SortDown"_ustr, ID_BROWSER_SORTDOWN, CommandGroup::CONTROLS ); + implDescribeSupportedFeature( u".uno:FormSlots/deleteRecord"_ustr, SID_FM_DELETEROWS, CommandGroup::EDIT ); + implDescribeSupportedFeature( u".uno:FormSlots/insertRecord"_ustr, ID_BROWSER_INSERT_ROW, CommandGroup::INSERT ); } bool SbaXDataBrowserController::Construct(vcl::Window* pParent) @@ -735,14 +712,14 @@ bool SbaXDataBrowserController::Construct(vcl::Window* pParent) // we want to have a grid with a "flat" border Reference< XPropertySet > xGridSet(m_xGridModel, UNO_QUERY); if ( xGridSet.is() ) - xGridSet->setPropertyValue(PROPERTY_BORDER, makeAny(sal_Int16(2))); + xGridSet->setPropertyValue(PROPERTY_BORDER, Any(sal_Int16(2))); // marry them Reference< css::container::XNameContainer > xNameCont(m_xRowSet, UNO_QUERY); { OUString sText(DBA_RES(STR_DATASOURCE_GRIDCONTROL_NAME)); - xNameCont->insertByName(sText, makeAny(m_xGridModel)); + xNameCont->insertByName(sText, Any(m_xGridModel)); } // create the view @@ -839,14 +816,14 @@ void SbaXDataBrowserController::RemoveColumnListener(const Reference< XPropertyS Reference< XRowSet > SbaXDataBrowserController::CreateForm() { return Reference< XRowSet > ( - getORB()->getServiceManager()->createInstanceWithContext("com.sun.star.form.component.Form", getORB()), + getORB()->getServiceManager()->createInstanceWithContext(u"com.sun.star.form.component.Form"_ustr, getORB()), UNO_QUERY); } Reference< css::form::XFormComponent > SbaXDataBrowserController::CreateGridModel() { return Reference< css::form::XFormComponent > ( - getORB()->getServiceManager()->createInstanceWithContext("com.sun.star.form.component.GridControl", getORB()), + getORB()->getServiceManager()->createInstanceWithContext(u"com.sun.star.form.component.GridControl"_ustr, getORB()), UNO_QUERY); } @@ -891,14 +868,13 @@ void SbaXDataBrowserController::removeModelListeners(const Reference< XControlMo void SbaXDataBrowserController::addControlListeners(const Reference< css::awt::XControl > & _xGridControl) { // to ge the 'modified' for the current cell - Reference< XModifyBroadcaster > xBroadcaster(getBrowserView()->getGridControl(), UNO_QUERY); - if (xBroadcaster.is()) - xBroadcaster->addModifyListener(static_cast<XModifyListener*>(this)); + rtl::Reference< SbaXGridControl > xGridControl(getBrowserView()->getGridControl() ); + if (xGridControl.is()) + xGridControl->addModifyListener(static_cast<XModifyListener*>(this)); // introduce ourself as dispatch provider for the grid - Reference< XDispatchProviderInterception > xInterception(getBrowserView()->getGridControl(), UNO_QUERY); - if (xInterception.is()) - xInterception->registerDispatchProviderInterceptor(static_cast<XDispatchProviderInterceptor*>(this)); + if (xGridControl.is()) + xGridControl->registerDispatchProviderInterceptor(static_cast<XDispatchProviderInterceptor*>(this)); // add as focus listener to the control (needed for the form controller functionality) Reference< XWindow > xWindow(_xGridControl, UNO_QUERY); @@ -925,9 +901,7 @@ void SAL_CALL SbaXDataBrowserController::focusGained(const FocusEvent& /*e*/) { // notify our activate listeners (registered on the form controller aggregate) EventObject aEvt(*this); - ::comphelper::OInterfaceIteratorHelper2 aIter(m_pFormControllerImpl->m_aActivateListeners); - while (aIter.hasMoreElements()) - static_cast<XFormControllerListener*>(aIter.next())->formActivated(aEvt); + m_xFormControllerImpl->m_aActivateListeners.notifyEach( &css::form::XFormControllerListener::formActivated, aEvt ); } void SAL_CALL SbaXDataBrowserController::focusLost(const FocusEvent& e) @@ -951,12 +925,10 @@ void SAL_CALL SbaXDataBrowserController::focusLost(const FocusEvent& e) // notify the listeners that the "form" we represent has been deactivated EventObject aEvt(*this); - ::comphelper::OInterfaceIteratorHelper2 aIter(m_pFormControllerImpl->m_aActivateListeners); - while (aIter.hasMoreElements()) - static_cast<XFormControllerListener*>(aIter.next())->formDeactivated(aEvt); + m_xFormControllerImpl->m_aActivateListeners.notifyEach( &css::form::XFormControllerListener::formDeactivated, aEvt ); // commit the changes of the grid control (as we're deactivated) - Reference< XBoundComponent > xCommitable(getBrowserView()->getGridControl(), UNO_QUERY); + rtl::Reference< SbaXGridControl > xCommitable(getBrowserView()->getGridControl()); if (xCommitable.is()) xCommitable->commit(); else @@ -998,7 +970,7 @@ void SbaXDataBrowserController::disposingColumnModel(const css::lang::EventObjec void SbaXDataBrowserController::disposing(const EventObject& Source) { // if it's a component other than our aggregate, forward it to the aggregate - if ( m_xFormControllerImpl != Source.Source ) + if ( uno::Reference<XInterface>(static_cast<cppu::OWeakObject*>(m_xFormControllerImpl.get()), UNO_QUERY) != Source.Source ) { Reference< XEventListener > xAggListener; m_xFormControllerImpl->queryAggregation( cppu::UnoType<decltype(xAggListener)>::get() ) >>= xAggListener; @@ -1010,7 +982,7 @@ void SbaXDataBrowserController::disposing(const EventObject& Source) if (getBrowserView()) { Reference< css::awt::XControl > xSourceControl(Source.Source, UNO_QUERY); - if (xSourceControl == getBrowserView()->getGridControl()) + if (xSourceControl == cppu::getXWeak(getBrowserView()->getGridControl().get())) removeControlListeners(getBrowserView()->getGridControl()); } @@ -1266,11 +1238,11 @@ void SbaXDataBrowserController::errorOccured(const css::sdb::SQLErrorEvent& aEve if ( m_nFormActionNestingLevel ) { OSL_ENSURE( !m_aCurrentError.isValid(), "SbaXDataBrowserController::errorOccurred: can handle one error per transaction only!" ); - m_aCurrentError = aInfo; + m_aCurrentError = std::move(aInfo); } else { - m_aCurrentError = aInfo; + m_aCurrentError = std::move(aInfo); m_aAsyncDisplayError.Call(); } } @@ -1284,28 +1256,26 @@ sal_Bool SbaXDataBrowserController::approveParameter(const css::form::DatabasePa return true; } - Reference< css::container::XIndexAccess > xParameters = aEvent.Parameters; SolarMutexGuard aSolarGuard; // default handling: instantiate an interaction handler and let it handle the parameter request try { // two continuations allowed: OK and Cancel - OParameterContinuation* pParamValues = new OParameterContinuation; - OInteractionAbort* pAbort = new OInteractionAbort; + rtl::Reference<OParameterContinuation> pParamValues = new OParameterContinuation; + rtl::Reference<OInteractionAbort> pAbort = new OInteractionAbort; // the request ParametersRequest aRequest; - aRequest.Parameters = xParameters; + aRequest.Parameters = aEvent.Parameters; aRequest.Connection = getConnection(Reference< XRowSet >(aEvent.Source, UNO_QUERY)); - OInteractionRequest* pParamRequest = new OInteractionRequest(makeAny(aRequest)); - Reference< XInteractionRequest > xParamRequest(pParamRequest); + rtl::Reference<OInteractionRequest> pParamRequest = new OInteractionRequest(Any(aRequest)); // some knittings pParamRequest->addContinuation(pParamValues); pParamRequest->addContinuation(pAbort); // create the handler, let it handle the request Reference< XInteractionHandler2 > xHandler(InteractionHandler::createWithParent(getORB(), getComponentWindow())); - xHandler->handle(xParamRequest); + xHandler->handle(pParamRequest); if (!pParamValues->wasSelected()) { // canceled @@ -1321,8 +1291,7 @@ sal_Bool SbaXDataBrowserController::approveParameter(const css::form::DatabasePa setLoadingCancelled(); return false; } - const PropertyValue* pFinalValues = aFinalValues.getConstArray(); - for (sal_Int32 i=0; i<aFinalValues.getLength(); ++i, ++pFinalValues) + for (sal_Int32 i = 0; i < aFinalValues.getLength(); ++i) { Reference< XPropertySet > xParam( aRequest.Parameters->getByIndex(i), css::uno::UNO_QUERY); @@ -1332,9 +1301,9 @@ sal_Bool SbaXDataBrowserController::approveParameter(const css::form::DatabasePa #ifdef DBG_UTIL OUString sName; xParam->getPropertyValue(PROPERTY_NAME) >>= sName; - OSL_ENSURE(sName == pFinalValues->Name, "SbaXDataBrowserController::approveParameter: suspicious value names!"); + OSL_ENSURE(sName == aFinalValues[i].Name, "SbaXDataBrowserController::approveParameter: suspicious value names!"); #endif - try { xParam->setPropertyValue(PROPERTY_VALUE, pFinalValues->Value); } + try { xParam->setPropertyValue(PROPERTY_VALUE, aFinalValues[i].Value); } catch(Exception&) { SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::approveParameter: setting one of the properties failed!"); @@ -1415,7 +1384,7 @@ FeatureState SbaXDataBrowserController::GetState(sal_uInt16 nId) const try { Reference< XPropertySet > xRowSetProps( getRowSet(), UNO_QUERY_THROW ); - OSL_VERIFY( xRowSetProps->getPropertyValue("AllowInserts") >>= bAllowInsertions ); + OSL_VERIFY( xRowSetProps->getPropertyValue(u"AllowInserts"_ustr) >>= bAllowInsertions ); } catch( const Exception& ) { @@ -1434,7 +1403,7 @@ FeatureState SbaXDataBrowserController::GetState(sal_uInt16 nId) const try { Reference< XPropertySet > xRowSetProps( getRowSet(), UNO_QUERY_THROW ); - OSL_VERIFY( xRowSetProps->getPropertyValue("AllowDeletes") >>= bAllowDeletions ); + OSL_VERIFY( xRowSetProps->getPropertyValue(u"AllowDeletes"_ustr) >>= bAllowDeletions ); OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_ROWCOUNT ) >>= nRowCount ); OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_ISNEW ) >>= bInsertionRow ); } @@ -1551,9 +1520,9 @@ FeatureState SbaXDataBrowserController::GetState(sal_uInt16 nId) const break; // no datasource -> no edit mode sal_Int32 nDataSourcePrivileges = ::comphelper::getINT32(xDataSourceSet->getPropertyValue(PROPERTY_PRIVILEGES)); - bool bInsertAllowedAndPossible = ((nDataSourcePrivileges & css::sdbcx::Privilege::INSERT) != 0) && ::comphelper::getBOOL(xDataSourceSet->getPropertyValue("AllowInserts")); - bool bUpdateAllowedAndPossible = ((nDataSourcePrivileges & css::sdbcx::Privilege::UPDATE) != 0) && ::comphelper::getBOOL(xDataSourceSet->getPropertyValue("AllowUpdates")); - bool bDeleteAllowedAndPossible = ((nDataSourcePrivileges & css::sdbcx::Privilege::DELETE) != 0) && ::comphelper::getBOOL(xDataSourceSet->getPropertyValue("AllowDeletes")); + bool bInsertAllowedAndPossible = ((nDataSourcePrivileges & css::sdbcx::Privilege::INSERT) != 0) && ::comphelper::getBOOL(xDataSourceSet->getPropertyValue(u"AllowInserts"_ustr)); + bool bUpdateAllowedAndPossible = ((nDataSourcePrivileges & css::sdbcx::Privilege::UPDATE) != 0) && ::comphelper::getBOOL(xDataSourceSet->getPropertyValue(u"AllowUpdates"_ustr)); + bool bDeleteAllowedAndPossible = ((nDataSourcePrivileges & css::sdbcx::Privilege::DELETE) != 0) && ::comphelper::getBOOL(xDataSourceSet->getPropertyValue(u"AllowDeletes"_ustr)); if (!bInsertAllowedAndPossible && !bUpdateAllowedAndPossible && !bDeleteAllowedAndPossible) break; // no insert/update/delete -> no edit mode @@ -1609,7 +1578,7 @@ void SbaXDataBrowserController::applyParserOrder(const OUString& _rOldOrder,cons bool bSuccess = false; try { - xFormSet->setPropertyValue(PROPERTY_ORDER, makeAny(_xParser->getOrder())); + xFormSet->setPropertyValue(PROPERTY_ORDER, Any(_xParser->getOrder())); bSuccess = reloadForm(m_xLoadable); } catch(Exception&) @@ -1618,7 +1587,7 @@ void SbaXDataBrowserController::applyParserOrder(const OUString& _rOldOrder,cons if (!bSuccess) { - xFormSet->setPropertyValue(PROPERTY_ORDER, makeAny(_rOldOrder)); + xFormSet->setPropertyValue(PROPERTY_ORDER, Any(_rOldOrder)); try { @@ -1651,8 +1620,8 @@ void SbaXDataBrowserController::applyParserFilter(const OUString& _rOldFilter, b try { FormErrorHelper aError(this); - xFormSet->setPropertyValue(PROPERTY_FILTER, makeAny(_xParser->getFilter())); - xFormSet->setPropertyValue(PROPERTY_HAVING_CLAUSE, makeAny(_xParser->getHavingClause())); + xFormSet->setPropertyValue(PROPERTY_FILTER, Any(_xParser->getFilter())); + xFormSet->setPropertyValue(PROPERTY_HAVING_CLAUSE, Any(_xParser->getHavingClause())); xFormSet->setPropertyValue(PROPERTY_APPLYFILTER, css::uno::Any(true)); bSuccess = reloadForm(m_xLoadable); @@ -1663,8 +1632,8 @@ void SbaXDataBrowserController::applyParserFilter(const OUString& _rOldFilter, b if (!bSuccess) { - xFormSet->setPropertyValue(PROPERTY_FILTER, makeAny(_rOldFilter)); - xFormSet->setPropertyValue(PROPERTY_HAVING_CLAUSE, makeAny(_sOldHaving)); + xFormSet->setPropertyValue(PROPERTY_FILTER, Any(_rOldFilter)); + xFormSet->setPropertyValue(PROPERTY_HAVING_CLAUSE, Any(_sOldHaving)); xFormSet->setPropertyValue(PROPERTY_APPLYFILTER, css::uno::Any(_bOldFilterApplied)); try @@ -1791,7 +1760,7 @@ void SbaXDataBrowserController::ExecuteFilterSortCrit(bool bFilter) void SbaXDataBrowserController::ExecuteSearch() { // calculate the control source of the active field - Reference< css::form::XGrid > xGrid(getBrowserView()->getGridControl(), UNO_QUERY); + rtl::Reference< SbaXGridControl > xGrid(getBrowserView()->getGridControl()); OSL_ENSURE(xGrid.is(), "SbaXDataBrowserController::ExecuteSearch : the control should have a css::form::XGrid interface !"); Reference< css::form::XGridPeer > xGridPeer(getBrowserView()->getGridControl()->getPeer(), UNO_QUERY); @@ -1815,9 +1784,9 @@ void SbaXDataBrowserController::ExecuteSearch() // prohibit the synchronization of the grid's display with the cursor's position Reference< XPropertySet > xModelSet(getControlModel(), UNO_QUERY); OSL_ENSURE(xModelSet.is(), "SbaXDataBrowserController::ExecuteSearch : no model set ?!"); - xModelSet->setPropertyValue("DisplayIsSynchron", css::uno::Any(false)); - xModelSet->setPropertyValue("AlwaysShowCursor", css::uno::Any(true)); - xModelSet->setPropertyValue("CursorColor", makeAny(COL_LIGHTRED)); + xModelSet->setPropertyValue(u"DisplayIsSynchron"_ustr, css::uno::Any(false)); + xModelSet->setPropertyValue(u"AlwaysShowCursor"_ustr, css::uno::Any(true)); + xModelSet->setPropertyValue(u"CursorColor"_ustr, Any(COL_LIGHTRED)); SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); VclPtr<AbstractFmSearchDialog> pDialog; @@ -1831,9 +1800,9 @@ void SbaXDataBrowserController::ExecuteSearch() pDialog.disposeAndClear(); // restore the grid's normal operating state - xModelSet->setPropertyValue("DisplayIsSynchron", css::uno::Any(true)); - xModelSet->setPropertyValue("AlwaysShowCursor", css::uno::Any(false)); - xModelSet->setPropertyValue("CursorColor", Any()); + xModelSet->setPropertyValue(u"DisplayIsSynchron"_ustr, css::uno::Any(true)); + xModelSet->setPropertyValue(u"AlwaysShowCursor"_ustr, css::uno::Any(false)); + xModelSet->setPropertyValue(u"CursorColor"_ustr, Any()); } void SbaXDataBrowserController::Execute(sal_uInt16 nId, const Sequence< PropertyValue >& _rArgs) @@ -1967,12 +1936,23 @@ void SbaXDataBrowserController::Execute(sal_uInt16 nId, const Sequence< Property Reference< XSingleSelectQueryComposer > xParser = createParser_nothrow(); const OUString sOldSort = xParser->getOrder(); bool bParserSuccess = false; - HANDLE_SQL_ERRORS( - xParser->setOrder(OUString()); xParser->appendOrderByColumn(xField, bSortUp), - bParserSuccess, - DBA_RES(SBA_BROWSER_SETTING_ORDER), - "SbaXDataBrowserController::Execute : caught an exception while composing the new filter !" - ) + try + { + xParser->setOrder(OUString()); + xParser->appendOrderByColumn(xField, bSortUp); + bParserSuccess = true; + } + catch(SQLException& e) + { + SQLException aError = ::dbtools::prependErrorInfo(e, *this, DBA_RES(SBA_BROWSER_SETTING_ORDER)); + css::sdb::SQLErrorEvent aEvent; + aEvent.Reason <<= aError; + errorOccured(aEvent); + } + catch(Exception&) + { + DBG_UNHANDLED_EXCEPTION("dbaccess", "SbaXDataBrowserController::Execute : caught an exception while composing the new filter !"); + } if (bParserSuccess) applyParserOrder(sOldSort,xParser); @@ -2004,8 +1984,22 @@ void SbaXDataBrowserController::Execute(sal_uInt16 nId, const Sequence< Property // -> completely overwrite it, else append one if (!bApplied) { - DO_SAFE( xParser->setFilter( OUString()), "SbaXDataBrowserController::Execute : caught an exception while resetting unapplied filter !" ); - DO_SAFE( xParser->setHavingClause(OUString()), "SbaXDataBrowserController::Execute : caught an exception while resetting unapplied HAVING clause !" ); + try + { + xParser->setFilter(OUString()); + } + catch(Exception&) + { + SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::Execute : caught an exception while resetting unapplied filter !"); + } + try + { + xParser->setHavingClause(OUString()); + } + catch(Exception&) + { + SAL_WARN("dbaccess.ui", "SbaXDataBrowserController::Execute : caught an exception while resetting unapplied HAVING clause !"); + } } bool bParserSuccess = false; @@ -2014,21 +2008,43 @@ void SbaXDataBrowserController::Execute(sal_uInt16 nId, const Sequence< Property if ( bHaving ) { - HANDLE_SQL_ERRORS( - xParser->appendHavingClauseByColumn(xField,true,nOp), - bParserSuccess, - DBA_RES(SBA_BROWSER_SETTING_FILTER), - "SbaXDataBrowserController::Execute : caught an exception while composing the new filter !" - ) + try + { + bParserSuccess = false; + xParser->appendHavingClauseByColumn(xField,true,nOp); + bParserSuccess = true; + } + catch(SQLException& e) + { + SQLException aError = ::dbtools::prependErrorInfo(e, *this, DBA_RES(SBA_BROWSER_SETTING_FILTER)); + css::sdb::SQLErrorEvent aEvent; + aEvent.Reason <<= aError; + errorOccured(aEvent); + } + catch(Exception&) + { + DBG_UNHANDLED_EXCEPTION("dbaccess", "SbaXDataBrowserController::Execute : caught an exception while composing the new filter !"); + } } else { - HANDLE_SQL_ERRORS( - xParser->appendFilterByColumn(xField,true,nOp), - bParserSuccess, - DBA_RES(SBA_BROWSER_SETTING_FILTER), - "SbaXDataBrowserController::Execute : caught an exception while composing the new filter !" - ) + try + { + bParserSuccess = false; + xParser->appendFilterByColumn(xField,true,nOp); + bParserSuccess = true; + } + catch(SQLException& e) + { + SQLException aError = ::dbtools::prependErrorInfo(e, *this, DBA_RES(SBA_BROWSER_SETTING_FILTER)); + css::sdb::SQLErrorEvent aEvent; + aEvent.Reason <<= aError; + errorOccured(aEvent); + } + catch(Exception&) + { + DBG_UNHANDLED_EXCEPTION("dbaccess", "SbaXDataBrowserController::Execute : caught an exception while composing the new filter !"); + } } if (bParserSuccess) @@ -2059,9 +2075,9 @@ void SbaXDataBrowserController::Execute(sal_uInt16 nId, const Sequence< Property Reference< XPropertySet > xSet(getRowSet(), UNO_QUERY); if ( xSet.is() ) { - xSet->setPropertyValue(PROPERTY_FILTER,makeAny(OUString())); - xSet->setPropertyValue(PROPERTY_HAVING_CLAUSE,makeAny(OUString())); - xSet->setPropertyValue(PROPERTY_ORDER,makeAny(OUString())); + xSet->setPropertyValue(PROPERTY_FILTER,Any(OUString())); + xSet->setPropertyValue(PROPERTY_HAVING_CLAUSE,Any(OUString())); + xSet->setPropertyValue(PROPERTY_ORDER,Any(OUString())); } try { @@ -2131,8 +2147,8 @@ bool SbaXDataBrowserController::SaveModified(bool bAskFor) { getBrowserView()->getVclControl()->GrabFocus(); - std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(getFrameWeld(), "dbaccess/ui/savemodifieddialog.ui")); - std::unique_ptr<weld::MessageDialog> xQry(xBuilder->weld_message_dialog("SaveModifiedDialog")); + std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(getFrameWeld(), u"dbaccess/ui/savemodifieddialog.ui"_ustr)); + std::unique_ptr<weld::MessageDialog> xQry(xBuilder->weld_message_dialog(u"SaveModifiedDialog"_ustr)); switch (xQry->run()) { case RET_NO: @@ -2179,16 +2195,12 @@ bool SbaXDataBrowserController::CommitCurrent() if (!getBrowserView()) return true; - Reference< css::awt::XControl > xActiveControl(getBrowserView()->getGridControl()); - Reference< css::form::XBoundControl > xLockingTest(xActiveControl, UNO_QUERY); + rtl::Reference< SbaXGridControl > xActiveControl(getBrowserView()->getGridControl()); + Reference< css::form::XBoundControl > xLockingTest(static_cast<cppu::OWeakObject*>(xActiveControl.get()), UNO_QUERY); bool bControlIsLocked = xLockingTest.is() && xLockingTest->getLock(); if (xActiveControl.is() && !bControlIsLocked) { - // At first check Control if it supports the IFace - Reference< css::form::XBoundComponent > xBoundControl(xActiveControl, UNO_QUERY); - if (!xBoundControl.is()) - xBoundControl.set(xActiveControl->getModel(), UNO_QUERY); - if (xBoundControl.is() && !xBoundControl->commit()) + if (!xActiveControl->commit()) return false; } return true; @@ -2260,7 +2272,7 @@ Reference< XPropertySet > SbaXDataBrowserController::getBoundField() const Reference< XPropertySet > xEmptyReturn; // get the current column from the grid - Reference< css::form::XGrid > xGrid(getBrowserView()->getGridControl(), UNO_QUERY); + rtl::Reference< SbaXGridControl > xGrid(getBrowserView()->getGridControl()); if (!xGrid.is()) return xEmptyReturn; sal_uInt16 nViewPos = xGrid->getCurrentColumnPosition(); @@ -2280,7 +2292,7 @@ Reference< XPropertySet > SbaXDataBrowserController::getBoundField() const IMPL_LINK(SbaXDataBrowserController, OnSearchContextRequest, FmSearchContext&, rContext, sal_uInt32) { - Reference< css::container::XIndexAccess > xPeerContainer(getBrowserView()->getGridControl(), UNO_QUERY); + rtl::Reference< SbaXGridControl > xPeerContainer(getBrowserView()->getGridControl()); // check all grid columns for their control source Reference< css::container::XIndexAccess > xModelColumns(getFormComponent(), UNO_QUERY); @@ -2335,9 +2347,9 @@ IMPL_LINK(SbaXDataBrowserController, OnFoundData, FmFoundRecordInformation&, rIn // let the grid sync its display with the cursor Reference< XPropertySet > xModelSet(getControlModel(), UNO_QUERY); OSL_ENSURE(xModelSet.is(), "SbaXDataBrowserController::OnFoundData : no model set ?!"); - Any aOld = xModelSet->getPropertyValue("DisplayIsSynchron"); - xModelSet->setPropertyValue("DisplayIsSynchron", css::uno::Any(true)); - xModelSet->setPropertyValue("DisplayIsSynchron", aOld); + Any aOld = xModelSet->getPropertyValue(u"DisplayIsSynchron"_ustr); + xModelSet->setPropertyValue(u"DisplayIsSynchron"_ustr, css::uno::Any(true)); + xModelSet->setPropertyValue(u"DisplayIsSynchron"_ustr, aOld); // and move to the field Reference< css::container::XIndexAccess > aColumnControls(getBrowserView()->getGridControl()->getPeer(), UNO_QUERY); @@ -2355,7 +2367,7 @@ IMPL_LINK(SbaXDataBrowserController, OnFoundData, FmFoundRecordInformation&, rIn } } - Reference< css::form::XGrid > xGrid(getBrowserView()->getGridControl(), UNO_QUERY); + rtl::Reference< SbaXGridControl > xGrid(getBrowserView()->getGridControl()); xGrid->setCurrentColumnPosition(nViewPos); //TODO: sal_Int32 -> sal_Int16! } @@ -2379,9 +2391,9 @@ IMPL_LINK(SbaXDataBrowserController, OnCanceledNotFound, FmFoundRecordInformatio // let the grid sync its display with the cursor Reference< XPropertySet > xModelSet(getControlModel(), UNO_QUERY); OSL_ENSURE(xModelSet.is(), "SbaXDataBrowserController::OnCanceledNotFound : no model set ?!"); - Any aOld = xModelSet->getPropertyValue("DisplayIsSynchron"); - xModelSet->setPropertyValue("DisplayIsSynchron", css::uno::Any(true)); - xModelSet->setPropertyValue("DisplayIsSynchron", aOld); + Any aOld = xModelSet->getPropertyValue(u"DisplayIsSynchron"_ustr); + xModelSet->setPropertyValue(u"DisplayIsSynchron"_ustr, css::uno::Any(true)); + xModelSet->setPropertyValue(u"DisplayIsSynchron"_ustr, aOld); } catch( const Exception& ) { @@ -2540,7 +2552,7 @@ bool SbaXDataBrowserController::isValidCursor() const sal_Int16 SbaXDataBrowserController::getCurrentColumnPosition() const { - Reference< css::form::XGrid > xGrid(getBrowserView()->getGridControl(), UNO_QUERY); + rtl::Reference< SbaXGridControl > xGrid(getBrowserView()->getGridControl()); sal_Int16 nViewPos = -1; try { @@ -2553,7 +2565,7 @@ sal_Int16 SbaXDataBrowserController::getCurrentColumnPosition() const void SbaXDataBrowserController::setCurrentColumnPosition( sal_Int16 _nPos ) { - Reference< css::form::XGrid > xGrid(getBrowserView()->getGridControl(), UNO_QUERY); + rtl::Reference< SbaXGridControl > xGrid(getBrowserView()->getGridControl()); try { if ( -1 != _nPos ) diff --git a/dbaccess/source/ui/browser/brwview.cxx b/dbaccess/source/ui/browser/brwview.cxx index 258c3966cee9..6a15ce0fca39 100644 --- a/dbaccess/source/ui/browser/brwview.cxx +++ b/dbaccess/source/ui/browser/brwview.cxx @@ -21,7 +21,6 @@ #include <sbagrid.hxx> #include <toolkit/helper/vclunohelper.hxx> #include <comphelper/types.hxx> -#include <vcl/fixed.hxx> #include <vcl/split.hxx> #include <strings.hxx> #include <com/sun/star/form/XLoadable.hpp> @@ -33,7 +32,6 @@ using namespace dbaui; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::sdb; using namespace ::com::sun::star::form; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::container; @@ -45,7 +43,7 @@ namespace { bool bGrabFocus = false; SbaGridControl* pVclControl = _pView->getVclControl(); - const Reference< css::awt::XControl >& xGrid = _pView->getGridControl(); + const rtl::Reference< SbaXGridControl > xGrid = _pView->getGridControl(); if (pVclControl && xGrid.is()) { bGrabFocus = true; @@ -71,7 +69,6 @@ UnoDataBrowserView::UnoDataBrowserView( vcl::Window* pParent, ,m_pTreeView(nullptr) ,m_pSplitter(nullptr) ,m_pVclControl(nullptr) - ,m_pStatus(nullptr) { } @@ -90,10 +87,8 @@ void UnoDataBrowserView::Construct(const Reference< css::awt::XControlModel >& x OSL_ENSURE(m_xGrid.is(), "UnoDataBrowserView::Construct : could not create a grid control !"); // in design mode (for the moment) m_xGrid->setDesignMode(true); - - Reference< css::awt::XWindow > xGridWindow(m_xGrid, UNO_QUERY); - xGridWindow->setVisible(true); - xGridWindow->setEnable(true); + m_xGrid->setVisible(true); + m_xGrid->setEnable(true); // introduce the model to the grid m_xGrid->setModel(xModel); @@ -124,8 +119,6 @@ void UnoDataBrowserView::dispose() m_pSplitter.disposeAndClear(); setTreeView(nullptr); - m_pStatus.disposeAndClear(); - try { ::comphelper::disposeComponent(m_xGrid); @@ -133,8 +126,8 @@ void UnoDataBrowserView::dispose() } catch(const Exception&) {} - m_pTreeView.clear(); - m_pVclControl.clear(); + m_pTreeView.reset(); + m_pVclControl.reset(); ODataView::dispose(); } @@ -167,10 +160,11 @@ void UnoDataBrowserView::showStatus( const OUString& _rStatus ) hideStatus(); else { - if (!m_pStatus) - m_pStatus = VclPtr<FixedText>::Create(this); - m_pStatus->SetText(_rStatus); - m_pStatus->Show(); + if (!m_pTreeView) + return; + weld::Label& rLabel = m_pTreeView->GetStatusBar(); + rLabel.set_label(_rStatus); + rLabel.show(); Resize(); PaintImmediately(); } @@ -178,10 +172,15 @@ void UnoDataBrowserView::showStatus( const OUString& _rStatus ) void UnoDataBrowserView::hideStatus() { - if (!m_pStatus || !m_pStatus->IsVisible()) + if (!m_pTreeView) + return; + weld::Label& rLabel = m_pTreeView->GetStatusBar(); + if (!rLabel.get_visible()) + { // nothing to do return; - m_pStatus->Hide(); + } + rLabel.hide(); Resize(); PaintImmediately(); } @@ -211,20 +210,12 @@ void UnoDataBrowserView::resizeDocumentView(tools::Rectangle& _rPlayground) Point aTreeViewPos( aPlaygroundPos ); Size aTreeViewSize( aSplitPos.X(), aPlaygroundSize.Height() ); - // the status pos and size - if (m_pStatus && m_pStatus->IsVisible()) - { - Size aStatusSize(aPlaygroundPos.X(), GetTextHeight() + 2); - aStatusSize = LogicToPixel(aStatusSize, MapMode(MapUnit::MapAppFont)); - aStatusSize.setWidth( aTreeViewSize.Width() - 2 - 2 ); - - Point aStatusPos( aPlaygroundPos.X() + 2, aTreeViewPos.Y() + aTreeViewSize.Height() - aStatusSize.Height() ); - m_pStatus->SetPosSizePixel( aStatusPos, aStatusSize ); - aTreeViewSize.AdjustHeight( -(aStatusSize.Height()) ); - } - // set the size of treelistbox m_pTreeView->SetPosSizePixel( aTreeViewPos, aTreeViewSize ); + // Call this to trigger InterimItemWindow::Layout immediately, and + // not later on idle so the statusbar will be shown to explain + // a long delay on opening databases + m_pTreeView->Resize(); //set the size of the splitter m_pSplitter->SetPosSizePixel( aSplitPos, Size( aSplitSize.Width(), aPlaygroundSize.Height() ) ); @@ -232,9 +223,8 @@ void UnoDataBrowserView::resizeDocumentView(tools::Rectangle& _rPlayground) } // set the size of grid control - Reference< css::awt::XWindow > xGridAsWindow(m_xGrid, UNO_QUERY); - if (xGridAsWindow.is()) - xGridAsWindow->setPosSize( aSplitPos.X() + aSplitSize.Width(), aPlaygroundPos.Y(), + if (m_xGrid.is()) + m_xGrid->setPosSize( aSplitPos.X() + aSplitSize.Width(), aPlaygroundPos.Y(), aPlaygroundSize.Width() - aSplitSize.Width() - aSplitPos.X(), aPlaygroundSize.Height(), css::awt::PosSize::POSSIZE); // just for completeness: there is no space left, we occupied it all ... @@ -257,11 +247,11 @@ SbaGridControl* UnoDataBrowserView::getVclControl() const Reference< css::awt::XWindowPeer > xPeer = m_xGrid->getPeer(); if ( xPeer.is() ) { - SbaXGridPeer* pPeer = comphelper::getUnoTunnelImplementation<SbaXGridPeer>(xPeer); + SbaXGridPeer* pPeer = dynamic_cast<SbaXGridPeer*>(xPeer.get()); UnoDataBrowserView* pTHIS = const_cast<UnoDataBrowserView*>(this); if ( pPeer ) { - m_pVclControl = static_cast<SbaGridControl*>(pPeer->GetWindow().get()); + m_pVclControl = static_cast<SbaGridControl*>(pPeer->GetWindow()); pTHIS->startComponentListening(VCLUnoHelper::GetInterface(m_pVclControl)); } } @@ -298,7 +288,7 @@ void UnoDataBrowserView::_disposing( const css::lang::EventObject& /*_rSource*/ bool UnoDataBrowserView::PreNotify( NotifyEvent& rNEvt ) { bool bDone = false; - if(rNEvt.GetType() == MouseNotifyEvent::KEYINPUT) + if(rNEvt.GetType() == NotifyEventType::KEYINPUT) { bool bGrabAllowed = isGrabVclControlFocusAllowed(this); if ( bGrabAllowed ) diff --git a/dbaccess/source/ui/browser/dataview.cxx b/dbaccess/source/ui/browser/dataview.cxx index b48a3f0adb17..11f9a91df015 100644 --- a/dbaccess/source/ui/browser/dataview.cxx +++ b/dbaccess/source/ui/browser/dataview.cxx @@ -23,16 +23,14 @@ #include <comphelper/namedvaluecollection.hxx> #include <dbaccess/IController.hxx> #include <svtools/acceleratorexecute.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <vcl/event.hxx> #include <vcl/settings.hxx> namespace dbaui { using namespace ::com::sun::star::uno; - using namespace ::com::sun::star::beans; using namespace ::com::sun::star::util; - using namespace ::com::sun::star::lang; using namespace ::com::sun::star::frame; ODataView::ODataView( vcl::Window* pParent, @@ -70,8 +68,8 @@ namespace dbaui { // draw the background { - rRenderContext.Push(PushFlags::LINECOLOR | PushFlags::FILLCOLOR); - rRenderContext.SetLineColor(COL_TRANSPARENT); + rRenderContext.Push(vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR); + rRenderContext.SetLineColor(); rRenderContext.SetFillColor(GetSettings().GetStyleSettings().GetFaceColor()); rRenderContext.DrawRect(_rRect); rRenderContext.Pop(); @@ -98,7 +96,7 @@ namespace dbaui bool bHandled = false; switch ( _rNEvt.GetType() ) { - case MouseNotifyEvent::KEYINPUT: + case NotifyEventType::KEYINPUT: { const KeyEvent* pKeyEvent = _rNEvt.GetKeyEvent(); const vcl::KeyCode& aKeyCode = pKeyEvent->GetKeyCode(); @@ -107,9 +105,9 @@ namespace dbaui return true; [[fallthrough]]; } - case MouseNotifyEvent::KEYUP: - case MouseNotifyEvent::MOUSEBUTTONDOWN: - case MouseNotifyEvent::MOUSEBUTTONUP: + case NotifyEventType::KEYUP: + case NotifyEventType::MOUSEBUTTONDOWN: + case NotifyEventType::MOUSEBUTTONUP: bHandled = m_xController->interceptUserInput( _rNEvt ); break; default: @@ -133,7 +131,7 @@ namespace dbaui if ( xModel.is() ) { ::comphelper::NamedValueCollection aArgs( xModel->getArgs() ); - aArgs.remove( "Hidden" ); + aArgs.remove( u"Hidden"_ustr ); xModel->attachResource( xModel->getURL(), aArgs.getPropertyValues() ); } } diff --git a/dbaccess/source/ui/browser/dbexchange.cxx b/dbaccess/source/ui/browser/dbexchange.cxx index d9358ec776ad..dc318dc0f61c 100644 --- a/dbaccess/source/ui/browser/dbexchange.cxx +++ b/dbaccess/source/ui/browser/dbexchange.cxx @@ -140,14 +140,14 @@ namespace dbaui osl_atomic_decrement( &m_refCount ); } - bool ODataClipboard::WriteObject( ::tools::SvRef<SotStorageStream>& rxOStm, void* pUserObject, sal_uInt32 nUserObjectId, const css::datatransfer::DataFlavor& /*rFlavor*/ ) + bool ODataClipboard::WriteObject( SvStream& rOStm, void* pUserObject, sal_uInt32 nUserObjectId, const css::datatransfer::DataFlavor& /*rFlavor*/ ) { if (nUserObjectId == FORMAT_OBJECT_ID_RTF || nUserObjectId == FORMAT_OBJECT_ID_HTML ) { ODatabaseImportExport* pExport = static_cast<ODatabaseImportExport*>(pUserObject); - if ( pExport && rxOStm.is() ) + if ( pExport ) { - pExport->setStream(rxOStm.get()); + pExport->setStream(&rOStm); return pExport->Write(); } } diff --git a/dbaccess/source/ui/browser/dbloader.cxx b/dbaccess/source/ui/browser/dbloader.cxx index 4f85ca5bc2bc..ba4e206d446c 100644 --- a/dbaccess/source/ui/browser/dbloader.cxx +++ b/dbaccess/source/ui/browser/dbloader.cxx @@ -26,21 +26,19 @@ #include <com/sun/star/frame/XFrameLoader.hpp> #include <com/sun/star/frame/XLoadEventListener.hpp> #include <com/sun/star/lang/XInitialization.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/lang/XSingleServiceFactory.hpp> #include <com/sun/star/sdb/ReportDesign.hpp> #include <com/sun/star/sdbc/XConnection.hpp> #include <com/sun/star/frame/XModule.hpp> #include <com/sun/star/sdbc/XDataSource.hpp> #include <comphelper/namedvaluecollection.hxx> -#include <comphelper/processfactory.hxx> #include <comphelper/types.hxx> #include <cppuhelper/implbase.hxx> #include <cppuhelper/supportsservice.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <tools/urlobj.hxx> +#include <unotools/fcm.hxx> #include <vcl/svapp.hxx> using namespace ::com::sun::star; @@ -94,7 +92,7 @@ org_openoffice_comp_dbu_DBContentLoader_get_implementation( // XServiceInfo OUString SAL_CALL DBContentLoader::getImplementationName() { - return "org.openoffice.comp.dbu.DBContentLoader"; + return u"org.openoffice.comp.dbu.DBContentLoader"_ustr; } // XServiceInfo @@ -106,7 +104,7 @@ sal_Bool SAL_CALL DBContentLoader::supportsService(const OUString& ServiceName) // XServiceInfo Sequence< OUString > SAL_CALL DBContentLoader::getSupportedServiceNames() { - return { "com.sun.star.frame.FrameLoader", "com.sun.star.sdb.ContentLoader" }; + return { u"com.sun.star.frame.FrameLoader"_ustr, u"com.sun.star.sdb.ContentLoader"_ustr }; } void SAL_CALL DBContentLoader::load(const Reference< XFrame > & rFrame, const OUString& rURL, @@ -116,22 +114,17 @@ void SAL_CALL DBContentLoader::load(const Reference< XFrame > & rFrame, const OU m_xListener = rListener; m_aArgs = rArgs; - static const struct ServiceNameToImplName + static constexpr struct ServiceNameToImplName { - const char* pAsciiServiceName; - const char* pAsciiImplementationName; - ServiceNameToImplName( const char* _pService, const char* _pImpl ) - :pAsciiServiceName( _pService ) - ,pAsciiImplementationName( _pImpl ) - { - } + OUString sServiceName; + OUString aAsciiImplementationName; } aImplementations[] = { - ServiceNameToImplName( URL_COMPONENT_FORMGRIDVIEW, "org.openoffice.comp.dbu.OFormGridView" ), - ServiceNameToImplName( URL_COMPONENT_DATASOURCEBROWSER, "org.openoffice.comp.dbu.ODatasourceBrowser" ), - ServiceNameToImplName( URL_COMPONENT_QUERYDESIGN, "org.openoffice.comp.dbu.OQueryDesign" ), - ServiceNameToImplName( URL_COMPONENT_TABLEDESIGN, "org.openoffice.comp.dbu.OTableDesign" ), - ServiceNameToImplName( URL_COMPONENT_RELATIONDESIGN, "org.openoffice.comp.dbu.ORelationDesign" ), - ServiceNameToImplName( URL_COMPONENT_VIEWDESIGN, "org.openoffice.comp.dbu.OViewDesign" ) + { URL_COMPONENT_FORMGRIDVIEW, u"org.openoffice.comp.dbu.OFormGridView"_ustr }, + { URL_COMPONENT_DATASOURCEBROWSER, u"org.openoffice.comp.dbu.ODatasourceBrowser"_ustr }, + { URL_COMPONENT_QUERYDESIGN, u"org.openoffice.comp.dbu.OQueryDesign"_ustr }, + { URL_COMPONENT_TABLEDESIGN, u"org.openoffice.comp.dbu.OTableDesign"_ustr }, + { URL_COMPONENT_RELATIONDESIGN, u"org.openoffice.comp.dbu.ORelationDesign"_ustr }, + { URL_COMPONENT_VIEWDESIGN, u"org.openoffice.comp.dbu.OViewDesign"_ustr } }; INetURLObject aParser( rURL ); @@ -140,10 +133,10 @@ void SAL_CALL DBContentLoader::load(const Reference< XFrame > & rFrame, const OU const OUString sComponentURL( aParser.GetMainURL( INetURLObject::DecodeMechanism::ToIUri ) ); for (const ServiceNameToImplName& aImplementation : aImplementations) { - if ( sComponentURL.equalsAscii( aImplementation.pAsciiServiceName ) ) + if ( sComponentURL == aImplementation.sServiceName ) { xController.set( m_xContext->getServiceManager()-> - createInstanceWithContext( OUString::createFromAscii( aImplementation.pAsciiImplementationName ), m_xContext), UNO_QUERY_THROW ); + createInstanceWithContext( aImplementation.aAsciiImplementationName, m_xContext), UNO_QUERY_THROW ); break; } } @@ -155,7 +148,7 @@ void SAL_CALL DBContentLoader::load(const Reference< XFrame > & rFrame, const OU if ( sComponentURL == URL_COMPONENT_DATASOURCEBROWSER ) { - bool bDisableBrowser = !aLoadArgs.getOrDefault( "ShowTreeViewButton", true ) // compatibility name + bool bDisableBrowser = !aLoadArgs.getOrDefault( u"ShowTreeViewButton"_ustr, true ) // compatibility name || !aLoadArgs.getOrDefault( PROPERTY_ENABLE_BROWSER, true ); if ( bDisableBrowser ) @@ -163,7 +156,7 @@ void SAL_CALL DBContentLoader::load(const Reference< XFrame > & rFrame, const OU try { Reference< XModule > xModule( xController, UNO_QUERY_THROW ); - xModule->setIdentifier( "com.sun.star.sdb.TableDataView" ); + xModule->setIdentifier( u"com.sun.star.sdb.TableDataView"_ustr ); } catch( const Exception& ) { @@ -174,20 +167,18 @@ void SAL_CALL DBContentLoader::load(const Reference< XFrame > & rFrame, const OU if ( sComponentURL == URL_COMPONENT_REPORTDESIGN ) { - bool bPreview = aLoadArgs.getOrDefault( "Preview", false ); + bool bPreview = aLoadArgs.getOrDefault( u"Preview"_ustr, false ); if ( bPreview ) { // report designs cannot be previewed if ( rListener.is() ) rListener->loadCancelled( this ); return; } - Reference< XModel > xReportModel( aLoadArgs.getOrDefault( "Model", Reference< XModel >() ) ); + Reference< XModel > xReportModel( aLoadArgs.getOrDefault( u"Model"_ustr, Reference< XModel >() ) ); if ( xReportModel.is() ) { xController.set( ReportDesign::create( m_xContext ) ); - xController->attachModel( xReportModel ); - xReportModel->connectController( xController.get() ); - xReportModel->setCurrentController( xController.get() ); + utl::ConnectModelController(xReportModel, xController); } } @@ -195,9 +186,9 @@ void SAL_CALL DBContentLoader::load(const Reference< XFrame > & rFrame, const OU Reference< XModel > xDatabaseDocument; if ( bSuccess ) { - Reference< XDataSource > xDataSource ( aLoadArgs.getOrDefault( "DataSource", Reference< XDataSource >() ) ); - OUString sDataSourceName( aLoadArgs.getOrDefault( "DataSourceName", OUString() ) ); - Reference< XConnection > xConnection ( aLoadArgs.getOrDefault( "ActiveConnection", Reference< XConnection >() ) ); + Reference< XDataSource > xDataSource ( aLoadArgs.getOrDefault( u"DataSource"_ustr, Reference< XDataSource >() ) ); + OUString sDataSourceName( aLoadArgs.getOrDefault( u"DataSourceName"_ustr, OUString() ) ); + Reference< XConnection > xConnection ( aLoadArgs.getOrDefault( u"ActiveConnection"_ustr, Reference< XConnection >() ) ); if ( xDataSource.is() ) { xDatabaseDocument.set( getDataSourceOrModel( xDataSource ), UNO_QUERY ); @@ -224,17 +215,13 @@ void SAL_CALL DBContentLoader::load(const Reference< XFrame > & rFrame, const OU try { Reference<XInitialization > xIni(xController,UNO_QUERY); - PropertyValue aFrame("Frame",0,makeAny(rFrame),PropertyState_DIRECT_VALUE); + PropertyValue aFrame(u"Frame"_ustr,0,Any(rFrame),PropertyState_DIRECT_VALUE); Sequence< Any > aInitArgs(m_aArgs.getLength()+1); Any* pBegin = aInitArgs.getArray(); - Any* pEnd = pBegin + aInitArgs.getLength(); *pBegin <<= aFrame; - const PropertyValue* pIter = m_aArgs.getConstArray(); - for(++pBegin;pBegin != pEnd;++pBegin,++pIter) - { - *pBegin <<= *pIter; - } + std::transform(m_aArgs.begin(), m_aArgs.end(), ++pBegin, + [](auto& val) { return Any(val); }); xIni->initialize(aInitArgs); } @@ -258,7 +245,7 @@ void SAL_CALL DBContentLoader::load(const Reference< XFrame > & rFrame, const OU { if ( xController.is() && rFrame.is() ) { - rFrame->setComponent( xController->getComponentWindow(), xController.get() ); + rFrame->setComponent( xController->getComponentWindow(), xController ); xController->attachFrame(rFrame); } diff --git a/dbaccess/source/ui/browser/dbtreemodel.hxx b/dbaccess/source/ui/browser/dbtreemodel.hxx index 2ea11b900975..55b1a3cffcc9 100644 --- a/dbaccess/source/ui/browser/dbtreemodel.hxx +++ b/dbaccess/source/ui/browser/dbtreemodel.hxx @@ -29,11 +29,6 @@ // tables holds the nameaccess for the tables // table holds the table -#define CONTAINER_QUERIES sal_uLong( 0 ) -#define CONTAINER_TABLES sal_uLong( 1 ) - -namespace com::sun::star::lang { class XMultiServiceFactory; } - namespace dbaui { struct DBTreeListUserData diff --git a/dbaccess/source/ui/browser/dsEntriesNoExp.cxx b/dbaccess/source/ui/browser/dsEntriesNoExp.cxx index d98f9dedadc2..f2c4dc949c64 100644 --- a/dbaccess/source/ui/browser/dsEntriesNoExp.cxx +++ b/dbaccess/source/ui/browser/dsEntriesNoExp.cxx @@ -23,14 +23,11 @@ #include <unodatbr.hxx> #include <browserids.hxx> -#include <imageprovider.hxx> #include <osl/diagnose.h> #include <dbtreelistbox.hxx> #include "dbtreemodel.hxx" using namespace ::com::sun::star::frame; -using namespace ::dbtools; -using namespace ::svx; namespace dbaui { @@ -56,59 +53,9 @@ OUString SbaTableQueryBrowser::GetEntryText(const weld::TreeIter& rEntry) const SbaTableQueryBrowser::EntryType SbaTableQueryBrowser::getEntryType(const weld::TreeIter& rEntry) const { - std::unique_ptr<weld::TreeIter> xRootEntry = m_pTreeView->GetRootLevelParent(&rEntry); - weld::TreeView& rTreeView = m_pTreeView->GetWidget(); - - if (rTreeView.iter_compare(*xRootEntry, rEntry) == 0) - return etDatasource; - - std::unique_ptr<weld::TreeIter> xEntryParent(rTreeView.make_iterator(&rEntry)); - if (!rTreeView.iter_parent(*xEntryParent)) - xEntryParent.reset(); - - std::unique_ptr<weld::TreeIter> xTables; - std::unique_ptr<weld::TreeIter> xQueries; - - std::unique_ptr<weld::TreeIter> xContainer = rTreeView.make_iterator(xRootEntry.get()); - if (rTreeView.iter_children(*xContainer)) - { - // 1st child is queries - xQueries = rTreeView.make_iterator(xContainer.get()); - - if (rTreeView.iter_next_sibling(*xContainer)) - { - // 2nd child is tables - xTables = rTreeView.make_iterator(xContainer.get()); - } - } - - if (xTables && rTreeView.iter_compare(*xTables, rEntry) == 0) - return etTableContainer; - - if (xQueries && rTreeView.iter_compare(*xQueries, rEntry) == 0) - return etQueryContainer; - - if (xTables && xEntryParent && rTreeView.iter_compare(*xTables, *xEntryParent) == 0) - return etTableOrView; - - if (xQueries && xEntryParent) - { - if (rTreeView.iter_compare(*xQueries, *xEntryParent) == 0) - { - DBTreeListUserData* pEntryData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(rEntry).toUInt64()); - if (pEntryData) - return pEntryData->eType; - return etQuery; - } - - while (rTreeView.iter_compare(*xEntryParent, *xQueries) != 0) - { - if (!rTreeView.iter_parent(*xEntryParent)) - return etUnknown; - } - } - - return etQueryContainer; + const weld::TreeView& rTreeView = m_pTreeView->GetWidget(); + DBTreeListUserData* pEntryData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(rEntry)); + return pEntryData ? pEntryData->eType : etUnknown; } void SbaTableQueryBrowser::select(const weld::TreeIter* pEntry, bool bSelect) @@ -159,28 +106,28 @@ void SbaTableQueryBrowser::describeSupportedFeatures() { SbaXDataBrowserController::describeSupportedFeatures(); - implDescribeSupportedFeature( ".uno:Title", ID_BROWSER_TITLE ); + implDescribeSupportedFeature( u".uno:Title"_ustr, ID_BROWSER_TITLE ); if ( !m_bShowMenu ) { - implDescribeSupportedFeature( ".uno:DSBEditDB", ID_TREE_EDIT_DATABASE ); - implDescribeSupportedFeature( ".uno:DSBCloseConnection", ID_TREE_CLOSE_CONN ); - implDescribeSupportedFeature( ".uno:DSBAdministrate", ID_TREE_ADMINISTRATE ); + implDescribeSupportedFeature( u".uno:DSBEditDB"_ustr, ID_TREE_EDIT_DATABASE ); + implDescribeSupportedFeature( u".uno:DSBCloseConnection"_ustr, ID_TREE_CLOSE_CONN ); + implDescribeSupportedFeature( u".uno:DSBAdministrate"_ustr, ID_TREE_ADMINISTRATE ); - implDescribeSupportedFeature( ".uno:DSBrowserExplorer", ID_BROWSER_EXPLORER, CommandGroup::VIEW ); + implDescribeSupportedFeature( u".uno:DSBrowserExplorer"_ustr, ID_BROWSER_EXPLORER, CommandGroup::VIEW ); - implDescribeSupportedFeature( ".uno:DSBFormLetter", ID_BROWSER_FORMLETTER, CommandGroup::DOCUMENT ); - implDescribeSupportedFeature( ".uno:DSBInsertColumns", ID_BROWSER_INSERTCOLUMNS, CommandGroup::INSERT ); - implDescribeSupportedFeature( ".uno:DSBInsertContent", ID_BROWSER_INSERTCONTENT, CommandGroup::INSERT ); - implDescribeSupportedFeature( ".uno:DSBDocumentDataSource", ID_BROWSER_DOCUMENT_DATASOURCE, CommandGroup::VIEW ); + implDescribeSupportedFeature( u".uno:DSBFormLetter"_ustr, ID_BROWSER_FORMLETTER, CommandGroup::DOCUMENT ); + implDescribeSupportedFeature( u".uno:DSBInsertColumns"_ustr, ID_BROWSER_INSERTCOLUMNS, CommandGroup::INSERT ); + implDescribeSupportedFeature( u".uno:DSBInsertContent"_ustr, ID_BROWSER_INSERTCONTENT, CommandGroup::INSERT ); + implDescribeSupportedFeature( u".uno:DSBDocumentDataSource"_ustr, ID_BROWSER_DOCUMENT_DATASOURCE, CommandGroup::VIEW ); - implDescribeSupportedFeature( ".uno:DataSourceBrowser/FormLetter", ID_BROWSER_FORMLETTER ); - implDescribeSupportedFeature( ".uno:DataSourceBrowser/InsertColumns", ID_BROWSER_INSERTCOLUMNS ); - implDescribeSupportedFeature( ".uno:DataSourceBrowser/InsertContent", ID_BROWSER_INSERTCONTENT ); - implDescribeSupportedFeature( ".uno:DataSourceBrowser/DocumentDataSource", ID_BROWSER_DOCUMENT_DATASOURCE ); + implDescribeSupportedFeature( u".uno:DataSourceBrowser/FormLetter"_ustr, ID_BROWSER_FORMLETTER ); + implDescribeSupportedFeature( u".uno:DataSourceBrowser/InsertColumns"_ustr, ID_BROWSER_INSERTCOLUMNS ); + implDescribeSupportedFeature( u".uno:DataSourceBrowser/InsertContent"_ustr, ID_BROWSER_INSERTCONTENT ); + implDescribeSupportedFeature( u".uno:DataSourceBrowser/DocumentDataSource"_ustr, ID_BROWSER_DOCUMENT_DATASOURCE ); } - implDescribeSupportedFeature( ".uno:CloseWin", ID_BROWSER_CLOSE, CommandGroup::DOCUMENT ); - implDescribeSupportedFeature( ".uno:DBRebuildData", ID_BROWSER_REFRESH_REBUILD, CommandGroup::DATA ); + implDescribeSupportedFeature( u".uno:CloseWin"_ustr, ID_BROWSER_CLOSE, CommandGroup::DOCUMENT ); + implDescribeSupportedFeature( u".uno:DBRebuildData"_ustr, ID_BROWSER_REFRESH_REBUILD, CommandGroup::DATA ); } sal_Int32 SbaTableQueryBrowser::getDatabaseObjectType( EntryType _eType ) diff --git a/dbaccess/source/ui/browser/dsbrowserDnD.cxx b/dbaccess/source/ui/browser/dsbrowserDnD.cxx index 7d51a5abf8fb..774f43b4c7a4 100644 --- a/dbaccess/source/ui/browser/dsbrowserDnD.cxx +++ b/dbaccess/source/ui/browser/dsbrowserDnD.cxx @@ -31,7 +31,7 @@ #include <connectivity/dbtools.hxx> #include <cppuhelper/exc_hlp.hxx> #include <svx/dataaccessdescriptor.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <osl/diagnose.h> #include <vcl/svapp.hxx> @@ -43,16 +43,8 @@ namespace dbaui using namespace ::com::sun::star::uno; using namespace ::com::sun::star::sdb; using namespace ::com::sun::star::sdbc; - using namespace ::com::sun::star::sdbcx; - using namespace ::com::sun::star::beans; - using namespace ::com::sun::star::util; using namespace ::com::sun::star::frame; using namespace ::com::sun::star::container; - using namespace ::com::sun::star::lang; - using namespace ::com::sun::star::form; - using namespace ::com::sun::star::io; - using namespace ::com::sun::star::i18n; - using namespace ::com::sun::star::task; using namespace ::com::sun::star::datatransfer; using namespace ::dbtools; using namespace ::svx; @@ -232,7 +224,7 @@ namespace dbaui weld::TreeView& rTreeView = m_pTreeView->GetWidget(); rTreeView.all_foreach([this, &rTreeView](weld::TreeIter& rEntryLoop){ // clear the user data of the tree model - DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(rEntryLoop).toUInt64()); + DBTreeListUserData* pData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(rEntryLoop)); if (pData) { rTreeView.set_id(rEntryLoop, OUString()); diff --git a/dbaccess/source/ui/browser/exsrcbrw.cxx b/dbaccess/source/ui/browser/exsrcbrw.cxx index 966ab8b90859..ffcf40e3c91d 100644 --- a/dbaccess/source/ui/browser/exsrcbrw.cxx +++ b/dbaccess/source/ui/browser/exsrcbrw.cxx @@ -23,14 +23,12 @@ #include <com/sun/star/form/XLoadable.hpp> #include <com/sun/star/frame/FrameSearchFlag.hpp> #include <formadapter.hxx> -#include <comphelper/processfactory.hxx> #include <strings.hxx> #include <o3tl/any.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <sal/log.hxx> using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::sdb; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::beans; @@ -62,7 +60,6 @@ Any SAL_CALL SbaExternalSourceBrowser::queryInterface(const Type& _rType) SbaExternalSourceBrowser::SbaExternalSourceBrowser(const Reference< css::uno::XComponentContext >& _rM) :SbaXDataBrowserController(_rM) ,m_aModifyListeners(getMutex()) - ,m_pDataSourceImpl(nullptr) ,m_bInQueryDispatch( false ) { @@ -74,12 +71,12 @@ SbaExternalSourceBrowser::~SbaExternalSourceBrowser() css::uno::Sequence<OUString> SAL_CALL SbaExternalSourceBrowser::getSupportedServiceNames() { - return { "com.sun.star.sdb.FormGridView" }; + return { u"com.sun.star.sdb.FormGridView"_ustr }; } OUString SAL_CALL SbaExternalSourceBrowser::getImplementationName() { - return "org.openoffice.comp.dbu.OFormGridView"; + return u"org.openoffice.comp.dbu.OFormGridView"_ustr; } Reference< XRowSet > SbaExternalSourceBrowser::CreateForm() @@ -106,9 +103,7 @@ void SbaExternalSourceBrowser::modified(const css::lang::EventObject& aEvent) // multiplex this event to all my listeners css::lang::EventObject aEvt(*this); - ::comphelper::OInterfaceIteratorHelper2 aIt(m_aModifyListeners); - while (aIt.hasMoreElements()) - static_cast< css::util::XModifyListener*>(aIt.next())->modified(aEvt); + m_aModifyListeners.notifyEach( &css::util::XModifyListener::modified, aEvt ); } void SAL_CALL SbaExternalSourceBrowser::dispatch(const css::util::URL& aURL, const Sequence< css::beans::PropertyValue>& aArgs) @@ -162,7 +157,7 @@ void SAL_CALL SbaExternalSourceBrowser::dispatch(const css::util::URL& aURL, con // set its properties if (xNewColProperties.is()) { - for (const css::beans::PropertyValue& rControlProp : std::as_const(aControlProps)) + for (const css::beans::PropertyValue& rControlProp : aControlProps) { try { @@ -185,7 +180,7 @@ void SAL_CALL SbaExternalSourceBrowser::dispatch(const css::util::URL& aURL, con nControlPos = 0; // append the column - xColContainer->insertByIndex(nControlPos, makeAny(xNewCol)); + xColContainer->insertByIndex(nControlPos, Any(xNewCol)); } else if ( aURL.Complete == ".uno:FormSlots/ClearView" ) { diff --git a/dbaccess/source/ui/browser/formadapter.cxx b/dbaccess/source/ui/browser/formadapter.cxx index 9620d5840a34..e0288c51dc38 100644 --- a/dbaccess/source/ui/browser/formadapter.cxx +++ b/dbaccess/source/ui/browser/formadapter.cxx @@ -89,13 +89,42 @@ Any SAL_CALL SbaXFormAdapter::queryInterface(const Type& _rType) void SbaXFormAdapter::StopListening() { // log off all our multiplexers - STOP_MULTIPLEXER_LISTENING(LoadListener, m_aLoadListeners, css::form::XLoadable, m_xMainForm); - STOP_MULTIPLEXER_LISTENING(RowSetListener, m_aRowSetListeners, css::sdbc::XRowSet, m_xMainForm); - STOP_MULTIPLEXER_LISTENING(RowSetApproveListener, m_aRowSetApproveListeners, css::sdb::XRowSetApproveBroadcaster, m_xMainForm); - STOP_MULTIPLEXER_LISTENING(SQLErrorListener, m_aErrorListeners, css::sdb::XSQLErrorBroadcaster, m_xMainForm); - STOP_MULTIPLEXER_LISTENING(SubmitListener, m_aSubmitListeners, css::form::XSubmit, m_xMainForm); - STOP_MULTIPLEXER_LISTENING(ResetListener, m_aResetListeners, css::form::XReset, m_xMainForm); - + if (m_aLoadListeners.getLength()) + { + css::uno::Reference< css::form::XLoadable > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->removeLoadListener(&m_aLoadListeners); + } + if (m_aRowSetListeners.getLength()) + { + css::uno::Reference< css::sdbc::XRowSet > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->removeRowSetListener(&m_aRowSetListeners); + } + if (m_aRowSetApproveListeners.getLength()) + { + css::uno::Reference< css::sdb::XRowSetApproveBroadcaster > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->removeRowSetApproveListener(&m_aRowSetApproveListeners); + } + if (m_aErrorListeners.getLength()) + { + css::uno::Reference< css::sdb::XSQLErrorBroadcaster > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->removeSQLErrorListener(&m_aErrorListeners); + } + if (m_aSubmitListeners.getLength()) + { + css::uno::Reference< css::form::XSubmit > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->removeSubmitListener(&m_aSubmitListeners); + } + if (m_aResetListeners.getLength()) + { + css::uno::Reference< css::form::XReset > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->removeResetListener(&m_aResetListeners); + } if (m_aParameterListeners.getLength()) { Reference< css::form::XDatabaseParameterBroadcaster > xBroadcaster(m_xMainForm, UNO_QUERY); @@ -103,8 +132,20 @@ void SbaXFormAdapter::StopListening() xBroadcaster->removeParameterListener(&m_aParameterListeners); } - STOP_PROPERTY_MULTIPLEXER_LISTENING(PropertyChangeListener, m_aPropertyChangeListeners, css::beans::XPropertySet, m_xMainForm); - STOP_PROPERTY_MULTIPLEXER_LISTENING(VetoableChangeListener, m_aVetoablePropertyChangeListeners, css::beans::XPropertySet, m_xMainForm); + if (m_aPropertyChangeListeners.getOverallLen()) + { + css::uno::Reference< css::beans::XPropertySet > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->removePropertyChangeListener(OUString(), &m_aPropertyChangeListeners); + } + + if (m_aVetoablePropertyChangeListeners.getOverallLen()) + { + css::uno::Reference< css::beans::XPropertySet > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->removeVetoableChangeListener(OUString(), &m_aVetoablePropertyChangeListeners); + } + if (m_aPropertiesChangeListeners.getLength()) { Reference< css::beans::XMultiPropertySet > xBroadcaster(m_xMainForm, UNO_QUERY); @@ -121,12 +162,42 @@ void SbaXFormAdapter::StopListening() void SbaXFormAdapter::StartListening() { // log off all our multiplexers - START_MULTIPLEXER_LISTENING(LoadListener, m_aLoadListeners, css::form::XLoadable, m_xMainForm); - START_MULTIPLEXER_LISTENING(RowSetListener, m_aRowSetListeners, css::sdbc::XRowSet, m_xMainForm); - START_MULTIPLEXER_LISTENING(RowSetApproveListener, m_aRowSetApproveListeners, css::sdb::XRowSetApproveBroadcaster, m_xMainForm); - START_MULTIPLEXER_LISTENING(SQLErrorListener, m_aErrorListeners, css::sdb::XSQLErrorBroadcaster, m_xMainForm); - START_MULTIPLEXER_LISTENING(SubmitListener, m_aSubmitListeners, css::form::XSubmit, m_xMainForm); - START_MULTIPLEXER_LISTENING(ResetListener, m_aResetListeners, css::form::XReset, m_xMainForm); + if (m_aLoadListeners.getLength()) + { + css::uno::Reference< css::form::XLoadable > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->addLoadListener(&m_aLoadListeners); + } + if (m_aRowSetListeners.getLength()) + { + css::uno::Reference< css::sdbc::XRowSet > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->addRowSetListener(&m_aRowSetListeners); + } + if (m_aRowSetApproveListeners.getLength()) + { + css::uno::Reference< css::sdb::XRowSetApproveBroadcaster > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->addRowSetApproveListener(&m_aRowSetApproveListeners); + } + if (m_aErrorListeners.getLength()) + { + css::uno::Reference< css::sdb::XSQLErrorBroadcaster > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->addSQLErrorListener(&m_aErrorListeners); + } + if (m_aSubmitListeners.getLength()) + { + css::uno::Reference< css::form::XSubmit > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->addSubmitListener(&m_aSubmitListeners); + } + if (m_aResetListeners.getLength()) + { + css::uno::Reference< css::form::XReset > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->addResetListener(&m_aResetListeners); + } if (m_aParameterListeners.getLength()) { @@ -135,13 +206,25 @@ void SbaXFormAdapter::StartListening() xBroadcaster->addParameterListener(&m_aParameterListeners); } - START_PROPERTY_MULTIPLEXER_LISTENING(PropertyChangeListener, m_aPropertyChangeListeners, css::beans::XPropertySet, m_xMainForm); - START_PROPERTY_MULTIPLEXER_LISTENING(VetoableChangeListener, m_aVetoablePropertyChangeListeners, css::beans::XPropertySet, m_xMainForm); + if (m_aPropertyChangeListeners.getOverallLen()) + { + css::uno::Reference< css::beans::XPropertySet > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->addPropertyChangeListener(OUString(), &m_aPropertyChangeListeners); + } + + if (m_aVetoablePropertyChangeListeners.getOverallLen()) + { + css::uno::Reference< css::beans::XPropertySet > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->addVetoableChangeListener(OUString(), &m_aVetoablePropertyChangeListeners); + } + if (m_aPropertiesChangeListeners.getLength()) { Reference< css::beans::XMultiPropertySet > xBroadcaster(m_xMainForm, UNO_QUERY); if (xBroadcaster.is()) - xBroadcaster->addPropertiesChangeListener(css::uno::Sequence<OUString>{""}, &m_aPropertiesChangeListeners); + xBroadcaster->addPropertiesChangeListener(css::uno::Sequence<OUString>{u""_ustr}, &m_aPropertiesChangeListeners); } // log off ourself @@ -166,9 +249,7 @@ void SbaXFormAdapter::AttachForm(const Reference< css::sdbc::XRowSet >& xNewMast if (xLoadable->isLoaded()) { css::lang::EventObject aEvt(*this); - ::comphelper::OInterfaceIteratorHelper2 aIt(m_aLoadListeners); - while (aIt.hasMoreElements()) - static_cast< css::form::XLoadListener*>(aIt.next())->unloaded(aEvt); + m_aLoadListeners.notifyEach( &css::form::XLoadListener::unloaded, aEvt ); } } @@ -184,9 +265,7 @@ void SbaXFormAdapter::AttachForm(const Reference< css::sdbc::XRowSet >& xNewMast if (xLoadable->isLoaded()) { css::lang::EventObject aEvt(*this); - ::comphelper::OInterfaceIteratorHelper2 aIt(m_aLoadListeners); - while (aIt.hasMoreElements()) - static_cast< css::form::XLoadListener*>(aIt.next())->loaded(aEvt); + m_aLoadListeners.notifyEach( &css::form::XLoadListener::loaded, aEvt ); } // TODO : perhaps _all_ of our listeners should be notified about our new state @@ -218,8 +297,6 @@ sal_Int32 SAL_CALL SbaXFormAdapter::findColumn(const OUString& columnName) return xIface->findColumn(columnName); ::dbtools::throwInvalidColumnException( columnName, *this ); - assert(false); - return 0; // Never reached } // css::sdbcx::XColumnsSupplier @@ -736,7 +813,26 @@ void SAL_CALL SbaXFormAdapter::execute() m_xMainForm->execute(); } -IMPLEMENT_LISTENER_ADMINISTRATION(SbaXFormAdapter, sdbc, RowSetListener, m_aRowSetListeners, css::sdbc::XRowSet, m_xMainForm) +void SAL_CALL SbaXFormAdapter::addRowSetListener(const css::uno::Reference< css::sdbc::XRowSetListener >& l) +{ + m_aRowSetListeners.addInterface(l); + if (m_aRowSetListeners.getLength() == 1) + { + css::uno::Reference< css::sdbc::XRowSet > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->addRowSetListener(&m_aRowSetListeners); + } +} +void SAL_CALL SbaXFormAdapter::removeRowSetListener(const css::uno::Reference< css::sdbc::XRowSetListener >& l) +{ + if (m_aRowSetListeners.getLength() == 1) + { + css::uno::Reference< css::sdbc::XRowSet > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->removeRowSetListener(&m_aRowSetListeners); + } + m_aRowSetListeners.removeInterface(l); +} // css::sdbcx::XDeleteRows Sequence<sal_Int32> SAL_CALL SbaXFormAdapter::deleteRows(const Sequence< Any >& rows) @@ -764,10 +860,48 @@ void SAL_CALL SbaXFormAdapter::clearWarnings() } // css::sdb::XRowSetApproveBroadcaster -IMPLEMENT_LISTENER_ADMINISTRATION(SbaXFormAdapter, sdb, RowSetApproveListener, m_aRowSetApproveListeners, css::sdb::XRowSetApproveBroadcaster, m_xMainForm) +void SAL_CALL SbaXFormAdapter::addRowSetApproveListener(const css::uno::Reference< css::sdb::XRowSetApproveListener >& l) +{ + m_aRowSetApproveListeners.addInterface(l); + if (m_aRowSetApproveListeners.getLength() == 1) + { + css::uno::Reference< css::sdb::XRowSetApproveBroadcaster > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->addRowSetApproveListener(&m_aRowSetApproveListeners); + } +} +void SAL_CALL SbaXFormAdapter::removeRowSetApproveListener(const css::uno::Reference< css::sdb::XRowSetApproveListener >& l) +{ + if (m_aRowSetApproveListeners.getLength() == 1) + { + css::uno::Reference< css::sdb::XRowSetApproveBroadcaster > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->removeRowSetApproveListener(&m_aRowSetApproveListeners); + } + m_aRowSetApproveListeners.removeInterface(l); +} // css::sdbc::XSQLErrorBroadcaster -IMPLEMENT_LISTENER_ADMINISTRATION(SbaXFormAdapter, sdb, SQLErrorListener, m_aErrorListeners, css::sdb::XSQLErrorBroadcaster, m_xMainForm) +void SAL_CALL SbaXFormAdapter::addSQLErrorListener(const css::uno::Reference< css::sdb::XSQLErrorListener >& l) +{ + m_aErrorListeners.addInterface(l); + if (m_aErrorListeners.getLength() == 1) + { + css::uno::Reference< css::sdb::XSQLErrorBroadcaster > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->addSQLErrorListener(&m_aErrorListeners); + } +} +void SAL_CALL SbaXFormAdapter::removeSQLErrorListener(const css::uno::Reference< css::sdb::XSQLErrorListener >& l) +{ + if (m_aErrorListeners.getLength() == 1) + { + css::uno::Reference< css::sdb::XSQLErrorBroadcaster > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->removeSQLErrorListener(&m_aErrorListeners); + } + m_aErrorListeners.removeInterface(l); +} // css::sdb::XResultSetAccess Reference< css::sdbc::XResultSet > SAL_CALL SbaXFormAdapter::createResultSet() @@ -808,7 +942,26 @@ sal_Bool SAL_CALL SbaXFormAdapter::isLoaded() return false; } -IMPLEMENT_LISTENER_ADMINISTRATION(SbaXFormAdapter, form, LoadListener, m_aLoadListeners, css::form::XLoadable, m_xMainForm) +void SAL_CALL SbaXFormAdapter::addLoadListener(const css::uno::Reference< css::form::XLoadListener>& l) +{ + m_aLoadListeners.addInterface(l); + if (m_aLoadListeners.getLength() == 1) + { + css::uno::Reference< css::form::XLoadable > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->addLoadListener(&m_aLoadListeners); + } +} +void SAL_CALL SbaXFormAdapter::removeLoadListener(const css::uno::Reference< css::form::XLoadListener >& l) +{ + if (m_aLoadListeners.getLength() == 1) + { + css::uno::Reference< css::form::XLoadable > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->removeLoadListener(&m_aLoadListeners); + } + m_aLoadListeners.removeInterface(l); +} // css::sdbc::XParameters void SAL_CALL SbaXFormAdapter::setNull(sal_Int32 parameterIndex, sal_Int32 sqlType) @@ -1014,7 +1167,26 @@ void SAL_CALL SbaXFormAdapter::submit(const Reference< css::awt::XControl >& aCo xSubmit->submit(aControl, aMouseEvt); } -IMPLEMENT_LISTENER_ADMINISTRATION(SbaXFormAdapter, form, SubmitListener, m_aSubmitListeners, css::form::XSubmit, m_xMainForm) +void SAL_CALL SbaXFormAdapter::addSubmitListener(const css::uno::Reference< css::form::XSubmitListener >& l) +{ + m_aSubmitListeners.addInterface(l); + if (m_aSubmitListeners.getLength() == 1) + { + css::uno::Reference< css::form::XSubmit > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->addSubmitListener(&m_aSubmitListeners); + } +} +void SAL_CALL SbaXFormAdapter::removeSubmitListener(const css::uno::Reference< css::form::XSubmitListener >& l) +{ + if (m_aSubmitListeners.getLength() == 1) + { + css::uno::Reference< css::form::XSubmit > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->removeSubmitListener(&m_aSubmitListeners); + } + m_aSubmitListeners.removeInterface(l); +} // css::awt::XTabControllerModel sal_Bool SAL_CALL SbaXFormAdapter::getGroupControl() @@ -1099,6 +1271,8 @@ void SAL_CALL SbaXFormAdapter::dispose() xComp->dispose(); } m_aChildren.clear(); + m_xMainForm.clear(); + m_xParent.clear(); } void SAL_CALL SbaXFormAdapter::addEventListener(const Reference< css::lang::XEventListener >& xListener) @@ -1119,7 +1293,7 @@ void SAL_CALL SbaXFormAdapter::setFastPropertyValue(sal_Int32 nHandle, const Any if (m_nNamePropHandle == nHandle) { - if (aValue.getValueType().getTypeClass() != TypeClass_STRING) + if (aValue.getValueTypeClass() != TypeClass_STRING) { throw css::lang::IllegalArgumentException(); } @@ -1134,9 +1308,8 @@ void SAL_CALL SbaXFormAdapter::setFastPropertyValue(sal_Int32 nHandle, const Any aValue >>= m_sName; - ::cppu::OInterfaceIteratorHelper aIt(*m_aPropertyChangeListeners.getContainer(PROPERTY_NAME)); - while (aIt.hasMoreElements()) - static_cast< css::beans::XPropertyChangeListener*>(aIt.next())->propertyChange(aEvt); + m_aPropertyChangeListeners.getContainer(PROPERTY_NAME)->notifyEach( + &XPropertyChangeListener::propertyChange, aEvt ); return; } @@ -1150,7 +1323,7 @@ Any SAL_CALL SbaXFormAdapter::getFastPropertyValue(sal_Int32 nHandle) OSL_ENSURE(xSet.is(), "SAL_CALL SbaXFormAdapter::getFastPropertyValue : have no master form !"); if (m_nNamePropHandle == nHandle) - return makeAny(m_sName); + return Any(m_sName); return xSet->getFastPropertyValue(nHandle); } @@ -1163,7 +1336,7 @@ OUString SAL_CALL SbaXFormAdapter::getName() void SAL_CALL SbaXFormAdapter::setName(const OUString& aName) { - setPropertyValue(PROPERTY_NAME, makeAny(aName)); + setPropertyValue(PROPERTY_NAME, Any(aName)); } // css::io::XPersistObject @@ -1227,13 +1400,14 @@ Sequence< Any > SAL_CALL SbaXFormAdapter::getPropertyValues(const Sequence< OUSt return Sequence< Any>(aPropertyNames.getLength()); Sequence< Any> aReturn = xSet->getPropertyValues(aPropertyNames); + auto aReturnRange = asNonConstRange(aReturn); // search for (and fake) the NAME property OSL_ENSURE(aReturn.getLength() == aPropertyNames.getLength(), "SAL_CALL SbaXFormAdapter::getPropertyValues : the main form returned an invalid-length sequence !"); for (sal_Int32 i=0; i<aPropertyNames.getLength(); ++i) if (aPropertyNames[i] == PROPERTY_NAME) { - aReturn[i] <<= m_sName; + aReturnRange[i] <<= m_sName; break; } @@ -1248,7 +1422,7 @@ void SAL_CALL SbaXFormAdapter::addPropertiesChangeListener(const Sequence< OUStr { Reference< css::beans::XMultiPropertySet > xBroadcaster(m_xMainForm, UNO_QUERY); if (xBroadcaster.is()) - xBroadcaster->addPropertiesChangeListener(Sequence< OUString>{""}, &m_aPropertiesChangeListeners); + xBroadcaster->addPropertiesChangeListener(Sequence< OUString>{u""_ustr}, &m_aPropertiesChangeListeners); } } @@ -1297,14 +1471,54 @@ Any SAL_CALL SbaXFormAdapter::getPropertyValue(const OUString& PropertyName) return xSet->getPropertyValue(PropertyName); } -IMPLEMENT_PROPERTY_LISTENER_ADMINISTRATION(SbaXFormAdapter, PropertyChangeListener, m_aPropertyChangeListeners, css::beans::XPropertySet, m_xMainForm); -IMPLEMENT_PROPERTY_LISTENER_ADMINISTRATION(SbaXFormAdapter, VetoableChangeListener, m_aVetoablePropertyChangeListeners, css::beans::XPropertySet, m_xMainForm); +void SAL_CALL SbaXFormAdapter::addPropertyChangeListener(const OUString& rName, const css::uno::Reference< css::beans::XPropertyChangeListener>& l ) +{ + m_aPropertyChangeListeners.addInterface(rName, l); + if (m_aPropertyChangeListeners.getOverallLen() == 1) + { + css::uno::Reference< css::beans::XPropertySet > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->addPropertyChangeListener(OUString(), &m_aPropertyChangeListeners); + } +} +void SAL_CALL SbaXFormAdapter::removePropertyChangeListener(const OUString& rName, const css::uno::Reference< css::beans::XPropertyChangeListener>& l ) +{ + if (m_aPropertyChangeListeners.getOverallLen() == 1) + { + css::uno::Reference< css::beans::XPropertySet > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->removePropertyChangeListener(OUString(), &m_aPropertyChangeListeners); + } + m_aPropertyChangeListeners.removeInterface(rName, l); +} + +void SAL_CALL SbaXFormAdapter::addVetoableChangeListener(const OUString& rName, const css::uno::Reference< css::beans::XVetoableChangeListener>& l ) +{ + m_aVetoablePropertyChangeListeners.addInterface(rName, l); + if (m_aVetoablePropertyChangeListeners.getOverallLen() == 1) + { + css::uno::Reference< css::beans::XPropertySet > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->addVetoableChangeListener(OUString(), &m_aVetoablePropertyChangeListeners); + } +} +void SAL_CALL SbaXFormAdapter::removeVetoableChangeListener(const OUString& rName, const css::uno::Reference< css::beans::XVetoableChangeListener>& l ) +{ + if (m_aVetoablePropertyChangeListeners.getOverallLen() == 1) + { + css::uno::Reference< css::beans::XPropertySet > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->removeVetoableChangeListener(OUString(), &m_aVetoablePropertyChangeListeners); + } + m_aVetoablePropertyChangeListeners.removeInterface(rName, l); +} + // css::util::XCancellable void SAL_CALL SbaXFormAdapter::cancel() { Reference< css::util::XCancellable > xCancel(m_xMainForm, UNO_QUERY); - if (xCancel.is()) + if (!xCancel.is()) return; xCancel->cancel(); } @@ -1326,7 +1540,7 @@ Sequence< css::beans::PropertyState> SAL_CALL SbaXFormAdapter::getPropertyStates // set them all to DEFAULT Sequence< css::beans::PropertyState> aReturn(aPropertyName.getLength()); - for (css::beans::PropertyState& rState : aReturn) + for (css::beans::PropertyState& rState : asNonConstRange(aReturn)) rState = css::beans::PropertyState_DEFAULT_VALUE; return aReturn; } @@ -1354,13 +1568,32 @@ void SAL_CALL SbaXFormAdapter::reset() xReset->reset(); } -IMPLEMENT_LISTENER_ADMINISTRATION(SbaXFormAdapter, form, ResetListener, m_aResetListeners, css::form::XReset, m_xMainForm) +void SAL_CALL SbaXFormAdapter::addResetListener(const css::uno::Reference< css::form::XResetListener >& l) +{ + m_aResetListeners.addInterface(l); + if (m_aResetListeners.getLength() == 1) + { + css::uno::Reference< css::form::XReset > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->addResetListener(&m_aResetListeners); + } +} +void SAL_CALL SbaXFormAdapter::removeResetListener(const css::uno::Reference< css::form::XResetListener >& l) +{ + if (m_aResetListeners.getLength() == 1) + { + css::uno::Reference< css::form::XReset > xBroadcaster(m_xMainForm, css::uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->removeResetListener(&m_aResetListeners); + } + m_aResetListeners.removeInterface(l); +} // css::container::XNameContainer void SbaXFormAdapter::implInsert(const Any& aElement, sal_Int32 nIndex, const OUString* pNewElName) { // extract the form component - if (aElement.getValueType().getTypeClass() != TypeClass_INTERFACE) + if (aElement.getValueTypeClass() != TypeClass_INTERFACE) { throw css::lang::IllegalArgumentException(); } @@ -1376,12 +1609,12 @@ void SbaXFormAdapter::implInsert(const Any& aElement, sal_Int32 nIndex, const OU if (!xElementSet.is()) { throw css::lang::IllegalArgumentException(); - } + } OUString sName; try { if (pNewElName) - xElementSet->setPropertyValue(PROPERTY_NAME, makeAny(*pNewElName)); + xElementSet->setPropertyValue(PROPERTY_NAME, Any(*pNewElName)); xElementSet->getPropertyValue(PROPERTY_NAME) >>= sName; } @@ -1411,9 +1644,7 @@ void SbaXFormAdapter::implInsert(const Any& aElement, sal_Int32 nIndex, const OU aEvt.Source = *this; aEvt.Accessor <<= nIndex; aEvt.Element <<= xElement; - ::comphelper::OInterfaceIteratorHelper2 aIt(m_aContainerListeners); - while (aIt.hasMoreElements()) - static_cast< css::container::XContainerListener*>(aIt.next())->elementInserted(aEvt); + m_aContainerListeners.notifyEach( &XContainerListener::elementInserted, aEvt ); } sal_Int32 SbaXFormAdapter::implGetPos(const OUString& rName) @@ -1462,7 +1693,7 @@ Any SAL_CALL SbaXFormAdapter::getByName(const OUString& aName) { throw css::container::NoSuchElementException(); } - return makeAny(m_aChildren[nPos]); + return Any(m_aChildren[nPos]); } Sequence< OUString > SAL_CALL SbaXFormAdapter::getElementNames() @@ -1516,10 +1747,7 @@ void SAL_CALL SbaXFormAdapter::removeByIndex(sal_Int32 _rIndex) css::container::ContainerEvent aEvt; aEvt.Source = *this; aEvt.Element <<= xAffected; - ::comphelper::OInterfaceIteratorHelper2 aIt(m_aContainerListeners); - while (aIt.hasMoreElements()) - static_cast< css::container::XContainerListener*>(aIt.next())->elementRemoved(aEvt); - + m_aContainerListeners.notifyEach( &XContainerListener::elementRemoved, aEvt ); } // css::container::XIndexReplace @@ -1529,7 +1757,7 @@ void SAL_CALL SbaXFormAdapter::replaceByIndex(sal_Int32 _rIndex, const Any& Elem throw css::lang::IndexOutOfBoundsException(); // extract the form component - if (Element.getValueType().getTypeClass() != TypeClass_INTERFACE) + if (Element.getValueTypeClass() != TypeClass_INTERFACE) { throw css::lang::IllegalArgumentException(); } @@ -1545,7 +1773,7 @@ void SAL_CALL SbaXFormAdapter::replaceByIndex(sal_Int32 _rIndex, const Any& Elem if (!xElementSet.is()) { throw css::lang::IllegalArgumentException(); - } + } OUString sName; try { @@ -1579,9 +1807,7 @@ void SAL_CALL SbaXFormAdapter::replaceByIndex(sal_Int32 _rIndex, const Any& Elem aEvt.Element <<= xElement; aEvt.ReplacedElement <<= xOld; - ::comphelper::OInterfaceIteratorHelper2 aIt(m_aContainerListeners); - while (aIt.hasMoreElements()) - static_cast< css::container::XContainerListener*>(aIt.next())->elementReplaced(aEvt); + m_aContainerListeners.notifyEach( &XContainerListener::elementReplaced, aEvt ); } // css::container::XIndexAccess @@ -1596,7 +1822,7 @@ Any SAL_CALL SbaXFormAdapter::getByIndex(sal_Int32 _rIndex) throw css::lang::IndexOutOfBoundsException(); Reference< css::form::XFormComponent > xElement = *(m_aChildren.begin() + _rIndex); - return makeAny(xElement); + return Any(xElement); } // css::container::XContainer diff --git a/dbaccess/source/ui/browser/genericcontroller.cxx b/dbaccess/source/ui/browser/genericcontroller.cxx index 4c12a3ae7b51..77aaafdbadfb 100644 --- a/dbaccess/source/ui/browser/genericcontroller.cxx +++ b/dbaccess/source/ui/browser/genericcontroller.cxx @@ -18,13 +18,12 @@ */ #include <dbaccess/genericcontroller.hxx> -#include <toolkit/awt/vclxwindow.hxx> #include <browserids.hxx> #include <vcl/svapp.hxx> #include <vcl/weld.hxx> #include <toolkit/helper/vclunohelper.hxx> #include <dbaccess/dataview.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <osl/diagnose.h> #include <vcl/stdtext.hxx> #include <framework/titlehelper.hxx> @@ -38,7 +37,6 @@ #include <com/sun/star/util/XCloseable.hpp> #include <com/sun/star/ui/XSidebarProvider.hpp> -#include <sfx2/userinputinterception.hxx> #include <datasourceconnector.hxx> #include <com/sun/star/frame/FrameSearchFlag.hpp> @@ -58,7 +56,6 @@ using namespace ::com::sun::star::frame; using namespace ::com::sun::star::frame::status; using namespace ::com::sun::star::util; using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::container; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::sdb; using namespace ::com::sun::star::task; @@ -67,45 +64,22 @@ using namespace ::com::sun::star::ui; using namespace ::dbtools; using namespace ::comphelper; -#define ALL_FEATURES -1 -#define FIRST_USER_DEFINED_FEATURE ( std::numeric_limits< sal_uInt16 >::max() - 1000 ) -#define LAST_USER_DEFINED_FEATURE ( std::numeric_limits< sal_uInt16 >::max() ) +constexpr auto ALL_FEATURES = -1; typedef std::unordered_map< sal_Int16, sal_Int16 > CommandHashMap; namespace dbaui { -namespace { - -// UserDefinedFeatures -class UserDefinedFeatures -{ -public: - explicit UserDefinedFeatures( const Reference< XController >& _rxController ); - - void execute( const URL& _rFeatureURL, const Sequence< PropertyValue>& _rArgs ); - -private: - css::uno::WeakReference< XController > m_aController; -}; - -} - -UserDefinedFeatures::UserDefinedFeatures( const Reference< XController >& _rxController ) - :m_aController( _rxController ) -{ -} - -void UserDefinedFeatures::execute( const URL& _rFeatureURL, const Sequence< PropertyValue>& _rArgs ) +void OGenericUnoController::executeUserDefinedFeatures( const URL& _rFeatureURL, const Sequence< PropertyValue>& _rArgs ) { try { - Reference< XController > xController( Reference< XController >(m_aController), UNO_SET_THROW ); + Reference< XController > xController( getXController(), UNO_SET_THROW ); Reference< XDispatchProvider > xDispatchProvider( xController->getFrame(), UNO_QUERY_THROW ); Reference< XDispatch > xDispatch( xDispatchProvider->queryDispatch( _rFeatureURL, - "_self", + u"_self"_ustr, FrameSearchFlag::AUTO ) ); @@ -124,22 +98,10 @@ void UserDefinedFeatures::execute( const URL& _rFeatureURL, const Sequence< Prop } } -// OGenericUnoController_Data -struct OGenericUnoController_Data -{ - ::sfx2::UserInputInterception m_aUserInputInterception; - UserDefinedFeatures m_aUserDefinedFeatures; - - OGenericUnoController_Data( OGenericUnoController& _rController, ::osl::Mutex& _rMutex ) - :m_aUserInputInterception( _rController, _rMutex ) - ,m_aUserDefinedFeatures( _rController.getXController() ) - { - } -}; - // OGenericUnoController OGenericUnoController::OGenericUnoController(const Reference< XComponentContext >& _rM) :OGenericUnoController_Base( getMutex() ) + ,m_aUserInputInterception(*this, getMutex()) ,m_pView(nullptr) #ifdef DBG_UTIL ,m_bDescribingSupportedFeatures( false ) @@ -153,12 +115,6 @@ OGenericUnoController::OGenericUnoController(const Reference< XComponentContext ,m_bCurrentlyModified(false) ,m_bExternalTitle(false) { - osl_atomic_increment( &m_refCount ); - { - m_pData.reset( new OGenericUnoController_Data( *this, getMutex() ) ); - } - osl_atomic_decrement( &m_refCount ); - try { @@ -198,7 +154,7 @@ bool OGenericUnoController::Construct(vcl::Window* /*pParent*/) { SAL_WARN("dbaccess.ui","OGenericUnoController::Construct: could not create (or start listening at) the database context!"); // at least notify the user. Though the whole component does not make any sense without the database context ... - ShowServiceNotAvailableError(getFrameWeld(), "com.sun.star.sdb.DatabaseContext", true); + ShowServiceNotAvailableError(getFrameWeld(), u"com.sun.star.sdb.DatabaseContext", true); } return true; @@ -210,7 +166,7 @@ IMPL_LINK_NOARG(OGenericUnoController, OnAsyncInvalidateAll, void*, void) InvalidateFeature_Impl(); } -void OGenericUnoController::impl_initialize() +void OGenericUnoController::impl_initialize(const ::comphelper::NamedValueCollection& /*rArguments*/) { } @@ -219,49 +175,46 @@ void SAL_CALL OGenericUnoController::initialize( const Sequence< Any >& aArgumen SolarMutexGuard aSolarGuard; ::osl::MutexGuard aGuard( getMutex() ); - Reference< XWindow > xParent; Reference< XFrame > xFrame; - PropertyValue aValue; - const Any* pIter = aArguments.getConstArray(); - const Any* pEnd = pIter + aArguments.getLength(); - - for ( ; pIter != pEnd; ++pIter ) + for (auto& arg : aArguments) { - if ( ( *pIter >>= aValue ) && aValue.Name == "Frame" ) + PropertyValue aValue; + if (arg >>= aValue) { - xFrame.set(aValue.Value,UNO_QUERY_THROW); - } - else if ( ( *pIter >>= aValue ) && aValue.Name == "Preview" ) - { - aValue.Value >>= m_bPreview; - m_bReadOnly = true; + if (aValue.Name == "Frame") + { + xFrame.set(aValue.Value, UNO_QUERY_THROW); + } + else if (aValue.Name == "Preview") + { + aValue.Value >>= m_bPreview; + m_bReadOnly = true; + } } } try { if ( !xFrame.is() ) - throw IllegalArgumentException("need a frame", *this, 1 ); + throw IllegalArgumentException(u"need a frame"_ustr, *this, 1 ); - xParent = xFrame->getContainerWindow(); - VCLXWindow* pParentComponent = comphelper::getUnoTunnelImplementation<VCLXWindow>(xParent); - VclPtr< vcl::Window > pParentWin = pParentComponent ? pParentComponent->GetWindow() : VclPtr< vcl::Window >(); + Reference<XWindow> xParent = xFrame->getContainerWindow(); + VclPtr<vcl::Window> pParentWin = VCLUnoHelper::GetWindow(xParent); if (!pParentWin) { - throw IllegalArgumentException("Parent window is null", *this, 1 ); + throw IllegalArgumentException(u"Parent window is null"_ustr, *this, 1 ); } - m_aInitParameters.assign( aArguments ); Construct( pParentWin ); ODataView* pView = getView(); if ( !pView ) - throw RuntimeException("unable to create a view", *this ); + throw RuntimeException(u"unable to create a view"_ustr, *this ); if ( m_bReadOnly || m_bPreview ) pView->EnableInput( false ); - impl_initialize(); + impl_initialize(::comphelper::NamedValueCollection(aArguments)); } catch(Exception&) { @@ -271,12 +224,12 @@ void SAL_CALL OGenericUnoController::initialize( const Sequence< Any >& aArgumen } } -void SAL_CALL OGenericUnoController::acquire( ) throw () +void SAL_CALL OGenericUnoController::acquire( ) noexcept { OGenericUnoController_Base::acquire(); } -void SAL_CALL OGenericUnoController::release( ) throw () +void SAL_CALL OGenericUnoController::release( ) noexcept { OGenericUnoController_Base::release(); } @@ -328,7 +281,7 @@ Reference<XSidebarProvider> SAL_CALL OGenericUnoController::getSidebar() OUString SAL_CALL OGenericUnoController::getViewControllerName() { - return "Default"; + return u"Default"_ustr; } Sequence< PropertyValue > SAL_CALL OGenericUnoController::getCreationArguments() @@ -375,11 +328,11 @@ namespace // #i68216# is the bug which requests to fix the code in Draw which relies on // framework's implementation details if ( !!_rFeatureState.sTitle ) - _out_rStates.push_back( makeAny( *_rFeatureState.sTitle ) ); - if ( !!_rFeatureState.bChecked ) - _out_rStates.push_back( makeAny( *_rFeatureState.bChecked ) ); - if ( !!_rFeatureState.bInvisible ) - _out_rStates.push_back( makeAny( Visibility( !*_rFeatureState.bInvisible ) ) ); + _out_rStates.push_back( Any( *_rFeatureState.sTitle ) ); + if ( _rFeatureState.bChecked.has_value() ) + _out_rStates.push_back( Any( *_rFeatureState.bChecked ) ); + if ( _rFeatureState.bInvisible.has_value() ) + _out_rStates.push_back( Any( Visibility( !*_rFeatureState.bInvisible ) ) ); if ( _rFeatureState.aValue.hasValue() ) _out_rStates.push_back( _rFeatureState.aValue ); if ( _out_rStates.empty() ) @@ -434,7 +387,7 @@ void OGenericUnoController::ImplBroadcastFeatureState(const OUString& _rFeature, // it is possible that listeners are registered or revoked while // we are notifying them, so we must use a copy of m_arrStatusListener, not // m_arrStatusListener itself - Dispatch aNotifyLoop( m_arrStatusListener ); + std::vector<DispatchTarget> aNotifyLoop( m_arrStatusListener ); for (auto const& elem : aNotifyLoop) { @@ -461,15 +414,10 @@ bool OGenericUnoController::isFeatureSupported( sal_Int32 _nId ) void OGenericUnoController::InvalidateFeature_Impl() { -#ifdef DBG_UTIL - static sal_Int32 s_nRecursions = 0; - ++s_nRecursions; -#endif - bool bEmpty = true; FeatureListener aNextFeature; { - ::osl::MutexGuard aGuard( m_aFeatureMutex); + std::unique_lock aGuard( m_aFeatureMutex); bEmpty = m_aFeaturesToInvalidate.empty(); if (!bEmpty) aNextFeature = m_aFeaturesToInvalidate.front(); @@ -502,16 +450,12 @@ void OGenericUnoController::InvalidateFeature_Impl() ImplBroadcastFeatureState( aFeaturePos->first, aNextFeature.xListener, aNextFeature.bForceBroadcast ); } - ::osl::MutexGuard aGuard( m_aFeatureMutex); + std::unique_lock aGuard( m_aFeatureMutex); m_aFeaturesToInvalidate.pop_front(); bEmpty = m_aFeaturesToInvalidate.empty(); if (!bEmpty) aNextFeature = m_aFeaturesToInvalidate.front(); } - -#ifdef DBG_UTIL - --s_nRecursions; -#endif } void OGenericUnoController::ImplInvalidateFeature( sal_Int32 _nId, const Reference< XStatusListener >& _xListener, bool _bForceBroadcast ) @@ -535,7 +479,7 @@ void OGenericUnoController::ImplInvalidateFeature( sal_Int32 _nId, const Referen bool bWasEmpty; { - ::osl::MutexGuard aGuard( m_aFeatureMutex ); + std::unique_lock aGuard( m_aFeatureMutex ); bWasEmpty = m_aFeaturesToInvalidate.empty(); m_aFeaturesToInvalidate.push_back( aListener ); } @@ -561,7 +505,7 @@ void OGenericUnoController::InvalidateAll_Impl() ImplBroadcastFeatureState( supportedFeature.first, nullptr, true ); { - ::osl::MutexGuard aGuard( m_aFeatureMutex); + std::unique_lock aGuard( m_aFeatureMutex); OSL_ENSURE(m_aFeaturesToInvalidate.size(), "OGenericUnoController::InvalidateAll_Impl: to be called from within InvalidateFeature_Impl only!"); m_aFeaturesToInvalidate.pop_front(); if(!m_aFeaturesToInvalidate.empty()) @@ -598,19 +542,13 @@ Reference< XDispatch > OGenericUnoController::queryDispatch(const URL& aURL, co Sequence< Reference< XDispatch > > OGenericUnoController::queryDispatches(const Sequence< DispatchDescriptor >& aDescripts) { - Sequence< Reference< XDispatch > > aReturn; - sal_Int32 nLen = aDescripts.getLength(); - if ( nLen ) + Sequence< Reference< XDispatch > > aReturn(aDescripts.getLength()); + if (aDescripts.hasElements()) { - aReturn.realloc( nLen ); - Reference< XDispatch >* pReturn = aReturn.getArray(); - const Reference< XDispatch >* pReturnEnd = aReturn.getArray() + nLen; - const DispatchDescriptor* pDescripts = aDescripts.getConstArray(); - - for ( ; pReturn != pReturnEnd; ++ pReturn, ++pDescripts ) - { - *pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags ); - } + std::transform(aDescripts.begin(), aDescripts.end(), aReturn.getArray(), + [this](auto& desc) { + return queryDispatch(desc.FeatureURL, desc.FrameName, desc.SearchFlags); + }); } return aReturn; @@ -667,14 +605,12 @@ void OGenericUnoController::removeStatusListener(const Reference< XStatusListene { if (_rURL.Complete.isEmpty()) { - m_arrStatusListener.erase(std::remove_if(m_arrStatusListener.begin(), m_arrStatusListener.end(), - [&aListener](const DispatchTarget& rCurrent) { return rCurrent.xListener == aListener; }), - m_arrStatusListener.end()); + std::erase_if(m_arrStatusListener, [&aListener](const DispatchTarget& rCurrent) { return rCurrent.xListener == aListener; }); } else { // remove the listener only for the given URL - Dispatch::iterator iterSearch = std::find_if(m_arrStatusListener.begin(), m_arrStatusListener.end(), + auto iterSearch = std::find_if(m_arrStatusListener.begin(), m_arrStatusListener.end(), [&aListener, &_rURL](const DispatchTarget& rCurrent) { return (rCurrent.xListener == aListener) && (rCurrent.aURL.Complete == _rURL.Complete); }); if (iterSearch != m_arrStatusListener.end()) @@ -688,18 +624,14 @@ void OGenericUnoController::removeStatusListener(const Reference< XStatusListene SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.find(_rURL.Complete); if (aIter != m_aSupportedFeatures.end()) { // clear the cache for that feature - StateCache::const_iterator aCachePos = m_aStateCache.find( aIter->second.nFeatureId ); + auto aCachePos = m_aStateCache.find( aIter->second.nFeatureId ); if ( aCachePos != m_aStateCache.end() ) m_aStateCache.erase( aCachePos ); } // now remove the listener from the deque - ::osl::MutexGuard aGuard( m_aFeatureMutex ); - m_aFeaturesToInvalidate.erase( - std::remove_if( m_aFeaturesToInvalidate.begin(), - m_aFeaturesToInvalidate.end(), - FindFeatureListener(aListener)) - ,m_aFeaturesToInvalidate.end()); + std::unique_lock aGuard( m_aFeatureMutex ); + std::erase_if( m_aFeaturesToInvalidate, FindFeatureListener(aListener)); } void OGenericUnoController::releaseNumberForComponent() @@ -721,7 +653,7 @@ void OGenericUnoController::disposing() { EventObject aDisposeEvent; aDisposeEvent.Source = static_cast<XWeak*>(this); - Dispatch aStatusListener = m_arrStatusListener; + std::vector<DispatchTarget> aStatusListener = m_arrStatusListener; for (auto const& statusListener : aStatusListener) { statusListener.xListener->disposing(aDisposeEvent); @@ -731,7 +663,7 @@ void OGenericUnoController::disposing() m_xDatabaseContext = nullptr; { - ::osl::MutexGuard aGuard( m_aFeatureMutex); + std::unique_lock aGuard( m_aFeatureMutex); m_aAsyncInvalidateAll.CancelCall(); m_aFeaturesToInvalidate.clear(); } @@ -747,7 +679,6 @@ void OGenericUnoController::disposing() m_xSlaveDispatcher = nullptr; m_xTitleHelper.clear(); m_xUrlTransformer.clear(); - m_aInitParameters.clear(); } void SAL_CALL OGenericUnoController::addEventListener( const Reference< XEventListener >& xListener ) @@ -769,16 +700,17 @@ void OGenericUnoController::frameAction(const FrameActionEvent& aEvent) m_aCurrentFrame.frameAction( aEvent.Action ); } -void OGenericUnoController::implDescribeSupportedFeature( const char* _pAsciiCommandURL, +void OGenericUnoController::implDescribeSupportedFeature( const OUString& _rCommandURL, sal_uInt16 _nFeatureId, sal_Int16 _nCommandGroup ) { #ifdef DBG_UTIL OSL_ENSURE( m_bDescribingSupportedFeatures, "OGenericUnoController::implDescribeSupportedFeature: bad timing for this call!" ); #endif - OSL_PRECOND( _nFeatureId < FIRST_USER_DEFINED_FEATURE, "OGenericUnoController::implDescribeSupportedFeature: invalid feature id!" ); + OSL_PRECOND( _nFeatureId < ( std::numeric_limits< sal_uInt16 >::max() - 1000 ), // FIRST_USER_DEFINED_FEATURE + "OGenericUnoController::implDescribeSupportedFeature: invalid feature id!" ); ControllerFeature aFeature; - aFeature.Command = OUString::createFromAscii( _pAsciiCommandURL ); + aFeature.Command = _rCommandURL; aFeature.nFeatureId = _nFeatureId; aFeature.GroupId = _nCommandGroup; @@ -792,11 +724,11 @@ void OGenericUnoController::implDescribeSupportedFeature( const char* _pAsciiCom void OGenericUnoController::describeSupportedFeatures() { // add all supported features - implDescribeSupportedFeature( ".uno:Copy", ID_BROWSER_COPY, CommandGroup::EDIT ); - implDescribeSupportedFeature( ".uno:Cut", ID_BROWSER_CUT, CommandGroup::EDIT ); - implDescribeSupportedFeature( ".uno:Paste", ID_BROWSER_PASTE, CommandGroup::EDIT ); - implDescribeSupportedFeature( ".uno:ClipboardFormatItems", ID_BROWSER_CLIPBOARD_FORMAT_ITEMS ); - implDescribeSupportedFeature( ".uno:DSBEditDoc", ID_BROWSER_EDITDOC, CommandGroup::DOCUMENT ); + implDescribeSupportedFeature( u".uno:Copy"_ustr, ID_BROWSER_COPY, CommandGroup::EDIT ); + implDescribeSupportedFeature( u".uno:Cut"_ustr, ID_BROWSER_CUT, CommandGroup::EDIT ); + implDescribeSupportedFeature( u".uno:Paste"_ustr, ID_BROWSER_PASTE, CommandGroup::EDIT ); + implDescribeSupportedFeature( u".uno:ClipboardFormatItems"_ustr, ID_BROWSER_CLIPBOARD_FORMAT_ITEMS ); + implDescribeSupportedFeature( u".uno:DSBEditDoc"_ustr, ID_BROWSER_EDITDOC, CommandGroup::DOCUMENT ); } FeatureState OGenericUnoController::GetState( sal_uInt16 _nId ) const @@ -828,7 +760,7 @@ void OGenericUnoController::Execute( sal_uInt16 _nId, const Sequence< PropertyVa // user defined features can be handled by dispatch interceptors resp. protocol handlers only. // So, we need to do a queryDispatch, and dispatch the URL - m_pData->m_aUserDefinedFeatures.execute( getURLForId( _nId ), _rArgs ); + executeUserDefinedFeatures( getURLForId( _nId ), _rArgs ); } URL OGenericUnoController::getURLForId(sal_Int32 _nId) const @@ -853,7 +785,11 @@ URL OGenericUnoController::getURLForId(sal_Int32 _nId) const bool OGenericUnoController::isUserDefinedFeature( const sal_uInt16 _nFeatureId ) { - return ( _nFeatureId >= FIRST_USER_DEFINED_FEATURE ) && ( _nFeatureId < LAST_USER_DEFINED_FEATURE ); + return + (_nFeatureId >= ( std::numeric_limits< sal_uInt16 >::max() - 1000 )) // test if >= FIRST_USER_DEFINED_FEATURE + && + ( _nFeatureId < (std::numeric_limits< sal_uInt16 >::max())) // test if < LAST_USER_DEFINED_FEATURE + ; } bool OGenericUnoController::isUserDefinedFeature( const OUString& _rFeatureURL ) const @@ -932,7 +868,7 @@ Reference< XLayoutManager > OGenericUnoController::getLayoutManager(const Refere { try { - xLayoutManager.set(xPropSet->getPropertyValue("LayoutManager"),UNO_QUERY); + xLayoutManager.set(xPropSet->getPropertyValue(u"LayoutManager"_ustr),UNO_QUERY); } catch ( Exception& ) { @@ -947,8 +883,8 @@ void OGenericUnoController::loadMenu(const Reference< XFrame >& _xFrame) if ( xLayoutManager.is() ) { xLayoutManager->lock(); - xLayoutManager->createElement( "private:resource/menubar/menubar" ); - xLayoutManager->createElement( "private:resource/toolbar/toolbar" ); + xLayoutManager->createElement( u"private:resource/menubar/menubar"_ustr ); + xLayoutManager->createElement( u"private:resource/toolbar/toolbar"_ustr ); xLayoutManager->unlock(); xLayoutManager->doLayout(); } @@ -1059,21 +995,16 @@ Reference< awt::XWindow> OGenericUnoController::getTopMostContainerWindow() cons return xWindow; } -Reference< XTitle > OGenericUnoController::impl_getTitleHelper_throw() +Reference< XTitle > OGenericUnoController::impl_getTitleHelper_throw(bool bCreateIfNecessary) { SolarMutexGuard aSolarGuard; ::osl::MutexGuard aGuard( getMutex() ); - if ( ! m_xTitleHelper.is ()) + if (!m_xTitleHelper.is() && bCreateIfNecessary) { Reference< XUntitledNumbers > xUntitledProvider(getPrivateModel(), UNO_QUERY ); - Reference< XController > xThis(static_cast< XController* >(this), UNO_QUERY_THROW); - ::framework::TitleHelper* pHelper = new ::framework::TitleHelper( m_xContext ); - m_xTitleHelper.set( static_cast< ::cppu::OWeakObject* >(pHelper), UNO_QUERY_THROW); - - pHelper->setOwner (xThis ); - pHelper->connectWithUntitledNumbers (xUntitledProvider); + m_xTitleHelper = new ::framework::TitleHelper( m_xContext, Reference< XController >(this), xUntitledProvider ); } return m_xTitleHelper; @@ -1107,7 +1038,7 @@ void SAL_CALL OGenericUnoController::addTitleChangeListener(const Reference< XTi void SAL_CALL OGenericUnoController::removeTitleChangeListener(const Reference< XTitleChangeListener >& xListener) { - Reference< XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper_throw(), UNO_QUERY); + Reference< XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper_throw(false), UNO_QUERY); if (xBroadcaster.is ()) xBroadcaster->removeTitleChangeListener (xListener); } @@ -1116,23 +1047,23 @@ void SAL_CALL OGenericUnoController::removeTitleChangeListener(const Reference< void SAL_CALL OGenericUnoController::addKeyHandler( const Reference< XKeyHandler >& _rxHandler ) { if ( _rxHandler.is() ) - m_pData->m_aUserInputInterception.addKeyHandler( _rxHandler ); + m_aUserInputInterception.addKeyHandler( _rxHandler ); } void SAL_CALL OGenericUnoController::removeKeyHandler( const Reference< XKeyHandler >& _rxHandler ) { - m_pData->m_aUserInputInterception.removeKeyHandler( _rxHandler ); + m_aUserInputInterception.removeKeyHandler( _rxHandler ); } void SAL_CALL OGenericUnoController::addMouseClickHandler( const Reference< XMouseClickHandler >& _rxHandler ) { if ( _rxHandler.is() ) - m_pData->m_aUserInputInterception.addMouseClickHandler( _rxHandler ); + m_aUserInputInterception.addMouseClickHandler( _rxHandler ); } void SAL_CALL OGenericUnoController::removeMouseClickHandler( const Reference< XMouseClickHandler >& _rxHandler ) { - m_pData->m_aUserInputInterception.removeMouseClickHandler( _rxHandler ); + m_aUserInputInterception.removeMouseClickHandler( _rxHandler ); } void OGenericUnoController::executeChecked(sal_uInt16 _nCommandId, const Sequence< PropertyValue >& aArgs) @@ -1158,14 +1089,14 @@ Reference< XController > OGenericUnoController::getXController() bool OGenericUnoController::interceptUserInput( const NotifyEvent& _rEvent ) { - return m_pData->m_aUserInputInterception.handleNotifyEvent( _rEvent ); + return m_aUserInputInterception.handleNotifyEvent( _rEvent ); } bool OGenericUnoController::isCommandChecked(sal_uInt16 _nCommandId) const { FeatureState aState = GetState( _nCommandId ); - return aState.bChecked && *aState.bChecked; + return aState.bChecked.has_value() && *aState.bChecked; } bool OGenericUnoController::isCommandEnabled( const OUString& _rCompleteCommandURL ) const @@ -1219,6 +1150,11 @@ void SAL_CALL OGenericUnoController::dispose() { SolarMutexGuard aSolarGuard; OGenericUnoController_Base::dispose(); + m_xUrlTransformer.clear(); + m_xSlaveDispatcher.clear(); + m_xMasterDispatcher.clear(); + m_xDatabaseContext.clear(); + m_xTitleHelper.clear(); } weld::Window* OGenericUnoController::getFrameWeld() const diff --git a/dbaccess/source/ui/browser/sbagrid.cxx b/dbaccess/source/ui/browser/sbagrid.cxx index 5e986fbb38e6..58017ff4c24c 100644 --- a/dbaccess/source/ui/browser/sbagrid.cxx +++ b/dbaccess/source/ui/browser/sbagrid.cxx @@ -18,7 +18,6 @@ */ #include <core_resource.hxx> -#include <helpids.h> #include <sot/exchange.hxx> @@ -34,26 +33,22 @@ #include <com/sun/star/view/XSelectionSupplier.hpp> #include <com/sun/star/awt/XTextComponent.hpp> #include <com/sun/star/sdbc/XResultSetUpdate.hpp> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <svl/numuno.hxx> #include <toolkit/helper/vclunohelper.hxx> #include <vcl/svapp.hxx> -#include <svl/zforlist.hxx> #include <cppuhelper/queryinterface.hxx> #include <connectivity/dbtools.hxx> -#include <comphelper/processfactory.hxx> +#include <comphelper/propertyvalue.hxx> #include <comphelper/types.hxx> #include <com/sun/star/sdbc/DataType.hpp> #include <com/sun/star/sdbc/SQLException.hpp> -#include <browserids.hxx> #include <strings.hrc> #include <strings.hxx> #include <dbexchange.hxx> -#include <TableRowExchange.hxx> -#include <TableRow.hxx> #include <svtools/stringtransfer.hxx> #include <UITools.hxx> #include <TokenWriter.hxx> @@ -64,12 +59,10 @@ using namespace ::com::sun::star::ui::dialogs; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::sdb; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::container; using namespace ::com::sun::star::datatransfer; using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::view; using namespace ::com::sun::star::form; using namespace ::com::sun::star::frame; using namespace ::com::sun::star::util; @@ -87,8 +80,8 @@ com_sun_star_comp_dbu_SbaXGridControl_get_implementation( css::uno::Sequence<OUString> SAL_CALL SbaXGridControl::getSupportedServiceNames() { - return { "com.sun.star.form.control.InteractionGridControl", "com.sun.star.form.control.GridControl", - "com.sun.star.awt.UnoControl" }; + return { u"com.sun.star.form.control.InteractionGridControl"_ustr, u"com.sun.star.form.control.GridControl"_ustr, + u"com.sun.star.awt.UnoControl"_ustr }; } @@ -96,7 +89,7 @@ css::uno::Sequence<OUString> SAL_CALL SbaXGridControl::getSupportedServiceNames( OUString SAL_CALL SbaXGridControl::getImplementationName() { - return "com.sun.star.comp.dbu.SbaXGridControl"; + return u"com.sun.star.comp.dbu.SbaXGridControl"_ustr; } SbaXGridControl::SbaXGridControl(const Reference< XComponentContext >& _rM) @@ -108,9 +101,9 @@ SbaXGridControl::~SbaXGridControl() { } -FmXGridPeer* SbaXGridControl::imp_CreatePeer(vcl::Window* pParent) +rtl::Reference<FmXGridPeer> SbaXGridControl::imp_CreatePeer(vcl::Window* pParent) { - FmXGridPeer* pReturn = new SbaXGridPeer(m_xContext); + rtl::Reference<FmXGridPeer> pReturn = new SbaXGridPeer(m_xContext); // translate properties into WinBits WinBits nStyle = WB_TABSTOP; @@ -132,9 +125,9 @@ FmXGridPeer* SbaXGridControl::imp_CreatePeer(vcl::Window* pParent) return pReturn; } -Any SAL_CALL SbaXGridControl::queryInterface(const Type& _rType) +Any SAL_CALL SbaXGridControl::queryAggregation(const Type& _rType) { - Any aRet = FmXGridControl::queryInterface(_rType); + Any aRet = FmXGridControl::queryAggregation(_rType); return aRet.hasValue() ? aRet : ::cppu::queryInterface(_rType,static_cast<css::frame::XDispatch*>(this)); } @@ -163,7 +156,7 @@ void SAL_CALL SbaXGridControl::createPeer(const Reference< css::awt::XToolkit > for (auto const& elem : m_aStatusMultiplexer) { if (elem.second.is() && elem.second->getLength()) - xDisp->addStatusListener(elem.second.get(), elem.first); + xDisp->addStatusListener(elem.second, elem.first); } } @@ -192,7 +185,7 @@ void SAL_CALL SbaXGridControl::addStatusListener( const Reference< XStatusListen if ( 1 == xMultiplexer->getLength() ) { // the first external listener for this URL Reference< XDispatch > xDisp( getPeer(), UNO_QUERY ); - xDisp->addStatusListener( xMultiplexer.get(), _rURL ); + xDisp->addStatusListener( xMultiplexer, _rURL ); } else { // already have other listeners for this URL @@ -214,7 +207,7 @@ void SAL_CALL SbaXGridControl::removeStatusListener(const Reference< css::frame: if (getPeer().is() && xMultiplexer->getLength() == 1) { Reference< css::frame::XDispatch > xDisp(getPeer(), UNO_QUERY); - xDisp->removeStatusListener(xMultiplexer.get(), _rURL); + xDisp->removeStatusListener(xMultiplexer, _rURL); } xMultiplexer->removeInterface( _rxListener ); } @@ -242,7 +235,6 @@ void SAL_CALL SbaXGridControl::dispose() // SbaXGridPeer SbaXGridPeer::SbaXGridPeer(const Reference< XComponentContext >& _rM) : FmXGridPeer(_rM) -,m_aStatusListeners(m_aMutex) { } @@ -252,10 +244,11 @@ SbaXGridPeer::~SbaXGridPeer() void SAL_CALL SbaXGridPeer::dispose() { - EventObject aEvt(*this); - - m_aStatusListeners.disposeAndClear(aEvt); - + { + std::unique_lock g(m_aMutex); + EventObject aEvt(*this); + m_aStatusListeners.disposeAndClear(g, aEvt); + } FmXGridPeer::dispose(); } @@ -280,13 +273,13 @@ void SbaXGridPeer::NotifyStatusChanged(const css::util::URL& _rUrl, const Refere xControl->statusChanged(aEvt); else { - ::cppu::OInterfaceContainerHelper * pIter = m_aStatusListeners.getContainer(_rUrl); + std::unique_lock g(m_aMutex); + ::comphelper::OInterfaceContainerHelper4<css::frame::XStatusListener> * pIter + = m_aStatusListeners.getContainer(g, _rUrl); if (pIter) { - ::cppu::OInterfaceIteratorHelper aListIter(*pIter); - while (aListIter.hasMoreElements()) - static_cast< css::frame::XStatusListener*>(aListIter.next())->statusChanged(aEvt); + pIter->notifyEach( g, &XStatusListener::statusChanged, aEvt ); } } } @@ -445,19 +438,24 @@ void SAL_CALL SbaXGridPeer::dispatch(const URL& aURL, const Sequence< PropertyVa void SAL_CALL SbaXGridPeer::addStatusListener(const Reference< css::frame::XStatusListener > & xControl, const css::util::URL& aURL) { - ::cppu::OInterfaceContainerHelper* pCont = m_aStatusListeners.getContainer(aURL); - if (!pCont) - m_aStatusListeners.addInterface(aURL,xControl); - else - pCont->addInterface(xControl); + { + std::unique_lock g(m_aMutex); + ::comphelper::OInterfaceContainerHelper4< css::frame::XStatusListener >* pCont + = m_aStatusListeners.getContainer(g, aURL); + if (!pCont) + m_aStatusListeners.addInterface(g, aURL,xControl); + else + pCont->addInterface(g, xControl); + } NotifyStatusChanged(aURL, xControl); } void SAL_CALL SbaXGridPeer::removeStatusListener(const Reference< css::frame::XStatusListener > & xControl, const css::util::URL& aURL) { - ::cppu::OInterfaceContainerHelper* pCont = m_aStatusListeners.getContainer(aURL); + std::unique_lock g(m_aMutex); + ::comphelper::OInterfaceContainerHelper4< css::frame::XStatusListener >* pCont = m_aStatusListeners.getContainer(g, aURL); if ( pCont ) - pCont->removeInterface(xControl); + pCont->removeInterface(g, xControl); } Sequence< Type > SAL_CALL SbaXGridPeer::getTypes() @@ -467,8 +465,6 @@ Sequence< Type > SAL_CALL SbaXGridPeer::getTypes() Sequence { cppu::UnoType<css::frame::XDispatch>::get() }); } -UNO3_GETIMPLEMENTATION2_IMPL(SbaXGridPeer, FmXGridPeer); - VclPtr<FmGridControl> SbaXGridPeer::imp_CreateControl(vcl::Window* pParent, WinBits nStyle) { return VclPtr<SbaGridControl>::Create( m_xContext, pParent, this, nStyle); @@ -523,7 +519,7 @@ void SbaGridHeader::ImplStartColumnDrag(sal_Int8 _nAction, const Point& _rMouseP tools::Rectangle aColRect = GetItemRect(nId); aColRect.AdjustLeft(nId ? 3 : 0 ); // the handle col (nId == 0) does not have a left margin for resizing aColRect.AdjustRight( -3 ); - bResizingCol = !aColRect.IsInside(_rMousePos); + bResizingCol = !aColRect.Contains(_rMousePos); } if (bResizingCol) return; @@ -544,26 +540,21 @@ void SbaGridHeader::ImplStartColumnDrag(sal_Int8 _nAction, const Point& _rMouseP ); } -void SbaGridHeader::PreExecuteColumnContextMenu(sal_uInt16 nColId, PopupMenu& rMenu) +void SbaGridHeader::PreExecuteColumnContextMenu(sal_uInt16 nColId, weld::Menu& rMenu, + weld::Menu& rInsertMenu, weld::Menu& rChangeMenu, + weld::Menu& rShowMenu) { - FmGridHeader::PreExecuteColumnContextMenu(nColId, rMenu); + FmGridHeader::PreExecuteColumnContextMenu(nColId, rMenu, rInsertMenu, rChangeMenu, rShowMenu); // some items are valid only if the db isn't readonly bool bDBIsReadOnly = static_cast<SbaGridControl*>(GetParent())->IsReadOnlyDB(); if (bDBIsReadOnly) { - rMenu.EnableItem(rMenu.GetItemId("hide"), false); - PopupMenu* pShowColsMenu = rMenu.GetPopupMenu(rMenu.GetItemId("show")); - if (pShowColsMenu) - { - // at most 16 items which mean "show column <name>" - for (sal_uInt16 i=1; i<16; ++i) - pShowColsMenu->EnableItem(i, false); - // "show cols/more..." and "show cols/all" - pShowColsMenu->EnableItem(pShowColsMenu->GetItemId("more"), false); - pShowColsMenu->EnableItem(pShowColsMenu->GetItemId("all"), false); - } + rMenu.set_visible(u"hide"_ustr, false); + rMenu.set_sensitive(u"hide"_ustr, false); + rMenu.set_visible(u"show"_ustr, false); + rMenu.set_sensitive(u"show"_ustr, false); } // prepend some new items @@ -589,45 +580,25 @@ void SbaGridHeader::PreExecuteColumnContextMenu(sal_uInt16 nColId, PopupMenu& rM case DataType::REF: break; default: - rMenu.InsertItem(ID_BROWSER_COLATTRSET, DBA_RES(RID_STR_COLUMN_FORMAT), MenuItemBits::NONE, OString(), nPos++); - rMenu.SetHelpId(ID_BROWSER_COLATTRSET, HID_BROWSER_COLUMNFORMAT); - rMenu.InsertSeparator(OString(), nPos++); + rMenu.insert(nPos++, u"colattrset"_ustr, DBA_RES(RID_STR_COLUMN_FORMAT), + nullptr, nullptr, nullptr, TRISTATE_INDET); + rMenu.insert_separator(nPos++, u"separator1"_ustr); } } - rMenu.InsertItem(ID_BROWSER_COLWIDTH, DBA_RES(RID_STR_COLUMN_WIDTH), MenuItemBits::NONE, OString(), nPos++); - rMenu.SetHelpId(ID_BROWSER_COLWIDTH, HID_BROWSER_COLUMNWIDTH); - rMenu.InsertSeparator(OString(), nPos++); + rMenu.insert(nPos++, u"colwidth"_ustr, DBA_RES(RID_STR_COLUMN_WIDTH), + nullptr, nullptr, nullptr, TRISTATE_INDET); + rMenu.insert_separator(nPos++, u"separator2"_ustr); } -void SbaGridHeader::PostExecuteColumnContextMenu(sal_uInt16 nColId, const PopupMenu& rMenu, sal_uInt16 nExecutionResult) +void SbaGridHeader::PostExecuteColumnContextMenu(sal_uInt16 nColId, const weld::Menu& rMenu, const OUString& rExecutionResult) { - switch (nExecutionResult) - { - case ID_BROWSER_COLWIDTH: - static_cast<SbaGridControl*>(GetParent())->SetColWidth(nColId); - break; - - case ID_BROWSER_COLATTRSET: - static_cast<SbaGridControl*>(GetParent())->SetColAttrs(nColId); - break; - case ID_BROWSER_COLUMNINFO: - { - sal_uInt16 nModelPos = static_cast<SbaGridControl*>(GetParent())->GetModelColumnPos(nColId); - Reference< XPropertySet > xField = static_cast<SbaGridControl*>(GetParent())->getField(nModelPos); - - if(!xField.is()) - break; - std::vector< std::shared_ptr<OTableRow> > vClipboardList; - // send it to the clipboard - vClipboardList.push_back(std::make_shared<OTableRow>(xField)); - rtl::Reference<OTableRowExchange> pData = new OTableRowExchange(vClipboardList); - pData->CopyToClipboard(GetParent()); - } - break; - - default: FmGridHeader::PostExecuteColumnContextMenu(nColId, rMenu, nExecutionResult); - } + if (rExecutionResult == "colwidth") + static_cast<SbaGridControl*>(GetParent())->SetColWidth(nColId); + else if (rExecutionResult == "colattrset") + static_cast<SbaGridControl*>(GetParent())->SetColAttrs(nColId); + else + FmGridHeader::PostExecuteColumnContextMenu(nColId, rMenu, rExecutionResult); } // SbaGridControl @@ -658,7 +629,7 @@ VclPtr<BrowserHeader> SbaGridControl::imp_CreateHeaderBar(BrowseBox* pParent) return VclPtr<SbaGridHeader>::Create(pParent); } -CellController* SbaGridControl::GetController(tools::Long nRow, sal_uInt16 nCol) +CellController* SbaGridControl::GetController(sal_Int32 nRow, sal_uInt16 nCol) { if ( m_bActivatingForDrop ) return nullptr; @@ -666,26 +637,26 @@ CellController* SbaGridControl::GetController(tools::Long nRow, sal_uInt16 nCol) return FmGridControl::GetController(nRow, nCol); } -void SbaGridControl::PreExecuteRowContextMenu(sal_uInt16 nRow, PopupMenu& rMenu) +void SbaGridControl::PreExecuteRowContextMenu(weld::Menu& rMenu) { - FmGridControl::PreExecuteRowContextMenu(nRow, rMenu); + FmGridControl::PreExecuteRowContextMenu(rMenu); sal_uInt16 nPos = 0; if (!IsReadOnlyDB()) { - rMenu.InsertItem(ID_BROWSER_TABLEATTR, DBA_RES(RID_STR_TABLE_FORMAT), MenuItemBits::NONE, OString(), nPos++); - rMenu.SetHelpId(ID_BROWSER_TABLEATTR, HID_BROWSER_TABLEFORMAT); - - rMenu.InsertItem(ID_BROWSER_ROWHEIGHT, DBA_RES(RID_STR_ROW_HEIGHT), MenuItemBits::NONE, OString(), nPos++); - rMenu.SetHelpId(ID_BROWSER_ROWHEIGHT, HID_BROWSER_ROWHEIGHT); - rMenu.InsertSeparator(OString(), nPos++); + rMenu.insert(nPos++, u"tableattr"_ustr, DBA_RES(RID_STR_TABLE_FORMAT), + nullptr, nullptr, nullptr, TRISTATE_INDET); + rMenu.insert(nPos++, u"rowheight"_ustr, DBA_RES(RID_STR_ROW_HEIGHT), + nullptr, nullptr, nullptr, TRISTATE_INDET); + rMenu.insert_separator(nPos++, u"separator1"_ustr); } if ( GetSelectRowCount() > 0 ) { - rMenu.InsertItem(ID_BROWSER_COPY, DBA_RES(RID_STR_COPY), MenuItemBits::NONE, OString(), nPos++); - rMenu.InsertSeparator(OString(), nPos++); + rMenu.insert(nPos++, u"copy"_ustr, DBA_RES(RID_STR_COPY), + nullptr, nullptr, nullptr, TRISTATE_INDET); + rMenu.insert_separator(nPos++, u"separator2"_ustr); } } @@ -693,7 +664,7 @@ SvNumberFormatter* SbaGridControl::GetDatasourceFormatter() { Reference< css::util::XNumberFormatsSupplier > xSupplier = ::dbtools::getNumberFormats(::dbtools::getConnection(Reference< XRowSet > (getDataSource(),UNO_QUERY)), true, getContext()); - SvNumberFormatsSupplierObj* pSupplierImpl = comphelper::getUnoTunnelImplementation<SvNumberFormatsSupplierObj>( xSupplier ); + SvNumberFormatsSupplierObj* pSupplierImpl = comphelper::getFromUnoTunnel<SvNumberFormatsSupplierObj>( xSupplier ); if ( !pSupplierImpl ) return nullptr; @@ -771,7 +742,7 @@ void SbaGridControl::SetRowHeight() } catch(Exception&) { - OSL_FAIL("setPropertyValue: PROPERTY_ROW_HEIGHT throws an exception"); + TOOLS_WARN_EXCEPTION( "dbaccess", "setPropertyValue: PROPERTY_ROW_HEIGHT throws an exception"); } } @@ -803,15 +774,11 @@ void SbaGridControl::SetBrowserAttrs() try { Reference< XComponentContext > xContext = getContext(); - css::beans::PropertyValue aArg; - css::uno::Sequence<css::uno::Any> aArguments(2); - aArg.Name = "IntrospectedObject"; - aArg.Value <<= xGridModel; - aArguments[0] <<= aArg; - aArg.Name = "ParentWindow"; - aArg.Value <<= VCLUnoHelper::GetInterface(this); - aArguments[1] <<= aArg; - Reference<XExecutableDialog> xExecute(xContext->getServiceManager()->createInstanceWithArgumentsAndContext("com.sun.star.form.ControlFontDialog", + css::uno::Sequence<css::uno::Any> aArguments{ + Any(comphelper::makePropertyValue(u"IntrospectedObject"_ustr, xGridModel)), + Any(comphelper::makePropertyValue(u"ParentWindow"_ustr, VCLUnoHelper::GetInterface(this))) + }; + Reference<XExecutableDialog> xExecute(xContext->getServiceManager()->createInstanceWithArgumentsAndContext(u"com.sun.star.form.ControlFontDialog"_ustr, aArguments, xContext), css::uno::UNO_QUERY_THROW); xExecute->execute(); } @@ -821,24 +788,16 @@ void SbaGridControl::SetBrowserAttrs() } } -void SbaGridControl::PostExecuteRowContextMenu(sal_uInt16 nRow, const PopupMenu& rMenu, sal_uInt16 nExecutionResult) +void SbaGridControl::PostExecuteRowContextMenu(const OUString& rExecutionResult) { - switch (nExecutionResult) - { - case ID_BROWSER_TABLEATTR: - SetBrowserAttrs(); - break; - case ID_BROWSER_ROWHEIGHT: - SetRowHeight(); - break; - case ID_BROWSER_COPY: - CopySelectedRowsToClipboard(); - break; - - default: - FmGridControl::PostExecuteRowContextMenu(nRow, rMenu, nExecutionResult); - break; - } + if (rExecutionResult == "tableattr") + SetBrowserAttrs(); + else if (rExecutionResult == "rowheight") + SetRowHeight(); + else if (rExecutionResult == "copy") + CopySelectedRowsToClipboard(); + else + FmGridControl::PostExecuteRowContextMenu(rExecutionResult); } void SbaGridControl::Select() @@ -850,7 +809,7 @@ void SbaGridControl::Select() m_pMasterListener->SelectionChanged(); } -void SbaGridControl::ActivateCell(tools::Long nRow, sal_uInt16 nCol, bool bSetCellFocus /*= sal_True*/ ) +void SbaGridControl::ActivateCell(sal_Int32 nRow, sal_uInt16 nCol, bool bSetCellFocus /*= sal_True*/ ) { FmGridControl::ActivateCell(nRow, nCol, bSetCellFocus); if (m_pMasterListener) @@ -937,9 +896,9 @@ bool SbaGridControl::IsReadOnlyDB() const void SbaGridControl::MouseButtonDown( const BrowserMouseEvent& rMEvt) { - tools::Long nRow = GetRowAtYPosPixel(rMEvt.GetPosPixel().Y()); + sal_Int32 nRow = GetRowAtYPosPixel(rMEvt.GetPosPixel().Y()); sal_uInt16 nColPos = GetColumnAtXPosPixel(rMEvt.GetPosPixel().X()); - sal_uInt16 nViewPos = (nColPos == BROWSER_INVALIDID) ? sal_uInt16(-1) : nColPos-1; + sal_uInt16 nViewPos = (nColPos == BROWSER_INVALIDID) ? sal_uInt16(-1) : sal_uInt16(nColPos - 1); // 'the handle column' and 'no valid column' will both result in a view position of -1 ! bool bHitEmptySpace = (nRow > GetRowCount()) || (nViewPos == sal_uInt16(-1)); @@ -963,16 +922,16 @@ void SbaGridControl::StartDrag( sal_Int8 _nAction, const Point& _rPosPixel ) // (Yes, this is controller (not view) functionality. But collecting and evaluating all the // information necessary via UNO would be quite difficult (if not impossible) so // my laziness says 'do it here'...) - tools::Long nRow = GetRowAtYPosPixel(_rPosPixel.Y()); + sal_Int32 nRow = GetRowAtYPosPixel(_rPosPixel.Y()); sal_uInt16 nColPos = GetColumnAtXPosPixel(_rPosPixel.X()); - sal_uInt16 nViewPos = (nColPos == BROWSER_INVALIDID) ? sal_uInt16(-1) : nColPos-1; + sal_uInt16 nViewPos = (nColPos == BROWSER_INVALIDID) ? sal_uInt16(-1) : sal_uInt16(nColPos-1); // 'the handle column' and 'no valid column' will both result in a view position of -1 ! bool bCurrentRowVirtual = IsCurrentAppending() && IsModified(); // the current row doesn't really exist: the user's appending a new one and already has entered some data, // so the row contains data which has no counter part within the data source - tools::Long nCorrectRowCount = GetRowCount(); + sal_Int32 nCorrectRowCount = GetRowCount(); if (GetOptions() & DbGridControlOptions::Insert) --nCorrectRowCount; // there is an empty row for inserting records if (bCurrentRowVirtual) @@ -1047,6 +1006,7 @@ void SbaGridControl::DoColumnDrag(sal_uInt16 nColumnPos) { Reference< XPropertySet > xDataSource = getDataSource(); OSL_ENSURE(xDataSource.is(), "SbaGridControl::DoColumnDrag : invalid data source !"); + ::dbtools::ensureRowSetConnection(Reference< XRowSet >(getDataSource(),UNO_QUERY), getContext(), nullptr); Reference< XPropertySet > xAffectedCol; Reference< XPropertySet > xAffectedField; @@ -1096,8 +1056,7 @@ void SbaGridControl::implTransferSelectedRows( sal_Int16 nRowPos, bool _bTrueIfC // collect the affected rows if ((GetSelectRowCount() == 0) && (nRowPos >= 0)) { - aSelectedRows.realloc( 1 ); - aSelectedRows[0] <<= static_cast<sal_Int32>(nRowPos + 1); + aSelectedRows = { Any(static_cast<sal_Int32>(nRowPos + 1)) }; bSelectionBookmarks = false; } else if ( !IsAllSelected() && GetSelectRowCount() ) @@ -1129,12 +1088,12 @@ void SbaGridControl::DoFieldDrag(sal_uInt16 nColumnPos, sal_Int16 nRowPos) try { OUString sCellText; - Reference< XGridFieldDataSupplier > xFieldData(static_cast< XGridPeer* >(GetPeer()), UNO_QUERY); + Reference< XGridFieldDataSupplier > xFieldData(GetPeer()); Sequence<sal_Bool> aSupportingText = xFieldData->queryFieldDataType(cppu::UnoType<decltype(sCellText)>::get()); - if (aSupportingText.getConstArray()[nColumnPos]) + if (aSupportingText[nColumnPos]) { Sequence< Any> aCellContents = xFieldData->queryFieldData(nRowPos, cppu::UnoType<decltype(sCellText)>::get()); - sCellText = ::comphelper::getString(aCellContents.getConstArray()[nColumnPos]); + sCellText = ::comphelper::getString(aCellContents[nColumnPos]); ::svt::OStringTransfer::StartStringDrag(sCellText, this, DND_ACTION_COPY); } } @@ -1175,82 +1134,83 @@ sal_Int8 SbaGridControl::AcceptDrop( const BrowserAcceptDropEvent& rEvt ) if (!::dbtools::getConnection(Reference< XRowSet > (getDataSource(),UNO_QUERY)).is()) return nAction; - if ( IsDropFormatSupported( SotClipboardFormatId::STRING ) ) do - { // odd construction, but spares us a lot of (explicit ;) goto's + if ( IsDropFormatSupported( SotClipboardFormatId::STRING ) ) + do + { // odd construction, but spares us a lot of (explicit ;) goto's - if (!GetEmptyRow().is()) - // without an empty row we're not in update mode - break; + if (!GetEmptyRow().is()) + // without an empty row we're not in update mode + break; - const tools::Long nRow = GetRowAtYPosPixel(rEvt.maPosPixel.Y(), false); - const sal_uInt16 nCol = GetColumnId(GetColumnAtXPosPixel(rEvt.maPosPixel.X())); + const sal_Int32 nRow = GetRowAtYPosPixel(rEvt.maPosPixel.Y(), false); + const sal_uInt16 nCol = GetColumnId(GetColumnAtXPosPixel(rEvt.maPosPixel.X())); - tools::Long nCorrectRowCount = GetRowCount(); - if (GetOptions() & DbGridControlOptions::Insert) - --nCorrectRowCount; // there is an empty row for inserting records - if (IsCurrentAppending()) - --nCorrectRowCount; // the current data record doesn't really exist, we are appending a new one + sal_Int32 nCorrectRowCount = GetRowCount(); + if (GetOptions() & DbGridControlOptions::Insert) + --nCorrectRowCount; // there is an empty row for inserting records + if (IsCurrentAppending()) + --nCorrectRowCount; // the current data record doesn't really exist, we are appending a new one - if ( (nCol == BROWSER_INVALIDID) || (nRow >= nCorrectRowCount) || (nCol == 0) ) - // no valid cell under the mouse cursor - break; + if ( (nCol == BROWSER_INVALIDID) || (nRow >= nCorrectRowCount) || (nCol == 0) ) + // no valid cell under the mouse cursor + break; - tools::Rectangle aRect = GetCellRect(nRow, nCol, false); - if (!aRect.IsInside(rEvt.maPosPixel)) - // not dropped within a cell (a cell isn't as wide as the column - the are small spaces) - break; + tools::Rectangle aRect = GetCellRect(nRow, nCol, false); + if (!aRect.Contains(rEvt.maPosPixel)) + // not dropped within a cell (a cell isn't as wide as the column - the are small spaces) + break; - if ((IsModified() || (GetCurrentRow().is() && GetCurrentRow()->IsModified())) && (GetCurrentPos() != nRow)) - // there is a current and modified row or cell and he text is to be dropped into another one - break; + if ((IsModified() || (GetCurrentRow().is() && GetCurrentRow()->IsModified())) && (GetCurrentPos() != nRow)) + // there is a current and modified row or cell and he text is to be dropped into another one + break; - CellControllerRef xCurrentController = Controller(); - if (xCurrentController.is() && xCurrentController->IsValueChangedFromSaved() && ((nRow != GetCurRow()) || (nCol != GetCurColumnId()))) - // the current controller is modified and the user wants to drop in another cell -> no chance - // (when leaving the modified cell an error may occur - this is deadly while dragging) - break; + CellControllerRef xCurrentController = Controller(); + if (xCurrentController.is() && xCurrentController->IsValueChangedFromSaved() && ((nRow != GetCurRow()) || (nCol != GetCurColumnId()))) + // the current controller is modified and the user wants to drop in another cell -> no chance + // (when leaving the modified cell an error may occur - this is deadly while dragging) + break; - Reference< XPropertySet > xField = getField(GetModelColumnPos(nCol)); - if (!xField.is()) - // the column is not valid bound (for instance a binary field) - break; + Reference< XPropertySet > xField = getField(GetModelColumnPos(nCol)); + if (!xField.is()) + // the column is not valid bound (for instance a binary field) + break; - try - { - if (::comphelper::getBOOL(xField->getPropertyValue(PROPERTY_ISREADONLY))) + try + { + if (::comphelper::getBOOL(xField->getPropertyValue(PROPERTY_ISREADONLY))) + break; + } + catch (const Exception& ) + { + // assume RO break; - } - catch (const Exception& ) - { - // assume RO - break; - } + } - try - { - // assume that text can be dropped into a field if the column has a css::awt::XTextComponent interface - Reference< XIndexAccess > xColumnControls(static_cast<css::form::XGridPeer*>(GetPeer()), UNO_QUERY); - if (xColumnControls.is()) + try { - Reference< css::awt::XTextComponent > xColControl( - xColumnControls->getByIndex(GetViewColumnPos(nCol)), - css::uno::UNO_QUERY); - if (xColControl.is()) + // assume that text can be dropped into a field if the column has a css::awt::XTextComponent interface + Reference< XIndexAccess > xColumnControls(GetPeer()); + if (xColumnControls.is()) { - m_bActivatingForDrop = true; - GoToRowColumnId(nRow, nCol); - m_bActivatingForDrop = false; - - nAction = DND_ACTION_COPY; + Reference< css::awt::XTextComponent > xColControl( + xColumnControls->getByIndex(GetViewColumnPos(nCol)), + css::uno::UNO_QUERY); + if (xColControl.is()) + { + m_bActivatingForDrop = true; + GoToRowColumnId(nRow, nCol); + m_bActivatingForDrop = false; + + nAction = DND_ACTION_COPY; + } } } - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION("dbaccess"); - } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION("dbaccess"); + } - } while (false); + } while (false); if(nAction != DND_ACTION_COPY && GetEmptyRow().is()) { @@ -1275,10 +1235,10 @@ sal_Int8 SbaGridControl::ExecuteDrop( const BrowserExecuteDropEvent& rEvt ) if ( IsDropFormatSupported( SotClipboardFormatId::STRING ) ) { - tools::Long nRow = GetRowAtYPosPixel(rEvt.maPosPixel.Y(), false); + sal_Int32 nRow = GetRowAtYPosPixel(rEvt.maPosPixel.Y(), false); sal_uInt16 nCol = GetColumnAtXPosPixel(rEvt.maPosPixel.X()); - tools::Long nCorrectRowCount = GetRowCount(); + sal_Int32 nCorrectRowCount = GetRowCount(); if (GetOptions() & DbGridControlOptions::Insert) --nCorrectRowCount; // there is an empty row for inserting records if (IsCurrentAppending()) @@ -1389,10 +1349,10 @@ IMPL_LINK_NOARG(SbaGridControl, AsynchDropEvent, void*, void) m_aDataDescriptor.clear(); } -OUString SbaGridControl::GetAccessibleObjectDescription( ::vcl::AccessibleBrowseBoxObjType eObjType,sal_Int32 _nPosition) const +OUString SbaGridControl::GetAccessibleObjectDescription( AccessibleBrowseBoxObjType eObjType,sal_Int32 _nPosition) const { OUString sRet; - if ( ::vcl::BBTYPE_BROWSEBOX == eObjType ) + if ( AccessibleBrowseBoxObjType::BrowseBox == eObjType ) { SolarMutexGuard aGuard; sRet = DBA_RES(STR_DATASOURCE_GRIDCONTROL_DESC); diff --git a/dbaccess/source/ui/browser/sbamultiplex.cxx b/dbaccess/source/ui/browser/sbamultiplex.cxx index 68673fd06ff2..8bf7ed747c03 100644 --- a/dbaccess/source/ui/browser/sbamultiplex.cxx +++ b/dbaccess/source/ui/browser/sbamultiplex.cxx @@ -18,79 +18,511 @@ */ #include <sbamultiplex.hxx> +#include <cppuhelper/queryinterface.hxx> + using namespace dbaui; // the listener multiplexers // XStatusListener -IMPLEMENT_LISTENER_MULTIPLEXER_CORE(SbaXStatusMultiplexer, css::frame::XStatusListener) +SbaXStatusMultiplexer::SbaXStatusMultiplexer(::cppu::OWeakObject& rSource, ::osl::Mutex& _rMutex) + :OSbaWeakSubObject(rSource) + ,OInterfaceContainerHelper3(_rMutex) +{ +} + +css::uno::Any SAL_CALL SbaXStatusMultiplexer::queryInterface(const css::uno::Type& _rType) +{ + css::uno::Any aReturn = OSbaWeakSubObject::queryInterface(_rType); + if (!aReturn.hasValue()) + aReturn = ::cppu::queryInterface(_rType, + static_cast< css::frame::XStatusListener* >(this), + static_cast< css::lang::XEventListener* >(static_cast< css::frame::XStatusListener* >(this)) + ); + + return aReturn; +} +void SAL_CALL SbaXStatusMultiplexer::disposing(const css::lang::EventObject& ) +{ +} + void SAL_CALL SbaXStatusMultiplexer::statusChanged(const css::frame::FeatureStateEvent& e) { m_aLastKnownStatus = e; m_aLastKnownStatus.Source = &m_rParent; - ::comphelper::OInterfaceIteratorHelper2 aIt( *this ); - while ( aIt.hasMoreElements() ) - static_cast< css::frame::XStatusListener* >( aIt.next() )->statusChanged( m_aLastKnownStatus ); + notifyEach( &XStatusListener::statusChanged, m_aLastKnownStatus ); } // LoadListener -IMPLEMENT_LISTENER_MULTIPLEXER_CORE(SbaXLoadMultiplexer, css::form::XLoadListener) -IMPLEMENT_LISTENER_MULTIPLEXER_VOID_METHOD(SbaXLoadMultiplexer, css::form::XLoadListener, loaded, css::lang::EventObject) -IMPLEMENT_LISTENER_MULTIPLEXER_VOID_METHOD(SbaXLoadMultiplexer, css::form::XLoadListener, unloaded, css::lang::EventObject) -IMPLEMENT_LISTENER_MULTIPLEXER_VOID_METHOD(SbaXLoadMultiplexer, css::form::XLoadListener, unloading, css::lang::EventObject) -IMPLEMENT_LISTENER_MULTIPLEXER_VOID_METHOD(SbaXLoadMultiplexer, css::form::XLoadListener, reloading, css::lang::EventObject) -IMPLEMENT_LISTENER_MULTIPLEXER_VOID_METHOD(SbaXLoadMultiplexer, css::form::XLoadListener, reloaded, css::lang::EventObject) +SbaXLoadMultiplexer::SbaXLoadMultiplexer(::cppu::OWeakObject& rSource, ::osl::Mutex& _rMutex) + :OSbaWeakSubObject(rSource) + ,OInterfaceContainerHelper3(_rMutex) +{ +} + +css::uno::Any SAL_CALL SbaXLoadMultiplexer::queryInterface(const css::uno::Type& _rType) +{ + css::uno::Any aReturn = OSbaWeakSubObject::queryInterface(_rType); + if (!aReturn.hasValue()) + aReturn = ::cppu::queryInterface(_rType, + static_cast< css::form::XLoadListener* >(this), + static_cast< css::lang::XEventListener* >(static_cast< css::form::XLoadListener* >(this)) + ); + + return aReturn; +} +void SAL_CALL SbaXLoadMultiplexer::disposing(const css::lang::EventObject& ) +{ +} + +void SAL_CALL SbaXLoadMultiplexer::loaded(const css::lang::EventObject& e) +{ + css::lang::EventObject aMulti(e); + aMulti.Source = &m_rParent; + notifyEach( &XLoadListener::loaded, aMulti ); +} +void SAL_CALL SbaXLoadMultiplexer::unloaded(const css::lang::EventObject& e) +{ + css::lang::EventObject aMulti(e); + aMulti.Source = &m_rParent; + notifyEach( &XLoadListener::unloaded, aMulti ); +} + +void SAL_CALL SbaXLoadMultiplexer::unloading(const css::lang::EventObject& e) +{ + css::lang::EventObject aMulti(e); + aMulti.Source = &m_rParent; + notifyEach( &XLoadListener::unloading, aMulti ); +} + +void SAL_CALL SbaXLoadMultiplexer::reloading(const css::lang::EventObject& e) +{ + css::lang::EventObject aMulti(e); + aMulti.Source = &m_rParent; + notifyEach( &XLoadListener::reloading, aMulti ); +} + +void SAL_CALL SbaXLoadMultiplexer::reloaded(const css::lang::EventObject& e) +{ + css::lang::EventObject aMulti(e); + aMulti.Source = &m_rParent; + notifyEach( &XLoadListener::reloaded, aMulti ); +} + // css::sdbc::XRowSetListener -IMPLEMENT_LISTENER_MULTIPLEXER_CORE(SbaXRowSetMultiplexer, css::sdbc::XRowSetListener) -IMPLEMENT_LISTENER_MULTIPLEXER_VOID_METHOD(SbaXRowSetMultiplexer, css::sdbc::XRowSetListener, cursorMoved, css::lang::EventObject) -IMPLEMENT_LISTENER_MULTIPLEXER_VOID_METHOD(SbaXRowSetMultiplexer, css::sdbc::XRowSetListener, rowChanged, css::lang::EventObject) -IMPLEMENT_LISTENER_MULTIPLEXER_VOID_METHOD(SbaXRowSetMultiplexer, css::sdbc::XRowSetListener, rowSetChanged, css::lang::EventObject) +SbaXRowSetMultiplexer::SbaXRowSetMultiplexer(::cppu::OWeakObject& rSource, ::osl::Mutex& _rMutex) + :OSbaWeakSubObject(rSource) + ,OInterfaceContainerHelper3(_rMutex) +{ +} + +css::uno::Any SAL_CALL SbaXRowSetMultiplexer::queryInterface(const css::uno::Type& _rType) +{ + css::uno::Any aReturn = OSbaWeakSubObject::queryInterface(_rType); + if (!aReturn.hasValue()) + aReturn = ::cppu::queryInterface(_rType, + static_cast< css::sdbc::XRowSetListener* >(this), + static_cast< css::lang::XEventListener* >(static_cast< css::sdbc::XRowSetListener* >(this)) + ); + + return aReturn; +} +void SAL_CALL SbaXRowSetMultiplexer::disposing(const css::lang::EventObject& ) +{ +} + +void SAL_CALL SbaXRowSetMultiplexer::cursorMoved(const css::lang::EventObject& e) +{ + css::lang::EventObject aMulti(e); + aMulti.Source = &m_rParent; + notifyEach( &XRowSetListener::cursorMoved, aMulti ); +} + +void SAL_CALL SbaXRowSetMultiplexer::rowChanged(const css::lang::EventObject& e) +{ + css::lang::EventObject aMulti(e); + aMulti.Source = &m_rParent; + notifyEach( &XRowSetListener::rowChanged, aMulti ); +} + +void SAL_CALL SbaXRowSetMultiplexer::rowSetChanged(const css::lang::EventObject& e) +{ + css::lang::EventObject aMulti(e); + aMulti.Source = &m_rParent; + notifyEach( &XRowSetListener::rowSetChanged, aMulti ); +} // css::sdb::XRowSetApproveListener -IMPLEMENT_LISTENER_MULTIPLEXER_CORE(SbaXRowSetApproveMultiplexer, css::sdb::XRowSetApproveListener) -IMPLEMENT_LISTENER_MULTIPLEXER_BOOL_METHOD(SbaXRowSetApproveMultiplexer, css::sdb::XRowSetApproveListener, approveCursorMove, css::lang::EventObject) -IMPLEMENT_LISTENER_MULTIPLEXER_BOOL_METHOD(SbaXRowSetApproveMultiplexer, css::sdb::XRowSetApproveListener, approveRowChange, css::sdb::RowChangeEvent) -IMPLEMENT_LISTENER_MULTIPLEXER_BOOL_METHOD(SbaXRowSetApproveMultiplexer, css::sdb::XRowSetApproveListener, approveRowSetChange, css::lang::EventObject) +SbaXRowSetApproveMultiplexer::SbaXRowSetApproveMultiplexer(::cppu::OWeakObject& rSource, ::osl::Mutex& _rMutex) + :OSbaWeakSubObject(rSource) + ,OInterfaceContainerHelper3(_rMutex) +{ +} + +css::uno::Any SAL_CALL SbaXRowSetApproveMultiplexer::queryInterface(const css::uno::Type& _rType) +{ + css::uno::Any aReturn = OSbaWeakSubObject::queryInterface(_rType); + if (!aReturn.hasValue()) + aReturn = ::cppu::queryInterface(_rType, + static_cast< css::sdb::XRowSetApproveListener* >(this), + static_cast< css::lang::XEventListener* >(static_cast< css::sdb::XRowSetApproveListener* >(this)) + ); + + return aReturn; +} +void SAL_CALL SbaXRowSetApproveMultiplexer::disposing(const css::lang::EventObject& ) +{ +} + +sal_Bool SAL_CALL SbaXRowSetApproveMultiplexer::approveCursorMove(const css::lang::EventObject& e) +{ + css::lang::EventObject aMulti(e); + aMulti.Source = &m_rParent; + ::comphelper::OInterfaceIteratorHelper3 aIt(*this); + bool bResult = true; + while (bResult && aIt.hasMoreElements()) + bResult = aIt.next()->approveCursorMove(aMulti); + return bResult; +} + +sal_Bool SAL_CALL SbaXRowSetApproveMultiplexer::approveRowChange(const css::sdb::RowChangeEvent& e) +{ + css::sdb::RowChangeEvent aMulti(e); + aMulti.Source = &m_rParent; + ::comphelper::OInterfaceIteratorHelper3 aIt(*this); + bool bResult = true; + while (bResult && aIt.hasMoreElements()) + bResult = aIt.next()->approveRowChange(aMulti); + return bResult; +} + +sal_Bool SAL_CALL SbaXRowSetApproveMultiplexer::approveRowSetChange(const css::lang::EventObject& e) +{ + css::lang::EventObject aMulti(e); + aMulti.Source = &m_rParent; + ::comphelper::OInterfaceIteratorHelper3 aIt(*this); + bool bResult = true; + while (bResult && aIt.hasMoreElements()) + bResult = aIt.next()->approveRowSetChange(aMulti); + return bResult; +} // css::sdb::XSQLErrorListener -IMPLEMENT_LISTENER_MULTIPLEXER_CORE(SbaXSQLErrorMultiplexer, css::sdb::XSQLErrorListener) -IMPLEMENT_LISTENER_MULTIPLEXER_VOID_METHOD(SbaXSQLErrorMultiplexer, css::sdb::XSQLErrorListener, errorOccured, css::sdb::SQLErrorEvent) +SbaXSQLErrorMultiplexer::SbaXSQLErrorMultiplexer(::cppu::OWeakObject& rSource, ::osl::Mutex& _rMutex) + :OSbaWeakSubObject(rSource) + ,OInterfaceContainerHelper3(_rMutex) +{ +} + +css::uno::Any SAL_CALL SbaXSQLErrorMultiplexer::queryInterface(const css::uno::Type& _rType) +{ + css::uno::Any aReturn = OSbaWeakSubObject::queryInterface(_rType); + if (!aReturn.hasValue()) + aReturn = ::cppu::queryInterface(_rType, + static_cast< css::sdb::XSQLErrorListener* >(this), + static_cast< css::lang::XEventListener* >(static_cast< css::sdb::XSQLErrorListener* >(this)) + ); + + return aReturn; +} +void SAL_CALL SbaXSQLErrorMultiplexer::disposing(const css::lang::EventObject& ) +{ +} + +void SAL_CALL SbaXSQLErrorMultiplexer::errorOccured(const css::sdb::SQLErrorEvent& e) +{ + css::sdb::SQLErrorEvent aMulti(e); + aMulti.Source = &m_rParent; + notifyEach( &XSQLErrorListener::errorOccured, aMulti ); +} // css::form::XDatabaseParameterListener -IMPLEMENT_LISTENER_MULTIPLEXER_CORE(SbaXParameterMultiplexer, css::form::XDatabaseParameterListener) -IMPLEMENT_LISTENER_MULTIPLEXER_BOOL_METHOD(SbaXParameterMultiplexer, css::form::XDatabaseParameterListener, approveParameter, css::form::DatabaseParameterEvent) +SbaXParameterMultiplexer::SbaXParameterMultiplexer(::cppu::OWeakObject& rSource, ::osl::Mutex& _rMutex) + :OSbaWeakSubObject(rSource) + ,OInterfaceContainerHelper3(_rMutex) +{ +} + +css::uno::Any SAL_CALL SbaXParameterMultiplexer::queryInterface(const css::uno::Type& _rType) +{ + css::uno::Any aReturn = OSbaWeakSubObject::queryInterface(_rType); + if (!aReturn.hasValue()) + aReturn = ::cppu::queryInterface(_rType, + static_cast< css::form::XDatabaseParameterListener* >(this), + static_cast< css::lang::XEventListener* >(static_cast< css::form::XDatabaseParameterListener* >(this)) + ); + + return aReturn; +} +void SAL_CALL SbaXParameterMultiplexer::disposing(const css::lang::EventObject& ) +{ +} + +sal_Bool SAL_CALL SbaXParameterMultiplexer::approveParameter(const css::form::DatabaseParameterEvent& e) +{ + css::form::DatabaseParameterEvent aMulti(e); + aMulti.Source = &m_rParent; + ::comphelper::OInterfaceIteratorHelper3 aIt(*this); + bool bResult = true; + while (bResult && aIt.hasMoreElements()) + bResult = aIt.next()->approveParameter(aMulti); + return bResult; +} // css::form::XSubmitListener -IMPLEMENT_LISTENER_MULTIPLEXER_CORE(SbaXSubmitMultiplexer, css::form::XSubmitListener) -IMPLEMENT_LISTENER_MULTIPLEXER_BOOL_METHOD(SbaXSubmitMultiplexer, css::form::XSubmitListener, approveSubmit, css::lang::EventObject) +SbaXSubmitMultiplexer::SbaXSubmitMultiplexer(::cppu::OWeakObject& rSource, ::osl::Mutex& _rMutex) + :OSbaWeakSubObject(rSource) + ,OInterfaceContainerHelper3(_rMutex) +{ +} + +css::uno::Any SAL_CALL SbaXSubmitMultiplexer::queryInterface(const css::uno::Type& _rType) +{ + css::uno::Any aReturn = OSbaWeakSubObject::queryInterface(_rType); + if (!aReturn.hasValue()) + aReturn = ::cppu::queryInterface(_rType, + static_cast< css::form::XSubmitListener* >(this), + static_cast< css::lang::XEventListener* >(static_cast< css::form::XSubmitListener* >(this)) + ); + + return aReturn; +} +void SAL_CALL SbaXSubmitMultiplexer::disposing(const css::lang::EventObject& ) +{ +} + + + +sal_Bool SAL_CALL SbaXSubmitMultiplexer::approveSubmit(const css::lang::EventObject& e) +{ + css::lang::EventObject aMulti(e); + aMulti.Source = &m_rParent; + ::comphelper::OInterfaceIteratorHelper3 aIt(*this); + bool bResult = true; + while (bResult && aIt.hasMoreElements()) + bResult = aIt.next()->approveSubmit(aMulti); + return bResult; +} // css::form::XResetListener -IMPLEMENT_LISTENER_MULTIPLEXER_CORE(SbaXResetMultiplexer, css::form::XResetListener) -IMPLEMENT_LISTENER_MULTIPLEXER_BOOL_METHOD(SbaXResetMultiplexer, css::form::XResetListener, approveReset, css::lang::EventObject) -IMPLEMENT_LISTENER_MULTIPLEXER_VOID_METHOD(SbaXResetMultiplexer, css::form::XResetListener, resetted, css::lang::EventObject) +SbaXResetMultiplexer::SbaXResetMultiplexer(::cppu::OWeakObject& rSource, ::osl::Mutex& _rMutex) + :OSbaWeakSubObject(rSource) + ,OInterfaceContainerHelper3(_rMutex) +{ +} + +css::uno::Any SAL_CALL SbaXResetMultiplexer::queryInterface(const css::uno::Type& _rType) +{ + css::uno::Any aReturn = OSbaWeakSubObject::queryInterface(_rType); + if (!aReturn.hasValue()) + aReturn = ::cppu::queryInterface(_rType, + static_cast< css::form::XResetListener* >(this), + static_cast< css::lang::XEventListener* >(static_cast< css::form::XResetListener* >(this)) + ); + + return aReturn; +} +void SAL_CALL SbaXResetMultiplexer::disposing(const css::lang::EventObject& ) +{ +} + + +sal_Bool SAL_CALL SbaXResetMultiplexer::approveReset(const css::lang::EventObject& e) +{ + css::lang::EventObject aMulti(e); + aMulti.Source = &m_rParent; + ::comphelper::OInterfaceIteratorHelper3 aIt(*this); + bool bResult = true; + while (bResult && aIt.hasMoreElements()) + bResult = aIt.next()->approveReset(aMulti); + return bResult; +} + +void SAL_CALL SbaXResetMultiplexer::resetted(const css::lang::EventObject& e) +{ + css::lang::EventObject aMulti(e); + aMulti.Source = &m_rParent; + notifyEach( &XResetListener::resetted, aMulti ); +} // css::beans::XPropertyChangeListener -IMPLEMENT_PROPERTY_MULTIPLEXER(SbaXPropertyChangeMultiplexer, css::beans::XPropertyChangeListener, propertyChange, css::beans::PropertyChangeEvent) +SbaXPropertyChangeMultiplexer::SbaXPropertyChangeMultiplexer(::cppu::OWeakObject& rSource, ::osl::Mutex& rMutex) + :OSbaWeakSubObject(rSource) + ,m_aListeners(rMutex) +{ +} + +css::uno::Any SAL_CALL SbaXPropertyChangeMultiplexer::queryInterface(const css::uno::Type& _rType) +{ + css::uno::Any aReturn = OSbaWeakSubObject::queryInterface(_rType); + if (!aReturn.hasValue()) + aReturn = ::cppu::queryInterface(_rType, + static_cast< css::beans::XPropertyChangeListener* >(this), + static_cast< css::lang::XEventListener* >(static_cast< css::beans::XPropertyChangeListener* >(this)) + ); + + return aReturn; +} +void SAL_CALL SbaXPropertyChangeMultiplexer::disposing(const css::lang::EventObject& ) +{ +} +void SAL_CALL SbaXPropertyChangeMultiplexer::propertyChange(const css::beans::PropertyChangeEvent& e) +{ + ::comphelper::OInterfaceContainerHelper3<XPropertyChangeListener>* pListeners = m_aListeners.getContainer(e.PropertyName); + if (pListeners) + Notify(*pListeners, e); + + /* do the notification for the unspecialized listeners, too */ + pListeners = m_aListeners.getContainer(OUString()); + if (pListeners) + Notify(*pListeners, e); +} + +void SbaXPropertyChangeMultiplexer::addInterface(const OUString& rName, + const css::uno::Reference< css::beans::XPropertyChangeListener > & rListener) +{ + m_aListeners.addInterface(rName, rListener); +} + +void SbaXPropertyChangeMultiplexer::removeInterface(const OUString& rName, + const css::uno::Reference< css::beans::XPropertyChangeListener > & rListener) +{ + m_aListeners.removeInterface(rName, rListener); +} + +void SbaXPropertyChangeMultiplexer::disposeAndClear() +{ + css::lang::EventObject aEvt(m_rParent); + m_aListeners.disposeAndClear(aEvt); +} + +sal_Int32 SbaXPropertyChangeMultiplexer::getOverallLen() const +{ + sal_Int32 nLen = 0; + const std::vector< OUString > aContained = m_aListeners.getContainedTypes(); + for ( OUString const & s : aContained) + { + ::comphelper::OInterfaceContainerHelper3<XPropertyChangeListener>* pListeners = m_aListeners.getContainer(s); + if (!pListeners) + continue; + nLen += pListeners->getLength(); + } + return nLen; +} + +void SbaXPropertyChangeMultiplexer::Notify(::comphelper::OInterfaceContainerHelper3<XPropertyChangeListener>& rListeners, const css::beans::PropertyChangeEvent& e) +{ + css::beans::PropertyChangeEvent aMulti(e); + aMulti.Source = &m_rParent; + rListeners.notifyEach( &XPropertyChangeListener::propertyChange, aMulti ); +} // css::beans::XVetoableChangeListener -IMPLEMENT_PROPERTY_MULTIPLEXER(SbaXVetoableChangeMultiplexer, css::beans::XVetoableChangeListener, vetoableChange, css::beans::PropertyChangeEvent) +SbaXVetoableChangeMultiplexer::SbaXVetoableChangeMultiplexer(::cppu::OWeakObject& rSource, ::osl::Mutex& rMutex) + :OSbaWeakSubObject(rSource) + ,m_aListeners(rMutex) +{ +} + +css::uno::Any SAL_CALL SbaXVetoableChangeMultiplexer::queryInterface(const css::uno::Type& _rType) +{ + css::uno::Any aReturn = OSbaWeakSubObject::queryInterface(_rType); + if (!aReturn.hasValue()) + aReturn = ::cppu::queryInterface(_rType, + static_cast< css::beans::XVetoableChangeListener* >(this), + static_cast< css::lang::XEventListener* >(static_cast< css::beans::XVetoableChangeListener* >(this)) + ); + + return aReturn; +} +void SAL_CALL SbaXVetoableChangeMultiplexer::disposing(const css::lang::EventObject& ) +{ +} +void SAL_CALL SbaXVetoableChangeMultiplexer::vetoableChange(const css::beans::PropertyChangeEvent& e) +{ + ::comphelper::OInterfaceContainerHelper3<css::beans::XVetoableChangeListener>* pListeners = m_aListeners.getContainer(e.PropertyName); + if (pListeners) + Notify(*pListeners, e); + + /* do the notification for the unspecialized listeners, too */ + pListeners = m_aListeners.getContainer(OUString()); + if (pListeners) + Notify(*pListeners, e); +} + +void SbaXVetoableChangeMultiplexer::addInterface(const OUString& rName, + const css::uno::Reference< css::beans::XVetoableChangeListener > & rListener) +{ + m_aListeners.addInterface(rName, rListener); +} + +void SbaXVetoableChangeMultiplexer::removeInterface(const OUString& rName, + const css::uno::Reference< css::beans::XVetoableChangeListener > & rListener) +{ + m_aListeners.removeInterface(rName, rListener); +} + +void SbaXVetoableChangeMultiplexer::disposeAndClear() +{ + css::lang::EventObject aEvt(m_rParent); + m_aListeners.disposeAndClear(aEvt); +} + +sal_Int32 SbaXVetoableChangeMultiplexer::getOverallLen() const +{ + sal_Int32 nLen = 0; + const std::vector< OUString > aContained = m_aListeners.getContainedTypes(); + for ( OUString const & s : aContained) + { + ::comphelper::OInterfaceContainerHelper3<XVetoableChangeListener>* pListeners = m_aListeners.getContainer(s); + if (!pListeners) + continue; + nLen += pListeners->getLength(); + } + return nLen; +} + +void SbaXVetoableChangeMultiplexer::Notify(::comphelper::OInterfaceContainerHelper3<XVetoableChangeListener>& rListeners, const css::beans::PropertyChangeEvent& e) +{ + css::beans::PropertyChangeEvent aMulti(e); + aMulti.Source = &m_rParent; + rListeners.notifyEach( &XVetoableChangeListener::vetoableChange, aMulti ); +} // css::beans::XPropertiesChangeListener -IMPLEMENT_LISTENER_MULTIPLEXER_CORE(SbaXPropertiesChangeMultiplexer, css::beans::XPropertiesChangeListener); +SbaXPropertiesChangeMultiplexer::SbaXPropertiesChangeMultiplexer(::cppu::OWeakObject& rSource, ::osl::Mutex& _rMutex) + :OSbaWeakSubObject(rSource) + ,OInterfaceContainerHelper3(_rMutex) +{ +} + +css::uno::Any SAL_CALL SbaXPropertiesChangeMultiplexer::queryInterface(const css::uno::Type& _rType) +{ + css::uno::Any aReturn = OSbaWeakSubObject::queryInterface(_rType); + if (!aReturn.hasValue()) + aReturn = ::cppu::queryInterface(_rType, + static_cast< css::beans::XPropertiesChangeListener* >(this), + static_cast< css::lang::XEventListener* >(static_cast< css::beans::XPropertiesChangeListener* >(this)) + ); + + return aReturn; +} +void SAL_CALL SbaXPropertiesChangeMultiplexer::disposing(const css::lang::EventObject& ) +{ +} + void SbaXPropertiesChangeMultiplexer::propertiesChange(const css::uno::Sequence< css::beans::PropertyChangeEvent>& aEvts) { // the SbaXPropertiesChangeMultiplexer doesn't care about the property names a listener logs on for, it simply // forwards _all_ changes to _all_ listeners css::uno::Sequence< css::beans::PropertyChangeEvent> aMulti(aEvts); - for (css::beans::PropertyChangeEvent & rEvent : aMulti) + for (css::beans::PropertyChangeEvent & rEvent : asNonConstRange(aMulti)) rEvent.Source = &m_rParent; - ::comphelper::OInterfaceIteratorHelper2 aIt(*this); - while (aIt.hasMoreElements()) - static_cast< css::beans::XPropertiesChangeListener*>(aIt.next())->propertiesChange(aMulti); + notifyEach( &css::beans::XPropertiesChangeListener::propertiesChange, aMulti ); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/ui/browser/unodatbr.cxx b/dbaccess/source/ui/browser/unodatbr.cxx index aa465eff620a..283f3680afd6 100644 --- a/dbaccess/source/ui/browser/unodatbr.cxx +++ b/dbaccess/source/ui/browser/unodatbr.cxx @@ -72,7 +72,6 @@ #include <com/sun/star/document/MacroExecMode.hpp> #include <com/sun/star/ui/XContextMenuInterceptor.hpp> -#include <comphelper/processfactory.hxx> #include <comphelper/extract.hxx> #include <comphelper/sequence.hxx> #include <comphelper/types.hxx> @@ -83,12 +82,13 @@ #include <svx/dataaccessdescriptor.hxx> #include <svx/databaseregistrationui.hxx> #include <toolkit/helper/vclunohelper.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <osl/diagnose.h> #include <sal/log.hxx> #include <tools/multisel.hxx> #include <tools/urlobj.hxx> #include <unotools/confignode.hxx> +#include <utility> #include <vcl/split.hxx> #include <vcl/svapp.hxx> #include <vcl/toolbox.hxx> @@ -111,7 +111,6 @@ using namespace ::com::sun::star::lang; using namespace ::com::sun::star::ui::dialogs; using namespace ::com::sun::star::task; using namespace ::com::sun::star::form; -using namespace ::com::sun::star::io; using namespace ::com::sun::star::i18n; using namespace ::com::sun::star::view; using namespace ::com::sun::star::datatransfer; @@ -152,12 +151,12 @@ static void SafeRemovePropertyListener(const Reference< XPropertySet > & xSet, c OUString SAL_CALL SbaTableQueryBrowser::getImplementationName() { - return "org.openoffice.comp.dbu.ODatasourceBrowser"; + return u"org.openoffice.comp.dbu.ODatasourceBrowser"_ustr; } css::uno::Sequence<OUString> SAL_CALL SbaTableQueryBrowser::getSupportedServiceNames() { - return { "com.sun.star.sdb.DataSourceBrowser" }; + return { u"com.sun.star.sdb.DataSourceBrowser"_ustr }; } SbaTableQueryBrowser::SbaTableQueryBrowser(const Reference< XComponentContext >& _rM) @@ -193,9 +192,9 @@ Any SAL_CALL SbaTableQueryBrowser::queryInterface(const Type& _rType) { if ( _rType.equals( cppu::UnoType<XScriptInvocationContext>::get() ) ) { - OSL_PRECOND( !!m_aDocScriptSupport, "SbaTableQueryBrowser::queryInterface: did not initialize this, yet!" ); - if ( !!m_aDocScriptSupport && *m_aDocScriptSupport ) - return makeAny( Reference< XScriptInvocationContext >( this ) ); + OSL_PRECOND( m_aDocScriptSupport.has_value(), "SbaTableQueryBrowser::queryInterface: did not initialize this, yet!" ); + if ( m_aDocScriptSupport.has_value() && *m_aDocScriptSupport ) + return Any( Reference< XScriptInvocationContext >( this ) ); return Any(); } @@ -212,13 +211,14 @@ Sequence< Type > SAL_CALL SbaTableQueryBrowser::getTypes( ) SbaTableQueryBrowser_Base::getTypes() ) ); - OSL_PRECOND( !!m_aDocScriptSupport, "SbaTableQueryBrowser::getTypes: did not initialize this, yet!" ); - if ( !m_aDocScriptSupport || !*m_aDocScriptSupport ) + OSL_PRECOND( m_aDocScriptSupport.has_value(), "SbaTableQueryBrowser::getTypes: did not initialize this, yet!" ); + if ( !m_aDocScriptSupport.has_value() || !*m_aDocScriptSupport ) { - auto newEnd = std::remove_if( aTypes.begin(), aTypes.end(), + auto [begin, end] = asNonConstRange(aTypes); + auto newEnd = std::remove_if( begin, end, [](const Type& type) { return type == cppu::UnoType<XScriptInvocationContext>::get(); } ); - aTypes.realloc( std::distance(aTypes.begin(), newEnd) ); + aTypes.realloc( std::distance(begin, newEnd) ); } return aTypes; } @@ -249,6 +249,11 @@ void SAL_CALL SbaTableQueryBrowser::disposing() // remove ourself as status listener implRemoveStatusListeners(); + // check out from all the objects we are listening + // the frame + if (m_xCurrentFrameParent.is()) + m_xCurrentFrameParent->removeFrameActionListener(static_cast<css::frame::XFrameActionListener*>(this)); + // remove the container listener from the database context try { @@ -260,10 +265,6 @@ void SAL_CALL SbaTableQueryBrowser::disposing() DBG_UNHANDLED_EXCEPTION("dbaccess"); } - // check out from all the objects we are listening - // the frame - if (m_xCurrentFrameParent.is()) - m_xCurrentFrameParent->removeFrameActionListener(static_cast<css::frame::XFrameActionListener*>(this)); SbaXDataBrowserController::disposing(); } @@ -285,49 +286,49 @@ bool SbaTableQueryBrowser::Construct(vcl::Window* pParent) { SAL_WARN("dbaccess.ui", "SbaTableQueryBrowser::Construct: could not create (or start listening at) the database context!"); } + // some help ids - if (getBrowserView() && getBrowserView()->getVclControl()) - { + if (!getBrowserView() || !getBrowserView()->getVclControl()) + return true; - // create controls and set sizes - const tools::Long nFrameWidth = getBrowserView()->LogicToPixel(::Size(3, 0), MapMode(MapUnit::MapAppFont)).Width(); + // create controls and set sizes + const tools::Long nFrameWidth = getBrowserView()->LogicToPixel(::Size(3, 0), MapMode(MapUnit::MapAppFont)).Width(); - m_pSplitter = VclPtr<Splitter>::Create(getBrowserView(),WB_HSCROLL); - m_pSplitter->SetPosSizePixel( ::Point(0,0), ::Size(nFrameWidth,0) ); - m_pSplitter->SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetDialogColor() ) ); + m_pSplitter = VclPtr<Splitter>::Create(getBrowserView(),WB_HSCROLL); + m_pSplitter->SetPosSizePixel( ::Point(0,0), ::Size(nFrameWidth,0) ); + m_pSplitter->SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetDialogColor() ) ); - m_pTreeView = VclPtr<InterimDBTreeListBox>::Create(getBrowserView(), E_TABLE); + m_pTreeView = VclPtr<InterimDBTreeListBox>::Create(getBrowserView()); - weld::TreeView& rTreeView = m_pTreeView->GetWidget(); - rTreeView.connect_expanding(LINK(this, SbaTableQueryBrowser, OnExpandEntry)); + weld::TreeView& rTreeView = m_pTreeView->GetWidget(); + rTreeView.connect_expanding(LINK(this, SbaTableQueryBrowser, OnExpandEntry)); - m_pTreeView->setCopyHandler(LINK(this, SbaTableQueryBrowser, OnCopyEntry)); + m_pTreeView->setCopyHandler(LINK(this, SbaTableQueryBrowser, OnCopyEntry)); - m_pTreeView->setContextMenuProvider( this ); - m_pTreeView->setControlActionListener( this ); - m_pTreeView->SetHelpId(HID_CTL_TREEVIEW); + m_pTreeView->setContextMenuProvider( this ); + m_pTreeView->setControlActionListener( this ); + m_pTreeView->SetHelpId(HID_CTL_TREEVIEW); - // a default pos for the splitter, so that the listbox is about 80 (logical) pixels wide - m_pSplitter->SetSplitPosPixel(getBrowserView()->LogicToPixel(::Size(80, 0), MapMode(MapUnit::MapAppFont)).Width()); + // a default pos for the splitter, so that the listbox is about 80 (logical) pixels wide + m_pSplitter->SetSplitPosPixel(getBrowserView()->LogicToPixel(::Size(80, 0), MapMode(MapUnit::MapAppFont)).Width()); - getBrowserView()->setSplitter(m_pSplitter); - getBrowserView()->setTreeView(m_pTreeView); + getBrowserView()->setSplitter(m_pSplitter); + getBrowserView()->setTreeView(m_pTreeView); - // fill view with data - rTreeView.set_sort_order(true); - rTreeView.set_sort_func([this](const weld::TreeIter& rLeft, const weld::TreeIter& rRight){ - return OnTreeEntryCompare(rLeft, rRight); - }); - rTreeView.make_sorted(); - m_pTreeView->SetSelChangeHdl(LINK(this, SbaTableQueryBrowser, OnSelectionChange)); - m_pTreeView->show_container(); + // fill view with data + rTreeView.set_sort_order(true); + rTreeView.set_sort_func([this](const weld::TreeIter& rLeft, const weld::TreeIter& rRight){ + return OnTreeEntryCompare(rLeft, rRight); + }); + rTreeView.make_sorted(); + m_pTreeView->SetSelChangeHdl(LINK(this, SbaTableQueryBrowser, OnSelectionChange)); + m_pTreeView->show_container(); - // TODO - getBrowserView()->getVclControl()->SetHelpId(HID_CTL_TABBROWSER); - if (getBrowserView()->getVclControl()->GetHeaderBar()) - getBrowserView()->getVclControl()->GetHeaderBar()->SetHelpId(HID_DATABROWSE_HEADER); - InvalidateFeature(ID_BROWSER_EXPLORER); - } + // TODO + getBrowserView()->getVclControl()->SetHelpId(HID_CTL_TABBROWSER); + if (getBrowserView()->getVclControl()->GetHeaderBar()) + getBrowserView()->getVclControl()->GetHeaderBar()->SetHelpId(HID_DATABROWSE_HEADER); + InvalidateFeature(ID_BROWSER_EXPLORER); return true; } @@ -415,8 +416,8 @@ void SbaTableQueryBrowser::impl_sanitizeRowSetClauses_nothrow() if ( invalidColumn ) { // reset the complete order statement at both the row set and the parser - xRowSetProps->setPropertyValue( PROPERTY_ORDER, makeAny( OUString() ) ); - xComposer->setOrder( "" ); + xRowSetProps->setPropertyValue( PROPERTY_ORDER, Any( OUString() ) ); + xComposer->setOrder( u""_ustr ); } // check if the columns participating in the filter refer to existing tables @@ -468,7 +469,7 @@ bool SbaTableQueryBrowser::InitializeForm( const Reference< XPropertySet > & i_f try { weld::TreeView& rTreeView = m_pTreeView->GetWidget(); - DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*m_xCurrentlyDisplayed).toUInt64()); + DBTreeListUserData* pData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*m_xCurrentlyDisplayed)); ENSURE_OR_RETURN_FALSE( pData, "SbaTableQueryBrowser::InitializeForm: No user data set at the currently displayed entry!" ); ENSURE_OR_RETURN_FALSE( pData->xObjectProperties.is(), "SbaTableQueryBrowser::InitializeForm: No table available!" ); @@ -478,16 +479,16 @@ bool SbaTableQueryBrowser::InitializeForm( const Reference< XPropertySet > & i_f const OUString aTransferProperties[] = { - OUString(PROPERTY_APPLYFILTER), - OUString(PROPERTY_FILTER), - OUString(PROPERTY_HAVING_CLAUSE), - OUString(PROPERTY_ORDER) + PROPERTY_APPLYFILTER, + PROPERTY_FILTER, + PROPERTY_HAVING_CLAUSE, + PROPERTY_ORDER }; - for (const auto & aTransferPropertie : aTransferProperties) + for (const auto & aTransferProperty : aTransferProperties) { - if ( !xPSI->hasPropertyByName( aTransferPropertie ) ) + if ( !xPSI->hasPropertyByName( aTransferProperty ) ) continue; - aPropertyValues.put( aTransferPropertie, pData->xObjectProperties->getPropertyValue( aTransferPropertie ) ); + aPropertyValues.put( aTransferProperty, pData->xObjectProperties->getPropertyValue( aTransferProperty ) ); } std::vector< OUString > aNames( aPropertyValues.getNames() ); @@ -522,9 +523,9 @@ void SbaTableQueryBrowser::initializePreviewMode() Reference< XPropertySet > xDataSourceSet(getRowSet(), UNO_QUERY); if ( xDataSourceSet.is() ) { - xDataSourceSet->setPropertyValue("AllowInserts",makeAny(false)); - xDataSourceSet->setPropertyValue("AllowUpdates",makeAny(false)); - xDataSourceSet->setPropertyValue("AllowDeletes",makeAny(false)); + xDataSourceSet->setPropertyValue(u"AllowInserts"_ustr,Any(false)); + xDataSourceSet->setPropertyValue(u"AllowUpdates"_ustr,Any(false)); + xDataSourceSet->setPropertyValue(u"AllowDeletes"_ustr,Any(false)); } } @@ -545,10 +546,10 @@ void SbaTableQueryBrowser::InitializeGridModel(const Reference< css::form::XForm if (m_xCurrentlyDisplayed) { Sequence< OUString> aProperties(6 + ( m_bPreview ? 5 : 0 )); - Sequence< Any> aValues(7 + ( m_bPreview ? 5 : 0 )); + Sequence< Any> aValues(6 + ( m_bPreview ? 5 : 0 )); weld::TreeView& rTreeView = m_pTreeView->GetWidget(); - DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*m_xCurrentlyDisplayed).toUInt64()); + DBTreeListUserData* pData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*m_xCurrentlyDisplayed)); OSL_ENSURE( pData->xObjectProperties.is(), "SbaTableQueryBrowser::InitializeGridModel: No table available!" ); if ( !pData->xObjectProperties.is() ) return; @@ -640,14 +641,14 @@ void SbaTableQueryBrowser::InitializeGridModel(const Reference< css::form::XForm case DataType::BOOLEAN: { aCurrentModelType = "CheckBox"; - aInitialValues.emplace_back( "VisualEffect", makeAny( VisualEffect::FLAT ) ); + aInitialValues.emplace_back( "VisualEffect", Any( VisualEffect::FLAT ) ); sDefaultProperty = PROPERTY_DEFAULTSTATE; sal_Int32 nNullable = ColumnValue::NULLABLE_UNKNOWN; OSL_VERIFY( xColumn->getPropertyValue( PROPERTY_ISNULLABLE ) >>= nNullable ); aInitialValues.emplace_back( "TriState", - makeAny( ColumnValue::NO_NULLS != nNullable ) + Any( ColumnValue::NO_NULLS != nNullable ) ); if ( ColumnValue::NO_NULLS == nNullable ) aDefault <<= sal_Int16(TRISTATE_FALSE); @@ -656,7 +657,7 @@ void SbaTableQueryBrowser::InitializeGridModel(const Reference< css::form::XForm case DataType::LONGVARCHAR: case DataType::CLOB: - aInitialValues.emplace_back( "MultiLine", makeAny( true ) ); + aInitialValues.emplace_back( "MultiLine", Any( true ) ); [[fallthrough]]; case DataType::BINARY: case DataType::VARBINARY: @@ -674,19 +675,19 @@ void SbaTableQueryBrowser::InitializeGridModel(const Reference< css::form::XForm sDefaultProperty = PROPERTY_EFFECTIVEDEFAULT; if ( xSupplier.is() ) - aInitialValues.emplace_back( "FormatsSupplier", makeAny( xSupplier ) ); - aInitialValues.emplace_back( "TreatAsNumber", makeAny( bFormattedIsNumeric ) ); + aInitialValues.emplace_back( "FormatsSupplier", Any( xSupplier ) ); + aInitialValues.emplace_back( "TreatAsNumber", Any( bFormattedIsNumeric ) ); aCopyProperties.emplace_back(PROPERTY_FORMATKEY ); break; } - aInitialValues.emplace_back( PROPERTY_CONTROLSOURCE, makeAny( rName ) ); + aInitialValues.emplace_back( PROPERTY_CONTROLSOURCE, Any( rName ) ); OUString sLabel; xColumn->getPropertyValue(PROPERTY_LABEL) >>= sLabel; if ( !sLabel.isEmpty() ) - aInitialValues.emplace_back( PROPERTY_LABEL, makeAny( sLabel ) ); + aInitialValues.emplace_back( PROPERTY_LABEL, Any( sLabel ) ); else - aInitialValues.emplace_back( PROPERTY_LABEL, makeAny( rName ) ); + aInitialValues.emplace_back( PROPERTY_LABEL, Any( rName ) ); Reference< XPropertySet > xGridCol( xColFactory->createColumn( aCurrentModelType ), UNO_SET_THROW ); Reference< XPropertySetInfo > xGridColPSI( xGridCol->getPropertySetInfo(), UNO_SET_THROW ); @@ -733,7 +734,7 @@ void SbaTableQueryBrowser::InitializeGridModel(const Reference< css::form::XForm // don't allow the mouse to scroll in the cells if ( xGridColPSI->hasPropertyByName( PROPERTY_MOUSE_WHEEL_BEHAVIOR ) ) - aInitialValues.emplace_back( PROPERTY_MOUSE_WHEEL_BEHAVIOR, makeAny( MouseWheelBehavior::SCROLL_DISABLED ) ); + aInitialValues.emplace_back( PROPERTY_MOUSE_WHEEL_BEHAVIOR, Any( MouseWheelBehavior::SCROLL_DISABLED ) ); // now set all those values for (auto const& property : aInitialValues) @@ -743,7 +744,7 @@ void SbaTableQueryBrowser::InitializeGridModel(const Reference< css::form::XForm for (auto const& copyPropertyName : aCopyProperties) xGridCol->setPropertyValue( copyPropertyName, xColumn->getPropertyValue(copyPropertyName) ); - xColContainer->insertByName(rName, makeAny(xGridCol)); + xColContainer->insertByName(rName, Any(xGridCol)); } } } @@ -760,7 +761,7 @@ static Reference<XPropertySet> getColumnHelper(const weld::TreeView& rTreeView, Reference<XPropertySet> xRet; if (pCurrentlyDisplayed) { - DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*pCurrentlyDisplayed).toUInt64()); + DBTreeListUserData* pData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*pCurrentlyDisplayed)); Reference<XColumnsSupplier> xColumnsSup(pData->xObjectProperties,UNO_QUERY); Reference<XNameAccess> xNames = xColumnsSup->getColumns(); OUString aName; @@ -776,7 +777,7 @@ void SbaTableQueryBrowser::transferChangedControlProperty(const OUString& _rProp if (m_xCurrentlyDisplayed) { weld::TreeView& rTreeView = m_pTreeView->GetWidget(); - DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*m_xCurrentlyDisplayed).toUInt64()); + DBTreeListUserData* pData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*m_xCurrentlyDisplayed)); Reference< XPropertySet > xObjectProps = pData->xObjectProperties; OSL_ENSURE(xObjectProps.is(),"SbaTableQueryBrowser::transferChangedControlProperty: no table/query object!"); if (xObjectProps.is()) @@ -804,7 +805,7 @@ void SbaTableQueryBrowser::propertyChange(const PropertyChangeEvent& evt) if(xProp.is()) { if(!evt.NewValue.hasValue()) - xProp->setPropertyValue(PROPERTY_WIDTH,makeAny(sal_Int32(227))); + xProp->setPropertyValue(PROPERTY_WIDTH,Any(sal_Int32(227))); else xProp->setPropertyValue(PROPERTY_WIDTH,evt.NewValue); } @@ -830,12 +831,12 @@ void SbaTableQueryBrowser::propertyChange(const PropertyChangeEvent& evt) { sal_Int16 nAlign = 0; if(evt.NewValue >>= nAlign) - xProp->setPropertyValue(PROPERTY_ALIGN,makeAny(sal_Int32(nAlign))); + xProp->setPropertyValue(PROPERTY_ALIGN,Any(sal_Int32(nAlign))); else xProp->setPropertyValue(PROPERTY_ALIGN,evt.NewValue); } else - xProp->setPropertyValue(PROPERTY_ALIGN,makeAny(css::awt::TextAlign::LEFT)); + xProp->setPropertyValue(PROPERTY_ALIGN,Any(css::awt::TextAlign::LEFT)); } } catch( const Exception& ) @@ -861,12 +862,12 @@ void SbaTableQueryBrowser::propertyChange(const PropertyChangeEvent& evt) { if (m_xCurrentlyDisplayed) { - DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*m_xCurrentlyDisplayed).toUInt64()); + DBTreeListUserData* pData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*m_xCurrentlyDisplayed)); OSL_ENSURE( pData->xObjectProperties.is(), "No table available!" ); bool bDefault = !evt.NewValue.hasValue(); if (bDefault) - pData->xObjectProperties->setPropertyValue(PROPERTY_ROW_HEIGHT,makeAny(sal_Int32(45))); + pData->xObjectProperties->setPropertyValue(PROPERTY_ROW_HEIGHT,Any(sal_Int32(45))); else pData->xObjectProperties->setPropertyValue(PROPERTY_ROW_HEIGHT,evt.NewValue); } @@ -1036,7 +1037,7 @@ namespace struct FilterByEntryDataId : public IEntryFilter { OUString sId; - explicit FilterByEntryDataId( const OUString& _rId ) : sId( _rId ) { } + explicit FilterByEntryDataId( OUString _aId ) : sId(std::move( _aId )) { } virtual ~FilterByEntryDataId() {} @@ -1053,8 +1054,8 @@ namespace OUString SbaTableQueryBrowser::getDataSourceAccessor(const weld::TreeIter& rDataSourceEntry) const { weld::TreeView& rTreeView = m_pTreeView->GetWidget(); - DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(rDataSourceEntry).toUInt64()); - OSL_ENSURE( pData, "SbaTableQueryBrowser::getDataSourceAccessor: invalid entry data!" ); + DBTreeListUserData* pData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(rDataSourceEntry)); + assert(pData && "SbaTableQueryBrowser::getDataSourceAccessor: invalid entry data!"); OSL_ENSURE( pData->eType == etDatasource, "SbaTableQueryBrowser::getDataSourceAccessor: entry does not denote a data source!" ); return !pData->sAccessor.isEmpty() ? pData->sAccessor : GetEntryText(rDataSourceEntry); } @@ -1093,14 +1094,14 @@ std::unique_ptr<weld::TreeIter> SbaTableQueryBrowser::getObjectEntry(const OUStr weld::TreeView& rTreeView = m_pTreeView->GetWidget(); - if (ppDataSourceEntry) - { - // (caller wants to have it...) - *ppDataSourceEntry = rTreeView.make_iterator(xDataSource.get()); - } - if (xDataSource) { + if (ppDataSourceEntry) + { + // (caller wants to have it...) + *ppDataSourceEntry = rTreeView.make_iterator(xDataSource.get()); + } + // expand if required so if (bExpandAncestors) rTreeView.expand_row(*xDataSource); @@ -1122,14 +1123,14 @@ std::unique_ptr<weld::TreeIter> SbaTableQueryBrowser::getObjectEntry(const OUStr } } - if (ppContainerEntry) - { - // (caller wants to have it...) - *ppContainerEntry = rTreeView.make_iterator(xCommandType.get()); - } - if (xCommandType) { + if (ppContainerEntry) + { + // (caller wants to have it...) + *ppContainerEntry = rTreeView.make_iterator(xCommandType.get()); + } + rTreeView.make_unsorted(); // expand if required so @@ -1166,7 +1167,7 @@ std::unique_ptr<weld::TreeIter> SbaTableQueryBrowser::getObjectEntry(const OUStr { if (ensureEntryObject(*xObject)) { - DBTreeListUserData* pParentData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xObject).toUInt64()); + DBTreeListUserData* pParentData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*xObject)); Reference< XNameAccess > xCollection( pParentData->xContainer, UNO_QUERY ); sal_Int32 nIndex2 = nIndex; sPath = _rCommand.getToken( 0, '/', nIndex2 ); @@ -1183,7 +1184,7 @@ std::unique_ptr<weld::TreeIter> SbaTableQueryBrowser::getObjectEntry(const OUStr { pEntryData->eType = etQueryContainer; } - implAppendEntry(xObject.get(), sPath, pEntryData, pEntryData->eType); + implAppendEntry(xObject.get(), sPath, pEntryData); } } } @@ -1225,33 +1226,33 @@ void SbaTableQueryBrowser::connectExternalDispatches() if ( m_aExternalFeatures.empty() ) { - const char* pURLs[] = { - ".uno:DataSourceBrowser/DocumentDataSource", - ".uno:DataSourceBrowser/FormLetter", - ".uno:DataSourceBrowser/InsertColumns", - ".uno:DataSourceBrowser/InsertContent", + static constexpr OUString aURLs[] { + u".uno:DataSourceBrowser/DocumentDataSource"_ustr, + u".uno:DataSourceBrowser/FormLetter"_ustr, + u".uno:DataSourceBrowser/InsertColumns"_ustr, + u".uno:DataSourceBrowser/InsertContent"_ustr, }; - const sal_uInt16 nIds[] = { + static constexpr sal_uInt16 nIds[] = { ID_BROWSER_DOCUMENT_DATASOURCE, ID_BROWSER_FORMLETTER, ID_BROWSER_INSERTCOLUMNS, ID_BROWSER_INSERTCONTENT }; - for ( size_t i=0; i < SAL_N_ELEMENTS( pURLs ); ++i ) + for ( size_t i=0; i < std::size( aURLs ); ++i ) { URL aURL; - aURL.Complete = OUString::createFromAscii( pURLs[i] ); + aURL.Complete = aURLs[i]; if ( m_xUrlTransformer.is() ) m_xUrlTransformer->parseStrict( aURL ); - m_aExternalFeatures[ nIds[ i ] ] = ExternalFeature( aURL ); + m_aExternalFeatures[ nIds[ i ] ] = ExternalFeature( std::move(aURL) ); } } for (auto & externalFeature : m_aExternalFeatures) { externalFeature.second.xDispatcher = xProvider->queryDispatch( - externalFeature.second.aURL, "_parent", FrameSearchFlag::PARENT + externalFeature.second.aURL, u"_parent"_ustr, FrameSearchFlag::PARENT ); if ( externalFeature.second.xDispatcher.get() == static_cast< XDispatch* >( this ) ) @@ -1291,8 +1292,8 @@ void SbaTableQueryBrowser::implCheckExternalSlot( sal_uInt16 _nId ) if ( pToolbox ) { bool bHaveDispatcher = m_aExternalFeatures[ _nId ].xDispatcher.is(); - if ( bHaveDispatcher != pToolbox->IsItemVisible( _nId ) ) - bHaveDispatcher ? pToolbox->ShowItem( _nId ) : pToolbox->HideItem( _nId ); + if ( bHaveDispatcher != pToolbox->IsItemVisible( ToolBoxItemId(_nId) ) ) + bHaveDispatcher ? pToolbox->ShowItem( ToolBoxItemId(_nId) ) : pToolbox->HideItem( ToolBoxItemId(_nId) ); } // and invalidate this feature in general @@ -1344,7 +1345,7 @@ void SAL_CALL SbaTableQueryBrowser::disposing( const css::lang::EventObject& _rS { do { - DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xDSLoop).toUInt64()); + DBTreeListUserData* pData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*xDSLoop)); if ( pData && pData->xConnection == xCon ) { // we set the connection to null to avoid a second disposing of the connection @@ -1458,7 +1459,7 @@ void SbaTableQueryBrowser::attachFrame(const Reference< css::frame::XFrame > & _ Reference< XFrame > xCurrentFrame( getFrame() ); if ( xCurrentFrame.is() ) { - m_xCurrentFrameParent = xCurrentFrame->findFrame("_parent",FrameSearchFlag::PARENT); + m_xCurrentFrameParent = xCurrentFrame->findFrame(u"_parent"_ustr,FrameSearchFlag::PARENT); if ( m_xCurrentFrameParent.is() ) m_xCurrentFrameParent->addFrameActionListener(static_cast<css::frame::XFrameActionListener*>(this)); @@ -1467,13 +1468,13 @@ void SbaTableQueryBrowser::attachFrame(const Reference< css::frame::XFrame > & _ { Reference< XPropertySet > xFrameProps( m_aCurrentFrame.getFrame(), UNO_QUERY_THROW ); Reference< XLayoutManager > xLayouter( - xFrameProps->getPropertyValue("LayoutManager"), + xFrameProps->getPropertyValue(u"LayoutManager"_ustr), UNO_QUERY ); if ( xLayouter.is() ) { Reference< XUIElement > xUI( - xLayouter->getElement( "private:resource/toolbar/toolbar" ), + xLayouter->getElement( u"private:resource/toolbar/toolbar"_ustr ), UNO_SET_THROW ); m_xMainToolbar.set(xUI->getRealInterface(), css::uno::UNO_QUERY); OSL_ENSURE( m_xMainToolbar.is(), "SbaTableQueryBrowser::attachFrame: where's my toolbox?" ); @@ -1644,7 +1645,7 @@ FeatureState SbaTableQueryBrowser::GetState(sal_uInt16 nId) const std::unique_ptr<weld::TreeIter> xDataSourceEntry = m_pTreeView->GetRootLevelParent(xCurrentEntry.get()); DBTreeListUserData* pDSData = xDataSourceEntry - ? reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xDataSourceEntry).toUInt64()) + ? weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*xDataSourceEntry)) : nullptr; if ( nId == ID_TREE_CLOSE_CONN ) @@ -1654,9 +1655,9 @@ FeatureState SbaTableQueryBrowser::GetState(sal_uInt16 nId) const else if ( nId == ID_TREE_EDIT_DATABASE ) { ::utl::OConfigurationTreeRoot aConfig( ::utl::OConfigurationTreeRoot::createWithComponentContext( getORB(), - "/org.openoffice.Office.DataAccess/Policies/Features/Common" ) ); + u"/org.openoffice.Office.DataAccess/Policies/Features/Common"_ustr ) ); bool bHaveEditDatabase( true ); - OSL_VERIFY( aConfig.getNodeValue( "EditDatabaseFromDataSourceView" ) >>= bHaveEditDatabase ); + OSL_VERIFY( aConfig.getNodeValue( u"EditDatabaseFromDataSourceView"_ustr ) >>= bHaveEditDatabase ); aReturn.bEnabled = getORB().is() && xDataSourceEntry && bHaveEditDatabase; } else if ( nId == ID_BROWSER_COPY ) @@ -2033,7 +2034,7 @@ void SbaTableQueryBrowser::implAddDatasource(const OUString& _rDbName, OUString& pDSData->eType = etDatasource; pDSData->sAccessor = sDataSourceId; pDSData->xConnection = _rxConnection; - OUString sId(OUString::number(reinterpret_cast<sal_uInt64>(pDSData))); + OUString sId(weld::toId(pDSData)); std::unique_ptr<weld::TreeIter> xDatasourceEntry(rTreeView.make_iterator()); rTreeView.insert(nullptr, -1, &sDSDisplayName, &sId, nullptr, nullptr, false, xDatasourceEntry.get()); @@ -2044,7 +2045,7 @@ void SbaTableQueryBrowser::implAddDatasource(const OUString& _rDbName, OUString& { DBTreeListUserData* pQueriesData = new DBTreeListUserData; pQueriesData->eType = etQueryContainer; - sId = OUString::number(reinterpret_cast<sal_uInt64>(pQueriesData)); + sId = weld::toId(pQueriesData); std::unique_ptr<weld::TreeIter> xRet(rTreeView.make_iterator()); rTreeView.insert(xDatasourceEntry.get(), -1, &_rQueryName, &sId, @@ -2057,7 +2058,7 @@ void SbaTableQueryBrowser::implAddDatasource(const OUString& _rDbName, OUString& { DBTreeListUserData* pTablesData = new DBTreeListUserData; pTablesData->eType = etTableContainer; - sId = OUString::number(reinterpret_cast<sal_uInt64>(pTablesData)); + sId = weld::toId(pTablesData); std::unique_ptr<weld::TreeIter> xRet(rTreeView.make_iterator()); rTreeView.insert(xDatasourceEntry.get(), -1, &_rTableName, &sId, @@ -2088,7 +2089,7 @@ void SbaTableQueryBrowser::populateTree(const Reference<XNameAccess>& _xNameAcce weld::TreeView& rTreeView = m_pTreeView->GetWidget(); rTreeView.make_unsorted(); - DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(rParent).toUInt64()); + DBTreeListUserData* pData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(rParent)); if (pData) // don't ask if the nameaccess is already set see OnExpandEntry views and tables pData->xContainer = _xNameAccess; @@ -2107,7 +2108,7 @@ void SbaTableQueryBrowser::populateTree(const Reference<XNameAccess>& _xNameAcce if ( xChild.is() ) pEntryData->eType = etQueryContainer; } - implAppendEntry(&rParent, rName, pEntryData, pEntryData->eType); + implAppendEntry(&rParent, rName, pEntryData); } } } @@ -2119,13 +2120,15 @@ void SbaTableQueryBrowser::populateTree(const Reference<XNameAccess>& _xNameAcce rTreeView.make_sorted(); } -std::unique_ptr<weld::TreeIter> SbaTableQueryBrowser::implAppendEntry(const weld::TreeIter* pParent, const OUString& rName, void* pUserData, EntryType eEntryType) +std::unique_ptr<weld::TreeIter> SbaTableQueryBrowser::implAppendEntry(const weld::TreeIter* pParent, const OUString& rName, const DBTreeListUserData* pUserData) { + EntryType eEntryType = pUserData->eType; + std::unique_ptr<ImageProvider> xImageProvider(getImageProviderFor(pParent)); OUString aImage = xImageProvider->getImageId(rName, getDatabaseObjectType(eEntryType)); - OUString sId(OUString::number(reinterpret_cast<sal_uInt64>(pUserData))); + OUString sId(weld::toId(pUserData)); weld::TreeView& rTreeView = m_pTreeView->GetWidget(); std::unique_ptr<weld::TreeIter> xNewEntry(rTreeView.make_iterator()); rTreeView.insert(pParent, -1, &rName, &sId, nullptr, nullptr, eEntryType == etQueryContainer, xNewEntry.get()); @@ -2147,7 +2150,7 @@ IMPL_LINK(SbaTableQueryBrowser, OnExpandEntry, const weld::TreeIter&, rParent, b std::unique_ptr<weld::TreeIter> xFirstParent = m_pTreeView->GetRootLevelParent(&rParent); OSL_ENSURE(xFirstParent,"SbaTableQueryBrowser::OnExpandEntry: No rootlevelparent!"); - DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(rParent).toInt64()); + DBTreeListUserData* pData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(rParent)); assert(pData && "SbaTableQueryBrowser::OnExpandEntry: No user data!"); if (etTableContainer == pData->eType) @@ -2156,9 +2159,7 @@ IMPL_LINK(SbaTableQueryBrowser, OnExpandEntry, const weld::TreeIter&, rParent, b // it could be that we already have a connection SharedConnection xConnection; - ensureConnection(xFirstParent.get(), xConnection); - - if ( xConnection.is() ) + if (ensureConnection(xFirstParent.get(), xConnection) && xConnection.is()) { SQLExceptionInfo aInfo; try @@ -2235,7 +2236,7 @@ IMPL_LINK(SbaTableQueryBrowser, OnExpandEntry, const weld::TreeIter&, rParent, b // we have to expand the queries or bookmarks if (ensureEntryObject(rParent)) { - DBTreeListUserData* pParentData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(rParent).toUInt64()); + DBTreeListUserData* pParentData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(rParent)); Reference< XNameAccess > xCollection( pParentData->xContainer, UNO_QUERY ); populateTree(xCollection, rParent, etQuery); } @@ -2249,8 +2250,8 @@ bool SbaTableQueryBrowser::ensureEntryObject(const weld::TreeIter& rEntry) // the user data of the entry weld::TreeView& rTreeView = m_pTreeView->GetWidget(); - DBTreeListUserData* pEntryData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(rEntry).toUInt64()); - OSL_ENSURE(pEntryData,"ensureEntryObject: user data should already be set!"); + DBTreeListUserData* pEntryData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(rEntry)); + assert(pEntryData && "ensureEntryObject: user data should already be set!"); std::unique_ptr<weld::TreeIter> xDataSourceEntry = m_pTreeView->GetRootLevelParent(&rEntry); @@ -2272,7 +2273,7 @@ bool SbaTableQueryBrowser::ensureEntryObject(const weld::TreeIter& rEntry) if (rTreeView.iter_compare(*xParent, *xDataSourceEntry) != 0) { OUString aName(rTreeView.get_text(rEntry)); - DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xParent).toUInt64()); + DBTreeListUserData* pData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*xParent)); try { Reference< XNameAccess > xNameAccess(pData->xContainer,UNO_QUERY); @@ -2344,17 +2345,17 @@ bool SbaTableQueryBrowser::implLoadAnything(const OUString& _rDataSourceName, co Reference<XPropertySet> xProp( getRowSet(), UNO_QUERY_THROW ); Reference< XLoadable > xLoadable( xProp, UNO_QUERY_THROW ); // the values allowing the RowSet to re-execute - xProp->setPropertyValue(PROPERTY_DATASOURCENAME, makeAny(_rDataSourceName)); + xProp->setPropertyValue(PROPERTY_DATASOURCENAME, Any(_rDataSourceName)); if(_rxConnection.is()) - xProp->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, makeAny( _rxConnection.getTyped() ) ); + xProp->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, Any( _rxConnection.getTyped() ) ); // set this _before_ setting the connection, else the rowset would rebuild it ... - xProp->setPropertyValue(PROPERTY_COMMAND_TYPE, makeAny(nCommandType)); - xProp->setPropertyValue(PROPERTY_COMMAND, makeAny(_rCommand)); - xProp->setPropertyValue(PROPERTY_ESCAPE_PROCESSING, css::uno::makeAny(_bEscapeProcessing)); + xProp->setPropertyValue(PROPERTY_COMMAND_TYPE, Any(nCommandType)); + xProp->setPropertyValue(PROPERTY_COMMAND, Any(_rCommand)); + xProp->setPropertyValue(PROPERTY_ESCAPE_PROCESSING, css::uno::Any(_bEscapeProcessing)); if ( m_bPreview ) { - xProp->setPropertyValue(PROPERTY_FETCHDIRECTION, makeAny(FetchDirection::FORWARD)); + xProp->setPropertyValue(PROPERTY_FETCHDIRECTION, Any(FetchDirection::FORWARD)); } // the formatter depends on the data source we're working on, so rebuild it here ... @@ -2424,45 +2425,45 @@ bool SbaTableQueryBrowser::implSelect(const OUString& _rDataSourceName, const OU const SharedConnection& _rxConnection, bool _bSelectDirect) { - if (_rDataSourceName.getLength() && _rCommand.getLength() && (-1 != nCommandType)) - { - std::unique_ptr<weld::TreeIter> xDataSource; - std::unique_ptr<weld::TreeIter> xCommandType; - std::unique_ptr<weld::TreeIter> xCommand = getObjectEntry( _rDataSourceName, _rCommand, nCommandType, &xDataSource, &xCommandType, true, _rxConnection ); + if (!_rDataSourceName.getLength() || !_rCommand.getLength() || (-1 == nCommandType)) + return false; - if (xCommand) - { - weld::TreeView& rTreeView = m_pTreeView->GetWidget(); + std::unique_ptr<weld::TreeIter> xDataSource; + std::unique_ptr<weld::TreeIter> xCommandType; + std::unique_ptr<weld::TreeIter> xCommand = getObjectEntry( _rDataSourceName, _rCommand, nCommandType, &xDataSource, &xCommandType, true, _rxConnection ); - bool bSuccess = true; - if ( _bSelectDirect ) - { - bSuccess = implSelect(xCommand.get()); - } - else - { - rTreeView.select(*xCommand); - } + if (xCommand) + { + weld::TreeView& rTreeView = m_pTreeView->GetWidget(); - if ( bSuccess ) - { - rTreeView.scroll_to_row(*xCommand); - rTreeView.set_cursor(*xCommand); - } + bool bSuccess = true; + if ( _bSelectDirect ) + { + bSuccess = implSelect(xCommand.get()); } - else if (!xCommandType) + else { - if (m_xCurrentlyDisplayed) - { - // tell the old entry (if any) it has been deselected - selectPath(m_xCurrentlyDisplayed.get(), false); - m_xCurrentlyDisplayed.reset(); - } + rTreeView.select(*xCommand); + } - // we have a command and need to display this in the rowset - return implLoadAnything(_rDataSourceName, _rCommand, nCommandType, _bEscapeProcessing, _rxConnection); + if ( bSuccess ) + { + rTreeView.scroll_to_row(*xCommand); + rTreeView.set_cursor(*xCommand); } } + else if (!xCommandType) + { + if (m_xCurrentlyDisplayed) + { + // tell the old entry (if any) it has been deselected + selectPath(m_xCurrentlyDisplayed.get(), false); + m_xCurrentlyDisplayed.reset(); + } + + // we have a command and need to display this in the rowset + return implLoadAnything(_rDataSourceName, _rCommand, nCommandType, _bEscapeProcessing, _rxConnection); + } return false; } @@ -2475,15 +2476,15 @@ IMPL_LINK_NOARG(SbaTableQueryBrowser, OnSelectionChange, LinkParamNone*, void) implSelect(xSelection.get()); } -std::unique_ptr<weld::TreeIter> SbaTableQueryBrowser::implGetConnectionEntry(weld::TreeIter& rEntry) const +std::unique_ptr<weld::TreeIter> SbaTableQueryBrowser::implGetConnectionEntry(const weld::TreeIter& rEntry) const { weld::TreeView& rTreeView = m_pTreeView->GetWidget(); std::unique_ptr<weld::TreeIter> xCurrentEntry(rTreeView.make_iterator(&rEntry)); - DBTreeListUserData* pEntryData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xCurrentEntry).toInt64()); + DBTreeListUserData* pEntryData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*xCurrentEntry)); while (pEntryData->eType != etDatasource) { rTreeView.iter_parent(*xCurrentEntry); - pEntryData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xCurrentEntry).toInt64()); + pEntryData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*xCurrentEntry)); } return xCurrentEntry; } @@ -2494,7 +2495,7 @@ bool SbaTableQueryBrowser::implSelect(const weld::TreeIter* pEntry) return false; weld::TreeView& rTreeView = m_pTreeView->GetWidget(); - DBTreeListUserData* pEntryData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*pEntry).toUInt64()); + DBTreeListUserData* pEntryData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*pEntry)); switch (pEntryData->eType) { case etTableOrView: @@ -2510,11 +2511,11 @@ bool SbaTableQueryBrowser::implSelect(const weld::TreeIter* pEntry) // get the entry for the tables or queries std::unique_ptr<weld::TreeIter> xContainer = rTreeView.make_iterator(pEntry); rTreeView.iter_parent(*xContainer); - DBTreeListUserData* pContainerData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xContainer).toUInt64()); + DBTreeListUserData* pContainerData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*xContainer)); // get the entry for the datasource std::unique_ptr<weld::TreeIter> xConnection = implGetConnectionEntry(*xContainer); - DBTreeListUserData* pConData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xConnection).toUInt64()); + DBTreeListUserData* pConData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*xConnection)); // reinitialize the rowset // but first check if it is necessary @@ -2537,8 +2538,7 @@ bool SbaTableQueryBrowser::implSelect(const weld::TreeIter* pEntry) { while (rTreeView.iter_compare(*xNextTemp, *xConnection) != 0) { - sNameBuffer.insert(0,'/'); - sNameBuffer.insert(0, rTreeView.get_text(*xTemp)); + sNameBuffer.insert(0, rTreeView.get_text(*xTemp) + "/"); rTreeView.copy_iterator(*xNextTemp, *xTemp); if (!rTreeView.iter_parent(*xNextTemp)) break; @@ -2575,7 +2575,7 @@ bool SbaTableQueryBrowser::implSelect(const weld::TreeIter* pEntry) selectPath(m_xCurrentlyDisplayed.get()); // get the name of the data source currently selected - ensureConnection(m_xCurrentlyDisplayed.get(), pConData->xConnection); + (void)ensureConnection(m_xCurrentlyDisplayed.get(), pConData->xConnection); if ( !pConData->xConnection.is() ) { @@ -2621,7 +2621,7 @@ bool SbaTableQueryBrowser::implSelect(const weld::TreeIter* pEntry) bool bEscapeProcessing = true; if(xNameAccess.is() && xNameAccess->hasByName(sSimpleName)) { - DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*pEntry).toUInt64()); + DBTreeListUserData* pData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*pEntry)); if ( !pData->xObjectProperties.is() ) { Reference<XInterface> xObject; @@ -2653,7 +2653,7 @@ bool SbaTableQueryBrowser::implSelect(const weld::TreeIter* pEntry) OUString sReplace = sSql.replaceFirst(sFilter, ""); xAnalyzer->setQuery(sReplace); Reference<XSingleSelectQueryComposer> xComposer(xAnalyzer,UNO_QUERY); - xComposer->setFilter("0=1"); + xComposer->setFilter(u"0=1"_ustr); aName = xAnalyzer->getQuery(); nCommandType = CommandType::COMMAND; } @@ -2722,14 +2722,14 @@ std::unique_ptr<weld::TreeIter> SbaTableQueryBrowser::getEntryFromContainer(cons if (rTreeView.iter_children(*xContainer)) { // 1st child is queries - DBTreeListUserData* pQueriesData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xContainer).toUInt64()); + DBTreeListUserData* pQueriesData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*xContainer)); if (pQueriesData && pQueriesData->xContainer == rxNameAccess) break; if (rTreeView.iter_next_sibling(*xContainer)) { // 2nd child is tables - DBTreeListUserData* pTablesData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xContainer).toUInt64()); + DBTreeListUserData* pTablesData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*xContainer)); if (pTablesData && pTablesData->xContainer == rxNameAccess) break; } @@ -2756,8 +2756,8 @@ void SAL_CALL SbaTableQueryBrowser::elementInserted(const ContainerEvent& rEvent rTreeView.make_unsorted(); // insert the new entry into the tree - DBTreeListUserData* pContainerData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xEntry).toUInt64()); - OSL_ENSURE(pContainerData, "elementInserted: There must be user data for this type!"); + DBTreeListUserData* pContainerData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*xEntry)); + assert(pContainerData && "elementInserted: There must be user data for this type!"); DBTreeListUserData* pNewData = new DBTreeListUserData; bool bIsTable = etTableContainer == pContainerData->eType; @@ -2776,7 +2776,7 @@ void SAL_CALL SbaTableQueryBrowser::elementInserted(const ContainerEvent& rEvent } pNewData->eType = etQuery; } - implAppendEntry(xEntry.get(), ::comphelper::getString(rEvent.Accessor), pNewData, pNewData->eType); + implAppendEntry(xEntry.get(), ::comphelper::getString(rEvent.Accessor), pNewData); rTreeView.make_sorted(); } @@ -2784,7 +2784,7 @@ void SAL_CALL SbaTableQueryBrowser::elementInserted(const ContainerEvent& rEvent SbaXDataBrowserController::elementInserted(rEvent); } -bool SbaTableQueryBrowser::isCurrentlyDisplayedChanged(const OUString& rName, const weld::TreeIter& rContainer) +bool SbaTableQueryBrowser::isCurrentlyDisplayedChanged(std::u16string_view rName, const weld::TreeIter& rContainer) { if (!m_xCurrentlyDisplayed) return false; @@ -2821,7 +2821,7 @@ void SAL_CALL SbaTableQueryBrowser::elementRemoved( const ContainerEvent& _rEven // unload unloadAndCleanup( false ); // don't dispose the connection - DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xTemp).toUInt64()); + DBTreeListUserData* pData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*xTemp)); rTreeView.set_id(*xTemp, OUString()); delete pData; // the data could be null because we have a table which isn't correct rTreeView.remove(*xTemp); @@ -2836,7 +2836,7 @@ void SAL_CALL SbaTableQueryBrowser::elementRemoved( const ContainerEvent& _rEven { if (rTreeView.get_text(*xChild) == aName) { - DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xChild).toUInt64()); + DBTreeListUserData* pData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*xChild)); rTreeView.set_id(*xChild, OUString()); delete pData; rTreeView.remove(*xChild); @@ -2861,7 +2861,7 @@ void SAL_CALL SbaTableQueryBrowser::elementReplaced( const ContainerEvent& _rEve std::unique_ptr<weld::TreeIter> xContainer = getEntryFromContainer(xNames); if (xContainer) { - // a table or query as been replaced + // a table or query has been replaced OUString aName = ::comphelper::getString(_rEvent.Accessor); weld::TreeView& rTreeView = m_pTreeView->GetWidget(); @@ -2872,13 +2872,13 @@ void SAL_CALL SbaTableQueryBrowser::elementReplaced( const ContainerEvent& _rEve std::unique_ptr<weld::TreeIter> xTemp = rTreeView.make_iterator(m_xCurrentlyDisplayed.get()); unloadAndCleanup( false ); // don't dispose the connection - DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xTemp).toUInt64()); + DBTreeListUserData* pData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*xTemp)); if (pData) { if ( etTableOrView == pData->eType ) { // only insert userdata when we have a table because the query is only a commanddefinition object and not a query - _rEvent.Element >>= pData->xObjectProperties; // remember the new element + _rEvent.Element >>= pData->xObjectProperties; // remember the new element } else { @@ -2897,7 +2897,7 @@ void SAL_CALL SbaTableQueryBrowser::elementReplaced( const ContainerEvent& _rEve { if (rTreeView.get_text(*xChild) == aName) { - DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xChild).toUInt64()); + DBTreeListUserData* pData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*xChild)); if (pData) { if ( etTableOrView == pData->eType ) @@ -2965,13 +2965,13 @@ void SbaTableQueryBrowser::disposeConnection(const weld::TreeIter* pDSEntry) if (pDSEntry) { weld::TreeView& rTreeView = m_pTreeView->GetWidget(); - DBTreeListUserData* pTreeListData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*pDSEntry).toUInt64()); + DBTreeListUserData* pTreeListData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*pDSEntry)); if (pTreeListData) impl_releaseConnection(pTreeListData->xConnection); } } -void SbaTableQueryBrowser::closeConnection(weld::TreeIter& rDSEntry, bool _bDisposeConnection) +void SbaTableQueryBrowser::closeConnection(const weld::TreeIter& rDSEntry, bool _bDisposeConnection) { OSL_ENSURE(impl_isDataSourceEntry(&rDSEntry), "SbaTableQueryBrowser::closeConnection: invalid entry (not top-level)!"); @@ -3001,7 +3001,7 @@ void SbaTableQueryBrowser::closeConnection(weld::TreeIter& rDSEntry, bool _bDisp { std::unique_ptr<weld::TreeIter> xRemove(rTreeView.make_iterator(xElements.get())); bElements = rTreeView.iter_next_sibling(*xElements); - DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xRemove).toUInt64()); + DBTreeListUserData* pData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*xRemove)); rTreeView.set_id(*xRemove, OUString()); delete pData; rTreeView.remove(*xRemove); @@ -3088,17 +3088,17 @@ namespace { DBG_UNHANDLED_EXCEPTION("dbaccess"); } - return xDataSource.get(); + return xDataSource; } } -void SbaTableQueryBrowser::impl_initialize() +void SbaTableQueryBrowser::impl_initialize(const ::comphelper::NamedValueCollection& rArguments) { SolarMutexGuard aGuard; // doin' a lot of VCL stuff here -> lock the SolarMutex // first initialize the parent - SbaXDataBrowserController::impl_initialize(); + SbaXDataBrowserController::impl_initialize(rArguments); Reference<XConnection> xForeignConnection; Reference< XFrame > xFrame; @@ -3110,8 +3110,6 @@ void SbaTableQueryBrowser::impl_initialize() OUString sInitialDataSourceName; OUString sInitialCommand; - const NamedValueCollection& rArguments( getInitParams() ); - rArguments.get_ensureType( PROPERTY_DATASOURCENAME, sInitialDataSourceName ); rArguments.get_ensureType( PROPERTY_COMMAND_TYPE, nInitialDisplayCommandType ); rArguments.get_ensureType( PROPERTY_COMMAND, sInitialCommand ); @@ -3120,22 +3118,22 @@ void SbaTableQueryBrowser::impl_initialize() rArguments.get_ensureType( PROPERTY_UPDATE_SCHEMANAME, aSchemaName ); rArguments.get_ensureType( PROPERTY_UPDATE_TABLENAME, aTableName ); rArguments.get_ensureType( PROPERTY_ESCAPE_PROCESSING, bEscapeProcessing ); - rArguments.get_ensureType( "Frame", xFrame ); + rArguments.get_ensureType( u"Frame"_ustr, xFrame ); rArguments.get_ensureType( PROPERTY_SHOWMENU, m_bShowMenu ); // disable the browser if either of ShowTreeViewButton (compatibility name) or EnableBrowser // is present and set to FALSE - bool bDisableBrowser = !rArguments.getOrDefault( "ShowTreeViewButton", true ) // compatibility name + bool bDisableBrowser = !rArguments.getOrDefault( u"ShowTreeViewButton"_ustr, true ) // compatibility name || !rArguments.getOrDefault( PROPERTY_ENABLE_BROWSER, true ); - OSL_ENSURE( !rArguments.has( "ShowTreeViewButton" ), + OSL_ENSURE( !rArguments.has( u"ShowTreeViewButton"_ustr ), "SbaTableQueryBrowser::impl_initialize: ShowTreeViewButton is superseded by EnableBrowser!" ); m_bEnableBrowser = !bDisableBrowser; // hide the tree view it is disabled in general, or if the settings tell to hide it initially bool bHideTreeView = ( !m_bEnableBrowser ) - || !rArguments.getOrDefault( "ShowTreeView", true ) // compatibility name + || !rArguments.getOrDefault( u"ShowTreeView"_ustr, true ) // compatibility name || !rArguments.getOrDefault( PROPERTY_SHOW_BROWSER, true ); - OSL_ENSURE( !rArguments.has( "ShowTreeView" ), + OSL_ENSURE( !rArguments.has( u"ShowTreeView"_ustr ), "SbaTableQueryBrowser::impl_initialize: ShowTreeView is superseded by ShowBrowser!" ); if ( bHideTreeView ) @@ -3147,24 +3145,14 @@ void SbaTableQueryBrowser::impl_initialize() { try { - Sequence< OUString> aProperties(5); - Sequence< Any> aValues(5); - - OUString* pStringIter = aProperties.getArray(); - Any* pValueIter = aValues.getArray(); - *pStringIter++ = "AlwaysShowCursor"; - *pValueIter++ <<= false; - *pStringIter++ = PROPERTY_BORDER; - *pValueIter++ <<= sal_Int16(0); - - *pStringIter++ = "HasNavigationBar"; - *pValueIter++ <<= false; - *pStringIter++ = "HasRecordMarker"; - *pValueIter++ <<= false; - - *pStringIter++ = "Tabstop"; - *pValueIter++ <<= false; - + Sequence< OUString> aProperties + { + u"AlwaysShowCursor"_ustr, PROPERTY_BORDER, u"HasNavigationBar"_ustr, u"HasRecordMarker"_ustr, u"Tabstop"_ustr + }; + Sequence< Any> aValues + { + Any(false), Any(sal_Int16(0)), Any(false), Any(false), Any(false) + }; Reference< XMultiPropertySet > xFormMultiSet(getFormComponent(), UNO_QUERY); if ( xFormMultiSet.is() ) xFormMultiSet->setPropertyValues(aProperties, aValues); @@ -3259,9 +3247,9 @@ void SbaTableQueryBrowser::impl_initialize() try { Reference< XPropertySet > xRowSetProps(getRowSet(), UNO_QUERY); - xRowSetProps->setPropertyValue(PROPERTY_UPDATE_CATALOGNAME,makeAny(aCatalogName)); - xRowSetProps->setPropertyValue(PROPERTY_UPDATE_SCHEMANAME,makeAny(aSchemaName)); - xRowSetProps->setPropertyValue(PROPERTY_UPDATE_TABLENAME,makeAny(aTableName)); + xRowSetProps->setPropertyValue(PROPERTY_UPDATE_CATALOGNAME,Any(aCatalogName)); + xRowSetProps->setPropertyValue(PROPERTY_UPDATE_SCHEMANAME,Any(aSchemaName)); + xRowSetProps->setPropertyValue(PROPERTY_UPDATE_TABLENAME,Any(aTableName)); } catch(const Exception&) @@ -3313,7 +3301,7 @@ bool SbaTableQueryBrowser::ensureConnection(const weld::TreeIter* pAnyEntry, Sha weld::TreeView& rTreeView = m_pTreeView->GetWidget(); DBTreeListUserData* pDSData = xDSEntry - ? reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xDSEntry).toUInt64()) + ? weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*xDSEntry)) : nullptr; return ensureConnection(xDSEntry.get(), pDSData, rConnection); @@ -3334,7 +3322,7 @@ bool SbaTableQueryBrowser::getExistentConnectionFor(const weld::TreeIter* pAnyEn weld::TreeView& rTreeView = m_pTreeView->GetWidget(); DBTreeListUserData* pDSData = xDSEntry - ? reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xDSEntry).toUInt64()) + ? weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*xDSEntry)) : nullptr; if (pDSData) rConnection = pDSData->xConnection; @@ -3443,7 +3431,7 @@ int SbaTableQueryBrowser::OnTreeEntryCompare(const weld::TreeIter& rLHS, const w return nCompareResult; } -void SbaTableQueryBrowser::implAdministrate(weld::TreeIter& rApplyTo) +void SbaTableQueryBrowser::implAdministrate(const weld::TreeIter& rApplyTo) { try { @@ -3468,16 +3456,16 @@ void SbaTableQueryBrowser::implAdministrate(weld::TreeIter& rApplyTo) InteractionHandler::createWithParent(getORB(), nullptr) ); ::comphelper::NamedValueCollection aLoadArgs; - aLoadArgs.put( "Model", xDocumentModel ); - aLoadArgs.put( "InteractionHandler", xInteractionHandler ); - aLoadArgs.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG ); + aLoadArgs.put( u"Model"_ustr, xDocumentModel ); + aLoadArgs.put( u"InteractionHandler"_ustr, xInteractionHandler ); + aLoadArgs.put( u"MacroExecutionMode"_ustr, MacroExecMode::USE_CONFIG ); Sequence< PropertyValue > aLoadArgPV; aLoadArgs >>= aLoadArgPV; xFrameLoader->loadComponentFromURL( xDocumentModel->getURL(), - "_default", + u"_default"_ustr, FrameSearchFlag::ALL | FrameSearchFlag::GLOBAL, aLoadArgPV ); @@ -3502,7 +3490,7 @@ bool SbaTableQueryBrowser::requestQuickHelp(const void* pUserData, OUString& rTe OUString SbaTableQueryBrowser::getContextMenuResourceName() const { - return "explorer"; + return u"explorer"_ustr; } IController& SbaTableQueryBrowser::getCommandController() @@ -3530,7 +3518,7 @@ Any SbaTableQueryBrowser::getCurrentSelection(weld::TreeView& rControl) const return Any(); NamedDatabaseObject aSelectedObject; - DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xSelected).toUInt64()); + DBTreeListUserData* pData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*xSelected)); aSelectedObject.Type = static_cast< sal_Int32 >( pData->eType ); switch ( aSelectedObject.Type ) @@ -3551,7 +3539,7 @@ Any SbaTableQueryBrowser::getCurrentSelection(weld::TreeView& rControl) const break; } - return makeAny( aSelectedObject ); + return Any( aSelectedObject ); } vcl::Window* SbaTableQueryBrowser::getMenuParent() const @@ -3651,7 +3639,7 @@ void SbaTableQueryBrowser::loadMenu(const Reference< XFrame >& _xFrame) if ( xLayoutManager.is() ) { xLayoutManager->lock(); - xLayoutManager->createElement( "private:resource/toolbar/toolbar" ); + xLayoutManager->createElement( u"private:resource/toolbar/toolbar"_ustr ); xLayoutManager->unlock(); xLayoutManager->doLayout(); } @@ -3759,7 +3747,7 @@ void SAL_CALL SbaTableQueryBrowser::registeredDatabaseLocation( const DatabaseRe implAddDatasource( Event.Name, SharedConnection() ); } -void SbaTableQueryBrowser::impl_cleanupDataSourceEntry(const OUString& rDataSourceName) +void SbaTableQueryBrowser::impl_cleanupDataSourceEntry(std::u16string_view rDataSourceName) { // get the top-level representing the removed data source weld::TreeView& rTreeView = m_pTreeView->GetWidget(); @@ -3788,14 +3776,14 @@ void SbaTableQueryBrowser::impl_cleanupDataSourceEntry(const OUString& rDataSour do { // delete any user data of the child entries of the to-be-removed entry - const DBTreeListUserData* pData = reinterpret_cast<const DBTreeListUserData*>(rTreeView.get_id(*xChild).toUInt64()); + const DBTreeListUserData* pData = weld::fromId<const DBTreeListUserData*>(rTreeView.get_id(*xChild)); rTreeView.set_id(*xChild, OUString()); delete pData; } while (rTreeView.iter_next_sibling(*xChild)); } // remove the entry - DBTreeListUserData* pData = reinterpret_cast<DBTreeListUserData*>(rTreeView.get_id(*xDataSourceEntry).toUInt64()); + DBTreeListUserData* pData = weld::fromId<DBTreeListUserData*>(rTreeView.get_id(*xDataSourceEntry)); rTreeView.set_id(*xDataSourceEntry, OUString()); delete pData; rTreeView.remove(*xDataSourceEntry); |