Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #ifndef _PRCNTFLD_HXX
20 : #define _PRCNTFLD_HXX
21 :
22 : #include <vcl/field.hxx>
23 : #include "swdllapi.h"
24 : #include "uitool.hxx"
25 :
26 : //Wraps a MetricField with extra features, preferred to PercentField
27 : class SW_DLLPUBLIC PercentFieldWrap
28 : {
29 : MetricField* m_pField;
30 :
31 : sal_Int64 nRefValue; // 100% value for conversion (in Twips)
32 : sal_Int64 nOldMax;
33 : sal_Int64 nOldMin;
34 : sal_Int64 nOldSpinSize;
35 : sal_Int64 nOldBaseValue;
36 : sal_Int64 nLastPercent;
37 : sal_Int64 nLastValue;
38 : sal_uInt16 nOldDigits;
39 : FieldUnit eOldUnit;
40 : bool bLockAutoCalculation; //prevent recalcution of percent values when the
41 : //reference value is changed
42 :
43 : SW_DLLPRIVATE sal_Int64 ImpPower10(sal_uInt16 n);
44 :
45 : public:
46 :
47 : PercentFieldWrap();
48 : void set(MetricField *pField);
49 0 : void SetUpHdl(const Link& rLink) { m_pField->SetUpHdl(rLink); }
50 0 : void SetDownHdl(const Link& rLink) { m_pField->SetDownHdl(rLink); }
51 0 : void SetLoseFocusHdl(const Link& rLink) { m_pField->SetLoseFocusHdl(rLink); }
52 0 : void SetMetric(FieldUnit eUnit) { ::SetMetric(*m_pField, eUnit); }
53 0 : void Enable(bool bEnable = true, bool bChild = true) { m_pField->Enable(bEnable, bChild); }
54 0 : void SetAccessibleName(const OUString& rName) { m_pField->SetAccessibleName(rName); }
55 0 : void SetText(const OUString& rStr) { m_pField->SetText(rStr); }
56 0 : void SetMetricFieldMin(sal_Int64 nNewMin) { m_pField->SetMin(nNewMin); }
57 : void SetMetricFieldMax(sal_Int64 nNewMax) { m_pField->SetMax(nNewMax); }
58 :
59 : void SetValue(sal_Int64 nNewValue, FieldUnit eInUnit = FUNIT_NONE);
60 :
61 : void SetPrcntValue(sal_Int64 nNewValue, FieldUnit eInUnit = FUNIT_NONE);
62 :
63 : void SetUserValue(sal_Int64 nNewValue, FieldUnit eInUnit = FUNIT_NONE);
64 :
65 : void SetBaseValue(sal_Int64 nNewValue, FieldUnit eInUnit = FUNIT_NONE);
66 :
67 : sal_Int64 GetValue(FieldUnit eOutUnit = FUNIT_NONE);
68 :
69 : bool IsValueModified();
70 :
71 : void SetMax(sal_Int64 nNewMax, FieldUnit eInUnit = FUNIT_NONE);
72 :
73 : void SetMin(sal_Int64 nNewMin, FieldUnit eInUnit = FUNIT_NONE);
74 :
75 : sal_Int64 NormalizePercent(sal_Int64 nValue);
76 : sal_Int64 DenormalizePercent(sal_Int64 nValue);
77 :
78 : void SetRefValue(sal_Int64 nValue);
79 : sal_Int64 GetRefValue() const { return nRefValue; }
80 : sal_Int64 GetRealValue(FieldUnit eOutUnit = FUNIT_NONE);
81 :
82 : sal_Int64 Convert(sal_Int64 nValue, FieldUnit eInUnit, FieldUnit eOutUnit);
83 :
84 : void ShowPercent(bool bPercent);
85 :
86 : sal_uInt16 GetOldDigits() const {return nOldDigits;}
87 :
88 : void LockAutoCalculation(bool bLock) {bLockAutoCalculation = bLock;}
89 : bool IsAutoCalculationLocked() const {return bLockAutoCalculation;}
90 : };
91 :
92 :
93 0 : class SW_DLLPUBLIC PercentField : public MetricField
94 : {
95 : sal_Int64 nRefValue; // 100% value for conversion (in Twips)
96 : sal_Int64 nOldMax;
97 : sal_Int64 nOldMin;
98 : sal_Int64 nOldSpinSize;
99 : sal_Int64 nOldBaseValue;
100 : sal_Int64 nLastPercent;
101 : sal_Int64 nLastValue;
102 : sal_uInt16 nOldDigits;
103 : FieldUnit eOldUnit;
104 : sal_Bool bLockAutoCalculation; //prevent recalcution of percent values when the
105 : //reference value is changed
106 :
107 : SW_DLLPRIVATE sal_Int64 ImpPower10(sal_uInt16 n);
108 :
109 : using MetricField::SetValue;
110 : using MetricField::GetValue;
111 : using MetricFormatter::SetUserValue;
112 : using MetricFormatter::SetBaseValue;
113 : using MetricFormatter::SetMax;
114 : using MetricFormatter::SetMin;
115 : using NumericFormatter::IsValueModified;
116 :
117 : public:
118 :
119 : virtual void SetValue(sal_Int64 nNewValue, FieldUnit eInUnit = FUNIT_NONE);
120 :
121 : PercentField( Window* pWin, const ResId& rResId );
122 :
123 : void SetPrcntValue(sal_Int64 nNewValue, FieldUnit eInUnit = FUNIT_NONE);
124 :
125 : void SetUserValue(sal_Int64 nNewValue, FieldUnit eInUnit = FUNIT_NONE);
126 :
127 : void SetBaseValue(sal_Int64 nNewValue, FieldUnit eInUnit = FUNIT_NONE);
128 :
129 : sal_Int64 GetValue(FieldUnit eOutUnit = FUNIT_NONE);
130 :
131 : sal_Bool IsValueModified();
132 :
133 : //using NumericFormatter::SetMax;
134 : void SetMax(sal_Int64 nNewMax, FieldUnit eInUnit = FUNIT_NONE);
135 :
136 : //using NumericFormatter::SetMin;
137 : void SetMin(sal_Int64 nNewMin, FieldUnit eInUnit = FUNIT_NONE);
138 :
139 : sal_Int64 NormalizePercent(sal_Int64 nValue);
140 : sal_Int64 DenormalizePercent(sal_Int64 nValue);
141 :
142 : void SetRefValue(sal_Int64 nValue);
143 : inline sal_Int64 GetRefValue() const { return nRefValue; }
144 : sal_Int64 GetRealValue(FieldUnit eOutUnit = FUNIT_NONE);
145 :
146 : sal_Int64 Convert(sal_Int64 nValue, FieldUnit eInUnit, FieldUnit eOutUnit);
147 :
148 : void ShowPercent(sal_Bool bPercent);
149 :
150 : sal_uInt16 GetOldDigits() const {return nOldDigits;}
151 :
152 0 : void LockAutoCalculation(sal_Bool bLock) {bLockAutoCalculation = bLock;}
153 : sal_Bool IsAutoCalculationLocked()const {return bLockAutoCalculation;}
154 : };
155 :
156 : #endif // _PRCNTFLD_HXX
157 :
158 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|