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