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