1*353d8f4dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*353d8f4dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*353d8f4dSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*353d8f4dSAndrew Rist * distributed with this work for additional information
6*353d8f4dSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*353d8f4dSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*353d8f4dSAndrew Rist * "License"); you may not use this file except in compliance
9*353d8f4dSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*353d8f4dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*353d8f4dSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*353d8f4dSAndrew Rist * software distributed under the License is distributed on an
15*353d8f4dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*353d8f4dSAndrew Rist * KIND, either express or implied. See the License for the
17*353d8f4dSAndrew Rist * specific language governing permissions and limitations
18*353d8f4dSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*353d8f4dSAndrew Rist *************************************************************/
21*353d8f4dSAndrew Rist
22*353d8f4dSAndrew Rist
23cdf0e10cSrcweir #ifndef _SFXSTATCACH_HXX
24cdf0e10cSrcweir #define _SFXSTATCACH_HXX
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProviderInterceptor.hpp>
27cdf0e10cSrcweir #include <com/sun/star/frame/XDispatch.hpp>
28cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp>
29cdf0e10cSrcweir #include <com/sun/star/frame/XStatusListener.hpp>
30cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp>
31cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
32cdf0e10cSrcweir #include <com/sun/star/frame/FeatureStateEvent.hpp>
33cdf0e10cSrcweir #include <com/sun/star/frame/DispatchDescriptor.hpp>
34cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
35cdf0e10cSrcweir #include <cppuhelper/weak.hxx>
36cdf0e10cSrcweir
37cdf0e10cSrcweir #ifndef _SFXBINDINGS_HXX
38cdf0e10cSrcweir #include <sfx2/bindings.hxx>
39cdf0e10cSrcweir #endif
40cdf0e10cSrcweir
41cdf0e10cSrcweir #ifndef _SFXMSGSERV_HXX
42cdf0e10cSrcweir #include "slotserv.hxx"
43cdf0e10cSrcweir #endif
44cdf0e10cSrcweir
45cdf0e10cSrcweir #include <sfx2/sfxuno.hxx>
46cdf0e10cSrcweir
47cdf0e10cSrcweir class SfxControllerItem;
48cdf0e10cSrcweir class SfxDispatcher;
49cdf0e10cSrcweir class BindDispatch_Impl : public ::com::sun::star::frame::XStatusListener ,
50cdf0e10cSrcweir public ::com::sun::star::lang::XTypeProvider ,
51cdf0e10cSrcweir public ::cppu::OWeakObject
52cdf0e10cSrcweir {
53cdf0e10cSrcweir friend class SfxStateCache;
54cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDisp;
55cdf0e10cSrcweir ::com::sun::star::util::URL aURL;
56cdf0e10cSrcweir ::com::sun::star::frame::FeatureStateEvent aStatus;
57cdf0e10cSrcweir SfxStateCache* pCache;
58cdf0e10cSrcweir const SfxSlot* pSlot;
59cdf0e10cSrcweir
60cdf0e10cSrcweir public:
61cdf0e10cSrcweir BindDispatch_Impl(
62cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > & rDisp,
63cdf0e10cSrcweir const ::com::sun::star::util::URL& rURL,
64cdf0e10cSrcweir SfxStateCache* pStateCache, const SfxSlot* pSlot );
65cdf0e10cSrcweir
66cdf0e10cSrcweir SFX_DECL_XINTERFACE_XTYPEPROVIDER
67cdf0e10cSrcweir
68cdf0e10cSrcweir virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException );
69cdf0e10cSrcweir virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw ( ::com::sun::star::uno::RuntimeException );
70cdf0e10cSrcweir
71cdf0e10cSrcweir void Release();
72cdf0e10cSrcweir const ::com::sun::star::frame::FeatureStateEvent& GetStatus() const;
73cdf0e10cSrcweir void Dispatch( com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > aProps, sal_Bool bForceSynchron = sal_False );
74cdf0e10cSrcweir };
75cdf0e10cSrcweir
76cdf0e10cSrcweir class SfxStateCache
77cdf0e10cSrcweir {
78cdf0e10cSrcweir friend class BindDispatch_Impl;
79cdf0e10cSrcweir BindDispatch_Impl* pDispatch;
80cdf0e10cSrcweir sal_uInt16 nId; // Slot-Id
81cdf0e10cSrcweir SfxControllerItem* pInternalController;
82cdf0e10cSrcweir com::sun::star::uno::Reference < com::sun::star::frame::XDispatch > xMyDispatch;
83cdf0e10cSrcweir SfxControllerItem* pController; // Ptr auf 1. gebundenen Controller (untereinander verkettet)
84cdf0e10cSrcweir SfxSlotServer aSlotServ; // SlotServer, SlotPtr = 0 -> Nicht auf Stack
85cdf0e10cSrcweir SfxPoolItem* pLastItem; // zuletzt verschicktes Item, nie -1
86cdf0e10cSrcweir SfxItemState eLastState; // zuletzt verschickter State
87cdf0e10cSrcweir sal_Bool bCtrlDirty:1; // Controller aktualisiert?
88cdf0e10cSrcweir sal_Bool bSlotDirty:1; // Funktion gfs. vorhanden, muss aktualisiert werden
89cdf0e10cSrcweir sal_Bool bItemVisible:1;// item visibility
90cdf0e10cSrcweir sal_Bool bItemDirty; // G"ultigkeit von pLastItem
91cdf0e10cSrcweir
92cdf0e10cSrcweir private:
93cdf0e10cSrcweir SfxStateCache( const SfxStateCache& rOrig ); // n.i.
94cdf0e10cSrcweir void SetState_Impl( SfxItemState, const SfxPoolItem*, sal_Bool bMaybeDirty=sal_False );
95cdf0e10cSrcweir
96cdf0e10cSrcweir public:
97cdf0e10cSrcweir SfxStateCache( sal_uInt16 nFuncId );
98cdf0e10cSrcweir ~SfxStateCache();
99cdf0e10cSrcweir
100cdf0e10cSrcweir sal_uInt16 GetId() const;
101cdf0e10cSrcweir
102cdf0e10cSrcweir const SfxSlotServer* GetSlotServer( SfxDispatcher &rDispat, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > & xProv );
GetSlotServer(SfxDispatcher & rDispat)103cdf0e10cSrcweir const SfxSlotServer* GetSlotServer( SfxDispatcher &rDispat )
104cdf0e10cSrcweir { return GetSlotServer( rDispat, ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > () ); }
105cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > GetDispatch() const;
106cdf0e10cSrcweir void Dispatch( const SfxItemSet* pSet, sal_Bool bForceSynchron = sal_False );
IsControllerDirty() const107cdf0e10cSrcweir sal_Bool IsControllerDirty() const
108cdf0e10cSrcweir { return bCtrlDirty ? sal_True : sal_False; }
GetItem() const109cdf0e10cSrcweir SfxPoolItem* GetItem() const { return pLastItem; }
110cdf0e10cSrcweir void ClearCache();
111cdf0e10cSrcweir
112cdf0e10cSrcweir void SetState( SfxItemState, const SfxPoolItem*, sal_Bool bMaybeDirty=sal_False );
113cdf0e10cSrcweir void SetCachedState(sal_Bool bAlways = sal_False);
114cdf0e10cSrcweir void DeleteFloatingWindows();
115cdf0e10cSrcweir void Invalidate( sal_Bool bWithSlot );
116cdf0e10cSrcweir void SetVisibleState( sal_Bool bShow=sal_True );
117cdf0e10cSrcweir
118cdf0e10cSrcweir SfxControllerItem* ChangeItemLink( SfxControllerItem* pNewBinding );
119cdf0e10cSrcweir SfxControllerItem* GetItemLink() const;
SetInternalController(SfxControllerItem * pCtrl)120cdf0e10cSrcweir void SetInternalController( SfxControllerItem* pCtrl )
121cdf0e10cSrcweir { DBG_ASSERT( !pInternalController, "Only one internal controller allowed!" ); pInternalController = pCtrl; }
ReleaseInternalController()122cdf0e10cSrcweir void ReleaseInternalController() { pInternalController = 0; }
GetInternalController() const123cdf0e10cSrcweir SfxControllerItem* GetInternalController() const { return pInternalController; }
124cdf0e10cSrcweir com::sun::star::uno::Reference < com::sun::star::frame::XDispatch >
GetInternalDispatch() const125cdf0e10cSrcweir GetInternalDispatch() const
126cdf0e10cSrcweir { return xMyDispatch; }
SetInternalDispatch(const com::sun::star::uno::Reference<com::sun::star::frame::XDispatch> & rDisp)127cdf0e10cSrcweir void SetInternalDispatch( const com::sun::star::uno::Reference < com::sun::star::frame::XDispatch >& rDisp )
128cdf0e10cSrcweir { xMyDispatch = rDisp; }
129cdf0e10cSrcweir };
130cdf0e10cSrcweir
131cdf0e10cSrcweir //--------------------------------------------------------------------
132cdf0e10cSrcweir
133cdf0e10cSrcweir // checks wheather this function is in the stack of active SfxObjectInterface
134cdf0e10cSrcweir
135cdf0e10cSrcweir //inline sal_Bool SfxStateCache::IsCallable( SfxDispatcher &rDispat )
136cdf0e10cSrcweir //{
137cdf0e10cSrcweir // return GetSlotServer(rDispat) != 0;
138cdf0e10cSrcweir //}
139cdf0e10cSrcweir //--------------------------------------------------------------------
140cdf0e10cSrcweir
141cdf0e10cSrcweir // clears Cached-Item
142cdf0e10cSrcweir
ClearCache()143cdf0e10cSrcweir inline void SfxStateCache::ClearCache()
144cdf0e10cSrcweir {
145cdf0e10cSrcweir bItemDirty = sal_True;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir
148cdf0e10cSrcweir //--------------------------------------------------------------------
149cdf0e10cSrcweir
150cdf0e10cSrcweir // registeres a item representing this function
151cdf0e10cSrcweir
ChangeItemLink(SfxControllerItem * pNewBinding)152cdf0e10cSrcweir inline SfxControllerItem* SfxStateCache::ChangeItemLink( SfxControllerItem* pNewBinding )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir SfxControllerItem* pOldBinding = pController;
155cdf0e10cSrcweir pController = pNewBinding;
156cdf0e10cSrcweir if ( pNewBinding )
157cdf0e10cSrcweir {
158cdf0e10cSrcweir bCtrlDirty = sal_True;
159cdf0e10cSrcweir bItemDirty = sal_True;
160cdf0e10cSrcweir }
161cdf0e10cSrcweir return pOldBinding;
162cdf0e10cSrcweir }
163cdf0e10cSrcweir //--------------------------------------------------------------------
164cdf0e10cSrcweir
165cdf0e10cSrcweir // returns the func binding which becomes called on spreading states
166cdf0e10cSrcweir
GetItemLink() const167cdf0e10cSrcweir inline SfxControllerItem* SfxStateCache::GetItemLink() const
168cdf0e10cSrcweir {
169cdf0e10cSrcweir return pController;
170cdf0e10cSrcweir }
171cdf0e10cSrcweir //--------------------------------------------------------------------
172cdf0e10cSrcweir
GetId() const173cdf0e10cSrcweir inline sal_uInt16 SfxStateCache::GetId() const
174cdf0e10cSrcweir {
175cdf0e10cSrcweir return nId;
176cdf0e10cSrcweir }
177cdf0e10cSrcweir
178cdf0e10cSrcweir #endif
179