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 :
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 <com/sun/star/util/XNumberFormatsSupplier.hpp>
27 : #include <com/sun/star/xml/sax/XAttributeList.hpp>
28 : #include <xmloff/xmlstyle.hxx>
29 : #include <rtl/ustrbuf.hxx>
30 : #include <i18nlangtag/lang.h>
31 : #include <vector>
32 : #include <unotools/localedatawrapper.hxx>
33 :
34 : #define XML_NUMBERSTYLES "NumberStyles"
35 :
36 : enum SvXMLStylesTokens
37 : {
38 : XML_TOK_STYLES_NUMBER_STYLE,
39 : XML_TOK_STYLES_CURRENCY_STYLE,
40 : XML_TOK_STYLES_PERCENTAGE_STYLE,
41 : XML_TOK_STYLES_DATE_STYLE,
42 : XML_TOK_STYLES_TIME_STYLE,
43 : XML_TOK_STYLES_BOOLEAN_STYLE,
44 : XML_TOK_STYLES_TEXT_STYLE
45 : };
46 :
47 : enum SvXMLDateElementAttributes
48 : {
49 : XML_DEA_NONE,
50 : XML_DEA_ANY,
51 : XML_DEA_SHORT,
52 : XML_DEA_LONG,
53 : XML_DEA_TEXTSHORT,
54 : XML_DEA_TEXTLONG
55 : };
56 :
57 : class Color;
58 : class SvXMLNumImpData;
59 : class SvXMLImport;
60 : class SvXMLStyleContext;
61 : class SvXMLStylesContext;
62 : struct SvXMLNumberInfo;
63 : class SvNumberFormatter;
64 : class SvtSysLocale;
65 : namespace com { namespace sun { namespace star { namespace lang {
66 : class XMultiServiceFactory;
67 : }}}}
68 :
69 :
70 : // use SvXMLNumFmtHelper in the context for <office:styles> to create
71 : // child contexts for data styles
72 :
73 : class SvXMLNumFmtHelper
74 : {
75 : SvXMLNumImpData* pData;
76 :
77 : public:
78 : SvXMLNumFmtHelper(
79 : const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >& rSupp,
80 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext );
81 :
82 : SvXMLNumFmtHelper(
83 : SvNumberFormatter* pNumberFormatter,
84 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext );
85 :
86 : ~SvXMLNumFmtHelper();
87 :
88 : SvXMLStyleContext* CreateChildContext( SvXMLImport& rImport,
89 : sal_uInt16 nPrefix, const OUString& rLocalName,
90 : const ::com::sun::star::uno::Reference<
91 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
92 : SvXMLStylesContext& rStyles);
93 :
94 0 : SvXMLNumImpData* getData() { return pData; }
95 :
96 : const SvXMLTokenMap& GetStylesElemTokenMap();
97 :
98 : // sal_uInt32 GetKeyForName( const OUString& rName );
99 : };
100 :
101 : // SvXMLNumFmtDefaults is used in import and export
102 :
103 : class SvXMLNumFmtDefaults
104 : {
105 : public:
106 : // return value is NfIndexTableOffset
107 : static sal_uInt16 GetDefaultDateFormat( SvXMLDateElementAttributes eDOW,
108 : SvXMLDateElementAttributes eDay, SvXMLDateElementAttributes eMonth,
109 : SvXMLDateElementAttributes eYear, SvXMLDateElementAttributes eHours,
110 : SvXMLDateElementAttributes eMins, SvXMLDateElementAttributes eSecs,
111 : bool bSystem );
112 : };
113 :
114 0 : struct MyCondition
115 : {
116 : OUString sCondition;
117 : OUString sMapName;
118 : };
119 :
120 : class XMLOFF_DLLPUBLIC SvXMLNumFormatContext : public SvXMLStyleContext
121 : {
122 : SvXMLNumImpData* pData;
123 : SvXMLStylesContext* pStyles;
124 : std::vector <MyCondition> aMyConditions;
125 : sal_uInt16 nType;
126 : sal_Int32 nKey;
127 : // OUString sFormatName;
128 : OUString sFormatTitle;
129 : // OUString sMapName;
130 : OUString sCalendar;
131 : OUString sFormatString;
132 : LanguageType nFormatLang;
133 : com::sun::star::lang::Locale aLocale;
134 : bool bAutoOrder;
135 : bool bFromSystem;
136 : bool bTruncate;
137 : bool bAutoDec; // set in AddNumber
138 : bool bAutoInt; // set in AddNumber
139 : bool bHasExtraText;
140 : OUStringBuffer aFormatCode;
141 : OUStringBuffer aConditions;
142 : bool bHasLongDoW;
143 : bool bHasEra;
144 : bool bHasDateTime;
145 : bool bRemoveAfterUse;
146 :
147 : // contained date elements, used to recognize default date formats
148 : SvXMLDateElementAttributes eDateDOW;
149 : SvXMLDateElementAttributes eDateDay;
150 : SvXMLDateElementAttributes eDateMonth;
151 : SvXMLDateElementAttributes eDateYear;
152 : SvXMLDateElementAttributes eDateHours;
153 : SvXMLDateElementAttributes eDateMins;
154 : SvXMLDateElementAttributes eDateSecs;
155 : bool bDateNoDefault;
156 :
157 : SAL_DLLPRIVATE sal_Int32 PrivateGetKey();
158 :
159 : public:
160 : SvXMLNumFormatContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
161 : const OUString& rLName,
162 : SvXMLNumImpData* pNewData, sal_uInt16 nNewType,
163 : const ::com::sun::star::uno::Reference<
164 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
165 : SvXMLStylesContext& rStyles );
166 : SvXMLNumFormatContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
167 : const OUString& rLName,
168 : const ::com::sun::star::uno::Reference<
169 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
170 : const sal_Int32 nKey,
171 : SvXMLStylesContext& rStyles );
172 : virtual ~SvXMLNumFormatContext();
173 :
174 : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
175 : const OUString& rLocalName,
176 : const ::com::sun::star::uno::Reference<
177 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList ) SAL_OVERRIDE;
178 : virtual void CreateAndInsert(bool bOverwrite) SAL_OVERRIDE;
179 : virtual void Finish(bool bOverwrite) SAL_OVERRIDE;
180 :
181 0 : SvXMLNumImpData* GetData() const { return pData; }
182 : sal_Int32 GetKey();
183 : sal_Int32 CreateAndInsert( SvNumberFormatter* pFormatter );
184 : sal_Int32 CreateAndInsert( com::sun::star::uno::Reference< com::sun::star::util::XNumberFormatsSupplier >& xFormatsSupplier );
185 0 : sal_uInt16 GetType() const { return nType; } // SvXMLStylesTokens
186 :
187 : bool IsFromSystem() const { return bFromSystem; }
188 0 : bool HasLongDoW() const { return bHasLongDoW; }
189 0 : void SetHasLongDoW(bool bSet) { bHasLongDoW = bSet; }
190 0 : bool HasEra() const { return bHasEra; }
191 : void SetHasEra(bool bSet) { bHasEra = bSet; }
192 :
193 : void UpdateCalendar( const OUString& rNewCalendar );
194 :
195 : const LocaleDataWrapper& GetLocaleData() const;
196 :
197 : void AddToCode( const OUString& rString );
198 : void AddToCode( sal_Unicode c );
199 : void AddNumber( const SvXMLNumberInfo& rInfo );
200 : void AddCurrency( const OUString& rContent, LanguageType nLang );
201 :
202 : void AddNfKeyword( sal_uInt16 nIndex );
203 : bool ReplaceNfKeyword( sal_uInt16 nOld, sal_uInt16 nNew );
204 : void AddCondition( const sal_Int32 nIndex );
205 : void AddCondition( const OUString& rCondition, const OUString& rApplyName );
206 : void AddColor( sal_uInt32 const nColor );
207 :
208 : /// determine whether number format uses the system language
209 : bool IsSystemLanguage();
210 : };
211 :
212 : #endif
213 :
214 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|