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 2 : 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 2998 : 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 : LanguageType nFormatLang;
132 : com::sun::star::lang::Locale aLocale;
133 : bool bAutoOrder;
134 : bool bFromSystem;
135 : bool bTruncate;
136 : bool bAutoDec; // set in AddNumber
137 : bool bAutoInt; // set in AddNumber
138 : bool bHasExtraText;
139 : OUStringBuffer aFormatCode;
140 : OUStringBuffer aConditions;
141 : bool bHasLongDoW;
142 : bool bHasEra;
143 : bool bHasDateTime;
144 : bool bRemoveAfterUse;
145 :
146 : // contained date elements, used to recognize default date formats
147 : SvXMLDateElementAttributes eDateDOW;
148 : SvXMLDateElementAttributes eDateDay;
149 : SvXMLDateElementAttributes eDateMonth;
150 : SvXMLDateElementAttributes eDateYear;
151 : SvXMLDateElementAttributes eDateHours;
152 : SvXMLDateElementAttributes eDateMins;
153 : SvXMLDateElementAttributes eDateSecs;
154 : bool bDateNoDefault;
155 :
156 : SAL_DLLPRIVATE sal_Int32 PrivateGetKey();
157 :
158 : public:
159 : SvXMLNumFormatContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
160 : const OUString& rLName,
161 : SvXMLNumImpData* pNewData, sal_uInt16 nNewType,
162 : const ::com::sun::star::uno::Reference<
163 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
164 : SvXMLStylesContext& rStyles );
165 : SvXMLNumFormatContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
166 : const OUString& rLName,
167 : const ::com::sun::star::uno::Reference<
168 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
169 : const sal_Int32 nKey,
170 : SvXMLStylesContext& rStyles );
171 : virtual ~SvXMLNumFormatContext();
172 :
173 : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
174 : const OUString& rLocalName,
175 : const ::com::sun::star::uno::Reference<
176 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList ) SAL_OVERRIDE;
177 : virtual void CreateAndInsert(bool bOverwrite) SAL_OVERRIDE;
178 : virtual void Finish(bool bOverwrite) SAL_OVERRIDE;
179 :
180 5338 : SvXMLNumImpData* GetData() const { return pData; }
181 : sal_Int32 GetKey();
182 : sal_Int32 CreateAndInsert( SvNumberFormatter* pFormatter );
183 : sal_Int32 CreateAndInsert( com::sun::star::uno::Reference< com::sun::star::util::XNumberFormatsSupplier >& xFormatsSupplier );
184 2218 : sal_uInt16 GetType() const { return nType; } // SvXMLStylesTokens
185 :
186 : bool IsFromSystem() const { return bFromSystem; }
187 2038 : bool HasLongDoW() const { return bHasLongDoW; }
188 5 : void SetHasLongDoW(bool bSet) { bHasLongDoW = bSet; }
189 158 : bool HasEra() const { return bHasEra; }
190 : void SetHasEra(bool bSet) { bHasEra = bSet; }
191 :
192 : void UpdateCalendar( const OUString& rNewCalendar );
193 :
194 : const LocaleDataWrapper& GetLocaleData() const;
195 :
196 : void AddToCode( const OUString& rString );
197 : void AddToCode( sal_Unicode c );
198 : void AddNumber( const SvXMLNumberInfo& rInfo );
199 : void AddCurrency( const OUString& rContent, LanguageType nLang );
200 :
201 : void AddNfKeyword( sal_uInt16 nIndex );
202 : bool ReplaceNfKeyword( sal_uInt16 nOld, sal_uInt16 nNew );
203 : void AddCondition( const sal_Int32 nIndex );
204 : void AddCondition( const OUString& rCondition, const OUString& rApplyName );
205 : void AddColor( sal_uInt32 const nColor );
206 :
207 : /// determine whether number format uses the system language
208 : bool IsSystemLanguage();
209 : };
210 :
211 : #endif
212 :
213 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|