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