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 <sfx2/sidebar/ControllerItem.hxx>
22 #include <sfx2/bindings.hxx>
23 #include <sfx2/sfxsids.hrc>
24 #include <comphelper/lok.hxx>
25 #include <unotools/localedatawrapper.hxx>
26 #include <tools/fldunit.hxx>
27 #include <svl/intitem.hxx>
31 namespace sfx2::sidebar
{
33 ControllerItem::ControllerItem (
34 const sal_uInt16 nSlotId
,
35 SfxBindings
&rBindings
,
36 ItemUpdateReceiverInterface
& rItemUpdateReceiver
)
37 : SfxControllerItem(nSlotId
, rBindings
),
38 mrItemUpdateReceiver(rItemUpdateReceiver
)
42 ControllerItem::~ControllerItem()
47 void ControllerItem::ReceiverNotifyItemUpdate(sal_uInt16 nSID
, SfxItemState eState
,
48 const SfxPoolItem
* pState
)
50 if (nSID
== SID_ATTR_METRIC
&& pState
&& comphelper::LibreOfficeKit::isActive())
52 std::unique_ptr
<SfxPoolItem
> xClose(pState
->Clone());
53 MeasurementSystem eSystem
54 = LocaleDataWrapper(comphelper::LibreOfficeKit::getLocale()).getMeasurementSystemEnum();
55 FieldUnit eUnit
= MeasurementSystem::Metric
== eSystem
? FieldUnit::CM
: FieldUnit::INCH
;
56 static_cast<SfxUInt16Item
*>(xClose
.get())->SetValue(static_cast<sal_uInt16
>(eUnit
));
57 mrItemUpdateReceiver
.NotifyItemUpdate(nSID
, eState
, xClose
.get());
60 mrItemUpdateReceiver
.NotifyItemUpdate(nSID
, eState
, pState
);
63 void ControllerItem::StateChangedAtToolBoxControl (
66 const SfxPoolItem
* pState
)
68 ReceiverNotifyItemUpdate(nSID
, eState
, pState
);
71 void ControllerItem::GetControlState (
73 boost::property_tree::ptree
& rState
)
75 mrItemUpdateReceiver
.GetControlState(nSID
, rState
);
78 void ControllerItem::RequestUpdate()
80 std::unique_ptr
<SfxPoolItem
> pState
;
81 const SfxItemState
eState (GetBindings().QueryState(GetId(), pState
));
82 ReceiverNotifyItemUpdate(GetId(), eState
, pState
.get());
85 ControllerItem::ItemUpdateReceiverInterface::~ItemUpdateReceiverInterface()
89 } // end of namespace sfx2::sidebar
91 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */