Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * The Contents of this file are made available subject to the terms of
5 : * either of the following licenses
6 : *
7 : * - GNU Lesser General Public License Version 2.1
8 : * - Sun Industry Standards Source License Version 1.1
9 : *
10 : * Sun Microsystems Inc., October, 2000
11 : *
12 : * GNU Lesser General Public License Version 2.1
13 : * =============================================
14 : * Copyright 2000 by Sun Microsystems, Inc.
15 : * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 : *
17 : * This library is free software; you can redistribute it and/or
18 : * modify it under the terms of the GNU Lesser General Public
19 : * License version 2.1, as published by the Free Software Foundation.
20 : *
21 : * This library is distributed in the hope that it will be useful,
22 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 : * Lesser General Public License for more details.
25 : *
26 : * You should have received a copy of the GNU Lesser General Public
27 : * License along with this library; if not, write to the Free Software
28 : * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 : * MA 02111-1307 USA
30 : *
31 : *
32 : * Sun Industry Standards Source License Version 1.1
33 : * =================================================
34 : * The contents of this file are subject to the Sun Industry Standards
35 : * Source License Version 1.1 (the "License"); You may not use this file
36 : * except in compliance with the License. You may obtain a copy of the
37 : * License at http://www.openoffice.org/license.html.
38 : *
39 : * Software provided under this License is provided on an "AS IS" basis,
40 : * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 : * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 : * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 : * See the License for the specific provisions governing your rights and
44 : * obligations concerning the Software.
45 : *
46 : * The Initial Developer of the Original Code is: IBM Corporation
47 : *
48 : * Copyright: 2008 by IBM Corporation
49 : *
50 : * All Rights Reserved.
51 : *
52 : * Contributor(s): _______________________________________
53 : *
54 : *
55 : ************************************************************************/
56 : /*************************************************************************
57 : * @file
58 : * Number style for table cell.
59 : ************************************************************************/
60 : #include "xfnumberstyle.hxx"
61 :
62 48 : XFNumberStyle::XFNumberStyle():m_aColor(0,0,0),m_aNegativeColor(255,0,0)
63 : {
64 48 : m_eType = enumXFNumberNumber;
65 48 : m_nDecimalDigits = 0;
66 48 : m_nMinInteger = 1;
67 48 : m_nMinExponent = 2;
68 48 : m_bGroup = false;
69 48 : m_bRedIfNegative = false;
70 48 : m_bCurrencySymbolPost = false;
71 48 : }
72 :
73 616 : enumXFStyle XFNumberStyle::GetStyleFamily()
74 : {
75 616 : return enumXFStyleNumber;
76 : }
77 :
78 46 : bool XFNumberStyle::Equal(IXFStyle *pStyle)
79 : {
80 46 : if( !pStyle || pStyle->GetStyleFamily() != enumXFStyleNumber )
81 6 : return false;
82 40 : XFNumberStyle *pOther = dynamic_cast<XFNumberStyle*>(pStyle);
83 40 : if( !pOther )
84 0 : return false;
85 :
86 40 : if( m_eType != pOther->m_eType )
87 0 : return false;
88 40 : if( m_nDecimalDigits != pOther->m_nDecimalDigits )
89 0 : return false;
90 40 : if( m_nMinInteger != pOther->m_nMinInteger )
91 0 : return false;
92 40 : if( m_bRedIfNegative != pOther->m_bRedIfNegative )
93 0 : return false;
94 40 : if( m_bGroup != pOther->m_bGroup )
95 0 : return false;
96 40 : if( m_aColor != pOther->m_aColor )
97 0 : return false;
98 40 : if( m_strPrefix != pOther->m_strPrefix )
99 0 : return false;
100 40 : if( m_strSuffix != pOther->m_strSuffix )
101 0 : return false;
102 :
103 : //When category of number format is scientific, the number can not be displayed normally in table.
104 40 : if ( m_nMinExponent != pOther->m_nMinExponent )
105 0 : return false;
106 :
107 40 : if( m_bRedIfNegative )
108 : {
109 40 : if( m_aNegativeColor != pOther->m_aNegativeColor )
110 0 : return false;
111 40 : if( m_strNegativePrefix != pOther->m_strNegativePrefix )
112 0 : return false;
113 40 : if( m_strNegativeSuffix != pOther->m_strNegativeSuffix )
114 0 : return false;
115 : }
116 :
117 40 : if( m_eType == enuMXFNumberCurrency )
118 : {
119 0 : if( m_bCurrencySymbolPost != pOther->m_bCurrencySymbolPost )
120 0 : return false;
121 0 : if( m_strCurrencySymbol != pOther->m_strCurrencySymbol )
122 0 : return false;
123 : }
124 :
125 40 : return true;
126 : }
127 :
128 6 : void XFNumberStyle::ToXml(IXFStream *pStrm)
129 : {
130 : // for Text content number format
131 6 : if (m_eType == enumXFText)
132 : {
133 6 : ToXml_StartElement(pStrm);
134 6 : ToXml_EndElement(pStrm);
135 12 : return;
136 : }
137 : // END for Text content number format
138 :
139 0 : if( !m_bRedIfNegative )
140 : {
141 0 : ToXml_Normal(pStrm);
142 : }
143 : else
144 : {
145 0 : ToXml_Negative(pStrm);
146 : }
147 : }
148 :
149 6 : void XFNumberStyle::ToXml_StartElement(IXFStream *pStrm)
150 : {
151 6 : IXFAttrList *pAttrList = pStrm->GetAttrList();
152 6 : pAttrList->Clear();
153 :
154 6 : pAttrList->AddAttribute( "style:name", GetStyleName() );
155 6 : if( !GetParentStyleName().isEmpty() )
156 0 : pAttrList->AddAttribute("style:parent-style-name",GetParentStyleName());
157 :
158 6 : pAttrList->AddAttribute( "style:family", "data-style" );
159 :
160 6 : if( m_eType == enumXFNumberNumber )
161 : {
162 0 : pStrm->StartElement( "number:number-style" );
163 : }
164 6 : else if( m_eType == enumXFNumberPercent )
165 : {
166 0 : pStrm->StartElement( "number:percentage-style" );
167 : }
168 6 : else if( m_eType == enuMXFNumberCurrency )
169 : {
170 0 : pStrm->StartElement( "number:currency-style" );
171 : }
172 6 : else if( m_eType == enumXFNumberScientific )
173 : {
174 0 : pStrm->StartElement( "number:number-style" );
175 : }
176 : // for Text content number format
177 6 : else if (m_eType == enumXFText)
178 : {
179 6 : pStrm->StartElement( "number:text-content");
180 : }
181 : // END for Text content number format
182 :
183 6 : }
184 :
185 6 : void XFNumberStyle::ToXml_EndElement(IXFStream *pStrm)
186 : {
187 6 : IXFAttrList *pAttrList = pStrm->GetAttrList();
188 6 : pAttrList->Clear();
189 :
190 6 : pAttrList->AddAttribute( "style:name", GetStyleName() );
191 6 : pAttrList->AddAttribute( "style:family", "data-style" );
192 :
193 6 : if( m_eType == enumXFNumberNumber )
194 : {
195 0 : pStrm->EndElement( "number:number-style" );
196 : }
197 6 : else if( m_eType == enumXFNumberPercent )
198 : {
199 0 : pStrm->EndElement( "number:percentage-style" );
200 : }
201 6 : else if( m_eType == enuMXFNumberCurrency )
202 : {
203 0 : pStrm->EndElement( "number:currency-style" );
204 : }
205 6 : else if( m_eType == enumXFNumberScientific )
206 : {
207 0 : pStrm->EndElement( "number:number-style" );
208 : }
209 : // for Text content number format
210 6 : else if (m_eType == enumXFText)
211 : {
212 6 : pStrm->EndElement( "number:text-content");
213 : }
214 : // END for Text content number format
215 :
216 6 : }
217 0 : void XFNumberStyle::ToXml_Normal(IXFStream *pStrm)
218 : {
219 0 : ToXml_StartElement(pStrm);
220 :
221 0 : ToXml_Content(pStrm,false);
222 :
223 0 : ToXml_EndElement(pStrm);
224 0 : }
225 :
226 0 : void XFNumberStyle::ToXml_Negative(IXFStream *pStrm)
227 : {
228 0 : IXFAttrList *pAttrList = pStrm->GetAttrList();
229 0 : pAttrList->Clear();
230 :
231 0 : OUString strStyleName = GetStyleName();
232 0 : OUString strGEStyle = strStyleName + "PO";
233 :
234 0 : SetStyleName(strGEStyle);
235 0 : ToXml_Normal(pStrm);
236 0 : SetStyleName(strStyleName);
237 :
238 0 : ToXml_StartElement(pStrm);
239 :
240 0 : ToXml_Content(pStrm,true);
241 :
242 0 : pAttrList->Clear();
243 0 : pAttrList->AddAttribute( "style:condition", "value()>=0" );
244 0 : pAttrList->AddAttribute( "style:apply-style-name", strGEStyle );
245 0 : pStrm->StartElement( "style:map" );
246 0 : pStrm->EndElement( "style:map" );
247 :
248 0 : ToXml_EndElement(pStrm);
249 0 : }
250 :
251 0 : void XFNumberStyle::ToXml_Content(IXFStream *pStrm, bool nagetive)
252 : {
253 0 : IXFAttrList *pAttrList = pStrm->GetAttrList();
254 0 : pAttrList->Clear();
255 : //color:
256 0 : if( !nagetive )
257 0 : pAttrList->AddAttribute( "fo:color", m_aColor.ToString() );
258 : else
259 0 : pAttrList->AddAttribute( "fo:color", m_aNegativeColor.ToString() );
260 :
261 0 : pStrm->StartElement( "style:properties" );
262 0 : pStrm->EndElement( "style:properties" );
263 :
264 0 : if( !nagetive )
265 : {
266 0 : if( !m_strPrefix.isEmpty() )
267 : {
268 0 : pStrm->StartElement( "number:text" );
269 0 : pStrm->Characters(m_strPrefix);
270 0 : pStrm->EndElement( "number:text" );
271 : }
272 : }
273 : else
274 : {
275 0 : if( m_strNegativePrefix.isEmpty() )
276 0 : m_strNegativePrefix = m_strPrefix;
277 0 : if( !m_strNegativePrefix.isEmpty() )
278 : {
279 0 : pStrm->StartElement( "number:text" );
280 : // pStrm->Characters(m_strNegativePrefix);
281 0 : pStrm->Characters(m_strNegativePrefix + "-");
282 0 : pStrm->EndElement( "number:text" );
283 : }
284 : else
285 : {
286 0 : pStrm->StartElement( "number:text" );
287 0 : pStrm->Characters("-");
288 0 : pStrm->EndElement( "number:text" );
289 : }
290 : }
291 :
292 0 : if( m_eType == enuMXFNumberCurrency && !m_bCurrencySymbolPost )
293 : {
294 0 : if( !m_strCurrencySymbol.isEmpty() )
295 : {
296 0 : pStrm->StartElement( "number:currency-symbol" );
297 0 : pStrm->Characters(m_strCurrencySymbol);
298 0 : pStrm->EndElement( "number:currency-symbol" );
299 : }
300 : }
301 :
302 : //When category of number format is scientific, the number can not be displayed normally in table.
303 0 : if ( m_eType == enumXFNumberScientific )
304 : {
305 0 : pAttrList->Clear();
306 0 : pAttrList->AddAttribute("number:decimal-places", OUString::number(m_nDecimalDigits));
307 0 : pAttrList->AddAttribute("number:min-integer-digits", OUString::number(m_nMinInteger));
308 0 : pAttrList->AddAttribute("number:min-exponent-digits", OUString::number(m_nMinExponent));
309 0 : pStrm->StartElement( "number:scientific-number" );
310 0 : pStrm->EndElement( "number:scientific-number" );
311 : }
312 : else
313 : {
314 0 : pAttrList->Clear();
315 0 : pAttrList->AddAttribute("number:decimal-places", OUString::number(m_nDecimalDigits));
316 0 : pAttrList->AddAttribute("number:min-integer-digits", OUString::number(m_nMinInteger));
317 :
318 0 : if( m_bGroup )
319 0 : pAttrList->AddAttribute("number:grouping","true");
320 : else
321 0 : pAttrList->AddAttribute("number:grouping","false");
322 :
323 0 : pStrm->StartElement( "number:number" );
324 0 : pStrm->EndElement( "number:number" );
325 : }
326 :
327 0 : if( m_eType == enuMXFNumberCurrency && m_bCurrencySymbolPost )
328 : {
329 0 : if( !m_strCurrencySymbol.isEmpty() )
330 : {
331 0 : pStrm->StartElement( "number:currency-symbol" );
332 0 : pStrm->Characters(m_strCurrencySymbol);
333 0 : pStrm->EndElement( "number:currency-symbol" );
334 : }
335 : }
336 :
337 0 : if( !nagetive )
338 : {
339 0 : if( !m_strSuffix.isEmpty() )
340 : {
341 0 : pStrm->StartElement( "number:text" );
342 0 : pStrm->Characters(m_strSuffix);
343 0 : pStrm->EndElement( "number:text" );
344 : }
345 : else
346 : {
347 0 : if( m_eType == enumXFNumberPercent )
348 : {
349 0 : pStrm->StartElement( "number:text" );
350 0 : pStrm->Characters("%");
351 0 : pStrm->EndElement( "number:text" );
352 : }
353 : }
354 : }
355 : else
356 : {
357 0 : if( m_strNegativeSuffix.isEmpty() )
358 0 : m_strNegativeSuffix = m_strSuffix;
359 0 : if( !m_strNegativeSuffix.isEmpty() )
360 : {
361 0 : pStrm->StartElement( "number:text" );
362 0 : pStrm->Characters(m_strNegativeSuffix);
363 0 : pStrm->EndElement( "number:text" );
364 : }
365 : else
366 : {
367 0 : if( m_eType == enumXFNumberPercent )
368 : {
369 0 : pStrm->StartElement( "number:text" );
370 0 : pStrm->Characters("%");
371 0 : pStrm->EndElement( "number:text" );
372 : }
373 : }
374 : }
375 0 : }
376 :
377 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|