1*cde9e8dcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*cde9e8dcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*cde9e8dcSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*cde9e8dcSAndrew Rist * distributed with this work for additional information
6*cde9e8dcSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*cde9e8dcSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*cde9e8dcSAndrew Rist * "License"); you may not use this file except in compliance
9*cde9e8dcSAndrew Rist * with the License. You may obtain a copy of the License at
10*cde9e8dcSAndrew Rist *
11*cde9e8dcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*cde9e8dcSAndrew Rist *
13*cde9e8dcSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*cde9e8dcSAndrew Rist * software distributed under the License is distributed on an
15*cde9e8dcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*cde9e8dcSAndrew Rist * KIND, either express or implied. See the License for the
17*cde9e8dcSAndrew Rist * specific language governing permissions and limitations
18*cde9e8dcSAndrew Rist * under the License.
19*cde9e8dcSAndrew Rist *
20*cde9e8dcSAndrew Rist *************************************************************/
21*cde9e8dcSAndrew Rist
22*cde9e8dcSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_chart2.hxx"
26cdf0e10cSrcweir #include "LegendItemConverter.hxx"
27cdf0e10cSrcweir #include "SchWhichPairs.hxx"
28cdf0e10cSrcweir #include "macros.hxx"
29cdf0e10cSrcweir #include "ItemPropertyMap.hxx"
30cdf0e10cSrcweir #include "GraphicPropertyItemConverter.hxx"
31cdf0e10cSrcweir #include "CharacterPropertyItemConverter.hxx"
32cdf0e10cSrcweir #include <com/sun/star/chart2/XLegend.hpp>
33cdf0e10cSrcweir #include <com/sun/star/chart2/LegendPosition.hpp>
34cdf0e10cSrcweir #include <com/sun/star/chart/ChartLegendExpansion.hpp>
35cdf0e10cSrcweir
36cdf0e10cSrcweir #include <svl/intitem.hxx>
37cdf0e10cSrcweir #include <svl/eitem.hxx>
38cdf0e10cSrcweir
39cdf0e10cSrcweir #include <functional>
40cdf0e10cSrcweir #include <algorithm>
41cdf0e10cSrcweir
42cdf0e10cSrcweir using namespace ::com::sun::star;
43cdf0e10cSrcweir
44cdf0e10cSrcweir namespace chart
45cdf0e10cSrcweir {
46cdf0e10cSrcweir namespace wrapper
47cdf0e10cSrcweir {
48cdf0e10cSrcweir
LegendItemConverter(const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertySet> & rPropertySet,SfxItemPool & rItemPool,SdrModel & rDrawModel,const uno::Reference<lang::XMultiServiceFactory> & xNamedPropertyContainerFactory,::std::auto_ptr<::com::sun::star::awt::Size> pRefSize)49cdf0e10cSrcweir LegendItemConverter::LegendItemConverter(
50cdf0e10cSrcweir const ::com::sun::star::uno::Reference<
51cdf0e10cSrcweir ::com::sun::star::beans::XPropertySet > & rPropertySet,
52cdf0e10cSrcweir SfxItemPool& rItemPool,
53cdf0e10cSrcweir SdrModel& rDrawModel,
54cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory,
55cdf0e10cSrcweir ::std::auto_ptr< ::com::sun::star::awt::Size > pRefSize ) :
56cdf0e10cSrcweir ItemConverter( rPropertySet, rItemPool )
57cdf0e10cSrcweir {
58cdf0e10cSrcweir m_aConverters.push_back( new GraphicPropertyItemConverter(
59cdf0e10cSrcweir rPropertySet, rItemPool, rDrawModel, xNamedPropertyContainerFactory,
60cdf0e10cSrcweir GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES ));
61cdf0e10cSrcweir m_aConverters.push_back( new CharacterPropertyItemConverter(
62cdf0e10cSrcweir rPropertySet, rItemPool, pRefSize,
63cdf0e10cSrcweir C2U( "ReferencePageSize" ) ));
64cdf0e10cSrcweir }
65cdf0e10cSrcweir
~LegendItemConverter()66cdf0e10cSrcweir LegendItemConverter::~LegendItemConverter()
67cdf0e10cSrcweir {
68cdf0e10cSrcweir ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
69cdf0e10cSrcweir ::comphelper::DeleteItemConverterPtr() );
70cdf0e10cSrcweir }
71cdf0e10cSrcweir
FillItemSet(SfxItemSet & rOutItemSet) const72cdf0e10cSrcweir void LegendItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
73cdf0e10cSrcweir {
74cdf0e10cSrcweir ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
75cdf0e10cSrcweir ::comphelper::FillItemSetFunc( rOutItemSet ));
76cdf0e10cSrcweir
77cdf0e10cSrcweir // own items
78cdf0e10cSrcweir ItemConverter::FillItemSet( rOutItemSet );
79cdf0e10cSrcweir }
80cdf0e10cSrcweir
ApplyItemSet(const SfxItemSet & rItemSet)81cdf0e10cSrcweir bool LegendItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
82cdf0e10cSrcweir {
83cdf0e10cSrcweir bool bResult = false;
84cdf0e10cSrcweir
85cdf0e10cSrcweir ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
86cdf0e10cSrcweir ::comphelper::ApplyItemSetFunc( rItemSet, bResult ));
87cdf0e10cSrcweir
88cdf0e10cSrcweir // own items
89cdf0e10cSrcweir return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
90cdf0e10cSrcweir }
91cdf0e10cSrcweir
GetWhichPairs() const92cdf0e10cSrcweir const sal_uInt16 * LegendItemConverter::GetWhichPairs() const
93cdf0e10cSrcweir {
94cdf0e10cSrcweir // must span all used items!
95cdf0e10cSrcweir return nLegendWhichPairs;
96cdf0e10cSrcweir }
97cdf0e10cSrcweir
GetItemProperty(tWhichIdType,tPropertyNameWithMemberId &) const98cdf0e10cSrcweir bool LegendItemConverter::GetItemProperty( tWhichIdType /*nWhichId*/, tPropertyNameWithMemberId & /*rOutProperty*/ ) const
99cdf0e10cSrcweir {
100cdf0e10cSrcweir // No own (non-special) properties
101cdf0e10cSrcweir return false;
102cdf0e10cSrcweir }
103cdf0e10cSrcweir
104cdf0e10cSrcweir
ApplySpecialItem(sal_uInt16 nWhichId,const SfxItemSet & rInItemSet)105cdf0e10cSrcweir bool LegendItemConverter::ApplySpecialItem( sal_uInt16 nWhichId, const SfxItemSet& rInItemSet )
106cdf0e10cSrcweir throw( uno::Exception )
107cdf0e10cSrcweir {
108cdf0e10cSrcweir bool bChanged = false;
109cdf0e10cSrcweir
110cdf0e10cSrcweir switch( nWhichId )
111cdf0e10cSrcweir {
112cdf0e10cSrcweir case SCHATTR_LEGEND_SHOW:
113cdf0e10cSrcweir {
114cdf0e10cSrcweir const SfxPoolItem* pPoolItem = NULL;
115cdf0e10cSrcweir if( rInItemSet.GetItemState( SCHATTR_LEGEND_SHOW, sal_True, &pPoolItem ) == SFX_ITEM_SET )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir sal_Bool bShow = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
118cdf0e10cSrcweir sal_Bool bWasShown = sal_True;
119cdf0e10cSrcweir if( ! (GetPropertySet()->getPropertyValue( C2U("Show")) >>= bWasShown) ||
120cdf0e10cSrcweir ( bWasShown != bShow ))
121cdf0e10cSrcweir {
122cdf0e10cSrcweir GetPropertySet()->setPropertyValue( C2U("Show"), uno::makeAny( bShow ));
123cdf0e10cSrcweir bChanged = true;
124cdf0e10cSrcweir }
125cdf0e10cSrcweir }
126cdf0e10cSrcweir
127cdf0e10cSrcweir }
128cdf0e10cSrcweir break;
129cdf0e10cSrcweir case SCHATTR_LEGEND_POS:
130cdf0e10cSrcweir {
131cdf0e10cSrcweir const SfxPoolItem* pPoolItem = NULL;
132cdf0e10cSrcweir if( rInItemSet.GetItemState( SCHATTR_LEGEND_POS, sal_True, &pPoolItem ) == SFX_ITEM_SET )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir chart2::LegendPosition eNewPos = static_cast<chart2::LegendPosition>(((const SfxInt32Item*)pPoolItem)->GetValue());
135cdf0e10cSrcweir
136cdf0e10cSrcweir ::com::sun::star::chart::ChartLegendExpansion eExpansion = ::com::sun::star::chart::ChartLegendExpansion_HIGH;
137cdf0e10cSrcweir switch( eNewPos )
138cdf0e10cSrcweir {
139cdf0e10cSrcweir case chart2::LegendPosition_LINE_START:
140cdf0e10cSrcweir case chart2::LegendPosition_LINE_END:
141cdf0e10cSrcweir eExpansion = ::com::sun::star::chart::ChartLegendExpansion_HIGH;
142cdf0e10cSrcweir break;
143cdf0e10cSrcweir case chart2::LegendPosition_PAGE_START:
144cdf0e10cSrcweir case chart2::LegendPosition_PAGE_END:
145cdf0e10cSrcweir eExpansion = ::com::sun::star::chart::ChartLegendExpansion_WIDE;
146cdf0e10cSrcweir break;
147cdf0e10cSrcweir default:
148cdf0e10cSrcweir break;
149cdf0e10cSrcweir }
150cdf0e10cSrcweir
151cdf0e10cSrcweir try
152cdf0e10cSrcweir {
153cdf0e10cSrcweir chart2::LegendPosition eOldPos;
154cdf0e10cSrcweir if( ! ( GetPropertySet()->getPropertyValue( C2U( "AnchorPosition" )) >>= eOldPos ) ||
155cdf0e10cSrcweir ( eOldPos != eNewPos ))
156cdf0e10cSrcweir {
157cdf0e10cSrcweir GetPropertySet()->setPropertyValue( C2U( "AnchorPosition" ), uno::makeAny( eNewPos ));
158cdf0e10cSrcweir GetPropertySet()->setPropertyValue( C2U( "Expansion" ), uno::makeAny( eExpansion ));
159cdf0e10cSrcweir GetPropertySet()->setPropertyValue( C2U( "RelativePosition" ), uno::Any());
160cdf0e10cSrcweir bChanged = true;
161cdf0e10cSrcweir }
162cdf0e10cSrcweir }
163cdf0e10cSrcweir catch( uno::Exception & ex )
164cdf0e10cSrcweir {
165cdf0e10cSrcweir ASSERT_EXCEPTION( ex );
166cdf0e10cSrcweir }
167cdf0e10cSrcweir }
168cdf0e10cSrcweir }
169cdf0e10cSrcweir break;
170cdf0e10cSrcweir }
171cdf0e10cSrcweir
172cdf0e10cSrcweir return bChanged;
173cdf0e10cSrcweir }
174cdf0e10cSrcweir
FillSpecialItem(sal_uInt16 nWhichId,SfxItemSet & rOutItemSet) const175cdf0e10cSrcweir void LegendItemConverter::FillSpecialItem(
176cdf0e10cSrcweir sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
177cdf0e10cSrcweir throw( uno::Exception )
178cdf0e10cSrcweir {
179cdf0e10cSrcweir switch( nWhichId )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir case SCHATTR_LEGEND_SHOW:
182cdf0e10cSrcweir {
183cdf0e10cSrcweir sal_Bool bShow = sal_True;
184cdf0e10cSrcweir GetPropertySet()->getPropertyValue( C2U( "Show" )) >>= bShow;
185cdf0e10cSrcweir rOutItemSet.Put( SfxBoolItem(SCHATTR_LEGEND_SHOW, bShow) );
186cdf0e10cSrcweir }
187cdf0e10cSrcweir break;
188cdf0e10cSrcweir case SCHATTR_LEGEND_POS:
189cdf0e10cSrcweir {
190cdf0e10cSrcweir chart2::LegendPosition eLegendPos( chart2::LegendPosition_LINE_END );
191cdf0e10cSrcweir GetPropertySet()->getPropertyValue( C2U( "AnchorPosition" )) >>= eLegendPos;
192cdf0e10cSrcweir rOutItemSet.Put( SfxInt32Item(SCHATTR_LEGEND_POS, eLegendPos ) );
193cdf0e10cSrcweir }
194cdf0e10cSrcweir break;
195cdf0e10cSrcweir }
196cdf0e10cSrcweir }
197cdf0e10cSrcweir
198cdf0e10cSrcweir } // namespace wrapper
199cdf0e10cSrcweir } // namespace chart
200