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"
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>
36 #include <boost/checked_delete.hpp>
38 using namespace ::com::sun::star
;
45 LegendItemConverter::LegendItemConverter(
46 const ::com::sun::star::uno::Reference
<
47 ::com::sun::star::beans::XPropertySet
> & rPropertySet
,
48 SfxItemPool
& rItemPool
,
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
));
73 ItemConverter::FillItemSet( rOutItemSet
);
76 bool LegendItemConverter::ApplyItemSet( const SfxItemSet
& rItemSet
)
80 ::std::for_each( m_aConverters
.begin(), m_aConverters
.end(),
81 ApplyItemSetFunc( rItemSet
, bResult
));
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
99 bool LegendItemConverter::ApplySpecialItem( sal_uInt16 nWhichId
, const SfxItemSet
& rInItemSet
)
100 throw( uno::Exception
)
102 bool bChanged
= false;
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
));
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
;
133 case chart2::LegendPosition_LINE_START
:
134 case chart2::LegendPosition_LINE_END
:
135 eExpansion
= ::com::sun::star::chart::ChartLegendExpansion_HIGH
;
137 case chart2::LegendPosition_PAGE_START
:
138 case chart2::LegendPosition_PAGE_END
:
139 eExpansion
= ::com::sun::star::chart::ChartLegendExpansion_WIDE
;
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());
157 catch( const uno::Exception
& ex
)
159 ASSERT_EXCEPTION( ex
);
169 void LegendItemConverter::FillSpecialItem(
170 sal_uInt16 nWhichId
, SfxItemSet
& rOutItemSet
) const
171 throw( uno::Exception
)
175 case SCHATTR_LEGEND_SHOW
:
178 GetPropertySet()->getPropertyValue( "Show" ) >>= bShow
;
179 rOutItemSet
.Put( SfxBoolItem(SCHATTR_LEGEND_SHOW
, bShow
) );
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
) );
192 } // namespace wrapper
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */