summaryrefslogtreecommitdiff
path: root/dbaccess/source/ui/browser/genericcontroller.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'dbaccess/source/ui/browser/genericcontroller.cxx')
-rw-r--r--dbaccess/source/ui/browser/genericcontroller.cxx194
1 files changed, 72 insertions, 122 deletions
diff --git a/dbaccess/source/ui/browser/genericcontroller.cxx b/dbaccess/source/ui/browser/genericcontroller.cxx
index e317c2a3beeb..77aaafdbadfb 100644
--- a/dbaccess/source/ui/browser/genericcontroller.cxx
+++ b/dbaccess/source/ui/browser/genericcontroller.cxx
@@ -23,7 +23,7 @@
#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>
@@ -37,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>
@@ -57,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;
@@ -66,43 +64,22 @@ using namespace ::com::sun::star::ui;
using namespace ::dbtools;
using namespace ::comphelper;
-#define ALL_FEATURES -1
+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
) );
@@ -121,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 )
@@ -150,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
{
@@ -207,7 +166,7 @@ IMPL_LINK_NOARG(OGenericUnoController, OnAsyncInvalidateAll, void*, void)
InvalidateFeature_Impl();
}
-void OGenericUnoController::impl_initialize()
+void OGenericUnoController::impl_initialize(const ::comphelper::NamedValueCollection& /*rArguments*/)
{
}
@@ -218,45 +177,44 @@ void SAL_CALL OGenericUnoController::initialize( const Sequence< Any >& aArgumen
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" )
- {
- xFrame.set(aValue.Value,UNO_QUERY_THROW);
- }
- else if ( ( *pIter >>= aValue ) && aValue.Name == "Preview" )
+ PropertyValue aValue;
+ if (arg >>= aValue)
{
- 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 );
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&)
{
@@ -323,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()
@@ -370,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() )
@@ -429,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)
{
@@ -459,7 +417,7 @@ void OGenericUnoController::InvalidateFeature_Impl()
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();
@@ -492,7 +450,7 @@ 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)
@@ -521,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 );
}
@@ -547,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())
@@ -584,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;
@@ -653,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())
@@ -674,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()
@@ -707,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);
@@ -717,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();
}
@@ -733,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 )
@@ -755,7 +700,7 @@ 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
@@ -765,7 +710,7 @@ void OGenericUnoController::implDescribeSupportedFeature( const char* _pAsciiCom
"OGenericUnoController::implDescribeSupportedFeature: invalid feature id!" );
ControllerFeature aFeature;
- aFeature.Command = OUString::createFromAscii( _pAsciiCommandURL );
+ aFeature.Command = _rCommandURL;
aFeature.nFeatureId = _nFeatureId;
aFeature.GroupId = _nCommandGroup;
@@ -779,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
@@ -815,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
@@ -923,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& )
{
@@ -938,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();
}
@@ -1050,12 +995,12 @@ 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 );
@@ -1093,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);
}
@@ -1102,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)
@@ -1144,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
@@ -1205,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