xref: /aoo42x/main/svx/source/items/chrtitem.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 
31 // include ---------------------------------------------------------------
32 #include <tools/stream.hxx>
33 #ifndef __SBX_SBXVARIABLE_HXX
34 #include <basic/sbxvar.hxx>
35 #endif
36 #if defined UNX && !defined LINUX
37 #include <wchar.h>
38 #endif
39 #include <rtl/math.hxx>
40 #include <unotools/intlwrapper.hxx>
41 #include <com/sun/star/chart/ChartAxisArrangeOrderType.hpp>
42 
43 #include <stdio.h>
44 #include <float.h>
45 #include <rtl/math.hxx>
46 
47 #include "svx/chrtitem.hxx"
48 
49 using namespace ::rtl;
50 using namespace ::com::sun::star;
51 // -----------------------------------------------------------------------
52 
53 TYPEINIT1_FACTORY(SvxChartStyleItem, SfxEnumItem, new SvxChartStyleItem(CHSTYLE_2D_LINE, 0));
54 TYPEINIT1(SvxChartDataDescrItem, SfxEnumItem);
55 TYPEINIT1(SvxChartTextOrderItem, SfxEnumItem);
56 TYPEINIT1(SvxChartTextOrientItem, SfxEnumItem);
57 TYPEINIT1(SvxChartIndicateItem, SfxEnumItem);
58 TYPEINIT1(SvxChartKindErrorItem, SfxEnumItem);
59 TYPEINIT1(SvxChartRegressItem, SfxEnumItem);
60 TYPEINIT1_FACTORY(SvxDoubleItem, SfxPoolItem, new SvxDoubleItem(0.0, 0));
61 
62 /*************************************************************************
63 |*
64 |*	SvxChartStyleItem
65 |*
66 *************************************************************************/
67 
68 SvxChartStyleItem::SvxChartStyleItem(SvxChartStyle eStyle, sal_uInt16 nId) :
69 	SfxEnumItem(nId, (sal_uInt16)eStyle)
70 {
71 }
72 
73 // -----------------------------------------------------------------------
74 
75 SvxChartStyleItem::SvxChartStyleItem(SvStream& rIn, sal_uInt16 nId) :
76 	SfxEnumItem(nId, rIn)
77 {
78 }
79 
80 // -----------------------------------------------------------------------
81 
82 SfxPoolItem* SvxChartStyleItem::Clone(SfxItemPool* /*pPool*/) const
83 {
84 	return new SvxChartStyleItem(*this);
85 }
86 
87 // -----------------------------------------------------------------------
88 
89 SfxPoolItem* SvxChartStyleItem::Create(SvStream& rIn, sal_uInt16 /*nVer*/) const
90 {
91 	return new SvxChartStyleItem(rIn, Which());
92 }
93 
94 /*************************************************************************
95 |*
96 |*	SvxChartDataDescrItem
97 |*
98 *************************************************************************/
99 
100 SvxChartDataDescrItem::SvxChartDataDescrItem(SvxChartDataDescr eDataDescr,
101 											 sal_uInt16 nId) :
102 	SfxEnumItem(nId, (sal_uInt16)eDataDescr)
103 {
104 }
105 
106 // -----------------------------------------------------------------------
107 
108 SvxChartDataDescrItem::SvxChartDataDescrItem(SvStream& rIn, sal_uInt16 nId) :
109 	SfxEnumItem(nId, rIn)
110 {
111 }
112 
113 // -----------------------------------------------------------------------
114 
115 SfxPoolItem* SvxChartDataDescrItem::Clone(SfxItemPool* /*pPool*/) const
116 {
117 	return new SvxChartDataDescrItem(*this);
118 }
119 
120 // -----------------------------------------------------------------------
121 
122 SfxPoolItem* SvxChartDataDescrItem::Create(SvStream& rIn, sal_uInt16 /*nVer*/) const
123 {
124 	return new SvxChartDataDescrItem(rIn, Which());
125 }
126 
127 /*************************************************************************
128 |*
129 |*	SvxChartTextOrderItem
130 |*
131 *************************************************************************/
132 
133 SvxChartTextOrderItem::SvxChartTextOrderItem(SvxChartTextOrder eOrder,
134 											 sal_uInt16 nId) :
135 	SfxEnumItem(nId, (sal_uInt16)eOrder)
136 {
137 }
138 
139 // -----------------------------------------------------------------------
140 
141 SvxChartTextOrderItem::SvxChartTextOrderItem(SvStream& rIn, sal_uInt16 nId) :
142 	SfxEnumItem(nId, rIn)
143 {
144 }
145 
146 // -----------------------------------------------------------------------
147 
148 SfxPoolItem* SvxChartTextOrderItem::Clone(SfxItemPool* /*pPool*/) const
149 {
150 	return new SvxChartTextOrderItem(*this);
151 }
152 
153 // -----------------------------------------------------------------------
154 
155 SfxPoolItem* SvxChartTextOrderItem::Create(SvStream& rIn, sal_uInt16 /*nVer*/) const
156 {
157 	return new SvxChartTextOrderItem(rIn, Which());
158 }
159 
160 // -----------------------------------------------------------------------
161 
162 sal_Bool SvxChartTextOrderItem::QueryValue( ::com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
163 {
164     // the order of the two enums is not equal, so a mapping is required
165 	::com::sun::star::chart::ChartAxisArrangeOrderType eAO;
166     SvxChartTextOrder eOrder( GetValue());
167 
168     switch( eOrder )
169     {
170         case CHTXTORDER_SIDEBYSIDE:
171             eAO = ::com::sun::star::chart::ChartAxisArrangeOrderType_SIDE_BY_SIDE; break;
172         case CHTXTORDER_UPDOWN:
173             eAO = ::com::sun::star::chart::ChartAxisArrangeOrderType_STAGGER_ODD; break;
174         case CHTXTORDER_DOWNUP:
175             eAO = ::com::sun::star::chart::ChartAxisArrangeOrderType_STAGGER_EVEN; break;
176         case CHTXTORDER_AUTO:
177             eAO = ::com::sun::star::chart::ChartAxisArrangeOrderType_AUTO; break;
178     }
179 
180 	rVal <<= eAO;
181 
182 	return sal_True;
183 }
184 
185 // -----------------------------------------------------------------------
186 
187 sal_Bool SvxChartTextOrderItem::PutValue( const ::com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
188 {
189     // the order of the two enums is not equal, so a mapping is required
190     ::com::sun::star::chart::ChartAxisArrangeOrderType eAO;
191     SvxChartTextOrder eOrder;
192 
193     if(!(rVal >>= eAO))
194     {
195         // also try an int (for Basic)
196         sal_Int32 nAO = 0;
197         if(!(rVal >>= nAO))
198             return sal_False;
199         eAO = static_cast< ::com::sun::star::chart::ChartAxisArrangeOrderType >( nAO );
200     }
201 
202     switch( eAO )
203     {
204         case ::com::sun::star::chart::ChartAxisArrangeOrderType_SIDE_BY_SIDE:
205             eOrder = CHTXTORDER_SIDEBYSIDE; break;
206         case ::com::sun::star::chart::ChartAxisArrangeOrderType_STAGGER_ODD:
207             eOrder = CHTXTORDER_UPDOWN; break;
208         case ::com::sun::star::chart::ChartAxisArrangeOrderType_STAGGER_EVEN:
209             eOrder = CHTXTORDER_DOWNUP; break;
210         case ::com::sun::star::chart::ChartAxisArrangeOrderType_AUTO:
211             eOrder = CHTXTORDER_AUTO; break;
212         default:
213             return sal_False;
214     }
215 
216 	SetValue( (sal_uInt16)eOrder );
217 
218 	return sal_True;
219 }
220 
221 /*************************************************************************
222 |*
223 |*	SvxChartTextOrientItem
224 |*
225 *************************************************************************/
226 
227 SvxChartTextOrientItem::SvxChartTextOrientItem(SvxChartTextOrient eOrient,
228 											   sal_uInt16 nId) :
229 	SfxEnumItem(nId, (sal_uInt16)eOrient)
230 {
231 }
232 
233 // -----------------------------------------------------------------------
234 
235 SvxChartTextOrientItem::SvxChartTextOrientItem(SvStream& rIn, sal_uInt16 nId) :
236 	SfxEnumItem(nId, rIn)
237 {
238 }
239 
240 // -----------------------------------------------------------------------
241 
242 SfxPoolItem* SvxChartTextOrientItem::Clone(SfxItemPool* /*pPool*/) const
243 {
244 	return new SvxChartTextOrientItem(*this);
245 }
246 
247 // -----------------------------------------------------------------------
248 
249 SfxPoolItem* SvxChartTextOrientItem::Create(SvStream& rIn, sal_uInt16 /*nVer*/) const
250 {
251 	return new SvxChartTextOrientItem(rIn, Which());
252 }
253 
254 /*************************************************************************
255 |*
256 |*	SvxDoubleItem
257 |*
258 *************************************************************************/
259 
260 SvxDoubleItem::SvxDoubleItem(double fValue, sal_uInt16 nId) :
261 	SfxPoolItem(nId),
262 	fVal(fValue)
263 {
264 }
265 
266 // -----------------------------------------------------------------------
267 
268 SvxDoubleItem::SvxDoubleItem(SvStream& rIn, sal_uInt16 nId) :
269 	SfxPoolItem(nId)
270 {
271 	rIn >> fVal;
272 }
273 
274 // -----------------------------------------------------------------------
275 
276 SvxDoubleItem::SvxDoubleItem(const SvxDoubleItem& rItem) :
277 	SfxPoolItem(rItem),
278 	fVal(rItem.fVal)
279 {
280 }
281 
282 // -----------------------------------------------------------------------
283 
284 XubString SvxDoubleItem::GetValueText() const
285 {
286 	rtl::OString aOStr( rtl::math::doubleToString( fVal, rtl_math_StringFormat_E, 4, '.', false ) );
287 	return String( aOStr.getStr(), (sal_uInt16)aOStr.getLength() );
288 }
289 
290 // -----------------------------------------------------------------------
291 
292 SfxItemPresentation SvxDoubleItem::GetPresentation
293             ( SfxItemPresentation /*ePresentation*/, SfxMapUnit /*eCoreMetric*/,
294               SfxMapUnit /*ePresentationMetric*/, XubString& rText,
295               const IntlWrapper * pIntlWrapper) const
296 {
297     DBG_ASSERT( pIntlWrapper, "SvxDoubleItem::GetPresentation: no IntlWrapper" );
298     if ( pIntlWrapper )
299     {
300         rText = ::rtl::math::doubleToUString( fVal, rtl_math_StringFormat_E, 4,
301             pIntlWrapper->getLocaleData()->getNumDecimalSep().GetChar(0), true );
302     }
303     else
304 		rText = GetValueText();
305 	return SFX_ITEM_PRESENTATION_NAMELESS;
306 }
307 
308 // -----------------------------------------------------------------------
309 
310 int SvxDoubleItem::operator == (const SfxPoolItem& rItem) const
311 {
312 	return (((SvxDoubleItem&)rItem).fVal == fVal);
313 }
314 
315 // -----------------------------------------------------------------------
316 
317 SfxPoolItem* SvxDoubleItem::Clone(SfxItemPool* /*pPool*/) const
318 {
319 	return new SvxDoubleItem(*this);
320 }
321 
322 // -----------------------------------------------------------------------
323 
324 SfxPoolItem* SvxDoubleItem::Create(SvStream& rIn, sal_uInt16 /*nVersion*/) const
325 {
326     double _fVal;
327     rIn >> _fVal;
328     return new SvxDoubleItem(_fVal, Which());
329 }
330 
331 // -----------------------------------------------------------------------
332 
333 SvStream& SvxDoubleItem::Store(SvStream& rOut, sal_uInt16 /*nItemVersion*/) const
334 {
335 	rOut << fVal;
336 	return rOut;
337 }
338 
339 // -----------------------------------------------------------------------
340 
341 double SvxDoubleItem::GetMin() const
342 {
343 	return DBL_MIN;
344 }
345 
346 // -----------------------------------------------------------------------
347 
348 double SvxDoubleItem::GetMax() const
349 {
350 	return DBL_MAX;
351 }
352 
353 // -----------------------------------------------------------------------
354 
355 SfxFieldUnit SvxDoubleItem::GetUnit() const
356 {
357 	return SFX_FUNIT_NONE;
358 }
359 
360 
361 
362 
363 // -----------------------------------------------------------------------
364 sal_Bool SvxDoubleItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
365 {
366 	rVal <<= fVal;
367 	return sal_True;
368 }
369 
370 // -----------------------------------------------------------------------
371 sal_Bool SvxDoubleItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
372 {
373 	return rVal >>= fVal;
374 }
375 
376 
377 
378 /*************************************************************************
379 |*
380 |*	SvxChartKindErrorItem
381 |*
382 *************************************************************************/
383 
384 SvxChartKindErrorItem::SvxChartKindErrorItem(SvxChartKindError eOrient,
385 											   sal_uInt16 nId) :
386 	SfxEnumItem(nId, (sal_uInt16)eOrient)
387 {
388 }
389 
390 // -----------------------------------------------------------------------
391 
392 SvxChartKindErrorItem::SvxChartKindErrorItem(SvStream& rIn, sal_uInt16 nId) :
393 	SfxEnumItem(nId, rIn)
394 {
395 }
396 
397 // -----------------------------------------------------------------------
398 
399 SfxPoolItem* SvxChartKindErrorItem::Clone(SfxItemPool* /*pPool*/) const
400 {
401 	return new SvxChartKindErrorItem(*this);
402 }
403 
404 // -----------------------------------------------------------------------
405 
406 SfxPoolItem* SvxChartKindErrorItem::Create(SvStream& rIn, sal_uInt16 /*nVer*/) const
407 {
408 	return new SvxChartKindErrorItem(rIn, Which());
409 }
410 
411 // -----------------------------------------------------------------------
412 
413 sal_uInt16 SvxChartKindErrorItem::GetVersion (sal_uInt16 nFileFormatVersion) const
414 {
415 	return (nFileFormatVersion == SOFFICE_FILEFORMAT_31)
416 			   ? USHRT_MAX
417 			   : 0;
418 }
419 
420 /*************************************************************************
421 |*
422 |*	SvxChartIndicateItem
423 |*
424 *************************************************************************/
425 
426 SvxChartIndicateItem::SvxChartIndicateItem(SvxChartIndicate eOrient,
427 											   sal_uInt16 nId) :
428 	SfxEnumItem(nId, (sal_uInt16)eOrient)
429 {
430 }
431 
432 // -----------------------------------------------------------------------
433 
434 SvxChartIndicateItem::SvxChartIndicateItem(SvStream& rIn, sal_uInt16 nId) :
435 	SfxEnumItem(nId, rIn)
436 {
437 }
438 
439 // -----------------------------------------------------------------------
440 
441 SfxPoolItem* SvxChartIndicateItem::Clone(SfxItemPool* /*pPool*/) const
442 {
443 	return new SvxChartIndicateItem(*this);
444 }
445 
446 // -----------------------------------------------------------------------
447 
448 SfxPoolItem* SvxChartIndicateItem::Create(SvStream& rIn, sal_uInt16 /*nVer*/) const
449 {
450 	return new SvxChartIndicateItem(rIn, Which());
451 }
452 
453 // -----------------------------------------------------------------------
454 
455 sal_uInt16 SvxChartIndicateItem::GetVersion (sal_uInt16 nFileFormatVersion) const
456 {
457 	return (nFileFormatVersion == SOFFICE_FILEFORMAT_31)
458 			   ? USHRT_MAX
459 			   : 0;
460 }
461 
462 /*************************************************************************
463 |*
464 |*	SvxChartRegressItem
465 |*
466 *************************************************************************/
467 
468 SvxChartRegressItem::SvxChartRegressItem(SvxChartRegress eOrient,
469 											   sal_uInt16 nId) :
470 	SfxEnumItem(nId, (sal_uInt16)eOrient)
471 {
472 }
473 
474 // -----------------------------------------------------------------------
475 
476 SvxChartRegressItem::SvxChartRegressItem(SvStream& rIn, sal_uInt16 nId) :
477 	SfxEnumItem(nId, rIn)
478 {
479 }
480 
481 // -----------------------------------------------------------------------
482 
483 SfxPoolItem* SvxChartRegressItem::Clone(SfxItemPool* /*pPool*/) const
484 {
485 	return new SvxChartRegressItem(*this);
486 }
487 
488 // -----------------------------------------------------------------------
489 
490 SfxPoolItem* SvxChartRegressItem::Create(SvStream& rIn, sal_uInt16 /*nVer*/) const
491 {
492 	return new SvxChartRegressItem(rIn, Which());
493 }
494 
495 // -----------------------------------------------------------------------
496 
497 sal_uInt16 SvxChartRegressItem::GetVersion (sal_uInt16 nFileFormatVersion) const
498 {
499 	return (nFileFormatVersion == SOFFICE_FILEFORMAT_31)
500 			   ? USHRT_MAX
501 			   : 0;
502 }
503 
504 
505