xref: /aoo41x/main/svx/source/items/chrtitem.cxx (revision f6e50924)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 // include ---------------------------------------------------------------
28 #include <tools/stream.hxx>
29 #ifndef __SBX_SBXVARIABLE_HXX
30 #include <basic/sbxvar.hxx>
31 #endif
32 #if defined UNX && !defined LINUX
33 #include <wchar.h>
34 #endif
35 #include <rtl/math.hxx>
36 #include <unotools/intlwrapper.hxx>
37 #include <com/sun/star/chart/ChartAxisArrangeOrderType.hpp>
38 
39 #include <stdio.h>
40 #include <float.h>
41 #include <rtl/math.hxx>
42 
43 #include "svx/chrtitem.hxx"
44 
45 using namespace ::rtl;
46 using namespace ::com::sun::star;
47 // -----------------------------------------------------------------------
48 
49 TYPEINIT1_FACTORY(SvxChartStyleItem, SfxEnumItem, new SvxChartStyleItem(CHSTYLE_2D_LINE, 0));
50 TYPEINIT1(SvxChartDataDescrItem, SfxEnumItem);
51 TYPEINIT1(SvxChartTextOrderItem, SfxEnumItem);
52 TYPEINIT1(SvxChartTextOrientItem, SfxEnumItem);
53 TYPEINIT1(SvxChartIndicateItem, SfxEnumItem);
54 TYPEINIT1(SvxChartKindErrorItem, SfxEnumItem);
55 TYPEINIT1(SvxChartRegressItem, SfxEnumItem);
56 TYPEINIT1_FACTORY(SvxDoubleItem, SfxPoolItem, new SvxDoubleItem(0.0, 0));
57 
58 /*************************************************************************
59 |*
60 |*	SvxChartStyleItem
61 |*
62 *************************************************************************/
63 
SvxChartStyleItem(SvxChartStyle eStyle,sal_uInt16 nId)64 SvxChartStyleItem::SvxChartStyleItem(SvxChartStyle eStyle, sal_uInt16 nId) :
65 	SfxEnumItem(nId, (sal_uInt16)eStyle)
66 {
67 }
68 
69 // -----------------------------------------------------------------------
70 
SvxChartStyleItem(SvStream & rIn,sal_uInt16 nId)71 SvxChartStyleItem::SvxChartStyleItem(SvStream& rIn, sal_uInt16 nId) :
72 	SfxEnumItem(nId, rIn)
73 {
74 }
75 
76 // -----------------------------------------------------------------------
77 
Clone(SfxItemPool *) const78 SfxPoolItem* SvxChartStyleItem::Clone(SfxItemPool* /*pPool*/) const
79 {
80 	return new SvxChartStyleItem(*this);
81 }
82 
83 // -----------------------------------------------------------------------
84 
Create(SvStream & rIn,sal_uInt16) const85 SfxPoolItem* SvxChartStyleItem::Create(SvStream& rIn, sal_uInt16 /*nVer*/) const
86 {
87 	return new SvxChartStyleItem(rIn, Which());
88 }
89 
90 /*************************************************************************
91 |*
92 |*	SvxChartDataDescrItem
93 |*
94 *************************************************************************/
95 
SvxChartDataDescrItem(SvxChartDataDescr eDataDescr,sal_uInt16 nId)96 SvxChartDataDescrItem::SvxChartDataDescrItem(SvxChartDataDescr eDataDescr,
97 											 sal_uInt16 nId) :
98 	SfxEnumItem(nId, (sal_uInt16)eDataDescr)
99 {
100 }
101 
102 // -----------------------------------------------------------------------
103 
SvxChartDataDescrItem(SvStream & rIn,sal_uInt16 nId)104 SvxChartDataDescrItem::SvxChartDataDescrItem(SvStream& rIn, sal_uInt16 nId) :
105 	SfxEnumItem(nId, rIn)
106 {
107 }
108 
109 // -----------------------------------------------------------------------
110 
Clone(SfxItemPool *) const111 SfxPoolItem* SvxChartDataDescrItem::Clone(SfxItemPool* /*pPool*/) const
112 {
113 	return new SvxChartDataDescrItem(*this);
114 }
115 
116 // -----------------------------------------------------------------------
117 
Create(SvStream & rIn,sal_uInt16) const118 SfxPoolItem* SvxChartDataDescrItem::Create(SvStream& rIn, sal_uInt16 /*nVer*/) const
119 {
120 	return new SvxChartDataDescrItem(rIn, Which());
121 }
122 
123 /*************************************************************************
124 |*
125 |*	SvxChartTextOrderItem
126 |*
127 *************************************************************************/
128 
SvxChartTextOrderItem(SvxChartTextOrder eOrder,sal_uInt16 nId)129 SvxChartTextOrderItem::SvxChartTextOrderItem(SvxChartTextOrder eOrder,
130 											 sal_uInt16 nId) :
131 	SfxEnumItem(nId, (sal_uInt16)eOrder)
132 {
133 }
134 
135 // -----------------------------------------------------------------------
136 
SvxChartTextOrderItem(SvStream & rIn,sal_uInt16 nId)137 SvxChartTextOrderItem::SvxChartTextOrderItem(SvStream& rIn, sal_uInt16 nId) :
138 	SfxEnumItem(nId, rIn)
139 {
140 }
141 
142 // -----------------------------------------------------------------------
143 
Clone(SfxItemPool *) const144 SfxPoolItem* SvxChartTextOrderItem::Clone(SfxItemPool* /*pPool*/) const
145 {
146 	return new SvxChartTextOrderItem(*this);
147 }
148 
149 // -----------------------------------------------------------------------
150 
Create(SvStream & rIn,sal_uInt16) const151 SfxPoolItem* SvxChartTextOrderItem::Create(SvStream& rIn, sal_uInt16 /*nVer*/) const
152 {
153 	return new SvxChartTextOrderItem(rIn, Which());
154 }
155 
156 // -----------------------------------------------------------------------
157 
QueryValue(::com::sun::star::uno::Any & rVal,sal_uInt8) const158 sal_Bool SvxChartTextOrderItem::QueryValue( ::com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
159 {
160     // the order of the two enums is not equal, so a mapping is required
161 	::com::sun::star::chart::ChartAxisArrangeOrderType eAO;
162     SvxChartTextOrder eOrder( GetValue());
163 
164     switch( eOrder )
165     {
166         case CHTXTORDER_SIDEBYSIDE:
167             eAO = ::com::sun::star::chart::ChartAxisArrangeOrderType_SIDE_BY_SIDE; break;
168         case CHTXTORDER_UPDOWN:
169             eAO = ::com::sun::star::chart::ChartAxisArrangeOrderType_STAGGER_ODD; break;
170         case CHTXTORDER_DOWNUP:
171             eAO = ::com::sun::star::chart::ChartAxisArrangeOrderType_STAGGER_EVEN; break;
172         case CHTXTORDER_AUTO:
173             eAO = ::com::sun::star::chart::ChartAxisArrangeOrderType_AUTO; break;
174     }
175 
176 	rVal <<= eAO;
177 
178 	return sal_True;
179 }
180 
181 // -----------------------------------------------------------------------
182 
PutValue(const::com::sun::star::uno::Any & rVal,sal_uInt8)183 sal_Bool SvxChartTextOrderItem::PutValue( const ::com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
184 {
185     // the order of the two enums is not equal, so a mapping is required
186     ::com::sun::star::chart::ChartAxisArrangeOrderType eAO;
187     SvxChartTextOrder eOrder;
188 
189     if(!(rVal >>= eAO))
190     {
191         // also try an int (for Basic)
192         sal_Int32 nAO = 0;
193         if(!(rVal >>= nAO))
194             return sal_False;
195         eAO = static_cast< ::com::sun::star::chart::ChartAxisArrangeOrderType >( nAO );
196     }
197 
198     switch( eAO )
199     {
200         case ::com::sun::star::chart::ChartAxisArrangeOrderType_SIDE_BY_SIDE:
201             eOrder = CHTXTORDER_SIDEBYSIDE; break;
202         case ::com::sun::star::chart::ChartAxisArrangeOrderType_STAGGER_ODD:
203             eOrder = CHTXTORDER_UPDOWN; break;
204         case ::com::sun::star::chart::ChartAxisArrangeOrderType_STAGGER_EVEN:
205             eOrder = CHTXTORDER_DOWNUP; break;
206         case ::com::sun::star::chart::ChartAxisArrangeOrderType_AUTO:
207             eOrder = CHTXTORDER_AUTO; break;
208         default:
209             return sal_False;
210     }
211 
212 	SetValue( (sal_uInt16)eOrder );
213 
214 	return sal_True;
215 }
216 
217 /*************************************************************************
218 |*
219 |*	SvxChartTextOrientItem
220 |*
221 *************************************************************************/
222 
SvxChartTextOrientItem(SvxChartTextOrient eOrient,sal_uInt16 nId)223 SvxChartTextOrientItem::SvxChartTextOrientItem(SvxChartTextOrient eOrient,
224 											   sal_uInt16 nId) :
225 	SfxEnumItem(nId, (sal_uInt16)eOrient)
226 {
227 }
228 
229 // -----------------------------------------------------------------------
230 
SvxChartTextOrientItem(SvStream & rIn,sal_uInt16 nId)231 SvxChartTextOrientItem::SvxChartTextOrientItem(SvStream& rIn, sal_uInt16 nId) :
232 	SfxEnumItem(nId, rIn)
233 {
234 }
235 
236 // -----------------------------------------------------------------------
237 
Clone(SfxItemPool *) const238 SfxPoolItem* SvxChartTextOrientItem::Clone(SfxItemPool* /*pPool*/) const
239 {
240 	return new SvxChartTextOrientItem(*this);
241 }
242 
243 // -----------------------------------------------------------------------
244 
Create(SvStream & rIn,sal_uInt16) const245 SfxPoolItem* SvxChartTextOrientItem::Create(SvStream& rIn, sal_uInt16 /*nVer*/) const
246 {
247 	return new SvxChartTextOrientItem(rIn, Which());
248 }
249 
250 /*************************************************************************
251 |*
252 |*	SvxDoubleItem
253 |*
254 *************************************************************************/
255 
SvxDoubleItem(double fValue,sal_uInt16 nId)256 SvxDoubleItem::SvxDoubleItem(double fValue, sal_uInt16 nId) :
257 	SfxPoolItem(nId),
258 	fVal(fValue)
259 {
260 }
261 
262 // -----------------------------------------------------------------------
263 
SvxDoubleItem(SvStream & rIn,sal_uInt16 nId)264 SvxDoubleItem::SvxDoubleItem(SvStream& rIn, sal_uInt16 nId) :
265 	SfxPoolItem(nId)
266 {
267 	rIn >> fVal;
268 }
269 
270 // -----------------------------------------------------------------------
271 
SvxDoubleItem(const SvxDoubleItem & rItem)272 SvxDoubleItem::SvxDoubleItem(const SvxDoubleItem& rItem) :
273 	SfxPoolItem(rItem),
274 	fVal(rItem.fVal)
275 {
276 }
277 
278 // -----------------------------------------------------------------------
279 
GetValueText() const280 XubString SvxDoubleItem::GetValueText() const
281 {
282 	rtl::OString aOStr( rtl::math::doubleToString( fVal, rtl_math_StringFormat_E, 4, '.', false ) );
283 	return String( aOStr.getStr(), (sal_uInt16)aOStr.getLength() );
284 }
285 
286 // -----------------------------------------------------------------------
287 
GetPresentation(SfxItemPresentation,SfxMapUnit,SfxMapUnit,XubString & rText,const IntlWrapper * pIntlWrapper) const288 SfxItemPresentation SvxDoubleItem::GetPresentation
289             ( SfxItemPresentation /*ePresentation*/, SfxMapUnit /*eCoreMetric*/,
290               SfxMapUnit /*ePresentationMetric*/, XubString& rText,
291               const IntlWrapper * pIntlWrapper) const
292 {
293     DBG_ASSERT( pIntlWrapper, "SvxDoubleItem::GetPresentation: no IntlWrapper" );
294     if ( pIntlWrapper )
295     {
296         rText = ::rtl::math::doubleToUString( fVal, rtl_math_StringFormat_E, 4,
297             pIntlWrapper->getLocaleData()->getNumDecimalSep().GetChar(0), true );
298     }
299     else
300 		rText = GetValueText();
301 	return SFX_ITEM_PRESENTATION_NAMELESS;
302 }
303 
304 // -----------------------------------------------------------------------
305 
operator ==(const SfxPoolItem & rItem) const306 int SvxDoubleItem::operator == (const SfxPoolItem& rItem) const
307 {
308 	return (((SvxDoubleItem&)rItem).fVal == fVal);
309 }
310 
311 // -----------------------------------------------------------------------
312 
Clone(SfxItemPool *) const313 SfxPoolItem* SvxDoubleItem::Clone(SfxItemPool* /*pPool*/) const
314 {
315 	return new SvxDoubleItem(*this);
316 }
317 
318 // -----------------------------------------------------------------------
319 
Create(SvStream & rIn,sal_uInt16) const320 SfxPoolItem* SvxDoubleItem::Create(SvStream& rIn, sal_uInt16 /*nVersion*/) const
321 {
322     double _fVal;
323     rIn >> _fVal;
324     return new SvxDoubleItem(_fVal, Which());
325 }
326 
327 // -----------------------------------------------------------------------
328 
Store(SvStream & rOut,sal_uInt16) const329 SvStream& SvxDoubleItem::Store(SvStream& rOut, sal_uInt16 /*nItemVersion*/) const
330 {
331 	rOut << fVal;
332 	return rOut;
333 }
334 
335 // -----------------------------------------------------------------------
336 
GetMin() const337 double SvxDoubleItem::GetMin() const
338 {
339 	return DBL_MIN;
340 }
341 
342 // -----------------------------------------------------------------------
343 
GetMax() const344 double SvxDoubleItem::GetMax() const
345 {
346 	return DBL_MAX;
347 }
348 
349 // -----------------------------------------------------------------------
350 
GetUnit() const351 SfxFieldUnit SvxDoubleItem::GetUnit() const
352 {
353 	return SFX_FUNIT_NONE;
354 }
355 
356 
357 
358 
359 // -----------------------------------------------------------------------
QueryValue(uno::Any & rVal,sal_uInt8) const360 sal_Bool SvxDoubleItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
361 {
362 	rVal <<= fVal;
363 	return sal_True;
364 }
365 
366 // -----------------------------------------------------------------------
PutValue(const uno::Any & rVal,sal_uInt8)367 sal_Bool SvxDoubleItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
368 {
369 	return rVal >>= fVal;
370 }
371 
372 
373 
374 /*************************************************************************
375 |*
376 |*	SvxChartKindErrorItem
377 |*
378 *************************************************************************/
379 
SvxChartKindErrorItem(SvxChartKindError eOrient,sal_uInt16 nId)380 SvxChartKindErrorItem::SvxChartKindErrorItem(SvxChartKindError eOrient,
381 											   sal_uInt16 nId) :
382 	SfxEnumItem(nId, (sal_uInt16)eOrient)
383 {
384 }
385 
386 // -----------------------------------------------------------------------
387 
SvxChartKindErrorItem(SvStream & rIn,sal_uInt16 nId)388 SvxChartKindErrorItem::SvxChartKindErrorItem(SvStream& rIn, sal_uInt16 nId) :
389 	SfxEnumItem(nId, rIn)
390 {
391 }
392 
393 // -----------------------------------------------------------------------
394 
Clone(SfxItemPool *) const395 SfxPoolItem* SvxChartKindErrorItem::Clone(SfxItemPool* /*pPool*/) const
396 {
397 	return new SvxChartKindErrorItem(*this);
398 }
399 
400 // -----------------------------------------------------------------------
401 
Create(SvStream & rIn,sal_uInt16) const402 SfxPoolItem* SvxChartKindErrorItem::Create(SvStream& rIn, sal_uInt16 /*nVer*/) const
403 {
404 	return new SvxChartKindErrorItem(rIn, Which());
405 }
406 
407 // -----------------------------------------------------------------------
408 
GetVersion(sal_uInt16 nFileFormatVersion) const409 sal_uInt16 SvxChartKindErrorItem::GetVersion (sal_uInt16 nFileFormatVersion) const
410 {
411 	return (nFileFormatVersion == SOFFICE_FILEFORMAT_31)
412 			   ? USHRT_MAX
413 			   : 0;
414 }
415 
416 /*************************************************************************
417 |*
418 |*	SvxChartIndicateItem
419 |*
420 *************************************************************************/
421 
SvxChartIndicateItem(SvxChartIndicate eOrient,sal_uInt16 nId)422 SvxChartIndicateItem::SvxChartIndicateItem(SvxChartIndicate eOrient,
423 											   sal_uInt16 nId) :
424 	SfxEnumItem(nId, (sal_uInt16)eOrient)
425 {
426 }
427 
428 // -----------------------------------------------------------------------
429 
SvxChartIndicateItem(SvStream & rIn,sal_uInt16 nId)430 SvxChartIndicateItem::SvxChartIndicateItem(SvStream& rIn, sal_uInt16 nId) :
431 	SfxEnumItem(nId, rIn)
432 {
433 }
434 
435 // -----------------------------------------------------------------------
436 
Clone(SfxItemPool *) const437 SfxPoolItem* SvxChartIndicateItem::Clone(SfxItemPool* /*pPool*/) const
438 {
439 	return new SvxChartIndicateItem(*this);
440 }
441 
442 // -----------------------------------------------------------------------
443 
Create(SvStream & rIn,sal_uInt16) const444 SfxPoolItem* SvxChartIndicateItem::Create(SvStream& rIn, sal_uInt16 /*nVer*/) const
445 {
446 	return new SvxChartIndicateItem(rIn, Which());
447 }
448 
449 // -----------------------------------------------------------------------
450 
GetVersion(sal_uInt16 nFileFormatVersion) const451 sal_uInt16 SvxChartIndicateItem::GetVersion (sal_uInt16 nFileFormatVersion) const
452 {
453 	return (nFileFormatVersion == SOFFICE_FILEFORMAT_31)
454 			   ? USHRT_MAX
455 			   : 0;
456 }
457 
458 /*************************************************************************
459 |*
460 |*	SvxChartRegressItem
461 |*
462 *************************************************************************/
463 
SvxChartRegressItem(SvxChartRegress eOrient,sal_uInt16 nId)464 SvxChartRegressItem::SvxChartRegressItem(SvxChartRegress eOrient,
465 											   sal_uInt16 nId) :
466 	SfxEnumItem(nId, (sal_uInt16)eOrient)
467 {
468 }
469 
470 // -----------------------------------------------------------------------
471 
SvxChartRegressItem(SvStream & rIn,sal_uInt16 nId)472 SvxChartRegressItem::SvxChartRegressItem(SvStream& rIn, sal_uInt16 nId) :
473 	SfxEnumItem(nId, rIn)
474 {
475 }
476 
477 // -----------------------------------------------------------------------
478 
Clone(SfxItemPool *) const479 SfxPoolItem* SvxChartRegressItem::Clone(SfxItemPool* /*pPool*/) const
480 {
481 	return new SvxChartRegressItem(*this);
482 }
483 
484 // -----------------------------------------------------------------------
485 
Create(SvStream & rIn,sal_uInt16) const486 SfxPoolItem* SvxChartRegressItem::Create(SvStream& rIn, sal_uInt16 /*nVer*/) const
487 {
488 	return new SvxChartRegressItem(rIn, Which());
489 }
490 
491 // -----------------------------------------------------------------------
492 
GetVersion(sal_uInt16 nFileFormatVersion) const493 sal_uInt16 SvxChartRegressItem::GetVersion (sal_uInt16 nFileFormatVersion) const
494 {
495 	return (nFileFormatVersion == SOFFICE_FILEFORMAT_31)
496 			   ? USHRT_MAX
497 			   : 0;
498 }
499 
500 
501