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 INCLUDED_SW_SOURCE_UIBASE_INC_PRCNTFLD_HXX
20 : #define INCLUDED_SW_SOURCE_UIBASE_INC_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 0 : class SW_DLLPUBLIC PercentField
28 : {
29 : VclPtr<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 : SAL_DLLPRIVATE sal_Int64 ImpPower10(sal_uInt16 n);
44 :
45 : public:
46 :
47 : PercentField();
48 : void set(MetricField *pField);
49 : const MetricField* get() const { return m_pField; }
50 0 : MetricField* get() { return m_pField; }
51 0 : void SetUpHdl(const Link<>& rLink) { m_pField->SetUpHdl(rLink); }
52 0 : void SetDownHdl(const Link<>& rLink) { m_pField->SetDownHdl(rLink); }
53 0 : void SetModifyHdl(const Link<>& rLink) { m_pField->SetModifyHdl(rLink); }
54 0 : void SetLoseFocusHdl(const Link<>& rLink) { m_pField->SetLoseFocusHdl(rLink); }
55 0 : void SetMetric(FieldUnit eUnit) { ::SetMetric(*m_pField, eUnit); }
56 0 : void Enable(bool bEnable = true, bool bChild = true) { m_pField->Enable(bEnable, bChild); }
57 0 : void Disable(bool bChild = true) { m_pField->Disable(bChild); }
58 0 : bool HasFocus() const { return m_pField->HasFocus(); }
59 0 : void SetAccessibleName(const OUString& rName) { m_pField->SetAccessibleName(rName); }
60 0 : void SetText(const OUString& rStr) { m_pField->SetText(rStr); }
61 0 : void SaveValue() { m_pField->SaveValue(); }
62 0 : void ClearModifyFlag() { m_pField->ClearModifyFlag(); }
63 0 : OUString GetSavedValue() const { return m_pField->GetSavedValue(); }
64 0 : OUString GetText() const { return m_pField->GetText(); }
65 0 : void SetMetricFieldMin(sal_Int64 nNewMin) { m_pField->SetMin(nNewMin); }
66 0 : void SetMetricFieldMax(sal_Int64 nNewMax) { m_pField->SetMax(nNewMax); }
67 :
68 0 : void SetValue(sal_Int64 nNewValue, FieldUnit eInUnit = FUNIT_NONE) { m_pField->SetValue(nNewValue, eInUnit); }
69 :
70 0 : void SetLast(sal_Int64 nNewLast) { m_pField->SetLast(nNewLast); }
71 :
72 : void SetPrcntValue(sal_Int64 nNewValue, FieldUnit eInUnit = FUNIT_NONE);
73 :
74 : void SetUserValue(sal_Int64 nNewValue, FieldUnit eInUnit = FUNIT_NONE);
75 :
76 : void SetBaseValue(sal_Int64 nNewValue, FieldUnit eInUnit = FUNIT_NONE);
77 :
78 : sal_Int64 GetValue(FieldUnit eOutUnit = FUNIT_NONE);
79 :
80 : bool IsValueModified();
81 :
82 : void SetMax(sal_Int64 nNewMax, FieldUnit eInUnit = FUNIT_NONE);
83 :
84 : void SetMin(sal_Int64 nNewMin, FieldUnit eInUnit = FUNIT_NONE);
85 :
86 0 : sal_Int64 GetMin() const { return m_pField->GetMin(); }
87 : sal_Int64 GetMax() const { return m_pField->GetMax(); }
88 :
89 : sal_Int64 NormalizePercent(sal_Int64 nValue);
90 : sal_Int64 DenormalizePercent(sal_Int64 nValue);
91 :
92 0 : sal_Int64 Normalize( sal_Int64 nValue ) const { return m_pField->Normalize(nValue); }
93 : sal_Int64 Denormalize( sal_Int64 nValue ) const { return m_pField->Denormalize(nValue); }
94 :
95 : void SetRefValue(sal_Int64 nValue);
96 : sal_Int64 GetRefValue() const { return nRefValue; }
97 : sal_Int64 GetRealValue(FieldUnit eOutUnit = FUNIT_NONE);
98 :
99 : sal_Int64 Convert(sal_Int64 nValue, FieldUnit eInUnit, FieldUnit eOutUnit);
100 :
101 : void ShowPercent(bool bPercent);
102 :
103 : sal_uInt16 GetOldDigits() const {return nOldDigits;}
104 :
105 0 : void LockAutoCalculation(bool bLock) {bLockAutoCalculation = bLock;}
106 : bool IsAutoCalculationLocked() const {return bLockAutoCalculation;}
107 : };
108 :
109 : #endif // INCLUDED_SW_SOURCE_UIBASE_INC_PRCNTFLD_HXX
110 :
111 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|