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: customshapeproperties.cxx,v $
10 * $Revision: 1.6.4.1 $
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 #include "oox/drawingml/customshapeproperties.hxx"
32 #include "oox/helper/helper.hxx"
33 #include "oox/helper/propertymap.hxx"
34 #include "oox/helper/propertyset.hxx"
35 #include "oox/core/namespaces.hxx"
36 #include "properties.hxx"
38 #include <com/sun/star/beans/XMultiPropertySet.hpp>
39 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40 #include <com/sun/star/graphic/XGraphicTransformer.hpp>
41 #include <com/sun/star/drawing/XShape.hpp>
42 #include <com/sun/star/drawing/XEnhancedCustomShapeDefaulter.hpp>
45 using namespace ::oox::core
;
46 using namespace ::com::sun::star
;
47 using namespace ::com::sun::star::uno
;
48 using namespace ::com::sun::star::beans
;
49 using namespace ::com::sun::star::graphic
;
50 using namespace ::com::sun::star::drawing
;
52 namespace oox
{ namespace drawingml
{
54 CustomShapeProperties::CustomShapeProperties()
57 CustomShapeProperties::~CustomShapeProperties()
61 void CustomShapeProperties::apply( const CustomShapePropertiesPtr
& /* rSourceCustomShapeProperties */ )
63 // not sure if this needs to be implemented
66 void CustomShapeProperties::pushToPropSet( const ::oox::core::XmlFilterBase
& /* rFilterBase */,
67 const Reference
< XPropertySet
>& xPropSet
, const Reference
< XShape
> & xShape
) const
69 if ( maShapePresetType
.getLength() )
71 //const uno::Reference < drawing::XShape > xShape( xPropSet, UNO_QUERY );
72 Reference
< drawing::XEnhancedCustomShapeDefaulter
> xDefaulter( xShape
, UNO_QUERY
);
74 xDefaulter
->createCustomShapeDefaults( maShapePresetType
);
76 const OUString sType
= CREATE_OUSTRING( "Type" );
77 const OUString
sCustomShapeGeometry( RTL_CONSTASCII_USTRINGPARAM( "CustomShapeGeometry" ) );
78 uno::Any aGeoPropSet
= xPropSet
->getPropertyValue( sCustomShapeGeometry
);
79 uno::Sequence
< beans::PropertyValue
> aGeoPropSeq
;
80 if ( aGeoPropSet
>>= aGeoPropSeq
)
82 sal_Int32 i
, nCount
= aGeoPropSeq
.getLength();
83 for ( i
= 0; i
< nCount
; i
++ )
85 const rtl::OUString
sAdjustmentValues( RTL_CONSTASCII_USTRINGPARAM( "AdjustmentValues" ) );
86 if ( aGeoPropSeq
[ i
].Name
.equals( sAdjustmentValues
) )
88 uno::Sequence
< com::sun::star::drawing::EnhancedCustomShapeAdjustmentValue
> aAdjustmentSeq
;
89 if ( aGeoPropSeq
[ i
].Value
>>= aAdjustmentSeq
)
91 sal_uInt32 j
, nHighest
= 0;
92 for( j
= 0; j
< maAdjustmentValues
.size(); j
++ )
94 const rtl::OUString
& rS( maAdjustmentValues
[ j
].maName
);
95 if ( rS
.getLength() > 3 )
97 sal_uInt32 nVal
= rS
.copy( 3 ).toInt32();
98 if ( ( nVal
< 10 ) && ( nVal
> nHighest
) )
102 if ( nHighest
> static_cast< sal_uInt32
>( aAdjustmentSeq
.getLength() ) )
103 aAdjustmentSeq
.realloc( nHighest
);
105 for ( j
= 0; j
< maAdjustmentValues
.size(); j
++ )
107 if( maAdjustmentValues
[ j
].maName
.getLength() > 3 )
109 sal_uInt32 nVal
= maAdjustmentValues
[ j
].maName
.copy( 3 ).toInt32();
112 double fNewAdj
= getValue( maAdjustmentValues
, nVal
);
113 aAdjustmentSeq
[ nVal
].State
= beans::PropertyState_DIRECT_VALUE
;
114 aAdjustmentSeq
[ nVal
].Value
<<= fNewAdj
;
118 aGeoPropSeq
[ i
].Value
<<= aAdjustmentSeq
;
119 xPropSet
->setPropertyValue( sCustomShapeGeometry
, Any( aGeoPropSeq
) );
122 else if ( aGeoPropSeq
[ i
].Name
.equals( sType
) )
124 aGeoPropSeq
[ i
].Value
<<= maShapePresetType
;
131 PropertyMap aPropertyMap
;
132 aPropertyMap
[ PROP_Type
] <<= CREATE_OUSTRING( "non-primitive" );
134 // converting the vector to a sequence
135 Sequence
< PropertyValue
> aSeq
= aPropertyMap
.makePropertyValueSequence();
136 PropertySet
aPropSet( xPropSet
);
137 aPropSet
.setProperty( PROP_CustomShapeGeometry
, aSeq
);
141 double CustomShapeProperties::getValue( const std::vector
< CustomShapeGuide
>& rGuideList
, sal_uInt32 nIndex
) const
144 if ( nIndex
< rGuideList
.size() )