LCOV - code coverage report
Current view: top level - oox/source/helper - modelobjecthelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 35 50 70.0 %
Date: 2014-11-03 Functions: 11 14 78.6 %
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/helper/modelobjecthelper.hxx"
      21             : 
      22             : #include <com/sun/star/awt/Gradient.hpp>
      23             : #include <com/sun/star/container/XNameContainer.hpp>
      24             : #include <com/sun/star/drawing/LineDash.hpp>
      25             : #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
      26             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      27             : #include "oox/helper/containerhelper.hxx"
      28             : #include "oox/helper/helper.hxx"
      29             : 
      30             : namespace oox {
      31             : 
      32             : using namespace ::com::sun::star;
      33             : using namespace ::com::sun::star::drawing;
      34             : using namespace ::com::sun::star::lang;
      35             : using namespace ::com::sun::star::uno;
      36             : 
      37        9150 : ObjectContainer::ObjectContainer( const Reference< XMultiServiceFactory >& rxModelFactory, const OUString& rServiceName ) :
      38             :     mxModelFactory( rxModelFactory ),
      39             :     maServiceName( rServiceName ),
      40        9150 :     mnIndex( 0 )
      41             : {
      42             :     OSL_ENSURE( mxModelFactory.is(), "ObjectContainer::ObjectContainer - missing service factory" );
      43        9150 : }
      44             : 
      45        9150 : ObjectContainer::~ObjectContainer()
      46             : {
      47        9150 : }
      48             : 
      49         250 : bool ObjectContainer::hasObject( const OUString& rObjName ) const
      50             : {
      51         250 :     createContainer();
      52         250 :     return mxContainer.is() && mxContainer->hasByName( rObjName );
      53             : }
      54             : 
      55           0 : Any ObjectContainer::getObject( const OUString& rObjName ) const
      56             : {
      57           0 :     if( hasObject( rObjName ) )
      58           0 :         return mxContainer->getByName( rObjName );
      59           0 :     return Any();
      60             : }
      61             : 
      62         244 : OUString ObjectContainer::insertObject( const OUString& rObjName, const Any& rObj, bool bInsertByUnusedName )
      63             : {
      64         244 :     createContainer();
      65         244 :     if( mxContainer.is() )
      66             :     {
      67         244 :         if( bInsertByUnusedName )
      68         178 :             return ContainerHelper::insertByUnusedName( mxContainer, rObjName + OUString::number( ++mnIndex ), ' ', rObj );
      69          66 :         if( ContainerHelper::insertByName( mxContainer, rObjName, rObj ) )
      70          66 :             return rObjName;
      71             :     }
      72           0 :     return OUString();
      73             : }
      74             : 
      75         494 : void ObjectContainer::createContainer() const
      76             : {
      77         494 :     if( !mxContainer.is() && mxModelFactory.is() ) try
      78             :     {
      79         114 :         mxContainer.set( mxModelFactory->createInstance( maServiceName ), UNO_QUERY_THROW );
      80         114 :         mxModelFactory.clear();
      81             :     }
      82           0 :     catch( Exception& )
      83             :     {
      84             :     }
      85             :     OSL_ENSURE( mxContainer.is(), "ObjectContainer::createContainer - container not found" );
      86         494 : }
      87             : 
      88        1830 : ModelObjectHelper::ModelObjectHelper( const Reference< XMultiServiceFactory >& rxModelFactory ) :
      89             :     maMarkerContainer(    rxModelFactory, "com.sun.star.drawing.MarkerTable" ),
      90             :     maDashContainer(      rxModelFactory, "com.sun.star.drawing.DashTable" ),
      91             :     maGradientContainer(  rxModelFactory, "com.sun.star.drawing.GradientTable" ),
      92             :     maTransGradContainer(  rxModelFactory, "com.sun.star.drawing.TransparencyGradientTable" ),
      93             :     maBitmapUrlContainer( rxModelFactory, "com.sun.star.drawing.BitmapTable" ),
      94             :     maDashNameBase(      "msLineDash " ),
      95             :     maGradientNameBase(  "msFillGradient " ),
      96             :     maTransGradNameBase( "msTransGradient " ),
      97        1830 :     maBitmapUrlNameBase( "msFillBitmap " )
      98             : {
      99        1830 : }
     100             : 
     101         250 : bool ModelObjectHelper::hasLineMarker( const OUString& rMarkerName ) const
     102             : {
     103         250 :     return maMarkerContainer.hasObject( rMarkerName );
     104             : }
     105             : 
     106          66 : bool ModelObjectHelper::insertLineMarker( const OUString& rMarkerName, const PolyPolygonBezierCoords& rMarker )
     107             : {
     108             :     OSL_ENSURE( rMarker.Coordinates.hasElements(), "ModelObjectHelper::insertLineMarker - line marker without coordinates" );
     109          66 :     if( rMarker.Coordinates.hasElements() )
     110          66 :         return !maMarkerContainer.insertObject( rMarkerName, Any( rMarker ), false ).isEmpty();
     111           0 :     return false;
     112             : }
     113             : 
     114           0 : OUString ModelObjectHelper::insertLineDash( const LineDash& rDash )
     115             : {
     116           0 :     return maDashContainer.insertObject( maDashNameBase, Any( rDash ), true );
     117             : }
     118             : 
     119           8 : OUString ModelObjectHelper::insertFillGradient( const awt::Gradient& rGradient )
     120             : {
     121           8 :     return maGradientContainer.insertObject( maGradientNameBase, Any( rGradient ), true );
     122             : }
     123             : 
     124          60 : OUString ModelObjectHelper::insertTransGrandient( const awt::Gradient& rGradient )
     125             : {
     126          60 :     return maTransGradContainer.insertObject( maTransGradNameBase, Any( rGradient ), true );
     127             : }
     128             : 
     129         110 : OUString ModelObjectHelper::insertFillBitmapUrl( const OUString& rGraphicUrl )
     130             : {
     131         110 :     if( !rGraphicUrl.isEmpty() )
     132         110 :         return maBitmapUrlContainer.insertObject( maBitmapUrlNameBase, Any( rGraphicUrl ), true );
     133           0 :     return OUString();
     134             : }
     135             : 
     136           0 : OUString ModelObjectHelper::getFillBitmapUrl( const OUString &rGraphicName )
     137             : {
     138           0 :     Any aAny = maBitmapUrlContainer.getObject( rGraphicName );
     139           0 :     if( aAny.hasValue() )
     140           0 :         return aAny.get<OUString>();
     141           0 :     return OUString();
     142             : }
     143             : 
     144             : } // namespace oox
     145             : 
     146             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10