bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / unoidl / unomodel.cxx
blob10941c629d07893163842d04e8e6833edb663ea5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <memory>
21 #include <boost/property_tree/json_parser.hpp>
23 #include <com/sun/star/presentation/XPresentation2.hpp>
25 #include <com/sun/star/lang/DisposedException.hpp>
26 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
27 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
28 #include <com/sun/star/lang/Locale.hpp>
29 #include <com/sun/star/style/XStyle.hpp>
30 #include <com/sun/star/awt/XDevice.hpp>
31 #include <com/sun/star/document/IndexedPropertyValues.hpp>
32 #include <com/sun/star/beans/PropertyAttribute.hpp>
34 #include <com/sun/star/embed/Aspects.hpp>
36 #include <comphelper/lok.hxx>
37 #include <comphelper/sequence.hxx>
38 #include <comphelper/servicehelper.hxx>
39 #include <cppuhelper/supportsservice.hxx>
40 #include <comphelper/processfactory.hxx>
41 #include <comphelper/profilezone.hxx>
43 #include <sal/log.hxx>
44 #include <editeng/unofield.hxx>
45 #include <notifydocumentevent.hxx>
46 #include <unomodel.hxx>
47 #include "unopool.hxx"
48 #include <sfx2/dispatch.hxx>
49 #include <sfx2/bindings.hxx>
50 #include <sfx2/lokhelper.hxx>
51 #include <vcl/commandevent.hxx>
52 #include <vcl/svapp.hxx>
53 #include <vcl/settings.hxx>
54 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
56 #include <editeng/UnoForbiddenCharsTable.hxx>
57 #include <svx/svdoutl.hxx>
58 #include <editeng/forbiddencharacterstable.hxx>
59 #include <o3tl/safeint.hxx>
60 #include <svx/UnoNamespaceMap.hxx>
61 #include <svx/svdlayer.hxx>
62 #include <svx/svdsob.hxx>
63 #include <svx/svdundo.hxx>
64 #include <svx/unoapi.hxx>
65 #include <svx/unofill.hxx>
66 #include <svx/unopool.hxx>
67 #include <svx/svdorect.hxx>
68 #include <editeng/flditem.hxx>
69 #include <editeng/fontitem.hxx>
70 #include <toolkit/awt/vclxdevice.hxx>
71 #include <svx/svdpool.hxx>
72 #include <editeng/unolingu.hxx>
73 #include <svx/svdpagv.hxx>
74 #include <svtools/unoimap.hxx>
75 #include <svx/unoshape.hxx>
76 #include <editeng/unonrule.hxx>
77 #include <editeng/eeitem.hxx>
78 #include <unotools/datetime.hxx>
79 #include <unotools/saveopt.hxx>
80 #include <xmloff/autolayout.hxx>
82 // Support creation of GraphicStorageHandler and EmbeddedObjectResolver
83 #include <svx/xmleohlp.hxx>
84 #include <svx/xmlgrhlp.hxx>
85 #include <DrawDocShell.hxx>
86 #include <ViewShellBase.hxx>
87 #include "UnoDocumentSettings.hxx"
89 #include <Annotation.hxx>
90 #include <drawdoc.hxx>
91 #include <sdmod.hxx>
92 #include <sdresid.hxx>
93 #include <sdpage.hxx>
95 #include <strings.hrc>
96 #include <strings.hxx>
97 #include "unolayer.hxx"
98 #include <unoprnms.hxx>
99 #include <unopage.hxx>
100 #include "unocpres.hxx"
101 #include "unoobj.hxx"
102 #include <stlpool.hxx>
103 #include "unopback.hxx"
104 #include <unokywds.hxx>
106 #include <FrameView.hxx>
107 #include <ClientView.hxx>
108 #include <DrawViewShell.hxx>
109 #include <ViewShell.hxx>
110 #include <Window.hxx>
111 #include <app.hrc>
112 #include <optsitem.hxx>
114 #include <vcl/pdfextoutdevdata.hxx>
115 #include <com/sun/star/presentation/AnimationSpeed.hpp>
116 #include <com/sun/star/presentation/ClickAction.hpp>
117 #include <svx/sdr/contact/viewobjectcontact.hxx>
118 #include <svx/sdr/contact/viewcontact.hxx>
119 #include <svx/sdr/contact/displayinfo.hxx>
121 #include <com/sun/star/office/XAnnotation.hpp>
122 #include <com/sun/star/office/XAnnotationAccess.hpp>
123 #include <com/sun/star/office/XAnnotationEnumeration.hpp>
124 #include <com/sun/star/geometry/RealPoint2D.hpp>
125 #include <com/sun/star/util/DateTime.hpp>
127 #include <drawinglayer/primitive2d/structuretagprimitive2d.hxx>
129 #include <sfx2/lokcharthelper.hxx>
130 #include <tools/debug.hxx>
131 #include <tools/diagnose_ex.h>
133 #define TWIPS_PER_PIXEL 15
135 using namespace ::cppu;
136 using namespace ::com::sun::star;
137 using namespace ::sd;
139 class SdUnoForbiddenCharsTable : public SvxUnoForbiddenCharsTable,
140 public SfxListener
142 public:
143 explicit SdUnoForbiddenCharsTable(SdrModel* pModel);
144 virtual ~SdUnoForbiddenCharsTable() override;
146 // SfxListener
147 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) throw () override;
148 protected:
149 virtual void onChange() override;
151 private:
152 SdrModel* mpModel;
155 SdUnoForbiddenCharsTable::SdUnoForbiddenCharsTable( SdrModel* pModel )
156 : SvxUnoForbiddenCharsTable( pModel->GetForbiddenCharsTable() ), mpModel( pModel )
158 StartListening( *pModel );
161 void SdUnoForbiddenCharsTable::onChange()
163 if( mpModel )
165 mpModel->ReformatAllTextObjects();
169 SdUnoForbiddenCharsTable::~SdUnoForbiddenCharsTable()
171 SolarMutexGuard g;
173 if( mpModel )
174 EndListening( *mpModel );
177 void SdUnoForbiddenCharsTable::Notify( SfxBroadcaster&, const SfxHint& rHint ) throw()
179 if (rHint.GetId() != SfxHintId::ThisIsAnSdrHint)
180 return;
181 const SdrHint* pSdrHint = static_cast<const SdrHint*>( &rHint );
182 if( SdrHintKind::ModelCleared == pSdrHint->GetKind() )
184 mpModel = nullptr;
188 const sal_uInt16 WID_MODEL_LANGUAGE = 1;
189 const sal_uInt16 WID_MODEL_TABSTOP = 2;
190 const sal_uInt16 WID_MODEL_VISAREA = 3;
191 const sal_uInt16 WID_MODEL_MAPUNIT = 4;
192 const sal_uInt16 WID_MODEL_FORBCHARS = 5;
193 const sal_uInt16 WID_MODEL_CONTFOCUS = 6;
194 const sal_uInt16 WID_MODEL_DSGNMODE = 7;
195 const sal_uInt16 WID_MODEL_BASICLIBS = 8;
196 const sal_uInt16 WID_MODEL_RUNTIMEUID = 9;
197 const sal_uInt16 WID_MODEL_BUILDID = 10;
198 const sal_uInt16 WID_MODEL_HASVALIDSIGNATURES = 11;
199 const sal_uInt16 WID_MODEL_DIALOGLIBS = 12;
200 const sal_uInt16 WID_MODEL_FONTS = 13;
201 const sal_uInt16 WID_MODEL_INTEROPGRABBAG = 14;
203 static const SvxItemPropertySet* ImplGetDrawModelPropertySet()
205 // Attention: the first parameter HAS TO BE sorted!!!
206 const static SfxItemPropertyMapEntry aDrawModelPropertyMap_Impl[] =
208 { OUString("BuildId"), WID_MODEL_BUILDID, ::cppu::UnoType<OUString>::get(), 0, 0},
209 { OUString(sUNO_Prop_CharLocale), WID_MODEL_LANGUAGE, ::cppu::UnoType<lang::Locale>::get(), 0, 0},
210 { OUString(sUNO_Prop_TabStop), WID_MODEL_TABSTOP, ::cppu::UnoType<sal_Int32>::get(), 0, 0},
211 { OUString(sUNO_Prop_VisibleArea), WID_MODEL_VISAREA, ::cppu::UnoType<awt::Rectangle>::get(), 0, 0},
212 { OUString(sUNO_Prop_MapUnit), WID_MODEL_MAPUNIT, ::cppu::UnoType<sal_Int16>::get(), beans::PropertyAttribute::READONLY, 0},
213 { OUString(sUNO_Prop_ForbiddenCharacters), WID_MODEL_FORBCHARS, cppu::UnoType<i18n::XForbiddenCharacters>::get(), beans::PropertyAttribute::READONLY, 0},
214 { OUString(sUNO_Prop_AutomContFocus), WID_MODEL_CONTFOCUS, cppu::UnoType<bool>::get(), 0, 0},
215 { OUString(sUNO_Prop_ApplyFrmDsgnMode), WID_MODEL_DSGNMODE, cppu::UnoType<bool>::get(), 0, 0},
216 { OUString("BasicLibraries"), WID_MODEL_BASICLIBS, cppu::UnoType<script::XLibraryContainer>::get(), beans::PropertyAttribute::READONLY, 0},
217 { OUString("DialogLibraries"), WID_MODEL_DIALOGLIBS, cppu::UnoType<script::XLibraryContainer>::get(), beans::PropertyAttribute::READONLY, 0},
218 { OUString(sUNO_Prop_RuntimeUID), WID_MODEL_RUNTIMEUID, ::cppu::UnoType<OUString>::get(), beans::PropertyAttribute::READONLY, 0},
219 { OUString(sUNO_Prop_HasValidSignatures), WID_MODEL_HASVALIDSIGNATURES, ::cppu::UnoType<sal_Bool>::get(), beans::PropertyAttribute::READONLY, 0},
220 { OUString("Fonts"), WID_MODEL_FONTS, cppu::UnoType<uno::Sequence<uno::Any>>::get(), beans::PropertyAttribute::READONLY, 0},
221 { OUString(sUNO_Prop_InteropGrabBag), WID_MODEL_INTEROPGRABBAG, cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get(), 0, 0},
222 { OUString(), 0, css::uno::Type(), 0, 0 }
224 static SvxItemPropertySet aDrawModelPropertySet_Impl( aDrawModelPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
225 return &aDrawModelPropertySet_Impl;
228 // this ctor is used from the DocShell
229 SdXImpressDocument::SdXImpressDocument(::sd::DrawDocShell* pShell, bool bClipBoard)
230 : SfxBaseModel( pShell ),
231 mpDocShell( pShell ),
232 mpDoc( pShell ? pShell->GetDoc() : nullptr ),
233 mbDisposed(false),
234 mbImpressDoc( pShell && pShell->GetDoc() && pShell->GetDoc()->GetDocumentType() == DocumentType::Impress ),
235 mbClipBoard( bClipBoard ),
236 mpPropSet( ImplGetDrawModelPropertySet() )
238 if( mpDoc )
240 StartListening( *mpDoc );
242 else
244 OSL_FAIL("DocShell is invalid");
248 SdXImpressDocument::SdXImpressDocument(SdDrawDocument* pDoc, bool bClipBoard)
249 : SfxBaseModel( nullptr ),
250 mpDocShell( nullptr ),
251 mpDoc( pDoc ),
252 mbDisposed(false),
253 mbImpressDoc( pDoc && pDoc->GetDocumentType() == DocumentType::Impress ),
254 mbClipBoard( bClipBoard ),
255 mpPropSet( ImplGetDrawModelPropertySet() )
257 if( mpDoc )
259 StartListening( *mpDoc );
261 else
263 OSL_FAIL("SdDrawDocument is invalid");
267 /***********************************************************************
269 ***********************************************************************/
270 SdXImpressDocument::~SdXImpressDocument() throw()
274 // XInterface
275 uno::Any SAL_CALL SdXImpressDocument::queryInterface( const uno::Type & rType )
277 uno::Any aAny;
279 if (rType == cppu::UnoType<lang::XServiceInfo>::get())
280 aAny <<= uno::Reference<lang::XServiceInfo>(this);
281 else if (rType == cppu::UnoType<beans::XPropertySet>::get())
282 aAny <<= uno::Reference<beans::XPropertySet>(this);
283 else if (rType == cppu::UnoType<lang::XMultiServiceFactory>::get())
284 aAny <<= uno::Reference<lang::XMultiServiceFactory>(this);
285 else if (rType == cppu::UnoType<drawing::XDrawPageDuplicator>::get())
286 aAny <<= uno::Reference<drawing::XDrawPageDuplicator>(this);
287 else if (rType == cppu::UnoType<drawing::XLayerSupplier>::get())
288 aAny <<= uno::Reference<drawing::XLayerSupplier>(this);
289 else if (rType == cppu::UnoType<drawing::XMasterPagesSupplier>::get())
290 aAny <<= uno::Reference<drawing::XMasterPagesSupplier>(this);
291 else if (rType == cppu::UnoType<drawing::XDrawPagesSupplier>::get())
292 aAny <<= uno::Reference<drawing::XDrawPagesSupplier>(this);
293 else if (rType == cppu::UnoType<presentation::XHandoutMasterSupplier>::get())
294 aAny <<= uno::Reference<presentation::XHandoutMasterSupplier>(this);
295 else if (rType == cppu::UnoType<document::XLinkTargetSupplier>::get())
296 aAny <<= uno::Reference<document::XLinkTargetSupplier>(this);
297 else if (rType == cppu::UnoType<style::XStyleFamiliesSupplier>::get())
298 aAny <<= uno::Reference<style::XStyleFamiliesSupplier>(this);
299 else if (rType == cppu::UnoType<css::ucb::XAnyCompareFactory>::get())
300 aAny <<= uno::Reference<css::ucb::XAnyCompareFactory>(this);
301 else if (rType == cppu::UnoType<view::XRenderable>::get())
302 aAny <<= uno::Reference<view::XRenderable>(this);
303 else if (mbImpressDoc && rType == cppu::UnoType<presentation::XPresentationSupplier>::get())
304 aAny <<= uno::Reference< presentation::XPresentationSupplier >(this);
305 else if (mbImpressDoc && rType == cppu::UnoType<presentation::XCustomPresentationSupplier>::get())
306 aAny <<= uno::Reference< presentation::XCustomPresentationSupplier >(this);
307 else
308 return SfxBaseModel::queryInterface(rType);
310 return aAny;
313 void SAL_CALL SdXImpressDocument::acquire() throw ( )
315 SfxBaseModel::acquire();
318 void SAL_CALL SdXImpressDocument::release() throw ( )
320 if (osl_atomic_decrement( &m_refCount ) != 0)
321 return;
323 // restore reference count:
324 osl_atomic_increment( &m_refCount );
325 if(!mbDisposed)
329 dispose();
331 catch (const uno::RuntimeException&)
332 { // don't break throw ()
333 css::uno::Any ex( cppu::getCaughtException() );
334 SAL_WARN( "sd", exceptionToString(ex) );
337 SfxBaseModel::release();
340 namespace
342 class theSdXImpressDocumentUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSdXImpressDocumentUnoTunnelId> {};
345 // XUnoTunnel
346 const css::uno::Sequence< sal_Int8 > & SdXImpressDocument::getUnoTunnelId() throw()
348 return theSdXImpressDocumentUnoTunnelId::get().getSeq();
351 SdXImpressDocument* SdXImpressDocument::getImplementation( const uno::Reference< uno::XInterface >& xInt )
353 css::uno::Reference< css::lang::XUnoTunnel > xUT( xInt, uno::UNO_QUERY );
354 if( xUT.is() )
355 return reinterpret_cast<SdXImpressDocument*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething( SdXImpressDocument::getUnoTunnelId() )));
356 else
357 return nullptr;
360 sal_Int64 SAL_CALL SdXImpressDocument::getSomething( const css::uno::Sequence< sal_Int8 >& rIdentifier )
362 if( rIdentifier.getLength() == 16 )
364 if( 0 == memcmp( SdXImpressDocument::getUnoTunnelId().getConstArray(), rIdentifier.getConstArray(), 16 ) )
365 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
367 if( 0 == memcmp( SdrModel::getUnoTunnelImplementationId().getConstArray(), rIdentifier.getConstArray(), 16 ) )
368 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(mpDoc));
371 return SfxBaseModel::getSomething( rIdentifier );
374 // XTypeProvider
375 uno::Sequence< uno::Type > SAL_CALL SdXImpressDocument::getTypes( )
377 ::SolarMutexGuard aGuard;
379 if( maTypeSequence.getLength() == 0 )
381 uno::Sequence< uno::Type > aTypes( SfxBaseModel::getTypes() );
382 aTypes = comphelper::concatSequences(aTypes,
383 uno::Sequence {
384 cppu::UnoType<beans::XPropertySet>::get(),
385 cppu::UnoType<lang::XServiceInfo>::get(),
386 cppu::UnoType<lang::XMultiServiceFactory>::get(),
387 cppu::UnoType<drawing::XDrawPageDuplicator>::get(),
388 cppu::UnoType<drawing::XLayerSupplier>::get(),
389 cppu::UnoType<drawing::XMasterPagesSupplier>::get(),
390 cppu::UnoType<drawing::XDrawPagesSupplier>::get(),
391 cppu::UnoType<document::XLinkTargetSupplier>::get(),
392 cppu::UnoType<style::XStyleFamiliesSupplier>::get(),
393 cppu::UnoType<css::ucb::XAnyCompareFactory>::get(),
394 cppu::UnoType<view::XRenderable>::get() });
395 if( mbImpressDoc )
397 aTypes = comphelper::concatSequences(aTypes,
398 uno::Sequence {
399 cppu::UnoType<presentation::XPresentationSupplier>::get(),
400 cppu::UnoType<presentation::XCustomPresentationSupplier>::get(),
401 cppu::UnoType<presentation::XHandoutMasterSupplier>::get() });
403 maTypeSequence = aTypes;
406 return maTypeSequence;
409 uno::Sequence< sal_Int8 > SAL_CALL SdXImpressDocument::getImplementationId( )
411 return css::uno::Sequence<sal_Int8>();
414 /***********************************************************************
416 ***********************************************************************/
417 void SdXImpressDocument::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
419 if( mpDoc )
421 if (rHint.GetId() == SfxHintId::ThisIsAnSdrHint)
423 const SdrHint* pSdrHint = static_cast<const SdrHint*>( &rHint );
424 if( hasEventListeners() )
426 document::EventObject aEvent;
427 if( SvxUnoDrawMSFactory::createEvent( mpDoc, pSdrHint, aEvent ) )
428 notifyEvent( aEvent );
431 if( pSdrHint->GetKind() == SdrHintKind::ModelCleared )
433 if( mpDoc )
434 EndListening( *mpDoc );
435 mpDoc = nullptr;
436 mpDocShell = nullptr;
439 else
441 // did our SdDrawDocument just died?
442 if(rHint.GetId() == SfxHintId::Dying)
444 // yes, so we ask for a new one
445 if( mpDocShell )
447 SdDrawDocument *pNewDoc = mpDocShell->GetDoc();
449 // is there a new one?
450 if( pNewDoc != mpDoc )
452 mpDoc = pNewDoc;
453 if(mpDoc)
454 StartListening( *mpDoc );
460 SfxBaseModel::Notify( rBC, rHint );
463 /******************************************************************************
465 ******************************************************************************/
466 SdPage* SdXImpressDocument::InsertSdPage( sal_uInt16 nPage, bool bDuplicate )
468 sal_uInt16 nPageCount = mpDoc->GetSdPageCount( PageKind::Standard );
469 SdrLayerAdmin& rLayerAdmin = mpDoc->GetLayerAdmin();
470 SdrLayerID aBckgrnd = rLayerAdmin.GetLayerID(sUNO_LayerName_background);
471 SdrLayerID aBckgrndObj = rLayerAdmin.GetLayerID(sUNO_LayerName_background_objects);
473 SdPage* pStandardPage = nullptr;
475 if( 0 == nPageCount )
477 // this is only used for clipboard where we only have one page
478 pStandardPage = mpDoc->AllocSdPage(false);
480 Size aDefSize(21000, 29700); // A4 portrait orientation
481 pStandardPage->SetSize( aDefSize );
482 mpDoc->InsertPage(pStandardPage, 0);
484 else
486 // here we determine the page after which we should insert
487 SdPage* pPreviousStandardPage = mpDoc->GetSdPage( std::min( static_cast<sal_uInt16>(nPageCount - 1), nPage ), PageKind::Standard );
488 SdrLayerIDSet aVisibleLayers = pPreviousStandardPage->TRG_GetMasterPageVisibleLayers();
489 bool bIsPageBack = aVisibleLayers.IsSet( aBckgrnd );
490 bool bIsPageObj = aVisibleLayers.IsSet( aBckgrndObj );
492 // AutoLayouts must be ready
493 mpDoc->StopWorkStartupDelay();
495 /* First we create a standard page and then a notes page. It is
496 guaranteed, that after a standard page the corresponding notes page
497 follows. */
499 sal_uInt16 nStandardPageNum = pPreviousStandardPage->GetPageNum() + 2;
500 SdPage* pPreviousNotesPage = static_cast<SdPage*>( mpDoc->GetPage( nStandardPageNum - 1 ) );
501 sal_uInt16 nNotesPageNum = nStandardPageNum + 1;
503 /**************************************************************
504 * standard page
505 **************************************************************/
506 if( bDuplicate )
507 pStandardPage = static_cast<SdPage*>( pPreviousStandardPage->CloneSdrPage(*mpDoc) );
508 else
509 pStandardPage = mpDoc->AllocSdPage(false);
511 pStandardPage->SetSize( pPreviousStandardPage->GetSize() );
512 pStandardPage->SetBorder( pPreviousStandardPage->GetLeftBorder(),
513 pPreviousStandardPage->GetUpperBorder(),
514 pPreviousStandardPage->GetRightBorder(),
515 pPreviousStandardPage->GetLowerBorder() );
516 pStandardPage->SetOrientation( pPreviousStandardPage->GetOrientation() );
517 pStandardPage->SetName(OUString());
519 // insert page after current page
520 mpDoc->InsertPage(pStandardPage, nStandardPageNum);
522 if( !bDuplicate )
524 // use MasterPage of the current page
525 pStandardPage->TRG_SetMasterPage(pPreviousStandardPage->TRG_GetMasterPage());
526 pStandardPage->SetLayoutName( pPreviousStandardPage->GetLayoutName() );
527 pStandardPage->SetAutoLayout(AUTOLAYOUT_NONE, true );
530 aBckgrnd = rLayerAdmin.GetLayerID(sUNO_LayerName_background);
531 aBckgrndObj = rLayerAdmin.GetLayerID(sUNO_LayerName_background_objects);
532 aVisibleLayers.Set(aBckgrnd, bIsPageBack);
533 aVisibleLayers.Set(aBckgrndObj, bIsPageObj);
534 pStandardPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
536 /**************************************************************
537 * notes page
538 **************************************************************/
539 SdPage* pNotesPage = nullptr;
541 if( bDuplicate )
542 pNotesPage = static_cast<SdPage*>( pPreviousNotesPage->CloneSdrPage(*mpDoc) );
543 else
544 pNotesPage = mpDoc->AllocSdPage(false);
546 pNotesPage->SetSize( pPreviousNotesPage->GetSize() );
547 pNotesPage->SetBorder( pPreviousNotesPage->GetLeftBorder(),
548 pPreviousNotesPage->GetUpperBorder(),
549 pPreviousNotesPage->GetRightBorder(),
550 pPreviousNotesPage->GetLowerBorder() );
551 pNotesPage->SetOrientation( pPreviousNotesPage->GetOrientation() );
552 pNotesPage->SetName(OUString());
553 pNotesPage->SetPageKind(PageKind::Notes);
555 // insert page after current page
556 mpDoc->InsertPage(pNotesPage, nNotesPageNum);
558 if( !bDuplicate )
560 // use MasterPage of the current page
561 pNotesPage->TRG_SetMasterPage(pPreviousNotesPage->TRG_GetMasterPage());
562 pNotesPage->SetLayoutName( pPreviousNotesPage->GetLayoutName() );
563 pNotesPage->SetAutoLayout(AUTOLAYOUT_NOTES, true );
567 SetModified();
569 return pStandardPage;
572 void SdXImpressDocument::SetModified() throw()
574 if( mpDoc )
575 mpDoc->SetChanged();
578 // XModel
579 void SAL_CALL SdXImpressDocument::lockControllers( )
581 ::SolarMutexGuard aGuard;
583 if( nullptr == mpDoc )
584 throw lang::DisposedException();
586 mpDoc->setLock(true);
589 void SAL_CALL SdXImpressDocument::unlockControllers( )
591 ::SolarMutexGuard aGuard;
593 if( nullptr == mpDoc )
594 throw lang::DisposedException();
596 if( mpDoc->isLocked() )
598 mpDoc->setLock(false);
602 sal_Bool SAL_CALL SdXImpressDocument::hasControllersLocked( )
604 ::SolarMutexGuard aGuard;
606 if( nullptr == mpDoc )
607 throw lang::DisposedException();
609 return mpDoc->isLocked();
612 uno::Reference < container::XIndexAccess > SAL_CALL SdXImpressDocument::getViewData()
614 ::SolarMutexGuard aGuard;
616 if( nullptr == mpDoc )
617 throw lang::DisposedException();
619 uno::Reference < container::XIndexAccess > xRet( SfxBaseModel::getViewData() );
621 if( !xRet.is() )
623 const std::vector<std::unique_ptr<sd::FrameView>> &rList = mpDoc->GetFrameViewList();
625 if( !rList.empty() )
627 xRet.set(document::IndexedPropertyValues::create( ::comphelper::getProcessComponentContext() ), uno::UNO_QUERY);
629 uno::Reference < container::XIndexContainer > xCont( xRet, uno::UNO_QUERY );
630 DBG_ASSERT( xCont.is(), "SdXImpressDocument::getViewData() failed for OLE object" );
631 if( xCont.is() )
633 for( sal_uInt32 i = 0, n = rList.size(); i < n; i++ )
635 ::sd::FrameView* pFrameView = rList[ i ].get();
637 uno::Sequence< beans::PropertyValue > aSeq;
638 pFrameView->WriteUserDataSequence( aSeq );
639 xCont->insertByIndex( i, uno::makeAny( aSeq ) );
645 return xRet;
648 void SAL_CALL SdXImpressDocument::setViewData( const uno::Reference < container::XIndexAccess >& xData )
650 ::SolarMutexGuard aGuard;
652 if( nullptr == mpDoc )
653 throw lang::DisposedException();
655 SfxBaseModel::setViewData( xData );
656 if( !(mpDocShell && (mpDocShell->GetCreateMode() == SfxObjectCreateMode::EMBEDDED) && xData.is()) )
657 return;
659 const sal_Int32 nCount = xData->getCount();
661 std::vector<std::unique_ptr<sd::FrameView>> &rViews = mpDoc->GetFrameViewList();
663 rViews.clear();
665 uno::Sequence< beans::PropertyValue > aSeq;
666 for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
668 if( xData->getByIndex( nIndex ) >>= aSeq )
670 std::unique_ptr<::sd::FrameView> pFrameView(new ::sd::FrameView( mpDoc ));
671 pFrameView->ReadUserDataSequence( aSeq );
672 rViews.push_back( std::move(pFrameView) );
677 // XDrawPageDuplicator
678 uno::Reference< drawing::XDrawPage > SAL_CALL SdXImpressDocument::duplicate( const uno::Reference< drawing::XDrawPage >& xPage )
680 ::SolarMutexGuard aGuard;
682 if( nullptr == mpDoc )
683 throw lang::DisposedException();
685 // get pPage from xPage and determine the Id (nPos ) afterwards
686 SvxDrawPage* pSvxPage = SvxDrawPage::getImplementation( xPage );
687 if( pSvxPage )
689 SdPage* pPage = static_cast<SdPage*>( pSvxPage->GetSdrPage() );
690 sal_uInt16 nPos = pPage->GetPageNum();
691 nPos = ( nPos - 1 ) / 2;
692 pPage = InsertSdPage( nPos, true );
693 if( pPage )
695 uno::Reference< drawing::XDrawPage > xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY );
696 return xDrawPage;
700 uno::Reference< drawing::XDrawPage > xDrawPage;
701 return xDrawPage;
704 // XDrawPagesSupplier
705 uno::Reference< drawing::XDrawPages > SAL_CALL SdXImpressDocument::getDrawPages()
707 ::SolarMutexGuard aGuard;
709 if( nullptr == mpDoc )
710 throw lang::DisposedException();
712 uno::Reference< drawing::XDrawPages > xDrawPages( mxDrawPagesAccess );
714 if( !xDrawPages.is() )
716 initializeDocument();
717 mxDrawPagesAccess = xDrawPages = new SdDrawPagesAccess(*this);
720 return xDrawPages;
723 // XMasterPagesSupplier
724 uno::Reference< drawing::XDrawPages > SAL_CALL SdXImpressDocument::getMasterPages()
726 ::SolarMutexGuard aGuard;
728 if( nullptr == mpDoc )
729 throw lang::DisposedException();
731 uno::Reference< drawing::XDrawPages > xMasterPages( mxMasterPagesAccess );
733 if( !xMasterPages.is() )
735 if ( !hasControllersLocked() )
736 initializeDocument();
737 mxMasterPagesAccess = xMasterPages = new SdMasterPagesAccess(*this);
740 return xMasterPages;
743 // XLayerManagerSupplier
744 uno::Reference< container::XNameAccess > SAL_CALL SdXImpressDocument::getLayerManager( )
746 ::SolarMutexGuard aGuard;
748 if( nullptr == mpDoc )
749 throw lang::DisposedException();
751 uno::Reference< container::XNameAccess > xLayerManager( mxLayerManager );
753 if( !xLayerManager.is() )
754 mxLayerManager = xLayerManager = new SdLayerManager(*this);
756 return xLayerManager;
759 // XCustomPresentationSupplier
760 uno::Reference< container::XNameContainer > SAL_CALL SdXImpressDocument::getCustomPresentations()
762 ::SolarMutexGuard aGuard;
764 if( nullptr == mpDoc )
765 throw lang::DisposedException();
767 uno::Reference< container::XNameContainer > xCustomPres( mxCustomPresentationAccess );
769 if( !xCustomPres.is() )
770 mxCustomPresentationAccess = xCustomPres = new SdXCustomPresentationAccess(*this);
772 return xCustomPres;
775 // XPresentationSupplier
776 uno::Reference< presentation::XPresentation > SAL_CALL SdXImpressDocument::getPresentation()
778 ::SolarMutexGuard aGuard;
780 if( nullptr == mpDoc )
781 throw lang::DisposedException();
783 return uno::Reference< presentation::XPresentation >( mpDoc->getPresentation().get() );
786 // XHandoutMasterSupplier
787 uno::Reference< drawing::XDrawPage > SAL_CALL SdXImpressDocument::getHandoutMasterPage()
789 ::SolarMutexGuard aGuard;
791 if( nullptr == mpDoc )
792 throw lang::DisposedException();
794 uno::Reference< drawing::XDrawPage > xPage;
796 initializeDocument();
797 SdPage* pPage = mpDoc->GetMasterSdPage(0, PageKind::Handout);
798 if (pPage)
799 xPage.set(pPage->getUnoPage(), uno::UNO_QUERY);
800 return xPage;
803 // XMultiServiceFactory ( SvxFmMSFactory )
805 css::uno::Reference<css::uno::XInterface> SdXImpressDocument::create(
806 OUString const & aServiceSpecifier, OUString const & referer)
808 ::SolarMutexGuard aGuard;
810 if( nullptr == mpDoc )
811 throw lang::DisposedException();
813 if( aServiceSpecifier == "com.sun.star.drawing.DashTable" )
815 if( !mxDashTable.is() )
816 mxDashTable = SvxUnoDashTable_createInstance( mpDoc );
818 return mxDashTable;
820 if( aServiceSpecifier == "com.sun.star.drawing.GradientTable" )
822 if( !mxGradientTable.is() )
823 mxGradientTable = SvxUnoGradientTable_createInstance( mpDoc );
825 return mxGradientTable;
827 if( aServiceSpecifier == "com.sun.star.drawing.HatchTable" )
829 if( !mxHatchTable.is() )
830 mxHatchTable = SvxUnoHatchTable_createInstance( mpDoc );
832 return mxHatchTable;
834 if( aServiceSpecifier == "com.sun.star.drawing.BitmapTable" )
836 if( !mxBitmapTable.is() )
837 mxBitmapTable = SvxUnoBitmapTable_createInstance( mpDoc );
839 return mxBitmapTable;
841 if( aServiceSpecifier == "com.sun.star.drawing.TransparencyGradientTable" )
843 if( !mxTransGradientTable.is() )
844 mxTransGradientTable = SvxUnoTransGradientTable_createInstance( mpDoc );
846 return mxTransGradientTable;
848 if( aServiceSpecifier == "com.sun.star.drawing.MarkerTable" )
850 if( !mxMarkerTable.is() )
851 mxMarkerTable = SvxUnoMarkerTable_createInstance( mpDoc );
853 return mxMarkerTable;
855 if( aServiceSpecifier == "com.sun.star.text.NumberingRules" )
857 return uno::Reference< uno::XInterface >( SvxCreateNumRule( mpDoc ), uno::UNO_QUERY );
859 if( aServiceSpecifier == "com.sun.star.drawing.Background" )
861 return uno::Reference< uno::XInterface >(
862 static_cast<uno::XWeak*>(new SdUnoPageBackground( mpDoc )));
865 if( aServiceSpecifier == "com.sun.star.drawing.Defaults" )
867 if( !mxDrawingPool.is() )
868 mxDrawingPool = SdUnoCreatePool( mpDoc );
870 return mxDrawingPool;
874 if ( aServiceSpecifier == sUNO_Service_ImageMapRectangleObject )
876 return SvUnoImageMapRectangleObject_createInstance( ImplGetSupportedMacroItems() );
879 if ( aServiceSpecifier == sUNO_Service_ImageMapCircleObject )
881 return SvUnoImageMapCircleObject_createInstance( ImplGetSupportedMacroItems() );
884 if ( aServiceSpecifier == sUNO_Service_ImageMapPolygonObject )
886 return SvUnoImageMapPolygonObject_createInstance( ImplGetSupportedMacroItems() );
889 if( aServiceSpecifier == "com.sun.star.document.Settings" ||
890 ( !mbImpressDoc && ( aServiceSpecifier == "com.sun.star.drawing.DocumentSettings" ) ) ||
891 ( mbImpressDoc && ( aServiceSpecifier == "com.sun.star.presentation.DocumentSettings" ) ) )
893 return sd::DocumentSettings_createInstance( this );
896 if( aServiceSpecifier == "com.sun.star.text.TextField.DateTime" ||
897 aServiceSpecifier == "com.sun.star.text.textfield.DateTime" )
899 return static_cast<cppu::OWeakObject *>(new SvxUnoTextField( text::textfield::Type::DATE ));
902 if( aServiceSpecifier == "com.sun.star.presentation.TextField.Header" ||
903 aServiceSpecifier == "com.sun.star.presentation.textfield.Header" )
905 return static_cast<cppu::OWeakObject *>(new SvxUnoTextField( text::textfield::Type::PRESENTATION_HEADER ));
908 if( aServiceSpecifier == "com.sun.star.presentation.TextField.Footer" ||
909 aServiceSpecifier == "com.sun.star.presentation.textfield.Footer" )
911 return static_cast<cppu::OWeakObject *>(new SvxUnoTextField( text::textfield::Type::PRESENTATION_FOOTER ));
914 if( aServiceSpecifier == "com.sun.star.presentation.TextField.DateTime" ||
915 aServiceSpecifier == "com.sun.star.presentation.textfield.DateTime" )
917 return static_cast<cppu::OWeakObject *>(new SvxUnoTextField( text::textfield::Type::PRESENTATION_DATE_TIME ));
920 if( aServiceSpecifier == "com.sun.star.text.TextField.PageName" ||
921 aServiceSpecifier == "com.sun.star.text.textfield.PageName" )
923 return static_cast<cppu::OWeakObject *>(new SvxUnoTextField( text::textfield::Type::PAGE_NAME ));
926 if (aServiceSpecifier == "com.sun.star.text.TextField.DocInfo.Custom" ||
927 aServiceSpecifier == "com.sun.star.text.textfield.DocInfo.Custom")
929 return static_cast<cppu::OWeakObject *>(new SvxUnoTextField(text::textfield::Type::DOCINFO_CUSTOM));
932 if( aServiceSpecifier == "com.sun.star.xml.NamespaceMap" )
934 static sal_uInt16 aWhichIds[] = { SDRATTR_XMLATTRIBUTES, EE_CHAR_XMLATTRIBS, EE_PARA_XMLATTRIBS, 0 };
936 return svx::NamespaceMap_createInstance( aWhichIds, &mpDoc->GetItemPool() );
939 // Support creation of GraphicStorageHandler and EmbeddedObjectResolver
940 if (aServiceSpecifier == "com.sun.star.document.ExportGraphicStorageHandler")
942 return static_cast<cppu::OWeakObject *>(new SvXMLGraphicHelper( SvXMLGraphicHelperMode::Write ));
945 if (aServiceSpecifier == "com.sun.star.document.ImportGraphicStorageHandler")
947 return static_cast<cppu::OWeakObject *>(new SvXMLGraphicHelper( SvXMLGraphicHelperMode::Read ));
950 if( aServiceSpecifier == "com.sun.star.document.ExportEmbeddedObjectResolver" )
952 comphelper::IEmbeddedHelper* pPersist = mpDoc->GetPersist();
953 if( nullptr == pPersist )
954 throw lang::DisposedException();
956 return static_cast<cppu::OWeakObject *>(new SvXMLEmbeddedObjectHelper( *pPersist, SvXMLEmbeddedObjectHelperMode::Write ));
959 if( aServiceSpecifier == "com.sun.star.document.ImportEmbeddedObjectResolver" )
961 comphelper::IEmbeddedHelper* pPersist = mpDoc->GetPersist();
962 if( nullptr == pPersist )
963 throw lang::DisposedException();
965 return static_cast<cppu::OWeakObject *>(new SvXMLEmbeddedObjectHelper( *pPersist, SvXMLEmbeddedObjectHelperMode::Read ));
968 uno::Reference< uno::XInterface > xRet;
970 if( aServiceSpecifier.startsWith( "com.sun.star.presentation.") )
972 const OUString aType( aServiceSpecifier.copy(26) );
973 SvxShape* pShape = nullptr;
975 sal_uInt16 nType = OBJ_TEXT;
976 // create a shape wrapper
977 if( aType.startsWith( "TitleTextShape" ) )
979 nType = OBJ_TEXT;
981 else if( aType.startsWith( "OutlinerShape" ) )
983 nType = OBJ_TEXT;
985 else if( aType.startsWith( "SubtitleShape" ) )
987 nType = OBJ_TEXT;
989 else if( aType.startsWith( "GraphicObjectShape" ) )
991 nType = OBJ_GRAF;
993 else if( aType.startsWith( "PageShape" ) )
995 nType = OBJ_PAGE;
997 else if( aType.startsWith( "OLE2Shape" ) )
999 nType = OBJ_OLE2;
1001 else if( aType.startsWith( "ChartShape" ) )
1003 nType = OBJ_OLE2;
1005 else if( aType.startsWith( "CalcShape" ) )
1007 nType = OBJ_OLE2;
1009 else if( aType.startsWith( "TableShape" ) )
1011 nType = OBJ_TABLE;
1013 else if( aType.startsWith( "OrgChartShape" ) )
1015 nType = OBJ_OLE2;
1017 else if( aType.startsWith( "NotesShape" ) )
1019 nType = OBJ_TEXT;
1021 else if( aType.startsWith( "HandoutShape" ) )
1023 nType = OBJ_PAGE;
1025 else if( aType.startsWith( "FooterShape" ) )
1027 nType = OBJ_TEXT;
1029 else if( aType.startsWith( "HeaderShape" ) )
1031 nType = OBJ_TEXT;
1033 else if( aType.startsWith( "SlideNumberShape" ) )
1035 nType = OBJ_TEXT;
1037 else if( aType.startsWith( "DateTimeShape" ) )
1039 nType = OBJ_TEXT;
1041 else if( aType.startsWith( "MediaShape" ) )
1043 nType = OBJ_MEDIA;
1045 else
1047 throw lang::ServiceNotRegisteredException();
1050 // create the API wrapper
1051 pShape = CreateSvxShapeByTypeAndInventor( nType, SdrInventor::Default, referer );
1053 // set shape type
1054 if( pShape && !mbClipBoard )
1055 pShape->SetShapeType(aServiceSpecifier);
1057 xRet = static_cast<uno::XWeak*>(pShape);
1059 else if ( aServiceSpecifier == "com.sun.star.drawing.TableShape" )
1061 SvxShape* pShape = CreateSvxShapeByTypeAndInventor( OBJ_TABLE, SdrInventor::Default, referer );
1062 if( pShape && !mbClipBoard )
1063 pShape->SetShapeType(aServiceSpecifier);
1065 xRet = static_cast<uno::XWeak*>(pShape);
1067 else
1069 xRet = SvxFmMSFactory::createInstance( aServiceSpecifier );
1072 uno::Reference< drawing::XShape > xShape( xRet, uno::UNO_QUERY );
1073 SvxShape* pShape = xShape.is() ? SvxShape::getImplementation(xShape) : nullptr;
1074 if (pShape)
1076 xRet.clear();
1077 new SdXShape( pShape, this );
1078 xRet = xShape;
1079 xShape.clear();
1082 return xRet;
1085 uno::Reference< uno::XInterface > SAL_CALL SdXImpressDocument::createInstance( const OUString& aServiceSpecifier )
1087 return create(aServiceSpecifier, "");
1090 css::uno::Reference<css::uno::XInterface>
1091 SdXImpressDocument::createInstanceWithArguments(
1092 OUString const & ServiceSpecifier,
1093 css::uno::Sequence<css::uno::Any> const & Arguments)
1095 OUString arg;
1096 if ((ServiceSpecifier == "com.sun.star.drawing.GraphicObjectShape"
1097 || ServiceSpecifier == "com.sun.star.drawing.MediaShape"
1098 || ServiceSpecifier == "com.sun.star.presentation.MediaShape")
1099 && Arguments.getLength() == 1 && (Arguments[0] >>= arg))
1101 return create(ServiceSpecifier, arg);
1103 return SvxFmMSFactory::createInstanceWithArguments(
1104 ServiceSpecifier, Arguments);
1107 uno::Sequence< OUString > SAL_CALL SdXImpressDocument::getAvailableServiceNames()
1109 ::SolarMutexGuard aGuard;
1111 if( nullptr == mpDoc )
1112 throw lang::DisposedException();
1114 const uno::Sequence< OUString > aSNS_ORG( SvxFmMSFactory::getAvailableServiceNames() );
1116 uno::Sequence< OUString > aSNS( mbImpressDoc ? 36 : 19 );
1118 sal_uInt16 i(0);
1120 aSNS[i++] = "com.sun.star.drawing.DashTable";
1121 aSNS[i++] = "com.sun.star.drawing.GradientTable";
1122 aSNS[i++] = "com.sun.star.drawing.HatchTable";
1123 aSNS[i++] = "com.sun.star.drawing.BitmapTable";
1124 aSNS[i++] = "com.sun.star.drawing.TransparencyGradientTable";
1125 aSNS[i++] = "com.sun.star.drawing.MarkerTable";
1126 aSNS[i++] = "com.sun.star.text.NumberingRules";
1127 aSNS[i++] = "com.sun.star.drawing.Background";
1128 aSNS[i++] = "com.sun.star.document.Settings";
1129 aSNS[i++] = sUNO_Service_ImageMapRectangleObject;
1130 aSNS[i++] = sUNO_Service_ImageMapCircleObject;
1131 aSNS[i++] = sUNO_Service_ImageMapPolygonObject;
1132 aSNS[i++] = "com.sun.star.xml.NamespaceMap";
1134 // Support creation of GraphicStorageHandler and EmbeddedObjectResolver
1135 aSNS[i++] = "com.sun.star.document.ExportGraphicStorageHandler";
1136 aSNS[i++] = "com.sun.star.document.ImportGraphicStorageHandler";
1137 aSNS[i++] = "com.sun.star.document.ExportEmbeddedObjectResolver";
1138 aSNS[i++] = "com.sun.star.document.ImportEmbeddedObjectResolver";
1139 aSNS[i++] = "com.sun.star.drawing.TableShape";
1141 if(mbImpressDoc)
1143 aSNS[i++] = "com.sun.star.presentation.TitleTextShape";
1144 aSNS[i++] = "com.sun.star.presentation.OutlinerShape";
1145 aSNS[i++] = "com.sun.star.presentation.SubtitleShape";
1146 aSNS[i++] = "com.sun.star.presentation.GraphicObjectShape";
1147 aSNS[i++] = "com.sun.star.presentation.ChartShape";
1148 aSNS[i++] = "com.sun.star.presentation.PageShape";
1149 aSNS[i++] = "com.sun.star.presentation.OLE2Shape";
1150 aSNS[i++] = "com.sun.star.presentation.TableShape";
1151 aSNS[i++] = "com.sun.star.presentation.OrgChartShape";
1152 aSNS[i++] = "com.sun.star.presentation.NotesShape";
1153 aSNS[i++] = "com.sun.star.presentation.HandoutShape";
1154 aSNS[i++] = "com.sun.star.presentation.DocumentSettings";
1155 aSNS[i++] = "com.sun.star.presentation.FooterShape";
1156 aSNS[i++] = "com.sun.star.presentation.HeaderShape";
1157 aSNS[i++] = "com.sun.star.presentation.SlideNumberShape";
1158 aSNS[i++] = "com.sun.star.presentation.DateTimeShape";
1159 aSNS[i++] = "com.sun.star.presentation.CalcShape";
1160 aSNS[i++] = "com.sun.star.presentation.MediaShape";
1162 else
1164 aSNS[i++] = "com.sun.star.drawing.DocumentSettings";
1167 DBG_ASSERT( i == aSNS.getLength(), "Sequence overrun!" );
1169 return comphelper::concatSequences( aSNS_ORG, aSNS );
1172 // lang::XServiceInfo
1173 OUString SAL_CALL SdXImpressDocument::getImplementationName()
1175 return OUString( "SdXImpressDocument" );
1176 /* // Matching the .component information:
1177 return mbImpressDoc
1178 ? OUString("com.sun.star.comp.Draw.PresentationDocument")
1179 : OUString("com.sun.star.comp.Draw.DrawingDocument");
1183 sal_Bool SAL_CALL SdXImpressDocument::supportsService( const OUString& ServiceName )
1185 return cppu::supportsService(this, ServiceName);
1188 uno::Sequence< OUString > SAL_CALL SdXImpressDocument::getSupportedServiceNames()
1190 ::SolarMutexGuard aGuard;
1192 uno::Sequence< OUString > aSeq( 4 );
1193 OUString* pServices = aSeq.getArray();
1195 *pServices++ = "com.sun.star.document.OfficeDocument";
1196 *pServices++ = "com.sun.star.drawing.GenericDrawingDocument";
1197 *pServices++ = "com.sun.star.drawing.DrawingDocumentFactory";
1199 if( mbImpressDoc )
1200 *pServices++ = "com.sun.star.presentation.PresentationDocument";
1201 else
1202 *pServices++ = "com.sun.star.drawing.DrawingDocument";
1204 return aSeq;
1207 // XPropertySet
1208 uno::Reference< beans::XPropertySetInfo > SAL_CALL SdXImpressDocument::getPropertySetInfo( )
1210 ::SolarMutexGuard aGuard;
1211 return mpPropSet->getPropertySetInfo();
1214 void SAL_CALL SdXImpressDocument::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
1216 ::SolarMutexGuard aGuard;
1218 if( nullptr == mpDoc )
1219 throw lang::DisposedException();
1221 const SfxItemPropertySimpleEntry* pEntry = mpPropSet->getPropertyMapEntry(aPropertyName);
1223 switch( pEntry ? pEntry->nWID : -1 )
1225 case WID_MODEL_LANGUAGE:
1227 lang::Locale aLocale;
1228 if(!(aValue >>= aLocale))
1229 throw lang::IllegalArgumentException();
1231 mpDoc->SetLanguage( LanguageTag::convertToLanguageType(aLocale), EE_CHAR_LANGUAGE );
1232 break;
1234 case WID_MODEL_TABSTOP:
1236 sal_Int32 nValue = 0;
1237 if(!(aValue >>= nValue) || nValue < 0 )
1238 throw lang::IllegalArgumentException();
1240 mpDoc->SetDefaultTabulator(static_cast<sal_uInt16>(nValue));
1241 break;
1243 case WID_MODEL_VISAREA:
1245 SfxObjectShell* pEmbeddedObj = mpDoc->GetDocSh();
1246 if( !pEmbeddedObj )
1247 break;
1249 awt::Rectangle aVisArea;
1250 if( !(aValue >>= aVisArea) || (aVisArea.Width < 0) || (aVisArea.Height < 0) )
1251 throw lang::IllegalArgumentException();
1253 sal_Int32 nRight, nTop;
1254 if (o3tl::checked_add(aVisArea.X, aVisArea.Width, nRight) || o3tl::checked_add(aVisArea.Y, aVisArea.Height, nTop))
1255 throw lang::IllegalArgumentException();
1257 pEmbeddedObj->SetVisArea(::tools::Rectangle(aVisArea.X, aVisArea.Y, nRight, nTop));
1259 break;
1260 case WID_MODEL_CONTFOCUS:
1262 bool bFocus = false;
1263 if( !(aValue >>= bFocus ) )
1264 throw lang::IllegalArgumentException();
1265 mpDoc->SetAutoControlFocus( bFocus );
1267 break;
1268 case WID_MODEL_DSGNMODE:
1270 bool bMode = false;
1271 if( !(aValue >>= bMode ) )
1272 throw lang::IllegalArgumentException();
1273 mpDoc->SetOpenInDesignMode( bMode );
1275 break;
1276 case WID_MODEL_BUILDID:
1277 aValue >>= maBuildId;
1278 return;
1279 case WID_MODEL_MAPUNIT:
1280 case WID_MODEL_BASICLIBS:
1281 case WID_MODEL_RUNTIMEUID: // is read-only
1282 case WID_MODEL_DIALOGLIBS:
1283 case WID_MODEL_FONTS:
1284 throw beans::PropertyVetoException();
1285 case WID_MODEL_INTEROPGRABBAG:
1286 setGrabBagItem(aValue);
1287 break;
1288 default:
1289 throw beans::UnknownPropertyException( aPropertyName, static_cast<cppu::OWeakObject*>(this));
1292 SetModified();
1295 uno::Any SAL_CALL SdXImpressDocument::getPropertyValue( const OUString& PropertyName )
1297 ::SolarMutexGuard aGuard;
1299 uno::Any aAny;
1300 if( nullptr == mpDoc )
1301 throw lang::DisposedException();
1303 const SfxItemPropertySimpleEntry* pEntry = mpPropSet->getPropertyMapEntry(PropertyName);
1305 switch( pEntry ? pEntry->nWID : -1 )
1307 case WID_MODEL_LANGUAGE:
1309 LanguageType eLang = mpDoc->GetLanguage( EE_CHAR_LANGUAGE );
1310 aAny <<= LanguageTag::convertToLocale( eLang);
1311 break;
1313 case WID_MODEL_TABSTOP:
1314 aAny <<= static_cast<sal_Int32>(mpDoc->GetDefaultTabulator());
1315 break;
1316 case WID_MODEL_VISAREA:
1318 SfxObjectShell* pEmbeddedObj = mpDoc->GetDocSh();
1319 if( !pEmbeddedObj )
1320 break;
1322 const ::tools::Rectangle& aRect = pEmbeddedObj->GetVisArea();
1323 awt::Rectangle aVisArea( aRect.Left(), aRect.Top(), aRect.getWidth(), aRect.getHeight() );
1324 aAny <<= aVisArea;
1326 break;
1327 case WID_MODEL_MAPUNIT:
1329 SfxObjectShell* pEmbeddedObj = mpDoc->GetDocSh();
1330 if( !pEmbeddedObj )
1331 break;
1333 sal_Int16 nMeasureUnit = 0;
1334 SvxMapUnitToMeasureUnit( pEmbeddedObj->GetMapUnit(), nMeasureUnit );
1335 aAny <<= nMeasureUnit;
1337 break;
1338 case WID_MODEL_FORBCHARS:
1340 aAny <<= getForbiddenCharsTable();
1342 break;
1343 case WID_MODEL_CONTFOCUS:
1344 aAny <<= mpDoc->GetAutoControlFocus();
1345 break;
1346 case WID_MODEL_DSGNMODE:
1347 aAny <<= mpDoc->GetOpenInDesignMode();
1348 break;
1349 case WID_MODEL_BASICLIBS:
1350 aAny <<= mpDocShell->GetBasicContainer();
1351 break;
1352 case WID_MODEL_DIALOGLIBS:
1353 aAny <<= mpDocShell->GetDialogContainer();
1354 break;
1355 case WID_MODEL_RUNTIMEUID:
1356 aAny <<= getRuntimeUID();
1357 break;
1358 case WID_MODEL_BUILDID:
1359 return uno::Any( maBuildId );
1360 case WID_MODEL_HASVALIDSIGNATURES:
1361 aAny <<= hasValidSignatures();
1362 break;
1363 case WID_MODEL_FONTS:
1365 uno::Sequence<uno::Any> aSeq;
1366 int nSeqIndex = 0;
1368 sal_uInt16 const aWhichIds[] { EE_CHAR_FONTINFO, EE_CHAR_FONTINFO_CJK,
1369 EE_CHAR_FONTINFO_CTL };
1371 const SfxItemPool& rPool = mpDoc->GetPool();
1373 for(sal_uInt16 nWhichId : aWhichIds)
1375 sal_uInt32 nItems = rPool.GetItemCount2( nWhichId );
1377 aSeq.realloc( aSeq.getLength() + nItems*5 + 5 );
1379 for (const SfxPoolItem* pItem : rPool.GetItemSurrogates(nWhichId))
1381 const SvxFontItem *pFont = static_cast<const SvxFontItem *>(pItem);
1383 aSeq[nSeqIndex++] <<= pFont->GetFamilyName();
1384 aSeq[nSeqIndex++] <<= pFont->GetStyleName();
1385 aSeq[nSeqIndex++] <<= sal_Int16(pFont->GetFamily());
1386 aSeq[nSeqIndex++] <<= sal_Int16(pFont->GetPitch());
1387 aSeq[nSeqIndex++] <<= sal_Int16(pFont->GetCharSet());
1390 const SvxFontItem& rFont = static_cast<const SvxFontItem&>(rPool.GetDefaultItem( nWhichId ));
1392 aSeq[nSeqIndex++] <<= rFont.GetFamilyName();
1393 aSeq[nSeqIndex++] <<= rFont.GetStyleName();
1394 aSeq[nSeqIndex++] <<= sal_Int16(rFont.GetFamily());
1395 aSeq[nSeqIndex++] <<= sal_Int16(rFont.GetPitch());
1396 aSeq[nSeqIndex++] <<= sal_Int16(rFont.GetCharSet());
1400 aSeq.realloc( nSeqIndex );
1401 aAny <<= aSeq;
1402 break;
1404 case WID_MODEL_INTEROPGRABBAG:
1405 getGrabBagItem(aAny);
1406 break;
1407 default:
1408 throw beans::UnknownPropertyException( PropertyName, static_cast<cppu::OWeakObject*>(this));
1411 return aAny;
1414 void SAL_CALL SdXImpressDocument::addPropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) {}
1415 void SAL_CALL SdXImpressDocument::removePropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) {}
1416 void SAL_CALL SdXImpressDocument::addVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) {}
1417 void SAL_CALL SdXImpressDocument::removeVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) {}
1419 // XLinkTargetSupplier
1420 uno::Reference< container::XNameAccess > SAL_CALL SdXImpressDocument::getLinks()
1422 ::SolarMutexGuard aGuard;
1424 if( nullptr == mpDoc )
1425 throw lang::DisposedException();
1427 uno::Reference< container::XNameAccess > xLinks( mxLinks );
1428 if( !xLinks.is() )
1429 mxLinks = xLinks = new SdDocLinkTargets( *this );
1430 return xLinks;
1433 // XStyleFamiliesSupplier
1434 uno::Reference< container::XNameAccess > SAL_CALL SdXImpressDocument::getStyleFamilies( )
1436 ::SolarMutexGuard aGuard;
1438 if( nullptr == mpDoc )
1439 throw lang::DisposedException();
1441 uno::Reference< container::XNameAccess > xStyles( dynamic_cast< container::XNameAccess* >( mpDoc->GetStyleSheetPool()) );
1442 return xStyles;
1445 // XAnyCompareFactory
1446 uno::Reference< css::ucb::XAnyCompare > SAL_CALL SdXImpressDocument::createAnyCompareByName( const OUString& )
1448 return SvxCreateNumRuleCompare();
1451 // XRenderable
1452 sal_Int32 SAL_CALL SdXImpressDocument::getRendererCount( const uno::Any& rSelection,
1453 const uno::Sequence< beans::PropertyValue >& )
1455 ::SolarMutexGuard aGuard;
1456 sal_Int32 nRet = 0;
1458 if( nullptr == mpDoc )
1459 throw lang::DisposedException();
1461 if (mpDocShell)
1463 uno::Reference< frame::XModel > xModel;
1465 rSelection >>= xModel;
1467 if( xModel == mpDocShell->GetModel() )
1468 nRet = mpDoc->GetSdPageCount( PageKind::Standard );
1469 else
1471 uno::Reference< drawing::XShapes > xShapes;
1473 rSelection >>= xShapes;
1475 if( xShapes.is() && xShapes->getCount() )
1476 nRet = 1;
1479 return nRet;
1482 uno::Sequence< beans::PropertyValue > SAL_CALL SdXImpressDocument::getRenderer( sal_Int32 , const uno::Any& ,
1483 const uno::Sequence< beans::PropertyValue >& rxOptions )
1485 ::SolarMutexGuard aGuard;
1487 if( nullptr == mpDoc )
1488 throw lang::DisposedException();
1490 bool bExportNotesPages = false;
1491 for( sal_Int32 nProperty = 0, nPropertyCount = rxOptions.getLength(); nProperty < nPropertyCount; ++nProperty )
1493 if ( rxOptions[ nProperty ].Name == "ExportNotesPages" )
1494 rxOptions[ nProperty].Value >>= bExportNotesPages;
1496 uno::Sequence< beans::PropertyValue > aRenderer;
1497 if (mpDocShell)
1499 awt::Size aPageSize;
1500 if ( bExportNotesPages )
1502 Size aNotesPageSize = mpDoc->GetSdPage( 0, PageKind::Notes )->GetSize();
1503 aPageSize = awt::Size( aNotesPageSize.Width(), aNotesPageSize.Height() );
1505 else
1507 const ::tools::Rectangle aVisArea( mpDocShell->GetVisArea( embed::Aspects::MSOLE_DOCPRINT ) );
1508 aPageSize = awt::Size( aVisArea.GetWidth(), aVisArea.GetHeight() );
1510 aRenderer.realloc( 1 );
1512 aRenderer[ 0 ].Name = "PageSize" ;
1513 aRenderer[ 0 ].Value <<= aPageSize;
1515 return aRenderer;
1518 class ImplRenderPaintProc : public sdr::contact::ViewObjectContactRedirector
1520 const SdrLayerAdmin& rLayerAdmin;
1521 SdrPageView* const pSdrPageView;
1522 vcl::PDFExtOutDevData* const pPDFExtOutDevData;
1524 vcl::PDFWriter::StructElement ImplBegStructureTag( SdrObject& rObject );
1526 public:
1527 bool IsVisible ( const SdrObject* pObj ) const;
1528 bool IsPrintable( const SdrObject* pObj ) const;
1530 ImplRenderPaintProc( const SdrLayerAdmin& rLA, SdrPageView* pView, vcl::PDFExtOutDevData* pData );
1532 // all default implementations just call the same methods at the original. To do something
1533 // different, override the method and at least do what the method does.
1534 virtual drawinglayer::primitive2d::Primitive2DContainer createRedirectedPrimitive2DSequence(
1535 const sdr::contact::ViewObjectContact& rOriginal,
1536 const sdr::contact::DisplayInfo& rDisplayInfo) override;
1539 ImplRenderPaintProc::ImplRenderPaintProc( const SdrLayerAdmin& rLA, SdrPageView* pView, vcl::PDFExtOutDevData* pData )
1540 : ViewObjectContactRedirector(),
1541 rLayerAdmin ( rLA ),
1542 pSdrPageView ( pView ),
1543 pPDFExtOutDevData ( pData )
1547 static sal_Int32 ImplPDFGetBookmarkPage( const OUString& rBookmark, SdDrawDocument const & rDoc )
1549 sal_Int32 nPage = -1;
1551 OUString aBookmark( rBookmark );
1553 if( rBookmark.startsWith("#") )
1554 aBookmark = rBookmark.copy( 1 );
1556 // is the bookmark a page ?
1557 bool bIsMasterPage;
1558 sal_uInt16 nPgNum = rDoc.GetPageByName( aBookmark, bIsMasterPage );
1559 SdrObject* pObj = nullptr;
1561 if ( nPgNum == SDRPAGE_NOTFOUND )
1563 // is the bookmark a object ?
1564 pObj = rDoc.GetObj( aBookmark );
1565 if (pObj)
1566 nPgNum = pObj->getSdrPageFromSdrObject()->GetPageNum();
1568 if ( nPgNum != SDRPAGE_NOTFOUND )
1569 nPage = ( nPgNum - 1 ) / 2;
1570 return nPage;
1573 static void ImplPDFExportComments( const uno::Reference< drawing::XDrawPage >& xPage, vcl::PDFExtOutDevData& rPDFExtOutDevData )
1577 uno::Reference< office::XAnnotationAccess > xAnnotationAccess( xPage, uno::UNO_QUERY_THROW );
1578 uno::Reference< office::XAnnotationEnumeration > xAnnotationEnumeration( xAnnotationAccess->createAnnotationEnumeration() );
1580 LanguageType eLanguage = Application::GetSettings().GetLanguageTag().getLanguageType();
1581 while( xAnnotationEnumeration->hasMoreElements() )
1583 uno::Reference< office::XAnnotation > xAnnotation( xAnnotationEnumeration->nextElement() );
1585 geometry::RealPoint2D aRealPoint2D( xAnnotation->getPosition() );
1586 uno::Reference< text::XText > xText( xAnnotation->getTextRange() );
1587 util::DateTime aDateTime( xAnnotation->getDateTime() );
1589 Date aDate( aDateTime.Day, aDateTime.Month, aDateTime.Year );
1590 ::tools::Time aTime( ::tools::Time::EMPTY );
1591 OUString aStr = SvxDateTimeField::GetFormatted( aDate, aTime,
1592 SvxDateFormat::B, SvxTimeFormat::AppDefault,
1593 *(SD_MOD()->GetNumberFormatter()), eLanguage );
1595 vcl::PDFNote aNote;
1596 OUString sTitle( xAnnotation->getAuthor() );
1597 sTitle += ", ";
1598 sTitle += aStr;
1599 aNote.Title = sTitle;
1600 aNote.Contents = xText->getString();
1601 rPDFExtOutDevData.CreateNote( ::tools::Rectangle( Point( static_cast< long >( aRealPoint2D.X * 100 ),
1602 static_cast< long >( aRealPoint2D.Y * 100 ) ), Size( 1000, 1000 ) ), aNote );
1605 catch (const uno::Exception&)
1610 static void ImplPDFExportShapeInteraction( const uno::Reference< drawing::XShape >& xShape, SdDrawDocument& rDoc, vcl::PDFExtOutDevData& rPDFExtOutDevData )
1612 if ( xShape->getShapeType() == "com.sun.star.drawing.GroupShape" )
1614 uno::Reference< container::XIndexAccess > xIndexAccess( xShape, uno::UNO_QUERY );
1615 if ( xIndexAccess.is() )
1617 sal_Int32 i, nCount = xIndexAccess->getCount();
1618 for ( i = 0; i < nCount; i++ )
1620 uno::Reference< drawing::XShape > xSubShape( xIndexAccess->getByIndex( i ), uno::UNO_QUERY );
1621 if ( xSubShape.is() )
1622 ImplPDFExportShapeInteraction( xSubShape, rDoc, rPDFExtOutDevData );
1626 else
1628 uno::Reference< beans::XPropertySet > xShapePropSet( xShape, uno::UNO_QUERY );
1629 if( xShapePropSet.is() )
1631 Size aPageSize( rDoc.GetSdPage( 0, PageKind::Standard )->GetSize() );
1632 Point aPoint( 0, 0 );
1633 ::tools::Rectangle aPageRect( aPoint, aPageSize );
1635 awt::Point aShapePos( xShape->getPosition() );
1636 awt::Size aShapeSize( xShape->getSize() );
1637 ::tools::Rectangle aLinkRect( Point( aShapePos.X, aShapePos.Y ), Size( aShapeSize.Width, aShapeSize.Height ) );
1639 // Handle linked videos.
1640 if (xShape->getShapeType() == "com.sun.star.drawing.MediaShape" || xShape->getShapeType() == "com.sun.star.presentation.MediaShape")
1642 OUString aMediaURL;
1643 xShapePropSet->getPropertyValue("MediaURL") >>= aMediaURL;
1644 if (!aMediaURL.isEmpty())
1646 sal_Int32 nScreenId = rPDFExtOutDevData.CreateScreen(aLinkRect, rPDFExtOutDevData.GetCurrentPageNumber());
1647 if (aMediaURL.startsWith("vnd.sun.star.Package:"))
1649 OUString aTempFileURL;
1650 xShapePropSet->getPropertyValue("PrivateTempFileURL") >>= aTempFileURL;
1651 rPDFExtOutDevData.SetScreenStream(nScreenId, aTempFileURL);
1653 else
1654 rPDFExtOutDevData.SetScreenURL(nScreenId, aMediaURL);
1658 presentation::ClickAction eCa;
1659 uno::Any aAny( xShapePropSet->getPropertyValue( "OnClick" ) );
1660 if ( aAny >>= eCa )
1662 switch ( eCa )
1664 case presentation::ClickAction_LASTPAGE :
1666 sal_Int32 nCount = rDoc.GetSdPageCount( PageKind::Standard );
1667 sal_Int32 nDestId = rPDFExtOutDevData.CreateDest( aPageRect, nCount - 1, vcl::PDFWriter::DestAreaType::FitRectangle );
1668 sal_Int32 nLinkId = rPDFExtOutDevData.CreateLink( aLinkRect );
1669 rPDFExtOutDevData.SetLinkDest( nLinkId, nDestId );
1671 break;
1672 case presentation::ClickAction_FIRSTPAGE :
1674 sal_Int32 nDestId = rPDFExtOutDevData.CreateDest( aPageRect, 0, vcl::PDFWriter::DestAreaType::FitRectangle );
1675 sal_Int32 nLinkId = rPDFExtOutDevData.CreateLink( aLinkRect );
1676 rPDFExtOutDevData.SetLinkDest( nLinkId, nDestId );
1678 break;
1679 case presentation::ClickAction_PREVPAGE :
1681 sal_Int32 nDestPage = rPDFExtOutDevData.GetCurrentPageNumber();
1682 if ( nDestPage )
1683 nDestPage--;
1684 sal_Int32 nDestId = rPDFExtOutDevData.CreateDest( aPageRect, nDestPage, vcl::PDFWriter::DestAreaType::FitRectangle );
1685 sal_Int32 nLinkId = rPDFExtOutDevData.CreateLink( aLinkRect );
1686 rPDFExtOutDevData.SetLinkDest( nLinkId, nDestId );
1688 break;
1689 case presentation::ClickAction_NEXTPAGE :
1691 sal_Int32 nDestPage = rPDFExtOutDevData.GetCurrentPageNumber() + 1;
1692 sal_Int32 nLastPage = rDoc.GetSdPageCount( PageKind::Standard ) - 1;
1693 if ( nDestPage > nLastPage )
1694 nDestPage = nLastPage;
1695 sal_Int32 nDestId = rPDFExtOutDevData.CreateDest( aPageRect, nDestPage, vcl::PDFWriter::DestAreaType::FitRectangle );
1696 sal_Int32 nLinkId = rPDFExtOutDevData.CreateLink( aLinkRect );
1697 rPDFExtOutDevData.SetLinkDest( nLinkId, nDestId );
1699 break;
1701 case presentation::ClickAction_PROGRAM :
1702 case presentation::ClickAction_BOOKMARK :
1703 case presentation::ClickAction_DOCUMENT :
1705 OUString aBookmark;
1706 xShapePropSet->getPropertyValue( "Bookmark" ) >>= aBookmark;
1707 if( !aBookmark.isEmpty() )
1709 switch( eCa )
1711 case presentation::ClickAction_DOCUMENT :
1712 case presentation::ClickAction_PROGRAM :
1714 sal_Int32 nLinkId = rPDFExtOutDevData.CreateLink( aLinkRect );
1715 rPDFExtOutDevData.SetLinkURL( nLinkId, aBookmark );
1717 break;
1718 case presentation::ClickAction_BOOKMARK :
1720 sal_Int32 nPage = ImplPDFGetBookmarkPage( aBookmark, rDoc );
1721 if ( nPage != -1 )
1723 sal_Int32 nDestId = rPDFExtOutDevData.CreateDest( aPageRect, nPage, vcl::PDFWriter::DestAreaType::FitRectangle );
1724 sal_Int32 nLinkId = rPDFExtOutDevData.CreateLink( aLinkRect );
1725 rPDFExtOutDevData.SetLinkDest( nLinkId, nDestId );
1728 break;
1729 default:
1730 break;
1734 break;
1736 case presentation::ClickAction_STOPPRESENTATION :
1737 case presentation::ClickAction_SOUND :
1738 case presentation::ClickAction_INVISIBLE :
1739 case presentation::ClickAction_VERB :
1740 case presentation::ClickAction_VANISH :
1741 case presentation::ClickAction_MACRO :
1742 default :
1743 break;
1750 vcl::PDFWriter::StructElement ImplRenderPaintProc::ImplBegStructureTag( SdrObject& rObject )
1752 vcl::PDFWriter::StructElement eElement(vcl::PDFWriter::NonStructElement);
1754 if ( pPDFExtOutDevData && pPDFExtOutDevData->GetIsExportTaggedPDF() )
1756 SdrInventor nInventor = rObject.GetObjInventor();
1757 sal_uInt16 nIdentifier = rObject.GetObjIdentifier();
1758 bool bIsTextObj = dynamic_cast< const SdrTextObj *>( &rObject ) != nullptr;
1760 if ( nInventor == SdrInventor::Default )
1762 if ( nIdentifier == OBJ_GRUP )
1763 eElement = vcl::PDFWriter::Section;
1764 else if ( nIdentifier == OBJ_TITLETEXT )
1765 eElement = vcl::PDFWriter::Heading;
1766 else if ( nIdentifier == OBJ_OUTLINETEXT )
1767 eElement = vcl::PDFWriter::Division;
1768 else if ( !bIsTextObj || !static_cast<SdrTextObj&>(rObject).HasText() )
1769 eElement = vcl::PDFWriter::Figure;
1773 return eElement;
1776 drawinglayer::primitive2d::Primitive2DContainer ImplRenderPaintProc::createRedirectedPrimitive2DSequence(
1777 const sdr::contact::ViewObjectContact& rOriginal,
1778 const sdr::contact::DisplayInfo& rDisplayInfo)
1780 SdrObject* pObject = rOriginal.GetViewContact().TryToGetSdrObject();
1782 if(pObject)
1784 drawinglayer::primitive2d::Primitive2DContainer xRetval;
1786 if(pObject->getSdrPageFromSdrObject())
1788 if(pObject->getSdrPageFromSdrObject()->checkVisibility(rOriginal, rDisplayInfo, false))
1790 if(IsVisible(pObject) && IsPrintable(pObject))
1792 const vcl::PDFWriter::StructElement eElement(ImplBegStructureTag( *pObject ));
1793 const bool bTagUsed(vcl::PDFWriter::NonStructElement != eElement);
1795 xRetval = sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence(rOriginal, rDisplayInfo);
1797 if(!xRetval.empty() && bTagUsed)
1799 // embed Primitive2DSequence in a structure tag element for
1800 // exactly this purpose (StructureTagPrimitive2D)
1802 const SdrPage* pSdrPage(pObject->getSdrPageFromSdrObject());
1803 const bool bBackground(nullptr != pSdrPage && pSdrPage->IsMasterPage());
1804 const bool bImage(pObject->GetObjIdentifier() == OBJ_GRAF);
1806 const drawinglayer::primitive2d::Primitive2DReference xReference(
1807 new drawinglayer::primitive2d::StructureTagPrimitive2D(
1808 eElement,
1809 bBackground,
1810 bImage,
1811 xRetval));
1813 xRetval = drawinglayer::primitive2d::Primitive2DContainer { xReference };
1819 return xRetval;
1821 else
1823 // not an object, maybe a page
1824 return sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence(rOriginal, rDisplayInfo);
1828 bool ImplRenderPaintProc::IsVisible( const SdrObject* pObj ) const
1830 bool bVisible = true;
1831 SdrLayerID nLayerId = pObj->GetLayer();
1832 if( pSdrPageView )
1834 const SdrLayer* pSdrLayer = rLayerAdmin.GetLayerPerID( nLayerId );
1835 if ( pSdrLayer )
1837 const OUString& aLayerName = pSdrLayer->GetName();
1838 bVisible = pSdrPageView->IsLayerVisible( aLayerName );
1841 return bVisible;
1843 bool ImplRenderPaintProc::IsPrintable( const SdrObject* pObj ) const
1845 bool bPrintable = true;
1846 SdrLayerID nLayerId = pObj->GetLayer();
1847 if( pSdrPageView )
1849 const SdrLayer* pSdrLayer = rLayerAdmin.GetLayerPerID( nLayerId );
1850 if ( pSdrLayer )
1852 const OUString& aLayerName = pSdrLayer->GetName();
1853 bPrintable = pSdrPageView->IsLayerPrintable( aLayerName );
1856 return bPrintable;
1860 namespace
1862 sal_Int16 CalcOutputPageNum(vcl::PDFExtOutDevData const * pPDFExtOutDevData, SdDrawDocument const *pDoc, sal_Int16 nPageNumber)
1864 //export all pages, simple one to one case
1865 if (pPDFExtOutDevData && pPDFExtOutDevData->GetIsExportHiddenSlides())
1866 return nPageNumber-1;
1867 //check all preceding pages, and only count non-hidden ones
1868 sal_Int16 nRet = 0;
1869 for (sal_Int16 i = 0; i < nPageNumber-1; ++i)
1871 if (!pDoc->GetSdPage(i, PageKind::Standard)->IsExcluded())
1872 ++nRet;
1874 return nRet;
1878 void SAL_CALL SdXImpressDocument::render( sal_Int32 nRenderer, const uno::Any& rSelection,
1879 const uno::Sequence< beans::PropertyValue >& rxOptions )
1881 ::SolarMutexGuard aGuard;
1883 if( nullptr == mpDoc )
1884 throw lang::DisposedException();
1886 if (!mpDocShell)
1887 return;
1889 uno::Reference< awt::XDevice > xRenderDevice;
1890 const sal_Int32 nPageNumber = nRenderer + 1;
1891 PageKind ePageKind = PageKind::Standard;
1892 bool bExportNotesPages = false;
1894 for( sal_Int32 nProperty = 0, nPropertyCount = rxOptions.getLength(); nProperty < nPropertyCount; ++nProperty )
1896 if ( rxOptions[ nProperty ].Name == "RenderDevice" )
1897 rxOptions[ nProperty ].Value >>= xRenderDevice;
1898 else if ( rxOptions[ nProperty ].Name == "ExportNotesPages" )
1900 rxOptions[ nProperty].Value >>= bExportNotesPages;
1901 if ( bExportNotesPages )
1902 ePageKind = PageKind::Notes;
1906 if( !(xRenderDevice.is() && nPageNumber && ( nPageNumber <= mpDoc->GetSdPageCount( ePageKind ) )) )
1907 return;
1909 VCLXDevice* pDevice = VCLXDevice::GetImplementation( xRenderDevice );
1910 VclPtr< OutputDevice> pOut = pDevice ? pDevice->GetOutputDevice() : VclPtr< OutputDevice >();
1912 if( !pOut )
1913 return;
1915 vcl::PDFExtOutDevData* pPDFExtOutDevData = dynamic_cast<vcl::PDFExtOutDevData* >( pOut->GetExtOutDevData() );
1917 if ( !(!( mpDoc->GetSdPage(static_cast<sal_Int16>(nPageNumber)-1, PageKind::Standard)->IsExcluded() ) ||
1918 (pPDFExtOutDevData && pPDFExtOutDevData->GetIsExportHiddenSlides())) )
1919 return;
1921 std::unique_ptr<::sd::ClientView> pView( new ::sd::ClientView( mpDocShell, pOut ) );
1922 ::tools::Rectangle aVisArea = ::tools::Rectangle( Point(), mpDoc->GetSdPage( static_cast<sal_uInt16>(nPageNumber) - 1, ePageKind )->GetSize() );
1923 vcl::Region aRegion( aVisArea );
1925 ::sd::ViewShell* pOldViewSh = mpDocShell->GetViewShell();
1926 ::sd::View* pOldSdView = pOldViewSh ? pOldViewSh->GetView() : nullptr;
1928 if ( pOldSdView )
1929 pOldSdView->SdrEndTextEdit();
1931 pView->SetHlplVisible( false );
1932 pView->SetGridVisible( false );
1933 pView->SetBordVisible( false );
1934 pView->SetPageVisible( false );
1935 pView->SetGlueVisible( false );
1937 pOut->SetMapMode(MapMode(MapUnit::Map100thMM));
1938 pOut->IntersectClipRegion( aVisArea );
1940 uno::Reference< frame::XModel > xModel;
1941 rSelection >>= xModel;
1943 if( xModel == mpDocShell->GetModel() )
1945 pView->ShowSdrPage( mpDoc->GetSdPage( static_cast<sal_uInt16>(nPageNumber) - 1, ePageKind ));
1946 SdrPageView* pPV = pView->GetSdrPageView();
1948 if( pOldSdView )
1950 SdrPageView* pOldPV = pOldSdView->GetSdrPageView();
1951 if( pPV && pOldPV )
1953 pPV->SetVisibleLayers( pOldPV->GetVisibleLayers() );
1954 pPV->SetPrintableLayers( pOldPV->GetPrintableLayers() );
1958 ImplRenderPaintProc aImplRenderPaintProc( mpDoc->GetLayerAdmin(),
1959 pPV, pPDFExtOutDevData );
1961 // background color for outliner :o
1962 SdPage* pPage = pPV ? static_cast<SdPage*>(pPV->GetPage()) : nullptr;
1963 if( pPage )
1965 SdrOutliner& rOutl = mpDoc->GetDrawOutliner();
1966 bool bScreenDisplay(true);
1968 // #i75566# printing; suppress AutoColor BackgroundColor generation
1969 // for visibility reasons by giving GetPageBackgroundColor()
1970 // the needed hint
1971 // #i75566# PDF export; suppress AutoColor BackgroundColor generation (see printing)
1972 if (pOut && ((OUTDEV_PRINTER == pOut->GetOutDevType())
1973 || (OUTDEV_PDF == pOut->GetOutDevType())))
1974 bScreenDisplay = false;
1976 // #i75566# Name change GetBackgroundColor -> GetPageBackgroundColor and
1977 // hint value if screen display. Only then the AutoColor mechanisms shall be applied
1978 rOutl.SetBackgroundColor( pPage->GetPageBackgroundColor( pPV, bScreenDisplay ) );
1980 pView->SdrPaintView::CompleteRedraw( pOut, aRegion, &aImplRenderPaintProc );
1982 if ( pPDFExtOutDevData && pPage )
1986 uno::Any aAny;
1987 uno::Reference< drawing::XDrawPage > xPage( uno::Reference< drawing::XDrawPage >::query( pPage->getUnoPage() ) );
1988 if ( xPage.is() )
1990 if ( pPDFExtOutDevData->GetIsExportNotes() )
1991 ImplPDFExportComments( xPage, *pPDFExtOutDevData );
1992 uno::Reference< beans::XPropertySet > xPagePropSet( xPage, uno::UNO_QUERY );
1993 if( xPagePropSet.is() )
1995 // exporting object interactions to pdf
1997 // if necessary, the master page interactions will be exported first
1998 bool bIsBackgroundObjectsVisible = false; // #i39428# IsBackgroundObjectsVisible not available for Draw
1999 if ( mbImpressDoc && xPagePropSet->getPropertySetInfo()->hasPropertyByName( "IsBackgroundObjectsVisible" ) )
2000 xPagePropSet->getPropertyValue( "IsBackgroundObjectsVisible" ) >>= bIsBackgroundObjectsVisible;
2001 if ( bIsBackgroundObjectsVisible && !pPDFExtOutDevData->GetIsExportNotesPages() )
2003 uno::Reference< drawing::XMasterPageTarget > xMasterPageTarget( xPage, uno::UNO_QUERY );
2004 if ( xMasterPageTarget.is() )
2006 uno::Reference< drawing::XDrawPage > xMasterPage = xMasterPageTarget->getMasterPage();
2007 if ( xMasterPage.is() )
2009 uno::Reference< drawing::XShapes> xShapes( xMasterPage, uno::UNO_QUERY );
2010 sal_Int32 i, nCount = xShapes->getCount();
2011 for ( i = 0; i < nCount; i++ )
2013 aAny = xShapes->getByIndex( i );
2014 uno::Reference< drawing::XShape > xShape;
2015 if ( aAny >>= xShape )
2016 ImplPDFExportShapeInteraction( xShape, *mpDoc, *pPDFExtOutDevData );
2022 // exporting slide page object interactions
2023 uno::Reference< drawing::XShapes> xShapes( xPage, uno::UNO_QUERY );
2024 sal_Int32 i, nCount = xShapes->getCount();
2025 for ( i = 0; i < nCount; i++ )
2027 aAny = xShapes->getByIndex( i );
2028 uno::Reference< drawing::XShape > xShape;
2029 if ( aAny >>= xShape )
2030 ImplPDFExportShapeInteraction( xShape, *mpDoc, *pPDFExtOutDevData );
2033 // exporting transition effects to pdf
2034 if ( mbImpressDoc && !pPDFExtOutDevData->GetIsExportNotesPages() && pPDFExtOutDevData->GetIsExportTransitionEffects() )
2036 const OUString sEffect( "Effect" );
2037 const OUString sSpeed ( "Speed" );
2038 sal_Int32 nTime = 800;
2039 presentation::AnimationSpeed aAs;
2040 if ( xPagePropSet->getPropertySetInfo( )->hasPropertyByName( sSpeed ) )
2042 aAny = xPagePropSet->getPropertyValue( sSpeed );
2043 if ( aAny >>= aAs )
2045 switch( aAs )
2047 case presentation::AnimationSpeed_SLOW : nTime = 1500; break;
2048 case presentation::AnimationSpeed_FAST : nTime = 300; break;
2049 default:
2050 case presentation::AnimationSpeed_MEDIUM : nTime = 800;
2054 presentation::FadeEffect eFe;
2055 vcl::PDFWriter::PageTransition eType = vcl::PDFWriter::PageTransition::Regular;
2056 if ( xPagePropSet->getPropertySetInfo( )->hasPropertyByName( sEffect ) )
2058 aAny = xPagePropSet->getPropertyValue( sEffect );
2059 if ( aAny >>= eFe )
2061 switch( eFe )
2063 case presentation::FadeEffect_HORIZONTAL_LINES :
2064 case presentation::FadeEffect_HORIZONTAL_CHECKERBOARD :
2065 case presentation::FadeEffect_HORIZONTAL_STRIPES : eType = vcl::PDFWriter::PageTransition::BlindsHorizontal; break;
2067 case presentation::FadeEffect_VERTICAL_LINES :
2068 case presentation::FadeEffect_VERTICAL_CHECKERBOARD :
2069 case presentation::FadeEffect_VERTICAL_STRIPES : eType = vcl::PDFWriter::PageTransition::BlindsVertical; break;
2071 case presentation::FadeEffect_UNCOVER_TO_RIGHT :
2072 case presentation::FadeEffect_UNCOVER_TO_UPPERRIGHT :
2073 case presentation::FadeEffect_ROLL_FROM_LEFT :
2074 case presentation::FadeEffect_FADE_FROM_UPPERLEFT :
2075 case presentation::FadeEffect_MOVE_FROM_UPPERLEFT :
2076 case presentation::FadeEffect_FADE_FROM_LEFT :
2077 case presentation::FadeEffect_MOVE_FROM_LEFT : eType = vcl::PDFWriter::PageTransition::WipeLeftToRight; break;
2079 case presentation::FadeEffect_UNCOVER_TO_BOTTOM :
2080 case presentation::FadeEffect_UNCOVER_TO_LOWERRIGHT :
2081 case presentation::FadeEffect_ROLL_FROM_TOP :
2082 case presentation::FadeEffect_FADE_FROM_UPPERRIGHT :
2083 case presentation::FadeEffect_MOVE_FROM_UPPERRIGHT :
2084 case presentation::FadeEffect_FADE_FROM_TOP :
2085 case presentation::FadeEffect_MOVE_FROM_TOP : eType = vcl::PDFWriter::PageTransition::WipeTopToBottom; break;
2087 case presentation::FadeEffect_UNCOVER_TO_LEFT :
2088 case presentation::FadeEffect_UNCOVER_TO_LOWERLEFT :
2089 case presentation::FadeEffect_ROLL_FROM_RIGHT :
2091 case presentation::FadeEffect_FADE_FROM_LOWERRIGHT :
2092 case presentation::FadeEffect_MOVE_FROM_LOWERRIGHT :
2093 case presentation::FadeEffect_FADE_FROM_RIGHT :
2094 case presentation::FadeEffect_MOVE_FROM_RIGHT : eType = vcl::PDFWriter::PageTransition::WipeRightToLeft; break;
2096 case presentation::FadeEffect_UNCOVER_TO_TOP :
2097 case presentation::FadeEffect_UNCOVER_TO_UPPERLEFT :
2098 case presentation::FadeEffect_ROLL_FROM_BOTTOM :
2099 case presentation::FadeEffect_FADE_FROM_LOWERLEFT :
2100 case presentation::FadeEffect_MOVE_FROM_LOWERLEFT :
2101 case presentation::FadeEffect_FADE_FROM_BOTTOM :
2102 case presentation::FadeEffect_MOVE_FROM_BOTTOM : eType = vcl::PDFWriter::PageTransition::WipeBottomToTop; break;
2104 case presentation::FadeEffect_OPEN_VERTICAL : eType = vcl::PDFWriter::PageTransition::SplitHorizontalInward; break;
2105 case presentation::FadeEffect_CLOSE_HORIZONTAL : eType = vcl::PDFWriter::PageTransition::SplitHorizontalOutward; break;
2107 case presentation::FadeEffect_OPEN_HORIZONTAL : eType = vcl::PDFWriter::PageTransition::SplitVerticalInward; break;
2108 case presentation::FadeEffect_CLOSE_VERTICAL : eType = vcl::PDFWriter::PageTransition::SplitVerticalOutward; break;
2110 case presentation::FadeEffect_FADE_TO_CENTER : eType = vcl::PDFWriter::PageTransition::BoxInward; break;
2111 case presentation::FadeEffect_FADE_FROM_CENTER : eType = vcl::PDFWriter::PageTransition::BoxOutward; break;
2113 case presentation::FadeEffect_NONE : eType = vcl::PDFWriter::PageTransition::Regular; break;
2115 case presentation::FadeEffect_RANDOM :
2116 case presentation::FadeEffect_DISSOLVE :
2117 default: eType = vcl::PDFWriter::PageTransition::Dissolve; break;
2122 if ( xPagePropSet->getPropertySetInfo( )->hasPropertyByName( sEffect ) ||
2123 xPagePropSet->getPropertySetInfo( )->hasPropertyByName( sSpeed ) )
2125 pPDFExtOutDevData->SetPageTransition( eType, nTime );
2131 Size aPageSize( mpDoc->GetSdPage( 0, PageKind::Standard )->GetSize() );
2132 Point aPoint( 0, 0 );
2133 ::tools::Rectangle aPageRect( aPoint, aPageSize );
2135 // resolving links found in this page by the method ImpEditEngine::Paint
2136 std::vector< vcl::PDFExtOutDevBookmarkEntry >& rBookmarks = pPDFExtOutDevData->GetBookmarks();
2137 for ( const auto& rBookmark : rBookmarks )
2139 sal_Int32 nPage = ImplPDFGetBookmarkPage( rBookmark.aBookmark, *mpDoc );
2140 if ( nPage != -1 )
2142 if ( rBookmark.nLinkId != -1 )
2143 pPDFExtOutDevData->SetLinkDest( rBookmark.nLinkId, pPDFExtOutDevData->CreateDest( aPageRect, nPage, vcl::PDFWriter::DestAreaType::FitRectangle ) );
2144 else
2145 pPDFExtOutDevData->DescribeRegisteredDest( rBookmark.nDestId, aPageRect, nPage, vcl::PDFWriter::DestAreaType::FitRectangle );
2147 else
2148 pPDFExtOutDevData->SetLinkURL( rBookmark.nLinkId, rBookmark.aBookmark );
2150 rBookmarks.clear();
2151 //---> #i56629, #i40318
2152 //get the page name, will be used as outline element in PDF bookmark pane
2153 OUString aPageName = mpDoc->GetSdPage( static_cast<sal_uInt16>(nPageNumber) - 1 , PageKind::Standard )->GetName();
2154 if( !aPageName.isEmpty() )
2156 // Destination PageNum
2157 const sal_Int32 nDestPageNum = CalcOutputPageNum(pPDFExtOutDevData, mpDoc, nPageNumber);
2159 // insert the bookmark to this page into the NamedDestinations
2160 if( pPDFExtOutDevData->GetIsExportNamedDestinations() )
2161 pPDFExtOutDevData->CreateNamedDest(aPageName, aPageRect, nDestPageNum);
2163 // add the name to the outline, (almost) same code as in sc/source/ui/unoobj/docuno.cxx
2164 // issue #i40318.
2166 if( pPDFExtOutDevData->GetIsExportBookmarks() )
2168 // Destination Export
2169 const sal_Int32 nDestId =
2170 pPDFExtOutDevData->CreateDest(aPageRect , nDestPageNum);
2172 // Create a new outline item:
2173 pPDFExtOutDevData->CreateOutlineItem( -1 , aPageName, nDestId );
2176 //<--- #i56629, #i40318
2178 catch (const uno::Exception&)
2184 else
2186 uno::Reference< drawing::XShapes > xShapes;
2187 rSelection >>= xShapes;
2189 if( xShapes.is() && xShapes->getCount() )
2191 SdrPageView* pPV = nullptr;
2193 ImplRenderPaintProc aImplRenderPaintProc( mpDoc->GetLayerAdmin(),
2194 pOldSdView ? pOldSdView->GetSdrPageView() : nullptr, pPDFExtOutDevData );
2196 for( sal_uInt32 i = 0, nCount = xShapes->getCount(); i < nCount; i++ )
2198 uno::Reference< drawing::XShape > xShape;
2199 xShapes->getByIndex( i ) >>= xShape;
2201 if( xShape.is() )
2203 SvxShape* pShape = SvxShape::getImplementation( xShape );
2205 if( pShape )
2207 SdrObject* pObj = pShape->GetSdrObject();
2208 if( pObj && pObj->getSdrPageFromSdrObject()
2209 && aImplRenderPaintProc.IsVisible( pObj )
2210 && aImplRenderPaintProc.IsPrintable( pObj ) )
2212 if( !pPV )
2213 pPV = pView->ShowSdrPage( pObj->getSdrPageFromSdrObject() );
2215 if( pPV )
2216 pView->MarkObj( pObj, pPV );
2221 pView->DrawMarkedObj(*pOut);
2226 DrawViewShell* SdXImpressDocument::GetViewShell()
2228 DrawViewShell* pViewSh = dynamic_cast<DrawViewShell*>(mpDocShell->GetViewShell());
2229 if (!pViewSh)
2231 SAL_WARN("sd", "DrawViewShell not available!");
2232 return nullptr;
2234 return pViewSh;
2237 void SdXImpressDocument::paintTile( VirtualDevice& rDevice,
2238 int nOutputWidth, int nOutputHeight,
2239 int nTilePosX, int nTilePosY,
2240 long nTileWidth, long nTileHeight )
2242 DrawViewShell* pViewSh = GetViewShell();
2243 if (!pViewSh)
2244 return;
2246 // Scaling. Must convert from pixels to twips. We know
2247 // that VirtualDevices use a DPI of 96.
2248 // We specifically calculate these scales first as we're still
2249 // in TWIPs, and might as well minimize the number of conversions.
2250 Fraction scaleX = Fraction( nOutputWidth, 96 ) * Fraction(1440) /
2251 Fraction( nTileWidth);
2252 Fraction scaleY = Fraction( nOutputHeight, 96 ) * Fraction(1440) /
2253 Fraction( nTileHeight);
2255 // svx seems to be the only component that works natively in
2256 // 100th mm rather than TWIP. It makes most sense just to
2257 // convert here and in getDocumentSize, and leave the tiled
2258 // rendering API working in TWIPs.
2259 long nTileWidthHMM = convertTwipToMm100( nTileWidth );
2260 long nTileHeightHMM = convertTwipToMm100( nTileHeight );
2261 int nTilePosXHMM = convertTwipToMm100( nTilePosX );
2262 int nTilePosYHMM = convertTwipToMm100( nTilePosY );
2264 MapMode aMapMode = rDevice.GetMapMode();
2265 aMapMode.SetMapUnit( MapUnit::Map100thMM );
2266 aMapMode.SetOrigin( Point( -nTilePosXHMM,
2267 -nTilePosYHMM) );
2268 aMapMode.SetScaleX( scaleX );
2269 aMapMode.SetScaleY( scaleY );
2271 rDevice.SetMapMode( aMapMode );
2273 rDevice.SetOutputSizePixel( Size(nOutputWidth, nOutputHeight) );
2275 Point aPoint(nTilePosXHMM, nTilePosYHMM);
2276 Size aSize(nTileWidthHMM, nTileHeightHMM);
2277 ::tools::Rectangle aRect(aPoint, aSize);
2279 pViewSh->GetView()->CompleteRedraw(&rDevice, vcl::Region(aRect));
2281 LokChartHelper::PaintAllChartsOnTile(rDevice, nOutputWidth, nOutputHeight,
2282 nTilePosX, nTilePosY, nTileWidth, nTileHeight);
2285 void SdXImpressDocument::setPart( int nPart )
2287 DrawViewShell* pViewSh = GetViewShell();
2288 if (!pViewSh)
2289 return;
2291 pViewSh->SwitchPage( nPart );
2294 int SdXImpressDocument::getParts()
2296 // TODO: master pages?
2297 // Read: drviews1.cxx
2298 return mpDoc->GetSdPageCount(PageKind::Standard);
2301 int SdXImpressDocument::getPart()
2303 DrawViewShell* pViewSh = GetViewShell();
2304 if (!pViewSh)
2305 return 0;
2307 return pViewSh->GetViewShellBase().getPart();
2310 OUString SdXImpressDocument::getPartName( int nPart )
2312 SdPage* pPage = mpDoc->GetSdPage( nPart, PageKind::Standard );
2313 if (!pPage)
2315 SAL_WARN("sd", "DrawViewShell not available!");
2316 return OUString();
2319 return pPage->GetName();
2322 OUString SdXImpressDocument::getPartHash( int nPart )
2324 SdPage* pPage = mpDoc->GetSdPage( nPart, PageKind::Standard );
2325 if (!pPage)
2327 SAL_WARN("sd", "DrawViewShell not available!");
2328 return OUString();
2331 return OUString::number(pPage->GetHashCode());
2334 VclPtr<vcl::Window> SdXImpressDocument::getDocWindow()
2336 SolarMutexGuard aGuard;
2337 DrawViewShell* pViewShell = GetViewShell();
2338 VclPtr<vcl::Window> pWindow;
2339 if (pViewShell)
2340 pWindow = pViewShell->GetActiveWindow();
2342 LokChartHelper aChartHelper(pViewShell->GetViewShell());
2343 VclPtr<vcl::Window> pChartWindow = aChartHelper.GetWindow();
2344 if (pChartWindow)
2345 pWindow = pChartWindow;
2347 return pWindow;
2350 void SdXImpressDocument::setPartMode( int nPartMode )
2352 DrawViewShell* pViewSh = GetViewShell();
2353 if (!pViewSh)
2354 return;
2356 PageKind aPageKind( PageKind::Standard );
2357 switch ( nPartMode )
2359 case LOK_PARTMODE_SLIDES:
2360 break;
2361 case LOK_PARTMODE_NOTES:
2362 aPageKind = PageKind::Notes;
2363 break;
2365 pViewSh->SetPageKind( aPageKind );
2368 Size SdXImpressDocument::getDocumentSize()
2370 DrawViewShell* pViewSh = GetViewShell();
2371 if (!pViewSh)
2372 return Size();
2374 SdrView *pSdrView = pViewSh->GetView();
2375 if (!pSdrView)
2376 return Size();
2378 SdrPageView* pCurPageView = pSdrView->GetSdrPageView();
2379 if (!pCurPageView)
2380 return Size();
2382 Size aSize = pCurPageView->GetPageRect().GetSize();
2383 // Convert the size in 100th mm to TWIP
2384 // See paintTile above for further info.
2385 return Size(convertMm100ToTwip(aSize.getWidth()), convertMm100ToTwip(aSize.getHeight()));
2388 OUString SdXImpressDocument::getPostIts()
2390 boost::property_tree::ptree aAnnotations;
2391 // Return annotations on master pages too ?
2392 const sal_uInt16 nMaxPages = mpDoc->GetPageCount();
2393 SdPage* pPage;
2394 for (sal_uInt16 nPage = 0; nPage < nMaxPages; ++nPage)
2396 pPage = static_cast<SdPage*>(mpDoc->GetPage(nPage));
2397 const sd::AnnotationVector& aPageAnnotations = pPage->getAnnotations();
2399 for (const uno::Reference<office::XAnnotation>& xAnnotation : aPageAnnotations)
2401 boost::property_tree::ptree aAnnotation;
2402 aAnnotation.put("id", sd::getAnnotationId(xAnnotation));
2403 aAnnotation.put("author", xAnnotation->getAuthor());
2404 aAnnotation.put("dateTime", utl::toISO8601(xAnnotation->getDateTime()));
2405 uno::Reference<text::XText> xText(xAnnotation->getTextRange());
2406 aAnnotation.put("text", xText->getString());
2407 aAnnotation.put("parthash", OUString::number(pPage->GetHashCode()));
2409 aAnnotations.push_back(std::make_pair("", aAnnotation));
2413 boost::property_tree::ptree aTree;
2414 aTree.add_child("comments", aAnnotations);
2415 std::stringstream aStream;
2416 boost::property_tree::write_json(aStream, aTree);
2418 return OUString::fromUtf8(aStream.str().c_str());
2421 void SdXImpressDocument::initializeForTiledRendering(const css::uno::Sequence<css::beans::PropertyValue>& rArguments)
2423 SolarMutexGuard aGuard;
2425 if (DrawViewShell* pViewShell = GetViewShell())
2427 DrawView* pDrawView = pViewShell->GetDrawView();
2428 for (sal_Int32 i = 0; i < rArguments.getLength(); ++i)
2430 const beans::PropertyValue& rValue = rArguments[i];
2431 if (rValue.Name == ".uno:ShowBorderShadow" && rValue.Value.has<bool>())
2432 pDrawView->SetPageShadowVisible(rValue.Value.get<bool>());
2433 else if (rValue.Name == ".uno:Author" && rValue.Value.has<OUString>())
2434 pDrawView->SetAuthor(rValue.Value.get<OUString>());
2437 // Disable comments if requested
2438 SdOptions* pOptions = SD_MOD()->GetSdOptions(mpDoc->GetDocumentType());
2439 pOptions->SetShowComments(comphelper::LibreOfficeKit::isTiledAnnotations());
2441 pViewShell->SetRuler(false);
2442 pViewShell->SetScrollBarsVisible(false);
2444 if (sd::Window* pWindow = pViewShell->GetActiveWindow())
2446 // get the full page size in pixels
2447 pWindow->EnableMapMode();
2448 Size aSize(pWindow->LogicToPixel(pDrawView->GetSdrPageView()->GetPage()->GetSize()));
2449 // Disable map mode, so that it's possible to send mouse event
2450 // coordinates in logic units
2451 pWindow->EnableMapMode(false);
2453 // arrange UI elements again with new view size
2454 pViewShell->GetParentWindow()->SetSizePixel(aSize);
2455 pViewShell->Resize();
2458 // Forces all images to be swapped in synchronously, this
2459 // ensures that images are available when paintTile is called
2460 // (whereas with async loading images start being loaded after
2461 // we have painted the tile, resulting in an invalidate, followed
2462 // by the tile being rerendered - which is wasteful and ugly).
2463 pDrawView->SetSwapAsynchron(false);
2466 // when the "This document may contain formatting or content that cannot
2467 // be saved..." dialog appears, it is auto-cancelled with tiled rendering,
2468 // causing 'Save' being disabled; so let's always save to the original
2469 // format
2470 SvtSaveOptions().SetWarnAlienFormat(false);
2473 void SdXImpressDocument::postKeyEvent(int nType, int nCharCode, int nKeyCode)
2475 SolarMutexGuard aGuard;
2476 SfxLokHelper::postKeyEventAsync(getDocWindow(), nType, nCharCode, nKeyCode);
2479 void SdXImpressDocument::postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons, int nModifier)
2481 SolarMutexGuard aGuard;
2483 DrawViewShell* pViewShell = GetViewShell();
2484 if (!pViewShell)
2485 return;
2487 double fScale = 1.0/TWIPS_PER_PIXEL;
2489 // check if user hit a chart which is being edited by him
2490 LokChartHelper aChartHelper(pViewShell->GetViewShell());
2491 if (aChartHelper.postMouseEvent(nType, nX, nY,
2492 nCount, nButtons, nModifier,
2493 fScale, fScale))
2494 return;
2496 // check if the user hit a chart which is being edited by someone else
2497 // and, if so, skip current mouse event
2498 if (nType != LOK_MOUSEEVENT_MOUSEMOVE)
2500 if (LokChartHelper::HitAny(Point(nX, nY)))
2501 return;
2504 const Point aPos(Point(convertTwipToMm100(nX), convertTwipToMm100(nY)));
2505 SfxLokHelper::postMouseEventAsync(pViewShell->GetActiveWindow(), nType,
2506 aPos, nCount,
2507 MouseEventModifiers::SIMPLECLICK,
2508 nButtons, nModifier);
2511 void SdXImpressDocument::setTextSelection(int nType, int nX, int nY)
2513 SolarMutexGuard aGuard;
2515 DrawViewShell* pViewShell = GetViewShell();
2516 if (!pViewShell)
2517 return;
2519 LokChartHelper aChartHelper(pViewShell->GetViewShell());
2520 if (aChartHelper.setTextSelection(nType, nX, nY))
2521 return;
2523 Point aPoint(convertTwipToMm100(nX), convertTwipToMm100(nY));
2524 switch (nType)
2526 case LOK_SETTEXTSELECTION_START:
2527 pViewShell->SetCursorMm100Position(aPoint, /*bPoint=*/false, /*bClearMark=*/false);
2528 break;
2529 case LOK_SETTEXTSELECTION_END:
2530 pViewShell->SetCursorMm100Position(aPoint, /*bPoint=*/true, /*bClearMark=*/false);
2531 break;
2532 case LOK_SETTEXTSELECTION_RESET:
2533 pViewShell->SetCursorMm100Position(aPoint, /*bPoint=*/true, /*bClearMark=*/true);
2534 break;
2535 default:
2536 assert(false);
2537 break;
2541 OString SdXImpressDocument::getTextSelection(const char* pMimeType, OString& rUsedMimeType)
2543 SolarMutexGuard aGuard;
2545 DrawViewShell* pViewShell = GetViewShell();
2546 if (!pViewShell)
2547 return OString();
2549 return pViewShell->GetTextSelection(pMimeType, rUsedMimeType);
2552 void SdXImpressDocument::setGraphicSelection(int nType, int nX, int nY)
2554 SolarMutexGuard aGuard;
2556 DrawViewShell* pViewShell = GetViewShell();
2557 if (!pViewShell)
2558 return;
2560 double fScale = 1.0/TWIPS_PER_PIXEL;
2562 LokChartHelper aChartHelper(pViewShell->GetViewShell());
2563 if (aChartHelper.setGraphicSelection(nType, nX, nY, fScale, fScale))
2564 return;
2566 Point aPoint(convertTwipToMm100(nX), convertTwipToMm100(nY));
2567 switch (nType)
2569 case LOK_SETGRAPHICSELECTION_START:
2570 pViewShell->SetGraphicMm100Position(/*bStart=*/true, aPoint);
2571 break;
2572 case LOK_SETGRAPHICSELECTION_END:
2573 pViewShell->SetGraphicMm100Position(/*bStart=*/false, aPoint);
2574 break;
2575 default:
2576 assert(false);
2577 break;
2581 void SdXImpressDocument::resetSelection()
2583 SolarMutexGuard aGuard;
2585 DrawViewShell* pViewShell = GetViewShell();
2586 if (!pViewShell)
2587 return;
2589 SdrView* pSdrView = pViewShell->GetView();
2590 if (!pSdrView)
2591 return;
2593 if (pSdrView->IsTextEdit())
2595 // Reset the editeng selection.
2596 pSdrView->UnmarkAll();
2597 // Finish editing.
2598 pSdrView->SdrEndTextEdit();
2600 // Reset graphic selection.
2601 pSdrView->UnmarkAll();
2604 void SdXImpressDocument::setClipboard(const uno::Reference<datatransfer::clipboard::XClipboard>& xClipboard)
2606 SolarMutexGuard aGuard;
2608 DrawViewShell* pViewShell = GetViewShell();
2609 if (!pViewShell)
2610 return;
2612 pViewShell->GetActiveWindow()->SetClipboard(xClipboard);
2615 bool SdXImpressDocument::isMimeTypeSupported()
2617 SolarMutexGuard aGuard;
2618 DrawViewShell* pViewShell = GetViewShell();
2619 if (!pViewShell)
2620 return false;
2622 TransferableDataHelper aDataHelper(TransferableDataHelper::CreateFromSystemClipboard(pViewShell->GetActiveWindow()));
2623 return EditEngine::HasValidData(aDataHelper.GetTransferable());
2626 PointerStyle SdXImpressDocument::getPointer()
2628 SolarMutexGuard aGuard;
2629 DrawViewShell* pViewShell = GetViewShell();
2630 if (!pViewShell)
2631 return PointerStyle::Arrow;
2633 Window* pWindow = pViewShell->GetActiveWindow();
2634 if (!pWindow)
2635 return PointerStyle::Arrow;
2637 return pWindow->GetPointer();
2640 uno::Reference< i18n::XForbiddenCharacters > SdXImpressDocument::getForbiddenCharsTable()
2642 uno::Reference< i18n::XForbiddenCharacters > xForb(mxForbiddenCharacters);
2644 if( !xForb.is() )
2645 mxForbiddenCharacters = xForb = new SdUnoForbiddenCharsTable( mpDoc );
2647 return xForb;
2650 void SdXImpressDocument::initializeDocument()
2652 if( mbClipBoard )
2653 return;
2655 switch( mpDoc->GetPageCount() )
2657 case 1:
2659 // nasty hack to detect clipboard document
2660 mbClipBoard = true;
2661 break;
2663 case 0:
2665 mpDoc->CreateFirstPages();
2666 mpDoc->StopWorkStartupDelay();
2667 break;
2672 SdrModel& SdXImpressDocument::getSdrModelFromUnoModel() const
2674 OSL_ENSURE(GetDoc(), "No SdrModel in draw/Impress, should not happen");
2675 return *GetDoc(); // TTTT should be reference
2678 void SAL_CALL SdXImpressDocument::dispose()
2680 if( mbDisposed )
2681 return;
2683 ::SolarMutexGuard aGuard;
2685 if( mpDoc )
2687 EndListening( *mpDoc );
2688 mpDoc = nullptr;
2691 // Call the base class dispose() before setting the mbDisposed flag
2692 // to true. The reason for this is that if close() has not yet been
2693 // called this is done in SfxBaseModel::dispose(). At the end of
2694 // that dispose() is called again. It is important to forward this
2695 // second dispose() to the base class, too.
2696 // As a consequence the following code has to be able to be run twice.
2697 SfxBaseModel::dispose();
2698 mbDisposed = true;
2700 uno::Reference< container::XNameAccess > xLinks( mxLinks );
2701 if( xLinks.is() )
2703 uno::Reference< lang::XComponent > xComp( xLinks, uno::UNO_QUERY );
2704 if( xComp.is() )
2705 xComp->dispose();
2707 xLinks = nullptr;
2710 uno::Reference< drawing::XDrawPages > xDrawPagesAccess( mxDrawPagesAccess );
2711 if( xDrawPagesAccess.is() )
2713 uno::Reference< lang::XComponent > xComp( xDrawPagesAccess, uno::UNO_QUERY );
2714 if( xComp.is() )
2715 xComp->dispose();
2717 xDrawPagesAccess = nullptr;
2720 uno::Reference< drawing::XDrawPages > xMasterPagesAccess( mxMasterPagesAccess );
2721 if( xDrawPagesAccess.is() )
2723 uno::Reference< lang::XComponent > xComp( xMasterPagesAccess, uno::UNO_QUERY );
2724 if( xComp.is() )
2725 xComp->dispose();
2727 xDrawPagesAccess = nullptr;
2730 uno::Reference< container::XNameAccess > xLayerManager( mxLayerManager );
2731 if( xLayerManager.is() )
2733 uno::Reference< lang::XComponent > xComp( xLayerManager, uno::UNO_QUERY );
2734 if( xComp.is() )
2735 xComp->dispose();
2737 xLayerManager = nullptr;
2740 uno::Reference< container::XNameContainer > xCustomPresentationAccess( mxCustomPresentationAccess );
2741 if( xCustomPresentationAccess.is() )
2743 uno::Reference< lang::XComponent > xComp( xCustomPresentationAccess, uno::UNO_QUERY );
2744 if( xComp.is() )
2745 xComp->dispose();
2747 xCustomPresentationAccess = nullptr;
2750 mxDashTable = nullptr;
2751 mxGradientTable = nullptr;
2752 mxHatchTable = nullptr;
2753 mxBitmapTable = nullptr;
2754 mxTransGradientTable = nullptr;
2755 mxMarkerTable = nullptr;
2756 mxDrawingPool = nullptr;
2759 // class SdDrawPagesAccess
2761 SdDrawPagesAccess::SdDrawPagesAccess( SdXImpressDocument& rMyModel ) throw()
2762 : mpModel( &rMyModel)
2766 SdDrawPagesAccess::~SdDrawPagesAccess() throw()
2770 // XIndexAccess
2771 sal_Int32 SAL_CALL SdDrawPagesAccess::getCount()
2773 ::SolarMutexGuard aGuard;
2775 if( nullptr == mpModel )
2776 throw lang::DisposedException();
2778 return mpModel->mpDoc->GetSdPageCount( PageKind::Standard );
2781 uno::Any SAL_CALL SdDrawPagesAccess::getByIndex( sal_Int32 Index )
2783 ::SolarMutexGuard aGuard;
2785 if( nullptr == mpModel )
2786 throw lang::DisposedException();
2788 uno::Any aAny;
2790 if( (Index < 0) || (Index >= mpModel->mpDoc->GetSdPageCount( PageKind::Standard ) ) )
2791 throw lang::IndexOutOfBoundsException();
2793 SdPage* pPage = mpModel->mpDoc->GetSdPage( static_cast<sal_uInt16>(Index), PageKind::Standard );
2794 if( pPage )
2796 uno::Reference< drawing::XDrawPage > xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY );
2797 aAny <<= xDrawPage;
2800 return aAny;
2803 // XNameAccess
2804 uno::Any SAL_CALL SdDrawPagesAccess::getByName( const OUString& aName )
2806 ::SolarMutexGuard aGuard;
2808 if( nullptr == mpModel )
2809 throw lang::DisposedException();
2811 if( !aName.isEmpty() )
2813 const sal_uInt16 nCount = mpModel->mpDoc->GetSdPageCount( PageKind::Standard );
2814 sal_uInt16 nPage;
2815 for( nPage = 0; nPage < nCount; nPage++ )
2817 SdPage* pPage = mpModel->mpDoc->GetSdPage( nPage, PageKind::Standard );
2818 if(nullptr == pPage)
2819 continue;
2821 if( aName == SdDrawPage::getPageApiName( pPage ) )
2823 uno::Any aAny;
2824 uno::Reference< drawing::XDrawPage > xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY );
2825 aAny <<= xDrawPage;
2826 return aAny;
2831 throw container::NoSuchElementException();
2834 uno::Sequence< OUString > SAL_CALL SdDrawPagesAccess::getElementNames()
2836 ::SolarMutexGuard aGuard;
2838 if( nullptr == mpModel )
2839 throw lang::DisposedException();
2841 const sal_uInt16 nCount = mpModel->mpDoc->GetSdPageCount( PageKind::Standard );
2842 uno::Sequence< OUString > aNames( nCount );
2843 OUString* pNames = aNames.getArray();
2845 sal_uInt16 nPage;
2846 for( nPage = 0; nPage < nCount; nPage++ )
2848 SdPage* pPage = mpModel->mpDoc->GetSdPage( nPage, PageKind::Standard );
2849 *pNames++ = SdDrawPage::getPageApiName( pPage );
2852 return aNames;
2855 sal_Bool SAL_CALL SdDrawPagesAccess::hasByName( const OUString& aName )
2857 ::SolarMutexGuard aGuard;
2859 if( nullptr == mpModel )
2860 throw lang::DisposedException();
2862 const sal_uInt16 nCount = mpModel->mpDoc->GetSdPageCount( PageKind::Standard );
2863 sal_uInt16 nPage;
2864 for( nPage = 0; nPage < nCount; nPage++ )
2866 SdPage* pPage = mpModel->mpDoc->GetSdPage( nPage, PageKind::Standard );
2867 if(nullptr == pPage)
2868 continue;
2870 if( aName == SdDrawPage::getPageApiName( pPage ) )
2871 return true;
2874 return false;
2877 // XElementAccess
2878 uno::Type SAL_CALL SdDrawPagesAccess::getElementType()
2880 return cppu::UnoType<drawing::XDrawPage>::get();
2883 sal_Bool SAL_CALL SdDrawPagesAccess::hasElements()
2885 return getCount() > 0;
2888 // XDrawPages
2891 * Creates a new page with model at the specified position.
2892 * @returns corresponding SdDrawPage
2894 uno::Reference< drawing::XDrawPage > SAL_CALL SdDrawPagesAccess::insertNewByIndex( sal_Int32 nIndex )
2896 ::SolarMutexGuard aGuard;
2897 comphelper::ProfileZone aZone("insertNewByIndex");
2899 if( nullptr == mpModel )
2900 throw lang::DisposedException();
2902 if( mpModel->mpDoc )
2904 SdPage* pPage = mpModel->InsertSdPage( static_cast<sal_uInt16>(nIndex), false );
2905 if( pPage )
2907 uno::Reference< drawing::XDrawPage > xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY );
2908 return xDrawPage;
2911 uno::Reference< drawing::XDrawPage > xDrawPage;
2912 return xDrawPage;
2916 * Removes the specified SdDrawPage from the model and the internal list. It
2917 * only works, if there is at least one *normal* page in the model after
2918 * removing this page.
2920 void SAL_CALL SdDrawPagesAccess::remove( const uno::Reference< drawing::XDrawPage >& xPage )
2922 ::SolarMutexGuard aGuard;
2924 if( nullptr == mpModel || mpModel->mpDoc == nullptr )
2925 throw lang::DisposedException();
2927 SdDrawDocument& rDoc = *mpModel->mpDoc;
2929 sal_uInt16 nPageCount = rDoc.GetSdPageCount( PageKind::Standard );
2930 if( nPageCount > 1 )
2932 // get pPage from xPage and determine the Id (nPos ) afterwards
2933 SdDrawPage* pSvxPage = SdDrawPage::getImplementation( xPage );
2934 if( pSvxPage )
2936 SdPage* pPage = static_cast<SdPage*>(pSvxPage->GetSdrPage());
2937 if(pPage && ( pPage->GetPageKind() == PageKind::Standard ) )
2939 sal_uInt16 nPage = pPage->GetPageNum();
2941 SdPage* pNotesPage = static_cast< SdPage* >( rDoc.GetPage( nPage+1 ) );
2943 bool bUndo = rDoc.IsUndoEnabled();
2944 if( bUndo )
2946 // Add undo actions and delete the pages. The order of adding
2947 // the undo actions is important.
2948 rDoc.BegUndo( SdResId( STR_UNDO_DELETEPAGES ) );
2949 rDoc.AddUndo(rDoc.GetSdrUndoFactory().CreateUndoDeletePage(*pNotesPage));
2950 rDoc.AddUndo(rDoc.GetSdrUndoFactory().CreateUndoDeletePage(*pPage));
2953 rDoc.RemovePage( nPage ); // the page
2954 rDoc.RemovePage( nPage ); // the notes page
2956 if( bUndo )
2958 rDoc.EndUndo();
2960 else
2962 delete pNotesPage;
2963 delete pPage;
2969 mpModel->SetModified();
2972 // XServiceInfo
2974 OUString SAL_CALL SdDrawPagesAccess::getImplementationName( )
2976 return OUString( "SdDrawPagesAccess" );
2979 sal_Bool SAL_CALL SdDrawPagesAccess::supportsService( const OUString& ServiceName )
2981 return cppu::supportsService(this, ServiceName);
2984 uno::Sequence< OUString > SAL_CALL SdDrawPagesAccess::getSupportedServiceNames( )
2986 OUString aService( "com.sun.star.drawing.DrawPages" );
2987 uno::Sequence< OUString > aSeq( &aService, 1 );
2988 return aSeq;
2991 // XComponent
2992 void SAL_CALL SdDrawPagesAccess::dispose( )
2994 mpModel = nullptr;
2997 void SAL_CALL SdDrawPagesAccess::addEventListener( const uno::Reference< lang::XEventListener >& )
2999 OSL_FAIL( "not implemented!" );
3002 void SAL_CALL SdDrawPagesAccess::removeEventListener( const uno::Reference< lang::XEventListener >& )
3004 OSL_FAIL( "not implemented!" );
3007 // class SdMasterPagesAccess
3009 SdMasterPagesAccess::SdMasterPagesAccess( SdXImpressDocument& rMyModel ) throw()
3010 : mpModel(&rMyModel)
3014 SdMasterPagesAccess::~SdMasterPagesAccess() throw()
3018 // XComponent
3019 void SAL_CALL SdMasterPagesAccess::dispose( )
3021 mpModel = nullptr;
3024 void SAL_CALL SdMasterPagesAccess::addEventListener( const uno::Reference< lang::XEventListener >& )
3026 OSL_FAIL( "not implemented!" );
3029 void SAL_CALL SdMasterPagesAccess::removeEventListener( const uno::Reference< lang::XEventListener >& )
3031 OSL_FAIL( "not implemented!" );
3034 // XIndexAccess
3035 sal_Int32 SAL_CALL SdMasterPagesAccess::getCount()
3037 ::SolarMutexGuard aGuard;
3039 if( nullptr == mpModel->mpDoc )
3040 throw lang::DisposedException();
3042 return mpModel->mpDoc->GetMasterSdPageCount(PageKind::Standard);
3046 * Provides a drawing::XDrawPage interface for accessing the Masterpage at the
3047 * specified position in the model.
3049 uno::Any SAL_CALL SdMasterPagesAccess::getByIndex( sal_Int32 Index )
3051 ::SolarMutexGuard aGuard;
3052 comphelper::ProfileZone aZone("SdMasterPagesAccess::getByIndex");
3054 if( nullptr == mpModel )
3055 throw lang::DisposedException();
3057 uno::Any aAny;
3059 if( (Index < 0) || (Index >= mpModel->mpDoc->GetMasterSdPageCount( PageKind::Standard ) ) )
3060 throw lang::IndexOutOfBoundsException();
3062 SdPage* pPage = mpModel->mpDoc->GetMasterSdPage( static_cast<sal_uInt16>(Index), PageKind::Standard );
3063 if( pPage )
3065 uno::Reference< drawing::XDrawPage > xDrawPage( pPage->getUnoPage(), uno::UNO_QUERY );
3066 aAny <<= xDrawPage;
3069 return aAny;
3072 // XElementAccess
3073 uno::Type SAL_CALL SdMasterPagesAccess::getElementType()
3075 return cppu::UnoType<drawing::XDrawPage>::get();
3078 sal_Bool SAL_CALL SdMasterPagesAccess::hasElements()
3080 return getCount() > 0;
3083 // XDrawPages
3084 uno::Reference< drawing::XDrawPage > SAL_CALL SdMasterPagesAccess::insertNewByIndex( sal_Int32 nInsertPos )
3086 ::SolarMutexGuard aGuard;
3088 if( nullptr == mpModel )
3089 throw lang::DisposedException();
3091 uno::Reference< drawing::XDrawPage > xDrawPage;
3093 SdDrawDocument* pDoc = mpModel->mpDoc;
3094 if( pDoc )
3096 // calculate internal index and check for range errors
3097 const sal_Int32 nMPageCount = pDoc->GetMasterPageCount();
3098 nInsertPos = nInsertPos * 2 + 1;
3099 if( nInsertPos < 0 || nInsertPos > nMPageCount )
3100 nInsertPos = nMPageCount;
3102 // now generate a unique name for the new masterpage
3103 const OUString aStdPrefix( SdResId(STR_LAYOUT_DEFAULT_NAME) );
3104 OUString aPrefix( aStdPrefix );
3106 bool bUnique = true;
3108 std::vector<OUString> aPageNames;
3109 for (sal_Int32 nMaster = 1; nMaster < nMPageCount; ++nMaster)
3111 const SdPage* pPage = static_cast<const SdPage*>(pDoc->GetMasterPage(static_cast<sal_uInt16>(nMaster)));
3112 if (!pPage)
3113 continue;
3114 aPageNames.push_back(pPage->GetName());
3115 if (aPageNames.back() == aPrefix)
3116 bUnique = false;
3119 sal_Int32 i = 0;
3120 while (!bUnique)
3122 aPrefix = aStdPrefix + " " + OUString::number(++i);
3123 bUnique = std::find(aPageNames.begin(), aPageNames.end(), aPrefix) == aPageNames.end();
3126 OUString aLayoutName( aPrefix );
3127 aLayoutName += SD_LT_SEPARATOR;
3128 aLayoutName += STR_LAYOUT_OUTLINE;
3130 // create styles
3131 static_cast<SdStyleSheetPool*>(pDoc->GetStyleSheetPool())->CreateLayoutStyleSheets( aPrefix );
3133 // get the first page for initial size and border settings
3134 SdPage* pPage = mpModel->mpDoc->GetSdPage( sal_uInt16(0), PageKind::Standard );
3135 SdPage* pRefNotesPage = mpModel->mpDoc->GetSdPage( sal_uInt16(0), PageKind::Notes);
3137 // create and insert new draw masterpage
3138 SdPage* pMPage = mpModel->mpDoc->AllocSdPage(true);
3139 pMPage->SetSize( pPage->GetSize() );
3140 pMPage->SetBorder( pPage->GetLeftBorder(),
3141 pPage->GetUpperBorder(),
3142 pPage->GetRightBorder(),
3143 pPage->GetLowerBorder() );
3144 pMPage->SetLayoutName( aLayoutName );
3145 pDoc->InsertMasterPage(pMPage, static_cast<sal_uInt16>(nInsertPos));
3148 // ensure default MasterPage fill
3149 pMPage->EnsureMasterPageDefaultBackground();
3152 xDrawPage.set( pMPage->getUnoPage(), uno::UNO_QUERY );
3154 // create and insert new notes masterpage
3155 SdPage* pMNotesPage = mpModel->mpDoc->AllocSdPage(true);
3156 pMNotesPage->SetSize( pRefNotesPage->GetSize() );
3157 pMNotesPage->SetPageKind(PageKind::Notes);
3158 pMNotesPage->SetBorder( pRefNotesPage->GetLeftBorder(),
3159 pRefNotesPage->GetUpperBorder(),
3160 pRefNotesPage->GetRightBorder(),
3161 pRefNotesPage->GetLowerBorder() );
3162 pMNotesPage->SetLayoutName( aLayoutName );
3163 pDoc->InsertMasterPage(pMNotesPage, static_cast<sal_uInt16>(nInsertPos) + 1);
3164 pMNotesPage->SetAutoLayout(AUTOLAYOUT_NOTES, true, true);
3165 mpModel->SetModified();
3168 return xDrawPage;
3172 * Removes the specified SdMasterPage from the model and the internal list. It
3173 * only works, if there is no *normal* page using this page as MasterPage in
3174 * the model.
3176 void SAL_CALL SdMasterPagesAccess::remove( const uno::Reference< drawing::XDrawPage >& xPage )
3178 ::SolarMutexGuard aGuard;
3180 if( nullptr == mpModel || mpModel->mpDoc == nullptr )
3181 throw lang::DisposedException();
3183 SdMasterPage* pSdPage = SdMasterPage::getImplementation( xPage );
3184 if(pSdPage == nullptr)
3185 return;
3187 SdPage* pPage = dynamic_cast< SdPage* > (pSdPage->GetSdrPage());
3189 DBG_ASSERT( pPage && pPage->IsMasterPage(), "SdMasterPage is not masterpage?");
3191 if( !pPage || !pPage->IsMasterPage() || (mpModel->mpDoc->GetMasterPageUserCount(pPage) > 0))
3192 return; //Todo: this should be excepted
3194 // only standard pages can be removed directly
3195 if( pPage->GetPageKind() != PageKind::Standard )
3196 return;
3198 sal_uInt16 nPage = pPage->GetPageNum();
3200 SdDrawDocument& rDoc = *mpModel->mpDoc;
3202 SdPage* pNotesPage = static_cast< SdPage* >( rDoc.GetMasterPage( nPage+1 ) );
3204 bool bUndo = rDoc.IsUndoEnabled();
3205 if( bUndo )
3207 // Add undo actions and delete the pages. The order of adding
3208 // the undo actions is important.
3209 rDoc.BegUndo( SdResId( STR_UNDO_DELETEPAGES ) );
3210 rDoc.AddUndo(rDoc.GetSdrUndoFactory().CreateUndoDeletePage(*pNotesPage));
3211 rDoc.AddUndo(rDoc.GetSdrUndoFactory().CreateUndoDeletePage(*pPage));
3214 // remove both pages
3215 rDoc.RemoveMasterPage( nPage );
3216 rDoc.RemoveMasterPage( nPage );
3218 if( bUndo )
3220 rDoc.EndUndo();
3222 else
3224 delete pNotesPage;
3225 delete pPage;
3229 // XServiceInfo
3231 OUString SAL_CALL SdMasterPagesAccess::getImplementationName( )
3233 return OUString( "SdMasterPagesAccess" );
3236 sal_Bool SAL_CALL SdMasterPagesAccess::supportsService( const OUString& ServiceName )
3238 return cppu::supportsService(this, ServiceName);
3241 uno::Sequence< OUString > SAL_CALL SdMasterPagesAccess::getSupportedServiceNames( )
3243 OUString aService( "com.sun.star.drawing.MasterPages" );
3244 uno::Sequence< OUString > aSeq( &aService, 1 );
3245 return aSeq;
3248 // class SdDocLinkTargets
3250 SdDocLinkTargets::SdDocLinkTargets( SdXImpressDocument& rMyModel ) throw()
3251 : mpModel( &rMyModel )
3255 SdDocLinkTargets::~SdDocLinkTargets() throw()
3259 // XComponent
3260 void SAL_CALL SdDocLinkTargets::dispose( )
3262 mpModel = nullptr;
3265 void SAL_CALL SdDocLinkTargets::addEventListener( const uno::Reference< lang::XEventListener >& )
3267 OSL_FAIL( "not implemented!" );
3270 void SAL_CALL SdDocLinkTargets::removeEventListener( const uno::Reference< lang::XEventListener >& )
3272 OSL_FAIL( "not implemented!" );
3275 // XNameAccess
3276 uno::Any SAL_CALL SdDocLinkTargets::getByName( const OUString& aName )
3278 ::SolarMutexGuard aGuard;
3280 if( nullptr == mpModel )
3281 throw lang::DisposedException();
3283 SdPage* pPage = FindPage( aName );
3285 if( pPage == nullptr )
3286 throw container::NoSuchElementException();
3288 uno::Any aAny;
3290 uno::Reference< beans::XPropertySet > xProps( pPage->getUnoPage(), uno::UNO_QUERY );
3291 if( xProps.is() )
3292 aAny <<= xProps;
3294 return aAny;
3297 uno::Sequence< OUString > SAL_CALL SdDocLinkTargets::getElementNames()
3299 ::SolarMutexGuard aGuard;
3301 if( nullptr == mpModel )
3302 throw lang::DisposedException();
3304 SdDrawDocument* pDoc = mpModel->GetDoc();
3305 if( pDoc == nullptr )
3307 uno::Sequence< OUString > aSeq;
3308 return aSeq;
3311 if( pDoc->GetDocumentType() == DocumentType::Draw )
3313 const sal_uInt16 nMaxPages = pDoc->GetSdPageCount( PageKind::Standard );
3314 const sal_uInt16 nMaxMasterPages = pDoc->GetMasterSdPageCount( PageKind::Standard );
3316 uno::Sequence< OUString > aSeq( nMaxPages + nMaxMasterPages );
3317 OUString* pStr = aSeq.getArray();
3319 sal_uInt16 nPage;
3320 // standard pages
3321 for( nPage = 0; nPage < nMaxPages; nPage++ )
3322 *pStr++ = pDoc->GetSdPage( nPage, PageKind::Standard )->GetName();
3324 // master pages
3325 for( nPage = 0; nPage < nMaxMasterPages; nPage++ )
3326 *pStr++ = pDoc->GetMasterSdPage( nPage, PageKind::Standard )->GetName();
3327 return aSeq;
3329 else
3331 const sal_uInt16 nMaxPages = pDoc->GetPageCount();
3332 const sal_uInt16 nMaxMasterPages = pDoc->GetMasterPageCount();
3334 uno::Sequence< OUString > aSeq( nMaxPages + nMaxMasterPages );
3335 OUString* pStr = aSeq.getArray();
3337 sal_uInt16 nPage;
3338 // standard pages
3339 for( nPage = 0; nPage < nMaxPages; nPage++ )
3340 *pStr++ = static_cast<SdPage*>(pDoc->GetPage( nPage ))->GetName();
3342 // master pages
3343 for( nPage = 0; nPage < nMaxMasterPages; nPage++ )
3344 *pStr++ = static_cast<SdPage*>(pDoc->GetMasterPage( nPage ))->GetName();
3345 return aSeq;
3349 sal_Bool SAL_CALL SdDocLinkTargets::hasByName( const OUString& aName )
3351 ::SolarMutexGuard aGuard;
3353 if( nullptr == mpModel )
3354 throw lang::DisposedException();
3356 return FindPage( aName ) != nullptr;
3359 // container::XElementAccess
3360 uno::Type SAL_CALL SdDocLinkTargets::getElementType()
3362 return cppu::UnoType<beans::XPropertySet>::get();
3365 sal_Bool SAL_CALL SdDocLinkTargets::hasElements()
3367 ::SolarMutexGuard aGuard;
3369 if( nullptr == mpModel )
3370 throw lang::DisposedException();
3372 return mpModel->GetDoc() != nullptr;
3375 SdPage* SdDocLinkTargets::FindPage( const OUString& rName ) const
3377 SdDrawDocument* pDoc = mpModel->GetDoc();
3378 if( pDoc == nullptr )
3379 return nullptr;
3381 const sal_uInt16 nMaxPages = pDoc->GetPageCount();
3382 const sal_uInt16 nMaxMasterPages = pDoc->GetMasterPageCount();
3384 sal_uInt16 nPage;
3385 SdPage* pPage;
3387 const bool bDraw = pDoc->GetDocumentType() == DocumentType::Draw;
3389 // standard pages
3390 for( nPage = 0; nPage < nMaxPages; nPage++ )
3392 pPage = static_cast<SdPage*>(pDoc->GetPage( nPage ));
3393 if( (pPage->GetName() == rName) && (!bDraw || (pPage->GetPageKind() == PageKind::Standard)) )
3394 return pPage;
3397 // master pages
3398 for( nPage = 0; nPage < nMaxMasterPages; nPage++ )
3400 pPage = static_cast<SdPage*>(pDoc->GetMasterPage( nPage ));
3401 if( (pPage->GetName() == rName) && (!bDraw || (pPage->GetPageKind() == PageKind::Standard)) )
3402 return pPage;
3405 return nullptr;
3408 // XServiceInfo
3409 OUString SAL_CALL SdDocLinkTargets::getImplementationName()
3411 return OUString( "SdDocLinkTargets" );
3414 sal_Bool SAL_CALL SdDocLinkTargets::supportsService( const OUString& ServiceName )
3416 return cppu::supportsService( this, ServiceName );
3419 uno::Sequence< OUString > SAL_CALL SdDocLinkTargets::getSupportedServiceNames()
3421 const OUString aSN( "com.sun.star.document.LinkTargets" );
3422 uno::Sequence< OUString > aSeq( &aSN, 1 );
3423 return aSeq;
3426 rtl::Reference< SdXImpressDocument > SdXImpressDocument::GetModel( SdDrawDocument const & rDocument )
3428 rtl::Reference< SdXImpressDocument > xRet;
3429 ::sd::DrawDocShell* pDocShell(rDocument.GetDocSh());
3430 if( pDocShell )
3432 uno::Reference<frame::XModel> xModel(pDocShell->GetModel());
3434 xRet.set( dynamic_cast< SdXImpressDocument* >( xModel.get() ) );
3437 return xRet;
3440 void NotifyDocumentEvent( SdDrawDocument const & rDocument, const OUString& rEventName )
3442 rtl::Reference< SdXImpressDocument > xModel( SdXImpressDocument::GetModel( rDocument ) );
3444 if( xModel.is() )
3446 uno::Reference< uno::XInterface > xSource( static_cast<uno::XWeak*>( xModel.get() ) );
3447 css::document::EventObject aEvent( xSource, rEventName );
3448 xModel->notifyEvent(aEvent );
3452 void NotifyDocumentEvent( SdDrawDocument const & rDocument, const OUString& rEventName, const uno::Reference< uno::XInterface >& xSource )
3454 rtl::Reference< SdXImpressDocument > xModel( SdXImpressDocument::GetModel( rDocument ) );
3456 if( xModel.is() )
3458 css::document::EventObject aEvent( xSource, rEventName );
3459 xModel->notifyEvent(aEvent );
3463 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */