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 .
22 #include <vcl/field.hxx>
26 //Wraps a MetricField with extra features, preferred to PercentField
27 class SW_DLLPUBLIC PercentFieldWrap
29 MetricField
* m_pField
;
31 sal_Int64 nRefValue
; // 100% value for conversion (in Twips)
34 sal_Int64 nOldSpinSize
;
35 sal_Int64 nOldBaseValue
;
36 sal_Int64 nLastPercent
;
38 sal_uInt16 nOldDigits
;
40 bool bLockAutoCalculation
; //prevent recalcution of percent values when the
41 //reference value is changed
43 SW_DLLPRIVATE sal_Int64
ImpPower10(sal_uInt16 n
);
48 void set(MetricField
*pField
);
49 const MetricField
* get() const { return m_pField
; }
50 MetricField
* get() { return m_pField
; }
51 void SetUpHdl(const Link
& rLink
) { m_pField
->SetUpHdl(rLink
); }
52 void SetDownHdl(const Link
& rLink
) { m_pField
->SetDownHdl(rLink
); }
53 void SetLoseFocusHdl(const Link
& rLink
) { m_pField
->SetLoseFocusHdl(rLink
); }
54 void SetMetric(FieldUnit eUnit
) { ::SetMetric(*m_pField
, eUnit
); }
55 void Enable(bool bEnable
= true, bool bChild
= true) { m_pField
->Enable(bEnable
, bChild
); }
56 bool HasFocus() const { return m_pField
->HasFocus(); }
57 void SetAccessibleName(const OUString
& rName
) { m_pField
->SetAccessibleName(rName
); }
58 void SetText(const OUString
& rStr
) { m_pField
->SetText(rStr
); }
59 void SaveValue() { m_pField
->SaveValue(); }
60 void ClearModifyFlag() { m_pField
->ClearModifyFlag(); }
61 OUString
GetSavedValue() const { return m_pField
->GetSavedValue(); }
62 OUString
GetText() const { return m_pField
->GetText(); }
63 void SetMetricFieldMin(sal_Int64 nNewMin
) { m_pField
->SetMin(nNewMin
); }
64 void SetMetricFieldMax(sal_Int64 nNewMax
) { m_pField
->SetMax(nNewMax
); }
66 void SetValue(sal_Int64 nNewValue
, FieldUnit eInUnit
= FUNIT_NONE
);
68 void SetLast(sal_Int64 nNewLast
) { m_pField
->SetLast(nNewLast
); }
70 void SetPrcntValue(sal_Int64 nNewValue
, FieldUnit eInUnit
= FUNIT_NONE
);
72 void SetUserValue(sal_Int64 nNewValue
, FieldUnit eInUnit
= FUNIT_NONE
);
74 void SetBaseValue(sal_Int64 nNewValue
, FieldUnit eInUnit
= FUNIT_NONE
);
76 sal_Int64
GetValue(FieldUnit eOutUnit
= FUNIT_NONE
);
78 bool IsValueModified();
80 void SetMax(sal_Int64 nNewMax
, FieldUnit eInUnit
= FUNIT_NONE
);
82 void SetMin(sal_Int64 nNewMin
, FieldUnit eInUnit
= FUNIT_NONE
);
84 sal_Int64
NormalizePercent(sal_Int64 nValue
);
85 sal_Int64
DenormalizePercent(sal_Int64 nValue
);
87 void SetRefValue(sal_Int64 nValue
);
88 sal_Int64
GetRefValue() const { return nRefValue
; }
89 sal_Int64
GetRealValue(FieldUnit eOutUnit
= FUNIT_NONE
);
91 sal_Int64
Convert(sal_Int64 nValue
, FieldUnit eInUnit
, FieldUnit eOutUnit
);
93 void ShowPercent(bool bPercent
);
95 sal_uInt16
GetOldDigits() const {return nOldDigits
;}
97 void LockAutoCalculation(bool bLock
) {bLockAutoCalculation
= bLock
;}
98 bool IsAutoCalculationLocked() const {return bLockAutoCalculation
;}
102 class SW_DLLPUBLIC PercentField
: public MetricField
104 sal_Int64 nRefValue
; // 100% value for conversion (in Twips)
107 sal_Int64 nOldSpinSize
;
108 sal_Int64 nOldBaseValue
;
109 sal_Int64 nLastPercent
;
110 sal_Int64 nLastValue
;
111 sal_uInt16 nOldDigits
;
113 sal_Bool bLockAutoCalculation
; //prevent recalcution of percent values when the
114 //reference value is changed
116 SW_DLLPRIVATE sal_Int64
ImpPower10(sal_uInt16 n
);
118 using MetricField::SetValue
;
119 using MetricField::GetValue
;
120 using MetricFormatter::SetUserValue
;
121 using MetricFormatter::SetBaseValue
;
122 using MetricFormatter::SetMax
;
123 using MetricFormatter::SetMin
;
124 using NumericFormatter::IsValueModified
;
128 virtual void SetValue(sal_Int64 nNewValue
, FieldUnit eInUnit
= FUNIT_NONE
);
130 PercentField( Window
* pWin
, const ResId
& rResId
);
132 void SetPrcntValue(sal_Int64 nNewValue
, FieldUnit eInUnit
= FUNIT_NONE
);
134 void SetUserValue(sal_Int64 nNewValue
, FieldUnit eInUnit
= FUNIT_NONE
);
136 void SetBaseValue(sal_Int64 nNewValue
, FieldUnit eInUnit
= FUNIT_NONE
);
138 sal_Int64
GetValue(FieldUnit eOutUnit
= FUNIT_NONE
);
140 sal_Bool
IsValueModified();
142 //using NumericFormatter::SetMax;
143 void SetMax(sal_Int64 nNewMax
, FieldUnit eInUnit
= FUNIT_NONE
);
145 //using NumericFormatter::SetMin;
146 void SetMin(sal_Int64 nNewMin
, FieldUnit eInUnit
= FUNIT_NONE
);
148 sal_Int64
NormalizePercent(sal_Int64 nValue
);
149 sal_Int64
DenormalizePercent(sal_Int64 nValue
);
151 void SetRefValue(sal_Int64 nValue
);
152 inline sal_Int64
GetRefValue() const { return nRefValue
; }
153 sal_Int64
GetRealValue(FieldUnit eOutUnit
= FUNIT_NONE
);
155 sal_Int64
Convert(sal_Int64 nValue
, FieldUnit eInUnit
, FieldUnit eOutUnit
);
157 void ShowPercent(sal_Bool bPercent
);
159 sal_uInt16
GetOldDigits() const {return nOldDigits
;}
161 void LockAutoCalculation(sal_Bool bLock
) {bLockAutoCalculation
= bLock
;}
162 sal_Bool
IsAutoCalculationLocked()const {return bLockAutoCalculation
;}
165 #endif // _PRCNTFLD_HXX
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */