Line data Source code
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 : #ifndef _SFX_UNOCTITM_HXX
20 : #define _SFX_UNOCTITM_HXX
21 :
22 : #include <functional>
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>
38 :
39 : #include <sfx2/sfxuno.hxx>
40 : #include <sfx2/ctrlitem.hxx>
41 : #include <osl/mutex.hxx>
42 :
43 : class SfxBindings;
44 : class SfxFrame;
45 : class SfxDispatcher;
46 :
47 : class SfxUnoControllerItem : public ::com::sun::star::frame::XStatusListener ,
48 : public ::com::sun::star::lang::XTypeProvider ,
49 : public ::cppu::OWeakObject
50 : {
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;
55 :
56 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > TryGetDispatch( SfxFrame* pFrame );
57 :
58 : public:
59 : SFX_DECL_XINTERFACE_XTYPEPROVIDER
60 :
61 :
62 : SfxUnoControllerItem( SfxControllerItem*, SfxBindings&, const String& );
63 : ~SfxUnoControllerItem();
64 :
65 : const ::com::sun::star::util::URL& GetCommand() const
66 : { return aCommand; }
67 :
68 : // XStatusListener
69 : virtual void SAL_CALL statusChanged(const ::com::sun::star::frame::FeatureStateEvent& Event) throw( ::com::sun::star::uno::RuntimeException );
70 :
71 : // Something else
72 : virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException );
73 : void UnBind();
74 : void GetNewDispatch();
75 : void ReleaseDispatch();
76 : void ReleaseBindings();
77 : };
78 :
79 : struct SfxStatusDispatcher_Impl_hashType
80 : {
81 : size_t operator()(const OUString& s) const
82 : { return s.hashCode(); }
83 : };
84 :
85 : typedef ::cppu::OMultiTypeInterfaceContainerHelperVar< OUString, SfxStatusDispatcher_Impl_hashType, std::equal_to< OUString > > SfxStatusDispatcher_Impl_ListenerContainer ;
86 :
87 55674 : class SfxStatusDispatcher : public ::com::sun::star::frame::XNotifyingDispatch,
88 : public ::com::sun::star::lang::XTypeProvider,
89 : public ::cppu::OWeakObject
90 : {
91 : ::osl::Mutex aMutex;
92 : SfxStatusDispatcher_Impl_ListenerContainer aListeners;
93 :
94 : public:
95 : SFX_DECL_XINTERFACE_XTYPEPROVIDER
96 :
97 : SfxStatusDispatcher();
98 :
99 : // XDispatch
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 );
106 :
107 : // Something else
108 : void ReleaseAll();
109 88286 : SfxStatusDispatcher_Impl_ListenerContainer& GetListeners()
110 88286 : { return aListeners; }
111 : };
112 :
113 : class SfxSlotServer;
114 : class SfxDispatchController_Impl;
115 : class SfxOfficeDispatch : public SfxStatusDispatcher
116 : , public ::com::sun::star::lang::XUnoTunnel
117 : {
118 : friend class SfxDispatchController_Impl;
119 : SfxDispatchController_Impl* pControllerItem;
120 : public:
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();
129 :
130 : SFX_DECL_XINTERFACE_XTYPEPROVIDER
131 :
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 );
142 :
143 : // XUnoTunnel
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();
146 :
147 : static sal_Bool IsMasterUnoCommand( const ::com::sun::star::util::URL& aURL );
148 : static OUString GetMasterUnoCommand( const ::com::sun::star::util::URL& aURL );
149 :
150 : void SetFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame);
151 :
152 : void SetMasterUnoCommand( sal_Bool bSet );
153 :
154 : SfxDispatcher* GetDispatcher_Impl();
155 : };
156 :
157 : class SfxDispatchController_Impl : public SfxControllerItem
158 : {
159 : ::com::sun::star::util::URL aDispatchURL;
160 : SfxDispatcher* pDispatcher;
161 : SfxBindings* pBindings;
162 : const SfxPoolItem* pLastState;
163 : sal_uInt16 nSlot;
164 : SfxOfficeDispatch* pDispatch;
165 : sal_Bool bMasterSlave;
166 : sal_Bool bVisible;
167 : const char* pUnoName;
168 : ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XFrame > xFrame;
169 :
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 );
173 :
174 : public:
175 : SfxDispatchController_Impl( SfxOfficeDispatch* pDisp,
176 : SfxBindings* pBind,
177 : SfxDispatcher* pDispat,
178 : const SfxSlot* pSlot,
179 : const ::com::sun::star::util::URL& rURL );
180 : ~SfxDispatchController_Impl();
181 :
182 : static OUString getSlaveCommand( const ::com::sun::star::util::URL& rURL );
183 :
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);
194 : };
195 :
196 : #endif
197 :
198 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|