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 SdrRectObj::SetPage( pNewPage ); 1087 1088 if(aFileName.Len() && bInsert) 1089 ImpLinkAnmeldung(); 1090 } 1091 1092 // ----------------------------------------------------------------------------- 1093 1094 void SdrGrafObj::SetModel( SdrModel* pNewModel ) 1095 { 1096 FASTBOOL bChg = pNewModel != pModel; 1097 1098 if( bChg ) 1099 { 1100 if( pGraphic->HasUserData() ) 1101 { 1102 ForceSwapIn(); 1103 pGraphic->SetUserData(); 1104 } 1105 1106 if( pGraphicLink != NULL ) 1107 ImpLinkAbmeldung(); 1108 } 1109 1110 // Model umsetzen 1111 SdrRectObj::SetModel(pNewModel); 1112 1113 if( bChg && aFileName.Len() ) 1114 ImpLinkAnmeldung(); 1115 } 1116 1117 // ----------------------------------------------------------------------------- 1118 1119 void SdrGrafObj::StartAnimation( OutputDevice* /*pOutDev*/, const Point& /*rPoint*/, const Size& /*rSize*/, long /*nExtraData*/) 1120 { 1121 // #111096# 1122 // use new graf animation 1123 SetGrafAnimationAllowed(sal_True); 1124 } 1125 1126 // ----------------------------------------------------------------------------- 1127 1128 void SdrGrafObj::StopAnimation(OutputDevice* /*pOutDev*/, long /*nExtraData*/) 1129 { 1130 // #111096# 1131 // use new graf animation 1132 SetGrafAnimationAllowed(sal_False); 1133 } 1134 1135 // ----------------------------------------------------------------------------- 1136 1137 FASTBOOL SdrGrafObj::HasGDIMetaFile() const 1138 { 1139 return( pGraphic->GetType() == GRAPHIC_GDIMETAFILE ); 1140 } 1141 1142 // ----------------------------------------------------------------------------- 1143 1144 const GDIMetaFile* SdrGrafObj::GetGDIMetaFile() const 1145 { 1146 DBG_ERROR( "Invalid return value! Don't use it! (KA)" ); 1147 return &GetGraphic().GetGDIMetaFile(); 1148 } 1149 1150 // ----------------------------------------------------------------------------- 1151 1152 bool SdrGrafObj::isEmbeddedSvg() const 1153 { 1154 return GRAPHIC_BITMAP == GetGraphicType() && GetGraphic().getSvgData().get(); 1155 } 1156 1157 GDIMetaFile SdrGrafObj::getMetafileFromEmbeddedSvg() const 1158 { 1159 GDIMetaFile aRetval; 1160 1161 if(isEmbeddedSvg() && GetModel()) 1162 { 1163 VirtualDevice aOut; 1164 const Rectangle aBoundRect(GetCurrentBoundRect()); 1165 const MapMode aMap(GetModel()->GetScaleUnit(), Point(), GetModel()->GetScaleFraction(), GetModel()->GetScaleFraction()); 1166 1167 aOut.EnableOutput(false); 1168 aOut.SetMapMode(aMap); 1169 aRetval.Record(&aOut); 1170 SingleObjectPainter(aOut); 1171 aRetval.Stop(); 1172 aRetval.WindStart(); 1173 aRetval.Move(-aBoundRect.Left(), -aBoundRect.Top()); 1174 aRetval.SetPrefMapMode(aMap); 1175 aRetval.SetPrefSize(aBoundRect.GetSize()); 1176 } 1177 1178 return aRetval; 1179 } 1180 1181 SdrObject* SdrGrafObj::DoConvertToPolyObj(sal_Bool bBezier, bool bAddText) const 1182 { 1183 SdrObject* pRetval = NULL; 1184 GraphicType aGraphicType(GetGraphicType()); 1185 GDIMetaFile aMtf; 1186 1187 if(isEmbeddedSvg()) 1188 { 1189 // Embedded Svg 1190 // There is currently no helper to create SdrObjects from primitives (even if I'm thinking 1191 // about writing one for some time). To get the roundtrip to SdrObjects it is necessary to 1192 // use the old converter path over the MetaFile mechanism. Create Metafile from Svg 1193 // primitives here pretty directly 1194 aMtf = getMetafileFromEmbeddedSvg(); 1195 aGraphicType = GRAPHIC_GDIMETAFILE; 1196 } 1197 else if(GRAPHIC_GDIMETAFILE == aGraphicType) 1198 { 1199 aMtf = GetTransformedGraphic(SDRGRAFOBJ_TRANSFORMATTR_COLOR|SDRGRAFOBJ_TRANSFORMATTR_MIRROR).GetGDIMetaFile(); 1200 } 1201 1202 switch(aGraphicType) 1203 { 1204 case GRAPHIC_GDIMETAFILE: 1205 { 1206 // NUR die aus dem MetaFile erzeugbaren Objekte in eine Gruppe packen und zurueckliefern 1207 ImpSdrGDIMetaFileImport aFilter(*GetModel(), GetLayer(), aRect); 1208 SdrObjGroup* pGrp = new SdrObjGroup(); 1209 sal_uInt32 nInsAnz = aFilter.DoImport(aMtf, *pGrp->GetSubList(), 0); 1210 1211 if(nInsAnz) 1212 { 1213 { 1214 // copy transformation 1215 GeoStat aGeoStat(GetGeoStat()); 1216 1217 if(aGeoStat.nShearWink) 1218 { 1219 aGeoStat.RecalcTan(); 1220 pGrp->NbcShear(aRect.TopLeft(), aGeoStat.nShearWink, aGeoStat.nTan, false); 1221 } 1222 1223 if(aGeoStat.nDrehWink) 1224 { 1225 aGeoStat.RecalcSinCos(); 1226 pGrp->NbcRotate(aRect.TopLeft(), aGeoStat.nDrehWink, aGeoStat.nSin, aGeoStat.nCos); 1227 } 1228 } 1229 1230 pRetval = pGrp; 1231 pGrp->NbcSetLayer(GetLayer()); 1232 pGrp->SetModel(GetModel()); 1233 1234 if(bAddText) 1235 { 1236 pRetval = ImpConvertAddText(pRetval, bBezier); 1237 } 1238 1239 // convert all children 1240 if( pRetval ) 1241 { 1242 SdrObject* pHalfDone = pRetval; 1243 pRetval = pHalfDone->DoConvertToPolyObj(bBezier, bAddText); 1244 SdrObject::Free( pHalfDone ); // resulting object is newly created 1245 1246 if( pRetval ) 1247 { 1248 // flatten subgroups. As we call 1249 // DoConvertToPolyObj() on the resulting group 1250 // objects, subgroups can exist (e.g. text is 1251 // a group object for every line). 1252 SdrObjList* pList = pRetval->GetSubList(); 1253 if( pList ) 1254 pList->FlattenGroups(); 1255 } 1256 } 1257 } 1258 else 1259 { 1260 delete pGrp; 1261 } 1262 1263 // #i118485# convert line and fill 1264 SdrObject* pLineFill = SdrRectObj::DoConvertToPolyObj(bBezier, false); 1265 1266 if(pLineFill) 1267 { 1268 if(pRetval) 1269 { 1270 pGrp = dynamic_cast< SdrObjGroup* >(pRetval); 1271 1272 if(!pGrp) 1273 { 1274 pGrp = new SdrObjGroup(); 1275 1276 pGrp->NbcSetLayer(GetLayer()); 1277 pGrp->SetModel(GetModel()); 1278 pGrp->GetSubList()->NbcInsertObject(pRetval); 1279 } 1280 1281 pGrp->GetSubList()->NbcInsertObject(pLineFill, 0); 1282 } 1283 else 1284 { 1285 pRetval = pLineFill; 1286 } 1287 } 1288 1289 break; 1290 } 1291 case GRAPHIC_BITMAP: 1292 { 1293 // Grundobjekt kreieren und Fuellung ergaenzen 1294 pRetval = SdrRectObj::DoConvertToPolyObj(bBezier, bAddText); 1295 1296 // Bitmap als Attribut retten 1297 if(pRetval) 1298 { 1299 // Bitmap als Fuellung holen 1300 SfxItemSet aSet(GetObjectItemSet()); 1301 1302 aSet.Put(XFillStyleItem(XFILL_BITMAP)); 1303 const BitmapEx aBitmapEx(GetTransformedGraphic().GetBitmapEx()); 1304 aSet.Put(XFillBitmapItem(String(), Graphic(aBitmapEx))); 1305 aSet.Put(XFillBmpTileItem(false)); 1306 1307 pRetval->SetMergedItemSet(aSet); 1308 } 1309 break; 1310 } 1311 case GRAPHIC_NONE: 1312 case GRAPHIC_DEFAULT: 1313 { 1314 pRetval = SdrRectObj::DoConvertToPolyObj(bBezier, bAddText); 1315 break; 1316 } 1317 } 1318 1319 return pRetval; 1320 } 1321 1322 // ----------------------------------------------------------------------------- 1323 1324 void SdrGrafObj::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) 1325 { 1326 SetXPolyDirty(); 1327 SdrRectObj::Notify( rBC, rHint ); 1328 ImpSetAttrToGrafInfo(); 1329 } 1330 1331 void SdrGrafObj::ImpSetAttrToGrafInfo() 1332 { 1333 const SfxItemSet& rSet = GetObjectItemSet(); 1334 const sal_uInt16 nTrans = ( (SdrGrafTransparenceItem&) rSet.Get( SDRATTR_GRAFTRANSPARENCE ) ).GetValue(); 1335 const SdrGrafCropItem& rCrop = (const SdrGrafCropItem&) rSet.Get( SDRATTR_GRAFCROP ); 1336 1337 aGrafInfo.SetLuminance( ( (SdrGrafLuminanceItem&) rSet.Get( SDRATTR_GRAFLUMINANCE ) ).GetValue() ); 1338 aGrafInfo.SetContrast( ( (SdrGrafContrastItem&) rSet.Get( SDRATTR_GRAFCONTRAST ) ).GetValue() ); 1339 aGrafInfo.SetChannelR( ( (SdrGrafRedItem&) rSet.Get( SDRATTR_GRAFRED ) ).GetValue() ); 1340 aGrafInfo.SetChannelG( ( (SdrGrafGreenItem&) rSet.Get( SDRATTR_GRAFGREEN ) ).GetValue() ); 1341 aGrafInfo.SetChannelB( ( (SdrGrafBlueItem&) rSet.Get( SDRATTR_GRAFBLUE ) ).GetValue() ); 1342 aGrafInfo.SetGamma( ( (SdrGrafGamma100Item&) rSet.Get( SDRATTR_GRAFGAMMA ) ).GetValue() * 0.01 ); 1343 aGrafInfo.SetTransparency( (sal_uInt8) FRound( Min( nTrans, (sal_uInt16) 100 ) * 2.55 ) ); 1344 aGrafInfo.SetInvert( ( (SdrGrafInvertItem&) rSet.Get( SDRATTR_GRAFINVERT ) ).GetValue() ); 1345 aGrafInfo.SetDrawMode( ( (SdrGrafModeItem&) rSet.Get( SDRATTR_GRAFMODE ) ).GetValue() ); 1346 aGrafInfo.SetCrop( rCrop.GetLeft(), rCrop.GetTop(), rCrop.GetRight(), rCrop.GetBottom() ); 1347 1348 SetXPolyDirty(); 1349 SetRectsDirty(); 1350 } 1351 1352 // ----------------------------------------------------------------------------- 1353 1354 void SdrGrafObj::ImpSetGrafInfoToAttr() 1355 { 1356 SetObjectItem( SdrGrafLuminanceItem( aGrafInfo.GetLuminance() ) ); 1357 SetObjectItem( SdrGrafContrastItem( aGrafInfo.GetContrast() ) ); 1358 SetObjectItem( SdrGrafRedItem( aGrafInfo.GetChannelR() ) ); 1359 SetObjectItem( SdrGrafGreenItem( aGrafInfo.GetChannelG() ) ); 1360 SetObjectItem( SdrGrafBlueItem( aGrafInfo.GetChannelB() ) ); 1361 SetObjectItem( SdrGrafGamma100Item( FRound( aGrafInfo.GetGamma() * 100.0 ) ) ); 1362 SetObjectItem( SdrGrafTransparenceItem( (sal_uInt16) FRound( aGrafInfo.GetTransparency() / 2.55 ) ) ); 1363 SetObjectItem( SdrGrafInvertItem( aGrafInfo.IsInvert() ) ); 1364 SetObjectItem( SdrGrafModeItem( aGrafInfo.GetDrawMode() ) ); 1365 SetObjectItem( SdrGrafCropItem( aGrafInfo.GetLeftCrop(), aGrafInfo.GetTopCrop(), aGrafInfo.GetRightCrop(), aGrafInfo.GetBottomCrop() ) ); 1366 } 1367 1368 // ----------------------------------------------------------------------------- 1369 1370 void SdrGrafObj::AdjustToMaxRect( const Rectangle& rMaxRect, bool bShrinkOnly ) 1371 { 1372 Size aSize; 1373 Size aMaxSize( rMaxRect.GetSize() ); 1374 if ( pGraphic->GetPrefMapMode().GetMapUnit() == MAP_PIXEL ) 1375 aSize = Application::GetDefaultDevice()->PixelToLogic( pGraphic->GetPrefSize(), MAP_100TH_MM ); 1376 else 1377 aSize = OutputDevice::LogicToLogic( pGraphic->GetPrefSize(), 1378 pGraphic->GetPrefMapMode(), 1379 MapMode( MAP_100TH_MM ) ); 1380 1381 if( aSize.Height() != 0 && aSize.Width() != 0 ) 1382 { 1383 Point aPos( rMaxRect.TopLeft() ); 1384 1385 // Falls Grafik zu gross, wird die Grafik 1386 // in die Seite eingepasst 1387 if ( (!bShrinkOnly || 1388 ( aSize.Height() > aMaxSize.Height() ) || 1389 ( aSize.Width() > aMaxSize.Width() ) )&& 1390 aSize.Height() && aMaxSize.Height() ) 1391 { 1392 float fGrfWH = (float)aSize.Width() / 1393 (float)aSize.Height(); 1394 float fWinWH = (float)aMaxSize.Width() / 1395 (float)aMaxSize.Height(); 1396 1397 // Grafik an Pagesize anpassen (skaliert) 1398 if ( fGrfWH < fWinWH ) 1399 { 1400 aSize.Width() = (long)(aMaxSize.Height() * fGrfWH); 1401 aSize.Height()= aMaxSize.Height(); 1402 } 1403 else if ( fGrfWH > 0.F ) 1404 { 1405 aSize.Width() = aMaxSize.Width(); 1406 aSize.Height()= (long)(aMaxSize.Width() / fGrfWH); 1407 } 1408 1409 aPos = rMaxRect.Center(); 1410 } 1411 1412 if( bShrinkOnly ) 1413 aPos = aRect.TopLeft(); 1414 1415 aPos.X() -= aSize.Width() / 2; 1416 aPos.Y() -= aSize.Height() / 2; 1417 SetLogicRect( Rectangle( aPos, aSize ) ); 1418 } 1419 } 1420 1421 // ----------------------------------------------------------------------------- 1422 1423 IMPL_LINK( SdrGrafObj, ImpSwapHdl, GraphicObject*, pO ) 1424 { 1425 SvStream* pRet = GRFMGR_AUTOSWAPSTREAM_NONE; 1426 1427 if( pO->IsInSwapOut() ) 1428 { 1429 if( pModel && !mbIsPreview && pModel->IsSwapGraphics() && pGraphic->GetSizeBytes() > 20480 ) 1430 { 1431 // test if this object is visualized from someone 1432 // ## test only if there are VOCs other than the preview renderer 1433 if(!GetViewContact().HasViewObjectContacts(true)) 1434 { 1435 const sal_uIntPtr nSwapMode = pModel->GetSwapGraphicsMode(); 1436 1437 if( ( pGraphic->HasUserData() || pGraphicLink ) && 1438 ( nSwapMode & SDR_SWAPGRAPHICSMODE_PURGE ) ) 1439 { 1440 pRet = GRFMGR_AUTOSWAPSTREAM_LINK; 1441 } 1442 else if( nSwapMode & SDR_SWAPGRAPHICSMODE_TEMP ) 1443 { 1444 pRet = GRFMGR_AUTOSWAPSTREAM_TEMP; 1445 pGraphic->SetUserData(); 1446 } 1447 1448 // #i102380# 1449 sdr::contact::ViewContactOfGraphic* pVC = dynamic_cast< sdr::contact::ViewContactOfGraphic* >(&GetViewContact()); 1450 1451 if(pVC) 1452 { 1453 pVC->flushGraphicObjects(); 1454 } 1455 } 1456 } 1457 } 1458 else if( pO->IsInSwapIn() ) 1459 { 1460 // kann aus dem original Doc-Stream nachgeladen werden... 1461 if( pModel != NULL ) 1462 { 1463 if( pGraphic->HasUserData() ) 1464 { 1465 SdrDocumentStreamInfo aStreamInfo; 1466 1467 aStreamInfo.mbDeleteAfterUse = sal_False; 1468 aStreamInfo.maUserData = pGraphic->GetUserData(); 1469 1470 SvStream* pStream = pModel->GetDocumentStream( aStreamInfo ); 1471 1472 if( pStream != NULL ) 1473 { 1474 Graphic aGraphic; 1475 1476 com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >* pFilterData = NULL; 1477 1478 if(mbInsidePaint && !GetViewContact().HasViewObjectContacts(true)) 1479 { 1480 pFilterData = new com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >( 3 ); 1481 1482 com::sun::star::awt::Size aPreviewSizeHint( 64, 64 ); 1483 sal_Bool bAllowPartialStreamRead = sal_True; 1484 sal_Bool bCreateNativeLink = sal_False; 1485 (*pFilterData)[ 0 ].Name = String( RTL_CONSTASCII_USTRINGPARAM( "PreviewSizeHint" ) ); 1486 (*pFilterData)[ 0 ].Value <<= aPreviewSizeHint; 1487 (*pFilterData)[ 1 ].Name = String( RTL_CONSTASCII_USTRINGPARAM( "AllowPartialStreamRead" ) ); 1488 (*pFilterData)[ 1 ].Value <<= bAllowPartialStreamRead; 1489 (*pFilterData)[ 2 ].Name = String( RTL_CONSTASCII_USTRINGPARAM( "CreateNativeLink" ) ); 1490 (*pFilterData)[ 2 ].Value <<= bCreateNativeLink; 1491 1492 mbIsPreview = sal_True; 1493 } 1494 1495 if(!GraphicFilter::GetGraphicFilter()->ImportGraphic( 1496 aGraphic, aStreamInfo.maUserData, *pStream, 1497 GRFILTER_FORMAT_DONTKNOW, NULL, 0, pFilterData)) 1498 { 1499 const String aUserData( pGraphic->GetUserData() ); 1500 1501 pGraphic->SetGraphic( aGraphic ); 1502 pGraphic->SetUserData( aUserData ); 1503 1504 // #142146# Graphic successfully swapped in. 1505 pRet = GRFMGR_AUTOSWAPSTREAM_LOADED; 1506 } 1507 delete pFilterData; 1508 1509 pStream->ResetError(); 1510 1511 if( aStreamInfo.mbDeleteAfterUse || aStreamInfo.mxStorageRef.is() ) 1512 { 1513 if ( aStreamInfo.mxStorageRef.is() ) 1514 { 1515 aStreamInfo.mxStorageRef->dispose(); 1516 aStreamInfo.mxStorageRef = 0; 1517 } 1518 1519 delete pStream; 1520 } 1521 } 1522 } 1523 else if( !ImpUpdateGraphicLink( sal_False ) ) 1524 { 1525 pRet = GRFMGR_AUTOSWAPSTREAM_TEMP; 1526 } 1527 else 1528 { 1529 pRet = GRFMGR_AUTOSWAPSTREAM_LOADED; 1530 } 1531 } 1532 else 1533 pRet = GRFMGR_AUTOSWAPSTREAM_TEMP; 1534 } 1535 1536 return (long)(void*) pRet; 1537 } 1538 1539 // ----------------------------------------------------------------------------- 1540 1541 // #111096# 1542 // Access to GrafAnimationAllowed flag 1543 sal_Bool SdrGrafObj::IsGrafAnimationAllowed() const 1544 { 1545 return mbGrafAnimationAllowed; 1546 } 1547 1548 void SdrGrafObj::SetGrafAnimationAllowed(sal_Bool bNew) 1549 { 1550 if(mbGrafAnimationAllowed != bNew) 1551 { 1552 mbGrafAnimationAllowed = bNew; 1553 ActionChanged(); 1554 } 1555 } 1556 1557 // #i25616# 1558 sal_Bool SdrGrafObj::IsObjectTransparent() const 1559 { 1560 if(((const SdrGrafTransparenceItem&)GetObjectItem(SDRATTR_GRAFTRANSPARENCE)).GetValue() 1561 || pGraphic->IsTransparent()) 1562 { 1563 return sal_True; 1564 } 1565 1566 return sal_False; 1567 } 1568 1569 Reference< XInputStream > SdrGrafObj::getInputStream() 1570 { 1571 Reference< XInputStream > xStream; 1572 1573 if( pModel ) 1574 { 1575 // if( !pGraphic->HasUserData() ) 1576 // pGraphic->SwapOut(); 1577 1578 // kann aus dem original Doc-Stream nachgeladen werden... 1579 if( pGraphic->HasUserData() ) 1580 { 1581 SdrDocumentStreamInfo aStreamInfo; 1582 1583 aStreamInfo.mbDeleteAfterUse = sal_False; 1584 aStreamInfo.maUserData = pGraphic->GetUserData(); 1585 1586 SvStream* pStream = pModel->GetDocumentStream( aStreamInfo ); 1587 1588 if( pStream ) 1589 xStream.set( new utl::OInputStreamWrapper( pStream, sal_True ) ); 1590 } 1591 else if( pGraphic && GetGraphic().IsLink() ) 1592 { 1593 Graphic aGraphic( GetGraphic() ); 1594 GfxLink aLink( aGraphic.GetLink() ); 1595 sal_uInt32 nSize = aLink.GetDataSize(); 1596 const void* pSourceData = (const void*)aLink.GetData(); 1597 if( nSize && pSourceData ) 1598 { 1599 sal_uInt8 * pBuffer = new sal_uInt8[ nSize ]; 1600 if( pBuffer ) 1601 { 1602 memcpy( pBuffer, pSourceData, nSize ); 1603 1604 SvMemoryStream* pStream = new SvMemoryStream( (void*)pBuffer, (sal_Size)nSize, STREAM_READ ); 1605 pStream->ObjectOwnsMemory( sal_True ); 1606 xStream.set( new utl::OInputStreamWrapper( pStream, sal_True ) ); 1607 } 1608 } 1609 } 1610 1611 if( !xStream.is() && aFileName.Len() ) 1612 { 1613 SvFileStream* pStream = new SvFileStream( aFileName, STREAM_READ ); 1614 if( pStream ) 1615 xStream.set( new utl::OInputStreamWrapper( pStream ) ); 1616 } 1617 } 1618 1619 return xStream; 1620 } 1621 1622 // eof 1623