1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "oox/drawingml/shapepropertymap.hxx" 29 30 #include <com/sun/star/awt/Gradient.hpp> 31 #include <com/sun/star/beans/NamedValue.hpp> 32 #include <com/sun/star/drawing/LineDash.hpp> 33 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp> 34 #include "oox/helper/modelobjecthelper.hxx" 35 36 namespace oox { 37 namespace drawingml { 38 39 // ============================================================================ 40 41 using namespace ::com::sun::star::awt; 42 using namespace ::com::sun::star::beans; 43 using namespace ::com::sun::star::drawing; 44 using namespace ::com::sun::star::uno; 45 46 using ::rtl::OUString; 47 48 // ============================================================================ 49 50 namespace { 51 52 static const sal_Int32 spnDefaultShapeIds[ SHAPEPROP_END ] = 53 { 54 PROP_LineStyle, PROP_LineWidth, PROP_LineColor, PROP_LineTransparence, PROP_LineDash, PROP_LineJoint, 55 PROP_LineStartName, PROP_LineStartWidth, PROP_LineStartCenter, PROP_LineEndName, PROP_LineEndWidth, PROP_LineEndCenter, 56 PROP_FillStyle, PROP_FillColor, PROP_FillTransparence, PROP_FillGradient, 57 PROP_FillBitmapURL, PROP_FillBitmapMode, PROP_FillBitmapSizeX, PROP_FillBitmapSizeY, 58 PROP_FillBitmapPositionOffsetX, PROP_FillBitmapPositionOffsetY, PROP_FillBitmapRectanglePoint 59 }; 60 61 } // namespace 62 63 ShapePropertyInfo ShapePropertyInfo::DEFAULT( spnDefaultShapeIds, true, false, false, false ); 64 65 ShapePropertyInfo::ShapePropertyInfo( const sal_Int32* pnPropertyIds, 66 bool bNamedLineMarker, bool bNamedLineDash, bool bNamedFillGradient, bool bNamedFillBitmapUrl ) : 67 mpnPropertyIds( pnPropertyIds ), 68 mbNamedLineMarker( bNamedLineMarker ), 69 mbNamedLineDash( bNamedLineDash ), 70 mbNamedFillGradient( bNamedFillGradient ), 71 mbNamedFillBitmapUrl( bNamedFillBitmapUrl ) 72 { 73 OSL_ENSURE( mpnPropertyIds != 0, "ShapePropertyInfo::ShapePropertyInfo - missing property identifiers" ); 74 } 75 76 // ============================================================================ 77 78 ShapePropertyMap::ShapePropertyMap( ModelObjectHelper& rModelObjHelper, const ShapePropertyInfo& rShapePropInfo ) : 79 mrModelObjHelper( rModelObjHelper ), 80 maShapePropInfo( rShapePropInfo ) 81 { 82 } 83 84 bool ShapePropertyMap::supportsProperty( ShapePropertyId ePropId ) const 85 { 86 return maShapePropInfo.has( ePropId ); 87 } 88 89 bool ShapePropertyMap::hasNamedLineMarkerInTable( const OUString& rMarkerName ) const 90 { 91 return maShapePropInfo.mbNamedLineMarker && mrModelObjHelper.hasLineMarker( rMarkerName ); 92 } 93 94 bool ShapePropertyMap::setAnyProperty( ShapePropertyId ePropId, const Any& rValue ) 95 { 96 // get current property identifier for the specified property 97 sal_Int32 nPropId = maShapePropInfo[ ePropId ]; 98 if( nPropId < 0 ) return false; 99 100 // special handling for properties supporting named objects in tables 101 switch( ePropId ) 102 { 103 case SHAPEPROP_LineStart: 104 case SHAPEPROP_LineEnd: 105 return setLineMarker( nPropId, rValue ); 106 107 case SHAPEPROP_LineDash: 108 return setLineDash( nPropId, rValue ); 109 110 case SHAPEPROP_FillGradient: 111 return setFillGradient( nPropId, rValue ); 112 113 case SHAPEPROP_FillBitmapUrl: 114 return setFillBitmapUrl( nPropId, rValue ); 115 116 default:; // suppress compiler warnings 117 } 118 119 // set plain property value 120 operator[]( nPropId ) = rValue; 121 return true; 122 } 123 124 // private -------------------------------------------------------------------- 125 126 bool ShapePropertyMap::setLineMarker( sal_Int32 nPropId, const Any& rValue ) 127 { 128 NamedValue aNamedMarker; 129 if( (rValue >>= aNamedMarker) && (aNamedMarker.Name.getLength() > 0) ) 130 { 131 // push line marker explicitly 132 if( !maShapePropInfo.mbNamedLineMarker ) 133 return setAnyProperty( nPropId, aNamedMarker.Value ); 134 135 // create named line marker (if coordinates have been passed) and push its name 136 bool bInserted = !aNamedMarker.Value.has< PolyPolygonBezierCoords >() || 137 mrModelObjHelper.insertLineMarker( aNamedMarker.Name, aNamedMarker.Value.get< PolyPolygonBezierCoords >() ); 138 return bInserted && setProperty( nPropId, aNamedMarker.Name ); 139 } 140 return false; 141 } 142 143 bool ShapePropertyMap::setLineDash( sal_Int32 nPropId, const Any& rValue ) 144 { 145 // push line dash explicitly 146 if( !maShapePropInfo.mbNamedLineDash ) 147 return setAnyProperty( nPropId, rValue ); 148 149 // create named line dash and push its name 150 if( rValue.has< LineDash >() ) 151 { 152 OUString aDashName = mrModelObjHelper.insertLineDash( rValue.get< LineDash >() ); 153 return (aDashName.getLength() > 0) && setProperty( nPropId, aDashName ); 154 } 155 156 return false; 157 } 158 159 bool ShapePropertyMap::setFillGradient( sal_Int32 nPropId, const Any& rValue ) 160 { 161 // push gradient explicitly 162 if( !maShapePropInfo.mbNamedFillGradient ) 163 return setAnyProperty( nPropId, rValue ); 164 165 // create named gradient and push its name 166 if( rValue.has< Gradient >() ) 167 { 168 OUString aGradientName = mrModelObjHelper.insertFillGradient( rValue.get< Gradient >() ); 169 return (aGradientName.getLength() > 0) && setProperty( nPropId, aGradientName ); 170 } 171 172 return false; 173 } 174 175 bool ShapePropertyMap::setFillBitmapUrl( sal_Int32 nPropId, const Any& rValue ) 176 { 177 // push bitmap URL explicitly 178 if( !maShapePropInfo.mbNamedFillBitmapUrl ) 179 return setAnyProperty( nPropId, rValue ); 180 181 // create named bitmap URL and push its name 182 if( rValue.has< OUString >() ) 183 { 184 OUString aBitmapUrlName = mrModelObjHelper.insertFillBitmapUrl( rValue.get< OUString >() ); 185 return (aBitmapUrlName.getLength() > 0) && setProperty( nPropId, aBitmapUrlName ); 186 } 187 188 return false; 189 } 190 191 // ============================================================================ 192 193 } // namespace drawingml 194 } // namespace oox 195