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