1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_chart2.hxx"
30*cdf0e10cSrcweir #include "LegendWrapper.hxx"
31*cdf0e10cSrcweir #include "macros.hxx"
32*cdf0e10cSrcweir #include "Chart2ModelContact.hxx"
33*cdf0e10cSrcweir #include "LegendHelper.hxx"
34*cdf0e10cSrcweir #include "ContainerHelper.hxx"
35*cdf0e10cSrcweir #include <comphelper/InlineContainer.hxx>
36*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/chart2/XTitled.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/chart/ChartLegendPosition.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/chart2/LegendPosition.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/chart/ChartLegendExpansion.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/chart2/RelativePosition.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/drawing/FillStyle.hpp>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #include "CharacterProperties.hxx"
45*cdf0e10cSrcweir #include "LineProperties.hxx"
46*cdf0e10cSrcweir #include "FillProperties.hxx"
47*cdf0e10cSrcweir #include "UserDefinedProperties.hxx"
48*cdf0e10cSrcweir #include "WrappedCharacterHeightProperty.hxx"
49*cdf0e10cSrcweir #include "PositionAndSizeHelper.hxx"
50*cdf0e10cSrcweir #include "WrappedDirectStateProperty.hxx"
51*cdf0e10cSrcweir #include "WrappedAutomaticPositionProperties.hxx"
52*cdf0e10cSrcweir #include "WrappedScaleTextProperties.hxx"
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir #include <algorithm>
55*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir using namespace ::com::sun::star;
58*cdf0e10cSrcweir using ::com::sun::star::beans::Property;
59*cdf0e10cSrcweir using ::osl::MutexGuard;
60*cdf0e10cSrcweir using ::com::sun::star::uno::Any;
61*cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
62*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir //-----------------------------------------------------------------------------
65*cdf0e10cSrcweir //-----------------------------------------------------------------------------
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir namespace chart
68*cdf0e10cSrcweir {
69*cdf0e10cSrcweir class WrappedLegendAlignmentProperty : public WrappedProperty
70*cdf0e10cSrcweir {
71*cdf0e10cSrcweir public:
72*cdf0e10cSrcweir     WrappedLegendAlignmentProperty();
73*cdf0e10cSrcweir     virtual ~WrappedLegendAlignmentProperty();
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir     virtual void setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
76*cdf0e10cSrcweir                                     throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException);
77*cdf0e10cSrcweir     virtual Any getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const
78*cdf0e10cSrcweir                                     throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException);
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir protected:
81*cdf0e10cSrcweir     virtual Any convertInnerToOuterValue( const Any& rInnerValue ) const;
82*cdf0e10cSrcweir     virtual Any convertOuterToInnerValue( const Any& rOuterValue ) const;
83*cdf0e10cSrcweir };
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir WrappedLegendAlignmentProperty::WrappedLegendAlignmentProperty()
86*cdf0e10cSrcweir     : ::chart::WrappedProperty( C2U( "Alignment" ), C2U( "AnchorPosition" ) )
87*cdf0e10cSrcweir {
88*cdf0e10cSrcweir }
89*cdf0e10cSrcweir WrappedLegendAlignmentProperty::~WrappedLegendAlignmentProperty()
90*cdf0e10cSrcweir {
91*cdf0e10cSrcweir }
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir Any WrappedLegendAlignmentProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const
94*cdf0e10cSrcweir                         throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
95*cdf0e10cSrcweir {
96*cdf0e10cSrcweir     Any aRet;
97*cdf0e10cSrcweir     if( xInnerPropertySet.is() )
98*cdf0e10cSrcweir     {
99*cdf0e10cSrcweir         sal_Bool bShowLegend = sal_True;
100*cdf0e10cSrcweir         xInnerPropertySet->getPropertyValue( C2U( "Show" ) ) >>= bShowLegend;
101*cdf0e10cSrcweir         if(!bShowLegend)
102*cdf0e10cSrcweir         {
103*cdf0e10cSrcweir             aRet = uno::makeAny( ::com::sun::star::chart::ChartLegendPosition_NONE );
104*cdf0e10cSrcweir         }
105*cdf0e10cSrcweir         else
106*cdf0e10cSrcweir         {
107*cdf0e10cSrcweir             aRet = xInnerPropertySet->getPropertyValue( m_aInnerName );
108*cdf0e10cSrcweir             aRet = this->convertInnerToOuterValue( aRet );
109*cdf0e10cSrcweir         }
110*cdf0e10cSrcweir     }
111*cdf0e10cSrcweir     return aRet;
112*cdf0e10cSrcweir }
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir void WrappedLegendAlignmentProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
115*cdf0e10cSrcweir                 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
116*cdf0e10cSrcweir {
117*cdf0e10cSrcweir     if(xInnerPropertySet.is())
118*cdf0e10cSrcweir     {
119*cdf0e10cSrcweir         sal_Bool bNewShowLegend = sal_True;
120*cdf0e10cSrcweir         sal_Bool bOldShowLegend = sal_True;
121*cdf0e10cSrcweir         {
122*cdf0e10cSrcweir             ::com::sun::star::chart::ChartLegendPosition eOuterPos(::com::sun::star::chart::ChartLegendPosition_NONE);
123*cdf0e10cSrcweir             if( (rOuterValue >>= eOuterPos)  && eOuterPos == ::com::sun::star::chart::ChartLegendPosition_NONE )
124*cdf0e10cSrcweir                 bNewShowLegend = sal_False;
125*cdf0e10cSrcweir             xInnerPropertySet->getPropertyValue( C2U( "Show" ) ) >>= bOldShowLegend;
126*cdf0e10cSrcweir         }
127*cdf0e10cSrcweir         if(bNewShowLegend!=bOldShowLegend)
128*cdf0e10cSrcweir         {
129*cdf0e10cSrcweir             xInnerPropertySet->setPropertyValue( C2U( "Show" ), uno::makeAny(bNewShowLegend) );
130*cdf0e10cSrcweir         }
131*cdf0e10cSrcweir         if(!bNewShowLegend)
132*cdf0e10cSrcweir             return;
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir         //set corresponding LegendPosition
135*cdf0e10cSrcweir         Any aInnerValue = this->convertOuterToInnerValue( rOuterValue );
136*cdf0e10cSrcweir         xInnerPropertySet->setPropertyValue( m_aInnerName, aInnerValue );
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir         //correct LegendExpansion
139*cdf0e10cSrcweir         chart2::LegendPosition eNewInnerPos(chart2::LegendPosition_LINE_END);
140*cdf0e10cSrcweir         if( aInnerValue >>= eNewInnerPos )
141*cdf0e10cSrcweir         {
142*cdf0e10cSrcweir             ::com::sun::star::chart::ChartLegendExpansion eNewExpansion =
143*cdf0e10cSrcweir                 ( eNewInnerPos == chart2::LegendPosition_LINE_END ||
144*cdf0e10cSrcweir                   eNewInnerPos == chart2::LegendPosition_LINE_START )
145*cdf0e10cSrcweir                 ? ::com::sun::star::chart::ChartLegendExpansion_HIGH
146*cdf0e10cSrcweir                 : ::com::sun::star::chart::ChartLegendExpansion_WIDE;
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir             ::com::sun::star::chart::ChartLegendExpansion eOldExpansion( ::com::sun::star::chart::ChartLegendExpansion_HIGH );
149*cdf0e10cSrcweir             bool bExpansionWasSet(
150*cdf0e10cSrcweir                 xInnerPropertySet->getPropertyValue( C2U( "Expansion" ) ) >>= eOldExpansion );
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir             if( !bExpansionWasSet || (eOldExpansion != eNewExpansion))
153*cdf0e10cSrcweir                 xInnerPropertySet->setPropertyValue( C2U( "Expansion" ), uno::makeAny( eNewExpansion ));
154*cdf0e10cSrcweir         }
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir         //correct RelativePosition
157*cdf0e10cSrcweir         Any aRelativePosition( xInnerPropertySet->getPropertyValue( C2U( "RelativePosition" ) ) );
158*cdf0e10cSrcweir         if(aRelativePosition.hasValue())
159*cdf0e10cSrcweir         {
160*cdf0e10cSrcweir             xInnerPropertySet->setPropertyValue( C2U( "RelativePosition" ), Any() );
161*cdf0e10cSrcweir         }
162*cdf0e10cSrcweir     }
163*cdf0e10cSrcweir }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir Any WrappedLegendAlignmentProperty::convertInnerToOuterValue( const Any& rInnerValue ) const
166*cdf0e10cSrcweir {
167*cdf0e10cSrcweir     ::com::sun::star::chart::ChartLegendPosition ePos = ::com::sun::star::chart::ChartLegendPosition_NONE;
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir     chart2::LegendPosition eNewPos;
170*cdf0e10cSrcweir     if( rInnerValue >>= eNewPos )
171*cdf0e10cSrcweir     {
172*cdf0e10cSrcweir         switch( eNewPos )
173*cdf0e10cSrcweir         {
174*cdf0e10cSrcweir             case chart2::LegendPosition_LINE_START:
175*cdf0e10cSrcweir                 ePos = ::com::sun::star::chart::ChartLegendPosition_LEFT;
176*cdf0e10cSrcweir                 break;
177*cdf0e10cSrcweir             case chart2::LegendPosition_LINE_END:
178*cdf0e10cSrcweir                 ePos = ::com::sun::star::chart::ChartLegendPosition_RIGHT;
179*cdf0e10cSrcweir                 break;
180*cdf0e10cSrcweir             case chart2::LegendPosition_PAGE_START:
181*cdf0e10cSrcweir                 ePos = ::com::sun::star::chart::ChartLegendPosition_TOP;
182*cdf0e10cSrcweir                 break;
183*cdf0e10cSrcweir             case chart2::LegendPosition_PAGE_END:
184*cdf0e10cSrcweir                 ePos = ::com::sun::star::chart::ChartLegendPosition_BOTTOM;
185*cdf0e10cSrcweir                 break;
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir             default:
188*cdf0e10cSrcweir                 ePos = ::com::sun::star::chart::ChartLegendPosition_NONE;
189*cdf0e10cSrcweir                 break;
190*cdf0e10cSrcweir         }
191*cdf0e10cSrcweir     }
192*cdf0e10cSrcweir     return uno::makeAny( ePos );
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir Any WrappedLegendAlignmentProperty::convertOuterToInnerValue( const Any& rOuterValue ) const
195*cdf0e10cSrcweir {
196*cdf0e10cSrcweir     chart2::LegendPosition eNewPos = chart2::LegendPosition_LINE_END;
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir     ::com::sun::star::chart::ChartLegendPosition ePos;
199*cdf0e10cSrcweir     if( rOuterValue >>= ePos )
200*cdf0e10cSrcweir     {
201*cdf0e10cSrcweir         switch( ePos )
202*cdf0e10cSrcweir         {
203*cdf0e10cSrcweir             case ::com::sun::star::chart::ChartLegendPosition_LEFT:
204*cdf0e10cSrcweir                 eNewPos = chart2::LegendPosition_LINE_START;
205*cdf0e10cSrcweir                 break;
206*cdf0e10cSrcweir             case ::com::sun::star::chart::ChartLegendPosition_RIGHT:
207*cdf0e10cSrcweir                 eNewPos = chart2::LegendPosition_LINE_END;
208*cdf0e10cSrcweir                 break;
209*cdf0e10cSrcweir             case ::com::sun::star::chart::ChartLegendPosition_TOP:
210*cdf0e10cSrcweir                 eNewPos = chart2::LegendPosition_PAGE_START;
211*cdf0e10cSrcweir                 break;
212*cdf0e10cSrcweir             case ::com::sun::star::chart::ChartLegendPosition_BOTTOM:
213*cdf0e10cSrcweir                 eNewPos = chart2::LegendPosition_PAGE_END;
214*cdf0e10cSrcweir                 break;
215*cdf0e10cSrcweir             default: // NONE
216*cdf0e10cSrcweir                 break;
217*cdf0e10cSrcweir         }
218*cdf0e10cSrcweir     }
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir     return uno::makeAny( eNewPos );
221*cdf0e10cSrcweir }
222*cdf0e10cSrcweir }
223*cdf0e10cSrcweir //-----------------------------------------------------------------------------
224*cdf0e10cSrcweir //-----------------------------------------------------------------------------
225*cdf0e10cSrcweir //-----------------------------------------------------------------------------
226*cdf0e10cSrcweir //-----------------------------------------------------------------------------
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir namespace
229*cdf0e10cSrcweir {
230*cdf0e10cSrcweir static const ::rtl::OUString lcl_aServiceName(
231*cdf0e10cSrcweir     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart.Legend" ));
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir enum
234*cdf0e10cSrcweir {
235*cdf0e10cSrcweir     PROP_LEGEND_ALIGNMENT,
236*cdf0e10cSrcweir     PROP_LEGEND_EXPANSION
237*cdf0e10cSrcweir };
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir void lcl_AddPropertiesToVector(
240*cdf0e10cSrcweir     ::std::vector< Property > & rOutProperties )
241*cdf0e10cSrcweir {
242*cdf0e10cSrcweir     rOutProperties.push_back(
243*cdf0e10cSrcweir         Property( C2U( "Alignment" ),
244*cdf0e10cSrcweir                   PROP_LEGEND_ALIGNMENT,
245*cdf0e10cSrcweir                   ::getCppuType( reinterpret_cast< const ::com::sun::star::chart::ChartLegendPosition * >(0)),
246*cdf0e10cSrcweir                   //#i111967# no PropertyChangeEvent is fired on change so far
247*cdf0e10cSrcweir                   beans::PropertyAttribute::MAYBEDEFAULT ));
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir     rOutProperties.push_back(
250*cdf0e10cSrcweir         Property( C2U( "Expansion" ),
251*cdf0e10cSrcweir                   PROP_LEGEND_EXPANSION,
252*cdf0e10cSrcweir                   ::getCppuType( reinterpret_cast< const ::com::sun::star::chart::ChartLegendExpansion * >(0)),
253*cdf0e10cSrcweir                   //#i111967# no PropertyChangeEvent is fired on change so far
254*cdf0e10cSrcweir                   beans::PropertyAttribute::MAYBEDEFAULT ));
255*cdf0e10cSrcweir }
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir struct StaticLegendWrapperPropertyArray_Initializer
258*cdf0e10cSrcweir {
259*cdf0e10cSrcweir     Sequence< Property >* operator()()
260*cdf0e10cSrcweir     {
261*cdf0e10cSrcweir         static Sequence< Property > aPropSeq( lcl_GetPropertySequence() );
262*cdf0e10cSrcweir         return &aPropSeq;
263*cdf0e10cSrcweir     }
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir private:
266*cdf0e10cSrcweir     Sequence< Property > lcl_GetPropertySequence()
267*cdf0e10cSrcweir     {
268*cdf0e10cSrcweir         ::std::vector< ::com::sun::star::beans::Property > aProperties;
269*cdf0e10cSrcweir         lcl_AddPropertiesToVector( aProperties );
270*cdf0e10cSrcweir         ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
271*cdf0e10cSrcweir         ::chart::LineProperties::AddPropertiesToVector( aProperties );
272*cdf0e10cSrcweir         ::chart::FillProperties::AddPropertiesToVector( aProperties );
273*cdf0e10cSrcweir         //::chart::NamedProperties::AddPropertiesToVector( aProperties );
274*cdf0e10cSrcweir         ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
275*cdf0e10cSrcweir         ::chart::wrapper::WrappedAutomaticPositionProperties::addProperties( aProperties );
276*cdf0e10cSrcweir         ::chart::wrapper::WrappedScaleTextProperties::addProperties( aProperties );
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir         ::std::sort( aProperties.begin(), aProperties.end(),
279*cdf0e10cSrcweir                      ::chart::PropertyNameLess() );
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
282*cdf0e10cSrcweir     }
283*cdf0e10cSrcweir };
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir struct StaticLegendWrapperPropertyArray : public rtl::StaticAggregate< Sequence< Property >, StaticLegendWrapperPropertyArray_Initializer >
286*cdf0e10cSrcweir {
287*cdf0e10cSrcweir };
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir } // anonymous namespace
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir // --------------------------------------------------------------------------------
292*cdf0e10cSrcweir // --------------------------------------------------------------------------------
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir namespace chart
295*cdf0e10cSrcweir {
296*cdf0e10cSrcweir namespace wrapper
297*cdf0e10cSrcweir {
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir LegendWrapper::LegendWrapper( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) :
300*cdf0e10cSrcweir         m_spChart2ModelContact( spChart2ModelContact ),
301*cdf0e10cSrcweir         m_aEventListenerContainer( m_aMutex )
302*cdf0e10cSrcweir {
303*cdf0e10cSrcweir }
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir LegendWrapper::~LegendWrapper()
306*cdf0e10cSrcweir {
307*cdf0e10cSrcweir }
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir // ____ XShape ____
310*cdf0e10cSrcweir awt::Point SAL_CALL LegendWrapper::getPosition()
311*cdf0e10cSrcweir     throw (uno::RuntimeException)
312*cdf0e10cSrcweir {
313*cdf0e10cSrcweir     return m_spChart2ModelContact->GetLegendPosition();
314*cdf0e10cSrcweir }
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir void SAL_CALL LegendWrapper::setPosition( const awt::Point& aPosition )
317*cdf0e10cSrcweir     throw (uno::RuntimeException)
318*cdf0e10cSrcweir {
319*cdf0e10cSrcweir     Reference< beans::XPropertySet > xProp( this->getInnerPropertySet() );
320*cdf0e10cSrcweir     if( xProp.is() )
321*cdf0e10cSrcweir     {
322*cdf0e10cSrcweir         awt::Size aPageSize( m_spChart2ModelContact->GetPageSize() );
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir         chart2::RelativePosition aRelativePosition;
325*cdf0e10cSrcweir         aRelativePosition.Anchor = drawing::Alignment_TOP_LEFT;
326*cdf0e10cSrcweir         aRelativePosition.Primary = double(aPosition.X)/double(aPageSize.Width);
327*cdf0e10cSrcweir         aRelativePosition.Secondary = double(aPosition.Y)/double(aPageSize.Height);
328*cdf0e10cSrcweir         xProp->setPropertyValue( C2U( "RelativePosition" ), uno::makeAny(aRelativePosition) );
329*cdf0e10cSrcweir     }
330*cdf0e10cSrcweir }
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir awt::Size SAL_CALL LegendWrapper::getSize()
333*cdf0e10cSrcweir     throw (uno::RuntimeException)
334*cdf0e10cSrcweir {
335*cdf0e10cSrcweir     return m_spChart2ModelContact->GetLegendSize();
336*cdf0e10cSrcweir }
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir void SAL_CALL LegendWrapper::setSize( const awt::Size& aSize )
339*cdf0e10cSrcweir     throw (beans::PropertyVetoException,
340*cdf0e10cSrcweir            uno::RuntimeException)
341*cdf0e10cSrcweir {
342*cdf0e10cSrcweir     Reference< beans::XPropertySet > xProp( this->getInnerPropertySet() );
343*cdf0e10cSrcweir     if( xProp.is() )
344*cdf0e10cSrcweir     {
345*cdf0e10cSrcweir         awt::Size aPageSize( m_spChart2ModelContact->GetPageSize() );
346*cdf0e10cSrcweir         awt::Rectangle aPageRectangle( 0,0,aPageSize.Width,aPageSize.Height);
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir         awt::Point aPos( this->getPosition() );
349*cdf0e10cSrcweir         awt::Rectangle aNewPositionAndSize(aPos.X,aPos.Y,aSize.Width,aSize.Height);
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir         PositionAndSizeHelper::moveObject( OBJECTTYPE_LEGEND
352*cdf0e10cSrcweir                 , xProp, aNewPositionAndSize, aPageRectangle );
353*cdf0e10cSrcweir     }
354*cdf0e10cSrcweir }
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir // ____ XShapeDescriptor (base of XShape) ____
357*cdf0e10cSrcweir ::rtl::OUString SAL_CALL LegendWrapper::getShapeType()
358*cdf0e10cSrcweir     throw (uno::RuntimeException)
359*cdf0e10cSrcweir {
360*cdf0e10cSrcweir     return C2U( "com.sun.star.chart.ChartLegend" );
361*cdf0e10cSrcweir }
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir // ____ XComponent ____
364*cdf0e10cSrcweir void SAL_CALL LegendWrapper::dispose()
365*cdf0e10cSrcweir     throw (uno::RuntimeException)
366*cdf0e10cSrcweir {
367*cdf0e10cSrcweir     Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
368*cdf0e10cSrcweir     m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) );
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir     // /--
371*cdf0e10cSrcweir     MutexGuard aGuard( GetMutex());
372*cdf0e10cSrcweir     clearWrappedPropertySet();
373*cdf0e10cSrcweir     // \--
374*cdf0e10cSrcweir }
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir void SAL_CALL LegendWrapper::addEventListener(
377*cdf0e10cSrcweir     const Reference< lang::XEventListener >& xListener )
378*cdf0e10cSrcweir     throw (uno::RuntimeException)
379*cdf0e10cSrcweir {
380*cdf0e10cSrcweir 	m_aEventListenerContainer.addInterface( xListener );
381*cdf0e10cSrcweir }
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir void SAL_CALL LegendWrapper::removeEventListener(
384*cdf0e10cSrcweir     const Reference< lang::XEventListener >& aListener )
385*cdf0e10cSrcweir     throw (uno::RuntimeException)
386*cdf0e10cSrcweir {
387*cdf0e10cSrcweir 	m_aEventListenerContainer.removeInterface( aListener );
388*cdf0e10cSrcweir }
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir // ================================================================================
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir //ReferenceSizePropertyProvider
393*cdf0e10cSrcweir void LegendWrapper::updateReferenceSize()
394*cdf0e10cSrcweir {
395*cdf0e10cSrcweir     Reference< beans::XPropertySet > xProp( this->getInnerPropertySet(), uno::UNO_QUERY );
396*cdf0e10cSrcweir     if( xProp.is() )
397*cdf0e10cSrcweir     {
398*cdf0e10cSrcweir         if( xProp->getPropertyValue( C2U("ReferencePageSize") ).hasValue() )
399*cdf0e10cSrcweir             xProp->setPropertyValue( C2U("ReferencePageSize"), uno::makeAny(
400*cdf0e10cSrcweir                 m_spChart2ModelContact->GetPageSize() ));
401*cdf0e10cSrcweir     }
402*cdf0e10cSrcweir }
403*cdf0e10cSrcweir Any LegendWrapper::getReferenceSize()
404*cdf0e10cSrcweir {
405*cdf0e10cSrcweir     Any aRet;
406*cdf0e10cSrcweir     Reference< beans::XPropertySet > xProp( this->getInnerPropertySet(), uno::UNO_QUERY );
407*cdf0e10cSrcweir     if( xProp.is() )
408*cdf0e10cSrcweir         aRet = xProp->getPropertyValue( C2U("ReferencePageSize") );
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir     return aRet;
411*cdf0e10cSrcweir }
412*cdf0e10cSrcweir awt::Size LegendWrapper::getCurrentSizeForReference()
413*cdf0e10cSrcweir {
414*cdf0e10cSrcweir     return m_spChart2ModelContact->GetPageSize();
415*cdf0e10cSrcweir }
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir // ================================================================================
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir // WrappedPropertySet
420*cdf0e10cSrcweir Reference< beans::XPropertySet > LegendWrapper::getInnerPropertySet()
421*cdf0e10cSrcweir {
422*cdf0e10cSrcweir     Reference< beans::XPropertySet > xRet;
423*cdf0e10cSrcweir     Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
424*cdf0e10cSrcweir     if( xDiagram.is() )
425*cdf0e10cSrcweir         xRet.set( xDiagram->getLegend(), uno::UNO_QUERY );
426*cdf0e10cSrcweir     OSL_ENSURE(xRet.is(),"LegendWrapper::getInnerPropertySet() is NULL");
427*cdf0e10cSrcweir     return xRet;
428*cdf0e10cSrcweir }
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir const Sequence< beans::Property >& LegendWrapper::getPropertySequence()
431*cdf0e10cSrcweir {
432*cdf0e10cSrcweir     return *StaticLegendWrapperPropertyArray::get();
433*cdf0e10cSrcweir }
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir const std::vector< WrappedProperty* > LegendWrapper::createWrappedProperties()
436*cdf0e10cSrcweir {
437*cdf0e10cSrcweir     ::std::vector< ::chart::WrappedProperty* > aWrappedProperties;
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir     aWrappedProperties.push_back( new WrappedLegendAlignmentProperty() );
440*cdf0e10cSrcweir     aWrappedProperties.push_back( new WrappedProperty( C2U("Expansion"), C2U("Expansion") ));
441*cdf0e10cSrcweir     WrappedCharacterHeightProperty::addWrappedProperties( aWrappedProperties, this );
442*cdf0e10cSrcweir     //same problem as for wall: thje defaults ion the old chart are different for different charttypes, so we need to export explicitly
443*cdf0e10cSrcweir     aWrappedProperties.push_back( new WrappedDirectStateProperty( C2U("FillStyle"), C2U("FillStyle") ) );
444*cdf0e10cSrcweir     aWrappedProperties.push_back( new WrappedDirectStateProperty( C2U("FillColor"), C2U("FillColor") ));
445*cdf0e10cSrcweir     WrappedAutomaticPositionProperties::addWrappedProperties( aWrappedProperties );
446*cdf0e10cSrcweir     WrappedScaleTextProperties::addWrappedProperties( aWrappedProperties, m_spChart2ModelContact );
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir     return aWrappedProperties;
449*cdf0e10cSrcweir }
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir // ================================================================================
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir Sequence< ::rtl::OUString > LegendWrapper::getSupportedServiceNames_Static()
454*cdf0e10cSrcweir {
455*cdf0e10cSrcweir     Sequence< ::rtl::OUString > aServices( 4 );
456*cdf0e10cSrcweir     aServices[ 0 ] = C2U( "com.sun.star.chart.ChartLegend" );
457*cdf0e10cSrcweir     aServices[ 1 ] = C2U( "com.sun.star.drawing.Shape" );
458*cdf0e10cSrcweir     aServices[ 2 ] = C2U( "com.sun.star.xml.UserDefinedAttributeSupplier" );
459*cdf0e10cSrcweir     aServices[ 3 ] = C2U( "com.sun.star.style.CharacterProperties" );
460*cdf0e10cSrcweir //     aServices[ 4 ] = C2U( "com.sun.star.beans.PropertySet" );
461*cdf0e10cSrcweir //     aServices[ 5 ] = C2U( "com.sun.star.drawing.FillProperties" );
462*cdf0e10cSrcweir //     aServices[ 6 ] = C2U( "com.sun.star.drawing.LineProperties" );
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir     return aServices;
465*cdf0e10cSrcweir }
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
468*cdf0e10cSrcweir APPHELPER_XSERVICEINFO_IMPL( LegendWrapper, lcl_aServiceName );
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir } //  namespace wrapper
471*cdf0e10cSrcweir } //  namespace chart
472