Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "LegendItemConverter.hxx"
21 : #include "SchWhichPairs.hxx"
22 : #include "macros.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>
29 :
30 : #include <svl/intitem.hxx>
31 : #include <svl/eitem.hxx>
32 :
33 : #include <functional>
34 : #include <algorithm>
35 :
36 : using namespace ::com::sun::star;
37 :
38 : namespace chart
39 : {
40 : namespace wrapper
41 : {
42 :
43 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
44 0 : LegendItemConverter::LegendItemConverter(
45 : const ::com::sun::star::uno::Reference<
46 : ::com::sun::star::beans::XPropertySet > & rPropertySet,
47 : SfxItemPool& rItemPool,
48 : SdrModel& rDrawModel,
49 : const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory,
50 : ::std::auto_ptr< ::com::sun::star::awt::Size > pRefSize ) :
51 0 : ItemConverter( rPropertySet, rItemPool )
52 : {
53 : m_aConverters.push_back( new GraphicPropertyItemConverter(
54 : rPropertySet, rItemPool, rDrawModel, xNamedPropertyContainerFactory,
55 0 : GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES ));
56 : m_aConverters.push_back( new CharacterPropertyItemConverter(
57 : rPropertySet, rItemPool, pRefSize,
58 0 : "ReferencePageSize" ));
59 0 : }
60 : SAL_WNODEPRECATED_DECLARATIONS_POP
61 :
62 0 : LegendItemConverter::~LegendItemConverter()
63 : {
64 : ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
65 0 : ::comphelper::DeleteItemConverterPtr() );
66 0 : }
67 :
68 0 : void LegendItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
69 : {
70 : ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
71 0 : ::comphelper::FillItemSetFunc( rOutItemSet ));
72 :
73 : // own items
74 0 : ItemConverter::FillItemSet( rOutItemSet );
75 0 : }
76 :
77 0 : bool LegendItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
78 : {
79 0 : bool bResult = false;
80 :
81 : ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
82 0 : ::comphelper::ApplyItemSetFunc( rItemSet, bResult ));
83 :
84 : // own items
85 0 : return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
86 : }
87 :
88 0 : const sal_uInt16 * LegendItemConverter::GetWhichPairs() const
89 : {
90 : // must span all used items!
91 0 : return nLegendWhichPairs;
92 : }
93 :
94 0 : bool LegendItemConverter::GetItemProperty( tWhichIdType /*nWhichId*/, tPropertyNameWithMemberId & /*rOutProperty*/ ) const
95 : {
96 : // No own (non-special) properties
97 0 : return false;
98 : }
99 :
100 :
101 0 : bool LegendItemConverter::ApplySpecialItem( sal_uInt16 nWhichId, const SfxItemSet& rInItemSet )
102 : throw( uno::Exception )
103 : {
104 0 : bool bChanged = false;
105 :
106 0 : switch( nWhichId )
107 : {
108 : case SCHATTR_LEGEND_SHOW:
109 : {
110 0 : const SfxPoolItem* pPoolItem = NULL;
111 0 : if( rInItemSet.GetItemState( SCHATTR_LEGEND_SHOW, sal_True, &pPoolItem ) == SFX_ITEM_SET )
112 : {
113 0 : sal_Bool bShow = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
114 0 : sal_Bool bWasShown = sal_True;
115 0 : if( ! (GetPropertySet()->getPropertyValue( "Show" ) >>= bWasShown) ||
116 : ( bWasShown != bShow ))
117 : {
118 0 : GetPropertySet()->setPropertyValue( "Show" , uno::makeAny( bShow ));
119 0 : bChanged = true;
120 : }
121 : }
122 :
123 : }
124 0 : break;
125 : case SCHATTR_LEGEND_POS:
126 : {
127 0 : const SfxPoolItem* pPoolItem = NULL;
128 0 : if( rInItemSet.GetItemState( SCHATTR_LEGEND_POS, sal_True, &pPoolItem ) == SFX_ITEM_SET )
129 : {
130 0 : chart2::LegendPosition eNewPos = static_cast<chart2::LegendPosition>(((const SfxInt32Item*)pPoolItem)->GetValue());
131 :
132 0 : ::com::sun::star::chart::ChartLegendExpansion eExpansion = ::com::sun::star::chart::ChartLegendExpansion_HIGH;
133 0 : switch( eNewPos )
134 : {
135 : case chart2::LegendPosition_LINE_START:
136 : case chart2::LegendPosition_LINE_END:
137 0 : eExpansion = ::com::sun::star::chart::ChartLegendExpansion_HIGH;
138 0 : break;
139 : case chart2::LegendPosition_PAGE_START:
140 : case chart2::LegendPosition_PAGE_END:
141 0 : eExpansion = ::com::sun::star::chart::ChartLegendExpansion_WIDE;
142 0 : break;
143 : default:
144 0 : break;
145 : }
146 :
147 : try
148 : {
149 : chart2::LegendPosition eOldPos;
150 0 : if( ! ( GetPropertySet()->getPropertyValue( "AnchorPosition" ) >>= eOldPos ) ||
151 : ( eOldPos != eNewPos ))
152 : {
153 0 : GetPropertySet()->setPropertyValue( "AnchorPosition" , uno::makeAny( eNewPos ));
154 0 : GetPropertySet()->setPropertyValue( "Expansion" , uno::makeAny( eExpansion ));
155 0 : GetPropertySet()->setPropertyValue( "RelativePosition" , uno::Any());
156 0 : bChanged = true;
157 : }
158 : }
159 0 : catch( const uno::Exception & ex )
160 : {
161 : ASSERT_EXCEPTION( ex );
162 : }
163 : }
164 : }
165 0 : break;
166 : }
167 :
168 0 : return bChanged;
169 : }
170 :
171 0 : void LegendItemConverter::FillSpecialItem(
172 : sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
173 : throw( uno::Exception )
174 : {
175 0 : switch( nWhichId )
176 : {
177 : case SCHATTR_LEGEND_SHOW:
178 : {
179 0 : sal_Bool bShow = sal_True;
180 0 : GetPropertySet()->getPropertyValue( "Show" ) >>= bShow;
181 0 : rOutItemSet.Put( SfxBoolItem(SCHATTR_LEGEND_SHOW, bShow) );
182 : }
183 0 : break;
184 : case SCHATTR_LEGEND_POS:
185 : {
186 0 : chart2::LegendPosition eLegendPos( chart2::LegendPosition_LINE_END );
187 0 : GetPropertySet()->getPropertyValue( "AnchorPosition" ) >>= eLegendPos;
188 0 : rOutItemSet.Put( SfxInt32Item(SCHATTR_LEGEND_POS, eLegendPos ) );
189 : }
190 0 : break;
191 : }
192 0 : }
193 :
194 : } // namespace wrapper
195 : } // namespace chart
196 :
197 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|