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