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 .
20 #include <sal/log.hxx>
21 #include <svl/itempool.hxx>
23 #include <sfx2/ctrlitem.hxx>
24 #include <sfx2/bindings.hxx>
25 #include <sfx2/dispatch.hxx>
26 #include <statcach.hxx>
27 #include <sfx2/viewfrm.hxx>
29 // returns the next registered SfxControllerItem with the same id
31 SfxControllerItem
* SfxControllerItem::GetItemLink()
33 return pNext
== this ? nullptr : pNext
;
37 // returns sal_True if this binding is really bound to a function
39 bool SfxControllerItem::IsBound() const
45 // registers with the id at the bindings
47 void SfxControllerItem::Bind( sal_uInt16 nNewId
, SfxBindings
*pBindinx
)
49 DBG_ASSERT(pBindings
|| pBindinx
, "No Bindings");
52 DBG_ASSERT(pBindings
, "No Bindings");
53 pBindings
->Release(*this);
61 pBindings
->Register(*this);
64 void SfxControllerItem::BindInternal_Impl( sal_uInt16 nNewId
, SfxBindings
*pBindinx
)
66 DBG_ASSERT(pBindings
|| pBindinx
, "No Bindings");
69 DBG_ASSERT(pBindings
, "No Bindings");
70 pBindings
->Release(*this);
78 pBindings
->RegisterInternal_Impl(*this);
82 void SfxControllerItem::UnBind()
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()>)
93 <SfxControllerItem::ReBind()>
94 <SfxControllerItem::ClearCache()>
97 DBG_ASSERT(pBindings
, "No Bindings");
98 DBG_ASSERT( IsBound(), "unbindings unbound SfxControllerItem" );
100 pBindings
->Release(*this);
105 void SfxControllerItem::ReBind()
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.
115 <SfxControllerItem::UnBind()>
116 <SfxControllerItem::ClearCache()>
120 DBG_ASSERT(pBindings
, "No Bindings");
121 DBG_ASSERT( !IsBound(), "bindings rebound SfxControllerItem" );
123 pBindings
->Register(*this);
127 void SfxControllerItem::ClearCache()
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.
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.
144 <SfxControllerItem::UnBind()>
145 <SfxControllerItem::ReBind()>
150 DBG_ASSERT(pBindings
, "No Bindings");
152 pBindings
->ClearCache_Impl( GetId() );
155 // replaces the successor in the list of bindings of the same id
156 SfxControllerItem
* SfxControllerItem::ChangeItemLink( SfxControllerItem
* pNewLink
)
158 SfxControllerItem
* pOldLink
= pNext
;
160 return pOldLink
== this ? nullptr : pOldLink
;
164 // changes the id of unbound functions (e.g. for sub-menu-ids)
165 void SfxControllerItem::SetId( sal_uInt16 nItemId
)
167 DBG_ASSERT( !IsBound(), "changing id of bound binding" );
171 // creates an atomic item for a controller without registration.
172 SfxControllerItem::SfxControllerItem()
175 , eFallbackCoreMetric(MapUnit::Map100thMM
)
180 // creates a representation of the function nId and registers it
181 SfxControllerItem::SfxControllerItem(sal_uInt16 nID
, SfxBindings
&rBindings
)
183 , pBindings(&rBindings
)
184 , eFallbackCoreMetric(MapUnit::Map100thMM
)
187 Bind(nId
, &rBindings
);
190 // unregisters the item in the bindings
191 SfxControllerItem::~SfxControllerItem()
196 void SfxControllerItem::dispose()
202 void SfxControllerItem::StateChangedAtToolBoxControl
204 sal_uInt16
, // <SID> of the triggering slot
205 SfxItemState
, // <SfxItemState> of 'pState'
206 const SfxPoolItem
* // Slot-Status, NULL or IsInvalidItem()
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'.
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()>.
219 Beware! The method is not called when the slot is invalid, however
220 has again assumed the same value.
222 This base class need not be called, further interim steps however
223 (eg <SfxToolboxControl> ) should be called.
229 void SfxControllerItem::GetControlState
232 boost::property_tree::ptree
&
237 void SfxStatusForwarder::StateChangedAtToolBoxControl
239 sal_uInt16 nSID
, // <SID> of the triggering slot
240 SfxItemState eState
, // <SfxItemState> of 'pState'
241 const SfxPoolItem
* pState
// Slot-Status, NULL or IsInvalidItem()
245 pMaster
->StateChangedAtToolBoxControl( nSID
, eState
, pState
);
249 SfxStatusForwarder::SfxStatusForwarder(
251 SfxControllerItem
& rMaster
):
252 SfxControllerItem( nSlotId
, rMaster
.GetBindings() ),
258 SfxItemState
SfxControllerItem::GetItemState
260 const SfxPoolItem
* pState
/* Pointer to <SfxPoolItem>, which
261 Status should be queried. */
266 Static method to determine the status of the SfxPoolItem-Pointers, to be
267 used in the method <SfxControllerItem::StateChanged(const SfxPoolItem*)>
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.
276 SfxItemState::DISABLED
277 Disabled and no further status information available.
278 All other values that may appear should be reset to
281 SfxItemState::DONTCARE
282 Enabled but there were only ambiguous values available
283 (i.e. non that can be queried).
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.
293 ? SfxItemState::DISABLED
294 : IsInvalidItem(pState
)
295 ? SfxItemState::DONTCARE
296 : pState
->IsVoidItem() && !pState
->Which()
297 ? SfxItemState::UNKNOWN
298 : SfxItemState::DEFAULT
;
302 MapUnit
SfxControllerItem::GetCoreMetric() const
306 Gets the measurement unit from the competent pool, in which the Status
311 SfxStateCache
*pCache
= pBindings
->GetStateCache( nId
);
312 SfxDispatcher
*pDispat
= pBindings
->GetDispatcher_Impl();
316 SfxViewFrame
* pViewFrame
= SfxViewFrame::Current();
318 SfxViewFrame::GetFirst();
320 pDispat
= pViewFrame
->GetDispatcher();
323 if ( pDispat
&& pCache
)
325 const SfxSlotServer
*pServer
= pCache
->GetSlotServer( *pDispat
);
328 SfxShell
*pSh
= pDispat
->GetShell( pServer
->GetShellLevel() );
329 SfxItemPool
&rPool
= pSh
->GetPool();
330 sal_uInt16 nWhich
= rPool
.GetWhich( nId
);
332 // invalidate slot and its message|slot server as 'global' information
333 // about the validated message|slot server is not made available
334 pCache
->Invalidate( true );
336 return rPool
.GetMetric( nWhich
);
340 SAL_INFO( "sfx.control", "W1: Can not find ItemPool!" );
341 return eFallbackCoreMetric
;
344 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */