/src/libreoffice/include/xmloff/xmlnumfi.hxx
Line | Count | Source |
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_XMLNUMFI_HXX |
21 | | #define INCLUDED_XMLOFF_XMLNUMFI_HXX |
22 | | |
23 | | #include <sal/config.h> |
24 | | #include <xmloff/dllapi.h> |
25 | | #include <sal/types.h> |
26 | | #include <xmloff/xmlstyle.hxx> |
27 | | #include <rtl/ustrbuf.hxx> |
28 | | #include <i18nlangtag/lang.h> |
29 | | #include <memory> |
30 | | #include <vector> |
31 | | |
32 | | namespace com::sun::star::uno { class XComponentContext; } |
33 | | namespace com::sun::star::util { class XNumberFormatsSupplier; } |
34 | | |
35 | | inline constexpr OUString XML_NUMBERSTYLES = u"NumberStyles"_ustr; |
36 | | |
37 | | enum class SvXMLStylesTokens |
38 | | { |
39 | | NUMBER_STYLE, |
40 | | CURRENCY_STYLE, |
41 | | PERCENTAGE_STYLE, |
42 | | DATE_STYLE, |
43 | | TIME_STYLE, |
44 | | BOOLEAN_STYLE, |
45 | | TEXT_STYLE |
46 | | }; |
47 | | |
48 | | enum SvXMLDateElementAttributes |
49 | | { |
50 | | XML_DEA_NONE, |
51 | | XML_DEA_ANY, |
52 | | XML_DEA_SHORT, |
53 | | XML_DEA_LONG, |
54 | | XML_DEA_TEXTSHORT, |
55 | | XML_DEA_TEXTLONG |
56 | | }; |
57 | | |
58 | | class Color; |
59 | | class SvXMLNumImpData; |
60 | | class SvXMLImport; |
61 | | struct SvXMLNumberInfo; |
62 | | class SvNumberFormatter; |
63 | | class LocaleDataWrapper; |
64 | | |
65 | | |
66 | | // use SvXMLNumFmtHelper in the context for <office:styles> to create |
67 | | // child contexts for data styles |
68 | | |
69 | | class SvXMLNumFmtHelper |
70 | | { |
71 | | std::unique_ptr<SvXMLNumImpData> m_pData; |
72 | | |
73 | | public: |
74 | | SvXMLNumFmtHelper( |
75 | | const css::uno::Reference< css::util::XNumberFormatsSupplier >& rSupp ); |
76 | | |
77 | | SvXMLNumFmtHelper( SvNumberFormatter* pNumberFormatter ); |
78 | | |
79 | | ~SvXMLNumFmtHelper(); |
80 | | |
81 | | SvXMLStyleContext* CreateChildContext( SvXMLImport& rImport, |
82 | | sal_Int32 nElement, |
83 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList, |
84 | | SvXMLStylesContext& rStyles); |
85 | | |
86 | 115 | SvXMLNumImpData* getData() { return m_pData.get(); } |
87 | | |
88 | | LanguageType GetLanguageForKey(sal_Int32 nKey) const; |
89 | | |
90 | | // sal_uInt32 GetKeyForName( const OUString& rName ); |
91 | | }; |
92 | | |
93 | | // SvXMLNumFmtDefaults is used in import and export |
94 | | |
95 | | class SvXMLNumFmtDefaults |
96 | | { |
97 | | public: |
98 | | // return value is NfIndexTableOffset |
99 | | static sal_uInt16 GetDefaultDateFormat( SvXMLDateElementAttributes eDOW, |
100 | | SvXMLDateElementAttributes eDay, SvXMLDateElementAttributes eMonth, |
101 | | SvXMLDateElementAttributes eYear, SvXMLDateElementAttributes eHours, |
102 | | SvXMLDateElementAttributes eMins, SvXMLDateElementAttributes eSecs, |
103 | | bool bSystem ); |
104 | | }; |
105 | | |
106 | | struct MyCondition |
107 | | { |
108 | | OUString sCondition; |
109 | | OUString sMapName; |
110 | | }; |
111 | | |
112 | | class XMLOFF_DLLPUBLIC SvXMLNumFormatContext : public SvXMLStyleContext |
113 | | { |
114 | | public: |
115 | | enum ImplicitCalendar |
116 | | { |
117 | | DEFAULT, |
118 | | SECONDARY, |
119 | | OTHER, |
120 | | DEFAULT_FROM_OTHER, |
121 | | SECONDARY_FROM_OTHER |
122 | | }; |
123 | | |
124 | | private: |
125 | | |
126 | | SvXMLNumImpData* m_pData; |
127 | | SvXMLStylesContext* m_pStyles; |
128 | | std::vector <MyCondition> m_aMyConditions; |
129 | | SvXMLStylesTokens m_nType; |
130 | | sal_Int32 m_nKey; |
131 | | // OUString sFormatName; |
132 | | OUString m_sFormatTitle; |
133 | | // OUString sMapName; |
134 | | OUString m_sCalendar; |
135 | | OUString m_aImplicitCalendar[2]; |
136 | | ImplicitCalendar m_eImplicitCalendar; |
137 | | LanguageType m_nFormatLang; |
138 | | bool m_bAutoOrder; |
139 | | bool m_bFromSystem; |
140 | | bool m_bTruncate; |
141 | | bool m_bAutoDec; // set in AddNumber |
142 | | bool m_bAutoInt; // set in AddNumber |
143 | | bool m_bHasExtraText; |
144 | | bool m_bHasTrailingEmptyText; |
145 | | OUStringBuffer m_aFormatCode{64}; |
146 | | OUStringBuffer m_aConditions{32}; |
147 | | bool m_bHasLongDoW; |
148 | | bool m_bHasDateTime; |
149 | | bool m_bRemoveAfterUse; |
150 | | |
151 | | // contained date elements, used to recognize default date formats |
152 | | SvXMLDateElementAttributes m_eDateDOW; |
153 | | SvXMLDateElementAttributes m_eDateDay; |
154 | | SvXMLDateElementAttributes m_eDateMonth; |
155 | | SvXMLDateElementAttributes m_eDateYear; |
156 | | SvXMLDateElementAttributes m_eDateHours; |
157 | | SvXMLDateElementAttributes m_eDateMins; |
158 | | SvXMLDateElementAttributes m_eDateSecs; |
159 | | bool m_bDateNoDefault; |
160 | | |
161 | | SAL_DLLPRIVATE sal_Int32 PrivateGetKey(std::vector<SvXMLNumFormatContext*>& rCreateStack); |
162 | | |
163 | | SAL_DLLPRIVATE sal_Int32 CreateAndInsert(SvNumberFormatter* pFormatter, std::vector<SvXMLNumFormatContext*>& rCreateStack); |
164 | | SAL_DLLPRIVATE void CreateAndInsert(bool bOverwrite, std::vector<SvXMLNumFormatContext*>& rCreateStack); |
165 | | |
166 | | public: |
167 | | SvXMLNumFormatContext( SvXMLImport& rImport, |
168 | | sal_Int32 nElement, |
169 | | SvXMLNumImpData* pNewData, |
170 | | SvXMLStylesTokens nNewType, |
171 | | const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList, |
172 | | SvXMLStylesContext& rStyles ); |
173 | | SvXMLNumFormatContext( SvXMLImport& rImport, |
174 | | const OUString& rName, |
175 | | const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList, |
176 | | const sal_Int32 nKey, |
177 | | LanguageType nLang, |
178 | | SvXMLStylesContext& rStyles ); |
179 | | virtual ~SvXMLNumFormatContext() override; |
180 | | |
181 | | virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( |
182 | | sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; |
183 | | virtual void CreateAndInsert(bool bOverwrite) override final; |
184 | | |
185 | | sal_Int32 GetKey(); |
186 | | sal_Int32 CreateAndInsert( css::uno::Reference< css::util::XNumberFormatsSupplier > const & xFormatsSupplier ); |
187 | 24.7k | SvXMLStylesTokens GetType() const { return m_nType; } // SvXMLStylesTokens |
188 | | |
189 | 14.2k | bool HasLongDoW() const { return m_bHasLongDoW; } |
190 | 7 | void SetHasLongDoW(bool bSet) { m_bHasLongDoW = bSet; } |
191 | 9 | void SetHasTrailingEmptyText(bool bSet) { m_bHasTrailingEmptyText = bSet; } |
192 | | |
193 | | void UpdateCalendar( const OUString& rNewCalendar ); |
194 | 910 | ImplicitCalendar GetImplicitCalendarState() const { return m_eImplicitCalendar; } |
195 | | |
196 | | const LocaleDataWrapper& GetLocaleData() const; |
197 | | |
198 | | void AddToCode( std::u16string_view rString ); |
199 | | void AddToCode( sal_Unicode c ); |
200 | | void AddNumber( const SvXMLNumberInfo& rInfo ); |
201 | | void AddCurrency( const OUString& rContent, LanguageType nLang ); |
202 | | |
203 | | void AddNfKeyword( sal_uInt16 nIndex ); |
204 | | bool ReplaceNfKeyword( sal_uInt16 nOld, sal_uInt16 nNew ); |
205 | | void AddCondition( const sal_Int32 nIndex ); |
206 | | void AddCondition( const OUString& rCondition, const OUString& rApplyName ); |
207 | | void AddColor( Color nColor ); |
208 | | |
209 | | /// determine whether number format uses the system language |
210 | | bool IsSystemLanguage() const; |
211 | | }; |
212 | | |
213 | | #endif |
214 | | |
215 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |