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 <svl/itempool.hxx>
22 #include <sfx2/ctrlitem.hxx>
23 #include <sfx2/bindings.hxx>
24 #include <sfx2/dispatch.hxx>
25 #include <sfx2/msgpool.hxx>
26 #include "statcach.hxx"
27 #include <sfx2/viewfrm.hxx>
29 //====================================================================
31 DBG_NAME(SfxControllerItem
);
33 //--------------------------------------------------------------------
36 void SfxControllerItem::CheckConfigure_Impl( sal_uIntPtr nType
)
38 // Real Slot? (i.e. no Separator etc.)
42 // is the ID configurable at all in 'nType'?
43 const SfxSlot
*pSlot
= SFX_SLOTPOOL().GetSlot(nId
);
44 DBG_ASSERTWARNING( pSlot
, "SfxControllerItem: binding not existing slot" );
45 if ( pSlot
&& !pSlot
->IsMode(nType
) )
47 DBG_WARNING( "SfxControllerItem: slot without ...Config-flag" );
48 DbgOutf( "SfxControllerItem: Config-flag missing at SID %5d",
55 //--------------------------------------------------------------------
56 // returns the next registered SfxControllerItem with the same id
58 SfxControllerItem
* SfxControllerItem::GetItemLink()
60 DBG_CHKTHIS(SfxControllerItem
, 0);
61 return pNext
== this ? 0 : pNext
;
64 //--------------------------------------------------------------------
65 // returns sal_True if this binding is really bound to a function
67 sal_Bool
SfxControllerItem::IsBound() const
69 DBG_CHKTHIS(SfxControllerItem
, 0);
73 //====================================================================
74 // registeres with the id at the bindings
76 void SfxControllerItem::Bind( sal_uInt16 nNewId
, SfxBindings
*pBindinx
)
78 DBG_CHKTHIS(SfxControllerItem
, 0);
79 DBG_ASSERT(pBindings
|| pBindinx
, "No Bindings");
82 DBG_ASSERT(pBindings
, "No Bindings");
83 pBindings
->Release(*this);
91 pBindings
->Register(*this);
94 void SfxControllerItem::BindInternal_Impl( sal_uInt16 nNewId
, SfxBindings
*pBindinx
)
96 DBG_CHKTHIS(SfxControllerItem
, 0);
97 DBG_ASSERT(pBindings
|| pBindinx
, "No Bindings");
100 DBG_ASSERT(pBindings
, "No Bindings");
101 pBindings
->Release(*this);
108 pBindings
= pBindinx
;
109 pBindings
->RegisterInternal_Impl(*this);
113 //====================================================================
115 void SfxControllerItem::UnBind()
119 Unbinds the connection of this SfxControllerItems with the SfxBindings
120 instance with which it to time is bound. From this time on it does not
121 receive any status notifications (<SfxControllerItem::StateChented()>)
126 <SfxControllerItem::ReBind()>
127 <SfxControllerItem::ClearCache()>
130 DBG_CHKTHIS(SfxControllerItem
, 0);
131 DBG_ASSERT(pBindings
, "No Bindings");
132 DBG_ASSERT( IsBound(), "unbindings unbound SfxControllerItem" );
134 pBindings
->Release(*this);
138 //====================================================================
140 void SfxControllerItem::ReBind()
144 Binds this SfxControllerItem with the SfxBindings instance again,
145 with which it was last bound. From this time on it does receive status
146 notifications (<SfxControllerItem::StateChented()>) again.
150 <SfxControllerItem::UnBind()>
151 <SfxControllerItem::ClearCache()>
155 DBG_CHKTHIS(SfxControllerItem
, 0);
156 DBG_ASSERT(pBindings
, "No Bindings");
157 DBG_ASSERT( !IsBound(), "bindings rebound SfxControllerItem" );
159 pBindings
->Register(*this);
162 //--------------------------------------------------------------------
164 void SfxControllerItem::ClearCache()
168 Clears the cache status for this SfxControllerItem. That is by the next
169 status update is the <SfxPoolItem> sent in any case, even if the same was
170 sent before. This is needed if a controller can be switched on and note
171 that status themselves.
175 The combined controller for adjusting the surface type and the concrete
176 expression (blue color, or hatching X) can be changed in type, but is then
177 notified of the next selection again, even if it the same data.
181 <SfxControllerItem::UnBind()>
182 <SfxControllerItem::ReBind()>
187 DBG_CHKTHIS(SfxControllerItem
, 0);
188 DBG_ASSERT(pBindings
, "No Bindings");
190 pBindings
->ClearCache_Impl( GetId() );
193 //--------------------------------------------------------------------
194 // replaces the successor in the list of bindings of the same id
196 SfxControllerItem
* SfxControllerItem::ChangeItemLink( SfxControllerItem
* pNewLink
)
198 DBG_CHKTHIS(SfxControllerItem
, 0);
199 SfxControllerItem
* pOldLink
= pNext
;
201 return pOldLink
== this ? 0 : pOldLink
;
204 //--------------------------------------------------------------------
205 // changes the id of unbound functions (e.g. for sub-menu-ids)
207 void SfxControllerItem::SetId( sal_uInt16 nItemId
)
209 DBG_CHKTHIS(SfxControllerItem
, 0);
210 DBG_ASSERT( !IsBound(), "changing id of bound binding" );
214 //--------------------------------------------------------------------
216 // creates a atomic item for a controller without registration.
218 SfxControllerItem::SfxControllerItem():
223 DBG_CTOR(SfxControllerItem
, 0);
226 //--------------------------------------------------------------------
227 // creates a representation of the function nId and registeres it
229 SfxControllerItem::SfxControllerItem( sal_uInt16 nID
, SfxBindings
&rBindings
):
232 pBindings(&rBindings
)
234 DBG_CTOR(SfxControllerItem
, 0);
235 Bind(nId
, &rBindings
);
238 //--------------------------------------------------------------------
239 // unregisteres the item in the bindings
241 SfxControllerItem::~SfxControllerItem()
244 pBindings
->Release(*this);
245 DBG_DTOR(SfxControllerItem
, 0);
248 //--------------------------------------------------------------------
250 void SfxControllerItem::StateChanged
252 sal_uInt16
, // <SID> of the triggering slot
253 SfxItemState
, // <SfxItemState> of 'pState'
254 const SfxPoolItem
* // Slot-Status, NULL or IsInvalidItem()
259 This virtual method is called by the SFx to inform the <SfxControllerItem>s
260 is about that state of the slots 'NSID' has changed. The new value and the
261 value determined by this status is given as 'pState' or 'eState'.
263 The status of a slot may change, for example when the MDI window is
264 switched or when the slot was invalidated explicitly with
265 <SfxBindings::Invalidate()>.
267 Achtung! Die Methode wird nicht gerufen, wenn der Slot ung"ultig wurde,
268 danach jedoch wieder denselben Wert angenommen hat.
270 Beware! The method is not called when the slot is invalid, however
271 has again assumed the same value.
273 This base class need not be called, further interim steps however
274 (eg <SfxToolboxControl> ) should be called.
278 DBG_CHKTHIS(SfxControllerItem
, 0);
281 //--------------------------------------------------------------------
283 void SfxControllerItem::DeleteFloatingWindow()
285 DBG_CHKTHIS(SfxControllerItem
, 0);
288 //--------------------------------------------------------------------
290 void SfxStatusForwarder::StateChanged
292 sal_uInt16 nSID
, // <SID> of the triggering slot
293 SfxItemState eState
, // <SfxItemState> of 'pState'
294 const SfxPoolItem
* pState
// Slot-Status, NULL or IsInvalidItem()
298 pMaster
->StateChanged( nSID
, eState
, pState
);
301 //--------------------------------------------------------------------
303 SfxStatusForwarder::SfxStatusForwarder(
305 SfxControllerItem
& rMaster
):
306 SfxControllerItem( nSlotId
, rMaster
.GetBindings() ),
311 //--------------------------------------------------------------------
313 SfxItemState
SfxControllerItem::GetItemState
315 const SfxPoolItem
* pState
/* Pointer to <SfxPoolItem>, which
316 Status should be queried. */
321 Static method to determine the status of the SfxPoolItem-Pointers, to be
322 used in the method <SfxControllerItem::StateChanged(const SfxPoolItem*)>
326 SfxItemState SFX_ITEM_UNKNOWN
327 Enabled, but no further status information available.
328 Typical for <Slot>s, which anyway are sometimes
329 disabled, but otherwise do not change their appearance.
332 Disabled and no further status information available.
333 All other values that may appear should be reset to
337 Enabled but there were only ambiguous values available
338 (i.e. non that can be queried).
341 Enabled and with available values, which are queried
342 by 'pState'. The Type is thus clearly defined in the
343 entire Program and specified through the Slot.
349 : IsInvalidItem(pState
)
351 : pState
->ISA(SfxVoidItem
) && !pState
->Which()
353 : SFX_ITEM_AVAILABLE
;
356 //--------------------------------------------------------------------
358 SfxMapUnit
SfxControllerItem::GetCoreMetric() const
362 Gets the measurement unit from the competent pool, in which the Status
367 SfxStateCache
*pCache
= pBindings
->GetStateCache( nId
);
368 SfxDispatcher
*pDispat
= pBindings
->GetDispatcher_Impl();
372 SfxViewFrame
* pViewFrame
= SfxViewFrame::Current();
374 SfxViewFrame::GetFirst();
376 pDispat
= pViewFrame
->GetDispatcher();
379 if ( pDispat
&& pCache
)
381 const SfxSlotServer
*pServer
= pCache
->GetSlotServer( *pDispat
);
384 SfxShell
*pSh
= pDispat
->GetShell( pServer
->GetShellLevel() );
385 SfxItemPool
&rPool
= pSh
->GetPool();
386 sal_uInt16 nWhich
= rPool
.GetWhich( nId
);
388 // invalidate slot and its message|slot server as 'global' information
389 // about the validated message|slot server is not made available
390 pCache
->Invalidate( sal_True
);
392 return rPool
.GetMetric( nWhich
);
396 DBG_WARNING( "W1: Can not find ItemPool!" );
397 return SFX_MAPUNIT_100TH_MM
;
400 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */