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

Generated by: LCOV version 1.10