LCOV - code coverage report
Current view: top level - oox/source/drawingml - shapepropertymap.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 68 0.0 %
Date: 2014-04-14 Functions: 0 13 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "oox/drawingml/shapepropertymap.hxx"
      21             : 
      22             : #include <com/sun/star/awt/Gradient.hpp>
      23             : #include <com/sun/star/beans/NamedValue.hpp>
      24             : #include <com/sun/star/drawing/LineDash.hpp>
      25             : #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
      26             : #include "oox/helper/modelobjecthelper.hxx"
      27             : 
      28             : namespace oox {
      29             : namespace drawingml {
      30             : 
      31             : 
      32             : 
      33             : using namespace ::com::sun::star;
      34             : using namespace ::com::sun::star::beans;
      35             : using namespace ::com::sun::star::drawing;
      36             : using namespace ::com::sun::star::uno;
      37             : 
      38             : 
      39             : 
      40             : namespace {
      41             : 
      42             : static const sal_Int32 spnDefaultShapeIds[ SHAPEPROP_END + 1 ] = // one for the PROP_END_LIST
      43             : {
      44             :     PROP_LineStyle, PROP_LineWidth, PROP_LineColor, PROP_LineTransparence, PROP_LineDash, PROP_LineJoint,
      45             :     PROP_LineStartName, PROP_LineStartWidth, PROP_LineStartCenter, PROP_LineEndName, PROP_LineEndWidth, PROP_LineEndCenter,
      46             :     PROP_FillStyle, PROP_FillColor, PROP_FillTransparence, PROP_FillTransparenceGradientName, PROP_FillGradient,
      47             :     PROP_FillBitmapURL, PROP_FillBitmapMode, PROP_FillBitmapSizeX, PROP_FillBitmapSizeY,
      48             :     PROP_FillBitmapPositionOffsetX, PROP_FillBitmapPositionOffsetY, PROP_FillBitmapRectanglePoint,
      49             :     PROP_FillHatch,
      50             :     PROP_ShadowXDistance,
      51             :     PROP_FillBitmapName,
      52             :     PROP_END_LIST
      53             : };
      54             : 
      55             : } // namespace
      56             : 
      57           0 : ShapePropertyInfo ShapePropertyInfo::DEFAULT( spnDefaultShapeIds, true, false, false, false );
      58             : 
      59           0 : ShapePropertyInfo::ShapePropertyInfo( const sal_Int32* pnPropertyIds,
      60             :         bool bNamedLineMarker, bool bNamedLineDash, bool bNamedFillGradient, bool bNamedFillBitmapUrl ) :
      61             :     mbNamedLineMarker( bNamedLineMarker ),
      62             :     mbNamedLineDash( bNamedLineDash ),
      63             :     mbNamedFillGradient( bNamedFillGradient ),
      64           0 :     mbNamedFillBitmapUrl( bNamedFillBitmapUrl )
      65             : {
      66             :     assert(pnPropertyIds);
      67             :     // normally we should not reach PROP_COUNT but it prevents infinite loops if we hit a bug
      68           0 :     for(size_t i = 0; i < static_cast<size_t>(PROP_COUNT); ++i)
      69             :     {
      70           0 :         if(pnPropertyIds[i] == PROP_END_LIST)
      71           0 :             break;
      72             : 
      73           0 :         maPropertyIds.push_back(pnPropertyIds[i]);
      74             :     }
      75           0 : }
      76             : 
      77             : 
      78             : 
      79           0 : ShapePropertyMap::ShapePropertyMap( ModelObjectHelper& rModelObjHelper, const ShapePropertyInfo& rShapePropInfo ) :
      80             :     mrModelObjHelper( rModelObjHelper ),
      81           0 :     maShapePropInfo( rShapePropInfo )
      82             : {
      83           0 : }
      84             : 
      85           0 : bool ShapePropertyMap::supportsProperty( ShapePropertyId ePropId ) const
      86             : {
      87           0 :     return maShapePropInfo.has( ePropId );
      88             : }
      89             : 
      90           0 : bool ShapePropertyMap::hasNamedLineMarkerInTable( const OUString& rMarkerName ) const
      91             : {
      92           0 :     return maShapePropInfo.mbNamedLineMarker && mrModelObjHelper.hasLineMarker( rMarkerName );
      93             : }
      94             : 
      95           0 : bool ShapePropertyMap::setAnyProperty( ShapePropertyId ePropId, const Any& rValue )
      96             : {
      97             :     // get current property identifier for the specified property
      98           0 :     sal_Int32 nPropId = maShapePropInfo[ ePropId ];
      99           0 :     if( nPropId < 0 ) return false;
     100             : 
     101             :     // special handling for properties supporting named objects in tables
     102           0 :     switch( ePropId )
     103             :     {
     104             :         case SHAPEPROP_LineStart:
     105             :         case SHAPEPROP_LineEnd:
     106           0 :             return setLineMarker( nPropId, rValue );
     107             : 
     108             :         case SHAPEPROP_LineDash:
     109           0 :             return setLineDash( nPropId, rValue );
     110             : 
     111             :         case SHAPEPROP_FillGradient:
     112           0 :             return setFillGradient( nPropId, rValue );
     113             : 
     114             :         case SHAPEPROP_GradientTransparency:
     115           0 :             return setGradientTrans( nPropId, rValue );
     116             : 
     117             :         case SHAPEPROP_FillBitmapUrl:
     118           0 :             return setFillBitmapUrl( nPropId, rValue );
     119             : 
     120             :         case SHAPEPROP_FillBitmapNameFromUrl:
     121           0 :             return setFillBitmapNameFromUrl( nPropId, rValue );
     122             : 
     123             :         default:;   // suppress compiler warnings
     124             :     }
     125             : 
     126             :     // set plain property value
     127           0 :     setAnyProperty( nPropId, rValue );
     128           0 :     return true;
     129             : }
     130             : 
     131             : // private --------------------------------------------------------------------
     132             : 
     133           0 : bool ShapePropertyMap::setLineMarker( sal_Int32 nPropId, const Any& rValue )
     134             : {
     135           0 :     NamedValue aNamedMarker;
     136           0 :     if( (rValue >>= aNamedMarker) && !aNamedMarker.Name.isEmpty() )
     137             :     {
     138             :         // push line marker explicitly
     139           0 :         if( !maShapePropInfo.mbNamedLineMarker )
     140           0 :             return setAnyProperty( nPropId, aNamedMarker.Value );
     141             : 
     142             :         // create named line marker (if coordinates have been passed) and push its name
     143           0 :         bool bInserted = !aNamedMarker.Value.has< PolyPolygonBezierCoords >() ||
     144           0 :             mrModelObjHelper.insertLineMarker( aNamedMarker.Name, aNamedMarker.Value.get< PolyPolygonBezierCoords >() );
     145           0 :         return bInserted && setProperty( nPropId, aNamedMarker.Name );
     146             :     }
     147           0 :     return false;
     148             : }
     149             : 
     150           0 : bool ShapePropertyMap::setLineDash( sal_Int32 nPropId, const Any& rValue )
     151             : {
     152             :     // push line dash explicitly
     153           0 :     if( !maShapePropInfo.mbNamedLineDash )
     154           0 :         return setAnyProperty( nPropId, rValue );
     155             : 
     156             :     // create named line dash and push its name
     157           0 :     if( rValue.has< LineDash >() )
     158             :     {
     159           0 :         OUString aDashName = mrModelObjHelper.insertLineDash( rValue.get< LineDash >() );
     160           0 :         return !aDashName.isEmpty() && setProperty( nPropId, aDashName );
     161             :     }
     162             : 
     163           0 :     return false;
     164             : }
     165             : 
     166           0 : bool ShapePropertyMap::setFillGradient( sal_Int32 nPropId, const Any& rValue )
     167             : {
     168             :     // push gradient explicitly
     169           0 :     if( !maShapePropInfo.mbNamedFillGradient )
     170           0 :         return setAnyProperty( nPropId, rValue );
     171             : 
     172             :     // create named gradient and push its name
     173           0 :     if( rValue.has< awt::Gradient >() )
     174             :     {
     175           0 :         OUString aGradientName = mrModelObjHelper.insertFillGradient( rValue.get< awt::Gradient >() );
     176           0 :         return !aGradientName.isEmpty() && setProperty( nPropId, aGradientName );
     177             :     }
     178             : 
     179           0 :     return false;
     180             : }
     181             : 
     182           0 : bool ShapePropertyMap::setGradientTrans( sal_Int32 nPropId, const Any& rValue )
     183             : {
     184             :     // create named gradient and push its name
     185           0 :     if( rValue.has< awt::Gradient >() )
     186             :     {
     187           0 :         OUString aGradientName = mrModelObjHelper.insertTransGrandient( rValue.get< awt::Gradient >() );
     188           0 :         return !aGradientName.isEmpty()  && setProperty( nPropId, aGradientName );
     189             :     }
     190             : 
     191           0 :     return false;
     192             : }
     193             : 
     194           0 : bool ShapePropertyMap::setFillBitmapUrl( sal_Int32 nPropId, const Any& rValue )
     195             : {
     196             :     // push bitmap URL explicitly
     197           0 :     if( !maShapePropInfo.mbNamedFillBitmapUrl )
     198           0 :         return setAnyProperty( nPropId, rValue );
     199             : 
     200             :     // create named bitmap URL and push its name
     201           0 :     if( rValue.has< OUString >() )
     202             :     {
     203           0 :         OUString aBitmapUrlName = mrModelObjHelper.insertFillBitmapUrl( rValue.get< OUString >() );
     204           0 :         return !aBitmapUrlName.isEmpty() && setProperty( nPropId, aBitmapUrlName );
     205             :     }
     206             : 
     207           0 :     return false;
     208             : }
     209             : 
     210           0 : bool ShapePropertyMap::setFillBitmapNameFromUrl( sal_Int32 /*nPropId*/, const Any& rValue )
     211             : {
     212           0 :     if( rValue.has< OUString >() )
     213             :     {
     214           0 :         OUString aBitmapUrlName = mrModelObjHelper.insertFillBitmapUrl( rValue.get< OUString >() );
     215           0 :         return !aBitmapUrlName.isEmpty() && setProperty( PROP_FillBitmapName, aBitmapUrlName );
     216             :     }
     217           0 :     return false;
     218             : }
     219             : 
     220             : 
     221             : 
     222             : } // namespace drawingml
     223           0 : } // namespace oox
     224             : 
     225             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10