1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef _SFX_UNOCTITM_HXX 24 #define _SFX_UNOCTITM_HXX 25 26 #include <functional> 27 #include <com/sun/star/frame/XNotifyingDispatch.hpp> 28 #include <com/sun/star/frame/XDispatchResultListener.hpp> 29 #include <com/sun/star/frame/XDispatchProviderInterceptor.hpp> 30 #include <com/sun/star/frame/XDispatch.hpp> 31 #include <com/sun/star/frame/XDispatchProvider.hpp> 32 #include <com/sun/star/frame/XStatusListener.hpp> 33 #include <com/sun/star/frame/FrameSearchFlag.hpp> 34 #include <com/sun/star/frame/XDispatchProviderInterception.hpp> 35 #include <com/sun/star/frame/FeatureStateEvent.hpp> 36 #include <com/sun/star/frame/DispatchDescriptor.hpp> 37 #include <com/sun/star/util/XURLTransformer.hpp> 38 #include <com/sun/star/lang/XUnoTunnel.hpp> 39 #include <com/sun/star/frame/XFrame.hpp> 40 #include <cppuhelper/weak.hxx> 41 #include <cppuhelper/interfacecontainer.hxx> 42 43 #include <sfx2/sfxuno.hxx> 44 #include <sfx2/ctrlitem.hxx> 45 #include <osl/mutex.hxx> 46 47 class SfxBindings; 48 class SfxFrame; 49 class SfxDispatcher; 50 51 class SfxUnoControllerItem : public ::com::sun::star::frame::XStatusListener , 52 public ::com::sun::star::lang::XTypeProvider , 53 public ::cppu::OWeakObject 54 { 55 ::com::sun::star::util::URL aCommand; 56 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDispatch; 57 SfxControllerItem* pCtrlItem; 58 SfxBindings* pBindings; 59 60 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > TryGetDispatch( SfxFrame* pFrame ); 61 62 public: 63 SFX_DECL_XINTERFACE_XTYPEPROVIDER 64 65 66 SfxUnoControllerItem( SfxControllerItem*, SfxBindings&, const String& ); 67 ~SfxUnoControllerItem(); 68 GetCommand() const69 const ::com::sun::star::util::URL& GetCommand() const 70 { return aCommand; } 71 void Execute(); 72 73 // XStatusListener 74 virtual void SAL_CALL statusChanged(const ::com::sun::star::frame::FeatureStateEvent& Event) throw( ::com::sun::star::uno::RuntimeException ); 75 76 // Something else 77 virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException ); 78 void UnBind(); 79 void GetNewDispatch(); 80 void ReleaseDispatch(); 81 void ReleaseBindings(); 82 }; 83 84 struct SfxStatusDispatcher_Impl_hashType 85 { operator ()SfxStatusDispatcher_Impl_hashType86 size_t operator()(const ::rtl::OUString& s) const 87 { return s.hashCode(); } 88 }; 89 90 typedef ::cppu::OMultiTypeInterfaceContainerHelperVar< ::rtl::OUString, SfxStatusDispatcher_Impl_hashType, std::equal_to< ::rtl::OUString > > SfxStatusDispatcher_Impl_ListenerContainer ; 91 92 class SfxStatusDispatcher : public ::com::sun::star::frame::XNotifyingDispatch, 93 public ::com::sun::star::lang::XTypeProvider, 94 public ::cppu::OWeakObject 95 { 96 ::osl::Mutex aMutex; 97 SfxStatusDispatcher_Impl_ListenerContainer aListeners; 98 99 public: 100 SFX_DECL_XINTERFACE_XTYPEPROVIDER 101 102 SfxStatusDispatcher(); 103 104 // XDispatch 105 virtual void SAL_CALL dispatchWithNotification( const ::com::sun::star::util::URL& aURL, 106 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs, 107 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchResultListener >& rListener ) throw( ::com::sun::star::uno::RuntimeException ); 108 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 ); 109 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 ); 110 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 ); 111 112 // Something else 113 void ReleaseAll(); GetListeners()114 SfxStatusDispatcher_Impl_ListenerContainer& GetListeners() 115 { return aListeners; } 116 }; 117 118 class SfxSlotServer; 119 class SfxDispatchController_Impl; 120 class SfxOfficeDispatch : public SfxStatusDispatcher 121 , public ::com::sun::star::lang::XUnoTunnel 122 { 123 friend class SfxDispatchController_Impl; 124 SfxDispatchController_Impl* pControllerItem; 125 public: 126 SfxOfficeDispatch( SfxBindings& rBind, 127 SfxDispatcher* pDispat, 128 const SfxSlot* pSlot, 129 const ::com::sun::star::util::URL& rURL ); 130 SfxOfficeDispatch( SfxDispatcher* pDispat, 131 const SfxSlot* pSlot, 132 const ::com::sun::star::util::URL& rURL ); 133 ~SfxOfficeDispatch(); 134 135 SFX_DECL_XINTERFACE_XTYPEPROVIDER 136 137 virtual void SAL_CALL dispatchWithNotification( const ::com::sun::star::util::URL& aURL, 138 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs, 139 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchResultListener >& rListener ) 140 throw( ::com::sun::star::uno::RuntimeException ); 141 virtual void SAL_CALL dispatch( const ::com::sun::star::util::URL& aURL, 142 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs ) 143 throw( ::com::sun::star::uno::RuntimeException ); 144 virtual void SAL_CALL addStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xControl, 145 const ::com::sun::star::util::URL& aURL) 146 throw( ::com::sun::star::uno::RuntimeException ); 147 148 // XUnoTunnel 149 virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException) ; 150 static const ::com::sun::star::uno::Sequence< sal_Int8 >& impl_getStaticIdentifier(); 151 152 static sal_Bool IsMasterUnoCommand( const ::com::sun::star::util::URL& aURL ); 153 static rtl::OUString GetMasterUnoCommand( const ::com::sun::star::util::URL& aURL ); 154 155 void SetFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame); 156 157 void SetMasterUnoCommand( sal_Bool bSet ); 158 sal_Bool IsMasterUnoCommand() const; 159 160 SfxDispatcher* GetDispatcher_Impl(); 161 }; 162 163 //#if 0 // _SOLAR__PRIVATE 164 class SfxDispatchController_Impl : public SfxControllerItem 165 { 166 ::com::sun::star::util::URL aDispatchURL; 167 SfxDispatcher* pDispatcher; 168 SfxBindings* pBindings; 169 const SfxPoolItem* pLastState; 170 sal_uInt16 nSlot; 171 SfxOfficeDispatch* pDispatch; 172 sal_Bool bMasterSlave; 173 sal_Bool bVisible; 174 const char* pUnoName; 175 ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XFrame > xFrame; 176 177 void addParametersToArgs( const com::sun::star::util::URL& aURL, 178 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rArgs ) const; 179 using SfxControllerItem::GetCoreMetric; 180 SfxMapUnit GetCoreMetric( SfxItemPool& rPool, sal_uInt16 nSlot ); 181 182 public: 183 SfxDispatchController_Impl( SfxOfficeDispatch* pDisp, 184 SfxBindings* pBind, 185 SfxDispatcher* pDispat, 186 const SfxSlot* pSlot, 187 const ::com::sun::star::util::URL& rURL ); 188 ~SfxDispatchController_Impl(); 189 190 static rtl::OUString getSlaveCommand( const ::com::sun::star::util::URL& rURL ); 191 192 void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState, SfxSlotServer* pServ ); 193 virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState ); 194 void setMasterSlaveCommand( sal_Bool bSet ); 195 sal_Bool isMasterSlaveCommand() const; 196 void SAL_CALL dispatch( const ::com::sun::star::util::URL& aURL, 197 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs, 198 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchResultListener >& rListener ) throw( ::com::sun::star::uno::RuntimeException ); 199 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 ); 200 void UnBindController(); 201 SfxDispatcher* GetDispatcher(); 202 void SetFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame); 203 }; 204 //#endif 205 206 #endif 207 208