/src/libreoffice/sfx2/source/inc/statcach.hxx
Line | Count | Source |
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> |
27 | | #include <cppuhelper/implbase.hxx> |
28 | | #include <tools/debug.hxx> |
29 | | #include <rtl/ref.hxx> |
30 | | |
31 | | #include <sfx2/bindings.hxx> |
32 | | |
33 | | #include "slotserv.hxx" |
34 | | |
35 | | class SfxControllerItem; |
36 | | class SfxDispatcher; |
37 | | class BindDispatch_Impl final : public ::cppu::WeakImplHelper< css::frame::XStatusListener > |
38 | | { |
39 | | friend class SfxStateCache; |
40 | | css::uno::Reference< css::frame::XDispatch > xDisp; |
41 | | css::util::URL aURL; |
42 | | css::frame::FeatureStateEvent aStatus; |
43 | | SfxStateCache* pCache; |
44 | | const SfxSlot* pSlot; |
45 | | |
46 | | public: |
47 | | BindDispatch_Impl( |
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 | 0 | 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 | | |
60 | | class SfxStateCache |
61 | | { |
62 | | friend class BindDispatch_Impl; |
63 | | rtl::Reference<BindDispatch_Impl> |
64 | | mxDispatch; |
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 |
76 | | |
77 | | private: |
78 | | SfxStateCache( const SfxStateCache& rOrig ) = delete; |
79 | | void SetState_Impl( SfxItemState, const SfxPoolItem*, bool bMaybeDirty ); |
80 | | |
81 | | public: |
82 | | SfxStateCache( sal_uInt16 nFuncId ); |
83 | | ~SfxStateCache(); |
84 | | |
85 | | sal_uInt16 GetId() const; |
86 | | |
87 | | const SfxSlotServer* GetSlotServer( SfxDispatcher &rDispat, const css::uno::Reference< css::frame::XDispatchProvider > & xProv ); |
88 | | const SfxSlotServer* GetSlotServer( SfxDispatcher &rDispat ) |
89 | 0 | { 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 | 0 | { 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 | | |
102 | | SfxControllerItem* ChangeItemLink( SfxControllerItem* pNewBinding ); |
103 | | SfxControllerItem* GetItemLink() const; |
104 | | void SetInternalController( SfxControllerItem* pCtrl ) |
105 | 0 | { DBG_ASSERT( !pInternalController, "Only one internal controller allowed!" ); pInternalController = pCtrl; } |
106 | 0 | void ReleaseInternalController() { pInternalController = nullptr; } |
107 | 213k | SfxControllerItem* GetInternalController() const { return pInternalController; } |
108 | | const css::uno::Reference < css::frame::XDispatch >& |
109 | | GetInternalDispatch() const |
110 | 0 | { return xMyDispatch; } |
111 | | void SetInternalDispatch( const css::uno::Reference < css::frame::XDispatch >& rDisp ) |
112 | 0 | { xMyDispatch = rDisp; } |
113 | | }; |
114 | | |
115 | | |
116 | | // clears Cached-Item |
117 | | |
118 | | inline void SfxStateCache::ClearCache() |
119 | 0 | { |
120 | 0 | bItemDirty = true; |
121 | 0 | } |
122 | | |
123 | | |
124 | | // registers an item representing this function |
125 | | |
126 | | inline SfxControllerItem* SfxStateCache::ChangeItemLink( SfxControllerItem* pNewBinding ) |
127 | 149k | { |
128 | 149k | SfxControllerItem* pOldBinding = pController; |
129 | 149k | pController = pNewBinding; |
130 | 149k | if ( pNewBinding ) |
131 | 85.2k | { |
132 | 85.2k | bCtrlDirty = true; |
133 | 85.2k | bItemDirty = true; |
134 | 85.2k | } |
135 | 149k | return pOldBinding; |
136 | 149k | } |
137 | | |
138 | | |
139 | | // returns the func binding which becomes called on spreading states |
140 | | |
141 | | inline SfxControllerItem* SfxStateCache::GetItemLink() const |
142 | 234k | { |
143 | 234k | return pController; |
144 | 234k | } |
145 | | |
146 | | |
147 | | inline sal_uInt16 SfxStateCache::GetId() const |
148 | 1.04M | { |
149 | 1.04M | return nId; |
150 | 1.04M | } |
151 | | |
152 | | #endif |
153 | | |
154 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |