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