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 20 #ifndef INCLUDED_XMLOFF_NUMEHELP_HXX 21 #define INCLUDED_XMLOFF_NUMEHELP_HXX 22 23 #include <sal/config.h> 24 #include <xmloff/xmlnamespace.hxx> 25 #include <xmloff/dllapi.h> 26 #include <sal/types.h> 27 #include <com/sun/star/uno/Reference.hxx> 28 29 #include <set> 30 #include <string_view> 31 32 namespace com::sun::star::util { class XNumberFormats; } 33 namespace com::sun::star::util { class XNumberFormatsSupplier; } 34 35 class SvXMLExport; 36 37 struct XMLNumberFormat 38 { 39 OUString sCurrency; 40 sal_Int32 nNumberFormat; 41 sal_Int16 nType; 42 bool bIsStandard : 1; 43 XMLNumberFormatXMLNumberFormat44 XMLNumberFormat(sal_Int32 nTempFormat) 45 : nNumberFormat(nTempFormat) 46 , nType(0) 47 , bIsStandard(false) 48 { 49 } 50 }; 51 52 struct LessNumberFormat 53 { operator ()LessNumberFormat54 bool operator() (const XMLNumberFormat& rValue1, const XMLNumberFormat& rValue2) const 55 { 56 return rValue1.nNumberFormat < rValue2.nNumberFormat; 57 } 58 }; 59 60 typedef std::set<XMLNumberFormat, LessNumberFormat> XMLNumberFormatSet; 61 62 class XMLOFF_DLLPUBLIC XMLNumberFormatAttributesExportHelper 63 { 64 css::uno::Reference< css::util::XNumberFormats > xNumberFormats; 65 SvXMLExport* pExport; 66 const OUString sAttrValue; 67 const OUString sAttrDateValue; 68 const OUString sAttrTimeValue; 69 const OUString sAttrBooleanValue; 70 const OUString sAttrStringValue; 71 const OUString sAttrCurrency; 72 XMLNumberFormatSet aNumberFormats; 73 public: 74 XMLNumberFormatAttributesExportHelper(css::uno::Reference< css::util::XNumberFormatsSupplier > const & xNumberFormatsSupplier); 75 XMLNumberFormatAttributesExportHelper(css::uno::Reference< css::util::XNumberFormatsSupplier > const & xNumberFormatsSupplier, 76 SvXMLExport& rExport ); 77 ~XMLNumberFormatAttributesExportHelper(); 78 79 sal_Int16 GetCellType(const sal_Int32 nNumberFormat, OUString& sCurrency, bool& bIsStandard); 80 static void WriteAttributes(SvXMLExport& rXMLExport, 81 const sal_Int16 nTypeKey, 82 const double& rValue, 83 const OUString& rCurrencySymbol, 84 bool bExportValue); 85 static bool GetCurrencySymbol(const sal_Int32 nNumberFormat, OUString& rCurrencySymbol, 86 css::uno::Reference< css::util::XNumberFormatsSupplier > const & xNumberFormatsSupplier); 87 static sal_Int16 GetCellType(const sal_Int32 nNumberFormat, bool& bIsStandard, 88 css::uno::Reference< css::util::XNumberFormatsSupplier > const & xNumberFormatsSupplier); 89 static void SetNumberFormatAttributes(SvXMLExport& rXMLExport, 90 const sal_Int32 nNumberFormat, 91 const double& rValue, 92 bool bExportValue = true); 93 static void SetNumberFormatAttributes(SvXMLExport& rXMLExport, 94 const OUString& rValue, 95 std::u16string_view rCharacters, 96 bool bExportValue, 97 bool bExportTypeAttribute = true); 98 99 bool GetCurrencySymbol(const sal_Int32 nNumberFormat, OUString& rCurrencySymbol); 100 sal_Int16 GetCellType(const sal_Int32 nNumberFormat, bool& bIsStandard); 101 void WriteAttributes(const sal_Int16 nTypeKey, 102 const double& rValue, 103 const OUString& rCurrencySymbol, 104 bool bExportValue, sal_uInt16 nNamespace = XML_NAMESPACE_OFFICE); 105 void SetNumberFormatAttributes(const sal_Int32 nNumberFormat, 106 const double& rValue, 107 bool bExportValue = true, 108 sal_uInt16 nNamespace = XML_NAMESPACE_OFFICE, bool bExportCurrencySymbol = true); 109 void SetNumberFormatAttributes(const OUString& rValue, 110 std::u16string_view rCharacters, 111 bool bExportValue = true, 112 sal_uInt16 nNamespace = XML_NAMESPACE_OFFICE); 113 }; 114 115 #endif 116 117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 118