LibreOffice Module lotuswordpro (master) 1
xfnumberstyle.cxx
Go to the documentation of this file.
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 ************************************************************************/
62
65 , m_nDecimalDigits(0)
66 , m_bGroup(false)
67 , m_aColor(0,0,0)
68 , m_bRedIfNegative(false)
69 , m_aNegativeColor(255,0,0)
70{}
71
73{
74 return enumXFStyleNumber;
75}
76
78{
79 if( !pStyle || pStyle->GetStyleFamily() != enumXFStyleNumber )
80 return false;
81 XFNumberStyle *pOther = dynamic_cast<XFNumberStyle*>(pStyle);
82 if( !pOther )
83 return false;
84
85 if( m_eType != pOther->m_eType )
86 return false;
87 if( m_nDecimalDigits != pOther->m_nDecimalDigits )
88 return false;
89 if( m_bRedIfNegative != pOther->m_bRedIfNegative )
90 return false;
91 if( m_bGroup != pOther->m_bGroup )
92 return false;
93 if( m_aColor != pOther->m_aColor )
94 return false;
95 if( m_strPrefix != pOther->m_strPrefix )
96 return false;
97 if( m_strSuffix != pOther->m_strSuffix )
98 return false;
99
100 if( m_bRedIfNegative )
101 {
102 if( m_aNegativeColor != pOther->m_aNegativeColor )
103 return false;
105 return false;
107 return false;
108 }
109
111 {
113 return false;
114 }
115
116 return true;
117}
118
120{
121 // for Text content number format
122 if (m_eType == enumXFText)
123 {
124 ToXml_StartElement(pStrm);
125 ToXml_EndElement(pStrm);
126 return;
127 }
128
129 if( !m_bRedIfNegative )
130 {
131 ToXml_Normal(pStrm);
132 }
133 else
134 {
135 ToXml_Negative(pStrm);
136 }
137}
138
140{
141 IXFAttrList *pAttrList = pStrm->GetAttrList();
142 pAttrList->Clear();
143
144 pAttrList->AddAttribute( "style:name", GetStyleName() );
145 if( !GetParentStyleName().isEmpty() )
146 pAttrList->AddAttribute("style:parent-style-name",GetParentStyleName());
147
148 pAttrList->AddAttribute( "style:family", "data-style" );
149
151 {
152 pStrm->StartElement( "number:number-style" );
153 }
154 else if( m_eType == enumXFNumberPercent )
155 {
156 pStrm->StartElement( "number:percentage-style" );
157 }
158 else if( m_eType == enuMXFNumberCurrency )
159 {
160 pStrm->StartElement( "number:currency-style" );
161 }
162 else if( m_eType == enumXFNumberScientific )
163 {
164 pStrm->StartElement( "number:number-style" );
165 }
166 // for Text content number format
167 else if (m_eType == enumXFText)
168 {
169 pStrm->StartElement( "number:text-content");
170 }
171
172}
173
175{
176 IXFAttrList *pAttrList = pStrm->GetAttrList();
177 pAttrList->Clear();
178
179 pAttrList->AddAttribute( "style:name", GetStyleName() );
180 pAttrList->AddAttribute( "style:family", "data-style" );
181
183 {
184 pStrm->EndElement( "number:number-style" );
185 }
186 else if( m_eType == enumXFNumberPercent )
187 {
188 pStrm->EndElement( "number:percentage-style" );
189 }
190 else if( m_eType == enuMXFNumberCurrency )
191 {
192 pStrm->EndElement( "number:currency-style" );
193 }
194 else if( m_eType == enumXFNumberScientific )
195 {
196 pStrm->EndElement( "number:number-style" );
197 }
198 // for Text content number format
199 else if (m_eType == enumXFText)
200 {
201 pStrm->EndElement( "number:text-content");
202 }
203 // END for Text content number format
204
205}
207{
208 ToXml_StartElement(pStrm);
209
210 ToXml_Content(pStrm,false);
211
212 ToXml_EndElement(pStrm);
213}
214
216{
217 IXFAttrList *pAttrList = pStrm->GetAttrList();
218 pAttrList->Clear();
219
220 OUString strStyleName = GetStyleName();
221 OUString strGEStyle = strStyleName + "PO";
222
223 SetStyleName(strGEStyle);
224 ToXml_Normal(pStrm);
225 SetStyleName(strStyleName);
226
227 ToXml_StartElement(pStrm);
228
229 ToXml_Content(pStrm,true);
230
231 pAttrList->Clear();
232 pAttrList->AddAttribute( "style:condition", "value()>=0" );
233 pAttrList->AddAttribute( "style:apply-style-name", strGEStyle );
234 pStrm->StartElement( "style:map" );
235 pStrm->EndElement( "style:map" );
236
237 ToXml_EndElement(pStrm);
238}
239
240void XFNumberStyle::ToXml_Content(IXFStream *pStrm, bool nagetive)
241{
242 IXFAttrList *pAttrList = pStrm->GetAttrList();
243 pAttrList->Clear();
244 //color:
245 if( !nagetive )
246 pAttrList->AddAttribute( "fo:color", m_aColor.ToString() );
247 else
248 pAttrList->AddAttribute( "fo:color", m_aNegativeColor.ToString() );
249
250 pStrm->StartElement( "style:properties" );
251 pStrm->EndElement( "style:properties" );
252
253 if( !nagetive )
254 {
255 if( !m_strPrefix.isEmpty() )
256 {
257 pStrm->StartElement( "number:text" );
258 pStrm->Characters(m_strPrefix);
259 pStrm->EndElement( "number:text" );
260 }
261 }
262 else
263 {
264 if( m_strNegativePrefix.isEmpty() )
266 if( !m_strNegativePrefix.isEmpty() )
267 {
268 pStrm->StartElement( "number:text" );
269 // pStrm->Characters(m_strNegativePrefix);
270 pStrm->Characters(m_strNegativePrefix + "-");
271 pStrm->EndElement( "number:text" );
272 }
273 else
274 {
275 pStrm->StartElement( "number:text" );
276 pStrm->Characters("-");
277 pStrm->EndElement( "number:text" );
278 }
279 }
280
282 {
283 if( !m_strCurrencySymbol.isEmpty() )
284 {
285 pStrm->StartElement( "number:currency-symbol" );
287 pStrm->EndElement( "number:currency-symbol" );
288 }
289 }
290
291 //When category of number format is scientific, the number can not be displayed normally in table.
293 {
294 pAttrList->Clear();
295 pAttrList->AddAttribute("number:decimal-places", OUString::number(m_nDecimalDigits));
296 pAttrList->AddAttribute("number:min-integer-digits", OUString::number(1));
297 pAttrList->AddAttribute("number:min-exponent-digits", OUString::number(2));
298 pStrm->StartElement( "number:scientific-number" );
299 pStrm->EndElement( "number:scientific-number" );
300 }
301 else
302 {
303 pAttrList->Clear();
304 pAttrList->AddAttribute("number:decimal-places", OUString::number(m_nDecimalDigits));
305 pAttrList->AddAttribute("number:min-integer-digits", OUString::number(1));
306
307 if( m_bGroup )
308 pAttrList->AddAttribute("number:grouping","true");
309 else
310 pAttrList->AddAttribute("number:grouping","false");
311
312 pStrm->StartElement( "number:number" );
313 pStrm->EndElement( "number:number" );
314 }
315
316 if( !nagetive )
317 {
318 if( !m_strSuffix.isEmpty() )
319 {
320 pStrm->StartElement( "number:text" );
321 pStrm->Characters(m_strSuffix);
322 pStrm->EndElement( "number:text" );
323 }
324 else
325 {
327 {
328 pStrm->StartElement( "number:text" );
329 pStrm->Characters("%");
330 pStrm->EndElement( "number:text" );
331 }
332 }
333 }
334 else
335 {
336 if( m_strNegativeSuffix.isEmpty() )
338 if( !m_strNegativeSuffix.isEmpty() )
339 {
340 pStrm->StartElement( "number:text" );
342 pStrm->EndElement( "number:text" );
343 }
344 else
345 {
347 {
348 pStrm->StartElement( "number:text" );
349 pStrm->Characters("%");
350 pStrm->EndElement( "number:text" );
351 }
352 }
353 }
354}
355
356/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Attribute list interface for sax writer.
Definition: ixfattrlist.hxx:72
virtual void Clear()=0
@descr: Clear all the attributes in the attribute list.
virtual void AddAttribute(const OUString &name, const OUString &value)=0
@descr: Add an attribute to the attribute list.
Stream wrapper for sax writer.
Definition: ixfstream.hxx:72
virtual void Characters(const OUString &oustr)=0
@descr output text node.
virtual IXFAttrList * GetAttrList()=0
@descr return the Attribute list interface.
virtual void StartElement(const OUString &oustr)=0
@descr Wrap XDocumentHandler::startElement()
virtual void EndElement(const OUString &oustr)=0
@descr Wrap XDocumentHandler::endElement()
@descr Interface for all style object.
Definition: ixfstyle.hxx:71
virtual enumXFStyle GetStyleFamily()=0
@descr: return the style family.
OUString ToString() const
Definition: xfcolor.cxx:63
enumXFNumberType m_eType
void ToXml_Normal(IXFStream *pStrm)
XFColor m_aNegativeColor
void ToXml_EndElement(IXFStream *pStrm)
void ToXml_Negative(IXFStream *pStrm)
OUString m_strCurrencySymbol
OUString m_strNegativeSuffix
void ToXml_Content(IXFStream *pStrm, bool nagetive)
OUString m_strSuffix
virtual enumXFStyle GetStyleFamily() override
@descr get style family.
OUString m_strNegativePrefix
OUString m_strPrefix
virtual bool Equal(IXFStyle *pStyle) override
@descr decide whether two style are equal.
sal_Int32 m_nDecimalDigits
void ToXml_StartElement(IXFStream *pStrm)
virtual void ToXml(IXFStream *pStrm) override
virtual OUString GetStyleName() override
@descr get style name.
Definition: xfstyle.cxx:70
virtual OUString GetParentStyleName() override
@descr set parent style name.
Definition: xfstyle.cxx:80
virtual void SetStyleName(const OUString &styleName) override
@descr set style name.
Definition: xfstyle.cxx:75
Color m_aColor
const EnumerationType m_eType
enumXFStyle
Definition: xfdefs.hxx:80
@ enumXFStyleNumber
Definition: xfdefs.hxx:92
@ enumXFNumberPercent
Definition: xfdefs.hxx:419
@ enumXFNumberNumber
Definition: xfdefs.hxx:418
@ enumXFNumberScientific
Definition: xfdefs.hxx:421
@ enuMXFNumberCurrency
Definition: xfdefs.hxx:420
@ enumXFText
Definition: xfdefs.hxx:422