LibreOffice Module dbaccess (master) 1
genericcontroller.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#ifndef INCLUDED_DBACCESS_GENERICCONTROLLER_HXX
21#define INCLUDED_DBACCESS_GENERICCONTROLLER_HXX
22
23#include <sal/config.h>
24
25#include <deque>
26#include <map>
27#include <memory>
28#include <mutex>
29#include <utility>
30#include <vector>
31
32#include <optional>
33
34#include <com/sun/star/awt/XUserInputInterception.hpp>
35#include <com/sun/star/frame/CommandGroup.hpp>
36#include <com/sun/star/frame/DispatchInformation.hpp>
37#include <com/sun/star/frame/XController2.hpp>
38#include <com/sun/star/frame/XDispatch.hpp>
39#include <com/sun/star/frame/XDispatchInformationProvider.hpp>
40#include <com/sun/star/frame/XDispatchProviderInterceptor.hpp>
41#include <com/sun/star/frame/XLayoutManager.hpp>
42#include <com/sun/star/frame/XTitle.hpp>
43#include <com/sun/star/frame/XTitleChangeBroadcaster.hpp>
44#include <com/sun/star/lang/EventObject.hpp>
45#include <com/sun/star/lang/XInitialization.hpp>
46#include <com/sun/star/lang/XServiceInfo.hpp>
47#include <com/sun/star/uno/Any.hxx>
48#include <com/sun/star/uno/Reference.hxx>
49#include <com/sun/star/uno/Sequence.hxx>
50#include <com/sun/star/util/URL.hpp>
51#include <com/sun/star/util/XModifyListener.hpp>
61#include <osl/mutex.hxx>
62#include <rtl/ustring.hxx>
63#include <sal/types.h>
64#include <tools/link.hxx>
65#include <vcl/vclptr.hxx>
67
68namespace com::sun::star {
69 namespace awt { class XKeyHandler; }
70 namespace awt { class XMouseClickHandler; }
71 namespace awt { class XWindow; }
72 namespace beans { struct PropertyValue; }
73 namespace frame { class XController; }
74 namespace frame { class XDispatchProvider; }
75 namespace frame { class XFrame; }
76 namespace frame { class XFrameActionListener; }
77 namespace frame { class XModel; }
78 namespace frame { class XStatusListener; }
79 namespace frame { class XTitleChangeListener; }
80 namespace frame { struct DispatchDescriptor; }
81 namespace frame { struct FrameActionEvent; }
82 namespace lang { class XEventListener; }
83 namespace sdb { class XDatabaseContext; }
84 namespace sdbc { class XConnection; }
85 namespace sdbc { class XDataSource; }
86 namespace ui { class XSidebarProvider; }
87 namespace uno { class XComponentContext; }
88 namespace util { class XURLTransformer; }
89}
90
91namespace vcl { class Window; }
92namespace weld { class Window; }
93class NotifyEvent;
94
95namespace dbaui
96{
97 class ODataView;
98
99 template< typename T >
100 inline bool SAL_CALL operator >>= (const css::uno::Any& _any, std::optional< T >& _value)
101 {
102 _value.reset(); // de-init the optional value
103
104 T directValue = T();
105 if ( _any >>= directValue )
106 _value = directValue;
107
108 return !!_value;
109 }
110
111
112 // = FeatureState
113
121 {
123
124 std::optional<bool> bChecked;
125 std::optional<bool> bInvisible;
126 css::uno::Any aValue;
127 std::optional<OUString> sTitle;
128
129 FeatureState() : bEnabled(false) { }
130 };
131
132
133 // = helper
134
135
136 struct ControllerFeature : public css::frame::DispatchInformation
137 {
138 sal_uInt16 nFeatureId;
139 };
140
141
142 typedef ::std::map < OUString
144 , ::std::less< OUString >
146
147
149 {
150 const sal_Int32 m_nId;
151 public:
152 CompareFeatureById(sal_Int32 _nId) : m_nId(_nId)
153 {}
154
155 bool operator()( const SupportedFeatures::value_type& _aType ) const
156 {
157 return m_nId == _aType.second.nFeatureId;
158 }
159 };
160
161
163 {
164 css::uno::Reference< css::frame::XStatusListener >
166 sal_Int32 nId;
168 };
169
170
172 {
173 const css::uno::Reference< css::frame::XStatusListener >& m_xListener;
174 public:
175 FindFeatureListener(const css::uno::Reference< css::frame::XStatusListener >& _xListener)
176 : m_xListener(_xListener)
177 {}
178
179 bool operator()( const FeatureListener& lhs ) const
180 {
181 return lhs.xListener == m_xListener;
182 }
183 };
184
185
187
188 typedef ::cppu::WeakComponentImplHelper< css::frame::XDispatch
189 , css::frame::XDispatchProviderInterceptor
190 , css::util::XModifyListener
191 , css::frame::XFrameActionListener
192 , css::lang::XInitialization
193 , css::lang::XServiceInfo
194 , css::frame::XDispatchInformationProvider
195 , css::frame::XController2
196 , css::frame::XTitle
197 , css::frame::XTitleChangeBroadcaster
198 , css::awt::XUserInputInterception
200
201 struct OGenericUnoController_Data;
202
206 ,public IController
207 {
208 private:
213 VclPtr<ODataView> m_pView; // our (VCL) "main window"
214
215#ifdef DBG_UTIL
217#endif
218
219 protected:
220
221 // attributes
223 {
224 css::util::URL aURL;
225 css::uno::Reference< css::frame::XStatusListener > xListener;
226
227 DispatchTarget(css::util::URL _aURL, css::uno::Reference< css::frame::XStatusListener > xRef) : aURL(std::move(_aURL)), xListener(std::move(xRef)) { }
228 };
229
230 typedef std::map<sal_uInt16, FeatureState> StateCache;
231 typedef std::vector<DispatchTarget> Dispatch;
232
233 ::std::deque< FeatureListener >
235
236 std::mutex m_aFeatureMutex; // locked when features are append to or remove from deque
237 StateCache m_aStateCache; // save the current status of feature state
238 Dispatch m_arrStatusListener; // all our listeners where we dispatch status changes
240 OAsynchronousLink m_aAsyncCloseTask; // called when a task should be closed
241
242 css::uno::Reference< css::util::XURLTransformer > m_xUrlTransformer; // needed sometimes
243 css::uno::Reference< css::uno::XComponentContext > m_xContext;
245 css::uno::Reference< css::frame::XDispatchProvider > m_xSlaveDispatcher; // for intercepting dispatches
246 css::uno::Reference< css::frame::XDispatchProvider > m_xMasterDispatcher; // ditto
247 css::uno::Reference< css::sdb::XDatabaseContext > m_xDatabaseContext;
248 css::uno::Reference< css::frame::XTitle > m_xTitleHelper;
249
252
255
256
257 // attribute access
259 ::cppu::OBroadcastHelper& getBroadcastHelper() { return OGenericUnoController_Base::rBHelper; }
260
261
262 // methods
263 OGenericUnoController( const css::uno::Reference< css::uno::XComponentContext >& _rM );
265 const ::comphelper::NamedValueCollection&
266 getInitParams() const { return m_aInitParameters; }
267
268 // closes the task when possible
269 void closeTask();
270
271 // if getMenu returns a non empty string than this will be dispatched at the frame
272 virtual void loadMenu(const css::uno::Reference< css::frame::XFrame >& _xFrame);
273
279 virtual void onLoadedMenu(const css::uno::Reference< css::frame::XLayoutManager >& _xLayoutManager);
280
281 // all the features which should be handled by this class
282 virtual void describeSupportedFeatures();
283
284 // state of a feature. 'feature' may be the handle of a css::util::URL somebody requested a dispatch interface for OR a toolbar slot.
285 virtual FeatureState GetState(sal_uInt16 nId) const;
286 // execute a feature
287 virtual void Execute(sal_uInt16 nId , const css::uno::Sequence< css::beans::PropertyValue>& aArgs);
288
302 void implDescribeSupportedFeature(
303 const OUString& _rCommandURL,
304 sal_uInt16 _nFeatureId,
305 sal_Int16 _nCommandGroup = css::frame::CommandGroup::INTERNAL
306 );
307
312 bool isFeatureSupported( sal_Int32 _nId );
313
314 // gets the URL which the given id is assigned to
315 css::util::URL getURLForId(sal_Int32 _nId) const;
316
321 static bool isUserDefinedFeature( const sal_uInt16 nFeatureId );
322
327 bool isUserDefinedFeature( const OUString& _rFeatureURL ) const;
328
329 // connect to a datasource
330 css::uno::Reference< css::sdbc::XConnection > connect(
331 const css::uno::Reference< css::sdbc::XDataSource>& _xDataSource
332 );
333
334 // connect to a datasource
335 css::uno::Reference< css::sdbc::XConnection > connect(
336 const OUString& _rsDataSourceName,
337 const OUString& _rContextInformation,
338 ::dbtools::SQLExceptionInfo* _pErrorInfo
339 );
340
341 void startConnectionListening(const css::uno::Reference< css::sdbc::XConnection >& _rxConnection);
342 void stopConnectionListening(const css::uno::Reference< css::sdbc::XConnection >& _rxConnection);
343
348 css::uno::Reference< css::awt::XWindow> getTopMostContainerWindow() const;
349
350 // XInitialize will be called inside initialize
351 virtual void impl_initialize();
352
353 virtual OUString getPrivateTitle() const { return OUString(); }
354
355 css::uno::Reference< css::frame::XTitle > impl_getTitleHelper_throw(bool bCreateIfNecessary = true);
356 virtual css::uno::Reference< css::frame::XModel > getPrivateModel() const
357 {
358 return css::uno::Reference< css::frame::XModel >();
359 }
360
361 virtual void startFrameListening( const css::uno::Reference< css::frame::XFrame >& _rxFrame );
362 virtual void stopFrameListening( const css::uno::Reference< css::frame::XFrame >& _rxFrame );
363
364 void releaseNumberForComponent();
365
366 virtual ~OGenericUnoController() override;
367
368 private:
369 void fillSupportedFeatures();
370
371 void InvalidateAll_Impl();
372 void InvalidateFeature_Impl();
373
374 void ImplInvalidateFeature( sal_Int32 _nId, const css::uno::Reference< css::frame::XStatusListener >& _xListener, bool _bForceBroadcast );
375
376 void ImplBroadcastFeatureState(const OUString& _rFeature, const css::uno::Reference< css::frame::XStatusListener > & xListener, bool _bIgnoreCache);
377
378 void executeUserDefinedFeatures( const css::util::URL& _rFeatureURL, const css::uno::Sequence< css::beans::PropertyValue>& _rArgs );
379
380 // link methods
381 DECL_DLLPRIVATE_LINK(OnAsyncInvalidateAll, void*, void);
382 DECL_DLLPRIVATE_LINK(OnAsyncCloseTask, void*, void);
383
384 public:
385 const css::uno::Reference< css::uno::XComponentContext >& getORB() const { return m_xContext; }
386 ODataView* getView() const { return m_pView; }
387 weld::Window* getFrameWeld() const;
388 void setView( const VclPtr<ODataView>& i_rView );
389 void clearView();
390 // shows an error box if the SQLExceptionInfo is valid
391 void showError(const ::dbtools::SQLExceptionInfo& _rInfo);
392
393 // if there is a css::util::URL translation for the id
394 // ('handle') then if xListener is NULL the change will be forwarded
395 // to all listeners to the given css::util::URL
396 // if there is a toolbar slot with the given id it is updated (the new state is determined via GetState)
397 // if _bForceBroadcast is sal_True, the current feature state is broadcasted no matter if it is the same as the cached state
398 void InvalidateFeature(sal_uInt16 nId, const css::uno::Reference< css::frame::XStatusListener > & xListener = nullptr, bool _bForceBroadcast = false);
399
402 void InvalidateAll();
403 // late construction
404 virtual bool Construct(vcl::Window* pParent);
405
412 static css::uno::Reference< css::frame::XLayoutManager > getLayoutManager(const css::uno::Reference< css::frame::XFrame >& _xFrame);
413
414 // IController
415 virtual void executeUnChecked(const css::util::URL& _rCommand, const css::uno::Sequence< css::beans::PropertyValue>& aArgs) override;
416 virtual void executeChecked(const css::util::URL& _rCommand, const css::uno::Sequence< css::beans::PropertyValue>& aArgs) override;
417 virtual void executeUnChecked(sal_uInt16 _nCommandId, const css::uno::Sequence< css::beans::PropertyValue>& aArgs) override;
418 virtual void executeChecked(sal_uInt16 _nCommandId, const css::uno::Sequence< css::beans::PropertyValue>& aArgs) override;
419 virtual bool isCommandEnabled(sal_uInt16 _nCommandId) const override;
420 virtual bool isCommandEnabled(const OUString& _rCompleteCommandURL) const override;
421 virtual bool isDataSourceReadOnly() const override;
422 virtual css::uno::Reference< css::frame::XController > getXController() override;
423 virtual bool interceptUserInput( const NotifyEvent& _rEvent ) override;
424
425 // misc
426 bool isCommandChecked(sal_uInt16 _nCommandId) const;
427
428 // css::lang::XEventListener
429 virtual void SAL_CALL disposing(const css::lang::EventObject& Source) override;
430
431 // css::util::XModifyListener
432 virtual void SAL_CALL modified(const css::lang::EventObject& aEvent) override;
433
434 // XInterface
435 virtual void SAL_CALL acquire( ) noexcept override;
436 virtual void SAL_CALL release( ) noexcept override;
437
438 // css::frame::XController2
439 virtual css::uno::Reference< css::awt::XWindow > SAL_CALL getComponentWindow() override;
440 virtual OUString SAL_CALL getViewControllerName() override;
441 virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getCreationArguments() override;
442
443 virtual css::uno::Reference< css::ui::XSidebarProvider > SAL_CALL getSidebar() override;
444
445
446 // css::frame::XController
447 virtual void SAL_CALL attachFrame(const css::uno::Reference< css::frame::XFrame > & xFrame) override;
448 virtual sal_Bool SAL_CALL attachModel(const css::uno::Reference< css::frame::XModel > & xModel) override;
449 virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) override = 0;
450 virtual css::uno::Any SAL_CALL getViewData() override;
451 virtual void SAL_CALL restoreViewData(const css::uno::Any& Data) override;
452 virtual css::uno::Reference< css::frame::XModel > SAL_CALL getModel() override;
453 virtual css::uno::Reference< css::frame::XFrame > SAL_CALL getFrame() override;
454
455 // css::frame::XDispatch
456 virtual void SAL_CALL dispatch(const css::util::URL& aURL, const css::uno::Sequence< css::beans::PropertyValue>& aArgs) override;
457 virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener > & aListener, const css::util::URL& aURL) override;
458 virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener > & aListener, const css::util::URL& aURL) override;
459
460 // css::frame::XDispatchProviderInterceptor
461 virtual css::uno::Reference< css::frame::XDispatchProvider > SAL_CALL getSlaveDispatchProvider() override;
462 virtual void SAL_CALL setSlaveDispatchProvider(const css::uno::Reference< css::frame::XDispatchProvider > & _xNewProvider) override;
463 virtual css::uno::Reference< css::frame::XDispatchProvider > SAL_CALL getMasterDispatchProvider() override;
464 virtual void SAL_CALL setMasterDispatchProvider(const css::uno::Reference< css::frame::XDispatchProvider > & _xNewProvider) override;
465
466 // css::frame::XDispatchProvider
467 virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(const css::util::URL& aURL, const OUString& aTargetFrameName, sal_Int32 nSearchFlags) override;
468 virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches(const css::uno::Sequence< css::frame::DispatchDescriptor >& aDescripts) override;
469
470 // css::lang::XComponent
471 virtual void SAL_CALL dispose() override; //LLA: need solar mutex {OGenericUnoController_COMPBASE::dispose(); }
472 virtual void SAL_CALL disposing() override;
473 virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > & aListener) override;
474 virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > & aListener) override;
475
476 // css::frame::XFrameActionListener
477 virtual void SAL_CALL frameAction(const css::frame::FrameActionEvent& aEvent) override;
478 // lang::XInitialization
479 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
480
481 // XServiceInfo
482 virtual OUString SAL_CALL getImplementationName() override = 0;
483 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
484 virtual css::uno::Sequence< OUString> SAL_CALL getSupportedServiceNames() override = 0;
485
486 // XDispatchInformationProvider
487 virtual css::uno::Sequence< ::sal_Int16 > SAL_CALL getSupportedCommandGroups() override;
488 virtual css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL getConfigurableDispatchInformation( ::sal_Int16 ) override;
489
490 // XTitle
491 virtual OUString SAL_CALL getTitle( ) override;
492 virtual void SAL_CALL setTitle( const OUString& sTitle ) override;
493
494 // XTitleChangeBroadcaster
495 virtual void SAL_CALL addTitleChangeListener( const css::uno::Reference< css::frame::XTitleChangeListener >& xListener ) override;
496 virtual void SAL_CALL removeTitleChangeListener( const css::uno::Reference< css::frame::XTitleChangeListener >& xListener ) override;
497
498 // XUserInputInterception
499 virtual void SAL_CALL addKeyHandler( const css::uno::Reference< css::awt::XKeyHandler >& xHandler ) override;
500 virtual void SAL_CALL removeKeyHandler( const css::uno::Reference< css::awt::XKeyHandler >& xHandler ) override;
501 virtual void SAL_CALL addMouseClickHandler( const css::uno::Reference< css::awt::XMouseClickHandler >& xHandler ) override;
502 virtual void SAL_CALL removeMouseClickHandler( const css::uno::Reference< css::awt::XMouseClickHandler >& xHandler ) override;
503 };
504}
505
506#endif // INCLUDED_DBACCESS_GENERICCONTROLLER_HXX
507
508
509/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::osl::Mutex & getMutex() const
bool operator()(const SupportedFeatures::value_type &_aType) const
helper class to encapsulate the frame which a controller is plugged into, doing some common actions o...
const css::uno::Reference< css::frame::XStatusListener > & m_xListener
bool operator()(const FeatureListener &lhs) const
FindFeatureListener(const css::uno::Reference< css::frame::XStatusListener > &_xListener)
OGenericUnoController(const css::uno::Reference< css::uno::XComponentContext > &_rM)
css::uno::Reference< css::util::XURLTransformer > m_xUrlTransformer
css::uno::Reference< css::frame::XTitle > m_xTitleHelper
css::uno::Reference< css::sdb::XDatabaseContext > m_xDatabaseContext
::cppu::OBroadcastHelper & getBroadcastHelper()
virtual OUString getPrivateTitle() const
::std::deque< FeatureListener > m_aFeaturesToInvalidate
css::uno::Reference< css::sdbc::XConnection > connect(const css::uno::Reference< css::sdbc::XDataSource > &_xDataSource)
::sfx2::UserInputInterception m_aUserInputInterception
DECL_DLLPRIVATE_LINK(OnAsyncInvalidateAll, void *, void)
std::vector< DispatchTarget > Dispatch
const ::comphelper::NamedValueCollection & getInitParams() const
virtual void executeChecked(sal_uInt16 _nCommandId, const css::uno::Sequence< css::beans::PropertyValue > &aArgs) override
executes the given command only when it is allowed
css::uno::Reference< css::frame::XDispatchProvider > m_xSlaveDispatcher
::comphelper::NamedValueCollection m_aInitParameters
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) 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 css::uno::Reference< css::frame::XModel > getPrivateModel() const
css::uno::Reference< css::frame::XDispatchProvider > m_xMasterDispatcher
OAsynchronousLink m_aAsyncInvalidateAll
std::map< sal_uInt16, FeatureState > StateCache
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
virtual void executeUnChecked(sal_uInt16 _nCommandId, const css::uno::Sequence< css::beans::PropertyValue > &aArgs) override
executes the given command without checking if it is allowed
css::uno::Reference< css::uno::XComponentContext > m_xContext
DECL_DLLPRIVATE_LINK(OnAsyncCloseTask, void *, void)
const css::uno::Reference< css::uno::XComponentContext > & getORB() const
SupportedFeatures m_aSupportedFeatures
Reference< XComponentContext > m_xContext
#define DBACCESS_DLLPUBLIC
URL aURL
Definition: intercept.cxx:87
Sequence< PropertyValue > aArguments
Definition: intercept.cxx:88
bool SAL_CALL operator>>=(const css::uno::Any &_any, std::optional< T > &_value)
::std::map< OUString, ControllerFeature, ::std::less< OUString > > SupportedFeatures
::comphelper::SharedMutexBase OGenericUnoController_MBASE
::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
void showError(const SQLExceptionInfo &_rInfo, const Reference< XWindow > &_xParent, const Reference< XComponentContext > &_rxContext)
const ::avmedia::MediaItem * Execute(const SdrMarkView *pSdrView, SfxRequest const &rReq)
void GetState(const SdrMarkView *pSdrView, SfxItemSet &rSet)
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
DispatchTarget(css::util::URL _aURL, css::uno::Reference< css::frame::XStatusListener > xRef)
css::uno::Reference< css::frame::XStatusListener > xListener
Reference< XFrame > xFrame
the frame which the component resides in. Must not be <NULL>
Reference< XModel > xModel
the model of the sub component. Might be <NULL>
unsigned char sal_Bool