Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #ifndef INCLUDED_SFX2_SOURCE_INC_STATCACH_HXX
20 : #define INCLUDED_SFX2_SOURCE_INC_STATCACH_HXX
21 :
22 : #include <com/sun/star/frame/XDispatchProviderInterceptor.hpp>
23 : #include <com/sun/star/frame/XDispatch.hpp>
24 : #include <com/sun/star/frame/XDispatchProvider.hpp>
25 : #include <com/sun/star/frame/XStatusListener.hpp>
26 : #include <com/sun/star/frame/FrameSearchFlag.hpp>
27 : #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
28 : #include <com/sun/star/frame/FeatureStateEvent.hpp>
29 : #include <com/sun/star/frame/DispatchDescriptor.hpp>
30 : #include <com/sun/star/beans/PropertyValue.hpp>
31 : #include <cppuhelper/implbase1.hxx>
32 :
33 : #include <sfx2/bindings.hxx>
34 :
35 : #include "slotserv.hxx"
36 :
37 : class SfxControllerItem;
38 : class SfxDispatcher;
39 0 : class BindDispatch_Impl : public ::cppu::WeakImplHelper1< css::frame::XStatusListener >
40 : {
41 : friend class SfxStateCache;
42 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDisp;
43 : ::com::sun::star::util::URL aURL;
44 : ::com::sun::star::frame::FeatureStateEvent aStatus;
45 : SfxStateCache* pCache;
46 : const SfxSlot* pSlot;
47 :
48 : public:
49 : BindDispatch_Impl(
50 : const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > & rDisp,
51 : const ::com::sun::star::util::URL& rURL,
52 : SfxStateCache* pStateCache, const SfxSlot* pSlot );
53 :
54 : virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
55 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
56 :
57 : void Release();
58 0 : const ::com::sun::star::frame::FeatureStateEvent& GetStatus() const { return aStatus;}
59 : void Dispatch( const com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue >& aProps, bool bForceSynchron = false );
60 : };
61 :
62 : class SfxStateCache
63 : {
64 : friend class BindDispatch_Impl;
65 : BindDispatch_Impl* pDispatch;
66 : sal_uInt16 nId; // Slot-Id
67 : SfxControllerItem* pInternalController;
68 : com::sun::star::uno::Reference < com::sun::star::frame::XDispatch > xMyDispatch;
69 : SfxControllerItem* pController; // Pointer to first bound Controller (interlinked with each other)
70 : SfxSlotServer aSlotServ; // SlotServer, SlotPtr = 0 -> not on Stack
71 : SfxPoolItem* pLastItem; // Last sent Item, never -1
72 : SfxItemState eLastState; // Last sent State
73 : bool bCtrlDirty:1; // Update Controller?
74 : bool bSlotDirty:1; // Present Funktion, must be updated
75 : bool bItemVisible:1; // item visibility
76 : bool bItemDirty; // Validity of pLastItem
77 :
78 : private:
79 : SfxStateCache( const SfxStateCache& rOrig ); // inward
80 : void SetState_Impl( SfxItemState, const SfxPoolItem*, bool bMaybeDirty=false );
81 :
82 : public:
83 : SfxStateCache( sal_uInt16 nFuncId );
84 : ~SfxStateCache();
85 :
86 : sal_uInt16 GetId() const;
87 :
88 : const SfxSlotServer* GetSlotServer( SfxDispatcher &rDispat, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > & xProv );
89 2956 : const SfxSlotServer* GetSlotServer( SfxDispatcher &rDispat )
90 2956 : { return GetSlotServer( rDispat, ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > () ); }
91 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > GetDispatch() const;
92 : void Dispatch( const SfxItemSet* pSet, bool bForceSynchron = false );
93 104433 : bool IsControllerDirty() const
94 104433 : { return bCtrlDirty ? sal_True : sal_False; }
95 : SfxPoolItem* GetItem() const { return pLastItem; }
96 : void ClearCache();
97 :
98 : void SetState( SfxItemState, const SfxPoolItem*, bool bMaybeDirty=false );
99 : void SetCachedState(bool bAlways = false);
100 : void DeleteFloatingWindows();
101 : void Invalidate( bool bWithSlot );
102 : void SetVisibleState( bool bShow=true );
103 :
104 : SfxControllerItem* ChangeItemLink( SfxControllerItem* pNewBinding );
105 : SfxControllerItem* GetItemLink() const;
106 130227 : void SetInternalController( SfxControllerItem* pCtrl )
107 130227 : { DBG_ASSERT( !pInternalController, "Only one internal controller allowed!" ); pInternalController = pCtrl; }
108 130227 : void ReleaseInternalController() { pInternalController = 0; }
109 1032692 : SfxControllerItem* GetInternalController() const { return pInternalController; }
110 : com::sun::star::uno::Reference < com::sun::star::frame::XDispatch >
111 203306 : GetInternalDispatch() const
112 203306 : { return xMyDispatch; }
113 130227 : void SetInternalDispatch( const com::sun::star::uno::Reference < com::sun::star::frame::XDispatch >& rDisp )
114 130227 : { xMyDispatch = rDisp; }
115 : };
116 :
117 :
118 :
119 : // clears Cached-Item
120 :
121 18 : inline void SfxStateCache::ClearCache()
122 : {
123 18 : bItemDirty = true;
124 18 : }
125 :
126 :
127 :
128 : // registeres a item representing this function
129 :
130 390040 : inline SfxControllerItem* SfxStateCache::ChangeItemLink( SfxControllerItem* pNewBinding )
131 : {
132 390040 : SfxControllerItem* pOldBinding = pController;
133 390040 : pController = pNewBinding;
134 390040 : if ( pNewBinding )
135 : {
136 232646 : bCtrlDirty = true;
137 232646 : bItemDirty = true;
138 : }
139 390040 : return pOldBinding;
140 : }
141 :
142 :
143 : // returns the func binding which becomes called on spreading states
144 :
145 824464 : inline SfxControllerItem* SfxStateCache::GetItemLink() const
146 : {
147 824464 : return pController;
148 : }
149 :
150 :
151 9322370 : inline sal_uInt16 SfxStateCache::GetId() const
152 : {
153 9322370 : return nId;
154 : }
155 :
156 : #endif
157 :
158 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|