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