1*d0626817SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*d0626817SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d0626817SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d0626817SAndrew Rist  * distributed with this work for additional information
6*d0626817SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d0626817SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d0626817SAndrew Rist  * "License"); you may not use this file except in compliance
9*d0626817SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*d0626817SAndrew Rist  *
11*d0626817SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*d0626817SAndrew Rist  *
13*d0626817SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d0626817SAndrew Rist  * software distributed under the License is distributed on an
15*d0626817SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d0626817SAndrew Rist  * KIND, either express or implied.  See the License for the
17*d0626817SAndrew Rist  * specific language governing permissions and limitations
18*d0626817SAndrew Rist  * under the License.
19*d0626817SAndrew Rist  *
20*d0626817SAndrew Rist  *************************************************************/
21*d0626817SAndrew Rist 
22*d0626817SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "oox/drawingml/shapepropertymap.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <com/sun/star/awt/Gradient.hpp>
27cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
28cdf0e10cSrcweir #include <com/sun/star/drawing/LineDash.hpp>
29cdf0e10cSrcweir #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
30cdf0e10cSrcweir #include "oox/helper/modelobjecthelper.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir namespace oox {
33cdf0e10cSrcweir namespace drawingml {
34cdf0e10cSrcweir 
35cdf0e10cSrcweir // ============================================================================
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using namespace ::com::sun::star::awt;
38cdf0e10cSrcweir using namespace ::com::sun::star::beans;
39cdf0e10cSrcweir using namespace ::com::sun::star::drawing;
40cdf0e10cSrcweir using namespace ::com::sun::star::uno;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir using ::rtl::OUString;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir // ============================================================================
45cdf0e10cSrcweir 
46cdf0e10cSrcweir namespace {
47cdf0e10cSrcweir 
48cdf0e10cSrcweir static const sal_Int32 spnDefaultShapeIds[ SHAPEPROP_END ] =
49cdf0e10cSrcweir {
50cdf0e10cSrcweir     PROP_LineStyle, PROP_LineWidth, PROP_LineColor, PROP_LineTransparence, PROP_LineDash, PROP_LineJoint,
51cdf0e10cSrcweir     PROP_LineStartName, PROP_LineStartWidth, PROP_LineStartCenter, PROP_LineEndName, PROP_LineEndWidth, PROP_LineEndCenter,
52cdf0e10cSrcweir     PROP_FillStyle, PROP_FillColor, PROP_FillTransparence, PROP_FillGradient,
53cdf0e10cSrcweir     PROP_FillBitmapURL, PROP_FillBitmapMode, PROP_FillBitmapSizeX, PROP_FillBitmapSizeY,
54cdf0e10cSrcweir     PROP_FillBitmapPositionOffsetX, PROP_FillBitmapPositionOffsetY, PROP_FillBitmapRectanglePoint
55cdf0e10cSrcweir };
56cdf0e10cSrcweir 
57cdf0e10cSrcweir } // namespace
58cdf0e10cSrcweir 
59cdf0e10cSrcweir ShapePropertyInfo ShapePropertyInfo::DEFAULT( spnDefaultShapeIds, true, false, false, false );
60cdf0e10cSrcweir 
ShapePropertyInfo(const sal_Int32 * pnPropertyIds,bool bNamedLineMarker,bool bNamedLineDash,bool bNamedFillGradient,bool bNamedFillBitmapUrl)61cdf0e10cSrcweir ShapePropertyInfo::ShapePropertyInfo( const sal_Int32* pnPropertyIds,
62cdf0e10cSrcweir         bool bNamedLineMarker, bool bNamedLineDash, bool bNamedFillGradient, bool bNamedFillBitmapUrl ) :
63cdf0e10cSrcweir     mpnPropertyIds( pnPropertyIds ),
64cdf0e10cSrcweir     mbNamedLineMarker( bNamedLineMarker ),
65cdf0e10cSrcweir     mbNamedLineDash( bNamedLineDash ),
66cdf0e10cSrcweir     mbNamedFillGradient( bNamedFillGradient ),
67cdf0e10cSrcweir     mbNamedFillBitmapUrl( bNamedFillBitmapUrl )
68cdf0e10cSrcweir {
69cdf0e10cSrcweir     OSL_ENSURE( mpnPropertyIds != 0, "ShapePropertyInfo::ShapePropertyInfo - missing property identifiers" );
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir // ============================================================================
73cdf0e10cSrcweir 
ShapePropertyMap(ModelObjectHelper & rModelObjHelper,const ShapePropertyInfo & rShapePropInfo)74cdf0e10cSrcweir ShapePropertyMap::ShapePropertyMap( ModelObjectHelper& rModelObjHelper, const ShapePropertyInfo& rShapePropInfo ) :
75cdf0e10cSrcweir     mrModelObjHelper( rModelObjHelper ),
76cdf0e10cSrcweir     maShapePropInfo( rShapePropInfo )
77cdf0e10cSrcweir {
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
supportsProperty(ShapePropertyId ePropId) const80cdf0e10cSrcweir bool ShapePropertyMap::supportsProperty( ShapePropertyId ePropId ) const
81cdf0e10cSrcweir {
82cdf0e10cSrcweir     return maShapePropInfo.has( ePropId );
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
hasNamedLineMarkerInTable(const OUString & rMarkerName) const85cdf0e10cSrcweir bool ShapePropertyMap::hasNamedLineMarkerInTable( const OUString& rMarkerName ) const
86cdf0e10cSrcweir {
87cdf0e10cSrcweir     return maShapePropInfo.mbNamedLineMarker && mrModelObjHelper.hasLineMarker( rMarkerName );
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
setAnyProperty(ShapePropertyId ePropId,const Any & rValue)90cdf0e10cSrcweir bool ShapePropertyMap::setAnyProperty( ShapePropertyId ePropId, const Any& rValue )
91cdf0e10cSrcweir {
92cdf0e10cSrcweir     // get current property identifier for the specified property
93cdf0e10cSrcweir     sal_Int32 nPropId = maShapePropInfo[ ePropId ];
94cdf0e10cSrcweir     if( nPropId < 0 ) return false;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     // special handling for properties supporting named objects in tables
97cdf0e10cSrcweir     switch( ePropId )
98cdf0e10cSrcweir     {
99cdf0e10cSrcweir         case SHAPEPROP_LineStart:
100cdf0e10cSrcweir         case SHAPEPROP_LineEnd:
101cdf0e10cSrcweir             return setLineMarker( nPropId, rValue );
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         case SHAPEPROP_LineDash:
104cdf0e10cSrcweir             return setLineDash( nPropId, rValue );
105cdf0e10cSrcweir 
106cdf0e10cSrcweir         case SHAPEPROP_FillGradient:
107cdf0e10cSrcweir             return setFillGradient( nPropId, rValue );
108cdf0e10cSrcweir 
109cdf0e10cSrcweir         case SHAPEPROP_FillBitmapUrl:
110cdf0e10cSrcweir             return setFillBitmapUrl( nPropId, rValue );
111cdf0e10cSrcweir 
112cdf0e10cSrcweir         default:;   // suppress compiler warnings
113cdf0e10cSrcweir     }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     // set plain property value
116cdf0e10cSrcweir     operator[]( nPropId ) = rValue;
117cdf0e10cSrcweir     return true;
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir // private --------------------------------------------------------------------
121cdf0e10cSrcweir 
setLineMarker(sal_Int32 nPropId,const Any & rValue)122cdf0e10cSrcweir bool ShapePropertyMap::setLineMarker( sal_Int32 nPropId, const Any& rValue )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir     NamedValue aNamedMarker;
125cdf0e10cSrcweir     if( (rValue >>= aNamedMarker) && (aNamedMarker.Name.getLength() > 0) )
126cdf0e10cSrcweir     {
127cdf0e10cSrcweir         // push line marker explicitly
128cdf0e10cSrcweir         if( !maShapePropInfo.mbNamedLineMarker )
129cdf0e10cSrcweir             return setAnyProperty( nPropId, aNamedMarker.Value );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir         // create named line marker (if coordinates have been passed) and push its name
132cdf0e10cSrcweir         bool bInserted = !aNamedMarker.Value.has< PolyPolygonBezierCoords >() ||
133cdf0e10cSrcweir             mrModelObjHelper.insertLineMarker( aNamedMarker.Name, aNamedMarker.Value.get< PolyPolygonBezierCoords >() );
134cdf0e10cSrcweir         return bInserted && setProperty( nPropId, aNamedMarker.Name );
135cdf0e10cSrcweir     }
136cdf0e10cSrcweir     return false;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir 
setLineDash(sal_Int32 nPropId,const Any & rValue)139cdf0e10cSrcweir bool ShapePropertyMap::setLineDash( sal_Int32 nPropId, const Any& rValue )
140cdf0e10cSrcweir {
141cdf0e10cSrcweir     // push line dash explicitly
142cdf0e10cSrcweir     if( !maShapePropInfo.mbNamedLineDash )
143cdf0e10cSrcweir         return setAnyProperty( nPropId, rValue );
144cdf0e10cSrcweir 
145cdf0e10cSrcweir     // create named line dash and push its name
146cdf0e10cSrcweir     if( rValue.has< LineDash >() )
147cdf0e10cSrcweir     {
148cdf0e10cSrcweir         OUString aDashName = mrModelObjHelper.insertLineDash( rValue.get< LineDash >() );
149cdf0e10cSrcweir         return (aDashName.getLength() > 0) && setProperty( nPropId, aDashName );
150cdf0e10cSrcweir     }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir     return false;
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
setFillGradient(sal_Int32 nPropId,const Any & rValue)155cdf0e10cSrcweir bool ShapePropertyMap::setFillGradient( sal_Int32 nPropId, const Any& rValue )
156cdf0e10cSrcweir {
157cdf0e10cSrcweir     // push gradient explicitly
158cdf0e10cSrcweir     if( !maShapePropInfo.mbNamedFillGradient )
159cdf0e10cSrcweir         return setAnyProperty( nPropId, rValue );
160cdf0e10cSrcweir 
161cdf0e10cSrcweir     // create named gradient and push its name
162cdf0e10cSrcweir     if( rValue.has< Gradient >() )
163cdf0e10cSrcweir     {
164cdf0e10cSrcweir         OUString aGradientName = mrModelObjHelper.insertFillGradient( rValue.get< Gradient >() );
165cdf0e10cSrcweir         return (aGradientName.getLength() > 0) && setProperty( nPropId, aGradientName );
166cdf0e10cSrcweir     }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     return false;
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
setFillBitmapUrl(sal_Int32 nPropId,const Any & rValue)171cdf0e10cSrcweir bool ShapePropertyMap::setFillBitmapUrl( sal_Int32 nPropId, const Any& rValue )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir     // push bitmap URL explicitly
174cdf0e10cSrcweir     if( !maShapePropInfo.mbNamedFillBitmapUrl )
175cdf0e10cSrcweir         return setAnyProperty( nPropId, rValue );
176cdf0e10cSrcweir 
177cdf0e10cSrcweir     // create named bitmap URL and push its name
178cdf0e10cSrcweir     if( rValue.has< OUString >() )
179cdf0e10cSrcweir     {
180cdf0e10cSrcweir         OUString aBitmapUrlName = mrModelObjHelper.insertFillBitmapUrl( rValue.get< OUString >() );
181cdf0e10cSrcweir         return (aBitmapUrlName.getLength() > 0) && setProperty( nPropId, aBitmapUrlName );
182cdf0e10cSrcweir     }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir     return false;
185cdf0e10cSrcweir }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir // ============================================================================
188cdf0e10cSrcweir 
189cdf0e10cSrcweir } // namespace drawingml
190cdf0e10cSrcweir } // namespace oox
191