1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svdograf.cxx,v $
10 * $Revision: 1.84.18.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
35 #include <unotools/streamwrap.hxx>
37 #include <sfx2/lnkbase.hxx>
39 #include <vcl/salbtype.hxx>
40 #include <sot/formats.hxx>
41 #include <sot/storage.hxx>
42 #include <unotools/ucbstreamhelper.hxx>
43 #include <unotools/localfilehelper.hxx>
44 #include <svtools/style.hxx>
45 #include <svtools/filter.hxx>
46 #include <svtools/urihelper.hxx>
47 #include <goodies/grfmgr.hxx>
48 #include <vcl/svapp.hxx>
50 #include "linkmgr.hxx"
51 #include <svx/svdetc.hxx>
52 #include "svdglob.hxx"
54 #include <svx/svdpool.hxx>
55 #include <svx/svdmodel.hxx>
56 #include <svx/svdpage.hxx>
57 #include <svx/svdmrkv.hxx>
58 #include <svx/svdpagv.hxx>
59 #include "svdviter.hxx"
60 #include <svx/svdview.hxx>
62 #include <svx/svdograf.hxx>
63 #include <svx/svdogrp.hxx>
64 #include <svx/xbitmap.hxx>
65 #include <svx/xbtmpit.hxx>
66 #include <svx/xflbmtit.hxx>
67 #include <svx/svdundo.hxx>
68 #include "svdfmtf.hxx"
69 #include <svx/sdgcpitm.hxx>
70 #include <svx/eeitem.hxx>
71 #include <svx/sdr/properties/graphicproperties.hxx>
72 #include <svx/sdr/contact/viewcontactofgraphic.hxx>
73 #include <basegfx/polygon/b2dpolygon.hxx>
74 #include <basegfx/polygon/b2dpolygontools.hxx>
76 using namespace ::com::sun::star::uno
;
77 using namespace ::com::sun::star::io
;
83 #define GRAFSTREAMPOS_INVALID 0xffffffff
84 #define SWAPGRAPHIC_TIMEOUT 5000
90 class SdrGraphicLink
: public sfx2::SvBaseLink
95 SdrGraphicLink(SdrGrafObj
* pObj
);
96 virtual ~SdrGraphicLink();
98 virtual void Closed();
99 virtual void DataChanged( const String
& rMimeType
,
100 const ::com::sun::star::uno::Any
& rValue
);
102 BOOL
Connect() { return 0 != GetRealObject(); }
103 void UpdateSynchron();
106 // -----------------------------------------------------------------------------
108 SdrGraphicLink::SdrGraphicLink(SdrGrafObj
* pObj
):
109 ::sfx2::SvBaseLink( ::sfx2::LINKUPDATE_ONCALL
, SOT_FORMATSTR_ID_SVXB
),
112 SetSynchron( FALSE
);
115 // -----------------------------------------------------------------------------
117 SdrGraphicLink::~SdrGraphicLink()
121 // -----------------------------------------------------------------------------
123 void SdrGraphicLink::DataChanged( const String
& rMimeType
,
124 const ::com::sun::star::uno::Any
& rValue
)
126 SdrModel
* pModel
= pGrafObj
? pGrafObj
->GetModel() : 0;
127 SvxLinkManager
* pLinkManager
= pModel
? pModel
->GetLinkManager() : 0;
129 if( pLinkManager
&& rValue
.hasValue() )
131 pLinkManager
->GetDisplayNames( this, 0, &pGrafObj
->aFileName
, 0, &pGrafObj
->aFilterName
);
134 if( SvxLinkManager::GetGraphicFromAny( rMimeType
, rValue
, aGraphic
))
136 GraphicType eOldGraphicType
= pGrafObj
->GetGraphicType(); // kein Hereinswappen
137 const sal_Bool bIsChanged
= pModel
->IsChanged();
139 pGrafObj
->SetGraphic( aGraphic
);
140 if( GRAPHIC_NONE
!= eOldGraphicType
)
141 pGrafObj
->SetChanged();
143 pModel
->SetChanged( bIsChanged
);
145 else if( SotExchange::GetFormatIdFromMimeType( rMimeType
) !=
146 SvxLinkManager::RegisterStatusInfoId() )
148 // only repaint, no objectchange
149 pGrafObj
->ActionChanged();
150 // pGrafObj->BroadcastObjectChange();
155 // -----------------------------------------------------------------------------
157 void SdrGraphicLink::Closed()
159 // Die Verbindung wird aufgehoben; pLink des Objekts auf NULL setzen, da die Link-Instanz ja gerade destruiert wird.
160 pGrafObj
->ForceSwapIn();
161 pGrafObj
->pGraphicLink
=NULL
;
162 pGrafObj
->ReleaseGraphicLink();
163 SvBaseLink::Closed();
166 // -----------------------------------------------------------------------------
168 void SdrGraphicLink::UpdateSynchron()
172 String
aMimeType( SotExchange::GetFormatMimeType( GetContentType() ));
173 ::com::sun::star::uno::Any aValue
;
174 GetObj()->GetData( aValue
, aMimeType
, TRUE
);
175 DataChanged( aMimeType
, aValue
);
183 //////////////////////////////////////////////////////////////////////////////
184 // BaseProperties section
186 sdr::properties::BaseProperties
* SdrGrafObj::CreateObjectSpecificProperties()
188 return new sdr::properties::GraphicProperties(*this);
191 //////////////////////////////////////////////////////////////////////////////
192 // DrawContact section
194 sdr::contact::ViewContact
* SdrGrafObj::CreateObjectSpecificViewContact()
196 return new sdr::contact::ViewContactOfGraphic(*this);
199 //////////////////////////////////////////////////////////////////////////////
201 TYPEINIT1(SdrGrafObj
,SdrRectObj
);
203 // -----------------------------------------------------------------------------
205 SdrGrafObj::SdrGrafObj()
207 pGraphicLink ( NULL
),
210 pGraphic
= new GraphicObject
;
211 pGraphic
->SetSwapStreamHdl( LINK( this, SdrGrafObj
, ImpSwapHdl
), SWAPGRAPHIC_TIMEOUT
);
215 mbGrafAnimationAllowed
= sal_True
;
218 mbLineIsOutsideGeometry
= sal_True
;
219 mbInsidePaint
= sal_False
;
220 mbIsPreview
= sal_False
;
223 mbSupportTextIndentingOnLineWidthChange
= sal_False
;
226 // -----------------------------------------------------------------------------
228 SdrGrafObj::SdrGrafObj(const Graphic
& rGrf
, const Rectangle
& rRect
)
229 : SdrRectObj ( rRect
),
230 pGraphicLink ( NULL
),
233 pGraphic
= new GraphicObject( rGrf
);
234 pGraphic
->SetSwapStreamHdl( LINK( this, SdrGrafObj
, ImpSwapHdl
), SWAPGRAPHIC_TIMEOUT
);
238 mbGrafAnimationAllowed
= sal_True
;
241 mbLineIsOutsideGeometry
= sal_True
;
242 mbInsidePaint
= sal_False
;
243 mbIsPreview
= sal_False
;
246 mbSupportTextIndentingOnLineWidthChange
= sal_False
;
249 // -----------------------------------------------------------------------------
251 SdrGrafObj::SdrGrafObj( const Graphic
& rGrf
)
253 pGraphicLink ( NULL
),
256 pGraphic
= new GraphicObject( rGrf
);
257 pGraphic
->SetSwapStreamHdl( LINK( this, SdrGrafObj
, ImpSwapHdl
), SWAPGRAPHIC_TIMEOUT
);
261 mbGrafAnimationAllowed
= sal_True
;
264 mbLineIsOutsideGeometry
= sal_True
;
265 mbInsidePaint
= sal_False
;
266 mbIsPreview
= sal_False
;
269 mbSupportTextIndentingOnLineWidthChange
= sal_False
;
272 // -----------------------------------------------------------------------------
274 SdrGrafObj::~SdrGrafObj()
280 // -----------------------------------------------------------------------------
282 void SdrGrafObj::SetGraphicObject( const GraphicObject
& rGrfObj
)
285 pGraphic
->SetSwapStreamHdl( LINK( this, SdrGrafObj
, ImpSwapHdl
), SWAPGRAPHIC_TIMEOUT
);
286 pGraphic
->SetUserData();
287 mbIsPreview
= sal_False
;
289 BroadcastObjectChange();
292 // -----------------------------------------------------------------------------
294 const GraphicObject
& SdrGrafObj::GetGraphicObject(bool bForceSwapIn
) const
304 // -----------------------------------------------------------------------------
306 void SdrGrafObj::SetGraphic( const Graphic
& rGrf
)
308 pGraphic
->SetGraphic( rGrf
);
309 pGraphic
->SetUserData();
310 mbIsPreview
= sal_False
;
312 BroadcastObjectChange();
315 // -----------------------------------------------------------------------------
317 const Graphic
& SdrGrafObj::GetGraphic() const
320 return pGraphic
->GetGraphic();
323 // -----------------------------------------------------------------------------
325 Graphic
SdrGrafObj::GetTransformedGraphic( ULONG nTransformFlags
) const
327 // #107947# Refactored most of the code to GraphicObject, where
328 // everybody can use e.g. the cropping functionality
330 GraphicType eType
= GetGraphicType();
331 MapMode
aDestMap( pModel
->GetScaleUnit(), Point(), pModel
->GetScaleFraction(), pModel
->GetScaleFraction() );
332 const Size
aDestSize( GetLogicRect().GetSize() );
333 const BOOL bMirror
= ( nTransformFlags
& SDRGRAFOBJ_TRANSFORMATTR_MIRROR
) != 0;
334 const BOOL bRotate
= ( ( nTransformFlags
& SDRGRAFOBJ_TRANSFORMATTR_ROTATE
) != 0 ) &&
335 ( aGeo
.nDrehWink
&& aGeo
.nDrehWink
!= 18000 ) && ( GRAPHIC_NONE
!= eType
);
337 // #104115# Need cropping info earlier
338 ( (SdrGrafObj
*) this )->ImpSetAttrToGrafInfo();
339 GraphicAttr aActAttr
;
341 if( SDRGRAFOBJ_TRANSFORMATTR_NONE
!= nTransformFlags
&&
342 GRAPHIC_NONE
!= eType
)
344 // actually transform the graphic only in this case. On the
345 // other hand, cropping will always happen
346 aActAttr
= aGrafInfo
;
350 USHORT nMirrorCase
= ( aGeo
.nDrehWink
== 18000 ) ? ( bMirrored
? 3 : 4 ) : ( bMirrored
? 2 : 1 );
351 FASTBOOL bHMirr
= nMirrorCase
== 2 || nMirrorCase
== 4;
352 FASTBOOL bVMirr
= nMirrorCase
== 3 || nMirrorCase
== 4;
354 aActAttr
.SetMirrorFlags( ( bHMirr
? BMP_MIRROR_HORZ
: 0 ) | ( bVMirr
? BMP_MIRROR_VERT
: 0 ) );
358 aActAttr
.SetRotation( sal_uInt16(aGeo
.nDrehWink
/ 10) );
361 // #107947# Delegate to moved code in GraphicObject
362 return GetGraphicObject().GetTransformedGraphic( aDestSize
, aDestMap
, aActAttr
);
365 // -----------------------------------------------------------------------------
367 GraphicType
SdrGrafObj::GetGraphicType() const
369 return pGraphic
->GetType();
372 sal_Bool
SdrGrafObj::IsAnimated() const
374 return pGraphic
->IsAnimated();
377 sal_Bool
SdrGrafObj::IsEPS() const
379 return pGraphic
->IsEPS();
382 sal_Bool
SdrGrafObj::IsSwappedOut() const
384 return mbIsPreview
? sal_True
: pGraphic
->IsSwappedOut();
387 const MapMode
& SdrGrafObj::GetGrafPrefMapMode() const
389 return pGraphic
->GetPrefMapMode();
392 const Size
& SdrGrafObj::GetGrafPrefSize() const
394 return pGraphic
->GetPrefSize();
397 // -----------------------------------------------------------------------------
399 void SdrGrafObj::SetGrafStreamURL( const String
& rGraphicStreamURL
)
401 mbIsPreview
= sal_False
;
402 if( !rGraphicStreamURL
.Len() )
404 pGraphic
->SetUserData();
406 else if( pModel
->IsSwapGraphics() )
408 pGraphic
->SetUserData( rGraphicStreamURL
);
410 // set state of graphic object to 'swapped out'
411 if( pGraphic
->GetType() == GRAPHIC_NONE
)
412 pGraphic
->SetSwapState();
416 // -----------------------------------------------------------------------------
418 String
SdrGrafObj::GetGrafStreamURL() const
420 return pGraphic
->GetUserData();
423 // -----------------------------------------------------------------------------
425 void SdrGrafObj::SetFileName(const String
& rFileName
)
427 aFileName
= rFileName
;
431 // -----------------------------------------------------------------------------
433 void SdrGrafObj::SetFilterName(const String
& rFilterName
)
435 aFilterName
= rFilterName
;
439 // -----------------------------------------------------------------------------
441 void SdrGrafObj::ForceSwapIn() const
445 // removing preview graphic
446 const String
aUserData( pGraphic
->GetUserData() );
449 pGraphic
->SetGraphic( aEmpty
);
450 pGraphic
->SetUserData( aUserData
);
451 pGraphic
->SetSwapState();
453 const_cast< SdrGrafObj
* >( this )->mbIsPreview
= sal_False
;
456 pGraphic
->FireSwapInRequest();
458 if( pGraphic
->IsSwappedOut() ||
459 ( pGraphic
->GetType() == GRAPHIC_NONE
) ||
460 ( pGraphic
->GetType() == GRAPHIC_DEFAULT
) )
462 Graphic aDefaultGraphic
;
463 aDefaultGraphic
.SetDefaultType();
464 pGraphic
->SetGraphic( aDefaultGraphic
);
468 // -----------------------------------------------------------------------------
470 void SdrGrafObj::ForceSwapOut() const
472 pGraphic
->FireSwapOutRequest();
475 // -----------------------------------------------------------------------------
477 void SdrGrafObj::ImpLinkAnmeldung()
479 SvxLinkManager
* pLinkManager
= pModel
!= NULL
? pModel
->GetLinkManager() : NULL
;
481 if( pLinkManager
!= NULL
&& pGraphicLink
== NULL
)
483 if( aFileName
.Len() )
485 pGraphicLink
= new SdrGraphicLink( this );
486 pLinkManager
->InsertFileLink( *pGraphicLink
, OBJECT_CLIENT_GRF
, aFileName
, ( aFilterName
.Len() ? &aFilterName
: NULL
), NULL
);
487 pGraphicLink
->Connect();
492 // -----------------------------------------------------------------------------
494 void SdrGrafObj::ImpLinkAbmeldung()
496 SvxLinkManager
* pLinkManager
= pModel
!= NULL
? pModel
->GetLinkManager() : NULL
;
498 if( pLinkManager
!= NULL
&& pGraphicLink
!=NULL
)
500 // Bei Remove wird *pGraphicLink implizit deleted
501 pLinkManager
->Remove( pGraphicLink
);
506 // -----------------------------------------------------------------------------
508 void SdrGrafObj::SetGraphicLink( const String
& rFileName
, const String
& rFilterName
)
511 aFileName
= rFileName
;
512 aFilterName
= rFilterName
;
514 pGraphic
->SetUserData();
516 // #92205# A linked graphic is per definition swapped out (has to be loaded)
517 pGraphic
->SetSwapState();
520 // -----------------------------------------------------------------------------
522 void SdrGrafObj::ReleaseGraphicLink()
525 aFileName
= String();
526 aFilterName
= String();
529 // -----------------------------------------------------------------------------
531 void SdrGrafObj::TakeObjInfo(SdrObjTransformInfoRec
& rInfo
) const
533 FASTBOOL bAnim
= pGraphic
->IsAnimated();
534 FASTBOOL bNoPresGrf
= ( pGraphic
->GetType() != GRAPHIC_NONE
) && !bEmptyPresObj
;
536 rInfo
.bResizeFreeAllowed
= aGeo
.nDrehWink
% 9000 == 0 ||
537 aGeo
.nDrehWink
% 18000 == 0 ||
538 aGeo
.nDrehWink
% 27000 == 0;
540 rInfo
.bResizePropAllowed
= TRUE
;
541 rInfo
.bRotateFreeAllowed
= bNoPresGrf
&& !bAnim
;
542 rInfo
.bRotate90Allowed
= bNoPresGrf
&& !bAnim
;
543 rInfo
.bMirrorFreeAllowed
= bNoPresGrf
&& !bAnim
;
544 rInfo
.bMirror45Allowed
= bNoPresGrf
&& !bAnim
;
545 rInfo
.bMirror90Allowed
= !bEmptyPresObj
;
546 rInfo
.bTransparenceAllowed
= FALSE
;
547 rInfo
.bGradientAllowed
= FALSE
;
548 rInfo
.bShearAllowed
= FALSE
;
549 rInfo
.bEdgeRadiusAllowed
=FALSE
;
550 rInfo
.bCanConvToPath
= FALSE
;
551 rInfo
.bCanConvToPathLineToArea
= FALSE
;
552 rInfo
.bCanConvToPolyLineToArea
= FALSE
;
553 rInfo
.bCanConvToPoly
= !IsEPS();
554 rInfo
.bCanConvToContour
= (rInfo
.bCanConvToPoly
|| LineGeometryUsageIsNecessary());
557 // -----------------------------------------------------------------------------
559 UINT16
SdrGrafObj::GetObjIdentifier() const
561 return UINT16( OBJ_GRAF
);
564 // -----------------------------------------------------------------------------
566 sal_Bool
SdrGrafObj::ImpUpdateGraphicLink() const
568 sal_Bool bRet
= sal_False
;
572 const sal_Bool bIsChanged
= pModel
->IsChanged();
573 pGraphicLink
->UpdateSynchron();
574 pModel
->SetChanged( bIsChanged
);
582 // -----------------------------------------------------------------------------
584 void SdrGrafObj::TakeObjNameSingul(XubString
& rName
) const
586 switch( pGraphic
->GetType() )
590 const USHORT nId
= ( ( pGraphic
->IsTransparent() || ( (const SdrGrafTransparenceItem
&) GetObjectItem( SDRATTR_GRAFTRANSPARENCE
) ).GetValue() ) ?
591 ( IsLinkedGraphic() ? STR_ObjNameSingulGRAFBMPTRANSLNK
: STR_ObjNameSingulGRAFBMPTRANS
) :
592 ( IsLinkedGraphic() ? STR_ObjNameSingulGRAFBMPLNK
: STR_ObjNameSingulGRAFBMP
) );
594 rName
=ImpGetResStr( nId
);
598 case GRAPHIC_GDIMETAFILE
:
599 rName
=ImpGetResStr( IsLinkedGraphic() ? STR_ObjNameSingulGRAFMTFLNK
: STR_ObjNameSingulGRAFMTF
);
603 rName
=ImpGetResStr( IsLinkedGraphic() ? STR_ObjNameSingulGRAFNONELNK
: STR_ObjNameSingulGRAFNONE
);
607 rName
=ImpGetResStr( IsLinkedGraphic() ? STR_ObjNameSingulGRAFLNK
: STR_ObjNameSingulGRAF
);
611 const String
aName(GetName());
615 rName
.AppendAscii( " '" );
617 rName
+= sal_Unicode( '\'' );
621 // -----------------------------------------------------------------------------
623 void SdrGrafObj::TakeObjNamePlural( XubString
& rName
) const
625 switch( pGraphic
->GetType() )
629 const USHORT nId
= ( ( pGraphic
->IsTransparent() || ( (const SdrGrafTransparenceItem
&) GetObjectItem( SDRATTR_GRAFTRANSPARENCE
) ).GetValue() ) ?
630 ( IsLinkedGraphic() ? STR_ObjNamePluralGRAFBMPTRANSLNK
: STR_ObjNamePluralGRAFBMPTRANS
) :
631 ( IsLinkedGraphic() ? STR_ObjNamePluralGRAFBMPLNK
: STR_ObjNamePluralGRAFBMP
) );
633 rName
=ImpGetResStr( nId
);
637 case GRAPHIC_GDIMETAFILE
:
638 rName
=ImpGetResStr( IsLinkedGraphic() ? STR_ObjNamePluralGRAFMTFLNK
: STR_ObjNamePluralGRAFMTF
);
642 rName
=ImpGetResStr( IsLinkedGraphic() ? STR_ObjNamePluralGRAFNONELNK
: STR_ObjNamePluralGRAFNONE
);
646 rName
=ImpGetResStr( IsLinkedGraphic() ? STR_ObjNamePluralGRAFLNK
: STR_ObjNamePluralGRAF
);
650 const String
aName(GetName());
654 rName
.AppendAscii( " '" );
656 rName
+= sal_Unicode( '\'' );
660 // -----------------------------------------------------------------------------
662 SdrObject
* SdrGrafObj::getFullDragClone() const
665 SdrGrafObj
* pRetval
= static_cast< SdrGrafObj
* >(SdrRectObj::getFullDragClone());
667 // #i103116# the full drag clone leads to problems
668 // with linked graphics, so reset the link in this
669 // temporary interaction object and load graphic
670 if(pRetval
&& IsLinkedGraphic())
672 pRetval
->ForceSwapIn();
673 pRetval
->ReleaseGraphicLink();
679 void SdrGrafObj::operator=( const SdrObject
& rObj
)
681 SdrRectObj::operator=( rObj
);
683 const SdrGrafObj
& rGraf
= (SdrGrafObj
&) rObj
;
685 pGraphic
->SetGraphic( rGraf
.GetGraphic() );
686 aCropRect
= rGraf
.aCropRect
;
687 aFileName
= rGraf
.aFileName
;
688 aFilterName
= rGraf
.aFilterName
;
689 bMirrored
= rGraf
.bMirrored
;
691 if( rGraf
.pGraphicLink
!= NULL
)
693 SetGraphicLink( aFileName
, aFilterName
);
696 ImpSetAttrToGrafInfo();
699 // -----------------------------------------------------------------------------
702 basegfx::B2DPolyPolygon
SdrGrafObj::TakeXorPoly() const
706 basegfx::B2DPolyPolygon aRetval
;
708 // take grown rectangle
709 const sal_Int32
nHalfLineWidth(ImpGetLineWdt() / 2);
710 const Rectangle
aGrownRect(
711 aRect
.Left() - nHalfLineWidth
,
712 aRect
.Top() - nHalfLineWidth
,
713 aRect
.Right() + nHalfLineWidth
,
714 aRect
.Bottom() + nHalfLineWidth
);
716 XPolygon
aXPoly(ImpCalcXPoly(aGrownRect
, GetEckenradius()));
717 aRetval
.append(aXPoly
.getB2DPolygon());
724 return SdrRectObj::TakeXorPoly();
728 // -----------------------------------------------------------------------------
730 sal_uInt32
SdrGrafObj::GetHdlCount() const
735 // -----------------------------------------------------------------------------
737 SdrHdl
* SdrGrafObj::GetHdl(sal_uInt32 nHdlNum
) const
739 return SdrRectObj::GetHdl( nHdlNum
+ 1L );
742 // -----------------------------------------------------------------------------
744 void SdrGrafObj::NbcResize(const Point
& rRef
, const Fraction
& xFact
, const Fraction
& yFact
)
746 SdrRectObj::NbcResize( rRef
, xFact
, yFact
);
748 FASTBOOL bMirrX
= xFact
.GetNumerator() < 0;
749 FASTBOOL bMirrY
= yFact
.GetNumerator() < 0;
751 if( bMirrX
!= bMirrY
)
752 bMirrored
= !bMirrored
;
755 // -----------------------------------------------------------------------------
757 void SdrGrafObj::NbcRotate(const Point
& rRef
, long nWink
, double sn
, double cs
)
759 SdrRectObj::NbcRotate(rRef
,nWink
,sn
,cs
);
762 // -----------------------------------------------------------------------------
764 void SdrGrafObj::NbcMirror(const Point
& rRef1
, const Point
& rRef2
)
766 SdrRectObj::NbcMirror(rRef1
,rRef2
);
767 bMirrored
= !bMirrored
;
770 // -----------------------------------------------------------------------------
772 void SdrGrafObj::NbcShear(const Point
& rRef
, long nWink
, double tn
, FASTBOOL bVShear
)
774 SdrRectObj::NbcRotate( rRef
, nWink
, tn
, bVShear
);
777 // -----------------------------------------------------------------------------
779 void SdrGrafObj::NbcSetSnapRect(const Rectangle
& rRect
)
781 SdrRectObj::NbcSetSnapRect(rRect
);
784 // -----------------------------------------------------------------------------
786 void SdrGrafObj::NbcSetLogicRect( const Rectangle
& rRect
)
788 //FASTBOOL bChg=rRect.GetSize()!=aRect.GetSize();
789 SdrRectObj::NbcSetLogicRect(rRect
);
792 // -----------------------------------------------------------------------------
794 SdrObjGeoData
* SdrGrafObj::NewGeoData() const
796 return new SdrGrafObjGeoData
;
799 // -----------------------------------------------------------------------------
801 void SdrGrafObj::SaveGeoData(SdrObjGeoData
& rGeo
) const
803 SdrRectObj::SaveGeoData(rGeo
);
804 SdrGrafObjGeoData
& rGGeo
=(SdrGrafObjGeoData
&)rGeo
;
805 rGGeo
.bMirrored
=bMirrored
;
808 // -----------------------------------------------------------------------------
810 void SdrGrafObj::RestGeoData(const SdrObjGeoData
& rGeo
)
812 //long nDrehMerk = aGeo.nDrehWink;
813 //long nShearMerk = aGeo.nShearWink;
814 //FASTBOOL bMirrMerk = bMirrored;
815 Size
aSizMerk( aRect
.GetSize() );
817 SdrRectObj::RestGeoData(rGeo
);
818 SdrGrafObjGeoData
& rGGeo
=(SdrGrafObjGeoData
&)rGeo
;
819 bMirrored
=rGGeo
.bMirrored
;
822 // -----------------------------------------------------------------------------
824 void SdrGrafObj::SetPage( SdrPage
* pNewPage
)
826 FASTBOOL bRemove
= pNewPage
== NULL
&& pPage
!= NULL
;
827 FASTBOOL bInsert
= pNewPage
!= NULL
&& pPage
== NULL
;
831 // hier kein SwapIn noetig, weil wenn nicht geladen, dann auch nicht animiert.
832 if( pGraphic
->IsAnimated())
833 pGraphic
->StopAnimation();
835 if( pGraphicLink
!= NULL
)
839 SdrRectObj::SetPage( pNewPage
);
841 if(aFileName
.Len() && bInsert
)
845 // -----------------------------------------------------------------------------
847 void SdrGrafObj::SetModel( SdrModel
* pNewModel
)
849 FASTBOOL bChg
= pNewModel
!= pModel
;
853 if( pGraphic
->HasUserData() )
856 pGraphic
->SetUserData();
859 if( pGraphicLink
!= NULL
)
864 SdrRectObj::SetModel(pNewModel
);
866 if( bChg
&& aFileName
.Len() )
870 // -----------------------------------------------------------------------------
872 void SdrGrafObj::StartAnimation( OutputDevice
* /*pOutDev*/, const Point
& /*rPoint*/, const Size
& /*rSize*/, long /*nExtraData*/)
875 // use new graf animation
876 SetGrafAnimationAllowed(sal_True
);
879 // -----------------------------------------------------------------------------
881 void SdrGrafObj::StopAnimation(OutputDevice
* /*pOutDev*/, long /*nExtraData*/)
884 // use new graf animation
885 SetGrafAnimationAllowed(sal_False
);
888 // -----------------------------------------------------------------------------
890 FASTBOOL
SdrGrafObj::HasGDIMetaFile() const
892 return( pGraphic
->GetType() == GRAPHIC_GDIMETAFILE
);
895 // -----------------------------------------------------------------------------
897 const GDIMetaFile
* SdrGrafObj::GetGDIMetaFile() const
899 DBG_ERROR( "Invalid return value! Don't use it! (KA)" );
900 return &GetGraphic().GetGDIMetaFile();
903 // -----------------------------------------------------------------------------
905 SdrObject
* SdrGrafObj::DoConvertToPolyObj(BOOL bBezier
) const
907 SdrObject
* pRetval
= NULL
;
909 switch( GetGraphicType() )
911 case GRAPHIC_GDIMETAFILE
:
913 // NUR die aus dem MetaFile erzeugbaren Objekte in eine Gruppe packen und zurueckliefern
914 SdrObjGroup
* pGrp
= new SdrObjGroup();
915 ImpSdrGDIMetaFileImport
aFilter(*GetModel());
916 Point
aOutPos( aRect
.TopLeft() );
917 const Size
aOutSiz( aRect
.GetSize() );
919 aFilter
.SetScaleRect(GetSnapRect());
920 aFilter
.SetLayer(GetLayer());
922 UINT32 nInsAnz
= aFilter
.DoImport(GetTransformedGraphic().GetGDIMetaFile(), *pGrp
->GetSubList(), 0);
926 pGrp
->NbcSetLayer(GetLayer());
927 pGrp
->SetModel(GetModel());
928 pRetval
= ImpConvertAddText(pRetval
, bBezier
);
930 // convert all children
933 SdrObject
* pHalfDone
= pRetval
;
934 pRetval
= pHalfDone
->DoConvertToPolyObj(bBezier
);
935 SdrObject::Free( pHalfDone
); // resulting object is newly created
939 // flatten subgroups. As we call
940 // DoConvertToPolyObj() on the resulting group
941 // objects, subgroups can exist (e.g. text is
942 // a group object for every line).
943 SdrObjList
* pList
= pRetval
->GetSubList();
945 pList
->FlattenGroups();
955 // Grundobjekt kreieren und Fuellung ergaenzen
956 pRetval
= SdrRectObj::DoConvertToPolyObj(bBezier
);
958 // Bitmap als Attribut retten
961 // Bitmap als Fuellung holen
962 SfxItemSet
aSet(GetObjectItemSet());
964 aSet
.Put(XFillStyleItem(XFILL_BITMAP
));
965 Bitmap
aBitmap( GetTransformedGraphic().GetBitmap() );
966 XOBitmap
aXBmp(aBitmap
, XBITMAP_STRETCH
);
967 aSet
.Put(XFillBitmapItem(String(), aXBmp
));
968 aSet
.Put(XFillBmpTileItem(FALSE
));
970 pRetval
->SetMergedItemSet(aSet
);
975 case GRAPHIC_DEFAULT
:
977 pRetval
= SdrRectObj::DoConvertToPolyObj(bBezier
);
985 // -----------------------------------------------------------------------------
987 void SdrGrafObj::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
990 SdrRectObj::Notify( rBC
, rHint
);
991 ImpSetAttrToGrafInfo();
994 void SdrGrafObj::ImpSetAttrToGrafInfo()
996 const SfxItemSet
& rSet
= GetObjectItemSet();
997 const sal_uInt16 nTrans
= ( (SdrGrafTransparenceItem
&) rSet
.Get( SDRATTR_GRAFTRANSPARENCE
) ).GetValue();
998 const SdrGrafCropItem
& rCrop
= (const SdrGrafCropItem
&) rSet
.Get( SDRATTR_GRAFCROP
);
1000 aGrafInfo
.SetLuminance( ( (SdrGrafLuminanceItem
&) rSet
.Get( SDRATTR_GRAFLUMINANCE
) ).GetValue() );
1001 aGrafInfo
.SetContrast( ( (SdrGrafContrastItem
&) rSet
.Get( SDRATTR_GRAFCONTRAST
) ).GetValue() );
1002 aGrafInfo
.SetChannelR( ( (SdrGrafRedItem
&) rSet
.Get( SDRATTR_GRAFRED
) ).GetValue() );
1003 aGrafInfo
.SetChannelG( ( (SdrGrafGreenItem
&) rSet
.Get( SDRATTR_GRAFGREEN
) ).GetValue() );
1004 aGrafInfo
.SetChannelB( ( (SdrGrafBlueItem
&) rSet
.Get( SDRATTR_GRAFBLUE
) ).GetValue() );
1005 aGrafInfo
.SetGamma( ( (SdrGrafGamma100Item
&) rSet
.Get( SDRATTR_GRAFGAMMA
) ).GetValue() * 0.01 );
1006 aGrafInfo
.SetTransparency( (BYTE
) FRound( Min( nTrans
, (USHORT
) 100 ) * 2.55 ) );
1007 aGrafInfo
.SetInvert( ( (SdrGrafInvertItem
&) rSet
.Get( SDRATTR_GRAFINVERT
) ).GetValue() );
1008 aGrafInfo
.SetDrawMode( ( (SdrGrafModeItem
&) rSet
.Get( SDRATTR_GRAFMODE
) ).GetValue() );
1009 aGrafInfo
.SetCrop( rCrop
.GetLeft(), rCrop
.GetTop(), rCrop
.GetRight(), rCrop
.GetBottom() );
1015 // -----------------------------------------------------------------------------
1017 void SdrGrafObj::ImpSetGrafInfoToAttr()
1019 SetObjectItem( SdrGrafLuminanceItem( aGrafInfo
.GetLuminance() ) );
1020 SetObjectItem( SdrGrafContrastItem( aGrafInfo
.GetContrast() ) );
1021 SetObjectItem( SdrGrafRedItem( aGrafInfo
.GetChannelR() ) );
1022 SetObjectItem( SdrGrafGreenItem( aGrafInfo
.GetChannelG() ) );
1023 SetObjectItem( SdrGrafBlueItem( aGrafInfo
.GetChannelB() ) );
1024 SetObjectItem( SdrGrafGamma100Item( FRound( aGrafInfo
.GetGamma() * 100.0 ) ) );
1025 SetObjectItem( SdrGrafTransparenceItem( (USHORT
) FRound( aGrafInfo
.GetTransparency() / 2.55 ) ) );
1026 SetObjectItem( SdrGrafInvertItem( aGrafInfo
.IsInvert() ) );
1027 SetObjectItem( SdrGrafModeItem( aGrafInfo
.GetDrawMode() ) );
1028 SetObjectItem( SdrGrafCropItem( aGrafInfo
.GetLeftCrop(), aGrafInfo
.GetTopCrop(), aGrafInfo
.GetRightCrop(), aGrafInfo
.GetBottomCrop() ) );
1031 // -----------------------------------------------------------------------------
1033 void SdrGrafObj::AdjustToMaxRect( const Rectangle
& rMaxRect
, BOOL bShrinkOnly
)
1036 Size
aMaxSize( rMaxRect
.GetSize() );
1037 if ( pGraphic
->GetPrefMapMode().GetMapUnit() == MAP_PIXEL
)
1038 aSize
= Application::GetDefaultDevice()->PixelToLogic( pGraphic
->GetPrefSize(), MAP_100TH_MM
);
1040 aSize
= OutputDevice::LogicToLogic( pGraphic
->GetPrefSize(),
1041 pGraphic
->GetPrefMapMode(),
1042 MapMode( MAP_100TH_MM
) );
1044 if( aSize
.Height() != 0 && aSize
.Width() != 0 )
1046 Point
aPos( rMaxRect
.TopLeft() );
1048 // Falls Grafik zu gross, wird die Grafik
1049 // in die Seite eingepasst
1050 if ( (!bShrinkOnly
||
1051 ( aSize
.Height() > aMaxSize
.Height() ) ||
1052 ( aSize
.Width() > aMaxSize
.Width() ) )&&
1053 aSize
.Height() && aMaxSize
.Height() )
1055 float fGrfWH
= (float)aSize
.Width() /
1056 (float)aSize
.Height();
1057 float fWinWH
= (float)aMaxSize
.Width() /
1058 (float)aMaxSize
.Height();
1060 // Grafik an Pagesize anpassen (skaliert)
1061 if ( fGrfWH
< fWinWH
)
1063 aSize
.Width() = (long)(aMaxSize
.Height() * fGrfWH
);
1064 aSize
.Height()= aMaxSize
.Height();
1066 else if ( fGrfWH
> 0.F
)
1068 aSize
.Width() = aMaxSize
.Width();
1069 aSize
.Height()= (long)(aMaxSize
.Width() / fGrfWH
);
1072 aPos
= rMaxRect
.Center();
1076 aPos
= aRect
.TopLeft();
1078 aPos
.X() -= aSize
.Width() / 2;
1079 aPos
.Y() -= aSize
.Height() / 2;
1080 SetLogicRect( Rectangle( aPos
, aSize
) );
1084 // -----------------------------------------------------------------------------
1086 IMPL_LINK( SdrGrafObj
, ImpSwapHdl
, GraphicObject
*, pO
)
1088 SvStream
* pRet
= GRFMGR_AUTOSWAPSTREAM_NONE
;
1090 if( pO
->IsInSwapOut() )
1092 if( pModel
&& !mbIsPreview
&& pModel
->IsSwapGraphics() && pGraphic
->GetSizeBytes() > 20480 )
1094 // test if this object is visualized from someone
1095 // ## test only if there are VOCs other than the preview renderer
1096 if(!GetViewContact().HasViewObjectContacts(true))
1098 const ULONG nSwapMode
= pModel
->GetSwapGraphicsMode();
1100 if( ( pGraphic
->HasUserData() || pGraphicLink
) &&
1101 ( nSwapMode
& SDR_SWAPGRAPHICSMODE_PURGE
) )
1105 else if( nSwapMode
& SDR_SWAPGRAPHICSMODE_TEMP
)
1107 pRet
= GRFMGR_AUTOSWAPSTREAM_TEMP
;
1108 pGraphic
->SetUserData();
1112 sdr::contact::ViewContactOfGraphic
* pVC
= dynamic_cast< sdr::contact::ViewContactOfGraphic
* >(&GetViewContact());
1116 pVC
->flushGraphicObjects();
1121 else if( pO
->IsInSwapIn() )
1123 // kann aus dem original Doc-Stream nachgeladen werden...
1124 if( pModel
!= NULL
)
1126 if( pGraphic
->HasUserData() )
1128 SdrDocumentStreamInfo aStreamInfo
;
1130 aStreamInfo
.mbDeleteAfterUse
= FALSE
;
1131 aStreamInfo
.maUserData
= pGraphic
->GetUserData();
1133 SvStream
* pStream
= pModel
->GetDocumentStream( aStreamInfo
);
1135 if( pStream
!= NULL
)
1139 com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyValue
>* pFilterData
= NULL
;
1141 if(mbInsidePaint
&& !GetViewContact().HasViewObjectContacts(true))
1143 // Rectangle aSnapRect(GetSnapRect());
1144 // const Rectangle aSnapRectPixel(pOutDev->LogicToPixel(aSnapRect));
1146 pFilterData
= new com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyValue
>( 3 );
1148 com::sun::star::awt::Size
aPreviewSizeHint( 64, 64 );
1149 sal_Bool bAllowPartialStreamRead
= sal_True
;
1150 sal_Bool bCreateNativeLink
= sal_False
;
1151 (*pFilterData
)[ 0 ].Name
= String( RTL_CONSTASCII_USTRINGPARAM( "PreviewSizeHint" ) );
1152 (*pFilterData
)[ 0 ].Value
<<= aPreviewSizeHint
;
1153 (*pFilterData
)[ 1 ].Name
= String( RTL_CONSTASCII_USTRINGPARAM( "AllowPartialStreamRead" ) );
1154 (*pFilterData
)[ 1 ].Value
<<= bAllowPartialStreamRead
;
1155 (*pFilterData
)[ 2 ].Name
= String( RTL_CONSTASCII_USTRINGPARAM( "CreateNativeLink" ) );
1156 (*pFilterData
)[ 2 ].Value
<<= bCreateNativeLink
;
1158 mbIsPreview
= sal_True
;
1161 if( !GetGrfFilter()->ImportGraphic( aGraphic
, String(), *pStream
,
1162 GRFILTER_FORMAT_DONTKNOW
, NULL
, 0, pFilterData
) )
1164 const String
aUserData( pGraphic
->GetUserData() );
1166 pGraphic
->SetGraphic( aGraphic
);
1167 pGraphic
->SetUserData( aUserData
);
1169 // #142146# Graphic successfully swapped in.
1170 pRet
= GRFMGR_AUTOSWAPSTREAM_LOADED
;
1174 pStream
->ResetError();
1176 if( aStreamInfo
.mbDeleteAfterUse
|| aStreamInfo
.mxStorageRef
.is() )
1178 if ( aStreamInfo
.mxStorageRef
.is() )
1180 aStreamInfo
.mxStorageRef
->dispose();
1181 aStreamInfo
.mxStorageRef
= 0;
1188 else if( !ImpUpdateGraphicLink() )
1190 pRet
= GRFMGR_AUTOSWAPSTREAM_TEMP
;
1194 pRet
= GRFMGR_AUTOSWAPSTREAM_LOADED
;
1198 pRet
= GRFMGR_AUTOSWAPSTREAM_TEMP
;
1201 return (long)(void*) pRet
;
1204 // -----------------------------------------------------------------------------
1207 // Access to GrafAnimationAllowed flag
1208 sal_Bool
SdrGrafObj::IsGrafAnimationAllowed() const
1210 return mbGrafAnimationAllowed
;
1213 void SdrGrafObj::SetGrafAnimationAllowed(sal_Bool bNew
)
1215 if(mbGrafAnimationAllowed
!= bNew
)
1217 mbGrafAnimationAllowed
= bNew
;
1223 sal_Bool
SdrGrafObj::IsObjectTransparent() const
1225 if(((const SdrGrafTransparenceItem
&)GetObjectItem(SDRATTR_GRAFTRANSPARENCE
)).GetValue()
1226 || pGraphic
->IsTransparent())
1234 Reference
< XInputStream
> SdrGrafObj::getInputStream()
1236 Reference
< XInputStream
> xStream
;
1240 // if( !pGraphic->HasUserData() )
1241 // pGraphic->SwapOut();
1243 // kann aus dem original Doc-Stream nachgeladen werden...
1244 if( pGraphic
->HasUserData() )
1246 SdrDocumentStreamInfo aStreamInfo
;
1248 aStreamInfo
.mbDeleteAfterUse
= FALSE
;
1249 aStreamInfo
.maUserData
= pGraphic
->GetUserData();
1251 SvStream
* pStream
= pModel
->GetDocumentStream( aStreamInfo
);
1254 xStream
.set( new utl::OInputStreamWrapper( pStream
, sal_True
) );
1256 else if( pGraphic
&& GetGraphic().IsLink() )
1258 Graphic
aGraphic( GetGraphic() );
1259 GfxLink
aLink( aGraphic
.GetLink() );
1260 sal_uInt32 nSize
= aLink
.GetDataSize();
1261 const void* pSourceData
= (const void*)aLink
.GetData();
1262 if( nSize
&& pSourceData
)
1264 sal_uInt8
* pBuffer
= new sal_uInt8
[ nSize
];
1267 memcpy( pBuffer
, pSourceData
, nSize
);
1269 SvMemoryStream
* pStream
= new SvMemoryStream( (void*)pBuffer
, (sal_Size
)nSize
, STREAM_READ
);
1270 pStream
->ObjectOwnsMemory( sal_True
);
1271 xStream
.set( new utl::OInputStreamWrapper( pStream
, sal_True
) );
1276 if( !xStream
.is() && aFileName
.Len() )
1278 SvFileStream
* pStream
= new SvFileStream( aFileName
, STREAM_READ
);
1280 xStream
.set( new utl::OInputStreamWrapper( pStream
) );