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 <svtools/unitconv.hxx> 23 #include <vcl/weld.hxx> 24 #include <swdllapi.h> 25 26 class SW_DLLPUBLIC SwPercentField 27 { 28 std::unique_ptr<weld::MetricSpinButton> m_pField; 29 30 int nRefValue; // 100% value for conversion (in Twips) 31 int nOldMax; 32 int nOldMin; 33 int nOldSpinSize; 34 int nOldPageSize; 35 int nLastPercent; 36 int nLastValue; 37 sal_uInt16 nOldDigits; 38 FieldUnit eOldUnit; 39 bool bLockAutoCalculation; //prevent recalculation of percent values when the 40 //reference value is changed 41 42 SAL_DLLPRIVATE static int ImpPower10(sal_uInt16 n); 43 44 public: 45 46 SwPercentField(std::unique_ptr<weld::MetricSpinButton> pControl); get() const47 const weld::MetricSpinButton* get() const { return m_pField.get(); } get()48 weld::MetricSpinButton* get() { return m_pField.get(); } connect_value_changed(const Link<weld::MetricSpinButton &,void> & rLink)49 void connect_value_changed(const Link<weld::MetricSpinButton&, void>& rLink) { m_pField->connect_value_changed(rLink); } SetMetric(FieldUnit eUnit)50 void SetMetric(FieldUnit eUnit) { ::SetFieldUnit(*m_pField, eUnit); } set_sensitive(bool bEnable)51 void set_sensitive(bool bEnable) { m_pField->set_sensitive(bEnable); } show()52 void show() { m_pField->show(); } has_focus() const53 bool has_focus() const { return m_pField->has_focus(); } save_value()54 void save_value() { m_pField->save_value(); } get_value_changed_from_saved() const55 bool get_value_changed_from_saved() const { return m_pField->get_value_changed_from_saved(); } set_text(const OUString & rStr)56 void set_text(const OUString& rStr) { m_pField->set_text(rStr); } set_accessible_name(const OUString & rStr)57 void set_accessible_name(const OUString& rStr) { m_pField->set_accessible_name(rStr); } SetMetricFieldMin(int nNewMin)58 void SetMetricFieldMin(int nNewMin) { m_pField->set_min(nNewMin, FieldUnit::NONE); } SetMetricFieldMax(int nNewMax)59 void SetMetricFieldMax(int nNewMax) { m_pField->set_max(nNewMax, FieldUnit::NONE); } 60 61 void set_value(int nNewValue, FieldUnit eInUnit = FieldUnit::NONE); 62 int get_value(FieldUnit eOutUnit = FieldUnit::NONE); 63 64 void set_min(int nNewMin, FieldUnit eInUnit); 65 void set_max(int nNewMax, FieldUnit eInUnit); 66 get_min(FieldUnit eOutUnit=FieldUnit::NONE) const67 int get_min(FieldUnit eOutUnit = FieldUnit::NONE) const { return m_pField->get_min(eOutUnit); } 68 69 int NormalizePercent(int nValue); 70 int DenormalizePercent(int nValue); 71 72 void SetRefValue(int nValue); 73 int GetRealValue(FieldUnit eOutUnit); 74 75 int Convert(int nValue, FieldUnit eInUnit, FieldUnit eOutUnit); 76 77 void ShowPercent(bool bPercent); 78 LockAutoCalculation(bool bLock)79 void LockAutoCalculation(bool bLock) {bLockAutoCalculation = bLock;} 80 }; 81 82 83 #endif // INCLUDED_SW_SOURCE_UIBASE_INC_PRCNTFLD_HXX 84 85 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 86