1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #ifndef _SFXSTATCACH_HXX 28 #define _SFXSTATCACH_HXX 29 30 #include <com/sun/star/frame/XDispatchProviderInterceptor.hpp> 31 #include <com/sun/star/frame/XDispatch.hpp> 32 #include <com/sun/star/frame/XDispatchProvider.hpp> 33 #include <com/sun/star/frame/XStatusListener.hpp> 34 #include <com/sun/star/frame/FrameSearchFlag.hpp> 35 #include <com/sun/star/frame/XDispatchProviderInterception.hpp> 36 #include <com/sun/star/frame/FeatureStateEvent.hpp> 37 #include <com/sun/star/frame/DispatchDescriptor.hpp> 38 #include <com/sun/star/beans/PropertyValue.hpp> 39 #include <cppuhelper/weak.hxx> 40 41 #ifndef _SFXBINDINGS_HXX 42 #include <sfx2/bindings.hxx> 43 #endif 44 45 #ifndef _SFXMSGSERV_HXX 46 #include "slotserv.hxx" 47 #endif 48 49 #include <sfx2/sfxuno.hxx> 50 51 class SfxControllerItem; 52 class SfxDispatcher; 53 class BindDispatch_Impl : public ::com::sun::star::frame::XStatusListener , 54 public ::com::sun::star::lang::XTypeProvider , 55 public ::cppu::OWeakObject 56 { 57 friend class SfxStateCache; 58 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDisp; 59 ::com::sun::star::util::URL aURL; 60 ::com::sun::star::frame::FeatureStateEvent aStatus; 61 SfxStateCache* pCache; 62 const SfxSlot* pSlot; 63 64 public: 65 BindDispatch_Impl( 66 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > & rDisp, 67 const ::com::sun::star::util::URL& rURL, 68 SfxStateCache* pStateCache, const SfxSlot* pSlot ); 69 70 SFX_DECL_XINTERFACE_XTYPEPROVIDER 71 72 virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException ); 73 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw ( ::com::sun::star::uno::RuntimeException ); 74 75 void Release(); 76 const ::com::sun::star::frame::FeatureStateEvent& GetStatus() const; 77 void Dispatch( com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > aProps, sal_Bool bForceSynchron = sal_False ); 78 }; 79 80 class SfxStateCache 81 { 82 friend class BindDispatch_Impl; 83 BindDispatch_Impl* pDispatch; 84 sal_uInt16 nId; // Slot-Id 85 SfxControllerItem* pInternalController; 86 com::sun::star::uno::Reference < com::sun::star::frame::XDispatch > xMyDispatch; 87 SfxControllerItem* pController; // Ptr auf 1. gebundenen Controller (untereinander verkettet) 88 SfxSlotServer aSlotServ; // SlotServer, SlotPtr = 0 -> Nicht auf Stack 89 SfxPoolItem* pLastItem; // zuletzt verschicktes Item, nie -1 90 SfxItemState eLastState; // zuletzt verschickter State 91 sal_Bool bCtrlDirty:1; // Controller aktualisiert? 92 sal_Bool bSlotDirty:1; // Funktion gfs. vorhanden, muss aktualisiert werden 93 sal_Bool bItemVisible:1;// item visibility 94 sal_Bool bItemDirty; // G"ultigkeit von pLastItem 95 96 private: 97 SfxStateCache( const SfxStateCache& rOrig ); // n.i. 98 void SetState_Impl( SfxItemState, const SfxPoolItem*, sal_Bool bMaybeDirty=sal_False ); 99 100 public: 101 SfxStateCache( sal_uInt16 nFuncId ); 102 ~SfxStateCache(); 103 104 sal_uInt16 GetId() const; 105 106 const SfxSlotServer* GetSlotServer( SfxDispatcher &rDispat, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > & xProv ); 107 const SfxSlotServer* GetSlotServer( SfxDispatcher &rDispat ) 108 { return GetSlotServer( rDispat, ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > () ); } 109 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > GetDispatch() const; 110 void Dispatch( const SfxItemSet* pSet, sal_Bool bForceSynchron = sal_False ); 111 sal_Bool IsControllerDirty() const 112 { return bCtrlDirty ? sal_True : sal_False; } 113 SfxPoolItem* GetItem() const { return pLastItem; } 114 void ClearCache(); 115 116 void SetState( SfxItemState, const SfxPoolItem*, sal_Bool bMaybeDirty=sal_False ); 117 void SetCachedState(sal_Bool bAlways = sal_False); 118 void DeleteFloatingWindows(); 119 void Invalidate( sal_Bool bWithSlot ); 120 void SetVisibleState( sal_Bool bShow=sal_True ); 121 122 SfxControllerItem* ChangeItemLink( SfxControllerItem* pNewBinding ); 123 SfxControllerItem* GetItemLink() const; 124 void SetInternalController( SfxControllerItem* pCtrl ) 125 { DBG_ASSERT( !pInternalController, "Only one internal controller allowed!" ); pInternalController = pCtrl; } 126 void ReleaseInternalController() { pInternalController = 0; } 127 SfxControllerItem* GetInternalController() const { return pInternalController; } 128 com::sun::star::uno::Reference < com::sun::star::frame::XDispatch > 129 GetInternalDispatch() const 130 { return xMyDispatch; } 131 void SetInternalDispatch( const com::sun::star::uno::Reference < com::sun::star::frame::XDispatch >& rDisp ) 132 { xMyDispatch = rDisp; } 133 }; 134 135 //-------------------------------------------------------------------- 136 137 // checks wheather this function is in the stack of active SfxObjectInterface 138 139 //inline sal_Bool SfxStateCache::IsCallable( SfxDispatcher &rDispat ) 140 //{ 141 // return GetSlotServer(rDispat) != 0; 142 //} 143 //-------------------------------------------------------------------- 144 145 // clears Cached-Item 146 147 inline void SfxStateCache::ClearCache() 148 { 149 bItemDirty = sal_True; 150 } 151 152 //-------------------------------------------------------------------- 153 154 // registeres a item representing this function 155 156 inline SfxControllerItem* SfxStateCache::ChangeItemLink( SfxControllerItem* pNewBinding ) 157 { 158 SfxControllerItem* pOldBinding = pController; 159 pController = pNewBinding; 160 if ( pNewBinding ) 161 { 162 bCtrlDirty = sal_True; 163 bItemDirty = sal_True; 164 } 165 return pOldBinding; 166 } 167 //-------------------------------------------------------------------- 168 169 // returns the func binding which becomes called on spreading states 170 171 inline SfxControllerItem* SfxStateCache::GetItemLink() const 172 { 173 return pController; 174 } 175 //-------------------------------------------------------------------- 176 177 inline sal_uInt16 SfxStateCache::GetId() const 178 { 179 return nId; 180 } 181 182 #endif 183