1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <TextLabelItemConverter.hxx>
21 #include <CharacterPropertyItemConverter.hxx>
22 #include <ChartModelHelper.hxx>
23 #include <ChartTypeHelper.hxx>
24 #include <DataSeriesHelper.hxx>
25 #include <DiagramHelper.hxx>
26 #include <ItemPropertyMap.hxx>
27 #include <SchWhichPairs.hxx>
29 #include <unonames.hxx>
31 #include <editeng/brushitem.hxx>
32 #include <editeng/sizeitem.hxx>
33 #include <svl/ilstitem.hxx>
34 #include <svl/intitem.hxx>
35 #include <svl/stritem.hxx>
36 #include <svx/tabline.hxx>
38 #include <com/sun/star/chart2/DataPointLabel.hpp>
39 #include <com/sun/star/chart2/Symbol.hpp>
41 using namespace com::sun::star
;
42 using namespace com::sun::star::chart2
;
43 using com::sun::star::uno::Reference
;
45 namespace chart
{ namespace wrapper
{
49 const ItemPropertyMapType
& getTextLabelPropertyMap()
51 static ItemPropertyMapType
aMap(
53 IPM_MAP_ENTRY(XATTR_LINESTYLE
, CHART_UNONAME_LABEL_BORDER_STYLE
, 0)
54 IPM_MAP_ENTRY(XATTR_LINEWIDTH
, CHART_UNONAME_LABEL_BORDER_WIDTH
, 0)
55 IPM_MAP_ENTRY(XATTR_LINEDASH
, CHART_UNONAME_LABEL_BORDER_DASH
, 0)
56 IPM_MAP_ENTRY(XATTR_LINECOLOR
, CHART_UNONAME_LABEL_BORDER_COLOR
, 0)
57 IPM_MAP_ENTRY(XATTR_LINETRANSPARENCE
, CHART_UNONAME_LABEL_BORDER_TRANS
, 0)
63 sal_Int32
getSymbolStyleForSymbol( const chart2::Symbol
& rSymbol
)
65 sal_Int32 nStyle
= SVX_SYMBOLTYPE_UNKNOWN
;
66 switch (rSymbol
.Style
)
68 case chart2::SymbolStyle_NONE
:
69 nStyle
= SVX_SYMBOLTYPE_NONE
;
71 case chart2::SymbolStyle_AUTO
:
72 nStyle
= SVX_SYMBOLTYPE_AUTO
;
74 case chart2::SymbolStyle_GRAPHIC
:
75 nStyle
= SVX_SYMBOLTYPE_BRUSHITEM
;
77 case chart2::SymbolStyle_STANDARD
:
78 nStyle
= rSymbol
.StandardSymbol
;
80 case chart2::SymbolStyle_POLYGON
:
87 bool numberFormatFromItemToPropertySet(
88 sal_uInt16 nWhichId
, const SfxItemSet
& rItemSet
, const uno::Reference
<beans::XPropertySet
>& xPropertySet
,
89 bool bOverwriteDataPoints
)
91 bool bChanged
= false;
92 if (!xPropertySet
.is())
95 OUString aPropertyName
= (SID_ATTR_NUMBERFORMAT_VALUE
== nWhichId
) ? OUString(CHART_UNONAME_NUMFMT
) : OUString("PercentageNumberFormat");
96 sal_uInt16 nSourceWhich
= (SID_ATTR_NUMBERFORMAT_VALUE
== nWhichId
) ? SID_ATTR_NUMBERFORMAT_SOURCE
: SCHATTR_PERCENT_NUMBERFORMAT_SOURCE
;
98 if (SfxItemState::SET
!= rItemSet
.GetItemState(nSourceWhich
))
102 bool bUseSourceFormat
= (static_cast<const SfxBoolItem
&>(rItemSet
.Get(nSourceWhich
)).GetValue());
103 if (!bUseSourceFormat
)
105 SfxItemState aState
= rItemSet
.GetItemState(nWhichId
);
106 if (aState
== SfxItemState::SET
)
108 sal_Int32 nFmt
= static_cast<sal_Int32
>(
109 static_cast<const SfxUInt32Item
&>(
110 rItemSet
.Get(nWhichId
)).GetValue());
111 aValue
= uno::makeAny(nFmt
);
117 uno::Any aOldValue
= xPropertySet
->getPropertyValue(aPropertyName
);
118 if (bOverwriteDataPoints
)
120 Reference
<chart2::XDataSeries
> xSeries(xPropertySet
, uno::UNO_QUERY
);
121 if (aValue
!= aOldValue
||
122 ::chart::DataSeriesHelper::hasAttributedDataPointDifferentValue(xSeries
, aPropertyName
, aOldValue
))
124 ::chart::DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints(xSeries
, aPropertyName
, aValue
);
128 else if (aOldValue
!= aValue
)
130 xPropertySet
->setPropertyValue(aPropertyName
, aValue
);
136 bool useSourceFormatFromItemToPropertySet(
137 sal_uInt16 nWhichId
, const SfxItemSet
& rItemSet
, const uno::Reference
<beans::XPropertySet
>& xPropertySet
,
138 bool bOverwriteDataPoints
)
140 bool bChanged
= false;
141 if (!xPropertySet
.is())
143 OUString aPropertyName
= (SID_ATTR_NUMBERFORMAT_SOURCE
== nWhichId
) ? OUString(CHART_UNONAME_NUMFMT
) : OUString("PercentageNumberFormat");
144 sal_uInt16 nFormatWhich
= (SID_ATTR_NUMBERFORMAT_SOURCE
== nWhichId
) ? SID_ATTR_NUMBERFORMAT_VALUE
: SCHATTR_PERCENT_NUMBERFORMAT_VALUE
;
146 if (SfxItemState::SET
!= rItemSet
.GetItemState(nWhichId
))
150 bool bUseSourceFormat
= (static_cast<const SfxBoolItem
&>(
151 rItemSet
.Get(nWhichId
)).GetValue());
152 if (!bUseSourceFormat
)
154 SfxItemState aState
= rItemSet
.GetItemState(nFormatWhich
);
155 if (aState
== SfxItemState::SET
)
157 sal_Int32 nFormatKey
= static_cast<sal_Int32
>(
158 static_cast<const SfxUInt32Item
&>(
159 rItemSet
.Get(nFormatWhich
)).GetValue());
160 aNewValue
<<= nFormatKey
;
166 uno::Any
aOldValue(xPropertySet
->getPropertyValue(aPropertyName
));
167 if (bOverwriteDataPoints
)
169 Reference
<chart2::XDataSeries
> xSeries(xPropertySet
, uno::UNO_QUERY
);
170 if (aNewValue
!= aOldValue
||
171 ::chart::DataSeriesHelper::hasAttributedDataPointDifferentValue(xSeries
, aPropertyName
, aOldValue
))
173 ::chart::DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints(xSeries
, aPropertyName
, aNewValue
);
177 else if (aOldValue
!= aNewValue
)
179 xPropertySet
->setPropertyValue(aPropertyName
, aNewValue
);
186 } // anonymous namespace
188 TextLabelItemConverter::TextLabelItemConverter(
189 const uno::Reference
<frame::XModel
>& xChartModel
,
190 const uno::Reference
<beans::XPropertySet
>& rPropertySet
,
191 const uno::Reference
<XDataSeries
>& xSeries
,
192 SfxItemPool
& rItemPool
, const awt::Size
* pRefSize
,
193 bool bDataSeries
, sal_Int32 nNumberFormat
, sal_Int32 nPercentNumberFormat
) :
194 ItemConverter(rPropertySet
, rItemPool
),
195 mnNumberFormat(nNumberFormat
),
196 mnPercentNumberFormat(nPercentNumberFormat
),
197 mbDataSeries(bDataSeries
),
198 mbForbidPercentValue(true)
200 maConverters
.push_back(new CharacterPropertyItemConverter(rPropertySet
, rItemPool
, pRefSize
, "ReferencePageSize"));
202 uno::Reference
<XDiagram
> xDiagram(ChartModelHelper::findDiagram(xChartModel
));
203 uno::Reference
<XChartType
> xChartType(DiagramHelper::getChartTypeOfSeries(xDiagram
, xSeries
));
205 bool bAmbiguous
= false;
206 bool bSwapXAndY
= DiagramHelper::getVertical(xDiagram
, bFound
, bAmbiguous
);
207 maAvailableLabelPlacements
= ChartTypeHelper::getSupportedLabelPlacements(xChartType
, DiagramHelper::getDimension(xDiagram
), bSwapXAndY
, xSeries
);
209 mbForbidPercentValue
= AxisType::CATEGORY
!= ChartTypeHelper::getAxisType(xChartType
, 0);
212 TextLabelItemConverter::~TextLabelItemConverter()
214 std::for_each(maConverters
.begin(), maConverters
.end(), boost::checked_deleter
<ItemConverter
>());
217 void TextLabelItemConverter::FillItemSet( SfxItemSet
& rOutItemSet
) const
219 std::for_each(maConverters
.begin(), maConverters
.end(),
220 FillItemSetFunc(rOutItemSet
));
223 ItemConverter::FillItemSet(rOutItemSet
);
226 bool TextLabelItemConverter::ApplyItemSet( const SfxItemSet
& rItemSet
)
228 bool bResult
= false;
230 std::for_each(maConverters
.begin(), maConverters
.end(),
231 ApplyItemSetFunc(rItemSet
, bResult
));
234 return ItemConverter::ApplyItemSet(rItemSet
) || bResult
;
237 const sal_uInt16
* TextLabelItemConverter::GetWhichPairs() const
239 // must span all used items!
240 return nTextLabelWhichPairs
;
243 bool TextLabelItemConverter::GetItemProperty( tWhichIdType nWhichId
, tPropertyNameWithMemberId
& rOutProperty
) const
245 const ItemPropertyMapType
& rMap
= getTextLabelPropertyMap();
246 ItemPropertyMapType::const_iterator it
= rMap
.find(nWhichId
);
248 if (it
== rMap
.end())
251 rOutProperty
= it
->second
;
255 bool TextLabelItemConverter::ApplySpecialItem( sal_uInt16 nWhichId
, const SfxItemSet
& rItemSet
)
256 throw (uno::Exception
)
258 bool bChanged
= false;
262 case SCHATTR_DATADESCR_SHOW_NUMBER
:
263 case SCHATTR_DATADESCR_SHOW_PERCENTAGE
:
264 case SCHATTR_DATADESCR_SHOW_CATEGORY
:
265 case SCHATTR_DATADESCR_SHOW_SYMBOL
:
267 const SfxBoolItem
& rItem
= static_cast<const SfxBoolItem
&>(rItemSet
.Get(nWhichId
));
269 uno::Any aOldValue
= GetPropertySet()->getPropertyValue(CHART_UNONAME_LABEL
);
270 chart2::DataPointLabel aLabel
;
271 if (aOldValue
>>= aLabel
)
273 sal_Bool
& rValue
= (SCHATTR_DATADESCR_SHOW_NUMBER
== nWhichId
) ? aLabel
.ShowNumber
: (
274 (SCHATTR_DATADESCR_SHOW_PERCENTAGE
== nWhichId
) ? aLabel
.ShowNumberInPercent
: (
275 (SCHATTR_DATADESCR_SHOW_CATEGORY
== nWhichId
) ? aLabel
.ShowCategoryName
: aLabel
.ShowLegendSymbol
));
276 bool bOldValue
= rValue
;
277 rValue
= rItem
.GetValue();
280 Reference
<chart2::XDataSeries
> xSeries(GetPropertySet(), uno::UNO_QUERY
);
281 if (bOldValue
!= bool(rValue
) ||
282 DataSeriesHelper::hasAttributedDataPointDifferentValue(xSeries
, CHART_UNONAME_LABEL
, aOldValue
))
284 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints(xSeries
, CHART_UNONAME_LABEL
, uno::makeAny(aLabel
));
288 else if (bOldValue
!= bool(rValue
))
290 GetPropertySet()->setPropertyValue(CHART_UNONAME_LABEL
, uno::makeAny(aLabel
));
296 case SID_ATTR_NUMBERFORMAT_VALUE
:
297 case SCHATTR_PERCENT_NUMBERFORMAT_VALUE
: //fall through intended
299 bChanged
= numberFormatFromItemToPropertySet(nWhichId
, rItemSet
, GetPropertySet(), mbDataSeries
);
302 case SID_ATTR_NUMBERFORMAT_SOURCE
:
303 case SCHATTR_PERCENT_NUMBERFORMAT_SOURCE
: //fall through intended
305 bChanged
= useSourceFormatFromItemToPropertySet(nWhichId
, rItemSet
, GetPropertySet(), mbDataSeries
);
308 case SCHATTR_DATADESCR_SEPARATOR
:
310 OUString aNewValue
= static_cast<const SfxStringItem
&>(rItemSet
.Get(nWhichId
)).GetValue();
314 GetPropertySet()->getPropertyValue("LabelSeparator") >>= aOldValue
;
317 Reference
<chart2::XDataSeries
> xSeries(GetPropertySet(), uno::UNO_QUERY
);
318 if (!aOldValue
.equals(aNewValue
) ||
319 DataSeriesHelper::hasAttributedDataPointDifferentValue(xSeries
, "LabelSeparator", uno::makeAny(aOldValue
)))
321 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints(xSeries
, "LabelSeparator", uno::makeAny(aNewValue
));
325 else if (!aOldValue
.equals(aNewValue
))
327 GetPropertySet()->setPropertyValue("LabelSeparator", uno::makeAny(aNewValue
));
331 catch (const uno::Exception
& e
)
337 case SCHATTR_DATADESCR_PLACEMENT
:
341 sal_Int32 nNew
= static_cast<const SfxInt32Item
&>(rItemSet
.Get(nWhichId
)).GetValue();
343 if (!(GetPropertySet()->getPropertyValue("LabelPlacement") >>= nOld
))
345 if (maAvailableLabelPlacements
.getLength())
346 nOld
= maAvailableLabelPlacements
[0];
350 Reference
<chart2::XDataSeries
> xSeries(GetPropertySet(), uno::UNO_QUERY
);
352 DataSeriesHelper::hasAttributedDataPointDifferentValue(xSeries
, "LabelPlacement", uno::makeAny(nOld
)))
354 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints(xSeries
, "LabelPlacement", uno::makeAny(nNew
));
358 else if (nOld
!= nNew
)
360 GetPropertySet()->setPropertyValue("LabelPlacement", uno::makeAny(nNew
));
364 catch (const uno::Exception
& e
)
370 case SCHATTR_STYLE_SYMBOL
:
373 static_cast<const SfxInt32Item
&>(
374 rItemSet
.Get(nWhichId
)).GetValue();
375 chart2::Symbol aSymbol
;
377 GetPropertySet()->getPropertyValue("Symbol") >>= aSymbol
;
378 sal_Int32 nOldStyle
= getSymbolStyleForSymbol(aSymbol
);
380 if (nStyle
!= nOldStyle
)
382 bool bDeleteSymbol
= false;
385 case SVX_SYMBOLTYPE_NONE
:
386 aSymbol
.Style
= chart2::SymbolStyle_NONE
;
388 case SVX_SYMBOLTYPE_AUTO
:
389 aSymbol
.Style
= chart2::SymbolStyle_AUTO
;
391 case SVX_SYMBOLTYPE_BRUSHITEM
:
392 aSymbol
.Style
= chart2::SymbolStyle_GRAPHIC
;
394 case SVX_SYMBOLTYPE_UNKNOWN
:
395 bDeleteSymbol
= true;
399 aSymbol
.Style
= chart2::SymbolStyle_STANDARD
;
400 aSymbol
.StandardSymbol
= nStyle
;
404 GetPropertySet()->setPropertyValue("Symbol", uno::Any());
406 GetPropertySet()->setPropertyValue("Symbol", uno::makeAny(aSymbol
));
411 case SCHATTR_SYMBOL_SIZE
:
413 Size aSize
= static_cast<const SvxSizeItem
&>(
414 rItemSet
.Get(nWhichId
)).GetSize();
415 chart2::Symbol aSymbol
;
417 GetPropertySet()->getPropertyValue("Symbol") >>= aSymbol
;
418 if (aSize
.getWidth() != aSymbol
.Size
.Width
||
419 aSize
.getHeight() != aSymbol
.Size
.Height
)
421 aSymbol
.Size
.Width
= aSize
.getWidth();
422 aSymbol
.Size
.Height
= aSize
.getHeight();
424 GetPropertySet()->setPropertyValue("Symbol", uno::makeAny(aSymbol
));
429 case SCHATTR_SYMBOL_BRUSH
:
431 const SvxBrushItem
& rBrshItem(static_cast<const SvxBrushItem
&>(
432 rItemSet
.Get(nWhichId
)));
433 uno::Any aXGraphicAny
;
434 const Graphic
* pGraphic(rBrshItem
.GetGraphic());
437 uno::Reference
<graphic::XGraphic
> xGraphic(pGraphic
->GetXGraphic());
440 aXGraphicAny
<<= xGraphic
;
441 chart2::Symbol aSymbol
;
442 GetPropertySet()->getPropertyValue("Symbol") >>= aSymbol
;
443 if (aSymbol
.Graphic
!= xGraphic
)
445 aSymbol
.Graphic
= xGraphic
;
446 GetPropertySet()->setPropertyValue("Symbol", uno::makeAny(aSymbol
));
453 case SCHATTR_TEXT_DEGREES
:
455 double fValue
= static_cast<double>(
456 static_cast<const SfxInt32Item
&>(
457 rItemSet
.Get(nWhichId
)).GetValue()) / 100.0;
458 double fOldValue
= 0.0;
460 (GetPropertySet()->getPropertyValue("TextRotation") >>= fOldValue
);
463 (bPropExisted
&& fOldValue
!= fValue
))
465 GetPropertySet()->setPropertyValue("TextRotation", uno::makeAny(fValue
));
475 void TextLabelItemConverter::FillSpecialItem( sal_uInt16 nWhichId
, SfxItemSet
& rOutItemSet
) const
476 throw (uno::Exception
)
480 case SCHATTR_DATADESCR_SHOW_NUMBER
:
481 case SCHATTR_DATADESCR_SHOW_PERCENTAGE
:
482 case SCHATTR_DATADESCR_SHOW_CATEGORY
:
483 case SCHATTR_DATADESCR_SHOW_SYMBOL
:
485 chart2::DataPointLabel aLabel
;
486 if (GetPropertySet()->getPropertyValue(CHART_UNONAME_LABEL
) >>= aLabel
)
488 bool bValue
= (SCHATTR_DATADESCR_SHOW_NUMBER
== nWhichId
) ? aLabel
.ShowNumber
: (
489 (SCHATTR_DATADESCR_SHOW_PERCENTAGE
== nWhichId
) ? aLabel
.ShowNumberInPercent
: (
490 (SCHATTR_DATADESCR_SHOW_CATEGORY
== nWhichId
) ? aLabel
.ShowCategoryName
: aLabel
.ShowLegendSymbol
));
492 rOutItemSet
.Put(SfxBoolItem(nWhichId
, bValue
));
496 if (DataSeriesHelper::hasAttributedDataPointDifferentValue(
497 Reference
<chart2::XDataSeries
>(GetPropertySet(), uno::UNO_QUERY
), CHART_UNONAME_LABEL
, uno::makeAny(aLabel
)))
499 rOutItemSet
.InvalidateItem(nWhichId
);
505 case SID_ATTR_NUMBERFORMAT_VALUE
:
508 if (!(GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT
) >>= nKey
))
509 nKey
= mnNumberFormat
;
510 rOutItemSet
.Put(SfxUInt32Item(nWhichId
, nKey
));
513 case SCHATTR_PERCENT_NUMBERFORMAT_VALUE
:
516 if (!(GetPropertySet()->getPropertyValue("PercentageNumberFormat") >>= nKey
))
517 nKey
= mnPercentNumberFormat
;
518 rOutItemSet
.Put(SfxUInt32Item(nWhichId
, nKey
));
521 case SID_ATTR_NUMBERFORMAT_SOURCE
:
523 bool bNumberFormatIsSet
= GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT
).hasValue();
524 rOutItemSet
.Put(SfxBoolItem(nWhichId
, !bNumberFormatIsSet
));
527 case SCHATTR_PERCENT_NUMBERFORMAT_SOURCE
:
529 bool bNumberFormatIsSet
= (GetPropertySet()->getPropertyValue("PercentageNumberFormat").hasValue());
530 rOutItemSet
.Put(SfxBoolItem(nWhichId
, !bNumberFormatIsSet
));
533 case SCHATTR_DATADESCR_SEPARATOR
:
538 GetPropertySet()->getPropertyValue("LabelSeparator") >>= aValue
;
539 rOutItemSet
.Put(SfxStringItem(nWhichId
, aValue
));
541 catch (const uno::Exception
& e
)
547 case SCHATTR_DATADESCR_PLACEMENT
:
551 sal_Int32 nPlacement
= 0;
552 if (GetPropertySet()->getPropertyValue("LabelPlacement") >>= nPlacement
)
553 rOutItemSet
.Put(SfxInt32Item(nWhichId
, nPlacement
));
554 else if (maAvailableLabelPlacements
.getLength())
555 rOutItemSet
.Put(SfxInt32Item(nWhichId
, maAvailableLabelPlacements
[0]));
557 catch (const uno::Exception
& e
)
563 case SCHATTR_DATADESCR_AVAILABLE_PLACEMENTS
:
565 rOutItemSet
.Put(SfxIntegerListItem(nWhichId
, maAvailableLabelPlacements
));
568 case SCHATTR_DATADESCR_NO_PERCENTVALUE
:
570 rOutItemSet
.Put(SfxBoolItem(nWhichId
, mbForbidPercentValue
));
573 case SCHATTR_STYLE_SYMBOL
:
575 chart2::Symbol aSymbol
;
576 if (GetPropertySet()->getPropertyValue("Symbol") >>= aSymbol
)
577 rOutItemSet
.Put(SfxInt32Item(nWhichId
, getSymbolStyleForSymbol(aSymbol
)));
580 case SCHATTR_SYMBOL_SIZE
:
582 chart2::Symbol aSymbol
;
583 if (GetPropertySet()->getPropertyValue("Symbol") >>= aSymbol
)
585 SvxSizeItem(nWhichId
, Size(aSymbol
.Size
.Width
, aSymbol
.Size
.Height
)));
588 case SCHATTR_SYMBOL_BRUSH
:
590 chart2::Symbol aSymbol
;
591 if ((GetPropertySet()->getPropertyValue("Symbol") >>= aSymbol
)
592 && aSymbol
.Graphic
.is())
595 SvxBrushItem(Graphic(aSymbol
.Graphic
), GPOS_MM
, SCHATTR_SYMBOL_BRUSH
));
599 case SCHATTR_TEXT_DEGREES
:
603 if (GetPropertySet()->getPropertyValue("TextRotation") >>= fValue
)
606 SfxInt32Item(nWhichId
, static_cast<sal_Int32
>(rtl::math::round(fValue
* 100.0))));
615 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */