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::uno
;
30 using namespace ::com::sun::star::beans
;
31 using namespace ::com::sun::star::util
;
32 using namespace ::com::sun::star::frame
;
33 using namespace ::com::sun::star::lang
;
34 using namespace ::com::sun::star
;
36 SFX_IMPL_TOOLBOX_CONTROL( SvxLineWidthToolBoxControl
, XLineWidthItem
);
38 SvxLineWidthToolBoxControl::SvxLineWidthToolBoxControl(
39 sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
) :
40 SfxToolBoxControl( nSlotId
, nId
, rTbx
)
42 addStatusListener( ".uno:MetricUnit");
46 SvxLineWidthToolBoxControl::~SvxLineWidthToolBoxControl()
50 void SvxLineWidthToolBoxControl::StateChangedAtToolBoxControl(
51 sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
)
53 SvxMetricField
* pFld
= static_cast<SvxMetricField
*>(
54 GetToolBox().GetItemWindow( GetId() ));
55 DBG_ASSERT( pFld
, "Window not found" );
57 if ( nSID
== SID_ATTR_METRIC
)
59 pFld
->RefreshDlgUnit();
63 if ( eState
== SfxItemState::DISABLED
)
65 pFld
->set_sensitive(false);
69 pFld
->set_sensitive(true);
71 if ( eState
== SfxItemState::DEFAULT
)
73 DBG_ASSERT( dynamic_cast<const XLineWidthItem
*>( pState
) != nullptr, "wrong ItemType" );
75 pFld
->SetDestCoreUnit(GetCoreMetric());
77 pFld
->Update( static_cast<const XLineWidthItem
*>(pState
) );
80 pFld
->Update( nullptr );
85 MapUnit
SvxLineWidthToolBoxControl::GetCoreMetric()
87 SfxObjectShell
* pSh
= SfxObjectShell::Current();
88 SfxItemPool
& rPool
= pSh
? pSh
->GetPool() : SfxGetpApp()->GetPool();
89 sal_uInt16 nWhich
= rPool
.GetWhich(SID_ATTR_LINE_WIDTH
);
90 return rPool
.GetMetric(nWhich
);
93 VclPtr
<InterimItemWindow
> SvxLineWidthToolBoxControl::CreateItemWindow(vcl::Window
*pParent
)
95 VclPtr
<SvxMetricField
> pWindow
= VclPtr
<SvxMetricField
>::Create(pParent
, m_xFrame
);
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */