fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / oox / source / drawingml / shapepropertymap.cxx
blobfe985dba892c3df360954660b20e56497d5036aa
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/drawingml/shapepropertymap.hxx"
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"
28 namespace oox {
29 namespace drawingml {
31 // ============================================================================
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;
38 // ============================================================================
40 namespace {
42 static const sal_Int32 spnDefaultShapeIds[ SHAPEPROP_END ] =
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
54 } // namespace
56 ShapePropertyInfo ShapePropertyInfo::DEFAULT( spnDefaultShapeIds, true, false, false, false );
58 ShapePropertyInfo::ShapePropertyInfo( const sal_Int32* pnPropertyIds,
59 bool bNamedLineMarker, bool bNamedLineDash, bool bNamedFillGradient, bool bNamedFillBitmapUrl ) :
60 mpnPropertyIds( pnPropertyIds ),
61 mbNamedLineMarker( bNamedLineMarker ),
62 mbNamedLineDash( bNamedLineDash ),
63 mbNamedFillGradient( bNamedFillGradient ),
64 mbNamedFillBitmapUrl( bNamedFillBitmapUrl )
66 OSL_ENSURE( mpnPropertyIds != 0, "ShapePropertyInfo::ShapePropertyInfo - missing property identifiers" );
69 // ============================================================================
71 ShapePropertyMap::ShapePropertyMap( ModelObjectHelper& rModelObjHelper, const ShapePropertyInfo& rShapePropInfo ) :
72 mrModelObjHelper( rModelObjHelper ),
73 maShapePropInfo( rShapePropInfo )
77 bool ShapePropertyMap::supportsProperty( ShapePropertyId ePropId ) const
79 return maShapePropInfo.has( ePropId );
82 bool ShapePropertyMap::hasNamedLineMarkerInTable( const OUString& rMarkerName ) const
84 return maShapePropInfo.mbNamedLineMarker && mrModelObjHelper.hasLineMarker( rMarkerName );
87 bool ShapePropertyMap::setAnyProperty( ShapePropertyId ePropId, const Any& rValue )
89 // get current property identifier for the specified property
90 sal_Int32 nPropId = maShapePropInfo[ ePropId ];
91 if( nPropId < 0 ) return false;
93 // special handling for properties supporting named objects in tables
94 switch( ePropId )
96 case SHAPEPROP_LineStart:
97 case SHAPEPROP_LineEnd:
98 return setLineMarker( nPropId, rValue );
100 case SHAPEPROP_LineDash:
101 return setLineDash( nPropId, rValue );
103 case SHAPEPROP_FillGradient:
104 return setFillGradient( nPropId, rValue );
106 case SHAPEPROP_GradientTransparency:
107 return setGradientTrans( nPropId, rValue );
109 case SHAPEPROP_FillBitmapUrl:
110 return setFillBitmapUrl( nPropId, rValue );
112 case SHAPEPROP_FillBitmapNameFromUrl:
113 return setFillBitmapNameFromUrl( nPropId, rValue );
115 default:; // suppress compiler warnings
118 // set plain property value
119 operator[]( nPropId ) = rValue;
120 return true;
123 // private --------------------------------------------------------------------
125 bool ShapePropertyMap::setLineMarker( sal_Int32 nPropId, const Any& rValue )
127 NamedValue aNamedMarker;
128 if( (rValue >>= aNamedMarker) && !aNamedMarker.Name.isEmpty() )
130 // push line marker explicitly
131 if( !maShapePropInfo.mbNamedLineMarker )
132 return setAnyProperty( nPropId, aNamedMarker.Value );
134 // create named line marker (if coordinates have been passed) and push its name
135 bool bInserted = !aNamedMarker.Value.has< PolyPolygonBezierCoords >() ||
136 mrModelObjHelper.insertLineMarker( aNamedMarker.Name, aNamedMarker.Value.get< PolyPolygonBezierCoords >() );
137 return bInserted && setProperty( nPropId, aNamedMarker.Name );
139 return false;
142 bool ShapePropertyMap::setLineDash( sal_Int32 nPropId, const Any& rValue )
144 // push line dash explicitly
145 if( !maShapePropInfo.mbNamedLineDash )
146 return setAnyProperty( nPropId, rValue );
148 // create named line dash and push its name
149 if( rValue.has< LineDash >() )
151 OUString aDashName = mrModelObjHelper.insertLineDash( rValue.get< LineDash >() );
152 return !aDashName.isEmpty() && setProperty( nPropId, aDashName );
155 return false;
158 bool ShapePropertyMap::setFillGradient( sal_Int32 nPropId, const Any& rValue )
160 // push gradient explicitly
161 if( !maShapePropInfo.mbNamedFillGradient )
162 return setAnyProperty( nPropId, rValue );
164 // create named gradient and push its name
165 if( rValue.has< awt::Gradient >() )
167 OUString aGradientName = mrModelObjHelper.insertFillGradient( rValue.get< awt::Gradient >() );
168 return !aGradientName.isEmpty() && setProperty( nPropId, aGradientName );
171 return false;
174 bool ShapePropertyMap::setGradientTrans( sal_Int32 nPropId, const Any& rValue )
176 // create named gradient and push its name
177 if( rValue.has< awt::Gradient >() )
179 OUString aGradientName = mrModelObjHelper.insertTransGrandient( rValue.get< awt::Gradient >() );
180 return !aGradientName.isEmpty() && setProperty( nPropId, aGradientName );
183 return false;
186 bool ShapePropertyMap::setFillBitmapUrl( sal_Int32 nPropId, const Any& rValue )
188 // push bitmap URL explicitly
189 if( !maShapePropInfo.mbNamedFillBitmapUrl )
190 return setAnyProperty( nPropId, rValue );
192 // create named bitmap URL and push its name
193 if( rValue.has< OUString >() )
195 OUString aBitmapUrlName = mrModelObjHelper.insertFillBitmapUrl( rValue.get< OUString >() );
196 return !aBitmapUrlName.isEmpty() && setProperty( nPropId, aBitmapUrlName );
199 return false;
202 bool ShapePropertyMap::setFillBitmapNameFromUrl( sal_Int32 /*nPropId*/, const Any& rValue )
204 if( rValue.has< OUString >() )
206 OUString aBitmapUrlName = mrModelObjHelper.insertFillBitmapUrl( rValue.get< OUString >() );
207 return !aBitmapUrlName.isEmpty() && setProperty( PROP_FillBitmapName, aBitmapUrlName );
209 return false;
212 // ============================================================================
214 } // namespace drawingml
215 } // namespace oox
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */