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