1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_xmloff.hxx" 30 31 32 33 #include <tools/debug.hxx> 34 #include <com/sun/star/document/XEventsSupplier.hpp> 35 #include <com/sun/star/container/XNameReplace.hpp> 36 #include <com/sun/star/presentation/ClickAction.hpp> 37 #include <com/sun/star/drawing/FillStyle.hpp> 38 #include <com/sun/star/drawing/LineStyle.hpp> 39 #include "unointerfacetouniqueidentifiermapper.hxx" 40 #include <com/sun/star/drawing/XGluePointsSupplier.hpp> 41 #include <com/sun/star/container/XIdentifierAccess.hpp> 42 #include <com/sun/star/drawing/GluePoint2.hpp> 43 #include <com/sun/star/drawing/Alignment.hpp> 44 #include <com/sun/star/drawing/EscapeDirection.hpp> 45 #include <com/sun/star/media/ZoomLevel.hpp> 46 #include <com/sun/star/awt/Rectangle.hpp> 47 48 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> 49 #include <com/sun/star/container/XNameAccess.hpp> 50 #include <comphelper/extract.hxx> 51 #include "ximpshap.hxx" 52 #include <xmloff/XMLBase64ImportContext.hxx> 53 #include <xmloff/XMLShapeStyleContext.hxx> 54 #include <xmloff/xmluconv.hxx> 55 #include <com/sun/star/container/XNamed.hpp> 56 #include <com/sun/star/drawing/CircleKind.hpp> 57 #include <com/sun/star/beans/XPropertySet.hpp> 58 #include <com/sun/star/awt/XControlModel.hpp> 59 #include <com/sun/star/drawing/XControlShape.hpp> 60 #include <com/sun/star/drawing/PointSequenceSequence.hpp> 61 #include <com/sun/star/drawing/PointSequence.hpp> 62 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> 63 #include <com/sun/star/lang/XServiceInfo.hpp> 64 #include <com/sun/star/util/XCloneable.hpp> 65 #include <com/sun/star/beans/XMultiPropertyStates.hpp> 66 #include "xexptran.hxx" 67 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp> 68 #include <com/sun/star/beans/XPropertySetInfo.hpp> 69 #include <com/sun/star/drawing/ConnectorType.hpp> 70 #include <com/sun/star/drawing/HomogenMatrix3.hpp> 71 #include "PropertySetMerger.hxx" 72 #include <xmloff/families.hxx> 73 #include "ximpstyl.hxx" 74 #include"xmloff/xmlnmspe.hxx" 75 #include <xmloff/xmltoken.hxx> 76 #include "EnhancedCustomShapeToken.hxx" 77 #include "XMLReplacementImageContext.hxx" 78 #include "XMLImageMapContext.hxx" 79 #include "sdpropls.hxx" 80 #include "eventimp.hxx" 81 82 #include "descriptionimp.hxx" 83 #include "ximpcustomshape.hxx" 84 #include "XMLEmbeddedObjectImportContext.hxx" 85 #include "xmloff/xmlerror.hxx" 86 #include <basegfx/matrix/b2dhommatrix.hxx> 87 #include <tools/string.hxx> 88 #include <com/sun/star/drawing/XEnhancedCustomShapeDefaulter.hpp> 89 90 // --> OD 2006-02-22 #b6382898# 91 #include <com/sun/star/text/XTextDocument.hpp> 92 // <-- 93 94 using ::rtl::OUString; 95 using ::rtl::OUStringBuffer; 96 97 using namespace ::com::sun::star; 98 using namespace ::com::sun::star::uno; 99 using namespace ::com::sun::star::drawing; 100 using namespace ::com::sun::star::style; 101 using namespace ::com::sun::star::container; 102 using namespace ::com::sun::star::document; 103 using namespace ::xmloff::token; 104 using namespace ::xmloff::EnhancedCustomShapeToken; 105 106 SvXMLEnumMapEntry aXML_GlueAlignment_EnumMap[] = 107 { 108 { XML_TOP_LEFT, drawing::Alignment_TOP_LEFT }, 109 { XML_TOP, drawing::Alignment_TOP }, 110 { XML_TOP_RIGHT, drawing::Alignment_TOP_RIGHT }, 111 { XML_LEFT, drawing::Alignment_LEFT }, 112 { XML_CENTER, drawing::Alignment_CENTER }, 113 { XML_RIGHT, drawing::Alignment_RIGHT }, 114 { XML_BOTTOM_LEFT, drawing::Alignment_BOTTOM_LEFT }, 115 { XML_BOTTOM, drawing::Alignment_BOTTOM }, 116 { XML_BOTTOM_RIGHT, drawing::Alignment_BOTTOM_RIGHT }, 117 { XML_TOKEN_INVALID, 0 } 118 }; 119 120 SvXMLEnumMapEntry aXML_GlueEscapeDirection_EnumMap[] = 121 { 122 { XML_AUTO, drawing::EscapeDirection_SMART }, 123 { XML_LEFT, drawing::EscapeDirection_LEFT }, 124 { XML_RIGHT, drawing::EscapeDirection_RIGHT }, 125 { XML_UP, drawing::EscapeDirection_UP }, 126 { XML_DOWN, drawing::EscapeDirection_DOWN }, 127 { XML_HORIZONTAL, drawing::EscapeDirection_HORIZONTAL }, 128 { XML_VERTICAL, drawing::EscapeDirection_VERTICAL }, 129 { XML_TOKEN_INVALID, 0 } 130 }; 131 132 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 133 134 static bool ImpIsEmptyURL( const ::rtl::OUString& rURL ) 135 { 136 if( rURL.getLength() == 0 ) 137 return true; 138 139 // #i13140# Also compare against 'toplevel' URLs. which also 140 // result in empty filename strings. 141 if( 0 == rURL.compareToAscii( "#./" ) ) 142 return true; 143 144 return false; 145 } 146 147 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 148 149 TYPEINIT1( SvXMLShapeContext, SvXMLImportContext ); 150 TYPEINIT1( SdXMLShapeContext, SvXMLShapeContext ); 151 152 SdXMLShapeContext::SdXMLShapeContext( 153 SvXMLImport& rImport, 154 sal_uInt16 nPrfx, 155 const OUString& rLocalName, 156 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 157 uno::Reference< drawing::XShapes >& rShapes, 158 sal_Bool bTemporaryShape) 159 : SvXMLShapeContext( rImport, nPrfx, rLocalName, bTemporaryShape ) 160 , mxShapes( rShapes ) 161 , mxAttrList(xAttrList) 162 , mbListContextPushed( false ) 163 , mnStyleFamily(XML_STYLE_FAMILY_SD_GRAPHICS_ID) 164 , mbIsPlaceholder(sal_False) 165 , mbClearDefaultAttributes( true ) 166 , mbIsUserTransformed(sal_False) 167 , mnZOrder(-1) 168 , maSize(1, 1) 169 , maPosition(0, 0) 170 , mbVisible(true) 171 , mbPrintable(true) 172 { 173 } 174 175 ////////////////////////////////////////////////////////////////////////////// 176 177 SdXMLShapeContext::~SdXMLShapeContext() 178 { 179 } 180 181 ////////////////////////////////////////////////////////////////////////////// 182 183 SvXMLImportContext *SdXMLShapeContext::CreateChildContext( sal_uInt16 p_nPrefix, 184 const OUString& rLocalName, 185 const uno::Reference< xml::sax::XAttributeList>& xAttrList ) 186 { 187 SvXMLImportContext * pContext = NULL; 188 189 // #i68101# 190 if( p_nPrefix == XML_NAMESPACE_SVG && 191 (IsXMLToken( rLocalName, XML_TITLE ) || IsXMLToken( rLocalName, XML_DESC ) ) ) 192 { 193 pContext = new SdXMLDescriptionContext( GetImport(), p_nPrefix, rLocalName, xAttrList, mxShape ); 194 } 195 else if( p_nPrefix == XML_NAMESPACE_OFFICE && IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) ) 196 { 197 pContext = new SdXMLEventsContext( GetImport(), p_nPrefix, rLocalName, xAttrList, mxShape ); 198 } 199 else if( p_nPrefix == XML_NAMESPACE_DRAW && IsXMLToken( rLocalName, XML_GLUE_POINT ) ) 200 { 201 addGluePoint( xAttrList ); 202 } 203 else if( p_nPrefix == XML_NAMESPACE_DRAW && IsXMLToken( rLocalName, XML_THUMBNAIL ) ) 204 { 205 // search attributes for xlink:href 206 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 207 for(sal_Int16 i=0; i < nAttrCount; i++) 208 { 209 OUString sAttrName = xAttrList->getNameByIndex( i ); 210 OUString aLocalName; 211 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); 212 213 if( nPrefix == XML_NAMESPACE_XLINK ) 214 { 215 if( IsXMLToken( aLocalName, XML_HREF ) ) 216 { 217 maThumbnailURL = xAttrList->getValueByIndex( i ); 218 break; 219 } 220 } 221 } 222 } 223 else 224 { 225 // create text cursor on demand 226 if( !mxCursor.is() ) 227 { 228 uno::Reference< text::XText > xText( mxShape, uno::UNO_QUERY ); 229 if( xText.is() ) 230 { 231 UniReference < XMLTextImportHelper > xTxtImport = 232 GetImport().GetTextImport(); 233 mxOldCursor = xTxtImport->GetCursor(); 234 mxCursor = xText->createTextCursor(); 235 if( mxCursor.is() ) 236 { 237 xTxtImport->SetCursor( mxCursor ); 238 } 239 240 // remember old list item and block (#91964#) and reset them 241 // for the text frame 242 xTxtImport->PushListContext(); 243 mbListContextPushed = true; 244 } 245 } 246 247 // if we have a text cursor, lets try to import some text 248 if( mxCursor.is() ) 249 { 250 pContext = GetImport().GetTextImport()->CreateTextChildContext( 251 GetImport(), p_nPrefix, rLocalName, xAttrList ); 252 } 253 } 254 255 // call parent for content 256 if(!pContext) 257 pContext = SvXMLImportContext::CreateChildContext( p_nPrefix, rLocalName, xAttrList ); 258 259 return pContext; 260 } 261 262 void SdXMLShapeContext::addGluePoint( const uno::Reference< xml::sax::XAttributeList>& xAttrList ) 263 { 264 // get the glue points container for this shape if its not already there 265 if( !mxGluePoints.is() ) 266 { 267 uno::Reference< drawing::XGluePointsSupplier > xSupplier( mxShape, uno::UNO_QUERY ); 268 if( !xSupplier.is() ) 269 return; 270 271 mxGluePoints = uno::Reference< container::XIdentifierContainer >::query( xSupplier->getGluePoints() ); 272 273 if( !mxGluePoints.is() ) 274 return; 275 } 276 277 drawing::GluePoint2 aGluePoint; 278 aGluePoint.IsUserDefined = sal_True; 279 aGluePoint.Position.X = 0; 280 aGluePoint.Position.Y = 0; 281 aGluePoint.Escape = drawing::EscapeDirection_SMART; 282 aGluePoint.PositionAlignment = drawing::Alignment_CENTER; 283 aGluePoint.IsRelative = sal_True; 284 285 sal_Int32 nId = -1; 286 287 // read attributes for the 3DScene 288 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 289 for(sal_Int16 i=0; i < nAttrCount; i++) 290 { 291 OUString sAttrName = xAttrList->getNameByIndex( i ); 292 OUString aLocalName; 293 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); 294 const OUString sValue( xAttrList->getValueByIndex( i ) ); 295 296 if( nPrefix == XML_NAMESPACE_SVG ) 297 { 298 if( IsXMLToken( aLocalName, XML_X ) ) 299 { 300 GetImport().GetMM100UnitConverter().convertMeasure(aGluePoint.Position.X, sValue); 301 } 302 else if( IsXMLToken( aLocalName, XML_Y ) ) 303 { 304 GetImport().GetMM100UnitConverter().convertMeasure(aGluePoint.Position.Y, sValue); 305 } 306 } 307 else if( nPrefix == XML_NAMESPACE_DRAW ) 308 { 309 if( IsXMLToken( aLocalName, XML_ID ) ) 310 { 311 nId = sValue.toInt32(); 312 } 313 else if( IsXMLToken( aLocalName, XML_ALIGN ) ) 314 { 315 sal_uInt16 eKind; 316 if( SvXMLUnitConverter::convertEnum( eKind, sValue, aXML_GlueAlignment_EnumMap ) ) 317 { 318 aGluePoint.PositionAlignment = (drawing::Alignment)eKind; 319 aGluePoint.IsRelative = sal_False; 320 } 321 } 322 else if( IsXMLToken( aLocalName, XML_ESCAPE_DIRECTION ) ) 323 { 324 sal_uInt16 eKind; 325 if( SvXMLUnitConverter::convertEnum( eKind, sValue, aXML_GlueEscapeDirection_EnumMap ) ) 326 { 327 aGluePoint.Escape = (drawing::EscapeDirection)eKind; 328 } 329 } 330 } 331 } 332 333 if( nId != -1 ) 334 { 335 try 336 { 337 sal_Int32 nInternalId = mxGluePoints->insert( uno::makeAny( aGluePoint ) ); 338 GetImport().GetShapeImport()->addGluePointMapping( mxShape, nId, nInternalId ); 339 } 340 catch( uno::Exception& ) 341 { 342 DBG_ERROR( "exception during setting of glue points!"); 343 } 344 } 345 } 346 ////////////////////////////////////////////////////////////////////////////// 347 348 void SdXMLShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>&) 349 { 350 GetImport().GetShapeImport()->finishShape( mxShape, mxAttrList, mxShapes ); 351 } 352 353 void SdXMLShapeContext::EndElement() 354 { 355 if(mxCursor.is()) 356 { 357 // delete addition newline 358 const OUString aEmpty; 359 mxCursor->gotoEnd( sal_False ); 360 mxCursor->goLeft( 1, sal_True ); 361 mxCursor->setString( aEmpty ); 362 363 // reset cursor 364 GetImport().GetTextImport()->ResetCursor(); 365 } 366 367 if(mxOldCursor.is()) 368 GetImport().GetTextImport()->SetCursor( mxOldCursor ); 369 370 // reinstall old list item (if necessary) #91964# 371 if (mbListContextPushed) { 372 GetImport().GetTextImport()->PopListContext(); 373 } 374 375 if( msHyperlink.getLength() != 0 ) try 376 { 377 const OUString sBookmark( RTL_CONSTASCII_USTRINGPARAM( "Bookmark" ) ); 378 379 Reference< XEventsSupplier > xEventsSupplier( mxShape, UNO_QUERY ); 380 if( xEventsSupplier.is() ) 381 { 382 const OUString sEventType( RTL_CONSTASCII_USTRINGPARAM( "EventType" ) ); 383 const OUString sClickAction( RTL_CONSTASCII_USTRINGPARAM( "ClickAction" ) ); 384 385 Reference< XNameReplace > xEvents( xEventsSupplier->getEvents(), UNO_QUERY_THROW ); 386 387 uno::Sequence< beans::PropertyValue > aProperties( 3 ); 388 aProperties[0].Name = sEventType; 389 aProperties[0].Handle = -1; 390 aProperties[0].Value <<= OUString( RTL_CONSTASCII_USTRINGPARAM("Presentation") ); 391 aProperties[0].State = beans::PropertyState_DIRECT_VALUE; 392 393 aProperties[1].Name = sClickAction; 394 aProperties[1].Handle = -1; 395 aProperties[1].Value <<= ::com::sun::star::presentation::ClickAction_DOCUMENT; 396 aProperties[1].State = beans::PropertyState_DIRECT_VALUE; 397 398 aProperties[2].Name = sBookmark; 399 aProperties[2].Handle = -1; 400 aProperties[2].Value <<= msHyperlink; 401 aProperties[2].State = beans::PropertyState_DIRECT_VALUE; 402 403 const OUString sAPIEventName( RTL_CONSTASCII_USTRINGPARAM( "OnClick" ) ); 404 xEvents->replaceByName( sAPIEventName, Any( aProperties ) ); 405 } 406 else 407 { 408 // in draw use the Bookmark property 409 Reference< beans::XPropertySet > xSet( mxShape, UNO_QUERY_THROW ); 410 xSet->setPropertyValue( sBookmark, Any( msHyperlink ) ); 411 xSet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "OnClick" ) ), Any( ::com::sun::star::presentation::ClickAction_DOCUMENT ) ); 412 } 413 } 414 catch( Exception& ) 415 { 416 DBG_ERROR("xmloff::SdXMLShapeContext::EndElement(), exception caught while setting hyperlink!"); 417 } 418 419 if( mxLockable.is() ) 420 mxLockable->removeActionLock(); 421 } 422 423 ////////////////////////////////////////////////////////////////////////////// 424 425 void SdXMLShapeContext::AddShape(uno::Reference< drawing::XShape >& xShape) 426 { 427 if(xShape.is()) 428 { 429 // set shape local 430 mxShape = xShape; 431 432 if(maShapeName.getLength()) 433 { 434 uno::Reference< container::XNamed > xNamed( mxShape, uno::UNO_QUERY ); 435 if( xNamed.is() ) 436 xNamed->setName( maShapeName ); 437 } 438 439 UniReference< XMLShapeImportHelper > xImp( GetImport().GetShapeImport() ); 440 xImp->addShape( xShape, mxAttrList, mxShapes ); 441 442 if( mbClearDefaultAttributes ) 443 { 444 uno::Reference<beans::XMultiPropertyStates> xMultiPropertyStates(xShape, uno::UNO_QUERY ); 445 if (xMultiPropertyStates.is()) 446 xMultiPropertyStates->setAllPropertiesToDefault(); 447 } 448 449 if( !mbVisible || !mbPrintable ) try 450 { 451 uno::Reference< beans::XPropertySet > xSet( xShape, uno::UNO_QUERY_THROW ); 452 if( !mbVisible ) 453 xSet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Visible" ) ), uno::Any( sal_False ) ); 454 455 if( !mbPrintable ) 456 xSet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Printable" ) ), uno::Any( sal_False ) ); 457 } 458 catch( Exception& ) 459 { 460 DBG_ERROR( "SdXMLShapeContext::AddShape(), exception caught!" ); 461 } 462 463 // #107848# 464 if(!mbTemporaryShape && (!GetImport().HasTextImport() 465 || !GetImport().GetTextImport()->IsInsideDeleteContext())) 466 { 467 xImp->shapeWithZIndexAdded( xShape, mnZOrder ); 468 } 469 470 if( maShapeId.getLength() ) 471 { 472 uno::Reference< uno::XInterface > xRef( xShape, uno::UNO_QUERY ); 473 GetImport().getInterfaceToIdentifierMapper().registerReference( maShapeId, xRef ); 474 } 475 476 // #91065# count only if counting for shape import is enabled 477 if(GetImport().GetShapeImport()->IsHandleProgressBarEnabled()) 478 { 479 // #80365# increment progress bar at load once for each draw object 480 GetImport().GetProgressBarHelper()->Increment(); 481 } 482 } 483 484 mxLockable = uno::Reference< document::XActionLockable >::query( xShape ); 485 486 if( mxLockable.is() ) 487 mxLockable->addActionLock(); 488 489 } 490 491 ////////////////////////////////////////////////////////////////////////////// 492 493 void SdXMLShapeContext::AddShape(const char* pServiceName ) 494 { 495 uno::Reference< lang::XMultiServiceFactory > xServiceFact(GetImport().GetModel(), uno::UNO_QUERY); 496 if(xServiceFact.is()) 497 { 498 try 499 { 500 // --> OD 2006-02-22 #b6382898# 501 // Since fix for issue i33294 the Writer model doesn't support 502 // com.sun.star.drawing.OLE2Shape anymore. 503 // To handle Draw OLE objects it's decided to import these 504 // objects as com.sun.star.drawing.OLE2Shape and convert these 505 // objects after the import into com.sun.star.drawing.GraphicObjectShape. 506 uno::Reference< drawing::XShape > xShape; 507 if ( OUString::createFromAscii(pServiceName).compareToAscii( "com.sun.star.drawing.OLE2Shape" ) == 0 && 508 uno::Reference< text::XTextDocument >(GetImport().GetModel(), uno::UNO_QUERY).is() ) 509 { 510 xShape = uno::Reference< drawing::XShape >(xServiceFact->createInstance(OUString::createFromAscii("com.sun.star.drawing.temporaryForXMLImportOLE2Shape")), uno::UNO_QUERY); 511 } 512 else 513 { 514 xShape = uno::Reference< drawing::XShape >(xServiceFact->createInstance(OUString::createFromAscii(pServiceName)), uno::UNO_QUERY); 515 } 516 // <-- 517 if( xShape.is() ) 518 AddShape( xShape ); 519 } 520 catch( const uno::Exception& e ) 521 { 522 uno::Sequence<rtl::OUString> aSeq( 1 ); 523 aSeq[0] = OUString::createFromAscii(pServiceName); 524 GetImport().SetError( XMLERROR_FLAG_ERROR | XMLERROR_API, 525 aSeq, e.Message, NULL ); 526 } 527 } 528 } 529 530 ////////////////////////////////////////////////////////////////////////////// 531 532 void SdXMLShapeContext::SetTransformation() 533 { 534 if(mxShape.is()) 535 { 536 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY); 537 if(xPropSet.is()) 538 { 539 ::basegfx::B2DHomMatrix aTransformation; 540 541 if(maSize.Width != 1 || maSize.Height != 1) 542 { 543 // take care there are no zeros used by error 544 if(0 == maSize.Width) 545 maSize.Width = 1; 546 if(0 == maSize.Height) 547 maSize.Height = 1; 548 549 // set global size. This should always be used. 550 aTransformation.scale(maSize.Width, maSize.Height); 551 } 552 553 if(maPosition.X != 0 || maPosition.Y != 0) 554 { 555 // if global position is used, add it to transformation 556 aTransformation.translate(maPosition.X, maPosition.Y); 557 } 558 559 if(mnTransform.NeedsAction()) 560 { 561 // transformation is used, apply to object. 562 // NOTICE: The transformation is applied AFTER evtl. used 563 // global positioning and scaling is used, so any shear or 564 // rotate used herein is applied around the (0,0) position 565 // of the PAGE object !!! 566 ::basegfx::B2DHomMatrix aMat; 567 mnTransform.GetFullTransform(aMat); 568 569 // now add to transformation 570 aTransformation *= aMat; 571 } 572 573 // now set transformation for this object 574 uno::Any aAny; 575 drawing::HomogenMatrix3 aMatrix; 576 577 aMatrix.Line1.Column1 = aTransformation.get(0, 0); 578 aMatrix.Line1.Column2 = aTransformation.get(0, 1); 579 aMatrix.Line1.Column3 = aTransformation.get(0, 2); 580 581 aMatrix.Line2.Column1 = aTransformation.get(1, 0); 582 aMatrix.Line2.Column2 = aTransformation.get(1, 1); 583 aMatrix.Line2.Column3 = aTransformation.get(1, 2); 584 585 aMatrix.Line3.Column1 = aTransformation.get(2, 0); 586 aMatrix.Line3.Column2 = aTransformation.get(2, 1); 587 aMatrix.Line3.Column3 = aTransformation.get(2, 2); 588 589 aAny <<= aMatrix; 590 591 xPropSet->setPropertyValue( 592 OUString(RTL_CONSTASCII_USTRINGPARAM("Transformation")), aAny); 593 } 594 } 595 } 596 597 ////////////////////////////////////////////////////////////////////////////// 598 599 void SdXMLShapeContext::SetStyle( bool bSupportsStyle /* = true */) 600 { 601 try 602 { 603 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY); 604 if( !xPropSet.is() ) 605 return; 606 607 do 608 { 609 XMLPropStyleContext* pDocStyle = NULL; 610 611 // set style on shape 612 if(maDrawStyleName.getLength() == 0) 613 break; 614 615 const SvXMLStyleContext* pStyle = 0L; 616 sal_Bool bAutoStyle(sal_False); 617 618 if(GetImport().GetShapeImport()->GetAutoStylesContext()) 619 pStyle = GetImport().GetShapeImport()->GetAutoStylesContext()->FindStyleChildContext(mnStyleFamily, maDrawStyleName); 620 621 if(pStyle) 622 bAutoStyle = sal_True; 623 624 if(!pStyle && GetImport().GetShapeImport()->GetStylesContext()) 625 pStyle = GetImport().GetShapeImport()->GetStylesContext()->FindStyleChildContext(mnStyleFamily, maDrawStyleName); 626 627 OUString aStyleName = maDrawStyleName; 628 uno::Reference< style::XStyle > xStyle; 629 630 if( pStyle && pStyle->ISA(XMLShapeStyleContext) ) 631 { 632 pDocStyle = PTR_CAST( XMLShapeStyleContext, pStyle ); 633 634 if( pDocStyle->GetStyle().is() ) 635 { 636 xStyle = pDocStyle->GetStyle(); 637 } 638 else 639 { 640 aStyleName = pDocStyle->GetParentName(); 641 } 642 } 643 644 if( !xStyle.is() && aStyleName.getLength() ) 645 { 646 try 647 { 648 649 uno::Reference< style::XStyleFamiliesSupplier > xFamiliesSupplier( GetImport().GetModel(), uno::UNO_QUERY ); 650 651 if( xFamiliesSupplier.is() ) 652 { 653 uno::Reference< container::XNameAccess > xFamilies( xFamiliesSupplier->getStyleFamilies() ); 654 if( xFamilies.is() ) 655 { 656 657 uno::Reference< container::XNameAccess > xFamily; 658 659 if( XML_STYLE_FAMILY_SD_PRESENTATION_ID == mnStyleFamily ) 660 { 661 aStyleName = GetImport().GetStyleDisplayName( 662 XML_STYLE_FAMILY_SD_PRESENTATION_ID, 663 aStyleName ); 664 sal_Int32 nPos = aStyleName.lastIndexOf( sal_Unicode('-') ); 665 if( -1 != nPos ) 666 { 667 OUString aFamily( aStyleName.copy( 0, nPos ) ); 668 669 xFamilies->getByName( aFamily ) >>= xFamily; 670 aStyleName = aStyleName.copy( nPos + 1 ); 671 } 672 } 673 else 674 { 675 // get graphics familie 676 xFamilies->getByName( OUString( RTL_CONSTASCII_USTRINGPARAM( "graphics" ) ) ) >>= xFamily; 677 aStyleName = GetImport().GetStyleDisplayName( 678 XML_STYLE_FAMILY_SD_GRAPHICS_ID, 679 aStyleName ); 680 } 681 682 if( xFamily.is() ) 683 xFamily->getByName( aStyleName ) >>= xStyle; 684 } 685 } 686 } 687 catch( uno::Exception& ) 688 { 689 DBG_ERROR( "could not find style for shape!" ); 690 } 691 } 692 693 if( bSupportsStyle && xStyle.is() ) 694 { 695 try 696 { 697 // set style on object 698 uno::Any aAny; 699 aAny <<= xStyle; 700 xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("Style")), aAny); 701 } 702 catch( uno::Exception& ) 703 { 704 DBG_ERROR( "could not find style for shape!" ); 705 } 706 } 707 708 // if this is an auto style, set its properties 709 if(bAutoStyle && pDocStyle) 710 { 711 // set PropertySet on object 712 pDocStyle->FillPropertySet(xPropSet); 713 } 714 715 } while(0); 716 717 // try to set text auto style 718 do 719 { 720 // set style on shape 721 if( 0 == maTextStyleName.getLength() ) 722 break; 723 724 if( NULL == GetImport().GetShapeImport()->GetAutoStylesContext()) 725 break; 726 727 const SvXMLStyleContext* pTempStyle = GetImport().GetShapeImport()->GetAutoStylesContext()->FindStyleChildContext(XML_STYLE_FAMILY_TEXT_PARAGRAPH, maTextStyleName); 728 XMLPropStyleContext* pStyle = PTR_CAST( XMLPropStyleContext, pTempStyle ); // use temp var, PTR_CAST is a bad macro, FindStyleChildContext will be called twice 729 if( pStyle == NULL ) 730 break; 731 732 // set PropertySet on object 733 pStyle->FillPropertySet(xPropSet); 734 735 } while(0); 736 } 737 catch( uno::Exception& ) 738 { 739 } 740 } 741 742 void SdXMLShapeContext::SetLayer() 743 { 744 if( maLayerName.getLength() ) 745 { 746 try 747 { 748 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY); 749 if(xPropSet.is() ) 750 { 751 uno::Any aAny; 752 aAny <<= maLayerName; 753 754 xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("LayerName")), aAny); 755 return; 756 } 757 } 758 catch( uno::Exception e ) 759 { 760 } 761 } 762 } 763 764 void SdXMLShapeContext::SetThumbnail() 765 { 766 if( 0 == maThumbnailURL.getLength() ) 767 return; 768 769 try 770 { 771 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY); 772 if( !xPropSet.is() ) 773 return; 774 775 const OUString sProperty(RTL_CONSTASCII_USTRINGPARAM("ThumbnailGraphicURL")); 776 777 uno::Reference< beans::XPropertySetInfo > xPropSetInfo( xPropSet->getPropertySetInfo() ); 778 if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName( sProperty ) ) 779 { 780 // load the thumbnail graphic and export it to a wmf stream so we can set 781 // it at the api 782 783 const OUString aInternalURL( GetImport().ResolveGraphicObjectURL( maThumbnailURL, sal_False ) ); 784 xPropSet->setPropertyValue( sProperty, uno::makeAny( aInternalURL ) ); 785 } 786 } 787 catch( uno::Exception e ) 788 { 789 } 790 } 791 792 // this is called from the parent group for each unparsed attribute in the attribute list 793 void SdXMLShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue ) 794 { 795 bool bHaveXmlId( false ); 796 if( (XML_NAMESPACE_DRAW == nPrefix) || (XML_NAMESPACE_DRAW_EXT == nPrefix) ) 797 { 798 if( IsXMLToken( rLocalName, XML_ZINDEX ) ) 799 { 800 mnZOrder = rValue.toInt32(); 801 } 802 else if( IsXMLToken( rLocalName, XML_ID ) ) 803 { 804 if (!bHaveXmlId) { maShapeId = rValue; }; 805 } 806 else if( IsXMLToken( rLocalName, XML_NAME ) ) 807 { 808 maShapeName = rValue; 809 } 810 else if( IsXMLToken( rLocalName, XML_STYLE_NAME ) ) 811 { 812 maDrawStyleName = rValue; 813 } 814 else if( IsXMLToken( rLocalName, XML_TEXT_STYLE_NAME ) ) 815 { 816 maTextStyleName = rValue; 817 } 818 else if( IsXMLToken( rLocalName, XML_LAYER ) ) 819 { 820 maLayerName = rValue; 821 } 822 else if( IsXMLToken( rLocalName, XML_TRANSFORM ) ) 823 { 824 mnTransform.SetString(rValue, GetImport().GetMM100UnitConverter()); 825 } 826 else if( IsXMLToken( rLocalName, XML_DISPLAY ) ) 827 { 828 mbVisible = IsXMLToken( rValue, XML_ALWAYS ) || IsXMLToken( rValue, XML_SCREEN ); 829 mbPrintable = IsXMLToken( rValue, XML_ALWAYS ) || IsXMLToken( rValue, XML_PRINTER ); 830 } 831 } 832 else if( XML_NAMESPACE_PRESENTATION == nPrefix ) 833 { 834 if( IsXMLToken( rLocalName, XML_USER_TRANSFORMED ) ) 835 { 836 mbIsUserTransformed = IsXMLToken( rValue, XML_TRUE ); 837 } 838 else if( IsXMLToken( rLocalName, XML_PLACEHOLDER ) ) 839 { 840 mbIsPlaceholder = IsXMLToken( rValue, XML_TRUE ); 841 if( mbIsPlaceholder ) 842 mbClearDefaultAttributes = false; 843 } 844 else if( IsXMLToken( rLocalName, XML_CLASS ) ) 845 { 846 maPresentationClass = rValue; 847 } 848 else if( IsXMLToken( rLocalName, XML_STYLE_NAME ) ) 849 { 850 maDrawStyleName = rValue; 851 mnStyleFamily = XML_STYLE_FAMILY_SD_PRESENTATION_ID; 852 } 853 } 854 else if( XML_NAMESPACE_SVG == nPrefix ) 855 { 856 if( IsXMLToken( rLocalName, XML_X ) ) 857 { 858 GetImport().GetMM100UnitConverter().convertMeasure(maPosition.X, rValue); 859 } 860 else if( IsXMLToken( rLocalName, XML_Y ) ) 861 { 862 GetImport().GetMM100UnitConverter().convertMeasure(maPosition.Y, rValue); 863 } 864 else if( IsXMLToken( rLocalName, XML_WIDTH ) ) 865 { 866 GetImport().GetMM100UnitConverter().convertMeasure(maSize.Width, rValue); 867 if( maSize.Width > 0 ) 868 maSize.Width += 1; 869 else if( maSize.Width < 0 ) 870 maSize.Width -= 1; 871 } 872 else if( IsXMLToken( rLocalName, XML_HEIGHT ) ) 873 { 874 GetImport().GetMM100UnitConverter().convertMeasure(maSize.Height, rValue); 875 if( maSize.Height > 0 ) 876 maSize.Height += 1; 877 else if( maSize.Height < 0 ) 878 maSize.Height -= 1; 879 } 880 else if( IsXMLToken( rLocalName, XML_TRANSFORM ) ) 881 { 882 // because of #85127# take svg:transform into account and hanle like 883 // draw:transform for compatibility 884 mnTransform.SetString(rValue, GetImport().GetMM100UnitConverter()); 885 } 886 887 // #i68101# 888 else if( IsXMLToken( rLocalName, XML_TITLE ) ) 889 { 890 maShapeTitle = rValue; 891 } 892 else if( IsXMLToken( rLocalName, XML_DESC ) ) 893 { 894 maShapeDescription = rValue; 895 } 896 } 897 else if( (XML_NAMESPACE_NONE == nPrefix) || (XML_NAMESPACE_XML == nPrefix) ) 898 { 899 if( IsXMLToken( rLocalName, XML_ID ) ) 900 { 901 maShapeId = rValue; 902 bHaveXmlId = true; 903 } 904 } 905 } 906 907 sal_Bool SdXMLShapeContext::isPresentationShape() const 908 { 909 if( maPresentationClass.getLength() && (const_cast<SdXMLShapeContext*>(this))->GetImport().GetShapeImport()->IsPresentationShapesSupported() ) 910 { 911 if(XML_STYLE_FAMILY_SD_PRESENTATION_ID == mnStyleFamily) 912 { 913 return sal_True; 914 } 915 916 if( IsXMLToken( maPresentationClass, XML_HEADER ) || IsXMLToken( maPresentationClass, XML_FOOTER ) || 917 IsXMLToken( maPresentationClass, XML_PAGE_NUMBER ) || IsXMLToken( maPresentationClass, XML_DATE_TIME ) ) 918 { 919 return sal_True; 920 } 921 } 922 923 return sal_False; 924 } 925 926 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 927 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 928 929 TYPEINIT1( SdXMLRectShapeContext, SdXMLShapeContext ); 930 931 SdXMLRectShapeContext::SdXMLRectShapeContext( 932 SvXMLImport& rImport, 933 sal_uInt16 nPrfx, 934 const OUString& rLocalName, 935 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 936 uno::Reference< drawing::XShapes >& rShapes, 937 sal_Bool bTemporaryShape) 938 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ), 939 mnRadius( 0L ) 940 { 941 } 942 943 ////////////////////////////////////////////////////////////////////////////// 944 945 SdXMLRectShapeContext::~SdXMLRectShapeContext() 946 { 947 } 948 949 ////////////////////////////////////////////////////////////////////////////// 950 951 // this is called from the parent group for each unparsed attribute in the attribute list 952 void SdXMLRectShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue ) 953 { 954 if( XML_NAMESPACE_DRAW == nPrefix ) 955 { 956 if( IsXMLToken( rLocalName, XML_CORNER_RADIUS ) ) 957 { 958 GetImport().GetMM100UnitConverter().convertMeasure(mnRadius, rValue); 959 return; 960 } 961 } 962 963 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue ); 964 } 965 966 ////////////////////////////////////////////////////////////////////////////// 967 968 void SdXMLRectShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList) 969 { 970 // create rectangle shape 971 AddShape("com.sun.star.drawing.RectangleShape"); 972 if(mxShape.is()) 973 { 974 // Add, set Style and properties from base shape 975 SetStyle(); 976 SetLayer(); 977 978 // set pos, size, shear and rotate 979 SetTransformation(); 980 981 if(mnRadius) 982 { 983 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY); 984 if(xPropSet.is()) 985 { 986 try 987 { 988 xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("CornerRadius")), uno::makeAny( mnRadius ) ); 989 } 990 catch( uno::Exception& ) 991 { 992 DBG_ERROR( "exception during setting of corner radius!"); 993 } 994 } 995 } 996 SdXMLShapeContext::StartElement(xAttrList); 997 } 998 } 999 1000 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1001 ////////////////////////////////////////3//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1002 1003 TYPEINIT1( SdXMLLineShapeContext, SdXMLShapeContext ); 1004 1005 SdXMLLineShapeContext::SdXMLLineShapeContext( 1006 SvXMLImport& rImport, 1007 sal_uInt16 nPrfx, 1008 const OUString& rLocalName, 1009 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 1010 uno::Reference< drawing::XShapes >& rShapes, 1011 sal_Bool bTemporaryShape) 1012 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ), 1013 mnX1( 0L ), 1014 mnY1( 0L ), 1015 mnX2( 1L ), 1016 mnY2( 1L ) 1017 { 1018 } 1019 1020 ////////////////////////////////////////////////////////////////////////////// 1021 1022 SdXMLLineShapeContext::~SdXMLLineShapeContext() 1023 { 1024 } 1025 1026 ////////////////////////////////////////////////////////////////////////////// 1027 1028 // this is called from the parent group for each unparsed attribute in the attribute list 1029 void SdXMLLineShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue ) 1030 { 1031 if( XML_NAMESPACE_SVG == nPrefix ) 1032 { 1033 if( IsXMLToken( rLocalName, XML_X1 ) ) 1034 { 1035 GetImport().GetMM100UnitConverter().convertMeasure(mnX1, rValue); 1036 return; 1037 } 1038 if( IsXMLToken( rLocalName, XML_Y1 ) ) 1039 { 1040 GetImport().GetMM100UnitConverter().convertMeasure(mnY1, rValue); 1041 return; 1042 } 1043 if( IsXMLToken( rLocalName, XML_X2 ) ) 1044 { 1045 GetImport().GetMM100UnitConverter().convertMeasure(mnX2, rValue); 1046 return; 1047 } 1048 if( IsXMLToken( rLocalName, XML_Y2 ) ) 1049 { 1050 GetImport().GetMM100UnitConverter().convertMeasure(mnY2, rValue); 1051 return; 1052 } 1053 } 1054 1055 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue ); 1056 } 1057 1058 ////////////////////////////////////////////////////////////////////////////// 1059 1060 void SdXMLLineShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList) 1061 { 1062 // #85920# use SetTransformation() to handle import of simple lines. 1063 // This is necessary to kake into account all anchor positions and 1064 // other things. All shape imports use the same import schemata now. 1065 // create necessary shape (Line Shape) 1066 AddShape("com.sun.star.drawing.PolyLineShape"); 1067 1068 if(mxShape.is()) 1069 { 1070 // Add, set Style and properties from base shape 1071 SetStyle(); 1072 SetLayer(); 1073 1074 // get sizes and offsets 1075 awt::Point aTopLeft(mnX1, mnY1); 1076 awt::Point aBottomRight(mnX2, mnY2); 1077 1078 if(mnX1 > mnX2) 1079 { 1080 aTopLeft.X = mnX2; 1081 aBottomRight.X = mnX1; 1082 } 1083 1084 if(mnY1 > mnY2) 1085 { 1086 aTopLeft.Y = mnY2; 1087 aBottomRight.Y = mnY1; 1088 } 1089 1090 // set local parameters on shape 1091 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY); 1092 if(xPropSet.is()) 1093 { 1094 drawing::PointSequenceSequence aPolyPoly(1L); 1095 drawing::PointSequence* pOuterSequence = aPolyPoly.getArray(); 1096 pOuterSequence->realloc(2L); 1097 awt::Point* pInnerSequence = pOuterSequence->getArray(); 1098 uno::Any aAny; 1099 1100 *pInnerSequence = awt::Point( mnX1 - aTopLeft.X, mnY1 - aTopLeft.Y); 1101 pInnerSequence++; 1102 *pInnerSequence = awt::Point( mnX2 - aTopLeft.X, mnY2 - aTopLeft.Y); 1103 1104 aAny <<= aPolyPoly; 1105 xPropSet->setPropertyValue( 1106 OUString(RTL_CONSTASCII_USTRINGPARAM("Geometry")), aAny); 1107 } 1108 1109 // set sizes for transformation 1110 maSize.Width = aBottomRight.X - aTopLeft.X; 1111 maSize.Height = aBottomRight.Y - aTopLeft.Y; 1112 maPosition.X = aTopLeft.X; 1113 maPosition.Y = aTopLeft.Y; 1114 1115 // set pos, size, shear and rotate and get copy of matrix 1116 SetTransformation(); 1117 1118 SdXMLShapeContext::StartElement(xAttrList); 1119 } 1120 } 1121 1122 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1123 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1124 1125 TYPEINIT1( SdXMLEllipseShapeContext, SdXMLShapeContext ); 1126 1127 SdXMLEllipseShapeContext::SdXMLEllipseShapeContext( 1128 SvXMLImport& rImport, 1129 sal_uInt16 nPrfx, 1130 const OUString& rLocalName, 1131 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 1132 uno::Reference< drawing::XShapes >& rShapes, 1133 sal_Bool bTemporaryShape) 1134 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ), 1135 mnCX( 0L ), 1136 mnCY( 0L ), 1137 mnRX( 1L ), 1138 mnRY( 1L ), 1139 meKind( drawing::CircleKind_FULL ), 1140 mnStartAngle( 0 ), 1141 mnEndAngle( 0 ) 1142 { 1143 } 1144 1145 ////////////////////////////////////////////////////////////////////////////// 1146 1147 SdXMLEllipseShapeContext::~SdXMLEllipseShapeContext() 1148 { 1149 } 1150 1151 ////////////////////////////////////////////////////////////////////////////// 1152 1153 // this is called from the parent group for each unparsed attribute in the attribute list 1154 void SdXMLEllipseShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue ) 1155 { 1156 if( XML_NAMESPACE_SVG == nPrefix ) 1157 { 1158 if( IsXMLToken( rLocalName, XML_RX ) ) 1159 { 1160 GetImport().GetMM100UnitConverter().convertMeasure(mnRX, rValue); 1161 return; 1162 } 1163 if( IsXMLToken( rLocalName, XML_RY ) ) 1164 { 1165 GetImport().GetMM100UnitConverter().convertMeasure(mnRY, rValue); 1166 return; 1167 } 1168 if( IsXMLToken( rLocalName, XML_CX ) ) 1169 { 1170 GetImport().GetMM100UnitConverter().convertMeasure(mnCX, rValue); 1171 return; 1172 } 1173 if( IsXMLToken( rLocalName, XML_CY ) ) 1174 { 1175 GetImport().GetMM100UnitConverter().convertMeasure(mnCY, rValue); 1176 return; 1177 } 1178 if( IsXMLToken( rLocalName, XML_R ) ) 1179 { 1180 // single radius, it's a circle and both radii are the same 1181 GetImport().GetMM100UnitConverter().convertMeasure(mnRX, rValue); 1182 mnRY = mnRX; 1183 return; 1184 } 1185 } 1186 else if( XML_NAMESPACE_DRAW == nPrefix ) 1187 { 1188 if( IsXMLToken( rLocalName, XML_KIND ) ) 1189 { 1190 sal_uInt16 eKind; 1191 if( SvXMLUnitConverter::convertEnum( eKind, rValue, aXML_CircleKind_EnumMap ) ) 1192 { 1193 meKind = eKind; 1194 } 1195 return; 1196 } 1197 if( IsXMLToken( rLocalName, XML_START_ANGLE ) ) 1198 { 1199 double dStartAngle; 1200 if( SvXMLUnitConverter::convertDouble( dStartAngle, rValue ) ) 1201 mnStartAngle = (sal_Int32)(dStartAngle * 100.0); 1202 return; 1203 } 1204 if( IsXMLToken( rLocalName, XML_END_ANGLE ) ) 1205 { 1206 double dEndAngle; 1207 if( SvXMLUnitConverter::convertDouble( dEndAngle, rValue ) ) 1208 mnEndAngle = (sal_Int32)(dEndAngle * 100.0); 1209 return; 1210 } 1211 } 1212 1213 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue ); 1214 } 1215 1216 ////////////////////////////////////////////////////////////////////////////// 1217 1218 void SdXMLEllipseShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList) 1219 { 1220 // create rectangle shape 1221 AddShape("com.sun.star.drawing.EllipseShape"); 1222 if(mxShape.is()) 1223 { 1224 // Add, set Style and properties from base shape 1225 SetStyle(); 1226 SetLayer(); 1227 1228 // set pos, size, shear and rotate 1229 SetTransformation(); 1230 1231 if( meKind != drawing::CircleKind_FULL ) 1232 { 1233 uno::Reference< beans::XPropertySet > xPropSet( mxShape, uno::UNO_QUERY ); 1234 if( xPropSet.is() ) 1235 { 1236 uno::Any aAny; 1237 aAny <<= (drawing::CircleKind)meKind; 1238 xPropSet->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("CircleKind")), aAny ); 1239 1240 aAny <<= mnStartAngle; 1241 xPropSet->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("CircleStartAngle")), aAny ); 1242 1243 aAny <<= mnEndAngle; 1244 xPropSet->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("CircleEndAngle")), aAny ); 1245 } 1246 } 1247 1248 SdXMLShapeContext::StartElement(xAttrList); 1249 } 1250 } 1251 1252 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1253 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1254 1255 TYPEINIT1( SdXMLPolygonShapeContext, SdXMLShapeContext ); 1256 1257 SdXMLPolygonShapeContext::SdXMLPolygonShapeContext( 1258 SvXMLImport& rImport, 1259 sal_uInt16 nPrfx, 1260 const OUString& rLocalName, 1261 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 1262 uno::Reference< drawing::XShapes >& rShapes, sal_Bool bClosed, sal_Bool bTemporaryShape) 1263 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ), 1264 mbClosed( bClosed ) 1265 { 1266 } 1267 1268 ////////////////////////////////////////////////////////////////////////////// 1269 1270 // this is called from the parent group for each unparsed attribute in the attribute list 1271 void SdXMLPolygonShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue ) 1272 { 1273 if( XML_NAMESPACE_SVG == nPrefix ) 1274 { 1275 if( IsXMLToken( rLocalName, XML_VIEWBOX ) ) 1276 { 1277 maViewBox = rValue; 1278 return; 1279 } 1280 } 1281 else if( XML_NAMESPACE_DRAW == nPrefix ) 1282 { 1283 if( IsXMLToken( rLocalName, XML_POINTS ) ) 1284 { 1285 maPoints = rValue; 1286 return; 1287 } 1288 } 1289 1290 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue ); 1291 } 1292 1293 ////////////////////////////////////////////////////////////////////////////// 1294 1295 SdXMLPolygonShapeContext::~SdXMLPolygonShapeContext() 1296 { 1297 } 1298 1299 ////////////////////////////////////////////////////////////////////////////// 1300 1301 void SdXMLPolygonShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList) 1302 { 1303 // Add, set Style and properties from base shape 1304 if(mbClosed) 1305 AddShape("com.sun.star.drawing.PolyPolygonShape"); 1306 else 1307 AddShape("com.sun.star.drawing.PolyLineShape"); 1308 1309 if( mxShape.is() ) 1310 { 1311 SetStyle(); 1312 SetLayer(); 1313 1314 // set local parameters on shape 1315 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY); 1316 if(xPropSet.is()) 1317 { 1318 // set polygon 1319 if(maPoints.getLength() && maViewBox.getLength()) 1320 { 1321 SdXMLImExViewBox aViewBox(maViewBox, GetImport().GetMM100UnitConverter()); 1322 awt::Size aSize(aViewBox.GetWidth(), aViewBox.GetHeight()); 1323 if (maSize.Width != 0 && maSize.Height !=0) 1324 { 1325 aSize = maSize; 1326 } 1327 awt::Point aPosition(aViewBox.GetX(), aViewBox.GetY()); 1328 SdXMLImExPointsElement aPoints(maPoints, aViewBox, 1329 aPosition, aSize, GetImport().GetMM100UnitConverter()); 1330 1331 uno::Any aAny; 1332 aAny <<= aPoints.GetPointSequenceSequence(); 1333 xPropSet->setPropertyValue( 1334 OUString(RTL_CONSTASCII_USTRINGPARAM("Geometry")), aAny); 1335 } 1336 } 1337 1338 // set pos, size, shear and rotate and get copy of matrix 1339 SetTransformation(); 1340 1341 SdXMLShapeContext::StartElement(xAttrList); 1342 } 1343 } 1344 1345 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1346 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1347 1348 TYPEINIT1( SdXMLPathShapeContext, SdXMLShapeContext ); 1349 1350 SdXMLPathShapeContext::SdXMLPathShapeContext( 1351 SvXMLImport& rImport, 1352 sal_uInt16 nPrfx, 1353 const OUString& rLocalName, 1354 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 1355 uno::Reference< drawing::XShapes >& rShapes, 1356 sal_Bool bTemporaryShape) 1357 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ), 1358 mbClosed( sal_True ) 1359 { 1360 } 1361 1362 ////////////////////////////////////////////////////////////////////////////// 1363 1364 SdXMLPathShapeContext::~SdXMLPathShapeContext() 1365 { 1366 } 1367 1368 ////////////////////////////////////////////////////////////////////////////// 1369 1370 // this is called from the parent group for each unparsed attribute in the attribute list 1371 void SdXMLPathShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue ) 1372 { 1373 if( XML_NAMESPACE_SVG == nPrefix ) 1374 { 1375 if( IsXMLToken( rLocalName, XML_VIEWBOX ) ) 1376 { 1377 maViewBox = rValue; 1378 return; 1379 } 1380 else if( IsXMLToken( rLocalName, XML_D ) ) 1381 { 1382 maD = rValue; 1383 return; 1384 } 1385 } 1386 1387 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue ); 1388 } 1389 1390 ////////////////////////////////////////////////////////////////////////////// 1391 1392 void SdXMLPathShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList) 1393 { 1394 // create polygon shape 1395 if(maD.getLength()) 1396 { 1397 // prepare some of the parameters 1398 SdXMLImExViewBox aViewBox(maViewBox, GetImport().GetMM100UnitConverter()); 1399 awt::Size aSize(aViewBox.GetWidth(), aViewBox.GetHeight()); 1400 awt::Point aPosition(aViewBox.GetX(), aViewBox.GetY()); 1401 if (maSize.Width != 0 && maSize.Height !=0) 1402 { 1403 aSize = maSize; 1404 } 1405 SdXMLImExSvgDElement aPoints(maD, aViewBox, 1406 aPosition, aSize, GetImport().GetMM100UnitConverter()); 1407 1408 const char* pService; 1409 // now create shape 1410 if(aPoints.IsCurve()) 1411 { 1412 if(aPoints.IsClosed()) 1413 { 1414 pService = "com.sun.star.drawing.ClosedBezierShape"; 1415 } 1416 else 1417 { 1418 pService = "com.sun.star.drawing.OpenBezierShape"; 1419 } 1420 } 1421 else 1422 { 1423 if(aPoints.IsClosed()) 1424 { 1425 pService = "com.sun.star.drawing.PolyPolygonShape"; 1426 } 1427 else 1428 { 1429 pService = "com.sun.star.drawing.PolyLineShape"; 1430 } 1431 } 1432 1433 // Add, set Style and properties from base shape 1434 AddShape(pService); 1435 1436 // #89344# test for mxShape.is() and not for mxShapes.is() to support 1437 // shape import helper classes WITHOUT XShapes (member mxShapes). This 1438 // is used by the writer. 1439 if( mxShape.is() ) 1440 { 1441 SetStyle(); 1442 SetLayer(); 1443 1444 // set local parameters on shape 1445 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY); 1446 if(xPropSet.is()) 1447 { 1448 uno::Any aAny; 1449 1450 // set svg:d 1451 if(maD.getLength()) 1452 { 1453 if(aPoints.IsCurve()) 1454 { 1455 drawing::PolyPolygonBezierCoords aSourcePolyPolygon( 1456 aPoints.GetPointSequenceSequence(), 1457 aPoints.GetFlagSequenceSequence()); 1458 1459 aAny <<= aSourcePolyPolygon; 1460 xPropSet->setPropertyValue( 1461 OUString(RTL_CONSTASCII_USTRINGPARAM("Geometry")), aAny); 1462 } 1463 else 1464 { 1465 aAny <<= aPoints.GetPointSequenceSequence(); 1466 xPropSet->setPropertyValue( 1467 OUString(RTL_CONSTASCII_USTRINGPARAM("Geometry")), aAny); 1468 } 1469 } 1470 } 1471 1472 // set pos, size, shear and rotate 1473 SetTransformation(); 1474 1475 SdXMLShapeContext::StartElement(xAttrList); 1476 } 1477 } 1478 } 1479 1480 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1481 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1482 1483 TYPEINIT1( SdXMLTextBoxShapeContext, SdXMLShapeContext ); 1484 1485 SdXMLTextBoxShapeContext::SdXMLTextBoxShapeContext( 1486 SvXMLImport& rImport, 1487 sal_uInt16 nPrfx, 1488 const OUString& rLocalName, 1489 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 1490 uno::Reference< drawing::XShapes >& rShapes, 1491 sal_Bool bTemporaryShape) 1492 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ), 1493 mnRadius(0) 1494 { 1495 } 1496 1497 ////////////////////////////////////////////////////////////////////////////// 1498 1499 SdXMLTextBoxShapeContext::~SdXMLTextBoxShapeContext() 1500 { 1501 } 1502 1503 ////////////////////////////////////////////////////////////////////////////// 1504 1505 // this is called from the parent group for each unparsed attribute in the attribute list 1506 void SdXMLTextBoxShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue ) 1507 { 1508 if( XML_NAMESPACE_DRAW == nPrefix ) 1509 { 1510 if( IsXMLToken( rLocalName, XML_CORNER_RADIUS ) ) 1511 { 1512 GetImport().GetMM100UnitConverter().convertMeasure(mnRadius, rValue); 1513 return; 1514 } 1515 } 1516 1517 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue ); 1518 } 1519 1520 ////////////////////////////////////////////////////////////////////////////// 1521 1522 void SdXMLTextBoxShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>&) 1523 { 1524 // create textbox shape 1525 sal_Bool bIsPresShape = sal_False; 1526 bool bClearText = false; 1527 1528 const char *pService = NULL; 1529 1530 if( isPresentationShape() ) 1531 { 1532 // check if the current document supports presentation shapes 1533 if( GetImport().GetShapeImport()->IsPresentationShapesSupported() ) 1534 { 1535 if( IsXMLToken( maPresentationClass, XML_PRESENTATION_SUBTITLE )) 1536 { 1537 // XmlShapeTypePresSubtitleShape 1538 pService = "com.sun.star.presentation.SubtitleShape"; 1539 } 1540 else if( IsXMLToken( maPresentationClass, XML_PRESENTATION_OUTLINE ) ) 1541 { 1542 // XmlShapeTypePresOutlinerShape 1543 pService = "com.sun.star.presentation.OutlinerShape"; 1544 } 1545 else if( IsXMLToken( maPresentationClass, XML_PRESENTATION_NOTES ) ) 1546 { 1547 // XmlShapeTypePresNotesShape 1548 pService = "com.sun.star.presentation.NotesShape"; 1549 } 1550 else if( IsXMLToken( maPresentationClass, XML_HEADER ) ) 1551 { 1552 // XmlShapeTypePresHeaderShape 1553 pService = "com.sun.star.presentation.HeaderShape"; 1554 bClearText = true; 1555 } 1556 else if( IsXMLToken( maPresentationClass, XML_FOOTER ) ) 1557 { 1558 // XmlShapeTypePresFooterShape 1559 pService = "com.sun.star.presentation.FooterShape"; 1560 bClearText = true; 1561 } 1562 else if( IsXMLToken( maPresentationClass, XML_PAGE_NUMBER ) ) 1563 { 1564 // XmlShapeTypePresSlideNumberShape 1565 pService = "com.sun.star.presentation.SlideNumberShape"; 1566 bClearText = true; 1567 } 1568 else if( IsXMLToken( maPresentationClass, XML_DATE_TIME ) ) 1569 { 1570 // XmlShapeTypePresDateTimeShape 1571 pService = "com.sun.star.presentation.DateTimeShape"; 1572 bClearText = true; 1573 } 1574 else // IsXMLToken( maPresentationClass, XML_PRESENTATION_TITLE ) ) 1575 { 1576 // XmlShapeTypePresTitleTextShape 1577 pService = "com.sun.star.presentation.TitleTextShape"; 1578 } 1579 bIsPresShape = sal_True; 1580 } 1581 } 1582 1583 if( NULL == pService ) 1584 { 1585 // normal text shape 1586 pService = "com.sun.star.drawing.TextShape"; 1587 } 1588 1589 // Add, set Style and properties from base shape 1590 AddShape(pService); 1591 1592 if( mxShape.is() ) 1593 { 1594 SetStyle(); 1595 SetLayer(); 1596 1597 if(bIsPresShape) 1598 { 1599 uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY); 1600 if(xProps.is()) 1601 { 1602 uno::Reference< beans::XPropertySetInfo > xPropsInfo( xProps->getPropertySetInfo() ); 1603 if( xPropsInfo.is() ) 1604 { 1605 if( !mbIsPlaceholder && xPropsInfo->hasPropertyByName(OUString(RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") ))) 1606 xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") ), ::cppu::bool2any( sal_False ) ); 1607 1608 if( mbIsUserTransformed && xPropsInfo->hasPropertyByName(OUString(RTL_CONSTASCII_USTRINGPARAM("IsPlaceholderDependent") ))) 1609 xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("IsPlaceholderDependent") ), ::cppu::bool2any( sal_False ) ); 1610 } 1611 } 1612 } 1613 1614 if( bClearText ) 1615 { 1616 uno::Reference< text::XText > xText( mxShape, uno::UNO_QUERY ); 1617 OUString aEmpty; 1618 xText->setString( aEmpty ); 1619 } 1620 1621 // set parameters on shape 1622 //A AW->CL: Eventually You need to strip scale and translate from the transformation 1623 //A to reach the same goal again. 1624 //A if(!bIsPresShape || mbIsUserTransformed) 1625 //A { 1626 //A // set pos and size on shape, this should remove binding 1627 //A // to pres object on masterpage 1628 //A SetSizeAndPosition(); 1629 //A } 1630 1631 // set pos, size, shear and rotate 1632 SetTransformation(); 1633 1634 if(mnRadius) 1635 { 1636 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY); 1637 if(xPropSet.is()) 1638 { 1639 try 1640 { 1641 xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("CornerRadius")), uno::makeAny( mnRadius ) ); 1642 } 1643 catch( uno::Exception& ) 1644 { 1645 DBG_ERROR( "exception during setting of corner radius!"); 1646 } 1647 } 1648 } 1649 1650 SdXMLShapeContext::StartElement(mxAttrList); 1651 } 1652 } 1653 1654 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1655 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1656 1657 TYPEINIT1( SdXMLControlShapeContext, SdXMLShapeContext ); 1658 1659 SdXMLControlShapeContext::SdXMLControlShapeContext( 1660 SvXMLImport& rImport, 1661 sal_uInt16 nPrfx, 1662 const OUString& rLocalName, 1663 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 1664 uno::Reference< drawing::XShapes >& rShapes, 1665 sal_Bool bTemporaryShape) 1666 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ) 1667 { 1668 } 1669 1670 ////////////////////////////////////////////////////////////////////////////// 1671 1672 SdXMLControlShapeContext::~SdXMLControlShapeContext() 1673 { 1674 } 1675 1676 ////////////////////////////////////////////////////////////////////////////// 1677 1678 // this is called from the parent group for each unparsed attribute in the attribute list 1679 void SdXMLControlShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue ) 1680 { 1681 if( XML_NAMESPACE_DRAW == nPrefix ) 1682 { 1683 if( IsXMLToken( rLocalName, XML_CONTROL ) ) 1684 { 1685 maFormId = rValue; 1686 return; 1687 } 1688 } 1689 1690 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue ); 1691 } 1692 1693 void SdXMLControlShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList) 1694 { 1695 // create Control shape 1696 // add, set style and properties from base shape 1697 AddShape("com.sun.star.drawing.ControlShape"); 1698 if( mxShape.is() ) 1699 { 1700 DBG_ASSERT( maFormId.getLength(), "draw:control without a form:id attribute!" ); 1701 if( maFormId.getLength() ) 1702 { 1703 #ifndef SVX_LIGHT 1704 if( GetImport().IsFormsSupported() ) 1705 { 1706 uno::Reference< awt::XControlModel > xControlModel( GetImport().GetFormImport()->lookupControl( maFormId ), uno::UNO_QUERY ); 1707 if( xControlModel.is() ) 1708 { 1709 uno::Reference< drawing::XControlShape > xControl( mxShape, uno::UNO_QUERY ); 1710 if( xControl.is() ) 1711 xControl->setControl( xControlModel ); 1712 1713 } 1714 } 1715 #endif // #ifndef SVX_LIGHT 1716 } 1717 1718 SetStyle(); 1719 SetLayer(); 1720 1721 // set pos, size, shear and rotate 1722 SetTransformation(); 1723 1724 SdXMLShapeContext::StartElement(xAttrList); 1725 } 1726 } 1727 1728 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1729 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1730 1731 TYPEINIT1( SdXMLConnectorShapeContext, SdXMLShapeContext ); 1732 1733 SdXMLConnectorShapeContext::SdXMLConnectorShapeContext( 1734 SvXMLImport& rImport, 1735 sal_uInt16 nPrfx, 1736 const OUString& rLocalName, 1737 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 1738 uno::Reference< drawing::XShapes >& rShapes, 1739 sal_Bool bTemporaryShape) 1740 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ), 1741 maStart(0,0), 1742 maEnd(1,1), 1743 mnType( (sal_uInt16)drawing::ConnectorType_STANDARD ), 1744 mnStartGlueId(-1), 1745 mnEndGlueId(-1), 1746 mnDelta1(0), 1747 mnDelta2(0), 1748 mnDelta3(0) 1749 { 1750 } 1751 1752 ////////////////////////////////////////////////////////////////////////////// 1753 1754 SdXMLConnectorShapeContext::~SdXMLConnectorShapeContext() 1755 { 1756 } 1757 1758 ////////////////////////////////////////////////////////////////////////////// 1759 1760 // this is called from the parent group for each unparsed attribute in the attribute list 1761 void SdXMLConnectorShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue ) 1762 { 1763 switch( nPrefix ) 1764 { 1765 case XML_NAMESPACE_DRAW: 1766 { 1767 if( IsXMLToken( rLocalName, XML_START_SHAPE ) ) 1768 { 1769 maStartShapeId = rValue; 1770 return; 1771 } 1772 if( IsXMLToken( rLocalName, XML_START_GLUE_POINT ) ) 1773 { 1774 mnStartGlueId = rValue.toInt32(); 1775 return; 1776 } 1777 if( IsXMLToken( rLocalName, XML_END_SHAPE ) ) 1778 { 1779 maEndShapeId = rValue; 1780 return; 1781 } 1782 if( IsXMLToken( rLocalName, XML_END_GLUE_POINT ) ) 1783 { 1784 mnEndGlueId = rValue.toInt32(); 1785 return; 1786 } 1787 if( IsXMLToken( rLocalName, XML_LINE_SKEW ) ) 1788 { 1789 SvXMLTokenEnumerator aTokenEnum( rValue ); 1790 OUString aToken; 1791 if( aTokenEnum.getNextToken( aToken ) ) 1792 { 1793 GetImport().GetMM100UnitConverter().convertMeasure(mnDelta1, aToken); 1794 if( aTokenEnum.getNextToken( aToken ) ) 1795 { 1796 GetImport().GetMM100UnitConverter().convertMeasure(mnDelta2, aToken); 1797 if( aTokenEnum.getNextToken( aToken ) ) 1798 { 1799 GetImport().GetMM100UnitConverter().convertMeasure(mnDelta3, aToken); 1800 } 1801 } 1802 } 1803 return; 1804 } 1805 if( IsXMLToken( rLocalName, XML_TYPE ) ) 1806 { 1807 SvXMLUnitConverter::convertEnum( mnType, rValue, aXML_ConnectionKind_EnumMap ); 1808 return; 1809 } 1810 } 1811 case XML_NAMESPACE_SVG: 1812 { 1813 if( IsXMLToken( rLocalName, XML_X1 ) ) 1814 { 1815 GetImport().GetMM100UnitConverter().convertMeasure(maStart.X, rValue); 1816 return; 1817 } 1818 if( IsXMLToken( rLocalName, XML_Y1 ) ) 1819 { 1820 GetImport().GetMM100UnitConverter().convertMeasure(maStart.Y, rValue); 1821 return; 1822 } 1823 if( IsXMLToken( rLocalName, XML_X2 ) ) 1824 { 1825 GetImport().GetMM100UnitConverter().convertMeasure(maEnd.X, rValue); 1826 return; 1827 } 1828 if( IsXMLToken( rLocalName, XML_Y2 ) ) 1829 { 1830 GetImport().GetMM100UnitConverter().convertMeasure(maEnd.Y, rValue); 1831 return; 1832 } 1833 if( IsXMLToken( rLocalName, XML_D ) ) 1834 { 1835 SdXMLImExViewBox aViewBox( 0, 0, 1, 1 ); 1836 awt::Point aPoint( 0, 0 ); 1837 awt::Size aSize( 1, 1 ); 1838 1839 SdXMLImExSvgDElement aPoints( rValue, aViewBox, 1840 aPoint, aSize, GetImport().GetMM100UnitConverter() ); 1841 1842 if ( aPoints.IsCurve() ) 1843 { 1844 drawing::PolyPolygonBezierCoords aSourcePolyPolygon( 1845 aPoints.GetPointSequenceSequence(), 1846 aPoints.GetFlagSequenceSequence()); 1847 maPath <<= aSourcePolyPolygon; 1848 } 1849 else 1850 { 1851 const drawing::PointSequenceSequence& rOuterSeq = aPoints.GetPointSequenceSequence(); 1852 drawing::FlagSequenceSequence aFlagSeqSeq( rOuterSeq.getLength() ); 1853 for ( int a = 0; a < rOuterSeq.getLength(); a++ ) 1854 aFlagSeqSeq[ a ] = drawing::FlagSequence( rOuterSeq[ a ].getLength() ); 1855 1856 drawing::PolyPolygonBezierCoords aSourcePolyPolygon( 1857 aPoints.GetPointSequenceSequence(), 1858 aFlagSeqSeq ); 1859 maPath <<= aSourcePolyPolygon; 1860 } 1861 } 1862 } 1863 } 1864 1865 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue ); 1866 } 1867 1868 ////////////////////////////////////////////////////////////////////////////// 1869 1870 void SdXMLConnectorShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList) 1871 { 1872 // #107928# 1873 // For security reasons, do not add empty connectors. There may have been an error in EA2 1874 // that created empty, far set off connectors (e.g. 63 meters below top of document). This 1875 // is not guaranteed, but it's definitely safe to not add empty connectors. 1876 sal_Bool bDoAdd(sal_True); 1877 1878 if( 0 == maStartShapeId.getLength() 1879 && 0 == maEndShapeId.getLength() 1880 && maStart.X == maEnd.X 1881 && maStart.Y == maEnd.Y 1882 && 0 == mnDelta1 1883 && 0 == mnDelta2 1884 && 0 == mnDelta3 1885 ) 1886 { 1887 bDoAdd = sal_False; 1888 } 1889 1890 if(bDoAdd) 1891 { 1892 // create Connector shape 1893 // add, set style and properties from base shape 1894 AddShape("com.sun.star.drawing.ConnectorShape"); 1895 if(mxShape.is()) 1896 { 1897 // add connection ids 1898 if( maStartShapeId.getLength() ) 1899 GetImport().GetShapeImport()->addShapeConnection( mxShape, sal_True, maStartShapeId, mnStartGlueId ); 1900 if( maEndShapeId.getLength() ) 1901 GetImport().GetShapeImport()->addShapeConnection( mxShape, sal_False, maEndShapeId, mnEndGlueId ); 1902 1903 uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY ); 1904 if( xProps.is() ) 1905 { 1906 uno::Any aAny; 1907 aAny <<= maStart; 1908 xProps->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("StartPosition")), aAny); 1909 1910 aAny <<= maEnd; 1911 xProps->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("EndPosition")), aAny ); 1912 1913 aAny <<= (drawing::ConnectorType)mnType; 1914 xProps->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("EdgeKind")), aAny ); 1915 1916 aAny <<= mnDelta1; 1917 xProps->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("EdgeLine1Delta")), aAny ); 1918 1919 aAny <<= mnDelta2; 1920 xProps->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("EdgeLine2Delta")), aAny ); 1921 1922 aAny <<= mnDelta3; 1923 xProps->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("EdgeLine3Delta")), aAny ); 1924 } 1925 SetStyle(); 1926 SetLayer(); 1927 1928 if ( maPath.hasValue() ) 1929 { 1930 // --> OD #i115492# 1931 // Ignore svg:d attribute for text documents created by OpenOffice.org 1932 // versions before OOo 3.3, because these OOo versions are storing 1933 // svg:d values not using the correct unit. 1934 bool bApplySVGD( true ); 1935 if ( uno::Reference< text::XTextDocument >(GetImport().GetModel(), uno::UNO_QUERY).is() ) 1936 { 1937 sal_Int32 nUPD( 0 ); 1938 sal_Int32 nBuild( 0 ); 1939 const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild ); 1940 if ( GetImport().IsTextDocInOOoFileFormat() || 1941 ( bBuildIdFound && 1942 ( ( nUPD == 641 ) || ( nUPD == 645 ) || // prior OOo 2.0 1943 ( nUPD == 680 ) || // OOo 2.x 1944 ( nUPD == 300 ) || // OOo 3.0 - OOo 3.0.1 1945 ( nUPD == 310 ) || // OOo 3.1 - OOo 3.1.1 1946 ( nUPD == 320 ) ) ) ) // OOo 3.2 - OOo 3.2.1 1947 { 1948 bApplySVGD = false; 1949 } 1950 } 1951 1952 if ( bApplySVGD ) 1953 { 1954 xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("PolyPolygonBezier") ), maPath ); 1955 } 1956 // <-- 1957 } 1958 1959 SdXMLShapeContext::StartElement(xAttrList); 1960 } 1961 } 1962 } 1963 1964 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1965 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1966 1967 TYPEINIT1( SdXMLMeasureShapeContext, SdXMLShapeContext ); 1968 1969 SdXMLMeasureShapeContext::SdXMLMeasureShapeContext( 1970 SvXMLImport& rImport, 1971 sal_uInt16 nPrfx, 1972 const OUString& rLocalName, 1973 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 1974 uno::Reference< drawing::XShapes >& rShapes, 1975 sal_Bool bTemporaryShape) 1976 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ), 1977 maStart(0,0), 1978 maEnd(1,1) 1979 { 1980 } 1981 1982 ////////////////////////////////////////////////////////////////////////////// 1983 1984 SdXMLMeasureShapeContext::~SdXMLMeasureShapeContext() 1985 { 1986 } 1987 1988 // this is called from the parent group for each unparsed attribute in the attribute list 1989 void SdXMLMeasureShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue ) 1990 { 1991 switch( nPrefix ) 1992 { 1993 case XML_NAMESPACE_SVG: 1994 { 1995 if( IsXMLToken( rLocalName, XML_X1 ) ) 1996 { 1997 GetImport().GetMM100UnitConverter().convertMeasure(maStart.X, rValue); 1998 return; 1999 } 2000 if( IsXMLToken( rLocalName, XML_Y1 ) ) 2001 { 2002 GetImport().GetMM100UnitConverter().convertMeasure(maStart.Y, rValue); 2003 return; 2004 } 2005 if( IsXMLToken( rLocalName, XML_X2 ) ) 2006 { 2007 GetImport().GetMM100UnitConverter().convertMeasure(maEnd.X, rValue); 2008 return; 2009 } 2010 if( IsXMLToken( rLocalName, XML_Y2 ) ) 2011 { 2012 GetImport().GetMM100UnitConverter().convertMeasure(maEnd.Y, rValue); 2013 return; 2014 } 2015 } 2016 } 2017 2018 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue ); 2019 } 2020 2021 ////////////////////////////////////////////////////////////////////////////// 2022 2023 void SdXMLMeasureShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList) 2024 { 2025 // create Measure shape 2026 // add, set style and properties from base shape 2027 AddShape("com.sun.star.drawing.MeasureShape"); 2028 if(mxShape.is()) 2029 { 2030 SetStyle(); 2031 SetLayer(); 2032 2033 uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY ); 2034 if( xProps.is() ) 2035 { 2036 uno::Any aAny; 2037 aAny <<= maStart; 2038 xProps->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("StartPosition")), aAny); 2039 2040 aAny <<= maEnd; 2041 xProps->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("EndPosition")), aAny ); 2042 } 2043 2044 // delete pre created fields 2045 uno::Reference< text::XText > xText( mxShape, uno::UNO_QUERY ); 2046 if( xText.is() ) 2047 { 2048 const OUString aEmpty( RTL_CONSTASCII_USTRINGPARAM( " " ) ); 2049 xText->setString( aEmpty ); 2050 } 2051 2052 SdXMLShapeContext::StartElement(xAttrList); 2053 } 2054 } 2055 2056 void SdXMLMeasureShapeContext::EndElement() 2057 { 2058 do 2059 { 2060 // delete pre created fields 2061 uno::Reference< text::XText > xText( mxShape, uno::UNO_QUERY ); 2062 if( !xText.is() ) 2063 break; 2064 2065 uno::Reference< text::XTextCursor > xCursor( xText->createTextCursor() ); 2066 if( !xCursor.is() ) 2067 break; 2068 2069 const OUString aEmpty; 2070 xCursor->collapseToStart(); 2071 xCursor->goRight( 1, sal_True ); 2072 xCursor->setString( aEmpty ); 2073 } 2074 while(0); 2075 2076 SdXMLShapeContext::EndElement(); 2077 } 2078 2079 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2080 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2081 2082 TYPEINIT1( SdXMLPageShapeContext, SdXMLShapeContext ); 2083 2084 SdXMLPageShapeContext::SdXMLPageShapeContext( 2085 SvXMLImport& rImport, 2086 sal_uInt16 nPrfx, 2087 const OUString& rLocalName, 2088 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 2089 uno::Reference< drawing::XShapes >& rShapes, 2090 sal_Bool bTemporaryShape) 2091 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ), mnPageNumber(0) 2092 { 2093 mbClearDefaultAttributes = false; 2094 } 2095 2096 ////////////////////////////////////////////////////////////////////////////// 2097 2098 SdXMLPageShapeContext::~SdXMLPageShapeContext() 2099 { 2100 } 2101 2102 ////////////////////////////////////////////////////////////////////////////// 2103 2104 // this is called from the parent group for each unparsed attribute in the attribute list 2105 void SdXMLPageShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue ) 2106 { 2107 if( XML_NAMESPACE_DRAW == nPrefix ) 2108 { 2109 if( IsXMLToken( rLocalName, XML_PAGE_NUMBER ) ) 2110 { 2111 mnPageNumber = rValue.toInt32(); 2112 return; 2113 } 2114 } 2115 2116 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue ); 2117 } 2118 2119 ////////////////////////////////////////////////////////////////////////////// 2120 2121 void SdXMLPageShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList) 2122 { 2123 // create Page shape 2124 // add, set style and properties from base shape 2125 2126 // #86163# take into account which type of PageShape needs to 2127 // be constructed. It's an pres shape if presentation:XML_CLASS == XML_PRESENTATION_PAGE. 2128 sal_Bool bIsPresentation = maPresentationClass.getLength() && 2129 GetImport().GetShapeImport()->IsPresentationShapesSupported(); 2130 2131 uno::Reference< lang::XServiceInfo > xInfo( mxShapes, uno::UNO_QUERY ); 2132 const sal_Bool bIsOnHandoutPage = xInfo.is() && xInfo->supportsService( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.HandoutMasterPage")) ); 2133 2134 if( bIsOnHandoutPage ) 2135 { 2136 AddShape("com.sun.star.presentation.HandoutShape"); 2137 } 2138 else 2139 { 2140 if(bIsPresentation && !IsXMLToken( maPresentationClass, XML_PRESENTATION_PAGE ) ) 2141 { 2142 bIsPresentation = sal_False; 2143 } 2144 2145 if(bIsPresentation) 2146 { 2147 AddShape("com.sun.star.presentation.PageShape"); 2148 } 2149 else 2150 { 2151 AddShape("com.sun.star.drawing.PageShape"); 2152 } 2153 } 2154 2155 if(mxShape.is()) 2156 { 2157 SetStyle(); 2158 SetLayer(); 2159 2160 // set pos, size, shear and rotate 2161 SetTransformation(); 2162 2163 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY); 2164 if(xPropSet.is()) 2165 { 2166 uno::Reference< beans::XPropertySetInfo > xPropSetInfo( xPropSet->getPropertySetInfo() ); 2167 const OUString aPageNumberStr(RTL_CONSTASCII_USTRINGPARAM("PageNumber")); 2168 if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName(aPageNumberStr)) 2169 xPropSet->setPropertyValue(aPageNumberStr, uno::makeAny( mnPageNumber )); 2170 } 2171 2172 SdXMLShapeContext::StartElement(xAttrList); 2173 } 2174 } 2175 2176 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2177 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2178 2179 TYPEINIT1( SdXMLCaptionShapeContext, SdXMLShapeContext ); 2180 2181 SdXMLCaptionShapeContext::SdXMLCaptionShapeContext( 2182 SvXMLImport& rImport, 2183 sal_uInt16 nPrfx, 2184 const OUString& rLocalName, 2185 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 2186 uno::Reference< drawing::XShapes >& rShapes, 2187 sal_Bool bTemporaryShape) 2188 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ), 2189 // #86616# for correct edge rounding import mnRadius needs to be initialized 2190 mnRadius( 0L ) 2191 { 2192 } 2193 2194 ////////////////////////////////////////////////////////////////////////////// 2195 2196 SdXMLCaptionShapeContext::~SdXMLCaptionShapeContext() 2197 { 2198 } 2199 2200 ////////////////////////////////////////////////////////////////////////////// 2201 2202 void SdXMLCaptionShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList) 2203 { 2204 // create Caption shape 2205 // add, set style and properties from base shape 2206 AddShape("com.sun.star.drawing.CaptionShape"); 2207 if( mxShape.is() ) 2208 { 2209 SetStyle(); 2210 SetLayer(); 2211 2212 uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY ); 2213 2214 // SJ: If AutoGrowWidthItem is set, SetTransformation will lead to the wrong SnapRect 2215 // because NbcAdjustTextFrameWidthAndHeight() is called (text is set later and center alignment 2216 // is the default setting, so the top left reference point that is used by the caption point is 2217 // no longer correct) There are two ways to solve this problem, temporarily disabling the 2218 // autogrowwith as we are doing here or to apply the CaptionPoint after setting text 2219 sal_Bool bIsAutoGrowWidth = sal_False; 2220 if ( xProps.is() ) 2221 { 2222 uno::Any aAny( xProps->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("TextAutoGrowWidth") ) ) ); 2223 aAny >>= bIsAutoGrowWidth; 2224 2225 if ( bIsAutoGrowWidth ) 2226 xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("TextAutoGrowWidth")), uno::makeAny( sal_False ) ); 2227 } 2228 2229 // set pos, size, shear and rotate 2230 SetTransformation(); 2231 if( xProps.is() ) 2232 xProps->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("CaptionPoint")), uno::makeAny( maCaptionPoint ) ); 2233 2234 if ( bIsAutoGrowWidth ) 2235 xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("TextAutoGrowWidth")), uno::makeAny( sal_True ) ); 2236 2237 if(mnRadius) 2238 { 2239 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY); 2240 if(xPropSet.is()) 2241 { 2242 try 2243 { 2244 xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("CornerRadius")), uno::makeAny( mnRadius ) ); 2245 } 2246 catch( uno::Exception& ) 2247 { 2248 DBG_ERROR( "exception during setting of corner radius!"); 2249 } 2250 } 2251 } 2252 2253 SdXMLShapeContext::StartElement(xAttrList); 2254 } 2255 } 2256 2257 // this is called from the parent group for each unparsed attribute in the attribute list 2258 void SdXMLCaptionShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue ) 2259 { 2260 if( XML_NAMESPACE_DRAW == nPrefix ) 2261 { 2262 if( IsXMLToken( rLocalName, XML_CAPTION_POINT_X ) ) 2263 { 2264 GetImport().GetMM100UnitConverter().convertMeasure(maCaptionPoint.X, rValue); 2265 return; 2266 } 2267 if( IsXMLToken( rLocalName, XML_CAPTION_POINT_Y ) ) 2268 { 2269 GetImport().GetMM100UnitConverter().convertMeasure(maCaptionPoint.Y, rValue); 2270 return; 2271 } 2272 if( IsXMLToken( rLocalName, XML_CORNER_RADIUS ) ) 2273 { 2274 GetImport().GetMM100UnitConverter().convertMeasure(mnRadius, rValue); 2275 return; 2276 } 2277 } 2278 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue ); 2279 } 2280 2281 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2282 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2283 2284 TYPEINIT1( SdXMLGraphicObjectShapeContext, SdXMLShapeContext ); 2285 2286 SdXMLGraphicObjectShapeContext::SdXMLGraphicObjectShapeContext( 2287 SvXMLImport& rImport, 2288 sal_uInt16 nPrfx, 2289 const OUString& rLocalName, 2290 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 2291 uno::Reference< drawing::XShapes >& rShapes, 2292 sal_Bool bTemporaryShape) 2293 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ), 2294 maURL() 2295 { 2296 } 2297 2298 ////////////////////////////////////////////////////////////////////////////// 2299 2300 // this is called from the parent group for each unparsed attribute in the attribute list 2301 void SdXMLGraphicObjectShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue ) 2302 { 2303 if( XML_NAMESPACE_XLINK == nPrefix ) 2304 { 2305 if( IsXMLToken( rLocalName, XML_HREF ) ) 2306 { 2307 maURL = rValue; 2308 return; 2309 } 2310 } 2311 2312 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue ); 2313 } 2314 2315 ////////////////////////////////////////////////////////////////////////////// 2316 2317 void SdXMLGraphicObjectShapeContext::StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& ) 2318 { 2319 // create graphic object shape 2320 const char *pService; 2321 2322 if( IsXMLToken( maPresentationClass, XML_GRAPHIC ) && GetImport().GetShapeImport()->IsPresentationShapesSupported() ) 2323 { 2324 pService = "com.sun.star.presentation.GraphicObjectShape"; 2325 } 2326 else 2327 { 2328 pService = "com.sun.star.drawing.GraphicObjectShape"; 2329 } 2330 2331 AddShape( pService ); 2332 2333 if(mxShape.is()) 2334 { 2335 SetStyle(); 2336 SetLayer(); 2337 2338 uno::Reference< beans::XPropertySet > xPropset(mxShape, uno::UNO_QUERY); 2339 if(xPropset.is()) 2340 { 2341 // since OOo 1.x had no line or fill style for graphics, but may create 2342 // documents with them, we have to override them here 2343 sal_Int32 nUPD, nBuildId; 2344 if( GetImport().getBuildIds( nUPD, nBuildId ) && (nUPD == 645) ) try 2345 { 2346 xPropset->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("FillStyle")), Any( FillStyle_NONE ) ); 2347 xPropset->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("LineStyle")), Any( LineStyle_NONE ) ); 2348 } 2349 catch( Exception& ) 2350 { 2351 } 2352 2353 uno::Reference< beans::XPropertySetInfo > xPropsInfo( xPropset->getPropertySetInfo() ); 2354 if( xPropsInfo.is() && xPropsInfo->hasPropertyByName(OUString(RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") ))) 2355 xPropset->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") ), ::cppu::bool2any( mbIsPlaceholder ) ); 2356 2357 if( !mbIsPlaceholder ) 2358 { 2359 if( maURL.getLength() ) 2360 { 2361 uno::Any aAny; 2362 aAny <<= GetImport().ResolveGraphicObjectURL( maURL, GetImport().isGraphicLoadOnDemandSupported() ); 2363 try 2364 { 2365 xPropset->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("GraphicURL") ), aAny ); 2366 xPropset->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("GraphicStreamURL") ), aAny ); 2367 } 2368 catch (lang::IllegalArgumentException const &) 2369 { 2370 } 2371 } 2372 } 2373 } 2374 2375 if(mbIsUserTransformed) 2376 { 2377 uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY); 2378 if(xProps.is()) 2379 { 2380 uno::Reference< beans::XPropertySetInfo > xPropsInfo( xProps->getPropertySetInfo() ); 2381 if( xPropsInfo.is() ) 2382 { 2383 if( xPropsInfo->hasPropertyByName(OUString(RTL_CONSTASCII_USTRINGPARAM("IsPlaceholderDependent") ))) 2384 xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("IsPlaceholderDependent") ), ::cppu::bool2any( sal_False ) ); 2385 } 2386 } 2387 } 2388 2389 // set pos, size, shear and rotate 2390 SetTransformation(); 2391 2392 SdXMLShapeContext::StartElement(mxAttrList); 2393 } 2394 } 2395 2396 void SdXMLGraphicObjectShapeContext::EndElement() 2397 { 2398 if( mxBase64Stream.is() ) 2399 { 2400 OUString sURL( GetImport().ResolveGraphicObjectURLFromBase64( mxBase64Stream ) ); 2401 if( sURL.getLength() ) 2402 { 2403 try 2404 { 2405 uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY); 2406 if(xProps.is()) 2407 { 2408 const uno::Any aAny( uno::makeAny( sURL ) ); 2409 xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("GraphicURL") ), aAny ); 2410 xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("GraphicStreamURL") ), aAny ); 2411 } 2412 } 2413 catch (lang::IllegalArgumentException const &) 2414 { 2415 } 2416 } 2417 } 2418 2419 SdXMLShapeContext::EndElement(); 2420 } 2421 2422 2423 ////////////////////////////////////////////////////////////////////////////// 2424 2425 SvXMLImportContext* SdXMLGraphicObjectShapeContext::CreateChildContext( 2426 sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, 2427 const uno::Reference<xml::sax::XAttributeList>& xAttrList ) 2428 { 2429 SvXMLImportContext* pContext = NULL; 2430 2431 if( (XML_NAMESPACE_OFFICE == nPrefix) && 2432 xmloff::token::IsXMLToken( rLocalName, xmloff::token::XML_BINARY_DATA ) ) 2433 { 2434 if( !maURL.getLength() && !mxBase64Stream.is() ) 2435 { 2436 mxBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64(); 2437 if( mxBase64Stream.is() ) 2438 pContext = new XMLBase64ImportContext( GetImport(), nPrefix, 2439 rLocalName, xAttrList, 2440 mxBase64Stream ); 2441 } 2442 } 2443 2444 // delegate to parent class if no context could be created 2445 if ( NULL == pContext ) 2446 pContext = SdXMLShapeContext::CreateChildContext(nPrefix, rLocalName, 2447 xAttrList); 2448 2449 return pContext; 2450 } 2451 2452 ////////////////////////////////////////////////////////////////////////////// 2453 2454 SdXMLGraphicObjectShapeContext::~SdXMLGraphicObjectShapeContext() 2455 { 2456 2457 } 2458 2459 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2460 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2461 2462 TYPEINIT1( SdXMLChartShapeContext, SdXMLShapeContext ); 2463 2464 SdXMLChartShapeContext::SdXMLChartShapeContext( 2465 SvXMLImport& rImport, 2466 sal_uInt16 nPrfx, 2467 const OUString& rLocalName, 2468 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 2469 uno::Reference< drawing::XShapes >& rShapes, 2470 sal_Bool bTemporaryShape) 2471 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ), 2472 mpChartContext( NULL ) 2473 { 2474 } 2475 2476 ////////////////////////////////////////////////////////////////////////////// 2477 2478 SdXMLChartShapeContext::~SdXMLChartShapeContext() 2479 { 2480 if( mpChartContext ) 2481 delete mpChartContext; 2482 } 2483 2484 ////////////////////////////////////////////////////////////////////////////// 2485 2486 void SdXMLChartShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList) 2487 { 2488 const sal_Bool bIsPresentation = isPresentationShape(); 2489 2490 AddShape( bIsPresentation ? "com.sun.star.presentation.ChartShape" : "com.sun.star.drawing.OLE2Shape" ); 2491 2492 if(mxShape.is()) 2493 { 2494 SetStyle(); 2495 SetLayer(); 2496 2497 if( !mbIsPlaceholder ) 2498 { 2499 uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY); 2500 if(xProps.is()) 2501 { 2502 uno::Reference< beans::XPropertySetInfo > xPropsInfo( xProps->getPropertySetInfo() ); 2503 if( xPropsInfo.is() && xPropsInfo->hasPropertyByName(OUString(RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") ))) 2504 xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") ), ::cppu::bool2any( sal_False ) ); 2505 2506 uno::Any aAny; 2507 2508 const OUString aCLSID( RTL_CONSTASCII_USTRINGPARAM("12DCAE26-281F-416F-a234-c3086127382e")); 2509 2510 aAny <<= aCLSID; 2511 xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("CLSID") ), aAny ); 2512 2513 #ifndef SVX_LIGHT 2514 aAny = xProps->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("Model") ) ); 2515 uno::Reference< frame::XModel > xChartModel; 2516 if( aAny >>= xChartModel ) 2517 { 2518 mpChartContext = GetImport().GetChartImport()->CreateChartContext( GetImport(), XML_NAMESPACE_SVG, GetXMLToken(XML_CHART), xChartModel, xAttrList ); 2519 } 2520 #endif 2521 } 2522 } 2523 2524 if(mbIsUserTransformed) 2525 { 2526 uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY); 2527 if(xProps.is()) 2528 { 2529 uno::Reference< beans::XPropertySetInfo > xPropsInfo( xProps->getPropertySetInfo() ); 2530 if( xPropsInfo.is() ) 2531 { 2532 if( xPropsInfo->hasPropertyByName(OUString(RTL_CONSTASCII_USTRINGPARAM("IsPlaceholderDependent") ))) 2533 xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("IsPlaceholderDependent") ), ::cppu::bool2any( sal_False ) ); 2534 } 2535 } 2536 } 2537 2538 2539 // set pos, size, shear and rotate 2540 SetTransformation(); 2541 2542 SdXMLShapeContext::StartElement(xAttrList); 2543 2544 if( mpChartContext ) 2545 mpChartContext->StartElement( xAttrList ); 2546 } 2547 } 2548 2549 void SdXMLChartShapeContext::EndElement() 2550 { 2551 if( mpChartContext ) 2552 mpChartContext->EndElement(); 2553 2554 SdXMLShapeContext::EndElement(); 2555 } 2556 2557 void SdXMLChartShapeContext::Characters( const ::rtl::OUString& rChars ) 2558 { 2559 if( mpChartContext ) 2560 mpChartContext->Characters( rChars ); 2561 } 2562 2563 SvXMLImportContext * SdXMLChartShapeContext::CreateChildContext( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, 2564 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList ) 2565 { 2566 if( mpChartContext ) 2567 return mpChartContext->CreateChildContext( nPrefix, rLocalName, xAttrList ); 2568 2569 return NULL; 2570 } 2571 2572 ////////////////////////////////////////////////////////////////////////////// 2573 2574 TYPEINIT1( SdXMLObjectShapeContext, SdXMLShapeContext ); 2575 2576 SdXMLObjectShapeContext::SdXMLObjectShapeContext( SvXMLImport& rImport, sal_uInt16 nPrfx, 2577 const rtl::OUString& rLocalName, 2578 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 2579 com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes, 2580 sal_Bool bTemporaryShape) 2581 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ) 2582 { 2583 } 2584 2585 SdXMLObjectShapeContext::~SdXMLObjectShapeContext() 2586 { 2587 } 2588 2589 void SdXMLObjectShapeContext::StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& ) 2590 { 2591 // #96717# in theorie, if we don't have a url we shouldn't even 2592 // export this ole shape. But practical its to risky right now 2593 // to change this so we better dispose this on load 2594 //if( !mbIsPlaceholder && ImpIsEmptyURL(maHref) ) 2595 // return; 2596 2597 // #100592# this BugFix prevents that a shape is created. CL 2598 // is thinking about an alternative. 2599 // #i13140# Check for more than empty string in maHref, there are 2600 // other possibilities that maHref results in empty container 2601 // storage names 2602 if( !(GetImport().getImportFlags() & IMPORT_EMBEDDED) && !mbIsPlaceholder && ImpIsEmptyURL(maHref) ) 2603 return; 2604 2605 const char* pService = "com.sun.star.drawing.OLE2Shape"; 2606 2607 sal_Bool bIsPresShape = maPresentationClass.getLength() && GetImport().GetShapeImport()->IsPresentationShapesSupported(); 2608 2609 if( bIsPresShape ) 2610 { 2611 if( IsXMLToken( maPresentationClass, XML_PRESENTATION_CHART ) ) 2612 { 2613 pService = "com.sun.star.presentation.ChartShape"; 2614 } 2615 else if( IsXMLToken( maPresentationClass, XML_PRESENTATION_TABLE ) ) 2616 { 2617 pService = "com.sun.star.presentation.CalcShape"; 2618 } 2619 else if( IsXMLToken( maPresentationClass, XML_PRESENTATION_OBJECT ) ) 2620 { 2621 pService = "com.sun.star.presentation.OLE2Shape"; 2622 } 2623 } 2624 2625 AddShape( pService ); 2626 2627 if( mxShape.is() ) 2628 { 2629 SetLayer(); 2630 2631 if(bIsPresShape) 2632 { 2633 uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY); 2634 if(xProps.is()) 2635 { 2636 uno::Reference< beans::XPropertySetInfo > xPropsInfo( xProps->getPropertySetInfo() ); 2637 if( xPropsInfo.is() ) 2638 { 2639 if( !mbIsPlaceholder && xPropsInfo->hasPropertyByName(OUString(RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") ))) 2640 xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") ), ::cppu::bool2any( sal_False ) ); 2641 2642 if( mbIsUserTransformed && xPropsInfo->hasPropertyByName(OUString(RTL_CONSTASCII_USTRINGPARAM("IsPlaceholderDependent") ))) 2643 xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("IsPlaceholderDependent") ), ::cppu::bool2any( sal_False ) ); 2644 } 2645 } 2646 } 2647 2648 if( !mbIsPlaceholder && maHref.getLength() ) 2649 { 2650 uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY ); 2651 2652 if( xProps.is() ) 2653 { 2654 OUString aPersistName = GetImport().ResolveEmbeddedObjectURL( maHref, maCLSID ); 2655 2656 if ( GetImport().IsPackageURL( maHref ) ) 2657 { 2658 const OUString sURL(RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.EmbeddedObject:" )); 2659 2660 if ( aPersistName.compareTo( sURL, sURL.getLength() ) == 0 ) 2661 aPersistName = aPersistName.copy( sURL.getLength() ); 2662 2663 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "PersistName" ) ), 2664 uno::makeAny( aPersistName ) ); 2665 } 2666 else 2667 { 2668 // this is OOo link object 2669 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "LinkURL" ) ), 2670 uno::makeAny( aPersistName ) ); 2671 } 2672 } 2673 } 2674 2675 // set pos, size, shear and rotate 2676 SetTransformation(); 2677 2678 SetStyle(); 2679 2680 GetImport().GetShapeImport()->finishShape( mxShape, mxAttrList, mxShapes ); 2681 } 2682 } 2683 2684 void SdXMLObjectShapeContext::EndElement() 2685 { 2686 // #i67705# 2687 const sal_uInt16 nGeneratorVersion(GetImport().getGeneratorVersion()); 2688 2689 if(nGeneratorVersion < SvXMLImport::OOo_34x) 2690 { 2691 // #i118485# 2692 // If it's an old file from us written before OOo3.4, we need to correct 2693 // FillStyle and LineStyle for OLE2 objects. The error was that the old paint 2694 // implementations just ignored added fill/linestyles completely, thus 2695 // those objects need to be corrected to not show blue and hairline which 2696 // always was the default, but would be shown now 2697 uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY); 2698 2699 if( xProps.is() ) 2700 { 2701 xProps->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FillStyle")), uno::makeAny(drawing::FillStyle_NONE)); 2702 xProps->setPropertyValue(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LineStyle")), uno::makeAny(drawing::LineStyle_NONE)); 2703 } 2704 } 2705 2706 // #100592# 2707 if( mxBase64Stream.is() ) 2708 { 2709 OUString aPersistName( GetImport().ResolveEmbeddedObjectURLFromBase64() ); 2710 const OUString sURL(RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.EmbeddedObject:" )); 2711 2712 aPersistName = aPersistName.copy( sURL.getLength() ); 2713 2714 uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY); 2715 if( xProps.is() ) 2716 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "PersistName" ) ), uno::makeAny( aPersistName ) ); 2717 } 2718 2719 SdXMLShapeContext::EndElement(); 2720 } 2721 2722 // this is called from the parent group for each unparsed attribute in the attribute list 2723 void SdXMLObjectShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue ) 2724 { 2725 switch( nPrefix ) 2726 { 2727 case XML_NAMESPACE_DRAW: 2728 if( IsXMLToken( rLocalName, XML_CLASS_ID ) ) 2729 { 2730 maCLSID = rValue; 2731 return; 2732 } 2733 break; 2734 case XML_NAMESPACE_XLINK: 2735 if( IsXMLToken( rLocalName, XML_HREF ) ) 2736 { 2737 maHref = rValue; 2738 return; 2739 } 2740 break; 2741 } 2742 2743 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue ); 2744 } 2745 2746 SvXMLImportContext* SdXMLObjectShapeContext::CreateChildContext( 2747 sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, 2748 const uno::Reference<xml::sax::XAttributeList>& xAttrList ) 2749 { 2750 // #100592# 2751 SvXMLImportContext* pContext = NULL; 2752 2753 if((XML_NAMESPACE_OFFICE == nPrefix) && IsXMLToken(rLocalName, XML_BINARY_DATA)) 2754 { 2755 mxBase64Stream = GetImport().GetStreamForEmbeddedObjectURLFromBase64(); 2756 if( mxBase64Stream.is() ) 2757 pContext = new XMLBase64ImportContext( GetImport(), nPrefix, 2758 rLocalName, xAttrList, 2759 mxBase64Stream ); 2760 } 2761 else if( ((XML_NAMESPACE_OFFICE == nPrefix) && IsXMLToken(rLocalName, XML_DOCUMENT)) || 2762 ((XML_NAMESPACE_MATH == nPrefix) && IsXMLToken(rLocalName, XML_MATH)) ) 2763 { 2764 XMLEmbeddedObjectImportContext *pEContext = 2765 new XMLEmbeddedObjectImportContext( GetImport(), nPrefix, 2766 rLocalName, xAttrList ); 2767 maCLSID = pEContext->GetFilterCLSID(); 2768 if( maCLSID.getLength() != 0 ) 2769 { 2770 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY); 2771 if( xPropSet.is() ) 2772 { 2773 xPropSet->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("CLSID") ), uno::makeAny( maCLSID ) ); 2774 2775 uno::Reference< lang::XComponent > xComp; 2776 xPropSet->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("Model") ) ) >>= xComp; 2777 DBG_ASSERT( xComp.is(), "no xModel for own OLE format" ); 2778 pEContext->SetComponent( xComp ); 2779 } 2780 } 2781 pContext = pEContext; 2782 } 2783 2784 // delegate to parent class if no context could be created 2785 if(!pContext) 2786 pContext = SdXMLShapeContext::CreateChildContext(nPrefix, rLocalName, xAttrList); 2787 2788 return pContext; 2789 } 2790 2791 ////////////////////////////////////////////////////////////////////////////// 2792 2793 TYPEINIT1( SdXMLAppletShapeContext, SdXMLShapeContext ); 2794 2795 SdXMLAppletShapeContext::SdXMLAppletShapeContext( SvXMLImport& rImport, sal_uInt16 nPrfx, 2796 const rtl::OUString& rLocalName, 2797 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 2798 com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes, 2799 sal_Bool bTemporaryShape) 2800 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ), 2801 mbIsScript( sal_False ) 2802 { 2803 } 2804 2805 SdXMLAppletShapeContext::~SdXMLAppletShapeContext() 2806 { 2807 } 2808 2809 void SdXMLAppletShapeContext::StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& ) 2810 { 2811 const char* pService = "com.sun.star.drawing.AppletShape"; 2812 AddShape( pService ); 2813 2814 if( mxShape.is() ) 2815 { 2816 SetLayer(); 2817 2818 // set pos, size, shear and rotate 2819 SetTransformation(); 2820 GetImport().GetShapeImport()->finishShape( mxShape, mxAttrList, mxShapes ); 2821 } 2822 } 2823 2824 // this is called from the parent group for each unparsed attribute in the attribute list 2825 void SdXMLAppletShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue ) 2826 { 2827 switch( nPrefix ) 2828 { 2829 case XML_NAMESPACE_DRAW: 2830 if( IsXMLToken( rLocalName, XML_APPLET_NAME ) ) 2831 { 2832 maAppletName = rValue; 2833 return; 2834 } 2835 if( IsXMLToken( rLocalName, XML_CODE ) ) 2836 { 2837 maAppletCode = rValue; 2838 return; 2839 } 2840 if( IsXMLToken( rLocalName, XML_MAY_SCRIPT ) ) 2841 { 2842 mbIsScript = IsXMLToken( rValue, XML_TRUE ); 2843 return; 2844 } 2845 break; 2846 case XML_NAMESPACE_XLINK: 2847 if( IsXMLToken( rLocalName, XML_HREF ) ) 2848 { 2849 maHref = GetImport().GetAbsoluteReference(rValue); 2850 return; 2851 } 2852 break; 2853 } 2854 2855 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue ); 2856 } 2857 2858 void SdXMLAppletShapeContext::EndElement() 2859 { 2860 uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY ); 2861 if( xProps.is() ) 2862 { 2863 uno::Any aAny; 2864 2865 if ( maSize.Width && maSize.Height ) 2866 { 2867 // the visual area for applet must be set on loading 2868 awt::Rectangle aRect( 0, 0, maSize.Width, maSize.Height ); 2869 aAny <<= aRect; 2870 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "VisibleArea" ) ), aAny ); 2871 } 2872 2873 if( maParams.getLength() ) 2874 { 2875 aAny <<= maParams; 2876 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "AppletCommands" ) ), aAny ); 2877 } 2878 2879 if( maHref.getLength() ) 2880 { 2881 aAny <<= maHref; 2882 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "AppletCodeBase" ) ), aAny ); 2883 } 2884 2885 if( maAppletName.getLength() ) 2886 { 2887 aAny <<= maAppletName; 2888 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "AppletName" ) ), aAny ); 2889 } 2890 2891 if( mbIsScript ) 2892 { 2893 aAny <<= mbIsScript; 2894 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "AppletIsScript" ) ), aAny ); 2895 2896 } 2897 2898 if( maAppletCode.getLength() ) 2899 { 2900 aAny <<= maAppletCode; 2901 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "AppletCode" ) ), aAny ); 2902 } 2903 2904 aAny <<= ::rtl::OUString( GetImport().GetDocumentBase() ); 2905 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "AppletDocBase" ) ), aAny ); 2906 2907 SetThumbnail(); 2908 } 2909 2910 SdXMLShapeContext::EndElement(); 2911 } 2912 2913 SvXMLImportContext * SdXMLAppletShapeContext::CreateChildContext( sal_uInt16 p_nPrefix, const ::rtl::OUString& rLocalName, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList ) 2914 { 2915 if( p_nPrefix == XML_NAMESPACE_DRAW && IsXMLToken( rLocalName, XML_PARAM ) ) 2916 { 2917 OUString aParamName, aParamValue; 2918 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 2919 // now parse the attribute list and look for draw:name and draw:value 2920 for(sal_Int16 a(0); a < nAttrCount; a++) 2921 { 2922 const OUString& rAttrName = xAttrList->getNameByIndex(a); 2923 OUString aLocalName; 2924 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(rAttrName, &aLocalName); 2925 const OUString aValue( xAttrList->getValueByIndex(a) ); 2926 2927 if( nPrefix == XML_NAMESPACE_DRAW ) 2928 { 2929 if( IsXMLToken( aLocalName, XML_NAME ) ) 2930 { 2931 aParamName = aValue; 2932 } 2933 else if( IsXMLToken( aLocalName, XML_VALUE ) ) 2934 { 2935 aParamValue = aValue; 2936 } 2937 } 2938 } 2939 2940 if( aParamName.getLength() ) 2941 { 2942 sal_Int32 nIndex = maParams.getLength(); 2943 maParams.realloc( nIndex + 1 ); 2944 maParams[nIndex].Name = aParamName; 2945 maParams[nIndex].Handle = -1; 2946 maParams[nIndex].Value <<= aParamValue; 2947 maParams[nIndex].State = beans::PropertyState_DIRECT_VALUE; 2948 } 2949 2950 return new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName ); 2951 } 2952 2953 return SdXMLShapeContext::CreateChildContext( p_nPrefix, rLocalName, xAttrList ); 2954 } 2955 2956 ////////////////////////////////////////////////////////////////////////////// 2957 2958 TYPEINIT1( SdXMLPluginShapeContext, SdXMLShapeContext ); 2959 2960 SdXMLPluginShapeContext::SdXMLPluginShapeContext( SvXMLImport& rImport, sal_uInt16 nPrfx, 2961 const rtl::OUString& rLocalName, 2962 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 2963 com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes, 2964 sal_Bool bTemporaryShape) : 2965 SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ), 2966 mbMedia( false ) 2967 { 2968 } 2969 2970 SdXMLPluginShapeContext::~SdXMLPluginShapeContext() 2971 { 2972 } 2973 2974 void SdXMLPluginShapeContext::StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList) 2975 { 2976 // watch for MimeType attribute to see if we have a media object 2977 for( sal_Int16 n = 0, nAttrCount = ( xAttrList.is() ? xAttrList->getLength() : 0 ); n < nAttrCount; ++n ) 2978 { 2979 OUString aLocalName; 2980 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( xAttrList->getNameByIndex( n ), &aLocalName ); 2981 2982 if( nPrefix == XML_NAMESPACE_DRAW && IsXMLToken( aLocalName, XML_MIME_TYPE ) ) 2983 { 2984 if( 0 == xAttrList->getValueByIndex( n ).compareToAscii( "application/vnd.sun.star.media" ) ) 2985 mbMedia = true; 2986 2987 // leave this loop 2988 n = nAttrCount - 1; 2989 } 2990 } 2991 2992 const char* pService; 2993 2994 sal_Bool bIsPresShape = sal_False; 2995 2996 if( mbMedia ) 2997 { 2998 pService = "com.sun.star.drawing.MediaShape"; 2999 3000 bIsPresShape = maPresentationClass.getLength() && GetImport().GetShapeImport()->IsPresentationShapesSupported(); 3001 if( bIsPresShape ) 3002 { 3003 if( IsXMLToken( maPresentationClass, XML_PRESENTATION_OBJECT ) ) 3004 { 3005 pService = "com.sun.star.presentation.MediaShape"; 3006 } 3007 } 3008 } 3009 else 3010 pService = "com.sun.star.drawing.PluginShape"; 3011 3012 AddShape( pService ); 3013 3014 if( mxShape.is() ) 3015 { 3016 SetLayer(); 3017 3018 if(bIsPresShape) 3019 { 3020 uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY ); 3021 if(xProps.is()) 3022 { 3023 uno::Reference< beans::XPropertySetInfo > xPropsInfo( xProps->getPropertySetInfo() ); 3024 if( xPropsInfo.is() ) 3025 { 3026 if( !mbIsPlaceholder && xPropsInfo->hasPropertyByName(OUString(RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") ))) 3027 xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") ), ::cppu::bool2any( sal_False ) ); 3028 3029 if( mbIsUserTransformed && xPropsInfo->hasPropertyByName(OUString(RTL_CONSTASCII_USTRINGPARAM("IsPlaceholderDependent") ))) 3030 xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("IsPlaceholderDependent") ), ::cppu::bool2any( sal_False ) ); 3031 } 3032 } 3033 } 3034 3035 // set pos, size, shear and rotate 3036 SetTransformation(); 3037 GetImport().GetShapeImport()->finishShape( mxShape, mxAttrList, mxShapes ); 3038 } 3039 } 3040 3041 // this is called from the parent group for each unparsed attribute in the attribute list 3042 void SdXMLPluginShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue ) 3043 { 3044 switch( nPrefix ) 3045 { 3046 case XML_NAMESPACE_DRAW: 3047 if( IsXMLToken( rLocalName, XML_MIME_TYPE ) ) 3048 { 3049 maMimeType = rValue; 3050 return; 3051 } 3052 break; 3053 case XML_NAMESPACE_XLINK: 3054 if( IsXMLToken( rLocalName, XML_HREF ) ) 3055 { 3056 maHref = GetImport().GetAbsoluteReference(rValue); 3057 return; 3058 } 3059 break; 3060 } 3061 3062 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue ); 3063 } 3064 3065 void SdXMLPluginShapeContext::EndElement() 3066 { 3067 uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY ); 3068 3069 if( xProps.is() ) 3070 { 3071 uno::Any aAny; 3072 3073 if ( maSize.Width && maSize.Height ) 3074 { 3075 const rtl::OUString sVisibleArea( RTL_CONSTASCII_USTRINGPARAM( "VisibleArea" ) ); 3076 uno::Reference< beans::XPropertySetInfo > aXPropSetInfo( xProps->getPropertySetInfo() ); 3077 if ( !aXPropSetInfo.is() || aXPropSetInfo->hasPropertyByName( sVisibleArea ) ) 3078 { 3079 // the visual area for a plugin must be set on loading 3080 awt::Rectangle aRect( 0, 0, maSize.Width, maSize.Height ); 3081 aAny <<= aRect; 3082 xProps->setPropertyValue( sVisibleArea, aAny ); 3083 } 3084 } 3085 3086 if( !mbMedia ) 3087 { 3088 // in case we have a plugin object 3089 if( maParams.getLength() ) 3090 { 3091 aAny <<= maParams; 3092 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "PluginCommands" ) ), aAny ); 3093 } 3094 3095 if( maMimeType.getLength() ) 3096 { 3097 aAny <<= maMimeType; 3098 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "PluginMimeType" ) ), aAny ); 3099 } 3100 3101 if( maHref.getLength() ) 3102 { 3103 aAny <<= maHref; 3104 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "PluginURL" ) ), aAny ); 3105 } 3106 } 3107 else 3108 { 3109 // in case we have a media object 3110 3111 OUString sTempRef; 3112 3113 // check for package URL 3114 if( GetImport().IsPackageURL( maHref ) ) 3115 { 3116 sTempRef = OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.Package:" ) ); 3117 } 3118 3119 sTempRef += maHref; 3120 3121 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaURL" ) ), uno::makeAny( sTempRef ) ); 3122 3123 for( sal_Int32 nParam = 0; nParam < maParams.getLength(); ++nParam ) 3124 { 3125 const OUString& rName = maParams[ nParam ].Name; 3126 3127 if( 0 == rName.compareToAscii( "Loop" ) ) 3128 { 3129 OUString aValueStr; 3130 maParams[ nParam ].Value >>= aValueStr; 3131 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Loop" ) ), 3132 uno::makeAny( static_cast< sal_Bool >( 0 == aValueStr.compareToAscii( "true" ) ) ) ); 3133 } 3134 else if( 0 == rName.compareToAscii( "Mute" ) ) 3135 { 3136 OUString aValueStr; 3137 maParams[ nParam ].Value >>= aValueStr; 3138 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Mute" ) ), 3139 uno::makeAny( static_cast< sal_Bool >( 0 == aValueStr.compareToAscii( "true" ) ) ) ); 3140 } 3141 else if( 0 == rName.compareToAscii( "VolumeDB" ) ) 3142 { 3143 OUString aValueStr; 3144 maParams[ nParam ].Value >>= aValueStr; 3145 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "VolumeDB" ) ), 3146 uno::makeAny( static_cast< sal_Int16 >( aValueStr.toInt32() ) ) ); 3147 } 3148 else if( 0 == rName.compareToAscii( "Zoom" ) ) 3149 { 3150 OUString aZoomStr; 3151 media::ZoomLevel eZoomLevel; 3152 3153 maParams[ nParam ].Value >>= aZoomStr; 3154 3155 if( 0 == aZoomStr.compareToAscii( "25%" ) ) 3156 eZoomLevel = media::ZoomLevel_ZOOM_1_TO_4; 3157 else if( 0 == aZoomStr.compareToAscii( "50%" ) ) 3158 eZoomLevel = media::ZoomLevel_ZOOM_1_TO_2; 3159 else if( 0 == aZoomStr.compareToAscii( "100%" ) ) 3160 eZoomLevel = media::ZoomLevel_ORIGINAL; 3161 else if( 0 == aZoomStr.compareToAscii( "200%" ) ) 3162 eZoomLevel = media::ZoomLevel_ZOOM_2_TO_1; 3163 else if( 0 == aZoomStr.compareToAscii( "400%" ) ) 3164 eZoomLevel = media::ZoomLevel_ZOOM_4_TO_1; 3165 else if( 0 == aZoomStr.compareToAscii( "fit" ) ) 3166 eZoomLevel = media::ZoomLevel_FIT_TO_WINDOW; 3167 else if( 0 == aZoomStr.compareToAscii( "fixedfit" ) ) 3168 eZoomLevel = media::ZoomLevel_FIT_TO_WINDOW_FIXED_ASPECT; 3169 else if( 0 == aZoomStr.compareToAscii( "fullscreen" ) ) 3170 eZoomLevel = media::ZoomLevel_FULLSCREEN; 3171 else 3172 eZoomLevel = media::ZoomLevel_NOT_AVAILABLE; 3173 3174 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Zoom" ) ), uno::makeAny( eZoomLevel ) ); 3175 } 3176 } 3177 } 3178 3179 SetThumbnail(); 3180 } 3181 3182 SdXMLShapeContext::EndElement(); 3183 } 3184 3185 SvXMLImportContext * SdXMLPluginShapeContext::CreateChildContext( sal_uInt16 p_nPrefix, const ::rtl::OUString& rLocalName, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList ) 3186 { 3187 if( p_nPrefix == XML_NAMESPACE_DRAW && IsXMLToken( rLocalName, XML_PARAM ) ) 3188 { 3189 OUString aParamName, aParamValue; 3190 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 3191 // now parse the attribute list and look for draw:name and draw:value 3192 for(sal_Int16 a(0); a < nAttrCount; a++) 3193 { 3194 const OUString& rAttrName = xAttrList->getNameByIndex(a); 3195 OUString aLocalName; 3196 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(rAttrName, &aLocalName); 3197 const OUString aValue( xAttrList->getValueByIndex(a) ); 3198 3199 if( nPrefix == XML_NAMESPACE_DRAW ) 3200 { 3201 if( IsXMLToken( aLocalName, XML_NAME ) ) 3202 { 3203 aParamName = aValue; 3204 } 3205 else if( IsXMLToken( aLocalName, XML_VALUE ) ) 3206 { 3207 aParamValue = aValue; 3208 } 3209 } 3210 3211 if( aParamName.getLength() ) 3212 { 3213 sal_Int32 nIndex = maParams.getLength(); 3214 maParams.realloc( nIndex + 1 ); 3215 maParams[nIndex].Name = aParamName; 3216 maParams[nIndex].Handle = -1; 3217 maParams[nIndex].Value <<= aParamValue; 3218 maParams[nIndex].State = beans::PropertyState_DIRECT_VALUE; 3219 } 3220 } 3221 3222 return new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName ); 3223 } 3224 3225 return SdXMLShapeContext::CreateChildContext( p_nPrefix, rLocalName, xAttrList ); 3226 } 3227 3228 ////////////////////////////////////////////////////////////////////////////// 3229 3230 TYPEINIT1( SdXMLFloatingFrameShapeContext, SdXMLShapeContext ); 3231 3232 SdXMLFloatingFrameShapeContext::SdXMLFloatingFrameShapeContext( SvXMLImport& rImport, sal_uInt16 nPrfx, 3233 const rtl::OUString& rLocalName, 3234 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 3235 com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes, 3236 sal_Bool bTemporaryShape) 3237 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ) 3238 { 3239 } 3240 3241 SdXMLFloatingFrameShapeContext::~SdXMLFloatingFrameShapeContext() 3242 { 3243 } 3244 3245 void SdXMLFloatingFrameShapeContext::StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& ) 3246 { 3247 const char* pService = "com.sun.star.drawing.FrameShape"; 3248 AddShape( pService ); 3249 3250 if( mxShape.is() ) 3251 { 3252 SetLayer(); 3253 3254 // set pos, size, shear and rotate 3255 SetTransformation(); 3256 3257 uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY ); 3258 if( xProps.is() ) 3259 { 3260 uno::Any aAny; 3261 3262 if( maFrameName.getLength() ) 3263 { 3264 aAny <<= maFrameName; 3265 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "FrameName" ) ), aAny ); 3266 } 3267 3268 if( maHref.getLength() ) 3269 { 3270 aAny <<= maHref; 3271 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "FrameURL" ) ), aAny ); 3272 } 3273 } 3274 3275 SetStyle(); 3276 3277 GetImport().GetShapeImport()->finishShape( mxShape, mxAttrList, mxShapes ); 3278 } 3279 } 3280 3281 // this is called from the parent group for each unparsed attribute in the attribute list 3282 void SdXMLFloatingFrameShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue ) 3283 { 3284 switch( nPrefix ) 3285 { 3286 case XML_NAMESPACE_DRAW: 3287 if( IsXMLToken( rLocalName, XML_FRAME_NAME ) ) 3288 { 3289 maFrameName = rValue; 3290 return; 3291 } 3292 break; 3293 case XML_NAMESPACE_XLINK: 3294 if( IsXMLToken( rLocalName, XML_HREF ) ) 3295 { 3296 maHref = GetImport().GetAbsoluteReference(rValue); 3297 return; 3298 } 3299 break; 3300 } 3301 3302 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue ); 3303 } 3304 3305 void SdXMLFloatingFrameShapeContext::EndElement() 3306 { 3307 uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY ); 3308 3309 if( xProps.is() ) 3310 { 3311 if ( maSize.Width && maSize.Height ) 3312 { 3313 // the visual area for a floating frame must be set on loading 3314 awt::Rectangle aRect( 0, 0, maSize.Width, maSize.Height ); 3315 uno::Any aAny; 3316 aAny <<= aRect; 3317 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "VisibleArea" ) ), aAny ); 3318 } 3319 } 3320 3321 SetThumbnail(); 3322 SdXMLShapeContext::EndElement(); 3323 } 3324 3325 ////////////////////////////////////////////////////////////////////////////// 3326 3327 TYPEINIT1( SdXMLFrameShapeContext, SdXMLShapeContext ); 3328 3329 SdXMLFrameShapeContext::SdXMLFrameShapeContext( SvXMLImport& rImport, sal_uInt16 nPrfx, 3330 const rtl::OUString& rLocalName, 3331 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 3332 com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes, 3333 sal_Bool bTemporaryShape) 3334 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ), 3335 mbSupportsReplacement( sal_False ) 3336 { 3337 uno::Reference < util::XCloneable > xClone( xAttrList, uno::UNO_QUERY ); 3338 if( xClone.is() ) 3339 mxAttrList.set( xClone->createClone(), uno::UNO_QUERY ); 3340 else 3341 mxAttrList = new SvXMLAttributeList( xAttrList ); 3342 3343 } 3344 3345 SdXMLFrameShapeContext::~SdXMLFrameShapeContext() 3346 { 3347 } 3348 3349 SvXMLImportContext *SdXMLFrameShapeContext::CreateChildContext( sal_uInt16 nPrefix, 3350 const OUString& rLocalName, 3351 const uno::Reference< xml::sax::XAttributeList>& xAttrList ) 3352 { 3353 SvXMLImportContext * pContext = 0; 3354 3355 if( !mxImplContext.Is() ) 3356 { 3357 pContext = GetImport().GetShapeImport()->CreateFrameChildContext( 3358 GetImport(), nPrefix, rLocalName, xAttrList, mxShapes, mxAttrList ); 3359 3360 mxImplContext = pContext; 3361 mbSupportsReplacement = IsXMLToken( rLocalName, XML_OBJECT ) || 3362 IsXMLToken( rLocalName, XML_OBJECT_OLE ); 3363 } 3364 else if( mbSupportsReplacement && !mxReplImplContext && 3365 XML_NAMESPACE_DRAW == nPrefix && 3366 IsXMLToken( rLocalName, XML_IMAGE ) ) 3367 { 3368 // read replacement image 3369 SvXMLImportContext *pImplContext = &mxImplContext; 3370 SdXMLShapeContext *pSContext = 3371 PTR_CAST( SdXMLShapeContext, pImplContext ); 3372 if( pSContext ) 3373 { 3374 uno::Reference < beans::XPropertySet > xPropSet( 3375 pSContext->getShape(), uno::UNO_QUERY ); 3376 if( xPropSet.is() ) 3377 { 3378 pContext = new XMLReplacementImageContext( GetImport(), 3379 nPrefix, rLocalName, xAttrList, xPropSet ); 3380 mxReplImplContext = pContext; 3381 } 3382 } 3383 } 3384 else if( 3385 ( nPrefix == XML_NAMESPACE_SVG && // #i68101# 3386 (IsXMLToken( rLocalName, XML_TITLE ) || IsXMLToken( rLocalName, XML_DESC ) ) ) || 3387 (nPrefix == XML_NAMESPACE_OFFICE && IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) ) || 3388 (nPrefix == XML_NAMESPACE_DRAW && (IsXMLToken( rLocalName, XML_GLUE_POINT ) || 3389 IsXMLToken( rLocalName, XML_THUMBNAIL ) ) ) ) 3390 { 3391 SvXMLImportContext *pImplContext = &mxImplContext; 3392 pContext = PTR_CAST( SdXMLShapeContext, pImplContext )->CreateChildContext( nPrefix, 3393 rLocalName, xAttrList ); 3394 } 3395 else if ( (XML_NAMESPACE_DRAW == nPrefix) && IsXMLToken( rLocalName, XML_IMAGE_MAP ) ) 3396 { 3397 SdXMLShapeContext *pSContext = dynamic_cast< SdXMLShapeContext* >( &mxImplContext ); 3398 if( pSContext ) 3399 { 3400 uno::Reference < beans::XPropertySet > xPropSet( pSContext->getShape(), uno::UNO_QUERY ); 3401 if (xPropSet.is()) 3402 { 3403 pContext = new XMLImageMapContext(GetImport(), nPrefix, rLocalName, xPropSet); 3404 } 3405 } 3406 } 3407 3408 // call parent for content 3409 if(!pContext) 3410 pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList ); 3411 3412 return pContext; 3413 } 3414 3415 void SdXMLFrameShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>&) 3416 { 3417 // ignore 3418 } 3419 3420 void SdXMLFrameShapeContext::EndElement() 3421 { 3422 if( !mxImplContext.Is() ) 3423 { 3424 // now check if this is an empty presentation object 3425 sal_Int16 nAttrCount = mxAttrList.is() ? mxAttrList->getLength() : 0; 3426 for(sal_Int16 a(0); a < nAttrCount; a++) 3427 { 3428 OUString aLocalName; 3429 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(mxAttrList->getNameByIndex(a), &aLocalName); 3430 3431 if( nPrefix == XML_NAMESPACE_PRESENTATION ) 3432 { 3433 if( IsXMLToken( aLocalName, XML_PLACEHOLDER ) ) 3434 { 3435 mbIsPlaceholder = IsXMLToken( mxAttrList->getValueByIndex(a), XML_TRUE ); 3436 } 3437 else if( IsXMLToken( aLocalName, XML_CLASS ) ) 3438 { 3439 maPresentationClass = mxAttrList->getValueByIndex(a); 3440 } 3441 } 3442 } 3443 3444 if( (maPresentationClass.getLength() != 0) && mbIsPlaceholder ) 3445 { 3446 uno::Reference< xml::sax::XAttributeList> xEmpty; 3447 3448 enum XMLTokenEnum eToken = XML_TEXT_BOX; 3449 3450 if( IsXMLToken( maPresentationClass, XML_GRAPHIC ) ) 3451 { 3452 eToken = XML_IMAGE; 3453 3454 } 3455 else if( IsXMLToken( maPresentationClass, XML_PRESENTATION_PAGE ) ) 3456 { 3457 eToken = XML_PAGE_THUMBNAIL; 3458 } 3459 else if( IsXMLToken( maPresentationClass, XML_PRESENTATION_CHART ) || 3460 IsXMLToken( maPresentationClass, XML_PRESENTATION_TABLE ) || 3461 IsXMLToken( maPresentationClass, XML_PRESENTATION_OBJECT ) ) 3462 { 3463 eToken = XML_OBJECT; 3464 } 3465 3466 mxImplContext = GetImport().GetShapeImport()->CreateFrameChildContext( 3467 GetImport(), XML_NAMESPACE_DRAW, GetXMLToken( eToken ), mxAttrList, mxShapes, xEmpty ); 3468 3469 if( mxImplContext.Is() ) 3470 { 3471 mxImplContext->StartElement( mxAttrList ); 3472 mxImplContext->EndElement(); 3473 } 3474 } 3475 } 3476 3477 mxImplContext = 0; 3478 SdXMLShapeContext::EndElement(); 3479 } 3480 3481 void SdXMLFrameShapeContext::processAttribute( sal_uInt16, 3482 const ::rtl::OUString&, const ::rtl::OUString& ) 3483 { 3484 // ignore 3485 } 3486 3487 TYPEINIT1( SdXMLCustomShapeContext, SdXMLShapeContext ); 3488 3489 SdXMLCustomShapeContext::SdXMLCustomShapeContext( 3490 SvXMLImport& rImport, 3491 sal_uInt16 nPrfx, 3492 const OUString& rLocalName, 3493 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 3494 uno::Reference< drawing::XShapes >& rShapes, 3495 sal_Bool bTemporaryShape) 3496 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ) 3497 { 3498 } 3499 3500 ////////////////////////////////////////////////////////////////////////////// 3501 3502 SdXMLCustomShapeContext::~SdXMLCustomShapeContext() 3503 { 3504 } 3505 3506 ////////////////////////////////////////////////////////////////////////////// 3507 3508 // this is called from the parent group for each unparsed attribute in the attribute list 3509 void SdXMLCustomShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue ) 3510 { 3511 if( XML_NAMESPACE_DRAW == nPrefix ) 3512 { 3513 if( IsXMLToken( rLocalName, XML_ENGINE ) ) 3514 { 3515 maCustomShapeEngine = rValue; 3516 return; 3517 } 3518 if ( IsXMLToken( rLocalName, XML_DATA ) ) 3519 { 3520 maCustomShapeData = rValue; 3521 return; 3522 } 3523 } 3524 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue ); 3525 } 3526 3527 ////////////////////////////////////////////////////////////////////////////// 3528 3529 void SdXMLCustomShapeContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList ) 3530 { 3531 // create rectangle shape 3532 AddShape("com.sun.star.drawing.CustomShape"); 3533 if ( mxShape.is() ) 3534 { 3535 // Add, set Style and properties from base shape 3536 SetStyle(); 3537 SetLayer(); 3538 3539 // set pos, size, shear and rotate 3540 SetTransformation(); 3541 3542 try 3543 { 3544 uno::Reference< beans::XPropertySet > xPropSet( mxShape, uno::UNO_QUERY ); 3545 if( xPropSet.is() ) 3546 { 3547 if ( maCustomShapeEngine.getLength() ) 3548 { 3549 uno::Any aAny; 3550 aAny <<= maCustomShapeEngine; 3551 xPropSet->setPropertyValue( EASGet( EAS_CustomShapeEngine ), aAny ); 3552 } 3553 if ( maCustomShapeData.getLength() ) 3554 { 3555 uno::Any aAny; 3556 aAny <<= maCustomShapeData; 3557 xPropSet->setPropertyValue( EASGet( EAS_CustomShapeData ), aAny ); 3558 } 3559 } 3560 } 3561 catch( uno::Exception& ) 3562 { 3563 DBG_ERROR( "could not set enhanced customshape geometry" ); 3564 } 3565 SdXMLShapeContext::StartElement(xAttrList); 3566 } 3567 } 3568 3569 void SdXMLCustomShapeContext::EndElement() 3570 { 3571 if ( !maCustomShapeGeometry.empty() ) 3572 { 3573 const rtl::OUString sCustomShapeGeometry ( RTL_CONSTASCII_USTRINGPARAM( "CustomShapeGeometry" ) ); 3574 3575 // converting the vector to a sequence 3576 uno::Sequence< beans::PropertyValue > aSeq( maCustomShapeGeometry.size() ); 3577 beans::PropertyValue* pValues = aSeq.getArray(); 3578 std::vector< beans::PropertyValue >::const_iterator aIter( maCustomShapeGeometry.begin() ); 3579 std::vector< beans::PropertyValue >::const_iterator aEnd( maCustomShapeGeometry.end() ); 3580 while ( aIter != aEnd ) 3581 *pValues++ = *aIter++; 3582 3583 try 3584 { 3585 uno::Reference< beans::XPropertySet > xPropSet( mxShape, uno::UNO_QUERY ); 3586 if( xPropSet.is() ) 3587 { 3588 uno::Any aAny; 3589 aAny <<= aSeq; 3590 xPropSet->setPropertyValue( sCustomShapeGeometry, aAny ); 3591 } 3592 } 3593 catch( uno::Exception& ) 3594 { 3595 DBG_ERROR( "could not set enhanced customshape geometry" ); 3596 } 3597 3598 sal_Int32 nUPD( 0 ); 3599 sal_Int32 nBuild( 0 ); 3600 GetImport().getBuildIds( nUPD, nBuild ); 3601 if( ((nUPD >= 640 && nUPD <= 645) || (nUPD == 680)) && (nBuild <= 9221) ) 3602 { 3603 Reference< drawing::XEnhancedCustomShapeDefaulter > xDefaulter( mxShape, UNO_QUERY ); 3604 if( xDefaulter.is() ) 3605 { 3606 rtl::OUString aEmptyType; 3607 xDefaulter->createCustomShapeDefaults( aEmptyType ); 3608 } 3609 } 3610 } 3611 3612 SdXMLShapeContext::EndElement(); 3613 } 3614 3615 ////////////////////////////////////////////////////////////////////////////// 3616 3617 SvXMLImportContext* SdXMLCustomShapeContext::CreateChildContext( 3618 sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, 3619 const uno::Reference<xml::sax::XAttributeList>& xAttrList ) 3620 { 3621 SvXMLImportContext* pContext = NULL; 3622 if ( XML_NAMESPACE_DRAW == nPrefix ) 3623 { 3624 if ( IsXMLToken( rLocalName, XML_ENHANCED_GEOMETRY ) ) 3625 { 3626 uno::Reference< beans::XPropertySet > xPropSet( mxShape,uno::UNO_QUERY ); 3627 if ( xPropSet.is() ) 3628 pContext = new XMLEnhancedCustomShapeContext( GetImport(), mxShape, nPrefix, rLocalName, maCustomShapeGeometry ); 3629 } 3630 } 3631 // delegate to parent class if no context could be created 3632 if ( NULL == pContext ) 3633 pContext = SdXMLShapeContext::CreateChildContext( nPrefix, rLocalName, 3634 xAttrList); 3635 return pContext; 3636 } 3637 3638 /////////////////////////////////////////////////////////////////////// 3639 3640 ////////////////////////////////////////////////////////////////////////////// 3641 3642 TYPEINIT1( SdXMLTableShapeContext, SdXMLShapeContext ); 3643 3644 SdXMLTableShapeContext::SdXMLTableShapeContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLocalName, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes ) 3645 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, sal_False ) 3646 { 3647 memset( &maTemplateStylesUsed, 0, sizeof( maTemplateStylesUsed ) ); 3648 } 3649 3650 SdXMLTableShapeContext::~SdXMLTableShapeContext() 3651 { 3652 } 3653 3654 void SdXMLTableShapeContext::StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ) 3655 { 3656 const char* pService = "com.sun.star.drawing.TableShape"; 3657 3658 sal_Bool bIsPresShape = maPresentationClass.getLength() && GetImport().GetShapeImport()->IsPresentationShapesSupported(); 3659 if( bIsPresShape ) 3660 { 3661 if( IsXMLToken( maPresentationClass, XML_PRESENTATION_TABLE ) ) 3662 { 3663 pService = "com.sun.star.presentation.TableShape"; 3664 } 3665 } 3666 3667 AddShape( pService ); 3668 3669 if( mxShape.is() ) 3670 { 3671 SetLayer(); 3672 3673 uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY); 3674 3675 if(bIsPresShape) 3676 { 3677 if(xProps.is()) 3678 { 3679 uno::Reference< beans::XPropertySetInfo > xPropsInfo( xProps->getPropertySetInfo() ); 3680 if( xPropsInfo.is() ) 3681 { 3682 if( !mbIsPlaceholder && xPropsInfo->hasPropertyByName(OUString(RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") ))) 3683 xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") ), ::cppu::bool2any( sal_False ) ); 3684 3685 if( mbIsUserTransformed && xPropsInfo->hasPropertyByName(OUString(RTL_CONSTASCII_USTRINGPARAM("IsPlaceholderDependent") ))) 3686 xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("IsPlaceholderDependent") ), ::cppu::bool2any( sal_False ) ); 3687 } 3688 } 3689 } 3690 3691 SetStyle(); 3692 3693 if( xProps.is() ) 3694 { 3695 if( msTemplateStyleName.getLength() ) try 3696 { 3697 Reference< XStyleFamiliesSupplier > xFamiliesSupp( GetImport().GetModel(), UNO_QUERY_THROW ); 3698 Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() ); 3699 const OUString sFamilyName( RTL_CONSTASCII_USTRINGPARAM("table" ) ); 3700 Reference< XNameAccess > xTableFamily( xFamilies->getByName( sFamilyName ), UNO_QUERY_THROW ); 3701 Reference< XStyle > xTableStyle( xTableFamily->getByName( msTemplateStyleName ), UNO_QUERY_THROW ); 3702 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "TableTemplate" ) ), Any( xTableStyle ) ); 3703 } 3704 catch( Exception& ) 3705 { 3706 DBG_ERROR("SdXMLTableShapeContext::StartElement(), exception caught!"); 3707 } 3708 3709 const XMLPropertyMapEntry* pEntry = &aXMLTableShapeAttributes[0]; 3710 for( int i = 0; pEntry->msApiName && (i < 6); i++, pEntry++ ) 3711 { 3712 try 3713 { 3714 const OUString sAPIPropertyName( OUString(pEntry->msApiName, pEntry->nApiNameLength, RTL_TEXTENCODING_ASCII_US ) ); 3715 xProps->setPropertyValue( sAPIPropertyName, Any( maTemplateStylesUsed[i] ) ); 3716 } 3717 catch( Exception& ) 3718 { 3719 DBG_ERROR("SdXMLTableShapeContext::StartElement(), exception caught!"); 3720 } 3721 } 3722 } 3723 3724 GetImport().GetShapeImport()->finishShape( mxShape, mxAttrList, mxShapes ); 3725 3726 const rtl::Reference< XMLTableImport >& xTableImport( GetImport().GetShapeImport()->GetShapeTableImport() ); 3727 if( xTableImport.is() && xProps.is() ) 3728 { 3729 uno::Reference< table::XColumnRowRange > xColumnRowRange( 3730 xProps->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("Model") ) ), uno::UNO_QUERY ); 3731 3732 if( xColumnRowRange.is() ) 3733 mxTableImportContext = xTableImport->CreateTableContext( GetPrefix(), GetLocalName(), xColumnRowRange ); 3734 3735 if( mxTableImportContext.Is() ) 3736 mxTableImportContext->StartElement( xAttrList ); 3737 } 3738 } 3739 } 3740 3741 void SdXMLTableShapeContext::EndElement() 3742 { 3743 if( mxTableImportContext.Is() ) 3744 mxTableImportContext->EndElement(); 3745 3746 SdXMLShapeContext::EndElement(); 3747 3748 if( mxShape.is() ) 3749 { 3750 // set pos, size, shear and rotate 3751 SetTransformation(); 3752 } 3753 } 3754 3755 // this is called from the parent group for each unparsed attribute in the attribute list 3756 void SdXMLTableShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue ) 3757 { 3758 if( nPrefix == XML_NAMESPACE_TABLE ) 3759 { 3760 if( IsXMLToken( rLocalName, XML_TEMPLATE_NAME ) ) 3761 { 3762 msTemplateStyleName = rValue; 3763 } 3764 else 3765 { 3766 int i = 0; 3767 const XMLPropertyMapEntry* pEntry = &aXMLTableShapeAttributes[0]; 3768 while( pEntry->msApiName && (i < 6) ) 3769 { 3770 if( IsXMLToken( rLocalName, pEntry->meXMLName ) ) 3771 { 3772 if( IsXMLToken( rValue, XML_TRUE ) ) 3773 maTemplateStylesUsed[i] = sal_True; 3774 break; 3775 } 3776 pEntry++; 3777 i++; 3778 } 3779 } 3780 } 3781 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue ); 3782 } 3783 3784 SvXMLImportContext* SdXMLTableShapeContext::CreateChildContext( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& xAttrList ) 3785 { 3786 if( mxTableImportContext.Is() && (nPrefix == XML_NAMESPACE_TABLE) ) 3787 return mxTableImportContext->CreateChildContext(nPrefix, rLocalName, xAttrList); 3788 else 3789 return SdXMLShapeContext::CreateChildContext(nPrefix, rLocalName, xAttrList); 3790 } 3791 3792