bump product version to 5.0.4.1
[LibreOffice.git] / sfx2 / source / inc / statcach.hxx
blob88867861a3baf33fc402dcc2246adec4e83b2bc2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SFX2_SOURCE_INC_STATCACH_HXX
20 #define INCLUDED_SFX2_SOURCE_INC_STATCACH_HXX
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>
33 #include <sfx2/bindings.hxx>
35 #include "slotserv.hxx"
37 class SfxControllerItem;
38 class SfxDispatcher;
39 class BindDispatch_Impl : public ::cppu::WeakImplHelper1< css::frame::XStatusListener >
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;
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 );
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;
57 void Release();
58 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 );
62 class SfxStateCache
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
78 private:
79 SfxStateCache( const SfxStateCache& rOrig ) SAL_DELETED_FUNCTION;
80 void SetState_Impl( SfxItemState, const SfxPoolItem*, bool bMaybeDirty=false );
82 public:
83 SfxStateCache( sal_uInt16 nFuncId );
84 ~SfxStateCache();
86 sal_uInt16 GetId() const;
88 const SfxSlotServer* GetSlotServer( SfxDispatcher &rDispat, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > & xProv );
89 const SfxSlotServer* GetSlotServer( SfxDispatcher &rDispat )
90 { 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 bool IsControllerDirty() const
94 { return bCtrlDirty; }
95 SfxPoolItem* GetItem() const { return pLastItem; }
96 void ClearCache();
98 void SetState( SfxItemState, const SfxPoolItem*, bool bMaybeDirty=false );
99 void SetCachedState(bool bAlways = false);
100 void Invalidate( bool bWithSlot );
101 void SetVisibleState( bool bShow=true );
103 SfxControllerItem* ChangeItemLink( SfxControllerItem* pNewBinding );
104 SfxControllerItem* GetItemLink() const;
105 void SetInternalController( SfxControllerItem* pCtrl )
106 { DBG_ASSERT( !pInternalController, "Only one internal controller allowed!" ); pInternalController = pCtrl; }
107 void ReleaseInternalController() { pInternalController = 0; }
108 SfxControllerItem* GetInternalController() const { return pInternalController; }
109 com::sun::star::uno::Reference < com::sun::star::frame::XDispatch >
110 GetInternalDispatch() const
111 { return xMyDispatch; }
112 void SetInternalDispatch( const com::sun::star::uno::Reference < com::sun::star::frame::XDispatch >& rDisp )
113 { xMyDispatch = rDisp; }
118 // clears Cached-Item
120 inline void SfxStateCache::ClearCache()
122 bItemDirty = true;
127 // registeres a item representing this function
129 inline SfxControllerItem* SfxStateCache::ChangeItemLink( SfxControllerItem* pNewBinding )
131 SfxControllerItem* pOldBinding = pController;
132 pController = pNewBinding;
133 if ( pNewBinding )
135 bCtrlDirty = true;
136 bItemDirty = true;
138 return pOldBinding;
142 // returns the func binding which becomes called on spreading states
144 inline SfxControllerItem* SfxStateCache::GetItemLink() const
146 return pController;
150 inline sal_uInt16 SfxStateCache::GetId() const
152 return nId;
155 #endif
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */