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 <vcl/toolbox.hxx>
21 #include <sfx2/app.hxx>
22 #include <sfx2/objsh.hxx>
23 #include <svl/itempool.hxx>
24 #include <svx/svxids.hrc>
25 #include <svx/xlnwtit.hxx>
26 #include <svx/linectrl.hxx>
27 #include "linemetricbox.hxx"
29 using namespace ::com::sun::star
;
31 SFX_IMPL_TOOLBOX_CONTROL( SvxLineWidthToolBoxControl
, XLineWidthItem
);
33 SvxLineWidthToolBoxControl::SvxLineWidthToolBoxControl(
34 sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
) :
35 SfxToolBoxControl( nSlotId
, nId
, rTbx
)
37 addStatusListener( u
".uno:MetricUnit"_ustr
);
41 SvxLineWidthToolBoxControl::~SvxLineWidthToolBoxControl()
45 void SvxLineWidthToolBoxControl::StateChangedAtToolBoxControl(
46 sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
)
48 SvxMetricField
* pFld
= static_cast<SvxMetricField
*>(
49 GetToolBox().GetItemWindow( GetId() ));
50 DBG_ASSERT( pFld
, "Window not found" );
52 if ( nSID
== SID_ATTR_METRIC
)
54 pFld
->RefreshDlgUnit();
58 if ( eState
== SfxItemState::DISABLED
)
60 pFld
->set_sensitive(false);
64 pFld
->set_sensitive(true);
66 if ( eState
== SfxItemState::DEFAULT
)
68 DBG_ASSERT( dynamic_cast<const XLineWidthItem
*>( pState
) != nullptr, "wrong ItemType" );
70 pFld
->SetDestCoreUnit(GetCoreMetric());
72 pFld
->Update( static_cast<const XLineWidthItem
*>(pState
) );
75 pFld
->Update( nullptr );
80 MapUnit
SvxLineWidthToolBoxControl::GetCoreMetric()
82 SfxObjectShell
* pSh
= SfxObjectShell::Current();
83 SfxItemPool
& rPool
= pSh
? pSh
->GetPool() : SfxGetpApp()->GetPool();
84 sal_uInt16 nWhich
= rPool
.GetWhichIDFromSlotID(SID_ATTR_LINE_WIDTH
);
85 return rPool
.GetMetric(nWhich
);
88 VclPtr
<InterimItemWindow
> SvxLineWidthToolBoxControl::CreateItemWindow(vcl::Window
*pParent
)
90 VclPtr
<SvxMetricField
> pWindow
= VclPtr
<SvxMetricField
>::Create(pParent
, m_xFrame
);
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */