LibreOffice Module sfx2 (master) 1
statcach.hxx
Go to the documentation of this file.
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/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>
28#include <tools/debug.hxx>
29#include <rtl/ref.hxx>
30
31#include <sfx2/bindings.hxx>
32
33#include "slotserv.hxx"
34
36class SfxDispatcher;
37class BindDispatch_Impl final : public ::cppu::WeakImplHelper< css::frame::XStatusListener >
38{
39friend class SfxStateCache;
40 css::uno::Reference< css::frame::XDispatch > xDisp;
41 css::util::URL aURL;
42 css::frame::FeatureStateEvent aStatus;
44 const SfxSlot* pSlot;
45
46public:
48 css::uno::Reference< css::frame::XDispatch > xDisp,
49 css::util::URL aURL,
50 SfxStateCache* pStateCache, const SfxSlot* pSlot );
51
52 virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) override;
53 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
54
55 const css::frame::FeatureStateEvent& GetStatus() const { return aStatus;}
56 sal_Int16 Dispatch( const css::uno::Sequence < css::beans::PropertyValue >& aProps, bool bForceSynchron );
57 void Release();
58};
59
61{
62friend class BindDispatch_Impl;
65 sal_uInt16 nId; // Slot-Id
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 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
76
77private:
78 SfxStateCache( const SfxStateCache& rOrig ) = delete;
79 void SetState_Impl( SfxItemState, const SfxPoolItem*, bool bMaybeDirty );
80
81public:
82 SfxStateCache( sal_uInt16 nFuncId );
84
85 sal_uInt16 GetId() const;
86
87 const SfxSlotServer* GetSlotServer( SfxDispatcher &rDispat, const css::uno::Reference< css::frame::XDispatchProvider > & xProv );
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; }
94 void ClearCache();
95
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& );
101
105 { DBG_ASSERT( !pInternalController, "Only one internal controller allowed!" ); pInternalController = pCtrl; }
108 const css::uno::Reference < css::frame::XDispatch >&
110 { return xMyDispatch; }
111 void SetInternalDispatch( const css::uno::Reference < css::frame::XDispatch >& rDisp )
112 { xMyDispatch = rDisp; }
113};
114
115
116// clears Cached-Item
117
119{
120 bItemDirty = true;
121}
122
123
124// registers an item representing this function
125
127{
128 SfxControllerItem* pOldBinding = pController;
129 pController = pNewBinding;
130 if ( pNewBinding )
131 {
132 bCtrlDirty = true;
133 bItemDirty = true;
134 }
135 return pOldBinding;
136}
137
138
139// returns the func binding which becomes called on spreading states
140
142{
143 return pController;
144}
145
146
147inline sal_uInt16 SfxStateCache::GetId() const
148{
149 return nId;
150}
151
152#endif
153
154/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::frame::XDispatch > xDisp
Definition: statcach.hxx:40
const css::frame::FeatureStateEvent & GetStatus() const
Definition: statcach.hxx:55
virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent &Event) override
Definition: statcach.cxx:70
BindDispatch_Impl(css::uno::Reference< css::frame::XDispatch > xDisp, css::util::URL aURL, SfxStateCache *pStateCache, const SfxSlot *pSlot)
Definition: statcach.cxx:51
css::frame::FeatureStateEvent aStatus
Definition: statcach.hxx:42
const SfxSlot * pSlot
Definition: statcach.hxx:44
SfxStateCache * pCache
Definition: statcach.hxx:43
sal_Int16 Dispatch(const css::uno::Sequence< css::beans::PropertyValue > &aProps, bool bForceSynchron)
Definition: statcach.cxx:163
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
Definition: statcach.cxx:61
css::util::URL aURL
Definition: statcach.hxx:41
Definition: msg.hxx:184
const css::uno::Reference< css::frame::XDispatch > & GetInternalDispatch() const
Definition: statcach.hxx:109
SfxStateCache(const SfxStateCache &rOrig)=delete
void Invalidate(bool bWithSlot)
Definition: statcach.cxx:211
sal_uInt16 nId
Definition: statcach.hxx:65
SfxControllerItem * GetItemLink() const
Definition: statcach.hxx:141
bool bItemDirty
Definition: statcach.hxx:75
SfxControllerItem * ChangeItemLink(SfxControllerItem *pNewBinding)
Definition: statcach.hxx:126
bool IsControllerDirty() const
Definition: statcach.hxx:92
sal_uInt16 GetId() const
Definition: statcach.hxx:147
void ClearCache()
Definition: statcach.hxx:118
css::uno::Reference< css::frame::XDispatch > GetDispatch() const
Definition: statcach.cxx:477
const SfxSlotServer * GetSlotServer(SfxDispatcher &rDispat)
Definition: statcach.hxx:88
void SetState(SfxItemState, const SfxPoolItem *, bool bMaybeDirty=false)
Definition: statcach.cxx:311
void SetCachedState(bool bAlways)
Definition: statcach.cxx:450
SfxControllerItem * GetInternalController() const
Definition: statcach.hxx:107
const SfxSlotServer * GetSlotServer(SfxDispatcher &rDispat, const css::uno::Reference< css::frame::XDispatchProvider > &xProv)
Definition: statcach.cxx:227
SfxPoolItem * pLastItem
Definition: statcach.hxx:70
bool bSlotDirty
Definition: statcach.hxx:73
css::uno::Reference< css::frame::XDispatch > xMyDispatch
Definition: statcach.hxx:67
void SetInternalController(SfxControllerItem *pCtrl)
Definition: statcach.hxx:104
SfxControllerItem * pInternalController
Definition: statcach.hxx:66
void SetInternalDispatch(const css::uno::Reference< css::frame::XDispatch > &rDisp)
Definition: statcach.hxx:111
SfxSlotServer aSlotServ
Definition: statcach.hxx:69
void ReleaseInternalController()
Definition: statcach.hxx:106
bool bItemVisible
Definition: statcach.hxx:74
void SetState_Impl(SfxItemState, const SfxPoolItem *, bool bMaybeDirty)
Definition: statcach.cxx:388
void SetVisibleState(bool bShow)
Definition: statcach.cxx:342
void GetState(boost::property_tree::ptree &)
Definition: statcach.cxx:329
sal_Int16 Dispatch(const SfxItemSet *pSet, bool bForceSynchron)
Definition: statcach.cxx:484
SfxItemState eLastState
Definition: statcach.hxx:71
bool bCtrlDirty
Definition: statcach.hxx:72
rtl::Reference< BindDispatch_Impl > mxDispatch
Definition: statcach.hxx:64
SfxControllerItem * pController
Definition: statcach.hxx:68
#define DBG_ASSERT(sCon, aError)
SfxItemState