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