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(), GetLayer(), aRect); 1149 SdrObjGroup* pGrp = new SdrObjGroup(); 1150 sal_uInt32 nInsAnz = aFilter.DoImport(aMtf, *pGrp->GetSubList(), 0); 1151 1152 if(nInsAnz) 1153 { 1154 { 1155 // copy transformation 1156 GeoStat aGeoStat(GetGeoStat()); 1157 1158 if(aGeoStat.nShearWink) 1159 { 1160 aGeoStat.RecalcTan(); 1161 pGrp->NbcShear(aRect.TopLeft(), aGeoStat.nShearWink, aGeoStat.nTan, false); 1162 } 1163 1164 if(aGeoStat.nDrehWink) 1165 { 1166 aGeoStat.RecalcSinCos(); 1167 pGrp->NbcRotate(aRect.TopLeft(), aGeoStat.nDrehWink, aGeoStat.nSin, aGeoStat.nCos); 1168 } 1169 } 1170 1171 pRetval = pGrp; 1172 pGrp->NbcSetLayer(GetLayer()); 1173 pGrp->SetModel(GetModel()); 1174 1175 if(bAddText) 1176 { 1177 pRetval = ImpConvertAddText(pRetval, bBezier); 1178 } 1179 1180 // convert all children 1181 if( pRetval ) 1182 { 1183 SdrObject* pHalfDone = pRetval; 1184 pRetval = pHalfDone->DoConvertToPolyObj(bBezier, bAddText); 1185 SdrObject::Free( pHalfDone ); // resulting object is newly created 1186 1187 if( pRetval ) 1188 { 1189 // flatten subgroups. As we call 1190 // DoConvertToPolyObj() on the resulting group 1191 // objects, subgroups can exist (e.g. text is 1192 // a group object for every line). 1193 SdrObjList* pList = pRetval->GetSubList(); 1194 if( pList ) 1195 pList->FlattenGroups(); 1196 } 1197 } 1198 } 1199 else 1200 { 1201 delete pGrp; 1202 } 1203 1204 // #i118485# convert line and fill 1205 SdrObject* pLineFill = SdrRectObj::DoConvertToPolyObj(bBezier, false); 1206 1207 if(pLineFill) 1208 { 1209 if(pRetval) 1210 { 1211 pGrp = dynamic_cast< SdrObjGroup* >(pRetval); 1212 1213 if(!pGrp) 1214 { 1215 pGrp = new SdrObjGroup(); 1216 1217 pGrp->NbcSetLayer(GetLayer()); 1218 pGrp->SetModel(GetModel()); 1219 pGrp->GetSubList()->NbcInsertObject(pRetval); 1220 } 1221 1222 pGrp->GetSubList()->NbcInsertObject(pLineFill, 0); 1223 } 1224 else 1225 { 1226 pRetval = pLineFill; 1227 } 1228 } 1229 1230 break; 1231 } 1232 case GRAPHIC_BITMAP: 1233 { 1234 // Grundobjekt kreieren und Fuellung ergaenzen 1235 pRetval = SdrRectObj::DoConvertToPolyObj(bBezier, bAddText); 1236 1237 // Bitmap als Attribut retten 1238 if(pRetval) 1239 { 1240 // Bitmap als Fuellung holen 1241 SfxItemSet aSet(GetObjectItemSet()); 1242 1243 aSet.Put(XFillStyleItem(XFILL_BITMAP)); 1244 const BitmapEx aBitmapEx(GetTransformedGraphic().GetBitmapEx()); 1245 aSet.Put(XFillBitmapItem(String(), Graphic(aBitmapEx))); 1246 aSet.Put(XFillBmpTileItem(false)); 1247 1248 pRetval->SetMergedItemSet(aSet); 1249 } 1250 break; 1251 } 1252 case GRAPHIC_NONE: 1253 case GRAPHIC_DEFAULT: 1254 { 1255 pRetval = SdrRectObj::DoConvertToPolyObj(bBezier, bAddText); 1256 break; 1257 } 1258 } 1259 1260 return pRetval; 1261 } 1262 1263 // ----------------------------------------------------------------------------- 1264 1265 void SdrGrafObj::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) 1266 { 1267 SetXPolyDirty(); 1268 SdrRectObj::Notify( rBC, rHint ); 1269 ImpSetAttrToGrafInfo(); 1270 } 1271 1272 void SdrGrafObj::ImpSetAttrToGrafInfo() 1273 { 1274 const SfxItemSet& rSet = GetObjectItemSet(); 1275 const sal_uInt16 nTrans = ( (SdrGrafTransparenceItem&) rSet.Get( SDRATTR_GRAFTRANSPARENCE ) ).GetValue(); 1276 const SdrGrafCropItem& rCrop = (const SdrGrafCropItem&) rSet.Get( SDRATTR_GRAFCROP ); 1277 1278 aGrafInfo.SetLuminance( ( (SdrGrafLuminanceItem&) rSet.Get( SDRATTR_GRAFLUMINANCE ) ).GetValue() ); 1279 aGrafInfo.SetContrast( ( (SdrGrafContrastItem&) rSet.Get( SDRATTR_GRAFCONTRAST ) ).GetValue() ); 1280 aGrafInfo.SetChannelR( ( (SdrGrafRedItem&) rSet.Get( SDRATTR_GRAFRED ) ).GetValue() ); 1281 aGrafInfo.SetChannelG( ( (SdrGrafGreenItem&) rSet.Get( SDRATTR_GRAFGREEN ) ).GetValue() ); 1282 aGrafInfo.SetChannelB( ( (SdrGrafBlueItem&) rSet.Get( SDRATTR_GRAFBLUE ) ).GetValue() ); 1283 aGrafInfo.SetGamma( ( (SdrGrafGamma100Item&) rSet.Get( SDRATTR_GRAFGAMMA ) ).GetValue() * 0.01 ); 1284 aGrafInfo.SetTransparency( (sal_uInt8) FRound( Min( nTrans, (sal_uInt16) 100 ) * 2.55 ) ); 1285 aGrafInfo.SetInvert( ( (SdrGrafInvertItem&) rSet.Get( SDRATTR_GRAFINVERT ) ).GetValue() ); 1286 aGrafInfo.SetDrawMode( ( (SdrGrafModeItem&) rSet.Get( SDRATTR_GRAFMODE ) ).GetValue() ); 1287 aGrafInfo.SetCrop( rCrop.GetLeft(), rCrop.GetTop(), rCrop.GetRight(), rCrop.GetBottom() ); 1288 1289 SetXPolyDirty(); 1290 SetRectsDirty(); 1291 } 1292 1293 // ----------------------------------------------------------------------------- 1294 1295 void SdrGrafObj::ImpSetGrafInfoToAttr() 1296 { 1297 SetObjectItem( SdrGrafLuminanceItem( aGrafInfo.GetLuminance() ) ); 1298 SetObjectItem( SdrGrafContrastItem( aGrafInfo.GetContrast() ) ); 1299 SetObjectItem( SdrGrafRedItem( aGrafInfo.GetChannelR() ) ); 1300 SetObjectItem( SdrGrafGreenItem( aGrafInfo.GetChannelG() ) ); 1301 SetObjectItem( SdrGrafBlueItem( aGrafInfo.GetChannelB() ) ); 1302 SetObjectItem( SdrGrafGamma100Item( FRound( aGrafInfo.GetGamma() * 100.0 ) ) ); 1303 SetObjectItem( SdrGrafTransparenceItem( (sal_uInt16) FRound( aGrafInfo.GetTransparency() / 2.55 ) ) ); 1304 SetObjectItem( SdrGrafInvertItem( aGrafInfo.IsInvert() ) ); 1305 SetObjectItem( SdrGrafModeItem( aGrafInfo.GetDrawMode() ) ); 1306 SetObjectItem( SdrGrafCropItem( aGrafInfo.GetLeftCrop(), aGrafInfo.GetTopCrop(), aGrafInfo.GetRightCrop(), aGrafInfo.GetBottomCrop() ) ); 1307 } 1308 1309 // ----------------------------------------------------------------------------- 1310 1311 void SdrGrafObj::AdjustToMaxRect( const Rectangle& rMaxRect, bool bShrinkOnly ) 1312 { 1313 Size aSize; 1314 Size aMaxSize( rMaxRect.GetSize() ); 1315 if ( pGraphic->GetPrefMapMode().GetMapUnit() == MAP_PIXEL ) 1316 aSize = Application::GetDefaultDevice()->PixelToLogic( pGraphic->GetPrefSize(), MAP_100TH_MM ); 1317 else 1318 aSize = OutputDevice::LogicToLogic( pGraphic->GetPrefSize(), 1319 pGraphic->GetPrefMapMode(), 1320 MapMode( MAP_100TH_MM ) ); 1321 1322 if( aSize.Height() != 0 && aSize.Width() != 0 ) 1323 { 1324 Point aPos( rMaxRect.TopLeft() ); 1325 1326 // Falls Grafik zu gross, wird die Grafik 1327 // in die Seite eingepasst 1328 if ( (!bShrinkOnly || 1329 ( aSize.Height() > aMaxSize.Height() ) || 1330 ( aSize.Width() > aMaxSize.Width() ) )&& 1331 aSize.Height() && aMaxSize.Height() ) 1332 { 1333 float fGrfWH = (float)aSize.Width() / 1334 (float)aSize.Height(); 1335 float fWinWH = (float)aMaxSize.Width() / 1336 (float)aMaxSize.Height(); 1337 1338 // Grafik an Pagesize anpassen (skaliert) 1339 if ( fGrfWH < fWinWH ) 1340 { 1341 aSize.Width() = (long)(aMaxSize.Height() * fGrfWH); 1342 aSize.Height()= aMaxSize.Height(); 1343 } 1344 else if ( fGrfWH > 0.F ) 1345 { 1346 aSize.Width() = aMaxSize.Width(); 1347 aSize.Height()= (long)(aMaxSize.Width() / fGrfWH); 1348 } 1349 1350 aPos = rMaxRect.Center(); 1351 } 1352 1353 if( bShrinkOnly ) 1354 aPos = aRect.TopLeft(); 1355 1356 aPos.X() -= aSize.Width() / 2; 1357 aPos.Y() -= aSize.Height() / 2; 1358 SetLogicRect( Rectangle( aPos, aSize ) ); 1359 } 1360 } 1361 1362 // ----------------------------------------------------------------------------- 1363 1364 IMPL_LINK( SdrGrafObj, ImpSwapHdl, GraphicObject*, pO ) 1365 { 1366 SvStream* pRet = GRFMGR_AUTOSWAPSTREAM_NONE; 1367 1368 if( pO->IsInSwapOut() ) 1369 { 1370 if( pModel && !mbIsPreview && pModel->IsSwapGraphics() && pGraphic->GetSizeBytes() > 20480 ) 1371 { 1372 // test if this object is visualized from someone 1373 // ## test only if there are VOCs other than the preview renderer 1374 if(!GetViewContact().HasViewObjectContacts(true)) 1375 { 1376 const sal_uIntPtr nSwapMode = pModel->GetSwapGraphicsMode(); 1377 1378 if( ( pGraphic->HasUserData() || pGraphicLink ) && 1379 ( nSwapMode & SDR_SWAPGRAPHICSMODE_PURGE ) ) 1380 { 1381 pRet = GRFMGR_AUTOSWAPSTREAM_LINK; 1382 } 1383 else if( nSwapMode & SDR_SWAPGRAPHICSMODE_TEMP ) 1384 { 1385 pRet = GRFMGR_AUTOSWAPSTREAM_TEMP; 1386 pGraphic->SetUserData(); 1387 } 1388 1389 // #i102380# 1390 sdr::contact::ViewContactOfGraphic* pVC = dynamic_cast< sdr::contact::ViewContactOfGraphic* >(&GetViewContact()); 1391 1392 if(pVC) 1393 { 1394 pVC->flushGraphicObjects(); 1395 } 1396 } 1397 } 1398 } 1399 else if( pO->IsInSwapIn() ) 1400 { 1401 // kann aus dem original Doc-Stream nachgeladen werden... 1402 if( pModel != NULL ) 1403 { 1404 if( pGraphic->HasUserData() ) 1405 { 1406 SdrDocumentStreamInfo aStreamInfo; 1407 1408 aStreamInfo.mbDeleteAfterUse = sal_False; 1409 aStreamInfo.maUserData = pGraphic->GetUserData(); 1410 1411 SvStream* pStream = pModel->GetDocumentStream( aStreamInfo ); 1412 1413 if( pStream != NULL ) 1414 { 1415 Graphic aGraphic; 1416 1417 com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >* pFilterData = NULL; 1418 1419 if(mbInsidePaint && !GetViewContact().HasViewObjectContacts(true)) 1420 { 1421 pFilterData = new com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >( 3 ); 1422 1423 com::sun::star::awt::Size aPreviewSizeHint( 64, 64 ); 1424 sal_Bool bAllowPartialStreamRead = sal_True; 1425 sal_Bool bCreateNativeLink = sal_False; 1426 (*pFilterData)[ 0 ].Name = String( RTL_CONSTASCII_USTRINGPARAM( "PreviewSizeHint" ) ); 1427 (*pFilterData)[ 0 ].Value <<= aPreviewSizeHint; 1428 (*pFilterData)[ 1 ].Name = String( RTL_CONSTASCII_USTRINGPARAM( "AllowPartialStreamRead" ) ); 1429 (*pFilterData)[ 1 ].Value <<= bAllowPartialStreamRead; 1430 (*pFilterData)[ 2 ].Name = String( RTL_CONSTASCII_USTRINGPARAM( "CreateNativeLink" ) ); 1431 (*pFilterData)[ 2 ].Value <<= bCreateNativeLink; 1432 1433 mbIsPreview = sal_True; 1434 } 1435 1436 if(!GraphicFilter::GetGraphicFilter()->ImportGraphic( 1437 aGraphic, aStreamInfo.maUserData, *pStream, 1438 GRFILTER_FORMAT_DONTKNOW, NULL, 0, pFilterData)) 1439 { 1440 const String aUserData( pGraphic->GetUserData() ); 1441 1442 pGraphic->SetGraphic( aGraphic ); 1443 pGraphic->SetUserData( aUserData ); 1444 1445 // #142146# Graphic successfully swapped in. 1446 pRet = GRFMGR_AUTOSWAPSTREAM_LOADED; 1447 } 1448 delete pFilterData; 1449 1450 pStream->ResetError(); 1451 1452 if( aStreamInfo.mbDeleteAfterUse || aStreamInfo.mxStorageRef.is() ) 1453 { 1454 if ( aStreamInfo.mxStorageRef.is() ) 1455 { 1456 aStreamInfo.mxStorageRef->dispose(); 1457 aStreamInfo.mxStorageRef = 0; 1458 } 1459 1460 delete pStream; 1461 } 1462 } 1463 } 1464 else if( !ImpUpdateGraphicLink( sal_False ) ) 1465 { 1466 pRet = GRFMGR_AUTOSWAPSTREAM_TEMP; 1467 } 1468 else 1469 { 1470 pRet = GRFMGR_AUTOSWAPSTREAM_LOADED; 1471 } 1472 } 1473 else 1474 pRet = GRFMGR_AUTOSWAPSTREAM_TEMP; 1475 } 1476 1477 return (long)(void*) pRet; 1478 } 1479 1480 // ----------------------------------------------------------------------------- 1481 1482 // #111096# 1483 // Access to GrafAnimationAllowed flag 1484 sal_Bool SdrGrafObj::IsGrafAnimationAllowed() const 1485 { 1486 return mbGrafAnimationAllowed; 1487 } 1488 1489 void SdrGrafObj::SetGrafAnimationAllowed(sal_Bool bNew) 1490 { 1491 if(mbGrafAnimationAllowed != bNew) 1492 { 1493 mbGrafAnimationAllowed = bNew; 1494 ActionChanged(); 1495 } 1496 } 1497 1498 // #i25616# 1499 sal_Bool SdrGrafObj::IsObjectTransparent() const 1500 { 1501 if(((const SdrGrafTransparenceItem&)GetObjectItem(SDRATTR_GRAFTRANSPARENCE)).GetValue() 1502 || pGraphic->IsTransparent()) 1503 { 1504 return sal_True; 1505 } 1506 1507 return sal_False; 1508 } 1509 1510 Reference< XInputStream > SdrGrafObj::getInputStream() 1511 { 1512 Reference< XInputStream > xStream; 1513 1514 if( pModel ) 1515 { 1516 // if( !pGraphic->HasUserData() ) 1517 // pGraphic->SwapOut(); 1518 1519 // kann aus dem original Doc-Stream nachgeladen werden... 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 ) 1530 xStream.set( new utl::OInputStreamWrapper( pStream, sal_True ) ); 1531 } 1532 else if( pGraphic && GetGraphic().IsLink() ) 1533 { 1534 Graphic aGraphic( GetGraphic() ); 1535 GfxLink aLink( aGraphic.GetLink() ); 1536 sal_uInt32 nSize = aLink.GetDataSize(); 1537 const void* pSourceData = (const void*)aLink.GetData(); 1538 if( nSize && pSourceData ) 1539 { 1540 sal_uInt8 * pBuffer = new sal_uInt8[ nSize ]; 1541 if( pBuffer ) 1542 { 1543 memcpy( pBuffer, pSourceData, nSize ); 1544 1545 SvMemoryStream* pStream = new SvMemoryStream( (void*)pBuffer, (sal_Size)nSize, STREAM_READ ); 1546 pStream->ObjectOwnsMemory( sal_True ); 1547 xStream.set( new utl::OInputStreamWrapper( pStream, sal_True ) ); 1548 } 1549 } 1550 } 1551 1552 if( !xStream.is() && aFileName.Len() ) 1553 { 1554 SvFileStream* pStream = new SvFileStream( aFileName, STREAM_READ ); 1555 if( pStream ) 1556 xStream.set( new utl::OInputStreamWrapper( pStream ) ); 1557 } 1558 } 1559 1560 return xStream; 1561 } 1562 1563 // eof 1564