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_chart2.hxx"
30 #include "DataPointItemConverter.hxx"
31 #include "SchWhichPairs.hxx"
32 #include "macros.hxx"
33 #include "ItemPropertyMap.hxx"
34 
35 #include "GraphicPropertyItemConverter.hxx"
36 #include "CharacterPropertyItemConverter.hxx"
37 #include "StatisticsItemConverter.hxx"
38 #include "SeriesOptionsItemConverter.hxx"
39 #include "DataSeriesHelper.hxx"
40 #include "DiagramHelper.hxx"
41 #include "ChartModelHelper.hxx"
42 #include "ChartTypeHelper.hxx"
43 #include <svx/chrtitem.hxx>
44 #include <com/sun/star/chart2/DataPointLabel.hpp>
45 #include <com/sun/star/chart2/Symbol.hpp>
46 
47 // header for class XFillColorItem
48 #include <svx/xflclit.hxx>
49 #include <svl/intitem.hxx>
50 #include <editeng/sizeitem.hxx>
51 // header for class SfxStringItem
52 #include <svl/stritem.hxx>
53 #include <editeng/brshitem.hxx>
54 //SfxIntegerListItem
55 #include <svl/ilstitem.hxx>
56 #define _SVSTDARR_ULONGS
57 #include <svl/svstdarr.hxx>
58 #include <vcl/graph.hxx>
59 #include <com/sun/star/graphic/XGraphic.hpp>
60 
61 // for SVX_SYMBOLTYPE_...
62 #include <svx/tabline.hxx>
63 
64 #include <functional>
65 #include <algorithm>
66 
67 using namespace ::com::sun::star;
68 using namespace ::com::sun::star::chart2;
69 using ::com::sun::star::uno::Reference;
70 
71 namespace
72 {
73 ::comphelper::ItemPropertyMapType & lcl_GetDataPointPropertyMap()
74 {
75     static ::comphelper::ItemPropertyMapType aDataPointPropertyMap(
76         ::comphelper::MakeItemPropertyMap
77 //        IPM_MAP_ENTRY( CHATTR_PIE_SEGMENT_OFFSET, "Offset", 0 )
78         IPM_MAP_ENTRY( SCHATTR_STYLE_SHAPE, "Geometry3D", 0 )
79         );
80 
81     return aDataPointPropertyMap;
82 };
83 
84 sal_Int32 lcl_getSymbolStyleForSymbol( const chart2::Symbol & rSymbol )
85 {
86     sal_Int32 nStyle = SVX_SYMBOLTYPE_UNKNOWN;
87     switch( rSymbol.Style )
88     {
89         case chart2::SymbolStyle_NONE:
90             nStyle = SVX_SYMBOLTYPE_NONE;
91             break;
92         case chart2::SymbolStyle_AUTO:
93             nStyle = SVX_SYMBOLTYPE_AUTO;
94             break;
95         case chart2::SymbolStyle_GRAPHIC:
96             nStyle = SVX_SYMBOLTYPE_BRUSHITEM;
97             break;
98         case chart2::SymbolStyle_STANDARD:
99             nStyle = rSymbol.StandardSymbol;
100             break;
101 
102         case chart2::SymbolStyle_POLYGON:
103             // to avoid warning
104         case chart2::SymbolStyle_MAKE_FIXED_SIZE:
105             // nothing
106             break;
107     }
108     return nStyle;
109 }
110 
111 bool lcl_NumberFormatFromItemToPropertySet( sal_uInt16 nWhichId, const SfxItemSet & rItemSet, const uno::Reference< beans::XPropertySet > & xPropertySet, bool bOverwriteAttributedDataPointsAlso  )
112 {
113     bool bChanged = false;
114     if( !xPropertySet.is() )
115         return bChanged;
116     rtl::OUString aPropertyName = (SID_ATTR_NUMBERFORMAT_VALUE==nWhichId) ? C2U( "NumberFormat" ) : C2U( "PercentageNumberFormat" );
117     sal_uInt16 nSourceWhich = (SID_ATTR_NUMBERFORMAT_VALUE==nWhichId) ? SID_ATTR_NUMBERFORMAT_SOURCE : SCHATTR_PERCENT_NUMBERFORMAT_SOURCE;
118 
119     if( SFX_ITEM_SET != rItemSet.GetItemState( nSourceWhich ) )
120         return bChanged;
121 
122     uno::Any aValue;
123     bool bUseSourceFormat = (static_cast< const SfxBoolItem & >(
124                 rItemSet.Get( nSourceWhich )).GetValue() );
125     if( !bUseSourceFormat )
126     {
127         SfxItemState aState = rItemSet.GetItemState( nWhichId );
128         if( aState == SFX_ITEM_SET )
129         {
130             sal_Int32 nFmt = static_cast< sal_Int32 >(
131                 static_cast< const SfxUInt32Item & >(
132                     rItemSet.Get( nWhichId )).GetValue());
133             aValue = uno::makeAny(nFmt);
134         }
135         else
136             return bChanged;
137     }
138 
139     uno::Any aOldValue( xPropertySet->getPropertyValue(aPropertyName) );
140     if( bOverwriteAttributedDataPointsAlso )
141     {
142         Reference< chart2::XDataSeries > xSeries( xPropertySet, uno::UNO_QUERY);
143         if( aValue != aOldValue ||
144             ::chart::DataSeriesHelper::hasAttributedDataPointDifferentValue( xSeries, aPropertyName, aOldValue ) )
145         {
146             ::chart::DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, aPropertyName, aValue );
147             bChanged = true;
148         }
149     }
150     else if( aOldValue != aValue )
151     {
152         xPropertySet->setPropertyValue(aPropertyName, aValue );
153         bChanged = true;
154     }
155     return bChanged;
156 }
157 
158 bool lcl_UseSourceFormatFromItemToPropertySet( sal_uInt16 nWhichId, const SfxItemSet & rItemSet, const uno::Reference< beans::XPropertySet > & xPropertySet, bool bOverwriteAttributedDataPointsAlso  )
159 {
160     bool bChanged = false;
161     if( !xPropertySet.is() )
162         return bChanged;
163     rtl::OUString aPropertyName = (SID_ATTR_NUMBERFORMAT_SOURCE==nWhichId) ? C2U( "NumberFormat" ) : C2U( "PercentageNumberFormat" );
164     sal_uInt16 nFormatWhich = (SID_ATTR_NUMBERFORMAT_SOURCE==nWhichId) ? SID_ATTR_NUMBERFORMAT_VALUE : SCHATTR_PERCENT_NUMBERFORMAT_VALUE;
165 
166     if( SFX_ITEM_SET != rItemSet.GetItemState( nWhichId ) )
167         return bChanged;
168 
169     uno::Any aNewValue;
170     bool bUseSourceFormat = (static_cast< const SfxBoolItem & >(
171                 rItemSet.Get( nWhichId )).GetValue() );
172     if( !bUseSourceFormat )
173     {
174         SfxItemState aState = rItemSet.GetItemState( nFormatWhich );
175         if( aState == SFX_ITEM_SET )
176         {
177             sal_Int32 nFormatKey = static_cast< sal_Int32 >(
178             static_cast< const SfxUInt32Item & >(
179                 rItemSet.Get( nFormatWhich )).GetValue());
180             aNewValue <<= nFormatKey;
181         }
182         else
183             return bChanged;
184     }
185 
186     uno::Any aOldValue( xPropertySet->getPropertyValue(aPropertyName) );
187     if( bOverwriteAttributedDataPointsAlso )
188     {
189         Reference< chart2::XDataSeries > xSeries( xPropertySet, uno::UNO_QUERY);
190         if( aNewValue != aOldValue ||
191             ::chart::DataSeriesHelper::hasAttributedDataPointDifferentValue( xSeries, aPropertyName, aOldValue ) )
192         {
193             ::chart::DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, aPropertyName, aNewValue );
194             bChanged = true;
195         }
196     }
197     else if( aOldValue != aNewValue )
198     {
199         xPropertySet->setPropertyValue( aPropertyName, aNewValue );
200         bChanged = true;
201     }
202 
203     return bChanged;
204 }
205 
206 } // anonymous namespace
207 
208 namespace chart
209 {
210 namespace wrapper
211 {
212 
213 DataPointItemConverter::DataPointItemConverter(
214     const uno::Reference< frame::XModel > & xChartModel,
215     const uno::Reference< uno::XComponentContext > & xContext,
216     const uno::Reference< beans::XPropertySet > & rPropertySet,
217     const uno::Reference< XDataSeries > & xSeries,
218     SfxItemPool& rItemPool,
219     SdrModel& rDrawModel,
220     NumberFormatterWrapper * pNumFormatter,
221     const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory,
222     GraphicPropertyItemConverter::eGraphicObjectType eMapTo /* = FILL_PROPERTIES */,
223     ::std::auto_ptr< awt::Size > pRefSize /* = NULL */,
224     bool bDataSeries /* = false */,
225     bool bUseSpecialFillColor /* = false */,
226     sal_Int32 nSpecialFillColor /* =0 */,
227     bool bOverwriteLabelsForAttributedDataPointsAlso /*false*/,
228     sal_Int32 nNumberFormat,
229     sal_Int32 nPercentNumberFormat
230     ) :
231         ItemConverter( rPropertySet, rItemPool ),
232         m_pNumberFormatterWrapper( pNumFormatter ),
233         m_bDataSeries( bDataSeries ),
234         m_bOverwriteLabelsForAttributedDataPointsAlso(m_bDataSeries && bOverwriteLabelsForAttributedDataPointsAlso),
235         m_bUseSpecialFillColor(bUseSpecialFillColor),
236         m_nSpecialFillColor(nSpecialFillColor),
237         m_nNumberFormat(nNumberFormat),
238         m_nPercentNumberFormat(nPercentNumberFormat),
239         m_aAvailableLabelPlacements(),
240         m_bForbidPercentValue(true)
241 {
242     m_aConverters.push_back( new GraphicPropertyItemConverter(
243                                  rPropertySet, rItemPool, rDrawModel, xNamedPropertyContainerFactory, eMapTo ));
244     m_aConverters.push_back( new CharacterPropertyItemConverter( rPropertySet, rItemPool, pRefSize,
245                                                                  C2U( "ReferencePageSize" )));
246     if( bDataSeries )
247     {
248         m_aConverters.push_back( new StatisticsItemConverter( xChartModel, rPropertySet, rItemPool ));
249         m_aConverters.push_back( new SeriesOptionsItemConverter( xChartModel, xContext, rPropertySet, rItemPool ));
250     }
251 
252     uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram(xChartModel) );
253     uno::Reference< XChartType > xChartType( DiagramHelper::getChartTypeOfSeries( xDiagram , xSeries ) );
254     bool bFound = false;
255     bool bAmbiguous = false;
256     sal_Bool bSwapXAndY = DiagramHelper::getVertical( xDiagram, bFound, bAmbiguous );
257     m_aAvailableLabelPlacements = ChartTypeHelper::getSupportedLabelPlacements( xChartType, DiagramHelper::getDimension( xDiagram ), bSwapXAndY, xSeries );
258 
259     m_bForbidPercentValue = AxisType::CATEGORY != ChartTypeHelper::getAxisType( xChartType, 0 );
260 }
261 
262 DataPointItemConverter::~DataPointItemConverter()
263 {
264     ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
265                      ::comphelper::DeleteItemConverterPtr() );
266 }
267 
268 void DataPointItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
269 {
270     ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
271                      ::comphelper::FillItemSetFunc( rOutItemSet ));
272 
273     // own items
274     ItemConverter::FillItemSet( rOutItemSet );
275 
276     if( m_bUseSpecialFillColor )
277     {
278         Color aColor(m_nSpecialFillColor);
279         rOutItemSet.Put( XFillColorItem( String(), aColor ) );
280     }
281 }
282 
283 bool DataPointItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
284 {
285     bool bResult = false;
286 
287     ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
288                      ::comphelper::ApplyItemSetFunc( rItemSet, bResult ));
289 
290     // own items
291     return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
292 }
293 
294 const sal_uInt16 * DataPointItemConverter::GetWhichPairs() const
295 {
296     // must span all used items!
297     if( m_bDataSeries )
298         return nRowWhichPairs;
299     return nDataPointWhichPairs;
300 }
301 
302 bool DataPointItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const
303 {
304     ::comphelper::ItemPropertyMapType & rMap( lcl_GetDataPointPropertyMap());
305     ::comphelper::ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId ));
306 
307     if( aIt == rMap.end())
308         return false;
309 
310     rOutProperty =(*aIt).second;
311     return true;
312 }
313 
314 
315 bool DataPointItemConverter::ApplySpecialItem(
316     sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
317     throw( uno::Exception )
318 {
319     bool bChanged = false;
320     uno::Any aValue;
321 
322     switch( nWhichId )
323     {
324         case SCHATTR_DATADESCR_SHOW_NUMBER:
325         case SCHATTR_DATADESCR_SHOW_PERCENTAGE:
326         case SCHATTR_DATADESCR_SHOW_CATEGORY:
327         case SCHATTR_DATADESCR_SHOW_SYMBOL:
328         {
329             const SfxBoolItem & rItem = static_cast< const SfxBoolItem & >( rItemSet.Get( nWhichId ));
330 
331             uno::Any aOldValue( GetPropertySet()->getPropertyValue( C2U( "Label" ) ));
332             chart2::DataPointLabel aLabel;
333             if( aOldValue >>= aLabel )
334             {
335                 sal_Bool& rValue = (SCHATTR_DATADESCR_SHOW_NUMBER==nWhichId) ? aLabel.ShowNumber : (
336                     (SCHATTR_DATADESCR_SHOW_PERCENTAGE==nWhichId) ? aLabel.ShowNumberInPercent : (
337                     (SCHATTR_DATADESCR_SHOW_CATEGORY==nWhichId) ? aLabel.ShowCategoryName : aLabel.ShowLegendSymbol ));
338                 sal_Bool bOldValue = rValue;
339                 rValue = static_cast< sal_Bool >( rItem.GetValue() );
340                 if( m_bOverwriteLabelsForAttributedDataPointsAlso )
341                 {
342                     Reference< chart2::XDataSeries > xSeries( GetPropertySet(), uno::UNO_QUERY);
343                     if( bOldValue != rValue ||
344                         DataSeriesHelper::hasAttributedDataPointDifferentValue( xSeries, C2U( "Label" ), aOldValue ) )
345                     {
346                         DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "Label" ), uno::makeAny( aLabel ) );
347                         bChanged = true;
348                     }
349                 }
350                 else if( bOldValue != rValue )
351                 {
352                     GetPropertySet()->setPropertyValue( C2U( "Label" ), uno::makeAny( aLabel ));
353                     bChanged = true;
354                 }
355             }
356         }
357         break;
358 
359         case SID_ATTR_NUMBERFORMAT_VALUE:
360         case SCHATTR_PERCENT_NUMBERFORMAT_VALUE:  //fall through intended
361         {
362             bChanged = lcl_NumberFormatFromItemToPropertySet( nWhichId, rItemSet, GetPropertySet(), m_bOverwriteLabelsForAttributedDataPointsAlso );
363         }
364         break;
365 
366         case SID_ATTR_NUMBERFORMAT_SOURCE:
367         case SCHATTR_PERCENT_NUMBERFORMAT_SOURCE: //fall through intended
368         {
369             bChanged = lcl_UseSourceFormatFromItemToPropertySet( nWhichId, rItemSet, GetPropertySet(), m_bOverwriteLabelsForAttributedDataPointsAlso );
370         }
371         break;
372 
373         case SCHATTR_DATADESCR_SEPARATOR:
374         {
375             rtl::OUString aNewValue = static_cast< const SfxStringItem & >( rItemSet.Get( nWhichId )).GetValue();
376             rtl::OUString aOldValue;
377             try
378             {
379                 GetPropertySet()->getPropertyValue( C2U( "LabelSeparator" ) ) >>= aOldValue;
380                 if( m_bOverwriteLabelsForAttributedDataPointsAlso )
381                 {
382                     Reference< chart2::XDataSeries > xSeries( GetPropertySet(), uno::UNO_QUERY);
383                     if( !aOldValue.equals(aNewValue) ||
384                         DataSeriesHelper::hasAttributedDataPointDifferentValue( xSeries, C2U( "LabelSeparator" ), uno::makeAny( aOldValue ) ) )
385                     {
386                         DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "LabelSeparator" ), uno::makeAny( aNewValue ) );
387                         bChanged = true;
388                     }
389                 }
390                 else if( !aOldValue.equals(aNewValue) )
391                 {
392                     GetPropertySet()->setPropertyValue( C2U( "LabelSeparator" ), uno::makeAny( aNewValue ));
393                     bChanged = true;
394                 }
395             }
396             catch( uno::Exception& e )
397 	        {
398                 ASSERT_EXCEPTION( e );
399             }
400         }
401         break;
402 
403         case SCHATTR_DATADESCR_PLACEMENT:
404         {
405 
406             try
407             {
408                 sal_Int32 nNew = static_cast< const SfxInt32Item & >( rItemSet.Get( nWhichId )).GetValue();
409                 sal_Int32 nOld =0;
410                 if( !(GetPropertySet()->getPropertyValue( C2U( "LabelPlacement" ) ) >>= nOld) )
411                 {
412                     if( m_aAvailableLabelPlacements.getLength() )
413                         nOld = m_aAvailableLabelPlacements[0];
414                 }
415                 if( m_bOverwriteLabelsForAttributedDataPointsAlso )
416                 {
417                     Reference< chart2::XDataSeries > xSeries( GetPropertySet(), uno::UNO_QUERY);
418                     if( nOld!=nNew ||
419                         DataSeriesHelper::hasAttributedDataPointDifferentValue( xSeries, C2U( "LabelPlacement" ), uno::makeAny( nOld ) ) )
420                     {
421                         DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "LabelPlacement" ), uno::makeAny( nNew ) );
422                         bChanged = true;
423                     }
424                 }
425                 else if( nOld!=nNew )
426                 {
427                     GetPropertySet()->setPropertyValue( C2U( "LabelPlacement" ), uno::makeAny( nNew ));
428                     bChanged = true;
429                 }
430             }
431             catch( uno::Exception& e )
432 	        {
433                 ASSERT_EXCEPTION( e );
434             }
435         }
436         break;
437 
438         case SCHATTR_STYLE_SYMBOL:
439         {
440             sal_Int32 nStyle =
441                 static_cast< const SfxInt32Item & >(
442                     rItemSet.Get( nWhichId )).GetValue();
443             chart2::Symbol aSymbol;
444 
445             GetPropertySet()->getPropertyValue( C2U( "Symbol" )) >>= aSymbol;
446             sal_Int32 nOldStyle = lcl_getSymbolStyleForSymbol( aSymbol );
447 
448             if( nStyle != nOldStyle )
449             {
450                 bool bDeleteSymbol = false;
451                 switch( nStyle )
452                 {
453                     case SVX_SYMBOLTYPE_NONE:
454                         aSymbol.Style = chart2::SymbolStyle_NONE;
455                         break;
456                     case SVX_SYMBOLTYPE_AUTO:
457                         aSymbol.Style = chart2::SymbolStyle_AUTO;
458                         break;
459                     case SVX_SYMBOLTYPE_BRUSHITEM:
460                         aSymbol.Style = chart2::SymbolStyle_GRAPHIC;
461                         break;
462                     case SVX_SYMBOLTYPE_UNKNOWN:
463                         bDeleteSymbol = true;
464                         break;
465 
466                     default:
467                         aSymbol.Style = chart2::SymbolStyle_STANDARD;
468                         aSymbol.StandardSymbol = nStyle;
469                 }
470 
471                 if( bDeleteSymbol )
472                     GetPropertySet()->setPropertyValue( C2U( "Symbol" ), uno::Any());
473                 else
474                     GetPropertySet()->setPropertyValue( C2U( "Symbol" ),
475                                                         uno::makeAny( aSymbol ));
476                 bChanged = true;
477             }
478         }
479         break;
480 
481         case SCHATTR_SYMBOL_SIZE:
482         {
483             Size aSize = static_cast< const SvxSizeItem & >(
484                 rItemSet.Get( nWhichId )).GetSize();
485             chart2::Symbol aSymbol;
486 
487             GetPropertySet()->getPropertyValue( C2U( "Symbol" )) >>= aSymbol;
488             if( aSize.getWidth() != aSymbol.Size.Width ||
489                 aSize.getHeight() != aSymbol.Size.Height )
490             {
491                 aSymbol.Size.Width = aSize.getWidth();
492                 aSymbol.Size.Height = aSize.getHeight();
493 
494                 GetPropertySet()->setPropertyValue( C2U( "Symbol" ), uno::makeAny( aSymbol ));
495                 bChanged = true;
496             }
497         }
498         break;
499 
500         case SCHATTR_SYMBOL_BRUSH:
501         {
502             const SvxBrushItem & rBrshItem( static_cast< const SvxBrushItem & >(
503                                                 rItemSet.Get( nWhichId )));
504             uno::Any aXGraphicAny;
505             const Graphic *pGraphic( rBrshItem.GetGraphic());
506             if( pGraphic )
507             {
508                 uno::Reference< graphic::XGraphic > xGraphic( pGraphic->GetXGraphic());
509                 if( xGraphic.is())
510                 {
511                     aXGraphicAny <<= xGraphic;
512                     chart2::Symbol aSymbol;
513                     GetPropertySet()->getPropertyValue( C2U( "Symbol" )) >>= aSymbol;
514                     if( aSymbol.Graphic != xGraphic )
515                     {
516                         aSymbol.Graphic = xGraphic;
517                         GetPropertySet()->setPropertyValue( C2U( "Symbol" ), uno::makeAny( aSymbol ));
518                         bChanged = true;
519                     }
520                 }
521             }
522         }
523         break;
524 
525         case SCHATTR_TEXT_DEGREES:
526         {
527             double fValue = static_cast< double >(
528                 static_cast< const SfxInt32Item & >(
529                     rItemSet.Get( nWhichId )).GetValue()) / 100.0;
530             double fOldValue = 0.0;
531             bool bPropExisted =
532                 ( GetPropertySet()->getPropertyValue( C2U( "TextRotation" )) >>= fOldValue );
533 
534             if( ! bPropExisted ||
535                 ( bPropExisted && fOldValue != fValue ))
536             {
537                 GetPropertySet()->setPropertyValue( C2U( "TextRotation" ), uno::makeAny( fValue ));
538                 bChanged = true;
539             }
540         }
541         break;
542     }
543 
544     return bChanged;
545 }
546 
547 void DataPointItemConverter::FillSpecialItem(
548     sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
549     throw( uno::Exception )
550 {
551     switch( nWhichId )
552     {
553         case SCHATTR_DATADESCR_SHOW_NUMBER:
554         case SCHATTR_DATADESCR_SHOW_PERCENTAGE:
555         case SCHATTR_DATADESCR_SHOW_CATEGORY:
556         case SCHATTR_DATADESCR_SHOW_SYMBOL:
557         {
558             chart2::DataPointLabel aLabel;
559             if( GetPropertySet()->getPropertyValue( C2U( "Label" )) >>= aLabel )
560             {
561                 sal_Bool bValue = (SCHATTR_DATADESCR_SHOW_NUMBER==nWhichId) ? aLabel.ShowNumber : (
562                     (SCHATTR_DATADESCR_SHOW_PERCENTAGE==nWhichId) ? aLabel.ShowNumberInPercent : (
563                     (SCHATTR_DATADESCR_SHOW_CATEGORY==nWhichId) ? aLabel.ShowCategoryName : aLabel.ShowLegendSymbol ));
564 
565                 rOutItemSet.Put( SfxBoolItem( nWhichId, bValue ));
566 
567                 if( m_bOverwriteLabelsForAttributedDataPointsAlso )
568                 {
569                     if( DataSeriesHelper::hasAttributedDataPointDifferentValue(
570                         Reference< chart2::XDataSeries >( GetPropertySet(), uno::UNO_QUERY), C2U( "Label" ), uno::makeAny(aLabel) ) )
571                     {
572                         rOutItemSet.InvalidateItem(nWhichId);
573                     }
574                 }
575             }
576         }
577         break;
578 
579         case SID_ATTR_NUMBERFORMAT_VALUE:
580         {
581             sal_Int32 nKey = 0;
582             if( !(GetPropertySet()->getPropertyValue( C2U( "NumberFormat" )) >>= nKey) )
583                 nKey = m_nNumberFormat;
584             rOutItemSet.Put( SfxUInt32Item( nWhichId, nKey ));
585         }
586         break;
587 
588         case SCHATTR_PERCENT_NUMBERFORMAT_VALUE:
589         {
590             sal_Int32 nKey = 0;
591             if( !(GetPropertySet()->getPropertyValue( C2U( "PercentageNumberFormat" )) >>= nKey) )
592                 nKey = m_nPercentNumberFormat;
593             rOutItemSet.Put( SfxUInt32Item( nWhichId, nKey ));
594         }
595         break;
596 
597         case SID_ATTR_NUMBERFORMAT_SOURCE:
598         {
599             bool bNumberFormatIsSet = ( GetPropertySet()->getPropertyValue( C2U( "NumberFormat" )).hasValue());
600             rOutItemSet.Put( SfxBoolItem( nWhichId, ! bNumberFormatIsSet ));
601         }
602         break;
603         case SCHATTR_PERCENT_NUMBERFORMAT_SOURCE:
604         {
605             bool bNumberFormatIsSet = ( GetPropertySet()->getPropertyValue( C2U( "PercentageNumberFormat" )).hasValue());
606             rOutItemSet.Put( SfxBoolItem( nWhichId, ! bNumberFormatIsSet ));
607         }
608         break;
609 
610         case SCHATTR_DATADESCR_SEPARATOR:
611         {
612             rtl::OUString aValue;
613             try
614             {
615                 GetPropertySet()->getPropertyValue( C2U( "LabelSeparator" ) ) >>= aValue;
616                 rOutItemSet.Put( SfxStringItem( nWhichId, aValue ));
617             }
618             catch( uno::Exception& e )
619 	        {
620                 ASSERT_EXCEPTION( e );
621             }
622         }
623         break;
624 
625         case SCHATTR_DATADESCR_PLACEMENT:
626         {
627             try
628             {
629                 sal_Int32 nPlacement=0;
630                 if( GetPropertySet()->getPropertyValue( C2U( "LabelPlacement" ) ) >>= nPlacement )
631                     rOutItemSet.Put( SfxInt32Item( nWhichId, nPlacement ));
632                 else if( m_aAvailableLabelPlacements.getLength() )
633                     rOutItemSet.Put( SfxInt32Item( nWhichId, m_aAvailableLabelPlacements[0] ));
634             }
635             catch( uno::Exception& e )
636 	        {
637                 ASSERT_EXCEPTION( e );
638             }
639         }
640         break;
641 
642         case SCHATTR_DATADESCR_AVAILABLE_PLACEMENTS:
643         {
644             SvULongs aList;
645             for ( sal_Int32 nN=0; nN<m_aAvailableLabelPlacements.getLength(); nN++ )
646                 aList.Insert( m_aAvailableLabelPlacements[nN], sal::static_int_cast< sal_uInt16 >(nN) );
647             rOutItemSet.Put( SfxIntegerListItem( nWhichId, aList ) );
648         }
649         break;
650 
651         case SCHATTR_DATADESCR_NO_PERCENTVALUE:
652         {
653             rOutItemSet.Put( SfxBoolItem( nWhichId, m_bForbidPercentValue ));
654         }
655         break;
656 
657         case SCHATTR_STYLE_SYMBOL:
658         {
659             chart2::Symbol aSymbol;
660             if( GetPropertySet()->getPropertyValue( C2U( "Symbol" )) >>= aSymbol )
661                 rOutItemSet.Put( SfxInt32Item( nWhichId, lcl_getSymbolStyleForSymbol( aSymbol ) ));
662         }
663         break;
664 
665         case SCHATTR_SYMBOL_SIZE:
666         {
667             chart2::Symbol aSymbol;
668             if( GetPropertySet()->getPropertyValue( C2U( "Symbol" )) >>= aSymbol )
669                 rOutItemSet.Put(
670                     SvxSizeItem( nWhichId, Size( aSymbol.Size.Width, aSymbol.Size.Height ) ));
671         }
672         break;
673 
674         case SCHATTR_SYMBOL_BRUSH:
675         {
676             chart2::Symbol aSymbol;
677             if(( GetPropertySet()->getPropertyValue( C2U( "Symbol" )) >>= aSymbol )
678                && aSymbol.Graphic.is() )
679             {
680                 rOutItemSet.Put( SvxBrushItem( Graphic( aSymbol.Graphic ), GPOS_MM, SCHATTR_SYMBOL_BRUSH ));
681             }
682         }
683         break;
684 
685         case SCHATTR_TEXT_DEGREES:
686         {
687             double fValue = 0;
688 
689             if( GetPropertySet()->getPropertyValue( C2U( "TextRotation" )) >>= fValue )
690             {
691                 rOutItemSet.Put( SfxInt32Item( nWhichId, static_cast< sal_Int32 >(
692                                                    ::rtl::math::round( fValue * 100.0 ) ) ));
693             }
694         }
695         break;
696    }
697 }
698 
699 } //  namespace wrapper
700 } //  namespace chart
701