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 <svx/relfld.hxx>
22 SvxRelativeField::SvxRelativeField(std::unique_ptr
<weld::MetricSpinButton
> pControl
)
23 : m_xSpinButton(std::move(pControl
))
26 , bRelativeMode(false)
28 , bNegativeEnabled(false)
31 weld::SpinButton
& rSpinButton
= m_xSpinButton
->get_widget();
32 rSpinButton
.connect_changed(LINK(this, SvxRelativeField
, ModifyHdl
));
35 IMPL_LINK_NOARG(SvxRelativeField
, ModifyHdl
, weld::Entry
&, void)
40 OUString aStr
= m_xSpinButton
->get_text();
41 bool bNewMode
= bRelative
;
45 const sal_Unicode
* pStr
= aStr
.getStr();
49 if( ( ( *pStr
< '0' ) || ( *pStr
> '9' ) ) &&
60 if ( aStr
.indexOf( "%" ) != -1 )
64 if ( bNewMode
!= bRelative
)
65 SetRelative( bNewMode
);
68 void SvxRelativeField::EnableRelativeMode(sal_uInt16 nMin
, sal_uInt16 nMax
)
73 m_xSpinButton
->set_unit(FieldUnit::CM
);
76 void SvxRelativeField::SetRelative( bool bNewRelative
)
78 weld::SpinButton
& rSpinButton
= m_xSpinButton
->get_widget();
80 int nStartPos
, nEndPos
;
81 rSpinButton
.get_selection_bounds(nStartPos
, nEndPos
);
82 OUString aStr
= rSpinButton
.get_text();
87 m_xSpinButton
->set_digits(0);
88 m_xSpinButton
->set_range(nRelMin
, nRelMax
, FieldUnit::NONE
);
89 m_xSpinButton
->set_unit(FieldUnit::PERCENT
);
94 m_xSpinButton
->set_digits(2);
95 m_xSpinButton
->set_range(bNegativeEnabled
? -9999 : 0, 9999, FieldUnit::NONE
);
96 m_xSpinButton
->set_unit(FieldUnit::CM
);
99 rSpinButton
.set_text(aStr
);
100 rSpinButton
.select_region(nStartPos
, nEndPos
);
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */