update credits
[LibreOffice.git] / oox / source / helper / modelobjecthelper.cxx
blob7d3954710974fe005b29b1a1b5fecd515a631a9d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "oox/helper/modelobjecthelper.hxx"
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"
30 namespace oox {
32 // ============================================================================
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;
39 // ============================================================================
41 ObjectContainer::ObjectContainer( const Reference< XMultiServiceFactory >& rxModelFactory, const OUString& rServiceName ) :
42 mxModelFactory( rxModelFactory ),
43 maServiceName( rServiceName ),
44 mnIndex( 0 )
46 OSL_ENSURE( mxModelFactory.is(), "ObjectContainer::ObjectContainer - missing service factory" );
49 ObjectContainer::~ObjectContainer()
53 bool ObjectContainer::hasObject( const OUString& rObjName ) const
55 createContainer();
56 return mxContainer.is() && mxContainer->hasByName( rObjName );
59 OUString ObjectContainer::insertObject( const OUString& rObjName, const Any& rObj, bool bInsertByUnusedName )
61 createContainer();
62 if( mxContainer.is() )
64 if( bInsertByUnusedName )
65 return ContainerHelper::insertByUnusedName( mxContainer, rObjName + OUString::valueOf( ++mnIndex ), ' ', rObj );
66 if( ContainerHelper::insertByName( mxContainer, rObjName, rObj ) )
67 return rObjName;
69 return OUString();
72 void ObjectContainer::createContainer() const
74 if( !mxContainer.is() && mxModelFactory.is() ) try
76 mxContainer.set( mxModelFactory->createInstance( maServiceName ), UNO_QUERY_THROW );
77 mxModelFactory.clear();
79 catch( Exception& )
82 OSL_ENSURE( mxContainer.is(), "ObjectContainer::createContainer - container not found" );
85 // ============================================================================
87 ModelObjectHelper::ModelObjectHelper( const Reference< XMultiServiceFactory >& rxModelFactory ) :
88 maMarkerContainer( rxModelFactory, "com.sun.star.drawing.MarkerTable" ),
89 maDashContainer( rxModelFactory, "com.sun.star.drawing.DashTable" ),
90 maGradientContainer( rxModelFactory, "com.sun.star.drawing.GradientTable" ),
91 maTransGradContainer( rxModelFactory, "com.sun.star.drawing.TransparencyGradientTable" ),
92 maBitmapUrlContainer( rxModelFactory, "com.sun.star.drawing.BitmapTable" ),
93 maDashNameBase( "msLineDash " ),
94 maGradientNameBase( "msFillGradient " ),
95 maTransGradNameBase( "msTransGradient " ),
96 maBitmapUrlNameBase( "msFillBitmap " )
100 bool ModelObjectHelper::hasLineMarker( const OUString& rMarkerName ) const
102 return maMarkerContainer.hasObject( rMarkerName );
105 bool ModelObjectHelper::insertLineMarker( const OUString& rMarkerName, const PolyPolygonBezierCoords& rMarker )
107 OSL_ENSURE( rMarker.Coordinates.hasElements(), "ModelObjectHelper::insertLineMarker - line marker without coordinates" );
108 if( rMarker.Coordinates.hasElements() )
109 return !maMarkerContainer.insertObject( rMarkerName, Any( rMarker ), false ).isEmpty();
110 return false;
113 OUString ModelObjectHelper::insertLineDash( const LineDash& rDash )
115 return maDashContainer.insertObject( maDashNameBase, Any( rDash ), true );
118 OUString ModelObjectHelper::insertFillGradient( const awt::Gradient& rGradient )
120 return maGradientContainer.insertObject( maGradientNameBase, Any( rGradient ), true );
123 OUString ModelObjectHelper::insertTransGrandient( const awt::Gradient& rGradient )
125 return maTransGradContainer.insertObject( maTransGradNameBase, Any( rGradient ), true );
128 OUString ModelObjectHelper::insertFillBitmapUrl( const OUString& rGraphicUrl )
130 if( !rGraphicUrl.isEmpty() )
131 return maBitmapUrlContainer.insertObject( maBitmapUrlNameBase, Any( rGraphicUrl ), true );
132 return OUString();
135 // ============================================================================
137 } // namespace oox
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */