merge the formfield patch from ooo-build
[ooovba.git] / svx / source / items / chrtitem.cxx
blob2e46e07cfb515e1a398f02ebeda6e3c8fdd5f406
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: chrtitem.cxx,v $
10 * $Revision: 1.17 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 // include ---------------------------------------------------------------
35 #include <tools/stream.hxx>
36 #ifndef __SBX_SBXVARIABLE_HXX
37 #include <basic/sbxvar.hxx>
38 #endif
39 #if defined UNX && !defined LINUX
40 #include <wchar.h>
41 #endif
42 #include <rtl/math.hxx>
43 #include <unotools/intlwrapper.hxx>
44 #include <com/sun/star/chart/ChartAxisArrangeOrderType.hpp>
46 #include <stdio.h>
47 #include <float.h>
48 #include <rtl/math.hxx>
50 #include "chrtitem.hxx"
52 using namespace ::rtl;
53 using namespace ::com::sun::star;
54 // -----------------------------------------------------------------------
56 TYPEINIT1_FACTORY(SvxChartStyleItem, SfxEnumItem, new SvxChartStyleItem(CHSTYLE_2D_LINE, 0));
57 TYPEINIT1(SvxChartDataDescrItem, SfxEnumItem);
58 TYPEINIT1(SvxChartLegendPosItem, SfxEnumItem);
59 TYPEINIT1(SvxChartTextOrderItem, SfxEnumItem);
60 TYPEINIT1(SvxChartTextOrientItem, SfxEnumItem);
61 TYPEINIT1(SvxChartIndicateItem, SfxEnumItem);
62 TYPEINIT1(SvxChartKindErrorItem, SfxEnumItem);
63 TYPEINIT1(SvxChartRegressItem, SfxEnumItem);
64 TYPEINIT1_FACTORY(SvxDoubleItem, SfxPoolItem, new SvxDoubleItem(0.0, 0));
66 /*************************************************************************
68 |* SvxChartStyleItem
70 *************************************************************************/
72 SvxChartStyleItem::SvxChartStyleItem(SvxChartStyle eStyle, USHORT nId) :
73 SfxEnumItem(nId, (USHORT)eStyle)
77 // -----------------------------------------------------------------------
79 SvxChartStyleItem::SvxChartStyleItem(SvStream& rIn, USHORT nId) :
80 SfxEnumItem(nId, rIn)
84 // -----------------------------------------------------------------------
86 SfxPoolItem* SvxChartStyleItem::Clone(SfxItemPool* /*pPool*/) const
88 return new SvxChartStyleItem(*this);
91 // -----------------------------------------------------------------------
93 SfxPoolItem* SvxChartStyleItem::Create(SvStream& rIn, USHORT /*nVer*/) const
95 return new SvxChartStyleItem(rIn, Which());
98 /*************************************************************************
100 |* SvxChartDataDescrItem
102 *************************************************************************/
104 SvxChartDataDescrItem::SvxChartDataDescrItem(SvxChartDataDescr eDataDescr,
105 USHORT nId) :
106 SfxEnumItem(nId, (USHORT)eDataDescr)
110 // -----------------------------------------------------------------------
112 SvxChartDataDescrItem::SvxChartDataDescrItem(SvStream& rIn, USHORT nId) :
113 SfxEnumItem(nId, rIn)
117 // -----------------------------------------------------------------------
119 SfxPoolItem* SvxChartDataDescrItem::Clone(SfxItemPool* /*pPool*/) const
121 return new SvxChartDataDescrItem(*this);
124 // -----------------------------------------------------------------------
126 SfxPoolItem* SvxChartDataDescrItem::Create(SvStream& rIn, USHORT /*nVer*/) const
128 return new SvxChartDataDescrItem(rIn, Which());
131 /*************************************************************************
133 |* SvxChartLegendPosItem
135 *************************************************************************/
137 SvxChartLegendPosItem::SvxChartLegendPosItem(SvxChartLegendPos eLegendPos,
138 USHORT nId) :
139 SfxEnumItem(nId, (USHORT)eLegendPos)
143 // -----------------------------------------------------------------------
145 SvxChartLegendPosItem::SvxChartLegendPosItem(SvStream& rIn, USHORT nId) :
146 SfxEnumItem(nId, rIn)
150 // -----------------------------------------------------------------------
152 SfxPoolItem* SvxChartLegendPosItem::Clone(SfxItemPool* /*pPool*/) const
154 return new SvxChartLegendPosItem(*this);
157 // -----------------------------------------------------------------------
159 SfxPoolItem* SvxChartLegendPosItem::Create(SvStream& rIn, USHORT /*nVer*/) const
161 return new SvxChartLegendPosItem(rIn, Which());
164 /*************************************************************************
166 |* SvxChartTextOrderItem
168 *************************************************************************/
170 SvxChartTextOrderItem::SvxChartTextOrderItem(SvxChartTextOrder eOrder,
171 USHORT nId) :
172 SfxEnumItem(nId, (USHORT)eOrder)
176 // -----------------------------------------------------------------------
178 SvxChartTextOrderItem::SvxChartTextOrderItem(SvStream& rIn, USHORT nId) :
179 SfxEnumItem(nId, rIn)
183 // -----------------------------------------------------------------------
185 SfxPoolItem* SvxChartTextOrderItem::Clone(SfxItemPool* /*pPool*/) const
187 return new SvxChartTextOrderItem(*this);
190 // -----------------------------------------------------------------------
192 SfxPoolItem* SvxChartTextOrderItem::Create(SvStream& rIn, USHORT /*nVer*/) const
194 return new SvxChartTextOrderItem(rIn, Which());
197 // -----------------------------------------------------------------------
199 sal_Bool SvxChartTextOrderItem::QueryValue( ::com::sun::star::uno::Any& rVal, BYTE /*nMemberId*/ ) const
201 // the order of the two enums is not equal, so a mapping is required
202 ::com::sun::star::chart::ChartAxisArrangeOrderType eAO;
203 SvxChartTextOrder eOrder( GetValue());
205 switch( eOrder )
207 case CHTXTORDER_SIDEBYSIDE:
208 eAO = ::com::sun::star::chart::ChartAxisArrangeOrderType_SIDE_BY_SIDE; break;
209 case CHTXTORDER_UPDOWN:
210 eAO = ::com::sun::star::chart::ChartAxisArrangeOrderType_STAGGER_ODD; break;
211 case CHTXTORDER_DOWNUP:
212 eAO = ::com::sun::star::chart::ChartAxisArrangeOrderType_STAGGER_EVEN; break;
213 case CHTXTORDER_AUTO:
214 eAO = ::com::sun::star::chart::ChartAxisArrangeOrderType_AUTO; break;
217 rVal <<= eAO;
219 return sal_True;
222 // -----------------------------------------------------------------------
224 sal_Bool SvxChartTextOrderItem::PutValue( const ::com::sun::star::uno::Any& rVal, BYTE /*nMemberId*/ )
226 // the order of the two enums is not equal, so a mapping is required
227 ::com::sun::star::chart::ChartAxisArrangeOrderType eAO;
228 SvxChartTextOrder eOrder;
230 if(!(rVal >>= eAO))
232 // also try an int (for Basic)
233 sal_Int32 nAO = 0;
234 if(!(rVal >>= nAO))
235 return sal_False;
236 eAO = static_cast< ::com::sun::star::chart::ChartAxisArrangeOrderType >( nAO );
239 switch( eAO )
241 case ::com::sun::star::chart::ChartAxisArrangeOrderType_SIDE_BY_SIDE:
242 eOrder = CHTXTORDER_SIDEBYSIDE; break;
243 case ::com::sun::star::chart::ChartAxisArrangeOrderType_STAGGER_ODD:
244 eOrder = CHTXTORDER_UPDOWN; break;
245 case ::com::sun::star::chart::ChartAxisArrangeOrderType_STAGGER_EVEN:
246 eOrder = CHTXTORDER_DOWNUP; break;
247 case ::com::sun::star::chart::ChartAxisArrangeOrderType_AUTO:
248 eOrder = CHTXTORDER_AUTO; break;
249 default:
250 return sal_False;
253 SetValue( (USHORT)eOrder );
255 return sal_True;
258 /*************************************************************************
260 |* SvxChartTextOrientItem
262 *************************************************************************/
264 SvxChartTextOrientItem::SvxChartTextOrientItem(SvxChartTextOrient eOrient,
265 USHORT nId) :
266 SfxEnumItem(nId, (USHORT)eOrient)
270 // -----------------------------------------------------------------------
272 SvxChartTextOrientItem::SvxChartTextOrientItem(SvStream& rIn, USHORT nId) :
273 SfxEnumItem(nId, rIn)
277 // -----------------------------------------------------------------------
279 SfxPoolItem* SvxChartTextOrientItem::Clone(SfxItemPool* /*pPool*/) const
281 return new SvxChartTextOrientItem(*this);
284 // -----------------------------------------------------------------------
286 SfxPoolItem* SvxChartTextOrientItem::Create(SvStream& rIn, USHORT /*nVer*/) const
288 return new SvxChartTextOrientItem(rIn, Which());
291 /*************************************************************************
293 |* SvxDoubleItem
295 *************************************************************************/
297 SvxDoubleItem::SvxDoubleItem(double fValue, USHORT nId) :
298 SfxPoolItem(nId),
299 fVal(fValue)
303 // -----------------------------------------------------------------------
305 SvxDoubleItem::SvxDoubleItem(SvStream& rIn, USHORT nId) :
306 SfxPoolItem(nId)
308 rIn >> fVal;
311 // -----------------------------------------------------------------------
313 SvxDoubleItem::SvxDoubleItem(const SvxDoubleItem& rItem) :
314 SfxPoolItem(rItem),
315 fVal(rItem.fVal)
319 // -----------------------------------------------------------------------
321 XubString SvxDoubleItem::GetValueText() const
323 rtl::OString aOStr( rtl::math::doubleToString( fVal, rtl_math_StringFormat_E, 4, '.', false ) );
324 return String( aOStr.getStr(), (sal_uInt16)aOStr.getLength() );
327 // -----------------------------------------------------------------------
329 SfxItemPresentation SvxDoubleItem::GetPresentation
330 ( SfxItemPresentation /*ePresentation*/, SfxMapUnit /*eCoreMetric*/,
331 SfxMapUnit /*ePresentationMetric*/, XubString& rText,
332 const IntlWrapper * pIntlWrapper) const
334 DBG_ASSERT( pIntlWrapper, "SvxDoubleItem::GetPresentation: no IntlWrapper" );
335 if ( pIntlWrapper )
337 rText = ::rtl::math::doubleToUString( fVal, rtl_math_StringFormat_E, 4,
338 pIntlWrapper->getLocaleData()->getNumDecimalSep().GetChar(0), true );
340 else
341 rText = GetValueText();
342 return SFX_ITEM_PRESENTATION_NAMELESS;
345 // -----------------------------------------------------------------------
347 int SvxDoubleItem::operator == (const SfxPoolItem& rItem) const
349 return (((SvxDoubleItem&)rItem).fVal == fVal);
352 // -----------------------------------------------------------------------
354 SfxPoolItem* SvxDoubleItem::Clone(SfxItemPool* /*pPool*/) const
356 return new SvxDoubleItem(*this);
359 // -----------------------------------------------------------------------
361 SfxPoolItem* SvxDoubleItem::Create(SvStream& rIn, USHORT /*nVersion*/) const
363 double _fVal;
364 rIn >> _fVal;
365 return new SvxDoubleItem(_fVal, Which());
368 // -----------------------------------------------------------------------
370 SvStream& SvxDoubleItem::Store(SvStream& rOut, USHORT /*nItemVersion*/) const
372 rOut << fVal;
373 return rOut;
376 // -----------------------------------------------------------------------
378 double SvxDoubleItem::GetMin() const
380 return DBL_MIN;
383 // -----------------------------------------------------------------------
385 double SvxDoubleItem::GetMax() const
387 return DBL_MAX;
390 // -----------------------------------------------------------------------
392 SfxFieldUnit SvxDoubleItem::GetUnit() const
394 return SFX_FUNIT_NONE;
400 // -----------------------------------------------------------------------
401 sal_Bool SvxDoubleItem::QueryValue( uno::Any& rVal, BYTE /*nMemberId*/ ) const
403 rVal <<= fVal;
404 return sal_True;
407 // -----------------------------------------------------------------------
408 sal_Bool SvxDoubleItem::PutValue( const uno::Any& rVal, BYTE /*nMemberId*/ )
410 return rVal >>= fVal;
415 /*************************************************************************
417 |* SvxChartKindErrorItem
419 *************************************************************************/
421 SvxChartKindErrorItem::SvxChartKindErrorItem(SvxChartKindError eOrient,
422 USHORT nId) :
423 SfxEnumItem(nId, (USHORT)eOrient)
427 // -----------------------------------------------------------------------
429 SvxChartKindErrorItem::SvxChartKindErrorItem(SvStream& rIn, USHORT nId) :
430 SfxEnumItem(nId, rIn)
434 // -----------------------------------------------------------------------
436 SfxPoolItem* SvxChartKindErrorItem::Clone(SfxItemPool* /*pPool*/) const
438 return new SvxChartKindErrorItem(*this);
441 // -----------------------------------------------------------------------
443 SfxPoolItem* SvxChartKindErrorItem::Create(SvStream& rIn, USHORT /*nVer*/) const
445 return new SvxChartKindErrorItem(rIn, Which());
448 // -----------------------------------------------------------------------
450 USHORT SvxChartKindErrorItem::GetVersion (USHORT nFileFormatVersion) const
452 return (nFileFormatVersion == SOFFICE_FILEFORMAT_31)
453 ? USHRT_MAX
454 : 0;
457 /*************************************************************************
459 |* SvxChartIndicateItem
461 *************************************************************************/
463 SvxChartIndicateItem::SvxChartIndicateItem(SvxChartIndicate eOrient,
464 USHORT nId) :
465 SfxEnumItem(nId, (USHORT)eOrient)
469 // -----------------------------------------------------------------------
471 SvxChartIndicateItem::SvxChartIndicateItem(SvStream& rIn, USHORT nId) :
472 SfxEnumItem(nId, rIn)
476 // -----------------------------------------------------------------------
478 SfxPoolItem* SvxChartIndicateItem::Clone(SfxItemPool* /*pPool*/) const
480 return new SvxChartIndicateItem(*this);
483 // -----------------------------------------------------------------------
485 SfxPoolItem* SvxChartIndicateItem::Create(SvStream& rIn, USHORT /*nVer*/) const
487 return new SvxChartIndicateItem(rIn, Which());
490 // -----------------------------------------------------------------------
492 USHORT SvxChartIndicateItem::GetVersion (USHORT nFileFormatVersion) const
494 return (nFileFormatVersion == SOFFICE_FILEFORMAT_31)
495 ? USHRT_MAX
496 : 0;
499 /*************************************************************************
501 |* SvxChartRegressItem
503 *************************************************************************/
505 SvxChartRegressItem::SvxChartRegressItem(SvxChartRegress eOrient,
506 USHORT nId) :
507 SfxEnumItem(nId, (USHORT)eOrient)
511 // -----------------------------------------------------------------------
513 SvxChartRegressItem::SvxChartRegressItem(SvStream& rIn, USHORT nId) :
514 SfxEnumItem(nId, rIn)
518 // -----------------------------------------------------------------------
520 SfxPoolItem* SvxChartRegressItem::Clone(SfxItemPool* /*pPool*/) const
522 return new SvxChartRegressItem(*this);
525 // -----------------------------------------------------------------------
527 SfxPoolItem* SvxChartRegressItem::Create(SvStream& rIn, USHORT /*nVer*/) const
529 return new SvxChartRegressItem(rIn, Which());
532 // -----------------------------------------------------------------------
534 USHORT SvxChartRegressItem::GetVersion (USHORT nFileFormatVersion) const
536 return (nFileFormatVersion == SOFFICE_FILEFORMAT_31)
537 ? USHRT_MAX
538 : 0;