LibreOffice Module sfx2 (master) 1
ctrlitem.cxx
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
20#include <sal/log.hxx>
21#include <svl/itempool.hxx>
22
23#include <sfx2/ctrlitem.hxx>
24#include <sfx2/bindings.hxx>
25#include <sfx2/dispatch.hxx>
26#include <statcach.hxx>
27#include <sfx2/viewfrm.hxx>
28
29// returns the next registered SfxControllerItem with the same id
30
32{
33 return pNext == this ? nullptr : pNext;
34}
35
36
37// returns sal_True if this binding is really bound to a function
38
40{
41 return pNext != this;
42}
43
44
45// registers with the id at the bindings
46
47void SfxControllerItem::Bind( sal_uInt16 nNewId, SfxBindings *pBindinx )
48{
49 DBG_ASSERT(pBindings || pBindinx, "No Bindings");
50
51 if ( IsBound() ) {
52 DBG_ASSERT(pBindings, "No Bindings");
53 pBindings->Release(*this);
54 }
55
56 nId = nNewId;
57 pNext = nullptr;
58
59 if (pBindinx)
60 pBindings = pBindinx;
61 pBindings->Register(*this);
62}
63
64void SfxControllerItem::BindInternal_Impl( sal_uInt16 nNewId, SfxBindings *pBindinx )
65{
66 DBG_ASSERT(pBindings || pBindinx, "No Bindings");
67
68 if ( IsBound() ) {
69 DBG_ASSERT(pBindings, "No Bindings");
70 pBindings->Release(*this);
71 }
72
73 nId = nNewId;
74 pNext = nullptr;
75
76 if (pBindinx)
77 pBindings = pBindinx;
79}
80
81
83
84/* [Description]
85
86 Unbinds the connection of this SfxControllerItems with the SfxBindings
87 instance with which it to time is bound. From this time on it does not
88 receive any status notifications (<SfxControllerItem::StateChented()>)
89 anymore.
90
91 [Cross-reference]
92
93 <SfxControllerItem::ReBind()>
94 <SfxControllerItem::ClearCache()>
95*/
96{
97 DBG_ASSERT(pBindings, "No Bindings");
98 DBG_ASSERT( IsBound(), "unbindings unbound SfxControllerItem" );
99
100 pBindings->Release(*this);
101 pNext = this;
102}
103
104
106
107/* [Description]
108
109 Binds this SfxControllerItem with the SfxBindings instance again,
110 with which it was last bound. From this time on it does receive status
111 notifications (<SfxControllerItem::StateChented()>) again.
112
113 [Cross-reference]
114
115 <SfxControllerItem::UnBind()>
116 <SfxControllerItem::ClearCache()>
117*/
118
119{
120 DBG_ASSERT(pBindings, "No Bindings");
121 DBG_ASSERT( !IsBound(), "bindings rebound SfxControllerItem" );
122
123 pBindings->Register(*this);
124}
125
126
128
129/* [Description]
130
131 Clears the cache status for this SfxControllerItem. That is by the next
132 status update is the <SfxPoolItem> sent in any case, even if the same was
133 sent before. This is needed if a controller can be switched on and note
134 that status themselves.
135
136 [Example]
137
138 The combined controller for adjusting the surface type and the concrete
139 expression (blue color, or hatching X) can be changed in type, but is then
140 notified of the next selection again, even if it the same data.
141
142 [Cross-reference]
143
144 <SfxControllerItem::UnBind()>
145 <SfxControllerItem::ReBind()>
146*/
147
148
149{
150 DBG_ASSERT(pBindings, "No Bindings");
151
153}
154
155// replaces the successor in the list of bindings of the same id
157{
158 SfxControllerItem* pOldLink = pNext;
159 pNext = pNewLink;
160 return pOldLink == this ? nullptr : pOldLink;
161}
162
163
164// changes the id of unbound functions (e.g. for sub-menu-ids)
165void SfxControllerItem::SetId( sal_uInt16 nItemId )
166{
167 DBG_ASSERT( !IsBound(), "changing id of bound binding" );
168 nId = nItemId;
169}
170
171// creates an atomic item for a controller without registration.
173 : pNext(this)
174 , pBindings(nullptr)
175 , eFallbackCoreMetric(MapUnit::Map100thMM)
176 , nId(0)
177{
178}
179
180// creates a representation of the function nId and registers it
182 : pNext(this)
183 , pBindings(&rBindings)
184 , eFallbackCoreMetric(MapUnit::Map100thMM)
185 , nId(nID)
186{
187 Bind(nId, &rBindings);
188}
189
190// unregisters the item in the bindings
192{
193 dispose();
194}
195
197{
198 if ( IsBound() )
199 UnBind();
200}
201
203(
204 sal_uInt16, // <SID> of the triggering slot
205 SfxItemState, // <SfxItemState> of 'pState'
206 const SfxPoolItem* // Slot-Status, NULL or IsInvalidItem()
207)
208
209/* [Description]
210
211 This virtual method is called by the SFx to inform the <SfxControllerItem>s
212 is about that state of the slots 'NSID' has changed. The new value and the
213 value determined by this status is given as 'pState' or 'eState'.
214
215 The status of a slot may change, for example when the MDI window is
216 switched or when the slot was invalidated explicitly with
217 <SfxBindings::Invalidate()>.
218
219 Beware! The method is not called when the slot is invalid, however
220 has again assumed the same value.
221
222 This base class need not be called, further interim steps however
223 (eg <SfxToolboxControl> ) should be called.
224*/
225
226{
227}
228
230(
231 sal_uInt16,
232 boost::property_tree::ptree&
233)
234{
235}
236
238(
239 sal_uInt16 nSID, // <SID> of the triggering slot
240 SfxItemState eState, // <SfxItemState> of 'pState'
241 const SfxPoolItem* pState // Slot-Status, NULL or IsInvalidItem()
242)
243
244{
245 pMaster->StateChangedAtToolBoxControl( nSID, eState, pState );
246}
247
248
250 sal_uInt16 nSlotId,
251 SfxControllerItem& rMaster ):
252 SfxControllerItem( nSlotId, rMaster.GetBindings() ),
253 pMaster( &rMaster )
254{
255}
256
257
259(
260 const SfxPoolItem* pState /* Pointer to <SfxPoolItem>, which
261 Status should be queried. */
262)
263
264/* [Description]
265
266 Static method to determine the status of the SfxPoolItem-Pointers, to be
267 used in the method <SfxControllerItem::StateChanged(const SfxPoolItem*)>
268
269 [Return value]
270
271 SfxItemState SfxItemState::UNKNOWN
272 Enabled, but no further status information available.
273 Typical for <Slot>s, which anyway are sometimes
274 disabled, but otherwise do not change their appearance.
275
276 SfxItemState::DISABLED
277 Disabled and no further status information available.
278 All other values that may appear should be reset to
279 default.
280
281 SfxItemState::DONTCARE
282 Enabled but there were only ambiguous values available
283 (i.e. non that can be queried).
284
285 SfxItemState::DEFAULT
286 Enabled and with available values, which are queried
287 by 'pState'. The Type is thus clearly defined in the
288 entire Program and specified through the Slot.
289*/
290
291{
292 return !pState
293 ? SfxItemState::DISABLED
294 : IsInvalidItem(pState)
295 ? SfxItemState::DONTCARE
296 : pState->IsVoidItem() && !pState->Which()
297 ? SfxItemState::UNKNOWN
298 : SfxItemState::DEFAULT;
299}
300
301
303
304/* [Description]
305
306 Gets the measurement unit from the competent pool, in which the Status
307 item exist.
308*/
309
310{
313
314 if ( !pDispat )
315 {
316 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
317 if ( pViewFrame )
318 pDispat = pViewFrame->GetDispatcher();
319 }
320
321 if ( pDispat && pCache )
322 {
323 const SfxSlotServer *pServer = pCache->GetSlotServer( *pDispat );
324 if ( pServer )
325 {
326 if (SfxShell *pSh = pDispat->GetShell( pServer->GetShellLevel() ))
327 {
328 SfxItemPool &rPool = pSh->GetPool();
329 sal_uInt16 nWhich = rPool.GetWhich( nId );
330
331 // invalidate slot and its message|slot server as 'global' information
332 // about the validated message|slot server is not made available
333 pCache->Invalidate( true );
334
335 return rPool.GetMetric( nWhich );
336 }
337 }
338 }
339
340 SAL_INFO( "sfx.control", "W1: Can not find ItemPool!" );
341 return eFallbackCoreMetric;
342}
343
344/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPRIVATE SfxStateCache * GetStateCache(sal_uInt16 nId, std::size_t *pPos)
Definition: bindings.cxx:474
SAL_DLLPRIVATE SfxDispatcher * GetDispatcher_Impl()
Definition: bindings.hxx:180
SAL_DLLPRIVATE void RegisterInternal_Impl(SfxControllerItem &rBinding)
Definition: bindings.cxx:769
void Register(SfxControllerItem &rBinding)
Definition: bindings.cxx:775
void Release(SfxControllerItem &rBinding)
Definition: bindings.cxx:814
SAL_DLLPRIVATE void ClearCache_Impl(sal_uInt16 nSlotId)
Definition: bindings.cxx:1484
SAL_DLLPRIVATE void BindInternal_Impl(sal_uInt16 nNewId, SfxBindings *)
Definition: ctrlitem.cxx:64
MapUnit eFallbackCoreMetric
Definition: ctrlitem.hxx:35
SfxControllerItem * ChangeItemLink(SfxControllerItem *pNewLink)
Definition: ctrlitem.cxx:156
void Bind(sal_uInt16 nNewId, SfxBindings *)
Definition: ctrlitem.cxx:47
virtual void StateChangedAtToolBoxControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState)
Definition: ctrlitem.cxx:203
virtual void GetControlState(sal_uInt16 nSID, boost::property_tree::ptree &)
Definition: ctrlitem.cxx:230
static SfxItemState GetItemState(const SfxPoolItem *pState)
Definition: ctrlitem.cxx:259
bool IsBound() const
Definition: ctrlitem.cxx:39
virtual void dispose()
Definition: ctrlitem.cxx:196
sal_uInt16 nId
Definition: ctrlitem.hxx:36
SfxControllerItem * pNext
Definition: ctrlitem.hxx:33
virtual ~SfxControllerItem()
Definition: ctrlitem.cxx:191
sal_uInt16 GetId() const
Definition: ctrlitem.hxx:63
SfxControllerItem * GetItemLink()
Definition: ctrlitem.cxx:31
MapUnit GetCoreMetric() const
Definition: ctrlitem.cxx:302
void SetId(sal_uInt16 nItemId)
Definition: ctrlitem.cxx:165
SfxBindings * pBindings
Definition: ctrlitem.hxx:34
SfxShell * GetShell(sal_uInt16 nIdx) const
Returns a pointer to the <SfxShell> which is at the position nIdx (from the top, last pushed is 0) on...
Definition: dispatch.cxx:529
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
virtual MapUnit GetMetric(sal_uInt16 nWhich) const
sal_uInt16 Which() const
virtual bool IsVoidItem() const
The class SfxShell is the base class for all classes, which provide the functionality of the form <Sl...
Definition: shell.hxx:128
sal_uInt16 GetShellLevel() const
Definition: slotserv.hxx:47
void Invalidate(bool bWithSlot)
Definition: statcach.cxx:211
const SfxSlotServer * GetSlotServer(SfxDispatcher &rDispat, const css::uno::Reference< css::frame::XDispatchProvider > &xProv)
Definition: statcach.cxx:227
SfxControllerItem * pMaster
Definition: ctrlitem.hxx:85
virtual void StateChangedAtToolBoxControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: ctrlitem.cxx:238
SfxStatusForwarder(sal_uInt16 nSlotId, SfxControllerItem &rMaster)
Definition: ctrlitem.cxx:249
static SAL_WARN_UNUSED_RESULT SfxViewFrame * Current()
Definition: viewfrm.cxx:1975
SfxDispatcher * GetDispatcher()
Definition: viewfrm.hxx:109
#define DBG_ASSERT(sCon, aError)
virtual SfxBindings & GetBindings() override
#define SAL_INFO(area, stream)
MapUnit
sal_Int16 nId
SfxItemState
bool IsInvalidItem(const SfxPoolItem *pItem)