xref: /trunk/main/oox/source/vml/vmlshape.cxx (revision ca5ec200)
1*ca5ec200SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ca5ec200SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ca5ec200SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ca5ec200SAndrew Rist  * distributed with this work for additional information
6*ca5ec200SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ca5ec200SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ca5ec200SAndrew Rist  * "License"); you may not use this file except in compliance
9*ca5ec200SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ca5ec200SAndrew Rist  *
11*ca5ec200SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ca5ec200SAndrew Rist  *
13*ca5ec200SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ca5ec200SAndrew Rist  * software distributed under the License is distributed on an
15*ca5ec200SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ca5ec200SAndrew Rist  * KIND, either express or implied.  See the License for the
17*ca5ec200SAndrew Rist  * specific language governing permissions and limitations
18*ca5ec200SAndrew Rist  * under the License.
19*ca5ec200SAndrew Rist  *
20*ca5ec200SAndrew Rist  *************************************************************/
21*ca5ec200SAndrew Rist 
22*ca5ec200SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "oox/vml/vmlshape.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValues.hpp>
27cdf0e10cSrcweir #include <com/sun/star/awt/XControlModel.hpp>
28cdf0e10cSrcweir #include <com/sun/star/drawing/PointSequenceSequence.hpp>
29cdf0e10cSrcweir #include <com/sun/star/drawing/XEnhancedCustomShapeDefaulter.hpp>
30cdf0e10cSrcweir #include <com/sun/star/drawing/XShapes.hpp>
31cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphic.hpp>
32cdf0e10cSrcweir #include <rtl/math.hxx>
33cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
34cdf0e10cSrcweir #include "oox/core/xmlfilterbase.hxx"
35cdf0e10cSrcweir #include "oox/drawingml/shapepropertymap.hxx"
36cdf0e10cSrcweir #include "oox/helper/containerhelper.hxx"
37cdf0e10cSrcweir #include "oox/helper/graphichelper.hxx"
38cdf0e10cSrcweir #include "oox/helper/propertyset.hxx"
39cdf0e10cSrcweir #include "oox/ole/axcontrol.hxx"
40cdf0e10cSrcweir #include "oox/ole/axcontrolfragment.hxx"
41cdf0e10cSrcweir #include "oox/ole/oleobjecthelper.hxx"
42cdf0e10cSrcweir #include "oox/vml/vmldrawing.hxx"
43cdf0e10cSrcweir #include "oox/vml/vmlshapecontainer.hxx"
44cdf0e10cSrcweir #include "oox/vml/vmltextbox.hxx"
45cdf0e10cSrcweir 
46cdf0e10cSrcweir namespace oox {
47cdf0e10cSrcweir namespace vml {
48cdf0e10cSrcweir 
49cdf0e10cSrcweir // ============================================================================
50cdf0e10cSrcweir 
51cdf0e10cSrcweir using namespace ::com::sun::star::awt;
52cdf0e10cSrcweir using namespace ::com::sun::star::drawing;
53cdf0e10cSrcweir using namespace ::com::sun::star::graphic;
54cdf0e10cSrcweir using namespace ::com::sun::star::uno;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir using ::oox::core::XmlFilterBase;
57cdf0e10cSrcweir using ::rtl::OUString;
58cdf0e10cSrcweir using ::rtl::OUStringBuffer;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir // ============================================================================
61cdf0e10cSrcweir 
62cdf0e10cSrcweir namespace {
63cdf0e10cSrcweir 
64cdf0e10cSrcweir const sal_Int32 VML_SHAPETYPE_PICTUREFRAME  = 75;
65cdf0e10cSrcweir const sal_Int32 VML_SHAPETYPE_HOSTCONTROL   = 201;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir // ----------------------------------------------------------------------------
68cdf0e10cSrcweir 
lclGetAbsPoint(const Point & rRelPoint,const Rectangle & rShapeRect,const Rectangle & rCoordSys)69cdf0e10cSrcweir Point lclGetAbsPoint( const Point& rRelPoint, const Rectangle& rShapeRect, const Rectangle& rCoordSys )
70cdf0e10cSrcweir {
71cdf0e10cSrcweir     double fWidthRatio = static_cast< double >( rShapeRect.Width ) / rCoordSys.Width;
72cdf0e10cSrcweir     double fHeightRatio = static_cast< double >( rShapeRect.Height ) / rCoordSys.Height;
73cdf0e10cSrcweir     Point aAbsPoint;
74cdf0e10cSrcweir     aAbsPoint.X = static_cast< sal_Int32 >( rShapeRect.X + fWidthRatio * (rRelPoint.X - rCoordSys.X) + 0.5 );
75cdf0e10cSrcweir     aAbsPoint.Y = static_cast< sal_Int32 >( rShapeRect.Y + fHeightRatio * (rRelPoint.Y - rCoordSys.Y) + 0.5 );
76cdf0e10cSrcweir     return aAbsPoint;
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
lclGetAbsRect(const Rectangle & rRelRect,const Rectangle & rShapeRect,const Rectangle & rCoordSys)79cdf0e10cSrcweir Rectangle lclGetAbsRect( const Rectangle& rRelRect, const Rectangle& rShapeRect, const Rectangle& rCoordSys )
80cdf0e10cSrcweir {
81cdf0e10cSrcweir     double fWidthRatio = static_cast< double >( rShapeRect.Width ) / rCoordSys.Width;
82cdf0e10cSrcweir     double fHeightRatio = static_cast< double >( rShapeRect.Height ) / rCoordSys.Height;
83cdf0e10cSrcweir     Rectangle aAbsRect;
84cdf0e10cSrcweir     aAbsRect.X = static_cast< sal_Int32 >( rShapeRect.X + fWidthRatio * (rRelRect.X - rCoordSys.X) + 0.5 );
85cdf0e10cSrcweir     aAbsRect.Y = static_cast< sal_Int32 >( rShapeRect.Y + fHeightRatio * (rRelRect.Y - rCoordSys.Y) + 0.5 );
86cdf0e10cSrcweir     aAbsRect.Width = static_cast< sal_Int32 >( fWidthRatio * rRelRect.Width + 0.5 );
87cdf0e10cSrcweir     aAbsRect.Height = static_cast< sal_Int32 >( fHeightRatio * rRelRect.Height + 0.5 );
88cdf0e10cSrcweir     return aAbsRect;
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir } // namespace
92cdf0e10cSrcweir 
93cdf0e10cSrcweir // ============================================================================
94cdf0e10cSrcweir 
ShapeTypeModel()95cdf0e10cSrcweir ShapeTypeModel::ShapeTypeModel()
96cdf0e10cSrcweir {
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
assignUsed(const ShapeTypeModel & rSource)99cdf0e10cSrcweir void ShapeTypeModel::assignUsed( const ShapeTypeModel& rSource )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir     moShapeType.assignIfUsed( rSource.moShapeType );
102cdf0e10cSrcweir     moCoordPos.assignIfUsed( rSource.moCoordPos );
103cdf0e10cSrcweir     moCoordSize.assignIfUsed( rSource.moCoordSize );
104cdf0e10cSrcweir     /*  The style properties position, left, top, width, height, margin-left,
105cdf0e10cSrcweir         margin-top are not derived from shape template to shape. */
106cdf0e10cSrcweir     maStrokeModel.assignUsed( rSource.maStrokeModel );
107cdf0e10cSrcweir     maFillModel.assignUsed( rSource.maFillModel );
108cdf0e10cSrcweir     moGraphicPath.assignIfUsed( rSource.moGraphicPath );
109cdf0e10cSrcweir     moGraphicTitle.assignIfUsed( rSource.moGraphicTitle );
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir // ----------------------------------------------------------------------------
113cdf0e10cSrcweir 
ShapeType(Drawing & rDrawing)114cdf0e10cSrcweir ShapeType::ShapeType( Drawing& rDrawing ) :
115cdf0e10cSrcweir     mrDrawing( rDrawing )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir }
118cdf0e10cSrcweir 
~ShapeType()119cdf0e10cSrcweir ShapeType::~ShapeType()
120cdf0e10cSrcweir {
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
getShapeType() const123cdf0e10cSrcweir sal_Int32 ShapeType::getShapeType() const
124cdf0e10cSrcweir {
125cdf0e10cSrcweir     return maTypeModel.moShapeType.get( 0 );
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
getGraphicPath() const128cdf0e10cSrcweir OUString ShapeType::getGraphicPath() const
129cdf0e10cSrcweir {
130cdf0e10cSrcweir     return maTypeModel.moGraphicPath.get( OUString() );
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
getCoordSystem() const133cdf0e10cSrcweir Rectangle ShapeType::getCoordSystem() const
134cdf0e10cSrcweir {
135cdf0e10cSrcweir     Int32Pair aCoordPos = maTypeModel.moCoordPos.get( Int32Pair( 0, 0 ) );
136cdf0e10cSrcweir     Int32Pair aCoordSize = maTypeModel.moCoordSize.get( Int32Pair( 1000, 1000 ) );
137cdf0e10cSrcweir     return Rectangle( aCoordPos.first, aCoordPos.second, aCoordSize.first, aCoordSize.second );
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
getRectangle(const ShapeParentAnchor * pParentAnchor) const140cdf0e10cSrcweir Rectangle ShapeType::getRectangle( const ShapeParentAnchor* pParentAnchor ) const
141cdf0e10cSrcweir {
142cdf0e10cSrcweir     return pParentAnchor ?
143cdf0e10cSrcweir         lclGetAbsRect( getRelRectangle(), pParentAnchor->maShapeRect, pParentAnchor->maCoordSys ) :
144cdf0e10cSrcweir         getAbsRectangle();
145cdf0e10cSrcweir }
146cdf0e10cSrcweir 
getAbsRectangle() const147cdf0e10cSrcweir Rectangle ShapeType::getAbsRectangle() const
148cdf0e10cSrcweir {
149cdf0e10cSrcweir     const GraphicHelper& rGraphicHelper = mrDrawing.getFilter().getGraphicHelper();
150cdf0e10cSrcweir     return Rectangle(
151cdf0e10cSrcweir         ConversionHelper::decodeMeasureToHmm( rGraphicHelper, maTypeModel.maLeft, 0, true, true ) + ConversionHelper::decodeMeasureToHmm( rGraphicHelper, maTypeModel.maMarginLeft, 0, true, true ),
152cdf0e10cSrcweir         ConversionHelper::decodeMeasureToHmm( rGraphicHelper, maTypeModel.maTop, 0, false, true ) + ConversionHelper::decodeMeasureToHmm( rGraphicHelper, maTypeModel.maMarginTop, 0, false, true ),
153cdf0e10cSrcweir         ConversionHelper::decodeMeasureToHmm( rGraphicHelper, maTypeModel.maWidth, 0, true, true ),
154cdf0e10cSrcweir         ConversionHelper::decodeMeasureToHmm( rGraphicHelper, maTypeModel.maHeight, 0, false, true ) );
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
getRelRectangle() const157cdf0e10cSrcweir Rectangle ShapeType::getRelRectangle() const
158cdf0e10cSrcweir {
159cdf0e10cSrcweir     return Rectangle(
160cdf0e10cSrcweir         maTypeModel.maLeft.toInt32(),
161cdf0e10cSrcweir         maTypeModel.maTop.toInt32(),
162cdf0e10cSrcweir         maTypeModel.maWidth.toInt32(),
163cdf0e10cSrcweir         maTypeModel.maHeight.toInt32() );
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir // ============================================================================
167cdf0e10cSrcweir 
ClientData()168cdf0e10cSrcweir ClientData::ClientData() :
169cdf0e10cSrcweir     mnObjType( XML_TOKEN_INVALID ),
170cdf0e10cSrcweir     mnTextHAlign( XML_Left ),
171cdf0e10cSrcweir     mnTextVAlign( XML_Top ),
172cdf0e10cSrcweir     mnCol( -1 ),
173cdf0e10cSrcweir     mnRow( -1 ),
174cdf0e10cSrcweir     mnChecked( VML_CLIENTDATA_UNCHECKED ),
175cdf0e10cSrcweir     mnDropStyle( XML_Combo ),
176cdf0e10cSrcweir     mnDropLines( 1 ),
177cdf0e10cSrcweir     mnVal( 0 ),
178cdf0e10cSrcweir     mnMin( 0 ),
179cdf0e10cSrcweir     mnMax( 0 ),
180cdf0e10cSrcweir     mnInc( 0 ),
181cdf0e10cSrcweir     mnPage( 0 ),
182cdf0e10cSrcweir     mnSelType( XML_Single ),
183cdf0e10cSrcweir     mnVTEdit( VML_CLIENTDATA_TEXT ),
184cdf0e10cSrcweir     mbPrintObject( true ),
185cdf0e10cSrcweir     mbVisible( false ),
186cdf0e10cSrcweir     mbDde( false ),
187cdf0e10cSrcweir     mbNo3D( false ),
188cdf0e10cSrcweir     mbNo3D2( false ),
189cdf0e10cSrcweir     mbMultiLine( false ),
190cdf0e10cSrcweir     mbVScroll( false ),
191cdf0e10cSrcweir     mbSecretEdit( false )
192cdf0e10cSrcweir {
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir // ----------------------------------------------------------------------------
196cdf0e10cSrcweir 
ShapeModel()197cdf0e10cSrcweir ShapeModel::ShapeModel()
198cdf0e10cSrcweir {
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
~ShapeModel()201cdf0e10cSrcweir ShapeModel::~ShapeModel()
202cdf0e10cSrcweir {
203cdf0e10cSrcweir }
204cdf0e10cSrcweir 
createTextBox()205cdf0e10cSrcweir TextBox& ShapeModel::createTextBox()
206cdf0e10cSrcweir {
207cdf0e10cSrcweir     mxTextBox.reset( new TextBox );
208cdf0e10cSrcweir     return *mxTextBox;
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
createClientData()211cdf0e10cSrcweir ClientData& ShapeModel::createClientData()
212cdf0e10cSrcweir {
213cdf0e10cSrcweir     mxClientData.reset( new ClientData );
214cdf0e10cSrcweir     return *mxClientData;
215cdf0e10cSrcweir }
216cdf0e10cSrcweir 
217cdf0e10cSrcweir // ----------------------------------------------------------------------------
218cdf0e10cSrcweir 
ShapeBase(Drawing & rDrawing)219cdf0e10cSrcweir ShapeBase::ShapeBase( Drawing& rDrawing ) :
220cdf0e10cSrcweir     ShapeType( rDrawing )
221cdf0e10cSrcweir {
222cdf0e10cSrcweir }
223cdf0e10cSrcweir 
finalizeFragmentImport()224cdf0e10cSrcweir void ShapeBase::finalizeFragmentImport()
225cdf0e10cSrcweir {
226cdf0e10cSrcweir     // resolve shape template reference
227cdf0e10cSrcweir     if( (maShapeModel.maType.getLength() > 1) && (maShapeModel.maType[ 0 ] == '#') )
228cdf0e10cSrcweir         if( const ShapeType* pShapeType = mrDrawing.getShapes().getShapeTypeById( maShapeModel.maType.copy( 1 ), true ) )
229cdf0e10cSrcweir             maTypeModel.assignUsed( pShapeType->getTypeModel() );
230cdf0e10cSrcweir }
231cdf0e10cSrcweir 
getShapeName() const232cdf0e10cSrcweir OUString ShapeBase::getShapeName() const
233cdf0e10cSrcweir {
234cdf0e10cSrcweir     if( maTypeModel.maShapeName.getLength() > 0 )
235cdf0e10cSrcweir         return maTypeModel.maShapeName;
236cdf0e10cSrcweir 
237cdf0e10cSrcweir     OUString aBaseName = mrDrawing.getShapeBaseName( *this );
238cdf0e10cSrcweir     if( aBaseName.getLength() > 0 )
239cdf0e10cSrcweir     {
240cdf0e10cSrcweir         sal_Int32 nShapeIdx = mrDrawing.getLocalShapeIndex( getShapeId() );
241cdf0e10cSrcweir         if( nShapeIdx > 0 )
242cdf0e10cSrcweir             return OUStringBuffer( aBaseName ).append( sal_Unicode( ' ' ) ).append( nShapeIdx ).makeStringAndClear();
243cdf0e10cSrcweir     }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir     return OUString();
246cdf0e10cSrcweir }
247cdf0e10cSrcweir 
getChildTypeById(const OUString &) const248cdf0e10cSrcweir const ShapeType* ShapeBase::getChildTypeById( const OUString& ) const
249cdf0e10cSrcweir {
250cdf0e10cSrcweir     return 0;
251cdf0e10cSrcweir }
252cdf0e10cSrcweir 
getChildById(const OUString &) const253cdf0e10cSrcweir const ShapeBase* ShapeBase::getChildById( const OUString& ) const
254cdf0e10cSrcweir {
255cdf0e10cSrcweir     return 0;
256cdf0e10cSrcweir }
257cdf0e10cSrcweir 
convertAndInsert(const Reference<XShapes> & rxShapes,const ShapeParentAnchor * pParentAnchor) const258cdf0e10cSrcweir Reference< XShape > ShapeBase::convertAndInsert( const Reference< XShapes >& rxShapes, const ShapeParentAnchor* pParentAnchor ) const
259cdf0e10cSrcweir {
260cdf0e10cSrcweir     Reference< XShape > xShape;
261cdf0e10cSrcweir     if( mrDrawing.isShapeSupported( *this ) )
262cdf0e10cSrcweir     {
263cdf0e10cSrcweir         /*  Calculate shape rectangle. Applications may do something special
264cdf0e10cSrcweir             according to some imported shape client data (e.g. Excel cell anchor). */
265cdf0e10cSrcweir         Rectangle aShapeRect = calcShapeRectangle( pParentAnchor );
266cdf0e10cSrcweir 
267cdf0e10cSrcweir         // convert the shape, if the calculated rectangle is not empty
268cdf0e10cSrcweir         if( ((aShapeRect.Width > 0) || (aShapeRect.Height > 0)) && rxShapes.is() )
269cdf0e10cSrcweir         {
270cdf0e10cSrcweir             xShape = implConvertAndInsert( rxShapes, aShapeRect );
271cdf0e10cSrcweir             if( xShape.is() )
272cdf0e10cSrcweir             {
273cdf0e10cSrcweir                 // set imported or generated shape name (not supported by form controls)
274cdf0e10cSrcweir                 PropertySet aShapeProp( xShape );
275cdf0e10cSrcweir                 if( aShapeProp.hasProperty( PROP_Name ) )
276cdf0e10cSrcweir                     aShapeProp.setProperty( PROP_Name, getShapeName() );
277cdf0e10cSrcweir 
278cdf0e10cSrcweir                 /*  Notify the drawing that a new shape has been inserted. For
279cdf0e10cSrcweir                     convenience, pass the rectangle that contains position and
280cdf0e10cSrcweir                     size of the shape. */
281cdf0e10cSrcweir                 bool bGroupChild = pParentAnchor != 0;
282cdf0e10cSrcweir                 mrDrawing.notifyXShapeInserted( xShape, aShapeRect, *this, bGroupChild );
283cdf0e10cSrcweir             }
284cdf0e10cSrcweir         }
285cdf0e10cSrcweir     }
286cdf0e10cSrcweir     return xShape;
287cdf0e10cSrcweir }
288cdf0e10cSrcweir 
convertFormatting(const Reference<XShape> & rxShape,const ShapeParentAnchor * pParentAnchor) const289cdf0e10cSrcweir void ShapeBase::convertFormatting( const Reference< XShape >& rxShape, const ShapeParentAnchor* pParentAnchor ) const
290cdf0e10cSrcweir {
291cdf0e10cSrcweir     if( rxShape.is() )
292cdf0e10cSrcweir     {
293cdf0e10cSrcweir         /*  Calculate shape rectangle. Applications may do something special
294cdf0e10cSrcweir             according to some imported shape client data (e.g. Excel cell anchor). */
295cdf0e10cSrcweir         Rectangle aShapeRect = calcShapeRectangle( pParentAnchor );
296cdf0e10cSrcweir 
297cdf0e10cSrcweir         // convert the shape, if the calculated rectangle is not empty
298cdf0e10cSrcweir         if( (aShapeRect.Width > 0) || (aShapeRect.Height > 0) )
299cdf0e10cSrcweir         {
300cdf0e10cSrcweir             rxShape->setPosition( Point( aShapeRect.X, aShapeRect.Y ) );
301cdf0e10cSrcweir             rxShape->setSize( Size( aShapeRect.Width, aShapeRect.Height ) );
302cdf0e10cSrcweir             convertShapeProperties( rxShape );
303cdf0e10cSrcweir         }
304cdf0e10cSrcweir     }
305cdf0e10cSrcweir }
306cdf0e10cSrcweir 
307cdf0e10cSrcweir // protected ------------------------------------------------------------------
308cdf0e10cSrcweir 
calcShapeRectangle(const ShapeParentAnchor * pParentAnchor) const309cdf0e10cSrcweir Rectangle ShapeBase::calcShapeRectangle( const ShapeParentAnchor* pParentAnchor ) const
310cdf0e10cSrcweir {
311cdf0e10cSrcweir     /*  Calculate shape rectangle. Applications may do something special
312cdf0e10cSrcweir         according to some imported shape client data (e.g. Excel cell anchor). */
313cdf0e10cSrcweir     Rectangle aShapeRect;
314cdf0e10cSrcweir     const ClientData* pClientData = getClientData();
315cdf0e10cSrcweir     if( !pClientData || !mrDrawing.convertClientAnchor( aShapeRect, pClientData->maAnchor ) )
316cdf0e10cSrcweir         aShapeRect = getRectangle( pParentAnchor );
317cdf0e10cSrcweir     return aShapeRect;
318cdf0e10cSrcweir }
319cdf0e10cSrcweir 
convertShapeProperties(const Reference<XShape> & rxShape) const320cdf0e10cSrcweir void ShapeBase::convertShapeProperties( const Reference< XShape >& rxShape ) const
321cdf0e10cSrcweir {
322cdf0e10cSrcweir     ::oox::drawingml::ShapePropertyMap aPropMap( mrDrawing.getFilter().getModelObjectHelper() );
323cdf0e10cSrcweir     const GraphicHelper& rGraphicHelper = mrDrawing.getFilter().getGraphicHelper();
324cdf0e10cSrcweir     maTypeModel.maStrokeModel.pushToPropMap( aPropMap, rGraphicHelper );
325cdf0e10cSrcweir     maTypeModel.maFillModel.pushToPropMap( aPropMap, rGraphicHelper );
326cdf0e10cSrcweir     PropertySet( rxShape ).setProperties( aPropMap );
327cdf0e10cSrcweir }
328cdf0e10cSrcweir 
329cdf0e10cSrcweir // ============================================================================
330cdf0e10cSrcweir 
SimpleShape(Drawing & rDrawing,const OUString & rService)331cdf0e10cSrcweir SimpleShape::SimpleShape( Drawing& rDrawing, const OUString& rService ) :
332cdf0e10cSrcweir     ShapeBase( rDrawing ),
333cdf0e10cSrcweir     maService( rService )
334cdf0e10cSrcweir {
335cdf0e10cSrcweir }
336cdf0e10cSrcweir 
implConvertAndInsert(const Reference<XShapes> & rxShapes,const Rectangle & rShapeRect) const337cdf0e10cSrcweir Reference< XShape > SimpleShape::implConvertAndInsert( const Reference< XShapes >& rxShapes, const Rectangle& rShapeRect ) const
338cdf0e10cSrcweir {
339cdf0e10cSrcweir     Reference< XShape > xShape = mrDrawing.createAndInsertXShape( maService, rxShapes, rShapeRect );
340cdf0e10cSrcweir     convertShapeProperties( xShape );
341cdf0e10cSrcweir     return xShape;
342cdf0e10cSrcweir }
343cdf0e10cSrcweir 
344cdf0e10cSrcweir // ============================================================================
345cdf0e10cSrcweir 
RectangleShape(Drawing & rDrawing)346cdf0e10cSrcweir RectangleShape::RectangleShape( Drawing& rDrawing ) :
347cdf0e10cSrcweir     SimpleShape( rDrawing, CREATE_OUSTRING( "com.sun.star.drawing.RectangleShape" ) )
348cdf0e10cSrcweir {
349cdf0e10cSrcweir }
350cdf0e10cSrcweir 
351cdf0e10cSrcweir // ============================================================================
352cdf0e10cSrcweir 
EllipseShape(Drawing & rDrawing)353cdf0e10cSrcweir EllipseShape::EllipseShape( Drawing& rDrawing ) :
354cdf0e10cSrcweir     SimpleShape( rDrawing, CREATE_OUSTRING( "com.sun.star.drawing.EllipseShape" ) )
355cdf0e10cSrcweir {
356cdf0e10cSrcweir }
357cdf0e10cSrcweir 
358cdf0e10cSrcweir // ============================================================================
359cdf0e10cSrcweir 
PolyLineShape(Drawing & rDrawing)360cdf0e10cSrcweir PolyLineShape::PolyLineShape( Drawing& rDrawing ) :
361cdf0e10cSrcweir     SimpleShape( rDrawing, CREATE_OUSTRING( "com.sun.star.drawing.PolyLineShape" ) )
362cdf0e10cSrcweir {
363cdf0e10cSrcweir }
364cdf0e10cSrcweir 
implConvertAndInsert(const Reference<XShapes> & rxShapes,const Rectangle & rShapeRect) const365cdf0e10cSrcweir Reference< XShape > PolyLineShape::implConvertAndInsert( const Reference< XShapes >& rxShapes, const Rectangle& rShapeRect ) const
366cdf0e10cSrcweir {
367cdf0e10cSrcweir     Reference< XShape > xShape = SimpleShape::implConvertAndInsert( rxShapes, rShapeRect );
368cdf0e10cSrcweir     // polygon path
369cdf0e10cSrcweir     Rectangle aCoordSys = getCoordSystem();
370cdf0e10cSrcweir     if( !maShapeModel.maPoints.empty() && (aCoordSys.Width > 0) && (aCoordSys.Height > 0) )
371cdf0e10cSrcweir     {
372cdf0e10cSrcweir         ::std::vector< Point > aAbsPoints;
373cdf0e10cSrcweir         for( ShapeModel::PointVector::const_iterator aIt = maShapeModel.maPoints.begin(), aEnd = maShapeModel.maPoints.end(); aIt != aEnd; ++aIt )
374cdf0e10cSrcweir             aAbsPoints.push_back( lclGetAbsPoint( *aIt, rShapeRect, aCoordSys ) );
375cdf0e10cSrcweir         PointSequenceSequence aPointSeq( 1 );
376cdf0e10cSrcweir         aPointSeq[ 0 ] = ContainerHelper::vectorToSequence( aAbsPoints );
377cdf0e10cSrcweir         PropertySet aPropSet( xShape );
378cdf0e10cSrcweir         aPropSet.setProperty( PROP_PolyPolygon, aPointSeq );
379cdf0e10cSrcweir     }
380cdf0e10cSrcweir     return xShape;
381cdf0e10cSrcweir }
382cdf0e10cSrcweir 
383cdf0e10cSrcweir // ============================================================================
384cdf0e10cSrcweir 
CustomShape(Drawing & rDrawing)385cdf0e10cSrcweir CustomShape::CustomShape( Drawing& rDrawing ) :
386cdf0e10cSrcweir     SimpleShape( rDrawing, CREATE_OUSTRING( "com.sun.star.drawing.CustomShape" ) )
387cdf0e10cSrcweir {
388cdf0e10cSrcweir }
389cdf0e10cSrcweir 
implConvertAndInsert(const Reference<XShapes> & rxShapes,const Rectangle & rShapeRect) const390cdf0e10cSrcweir Reference< XShape > CustomShape::implConvertAndInsert( const Reference< XShapes >& rxShapes, const Rectangle& rShapeRect ) const
391cdf0e10cSrcweir {
392cdf0e10cSrcweir     // try to create a custom shape
393cdf0e10cSrcweir     Reference< XShape > xShape = SimpleShape::implConvertAndInsert( rxShapes, rShapeRect );
394cdf0e10cSrcweir     if( xShape.is() ) try
395cdf0e10cSrcweir     {
396cdf0e10cSrcweir         // create the custom shape geometry
397cdf0e10cSrcweir         Reference< XEnhancedCustomShapeDefaulter > xDefaulter( xShape, UNO_QUERY_THROW );
398cdf0e10cSrcweir         xDefaulter->createCustomShapeDefaults( OUString::valueOf( getShapeType() ) );
399cdf0e10cSrcweir         // convert common properties
400cdf0e10cSrcweir         convertShapeProperties( xShape );
401cdf0e10cSrcweir     }
402cdf0e10cSrcweir     catch( Exception& )
403cdf0e10cSrcweir     {
404cdf0e10cSrcweir     }
405cdf0e10cSrcweir     return xShape;
406cdf0e10cSrcweir }
407cdf0e10cSrcweir 
408cdf0e10cSrcweir // ============================================================================
409cdf0e10cSrcweir 
ComplexShape(Drawing & rDrawing)410cdf0e10cSrcweir ComplexShape::ComplexShape( Drawing& rDrawing ) :
411cdf0e10cSrcweir     CustomShape( rDrawing )
412cdf0e10cSrcweir {
413cdf0e10cSrcweir }
414cdf0e10cSrcweir 
implConvertAndInsert(const Reference<XShapes> & rxShapes,const Rectangle & rShapeRect) const415cdf0e10cSrcweir Reference< XShape > ComplexShape::implConvertAndInsert( const Reference< XShapes >& rxShapes, const Rectangle& rShapeRect ) const
416cdf0e10cSrcweir {
417cdf0e10cSrcweir     XmlFilterBase& rFilter = mrDrawing.getFilter();
418cdf0e10cSrcweir     sal_Int32 nShapeType = getShapeType();
419cdf0e10cSrcweir     OUString aGraphicPath = getGraphicPath();
420cdf0e10cSrcweir 
421cdf0e10cSrcweir     // try to find registered OLE object info
422cdf0e10cSrcweir     if( const OleObjectInfo* pOleObjectInfo = mrDrawing.getOleObjectInfo( maTypeModel.maShapeId ) )
423cdf0e10cSrcweir     {
424cdf0e10cSrcweir         OSL_ENSURE( nShapeType == VML_SHAPETYPE_PICTUREFRAME, "ComplexShape::implConvertAndInsert - unexpected shape type" );
425cdf0e10cSrcweir 
426cdf0e10cSrcweir         // if OLE object is embedded into a DrawingML shape (PPTX), do not create it here
427cdf0e10cSrcweir         if( pOleObjectInfo->mbDmlShape )
428cdf0e10cSrcweir             return Reference< XShape >();
429cdf0e10cSrcweir 
430cdf0e10cSrcweir         PropertyMap aOleProps;
431cdf0e10cSrcweir         Size aOleSize( rShapeRect.Width, rShapeRect.Height );
432cdf0e10cSrcweir         if( rFilter.getOleObjectHelper().importOleObject( aOleProps, *pOleObjectInfo, aOleSize ) )
433cdf0e10cSrcweir         {
434cdf0e10cSrcweir             Reference< XShape > xShape = mrDrawing.createAndInsertXShape( CREATE_OUSTRING( "com.sun.star.drawing.OLE2Shape" ), rxShapes, rShapeRect );
435cdf0e10cSrcweir             if( xShape.is() )
436cdf0e10cSrcweir             {
437cdf0e10cSrcweir                 // set the replacement graphic
438cdf0e10cSrcweir                 if( aGraphicPath.getLength() > 0 )
439cdf0e10cSrcweir                 {
440cdf0e10cSrcweir                     Reference< XGraphic > xGraphic = rFilter.getGraphicHelper().importEmbeddedGraphic( aGraphicPath );
441cdf0e10cSrcweir                     if( xGraphic.is() )
442cdf0e10cSrcweir                         aOleProps[ PROP_Graphic ] <<= xGraphic;
443cdf0e10cSrcweir                 }
444cdf0e10cSrcweir 
445cdf0e10cSrcweir                 PropertySet aPropSet( xShape );
446cdf0e10cSrcweir                 aPropSet.setProperties( aOleProps );
447cdf0e10cSrcweir 
448cdf0e10cSrcweir                 return xShape;
449cdf0e10cSrcweir             }
450cdf0e10cSrcweir         }
451cdf0e10cSrcweir     }
452cdf0e10cSrcweir 
453cdf0e10cSrcweir     // try to find registered form control info
454cdf0e10cSrcweir     const ControlInfo* pControlInfo = mrDrawing.getControlInfo( maTypeModel.maShapeId );
455cdf0e10cSrcweir     if( pControlInfo && (pControlInfo->maFragmentPath.getLength() > 0) )
456cdf0e10cSrcweir     {
457cdf0e10cSrcweir         OSL_ENSURE( nShapeType == VML_SHAPETYPE_HOSTCONTROL, "ComplexShape::implConvertAndInsert - unexpected shape type" );
458cdf0e10cSrcweir         OUString aShapeName = getShapeName();
459cdf0e10cSrcweir         if( aShapeName.getLength() > 0 )
460cdf0e10cSrcweir         {
461cdf0e10cSrcweir             OSL_ENSURE( aShapeName == pControlInfo->maName, "ComplexShape::implConvertAndInsert - control name mismatch" );
462cdf0e10cSrcweir             // load the control properties from fragment
463cdf0e10cSrcweir             ::oox::ole::EmbeddedControl aControl( aShapeName );
464cdf0e10cSrcweir             if( rFilter.importFragment( new ::oox::ole::AxControlFragment( rFilter, pControlInfo->maFragmentPath, aControl ) ) )
465cdf0e10cSrcweir             {
466cdf0e10cSrcweir                 // create and return the control shape (including control model)
467cdf0e10cSrcweir                 sal_Int32 nCtrlIndex = -1;
468cdf0e10cSrcweir                 Reference< XShape > xShape = mrDrawing.createAndInsertXControlShape( aControl, rxShapes, rShapeRect, nCtrlIndex );
469cdf0e10cSrcweir                 // on error, proceed and try to create picture from replacement image
470cdf0e10cSrcweir                 if( xShape.is() )
471cdf0e10cSrcweir                     return xShape;
472cdf0e10cSrcweir             }
473cdf0e10cSrcweir         }
474cdf0e10cSrcweir     }
475cdf0e10cSrcweir 
476cdf0e10cSrcweir     // host application wants to create the shape (do not try failed OLE controls again)
477cdf0e10cSrcweir     if( (nShapeType == VML_SHAPETYPE_HOSTCONTROL) && !pControlInfo )
478cdf0e10cSrcweir     {
479cdf0e10cSrcweir         OSL_ENSURE( getClientData(), "ComplexShape::implConvertAndInsert - missing client data" );
480cdf0e10cSrcweir         Reference< XShape > xShape = mrDrawing.createAndInsertClientXShape( *this, rxShapes, rShapeRect );
481cdf0e10cSrcweir         if( xShape.is() )
482cdf0e10cSrcweir             return xShape;
483cdf0e10cSrcweir     }
484cdf0e10cSrcweir 
485cdf0e10cSrcweir     // try to create a picture object
486cdf0e10cSrcweir     if( aGraphicPath.getLength() > 0 )
487cdf0e10cSrcweir     {
488cdf0e10cSrcweir         Reference< XShape > xShape = mrDrawing.createAndInsertXShape( CREATE_OUSTRING( "com.sun.star.drawing.GraphicObjectShape" ), rxShapes, rShapeRect );
489cdf0e10cSrcweir         if( xShape.is() )
490cdf0e10cSrcweir         {
491cdf0e10cSrcweir             OUString aGraphicUrl = rFilter.getGraphicHelper().importEmbeddedGraphicObject( aGraphicPath );
492cdf0e10cSrcweir             if( aGraphicUrl.getLength() > 0 )
493cdf0e10cSrcweir             {
494cdf0e10cSrcweir                 PropertySet aPropSet( xShape );
495cdf0e10cSrcweir                 aPropSet.setProperty( PROP_GraphicURL, aGraphicUrl );
496cdf0e10cSrcweir             }
497cdf0e10cSrcweir         }
498cdf0e10cSrcweir         return xShape;
499cdf0e10cSrcweir     }
500cdf0e10cSrcweir 
501cdf0e10cSrcweir     // default: try to create a custom shape
502cdf0e10cSrcweir     return CustomShape::implConvertAndInsert( rxShapes, rShapeRect );
503cdf0e10cSrcweir }
504cdf0e10cSrcweir 
505cdf0e10cSrcweir // ============================================================================
506cdf0e10cSrcweir 
GroupShape(Drawing & rDrawing)507cdf0e10cSrcweir GroupShape::GroupShape( Drawing& rDrawing ) :
508cdf0e10cSrcweir     ShapeBase( rDrawing ),
509cdf0e10cSrcweir     mxChildren( new ShapeContainer( rDrawing ) )
510cdf0e10cSrcweir {
511cdf0e10cSrcweir }
512cdf0e10cSrcweir 
~GroupShape()513cdf0e10cSrcweir GroupShape::~GroupShape()
514cdf0e10cSrcweir {
515cdf0e10cSrcweir }
516cdf0e10cSrcweir 
finalizeFragmentImport()517cdf0e10cSrcweir void GroupShape::finalizeFragmentImport()
518cdf0e10cSrcweir {
519cdf0e10cSrcweir     // basic shape processing
520cdf0e10cSrcweir     ShapeBase::finalizeFragmentImport();
521cdf0e10cSrcweir     // finalize all child shapes
522cdf0e10cSrcweir     mxChildren->finalizeFragmentImport();
523cdf0e10cSrcweir }
524cdf0e10cSrcweir 
getChildTypeById(const OUString & rShapeId) const525cdf0e10cSrcweir const ShapeType* GroupShape::getChildTypeById( const OUString& rShapeId ) const
526cdf0e10cSrcweir {
527cdf0e10cSrcweir     return mxChildren->getShapeTypeById( rShapeId, true );
528cdf0e10cSrcweir }
529cdf0e10cSrcweir 
getChildById(const OUString & rShapeId) const530cdf0e10cSrcweir const ShapeBase* GroupShape::getChildById( const OUString& rShapeId ) const
531cdf0e10cSrcweir {
532cdf0e10cSrcweir     return mxChildren->getShapeById( rShapeId, true );
533cdf0e10cSrcweir }
534cdf0e10cSrcweir 
implConvertAndInsert(const Reference<XShapes> & rxShapes,const Rectangle & rShapeRect) const535cdf0e10cSrcweir Reference< XShape > GroupShape::implConvertAndInsert( const Reference< XShapes >& rxShapes, const Rectangle& rShapeRect ) const
536cdf0e10cSrcweir {
537cdf0e10cSrcweir     Reference< XShape > xGroupShape;
538cdf0e10cSrcweir     // check that this shape contains children and a valid coordinate system
539cdf0e10cSrcweir     ShapeParentAnchor aParentAnchor;
540cdf0e10cSrcweir     aParentAnchor.maShapeRect = rShapeRect;
541cdf0e10cSrcweir     aParentAnchor.maCoordSys = getCoordSystem();
542cdf0e10cSrcweir     if( !mxChildren->empty() && (aParentAnchor.maCoordSys.Width > 0) && (aParentAnchor.maCoordSys.Height > 0) ) try
543cdf0e10cSrcweir     {
544cdf0e10cSrcweir         xGroupShape = mrDrawing.createAndInsertXShape( CREATE_OUSTRING( "com.sun.star.drawing.GroupShape" ), rxShapes, rShapeRect );
545cdf0e10cSrcweir         Reference< XShapes > xChildShapes( xGroupShape, UNO_QUERY_THROW );
546cdf0e10cSrcweir         mxChildren->convertAndInsert( xChildShapes, &aParentAnchor );
547cdf0e10cSrcweir         // no child shape has been created - delete the group shape
548cdf0e10cSrcweir         if( !xChildShapes->hasElements() )
549cdf0e10cSrcweir         {
550cdf0e10cSrcweir             rxShapes->remove( xGroupShape );
551cdf0e10cSrcweir             xGroupShape.clear();
552cdf0e10cSrcweir         }
553cdf0e10cSrcweir     }
554cdf0e10cSrcweir     catch( Exception& )
555cdf0e10cSrcweir     {
556cdf0e10cSrcweir     }
557cdf0e10cSrcweir     return xGroupShape;
558cdf0e10cSrcweir }
559cdf0e10cSrcweir 
560cdf0e10cSrcweir // ============================================================================
561cdf0e10cSrcweir 
562cdf0e10cSrcweir } // namespace vml
563cdf0e10cSrcweir } // namespace oox
564