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