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); 75 76 // Something else 77 virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source); 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 ); 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 ); 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); 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); 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 virtual void SAL_CALL dispatch( const ::com::sun::star::util::URL& aURL, 141 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs ); 142 virtual void SAL_CALL addStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xControl, 143 const ::com::sun::star::util::URL& aURL); 144 145 // XUnoTunnel 146 virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) ; 147 static const ::com::sun::star::uno::Sequence< sal_Int8 >& impl_getStaticIdentifier(); 148 149 static sal_Bool IsMasterUnoCommand( const ::com::sun::star::util::URL& aURL ); 150 static rtl::OUString GetMasterUnoCommand( const ::com::sun::star::util::URL& aURL ); 151 152 void SetFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame); 153 154 void SetMasterUnoCommand( sal_Bool bSet ); 155 sal_Bool IsMasterUnoCommand() const; 156 157 SfxDispatcher* GetDispatcher_Impl(); 158 }; 159 160 //#if 0 // _SOLAR__PRIVATE 161 class SfxDispatchController_Impl : public SfxControllerItem 162 { 163 ::com::sun::star::util::URL aDispatchURL; 164 SfxDispatcher* pDispatcher; 165 SfxBindings* pBindings; 166 const SfxPoolItem* pLastState; 167 sal_uInt16 nSlot; 168 SfxOfficeDispatch* pDispatch; 169 sal_Bool bMasterSlave; 170 sal_Bool bVisible; 171 const char* pUnoName; 172 ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XFrame > xFrame; 173 174 void addParametersToArgs( const com::sun::star::util::URL& aURL, 175 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rArgs ) const; 176 using SfxControllerItem::GetCoreMetric; 177 SfxMapUnit GetCoreMetric( SfxItemPool& rPool, sal_uInt16 nSlot ); 178 179 public: 180 SfxDispatchController_Impl( SfxOfficeDispatch* pDisp, 181 SfxBindings* pBind, 182 SfxDispatcher* pDispat, 183 const SfxSlot* pSlot, 184 const ::com::sun::star::util::URL& rURL ); 185 ~SfxDispatchController_Impl(); 186 187 static rtl::OUString getSlaveCommand( const ::com::sun::star::util::URL& rURL ); 188 189 void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState, SfxSlotServer* pServ ); 190 virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState ); 191 void setMasterSlaveCommand( sal_Bool bSet ); 192 sal_Bool isMasterSlaveCommand() const; 193 void SAL_CALL dispatch( const ::com::sun::star::util::URL& aURL, 194 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs, 195 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchResultListener >& rListener ); 196 void SAL_CALL addStatusListener(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > & xControl, const ::com::sun::star::util::URL& aURL); 197 void UnBindController(); 198 SfxDispatcher* GetDispatcher(); 199 void SetFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame); 200 }; 201 //#endif 202 203 #endif 204