1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <com/sun/star/frame/XNotifyingDispatch.hpp>
23 #include <comphelper/multiinterfacecontainer4.hxx>
24 #include <cppuhelper/implbase.hxx>
25 #include <cppuhelper/weakref.hxx>
27 #include <svl/lstner.hxx>
28 #include <sfx2/ctrlitem.hxx>
31 namespace com::sun::star::frame
{ class XFrame
; }
32 namespace com::sun::star::frame
{ class XNotifyingDispatch
; }
33 namespace com::sun::star::frame
{ class XStatusListener
; }
34 namespace com::sun::star::frame
{ struct FeatureStateEvent
; }
40 typedef comphelper::OMultiTypeInterfaceContainerHelperVar4
<OUString
, css::frame::XStatusListener
>
41 SfxStatusDispatcher_Impl_ListenerContainer
;
43 class SfxStatusDispatcher
: public cppu::WeakImplHelper
<css::frame::XNotifyingDispatch
>
47 SfxStatusDispatcher_Impl_ListenerContainer maListeners
;
51 SfxStatusDispatcher();
54 virtual void SAL_CALL
dispatchWithNotification( const css::util::URL
& aURL
,
55 const css::uno::Sequence
< css::beans::PropertyValue
>& aArgs
,
56 const css::uno::Reference
< css::frame::XDispatchResultListener
>& rListener
) override
;
57 virtual void SAL_CALL
dispatch( const css::util::URL
& aURL
, const css::uno::Sequence
< css::beans::PropertyValue
>& aArgs
) override
;
58 virtual void SAL_CALL
addStatusListener(const css::uno::Reference
< css::frame::XStatusListener
> & xControl
, const css::util::URL
& aURL
) override
;
59 virtual void SAL_CALL
removeStatusListener(const css::uno::Reference
< css::frame::XStatusListener
> & xControl
, const css::util::URL
& aURL
) override
;
63 void sendStatusChanged(const OUString
& rURL
, const css::frame::FeatureStateEvent
& rEvent
);
64 std::vector
<OUString
> getContainedTypes() { std::unique_lock
g(maMutex
); return maListeners
.getContainedTypes(g
); };
68 class SfxDispatchController_Impl
;
69 class SfxOfficeDispatch final
: public cppu::ImplInheritanceHelper
<SfxStatusDispatcher
>
71 friend class SfxDispatchController_Impl
;
72 std::unique_ptr
<SfxDispatchController_Impl
> pImpl
;
74 SfxOfficeDispatch( SfxBindings
& rBind
,
75 SfxDispatcher
* pDispat
,
77 const css::util::URL
& rURL
);
78 SfxOfficeDispatch( SfxDispatcher
* pDispat
,
80 const css::util::URL
& rURL
);
81 virtual ~SfxOfficeDispatch() override
;
83 virtual void SAL_CALL
dispatchWithNotification( const css::util::URL
& aURL
,
84 const css::uno::Sequence
< css::beans::PropertyValue
>& aArgs
,
85 const css::uno::Reference
< css::frame::XDispatchResultListener
>& rListener
) override
;
86 virtual void SAL_CALL
dispatch( const css::util::URL
& aURL
,
87 const css::uno::Sequence
< css::beans::PropertyValue
>& aArgs
) override
;
88 virtual void SAL_CALL
addStatusListener( const css::uno::Reference
< css::frame::XStatusListener
> & xControl
,
89 const css::util::URL
& aURL
) override
;
91 static bool IsMasterUnoCommand( const css::util::URL
& aURL
);
92 static OUString
GetMasterUnoCommand( const css::util::URL
& aURL
);
94 void SetFrame(const css::uno::Reference
< css::frame::XFrame
>& xFrame
);
96 void SetMasterUnoCommand( bool bSet
);
98 SfxDispatcher
* GetDispatcher_Impl();
100 sal_uInt16
GetId() const;
103 class SfxDispatchController_Impl final
104 : public SfxControllerItem
107 css::util::URL aDispatchURL
;
108 SfxDispatcher
* pDispatcher
;
109 SfxBindings
* pBindings
;
110 const SfxPoolItem
* pLastState
;
111 SfxOfficeDispatch
* pDispatch
;
114 css::uno::WeakReference
< css::frame::XFrame
> xFrame
;
116 static void addParametersToArgs( const css::util::URL
& aURL
,
117 css::uno::Sequence
< css::beans::PropertyValue
>& rArgs
);
118 static MapUnit
GetCoreMetric( SfxItemPool
const & rPool
, sal_uInt16 nSlot
);
120 void sendStatusChanged(const OUString
& rURL
, const css::frame::FeatureStateEvent
& rEvent
);
123 SfxDispatchController_Impl( SfxOfficeDispatch
* pDisp
,
125 SfxDispatcher
* pDispat
,
126 const SfxSlot
* pSlot
,
127 css::util::URL aURL
);
128 virtual ~SfxDispatchController_Impl() override
;
130 virtual void Notify(SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
132 static OUString
getSlaveCommand( const css::util::URL
& rURL
);
134 void StateChanged( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
, SfxSlotServer
const * pServ
);
135 virtual void StateChangedAtToolBoxControl( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
) override
;
136 void setMasterSlaveCommand( bool bSet
);
137 /// @throws css::uno::RuntimeException
138 void dispatch( const css::util::URL
& aURL
,
139 const css::uno::Sequence
< css::beans::PropertyValue
>& aArgs
,
140 const css::uno::Reference
< css::frame::XDispatchResultListener
>& rListener
);
142 /// @throws css::uno::RuntimeException
143 void addStatusListener(const css::uno::Reference
< css::frame::XStatusListener
> & xControl
, const css::util::URL
& aURL
);
144 void UnBindController();
145 SfxDispatcher
* GetDispatcher();
146 void SetFrame(const css::uno::Reference
< css::frame::XFrame
>& xFrame
);
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */