fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / itemsetwrapper / LegendItemConverter.cxx
blob26d3038f9b7602bde07b90b76671e8e15d1aa5fa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "macros.hxx"
23 #include "ItemPropertyMap.hxx"
24 #include "GraphicPropertyItemConverter.hxx"
25 #include "CharacterPropertyItemConverter.hxx"
26 #include <com/sun/star/chart2/XLegend.hpp>
27 #include <com/sun/star/chart2/LegendPosition.hpp>
28 #include <com/sun/star/chart/ChartLegendExpansion.hpp>
30 #include <svl/intitem.hxx>
31 #include <svl/eitem.hxx>
33 #include <functional>
34 #include <algorithm>
36 #include <boost/checked_delete.hpp>
38 using namespace ::com::sun::star;
40 namespace chart
42 namespace wrapper
45 LegendItemConverter::LegendItemConverter(
46 const ::com::sun::star::uno::Reference<
47 ::com::sun::star::beans::XPropertySet > & rPropertySet,
48 SfxItemPool& rItemPool,
49 SdrModel& rDrawModel,
50 const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory,
51 const awt::Size* pRefSize ) :
52 ItemConverter( rPropertySet, rItemPool )
54 m_aConverters.push_back( new GraphicPropertyItemConverter(
55 rPropertySet, rItemPool, rDrawModel, xNamedPropertyContainerFactory,
56 GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES ));
57 m_aConverters.push_back( new CharacterPropertyItemConverter(
58 rPropertySet, rItemPool, pRefSize,
59 "ReferencePageSize" ));
62 LegendItemConverter::~LegendItemConverter()
64 ::std::for_each( m_aConverters.begin(), m_aConverters.end(), boost::checked_deleter<ItemConverter>());
67 void LegendItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
69 ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
70 FillItemSetFunc( rOutItemSet ));
72 // own items
73 ItemConverter::FillItemSet( rOutItemSet );
76 bool LegendItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
78 bool bResult = false;
80 ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
81 ApplyItemSetFunc( rItemSet, bResult ));
83 // own items
84 return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
87 const sal_uInt16 * LegendItemConverter::GetWhichPairs() const
89 // must span all used items!
90 return nLegendWhichPairs;
93 bool LegendItemConverter::GetItemProperty( tWhichIdType /*nWhichId*/, tPropertyNameWithMemberId & /*rOutProperty*/ ) const
95 // No own (non-special) properties
96 return false;
99 bool LegendItemConverter::ApplySpecialItem( sal_uInt16 nWhichId, const SfxItemSet& rInItemSet )
100 throw( uno::Exception )
102 bool bChanged = false;
104 switch( nWhichId )
106 case SCHATTR_LEGEND_SHOW:
108 const SfxPoolItem* pPoolItem = NULL;
109 if( rInItemSet.GetItemState( SCHATTR_LEGEND_SHOW, true, &pPoolItem ) == SfxItemState::SET )
111 bool bShow = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
112 bool bWasShown = true;
113 if( ! (GetPropertySet()->getPropertyValue( "Show" ) >>= bWasShown) ||
114 ( bWasShown != bShow ))
116 GetPropertySet()->setPropertyValue( "Show" , uno::makeAny( bShow ));
117 bChanged = true;
122 break;
123 case SCHATTR_LEGEND_POS:
125 const SfxPoolItem* pPoolItem = NULL;
126 if( rInItemSet.GetItemState( SCHATTR_LEGEND_POS, true, &pPoolItem ) == SfxItemState::SET )
128 chart2::LegendPosition eNewPos = static_cast<chart2::LegendPosition>(static_cast<const SfxInt32Item*>(pPoolItem)->GetValue());
130 ::com::sun::star::chart::ChartLegendExpansion eExpansion = ::com::sun::star::chart::ChartLegendExpansion_HIGH;
131 switch( eNewPos )
133 case chart2::LegendPosition_LINE_START:
134 case chart2::LegendPosition_LINE_END:
135 eExpansion = ::com::sun::star::chart::ChartLegendExpansion_HIGH;
136 break;
137 case chart2::LegendPosition_PAGE_START:
138 case chart2::LegendPosition_PAGE_END:
139 eExpansion = ::com::sun::star::chart::ChartLegendExpansion_WIDE;
140 break;
141 default:
142 break;
147 chart2::LegendPosition eOldPos;
148 if( ! ( GetPropertySet()->getPropertyValue( "AnchorPosition" ) >>= eOldPos ) ||
149 ( eOldPos != eNewPos ))
151 GetPropertySet()->setPropertyValue( "AnchorPosition" , uno::makeAny( eNewPos ));
152 GetPropertySet()->setPropertyValue( "Expansion" , uno::makeAny( eExpansion ));
153 GetPropertySet()->setPropertyValue( "RelativePosition" , uno::Any());
154 bChanged = true;
157 catch( const uno::Exception & ex )
159 ASSERT_EXCEPTION( ex );
163 break;
166 return bChanged;
169 void LegendItemConverter::FillSpecialItem(
170 sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
171 throw( uno::Exception )
173 switch( nWhichId )
175 case SCHATTR_LEGEND_SHOW:
177 bool bShow = true;
178 GetPropertySet()->getPropertyValue( "Show" ) >>= bShow;
179 rOutItemSet.Put( SfxBoolItem(SCHATTR_LEGEND_SHOW, bShow) );
181 break;
182 case SCHATTR_LEGEND_POS:
184 chart2::LegendPosition eLegendPos( chart2::LegendPosition_LINE_END );
185 GetPropertySet()->getPropertyValue( "AnchorPosition" ) >>= eLegendPos;
186 rOutItemSet.Put( SfxInt32Item(SCHATTR_LEGEND_POS, eLegendPos ) );
188 break;
192 } // namespace wrapper
193 } // namespace chart
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */