1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*63bba73cSAndrew Rist * distributed with this work for additional information
6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at
10*63bba73cSAndrew Rist *
11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist *
13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the
17*63bba73cSAndrew Rist * specific language governing permissions and limitations
18*63bba73cSAndrew Rist * under the License.
19*63bba73cSAndrew Rist *
20*63bba73cSAndrew Rist *************************************************************/
21*63bba73cSAndrew Rist
22*63bba73cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <unotools/syslocale.hxx>
28cdf0e10cSrcweir
29cdf0e10cSrcweir #define _ZFORLIST_DECLARE_TABLE
30cdf0e10cSrcweir #include <svl/zforlist.hxx>
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include <svl/zformat.hxx>
33cdf0e10cSrcweir #include <svl/numuno.hxx>
34cdf0e10cSrcweir #include <rtl/math.hxx>
35cdf0e10cSrcweir #include <i18npool/mslangid.hxx>
36cdf0e10cSrcweir #include <tools/debug.hxx>
37cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
38cdf0e10cSrcweir
39cdf0e10cSrcweir // #110680#
40cdf0e10cSrcweir //#include <comphelper/processfactory.hxx>
41cdf0e10cSrcweir
42cdf0e10cSrcweir #include <xmloff/xmlnumfi.hxx>
43cdf0e10cSrcweir #include <xmloff/xmltkmap.hxx>
44cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
45cdf0e10cSrcweir #include <xmloff/xmlictxt.hxx>
46cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
47cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
48cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
49cdf0e10cSrcweir #include <xmloff/families.hxx>
50cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
51cdf0e10cSrcweir
52cdf0e10cSrcweir using ::rtl::OUString;
53cdf0e10cSrcweir using ::rtl::OUStringBuffer;
54cdf0e10cSrcweir
55cdf0e10cSrcweir using namespace ::com::sun::star;
56cdf0e10cSrcweir using namespace ::xmloff::token;
57cdf0e10cSrcweir
58cdf0e10cSrcweir //-------------------------------------------------------------------------
59cdf0e10cSrcweir
60cdf0e10cSrcweir struct SvXMLNumFmtEntry
61cdf0e10cSrcweir {
62cdf0e10cSrcweir rtl::OUString aName;
63cdf0e10cSrcweir sal_uInt32 nKey;
64cdf0e10cSrcweir sal_Bool bRemoveAfterUse;
65cdf0e10cSrcweir
SvXMLNumFmtEntrySvXMLNumFmtEntry66cdf0e10cSrcweir SvXMLNumFmtEntry( const rtl::OUString& rN, sal_uInt32 nK, sal_Bool bR ) :
67cdf0e10cSrcweir aName(rN), nKey(nK), bRemoveAfterUse(bR) {}
68cdf0e10cSrcweir };
69cdf0e10cSrcweir
70cdf0e10cSrcweir typedef SvXMLNumFmtEntry* SvXMLNumFmtEntryPtr;
71cdf0e10cSrcweir SV_DECL_PTRARR_DEL( SvXMLNumFmtEntryArr, SvXMLNumFmtEntryPtr, 4, 4 )
72cdf0e10cSrcweir
73cdf0e10cSrcweir struct SvXMLEmbeddedElement
74cdf0e10cSrcweir {
75cdf0e10cSrcweir sal_Int32 nFormatPos;
76cdf0e10cSrcweir rtl::OUString aText;
77cdf0e10cSrcweir
SvXMLEmbeddedElementSvXMLEmbeddedElement78cdf0e10cSrcweir SvXMLEmbeddedElement( sal_Int32 nFP, const rtl::OUString& rT ) :
79cdf0e10cSrcweir nFormatPos(nFP), aText(rT) {}
80cdf0e10cSrcweir
81cdf0e10cSrcweir // comparison operators for PTRARR sorting - sorted by position
operator ==SvXMLEmbeddedElement82cdf0e10cSrcweir sal_Bool operator ==( const SvXMLEmbeddedElement& r ) const { return nFormatPos == r.nFormatPos; }
operator <SvXMLEmbeddedElement83cdf0e10cSrcweir sal_Bool operator < ( const SvXMLEmbeddedElement& r ) const { return nFormatPos < r.nFormatPos; }
84cdf0e10cSrcweir };
85cdf0e10cSrcweir
86cdf0e10cSrcweir typedef SvXMLEmbeddedElement* SvXMLEmbeddedElementPtr;
87cdf0e10cSrcweir SV_DECL_PTRARR_SORT_DEL( SvXMLEmbeddedElementArr, SvXMLEmbeddedElementPtr, 0, 4 )
88cdf0e10cSrcweir
89cdf0e10cSrcweir //-------------------------------------------------------------------------
90cdf0e10cSrcweir
91cdf0e10cSrcweir class SvXMLNumImpData
92cdf0e10cSrcweir {
93cdf0e10cSrcweir SvNumberFormatter* pFormatter;
94cdf0e10cSrcweir SvXMLTokenMap* pStylesElemTokenMap;
95cdf0e10cSrcweir SvXMLTokenMap* pStyleElemTokenMap;
96cdf0e10cSrcweir SvXMLTokenMap* pStyleAttrTokenMap;
97cdf0e10cSrcweir SvXMLTokenMap* pStyleElemAttrTokenMap;
98cdf0e10cSrcweir LocaleDataWrapper* pLocaleData;
99cdf0e10cSrcweir SvXMLNumFmtEntryArr aNameEntries;
100cdf0e10cSrcweir
101cdf0e10cSrcweir // #110680#
102cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxServiceFactory;
103cdf0e10cSrcweir
104cdf0e10cSrcweir public:
105cdf0e10cSrcweir // #110680#
106cdf0e10cSrcweir // SvXMLNumImpData( SvNumberFormatter* pFmt );
107cdf0e10cSrcweir SvXMLNumImpData(
108cdf0e10cSrcweir SvNumberFormatter* pFmt,
109cdf0e10cSrcweir const uno::Reference<lang::XMultiServiceFactory>& xServiceFactory );
110cdf0e10cSrcweir ~SvXMLNumImpData();
111cdf0e10cSrcweir
GetNumberFormatter() const112cdf0e10cSrcweir SvNumberFormatter* GetNumberFormatter() const { return pFormatter; }
113cdf0e10cSrcweir const SvXMLTokenMap& GetStylesElemTokenMap();
114cdf0e10cSrcweir const SvXMLTokenMap& GetStyleElemTokenMap();
115cdf0e10cSrcweir const SvXMLTokenMap& GetStyleAttrTokenMap();
116cdf0e10cSrcweir const SvXMLTokenMap& GetStyleElemAttrTokenMap();
117cdf0e10cSrcweir const LocaleDataWrapper& GetLocaleData( LanguageType nLang );
118cdf0e10cSrcweir sal_uInt32 GetKeyForName( const rtl::OUString& rName );
119cdf0e10cSrcweir void AddKey( sal_uInt32 nKey, const rtl::OUString& rName, sal_Bool bRemoveAfterUse );
120cdf0e10cSrcweir void SetUsed( sal_uInt32 nKey );
121cdf0e10cSrcweir void RemoveVolatileFormats();
122cdf0e10cSrcweir };
123cdf0e10cSrcweir
124cdf0e10cSrcweir
125cdf0e10cSrcweir struct SvXMLNumberInfo
126cdf0e10cSrcweir {
127cdf0e10cSrcweir sal_Int32 nDecimals;
128cdf0e10cSrcweir sal_Int32 nInteger;
129cdf0e10cSrcweir sal_Int32 nExpDigits;
130cdf0e10cSrcweir sal_Int32 nNumerDigits;
131cdf0e10cSrcweir sal_Int32 nDenomDigits;
132cdf0e10cSrcweir sal_Bool bGrouping;
133cdf0e10cSrcweir sal_Bool bDecReplace;
134cdf0e10cSrcweir sal_Bool bVarDecimals;
135cdf0e10cSrcweir double fDisplayFactor;
136cdf0e10cSrcweir SvXMLEmbeddedElementArr aEmbeddedElements;
137cdf0e10cSrcweir
SvXMLNumberInfoSvXMLNumberInfo138cdf0e10cSrcweir SvXMLNumberInfo()
139cdf0e10cSrcweir {
140cdf0e10cSrcweir nDecimals = nInteger = nExpDigits = nNumerDigits = nDenomDigits = -1;
141cdf0e10cSrcweir bGrouping = bDecReplace = bVarDecimals = sal_False;
142cdf0e10cSrcweir fDisplayFactor = 1.0;
143cdf0e10cSrcweir }
144cdf0e10cSrcweir };
145cdf0e10cSrcweir
146cdf0e10cSrcweir class SvXMLNumFmtElementContext : public SvXMLImportContext
147cdf0e10cSrcweir {
148cdf0e10cSrcweir SvXMLNumFormatContext& rParent;
149cdf0e10cSrcweir sal_uInt16 nType;
150cdf0e10cSrcweir rtl::OUStringBuffer aContent;
151cdf0e10cSrcweir SvXMLNumberInfo aNumInfo;
152cdf0e10cSrcweir LanguageType nElementLang;
153cdf0e10cSrcweir sal_Bool bLong;
154cdf0e10cSrcweir sal_Bool bTextual;
155cdf0e10cSrcweir rtl::OUString sCalendar;
156cdf0e10cSrcweir
157cdf0e10cSrcweir public:
158cdf0e10cSrcweir SvXMLNumFmtElementContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
159cdf0e10cSrcweir const rtl::OUString& rLName,
160cdf0e10cSrcweir SvXMLNumFormatContext& rParentContext, sal_uInt16 nNewType,
161cdf0e10cSrcweir const ::com::sun::star::uno::Reference<
162cdf0e10cSrcweir ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
163cdf0e10cSrcweir virtual ~SvXMLNumFmtElementContext();
164cdf0e10cSrcweir
165cdf0e10cSrcweir virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
166cdf0e10cSrcweir const rtl::OUString& rLocalName,
167cdf0e10cSrcweir const ::com::sun::star::uno::Reference<
168cdf0e10cSrcweir ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
169cdf0e10cSrcweir virtual void Characters( const rtl::OUString& rChars );
170cdf0e10cSrcweir virtual void EndElement();
171cdf0e10cSrcweir
172cdf0e10cSrcweir void AddEmbeddedElement( sal_Int32 nFormatPos, const rtl::OUString& rContent );
173cdf0e10cSrcweir };
174cdf0e10cSrcweir
175cdf0e10cSrcweir
176cdf0e10cSrcweir class SvXMLNumFmtEmbeddedTextContext : public SvXMLImportContext
177cdf0e10cSrcweir {
178cdf0e10cSrcweir SvXMLNumFmtElementContext& rParent;
179cdf0e10cSrcweir rtl::OUStringBuffer aContent;
180cdf0e10cSrcweir sal_Int32 nTextPosition;
181cdf0e10cSrcweir
182cdf0e10cSrcweir public:
183cdf0e10cSrcweir SvXMLNumFmtEmbeddedTextContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
184cdf0e10cSrcweir const rtl::OUString& rLName,
185cdf0e10cSrcweir SvXMLNumFmtElementContext& rParentContext,
186cdf0e10cSrcweir const ::com::sun::star::uno::Reference<
187cdf0e10cSrcweir ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
188cdf0e10cSrcweir virtual ~SvXMLNumFmtEmbeddedTextContext();
189cdf0e10cSrcweir
190cdf0e10cSrcweir virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
191cdf0e10cSrcweir const rtl::OUString& rLocalName,
192cdf0e10cSrcweir const ::com::sun::star::uno::Reference<
193cdf0e10cSrcweir ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
194cdf0e10cSrcweir virtual void Characters( const rtl::OUString& rChars );
195cdf0e10cSrcweir virtual void EndElement();
196cdf0e10cSrcweir };
197cdf0e10cSrcweir
198cdf0e10cSrcweir
199cdf0e10cSrcweir class SvXMLNumFmtMapContext : public SvXMLImportContext
200cdf0e10cSrcweir {
201cdf0e10cSrcweir SvXMLNumFormatContext& rParent;
202cdf0e10cSrcweir rtl::OUString sCondition;
203cdf0e10cSrcweir rtl::OUString sName;
204cdf0e10cSrcweir
205cdf0e10cSrcweir public:
206cdf0e10cSrcweir SvXMLNumFmtMapContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
207cdf0e10cSrcweir const rtl::OUString& rLName,
208cdf0e10cSrcweir SvXMLNumFormatContext& rParentContext,
209cdf0e10cSrcweir const ::com::sun::star::uno::Reference<
210cdf0e10cSrcweir ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
211cdf0e10cSrcweir virtual ~SvXMLNumFmtMapContext();
212cdf0e10cSrcweir
213cdf0e10cSrcweir virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
214cdf0e10cSrcweir const rtl::OUString& rLocalName,
215cdf0e10cSrcweir const ::com::sun::star::uno::Reference<
216cdf0e10cSrcweir ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
217cdf0e10cSrcweir virtual void Characters( const rtl::OUString& rChars );
218cdf0e10cSrcweir virtual void EndElement();
219cdf0e10cSrcweir };
220cdf0e10cSrcweir
221cdf0e10cSrcweir
222cdf0e10cSrcweir class SvXMLNumFmtPropContext : public SvXMLImportContext
223cdf0e10cSrcweir {
224cdf0e10cSrcweir SvXMLNumFormatContext& rParent;
225cdf0e10cSrcweir Color aColor;
226cdf0e10cSrcweir sal_Bool bColSet;
227cdf0e10cSrcweir
228cdf0e10cSrcweir public:
229cdf0e10cSrcweir SvXMLNumFmtPropContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
230cdf0e10cSrcweir const rtl::OUString& rLName,
231cdf0e10cSrcweir SvXMLNumFormatContext& rParentContext,
232cdf0e10cSrcweir const ::com::sun::star::uno::Reference<
233cdf0e10cSrcweir ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
234cdf0e10cSrcweir virtual ~SvXMLNumFmtPropContext();
235cdf0e10cSrcweir
236cdf0e10cSrcweir virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
237cdf0e10cSrcweir const rtl::OUString& rLocalName,
238cdf0e10cSrcweir const ::com::sun::star::uno::Reference<
239cdf0e10cSrcweir ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
240cdf0e10cSrcweir virtual void Characters( const rtl::OUString& rChars );
241cdf0e10cSrcweir virtual void EndElement();
242cdf0e10cSrcweir };
243cdf0e10cSrcweir
244cdf0e10cSrcweir
245cdf0e10cSrcweir //-------------------------------------------------------------------------
246cdf0e10cSrcweir
247cdf0e10cSrcweir enum SvXMLStyleTokens
248cdf0e10cSrcweir {
249cdf0e10cSrcweir XML_TOK_STYLE_TEXT,
250cdf0e10cSrcweir XML_TOK_STYLE_NUMBER,
251cdf0e10cSrcweir XML_TOK_STYLE_SCIENTIFIC_NUMBER,
252cdf0e10cSrcweir XML_TOK_STYLE_FRACTION,
253cdf0e10cSrcweir XML_TOK_STYLE_CURRENCY_SYMBOL,
254cdf0e10cSrcweir XML_TOK_STYLE_DAY,
255cdf0e10cSrcweir XML_TOK_STYLE_MONTH,
256cdf0e10cSrcweir XML_TOK_STYLE_YEAR,
257cdf0e10cSrcweir XML_TOK_STYLE_ERA,
258cdf0e10cSrcweir XML_TOK_STYLE_DAY_OF_WEEK,
259cdf0e10cSrcweir XML_TOK_STYLE_WEEK_OF_YEAR,
260cdf0e10cSrcweir XML_TOK_STYLE_QUARTER,
261cdf0e10cSrcweir XML_TOK_STYLE_HOURS,
262cdf0e10cSrcweir XML_TOK_STYLE_AM_PM,
263cdf0e10cSrcweir XML_TOK_STYLE_MINUTES,
264cdf0e10cSrcweir XML_TOK_STYLE_SECONDS,
265cdf0e10cSrcweir XML_TOK_STYLE_BOOLEAN,
266cdf0e10cSrcweir XML_TOK_STYLE_TEXT_CONTENT,
267cdf0e10cSrcweir XML_TOK_STYLE_PROPERTIES,
268cdf0e10cSrcweir XML_TOK_STYLE_MAP
269cdf0e10cSrcweir };
270cdf0e10cSrcweir
271cdf0e10cSrcweir enum SvXMLStyleAttrTokens
272cdf0e10cSrcweir {
273cdf0e10cSrcweir XML_TOK_STYLE_ATTR_NAME,
274cdf0e10cSrcweir XML_TOK_STYLE_ATTR_LANGUAGE,
275cdf0e10cSrcweir XML_TOK_STYLE_ATTR_COUNTRY,
276cdf0e10cSrcweir XML_TOK_STYLE_ATTR_TITLE,
277cdf0e10cSrcweir XML_TOK_STYLE_ATTR_AUTOMATIC_ORDER,
278cdf0e10cSrcweir XML_TOK_STYLE_ATTR_FORMAT_SOURCE,
279cdf0e10cSrcweir XML_TOK_STYLE_ATTR_TRUNCATE_ON_OVERFLOW,
280cdf0e10cSrcweir XML_TOK_STYLE_ATTR_VOLATILE,
281cdf0e10cSrcweir XML_TOK_STYLE_ATTR_TRANSL_FORMAT,
282cdf0e10cSrcweir XML_TOK_STYLE_ATTR_TRANSL_LANGUAGE,
283cdf0e10cSrcweir XML_TOK_STYLE_ATTR_TRANSL_COUNTRY,
284cdf0e10cSrcweir XML_TOK_STYLE_ATTR_TRANSL_STYLE
285cdf0e10cSrcweir };
286cdf0e10cSrcweir
287cdf0e10cSrcweir enum SvXMLStyleElemAttrTokens
288cdf0e10cSrcweir {
289cdf0e10cSrcweir XML_TOK_ELEM_ATTR_DECIMAL_PLACES,
290cdf0e10cSrcweir XML_TOK_ELEM_ATTR_MIN_INTEGER_DIGITS,
291cdf0e10cSrcweir XML_TOK_ELEM_ATTR_GROUPING,
292cdf0e10cSrcweir XML_TOK_ELEM_ATTR_DISPLAY_FACTOR,
293cdf0e10cSrcweir XML_TOK_ELEM_ATTR_DECIMAL_REPLACEMENT,
294cdf0e10cSrcweir XML_TOK_ELEM_ATTR_MIN_EXPONENT_DIGITS,
295cdf0e10cSrcweir XML_TOK_ELEM_ATTR_MIN_NUMERATOR_DIGITS,
296cdf0e10cSrcweir XML_TOK_ELEM_ATTR_MIN_DENOMINATOR_DIGITS,
297cdf0e10cSrcweir XML_TOK_ELEM_ATTR_LANGUAGE,
298cdf0e10cSrcweir XML_TOK_ELEM_ATTR_COUNTRY,
299cdf0e10cSrcweir XML_TOK_ELEM_ATTR_STYLE,
300cdf0e10cSrcweir XML_TOK_ELEM_ATTR_TEXTUAL,
301cdf0e10cSrcweir XML_TOK_ELEM_ATTR_CALENDAR
302cdf0e10cSrcweir };
303cdf0e10cSrcweir
304cdf0e10cSrcweir //-------------------------------------------------------------------------
305cdf0e10cSrcweir
306cdf0e10cSrcweir //
307cdf0e10cSrcweir // standard colors
308cdf0e10cSrcweir //
309cdf0e10cSrcweir
310cdf0e10cSrcweir #define XML_NUMF_COLORCOUNT 10
311cdf0e10cSrcweir
312cdf0e10cSrcweir static ColorData aNumFmtStdColors[XML_NUMF_COLORCOUNT] =
313cdf0e10cSrcweir {
314cdf0e10cSrcweir COL_BLACK,
315cdf0e10cSrcweir COL_LIGHTBLUE,
316cdf0e10cSrcweir COL_LIGHTGREEN,
317cdf0e10cSrcweir COL_LIGHTCYAN,
318cdf0e10cSrcweir COL_LIGHTRED,
319cdf0e10cSrcweir COL_LIGHTMAGENTA,
320cdf0e10cSrcweir COL_BROWN,
321cdf0e10cSrcweir COL_GRAY,
322cdf0e10cSrcweir COL_YELLOW,
323cdf0e10cSrcweir COL_WHITE
324cdf0e10cSrcweir };
325cdf0e10cSrcweir
326cdf0e10cSrcweir //
327cdf0e10cSrcweir // token maps
328cdf0e10cSrcweir //
329cdf0e10cSrcweir
330cdf0e10cSrcweir // maps for SvXMLUnitConverter::convertEnum
331cdf0e10cSrcweir
332cdf0e10cSrcweir static __FAR_DATA SvXMLEnumMapEntry aStyleValueMap[] =
333cdf0e10cSrcweir {
334cdf0e10cSrcweir { XML_SHORT, sal_False },
335cdf0e10cSrcweir { XML_LONG, sal_True },
336cdf0e10cSrcweir { XML_TOKEN_INVALID, 0 }
337cdf0e10cSrcweir };
338cdf0e10cSrcweir
339cdf0e10cSrcweir static __FAR_DATA SvXMLEnumMapEntry aFormatSourceMap[] =
340cdf0e10cSrcweir {
341cdf0e10cSrcweir { XML_FIXED, sal_False },
342cdf0e10cSrcweir { XML_LANGUAGE, sal_True },
343cdf0e10cSrcweir { XML_TOKEN_INVALID, 0 }
344cdf0e10cSrcweir };
345cdf0e10cSrcweir
346cdf0e10cSrcweir //-------------------------------------------------------------------------
347cdf0e10cSrcweir
348cdf0e10cSrcweir struct SvXMLDefaultDateFormat
349cdf0e10cSrcweir {
350cdf0e10cSrcweir NfIndexTableOffset eFormat;
351cdf0e10cSrcweir SvXMLDateElementAttributes eDOW;
352cdf0e10cSrcweir SvXMLDateElementAttributes eDay;
353cdf0e10cSrcweir SvXMLDateElementAttributes eMonth;
354cdf0e10cSrcweir SvXMLDateElementAttributes eYear;
355cdf0e10cSrcweir SvXMLDateElementAttributes eHours;
356cdf0e10cSrcweir SvXMLDateElementAttributes eMins;
357cdf0e10cSrcweir SvXMLDateElementAttributes eSecs;
358cdf0e10cSrcweir sal_Bool bSystem;
359cdf0e10cSrcweir };
360cdf0e10cSrcweir
361cdf0e10cSrcweir static __FAR_DATA SvXMLDefaultDateFormat aDefaultDateFormats[] =
362cdf0e10cSrcweir {
363cdf0e10cSrcweir // format day-of-week day month year hours minutes seconds format-source
364cdf0e10cSrcweir
365cdf0e10cSrcweir { NF_DATE_SYSTEM_SHORT, XML_DEA_NONE, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, sal_True },
366cdf0e10cSrcweir { NF_DATE_SYSTEM_LONG, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, sal_True },
367cdf0e10cSrcweir { NF_DATE_SYS_MMYY, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_LONG, XML_DEA_SHORT, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, sal_False },
368cdf0e10cSrcweir { NF_DATE_SYS_DDMMM, XML_DEA_NONE, XML_DEA_LONG, XML_DEA_TEXTSHORT, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, sal_False },
369cdf0e10cSrcweir { NF_DATE_SYS_DDMMYYYY, XML_DEA_NONE, XML_DEA_LONG, XML_DEA_LONG, XML_DEA_LONG, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, sal_False },
370cdf0e10cSrcweir { NF_DATE_SYS_DDMMYY, XML_DEA_NONE, XML_DEA_LONG, XML_DEA_LONG, XML_DEA_SHORT, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, sal_False },
371cdf0e10cSrcweir { NF_DATE_SYS_DMMMYY, XML_DEA_NONE, XML_DEA_SHORT, XML_DEA_TEXTSHORT, XML_DEA_SHORT, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, sal_False },
372cdf0e10cSrcweir { NF_DATE_SYS_DMMMYYYY, XML_DEA_NONE, XML_DEA_SHORT, XML_DEA_TEXTSHORT, XML_DEA_LONG, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, sal_False },
373cdf0e10cSrcweir { NF_DATE_SYS_DMMMMYYYY, XML_DEA_NONE, XML_DEA_SHORT, XML_DEA_TEXTLONG, XML_DEA_LONG, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, sal_False },
374cdf0e10cSrcweir { NF_DATE_SYS_NNDMMMYY, XML_DEA_SHORT, XML_DEA_SHORT, XML_DEA_TEXTSHORT, XML_DEA_SHORT, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, sal_False },
375cdf0e10cSrcweir { NF_DATE_SYS_NNDMMMMYYYY, XML_DEA_SHORT, XML_DEA_SHORT, XML_DEA_TEXTLONG, XML_DEA_LONG, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, sal_False },
376cdf0e10cSrcweir { NF_DATE_SYS_NNNNDMMMMYYYY, XML_DEA_LONG, XML_DEA_SHORT, XML_DEA_TEXTLONG, XML_DEA_LONG, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, sal_False },
377cdf0e10cSrcweir { NF_DATETIME_SYSTEM_SHORT_HHMM, XML_DEA_NONE, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_NONE, sal_True },
378cdf0e10cSrcweir { NF_DATETIME_SYS_DDMMYYYY_HHMMSS, XML_DEA_NONE, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_ANY, sal_False }
379cdf0e10cSrcweir };
380cdf0e10cSrcweir
381cdf0e10cSrcweir //-------------------------------------------------------------------------
382cdf0e10cSrcweir
383cdf0e10cSrcweir SV_IMPL_PTRARR( SvXMLNumFmtEntryArr, SvXMLNumFmtEntryPtr );
384cdf0e10cSrcweir SV_IMPL_OP_PTRARR_SORT( SvXMLEmbeddedElementArr, SvXMLEmbeddedElementPtr );
385cdf0e10cSrcweir
386cdf0e10cSrcweir //-------------------------------------------------------------------------
387cdf0e10cSrcweir
388cdf0e10cSrcweir //
389cdf0e10cSrcweir // SvXMLNumImpData
390cdf0e10cSrcweir //
391cdf0e10cSrcweir
392cdf0e10cSrcweir // #110680#
393cdf0e10cSrcweir // SvXMLNumImpData::SvXMLNumImpData( SvNumberFormatter* pFmt ) :
SvXMLNumImpData(SvNumberFormatter * pFmt,const uno::Reference<lang::XMultiServiceFactory> & xServiceFactory)394cdf0e10cSrcweir SvXMLNumImpData::SvXMLNumImpData(
395cdf0e10cSrcweir SvNumberFormatter* pFmt,
396cdf0e10cSrcweir const uno::Reference<lang::XMultiServiceFactory>& xServiceFactory )
397cdf0e10cSrcweir : pFormatter(pFmt),
398cdf0e10cSrcweir pStylesElemTokenMap(NULL),
399cdf0e10cSrcweir pStyleElemTokenMap(NULL),
400cdf0e10cSrcweir pStyleAttrTokenMap(NULL),
401cdf0e10cSrcweir pStyleElemAttrTokenMap(NULL),
402cdf0e10cSrcweir pLocaleData(NULL),
403cdf0e10cSrcweir
404cdf0e10cSrcweir // #110680#
405cdf0e10cSrcweir mxServiceFactory(xServiceFactory)
406cdf0e10cSrcweir {
407cdf0e10cSrcweir DBG_ASSERT( mxServiceFactory.is(), "got no service manager" );
408cdf0e10cSrcweir }
409cdf0e10cSrcweir
~SvXMLNumImpData()410cdf0e10cSrcweir SvXMLNumImpData::~SvXMLNumImpData()
411cdf0e10cSrcweir {
412cdf0e10cSrcweir delete pStylesElemTokenMap;
413cdf0e10cSrcweir delete pStyleElemTokenMap;
414cdf0e10cSrcweir delete pStyleAttrTokenMap;
415cdf0e10cSrcweir delete pStyleElemAttrTokenMap;
416cdf0e10cSrcweir delete pLocaleData;
417cdf0e10cSrcweir }
418cdf0e10cSrcweir
GetKeyForName(const rtl::OUString & rName)419cdf0e10cSrcweir sal_uInt32 SvXMLNumImpData::GetKeyForName( const rtl::OUString& rName )
420cdf0e10cSrcweir {
421cdf0e10cSrcweir sal_uInt16 nCount = aNameEntries.Count();
422cdf0e10cSrcweir for (sal_uInt16 i=0; i<nCount; i++)
423cdf0e10cSrcweir {
424cdf0e10cSrcweir const SvXMLNumFmtEntry* pObj = aNameEntries[i];
425cdf0e10cSrcweir if ( pObj->aName == rName )
426cdf0e10cSrcweir return pObj->nKey; // found
427cdf0e10cSrcweir }
428cdf0e10cSrcweir return NUMBERFORMAT_ENTRY_NOT_FOUND;
429cdf0e10cSrcweir }
430cdf0e10cSrcweir
AddKey(sal_uInt32 nKey,const rtl::OUString & rName,sal_Bool bRemoveAfterUse)431cdf0e10cSrcweir void SvXMLNumImpData::AddKey( sal_uInt32 nKey, const rtl::OUString& rName, sal_Bool bRemoveAfterUse )
432cdf0e10cSrcweir {
433cdf0e10cSrcweir if ( bRemoveAfterUse )
434cdf0e10cSrcweir {
435cdf0e10cSrcweir // if there is already an entry for this key without the bRemoveAfterUse flag,
436cdf0e10cSrcweir // clear the flag for this entry, too
437cdf0e10cSrcweir
438cdf0e10cSrcweir sal_uInt16 nCount = aNameEntries.Count();
439cdf0e10cSrcweir for (sal_uInt16 i=0; i<nCount; i++)
440cdf0e10cSrcweir {
441cdf0e10cSrcweir SvXMLNumFmtEntry* pObj = aNameEntries[i];
442cdf0e10cSrcweir if ( pObj->nKey == nKey && !pObj->bRemoveAfterUse )
443cdf0e10cSrcweir {
444cdf0e10cSrcweir bRemoveAfterUse = sal_False; // clear flag for new entry
445cdf0e10cSrcweir break;
446cdf0e10cSrcweir }
447cdf0e10cSrcweir }
448cdf0e10cSrcweir }
449cdf0e10cSrcweir else
450cdf0e10cSrcweir {
451cdf0e10cSrcweir // call SetUsed to clear the bRemoveAfterUse flag for other entries for this key
452cdf0e10cSrcweir SetUsed( nKey );
453cdf0e10cSrcweir }
454cdf0e10cSrcweir
455cdf0e10cSrcweir SvXMLNumFmtEntry* pObj = new SvXMLNumFmtEntry( rName, nKey, bRemoveAfterUse );
456cdf0e10cSrcweir aNameEntries.Insert( pObj, aNameEntries.Count() );
457cdf0e10cSrcweir }
458cdf0e10cSrcweir
SetUsed(sal_uInt32 nKey)459cdf0e10cSrcweir void SvXMLNumImpData::SetUsed( sal_uInt32 nKey )
460cdf0e10cSrcweir {
461cdf0e10cSrcweir sal_uInt16 nCount = aNameEntries.Count();
462cdf0e10cSrcweir for (sal_uInt16 i=0; i<nCount; i++)
463cdf0e10cSrcweir {
464cdf0e10cSrcweir SvXMLNumFmtEntry* pObj = aNameEntries[i];
465cdf0e10cSrcweir if ( pObj->nKey == nKey )
466cdf0e10cSrcweir {
467cdf0e10cSrcweir pObj->bRemoveAfterUse = sal_False; // used -> don't remove
468cdf0e10cSrcweir
469cdf0e10cSrcweir // continue searching - there may be several entries for the same key
470cdf0e10cSrcweir // (with different names), the format must not be deleted if any one of
471cdf0e10cSrcweir // them is used
472cdf0e10cSrcweir }
473cdf0e10cSrcweir }
474cdf0e10cSrcweir }
475cdf0e10cSrcweir
RemoveVolatileFormats()476cdf0e10cSrcweir void SvXMLNumImpData::RemoveVolatileFormats()
477cdf0e10cSrcweir {
478cdf0e10cSrcweir // remove temporary (volatile) formats from NumberFormatter
479cdf0e10cSrcweir // called at the end of each import (styles and content), so volatile formats
480cdf0e10cSrcweir // from styles can't be used in content
481cdf0e10cSrcweir
482cdf0e10cSrcweir if ( !pFormatter )
483cdf0e10cSrcweir return;
484cdf0e10cSrcweir
485cdf0e10cSrcweir sal_uInt16 nCount = aNameEntries.Count();
486cdf0e10cSrcweir for (sal_uInt16 i=0; i<nCount; i++)
487cdf0e10cSrcweir {
488cdf0e10cSrcweir const SvXMLNumFmtEntry* pObj = aNameEntries[i];
489cdf0e10cSrcweir if ( pObj->bRemoveAfterUse )
490cdf0e10cSrcweir {
491cdf0e10cSrcweir const SvNumberformat* pFormat = pFormatter->GetEntry(pObj->nKey);
492cdf0e10cSrcweir if (pFormat && (pFormat->GetType() & NUMBERFORMAT_DEFINED))
493cdf0e10cSrcweir pFormatter->DeleteEntry( pObj->nKey );
494cdf0e10cSrcweir }
495cdf0e10cSrcweir }
496cdf0e10cSrcweir }
497cdf0e10cSrcweir
GetStylesElemTokenMap()498cdf0e10cSrcweir const SvXMLTokenMap& SvXMLNumImpData::GetStylesElemTokenMap()
499cdf0e10cSrcweir {
500cdf0e10cSrcweir if( !pStylesElemTokenMap )
501cdf0e10cSrcweir {
502cdf0e10cSrcweir static __FAR_DATA SvXMLTokenMapEntry aStylesElemMap[] =
503cdf0e10cSrcweir {
504cdf0e10cSrcweir // style elements
505cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_NUMBER_STYLE, XML_TOK_STYLES_NUMBER_STYLE },
506cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_CURRENCY_STYLE, XML_TOK_STYLES_CURRENCY_STYLE },
507cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_PERCENTAGE_STYLE, XML_TOK_STYLES_PERCENTAGE_STYLE },
508cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_DATE_STYLE, XML_TOK_STYLES_DATE_STYLE },
509cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_TIME_STYLE, XML_TOK_STYLES_TIME_STYLE },
510cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_BOOLEAN_STYLE, XML_TOK_STYLES_BOOLEAN_STYLE },
511cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_TEXT_STYLE, XML_TOK_STYLES_TEXT_STYLE },
512cdf0e10cSrcweir XML_TOKEN_MAP_END
513cdf0e10cSrcweir };
514cdf0e10cSrcweir
515cdf0e10cSrcweir pStylesElemTokenMap = new SvXMLTokenMap( aStylesElemMap );
516cdf0e10cSrcweir }
517cdf0e10cSrcweir return *pStylesElemTokenMap;
518cdf0e10cSrcweir }
519cdf0e10cSrcweir
GetStyleElemTokenMap()520cdf0e10cSrcweir const SvXMLTokenMap& SvXMLNumImpData::GetStyleElemTokenMap()
521cdf0e10cSrcweir {
522cdf0e10cSrcweir if( !pStyleElemTokenMap )
523cdf0e10cSrcweir {
524cdf0e10cSrcweir static __FAR_DATA SvXMLTokenMapEntry aStyleElemMap[] =
525cdf0e10cSrcweir {
526cdf0e10cSrcweir // elements in a style
527cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_TEXT, XML_TOK_STYLE_TEXT },
528cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_NUMBER, XML_TOK_STYLE_NUMBER },
529cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_SCIENTIFIC_NUMBER, XML_TOK_STYLE_SCIENTIFIC_NUMBER },
530cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_FRACTION, XML_TOK_STYLE_FRACTION },
531cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_CURRENCY_SYMBOL, XML_TOK_STYLE_CURRENCY_SYMBOL },
532cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_DAY, XML_TOK_STYLE_DAY },
533cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_MONTH, XML_TOK_STYLE_MONTH },
534cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_YEAR, XML_TOK_STYLE_YEAR },
535cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_ERA, XML_TOK_STYLE_ERA },
536cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_DAY_OF_WEEK, XML_TOK_STYLE_DAY_OF_WEEK },
537cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_WEEK_OF_YEAR, XML_TOK_STYLE_WEEK_OF_YEAR },
538cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_QUARTER, XML_TOK_STYLE_QUARTER },
539cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_HOURS, XML_TOK_STYLE_HOURS },
540cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_AM_PM, XML_TOK_STYLE_AM_PM },
541cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_MINUTES, XML_TOK_STYLE_MINUTES },
542cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_SECONDS, XML_TOK_STYLE_SECONDS },
543cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_BOOLEAN, XML_TOK_STYLE_BOOLEAN },
544cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_TEXT_CONTENT, XML_TOK_STYLE_TEXT_CONTENT },
545cdf0e10cSrcweir { XML_NAMESPACE_STYLE, XML_TEXT_PROPERTIES, XML_TOK_STYLE_PROPERTIES },
546cdf0e10cSrcweir { XML_NAMESPACE_STYLE, XML_MAP, XML_TOK_STYLE_MAP },
547cdf0e10cSrcweir XML_TOKEN_MAP_END
548cdf0e10cSrcweir };
549cdf0e10cSrcweir
550cdf0e10cSrcweir pStyleElemTokenMap = new SvXMLTokenMap( aStyleElemMap );
551cdf0e10cSrcweir }
552cdf0e10cSrcweir return *pStyleElemTokenMap;
553cdf0e10cSrcweir }
554cdf0e10cSrcweir
GetStyleAttrTokenMap()555cdf0e10cSrcweir const SvXMLTokenMap& SvXMLNumImpData::GetStyleAttrTokenMap()
556cdf0e10cSrcweir {
557cdf0e10cSrcweir if( !pStyleAttrTokenMap )
558cdf0e10cSrcweir {
559cdf0e10cSrcweir static __FAR_DATA SvXMLTokenMapEntry aStyleAttrMap[] =
560cdf0e10cSrcweir {
561cdf0e10cSrcweir // attributes for a style
562cdf0e10cSrcweir { XML_NAMESPACE_STYLE, XML_NAME, XML_TOK_STYLE_ATTR_NAME },
563cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_LANGUAGE, XML_TOK_STYLE_ATTR_LANGUAGE },
564cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_COUNTRY, XML_TOK_STYLE_ATTR_COUNTRY },
565cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_TITLE, XML_TOK_STYLE_ATTR_TITLE },
566cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_AUTOMATIC_ORDER, XML_TOK_STYLE_ATTR_AUTOMATIC_ORDER },
567cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_FORMAT_SOURCE, XML_TOK_STYLE_ATTR_FORMAT_SOURCE },
568cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_TRUNCATE_ON_OVERFLOW, XML_TOK_STYLE_ATTR_TRUNCATE_ON_OVERFLOW },
569cdf0e10cSrcweir { XML_NAMESPACE_STYLE, XML_VOLATILE, XML_TOK_STYLE_ATTR_VOLATILE },
570cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_TRANSLITERATION_FORMAT, XML_TOK_STYLE_ATTR_TRANSL_FORMAT },
571cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_TRANSLITERATION_LANGUAGE, XML_TOK_STYLE_ATTR_TRANSL_LANGUAGE },
572cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_TRANSLITERATION_COUNTRY, XML_TOK_STYLE_ATTR_TRANSL_COUNTRY },
573cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_TRANSLITERATION_STYLE, XML_TOK_STYLE_ATTR_TRANSL_STYLE },
574cdf0e10cSrcweir XML_TOKEN_MAP_END
575cdf0e10cSrcweir };
576cdf0e10cSrcweir
577cdf0e10cSrcweir pStyleAttrTokenMap = new SvXMLTokenMap( aStyleAttrMap );
578cdf0e10cSrcweir }
579cdf0e10cSrcweir return *pStyleAttrTokenMap;
580cdf0e10cSrcweir }
581cdf0e10cSrcweir
GetStyleElemAttrTokenMap()582cdf0e10cSrcweir const SvXMLTokenMap& SvXMLNumImpData::GetStyleElemAttrTokenMap()
583cdf0e10cSrcweir {
584cdf0e10cSrcweir if( !pStyleElemAttrTokenMap )
585cdf0e10cSrcweir {
586cdf0e10cSrcweir static __FAR_DATA SvXMLTokenMapEntry aStyleElemAttrMap[] =
587cdf0e10cSrcweir {
588cdf0e10cSrcweir // attributes for an element within a style
589cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_DECIMAL_PLACES, XML_TOK_ELEM_ATTR_DECIMAL_PLACES },
590cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_MIN_INTEGER_DIGITS, XML_TOK_ELEM_ATTR_MIN_INTEGER_DIGITS },
591cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_GROUPING, XML_TOK_ELEM_ATTR_GROUPING },
592cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_DISPLAY_FACTOR, XML_TOK_ELEM_ATTR_DISPLAY_FACTOR },
593cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_DECIMAL_REPLACEMENT, XML_TOK_ELEM_ATTR_DECIMAL_REPLACEMENT },
594cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_MIN_EXPONENT_DIGITS, XML_TOK_ELEM_ATTR_MIN_EXPONENT_DIGITS },
595cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_MIN_NUMERATOR_DIGITS, XML_TOK_ELEM_ATTR_MIN_NUMERATOR_DIGITS },
596cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_MIN_DENOMINATOR_DIGITS, XML_TOK_ELEM_ATTR_MIN_DENOMINATOR_DIGITS },
597cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_LANGUAGE, XML_TOK_ELEM_ATTR_LANGUAGE },
598cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_COUNTRY, XML_TOK_ELEM_ATTR_COUNTRY },
599cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_STYLE, XML_TOK_ELEM_ATTR_STYLE },
600cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_TEXTUAL, XML_TOK_ELEM_ATTR_TEXTUAL },
601cdf0e10cSrcweir { XML_NAMESPACE_NUMBER, XML_CALENDAR, XML_TOK_ELEM_ATTR_CALENDAR },
602cdf0e10cSrcweir XML_TOKEN_MAP_END
603cdf0e10cSrcweir };
604cdf0e10cSrcweir
605cdf0e10cSrcweir pStyleElemAttrTokenMap = new SvXMLTokenMap( aStyleElemAttrMap );
606cdf0e10cSrcweir }
607cdf0e10cSrcweir return *pStyleElemAttrTokenMap;
608cdf0e10cSrcweir }
609cdf0e10cSrcweir
GetLocaleData(LanguageType nLang)610cdf0e10cSrcweir const LocaleDataWrapper& SvXMLNumImpData::GetLocaleData( LanguageType nLang )
611cdf0e10cSrcweir {
612cdf0e10cSrcweir if ( !pLocaleData )
613cdf0e10cSrcweir // #110680#
614cdf0e10cSrcweir //pLocaleData = new LocaleDataWrapper(
615cdf0e10cSrcweir // (pFormatter ? pFormatter->GetServiceManager() :
616cdf0e10cSrcweir // ::comphelper::getProcessServiceFactory()),
617cdf0e10cSrcweir // MsLangId::convertLanguageToLocale( nLang ) );
618cdf0e10cSrcweir pLocaleData = new LocaleDataWrapper(
619cdf0e10cSrcweir (pFormatter ? pFormatter->GetServiceManager() :
620cdf0e10cSrcweir mxServiceFactory),
621cdf0e10cSrcweir MsLangId::convertLanguageToLocale( nLang ) );
622cdf0e10cSrcweir else
623cdf0e10cSrcweir pLocaleData->setLocale( MsLangId::convertLanguageToLocale( nLang ) );
624cdf0e10cSrcweir return *pLocaleData;
625cdf0e10cSrcweir }
626cdf0e10cSrcweir
627cdf0e10cSrcweir //-------------------------------------------------------------------------
628cdf0e10cSrcweir
629cdf0e10cSrcweir //
630cdf0e10cSrcweir // SvXMLNumFmtMapContext
631cdf0e10cSrcweir //
632cdf0e10cSrcweir
SvXMLNumFmtMapContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const rtl::OUString & rLName,SvXMLNumFormatContext & rParentContext,const uno::Reference<xml::sax::XAttributeList> & xAttrList)633cdf0e10cSrcweir SvXMLNumFmtMapContext::SvXMLNumFmtMapContext( SvXMLImport& rImport,
634cdf0e10cSrcweir sal_uInt16 nPrfx, const rtl::OUString& rLName,
635cdf0e10cSrcweir SvXMLNumFormatContext& rParentContext,
636cdf0e10cSrcweir const uno::Reference<xml::sax::XAttributeList>& xAttrList ) :
637cdf0e10cSrcweir SvXMLImportContext( rImport, nPrfx, rLName ),
638cdf0e10cSrcweir rParent( rParentContext )
639cdf0e10cSrcweir {
640cdf0e10cSrcweir sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
641cdf0e10cSrcweir for( sal_Int16 i=0; i < nAttrCount; i++ )
642cdf0e10cSrcweir {
643cdf0e10cSrcweir OUString sAttrName = xAttrList->getNameByIndex( i );
644cdf0e10cSrcweir OUString sValue = xAttrList->getValueByIndex( i );
645cdf0e10cSrcweir OUString aLocalName;
646cdf0e10cSrcweir sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
647cdf0e10cSrcweir if ( nPrefix == XML_NAMESPACE_STYLE )
648cdf0e10cSrcweir {
649cdf0e10cSrcweir if ( IsXMLToken( aLocalName, XML_CONDITION) )
650cdf0e10cSrcweir sCondition = sValue;
651cdf0e10cSrcweir else if ( IsXMLToken( aLocalName, XML_APPLY_STYLE_NAME) )
652cdf0e10cSrcweir sName = sValue;
653cdf0e10cSrcweir }
654cdf0e10cSrcweir }
655cdf0e10cSrcweir }
656cdf0e10cSrcweir
~SvXMLNumFmtMapContext()657cdf0e10cSrcweir SvXMLNumFmtMapContext::~SvXMLNumFmtMapContext()
658cdf0e10cSrcweir {
659cdf0e10cSrcweir }
660cdf0e10cSrcweir
CreateChildContext(sal_uInt16 nPrfx,const rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> &)661cdf0e10cSrcweir SvXMLImportContext* SvXMLNumFmtMapContext::CreateChildContext(
662cdf0e10cSrcweir sal_uInt16 nPrfx, const rtl::OUString& rLName,
663cdf0e10cSrcweir const uno::Reference<xml::sax::XAttributeList>& )
664cdf0e10cSrcweir {
665cdf0e10cSrcweir // no elements supported - use default context
666cdf0e10cSrcweir return new SvXMLImportContext( GetImport(), nPrfx, rLName );
667cdf0e10cSrcweir }
668cdf0e10cSrcweir
Characters(const rtl::OUString &)669cdf0e10cSrcweir void SvXMLNumFmtMapContext::Characters( const rtl::OUString& )
670cdf0e10cSrcweir {
671cdf0e10cSrcweir }
672cdf0e10cSrcweir
EndElement()673cdf0e10cSrcweir void SvXMLNumFmtMapContext::EndElement()
674cdf0e10cSrcweir {
675cdf0e10cSrcweir rParent.AddCondition( sCondition, sName );
676cdf0e10cSrcweir }
677cdf0e10cSrcweir
678cdf0e10cSrcweir //-------------------------------------------------------------------------
679cdf0e10cSrcweir
680cdf0e10cSrcweir //
681cdf0e10cSrcweir // SvXMLNumFmtPropContext
682cdf0e10cSrcweir //
683cdf0e10cSrcweir
SvXMLNumFmtPropContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const rtl::OUString & rLName,SvXMLNumFormatContext & rParentContext,const uno::Reference<xml::sax::XAttributeList> & xAttrList)684cdf0e10cSrcweir SvXMLNumFmtPropContext::SvXMLNumFmtPropContext( SvXMLImport& rImport,
685cdf0e10cSrcweir sal_uInt16 nPrfx, const rtl::OUString& rLName,
686cdf0e10cSrcweir SvXMLNumFormatContext& rParentContext,
687cdf0e10cSrcweir const uno::Reference<xml::sax::XAttributeList>& xAttrList ) :
688cdf0e10cSrcweir SvXMLImportContext( rImport, nPrfx, rLName ),
689cdf0e10cSrcweir rParent( rParentContext ),
690cdf0e10cSrcweir bColSet( sal_False )
691cdf0e10cSrcweir {
692cdf0e10cSrcweir sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
693cdf0e10cSrcweir for( sal_Int16 i=0; i < nAttrCount; i++ )
694cdf0e10cSrcweir {
695cdf0e10cSrcweir OUString sAttrName = xAttrList->getNameByIndex( i );
696cdf0e10cSrcweir OUString sValue = xAttrList->getValueByIndex( i );
697cdf0e10cSrcweir OUString aLocalName;
698cdf0e10cSrcweir sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
699cdf0e10cSrcweir if ( nPrefix == XML_NAMESPACE_FO && IsXMLToken( aLocalName, XML_COLOR ) )
700cdf0e10cSrcweir bColSet = SvXMLUnitConverter::convertColor( aColor, sValue );
701cdf0e10cSrcweir }
702cdf0e10cSrcweir }
703cdf0e10cSrcweir
~SvXMLNumFmtPropContext()704cdf0e10cSrcweir SvXMLNumFmtPropContext::~SvXMLNumFmtPropContext()
705cdf0e10cSrcweir {
706cdf0e10cSrcweir }
707cdf0e10cSrcweir
CreateChildContext(sal_uInt16 nPrfx,const rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> &)708cdf0e10cSrcweir SvXMLImportContext* SvXMLNumFmtPropContext::CreateChildContext(
709cdf0e10cSrcweir sal_uInt16 nPrfx, const rtl::OUString& rLName,
710cdf0e10cSrcweir const uno::Reference<xml::sax::XAttributeList>& )
711cdf0e10cSrcweir {
712cdf0e10cSrcweir // no elements supported - use default context
713cdf0e10cSrcweir return new SvXMLImportContext( GetImport(), nPrfx, rLName );
714cdf0e10cSrcweir }
715cdf0e10cSrcweir
Characters(const rtl::OUString &)716cdf0e10cSrcweir void SvXMLNumFmtPropContext::Characters( const rtl::OUString& )
717cdf0e10cSrcweir {
718cdf0e10cSrcweir }
719cdf0e10cSrcweir
EndElement()720cdf0e10cSrcweir void SvXMLNumFmtPropContext::EndElement()
721cdf0e10cSrcweir {
722cdf0e10cSrcweir if (bColSet)
723cdf0e10cSrcweir rParent.AddColor( aColor );
724cdf0e10cSrcweir }
725cdf0e10cSrcweir
726cdf0e10cSrcweir //-------------------------------------------------------------------------
727cdf0e10cSrcweir
728cdf0e10cSrcweir //
729cdf0e10cSrcweir // SvXMLNumFmtEmbeddedTextContext
730cdf0e10cSrcweir //
731cdf0e10cSrcweir
SvXMLNumFmtEmbeddedTextContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const rtl::OUString & rLName,SvXMLNumFmtElementContext & rParentContext,const uno::Reference<xml::sax::XAttributeList> & xAttrList)732cdf0e10cSrcweir SvXMLNumFmtEmbeddedTextContext::SvXMLNumFmtEmbeddedTextContext( SvXMLImport& rImport,
733cdf0e10cSrcweir sal_uInt16 nPrfx, const rtl::OUString& rLName,
734cdf0e10cSrcweir SvXMLNumFmtElementContext& rParentContext,
735cdf0e10cSrcweir const uno::Reference<xml::sax::XAttributeList>& xAttrList ) :
736cdf0e10cSrcweir SvXMLImportContext( rImport, nPrfx, rLName ),
737cdf0e10cSrcweir rParent( rParentContext ),
738cdf0e10cSrcweir nTextPosition( 0 )
739cdf0e10cSrcweir {
740cdf0e10cSrcweir sal_Int32 nAttrVal;
741cdf0e10cSrcweir
742cdf0e10cSrcweir sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
743cdf0e10cSrcweir for( sal_Int16 i=0; i < nAttrCount; i++ )
744cdf0e10cSrcweir {
745cdf0e10cSrcweir OUString sAttrName = xAttrList->getNameByIndex( i );
746cdf0e10cSrcweir OUString sValue = xAttrList->getValueByIndex( i );
747cdf0e10cSrcweir OUString aLocalName;
748cdf0e10cSrcweir sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
749cdf0e10cSrcweir if ( nPrefix == XML_NAMESPACE_NUMBER && IsXMLToken( aLocalName, XML_POSITION ) )
750cdf0e10cSrcweir {
751cdf0e10cSrcweir if ( SvXMLUnitConverter::convertNumber( nAttrVal, sValue, 0 ) )
752cdf0e10cSrcweir nTextPosition = nAttrVal;
753cdf0e10cSrcweir }
754cdf0e10cSrcweir }
755cdf0e10cSrcweir }
756cdf0e10cSrcweir
~SvXMLNumFmtEmbeddedTextContext()757cdf0e10cSrcweir SvXMLNumFmtEmbeddedTextContext::~SvXMLNumFmtEmbeddedTextContext()
758cdf0e10cSrcweir {
759cdf0e10cSrcweir }
760cdf0e10cSrcweir
CreateChildContext(sal_uInt16 nPrfx,const rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> &)761cdf0e10cSrcweir SvXMLImportContext* SvXMLNumFmtEmbeddedTextContext::CreateChildContext(
762cdf0e10cSrcweir sal_uInt16 nPrfx, const rtl::OUString& rLName,
763cdf0e10cSrcweir const uno::Reference<xml::sax::XAttributeList>& )
764cdf0e10cSrcweir {
765cdf0e10cSrcweir // no elements supported - use default context
766cdf0e10cSrcweir return new SvXMLImportContext( GetImport(), nPrfx, rLName );
767cdf0e10cSrcweir }
768cdf0e10cSrcweir
Characters(const rtl::OUString & rChars)769cdf0e10cSrcweir void SvXMLNumFmtEmbeddedTextContext::Characters( const rtl::OUString& rChars )
770cdf0e10cSrcweir {
771cdf0e10cSrcweir aContent.append( rChars );
772cdf0e10cSrcweir }
773cdf0e10cSrcweir
EndElement()774cdf0e10cSrcweir void SvXMLNumFmtEmbeddedTextContext::EndElement()
775cdf0e10cSrcweir {
776cdf0e10cSrcweir rParent.AddEmbeddedElement( nTextPosition, aContent.makeStringAndClear() );
777cdf0e10cSrcweir }
778cdf0e10cSrcweir
779cdf0e10cSrcweir //-------------------------------------------------------------------------
780cdf0e10cSrcweir
lcl_ValidChar(sal_Unicode cChar,const SvXMLNumFormatContext & rParent)781cdf0e10cSrcweir sal_Bool lcl_ValidChar( sal_Unicode cChar, const SvXMLNumFormatContext& rParent )
782cdf0e10cSrcweir {
783cdf0e10cSrcweir sal_uInt16 nFormatType = rParent.GetType();
784cdf0e10cSrcweir
785cdf0e10cSrcweir // Treat space equal to non-breaking space separator.
786cdf0e10cSrcweir const sal_Unicode cNBSP = 0x00A0;
787cdf0e10cSrcweir sal_Unicode cTS;
788cdf0e10cSrcweir if ( ( nFormatType == XML_TOK_STYLES_NUMBER_STYLE ||
789cdf0e10cSrcweir nFormatType == XML_TOK_STYLES_CURRENCY_STYLE ||
790cdf0e10cSrcweir nFormatType == XML_TOK_STYLES_PERCENTAGE_STYLE ) &&
791cdf0e10cSrcweir (cChar == (cTS = rParent.GetLocaleData().getNumThousandSep().GetChar(0)) ||
792cdf0e10cSrcweir (cChar == ' ' && cTS == cNBSP)) )
793cdf0e10cSrcweir {
794cdf0e10cSrcweir // #i22394# Extra occurrences of thousands separator must be quoted, so they
795cdf0e10cSrcweir // aren't mis-interpreted as display-factor.
796cdf0e10cSrcweir // This must be limited to the format types that can contain a number element,
797cdf0e10cSrcweir // because the same character can be a date separator that should not be quoted
798cdf0e10cSrcweir // in date formats.
799cdf0e10cSrcweir
800cdf0e10cSrcweir return sal_False; // force quotes
801cdf0e10cSrcweir }
802cdf0e10cSrcweir
803cdf0e10cSrcweir // see ImpSvNumberformatScan::Next_Symbol
804cdf0e10cSrcweir if ( cChar == ' ' ||
805cdf0e10cSrcweir cChar == '-' ||
806cdf0e10cSrcweir cChar == '/' ||
807cdf0e10cSrcweir cChar == '.' ||
808cdf0e10cSrcweir cChar == ',' ||
809cdf0e10cSrcweir cChar == ':' ||
810cdf0e10cSrcweir cChar == '\'' )
811cdf0e10cSrcweir return sal_True; // for all format types
812cdf0e10cSrcweir
813cdf0e10cSrcweir // percent sign must be used without quotes for percentage styles only
814cdf0e10cSrcweir if ( nFormatType == XML_TOK_STYLES_PERCENTAGE_STYLE && cChar == '%' )
815cdf0e10cSrcweir return sal_True;
816cdf0e10cSrcweir
817cdf0e10cSrcweir // don't put quotes around single parentheses (often used for negative numbers)
818cdf0e10cSrcweir if ( ( nFormatType == XML_TOK_STYLES_NUMBER_STYLE ||
819cdf0e10cSrcweir nFormatType == XML_TOK_STYLES_CURRENCY_STYLE ||
820cdf0e10cSrcweir nFormatType == XML_TOK_STYLES_PERCENTAGE_STYLE ) &&
821cdf0e10cSrcweir ( cChar == '(' || cChar == ')' ) )
822cdf0e10cSrcweir return sal_True;
823cdf0e10cSrcweir
824cdf0e10cSrcweir return sal_False;
825cdf0e10cSrcweir }
826cdf0e10cSrcweir
lcl_EnquoteIfNecessary(rtl::OUStringBuffer & rContent,const SvXMLNumFormatContext & rParent)827cdf0e10cSrcweir void lcl_EnquoteIfNecessary( rtl::OUStringBuffer& rContent, const SvXMLNumFormatContext& rParent )
828cdf0e10cSrcweir {
829cdf0e10cSrcweir sal_Bool bQuote = sal_True;
830cdf0e10cSrcweir sal_Int32 nLength = rContent.getLength();
831cdf0e10cSrcweir
832cdf0e10cSrcweir if ( ( nLength == 1 &&
833cdf0e10cSrcweir lcl_ValidChar( rContent.charAt(0), rParent ) ) ||
834cdf0e10cSrcweir ( nLength == 2 &&
835cdf0e10cSrcweir lcl_ValidChar( rContent.charAt(0), rParent ) &&
836cdf0e10cSrcweir rContent.charAt(1) == ' ' ) )
837cdf0e10cSrcweir {
838cdf0e10cSrcweir // don't quote single separator characters like space or percent,
839cdf0e10cSrcweir // or separator characters followed by space (used in date formats)
840cdf0e10cSrcweir bQuote = sal_False;
841cdf0e10cSrcweir }
842cdf0e10cSrcweir else if ( rParent.GetType() == XML_TOK_STYLES_PERCENTAGE_STYLE && nLength > 1 )
843cdf0e10cSrcweir {
844cdf0e10cSrcweir // the percent character in percentage styles must be left out of quoting
845cdf0e10cSrcweir // (one occurence is enough even if there are several percent characters in the string)
846cdf0e10cSrcweir
847cdf0e10cSrcweir rtl::OUString aString( rContent.getStr() );
848cdf0e10cSrcweir sal_Int32 nPos = aString.indexOf( (sal_Unicode) '%' );
849cdf0e10cSrcweir if ( nPos >= 0 )
850cdf0e10cSrcweir {
851cdf0e10cSrcweir if ( nPos + 1 < nLength )
852cdf0e10cSrcweir {
853cdf0e10cSrcweir if ( nPos + 2 == nLength && lcl_ValidChar( rContent.charAt(nPos + 1), rParent ) )
854cdf0e10cSrcweir {
855cdf0e10cSrcweir // single character that doesn't need quoting
856cdf0e10cSrcweir }
857cdf0e10cSrcweir else
858cdf0e10cSrcweir {
859cdf0e10cSrcweir // quote text behind percent character
860cdf0e10cSrcweir rContent.insert( nPos + 1, (sal_Unicode) '"' );
861cdf0e10cSrcweir rContent.append( (sal_Unicode) '"' );
862cdf0e10cSrcweir }
863cdf0e10cSrcweir }
864cdf0e10cSrcweir if ( nPos > 0 )
865cdf0e10cSrcweir {
866cdf0e10cSrcweir if ( nPos == 1 && lcl_ValidChar( rContent.charAt(0), rParent ) )
867cdf0e10cSrcweir {
868cdf0e10cSrcweir // single character that doesn't need quoting
869cdf0e10cSrcweir }
870cdf0e10cSrcweir else
871cdf0e10cSrcweir {
872cdf0e10cSrcweir // quote text before percent character
873cdf0e10cSrcweir rContent.insert( nPos, (sal_Unicode) '"' );
874cdf0e10cSrcweir rContent.insert( 0, (sal_Unicode) '"' );
875cdf0e10cSrcweir }
876cdf0e10cSrcweir }
877cdf0e10cSrcweir bQuote = sal_False;
878cdf0e10cSrcweir }
879cdf0e10cSrcweir // else: normal quoting (below)
880cdf0e10cSrcweir }
881cdf0e10cSrcweir
882cdf0e10cSrcweir if ( bQuote )
883cdf0e10cSrcweir {
884cdf0e10cSrcweir // #i55469# quotes in the string itself have to be escaped
885cdf0e10cSrcweir rtl::OUString aString( rContent.getStr() );
886cdf0e10cSrcweir bool bEscape = ( aString.indexOf( (sal_Unicode) '"' ) >= 0 );
887cdf0e10cSrcweir if ( bEscape )
888cdf0e10cSrcweir {
889cdf0e10cSrcweir // A quote is turned into "\"" - a quote to end quoted text, an escaped quote,
890cdf0e10cSrcweir // and a quote to resume quoting.
891cdf0e10cSrcweir rtl::OUString aInsert( rtl::OUString::createFromAscii( "\"\\\"" ) );
892cdf0e10cSrcweir
893cdf0e10cSrcweir sal_Int32 nPos = 0;
894cdf0e10cSrcweir while ( nPos < rContent.getLength() )
895cdf0e10cSrcweir {
896cdf0e10cSrcweir if ( rContent.charAt( nPos ) == (sal_Unicode) '"' )
897cdf0e10cSrcweir {
898cdf0e10cSrcweir rContent.insert( nPos, aInsert );
899cdf0e10cSrcweir nPos += aInsert.getLength();
900cdf0e10cSrcweir }
901cdf0e10cSrcweir ++nPos;
902cdf0e10cSrcweir }
903cdf0e10cSrcweir }
904cdf0e10cSrcweir
905cdf0e10cSrcweir // quote string literals
906cdf0e10cSrcweir rContent.insert( 0, (sal_Unicode) '"' );
907cdf0e10cSrcweir rContent.append( (sal_Unicode) '"' );
908cdf0e10cSrcweir
909cdf0e10cSrcweir // remove redundant double quotes at start or end
910cdf0e10cSrcweir if ( bEscape )
911cdf0e10cSrcweir {
912cdf0e10cSrcweir if ( rContent.getLength() > 2 &&
913cdf0e10cSrcweir rContent.charAt(0) == (sal_Unicode) '"' &&
914cdf0e10cSrcweir rContent.charAt(1) == (sal_Unicode) '"' )
915cdf0e10cSrcweir {
916cdf0e10cSrcweir String aTrimmed( rContent.makeStringAndClear().copy(2) );
917cdf0e10cSrcweir rContent = rtl::OUStringBuffer( aTrimmed );
918cdf0e10cSrcweir }
919cdf0e10cSrcweir
920cdf0e10cSrcweir sal_Int32 nLen = rContent.getLength();
921cdf0e10cSrcweir if ( nLen > 2 &&
922cdf0e10cSrcweir rContent.charAt(nLen-1) == (sal_Unicode) '"' &&
923cdf0e10cSrcweir rContent.charAt(nLen-2) == (sal_Unicode) '"' )
924cdf0e10cSrcweir {
925cdf0e10cSrcweir String aTrimmed( rContent.makeStringAndClear().copy( 0, nLen - 2 ) );
926cdf0e10cSrcweir rContent = rtl::OUStringBuffer( aTrimmed );
927cdf0e10cSrcweir }
928cdf0e10cSrcweir }
929cdf0e10cSrcweir }
930cdf0e10cSrcweir }
931cdf0e10cSrcweir
932cdf0e10cSrcweir //
933cdf0e10cSrcweir // SvXMLNumFmtElementContext
934cdf0e10cSrcweir //
935cdf0e10cSrcweir
SvXMLNumFmtElementContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const rtl::OUString & rLName,SvXMLNumFormatContext & rParentContext,sal_uInt16 nNewType,const uno::Reference<xml::sax::XAttributeList> & xAttrList)936cdf0e10cSrcweir SvXMLNumFmtElementContext::SvXMLNumFmtElementContext( SvXMLImport& rImport,
937cdf0e10cSrcweir sal_uInt16 nPrfx, const rtl::OUString& rLName,
938cdf0e10cSrcweir SvXMLNumFormatContext& rParentContext, sal_uInt16 nNewType,
939cdf0e10cSrcweir const uno::Reference<xml::sax::XAttributeList>& xAttrList ) :
940cdf0e10cSrcweir SvXMLImportContext( rImport, nPrfx, rLName ),
941cdf0e10cSrcweir rParent( rParentContext ),
942cdf0e10cSrcweir nType( nNewType ),
943cdf0e10cSrcweir nElementLang( LANGUAGE_SYSTEM ),
944cdf0e10cSrcweir bLong( sal_False ),
945cdf0e10cSrcweir bTextual( sal_False )
946cdf0e10cSrcweir {
947cdf0e10cSrcweir OUString sLanguage, sCountry;
948cdf0e10cSrcweir sal_Int32 nAttrVal;
949cdf0e10cSrcweir sal_Bool bAttrBool;
950cdf0e10cSrcweir sal_uInt16 nAttrEnum;
951cdf0e10cSrcweir double fAttrDouble;
952cdf0e10cSrcweir
953cdf0e10cSrcweir sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
954cdf0e10cSrcweir for( sal_Int16 i=0; i < nAttrCount; i++ )
955cdf0e10cSrcweir {
956cdf0e10cSrcweir OUString sAttrName = xAttrList->getNameByIndex( i );
957cdf0e10cSrcweir OUString sValue = xAttrList->getValueByIndex( i );
958cdf0e10cSrcweir OUString aLocalName;
959cdf0e10cSrcweir sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
960cdf0e10cSrcweir
961cdf0e10cSrcweir const SvXMLTokenMap& rTokenMap = rParent.GetData()->GetStyleElemAttrTokenMap();
962cdf0e10cSrcweir sal_uInt16 nToken = rTokenMap.Get( nPrefix, aLocalName );
963cdf0e10cSrcweir
964cdf0e10cSrcweir switch (nToken)
965cdf0e10cSrcweir {
966cdf0e10cSrcweir case XML_TOK_ELEM_ATTR_DECIMAL_PLACES:
967cdf0e10cSrcweir if ( SvXMLUnitConverter::convertNumber( nAttrVal, sValue, 0 ) )
968cdf0e10cSrcweir aNumInfo.nDecimals = nAttrVal;
969cdf0e10cSrcweir break;
970cdf0e10cSrcweir case XML_TOK_ELEM_ATTR_MIN_INTEGER_DIGITS:
971cdf0e10cSrcweir if ( SvXMLUnitConverter::convertNumber( nAttrVal, sValue, 0 ) )
972cdf0e10cSrcweir aNumInfo.nInteger = nAttrVal;
973cdf0e10cSrcweir break;
974cdf0e10cSrcweir case XML_TOK_ELEM_ATTR_GROUPING:
975cdf0e10cSrcweir if ( SvXMLUnitConverter::convertBool( bAttrBool, sValue ) )
976cdf0e10cSrcweir aNumInfo.bGrouping = bAttrBool;
977cdf0e10cSrcweir break;
978cdf0e10cSrcweir case XML_TOK_ELEM_ATTR_DISPLAY_FACTOR:
979cdf0e10cSrcweir if ( SvXMLUnitConverter::convertDouble( fAttrDouble, sValue ) )
980cdf0e10cSrcweir aNumInfo.fDisplayFactor = fAttrDouble;
981cdf0e10cSrcweir break;
982cdf0e10cSrcweir case XML_TOK_ELEM_ATTR_DECIMAL_REPLACEMENT:
983cdf0e10cSrcweir if ( sValue.getLength() > 0 )
984cdf0e10cSrcweir aNumInfo.bDecReplace = sal_True; // only a default string is supported
985cdf0e10cSrcweir else
986cdf0e10cSrcweir aNumInfo.bVarDecimals = sal_True; // empty replacement string: variable decimals
987cdf0e10cSrcweir break;
988cdf0e10cSrcweir case XML_TOK_ELEM_ATTR_MIN_EXPONENT_DIGITS:
989cdf0e10cSrcweir if ( SvXMLUnitConverter::convertNumber( nAttrVal, sValue, 0 ) )
990cdf0e10cSrcweir aNumInfo.nExpDigits = nAttrVal;
991cdf0e10cSrcweir break;
992cdf0e10cSrcweir case XML_TOK_ELEM_ATTR_MIN_NUMERATOR_DIGITS:
993cdf0e10cSrcweir if ( SvXMLUnitConverter::convertNumber( nAttrVal, sValue, 0 ) )
994cdf0e10cSrcweir aNumInfo.nNumerDigits = nAttrVal;
995cdf0e10cSrcweir break;
996cdf0e10cSrcweir case XML_TOK_ELEM_ATTR_MIN_DENOMINATOR_DIGITS:
997cdf0e10cSrcweir if ( SvXMLUnitConverter::convertNumber( nAttrVal, sValue, 0 ) )
998cdf0e10cSrcweir aNumInfo.nDenomDigits = nAttrVal;
999cdf0e10cSrcweir break;
1000cdf0e10cSrcweir case XML_TOK_ELEM_ATTR_LANGUAGE:
1001cdf0e10cSrcweir sLanguage = sValue;
1002cdf0e10cSrcweir break;
1003cdf0e10cSrcweir case XML_TOK_ELEM_ATTR_COUNTRY:
1004cdf0e10cSrcweir sCountry = sValue;
1005cdf0e10cSrcweir break;
1006cdf0e10cSrcweir case XML_TOK_ELEM_ATTR_STYLE:
1007cdf0e10cSrcweir if ( SvXMLUnitConverter::convertEnum( nAttrEnum, sValue, aStyleValueMap ) )
1008cdf0e10cSrcweir bLong = (sal_Bool) nAttrEnum;
1009cdf0e10cSrcweir break;
1010cdf0e10cSrcweir case XML_TOK_ELEM_ATTR_TEXTUAL:
1011cdf0e10cSrcweir if ( SvXMLUnitConverter::convertBool( bAttrBool, sValue ) )
1012cdf0e10cSrcweir bTextual = bAttrBool;
1013cdf0e10cSrcweir break;
1014cdf0e10cSrcweir case XML_TOK_ELEM_ATTR_CALENDAR:
1015cdf0e10cSrcweir sCalendar = sValue;
1016cdf0e10cSrcweir break;
1017cdf0e10cSrcweir }
1018cdf0e10cSrcweir }
1019cdf0e10cSrcweir
1020cdf0e10cSrcweir if ( sLanguage.getLength() || sCountry.getLength() )
1021cdf0e10cSrcweir {
1022cdf0e10cSrcweir nElementLang = MsLangId::convertIsoNamesToLanguage( sLanguage, sCountry );
1023cdf0e10cSrcweir if ( nElementLang == LANGUAGE_DONTKNOW )
1024cdf0e10cSrcweir nElementLang = LANGUAGE_SYSTEM; //! error handling for invalid locales?
1025cdf0e10cSrcweir }
1026cdf0e10cSrcweir }
1027cdf0e10cSrcweir
~SvXMLNumFmtElementContext()1028cdf0e10cSrcweir SvXMLNumFmtElementContext::~SvXMLNumFmtElementContext()
1029cdf0e10cSrcweir {
1030cdf0e10cSrcweir }
1031cdf0e10cSrcweir
CreateChildContext(sal_uInt16 nPrfx,const rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)1032cdf0e10cSrcweir SvXMLImportContext* SvXMLNumFmtElementContext::CreateChildContext(
1033cdf0e10cSrcweir sal_uInt16 nPrfx, const rtl::OUString& rLName,
1034cdf0e10cSrcweir const uno::Reference<xml::sax::XAttributeList>& xAttrList )
1035cdf0e10cSrcweir {
1036cdf0e10cSrcweir // only number:number supports number:embedded-text child element
1037cdf0e10cSrcweir
1038cdf0e10cSrcweir if ( nType == XML_TOK_STYLE_NUMBER &&
1039cdf0e10cSrcweir nPrfx == XML_NAMESPACE_NUMBER && IsXMLToken( rLName, XML_EMBEDDED_TEXT ) )
1040cdf0e10cSrcweir {
1041cdf0e10cSrcweir return new SvXMLNumFmtEmbeddedTextContext( GetImport(), nPrfx, rLName, *this, xAttrList );
1042cdf0e10cSrcweir }
1043cdf0e10cSrcweir else
1044cdf0e10cSrcweir return new SvXMLImportContext( GetImport(), nPrfx, rLName );
1045cdf0e10cSrcweir }
1046cdf0e10cSrcweir
Characters(const rtl::OUString & rChars)1047cdf0e10cSrcweir void SvXMLNumFmtElementContext::Characters( const rtl::OUString& rChars )
1048cdf0e10cSrcweir {
1049cdf0e10cSrcweir aContent.append( rChars );
1050cdf0e10cSrcweir }
1051cdf0e10cSrcweir
AddEmbeddedElement(sal_Int32 nFormatPos,const rtl::OUString & rContent)1052cdf0e10cSrcweir void SvXMLNumFmtElementContext::AddEmbeddedElement( sal_Int32 nFormatPos, const rtl::OUString& rContent )
1053cdf0e10cSrcweir {
1054cdf0e10cSrcweir if ( rContent.getLength() )
1055cdf0e10cSrcweir {
1056cdf0e10cSrcweir SvXMLEmbeddedElement* pObj = new SvXMLEmbeddedElement( nFormatPos, rContent );
1057cdf0e10cSrcweir if ( !aNumInfo.aEmbeddedElements.Insert( pObj ) )
1058cdf0e10cSrcweir {
1059cdf0e10cSrcweir // there's already an element at this position - append text to existing element
1060cdf0e10cSrcweir
1061cdf0e10cSrcweir delete pObj;
1062cdf0e10cSrcweir sal_uInt16 nElementCount = aNumInfo.aEmbeddedElements.Count();
1063cdf0e10cSrcweir for (sal_uInt16 i=0; i<nElementCount; i++)
1064cdf0e10cSrcweir {
1065cdf0e10cSrcweir pObj = aNumInfo.aEmbeddedElements[i];
1066cdf0e10cSrcweir if ( pObj->nFormatPos == nFormatPos )
1067cdf0e10cSrcweir {
1068cdf0e10cSrcweir pObj->aText += rContent;
1069cdf0e10cSrcweir break;
1070cdf0e10cSrcweir }
1071cdf0e10cSrcweir }
1072cdf0e10cSrcweir }
1073cdf0e10cSrcweir }
1074cdf0e10cSrcweir }
1075cdf0e10cSrcweir
EndElement()1076cdf0e10cSrcweir void SvXMLNumFmtElementContext::EndElement()
1077cdf0e10cSrcweir {
1078cdf0e10cSrcweir sal_Bool bEffLong = bLong;
1079cdf0e10cSrcweir switch (nType)
1080cdf0e10cSrcweir {
1081cdf0e10cSrcweir case XML_TOK_STYLE_TEXT:
1082cdf0e10cSrcweir if ( rParent.HasLongDoW() &&
1083cdf0e10cSrcweir rParent.GetLocaleData().getLongDateDayOfWeekSep() ==
1084cdf0e10cSrcweir String( aContent.getStr() ) )
1085cdf0e10cSrcweir {
1086cdf0e10cSrcweir // skip separator constant after long day of week
1087cdf0e10cSrcweir // (NF_KEY_NNNN contains the separator)
1088cdf0e10cSrcweir
1089cdf0e10cSrcweir if ( rParent.ReplaceNfKeyword( NF_KEY_NNN, NF_KEY_NNNN ) )
1090cdf0e10cSrcweir {
1091cdf0e10cSrcweir //!aContent.setLength(0); //! doesn't work, #76293#
1092cdf0e10cSrcweir aContent = OUStringBuffer();
1093cdf0e10cSrcweir }
1094cdf0e10cSrcweir
1095cdf0e10cSrcweir rParent.SetHasLongDoW( sal_False ); // only once
1096cdf0e10cSrcweir }
1097cdf0e10cSrcweir if ( aContent.getLength() )
1098cdf0e10cSrcweir {
1099cdf0e10cSrcweir lcl_EnquoteIfNecessary( aContent, rParent );
1100cdf0e10cSrcweir rParent.AddToCode( aContent.makeStringAndClear() );
1101cdf0e10cSrcweir }
1102cdf0e10cSrcweir break;
1103cdf0e10cSrcweir
1104cdf0e10cSrcweir case XML_TOK_STYLE_NUMBER:
1105cdf0e10cSrcweir rParent.AddNumber( aNumInfo );
1106cdf0e10cSrcweir break;
1107cdf0e10cSrcweir
1108cdf0e10cSrcweir case XML_TOK_STYLE_CURRENCY_SYMBOL:
1109cdf0e10cSrcweir rParent.AddCurrency( aContent.makeStringAndClear(), nElementLang );
1110cdf0e10cSrcweir break;
1111cdf0e10cSrcweir
1112cdf0e10cSrcweir case XML_TOK_STYLE_TEXT_CONTENT:
1113cdf0e10cSrcweir rParent.AddToCode( OUString::valueOf((sal_Unicode)'@') );
1114cdf0e10cSrcweir break;
1115cdf0e10cSrcweir case XML_TOK_STYLE_BOOLEAN:
1116cdf0e10cSrcweir // ignored - only default boolean format is supported
1117cdf0e10cSrcweir break;
1118cdf0e10cSrcweir
1119cdf0e10cSrcweir case XML_TOK_STYLE_DAY:
1120cdf0e10cSrcweir rParent.UpdateCalendar( sCalendar );
1121cdf0e10cSrcweir #if 0
1122cdf0e10cSrcweir //! I18N doesn't provide SYSTEM or extended date information yet
1123cdf0e10cSrcweir if ( rParent.IsFromSystem() )
1124cdf0e10cSrcweir bEffLong = SvXMLNumFmtDefaults::IsSystemLongDay( rParent.GetInternational(), bLong );
1125cdf0e10cSrcweir #endif
1126cdf0e10cSrcweir rParent.AddNfKeyword(
1127cdf0e10cSrcweir sal::static_int_cast< sal_uInt16 >(
1128cdf0e10cSrcweir bEffLong ? NF_KEY_DD : NF_KEY_D ) );
1129cdf0e10cSrcweir break;
1130cdf0e10cSrcweir case XML_TOK_STYLE_MONTH:
1131cdf0e10cSrcweir rParent.UpdateCalendar( sCalendar );
1132cdf0e10cSrcweir #if 0
1133cdf0e10cSrcweir //! I18N doesn't provide SYSTEM or extended date information yet
1134cdf0e10cSrcweir if ( rParent.IsFromSystem() )
1135cdf0e10cSrcweir {
1136cdf0e10cSrcweir bEffLong = SvXMLNumFmtDefaults::IsSystemLongMonth( rParent.GetInternational(), bLong );
1137cdf0e10cSrcweir bTextual = SvXMLNumFmtDefaults::IsSystemTextualMonth( rParent.GetInternational(), bLong );
1138cdf0e10cSrcweir }
1139cdf0e10cSrcweir #endif
1140cdf0e10cSrcweir rParent.AddNfKeyword(
1141cdf0e10cSrcweir sal::static_int_cast< sal_uInt16 >(
1142cdf0e10cSrcweir bTextual
1143cdf0e10cSrcweir ? ( bEffLong ? NF_KEY_MMMM : NF_KEY_MMM )
1144cdf0e10cSrcweir : ( bEffLong ? NF_KEY_MM : NF_KEY_M ) ) );
1145cdf0e10cSrcweir break;
1146cdf0e10cSrcweir case XML_TOK_STYLE_YEAR:
1147cdf0e10cSrcweir rParent.UpdateCalendar( sCalendar );
1148cdf0e10cSrcweir #if 0
1149cdf0e10cSrcweir //! I18N doesn't provide SYSTEM or extended date information yet
1150cdf0e10cSrcweir if ( rParent.IsFromSystem() )
1151cdf0e10cSrcweir bEffLong = SvXMLNumFmtDefaults::IsSystemLongYear( rParent.GetInternational(), bLong );
1152cdf0e10cSrcweir #endif
1153cdf0e10cSrcweir // Y after G (era) is replaced by E
1154cdf0e10cSrcweir if ( rParent.HasEra() )
1155cdf0e10cSrcweir rParent.AddNfKeyword(
1156cdf0e10cSrcweir sal::static_int_cast< sal_uInt16 >(
1157cdf0e10cSrcweir bEffLong ? NF_KEY_EEC : NF_KEY_EC ) );
1158cdf0e10cSrcweir else
1159cdf0e10cSrcweir rParent.AddNfKeyword(
1160cdf0e10cSrcweir sal::static_int_cast< sal_uInt16 >(
1161cdf0e10cSrcweir bEffLong ? NF_KEY_YYYY : NF_KEY_YY ) );
1162cdf0e10cSrcweir break;
1163cdf0e10cSrcweir case XML_TOK_STYLE_ERA:
1164cdf0e10cSrcweir rParent.UpdateCalendar( sCalendar );
1165cdf0e10cSrcweir #if 0
1166cdf0e10cSrcweir //! I18N doesn't provide SYSTEM or extended date information yet
1167cdf0e10cSrcweir if ( rParent.IsFromSystem() )
1168cdf0e10cSrcweir bEffLong = SvXMLNumFmtDefaults::IsSystemLongEra( rParent.GetInternational(), bLong );
1169cdf0e10cSrcweir #endif
1170cdf0e10cSrcweir rParent.AddNfKeyword(
1171cdf0e10cSrcweir sal::static_int_cast< sal_uInt16 >(
1172cdf0e10cSrcweir bEffLong ? NF_KEY_GGG : NF_KEY_G ) );
1173cdf0e10cSrcweir // HasEra flag is set
1174cdf0e10cSrcweir break;
1175cdf0e10cSrcweir case XML_TOK_STYLE_DAY_OF_WEEK:
1176cdf0e10cSrcweir rParent.UpdateCalendar( sCalendar );
1177cdf0e10cSrcweir #if 0
1178cdf0e10cSrcweir //! I18N doesn't provide SYSTEM or extended date information yet
1179cdf0e10cSrcweir if ( rParent.IsFromSystem() )
1180cdf0e10cSrcweir bEffLong = SvXMLNumFmtDefaults::IsSystemLongDayOfWeek( rParent.GetInternational(), bLong );
1181cdf0e10cSrcweir #endif
1182cdf0e10cSrcweir rParent.AddNfKeyword(
1183cdf0e10cSrcweir sal::static_int_cast< sal_uInt16 >(
1184cdf0e10cSrcweir bEffLong ? NF_KEY_NNNN : NF_KEY_NN ) );
1185cdf0e10cSrcweir break;
1186cdf0e10cSrcweir case XML_TOK_STYLE_WEEK_OF_YEAR:
1187cdf0e10cSrcweir rParent.UpdateCalendar( sCalendar );
1188cdf0e10cSrcweir rParent.AddNfKeyword( NF_KEY_WW );
1189cdf0e10cSrcweir break;
1190cdf0e10cSrcweir case XML_TOK_STYLE_QUARTER:
1191cdf0e10cSrcweir rParent.UpdateCalendar( sCalendar );
1192cdf0e10cSrcweir rParent.AddNfKeyword(
1193cdf0e10cSrcweir sal::static_int_cast< sal_uInt16 >(
1194cdf0e10cSrcweir bEffLong ? NF_KEY_QQ : NF_KEY_Q ) );
1195cdf0e10cSrcweir break;
1196cdf0e10cSrcweir case XML_TOK_STYLE_HOURS:
1197cdf0e10cSrcweir rParent.AddNfKeyword(
1198cdf0e10cSrcweir sal::static_int_cast< sal_uInt16 >(
1199cdf0e10cSrcweir bEffLong ? NF_KEY_HH : NF_KEY_H ) );
1200cdf0e10cSrcweir break;
1201cdf0e10cSrcweir case XML_TOK_STYLE_AM_PM:
1202cdf0e10cSrcweir //! short/long?
1203cdf0e10cSrcweir rParent.AddNfKeyword( NF_KEY_AMPM );
1204cdf0e10cSrcweir break;
1205cdf0e10cSrcweir case XML_TOK_STYLE_MINUTES:
1206cdf0e10cSrcweir rParent.AddNfKeyword(
1207cdf0e10cSrcweir sal::static_int_cast< sal_uInt16 >(
1208cdf0e10cSrcweir bEffLong ? NF_KEY_MMI : NF_KEY_MI ) );
1209cdf0e10cSrcweir break;
1210cdf0e10cSrcweir case XML_TOK_STYLE_SECONDS:
1211cdf0e10cSrcweir rParent.AddNfKeyword(
1212cdf0e10cSrcweir sal::static_int_cast< sal_uInt16 >(
1213cdf0e10cSrcweir bEffLong ? NF_KEY_SS : NF_KEY_S ) );
1214cdf0e10cSrcweir if ( aNumInfo.nDecimals > 0 )
1215cdf0e10cSrcweir {
1216cdf0e10cSrcweir // manually add the decimal places
1217cdf0e10cSrcweir const String& rSep = rParent.GetLocaleData().getNumDecimalSep();
1218cdf0e10cSrcweir for ( xub_StrLen j=0; j<rSep.Len(); j++ )
1219cdf0e10cSrcweir {
1220cdf0e10cSrcweir rParent.AddToCode( OUString::valueOf( rSep.GetChar(j) ) );
1221cdf0e10cSrcweir }
1222cdf0e10cSrcweir for (sal_Int32 i=0; i<aNumInfo.nDecimals; i++)
1223cdf0e10cSrcweir rParent.AddToCode( OUString::valueOf((sal_Unicode)'0') );
1224cdf0e10cSrcweir }
1225cdf0e10cSrcweir break;
1226cdf0e10cSrcweir
1227cdf0e10cSrcweir case XML_TOK_STYLE_FRACTION:
1228cdf0e10cSrcweir {
1229cdf0e10cSrcweir if ( aNumInfo.nInteger >= 0 )
1230cdf0e10cSrcweir {
1231cdf0e10cSrcweir // add integer part only if min-integer-digits attribute is there
1232cdf0e10cSrcweir aNumInfo.nDecimals = 0;
1233cdf0e10cSrcweir rParent.AddNumber( aNumInfo ); // number without decimals
1234cdf0e10cSrcweir rParent.AddToCode( OUString::valueOf((sal_Unicode)' ') );
1235cdf0e10cSrcweir }
1236cdf0e10cSrcweir
1237cdf0e10cSrcweir //! build string and add at once
1238cdf0e10cSrcweir
1239cdf0e10cSrcweir sal_Int32 i;
1240cdf0e10cSrcweir for (i=0; i<aNumInfo.nNumerDigits; i++)
1241cdf0e10cSrcweir rParent.AddToCode( OUString::valueOf((sal_Unicode)'?') );
1242cdf0e10cSrcweir rParent.AddToCode( OUString::valueOf((sal_Unicode)'/') );
1243cdf0e10cSrcweir for (i=0; i<aNumInfo.nDenomDigits; i++)
1244cdf0e10cSrcweir rParent.AddToCode( OUString::valueOf((sal_Unicode)'?') );
1245cdf0e10cSrcweir }
1246cdf0e10cSrcweir break;
1247cdf0e10cSrcweir
1248cdf0e10cSrcweir case XML_TOK_STYLE_SCIENTIFIC_NUMBER:
1249cdf0e10cSrcweir {
1250cdf0e10cSrcweir rParent.AddNumber( aNumInfo ); // simple number
1251cdf0e10cSrcweir
1252cdf0e10cSrcweir rParent.AddToCode( OUString::createFromAscii( "E+" ) );
1253cdf0e10cSrcweir for (sal_Int32 i=0; i<aNumInfo.nExpDigits; i++)
1254cdf0e10cSrcweir rParent.AddToCode( OUString::valueOf((sal_Unicode)'0') );
1255cdf0e10cSrcweir }
1256cdf0e10cSrcweir break;
1257cdf0e10cSrcweir
1258cdf0e10cSrcweir default:
1259cdf0e10cSrcweir DBG_ERROR("invalid element ID");
1260cdf0e10cSrcweir }
1261cdf0e10cSrcweir }
1262cdf0e10cSrcweir
1263cdf0e10cSrcweir //-------------------------------------------------------------------------
1264cdf0e10cSrcweir
IsSystemLongDay(const SvtSysLocale &,sal_Bool bLong)1265cdf0e10cSrcweir sal_Bool SvXMLNumFmtDefaults::IsSystemLongDay( const SvtSysLocale&, sal_Bool bLong )
1266cdf0e10cSrcweir {
1267cdf0e10cSrcweir // TODO: merge system information and defaults into i18n locale data
1268cdf0e10cSrcweir #if 0
1269cdf0e10cSrcweir return bLong ? rIntn.IsLongDateDayLeadingZero() : rIntn.IsDateDayLeadingZero();
1270cdf0e10cSrcweir #else
1271cdf0e10cSrcweir return !bLong;
1272cdf0e10cSrcweir #endif
1273cdf0e10cSrcweir }
1274cdf0e10cSrcweir
IsSystemLongMonth(const SvtSysLocale &,sal_Bool bLong)1275cdf0e10cSrcweir sal_Bool SvXMLNumFmtDefaults::IsSystemLongMonth( const SvtSysLocale&, sal_Bool bLong )
1276cdf0e10cSrcweir {
1277cdf0e10cSrcweir // TODO: merge system information and defaults into i18n locale data
1278cdf0e10cSrcweir #if 0
1279cdf0e10cSrcweir if (bLong)
1280cdf0e10cSrcweir {
1281cdf0e10cSrcweir MonthFormat eMonth = rIntn.GetLongDateMonthFormat();
1282cdf0e10cSrcweir return ( eMonth == MONTH_ZERO || eMonth == MONTH_LONG );
1283cdf0e10cSrcweir }
1284cdf0e10cSrcweir else
1285cdf0e10cSrcweir return rIntn.IsDateMonthLeadingZero();
1286cdf0e10cSrcweir #else
1287cdf0e10cSrcweir return !bLong;
1288cdf0e10cSrcweir #endif
1289cdf0e10cSrcweir }
1290cdf0e10cSrcweir
IsSystemTextualMonth(const SvtSysLocale &,sal_Bool bLong)1291cdf0e10cSrcweir sal_Bool SvXMLNumFmtDefaults::IsSystemTextualMonth( const SvtSysLocale&, sal_Bool bLong )
1292cdf0e10cSrcweir {
1293cdf0e10cSrcweir // TODO: merge system information and defaults into i18n locale data
1294cdf0e10cSrcweir #if 0
1295cdf0e10cSrcweir if (bLong)
1296cdf0e10cSrcweir {
1297cdf0e10cSrcweir MonthFormat eMonth = rIntn.GetLongDateMonthFormat();
1298cdf0e10cSrcweir return ( eMonth == MONTH_SHORT || eMonth == MONTH_LONG );
1299cdf0e10cSrcweir }
1300cdf0e10cSrcweir else
1301cdf0e10cSrcweir return sal_False;
1302cdf0e10cSrcweir #else
1303cdf0e10cSrcweir return bLong;
1304cdf0e10cSrcweir #endif
1305cdf0e10cSrcweir }
1306cdf0e10cSrcweir
IsSystemLongYear(const SvtSysLocale &,sal_Bool bLong)1307cdf0e10cSrcweir sal_Bool SvXMLNumFmtDefaults::IsSystemLongYear( const SvtSysLocale&, sal_Bool bLong )
1308cdf0e10cSrcweir {
1309cdf0e10cSrcweir // TODO: merge system information and defaults into i18n locale data
1310cdf0e10cSrcweir #if 0
1311cdf0e10cSrcweir return bLong ? rIntn.IsLongDateCentury() : rIntn.IsDateCentury();
1312cdf0e10cSrcweir #else
1313cdf0e10cSrcweir return bLong;
1314cdf0e10cSrcweir #endif
1315cdf0e10cSrcweir }
1316cdf0e10cSrcweir
IsSystemLongEra(const SvtSysLocale & rSysLoc,sal_Bool bLong)1317cdf0e10cSrcweir sal_Bool SvXMLNumFmtDefaults::IsSystemLongEra( const SvtSysLocale& rSysLoc, sal_Bool bLong )
1318cdf0e10cSrcweir {
1319cdf0e10cSrcweir // TODO: merge system information and defaults into i18n locale data
1320cdf0e10cSrcweir return IsSystemLongYear( rSysLoc, bLong ); // no separate setting
1321cdf0e10cSrcweir }
1322cdf0e10cSrcweir
IsSystemLongDayOfWeek(const SvtSysLocale &,sal_Bool bLong)1323cdf0e10cSrcweir sal_Bool SvXMLNumFmtDefaults::IsSystemLongDayOfWeek( const SvtSysLocale&, sal_Bool bLong )
1324cdf0e10cSrcweir {
1325cdf0e10cSrcweir // TODO: merge system information and defaults into i18n locale data
1326cdf0e10cSrcweir #if 0
1327cdf0e10cSrcweir return ( bLong && rIntn.GetLongDateDayOfWeekFormat() == DAYOFWEEK_LONG );
1328cdf0e10cSrcweir #else
1329cdf0e10cSrcweir return bLong && true;
1330cdf0e10cSrcweir #endif
1331cdf0e10cSrcweir }
1332cdf0e10cSrcweir
GetDefaultDateFormat(SvXMLDateElementAttributes eDOW,SvXMLDateElementAttributes eDay,SvXMLDateElementAttributes eMonth,SvXMLDateElementAttributes eYear,SvXMLDateElementAttributes eHours,SvXMLDateElementAttributes eMins,SvXMLDateElementAttributes eSecs,sal_Bool bSystem)1333cdf0e10cSrcweir sal_uInt16 SvXMLNumFmtDefaults::GetDefaultDateFormat( SvXMLDateElementAttributes eDOW,
1334cdf0e10cSrcweir SvXMLDateElementAttributes eDay, SvXMLDateElementAttributes eMonth,
1335cdf0e10cSrcweir SvXMLDateElementAttributes eYear, SvXMLDateElementAttributes eHours,
1336cdf0e10cSrcweir SvXMLDateElementAttributes eMins, SvXMLDateElementAttributes eSecs,
1337cdf0e10cSrcweir sal_Bool bSystem )
1338cdf0e10cSrcweir {
1339cdf0e10cSrcweir const sal_uInt16 nCount = sizeof(aDefaultDateFormats) / sizeof(SvXMLDefaultDateFormat);
1340cdf0e10cSrcweir for (sal_uInt16 nPos=0; nPos<nCount; nPos++)
1341cdf0e10cSrcweir {
1342cdf0e10cSrcweir const SvXMLDefaultDateFormat& rEntry = aDefaultDateFormats[nPos];
1343cdf0e10cSrcweir if ( bSystem == rEntry.bSystem &&
1344cdf0e10cSrcweir ( eDOW == rEntry.eDOW || ( rEntry.eDOW == XML_DEA_ANY && eDOW != XML_DEA_NONE ) ) &&
1345cdf0e10cSrcweir ( eDay == rEntry.eDay || ( rEntry.eDay == XML_DEA_ANY && eDay != XML_DEA_NONE ) ) &&
1346cdf0e10cSrcweir ( eMonth == rEntry.eMonth || ( rEntry.eMonth == XML_DEA_ANY && eMonth != XML_DEA_NONE ) ) &&
1347cdf0e10cSrcweir ( eYear == rEntry.eYear || ( rEntry.eYear == XML_DEA_ANY && eYear != XML_DEA_NONE ) ) &&
1348cdf0e10cSrcweir ( eHours == rEntry.eHours || ( rEntry.eHours == XML_DEA_ANY && eHours != XML_DEA_NONE ) ) &&
1349cdf0e10cSrcweir ( eMins == rEntry.eMins || ( rEntry.eMins == XML_DEA_ANY && eMins != XML_DEA_NONE ) ) &&
1350cdf0e10cSrcweir ( eSecs == rEntry.eSecs || ( rEntry.eSecs == XML_DEA_ANY && eSecs != XML_DEA_NONE ) ) )
1351cdf0e10cSrcweir {
1352cdf0e10cSrcweir return sal::static_int_cast< sal_uInt16 >(rEntry.eFormat);
1353cdf0e10cSrcweir }
1354cdf0e10cSrcweir }
1355cdf0e10cSrcweir
1356cdf0e10cSrcweir return NF_INDEX_TABLE_ENTRIES; // invalid
1357cdf0e10cSrcweir }
1358cdf0e10cSrcweir
1359cdf0e10cSrcweir //-------------------------------------------------------------------------
1360cdf0e10cSrcweir
1361cdf0e10cSrcweir //
1362cdf0e10cSrcweir // SvXMLNumFormatContext
1363cdf0e10cSrcweir //
1364cdf0e10cSrcweir
SvXMLNumFormatContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const rtl::OUString & rLName,SvXMLNumImpData * pNewData,sal_uInt16 nNewType,const uno::Reference<xml::sax::XAttributeList> & xAttrList,SvXMLStylesContext & rStyles)1365cdf0e10cSrcweir SvXMLNumFormatContext::SvXMLNumFormatContext( SvXMLImport& rImport,
1366cdf0e10cSrcweir sal_uInt16 nPrfx, const rtl::OUString& rLName,
1367cdf0e10cSrcweir SvXMLNumImpData* pNewData, sal_uInt16 nNewType,
1368cdf0e10cSrcweir const uno::Reference<xml::sax::XAttributeList>& xAttrList,
1369cdf0e10cSrcweir SvXMLStylesContext& rStyles ) :
1370cdf0e10cSrcweir SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList ),
1371cdf0e10cSrcweir pData( pNewData ),
1372cdf0e10cSrcweir pStyles( &rStyles ),
1373cdf0e10cSrcweir aMyConditions(),
1374cdf0e10cSrcweir nType( nNewType ),
1375cdf0e10cSrcweir nKey(-1),
1376cdf0e10cSrcweir nFormatLang( LANGUAGE_SYSTEM ),
1377cdf0e10cSrcweir bAutoOrder( sal_False ),
1378cdf0e10cSrcweir bFromSystem( sal_False ),
1379cdf0e10cSrcweir bTruncate( sal_True ),
1380cdf0e10cSrcweir bAutoDec( sal_False ),
1381cdf0e10cSrcweir bAutoInt( sal_False ),
1382cdf0e10cSrcweir bHasExtraText( sal_False ),
1383cdf0e10cSrcweir bHasLongDoW( sal_False ),
1384cdf0e10cSrcweir bHasEra( sal_False ),
1385cdf0e10cSrcweir bHasDateTime( sal_False ),
1386cdf0e10cSrcweir bRemoveAfterUse( sal_False ),
1387cdf0e10cSrcweir eDateDOW( XML_DEA_NONE ),
1388cdf0e10cSrcweir eDateDay( XML_DEA_NONE ),
1389cdf0e10cSrcweir eDateMonth( XML_DEA_NONE ),
1390cdf0e10cSrcweir eDateYear( XML_DEA_NONE ),
1391cdf0e10cSrcweir eDateHours( XML_DEA_NONE ),
1392cdf0e10cSrcweir eDateMins( XML_DEA_NONE ),
1393cdf0e10cSrcweir eDateSecs( XML_DEA_NONE ),
1394cdf0e10cSrcweir bDateNoDefault( sal_False )
1395cdf0e10cSrcweir {
1396cdf0e10cSrcweir OUString sLanguage, sCountry;
1397cdf0e10cSrcweir ::com::sun::star::i18n::NativeNumberXmlAttributes aNatNumAttr;
1398cdf0e10cSrcweir sal_Bool bAttrBool;
1399cdf0e10cSrcweir sal_uInt16 nAttrEnum;
1400cdf0e10cSrcweir
1401cdf0e10cSrcweir sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1402cdf0e10cSrcweir for( sal_Int16 i=0; i < nAttrCount; i++ )
1403cdf0e10cSrcweir {
1404cdf0e10cSrcweir OUString sAttrName = xAttrList->getNameByIndex( i );
1405cdf0e10cSrcweir OUString sValue = xAttrList->getValueByIndex( i );
1406cdf0e10cSrcweir OUString aLocalName;
1407cdf0e10cSrcweir sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
1408cdf0e10cSrcweir
1409cdf0e10cSrcweir const SvXMLTokenMap& rTokenMap = pData->GetStyleAttrTokenMap();
1410cdf0e10cSrcweir sal_uInt16 nToken = rTokenMap.Get( nPrefix, aLocalName );
1411cdf0e10cSrcweir switch (nToken)
1412cdf0e10cSrcweir {
1413cdf0e10cSrcweir case XML_TOK_STYLE_ATTR_NAME:
1414cdf0e10cSrcweir // aName = sValue;
1415cdf0e10cSrcweir break;
1416cdf0e10cSrcweir case XML_TOK_STYLE_ATTR_LANGUAGE:
1417cdf0e10cSrcweir sLanguage = sValue;
1418cdf0e10cSrcweir break;
1419cdf0e10cSrcweir case XML_TOK_STYLE_ATTR_COUNTRY:
1420cdf0e10cSrcweir sCountry = sValue;
1421cdf0e10cSrcweir break;
1422cdf0e10cSrcweir case XML_TOK_STYLE_ATTR_TITLE:
1423cdf0e10cSrcweir sFormatTitle = sValue;
1424cdf0e10cSrcweir break;
1425cdf0e10cSrcweir case XML_TOK_STYLE_ATTR_AUTOMATIC_ORDER:
1426cdf0e10cSrcweir if ( SvXMLUnitConverter::convertBool( bAttrBool, sValue ) )
1427cdf0e10cSrcweir bAutoOrder = bAttrBool;
1428cdf0e10cSrcweir break;
1429cdf0e10cSrcweir case XML_TOK_STYLE_ATTR_FORMAT_SOURCE:
1430cdf0e10cSrcweir if ( SvXMLUnitConverter::convertEnum( nAttrEnum, sValue, aFormatSourceMap ) )
1431cdf0e10cSrcweir bFromSystem = (sal_Bool) nAttrEnum;
1432cdf0e10cSrcweir break;
1433cdf0e10cSrcweir case XML_TOK_STYLE_ATTR_TRUNCATE_ON_OVERFLOW:
1434cdf0e10cSrcweir if ( SvXMLUnitConverter::convertBool( bAttrBool, sValue ) )
1435cdf0e10cSrcweir bTruncate = bAttrBool;
1436cdf0e10cSrcweir break;
1437cdf0e10cSrcweir case XML_TOK_STYLE_ATTR_VOLATILE:
1438cdf0e10cSrcweir // volatile formats can be removed after importing
1439cdf0e10cSrcweir // if not used in other styles
1440cdf0e10cSrcweir if ( SvXMLUnitConverter::convertBool( bAttrBool, sValue ) )
1441cdf0e10cSrcweir bRemoveAfterUse = bAttrBool;
1442cdf0e10cSrcweir break;
1443cdf0e10cSrcweir case XML_TOK_STYLE_ATTR_TRANSL_FORMAT:
1444cdf0e10cSrcweir aNatNumAttr.Format = sValue;
1445cdf0e10cSrcweir break;
1446cdf0e10cSrcweir case XML_TOK_STYLE_ATTR_TRANSL_LANGUAGE:
1447cdf0e10cSrcweir aNatNumAttr.Locale.Language = sValue;
1448cdf0e10cSrcweir break;
1449cdf0e10cSrcweir case XML_TOK_STYLE_ATTR_TRANSL_COUNTRY:
1450cdf0e10cSrcweir aNatNumAttr.Locale.Country = sValue;
1451cdf0e10cSrcweir break;
1452cdf0e10cSrcweir case XML_TOK_STYLE_ATTR_TRANSL_STYLE:
1453cdf0e10cSrcweir aNatNumAttr.Style = sValue;
1454cdf0e10cSrcweir break;
1455cdf0e10cSrcweir }
1456cdf0e10cSrcweir }
1457cdf0e10cSrcweir
1458cdf0e10cSrcweir if ( sLanguage.getLength() || sCountry.getLength() )
1459cdf0e10cSrcweir {
1460cdf0e10cSrcweir nFormatLang = MsLangId::convertIsoNamesToLanguage( sLanguage, sCountry );
1461cdf0e10cSrcweir if ( nFormatLang == LANGUAGE_DONTKNOW )
1462cdf0e10cSrcweir nFormatLang = LANGUAGE_SYSTEM; //! error handling for invalid locales?
1463cdf0e10cSrcweir }
1464cdf0e10cSrcweir
1465cdf0e10cSrcweir if ( aNatNumAttr.Format.getLength() )
1466cdf0e10cSrcweir {
1467cdf0e10cSrcweir SvNumberFormatter* pFormatter = pData->GetNumberFormatter();
1468cdf0e10cSrcweir if ( pFormatter )
1469cdf0e10cSrcweir {
1470cdf0e10cSrcweir sal_Int32 nNatNum = pFormatter->GetNatNum()->convertFromXmlAttributes( aNatNumAttr );
1471cdf0e10cSrcweir aFormatCode.appendAscii( RTL_CONSTASCII_STRINGPARAM( "[NatNum" ) );
1472cdf0e10cSrcweir aFormatCode.append( nNatNum, 10 );
1473cdf0e10cSrcweir
1474cdf0e10cSrcweir LanguageType eLang = MsLangId::convertLocaleToLanguage( aNatNumAttr.Locale );
1475cdf0e10cSrcweir if ( eLang == LANGUAGE_DONTKNOW )
1476cdf0e10cSrcweir eLang = LANGUAGE_SYSTEM; //! error handling for invalid locales?
1477cdf0e10cSrcweir if ( eLang != nFormatLang && eLang != LANGUAGE_SYSTEM )
1478cdf0e10cSrcweir {
1479cdf0e10cSrcweir aFormatCode.appendAscii( RTL_CONSTASCII_STRINGPARAM( "][$-" ) );
1480cdf0e10cSrcweir // language code in upper hex:
1481cdf0e10cSrcweir aFormatCode.append( String::CreateFromInt32( sal_Int32( eLang ), 16 ).ToUpperAscii() );
1482cdf0e10cSrcweir }
1483cdf0e10cSrcweir aFormatCode.append( sal_Unicode(']') );
1484cdf0e10cSrcweir }
1485cdf0e10cSrcweir }
1486cdf0e10cSrcweir }
1487cdf0e10cSrcweir
SvXMLNumFormatContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,const sal_Int32 nTempKey,SvXMLStylesContext & rStyles)1488cdf0e10cSrcweir SvXMLNumFormatContext::SvXMLNumFormatContext( SvXMLImport& rImport,
1489cdf0e10cSrcweir sal_uInt16 nPrfx, const rtl::OUString& rLName,
1490cdf0e10cSrcweir const uno::Reference<xml::sax::XAttributeList>& xAttrList,
1491cdf0e10cSrcweir const sal_Int32 nTempKey,
1492cdf0e10cSrcweir SvXMLStylesContext& rStyles ) :
1493cdf0e10cSrcweir SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList, XML_STYLE_FAMILY_DATA_STYLE ),
1494cdf0e10cSrcweir pData( NULL ),
1495cdf0e10cSrcweir pStyles( &rStyles ),
1496cdf0e10cSrcweir aMyConditions(),
1497cdf0e10cSrcweir nType( 0 ),
1498cdf0e10cSrcweir nKey(nTempKey),
1499cdf0e10cSrcweir nFormatLang( LANGUAGE_SYSTEM ),
1500cdf0e10cSrcweir bAutoOrder( sal_False ),
1501cdf0e10cSrcweir bFromSystem( sal_False ),
1502cdf0e10cSrcweir bTruncate( sal_True ),
1503cdf0e10cSrcweir bAutoDec( sal_False ),
1504cdf0e10cSrcweir bAutoInt( sal_False ),
1505cdf0e10cSrcweir bHasExtraText( sal_False ),
1506cdf0e10cSrcweir bHasLongDoW( sal_False ),
1507cdf0e10cSrcweir bHasEra( sal_False ),
1508cdf0e10cSrcweir bHasDateTime( sal_False ),
1509cdf0e10cSrcweir bRemoveAfterUse( sal_False ),
1510cdf0e10cSrcweir eDateDOW( XML_DEA_NONE ),
1511cdf0e10cSrcweir eDateDay( XML_DEA_NONE ),
1512cdf0e10cSrcweir eDateMonth( XML_DEA_NONE ),
1513cdf0e10cSrcweir eDateYear( XML_DEA_NONE ),
1514cdf0e10cSrcweir eDateHours( XML_DEA_NONE ),
1515cdf0e10cSrcweir eDateMins( XML_DEA_NONE ),
1516cdf0e10cSrcweir eDateSecs( XML_DEA_NONE ),
1517cdf0e10cSrcweir bDateNoDefault( sal_False )
1518cdf0e10cSrcweir {
1519cdf0e10cSrcweir SetAttribute(XML_NAMESPACE_STYLE, GetXMLToken(XML_NAME), rLName);
1520cdf0e10cSrcweir }
1521cdf0e10cSrcweir
~SvXMLNumFormatContext()1522cdf0e10cSrcweir SvXMLNumFormatContext::~SvXMLNumFormatContext()
1523cdf0e10cSrcweir {
1524cdf0e10cSrcweir }
1525cdf0e10cSrcweir
CreateChildContext(sal_uInt16 nPrfx,const rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)1526cdf0e10cSrcweir SvXMLImportContext* SvXMLNumFormatContext::CreateChildContext(
1527cdf0e10cSrcweir sal_uInt16 nPrfx, const rtl::OUString& rLName,
1528cdf0e10cSrcweir const uno::Reference<xml::sax::XAttributeList>& xAttrList )
1529cdf0e10cSrcweir {
1530cdf0e10cSrcweir SvXMLImportContext* pContext = NULL;
1531cdf0e10cSrcweir
1532cdf0e10cSrcweir const SvXMLTokenMap& rTokenMap = pData->GetStyleElemTokenMap();
1533cdf0e10cSrcweir sal_uInt16 nToken = rTokenMap.Get( nPrfx, rLName );
1534cdf0e10cSrcweir switch (nToken)
1535cdf0e10cSrcweir {
1536cdf0e10cSrcweir case XML_TOK_STYLE_TEXT:
1537cdf0e10cSrcweir case XML_TOK_STYLE_NUMBER:
1538cdf0e10cSrcweir case XML_TOK_STYLE_SCIENTIFIC_NUMBER:
1539cdf0e10cSrcweir case XML_TOK_STYLE_FRACTION:
1540cdf0e10cSrcweir case XML_TOK_STYLE_CURRENCY_SYMBOL:
1541cdf0e10cSrcweir case XML_TOK_STYLE_DAY:
1542cdf0e10cSrcweir case XML_TOK_STYLE_MONTH:
1543cdf0e10cSrcweir case XML_TOK_STYLE_YEAR:
1544cdf0e10cSrcweir case XML_TOK_STYLE_ERA:
1545cdf0e10cSrcweir case XML_TOK_STYLE_DAY_OF_WEEK:
1546cdf0e10cSrcweir case XML_TOK_STYLE_WEEK_OF_YEAR:
1547cdf0e10cSrcweir case XML_TOK_STYLE_QUARTER:
1548cdf0e10cSrcweir case XML_TOK_STYLE_HOURS:
1549cdf0e10cSrcweir case XML_TOK_STYLE_AM_PM:
1550cdf0e10cSrcweir case XML_TOK_STYLE_MINUTES:
1551cdf0e10cSrcweir case XML_TOK_STYLE_SECONDS:
1552cdf0e10cSrcweir case XML_TOK_STYLE_BOOLEAN:
1553cdf0e10cSrcweir case XML_TOK_STYLE_TEXT_CONTENT:
1554cdf0e10cSrcweir pContext = new SvXMLNumFmtElementContext( GetImport(), nPrfx, rLName,
1555cdf0e10cSrcweir *this, nToken, xAttrList );
1556cdf0e10cSrcweir break;
1557cdf0e10cSrcweir
1558cdf0e10cSrcweir case XML_TOK_STYLE_PROPERTIES:
1559cdf0e10cSrcweir pContext = new SvXMLNumFmtPropContext( GetImport(), nPrfx, rLName,
1560cdf0e10cSrcweir *this, xAttrList );
1561cdf0e10cSrcweir break;
1562cdf0e10cSrcweir case XML_TOK_STYLE_MAP:
1563cdf0e10cSrcweir {
1564cdf0e10cSrcweir // SvXMLNumFmtMapContext::EndElement adds to aMyConditions,
1565cdf0e10cSrcweir // so there's no need for an extra flag
1566cdf0e10cSrcweir pContext = new SvXMLNumFmtMapContext( GetImport(), nPrfx, rLName,
1567cdf0e10cSrcweir *this, xAttrList );
1568cdf0e10cSrcweir }
1569cdf0e10cSrcweir break;
1570cdf0e10cSrcweir }
1571cdf0e10cSrcweir
1572cdf0e10cSrcweir if( !pContext )
1573cdf0e10cSrcweir pContext = new SvXMLImportContext( GetImport(), nPrfx, rLName );
1574cdf0e10cSrcweir return pContext;
1575cdf0e10cSrcweir }
1576cdf0e10cSrcweir
GetKey()1577cdf0e10cSrcweir sal_Int32 SvXMLNumFormatContext::GetKey()
1578cdf0e10cSrcweir {
1579cdf0e10cSrcweir if (nKey > -1)
1580cdf0e10cSrcweir {
1581cdf0e10cSrcweir if (bRemoveAfterUse)
1582cdf0e10cSrcweir {
1583cdf0e10cSrcweir // format is used -> don't remove
1584cdf0e10cSrcweir bRemoveAfterUse = sal_False;
1585cdf0e10cSrcweir if (pData)
1586cdf0e10cSrcweir pData->SetUsed(nKey);
1587cdf0e10cSrcweir
1588cdf0e10cSrcweir // Add to import's list of keys now - CreateAndInsert didn't add
1589cdf0e10cSrcweir // the style if bRemoveAfterUse was set.
1590cdf0e10cSrcweir GetImport().AddNumberStyle( nKey, GetName() );
1591cdf0e10cSrcweir }
1592cdf0e10cSrcweir return nKey;
1593cdf0e10cSrcweir }
1594cdf0e10cSrcweir else
1595cdf0e10cSrcweir {
1596cdf0e10cSrcweir // reset bRemoveAfterUse before CreateAndInsert, so AddKey is called without bRemoveAfterUse set
1597cdf0e10cSrcweir bRemoveAfterUse = sal_False;
1598cdf0e10cSrcweir CreateAndInsert(sal_True);
1599cdf0e10cSrcweir return nKey;
1600cdf0e10cSrcweir }
1601cdf0e10cSrcweir }
1602cdf0e10cSrcweir
PrivateGetKey()1603cdf0e10cSrcweir sal_Int32 SvXMLNumFormatContext::PrivateGetKey()
1604cdf0e10cSrcweir {
1605cdf0e10cSrcweir // used for map elements in CreateAndInsert - don't reset bRemoveAfterUse flag
1606cdf0e10cSrcweir
1607cdf0e10cSrcweir if (nKey > -1)
1608cdf0e10cSrcweir return nKey;
1609cdf0e10cSrcweir else
1610cdf0e10cSrcweir {
1611cdf0e10cSrcweir CreateAndInsert(sal_True);
1612cdf0e10cSrcweir return nKey;
1613cdf0e10cSrcweir }
1614cdf0e10cSrcweir }
1615cdf0e10cSrcweir
CreateAndInsert(com::sun::star::uno::Reference<com::sun::star::util::XNumberFormatsSupplier> & xFormatsSupplier)1616cdf0e10cSrcweir sal_Int32 SvXMLNumFormatContext::CreateAndInsert( com::sun::star::uno::Reference< com::sun::star::util::XNumberFormatsSupplier >& xFormatsSupplier )
1617cdf0e10cSrcweir {
1618cdf0e10cSrcweir if (nKey <= -1)
1619cdf0e10cSrcweir {
1620cdf0e10cSrcweir SvNumberFormatter* pFormatter = NULL;
1621cdf0e10cSrcweir SvNumberFormatsSupplierObj* pObj =
1622cdf0e10cSrcweir SvNumberFormatsSupplierObj::getImplementation( xFormatsSupplier );
1623cdf0e10cSrcweir if (pObj)
1624cdf0e10cSrcweir pFormatter = pObj->GetNumberFormatter();
1625cdf0e10cSrcweir
1626cdf0e10cSrcweir if ( pFormatter )
1627cdf0e10cSrcweir return CreateAndInsert( pFormatter );
1628cdf0e10cSrcweir else
1629cdf0e10cSrcweir return -1;
1630cdf0e10cSrcweir }
1631cdf0e10cSrcweir else
1632cdf0e10cSrcweir return nKey;
1633cdf0e10cSrcweir }
1634cdf0e10cSrcweir
CreateAndInsert(sal_Bool)1635cdf0e10cSrcweir void SvXMLNumFormatContext::CreateAndInsert(sal_Bool /*bOverwrite*/)
1636cdf0e10cSrcweir {
1637cdf0e10cSrcweir if (!(nKey > -1))
1638cdf0e10cSrcweir CreateAndInsert(pData->GetNumberFormatter());
1639cdf0e10cSrcweir }
1640cdf0e10cSrcweir
CreateAndInsert(SvNumberFormatter * pFormatter)1641cdf0e10cSrcweir sal_Int32 SvXMLNumFormatContext::CreateAndInsert(SvNumberFormatter* pFormatter)
1642cdf0e10cSrcweir {
1643cdf0e10cSrcweir if (!pFormatter)
1644cdf0e10cSrcweir {
1645cdf0e10cSrcweir DBG_ERROR("no number formatter");
1646cdf0e10cSrcweir return -1;
1647cdf0e10cSrcweir }
1648cdf0e10cSrcweir
1649cdf0e10cSrcweir sal_uInt32 nIndex = NUMBERFORMAT_ENTRY_NOT_FOUND;
1650cdf0e10cSrcweir
1651cdf0e10cSrcweir for (sal_uInt32 i = 0; i < aMyConditions.size(); i++)
1652cdf0e10cSrcweir {
1653cdf0e10cSrcweir SvXMLNumFormatContext* pStyle = (SvXMLNumFormatContext *)pStyles->FindStyleChildContext(
1654cdf0e10cSrcweir XML_STYLE_FAMILY_DATA_STYLE, aMyConditions[i].sMapName, sal_False);
1655cdf0e10cSrcweir if (pStyle)
1656cdf0e10cSrcweir {
1657cdf0e10cSrcweir if ((pStyle->PrivateGetKey() > -1)) // don't reset pStyle's bRemoveAfterUse flag
1658cdf0e10cSrcweir AddCondition(i);
1659cdf0e10cSrcweir }
1660cdf0e10cSrcweir }
1661cdf0e10cSrcweir
1662cdf0e10cSrcweir if ( !aFormatCode.getLength() )
1663cdf0e10cSrcweir {
1664cdf0e10cSrcweir // insert empty format as empty string (with quotes)
1665cdf0e10cSrcweir // #93901# this check has to be done before inserting the conditions
1666cdf0e10cSrcweir aFormatCode.appendAscii("\"\""); // ""
1667cdf0e10cSrcweir }
1668cdf0e10cSrcweir
1669cdf0e10cSrcweir aFormatCode.insert( 0, aConditions.makeStringAndClear() );
1670cdf0e10cSrcweir OUString sFormat = aFormatCode.makeStringAndClear();
1671cdf0e10cSrcweir
1672cdf0e10cSrcweir // test special cases
1673cdf0e10cSrcweir
1674cdf0e10cSrcweir if ( bAutoDec ) // automatic decimal places
1675cdf0e10cSrcweir {
1676cdf0e10cSrcweir // #99391# adjust only if the format contains no text elements, no conditions
1677cdf0e10cSrcweir // and no color definition (detected by the '[' at the start)
1678cdf0e10cSrcweir
1679cdf0e10cSrcweir if ( nType == XML_TOK_STYLES_NUMBER_STYLE && !bHasExtraText &&
1680cdf0e10cSrcweir aMyConditions.size() == 0 && sFormat.toChar() != (sal_Unicode)'[' )
1681cdf0e10cSrcweir nIndex = pFormatter->GetStandardIndex( nFormatLang );
1682cdf0e10cSrcweir }
1683cdf0e10cSrcweir if ( bAutoInt ) // automatic integer digits
1684cdf0e10cSrcweir {
1685cdf0e10cSrcweir //! only if two decimal places was set?
1686cdf0e10cSrcweir
1687cdf0e10cSrcweir if ( nType == XML_TOK_STYLES_NUMBER_STYLE && !bHasExtraText &&
1688cdf0e10cSrcweir aMyConditions.size() == 0 && sFormat.toChar() != (sal_Unicode)'[' )
1689cdf0e10cSrcweir nIndex = pFormatter->GetFormatIndex( NF_NUMBER_SYSTEM, nFormatLang );
1690cdf0e10cSrcweir }
1691cdf0e10cSrcweir
1692cdf0e10cSrcweir // boolean is always the builtin boolean format
1693cdf0e10cSrcweir // (no other boolean formats are implemented)
1694cdf0e10cSrcweir if ( nType == XML_TOK_STYLES_BOOLEAN_STYLE )
1695cdf0e10cSrcweir nIndex = pFormatter->GetFormatIndex( NF_BOOLEAN, nFormatLang );
1696cdf0e10cSrcweir
1697cdf0e10cSrcweir // check for default date formats
1698cdf0e10cSrcweir if ( nType == XML_TOK_STYLES_DATE_STYLE && bAutoOrder && !bDateNoDefault )
1699cdf0e10cSrcweir {
1700cdf0e10cSrcweir NfIndexTableOffset eFormat = (NfIndexTableOffset) SvXMLNumFmtDefaults::GetDefaultDateFormat(
1701cdf0e10cSrcweir eDateDOW, eDateDay, eDateMonth, eDateYear,
1702cdf0e10cSrcweir eDateHours, eDateMins, eDateSecs, bFromSystem );
1703cdf0e10cSrcweir if ( eFormat < NF_INDEX_TABLE_ENTRIES )
1704cdf0e10cSrcweir {
1705cdf0e10cSrcweir // #109651# if a date format has the automatic-order attribute and
1706cdf0e10cSrcweir // contains exactly the elements of one of the default date formats,
1707cdf0e10cSrcweir // use that default format, with the element order and separators
1708cdf0e10cSrcweir // from the current locale settings
1709cdf0e10cSrcweir
1710cdf0e10cSrcweir nIndex = pFormatter->GetFormatIndex( eFormat, nFormatLang );
1711cdf0e10cSrcweir }
1712cdf0e10cSrcweir }
1713cdf0e10cSrcweir
1714cdf0e10cSrcweir if ( nIndex == NUMBERFORMAT_ENTRY_NOT_FOUND && sFormat.getLength() )
1715cdf0e10cSrcweir {
1716cdf0e10cSrcweir // insert by format string
1717cdf0e10cSrcweir
1718cdf0e10cSrcweir String aFormatStr( sFormat );
1719cdf0e10cSrcweir nIndex = pFormatter->GetEntryKey( aFormatStr, nFormatLang );
1720cdf0e10cSrcweir if ( nIndex == NUMBERFORMAT_ENTRY_NOT_FOUND )
1721cdf0e10cSrcweir {
1722cdf0e10cSrcweir xub_StrLen nErrPos = 0;
1723cdf0e10cSrcweir short l_nType = 0;
1724cdf0e10cSrcweir sal_Bool bOk = pFormatter->PutEntry( aFormatStr, nErrPos, l_nType, nIndex, nFormatLang );
1725cdf0e10cSrcweir if ( !bOk && nErrPos == 0 && aFormatStr != String(sFormat) )
1726cdf0e10cSrcweir {
1727cdf0e10cSrcweir // if the string was modified by PutEntry, look for an existing format
1728cdf0e10cSrcweir // with the modified string
1729cdf0e10cSrcweir nIndex = pFormatter->GetEntryKey( aFormatStr, nFormatLang );
1730cdf0e10cSrcweir if ( nIndex != NUMBERFORMAT_ENTRY_NOT_FOUND )
1731cdf0e10cSrcweir bOk = sal_True;
1732cdf0e10cSrcweir }
1733cdf0e10cSrcweir if (!bOk)
1734cdf0e10cSrcweir nIndex = NUMBERFORMAT_ENTRY_NOT_FOUND;
1735cdf0e10cSrcweir }
1736cdf0e10cSrcweir }
1737cdf0e10cSrcweir
1738cdf0e10cSrcweir #if 0
1739cdf0e10cSrcweir //! I18N doesn't provide SYSTEM or extended date information yet
1740cdf0e10cSrcweir if ( nIndex != NUMBERFORMAT_ENTRY_NOT_FOUND && !bFromSystem )
1741cdf0e10cSrcweir {
1742cdf0e10cSrcweir // instead of automatic date format, use fixed formats if bFromSystem is not set
1743cdf0e10cSrcweir //! prevent use of automatic formats in other cases, force user-defined format?
1744cdf0e10cSrcweir
1745cdf0e10cSrcweir sal_uInt32 nNewIndex = nIndex;
1746cdf0e10cSrcweir
1747cdf0e10cSrcweir NfIndexTableOffset eOffset = pFormatter->GetIndexTableOffset( nIndex );
1748cdf0e10cSrcweir if ( eOffset == NF_DATE_SYSTEM_SHORT )
1749cdf0e10cSrcweir {
1750cdf0e10cSrcweir const International& rInt = pData->GetInternational( nFormatLang );
1751cdf0e10cSrcweir if ( rInt.IsDateDayLeadingZero() && rInt.IsDateMonthLeadingZero() )
1752cdf0e10cSrcweir {
1753cdf0e10cSrcweir if ( rInt.IsDateCentury() )
1754cdf0e10cSrcweir nNewIndex = pFormatter->GetFormatIndex( NF_DATE_SYS_DDMMYYYY, nFormatLang );
1755cdf0e10cSrcweir else
1756cdf0e10cSrcweir nNewIndex = pFormatter->GetFormatIndex( NF_DATE_SYS_DDMMYY, nFormatLang );
1757cdf0e10cSrcweir }
1758cdf0e10cSrcweir }
1759cdf0e10cSrcweir else if ( eOffset == NF_DATE_SYSTEM_LONG )
1760cdf0e10cSrcweir {
1761cdf0e10cSrcweir const International& rInt = pData->GetInternational( nFormatLang );
1762cdf0e10cSrcweir if ( !rInt.IsLongDateDayLeadingZero() )
1763cdf0e10cSrcweir {
1764cdf0e10cSrcweir sal_Bool bCentury = rInt.IsLongDateCentury();
1765cdf0e10cSrcweir MonthFormat eMonth = rInt.GetLongDateMonthFormat();
1766cdf0e10cSrcweir if ( eMonth == MONTH_LONG && bCentury )
1767cdf0e10cSrcweir {
1768cdf0e10cSrcweir if ( rInt.GetLongDateDayOfWeekFormat() == DAYOFWEEK_LONG )
1769cdf0e10cSrcweir nNewIndex = pFormatter->GetFormatIndex( NF_DATE_SYS_NNNNDMMMMYYYY, nFormatLang );
1770cdf0e10cSrcweir else
1771cdf0e10cSrcweir nNewIndex = pFormatter->GetFormatIndex( NF_DATE_SYS_NNDMMMMYYYY, nFormatLang );
1772cdf0e10cSrcweir }
1773cdf0e10cSrcweir else if ( eMonth == MONTH_SHORT && !bCentury )
1774cdf0e10cSrcweir nNewIndex = pFormatter->GetFormatIndex( NF_DATE_SYS_NNDMMMYY, nFormatLang );
1775cdf0e10cSrcweir }
1776cdf0e10cSrcweir }
1777cdf0e10cSrcweir
1778cdf0e10cSrcweir if ( nNewIndex != nIndex )
1779cdf0e10cSrcweir {
1780cdf0e10cSrcweir // verify the fixed format really matches the format string
1781cdf0e10cSrcweir // (not the case with some formats from locale data)
1782cdf0e10cSrcweir
1783cdf0e10cSrcweir const SvNumberformat* pFixedFormat = pFormatter->GetEntry( nNewIndex );
1784cdf0e10cSrcweir if ( pFixedFormat && pFixedFormat->GetFormatstring() == String(sFormat) )
1785cdf0e10cSrcweir nIndex = nNewIndex;
1786cdf0e10cSrcweir }
1787cdf0e10cSrcweir }
1788cdf0e10cSrcweir #endif
1789cdf0e10cSrcweir
1790cdf0e10cSrcweir if ( nIndex != NUMBERFORMAT_ENTRY_NOT_FOUND && !bAutoOrder )
1791cdf0e10cSrcweir {
1792cdf0e10cSrcweir // use fixed-order formats instead of SYS... if bAutoOrder is false
1793cdf0e10cSrcweir // (only if the format strings are equal for the locale)
1794cdf0e10cSrcweir
1795cdf0e10cSrcweir NfIndexTableOffset eOffset = pFormatter->GetIndexTableOffset( nIndex );
1796cdf0e10cSrcweir if ( eOffset == NF_DATE_SYS_DMMMYYYY )
1797cdf0e10cSrcweir {
1798cdf0e10cSrcweir sal_uInt32 nNewIndex = pFormatter->GetFormatIndex( NF_DATE_DIN_DMMMYYYY, nFormatLang );
1799cdf0e10cSrcweir const SvNumberformat* pOldEntry = pFormatter->GetEntry( nIndex );
1800cdf0e10cSrcweir const SvNumberformat* pNewEntry = pFormatter->GetEntry( nNewIndex );
1801cdf0e10cSrcweir if ( pOldEntry && pNewEntry && pOldEntry->GetFormatstring() == pNewEntry->GetFormatstring() )
1802cdf0e10cSrcweir nIndex = nNewIndex;
1803cdf0e10cSrcweir }
1804cdf0e10cSrcweir else if ( eOffset == NF_DATE_SYS_DMMMMYYYY )
1805cdf0e10cSrcweir {
1806cdf0e10cSrcweir sal_uInt32 nNewIndex = pFormatter->GetFormatIndex( NF_DATE_DIN_DMMMMYYYY, nFormatLang );
1807cdf0e10cSrcweir const SvNumberformat* pOldEntry = pFormatter->GetEntry( nIndex );
1808cdf0e10cSrcweir const SvNumberformat* pNewEntry = pFormatter->GetEntry( nNewIndex );
1809cdf0e10cSrcweir if ( pOldEntry && pNewEntry && pOldEntry->GetFormatstring() == pNewEntry->GetFormatstring() )
1810cdf0e10cSrcweir nIndex = nNewIndex;
1811cdf0e10cSrcweir }
1812cdf0e10cSrcweir }
1813cdf0e10cSrcweir
1814cdf0e10cSrcweir if ((nIndex != NUMBERFORMAT_ENTRY_NOT_FOUND) && sFormatTitle.getLength())
1815cdf0e10cSrcweir {
1816cdf0e10cSrcweir SvNumberformat* pFormat = const_cast<SvNumberformat*>(pFormatter->GetEntry( nIndex ));
1817cdf0e10cSrcweir if (pFormat)
1818cdf0e10cSrcweir {
1819cdf0e10cSrcweir String sTitle (sFormatTitle);
1820cdf0e10cSrcweir pFormat->SetComment(sTitle);
1821cdf0e10cSrcweir }
1822cdf0e10cSrcweir }
1823cdf0e10cSrcweir
1824cdf0e10cSrcweir if ( nIndex == NUMBERFORMAT_ENTRY_NOT_FOUND )
1825cdf0e10cSrcweir {
1826cdf0e10cSrcweir DBG_ERROR("invalid number format");
1827cdf0e10cSrcweir nIndex = pFormatter->GetStandardIndex( nFormatLang );
1828cdf0e10cSrcweir }
1829cdf0e10cSrcweir
1830cdf0e10cSrcweir pData->AddKey( nIndex, GetName(), bRemoveAfterUse );
1831cdf0e10cSrcweir nKey = nIndex;
1832cdf0e10cSrcweir
1833cdf0e10cSrcweir // Add to import's list of keys (shared between styles and content import)
1834cdf0e10cSrcweir // only if not volatile - formats are removed from NumberFormatter at the
1835cdf0e10cSrcweir // end of each import (in SvXMLNumFmtHelper dtor).
1836cdf0e10cSrcweir // If bRemoveAfterUse is reset later in GetKey, AddNumberStyle is called there.
1837cdf0e10cSrcweir
1838cdf0e10cSrcweir if (!bRemoveAfterUse)
1839cdf0e10cSrcweir GetImport().AddNumberStyle( nKey, GetName() );
1840cdf0e10cSrcweir
1841cdf0e10cSrcweir #if 0
1842cdf0e10cSrcweir ByteString aByte( String(sFormatName), gsl_getSystemTextEncoding() );
1843cdf0e10cSrcweir aByte.Append( " | " );
1844cdf0e10cSrcweir aByte.Append(ByteString( String(sFormat), gsl_getSystemTextEncoding() ));
1845cdf0e10cSrcweir aByte.Append( " | " );
1846cdf0e10cSrcweir aByte.Append(ByteString::CreateFromInt32( nIndex ));
1847cdf0e10cSrcweir
1848cdf0e10cSrcweir // DBG_ERROR(aByte.GetBuffer());
1849cdf0e10cSrcweir int xxx=42;
1850cdf0e10cSrcweir #endif
1851cdf0e10cSrcweir
1852cdf0e10cSrcweir return nKey;
1853cdf0e10cSrcweir }
1854cdf0e10cSrcweir
Finish(sal_Bool bOverwrite)1855cdf0e10cSrcweir void SvXMLNumFormatContext::Finish( sal_Bool bOverwrite )
1856cdf0e10cSrcweir {
1857cdf0e10cSrcweir SvXMLStyleContext::Finish( bOverwrite );
1858cdf0e10cSrcweir // AddCondition();
1859cdf0e10cSrcweir }
1860cdf0e10cSrcweir
GetLocaleData() const1861cdf0e10cSrcweir const LocaleDataWrapper& SvXMLNumFormatContext::GetLocaleData() const
1862cdf0e10cSrcweir {
1863cdf0e10cSrcweir return pData->GetLocaleData( nFormatLang );
1864cdf0e10cSrcweir }
1865cdf0e10cSrcweir
AddToCode(const rtl::OUString & rString)1866cdf0e10cSrcweir void SvXMLNumFormatContext::AddToCode( const rtl::OUString& rString )
1867cdf0e10cSrcweir {
1868cdf0e10cSrcweir aFormatCode.append( rString );
1869cdf0e10cSrcweir bHasExtraText = sal_True;
1870cdf0e10cSrcweir }
1871cdf0e10cSrcweir
AddNumber(const SvXMLNumberInfo & rInfo)1872cdf0e10cSrcweir void SvXMLNumFormatContext::AddNumber( const SvXMLNumberInfo& rInfo )
1873cdf0e10cSrcweir {
1874cdf0e10cSrcweir SvNumberFormatter* pFormatter = pData->GetNumberFormatter();
1875cdf0e10cSrcweir if (!pFormatter)
1876cdf0e10cSrcweir return;
1877cdf0e10cSrcweir
1878cdf0e10cSrcweir // store special conditions
1879cdf0e10cSrcweir bAutoDec = ( rInfo.nDecimals < 0 );
1880cdf0e10cSrcweir bAutoInt = ( rInfo.nInteger < 0 );
1881cdf0e10cSrcweir
1882cdf0e10cSrcweir sal_uInt16 nPrec = 0;
1883cdf0e10cSrcweir sal_uInt16 nLeading = 0;
1884cdf0e10cSrcweir if ( rInfo.nDecimals >= 0 ) // < 0 : Default
1885cdf0e10cSrcweir nPrec = (sal_uInt16) rInfo.nDecimals;
1886cdf0e10cSrcweir if ( rInfo.nInteger >= 0 ) // < 0 : Default
1887cdf0e10cSrcweir nLeading = (sal_uInt16) rInfo.nInteger;
1888cdf0e10cSrcweir
1889cdf0e10cSrcweir if ( bAutoDec )
1890cdf0e10cSrcweir {
1891cdf0e10cSrcweir if ( nType == XML_TOK_STYLES_CURRENCY_STYLE )
1892cdf0e10cSrcweir {
1893cdf0e10cSrcweir // for currency formats, "automatic decimals" is used for the automatic
1894cdf0e10cSrcweir // currency format with (fixed) decimals from the locale settings
1895cdf0e10cSrcweir
1896cdf0e10cSrcweir const LocaleDataWrapper& rLoc = pData->GetLocaleData( nFormatLang );
1897cdf0e10cSrcweir nPrec = rLoc.getCurrDigits();
1898cdf0e10cSrcweir }
1899cdf0e10cSrcweir else
1900cdf0e10cSrcweir {
1901cdf0e10cSrcweir // for other types, "automatic decimals" means dynamic determination of
1902cdf0e10cSrcweir // decimals, as achieved with the "general" keyword
1903cdf0e10cSrcweir
1904cdf0e10cSrcweir aFormatCode.append( pFormatter->GetStandardName( nFormatLang ) );
1905cdf0e10cSrcweir return;
1906cdf0e10cSrcweir }
1907cdf0e10cSrcweir }
1908cdf0e10cSrcweir if ( bAutoInt )
1909cdf0e10cSrcweir {
1910cdf0e10cSrcweir //!...
1911cdf0e10cSrcweir }
1912cdf0e10cSrcweir
1913cdf0e10cSrcweir sal_uInt16 nGenPrec = nPrec;
1914cdf0e10cSrcweir if ( rInfo.bDecReplace || rInfo.bVarDecimals )
1915cdf0e10cSrcweir nGenPrec = 0; // generate format without decimals...
1916cdf0e10cSrcweir
1917cdf0e10cSrcweir sal_Bool bGrouping = rInfo.bGrouping;
1918cdf0e10cSrcweir sal_uInt16 nEmbeddedCount = rInfo.aEmbeddedElements.Count();
1919cdf0e10cSrcweir if ( nEmbeddedCount )
1920cdf0e10cSrcweir bGrouping = sal_False; // grouping and embedded characters can't be used together
1921cdf0e10cSrcweir
1922cdf0e10cSrcweir String aNumStr;
1923cdf0e10cSrcweir sal_uInt32 nStdIndex = pFormatter->GetStandardIndex( nFormatLang );
1924cdf0e10cSrcweir pFormatter->GenerateFormat( aNumStr, nStdIndex, nFormatLang,
1925cdf0e10cSrcweir bGrouping, sal_False, nGenPrec, nLeading );
1926cdf0e10cSrcweir
1927cdf0e10cSrcweir if ( rInfo.nExpDigits >= 0 && nLeading == 0 && !bGrouping && nEmbeddedCount == 0 )
1928cdf0e10cSrcweir {
1929cdf0e10cSrcweir // #i43959# For scientific numbers, "#" in the integer part forces a digit,
1930cdf0e10cSrcweir // so it has to be removed if nLeading is 0 (".00E+0", not "#.00E+0").
1931cdf0e10cSrcweir
1932cdf0e10cSrcweir aNumStr.EraseLeadingChars( (sal_Unicode)'#' );
1933cdf0e10cSrcweir }
1934cdf0e10cSrcweir
1935cdf0e10cSrcweir if ( nEmbeddedCount )
1936cdf0e10cSrcweir {
1937cdf0e10cSrcweir // insert embedded strings into number string
1938cdf0e10cSrcweir // only the integer part is supported
1939cdf0e10cSrcweir // nZeroPos is the string position where format position 0 is inserted
1940cdf0e10cSrcweir
1941cdf0e10cSrcweir xub_StrLen nZeroPos = aNumStr.Search( pData->GetLocaleData( nFormatLang ).getNumDecimalSep() );
1942cdf0e10cSrcweir if ( nZeroPos == STRING_NOTFOUND )
1943cdf0e10cSrcweir nZeroPos = aNumStr.Len();
1944cdf0e10cSrcweir
1945cdf0e10cSrcweir // aEmbeddedElements is sorted - last entry has the largest position (leftmost)
1946cdf0e10cSrcweir const SvXMLEmbeddedElement* pLastObj = rInfo.aEmbeddedElements[nEmbeddedCount - 1];
1947cdf0e10cSrcweir sal_Int32 nLastFormatPos = pLastObj->nFormatPos;
1948cdf0e10cSrcweir if ( nLastFormatPos >= nZeroPos )
1949cdf0e10cSrcweir {
1950cdf0e10cSrcweir // add '#' characters so all embedded texts are really embedded in digits
1951cdf0e10cSrcweir // (there always has to be a digit before the leftmost embedded text)
1952cdf0e10cSrcweir
1953cdf0e10cSrcweir xub_StrLen nAddCount = (xub_StrLen)nLastFormatPos + 1 - nZeroPos;
1954cdf0e10cSrcweir String aDigitStr;
1955cdf0e10cSrcweir aDigitStr.Fill( nAddCount, (sal_Unicode)'#' );
1956cdf0e10cSrcweir aNumStr.Insert( aDigitStr, 0 );
1957cdf0e10cSrcweir nZeroPos = nZeroPos + nAddCount;
1958cdf0e10cSrcweir }
1959cdf0e10cSrcweir
1960cdf0e10cSrcweir // aEmbeddedElements is sorted with ascending positions - loop is from right to left
1961cdf0e10cSrcweir for (sal_uInt16 nElement = 0; nElement < nEmbeddedCount; nElement++)
1962cdf0e10cSrcweir {
1963cdf0e10cSrcweir const SvXMLEmbeddedElement* pObj = rInfo.aEmbeddedElements[nElement];
1964cdf0e10cSrcweir sal_Int32 nFormatPos = pObj->nFormatPos;
1965cdf0e10cSrcweir sal_Int32 nInsertPos = nZeroPos - nFormatPos;
1966cdf0e10cSrcweir if ( nFormatPos >= 0 && nInsertPos >= 0 )
1967cdf0e10cSrcweir {
1968cdf0e10cSrcweir rtl::OUStringBuffer aContent( pObj->aText );
1969cdf0e10cSrcweir // #107805# always quote embedded strings - even space would otherwise
1970cdf0e10cSrcweir // be recognized as thousands separator in French.
1971cdf0e10cSrcweir aContent.insert( 0, (sal_Unicode) '"' );
1972cdf0e10cSrcweir aContent.append( (sal_Unicode) '"' );
1973cdf0e10cSrcweir
1974cdf0e10cSrcweir aNumStr.Insert( String( aContent.makeStringAndClear() ), (xub_StrLen)nInsertPos );
1975cdf0e10cSrcweir }
1976cdf0e10cSrcweir }
1977cdf0e10cSrcweir }
1978cdf0e10cSrcweir
1979cdf0e10cSrcweir aFormatCode.append( aNumStr );
1980cdf0e10cSrcweir
1981cdf0e10cSrcweir if ( ( rInfo.bDecReplace || rInfo.bVarDecimals ) && nPrec ) // add decimal replacement (dashes)
1982cdf0e10cSrcweir {
1983cdf0e10cSrcweir // add dashes for explicit decimal replacement, # for variable decimals
1984cdf0e10cSrcweir sal_Unicode cAdd = rInfo.bDecReplace ? '-' : '#';
1985cdf0e10cSrcweir
1986cdf0e10cSrcweir aFormatCode.append( pData->GetLocaleData( nFormatLang ).getNumDecimalSep() );
1987cdf0e10cSrcweir for ( sal_uInt16 i=0; i<nPrec; i++)
1988cdf0e10cSrcweir aFormatCode.append( cAdd );
1989cdf0e10cSrcweir }
1990cdf0e10cSrcweir
1991cdf0e10cSrcweir // add extra thousands separators for display factor
1992cdf0e10cSrcweir
1993cdf0e10cSrcweir if ( rInfo.fDisplayFactor != 1.0 && rInfo.fDisplayFactor > 0.0 )
1994cdf0e10cSrcweir {
1995cdf0e10cSrcweir // test for 1.0 is just for optimization - nSepCount would be 0
1996cdf0e10cSrcweir
1997cdf0e10cSrcweir // one separator for each factor of 1000
1998cdf0e10cSrcweir sal_Int32 nSepCount = (sal_Int32) ::rtl::math::round( log10(rInfo.fDisplayFactor) / 3.0 );
1999cdf0e10cSrcweir if ( nSepCount > 0 )
2000cdf0e10cSrcweir {
2001cdf0e10cSrcweir OUString aSep = pData->GetLocaleData( nFormatLang ).getNumThousandSep();
2002cdf0e10cSrcweir for ( sal_Int32 i=0; i<nSepCount; i++ )
2003cdf0e10cSrcweir aFormatCode.append( aSep );
2004cdf0e10cSrcweir }
2005cdf0e10cSrcweir }
2006cdf0e10cSrcweir }
2007cdf0e10cSrcweir
AddCurrency(const rtl::OUString & rContent,LanguageType nLang)2008cdf0e10cSrcweir void SvXMLNumFormatContext::AddCurrency( const rtl::OUString& rContent, LanguageType nLang )
2009cdf0e10cSrcweir {
2010cdf0e10cSrcweir sal_Bool bAutomatic = sal_False;
2011cdf0e10cSrcweir OUString aSymbol = rContent;
2012cdf0e10cSrcweir if ( aSymbol.getLength() == 0 )
2013cdf0e10cSrcweir {
2014cdf0e10cSrcweir // get currency symbol for language
2015cdf0e10cSrcweir
2016cdf0e10cSrcweir //aSymbol = pData->GetLocaleData( nFormatLang ).getCurrSymbol();
2017cdf0e10cSrcweir
2018cdf0e10cSrcweir SvNumberFormatter* pFormatter = pData->GetNumberFormatter();
2019cdf0e10cSrcweir if ( pFormatter )
2020cdf0e10cSrcweir {
2021cdf0e10cSrcweir pFormatter->ChangeIntl( nFormatLang );
2022cdf0e10cSrcweir String sCurString, sDummy;
2023cdf0e10cSrcweir pFormatter->GetCompatibilityCurrency( sCurString, sDummy );
2024cdf0e10cSrcweir aSymbol = sCurString;
2025cdf0e10cSrcweir
2026cdf0e10cSrcweir bAutomatic = sal_True;
2027cdf0e10cSrcweir }
2028cdf0e10cSrcweir }
2029cdf0e10cSrcweir else if ( nLang == LANGUAGE_SYSTEM && aSymbol.compareToAscii("CCC") == 0 )
2030cdf0e10cSrcweir {
2031cdf0e10cSrcweir // "CCC" is used for automatic long symbol
2032cdf0e10cSrcweir bAutomatic = sal_True;
2033cdf0e10cSrcweir }
2034cdf0e10cSrcweir
2035cdf0e10cSrcweir if ( bAutomatic )
2036cdf0e10cSrcweir {
2037cdf0e10cSrcweir // remove unnecessary quotes before automatic symbol (formats like "-(0DM)")
2038cdf0e10cSrcweir // otherwise the currency symbol isn't recognized (#94048#)
2039cdf0e10cSrcweir
2040cdf0e10cSrcweir sal_Int32 nLength = aFormatCode.getLength();
2041cdf0e10cSrcweir if ( nLength > 1 && aFormatCode.charAt( nLength-1 ) == '"' )
2042cdf0e10cSrcweir {
2043cdf0e10cSrcweir // find start of quoted string
2044cdf0e10cSrcweir // When SvXMLNumFmtElementContext::EndElement creates escaped quotes,
2045cdf0e10cSrcweir // they must be handled here, too.
2046cdf0e10cSrcweir
2047cdf0e10cSrcweir sal_Int32 nFirst = nLength - 2;
2048cdf0e10cSrcweir while ( nFirst >= 0 && aFormatCode.charAt( nFirst ) != '"' )
2049cdf0e10cSrcweir --nFirst;
2050cdf0e10cSrcweir if ( nFirst >= 0 )
2051cdf0e10cSrcweir {
2052cdf0e10cSrcweir // remove both quotes from aFormatCode
2053cdf0e10cSrcweir rtl::OUString aOld = aFormatCode.makeStringAndClear();
2054cdf0e10cSrcweir if ( nFirst > 0 )
2055cdf0e10cSrcweir aFormatCode.append( aOld.copy( 0, nFirst ) );
2056cdf0e10cSrcweir if ( nLength > nFirst + 2 )
2057cdf0e10cSrcweir aFormatCode.append( aOld.copy( nFirst + 1, nLength - nFirst - 2 ) );
2058cdf0e10cSrcweir }
2059cdf0e10cSrcweir }
2060cdf0e10cSrcweir }
2061cdf0e10cSrcweir
2062cdf0e10cSrcweir if (!bAutomatic)
2063cdf0e10cSrcweir aFormatCode.appendAscii( "[$" ); // intro for "new" currency symbols
2064cdf0e10cSrcweir
2065cdf0e10cSrcweir aFormatCode.append( aSymbol );
2066cdf0e10cSrcweir
2067cdf0e10cSrcweir if (!bAutomatic)
2068cdf0e10cSrcweir {
2069cdf0e10cSrcweir if ( nLang != LANGUAGE_SYSTEM )
2070cdf0e10cSrcweir {
2071cdf0e10cSrcweir // '-' sign and language code in hex:
2072cdf0e10cSrcweir aFormatCode.append( (sal_Unicode) '-' );
2073cdf0e10cSrcweir aFormatCode.append( String::CreateFromInt32( sal_Int32( nLang ), 16 ).ToUpperAscii() );
2074cdf0e10cSrcweir }
2075cdf0e10cSrcweir
2076cdf0e10cSrcweir aFormatCode.append( (sal_Unicode) ']' ); // end of "new" currency symbol
2077cdf0e10cSrcweir }
2078cdf0e10cSrcweir }
2079cdf0e10cSrcweir
AddNfKeyword(sal_uInt16 nIndex)2080cdf0e10cSrcweir void SvXMLNumFormatContext::AddNfKeyword( sal_uInt16 nIndex )
2081cdf0e10cSrcweir {
2082cdf0e10cSrcweir SvNumberFormatter* pFormatter = pData->GetNumberFormatter();
2083cdf0e10cSrcweir if (!pFormatter)
2084cdf0e10cSrcweir return;
2085cdf0e10cSrcweir
2086cdf0e10cSrcweir if ( nIndex == NF_KEY_G || nIndex == NF_KEY_GG || nIndex == NF_KEY_GGG )
2087cdf0e10cSrcweir bHasEra = sal_True;
2088cdf0e10cSrcweir
2089cdf0e10cSrcweir if ( nIndex == NF_KEY_NNNN )
2090cdf0e10cSrcweir {
2091cdf0e10cSrcweir nIndex = NF_KEY_NNN;
2092cdf0e10cSrcweir bHasLongDoW = sal_True; // to remove string constant with separator
2093cdf0e10cSrcweir }
2094cdf0e10cSrcweir
2095cdf0e10cSrcweir String sKeyword = pFormatter->GetKeyword( nFormatLang, nIndex );
2096cdf0e10cSrcweir
2097cdf0e10cSrcweir if ( nIndex == NF_KEY_H || nIndex == NF_KEY_HH ||
2098cdf0e10cSrcweir nIndex == NF_KEY_MI || nIndex == NF_KEY_MMI ||
2099cdf0e10cSrcweir nIndex == NF_KEY_S || nIndex == NF_KEY_SS )
2100cdf0e10cSrcweir {
2101cdf0e10cSrcweir if ( !bTruncate && !bHasDateTime )
2102cdf0e10cSrcweir {
2103cdf0e10cSrcweir // with truncate-on-overflow = false, add "[]" to first time part
2104cdf0e10cSrcweir
2105cdf0e10cSrcweir sKeyword.Insert( (sal_Unicode) '[', 0 );
2106cdf0e10cSrcweir sKeyword.Append( (sal_Unicode) ']' );
2107cdf0e10cSrcweir }
2108cdf0e10cSrcweir bHasDateTime = sal_True;
2109cdf0e10cSrcweir }
2110cdf0e10cSrcweir
2111cdf0e10cSrcweir aFormatCode.append( sKeyword );
2112cdf0e10cSrcweir
2113cdf0e10cSrcweir // collect the date elements that the format contains, to recognize default date formats
2114cdf0e10cSrcweir switch ( nIndex )
2115cdf0e10cSrcweir {
2116cdf0e10cSrcweir case NF_KEY_NN: eDateDOW = XML_DEA_SHORT; break;
2117cdf0e10cSrcweir case NF_KEY_NNN:
2118cdf0e10cSrcweir case NF_KEY_NNNN: eDateDOW = XML_DEA_LONG; break;
2119cdf0e10cSrcweir case NF_KEY_D: eDateDay = XML_DEA_SHORT; break;
2120cdf0e10cSrcweir case NF_KEY_DD: eDateDay = XML_DEA_LONG; break;
2121cdf0e10cSrcweir case NF_KEY_M: eDateMonth = XML_DEA_SHORT; break;
2122cdf0e10cSrcweir case NF_KEY_MM: eDateMonth = XML_DEA_LONG; break;
2123cdf0e10cSrcweir case NF_KEY_MMM: eDateMonth = XML_DEA_TEXTSHORT; break;
2124cdf0e10cSrcweir case NF_KEY_MMMM: eDateMonth = XML_DEA_TEXTLONG; break;
2125cdf0e10cSrcweir case NF_KEY_YY: eDateYear = XML_DEA_SHORT; break;
2126cdf0e10cSrcweir case NF_KEY_YYYY: eDateYear = XML_DEA_LONG; break;
2127cdf0e10cSrcweir case NF_KEY_H: eDateHours = XML_DEA_SHORT; break;
2128cdf0e10cSrcweir case NF_KEY_HH: eDateHours = XML_DEA_LONG; break;
2129cdf0e10cSrcweir case NF_KEY_MI: eDateMins = XML_DEA_SHORT; break;
2130cdf0e10cSrcweir case NF_KEY_MMI: eDateMins = XML_DEA_LONG; break;
2131cdf0e10cSrcweir case NF_KEY_S: eDateSecs = XML_DEA_SHORT; break;
2132cdf0e10cSrcweir case NF_KEY_SS: eDateSecs = XML_DEA_LONG; break;
2133cdf0e10cSrcweir case NF_KEY_AP:
2134cdf0e10cSrcweir case NF_KEY_AMPM: break; // AM/PM may or may not be in date/time formats -> ignore by itself
2135cdf0e10cSrcweir default:
2136cdf0e10cSrcweir bDateNoDefault = sal_True; // any other element -> no default format
2137cdf0e10cSrcweir }
2138cdf0e10cSrcweir }
2139cdf0e10cSrcweir
lcl_IsAtEnd(rtl::OUStringBuffer & rBuffer,const String & rToken)2140cdf0e10cSrcweir sal_Bool lcl_IsAtEnd( rtl::OUStringBuffer& rBuffer, const String& rToken )
2141cdf0e10cSrcweir {
2142cdf0e10cSrcweir sal_Int32 nBufLen = rBuffer.getLength();
2143cdf0e10cSrcweir xub_StrLen nTokLen = rToken.Len();
2144cdf0e10cSrcweir
2145cdf0e10cSrcweir if ( nTokLen > nBufLen )
2146cdf0e10cSrcweir return sal_False;
2147cdf0e10cSrcweir
2148cdf0e10cSrcweir sal_Int32 nStartPos = nBufLen - nTokLen;
2149cdf0e10cSrcweir for ( xub_StrLen nTokPos = 0; nTokPos < nTokLen; nTokPos++ )
2150cdf0e10cSrcweir if ( rToken.GetChar( nTokPos ) != rBuffer.charAt( nStartPos + nTokPos ) )
2151cdf0e10cSrcweir return sal_False;
2152cdf0e10cSrcweir
2153cdf0e10cSrcweir return sal_True;
2154cdf0e10cSrcweir }
2155cdf0e10cSrcweir
ReplaceNfKeyword(sal_uInt16 nOld,sal_uInt16 nNew)2156cdf0e10cSrcweir sal_Bool SvXMLNumFormatContext::ReplaceNfKeyword( sal_uInt16 nOld, sal_uInt16 nNew )
2157cdf0e10cSrcweir {
2158cdf0e10cSrcweir // replaces one keyword with another if it is found at the end of the code
2159cdf0e10cSrcweir
2160cdf0e10cSrcweir SvNumberFormatter* pFormatter = pData->GetNumberFormatter();
2161cdf0e10cSrcweir if (!pFormatter)
2162cdf0e10cSrcweir return sal_False;
2163cdf0e10cSrcweir
2164cdf0e10cSrcweir String sOldStr = pFormatter->GetKeyword( nFormatLang, nOld );
2165cdf0e10cSrcweir if ( lcl_IsAtEnd( aFormatCode, sOldStr ) )
2166cdf0e10cSrcweir {
2167cdf0e10cSrcweir // remove old keyword
2168cdf0e10cSrcweir aFormatCode.setLength( aFormatCode.getLength() - sOldStr.Len() );
2169cdf0e10cSrcweir
2170cdf0e10cSrcweir // add new keyword
2171cdf0e10cSrcweir String sNewStr = pFormatter->GetKeyword( nFormatLang, nNew );
2172cdf0e10cSrcweir aFormatCode.append( sNewStr );
2173cdf0e10cSrcweir
2174cdf0e10cSrcweir return sal_True; // changed
2175cdf0e10cSrcweir }
2176cdf0e10cSrcweir return sal_False; // not found
2177cdf0e10cSrcweir }
2178cdf0e10cSrcweir
AddCondition(const sal_Int32 nIndex)2179cdf0e10cSrcweir void SvXMLNumFormatContext::AddCondition( const sal_Int32 nIndex )
2180cdf0e10cSrcweir {
2181cdf0e10cSrcweir rtl::OUString rApplyName = aMyConditions[nIndex].sMapName;
2182cdf0e10cSrcweir rtl::OUString rCondition = aMyConditions[nIndex].sCondition;
2183cdf0e10cSrcweir SvNumberFormatter* pFormatter = pData->GetNumberFormatter();
2184cdf0e10cSrcweir sal_uInt32 l_nKey = pData->GetKeyForName( rApplyName );
2185cdf0e10cSrcweir OUString sValue = OUString::createFromAscii( "value()" ); //! define constant
2186cdf0e10cSrcweir sal_Int32 nValLen = sValue.getLength();
2187cdf0e10cSrcweir
2188cdf0e10cSrcweir if ( pFormatter && l_nKey != NUMBERFORMAT_ENTRY_NOT_FOUND &&
2189cdf0e10cSrcweir rCondition.copy( 0, nValLen ) == sValue )
2190cdf0e10cSrcweir {
2191cdf0e10cSrcweir //! test for valid conditions
2192cdf0e10cSrcweir //! test for default conditions
2193cdf0e10cSrcweir
2194cdf0e10cSrcweir OUString sRealCond = rCondition.copy( nValLen, rCondition.getLength() - nValLen );
2195cdf0e10cSrcweir sal_Bool bDefaultCond = sal_False;
2196cdf0e10cSrcweir
2197cdf0e10cSrcweir //! collect all conditions first and adjust default to >=0, >0 or <0 depending on count
2198cdf0e10cSrcweir //! allow blanks in conditions
2199cdf0e10cSrcweir sal_Bool bFirstCond = ( aConditions.getLength() == 0 );
2200cdf0e10cSrcweir if ( bFirstCond && aMyConditions.size() == 1 && sRealCond.compareToAscii( ">=0" ) == 0 )
2201cdf0e10cSrcweir bDefaultCond = sal_True;
2202cdf0e10cSrcweir
2203cdf0e10cSrcweir if ( nType == XML_TOK_STYLES_TEXT_STYLE && nIndex == 2 )
2204cdf0e10cSrcweir {
2205cdf0e10cSrcweir // The third condition in a number format with a text part can only be
2206cdf0e10cSrcweir // "all other numbers", the condition string must be empty.
2207cdf0e10cSrcweir bDefaultCond = sal_True;
2208cdf0e10cSrcweir }
2209cdf0e10cSrcweir
2210cdf0e10cSrcweir if (!bDefaultCond)
2211cdf0e10cSrcweir {
2212cdf0e10cSrcweir sal_Int32 nPos = sRealCond.indexOf( '.' );
2213cdf0e10cSrcweir if ( nPos >= 0 )
2214cdf0e10cSrcweir { // #i8026# #103991# localize decimal separator
2215cdf0e10cSrcweir const String& rDecSep = GetLocaleData().getNumDecimalSep();
2216cdf0e10cSrcweir if ( rDecSep.Len() > 1 || rDecSep.GetChar(0) != '.' )
2217cdf0e10cSrcweir sRealCond = sRealCond.replaceAt( nPos, 1, rDecSep );
2218cdf0e10cSrcweir }
2219cdf0e10cSrcweir aConditions.append( (sal_Unicode) '[' );
2220cdf0e10cSrcweir aConditions.append( sRealCond );
2221cdf0e10cSrcweir aConditions.append( (sal_Unicode) ']' );
2222cdf0e10cSrcweir }
2223cdf0e10cSrcweir
2224cdf0e10cSrcweir const SvNumberformat* pFormat = pFormatter->GetEntry(l_nKey);
2225cdf0e10cSrcweir if ( pFormat )
2226cdf0e10cSrcweir aConditions.append( OUString( pFormat->GetFormatstring() ) );
2227cdf0e10cSrcweir
2228cdf0e10cSrcweir aConditions.append( (sal_Unicode) ';' );
2229cdf0e10cSrcweir }
2230cdf0e10cSrcweir }
2231cdf0e10cSrcweir
AddCondition(const sal_Int32 nIndex,const rtl::OUString & rFormat,const LocaleDataWrapper & rData)2232cdf0e10cSrcweir void SvXMLNumFormatContext::AddCondition( const sal_Int32 nIndex, const rtl::OUString& rFormat, const LocaleDataWrapper& rData )
2233cdf0e10cSrcweir {
2234cdf0e10cSrcweir rtl::OUString rCondition = aMyConditions[nIndex].sCondition;
2235cdf0e10cSrcweir OUString sValue = OUString::createFromAscii( "value()" ); //! define constant
2236cdf0e10cSrcweir sal_Int32 nValLen = sValue.getLength();
2237cdf0e10cSrcweir
2238cdf0e10cSrcweir if ( rCondition.copy( 0, nValLen ) == sValue )
2239cdf0e10cSrcweir {
2240cdf0e10cSrcweir //! test for valid conditions
2241cdf0e10cSrcweir //! test for default conditions
2242cdf0e10cSrcweir
2243cdf0e10cSrcweir OUString sRealCond = rCondition.copy( nValLen, rCondition.getLength() - nValLen );
2244cdf0e10cSrcweir sal_Bool bDefaultCond = sal_False;
2245cdf0e10cSrcweir
2246cdf0e10cSrcweir //! collect all conditions first and adjust default to >=0, >0 or <0 depending on count
2247cdf0e10cSrcweir //! allow blanks in conditions
2248cdf0e10cSrcweir sal_Bool bFirstCond = ( aConditions.getLength() == 0 );
2249cdf0e10cSrcweir if ( bFirstCond && aMyConditions.size() == 1 && sRealCond.compareToAscii( ">=0" ) == 0 )
2250cdf0e10cSrcweir bDefaultCond = sal_True;
2251cdf0e10cSrcweir
2252cdf0e10cSrcweir if ( nType == XML_TOK_STYLES_TEXT_STYLE && nIndex == 2 )
2253cdf0e10cSrcweir {
2254cdf0e10cSrcweir // The third condition in a number format with a text part can only be
2255cdf0e10cSrcweir // "all other numbers", the condition string must be empty.
2256cdf0e10cSrcweir bDefaultCond = sal_True;
2257cdf0e10cSrcweir }
2258cdf0e10cSrcweir
2259cdf0e10cSrcweir if (!bDefaultCond)
2260cdf0e10cSrcweir {
2261cdf0e10cSrcweir sal_Int32 nPos = sRealCond.indexOf( '.' );
2262cdf0e10cSrcweir if ( nPos >= 0 )
2263cdf0e10cSrcweir { // #i8026# #103991# localize decimal separator
2264cdf0e10cSrcweir const String& rDecSep = rData.getNumDecimalSep();
2265cdf0e10cSrcweir if ( rDecSep.Len() > 1 || rDecSep.GetChar(0) != '.' )
2266cdf0e10cSrcweir sRealCond = sRealCond.replaceAt( nPos, 1, rDecSep );
2267cdf0e10cSrcweir }
2268cdf0e10cSrcweir aConditions.append( (sal_Unicode) '[' );
2269cdf0e10cSrcweir aConditions.append( sRealCond );
2270cdf0e10cSrcweir aConditions.append( (sal_Unicode) ']' );
2271cdf0e10cSrcweir }
2272cdf0e10cSrcweir
2273cdf0e10cSrcweir aConditions.append( rFormat );
2274cdf0e10cSrcweir
2275cdf0e10cSrcweir aConditions.append( (sal_Unicode) ';' );
2276cdf0e10cSrcweir }
2277cdf0e10cSrcweir }
2278cdf0e10cSrcweir
AddCondition(const rtl::OUString & rCondition,const rtl::OUString & rApplyName)2279cdf0e10cSrcweir void SvXMLNumFormatContext::AddCondition( const rtl::OUString& rCondition, const rtl::OUString& rApplyName )
2280cdf0e10cSrcweir {
2281cdf0e10cSrcweir MyCondition aCondition;
2282cdf0e10cSrcweir aCondition.sCondition = rCondition;
2283cdf0e10cSrcweir aCondition.sMapName = rApplyName;
2284cdf0e10cSrcweir aMyConditions.push_back(aCondition);
2285cdf0e10cSrcweir }
2286cdf0e10cSrcweir
AddColor(const Color & rColor)2287cdf0e10cSrcweir void SvXMLNumFormatContext::AddColor( const Color& rColor )
2288cdf0e10cSrcweir {
2289cdf0e10cSrcweir SvNumberFormatter* pFormatter = pData->GetNumberFormatter();
2290cdf0e10cSrcweir if (!pFormatter)
2291cdf0e10cSrcweir return;
2292cdf0e10cSrcweir
2293cdf0e10cSrcweir OUStringBuffer aColName;
2294cdf0e10cSrcweir for ( sal_uInt16 i=0; i<XML_NUMF_COLORCOUNT; i++ )
2295cdf0e10cSrcweir if ( rColor == aNumFmtStdColors[i] )
2296cdf0e10cSrcweir {
2297cdf0e10cSrcweir aColName = OUString( pFormatter->GetKeyword( nFormatLang, sal::static_int_cast< sal_uInt16 >(NF_KEY_FIRSTCOLOR + i) ) );
2298cdf0e10cSrcweir break;
2299cdf0e10cSrcweir }
2300cdf0e10cSrcweir
2301cdf0e10cSrcweir if ( aColName.getLength() )
2302cdf0e10cSrcweir {
2303cdf0e10cSrcweir aColName.insert( 0, (sal_Unicode) '[' );
2304cdf0e10cSrcweir aColName.append( (sal_Unicode) ']' );
2305cdf0e10cSrcweir aFormatCode.insert( 0, aColName.makeStringAndClear() );
2306cdf0e10cSrcweir }
2307cdf0e10cSrcweir }
2308cdf0e10cSrcweir
UpdateCalendar(const rtl::OUString & rNewCalendar)2309cdf0e10cSrcweir void SvXMLNumFormatContext::UpdateCalendar( const rtl::OUString& rNewCalendar )
2310cdf0e10cSrcweir {
2311cdf0e10cSrcweir if ( rNewCalendar != sCalendar )
2312cdf0e10cSrcweir {
2313cdf0e10cSrcweir sCalendar = rNewCalendar;
2314cdf0e10cSrcweir if ( sCalendar.getLength() )
2315cdf0e10cSrcweir {
2316cdf0e10cSrcweir aFormatCode.appendAscii( "[~" ); // intro for calendar code
2317cdf0e10cSrcweir aFormatCode.append( sCalendar );
2318cdf0e10cSrcweir aFormatCode.append( (sal_Unicode) ']' ); // end of "new" currency symbolcalendar code
2319cdf0e10cSrcweir }
2320cdf0e10cSrcweir }
2321cdf0e10cSrcweir }
2322cdf0e10cSrcweir
IsSystemLanguage()2323cdf0e10cSrcweir sal_Bool SvXMLNumFormatContext::IsSystemLanguage()
2324cdf0e10cSrcweir {
2325cdf0e10cSrcweir return nFormatLang == LANGUAGE_SYSTEM;
2326cdf0e10cSrcweir }
2327cdf0e10cSrcweir
2328cdf0e10cSrcweir //-------------------------------------------------------------------------
2329cdf0e10cSrcweir
2330cdf0e10cSrcweir //
2331cdf0e10cSrcweir // SvXMLNumFmtHelper
2332cdf0e10cSrcweir //
2333cdf0e10cSrcweir
2334cdf0e10cSrcweir // #110680#
2335cdf0e10cSrcweir //SvXMLNumFmtHelper::SvXMLNumFmtHelper(
2336cdf0e10cSrcweir // const uno::Reference<util::XNumberFormatsSupplier>& rSupp )
SvXMLNumFmtHelper(const uno::Reference<util::XNumberFormatsSupplier> & rSupp,const uno::Reference<lang::XMultiServiceFactory> & xServiceFactory)2337cdf0e10cSrcweir SvXMLNumFmtHelper::SvXMLNumFmtHelper(
2338cdf0e10cSrcweir const uno::Reference<util::XNumberFormatsSupplier>& rSupp,
2339cdf0e10cSrcweir const uno::Reference<lang::XMultiServiceFactory>& xServiceFactory )
2340cdf0e10cSrcweir : mxServiceFactory(xServiceFactory)
2341cdf0e10cSrcweir {
2342cdf0e10cSrcweir DBG_ASSERT( mxServiceFactory.is(), "got no service manager" );
2343cdf0e10cSrcweir
2344cdf0e10cSrcweir SvNumberFormatter* pFormatter = NULL;
2345cdf0e10cSrcweir SvNumberFormatsSupplierObj* pObj =
2346cdf0e10cSrcweir SvNumberFormatsSupplierObj::getImplementation( rSupp );
2347cdf0e10cSrcweir if (pObj)
2348cdf0e10cSrcweir pFormatter = pObj->GetNumberFormatter();
2349cdf0e10cSrcweir
2350cdf0e10cSrcweir // #110680#
2351cdf0e10cSrcweir // pData = new SvXMLNumImpData( pFormatter );
2352cdf0e10cSrcweir pData = new SvXMLNumImpData( pFormatter, mxServiceFactory );
2353cdf0e10cSrcweir }
2354cdf0e10cSrcweir
2355cdf0e10cSrcweir // #110680#
2356cdf0e10cSrcweir // SvXMLNumFmtHelper::SvXMLNumFmtHelper( SvNumberFormatter* pNumberFormatter )
SvXMLNumFmtHelper(SvNumberFormatter * pNumberFormatter,const uno::Reference<lang::XMultiServiceFactory> & xServiceFactory)2357cdf0e10cSrcweir SvXMLNumFmtHelper::SvXMLNumFmtHelper(
2358cdf0e10cSrcweir SvNumberFormatter* pNumberFormatter,
2359cdf0e10cSrcweir const uno::Reference<lang::XMultiServiceFactory>& xServiceFactory )
2360cdf0e10cSrcweir : mxServiceFactory(xServiceFactory)
2361cdf0e10cSrcweir {
2362cdf0e10cSrcweir DBG_ASSERT( mxServiceFactory.is(), "got no service manager" );
2363cdf0e10cSrcweir
2364cdf0e10cSrcweir // #110680#
2365cdf0e10cSrcweir // pData = new SvXMLNumImpData( pNumberFormatter );
2366cdf0e10cSrcweir pData = new SvXMLNumImpData( pNumberFormatter, mxServiceFactory );
2367cdf0e10cSrcweir }
2368cdf0e10cSrcweir
~SvXMLNumFmtHelper()2369cdf0e10cSrcweir SvXMLNumFmtHelper::~SvXMLNumFmtHelper()
2370cdf0e10cSrcweir {
2371cdf0e10cSrcweir // remove temporary (volatile) formats from NumberFormatter
2372cdf0e10cSrcweir pData->RemoveVolatileFormats();
2373cdf0e10cSrcweir
2374cdf0e10cSrcweir delete pData;
2375cdf0e10cSrcweir }
2376cdf0e10cSrcweir
CreateChildContext(SvXMLImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,SvXMLStylesContext & rStyles)2377cdf0e10cSrcweir SvXMLStyleContext* SvXMLNumFmtHelper::CreateChildContext( SvXMLImport& rImport,
2378cdf0e10cSrcweir sal_uInt16 nPrefix, const OUString& rLocalName,
2379cdf0e10cSrcweir const uno::Reference<xml::sax::XAttributeList>& xAttrList,
2380cdf0e10cSrcweir SvXMLStylesContext& rStyles )
2381cdf0e10cSrcweir {
2382cdf0e10cSrcweir SvXMLStyleContext* pContext = NULL;
2383cdf0e10cSrcweir
2384cdf0e10cSrcweir const SvXMLTokenMap& rTokenMap = pData->GetStylesElemTokenMap();
2385cdf0e10cSrcweir sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
2386cdf0e10cSrcweir switch (nToken)
2387cdf0e10cSrcweir {
2388cdf0e10cSrcweir case XML_TOK_STYLES_NUMBER_STYLE:
2389cdf0e10cSrcweir case XML_TOK_STYLES_CURRENCY_STYLE:
2390cdf0e10cSrcweir case XML_TOK_STYLES_PERCENTAGE_STYLE:
2391cdf0e10cSrcweir case XML_TOK_STYLES_DATE_STYLE:
2392cdf0e10cSrcweir case XML_TOK_STYLES_TIME_STYLE:
2393cdf0e10cSrcweir case XML_TOK_STYLES_BOOLEAN_STYLE:
2394cdf0e10cSrcweir case XML_TOK_STYLES_TEXT_STYLE:
2395cdf0e10cSrcweir pContext = new SvXMLNumFormatContext( rImport, nPrefix, rLocalName,
2396cdf0e10cSrcweir pData, nToken, xAttrList, rStyles );
2397cdf0e10cSrcweir break;
2398cdf0e10cSrcweir }
2399cdf0e10cSrcweir
2400cdf0e10cSrcweir // return NULL if not a data style, caller must handle other elements
2401cdf0e10cSrcweir return pContext;
2402cdf0e10cSrcweir }
2403cdf0e10cSrcweir
GetStylesElemTokenMap()2404cdf0e10cSrcweir const SvXMLTokenMap& SvXMLNumFmtHelper::GetStylesElemTokenMap()
2405cdf0e10cSrcweir {
2406cdf0e10cSrcweir return pData->GetStylesElemTokenMap();
2407cdf0e10cSrcweir }
2408cdf0e10cSrcweir
2409cdf0e10cSrcweir /*sal_uInt32 SvXMLNumFmtHelper::GetKeyForName( const rtl::OUString& rName )
2410cdf0e10cSrcweir {
2411cdf0e10cSrcweir return pData->GetKeyForName( rName );
2412cdf0e10cSrcweir }*/
2413cdf0e10cSrcweir
2414cdf0e10cSrcweir
2415