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