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