27#include <osl/diagnose.h>
33#include <com/sun/star/sdbc/XDataSource.hpp>
34#include <com/sun/star/sdb/DatabaseContext.hpp>
35#include <com/sun/star/beans/XPropertySet.hpp>
36#include <com/sun/star/util/URLTransformer.hpp>
37#include <com/sun/star/util/XCloseable.hpp>
39#include <com/sun/star/ui/XSidebarProvider.hpp>
42#include <com/sun/star/frame/FrameSearchFlag.hpp>
43#include <com/sun/star/frame/status/Visibility.hpp>
44#include <com/sun/star/frame/XUntitledNumbers.hpp>
45#include <com/sun/star/util/XModifiable.hpp>
46#include <rtl/ustring.hxx>
49#include <unordered_map>
56using namespace ::com::sun::star::frame::status;
68#define ALL_FEATURES -1
89 SAL_WARN(
"dbaccess.ui",
"UserDefinedFeatures::execute: the controller shouldn't be the dispatcher here!" );
94 xDispatch->dispatch( _rFeatureURL, _rArgs );
105 ,m_aUserInputInterception(*this,
getMutex())
108 ,m_bDescribingSupportedFeatures( false )
113 ,m_aCurrentFrame( *this )
116 ,m_bCurrentlyModified(false)
117 ,m_bExternalTitle(false)
137 OSL_ENSURE(
getView(),
"the view is NULL!" );
149 OSL_ENSURE(
getORB().is(),
"OGenericUnoController::Construct need a service factory!");
156 SAL_WARN(
"dbaccess.ui",
"OGenericUnoController::Construct: could not create (or start listening at) the database context!");
166 if ( !OGenericUnoController_Base::rBHelper.bInDispose && !OGenericUnoController_Base::rBHelper.bDisposed )
167 InvalidateFeature_Impl();
177 ::osl::MutexGuard aGuard(
getMutex() );
181 PropertyValue aValue;
185 for ( ; pIter != pEnd; ++pIter )
187 if ( ( *pIter >>= aValue ) && aValue.Name ==
"Frame" )
189 xFrame.set(aValue.Value,UNO_QUERY_THROW);
191 else if ( ( *pIter >>= aValue ) && aValue.Name ==
"Preview" )
200 throw IllegalArgumentException(
"need a frame", *
this, 1 );
206 throw IllegalArgumentException(
"Parent window is null", *
this, 1 );
231 OGenericUnoController_Base::acquire();
236 OGenericUnoController_Base::release();
242 _rxFrame->addFrameActionListener(
this );
248 _rxFrame->removeFrameActionListener(
this );
260 ::osl::MutexGuard aGuard(
getMutex() );
299 ::osl::MutexGuard aGuard(
getMutex() );
313 typedef std::vector< Any > States;
315 void lcl_notifyMultipleStates( XStatusListener& _rListener, FeatureStateEvent& _rEvent,
const States& _rStates )
317 for (
auto const& elem : _rStates)
319 _rEvent.State = elem;
320 _rListener.statusChanged( _rEvent );
324 void lcl_collectStates(
const FeatureState& _rFeatureState, States& _out_rStates )
332 if ( !!_rFeatureState.sTitle )
333 _out_rStates.push_back(
Any( *_rFeatureState.sTitle ) );
334 if ( !!_rFeatureState.bChecked )
335 _out_rStates.push_back(
Any( *_rFeatureState.bChecked ) );
336 if ( !!_rFeatureState.bInvisible )
337 _out_rStates.push_back(
Any(
Visibility( !*_rFeatureState.bInvisible ) ) );
338 if ( _rFeatureState.aValue.hasValue() )
339 _out_rStates.push_back( _rFeatureState.aValue );
340 if ( _out_rStates.empty() )
341 _out_rStates.emplace_back( );
351 if ( !_bIgnoreCache )
356 if ( bAlreadyCached )
364 rCachedState = aFeatState;
367 aEvent.FeatureURL.Complete = _rFeature;
370 aEvent.Source =
static_cast<XDispatch*
>(
this);
375 lcl_collectStates( aFeatState, aStates );
378 if ( xListener.is() )
379 lcl_notifyMultipleStates( *xListener,
aEvent, aStates );
382 std::set<OUString> aFeatureCommands;
385 if( rFeature.second.nFeatureId == nFeat )
386 aFeatureCommands.insert( rFeature.first );
394 for (
auto const& elem : aNotifyLoop)
396 if ( aFeatureCommands.find( elem.aURL.Complete ) != aFeatureCommands.end() )
398 aEvent.FeatureURL = elem.aURL;
399 lcl_notifyMultipleStates( *elem.xListener,
aEvent, aStates );
408 SupportedFeatures::const_iterator aFeaturePos = std::find_if(
436 SupportedFeatures::const_iterator aFeaturePos = std::find_if(
442#if OSL_DEBUG_LEVEL > 0
445 SAL_WARN(
"dbaccess.ui",
"OGenericUnoController::InvalidateFeature_Impl: feature id "
447 <<
" has been invalidated, but is not supported!" );
465#if OSL_DEBUG_LEVEL > 0
468 auto isSupportedFeature = std::any_of(
473 OSL_ENSURE( isSupportedFeature,
"OGenericUnoController::ImplInvalidateFeature: invalidating an unsupported feature is suspicious, at least!" );
478 aListener.
nId = _nId;
511 OSL_ENSURE(
m_aFeaturesToInvalidate.size(),
"OGenericUnoController::InvalidateAll_Impl: to be called from within InvalidateFeature_Impl only!");
522 OSL_PRECOND( !
m_aSupportedFeatures.empty(),
"OGenericUnoController::queryDispatch: shouldn't this be filled at construction time?" );
527 if (
aURL.Complete ==
".uno:FormSlots/ConfirmDeletion"
548 sal_Int32 nLen = aDescripts.getLength();
551 aReturn.realloc( nLen );
554 const DispatchDescriptor* pDescripts = aDescripts.getConstArray();
556 for ( ; pReturn != pReturnEnd; ++ pReturn, ++pDescripts )
558 *pReturn =
queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags );
600 URL aParsedURL( _rURL );
614 if (_rURL.Complete.isEmpty())
617 [&aListener](
const DispatchTarget& rCurrent) { return rCurrent.xListener == aListener; }),
625 return (rCurrent.xListener == aListener) && (rCurrent.aURL.Complete == _rURL.Complete); });
630 OSL_PRECOND( !
m_aSupportedFeatures.empty(),
"OGenericUnoController::removeStatusListener: shouldn't this be filled at construction time?" );
637 StateCache::const_iterator aCachePos =
m_aStateCache.find( aIter->second.nFeatureId );
656 if ( xUntitledProvider.is() )
657 xUntitledProvider->releaseNumberForComponent(
static_cast<XWeak*
>(
this));
668 EventObject aDisposeEvent;
669 aDisposeEvent.Source =
static_cast<XWeak*
>(
this);
671 for (
auto const& statusListener : aStatusListener)
673 statusListener.xListener->disposing(aDisposeEvent);
702 OGenericUnoController_Base::WeakComponentImplHelperBase::addEventListener( xListener );
708 OGenericUnoController_Base::WeakComponentImplHelperBase::removeEventListener( xListener );
713 ::osl::MutexGuard aGuard(
getMutex() );
719 sal_uInt16 _nFeatureId, sal_Int16 _nCommandGroup )
724 OSL_PRECOND( _nFeatureId < ( std::numeric_limits< sal_uInt16 >::max() - 1000 ),
725 "OGenericUnoController::implDescribeSupportedFeature: invalid feature id!" );
728 aFeature.Command = _rCommandURL;
730 aFeature.GroupId = _nCommandGroup;
732#if OSL_DEBUG_LEVEL > 0
734 "OGenericUnoController::implDescribeSupportedFeature: this feature is already there!" );
774 "OGenericUnoController::Execute: responsible for user defined features only!" );
786 SupportedFeatures::const_iterator aIter = std::find_if(
794 aReturn.Complete = aIter->first;
804 (_nFeatureId >= ( std::numeric_limits< sal_uInt16 >::max() - 1000 ))
806 ( _nFeatureId < (std::numeric_limits< sal_uInt16 >::max()))
814 "OGenericUnoController::isUserDefinedFeature: this is no supported feature at all!" );
829 xComponent->addEventListener(
static_cast<XFrameActionListener*
>(
this));
837 xComponent->removeEventListener(
static_cast<XFrameActionListener*
>(
this));
886 xLayoutManager.set(xPropSet->getPropertyValue(
"LayoutManager"),UNO_QUERY);
892 return xLayoutManager;
898 if ( xLayoutManager.is() )
900 xLayoutManager->lock();
901 xLayoutManager->createElement(
"private:resource/menubar/menubar" );
902 xLayoutManager->createElement(
"private:resource/toolbar/toolbar" );
903 xLayoutManager->unlock();
904 xLayoutManager->doLayout();
922 if ( !OGenericUnoController_Base::rBHelper.bInDispose )
927 xCloseable->close(
false );
952 ::osl::MutexGuard aGuard(
getMutex() );
958 SAL_WARN(
"dbaccess.ui",
"OGenericUnoController::attachModel: not supported!" );
969 OSL_PRECOND( !
m_aSupportedFeatures.empty(),
"OGenericUnoController::executeUnChecked: shouldn't this be filled at construction time?" );
975 Execute( aIter->second.nFeatureId, aArgs );
980 OSL_PRECOND( !
m_aSupportedFeatures.empty(),
"OGenericUnoController::executeChecked: shouldn't this be filled at construction time?" );
987 sal_uInt16 nFeatureId = aIter->second.nFeatureId;
988 if (
GetState( nFeatureId ).bEnabled )
1001 xWindow =
xFrame->getContainerWindow();
1008 xWindow =
xFrame->getContainerWindow();
1016 ::osl::MutexGuard aGuard(
getMutex() );
1031 ::osl::MutexGuard aGuard(
getMutex() );
1041 ::osl::MutexGuard aGuard(
getMutex() );
1050 if (xBroadcaster.is ())
1051 xBroadcaster->addTitleChangeListener (xListener);
1057 if (xBroadcaster.is ())
1058 xBroadcaster->removeTitleChangeListener (xListener);
1064 if ( _rxHandler.is() )
1075 if ( _rxHandler.is() )
1119 OSL_ENSURE( !_rCompleteCommandURL.isEmpty(),
"OGenericUnoController::isCommandEnabled: Empty command url!" );
1133 if ( supportedFeature.second.GroupId != CommandGroup::INTERNAL )
1134 aCmdHashMap.emplace( supportedFeature.second.GroupId, 0 );
1141 std::vector< DispatchInformation > aInformationVector;
1144 if ( sal_Int16( supportedFeature.second.GroupId ) == CommandGroup )
1146 aInformationVector.push_back( supportedFeature.second );
1167 OGenericUnoController_Base::dispose();
#define ID_BROWSER_EDITDOC
#define ID_BROWSER_SAVEDOC
#define ID_BROWSER_CLIPBOARD_FORMAT_ITEMS
static css::uno::Reference< css::awt::XWindow > GetInterface(vcl::Window *pWindow)
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
void assign(const css::uno::Sequence< css::uno::Any > &_rArguments)
const css::uno::Reference< css::frame::XFrame > & getFrame() const
void frameAction(css::frame::FrameAction _eAction)
notifies the instance that a certain frame action happened with our frame
const css::uno::Reference< css::frame::XFrame > & attachFrame(const css::uno::Reference< css::frame::XFrame > &_rxFrame)
attaches a new frame
void Call(void *_pArgument=nullptr)
void attachFrame(const css::uno::Reference< css::frame::XFrame > &_xFrame)
virtual void Construct()
late construction
css::uno::Reference< css::sdbc::XConnection > connect(const OUString &_rDataSourceName, ::dbtools::SQLExceptionInfo *_pErrorInfo) const
creates a connection to the data source, displays the possible error to the user, or returns it
virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener > &aListener, const css::util::URL &aURL) override
weld::Window * getFrameWeld() const
virtual void stopFrameListening(const css::uno::Reference< css::frame::XFrame > &_rxFrame)
void ImplBroadcastFeatureState(const OUString &_rFeature, const css::uno::Reference< css::frame::XStatusListener > &xListener, bool _bIgnoreCache)
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual void SAL_CALL setMasterDispatchProvider(const css::uno::Reference< css::frame::XDispatchProvider > &_xNewProvider) override
virtual FeatureState GetState(sal_uInt16 nId) const
virtual void SAL_CALL modified(const css::lang::EventObject &aEvent) override
css::uno::Reference< css::util::XURLTransformer > m_xUrlTransformer
ControllerFrame m_aCurrentFrame
virtual void SAL_CALL addMouseClickHandler(const css::uno::Reference< css::awt::XMouseClickHandler > &xHandler) override
css::uno::Reference< css::frame::XTitle > m_xTitleHelper
virtual void startFrameListening(const css::uno::Reference< css::frame::XFrame > &_rxFrame)
virtual void SAL_CALL dispatch(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &aArgs) override
virtual void onLoadedMenu(const css::uno::Reference< css::frame::XLayoutManager > &_xLayoutManager)
called when our menu has been loaded into our frame, can be used to load sub toolbars
virtual void SAL_CALL removeTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener > &xListener) override
virtual bool isDataSourceReadOnly() const override
checks if the selected data source is read only
Dispatch m_arrStatusListener
void fillSupportedFeatures()
css::uno::Reference< css::sdb::XDatabaseContext > m_xDatabaseContext
void ImplInvalidateFeature(sal_Int32 _nId, const css::uno::Reference< css::frame::XStatusListener > &_xListener, bool _bForceBroadcast)
std::mutex m_aFeatureMutex
virtual void SAL_CALL attachFrame(const css::uno::Reference< css::frame::XFrame > &xFrame) override
virtual OUString getPrivateTitle() const
::std::deque< FeatureListener > m_aFeaturesToInvalidate
virtual css::uno::Any SAL_CALL getViewData() override
virtual OUString SAL_CALL getViewControllerName() override
virtual void SAL_CALL release() noexcept override
css::uno::Reference< css::sdbc::XConnection > connect(const css::uno::Reference< css::sdbc::XDataSource > &_xDataSource)
::sfx2::UserInputInterception m_aUserInputInterception
css::uno::Reference< css::frame::XTitle > impl_getTitleHelper_throw(bool bCreateIfNecessary=true)
virtual css::uno::Reference< css::awt::XWindow > SAL_CALL getComponentWindow() override
virtual css::uno::Reference< css::frame::XController > getXController() override
provides access to the model of the controller
OGenericUnoController()=delete
virtual void SAL_CALL setTitle(const OUString &sTitle) override
std::vector< DispatchTarget > Dispatch
void InvalidateAll_Impl()
virtual css::uno::Reference< css::ui::XSidebarProvider > SAL_CALL getSidebar() override
bool isFeatureSupported(sal_Int32 _nId)
returns <TRUE> if the feature is supported, otherwise <FALSE>
virtual bool isCommandEnabled(sal_uInt16 _nCommandId) const override
checks if the given Command is enabled
void executeUserDefinedFeatures(const css::util::URL &_rFeatureURL, const css::uno::Sequence< css::beans::PropertyValue > &_rArgs)
bool isCommandChecked(sal_uInt16 _nCommandId) const
virtual css::uno::Sequence< ::sal_Int16 > SAL_CALL getSupportedCommandGroups() override
virtual void SAL_CALL acquire() noexcept override
virtual css::uno::Reference< css::frame::XFrame > SAL_CALL getFrame() override
virtual ~OGenericUnoController() override
void showError(const ::dbtools::SQLExceptionInfo &_rInfo)
css::uno::Reference< css::frame::XDispatchProvider > m_xSlaveDispatcher
::comphelper::NamedValueCollection m_aInitParameters
virtual css::uno::Reference< css::frame::XModel > SAL_CALL getModel() override
void implDescribeSupportedFeature(const OUString &_rCommandURL, sal_uInt16 _nFeatureId, sal_Int16 _nCommandGroup=css::frame::CommandGroup::INTERNAL)
describes a feature supported by the controller
void setView(const VclPtr< ODataView > &i_rView)
ODataView * getView() const
virtual bool interceptUserInput(const NotifyEvent &_rEvent) override
allows interception of user input, aka mouse clicks and key events
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
virtual css::uno::Reference< css::frame::XDispatchProvider > SAL_CALL getMasterDispatchProvider() override
virtual void SAL_CALL dispose() override
virtual void executeChecked(const css::util::URL &_rCommand, const css::uno::Sequence< css::beans::PropertyValue > &aArgs) override
executes the given command only when it is allowed
virtual void SAL_CALL addKeyHandler(const css::uno::Reference< css::awt::XKeyHandler > &xHandler) override
void stopConnectionListening(const css::uno::Reference< css::sdbc::XConnection > &_rxConnection)
virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches(const css::uno::Sequence< css::frame::DispatchDescriptor > &aDescripts) override
virtual OUString SAL_CALL getTitle() override
virtual void loadMenu(const css::uno::Reference< css::frame::XFrame > &_xFrame)
VclPtr< ODataView > m_pView
void InvalidateFeature(sal_uInt16 nId, const css::uno::Reference< css::frame::XStatusListener > &xListener=nullptr, bool _bForceBroadcast=false)
virtual void Execute(sal_uInt16 nId, const css::uno::Sequence< css::beans::PropertyValue > &aArgs)
virtual css::uno::Reference< css::frame::XModel > getPrivateModel() const
css::uno::Reference< css::frame::XDispatchProvider > m_xMasterDispatcher
virtual bool Construct(vcl::Window *pParent)
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
virtual void SAL_CALL frameAction(const css::frame::FrameActionEvent &aEvent) override
virtual void SAL_CALL restoreViewData(const css::uno::Any &Data) override
OAsynchronousLink m_aAsyncInvalidateAll
virtual sal_Bool SAL_CALL attachModel(const css::uno::Reference< css::frame::XModel > &xModel) override
OAsynchronousLink m_aAsyncCloseTask
virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(const css::util::URL &aURL, const OUString &aTargetFrameName, sal_Int32 nSearchFlags) override
virtual void SAL_CALL setSlaveDispatchProvider(const css::uno::Reference< css::frame::XDispatchProvider > &_xNewProvider) override
virtual css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL getConfigurableDispatchInformation(::sal_Int16) override
virtual void SAL_CALL addTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener > &xListener) override
virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener > &aListener, const css::util::URL &aURL) override
virtual void executeUnChecked(const css::util::URL &_rCommand, const css::uno::Sequence< css::beans::PropertyValue > &aArgs) override
executes the given command without checking if it is allowed
::osl::Mutex & getMutex() const
bool m_bCurrentlyModified
virtual void SAL_CALL removeKeyHandler(const css::uno::Reference< css::awt::XKeyHandler > &xHandler) override
css::util::URL getURLForId(sal_Int32 _nId) const
void releaseNumberForComponent()
bool m_bDescribingSupportedFeatures
virtual void SAL_CALL disposing() override
virtual void impl_initialize()
void InvalidateFeature_Impl()
virtual void SAL_CALL removeMouseClickHandler(const css::uno::Reference< css::awt::XMouseClickHandler > &xHandler) override
void startConnectionListening(const css::uno::Reference< css::sdbc::XConnection > &_rxConnection)
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual css::uno::Reference< css::frame::XDispatchProvider > SAL_CALL getSlaveDispatchProvider() override
void InvalidateAll()
InvalidateAll invalidates all features currently known.
virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getCreationArguments() override
static css::uno::Reference< css::frame::XLayoutManager > getLayoutManager(const css::uno::Reference< css::frame::XFrame > &_xFrame)
get the layout manager
virtual void describeSupportedFeatures()
const css::uno::Reference< css::uno::XComponentContext > & getORB() const
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
static bool isUserDefinedFeature(const sal_uInt16 nFeatureId)
determines whether the given feature ID denotes a user-defined feature
SupportedFeatures m_aSupportedFeatures
css::uno::Reference< css::awt::XWindow > getTopMostContainerWindow() const
return the container window of the top most frame
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
void EnableInput(bool bEnable=true, bool bChild=true)
Reference< XComponentContext > m_xContext
#define DBG_UNHANDLED_EXCEPTION(...)
Reference< XDispatch > xDispatch
std::unordered_map< sal_Int16, sal_Int16 > CommandHashMap
Sequence< PropertyValue > aArguments
#define LINK(Instance, Class, Member)
#define SAL_WARN(area, stream)
css::uno::Sequence< typename M::key_type > mapKeysToSequence(M const &map)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
IMPL_LINK_NOARG(OApplicationController, OnClipboardChanged, TransferableDataHelper *, void)
::cppu::WeakComponentImplHelper< css::frame::XDispatch, css::frame::XDispatchProviderInterceptor, css::util::XModifyListener, css::frame::XFrameActionListener, css::lang::XInitialization, css::lang::XServiceInfo, css::frame::XDispatchInformationProvider, css::frame::XController2, css::frame::XTitle, css::frame::XTitleChangeBroadcaster, css::awt::XUserInputInterception > OGenericUnoController_Base
::osl::Mutex & getMutex()
void VCL_DLLPUBLIC ShowServiceNotAvailableError(weld::Widget *pParent, std::u16string_view rServiceName, bool bError)
css::uno::Reference< css::frame::XStatusListener > xListener
describes the state of a feature
std::optional< bool > bChecked
std::optional< OUString > sTitle
std::optional< bool > bInvisible
Reference< XController > xController
the controller of the sub component. Must not be <NULL>
Reference< XFrame > xFrame
the frame which the component resides in. Must not be <NULL>