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 _SFXSTATCACH_HXX 24 #define _SFXSTATCACH_HXX 25 26 #include <com/sun/star/frame/XDispatchProviderInterceptor.hpp> 27 #include <com/sun/star/frame/XDispatch.hpp> 28 #include <com/sun/star/frame/XDispatchProvider.hpp> 29 #include <com/sun/star/frame/XStatusListener.hpp> 30 #include <com/sun/star/frame/FrameSearchFlag.hpp> 31 #include <com/sun/star/frame/XDispatchProviderInterception.hpp> 32 #include <com/sun/star/frame/FeatureStateEvent.hpp> 33 #include <com/sun/star/frame/DispatchDescriptor.hpp> 34 #include <com/sun/star/beans/PropertyValue.hpp> 35 #include <cppuhelper/weak.hxx> 36 37 #ifndef _SFXBINDINGS_HXX 38 #include <sfx2/bindings.hxx> 39 #endif 40 41 #ifndef _SFXMSGSERV_HXX 42 #include "slotserv.hxx" 43 #endif 44 45 #include <sfx2/sfxuno.hxx> 46 47 class SfxControllerItem; 48 class SfxDispatcher; 49 class BindDispatch_Impl : public ::com::sun::star::frame::XStatusListener , 50 public ::com::sun::star::lang::XTypeProvider , 51 public ::cppu::OWeakObject 52 { 53 friend class SfxStateCache; 54 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDisp; 55 ::com::sun::star::util::URL aURL; 56 ::com::sun::star::frame::FeatureStateEvent aStatus; 57 SfxStateCache* pCache; 58 const SfxSlot* pSlot; 59 60 public: 61 BindDispatch_Impl( 62 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > & rDisp, 63 const ::com::sun::star::util::URL& rURL, 64 SfxStateCache* pStateCache, const SfxSlot* pSlot ); 65 66 SFX_DECL_XINTERFACE_XTYPEPROVIDER 67 68 virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException ); 69 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw ( ::com::sun::star::uno::RuntimeException ); 70 71 void Release(); 72 const ::com::sun::star::frame::FeatureStateEvent& GetStatus() const; 73 void Dispatch( com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > aProps, sal_Bool bForceSynchron = sal_False ); 74 }; 75 76 class SfxStateCache 77 { 78 friend class BindDispatch_Impl; 79 BindDispatch_Impl* pDispatch; 80 sal_uInt16 nId; // Slot-Id 81 SfxControllerItem* pInternalController; 82 com::sun::star::uno::Reference < com::sun::star::frame::XDispatch > xMyDispatch; 83 SfxControllerItem* pController; // Ptr auf 1. gebundenen Controller (untereinander verkettet) 84 SfxSlotServer aSlotServ; // SlotServer, SlotPtr = 0 -> Nicht auf Stack 85 SfxPoolItem* pLastItem; // zuletzt verschicktes Item, nie -1 86 SfxItemState eLastState; // zuletzt verschickter State 87 sal_Bool bCtrlDirty:1; // Controller aktualisiert? 88 sal_Bool bSlotDirty:1; // Funktion gfs. vorhanden, muss aktualisiert werden 89 sal_Bool bItemVisible:1;// item visibility 90 sal_Bool bItemDirty; // G"ultigkeit von pLastItem 91 92 private: 93 SfxStateCache( const SfxStateCache& rOrig ); // n.i. 94 void SetState_Impl( SfxItemState, const SfxPoolItem*, sal_Bool bMaybeDirty=sal_False ); 95 96 public: 97 SfxStateCache( sal_uInt16 nFuncId ); 98 ~SfxStateCache(); 99 100 sal_uInt16 GetId() const; 101 102 const SfxSlotServer* GetSlotServer( SfxDispatcher &rDispat, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > & xProv ); 103 const SfxSlotServer* GetSlotServer( SfxDispatcher &rDispat ) 104 { return GetSlotServer( rDispat, ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > () ); } 105 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > GetDispatch() const; 106 void Dispatch( const SfxItemSet* pSet, sal_Bool bForceSynchron = sal_False ); 107 sal_Bool IsControllerDirty() const 108 { return bCtrlDirty ? sal_True : sal_False; } 109 SfxPoolItem* GetItem() const { return pLastItem; } 110 void ClearCache(); 111 112 void SetState( SfxItemState, const SfxPoolItem*, sal_Bool bMaybeDirty=sal_False ); 113 void SetCachedState(sal_Bool bAlways = sal_False); 114 void DeleteFloatingWindows(); 115 void Invalidate( sal_Bool bWithSlot ); 116 void SetVisibleState( sal_Bool bShow=sal_True ); 117 118 SfxControllerItem* ChangeItemLink( SfxControllerItem* pNewBinding ); 119 SfxControllerItem* GetItemLink() const; 120 void SetInternalController( SfxControllerItem* pCtrl ) 121 { DBG_ASSERT( !pInternalController, "Only one internal controller allowed!" ); pInternalController = pCtrl; } 122 void ReleaseInternalController() { pInternalController = 0; } 123 SfxControllerItem* GetInternalController() const { return pInternalController; } 124 com::sun::star::uno::Reference < com::sun::star::frame::XDispatch > 125 GetInternalDispatch() const 126 { return xMyDispatch; } 127 void SetInternalDispatch( const com::sun::star::uno::Reference < com::sun::star::frame::XDispatch >& rDisp ) 128 { xMyDispatch = rDisp; } 129 }; 130 131 //-------------------------------------------------------------------- 132 133 // checks wheather this function is in the stack of active SfxObjectInterface 134 135 //inline sal_Bool SfxStateCache::IsCallable( SfxDispatcher &rDispat ) 136 //{ 137 // return GetSlotServer(rDispat) != 0; 138 //} 139 //-------------------------------------------------------------------- 140 141 // clears Cached-Item 142 143 inline void SfxStateCache::ClearCache() 144 { 145 bItemDirty = sal_True; 146 } 147 148 //-------------------------------------------------------------------- 149 150 // registeres a item representing this function 151 152 inline SfxControllerItem* SfxStateCache::ChangeItemLink( SfxControllerItem* pNewBinding ) 153 { 154 SfxControllerItem* pOldBinding = pController; 155 pController = pNewBinding; 156 if ( pNewBinding ) 157 { 158 bCtrlDirty = sal_True; 159 bItemDirty = sal_True; 160 } 161 return pOldBinding; 162 } 163 //-------------------------------------------------------------------- 164 165 // returns the func binding which becomes called on spreading states 166 167 inline SfxControllerItem* SfxStateCache::GetItemLink() const 168 { 169 return pController; 170 } 171 //-------------------------------------------------------------------- 172 173 inline sal_uInt16 SfxStateCache::GetId() const 174 { 175 return nId; 176 } 177 178 #endif 179