1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: LegendItemConverter.cxx,v $
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"
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>
47 using namespace ::com::sun::star
;
54 LegendItemConverter::LegendItemConverter(
55 const ::com::sun::star::uno::Reference
<
56 ::com::sun::star::beans::XPropertySet
> & rPropertySet
,
57 SfxItemPool
& rItemPool
,
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
));
83 ItemConverter::FillItemSet( rOutItemSet
);
86 bool LegendItemConverter::ApplyItemSet( const SfxItemSet
& rItemSet
)
90 ::std::for_each( m_aConverters
.begin(), m_aConverters
.end(),
91 ::comphelper::ApplyItemSetFunc( rItemSet
, bResult
));
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
110 bool LegendItemConverter::ApplySpecialItem(
111 USHORT nWhichId
, const SfxItemSet
& rItemSet
)
112 throw( uno::Exception
)
114 bool bChanged
= false;
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();
131 eNewPos
= chart2::LegendPosition_LINE_START
;
134 eNewPos
= chart2::LegendPosition_LINE_END
;
137 eNewPos
= chart2::LegendPosition_PAGE_START
;
140 case CHLEGEND_BOTTOM
:
141 eNewPos
= chart2::LegendPosition_PAGE_END
;
146 case CHLEGEND_NONE_LEFT
:
147 case CHLEGEND_NONE_RIGHT
:
148 case CHLEGEND_NONE_TOP
:
149 case CHLEGEND_NONE_BOTTOM
:
156 sal_Bool bWasShown
= sal_True
;
157 if( ! (GetPropertySet()->getPropertyValue( C2U("Show")) >>= bWasShown
) ||
158 ( bWasShown
!= bShow
))
160 GetPropertySet()->setPropertyValue( C2U("Show"), uno::makeAny( 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());
179 catch( uno::Exception
& ex
)
181 ASSERT_EXCEPTION( ex
);
190 void LegendItemConverter::FillSpecialItem(
191 USHORT nWhichId
, SfxItemSet
& rOutItemSet
) const
192 throw( uno::Exception
)
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
;
206 eItemPos
= CHLEGEND_NONE
;
208 else if( GetPropertySet()->getPropertyValue( C2U( "AnchorPosition" )) >>= ePos
)
212 case chart2::LegendPosition_LINE_START
:
213 eItemPos
= CHLEGEND_LEFT
;
215 case chart2::LegendPosition_LINE_END
:
216 eItemPos
= CHLEGEND_RIGHT
;
218 case chart2::LegendPosition_PAGE_START
:
219 eItemPos
= CHLEGEND_TOP
;
221 case chart2::LegendPosition_PAGE_END
:
222 eItemPos
= CHLEGEND_BOTTOM
;
225 case chart2::LegendPosition_CUSTOM
:
227 eItemPos
= CHLEGEND_RIGHT
;
232 rOutItemSet
.Put( SvxChartLegendPosItem( eItemPos
, SCHATTR_LEGEND_POS
) );
238 } // namespace wrapper