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