xref: /aoo4110/main/xmloff/inc/xmloff/xmlnumfi.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _XMLOFF_XMLNUMFI_HXX
25 #define _XMLOFF_XMLNUMFI_HXX
26 
27 #include "sal/config.h"
28 #include "xmloff/dllapi.h"
29 #include "sal/types.h"
30 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
31 #include <com/sun/star/xml/sax/XAttributeList.hpp>
32 #include <xmloff/xmlstyle.hxx>
33 #include <rtl/ustrbuf.hxx>
34 #include <i18npool/lang.h>
35 #ifndef __SGI_STL_VECTOR
36 #include <vector>
37 #endif
38 #include <unotools/localedatawrapper.hxx>
39 
40 #define XML_NUMBERSTYLES "NumberStyles"
41 
42 enum SvXMLStylesTokens
43 {
44 	XML_TOK_STYLES_NUMBER_STYLE,
45 	XML_TOK_STYLES_CURRENCY_STYLE,
46 	XML_TOK_STYLES_PERCENTAGE_STYLE,
47 	XML_TOK_STYLES_DATE_STYLE,
48 	XML_TOK_STYLES_TIME_STYLE,
49 	XML_TOK_STYLES_BOOLEAN_STYLE,
50 	XML_TOK_STYLES_TEXT_STYLE
51 };
52 
53 enum SvXMLDateElementAttributes
54 {
55 	XML_DEA_NONE,
56 	XML_DEA_ANY,
57 	XML_DEA_SHORT,
58 	XML_DEA_LONG,
59 	XML_DEA_TEXTSHORT,
60 	XML_DEA_TEXTLONG
61 };
62 
63 class Color;
64 class SvXMLNumImpData;
65 class SvXMLImport;
66 class SvXMLStyleContext;
67 class SvXMLStylesContext;
68 struct SvXMLNumberInfo;
69 class SvNumberFormatter;
70 class SvtSysLocale;
71 
72 //	use SvXMLNumFmtHelper in the context for <office:styles> to create
73 //	child contexts for data styles
74 
75 class SvXMLNumFmtHelper
76 {
77 	SvXMLNumImpData* pData;
78 
79 	// #110680#
80 	::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxServiceFactory;
81 
82 public:
83 	// #110680#
84 	//SvXMLNumFmtHelper( const ::com::sun::star::uno::Reference<
85 	//		::com::sun::star::util::XNumberFormatsSupplier >& rSupp );
86 	//SvXMLNumFmtHelper( SvNumberFormatter* pNumberFormatter );
87 	SvXMLNumFmtHelper(
88 		const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >& rSupp,
89 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory );
90 
91 	SvXMLNumFmtHelper(
92 		SvNumberFormatter* pNumberFormatter,
93 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory );
94 
95 	~SvXMLNumFmtHelper();
96 
97 	SvXMLStyleContext*	CreateChildContext( SvXMLImport& rImport,
98 				sal_uInt16 nPrefix, const rtl::OUString& rLocalName,
99 				const ::com::sun::star::uno::Reference<
100 				  	::com::sun::star::xml::sax::XAttributeList>& xAttrList,
101 					SvXMLStylesContext& rStyles);
102 
getData()103 	SvXMLNumImpData* getData() { return pData; }
104 
105 	const SvXMLTokenMap&	GetStylesElemTokenMap();
106 
107 //	sal_uInt32	GetKeyForName( const rtl::OUString& rName );
108 };
109 
110 //	SvXMLNumFmtDefaults is used in import and export
111 
112 class SvXMLNumFmtDefaults
113 {
114 public:
115 	static sal_Bool	IsSystemLongDay( const SvtSysLocale& rSysLoc, sal_Bool bLong );
116 	static sal_Bool	IsSystemLongMonth( const SvtSysLocale& rSysLoc, sal_Bool bLong );
117 	static sal_Bool	IsSystemTextualMonth( const SvtSysLocale& rSysLoc, sal_Bool bLong );
118 	static sal_Bool	IsSystemLongYear( const SvtSysLocale& rSysLoc, sal_Bool bLong );
119 	static sal_Bool	IsSystemLongEra( const SvtSysLocale& rSysLoc, sal_Bool bLong );
120 	static sal_Bool	IsSystemLongDayOfWeek( const SvtSysLocale& rSysLoc, sal_Bool bLong );
121 
122 	// return value is NfIndexTableOffset
123 	static sal_uInt16 GetDefaultDateFormat( SvXMLDateElementAttributes eDOW,
124 				SvXMLDateElementAttributes eDay, SvXMLDateElementAttributes eMonth,
125 				SvXMLDateElementAttributes eYear, SvXMLDateElementAttributes eHours,
126 				SvXMLDateElementAttributes eMins, SvXMLDateElementAttributes eSecs,
127 				sal_Bool bSystem );
128 };
129 
130 struct MyCondition
131 {
132 	rtl::OUString	sCondition;
133 	rtl::OUString	sMapName;
134 };
135 
136 class XMLOFF_DLLPUBLIC SvXMLNumFormatContext : public SvXMLStyleContext
137 {
138 	SvXMLNumImpData*	pData;
139 	SvXMLStylesContext*				pStyles;
140 	std::vector <MyCondition>	aMyConditions;
141 	sal_uInt16			nType;
142 	sal_Int32			nKey;
143 //	rtl::OUString		sFormatName;
144 	rtl::OUString		sFormatTitle;
145 //	rtl::OUString		sMapName;
146 	rtl::OUString		sCalendar;
147 	rtl::OUString		sFormatString;
148 	LanguageType		nFormatLang;
149     com::sun::star::lang::Locale	aLocale;
150 	sal_Bool			bAutoOrder;
151 	sal_Bool			bFromSystem;
152 	sal_Bool			bTruncate;
153 	sal_Bool			bAutoDec;		// set in AddNumber
154 	sal_Bool			bAutoInt;		// set in AddNumber
155 	sal_Bool			bHasExtraText;
156 	rtl::OUStringBuffer	aFormatCode;
157 	rtl::OUStringBuffer	aConditions;
158 	sal_Bool			bHasLongDoW;
159 	sal_Bool			bHasEra;
160 	sal_Bool			bHasDateTime;
161 	sal_Bool			bRemoveAfterUse;
162 
163 	//	contained date elements, used to recognize default date formats
164 	SvXMLDateElementAttributes	eDateDOW;
165 	SvXMLDateElementAttributes	eDateDay;
166 	SvXMLDateElementAttributes	eDateMonth;
167 	SvXMLDateElementAttributes	eDateYear;
168 	SvXMLDateElementAttributes	eDateHours;
169 	SvXMLDateElementAttributes	eDateMins;
170 	SvXMLDateElementAttributes	eDateSecs;
171 	sal_Bool					bDateNoDefault;
172 
173 	SAL_DLLPRIVATE sal_Int32 PrivateGetKey();
174 
175 public:
176 				SvXMLNumFormatContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
177 									const rtl::OUString& rLName,
178 									SvXMLNumImpData* pNewData, sal_uInt16 nNewType,
179 									const ::com::sun::star::uno::Reference<
180 										::com::sun::star::xml::sax::XAttributeList>& xAttrList,
181 									SvXMLStylesContext& rStyles );
182 				SvXMLNumFormatContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
183 									const rtl::OUString& rLName,
184 									const ::com::sun::star::uno::Reference<
185 										::com::sun::star::xml::sax::XAttributeList>& xAttrList,
186 									const sal_Int32 nKey,
187 									SvXMLStylesContext& rStyles );
188 	virtual		~SvXMLNumFormatContext();
189 
190 	virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
191 									const rtl::OUString& rLocalName,
192 									const ::com::sun::star::uno::Reference<
193 									  	::com::sun::star::xml::sax::XAttributeList>& xAttrList );
194 	virtual void CreateAndInsert(sal_Bool bOverwrite);
195 	virtual void Finish(sal_Bool bOverwrite);
196 
GetData() const197 	SvXMLNumImpData* GetData() const				{ return pData; }
198 	sal_Int32 GetKey();
199     sal_Int32 CreateAndInsert( SvNumberFormatter* pFormatter );
200     sal_Int32 CreateAndInsert( com::sun::star::uno::Reference< com::sun::star::util::XNumberFormatsSupplier >& xFormatsSupplier );
GetType() const201 	sal_uInt16 GetType() const						{ return nType; }	// SvXMLStylesTokens
202 
IsFromSystem() const203 	sal_Bool IsFromSystem() const					{ return bFromSystem; }
HasLongDoW() const204 	sal_Bool HasLongDoW() const						{ return bHasLongDoW; }
SetHasLongDoW(sal_Bool bSet)205 	void SetHasLongDoW(sal_Bool bSet)				{ bHasLongDoW = bSet; }
HasEra() const206 	sal_Bool HasEra() const							{ return bHasEra; }
SetHasEra(sal_Bool bSet)207 	void SetHasEra(sal_Bool bSet)					{ bHasEra = bSet; }
208 
209 	void UpdateCalendar( const rtl::OUString& rNewCalendar );
210 
211 	const LocaleDataWrapper& GetLocaleData() const;
212 
213 	void AddToCode( const rtl::OUString& rString );
214 	void AddNumber( const SvXMLNumberInfo& rInfo );
215 	void AddCurrency( const rtl::OUString& rContent, LanguageType nLang );
216 
217 	void AddNfKeyword( sal_uInt16 nIndex );
218 	sal_Bool ReplaceNfKeyword( sal_uInt16 nOld, sal_uInt16 nNew );
219 	void AddCondition( const sal_Int32 nIndex );
220 	void AddCondition( const sal_Int32 nIndex, const rtl::OUString& rFormat, const LocaleDataWrapper& rData );
221 	void AddCondition( const rtl::OUString& rCondition, const rtl::OUString& rApplyName );
222 	void AddColor( const Color& rColor );
223 
224     /// determine whether number format uses the system language
225     sal_Bool IsSystemLanguage();
226 };
227 
228 #endif
229 
230