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 #include "oox/drawingml/shapepropertymap.hxx" 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include <com/sun/star/awt/Gradient.hpp> 31*cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/drawing/LineDash.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp> 34*cdf0e10cSrcweir #include "oox/helper/modelobjecthelper.hxx" 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir namespace oox { 37*cdf0e10cSrcweir namespace drawingml { 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir // ============================================================================ 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir using namespace ::com::sun::star::awt; 42*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 43*cdf0e10cSrcweir using namespace ::com::sun::star::drawing; 44*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir using ::rtl::OUString; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir // ============================================================================ 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir namespace { 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir static const sal_Int32 spnDefaultShapeIds[ SHAPEPROP_END ] = 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir PROP_LineStyle, PROP_LineWidth, PROP_LineColor, PROP_LineTransparence, PROP_LineDash, PROP_LineJoint, 55*cdf0e10cSrcweir PROP_LineStartName, PROP_LineStartWidth, PROP_LineStartCenter, PROP_LineEndName, PROP_LineEndWidth, PROP_LineEndCenter, 56*cdf0e10cSrcweir PROP_FillStyle, PROP_FillColor, PROP_FillTransparence, PROP_FillGradient, 57*cdf0e10cSrcweir PROP_FillBitmapURL, PROP_FillBitmapMode, PROP_FillBitmapSizeX, PROP_FillBitmapSizeY, 58*cdf0e10cSrcweir PROP_FillBitmapPositionOffsetX, PROP_FillBitmapPositionOffsetY, PROP_FillBitmapRectanglePoint 59*cdf0e10cSrcweir }; 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir } // namespace 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir ShapePropertyInfo ShapePropertyInfo::DEFAULT( spnDefaultShapeIds, true, false, false, false ); 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir ShapePropertyInfo::ShapePropertyInfo( const sal_Int32* pnPropertyIds, 66*cdf0e10cSrcweir bool bNamedLineMarker, bool bNamedLineDash, bool bNamedFillGradient, bool bNamedFillBitmapUrl ) : 67*cdf0e10cSrcweir mpnPropertyIds( pnPropertyIds ), 68*cdf0e10cSrcweir mbNamedLineMarker( bNamedLineMarker ), 69*cdf0e10cSrcweir mbNamedLineDash( bNamedLineDash ), 70*cdf0e10cSrcweir mbNamedFillGradient( bNamedFillGradient ), 71*cdf0e10cSrcweir mbNamedFillBitmapUrl( bNamedFillBitmapUrl ) 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir OSL_ENSURE( mpnPropertyIds != 0, "ShapePropertyInfo::ShapePropertyInfo - missing property identifiers" ); 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir // ============================================================================ 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir ShapePropertyMap::ShapePropertyMap( ModelObjectHelper& rModelObjHelper, const ShapePropertyInfo& rShapePropInfo ) : 79*cdf0e10cSrcweir mrModelObjHelper( rModelObjHelper ), 80*cdf0e10cSrcweir maShapePropInfo( rShapePropInfo ) 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir bool ShapePropertyMap::supportsProperty( ShapePropertyId ePropId ) const 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir return maShapePropInfo.has( ePropId ); 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir bool ShapePropertyMap::hasNamedLineMarkerInTable( const OUString& rMarkerName ) const 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir return maShapePropInfo.mbNamedLineMarker && mrModelObjHelper.hasLineMarker( rMarkerName ); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir bool ShapePropertyMap::setAnyProperty( ShapePropertyId ePropId, const Any& rValue ) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir // get current property identifier for the specified property 97*cdf0e10cSrcweir sal_Int32 nPropId = maShapePropInfo[ ePropId ]; 98*cdf0e10cSrcweir if( nPropId < 0 ) return false; 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir // special handling for properties supporting named objects in tables 101*cdf0e10cSrcweir switch( ePropId ) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir case SHAPEPROP_LineStart: 104*cdf0e10cSrcweir case SHAPEPROP_LineEnd: 105*cdf0e10cSrcweir return setLineMarker( nPropId, rValue ); 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir case SHAPEPROP_LineDash: 108*cdf0e10cSrcweir return setLineDash( nPropId, rValue ); 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir case SHAPEPROP_FillGradient: 111*cdf0e10cSrcweir return setFillGradient( nPropId, rValue ); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir case SHAPEPROP_FillBitmapUrl: 114*cdf0e10cSrcweir return setFillBitmapUrl( nPropId, rValue ); 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir default:; // suppress compiler warnings 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir // set plain property value 120*cdf0e10cSrcweir operator[]( nPropId ) = rValue; 121*cdf0e10cSrcweir return true; 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir // private -------------------------------------------------------------------- 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir bool ShapePropertyMap::setLineMarker( sal_Int32 nPropId, const Any& rValue ) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir NamedValue aNamedMarker; 129*cdf0e10cSrcweir if( (rValue >>= aNamedMarker) && (aNamedMarker.Name.getLength() > 0) ) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir // push line marker explicitly 132*cdf0e10cSrcweir if( !maShapePropInfo.mbNamedLineMarker ) 133*cdf0e10cSrcweir return setAnyProperty( nPropId, aNamedMarker.Value ); 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir // create named line marker (if coordinates have been passed) and push its name 136*cdf0e10cSrcweir bool bInserted = !aNamedMarker.Value.has< PolyPolygonBezierCoords >() || 137*cdf0e10cSrcweir mrModelObjHelper.insertLineMarker( aNamedMarker.Name, aNamedMarker.Value.get< PolyPolygonBezierCoords >() ); 138*cdf0e10cSrcweir return bInserted && setProperty( nPropId, aNamedMarker.Name ); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir return false; 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir bool ShapePropertyMap::setLineDash( sal_Int32 nPropId, const Any& rValue ) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir // push line dash explicitly 146*cdf0e10cSrcweir if( !maShapePropInfo.mbNamedLineDash ) 147*cdf0e10cSrcweir return setAnyProperty( nPropId, rValue ); 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir // create named line dash and push its name 150*cdf0e10cSrcweir if( rValue.has< LineDash >() ) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir OUString aDashName = mrModelObjHelper.insertLineDash( rValue.get< LineDash >() ); 153*cdf0e10cSrcweir return (aDashName.getLength() > 0) && setProperty( nPropId, aDashName ); 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir return false; 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir bool ShapePropertyMap::setFillGradient( sal_Int32 nPropId, const Any& rValue ) 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir // push gradient explicitly 162*cdf0e10cSrcweir if( !maShapePropInfo.mbNamedFillGradient ) 163*cdf0e10cSrcweir return setAnyProperty( nPropId, rValue ); 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir // create named gradient and push its name 166*cdf0e10cSrcweir if( rValue.has< Gradient >() ) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir OUString aGradientName = mrModelObjHelper.insertFillGradient( rValue.get< Gradient >() ); 169*cdf0e10cSrcweir return (aGradientName.getLength() > 0) && setProperty( nPropId, aGradientName ); 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir return false; 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir bool ShapePropertyMap::setFillBitmapUrl( sal_Int32 nPropId, const Any& rValue ) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir // push bitmap URL explicitly 178*cdf0e10cSrcweir if( !maShapePropInfo.mbNamedFillBitmapUrl ) 179*cdf0e10cSrcweir return setAnyProperty( nPropId, rValue ); 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir // create named bitmap URL and push its name 182*cdf0e10cSrcweir if( rValue.has< OUString >() ) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir OUString aBitmapUrlName = mrModelObjHelper.insertFillBitmapUrl( rValue.get< OUString >() ); 185*cdf0e10cSrcweir return (aBitmapUrlName.getLength() > 0) && setProperty( nPropId, aBitmapUrlName ); 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir return false; 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir // ============================================================================ 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir } // namespace drawingml 194*cdf0e10cSrcweir } // namespace oox 195