merge the formfield patch from ooo-build
[ooovba.git] / chart2 / source / controller / itemsetwrapper / LegendItemConverter.cxx
blob052893b6ac90b4972dd6b40e6c09e48e8b127308
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: LegendItemConverter.cxx,v $
10 * $Revision: 1.16 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "LegendItemConverter.hxx"
34 #include "SchWhichPairs.hxx"
35 #include "macros.hxx"
36 #include "ItemPropertyMap.hxx"
37 #include "GraphicPropertyItemConverter.hxx"
38 #include "CharacterPropertyItemConverter.hxx"
39 #include <svx/chrtitem.hxx>
40 #include <com/sun/star/chart2/XLegend.hpp>
41 #include <com/sun/star/chart2/LegendPosition.hpp>
42 #include <com/sun/star/chart2/LegendExpansion.hpp>
44 #include <functional>
45 #include <algorithm>
47 using namespace ::com::sun::star;
49 namespace chart
51 namespace wrapper
54 LegendItemConverter::LegendItemConverter(
55 const ::com::sun::star::uno::Reference<
56 ::com::sun::star::beans::XPropertySet > & rPropertySet,
57 SfxItemPool& rItemPool,
58 SdrModel& rDrawModel,
59 const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory,
60 ::std::auto_ptr< ::com::sun::star::awt::Size > pRefSize ) :
61 ItemConverter( rPropertySet, rItemPool )
63 m_aConverters.push_back( new GraphicPropertyItemConverter(
64 rPropertySet, rItemPool, rDrawModel, xNamedPropertyContainerFactory,
65 GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES ));
66 m_aConverters.push_back( new CharacterPropertyItemConverter(
67 rPropertySet, rItemPool, pRefSize,
68 C2U( "ReferencePageSize" ) ));
71 LegendItemConverter::~LegendItemConverter()
73 ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
74 ::comphelper::DeleteItemConverterPtr() );
77 void LegendItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
79 ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
80 ::comphelper::FillItemSetFunc( rOutItemSet ));
82 // own items
83 ItemConverter::FillItemSet( rOutItemSet );
86 bool LegendItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
88 bool bResult = false;
90 ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
91 ::comphelper::ApplyItemSetFunc( rItemSet, bResult ));
93 // own items
94 return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
97 const USHORT * LegendItemConverter::GetWhichPairs() const
99 // must span all used items!
100 return nLegendWhichPairs;
103 bool LegendItemConverter::GetItemProperty( tWhichIdType /*nWhichId*/, tPropertyNameWithMemberId & /*rOutProperty*/ ) const
105 // No own (non-special) properties
106 return false;
110 bool LegendItemConverter::ApplySpecialItem(
111 USHORT nWhichId, const SfxItemSet & rItemSet )
112 throw( uno::Exception )
114 bool bChanged = false;
116 switch( nWhichId )
118 case SCHATTR_LEGEND_POS:
120 chart2::LegendPosition eNewPos = chart2::LegendPosition_LINE_END;
121 chart2::LegendPosition eOldPos;
122 bool bIsWide = false;
123 sal_Bool bShow = sal_True;
125 SvxChartLegendPos eItemPos =
126 static_cast< const SvxChartLegendPosItem & >(
127 rItemSet.Get( nWhichId )).GetValue();
128 switch( eItemPos )
130 case CHLEGEND_LEFT:
131 eNewPos = chart2::LegendPosition_LINE_START;
132 break;
133 case CHLEGEND_RIGHT:
134 eNewPos = chart2::LegendPosition_LINE_END;
135 break;
136 case CHLEGEND_TOP:
137 eNewPos = chart2::LegendPosition_PAGE_START;
138 bIsWide = true;
139 break;
140 case CHLEGEND_BOTTOM:
141 eNewPos = chart2::LegendPosition_PAGE_END;
142 bIsWide = true;
143 break;
145 case CHLEGEND_NONE:
146 case CHLEGEND_NONE_LEFT:
147 case CHLEGEND_NONE_RIGHT:
148 case CHLEGEND_NONE_TOP:
149 case CHLEGEND_NONE_BOTTOM:
150 bShow = sal_False;
151 break;
156 sal_Bool bWasShown = sal_True;
157 if( ! (GetPropertySet()->getPropertyValue( C2U("Show")) >>= bWasShown) ||
158 ( bWasShown != bShow ))
160 GetPropertySet()->setPropertyValue( C2U("Show"), uno::makeAny( bShow ));
161 bChanged = true;
164 if( bShow )
166 if( ! ( GetPropertySet()->getPropertyValue( C2U( "AnchorPosition" )) >>= eOldPos ) ||
167 ( eOldPos != eNewPos ))
169 GetPropertySet()->setPropertyValue( C2U( "AnchorPosition" ), uno::makeAny( eNewPos ));
170 chart2::LegendExpansion eExp = bIsWide
171 ? chart2::LegendExpansion_WIDE
172 : chart2::LegendExpansion_HIGH;
173 GetPropertySet()->setPropertyValue( C2U( "Expansion" ), uno::makeAny( eExp ));
174 GetPropertySet()->setPropertyValue( C2U( "RelativePosition" ), uno::Any());
175 bChanged = true;
179 catch( uno::Exception & ex )
181 ASSERT_EXCEPTION( ex );
184 break;
187 return bChanged;
190 void LegendItemConverter::FillSpecialItem(
191 USHORT nWhichId, SfxItemSet & rOutItemSet ) const
192 throw( uno::Exception )
194 switch( nWhichId )
196 case SCHATTR_LEGEND_POS:
198 SvxChartLegendPos eItemPos( CHLEGEND_RIGHT );
199 chart2::LegendPosition ePos;
201 sal_Bool bShow = sal_True;
202 GetPropertySet()->getPropertyValue( C2U( "Show" )) >>= bShow;
204 if( ! bShow )
206 eItemPos = CHLEGEND_NONE;
208 else if( GetPropertySet()->getPropertyValue( C2U( "AnchorPosition" )) >>= ePos )
210 switch( ePos )
212 case chart2::LegendPosition_LINE_START:
213 eItemPos = CHLEGEND_LEFT;
214 break;
215 case chart2::LegendPosition_LINE_END:
216 eItemPos = CHLEGEND_RIGHT;
217 break;
218 case chart2::LegendPosition_PAGE_START:
219 eItemPos = CHLEGEND_TOP;
220 break;
221 case chart2::LegendPosition_PAGE_END:
222 eItemPos = CHLEGEND_BOTTOM;
223 break;
225 case chart2::LegendPosition_CUSTOM:
226 default:
227 eItemPos = CHLEGEND_RIGHT;
228 break;
232 rOutItemSet.Put( SvxChartLegendPosItem( eItemPos, SCHATTR_LEGEND_POS ) );
234 break;
238 } // namespace wrapper
239 } // namespace chart