1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/XDispatch.hpp>
23 #include <com/sun/star/frame/XDispatchProvider.hpp>
24 #include <com/sun/star/frame/XStatusListener.hpp>
25 #include <com/sun/star/frame/FeatureStateEvent.hpp>
26 #include <com/sun/star/beans/PropertyValue.hpp>
27 #include <cppuhelper/implbase.hxx>
28 #include <tools/debug.hxx>
29 #include <rtl/ref.hxx>
31 #include <sfx2/bindings.hxx>
33 #include "slotserv.hxx"
35 class SfxControllerItem
;
37 class BindDispatch_Impl final
: public ::cppu::WeakImplHelper
< css::frame::XStatusListener
>
39 friend class SfxStateCache
;
40 css::uno::Reference
< css::frame::XDispatch
> xDisp
;
42 css::frame::FeatureStateEvent aStatus
;
43 SfxStateCache
* pCache
;
48 css::uno::Reference
< css::frame::XDispatch
> xDisp
,
50 SfxStateCache
* pStateCache
, const SfxSlot
* pSlot
);
52 virtual void SAL_CALL
statusChanged( const css::frame::FeatureStateEvent
& Event
) override
;
53 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
55 const css::frame::FeatureStateEvent
& GetStatus() const { return aStatus
;}
56 sal_Int16
Dispatch( const css::uno::Sequence
< css::beans::PropertyValue
>& aProps
, bool bForceSynchron
);
62 friend class BindDispatch_Impl
;
63 rtl::Reference
<BindDispatch_Impl
>
65 sal_uInt16 nId
; // Slot-Id
66 SfxControllerItem
* pInternalController
;
67 css::uno::Reference
< css::frame::XDispatch
> xMyDispatch
;
68 SfxControllerItem
* pController
; // Pointer to first bound Controller (interlinked with each other)
69 SfxSlotServer aSlotServ
; // SlotServer, SlotPtr = 0 -> not on Stack
70 const SfxPoolItem
* pLastItem
; // Last sent Item, never -1
71 SfxItemState eLastState
; // Last sent State
72 bool bCtrlDirty
:1; // Update Controller?
73 bool bSlotDirty
:1; // Present Function, must be updated
74 bool bItemVisible
:1; // item visibility
75 bool bItemDirty
; // Validity of pLastItem
78 SfxStateCache( const SfxStateCache
& rOrig
) = delete;
79 void SetState_Impl( SfxItemState
, const SfxPoolItem
*, bool bMaybeDirty
);
82 SfxStateCache( sal_uInt16 nFuncId
);
85 sal_uInt16
GetId() const;
87 const SfxSlotServer
* GetSlotServer( SfxDispatcher
&rDispat
, const css::uno::Reference
< css::frame::XDispatchProvider
> & xProv
);
88 const SfxSlotServer
* GetSlotServer( SfxDispatcher
&rDispat
)
89 { return GetSlotServer( rDispat
, css::uno::Reference
< css::frame::XDispatchProvider
> () ); }
90 css::uno::Reference
< css::frame::XDispatch
> GetDispatch() const;
91 sal_Int16
Dispatch( const SfxItemSet
* pSet
, bool bForceSynchron
);
92 bool IsControllerDirty() const
93 { return bCtrlDirty
; }
96 void SetState( SfxItemState
, const SfxPoolItem
*, bool bMaybeDirty
=false );
97 void SetCachedState(bool bAlways
);
98 void Invalidate( bool bWithSlot
);
99 void SetVisibleState( bool bShow
);
100 void GetState( boost::property_tree::ptree
& );
102 SfxControllerItem
* ChangeItemLink( SfxControllerItem
* pNewBinding
);
103 SfxControllerItem
* GetItemLink() const;
104 void SetInternalController( SfxControllerItem
* pCtrl
)
105 { DBG_ASSERT( !pInternalController
, "Only one internal controller allowed!" ); pInternalController
= pCtrl
; }
106 void ReleaseInternalController() { pInternalController
= nullptr; }
107 SfxControllerItem
* GetInternalController() const { return pInternalController
; }
108 const css::uno::Reference
< css::frame::XDispatch
>&
109 GetInternalDispatch() const
110 { return xMyDispatch
; }
111 void SetInternalDispatch( const css::uno::Reference
< css::frame::XDispatch
>& rDisp
)
112 { xMyDispatch
= rDisp
; }
116 // clears Cached-Item
118 inline void SfxStateCache::ClearCache()
124 // registers an item representing this function
126 inline SfxControllerItem
* SfxStateCache::ChangeItemLink( SfxControllerItem
* pNewBinding
)
128 SfxControllerItem
* pOldBinding
= pController
;
129 pController
= pNewBinding
;
139 // returns the func binding which becomes called on spreading states
141 inline SfxControllerItem
* SfxStateCache::GetItemLink() const
147 inline sal_uInt16
SfxStateCache::GetId() const
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */