1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svx.hxx" 26 27 #define _ANIMATION 28 #include <unotools/streamwrap.hxx> 29 30 #include <sfx2/lnkbase.hxx> 31 #include <math.h> 32 #include <vcl/salbtype.hxx> 33 #include <sot/formats.hxx> 34 #include <sot/storage.hxx> 35 #include <unotools/ucbstreamhelper.hxx> 36 #include <unotools/localfilehelper.hxx> 37 #include <svl/style.hxx> 38 #include <svtools/filter.hxx> 39 #include <svl/urihelper.hxx> 40 #include <svtools/grfmgr.hxx> 41 #include <vcl/svapp.hxx> 42 43 #include <sfx2/linkmgr.hxx> 44 #include <sfx2/docfile.hxx> 45 #include <svx/svdetc.hxx> 46 #include "svx/svdglob.hxx" 47 #include "svx/svdstr.hrc" 48 #include <svx/svdpool.hxx> 49 #include <svx/svdmodel.hxx> 50 #include <svx/svdpage.hxx> 51 #include <svx/svdmrkv.hxx> 52 #include <svx/svdpagv.hxx> 53 #include "svx/svdviter.hxx" 54 #include <svx/svdview.hxx> 55 #include "svtools/filter.hxx" 56 #include <svx/svdograf.hxx> 57 #include <svx/svdogrp.hxx> 58 #include <svx/xbtmpit.hxx> 59 #include <svx/xflbmtit.hxx> 60 #include <svx/svdundo.hxx> 61 #include "svdfmtf.hxx" 62 #include <svx/sdgcpitm.hxx> 63 #include <editeng/eeitem.hxx> 64 #include <svx/sdr/properties/graphicproperties.hxx> 65 #include <svx/sdr/contact/viewcontactofgraphic.hxx> 66 #include <basegfx/polygon/b2dpolygon.hxx> 67 #include <basegfx/polygon/b2dpolygontools.hxx> 68 #include <osl/thread.hxx> 69 #include <vos/mutex.hxx> 70 #include <drawinglayer/processor2d/objectinfoextractor2d.hxx> 71 #include <drawinglayer/primitive2d/objectinfoprimitive2d.hxx> 72 73 using namespace ::com::sun::star::uno; 74 using namespace ::com::sun::star::io; 75 76 // ----------- 77 // - Defines - 78 // ----------- 79 80 #define GRAFSTREAMPOS_INVALID 0xffffffff 81 #define SWAPGRAPHIC_TIMEOUT 5000 82 83 84 // ------------------ 85 // - SdrGraphicLink - 86 // ------------------ 87 88 89 const Graphic ImpLoadLinkedGraphic( const String aFileName, const String aFilterName ) 90 { 91 Graphic aGraphic; 92 93 SfxMedium xMed( aFileName, STREAM_STD_READ, sal_True ); 94 xMed.DownLoad(); 95 96 SvStream* pInStrm = xMed.GetInStream(); 97 if ( pInStrm ) 98 { 99 pInStrm->Seek( STREAM_SEEK_TO_BEGIN ); 100 GraphicFilter* pGF = GraphicFilter::GetGraphicFilter(); 101 102 const sal_uInt16 nFilter = aFilterName.Len() && pGF->GetImportFormatCount() 103 ? pGF->GetImportFormatNumber( aFilterName ) 104 : GRFILTER_FORMAT_DONTKNOW; 105 106 String aEmptyStr; 107 com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > aFilterData( 1 ); 108 109 // Room for improvment: 110 // As this is a linked graphic the GfxLink is not needed if saving/loading our own format. 111 // But this link is required by some filters to access the native graphic (pdf export/ms export), 112 // there we should create a new service to provide this data if needed 113 aFilterData[ 0 ].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CreateNativeLink" ) ); 114 aFilterData[ 0 ].Value = Any( sal_True ); 115 pGF->ImportGraphic( aGraphic, aEmptyStr, *pInStrm, nFilter, NULL, 0, &aFilterData ); 116 } 117 return aGraphic; 118 } 119 120 class SdrGraphicUpdater; 121 class SdrGraphicLink : public sfx2::SvBaseLink 122 { 123 SdrGrafObj* pGrafObj; 124 SdrGraphicUpdater* pGraphicUpdater; 125 126 public: 127 SdrGraphicLink(SdrGrafObj* pObj); 128 virtual ~SdrGraphicLink(); 129 130 virtual void Closed(); 131 virtual void DataChanged( const String& rMimeType, 132 const ::com::sun::star::uno::Any & rValue ); 133 void DataChanged( const Graphic& rGraphic ); 134 135 sal_Bool Connect() { return 0 != GetRealObject(); } 136 void UpdateAsynchron(); 137 void RemoveGraphicUpdater(); 138 }; 139 140 class SdrGraphicUpdater : public ::osl::Thread 141 { 142 public: 143 SdrGraphicUpdater( const String& rFileName, const String& rFilterName, SdrGraphicLink& ); 144 virtual ~SdrGraphicUpdater( void ); 145 146 void SAL_CALL Terminate( void ); 147 148 sal_Bool GraphicLinkChanged( const String& rFileName ){ return maFileName != rFileName; }; 149 150 protected: 151 152 /** is called from the inherited create method and acts as the 153 main function of this thread. 154 */ 155 virtual void SAL_CALL run(void); 156 157 /** Called after the thread is terminated via the terminate 158 method. Used to kill the thread by calling delete on this. 159 */ 160 virtual void SAL_CALL onTerminated(void); 161 162 private: 163 164 const String maFileName; 165 const String maFilterName; 166 SdrGraphicLink& mrGraphicLink; 167 168 volatile bool mbIsTerminated; 169 }; 170 171 SdrGraphicUpdater::SdrGraphicUpdater( const String& rFileName, const String& rFilterName, SdrGraphicLink& rGraphicLink ) 172 : maFileName( rFileName ) 173 , maFilterName( rFilterName ) 174 , mrGraphicLink( rGraphicLink ) 175 , mbIsTerminated( sal_False ) 176 { 177 create(); 178 } 179 180 SdrGraphicUpdater::~SdrGraphicUpdater( void ) 181 { 182 } 183 184 void SdrGraphicUpdater::Terminate() 185 { 186 mbIsTerminated = sal_True; 187 } 188 189 void SAL_CALL SdrGraphicUpdater::onTerminated(void) 190 { 191 delete this; 192 } 193 194 void SAL_CALL SdrGraphicUpdater::run(void) 195 { 196 Graphic aGraphic( ImpLoadLinkedGraphic( maFileName, maFilterName ) ); 197 vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 198 if ( !mbIsTerminated ) 199 { 200 mrGraphicLink.DataChanged( aGraphic ); 201 mrGraphicLink.RemoveGraphicUpdater(); 202 } 203 } 204 205 // ----------------------------------------------------------------------------- 206 207 SdrGraphicLink::SdrGraphicLink(SdrGrafObj* pObj) 208 : ::sfx2::SvBaseLink( ::sfx2::LINKUPDATE_ONCALL, SOT_FORMATSTR_ID_SVXB ) 209 , pGrafObj( pObj ) 210 , pGraphicUpdater( NULL ) 211 { 212 SetSynchron( sal_False ); 213 } 214 215 // ----------------------------------------------------------------------------- 216 217 SdrGraphicLink::~SdrGraphicLink() 218 { 219 if ( pGraphicUpdater ) 220 pGraphicUpdater->Terminate(); 221 } 222 223 // ----------------------------------------------------------------------------- 224 225 void SdrGraphicLink::DataChanged( const Graphic& rGraphic ) 226 { 227 pGrafObj->ImpSetLinkedGraphic( rGraphic ); 228 } 229 230 // ----------------------------------------------------------------------------- 231 232 void SdrGraphicLink::RemoveGraphicUpdater() 233 { 234 pGraphicUpdater = NULL; 235 } 236 237 // ----------------------------------------------------------------------------- 238 239 void SdrGraphicLink::DataChanged( const String& rMimeType, 240 const ::com::sun::star::uno::Any & rValue ) 241 { 242 SdrModel* pModel = pGrafObj ? pGrafObj->GetModel() : 0; 243 sfx2::LinkManager* pLinkManager= pModel ? pModel->GetLinkManager() : 0; 244 245 if( pLinkManager && rValue.hasValue() ) 246 { 247 pLinkManager->GetDisplayNames( this, 0, &pGrafObj->aFileName, 0, &pGrafObj->aFilterName ); 248 249 Graphic aGraphic; 250 if( sfx2::LinkManager::GetGraphicFromAny( rMimeType, rValue, aGraphic )) 251 { 252 pGrafObj->NbcSetGraphic( aGraphic ); 253 pGrafObj->ActionChanged(); 254 } 255 else if( SotExchange::GetFormatIdFromMimeType( rMimeType ) != sfx2::LinkManager::RegisterStatusInfoId() ) 256 { 257 // broadcasting, to update slidesorter 258 pGrafObj->BroadcastObjectChange(); 259 } 260 } 261 } 262 263 // ----------------------------------------------------------------------------- 264 265 void SdrGraphicLink::Closed() 266 { 267 // Die Verbindung wird aufgehoben; pLink des Objekts auf NULL setzen, da die Link-Instanz ja gerade destruiert wird. 268 pGrafObj->ForceSwapIn(); 269 pGrafObj->pGraphicLink=NULL; 270 pGrafObj->ReleaseGraphicLink(); 271 SvBaseLink::Closed(); 272 } 273 274 // ----------------------------------------------------------------------------- 275 276 void SdrGraphicLink::UpdateAsynchron() 277 { 278 if( GetObj() ) 279 { 280 if ( pGraphicUpdater ) 281 { 282 if ( pGraphicUpdater->GraphicLinkChanged( pGrafObj->GetFileName() ) ) 283 { 284 pGraphicUpdater->Terminate(); 285 pGraphicUpdater = new SdrGraphicUpdater( pGrafObj->GetFileName(), pGrafObj->GetFilterName(), *this ); 286 } 287 } 288 else 289 pGraphicUpdater = new SdrGraphicUpdater( pGrafObj->GetFileName(), pGrafObj->GetFilterName(), *this ); 290 } 291 } 292 293 // -------------- 294 // - SdrGrafObj - 295 // -------------- 296 297 ////////////////////////////////////////////////////////////////////////////// 298 // BaseProperties section 299 300 sdr::properties::BaseProperties* SdrGrafObj::CreateObjectSpecificProperties() 301 { 302 return new sdr::properties::GraphicProperties(*this); 303 } 304 305 ////////////////////////////////////////////////////////////////////////////// 306 // DrawContact section 307 308 sdr::contact::ViewContact* SdrGrafObj::CreateObjectSpecificViewContact() 309 { 310 return new sdr::contact::ViewContactOfGraphic(*this); 311 } 312 313 ////////////////////////////////////////////////////////////////////////////// 314 // check if SVG and if try to get ObjectInfoPrimitive2D and extract info 315 316 void SdrGrafObj::onGraphicChanged() 317 { 318 String aName; 319 String aTitle; 320 String aDesc; 321 322 if(pGraphic) 323 { 324 const SvgDataPtr& rSvgDataPtr = pGraphic->GetGraphic().getSvgData(); 325 326 if(rSvgDataPtr.get()) 327 { 328 const drawinglayer::primitive2d::Primitive2DSequence aSequence(rSvgDataPtr->getPrimitive2DSequence()); 329 330 if(aSequence.hasElements()) 331 { 332 drawinglayer::geometry::ViewInformation2D aViewInformation2D; 333 drawinglayer::processor2d::ObjectInfoPrimitiveExtractor2D aProcessor(aViewInformation2D); 334 335 aProcessor.process(aSequence); 336 337 const drawinglayer::primitive2d::ObjectInfoPrimitive2D* pResult = aProcessor.getResult(); 338 339 if(pResult) 340 { 341 aName = pResult->getName(); 342 aTitle = pResult->getTitle(); 343 aDesc = pResult->getDesc(); 344 } 345 } 346 } 347 } 348 349 if(aName.Len()) 350 { 351 SetName(aName); 352 } 353 354 if(aTitle.Len()) 355 { 356 SetTitle(aTitle); 357 } 358 359 if(aDesc.Len()) 360 { 361 SetDescription(aDesc); 362 } 363 } 364 365 ////////////////////////////////////////////////////////////////////////////// 366 367 TYPEINIT1(SdrGrafObj,SdrRectObj); 368 369 // ----------------------------------------------------------------------------- 370 371 SdrGrafObj::SdrGrafObj() 372 : SdrRectObj(), 373 pGraphicLink ( NULL ), 374 bMirrored ( sal_False ) 375 { 376 pGraphic = new GraphicObject; 377 mpReplacementGraphic = 0; 378 pGraphic->SetSwapStreamHdl( LINK( this, SdrGrafObj, ImpSwapHdl ), SWAPGRAPHIC_TIMEOUT ); 379 onGraphicChanged(); 380 381 // #i118485# Shear allowed and possible now 382 bNoShear = false; 383 384 // #111096# 385 mbGrafAnimationAllowed = sal_True; 386 387 // #i25616# 388 mbLineIsOutsideGeometry = sal_True; 389 mbInsidePaint = sal_False; 390 mbIsPreview = sal_False; 391 392 // #i25616# 393 mbSupportTextIndentingOnLineWidthChange = sal_False; 394 } 395 396 // ----------------------------------------------------------------------------- 397 398 SdrGrafObj::SdrGrafObj(const Graphic& rGrf, const Rectangle& rRect) 399 : SdrRectObj ( rRect ), 400 pGraphicLink ( NULL ), 401 bMirrored ( sal_False ) 402 { 403 pGraphic = new GraphicObject( rGrf ); 404 mpReplacementGraphic = 0; 405 pGraphic->SetSwapStreamHdl( LINK( this, SdrGrafObj, ImpSwapHdl ), SWAPGRAPHIC_TIMEOUT ); 406 onGraphicChanged(); 407 408 // #i118485# Shear allowed and possible now 409 bNoShear = false; 410 411 // #111096# 412 mbGrafAnimationAllowed = sal_True; 413 414 // #i25616# 415 mbLineIsOutsideGeometry = sal_True; 416 mbInsidePaint = sal_False; 417 mbIsPreview = sal_False; 418 419 // #i25616# 420 mbSupportTextIndentingOnLineWidthChange = sal_False; 421 } 422 423 // ----------------------------------------------------------------------------- 424 425 SdrGrafObj::SdrGrafObj( const Graphic& rGrf ) 426 : SdrRectObj(), 427 pGraphicLink ( NULL ), 428 bMirrored ( sal_False ) 429 { 430 pGraphic = new GraphicObject( rGrf ); 431 mpReplacementGraphic = 0; 432 pGraphic->SetSwapStreamHdl( LINK( this, SdrGrafObj, ImpSwapHdl ), SWAPGRAPHIC_TIMEOUT ); 433 onGraphicChanged(); 434 435 // #i118485# Shear allowed and possible now 436 bNoShear = false; 437 438 // #111096# 439 mbGrafAnimationAllowed = sal_True; 440 441 // #i25616# 442 mbLineIsOutsideGeometry = sal_True; 443 mbInsidePaint = sal_False; 444 mbIsPreview = sal_False; 445 446 // #i25616# 447 mbSupportTextIndentingOnLineWidthChange = sal_False; 448 } 449 450 // ----------------------------------------------------------------------------- 451 452 SdrGrafObj::~SdrGrafObj() 453 { 454 delete pGraphic; 455 delete mpReplacementGraphic; 456 ImpLinkAbmeldung(); 457 } 458 459 // ----------------------------------------------------------------------------- 460 461 void SdrGrafObj::SetGraphicObject( const GraphicObject& rGrfObj ) 462 { 463 *pGraphic = rGrfObj; 464 delete mpReplacementGraphic; 465 mpReplacementGraphic = 0; 466 pGraphic->SetSwapStreamHdl( LINK( this, SdrGrafObj, ImpSwapHdl ), SWAPGRAPHIC_TIMEOUT ); 467 pGraphic->SetUserData(); 468 mbIsPreview = sal_False; 469 SetChanged(); 470 BroadcastObjectChange(); 471 onGraphicChanged(); 472 } 473 474 // ----------------------------------------------------------------------------- 475 476 const GraphicObject& SdrGrafObj::GetGraphicObject(bool bForceSwapIn) const 477 { 478 if(bForceSwapIn) 479 { 480 ForceSwapIn(); 481 } 482 483 return *pGraphic; 484 } 485 486 const GraphicObject* SdrGrafObj::GetReplacementGraphicObject() const 487 { 488 if(!mpReplacementGraphic && pGraphic) 489 { 490 const SvgDataPtr& rSvgDataPtr = pGraphic->GetGraphic().getSvgData(); 491 492 if(rSvgDataPtr.get()) 493 { 494 const_cast< SdrGrafObj* >(this)->mpReplacementGraphic = new GraphicObject(rSvgDataPtr->getReplacement()); 495 } 496 } 497 498 return mpReplacementGraphic; 499 } 500 501 // ----------------------------------------------------------------------------- 502 503 void SdrGrafObj::NbcSetGraphic( const Graphic& rGrf ) 504 { 505 pGraphic->SetGraphic( rGrf ); 506 delete mpReplacementGraphic; 507 mpReplacementGraphic = 0; 508 pGraphic->SetUserData(); 509 mbIsPreview = sal_False; 510 onGraphicChanged(); 511 } 512 513 void SdrGrafObj::SetGraphic( const Graphic& rGrf ) 514 { 515 NbcSetGraphic(rGrf); 516 SetChanged(); 517 BroadcastObjectChange(); 518 } 519 520 // ----------------------------------------------------------------------------- 521 522 const Graphic& SdrGrafObj::GetGraphic() const 523 { 524 ForceSwapIn(); 525 return pGraphic->GetGraphic(); 526 } 527 528 // ----------------------------------------------------------------------------- 529 530 Graphic SdrGrafObj::GetTransformedGraphic( sal_uIntPtr nTransformFlags ) const 531 { 532 // #107947# Refactored most of the code to GraphicObject, where 533 // everybody can use e.g. the cropping functionality 534 535 GraphicType eType = GetGraphicType(); 536 MapMode aDestMap( pModel->GetScaleUnit(), Point(), pModel->GetScaleFraction(), pModel->GetScaleFraction() ); 537 const Size aDestSize( GetLogicRect().GetSize() ); 538 const sal_Bool bMirror = ( nTransformFlags & SDRGRAFOBJ_TRANSFORMATTR_MIRROR ) != 0; 539 const sal_Bool bRotate = ( ( nTransformFlags & SDRGRAFOBJ_TRANSFORMATTR_ROTATE ) != 0 ) && 540 ( aGeo.nDrehWink && aGeo.nDrehWink != 18000 ) && ( GRAPHIC_NONE != eType ); 541 542 // #104115# Need cropping info earlier 543 ( (SdrGrafObj*) this )->ImpSetAttrToGrafInfo(); 544 GraphicAttr aActAttr; 545 546 if( SDRGRAFOBJ_TRANSFORMATTR_NONE != nTransformFlags && 547 GRAPHIC_NONE != eType ) 548 { 549 // actually transform the graphic only in this case. On the 550 // other hand, cropping will always happen 551 aActAttr = aGrafInfo; 552 553 if( bMirror ) 554 { 555 sal_uInt16 nMirrorCase = ( aGeo.nDrehWink == 18000 ) ? ( bMirrored ? 3 : 4 ) : ( bMirrored ? 2 : 1 ); 556 FASTBOOL bHMirr = nMirrorCase == 2 || nMirrorCase == 4; 557 FASTBOOL bVMirr = nMirrorCase == 3 || nMirrorCase == 4; 558 559 aActAttr.SetMirrorFlags( ( bHMirr ? BMP_MIRROR_HORZ : 0 ) | ( bVMirr ? BMP_MIRROR_VERT : 0 ) ); 560 } 561 562 if( bRotate ) 563 aActAttr.SetRotation( sal_uInt16(aGeo.nDrehWink / 10) ); 564 } 565 566 // #107947# Delegate to moved code in GraphicObject 567 return GetGraphicObject().GetTransformedGraphic( aDestSize, aDestMap, aActAttr ); 568 } 569 570 // ----------------------------------------------------------------------------- 571 572 GraphicType SdrGrafObj::GetGraphicType() const 573 { 574 return pGraphic->GetType(); 575 } 576 577 sal_Bool SdrGrafObj::IsAnimated() const 578 { 579 return pGraphic->IsAnimated(); 580 } 581 582 sal_Bool SdrGrafObj::IsEPS() const 583 { 584 return pGraphic->IsEPS(); 585 } 586 587 sal_Bool SdrGrafObj::IsSwappedOut() const 588 { 589 return mbIsPreview ? sal_True : pGraphic->IsSwappedOut(); 590 } 591 592 const MapMode& SdrGrafObj::GetGrafPrefMapMode() const 593 { 594 return pGraphic->GetPrefMapMode(); 595 } 596 597 const Size& SdrGrafObj::GetGrafPrefSize() const 598 { 599 return pGraphic->GetPrefSize(); 600 } 601 602 // ----------------------------------------------------------------------------- 603 604 void SdrGrafObj::SetGrafStreamURL( const String& rGraphicStreamURL ) 605 { 606 mbIsPreview = sal_False; 607 if( !rGraphicStreamURL.Len() ) 608 { 609 pGraphic->SetUserData(); 610 } 611 else if( pModel->IsSwapGraphics() ) 612 { 613 pGraphic->SetUserData( rGraphicStreamURL ); 614 615 // set state of graphic object to 'swapped out' 616 if( pGraphic->GetType() == GRAPHIC_NONE ) 617 pGraphic->SetSwapState(); 618 } 619 } 620 621 // ----------------------------------------------------------------------------- 622 623 String SdrGrafObj::GetGrafStreamURL() const 624 { 625 return pGraphic->GetUserData(); 626 } 627 628 // ----------------------------------------------------------------------------- 629 630 void SdrGrafObj::SetFileName(const String& rFileName) 631 { 632 aFileName = rFileName; 633 SetChanged(); 634 } 635 636 // ----------------------------------------------------------------------------- 637 638 void SdrGrafObj::SetFilterName(const String& rFilterName) 639 { 640 aFilterName = rFilterName; 641 SetChanged(); 642 } 643 644 // ----------------------------------------------------------------------------- 645 646 void SdrGrafObj::ForceSwapIn() const 647 { 648 if( mbIsPreview ) 649 { 650 // removing preview graphic 651 const String aUserData( pGraphic->GetUserData() ); 652 653 Graphic aEmpty; 654 pGraphic->SetGraphic( aEmpty ); 655 pGraphic->SetUserData( aUserData ); 656 pGraphic->SetSwapState(); 657 658 const_cast< SdrGrafObj* >( this )->mbIsPreview = sal_False; 659 } 660 if ( pGraphicLink && pGraphic->IsSwappedOut() ) 661 ImpUpdateGraphicLink( sal_False ); 662 else 663 pGraphic->FireSwapInRequest(); 664 665 if( pGraphic->IsSwappedOut() || 666 ( pGraphic->GetType() == GRAPHIC_NONE ) || 667 ( pGraphic->GetType() == GRAPHIC_DEFAULT ) ) 668 { 669 Graphic aDefaultGraphic; 670 aDefaultGraphic.SetDefaultType(); 671 pGraphic->SetGraphic( aDefaultGraphic ); 672 } 673 } 674 675 // ----------------------------------------------------------------------------- 676 677 void SdrGrafObj::ForceSwapOut() const 678 { 679 pGraphic->FireSwapOutRequest(); 680 } 681 682 // ----------------------------------------------------------------------------- 683 684 void SdrGrafObj::ImpLinkAnmeldung() 685 { 686 sfx2::LinkManager* pLinkManager = pModel != NULL ? pModel->GetLinkManager() : NULL; 687 688 if( pLinkManager != NULL && pGraphicLink == NULL ) 689 { 690 if( aFileName.Len() ) 691 { 692 pGraphicLink = new SdrGraphicLink( this ); 693 pLinkManager->InsertFileLink( *pGraphicLink, OBJECT_CLIENT_GRF, aFileName, ( aFilterName.Len() ? &aFilterName : NULL ), NULL ); 694 pGraphicLink->Connect(); 695 } 696 } 697 } 698 699 // ----------------------------------------------------------------------------- 700 701 void SdrGrafObj::ImpLinkAbmeldung() 702 { 703 sfx2::LinkManager* pLinkManager = pModel != NULL ? pModel->GetLinkManager() : NULL; 704 705 if( pLinkManager != NULL && pGraphicLink!=NULL) 706 { 707 // Bei Remove wird *pGraphicLink implizit deleted 708 pLinkManager->Remove( pGraphicLink ); 709 pGraphicLink=NULL; 710 } 711 } 712 713 // ----------------------------------------------------------------------------- 714 715 void SdrGrafObj::SetGraphicLink( const String& rFileName, const String& rFilterName ) 716 { 717 ImpLinkAbmeldung(); 718 aFileName = rFileName; 719 aFilterName = rFilterName; 720 ImpLinkAnmeldung(); 721 pGraphic->SetUserData(); 722 723 // #92205# A linked graphic is per definition swapped out (has to be loaded) 724 pGraphic->SetSwapState(); 725 } 726 727 // ----------------------------------------------------------------------------- 728 729 void SdrGrafObj::ReleaseGraphicLink() 730 { 731 ImpLinkAbmeldung(); 732 aFileName = String(); 733 aFilterName = String(); 734 } 735 736 // ----------------------------------------------------------------------------- 737 738 void SdrGrafObj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const 739 { 740 FASTBOOL bAnim = pGraphic->IsAnimated(); 741 FASTBOOL bNoPresGrf = ( pGraphic->GetType() != GRAPHIC_NONE ) && !bEmptyPresObj; 742 743 rInfo.bResizeFreeAllowed = aGeo.nDrehWink % 9000 == 0 || 744 aGeo.nDrehWink % 18000 == 0 || 745 aGeo.nDrehWink % 27000 == 0; 746 747 rInfo.bResizePropAllowed = sal_True; 748 rInfo.bRotateFreeAllowed = bNoPresGrf && !bAnim; 749 rInfo.bRotate90Allowed = bNoPresGrf && !bAnim; 750 rInfo.bMirrorFreeAllowed = bNoPresGrf && !bAnim; 751 rInfo.bMirror45Allowed = bNoPresGrf && !bAnim; 752 rInfo.bMirror90Allowed = !bEmptyPresObj; 753 rInfo.bTransparenceAllowed = sal_False; 754 rInfo.bGradientAllowed = sal_False; 755 756 // #i118485# Shear allowed and possible now 757 rInfo.bShearAllowed = true; 758 759 rInfo.bEdgeRadiusAllowed=sal_False; 760 rInfo.bCanConvToPath = !IsEPS(); 761 rInfo.bCanConvToPathLineToArea = sal_False; 762 rInfo.bCanConvToPolyLineToArea = sal_False; 763 rInfo.bCanConvToPoly = !IsEPS(); 764 rInfo.bCanConvToContour = (rInfo.bCanConvToPoly || LineGeometryUsageIsNecessary()); 765 } 766 767 // ----------------------------------------------------------------------------- 768 769 sal_uInt16 SdrGrafObj::GetObjIdentifier() const 770 { 771 return sal_uInt16( OBJ_GRAF ); 772 } 773 774 // ----------------------------------------------------------------------------- 775 776 /* The graphic of the GraphicLink will be loaded. If it is called with 777 bAsynchron = true then the graphic will be set later via DataChanged 778 */ 779 sal_Bool SdrGrafObj::ImpUpdateGraphicLink( sal_Bool bAsynchron ) const 780 { 781 sal_Bool bRet = sal_False; 782 if( pGraphicLink ) 783 { 784 if ( bAsynchron ) 785 pGraphicLink->UpdateAsynchron(); 786 else 787 pGraphicLink->DataChanged( ImpLoadLinkedGraphic( aFileName, aFilterName ) ); 788 bRet = sal_True; 789 } 790 return bRet; 791 } 792 793 // ----------------------------------------------------------------------------- 794 795 void SdrGrafObj::ImpSetLinkedGraphic( const Graphic& rGraphic ) 796 { 797 const sal_Bool bIsChanged = GetModel()->IsChanged(); 798 NbcSetGraphic( rGraphic ); 799 ActionChanged(); 800 BroadcastObjectChange(); 801 GetModel()->SetChanged( bIsChanged ); 802 } 803 804 // ----------------------------------------------------------------------------- 805 806 void SdrGrafObj::TakeObjNameSingul(XubString& rName) const 807 { 808 if(pGraphic) 809 { 810 const SvgDataPtr& rSvgDataPtr = pGraphic->GetGraphic().getSvgData(); 811 812 if(rSvgDataPtr.get()) 813 { 814 rName = ImpGetResStr(STR_ObjNameSingulGRAFSVG); 815 } 816 else 817 { 818 switch( pGraphic->GetType() ) 819 { 820 case GRAPHIC_BITMAP: 821 { 822 const sal_uInt16 nId = ( ( pGraphic->IsTransparent() || ( (const SdrGrafTransparenceItem&) GetObjectItem( SDRATTR_GRAFTRANSPARENCE ) ).GetValue() ) ? 823 ( IsLinkedGraphic() ? STR_ObjNameSingulGRAFBMPTRANSLNK : STR_ObjNameSingulGRAFBMPTRANS ) : 824 ( IsLinkedGraphic() ? STR_ObjNameSingulGRAFBMPLNK : STR_ObjNameSingulGRAFBMP ) ); 825 826 rName=ImpGetResStr( nId ); 827 } 828 break; 829 830 case GRAPHIC_GDIMETAFILE: 831 rName=ImpGetResStr( IsLinkedGraphic() ? STR_ObjNameSingulGRAFMTFLNK : STR_ObjNameSingulGRAFMTF ); 832 break; 833 834 case GRAPHIC_NONE: 835 rName=ImpGetResStr( IsLinkedGraphic() ? STR_ObjNameSingulGRAFNONELNK : STR_ObjNameSingulGRAFNONE ); 836 break; 837 838 default: 839 rName=ImpGetResStr( IsLinkedGraphic() ? STR_ObjNameSingulGRAFLNK : STR_ObjNameSingulGRAF ); 840 break; 841 } 842 } 843 844 const String aName(GetName()); 845 846 if( aName.Len() ) 847 { 848 rName.AppendAscii( " '" ); 849 rName += aName; 850 rName += sal_Unicode( '\'' ); 851 } 852 } 853 } 854 855 // ----------------------------------------------------------------------------- 856 857 void SdrGrafObj::TakeObjNamePlural( XubString& rName ) const 858 { 859 if(pGraphic) 860 { 861 const SvgDataPtr& rSvgDataPtr = pGraphic->GetGraphic().getSvgData(); 862 863 if(rSvgDataPtr.get()) 864 { 865 rName = ImpGetResStr(STR_ObjNamePluralGRAFSVG); 866 } 867 else 868 { 869 switch( pGraphic->GetType() ) 870 { 871 case GRAPHIC_BITMAP: 872 { 873 const sal_uInt16 nId = ( ( pGraphic->IsTransparent() || ( (const SdrGrafTransparenceItem&) GetObjectItem( SDRATTR_GRAFTRANSPARENCE ) ).GetValue() ) ? 874 ( IsLinkedGraphic() ? STR_ObjNamePluralGRAFBMPTRANSLNK : STR_ObjNamePluralGRAFBMPTRANS ) : 875 ( IsLinkedGraphic() ? STR_ObjNamePluralGRAFBMPLNK : STR_ObjNamePluralGRAFBMP ) ); 876 877 rName=ImpGetResStr( nId ); 878 } 879 break; 880 881 case GRAPHIC_GDIMETAFILE: 882 rName=ImpGetResStr( IsLinkedGraphic() ? STR_ObjNamePluralGRAFMTFLNK : STR_ObjNamePluralGRAFMTF ); 883 break; 884 885 case GRAPHIC_NONE: 886 rName=ImpGetResStr( IsLinkedGraphic() ? STR_ObjNamePluralGRAFNONELNK : STR_ObjNamePluralGRAFNONE ); 887 break; 888 889 default: 890 rName=ImpGetResStr( IsLinkedGraphic() ? STR_ObjNamePluralGRAFLNK : STR_ObjNamePluralGRAF ); 891 break; 892 } 893 } 894 895 const String aName(GetName()); 896 897 if( aName.Len() ) 898 { 899 rName.AppendAscii( " '" ); 900 rName += aName; 901 rName += sal_Unicode( '\'' ); 902 } 903 } 904 } 905 906 // ----------------------------------------------------------------------------- 907 908 SdrObject* SdrGrafObj::getFullDragClone() const 909 { 910 // call parent 911 SdrGrafObj* pRetval = static_cast< SdrGrafObj* >(SdrRectObj::getFullDragClone()); 912 913 // #i103116# the full drag clone leads to problems 914 // with linked graphics, so reset the link in this 915 // temporary interaction object and load graphic 916 if(pRetval && IsLinkedGraphic()) 917 { 918 pRetval->ForceSwapIn(); 919 pRetval->ReleaseGraphicLink(); 920 } 921 922 return pRetval; 923 } 924 925 void SdrGrafObj::operator=( const SdrObject& rObj ) 926 { 927 SdrRectObj::operator=( rObj ); 928 929 const SdrGrafObj& rGraf = (SdrGrafObj&) rObj; 930 931 pGraphic->SetGraphic( rGraf.GetGraphic(), &rGraf.GetGraphicObject() ); 932 aCropRect = rGraf.aCropRect; 933 aFileName = rGraf.aFileName; 934 aFilterName = rGraf.aFilterName; 935 bMirrored = rGraf.bMirrored; 936 937 if( rGraf.pGraphicLink != NULL) 938 { 939 SetGraphicLink( aFileName, aFilterName ); 940 } 941 942 ImpSetAttrToGrafInfo(); 943 } 944 945 // ----------------------------------------------------------------------------- 946 // #i25616# 947 948 basegfx::B2DPolyPolygon SdrGrafObj::TakeXorPoly() const 949 { 950 if(mbInsidePaint) 951 { 952 basegfx::B2DPolyPolygon aRetval; 953 954 // take grown rectangle 955 const sal_Int32 nHalfLineWidth(ImpGetLineWdt() / 2); 956 const Rectangle aGrownRect( 957 aRect.Left() - nHalfLineWidth, 958 aRect.Top() - nHalfLineWidth, 959 aRect.Right() + nHalfLineWidth, 960 aRect.Bottom() + nHalfLineWidth); 961 962 XPolygon aXPoly(ImpCalcXPoly(aGrownRect, GetEckenradius())); 963 aRetval.append(aXPoly.getB2DPolygon()); 964 965 return aRetval; 966 } 967 else 968 { 969 // call parent 970 return SdrRectObj::TakeXorPoly(); 971 } 972 } 973 974 // ----------------------------------------------------------------------------- 975 976 sal_uInt32 SdrGrafObj::GetHdlCount() const 977 { 978 return 8L; 979 } 980 981 // ----------------------------------------------------------------------------- 982 983 SdrHdl* SdrGrafObj::GetHdl(sal_uInt32 nHdlNum) const 984 { 985 return SdrRectObj::GetHdl( nHdlNum + 1L ); 986 } 987 988 // ----------------------------------------------------------------------------- 989 990 void SdrGrafObj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact) 991 { 992 SdrRectObj::NbcResize( rRef, xFact, yFact ); 993 994 FASTBOOL bMirrX = xFact.GetNumerator() < 0; 995 FASTBOOL bMirrY = yFact.GetNumerator() < 0; 996 997 if( bMirrX != bMirrY ) 998 bMirrored = !bMirrored; 999 } 1000 1001 // ----------------------------------------------------------------------------- 1002 1003 void SdrGrafObj::NbcRotate(const Point& rRef, long nWink, double sn, double cs) 1004 { 1005 SdrRectObj::NbcRotate(rRef,nWink,sn,cs); 1006 } 1007 1008 // ----------------------------------------------------------------------------- 1009 1010 void SdrGrafObj::NbcMirror(const Point& rRef1, const Point& rRef2) 1011 { 1012 SdrRectObj::NbcMirror(rRef1,rRef2); 1013 bMirrored = !bMirrored; 1014 } 1015 1016 // ----------------------------------------------------------------------------- 1017 1018 void SdrGrafObj::NbcShear(const Point& rRef, long nWink, double tn, FASTBOOL bVShear) 1019 { 1020 // #i118485# Call Shear now, old version redirected to rotate 1021 SdrRectObj::NbcShear(rRef, nWink, tn, bVShear); 1022 } 1023 1024 // ----------------------------------------------------------------------------- 1025 1026 void SdrGrafObj::NbcSetSnapRect(const Rectangle& rRect) 1027 { 1028 SdrRectObj::NbcSetSnapRect(rRect); 1029 } 1030 1031 // ----------------------------------------------------------------------------- 1032 1033 void SdrGrafObj::NbcSetLogicRect( const Rectangle& rRect) 1034 { 1035 //int bChg=rRect.GetSize()!=aRect.GetSize(); 1036 SdrRectObj::NbcSetLogicRect(rRect); 1037 } 1038 1039 // ----------------------------------------------------------------------------- 1040 1041 SdrObjGeoData* SdrGrafObj::NewGeoData() const 1042 { 1043 return new SdrGrafObjGeoData; 1044 } 1045 1046 // ----------------------------------------------------------------------------- 1047 1048 void SdrGrafObj::SaveGeoData(SdrObjGeoData& rGeo) const 1049 { 1050 SdrRectObj::SaveGeoData(rGeo); 1051 SdrGrafObjGeoData& rGGeo=(SdrGrafObjGeoData&)rGeo; 1052 rGGeo.bMirrored=bMirrored; 1053 } 1054 1055 // ----------------------------------------------------------------------------- 1056 1057 void SdrGrafObj::RestGeoData(const SdrObjGeoData& rGeo) 1058 { 1059 //long nDrehMerk = aGeo.nDrehWink; 1060 //long nShearMerk = aGeo.nShearWink; 1061 //int bMirrMerk = bMirrored; 1062 Size aSizMerk( aRect.GetSize() ); 1063 1064 SdrRectObj::RestGeoData(rGeo); 1065 SdrGrafObjGeoData& rGGeo=(SdrGrafObjGeoData&)rGeo; 1066 bMirrored=rGGeo.bMirrored; 1067 } 1068 1069 // ----------------------------------------------------------------------------- 1070 1071 void SdrGrafObj::SetPage( SdrPage* pNewPage ) 1072 { 1073 FASTBOOL bRemove = pNewPage == NULL && pPage != NULL; 1074 FASTBOOL bInsert = pNewPage != NULL && pPage == NULL; 1075 1076 if( bRemove ) 1077 { 1078 // hier kein SwapIn noetig, weil wenn nicht geladen, dann auch nicht animiert. 1079 if( pGraphic->IsAnimated()) 1080 pGraphic->StopAnimation(); 1081 1082 if( pGraphicLink != NULL ) 1083 ImpLinkAbmeldung(); 1084 } 1085 1086 if(!pModel && !GetStyleSheet() && pNewPage->GetModel()) 1087 { 1088 // #119287# Set default StyleSheet for SdrGrafObj here, it is different from 'Default'. This 1089 // needs to be done before the style 'Default' is set from the :SetModel() call which is triggered 1090 // from the following :SetPage(). 1091 // TTTT: Needs to be moved in branch aw080 due to having a SdrModel from the beginning, is at this 1092 // place for convenience currently (works in both versions, is not in the way) 1093 SfxStyleSheet* pSheet = pNewPage->GetModel()->GetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj(); 1094 1095 if(pSheet) 1096 { 1097 SetStyleSheet(pSheet, false); 1098 } 1099 else 1100 { 1101 SetMergedItem(XFillStyleItem(XFILL_NONE)); 1102 SetMergedItem(XLineStyleItem(XLINE_NONE)); 1103 } 1104 } 1105 1106 SdrRectObj::SetPage( pNewPage ); 1107 1108 if(aFileName.Len() && bInsert) 1109 ImpLinkAnmeldung(); 1110 } 1111 1112 // ----------------------------------------------------------------------------- 1113 1114 void SdrGrafObj::SetModel( SdrModel* pNewModel ) 1115 { 1116 FASTBOOL bChg = pNewModel != pModel; 1117 1118 if( bChg ) 1119 { 1120 if( pGraphic->HasUserData() ) 1121 { 1122 ForceSwapIn(); 1123 pGraphic->SetUserData(); 1124 } 1125 1126 if( pGraphicLink != NULL ) 1127 ImpLinkAbmeldung(); 1128 } 1129 1130 // Model umsetzen 1131 SdrRectObj::SetModel(pNewModel); 1132 1133 if( bChg && aFileName.Len() ) 1134 ImpLinkAnmeldung(); 1135 } 1136 1137 // ----------------------------------------------------------------------------- 1138 1139 void SdrGrafObj::StartAnimation( OutputDevice* /*pOutDev*/, const Point& /*rPoint*/, const Size& /*rSize*/, long /*nExtraData*/) 1140 { 1141 // #111096# 1142 // use new graf animation 1143 SetGrafAnimationAllowed(sal_True); 1144 } 1145 1146 // ----------------------------------------------------------------------------- 1147 1148 void SdrGrafObj::StopAnimation(OutputDevice* /*pOutDev*/, long /*nExtraData*/) 1149 { 1150 // #111096# 1151 // use new graf animation 1152 SetGrafAnimationAllowed(sal_False); 1153 } 1154 1155 // ----------------------------------------------------------------------------- 1156 1157 FASTBOOL SdrGrafObj::HasGDIMetaFile() const 1158 { 1159 return( pGraphic->GetType() == GRAPHIC_GDIMETAFILE ); 1160 } 1161 1162 // ----------------------------------------------------------------------------- 1163 1164 const GDIMetaFile* SdrGrafObj::GetGDIMetaFile() const 1165 { 1166 DBG_ERROR( "Invalid return value! Don't use it! (KA)" ); 1167 return &GetGraphic().GetGDIMetaFile(); 1168 } 1169 1170 // ----------------------------------------------------------------------------- 1171 1172 bool SdrGrafObj::isEmbeddedSvg() const 1173 { 1174 return GRAPHIC_BITMAP == GetGraphicType() && GetGraphic().getSvgData().get(); 1175 } 1176 1177 GDIMetaFile SdrGrafObj::getMetafileFromEmbeddedSvg() const 1178 { 1179 GDIMetaFile aRetval; 1180 1181 if(isEmbeddedSvg() && GetModel()) 1182 { 1183 VirtualDevice aOut; 1184 const Rectangle aBoundRect(GetCurrentBoundRect()); 1185 const MapMode aMap(GetModel()->GetScaleUnit(), Point(), GetModel()->GetScaleFraction(), GetModel()->GetScaleFraction()); 1186 1187 aOut.EnableOutput(false); 1188 aOut.SetMapMode(aMap); 1189 aRetval.Record(&aOut); 1190 SingleObjectPainter(aOut); 1191 aRetval.Stop(); 1192 aRetval.WindStart(); 1193 aRetval.Move(-aBoundRect.Left(), -aBoundRect.Top()); 1194 aRetval.SetPrefMapMode(aMap); 1195 aRetval.SetPrefSize(aBoundRect.GetSize()); 1196 } 1197 1198 return aRetval; 1199 } 1200 1201 SdrObject* SdrGrafObj::DoConvertToPolyObj(sal_Bool bBezier, bool bAddText) const 1202 { 1203 SdrObject* pRetval = NULL; 1204 GraphicType aGraphicType(GetGraphicType()); 1205 GDIMetaFile aMtf; 1206 1207 if(isEmbeddedSvg()) 1208 { 1209 // Embedded Svg 1210 // There is currently no helper to create SdrObjects from primitives (even if I'm thinking 1211 // about writing one for some time). To get the roundtrip to SdrObjects it is necessary to 1212 // use the old converter path over the MetaFile mechanism. Create Metafile from Svg 1213 // primitives here pretty directly 1214 aMtf = getMetafileFromEmbeddedSvg(); 1215 aGraphicType = GRAPHIC_GDIMETAFILE; 1216 } 1217 else if(GRAPHIC_GDIMETAFILE == aGraphicType) 1218 { 1219 aMtf = GetTransformedGraphic(SDRGRAFOBJ_TRANSFORMATTR_COLOR|SDRGRAFOBJ_TRANSFORMATTR_MIRROR).GetGDIMetaFile(); 1220 } 1221 1222 switch(aGraphicType) 1223 { 1224 case GRAPHIC_GDIMETAFILE: 1225 { 1226 // NUR die aus dem MetaFile erzeugbaren Objekte in eine Gruppe packen und zurueckliefern 1227 ImpSdrGDIMetaFileImport aFilter(*GetModel(), GetLayer(), aRect); 1228 SdrObjGroup* pGrp = new SdrObjGroup(); 1229 sal_uInt32 nInsAnz = aFilter.DoImport(aMtf, *pGrp->GetSubList(), 0); 1230 1231 if(nInsAnz) 1232 { 1233 { 1234 // copy transformation 1235 GeoStat aGeoStat(GetGeoStat()); 1236 1237 if(aGeoStat.nShearWink) 1238 { 1239 aGeoStat.RecalcTan(); 1240 pGrp->NbcShear(aRect.TopLeft(), aGeoStat.nShearWink, aGeoStat.nTan, false); 1241 } 1242 1243 if(aGeoStat.nDrehWink) 1244 { 1245 aGeoStat.RecalcSinCos(); 1246 pGrp->NbcRotate(aRect.TopLeft(), aGeoStat.nDrehWink, aGeoStat.nSin, aGeoStat.nCos); 1247 } 1248 } 1249 1250 pRetval = pGrp; 1251 pGrp->NbcSetLayer(GetLayer()); 1252 pGrp->SetModel(GetModel()); 1253 1254 if(bAddText) 1255 { 1256 pRetval = ImpConvertAddText(pRetval, bBezier); 1257 } 1258 1259 // convert all children 1260 if( pRetval ) 1261 { 1262 SdrObject* pHalfDone = pRetval; 1263 pRetval = pHalfDone->DoConvertToPolyObj(bBezier, bAddText); 1264 SdrObject::Free( pHalfDone ); // resulting object is newly created 1265 1266 if( pRetval ) 1267 { 1268 // flatten subgroups. As we call 1269 // DoConvertToPolyObj() on the resulting group 1270 // objects, subgroups can exist (e.g. text is 1271 // a group object for every line). 1272 SdrObjList* pList = pRetval->GetSubList(); 1273 if( pList ) 1274 pList->FlattenGroups(); 1275 } 1276 } 1277 } 1278 else 1279 { 1280 delete pGrp; 1281 } 1282 1283 // #i118485# convert line and fill 1284 SdrObject* pLineFill = SdrRectObj::DoConvertToPolyObj(bBezier, false); 1285 1286 if(pLineFill) 1287 { 1288 if(pRetval) 1289 { 1290 pGrp = dynamic_cast< SdrObjGroup* >(pRetval); 1291 1292 if(!pGrp) 1293 { 1294 pGrp = new SdrObjGroup(); 1295 1296 pGrp->NbcSetLayer(GetLayer()); 1297 pGrp->SetModel(GetModel()); 1298 pGrp->GetSubList()->NbcInsertObject(pRetval); 1299 } 1300 1301 pGrp->GetSubList()->NbcInsertObject(pLineFill, 0); 1302 } 1303 else 1304 { 1305 pRetval = pLineFill; 1306 } 1307 } 1308 1309 break; 1310 } 1311 case GRAPHIC_BITMAP: 1312 { 1313 // Grundobjekt kreieren und Fuellung ergaenzen 1314 pRetval = SdrRectObj::DoConvertToPolyObj(bBezier, bAddText); 1315 1316 // Bitmap als Attribut retten 1317 if(pRetval) 1318 { 1319 // Bitmap als Fuellung holen 1320 SfxItemSet aSet(GetObjectItemSet()); 1321 1322 aSet.Put(XFillStyleItem(XFILL_BITMAP)); 1323 const BitmapEx aBitmapEx(GetTransformedGraphic().GetBitmapEx()); 1324 aSet.Put(XFillBitmapItem(String(), Graphic(aBitmapEx))); 1325 aSet.Put(XFillBmpTileItem(false)); 1326 1327 pRetval->SetMergedItemSet(aSet); 1328 } 1329 break; 1330 } 1331 case GRAPHIC_NONE: 1332 case GRAPHIC_DEFAULT: 1333 { 1334 pRetval = SdrRectObj::DoConvertToPolyObj(bBezier, bAddText); 1335 break; 1336 } 1337 } 1338 1339 return pRetval; 1340 } 1341 1342 // ----------------------------------------------------------------------------- 1343 1344 void SdrGrafObj::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) 1345 { 1346 SetXPolyDirty(); 1347 SdrRectObj::Notify( rBC, rHint ); 1348 ImpSetAttrToGrafInfo(); 1349 } 1350 1351 void SdrGrafObj::ImpSetAttrToGrafInfo() 1352 { 1353 const SfxItemSet& rSet = GetObjectItemSet(); 1354 const sal_uInt16 nTrans = ( (SdrGrafTransparenceItem&) rSet.Get( SDRATTR_GRAFTRANSPARENCE ) ).GetValue(); 1355 const SdrGrafCropItem& rCrop = (const SdrGrafCropItem&) rSet.Get( SDRATTR_GRAFCROP ); 1356 1357 aGrafInfo.SetLuminance( ( (SdrGrafLuminanceItem&) rSet.Get( SDRATTR_GRAFLUMINANCE ) ).GetValue() ); 1358 aGrafInfo.SetContrast( ( (SdrGrafContrastItem&) rSet.Get( SDRATTR_GRAFCONTRAST ) ).GetValue() ); 1359 aGrafInfo.SetChannelR( ( (SdrGrafRedItem&) rSet.Get( SDRATTR_GRAFRED ) ).GetValue() ); 1360 aGrafInfo.SetChannelG( ( (SdrGrafGreenItem&) rSet.Get( SDRATTR_GRAFGREEN ) ).GetValue() ); 1361 aGrafInfo.SetChannelB( ( (SdrGrafBlueItem&) rSet.Get( SDRATTR_GRAFBLUE ) ).GetValue() ); 1362 aGrafInfo.SetGamma( ( (SdrGrafGamma100Item&) rSet.Get( SDRATTR_GRAFGAMMA ) ).GetValue() * 0.01 ); 1363 aGrafInfo.SetTransparency( (sal_uInt8) FRound( Min( nTrans, (sal_uInt16) 100 ) * 2.55 ) ); 1364 aGrafInfo.SetInvert( ( (SdrGrafInvertItem&) rSet.Get( SDRATTR_GRAFINVERT ) ).GetValue() ); 1365 aGrafInfo.SetDrawMode( ( (SdrGrafModeItem&) rSet.Get( SDRATTR_GRAFMODE ) ).GetValue() ); 1366 aGrafInfo.SetCrop( rCrop.GetLeft(), rCrop.GetTop(), rCrop.GetRight(), rCrop.GetBottom() ); 1367 1368 SetXPolyDirty(); 1369 SetRectsDirty(); 1370 } 1371 1372 // ----------------------------------------------------------------------------- 1373 1374 void SdrGrafObj::ImpSetGrafInfoToAttr() 1375 { 1376 SetObjectItem( SdrGrafLuminanceItem( aGrafInfo.GetLuminance() ) ); 1377 SetObjectItem( SdrGrafContrastItem( aGrafInfo.GetContrast() ) ); 1378 SetObjectItem( SdrGrafRedItem( aGrafInfo.GetChannelR() ) ); 1379 SetObjectItem( SdrGrafGreenItem( aGrafInfo.GetChannelG() ) ); 1380 SetObjectItem( SdrGrafBlueItem( aGrafInfo.GetChannelB() ) ); 1381 SetObjectItem( SdrGrafGamma100Item( FRound( aGrafInfo.GetGamma() * 100.0 ) ) ); 1382 SetObjectItem( SdrGrafTransparenceItem( (sal_uInt16) FRound( aGrafInfo.GetTransparency() / 2.55 ) ) ); 1383 SetObjectItem( SdrGrafInvertItem( aGrafInfo.IsInvert() ) ); 1384 SetObjectItem( SdrGrafModeItem( aGrafInfo.GetDrawMode() ) ); 1385 SetObjectItem( SdrGrafCropItem( aGrafInfo.GetLeftCrop(), aGrafInfo.GetTopCrop(), aGrafInfo.GetRightCrop(), aGrafInfo.GetBottomCrop() ) ); 1386 } 1387 1388 // ----------------------------------------------------------------------------- 1389 1390 void SdrGrafObj::AdjustToMaxRect( const Rectangle& rMaxRect, bool bShrinkOnly ) 1391 { 1392 Size aSize; 1393 Size aMaxSize( rMaxRect.GetSize() ); 1394 if ( pGraphic->GetPrefMapMode().GetMapUnit() == MAP_PIXEL ) 1395 aSize = Application::GetDefaultDevice()->PixelToLogic( pGraphic->GetPrefSize(), MAP_100TH_MM ); 1396 else 1397 aSize = OutputDevice::LogicToLogic( pGraphic->GetPrefSize(), 1398 pGraphic->GetPrefMapMode(), 1399 MapMode( MAP_100TH_MM ) ); 1400 1401 if( aSize.Height() != 0 && aSize.Width() != 0 ) 1402 { 1403 Point aPos( rMaxRect.TopLeft() ); 1404 1405 // Falls Grafik zu gross, wird die Grafik 1406 // in die Seite eingepasst 1407 if ( (!bShrinkOnly || 1408 ( aSize.Height() > aMaxSize.Height() ) || 1409 ( aSize.Width() > aMaxSize.Width() ) )&& 1410 aSize.Height() && aMaxSize.Height() ) 1411 { 1412 float fGrfWH = (float)aSize.Width() / 1413 (float)aSize.Height(); 1414 float fWinWH = (float)aMaxSize.Width() / 1415 (float)aMaxSize.Height(); 1416 1417 // Grafik an Pagesize anpassen (skaliert) 1418 if ( fGrfWH < fWinWH ) 1419 { 1420 aSize.Width() = (long)(aMaxSize.Height() * fGrfWH); 1421 aSize.Height()= aMaxSize.Height(); 1422 } 1423 else if ( fGrfWH > 0.F ) 1424 { 1425 aSize.Width() = aMaxSize.Width(); 1426 aSize.Height()= (long)(aMaxSize.Width() / fGrfWH); 1427 } 1428 1429 aPos = rMaxRect.Center(); 1430 } 1431 1432 if( bShrinkOnly ) 1433 aPos = aRect.TopLeft(); 1434 1435 aPos.X() -= aSize.Width() / 2; 1436 aPos.Y() -= aSize.Height() / 2; 1437 SetLogicRect( Rectangle( aPos, aSize ) ); 1438 } 1439 } 1440 1441 // ----------------------------------------------------------------------------- 1442 1443 IMPL_LINK( SdrGrafObj, ImpSwapHdl, GraphicObject*, pO ) 1444 { 1445 SvStream* pRet = GRFMGR_AUTOSWAPSTREAM_NONE; 1446 1447 if( pO->IsInSwapOut() ) 1448 { 1449 if( pModel && !mbIsPreview && pModel->IsSwapGraphics() && pGraphic->GetSizeBytes() > 20480 ) 1450 { 1451 // test if this object is visualized from someone 1452 // ## test only if there are VOCs other than the preview renderer 1453 if(!GetViewContact().HasViewObjectContacts(true)) 1454 { 1455 const sal_uIntPtr nSwapMode = pModel->GetSwapGraphicsMode(); 1456 1457 if( ( pGraphic->HasUserData() || pGraphicLink ) && 1458 ( nSwapMode & SDR_SWAPGRAPHICSMODE_PURGE ) ) 1459 { 1460 pRet = GRFMGR_AUTOSWAPSTREAM_LINK; 1461 } 1462 else if( nSwapMode & SDR_SWAPGRAPHICSMODE_TEMP ) 1463 { 1464 pRet = GRFMGR_AUTOSWAPSTREAM_TEMP; 1465 pGraphic->SetUserData(); 1466 } 1467 1468 // #i102380# 1469 sdr::contact::ViewContactOfGraphic* pVC = dynamic_cast< sdr::contact::ViewContactOfGraphic* >(&GetViewContact()); 1470 1471 if(pVC) 1472 { 1473 pVC->flushGraphicObjects(); 1474 } 1475 } 1476 } 1477 } 1478 else if( pO->IsInSwapIn() ) 1479 { 1480 // kann aus dem original Doc-Stream nachgeladen werden... 1481 if( pModel != NULL ) 1482 { 1483 if( pGraphic->HasUserData() ) 1484 { 1485 SdrDocumentStreamInfo aStreamInfo; 1486 1487 aStreamInfo.mbDeleteAfterUse = sal_False; 1488 aStreamInfo.maUserData = pGraphic->GetUserData(); 1489 1490 SvStream* pStream = pModel->GetDocumentStream( aStreamInfo ); 1491 1492 if( pStream != NULL ) 1493 { 1494 Graphic aGraphic; 1495 1496 com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >* pFilterData = NULL; 1497 1498 if(mbInsidePaint && !GetViewContact().HasViewObjectContacts(true)) 1499 { 1500 pFilterData = new com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >( 3 ); 1501 1502 com::sun::star::awt::Size aPreviewSizeHint( 64, 64 ); 1503 sal_Bool bAllowPartialStreamRead = sal_True; 1504 sal_Bool bCreateNativeLink = sal_False; 1505 (*pFilterData)[ 0 ].Name = String( RTL_CONSTASCII_USTRINGPARAM( "PreviewSizeHint" ) ); 1506 (*pFilterData)[ 0 ].Value <<= aPreviewSizeHint; 1507 (*pFilterData)[ 1 ].Name = String( RTL_CONSTASCII_USTRINGPARAM( "AllowPartialStreamRead" ) ); 1508 (*pFilterData)[ 1 ].Value <<= bAllowPartialStreamRead; 1509 (*pFilterData)[ 2 ].Name = String( RTL_CONSTASCII_USTRINGPARAM( "CreateNativeLink" ) ); 1510 (*pFilterData)[ 2 ].Value <<= bCreateNativeLink; 1511 1512 mbIsPreview = sal_True; 1513 } 1514 1515 if(!GraphicFilter::GetGraphicFilter()->ImportGraphic( 1516 aGraphic, aStreamInfo.maUserData, *pStream, 1517 GRFILTER_FORMAT_DONTKNOW, NULL, 0, pFilterData)) 1518 { 1519 const String aUserData( pGraphic->GetUserData() ); 1520 1521 pGraphic->SetGraphic( aGraphic ); 1522 pGraphic->SetUserData( aUserData ); 1523 1524 // #142146# Graphic successfully swapped in. 1525 pRet = GRFMGR_AUTOSWAPSTREAM_LOADED; 1526 } 1527 delete pFilterData; 1528 1529 pStream->ResetError(); 1530 1531 if( aStreamInfo.mbDeleteAfterUse || aStreamInfo.mxStorageRef.is() ) 1532 { 1533 if ( aStreamInfo.mxStorageRef.is() ) 1534 { 1535 aStreamInfo.mxStorageRef->dispose(); 1536 aStreamInfo.mxStorageRef = 0; 1537 } 1538 1539 delete pStream; 1540 } 1541 } 1542 } 1543 else if( !ImpUpdateGraphicLink( sal_False ) ) 1544 { 1545 pRet = GRFMGR_AUTOSWAPSTREAM_TEMP; 1546 } 1547 else 1548 { 1549 pRet = GRFMGR_AUTOSWAPSTREAM_LOADED; 1550 } 1551 } 1552 else 1553 pRet = GRFMGR_AUTOSWAPSTREAM_TEMP; 1554 } 1555 1556 return (long)(void*) pRet; 1557 } 1558 1559 // ----------------------------------------------------------------------------- 1560 1561 // #111096# 1562 // Access to GrafAnimationAllowed flag 1563 sal_Bool SdrGrafObj::IsGrafAnimationAllowed() const 1564 { 1565 return mbGrafAnimationAllowed; 1566 } 1567 1568 void SdrGrafObj::SetGrafAnimationAllowed(sal_Bool bNew) 1569 { 1570 if(mbGrafAnimationAllowed != bNew) 1571 { 1572 mbGrafAnimationAllowed = bNew; 1573 ActionChanged(); 1574 } 1575 } 1576 1577 // #i25616# 1578 sal_Bool SdrGrafObj::IsObjectTransparent() const 1579 { 1580 if(((const SdrGrafTransparenceItem&)GetObjectItem(SDRATTR_GRAFTRANSPARENCE)).GetValue() 1581 || pGraphic->IsTransparent()) 1582 { 1583 return sal_True; 1584 } 1585 1586 return sal_False; 1587 } 1588 1589 Reference< XInputStream > SdrGrafObj::getInputStream() 1590 { 1591 Reference< XInputStream > xStream; 1592 1593 if( pModel ) 1594 { 1595 // if( !pGraphic->HasUserData() ) 1596 // pGraphic->SwapOut(); 1597 1598 // kann aus dem original Doc-Stream nachgeladen werden... 1599 if( pGraphic->HasUserData() ) 1600 { 1601 SdrDocumentStreamInfo aStreamInfo; 1602 1603 aStreamInfo.mbDeleteAfterUse = sal_False; 1604 aStreamInfo.maUserData = pGraphic->GetUserData(); 1605 1606 SvStream* pStream = pModel->GetDocumentStream( aStreamInfo ); 1607 1608 if( pStream ) 1609 xStream.set( new utl::OInputStreamWrapper( pStream, sal_True ) ); 1610 } 1611 else if( pGraphic && GetGraphic().IsLink() ) 1612 { 1613 Graphic aGraphic( GetGraphic() ); 1614 GfxLink aLink( aGraphic.GetLink() ); 1615 sal_uInt32 nSize = aLink.GetDataSize(); 1616 const void* pSourceData = (const void*)aLink.GetData(); 1617 if( nSize && pSourceData ) 1618 { 1619 sal_uInt8 * pBuffer = new sal_uInt8[ nSize ]; 1620 if( pBuffer ) 1621 { 1622 memcpy( pBuffer, pSourceData, nSize ); 1623 1624 SvMemoryStream* pStream = new SvMemoryStream( (void*)pBuffer, (sal_Size)nSize, STREAM_READ ); 1625 pStream->ObjectOwnsMemory( sal_True ); 1626 xStream.set( new utl::OInputStreamWrapper( pStream, sal_True ) ); 1627 } 1628 } 1629 } 1630 1631 if( !xStream.is() && aFileName.Len() ) 1632 { 1633 SvFileStream* pStream = new SvFileStream( aFileName, STREAM_READ ); 1634 if( pStream ) 1635 xStream.set( new utl::OInputStreamWrapper( pStream ) ); 1636 } 1637 } 1638 1639 return xStream; 1640 } 1641 1642 // eof 1643