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