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 <ItemPropertyMap.hxx>
23 #include <GraphicPropertyItemConverter.hxx>
24 #include <CharacterPropertyItemConverter.hxx>
25 #include <com/sun/star/chart2/XLegend.hpp>
26 #include <com/sun/star/chart2/LegendPosition.hpp>
27 #include <com/sun/star/chart/ChartLegendExpansion.hpp>
29 #include <svl/intitem.hxx>
30 #include <svl/eitem.hxx>
31 #include <tools/diagnose_ex.h>
37 using namespace ::com::sun::star
;
44 LegendItemConverter::LegendItemConverter(
45 const css::uno::Reference
< css::beans::XPropertySet
> & rPropertySet
,
46 SfxItemPool
& rItemPool
,
48 const uno::Reference
< lang::XMultiServiceFactory
> & xNamedPropertyContainerFactory
,
49 const awt::Size
* pRefSize
) :
50 ItemConverter( rPropertySet
, rItemPool
)
52 m_aConverters
.push_back( new GraphicPropertyItemConverter(
53 rPropertySet
, rItemPool
, rDrawModel
, xNamedPropertyContainerFactory
,
54 GraphicObjectType::LineAndFillProperties
));
55 m_aConverters
.push_back( new CharacterPropertyItemConverter(
56 rPropertySet
, rItemPool
, pRefSize
,
57 "ReferencePageSize" ));
60 LegendItemConverter::~LegendItemConverter()
62 std::for_each( m_aConverters
.begin(), m_aConverters
.end(), std::default_delete
<ItemConverter
>());
65 void LegendItemConverter::FillItemSet( SfxItemSet
& rOutItemSet
) const
67 for( const auto& pConv
: m_aConverters
)
68 pConv
->FillItemSet( rOutItemSet
);
71 ItemConverter::FillItemSet( rOutItemSet
);
74 bool LegendItemConverter::ApplyItemSet( const SfxItemSet
& rItemSet
)
78 for( const auto& pConv
: m_aConverters
)
79 bResult
= pConv
->ApplyItemSet( rItemSet
) || bResult
;
82 return ItemConverter::ApplyItemSet( rItemSet
) || bResult
;
85 const sal_uInt16
* LegendItemConverter::GetWhichPairs() const
87 // must span all used items!
88 return nLegendWhichPairs
;
91 bool LegendItemConverter::GetItemProperty( tWhichIdType
/*nWhichId*/, tPropertyNameWithMemberId
& /*rOutProperty*/ ) const
93 // No own (non-special) properties
97 bool LegendItemConverter::ApplySpecialItem( sal_uInt16 nWhichId
, const SfxItemSet
& rInItemSet
)
99 bool bChanged
= false;
103 case SCHATTR_LEGEND_SHOW
:
105 const SfxPoolItem
* pPoolItem
= nullptr;
106 if( rInItemSet
.GetItemState( SCHATTR_LEGEND_SHOW
, true, &pPoolItem
) == SfxItemState::SET
)
108 bool bShow
= static_cast< const SfxBoolItem
* >( pPoolItem
)->GetValue();
109 bool bWasShown
= true;
110 if( ! (GetPropertySet()->getPropertyValue( "Show" ) >>= bWasShown
) ||
111 ( bWasShown
!= bShow
))
113 GetPropertySet()->setPropertyValue( "Show" , uno::Any( bShow
));
120 case SCHATTR_LEGEND_POS
:
122 const SfxPoolItem
* pPoolItem
= nullptr;
123 if( rInItemSet
.GetItemState( SCHATTR_LEGEND_POS
, true, &pPoolItem
) == SfxItemState::SET
)
125 chart2::LegendPosition eNewPos
= static_cast<chart2::LegendPosition
>(static_cast<const SfxInt32Item
*>(pPoolItem
)->GetValue());
127 css::chart::ChartLegendExpansion eExpansion
= css::chart::ChartLegendExpansion_HIGH
;
130 case chart2::LegendPosition_LINE_START
:
131 case chart2::LegendPosition_LINE_END
:
132 eExpansion
= css::chart::ChartLegendExpansion_HIGH
;
134 case chart2::LegendPosition_PAGE_START
:
135 case chart2::LegendPosition_PAGE_END
:
136 eExpansion
= css::chart::ChartLegendExpansion_WIDE
;
144 chart2::LegendPosition eOldPos
;
145 if( ! ( GetPropertySet()->getPropertyValue( "AnchorPosition" ) >>= eOldPos
) ||
146 ( eOldPos
!= eNewPos
))
148 GetPropertySet()->setPropertyValue( "AnchorPosition" , uno::Any( eNewPos
));
149 GetPropertySet()->setPropertyValue( "Expansion" , uno::Any( eExpansion
));
150 GetPropertySet()->setPropertyValue( "RelativePosition" , uno::Any());
154 catch( const uno::Exception
& )
156 DBG_UNHANDLED_EXCEPTION("chart2");
166 void LegendItemConverter::FillSpecialItem(
167 sal_uInt16 nWhichId
, SfxItemSet
& rOutItemSet
) const
171 case SCHATTR_LEGEND_SHOW
:
174 GetPropertySet()->getPropertyValue( "Show" ) >>= bShow
;
175 rOutItemSet
.Put( SfxBoolItem(SCHATTR_LEGEND_SHOW
, bShow
) );
178 case SCHATTR_LEGEND_POS
:
180 chart2::LegendPosition
eLegendPos( chart2::LegendPosition_LINE_END
);
181 GetPropertySet()->getPropertyValue( "AnchorPosition" ) >>= eLegendPos
;
182 rOutItemSet
.Put( SfxInt32Item(SCHATTR_LEGEND_POS
, static_cast<sal_Int32
>(eLegendPos
) ) );
188 } // namespace wrapper
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */