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 <LegendItemConverter.hxx>
21 #include "SchWhichPairs.hxx"
22 #include <GraphicPropertyItemConverter.hxx>
23 #include <CharacterPropertyItemConverter.hxx>
24 #include <com/sun/star/chart2/LegendPosition.hpp>
25 #include <com/sun/star/chart/ChartLegendExpansion.hpp>
26 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <svl/intitem.hxx>
29 #include <svl/eitem.hxx>
30 #include <tools/diagnose_ex.h>
34 using namespace ::com::sun::star
;
36 namespace chart::wrapper
39 LegendItemConverter::LegendItemConverter(
40 const css::uno::Reference
< css::beans::XPropertySet
> & rPropertySet
,
41 SfxItemPool
& rItemPool
,
43 const uno::Reference
< lang::XMultiServiceFactory
> & xNamedPropertyContainerFactory
,
44 const awt::Size
* pRefSize
) :
45 ItemConverter( rPropertySet
, rItemPool
)
47 m_aConverters
.emplace_back( new GraphicPropertyItemConverter(
48 rPropertySet
, rItemPool
, rDrawModel
, xNamedPropertyContainerFactory
,
49 GraphicObjectType::LineAndFillProperties
));
50 m_aConverters
.emplace_back( new CharacterPropertyItemConverter(
51 rPropertySet
, rItemPool
, pRefSize
,
52 "ReferencePageSize" ));
55 LegendItemConverter::~LegendItemConverter()
59 void LegendItemConverter::FillItemSet( SfxItemSet
& rOutItemSet
) const
61 for( const auto& pConv
: m_aConverters
)
62 pConv
->FillItemSet( rOutItemSet
);
65 ItemConverter::FillItemSet( rOutItemSet
);
68 bool LegendItemConverter::ApplyItemSet( const SfxItemSet
& rItemSet
)
72 for( const auto& pConv
: m_aConverters
)
73 bResult
= pConv
->ApplyItemSet( rItemSet
) || bResult
;
76 return ItemConverter::ApplyItemSet( rItemSet
) || bResult
;
79 const sal_uInt16
* LegendItemConverter::GetWhichPairs() const
81 // must span all used items!
82 return nLegendWhichPairs
;
85 bool LegendItemConverter::GetItemProperty( tWhichIdType
/*nWhichId*/, tPropertyNameWithMemberId
& /*rOutProperty*/ ) const
87 // No own (non-special) properties
91 bool LegendItemConverter::ApplySpecialItem( sal_uInt16 nWhichId
, const SfxItemSet
& rInItemSet
)
93 bool bChanged
= false;
97 case SCHATTR_LEGEND_SHOW
:
99 const SfxPoolItem
* pPoolItem
= nullptr;
100 if( rInItemSet
.GetItemState( SCHATTR_LEGEND_SHOW
, true, &pPoolItem
) == SfxItemState::SET
)
102 bool bShow
= static_cast< const SfxBoolItem
* >( pPoolItem
)->GetValue();
103 bool bWasShown
= true;
104 if( ! (GetPropertySet()->getPropertyValue( "Show" ) >>= bWasShown
) ||
105 ( bWasShown
!= bShow
))
107 GetPropertySet()->setPropertyValue( "Show" , uno::Any( bShow
));
114 case SCHATTR_LEGEND_POS
:
116 const SfxPoolItem
* pPoolItem
= nullptr;
117 if( rInItemSet
.GetItemState( SCHATTR_LEGEND_POS
, true, &pPoolItem
) == SfxItemState::SET
)
119 chart2::LegendPosition eNewPos
= static_cast<chart2::LegendPosition
>(static_cast<const SfxInt32Item
*>(pPoolItem
)->GetValue());
121 css::chart::ChartLegendExpansion eExpansion
= css::chart::ChartLegendExpansion_HIGH
;
124 case chart2::LegendPosition_LINE_START
:
125 case chart2::LegendPosition_LINE_END
:
126 eExpansion
= css::chart::ChartLegendExpansion_HIGH
;
128 case chart2::LegendPosition_PAGE_START
:
129 case chart2::LegendPosition_PAGE_END
:
130 eExpansion
= css::chart::ChartLegendExpansion_WIDE
;
138 chart2::LegendPosition eOldPos
;
139 if( ! ( GetPropertySet()->getPropertyValue( "AnchorPosition" ) >>= eOldPos
) ||
140 ( eOldPos
!= eNewPos
))
142 GetPropertySet()->setPropertyValue( "AnchorPosition" , uno::Any( eNewPos
));
143 GetPropertySet()->setPropertyValue( "Expansion" , uno::Any( eExpansion
));
144 GetPropertySet()->setPropertyValue( "RelativePosition" , uno::Any());
148 catch( const uno::Exception
& )
150 DBG_UNHANDLED_EXCEPTION("chart2");
155 case SCHATTR_LEGEND_NO_OVERLAY
:
157 const SfxPoolItem
* pPoolItem
= nullptr;
158 if(rInItemSet
.GetItemState(SCHATTR_LEGEND_NO_OVERLAY
, true, &pPoolItem
) == SfxItemState::SET
)
160 bool bOverlay
= !static_cast<const SfxBoolItem
*>(pPoolItem
)->GetValue();
161 bool bOldOverlay
= false;
162 if(!(GetPropertySet()->getPropertyValue("Overlay") >>= bOldOverlay
) ||
163 (bOldOverlay
!= bOverlay
))
165 GetPropertySet()->setPropertyValue("Overlay", uno::Any(bOverlay
));
177 void LegendItemConverter::FillSpecialItem(
178 sal_uInt16 nWhichId
, SfxItemSet
& rOutItemSet
) const
182 case SCHATTR_LEGEND_SHOW
:
185 GetPropertySet()->getPropertyValue( "Show" ) >>= bShow
;
186 rOutItemSet
.Put( SfxBoolItem(SCHATTR_LEGEND_SHOW
, bShow
) );
189 case SCHATTR_LEGEND_POS
:
191 chart2::LegendPosition
eLegendPos( chart2::LegendPosition_LINE_END
);
192 GetPropertySet()->getPropertyValue( "AnchorPosition" ) >>= eLegendPos
;
193 rOutItemSet
.Put( SfxInt32Item(SCHATTR_LEGEND_POS
, static_cast<sal_Int32
>(eLegendPos
) ) );
196 case SCHATTR_LEGEND_NO_OVERLAY
:
198 bool bOverlay
= false;
199 GetPropertySet()->getPropertyValue("Overlay") >>= bOverlay
;
200 rOutItemSet
.Put(SfxBoolItem(SCHATTR_LEGEND_NO_OVERLAY
, !bOverlay
));
206 } // namespace chart::wrapper
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */