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 .
19 #ifndef _SFX_UNOCTITM_HXX
20 #define _SFX_UNOCTITM_HXX
23 #include <com/sun/star/frame/XNotifyingDispatch.hpp>
24 #include <com/sun/star/frame/XDispatchResultListener.hpp>
25 #include <com/sun/star/frame/XDispatchProviderInterceptor.hpp>
26 #include <com/sun/star/frame/XDispatch.hpp>
27 #include <com/sun/star/frame/XDispatchProvider.hpp>
28 #include <com/sun/star/frame/XStatusListener.hpp>
29 #include <com/sun/star/frame/FrameSearchFlag.hpp>
30 #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
31 #include <com/sun/star/frame/FeatureStateEvent.hpp>
32 #include <com/sun/star/frame/DispatchDescriptor.hpp>
33 #include <com/sun/star/util/XURLTransformer.hpp>
34 #include <com/sun/star/lang/XUnoTunnel.hpp>
35 #include <com/sun/star/frame/XFrame.hpp>
36 #include <cppuhelper/weak.hxx>
37 #include <cppuhelper/interfacecontainer.hxx>
39 #include <sfx2/sfxuno.hxx>
40 #include <sfx2/ctrlitem.hxx>
41 #include <osl/mutex.hxx>
47 class SfxUnoControllerItem
: public ::com::sun::star::frame::XStatusListener
,
48 public ::com::sun::star::lang::XTypeProvider
,
49 public ::cppu::OWeakObject
51 ::com::sun::star::util::URL aCommand
;
52 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatch
> xDispatch
;
53 SfxControllerItem
* pCtrlItem
;
54 SfxBindings
* pBindings
;
56 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatch
> TryGetDispatch( SfxFrame
* pFrame
);
59 SFX_DECL_XINTERFACE_XTYPEPROVIDER
62 SfxUnoControllerItem( SfxControllerItem
*, SfxBindings
&, const String
& );
63 ~SfxUnoControllerItem();
65 const ::com::sun::star::util::URL
& GetCommand() const
69 virtual void SAL_CALL
statusChanged(const ::com::sun::star::frame::FeatureStateEvent
& Event
) throw( ::com::sun::star::uno::RuntimeException
);
72 virtual void SAL_CALL
disposing(const ::com::sun::star::lang::EventObject
& Source
) throw( ::com::sun::star::uno::RuntimeException
);
74 void GetNewDispatch();
75 void ReleaseDispatch();
76 void ReleaseBindings();
79 struct SfxStatusDispatcher_Impl_hashType
81 size_t operator()(const OUString
& s
) const
82 { return s
.hashCode(); }
85 typedef ::cppu::OMultiTypeInterfaceContainerHelperVar
< OUString
, SfxStatusDispatcher_Impl_hashType
, std::equal_to
< OUString
> > SfxStatusDispatcher_Impl_ListenerContainer
;
87 class SfxStatusDispatcher
: public ::com::sun::star::frame::XNotifyingDispatch
,
88 public ::com::sun::star::lang::XTypeProvider
,
89 public ::cppu::OWeakObject
92 SfxStatusDispatcher_Impl_ListenerContainer aListeners
;
95 SFX_DECL_XINTERFACE_XTYPEPROVIDER
97 SfxStatusDispatcher();
100 virtual void SAL_CALL
dispatchWithNotification( const ::com::sun::star::util::URL
& aURL
,
101 const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& aArgs
,
102 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatchResultListener
>& rListener
) throw( ::com::sun::star::uno::RuntimeException
);
103 virtual void SAL_CALL
dispatch( const ::com::sun::star::util::URL
& aURL
, const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& aArgs
) throw( ::com::sun::star::uno::RuntimeException
);
104 virtual void SAL_CALL
addStatusListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XStatusListener
> & xControl
, const ::com::sun::star::util::URL
& aURL
) throw( ::com::sun::star::uno::RuntimeException
);
105 virtual void SAL_CALL
removeStatusListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XStatusListener
> & xControl
, const ::com::sun::star::util::URL
& aURL
) throw( ::com::sun::star::uno::RuntimeException
);
109 SfxStatusDispatcher_Impl_ListenerContainer
& GetListeners()
110 { return aListeners
; }
114 class SfxDispatchController_Impl
;
115 class SfxOfficeDispatch
: public SfxStatusDispatcher
116 , public ::com::sun::star::lang::XUnoTunnel
118 friend class SfxDispatchController_Impl
;
119 SfxDispatchController_Impl
* pControllerItem
;
121 SfxOfficeDispatch( SfxBindings
& rBind
,
122 SfxDispatcher
* pDispat
,
123 const SfxSlot
* pSlot
,
124 const ::com::sun::star::util::URL
& rURL
);
125 SfxOfficeDispatch( SfxDispatcher
* pDispat
,
126 const SfxSlot
* pSlot
,
127 const ::com::sun::star::util::URL
& rURL
);
128 ~SfxOfficeDispatch();
130 SFX_DECL_XINTERFACE_XTYPEPROVIDER
132 virtual void SAL_CALL
dispatchWithNotification( const ::com::sun::star::util::URL
& aURL
,
133 const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& aArgs
,
134 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatchResultListener
>& rListener
)
135 throw( ::com::sun::star::uno::RuntimeException
);
136 virtual void SAL_CALL
dispatch( const ::com::sun::star::util::URL
& aURL
,
137 const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& aArgs
)
138 throw( ::com::sun::star::uno::RuntimeException
);
139 virtual void SAL_CALL
addStatusListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XStatusListener
> & xControl
,
140 const ::com::sun::star::util::URL
& aURL
)
141 throw( ::com::sun::star::uno::RuntimeException
);
144 virtual sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
< sal_Int8
>& aIdentifier
) throw(::com::sun::star::uno::RuntimeException
) ;
145 static const ::com::sun::star::uno::Sequence
< sal_Int8
>& impl_getStaticIdentifier();
147 static sal_Bool
IsMasterUnoCommand( const ::com::sun::star::util::URL
& aURL
);
148 static OUString
GetMasterUnoCommand( const ::com::sun::star::util::URL
& aURL
);
150 void SetFrame(const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
>& xFrame
);
152 void SetMasterUnoCommand( sal_Bool bSet
);
154 SfxDispatcher
* GetDispatcher_Impl();
157 class SfxDispatchController_Impl
: public SfxControllerItem
159 ::com::sun::star::util::URL aDispatchURL
;
160 SfxDispatcher
* pDispatcher
;
161 SfxBindings
* pBindings
;
162 const SfxPoolItem
* pLastState
;
164 SfxOfficeDispatch
* pDispatch
;
165 sal_Bool bMasterSlave
;
167 const char* pUnoName
;
168 ::com::sun::star::uno::WeakReference
< ::com::sun::star::frame::XFrame
> xFrame
;
170 void addParametersToArgs( const com::sun::star::util::URL
& aURL
,
171 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& rArgs
) const;
172 SfxMapUnit
GetCoreMetric( SfxItemPool
& rPool
, sal_uInt16 nSlot
);
175 SfxDispatchController_Impl( SfxOfficeDispatch
* pDisp
,
177 SfxDispatcher
* pDispat
,
178 const SfxSlot
* pSlot
,
179 const ::com::sun::star::util::URL
& rURL
);
180 ~SfxDispatchController_Impl();
182 static OUString
getSlaveCommand( const ::com::sun::star::util::URL
& rURL
);
184 void StateChanged( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
, SfxSlotServer
* pServ
);
185 virtual void StateChanged( sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
);
186 void setMasterSlaveCommand( sal_Bool bSet
);
187 void SAL_CALL
dispatch( const ::com::sun::star::util::URL
& aURL
,
188 const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& aArgs
,
189 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatchResultListener
>& rListener
) throw( ::com::sun::star::uno::RuntimeException
);
190 void SAL_CALL
addStatusListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XStatusListener
> & xControl
, const ::com::sun::star::util::URL
& aURL
) throw( ::com::sun::star::uno::RuntimeException
);
191 void UnBindController();
192 SfxDispatcher
* GetDispatcher();
193 void SetFrame(const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
>& xFrame
);
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */