1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <libxml/xmlwriter.h>
22 #include "PageListWatcher.hxx"
23 #include <com/sun/star/document/PrinterIndependentLayout.hpp>
24 #include <com/sun/star/i18n/ScriptType.hpp>
25 #include <com/sun/star/beans/XPropertyContainer.hpp>
26 #include <com/sun/star/beans/PropertyAttribute.hpp>
27 #include <com/sun/star/document/XDocumentProperties.hpp>
28 #include <com/sun/star/frame/XModel.hpp>
29 #include <editeng/forbiddencharacterstable.hxx>
31 #include <svl/srchitem.hxx>
32 #include <editeng/eeitem.hxx>
33 #include <editeng/scriptspaceitem.hxx>
34 #include <tools/debug.hxx>
36 #include <unotools/configmgr.hxx>
37 #include <unotools/useroptions.hxx>
38 #include <officecfg/Office/Impress.hxx>
39 #include <officecfg/Office/Draw.hxx>
41 #include <sfx2/linkmgr.hxx>
42 #include <Outliner.hxx>
44 #include <editeng/editstat.hxx>
45 #include <svx/svdotext.hxx>
46 #include <editeng/unolingu.hxx>
47 #include <svl/itempool.hxx>
48 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
49 #include <com/sun/star/beans/XPropertySet.hpp>
50 #include <editeng/outlobj.hxx>
51 #include <comphelper/getexpandeduri.hxx>
52 #include <i18nlangtag/mslangid.hxx>
53 #include <i18nlangtag/languagetag.hxx>
54 #include <unotools/charclass.hxx>
55 #include <comphelper/processfactory.hxx>
56 #include <unotools/lingucfg.hxx>
57 #include <unotools/localedatawrapper.hxx>
58 #include <unotools/syslocale.hxx>
59 #include <com/sun/star/uno/Reference.hxx>
60 #include <com/sun/star/xml/dom/XDocumentBuilder.hpp>
61 #include <com/sun/star/xml/dom/XDocument.hpp>
62 #include <com/sun/star/xml/dom/XNodeList.hpp>
63 #include <com/sun/star/xml/dom/DocumentBuilder.hpp>
64 #include <com/sun/star/uno/XComponentContext.hpp>
65 #include <rtl/ustring.hxx>
67 #include <editeng/outliner.hxx>
68 #include <drawdoc.hxx>
70 #include <strings.hrc>
72 #include <stlpool.hxx>
73 #include <sdresid.hxx>
74 #include <customshowlist.hxx>
75 #include <DrawDocShell.hxx>
76 #include <GraphicDocShell.hxx>
78 #include <optsitem.hxx>
79 #include <FrameView.hxx>
80 #include <undo/undomanager.hxx>
81 #include <sdundogr.hxx>
82 #include <undopage.hxx>
83 #include <vcl/settings.hxx>
84 #include <vcl/svapp.hxx>
85 #include <unokywds.hxx>
87 namespace com::sun::star::linguistic2
{ class XHyphenator
; }
88 namespace com::sun::star::linguistic2
{ class XSpellChecker1
; }
91 using namespace ::com::sun::star
;
92 using namespace ::com::sun::star::uno
;
93 using namespace ::com::sun::star::linguistic2
;
95 using namespace com::sun::star::xml::dom
;
96 using ::com::sun::star::uno::Reference
;
99 SdDrawDocument
* SdDrawDocument::s_pDocLockedInsertingLinks
= nullptr;
101 PresentationSettings::PresentationSettings()
106 mbMouseVisible( false ),
107 mbMouseAsPen( false ),
108 mbLockedPages( false ),
109 mbAlwaysOnTop( false ),
110 mbFullScreen( true ),
111 mbAnimationAllowed( true ),
113 mbShowPauseLogo( false ),
114 mbStartCustomShow( false ),
115 mbInteractive( true )
119 SdDrawDocument::SdDrawDocument(DocumentType eType
, SfxObjectShell
* pDrDocSh
)
123 , mpDocSh(static_cast< ::sd::DrawDocShell
*>(pDrDocSh
))
124 , mpCreatingTransferable( nullptr )
125 , mbHasOnlineSpellErrors(false)
126 , mbInitialOnlineSpellingEnabled(true)
127 , mbNewOrLoadCompleted(false)
128 , mbOnlineSpell(false)
129 , mnStartWithPresentation(0)
130 , mbExitAfterPresenting( false )
131 , meLanguage( LANGUAGE_SYSTEM
)
132 , meLanguageCJK( LANGUAGE_SYSTEM
)
133 , meLanguageCTL( LANGUAGE_SYSTEM
)
134 , mePageNumType(SVX_NUM_ARABIC
)
135 , mbAllocDocSh(false)
137 , mbEmbedFonts(false)
138 , mbEmbedUsedFontsOnly(false)
139 , mbEmbedFontScriptLatin(true)
140 , mbEmbedFontScriptAsian(true)
141 , mbEmbedFontScriptComplex(true)
142 , mnImagePreferredDPI(0)
144 m_bThemedControls
= false;
146 mpDrawPageListWatcher
.reset(new ImpDrawPageListWatcher(*this));
147 mpMasterPageListWatcher
.reset(new ImpMasterPageListWatcher(*this));
149 this->SetImpress(true);
153 SetObjectShell(pDrDocSh
); // for VCDrawModel
160 // Set measuring unit (of the application) and scale (of SdMod)
162 SdOptions
* pOptions
= SdModule::get()->GetSdOptions(meDocType
);
163 nX
= officecfg::Office::Draw::Zoom::ScaleX::get();
164 nY
= officecfg::Office::Draw::Zoom::ScaleY::get();
165 SvtSysLocale aSysLocale
;
167 // Allow UI scale only for draw documents.
168 if( eType
== DocumentType::Draw
)
169 if (aSysLocale
.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric
)
170 SetUIUnit( static_cast<FieldUnit
>(officecfg::Office::Draw::Layout::Other::MeasureUnit::Metric::get()), Fraction( nX
, nY
) ); // user-defined
172 SetUIUnit( static_cast<FieldUnit
>(officecfg::Office::Draw::Layout::Other::MeasureUnit::NonMetric::get()), Fraction( nX
, nY
) ); // user-defined
174 if (aSysLocale
.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric
)
175 SetUIUnit( static_cast<FieldUnit
>(officecfg::Office::Impress::Layout::Other::MeasureUnit::Metric::get()), Fraction( 1, 1 ) ); // default
177 SetUIUnit( static_cast<FieldUnit
>(officecfg::Office::Impress::Layout::Other::MeasureUnit::NonMetric::get()), Fraction( 1, 1 ) ); // default
179 SetScaleUnit(MapUnit::Map100thMM
);
180 SetDefaultFontHeight(o3tl::convert(24, o3tl::Length::pt
, o3tl::Length::mm100
));
182 m_pItemPool
->SetDefaultMetric(MapUnit::Map100thMM
);
185 // DrawingEngine has to know where it is...
186 FmFormModel::SetStyleSheetPool( new SdStyleSheetPool( GetPool(), this ) );
188 // Set StyleSheetPool for DrawOutliner, so text objects can be read correctly.
189 // The link to the StyleRequest handler of the document is set later, in
190 // NewOrLoadCompleted, because only then do all the templates exist.
191 SdrOutliner
& rOutliner
= GetDrawOutliner();
192 rOutliner
.SetStyleSheetPool(static_cast<SfxStyleSheetPool
*>(GetStyleSheetPool()));
193 SetCalcFieldValueHdl( &rOutliner
);
195 // set linguistic options
196 if (!comphelper::IsFuzzing())
198 const SvtLinguConfig aLinguConfig
;
199 SvtLinguOptions aOptions
;
200 aLinguConfig
.GetOptions( aOptions
);
202 SetLanguage( MsLangId::resolveSystemLanguageByScriptType(aOptions
.nDefaultLanguage
,
203 css::i18n::ScriptType::LATIN
), EE_CHAR_LANGUAGE
);
204 SetLanguage( MsLangId::resolveSystemLanguageByScriptType(aOptions
.nDefaultLanguage_CJK
,
205 css::i18n::ScriptType::ASIAN
), EE_CHAR_LANGUAGE_CJK
);
206 SetLanguage( MsLangId::resolveSystemLanguageByScriptType(aOptions
.nDefaultLanguage_CTL
,
207 css::i18n::ScriptType::COMPLEX
), EE_CHAR_LANGUAGE_CTL
);
209 mbOnlineSpell
= aOptions
.bIsSpellAuto
;
212 LanguageType eRealLanguage
= MsLangId::getRealLanguage( meLanguage
);
213 moCharClass
.emplace(LanguageTag( eRealLanguage
));
215 // If the current application language is a language that uses right-to-left text...
216 LanguageType eRealCTLLanguage
= Application::GetSettings().GetLanguageTag().getLanguageType();
218 // for korean and japanese languages we have a different default for apply spacing between asian, latin and ctl text
219 if (MsLangId::isKorean(eRealCTLLanguage
) || (LANGUAGE_JAPANESE
== eRealCTLLanguage
))
221 GetPool().GetSecondaryPool()->SetUserDefaultItem( SvxScriptSpaceItem( false, EE_PARA_ASIANCJKSPACING
) );
224 // Set DefTab and SpellOptions for the SD module
225 if (eType
== DocumentType::Impress
)
226 if (aSysLocale
.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric
)
227 SetDefaultTabulator( static_cast<sal_uInt16
>(officecfg::Office::Impress::Layout::Other::TabStop::Metric::get()) );
229 SetDefaultTabulator( static_cast<sal_uInt16
>(officecfg::Office::Impress::Layout::Other::TabStop::NonMetric::get()) );
231 if (aSysLocale
.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric
)
232 SetDefaultTabulator( static_cast<sal_uInt16
>(officecfg::Office::Draw::Layout::Other::TabStop::Metric::get()) );
234 SetDefaultTabulator( static_cast<sal_uInt16
>(officecfg::Office::Draw::Layout::Other::TabStop::NonMetric::get()) );
238 Reference
< XSpellChecker1
> xSpellChecker( LinguMgr::GetSpellChecker() );
239 if ( xSpellChecker
.is() )
240 rOutliner
.SetSpeller( xSpellChecker
);
242 Reference
< XHyphenator
> xHyphenator( LinguMgr::GetHyphenator() );
243 if( xHyphenator
.is() )
244 rOutliner
.SetHyphenator( xHyphenator
);
246 SetForbiddenCharsTable(SvxForbiddenCharactersTable::makeForbiddenCharactersTable(::comphelper::getProcessComponentContext()));
250 OSL_FAIL("Can't get SpellChecker");
253 rOutliner
.SetDefaultLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() );
257 SetLinkManager( new sfx2::LinkManager(mpDocSh
) );
260 EEControlBits nCntrl
= rOutliner
.GetControlWord();
261 nCntrl
|= EEControlBits::ALLOWBIGOBJS
;
264 nCntrl
|= EEControlBits::ONLINESPELLING
;
266 nCntrl
&= ~EEControlBits::ONLINESPELLING
;
268 nCntrl
&= ~ EEControlBits::ULSPACESUMMATION
;
269 if ( meDocType
!= DocumentType::Impress
)
270 SetSummationOfParagraphs( false );
273 SetSummationOfParagraphs( pOptions
->IsSummationOfParagraphs() );
274 if ( pOptions
->IsSummationOfParagraphs() )
275 nCntrl
|= EEControlBits::ULSPACESUMMATION
;
277 rOutliner
.SetControlWord(nCntrl
);
279 // Initialize the printer independent layout mode
280 SetPrinterIndependentLayout (pOptions
->GetPrinterIndependentLayout());
282 // Set the StyleSheetPool for HitTestOutliner.
283 // The link to the StyleRequest handler of the document is set later, in
284 // NewOrLoadCompleted, because only then do all the templates exist.
285 m_pHitTestOutliner
->SetStyleSheetPool( static_cast<SfxStyleSheetPool
*>(GetStyleSheetPool()) );
287 SetCalcFieldValueHdl( m_pHitTestOutliner
.get() );
291 Reference
< XSpellChecker1
> xSpellChecker( LinguMgr::GetSpellChecker() );
292 if ( xSpellChecker
.is() )
293 m_pHitTestOutliner
->SetSpeller( xSpellChecker
);
295 Reference
< XHyphenator
> xHyphenator( LinguMgr::GetHyphenator() );
296 if( xHyphenator
.is() )
297 m_pHitTestOutliner
->SetHyphenator( xHyphenator
);
301 OSL_FAIL("Can't get SpellChecker");
304 m_pHitTestOutliner
->SetDefaultLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() );
306 EEControlBits nCntrl2
= m_pHitTestOutliner
->GetControlWord();
307 nCntrl2
|= EEControlBits::ALLOWBIGOBJS
;
308 nCntrl2
&= ~EEControlBits::ONLINESPELLING
;
310 nCntrl2
&= ~ EEControlBits::ULSPACESUMMATION
;
311 if ( pOptions
->IsSummationOfParagraphs() )
312 nCntrl2
|= EEControlBits::ULSPACESUMMATION
;
314 m_pHitTestOutliner
->SetControlWord( nCntrl2
);
318 * We create the following default layers on all pages and master pages:
320 * sUNO_LayerName_layout; "layout": default layer for drawing objects of normal pages
321 * localized by SdResId(STR_LAYER_LAYOUT)
323 * sUNO_LayerName_background; "background": background of the master page
324 * localized by SdResId(STR_LAYER_BCKGRND)
325 * (currently unused within normal pages and not visible to users)
327 * sUNO_LayerName_background_objects; "backgroundobjects": objects on the background of master pages
328 * localized by SdResId(STR_LAYER_BCKGRNDOBJ)
329 * (currently unused within normal pages)
331 * sUNO_LayerName_controls; "controls": default layer for controls
332 * localized by SdResId(STR_LAYER_CONTROLS)
333 * (currently special handling in regard to z-order)
335 * sUNO_LayerName_measurelines; "measurelines" : default layer for measure lines
336 * localized by SdResId(STR_LAYER_MEASURELINES)
340 SdrLayerAdmin
& rLayerAdmin
= GetLayerAdmin();
341 rLayerAdmin
.NewLayer( sUNO_LayerName_layout
);
342 rLayerAdmin
.NewLayer( sUNO_LayerName_background
);
343 rLayerAdmin
.NewLayer( sUNO_LayerName_background_objects
);
344 rLayerAdmin
.NewLayer( sUNO_LayerName_controls
);
345 rLayerAdmin
.NewLayer( sUNO_LayerName_measurelines
);
347 rLayerAdmin
.SetControlLayerName(sUNO_LayerName_controls
);
353 SdDrawDocument::~SdDrawDocument()
355 Broadcast(SdrHint(SdrHintKind::ModelCleared
));
357 if (mpWorkStartupTimer
)
359 if ( mpWorkStartupTimer
->IsActive() )
360 mpWorkStartupTimer
->Stop();
362 mpWorkStartupTimer
.reset();
365 StopOnlineSpelling();
366 mpOnlineSearchItem
.reset();
369 SetAllocDocSh(false);
376 if ( !m_pLinkManager
->GetLinks().empty() )
378 m_pLinkManager
->Remove( 0, m_pLinkManager
->GetLinks().size() );
381 delete m_pLinkManager
;
382 m_pLinkManager
= nullptr;
385 maFrameViewList
.clear();
386 mpCustomShowList
.reset();
388 mpInternalOutliner
.reset();
392 void SdDrawDocument::adaptSizeAndBorderForAllPages(
393 const Size
& rNewSize
,
395 ::tools::Long nRight
,
396 ::tools::Long nUpper
,
397 ::tools::Long nLower
)
399 const sal_uInt16
nMasterPageCnt(GetMasterSdPageCount(PageKind::Standard
));
400 const sal_uInt16
nPageCnt(GetSdPageCount(PageKind::Standard
));
402 if(0 == nMasterPageCnt
&& 0 == nPageCnt
)
407 SdPage
* pPage(0 != nPageCnt
? GetSdPage(0, PageKind::Standard
) : GetMasterSdPage(0, PageKind::Standard
));
409 // call fully implemented local version, including getting
410 // some more information from one of the Pages (1st one)
411 AdaptPageSizeForAllPages(
420 pPage
->GetOrientation(),
421 pPage
->GetPaperBin(),
422 pPage
->IsBackgroundFullSize());
424 // adjust handout page to new format of the standard page
427 GetSdPage(0, PageKind::Handout
)->CreateTitleAndLayout(true);
431 void SdDrawDocument::AdaptPageSizeForAllPages(
432 const Size
& rNewSize
,
434 SdUndoGroup
* pUndoGroup
,
436 ::tools::Long nRight
,
437 ::tools::Long nUpper
,
438 ::tools::Long nLower
,
440 Orientation eOrientation
,
441 sal_uInt16 nPaperBin
,
442 bool bBackgroundFullSize
)
445 const sal_uInt16
nMasterPageCnt(GetMasterSdPageCount(ePageKind
));
446 const sal_uInt16
nPageCnt(GetSdPageCount(ePageKind
));
448 if(0 == nMasterPageCnt
&& 0 == nPageCnt
)
453 for (i
= 0; i
< nMasterPageCnt
; i
++)
455 // first, handle all master pages
456 SdPage
* pPage(GetMasterSdPage(i
, ePageKind
));
461 new SdPageFormatUndoAction(
465 pPage
->GetLeftBorder(), pPage
->GetRightBorder(),
466 pPage
->GetUpperBorder(), pPage
->GetLowerBorder(),
467 pPage
->GetOrientation(),
468 pPage
->GetPaperBin(),
469 pPage
->IsBackgroundFullSize(),
476 bBackgroundFullSize
));
477 pUndoGroup
->AddAction(pUndo
);
480 if (rNewSize
.Width() > 0 || nLeft
>= 0 || nRight
>= 0 || nUpper
>= 0 || nLower
>= 0)
482 ::tools::Rectangle
aNewBorderRect(nLeft
, nUpper
, nRight
, nLower
);
483 pPage
->ScaleObjects(rNewSize
, aNewBorderRect
, bScaleAll
);
485 if (rNewSize
.Width() > 0)
487 pPage
->SetSize(rNewSize
);
491 if( nLeft
>= 0 || nRight
>= 0 || nUpper
>= 0 || nLower
>= 0 )
493 pPage
->SetBorder(nLeft
, nUpper
, nRight
, nLower
);
496 pPage
->SetOrientation(eOrientation
);
497 pPage
->SetPaperBin( nPaperBin
);
498 pPage
->SetBackgroundFullSize( bBackgroundFullSize
);
500 if ( ePageKind
== PageKind::Standard
)
502 GetMasterSdPage(i
, PageKind::Notes
)->CreateTitleAndLayout();
505 pPage
->CreateTitleAndLayout();
508 for (i
= 0; i
< nPageCnt
; i
++)
510 // then, handle all pages
511 SdPage
* pPage(GetSdPage(i
, ePageKind
));
516 new SdPageFormatUndoAction(
520 pPage
->GetLeftBorder(), pPage
->GetRightBorder(),
521 pPage
->GetUpperBorder(), pPage
->GetLowerBorder(),
522 pPage
->GetOrientation(),
523 pPage
->GetPaperBin(),
524 pPage
->IsBackgroundFullSize(),
531 bBackgroundFullSize
));
532 pUndoGroup
->AddAction(pUndo
);
535 if (rNewSize
.Width() > 0 || nLeft
>= 0 || nRight
>= 0 || nUpper
>= 0 || nLower
>= 0)
537 ::tools::Rectangle
aNewBorderRect(nLeft
, nUpper
, nRight
, nLower
);
538 pPage
->ScaleObjects(rNewSize
, aNewBorderRect
, bScaleAll
);
540 if (rNewSize
.Width() > 0)
542 pPage
->SetSize(rNewSize
);
546 if( nLeft
>= 0 || nRight
>= 0 || nUpper
>= 0 || nLower
>= 0 )
548 pPage
->SetBorder(nLeft
, nUpper
, nRight
, nLower
);
551 pPage
->SetOrientation(eOrientation
);
552 pPage
->SetPaperBin( nPaperBin
);
553 pPage
->SetBackgroundFullSize( bBackgroundFullSize
);
555 if ( ePageKind
== PageKind::Standard
)
557 SdPage
* pNotesPage
= GetSdPage(i
, PageKind::Notes
);
558 pNotesPage
->SetAutoLayout( pNotesPage
->GetAutoLayout() );
561 pPage
->SetAutoLayout( pPage
->GetAutoLayout() );
565 SdrModel
* SdDrawDocument::AllocModel() const
567 return AllocSdDrawDocument();
573 /// Copies all user-defined properties from pSource to pDestination.
574 void lcl_copyUserDefinedProperties(const SfxObjectShell
* pSource
, const SfxObjectShell
* pDestination
)
576 if (!pSource
|| !pDestination
)
579 uno::Reference
<document::XDocumentProperties
> xSource
= pSource
->getDocProperties();
580 uno::Reference
<document::XDocumentProperties
> xDestination
= pDestination
->getDocProperties();
581 uno::Reference
<beans::XPropertyContainer
> xSourcePropertyContainer
= xSource
->getUserDefinedProperties();
582 uno::Reference
<beans::XPropertyContainer
> xDestinationPropertyContainer
= xDestination
->getUserDefinedProperties();
583 uno::Reference
<beans::XPropertySet
> xSourcePropertySet(xSourcePropertyContainer
, uno::UNO_QUERY
);
584 const uno::Sequence
<beans::Property
> aProperties
= xSourcePropertySet
->getPropertySetInfo()->getProperties();
586 for (const beans::Property
& rProperty
: aProperties
)
588 const OUString
& rKey
= rProperty
.Name
;
589 uno::Any aValue
= xSourcePropertySet
->getPropertyValue(rKey
);
590 // We know that pDestination was just created, so has no properties: addProperty() will never throw.
591 xDestinationPropertyContainer
->addProperty(rKey
, beans::PropertyAttribute::REMOVABLE
, aValue
);
597 // This method creates a new document (SdDrawDocument) and returns a pointer to
598 // said document. The drawing engine uses this method to put the document (or
599 // parts of it) into the clipboard/DragServer.
600 SdDrawDocument
* SdDrawDocument::AllocSdDrawDocument() const
602 SdDrawDocument
* pNewModel
= nullptr;
604 if( mpCreatingTransferable
)
606 // Document is created for drag & drop/clipboard. To be able to
607 // do this, the document has to know a DocShell (SvPersist).
608 SfxObjectShell
* pObj
= nullptr;
609 ::sd::DrawDocShell
* pNewDocSh
= nullptr;
611 if( meDocType
== DocumentType::Impress
)
612 mpCreatingTransferable
->SetDocShell( new ::sd::DrawDocShell(
613 SfxObjectCreateMode::EMBEDDED
, true, meDocType
) );
615 mpCreatingTransferable
->SetDocShell( new ::sd::GraphicDocShell(
616 SfxObjectCreateMode::EMBEDDED
) );
618 pObj
= mpCreatingTransferable
->GetDocShell().get();
619 pNewDocSh
= static_cast< ::sd::DrawDocShell
*>( pObj
);
620 pNewDocSh
->DoInitNew();
621 pNewModel
= pNewDocSh
->GetDoc();
623 // Only necessary for clipboard -
624 // for drag & drop this is handled by DragServer
625 SdStyleSheetPool
* pOldStylePool
= static_cast<SdStyleSheetPool
*>( GetStyleSheetPool() );
626 SdStyleSheetPool
* pNewStylePool
= static_cast<SdStyleSheetPool
*>( pNewModel
->GetStyleSheetPool() );
628 pNewStylePool
->CopyGraphicSheets(*pOldStylePool
);
629 pNewStylePool
->CopyCellSheets(*pOldStylePool
);
630 pNewStylePool
->CopyTableStyles(*pOldStylePool
);
632 for (sal_uInt16 i
= 0; i
< GetMasterSdPageCount(PageKind::Standard
); i
++)
634 // Move with all of the master page's layouts
635 OUString
aOldLayoutName(const_cast<SdDrawDocument
*>(this)->GetMasterSdPage(i
, PageKind::Standard
)->GetLayoutName());
636 aOldLayoutName
= aOldLayoutName
.copy( 0, aOldLayoutName
.indexOf( SD_LT_SEPARATOR
) );
637 StyleSheetCopyResultVector aCreatedSheets
;
638 pNewStylePool
->CopyLayoutSheets(aOldLayoutName
, *pOldStylePool
, aCreatedSheets
);
641 lcl_copyUserDefinedProperties(GetDocSh(), pNewDocSh
);
643 pNewModel
->NewOrLoadCompleted( DocCreationMode::Loaded
); // loaded from source document
645 else if( mbAllocDocSh
)
647 // Create a DocShell which is then returned with GetAllocedDocSh()
648 SdDrawDocument
* pDoc
= const_cast<SdDrawDocument
*>(this);
649 pDoc
->SetAllocDocSh(false);
650 pDoc
->mxAllocedDocShRef
= new ::sd::DrawDocShell(
651 SfxObjectCreateMode::EMBEDDED
, true, meDocType
);
652 pDoc
->mxAllocedDocShRef
->DoInitNew();
653 pNewModel
= pDoc
->mxAllocedDocShRef
->GetDoc();
657 pNewModel
= new SdDrawDocument(meDocType
, nullptr);
663 rtl::Reference
<SdPage
> SdDrawDocument::AllocSdPage(bool bMasterPage
)
665 return new SdPage(*this, bMasterPage
);
668 // This method creates a new page (SdPage) and returns a pointer to said page.
669 // The drawing engine uses this method to create pages (whose types it does
670 // not know, as they are _derivatives_ of SdrPage) when loading.
671 rtl::Reference
<SdrPage
> SdDrawDocument::AllocPage(bool bMasterPage
)
673 return AllocSdPage(bMasterPage
);
676 // When the model has changed
677 void SdDrawDocument::SetChanged(bool bFlag
)
681 if (mbNewOrLoadCompleted
&& mpDocSh
->IsEnableSetModified())
683 // Pass on to base class
684 FmFormModel::SetChanged(bFlag
);
686 // Forward to ObjectShell
687 mpDocSh
->SetModified(bFlag
);
692 // Pass on to base class
693 FmFormModel::SetChanged(bFlag
);
697 // The model changed, don't call anything else
698 void SdDrawDocument::NbcSetChanged(bool bFlag
)
700 // forward to baseclass
701 FmFormModel::SetChanged(bFlag
);
704 // NewOrLoadCompleted is called when the document is loaded, or when it is clear
705 // it won't load any more.
706 void SdDrawDocument::NewOrLoadCompleted(DocCreationMode eMode
)
708 if (eMode
== DocCreationMode::New
)
711 // create slideshow and default templates,
712 // create pool for virtual controls
713 CreateLayoutTemplates();
714 CreateDefaultCellStyles();
716 static_cast< SdStyleSheetPool
* >( mxStyleSheetPool
.get() )->CreatePseudosIfNecessary();
718 else if (eMode
== DocCreationMode::Loaded
)
720 // Document has finished loading
724 if ( GetMasterSdPageCount(PageKind::Standard
) > 1 )
725 RemoveUnnecessaryMasterPages( nullptr, true, false );
727 for ( sal_uInt16 i
= 0; i
< GetPageCount(); i
++ )
729 // Check for correct layout names
730 SdPage
* pPage
= static_cast<SdPage
*>( GetPage( i
) );
732 if(pPage
->TRG_HasMasterPage())
734 SdPage
& rMaster
= static_cast<SdPage
&>(pPage
->TRG_GetMasterPage() );
736 if(rMaster
.GetLayoutName() != pPage
->GetLayoutName())
738 pPage
->SetLayoutName(rMaster
.GetLayoutName());
743 for ( sal_uInt16 nPage
= 0; nPage
< GetMasterPageCount(); nPage
++)
745 // LayoutName and PageName must be the same
746 SdPage
* pPage
= static_cast<SdPage
*>( GetMasterPage( nPage
) );
748 OUString
aName( pPage
->GetLayoutName() );
749 aName
= aName
.copy( 0, aName
.indexOf( SD_LT_SEPARATOR
) );
751 if( aName
!= pPage
->GetName() )
752 pPage
->SetName( aName
);
755 // Create names of the styles in the user's language
756 static_cast<SdStyleSheetPool
*>(mxStyleSheetPool
.get())->UpdateStdNames();
758 // Create any missing styles - eg. formerly, there was no Subtitle style
759 static_cast<SdStyleSheetPool
*>(mxStyleSheetPool
.get())->CreatePseudosIfNecessary();
762 // Set default style of Drawing Engine
763 OUString
aName( SdResId(STR_STANDARD_STYLESHEET_NAME
));
764 SetDefaultStyleSheet(static_cast<SfxStyleSheet
*>(mxStyleSheetPool
->Find(aName
, SfxStyleFamily::Para
)));
766 // #i119287# Set default StyleSheet for SdrGrafObj and SdrOle2Obj
767 SetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj(static_cast<SfxStyleSheet
*>(mxStyleSheetPool
->Find(SdResId(STR_POOLSHEET_OBJNOLINENOFILL
), SfxStyleFamily::Para
)));
769 // Initialize DrawOutliner and DocumentOutliner, but don't initialize the
770 // global outliner, as it is not document specific like StyleSheetPool and
771 // StyleRequestHandler are.
772 ::Outliner
& rDrawOutliner
= GetDrawOutliner();
773 rDrawOutliner
.SetStyleSheetPool(static_cast<SfxStyleSheetPool
*>(GetStyleSheetPool()));
774 EEControlBits nCntrl
= rDrawOutliner
.GetControlWord();
776 nCntrl
|= EEControlBits::ONLINESPELLING
;
778 nCntrl
&= ~EEControlBits::ONLINESPELLING
;
779 rDrawOutliner
.SetControlWord(nCntrl
);
781 // Initialize HitTestOutliner and DocumentOutliner, but don't initialize the
782 // global outliner, as it is not document specific like StyleSheetPool and
783 // StyleRequestHandler are.
784 m_pHitTestOutliner
->SetStyleSheetPool(static_cast<SfxStyleSheetPool
*>(GetStyleSheetPool()));
788 mpOutliner
->SetStyleSheetPool(static_cast<SfxStyleSheetPool
*>(GetStyleSheetPool()));
790 if(mpInternalOutliner
)
792 mpInternalOutliner
->SetStyleSheetPool(static_cast<SfxStyleSheetPool
*>(GetStyleSheetPool()));
795 if ( eMode
== DocCreationMode::Loaded
)
797 // Make presentation objects listeners of the appropriate styles
798 SdStyleSheetPool
* pSPool
= static_cast<SdStyleSheetPool
*>( GetStyleSheetPool() );
799 sal_uInt16 nPage
, nPageCount
;
801 // create missing layout style sheets for broken documents
802 // that were created with the 5.2
803 nPageCount
= GetMasterSdPageCount( PageKind::Standard
);
804 for (nPage
= 0; nPage
< nPageCount
; nPage
++)
806 SdPage
* pPage
= GetMasterSdPage(nPage
, PageKind::Standard
);
807 pSPool
->CreateLayoutStyleSheets( pPage
->GetName(), true );
810 // Default and notes pages:
811 for (nPage
= 0; nPage
< GetPageCount(); nPage
++)
813 SdPage
* pPage
= static_cast<SdPage
*>(GetPage(nPage
));
814 NewOrLoadCompleted( pPage
, pSPool
);
818 for (nPage
= 0; nPage
< GetMasterPageCount(); nPage
++)
820 SdPage
* pPage
= static_cast<SdPage
*>(GetMasterPage(nPage
));
822 NewOrLoadCompleted( pPage
, pSPool
);
826 mbNewOrLoadCompleted
= true;
831 /** updates all links, only links in this document should by resolved */
832 void SdDrawDocument::UpdateAllLinks()
834 if (s_pDocLockedInsertingLinks
|| !m_pLinkManager
|| m_pLinkManager
->GetLinks().empty())
837 s_pDocLockedInsertingLinks
= this; // lock inserting links. only links in this document should by resolved
841 comphelper::EmbeddedObjectContainer
& rEmbeddedObjectContainer
= mpDocSh
->getEmbeddedObjectContainer();
842 rEmbeddedObjectContainer
.setUserAllowsLinkUpdate(true);
845 m_pLinkManager
->UpdateAllLinks(true, false, nullptr, u
""_ustr
); // query box: update all links?
847 if (s_pDocLockedInsertingLinks
== this)
848 s_pDocLockedInsertingLinks
= nullptr; // unlock inserting links
851 /** this loops over the presentation objects of a page and repairs some new settings
852 from old binary files and resets all default strings for empty presentation objects.
854 void SdDrawDocument::NewOrLoadCompleted( SdPage
* pPage
, SdStyleSheetPool
* pSPool
)
856 sd::ShapeList
& rPresentationShapes( pPage
->GetPresentationShapeList() );
857 if(rPresentationShapes
.isEmpty())
860 // Create lists of title and outline styles
861 OUString aName
= pPage
->GetLayoutName();
862 aName
= aName
.copy( 0, aName
.indexOf( SD_LT_SEPARATOR
) );
864 std::vector
<SfxStyleSheetBase
*> aOutlineList
;
865 pSPool
->CreateOutlineSheetList(aName
,aOutlineList
);
867 SfxStyleSheet
* pTitleSheet
= static_cast<SfxStyleSheet
*>(pSPool
->GetTitleSheet(aName
));
869 SdrObject
* pObj
= nullptr;
870 rPresentationShapes
.seekShape(0);
872 // Now look for title and outline text objects, then make those objects
874 while( (pObj
= rPresentationShapes
.getNextShape()) )
876 if (pObj
->GetObjInventor() == SdrInventor::Default
)
878 OutlinerParaObject
* pOPO
= pObj
->GetOutlinerParaObject();
879 SdrObjKind nId
= pObj
->GetObjIdentifier();
881 if (nId
== SdrObjKind::TitleText
)
883 if( pOPO
&& pOPO
->GetOutlinerMode() == OutlinerMode::DontKnow
)
884 pOPO
->SetOutlinerMode( OutlinerMode::TitleObject
);
886 // sal_True: don't delete "hard" attributes when doing this.
888 pObj
->SetStyleSheet(pTitleSheet
, true);
890 else if (nId
== SdrObjKind::OutlineText
)
892 if( pOPO
&& pOPO
->GetOutlinerMode() == OutlinerMode::DontKnow
)
893 pOPO
->SetOutlinerMode( OutlinerMode::OutlineObject
);
895 std::vector
<SfxStyleSheetBase
*>::iterator iter
;
896 for (iter
= aOutlineList
.begin(); iter
!= aOutlineList
.end(); ++iter
)
898 SfxStyleSheet
* pSheet
= static_cast<SfxStyleSheet
*>(*iter
);
902 pObj
->StartListening(*pSheet
);
904 if( iter
== aOutlineList
.begin())
905 // text frame listens to stylesheet of layer 1
906 pObj
->NbcSetStyleSheet(pSheet
, true);
911 if( auto pTextObj
= DynCastSdrTextObj( pObj
) )
912 if (pTextObj
->IsEmptyPresObj())
914 PresObjKind ePresObjKind
= pPage
->GetPresObjKind(pObj
);
915 OUString
aString( pPage
->GetPresObjText(ePresObjKind
) );
917 if (!aString
.isEmpty())
919 SdOutliner
* pInternalOutl
= GetInternalOutliner();
920 pPage
->SetObjText( pTextObj
, pInternalOutl
, ePresObjKind
, aString
);
921 pObj
->NbcSetStyleSheet( pPage
->GetStyleSheetForPresObj( ePresObjKind
), true );
922 pInternalOutl
->Clear();
929 // Local outliner that is used for outline mode. In this outliner, OutlinerViews
931 SdOutliner
* SdDrawDocument::GetOutliner(bool bCreateOutliner
)
933 if (!mpOutliner
&& bCreateOutliner
)
935 mpOutliner
.reset(new SdOutliner( this, OutlinerMode::TextObject
));
938 mpOutliner
->SetRefDevice(SdModule::get()->GetVirtualRefDevice());
940 mpOutliner
->SetDefTab( m_nDefaultTabulator
);
941 mpOutliner
->SetStyleSheetPool(static_cast<SfxStyleSheetPool
*>(GetStyleSheetPool()));
944 return mpOutliner
.get();
947 // Internal outliner that is used to create text objects. We don't insert any
948 // OutlinerViews into this outliner!
949 SdOutliner
* SdDrawDocument::GetInternalOutliner(bool bCreateOutliner
)
951 if ( !mpInternalOutliner
&& bCreateOutliner
)
953 mpInternalOutliner
.reset( new SdOutliner( this, OutlinerMode::TextObject
) );
955 // This outliner is only used to create special text objects. As no
956 // information about portions is saved in this outliner, the update mode
957 // can/should always remain sal_False.
958 mpInternalOutliner
->SetUpdateLayout( false );
959 mpInternalOutliner
->EnableUndo( false );
962 mpInternalOutliner
->SetRefDevice(SdModule::get()->GetVirtualRefDevice());
964 mpInternalOutliner
->SetDefTab( m_nDefaultTabulator
);
965 mpInternalOutliner
->SetStyleSheetPool(static_cast<SfxStyleSheetPool
*>(GetStyleSheetPool()));
968 DBG_ASSERT( !mpInternalOutliner
|| ( ! mpInternalOutliner
->IsUpdateLayout() ) , "InternalOutliner: UpdateMode = sal_True !" );
969 DBG_ASSERT( !mpInternalOutliner
|| ( ! mpInternalOutliner
->IsUndoEnabled() ), "InternalOutliner: Undo = sal_True !" );
971 // If you add stuff here, always clear it out.
973 // a) no unnecessary Clear calls
974 // b) no wasted memory
975 DBG_ASSERT( !mpInternalOutliner
|| ( ( mpInternalOutliner
->GetParagraphCount() == 1 ) && ( mpInternalOutliner
->GetText( mpInternalOutliner
->GetParagraph( 0 ) ).isEmpty() ) ), "InternalOutliner: not empty!" );
977 return mpInternalOutliner
.get();
980 // OnlineSpelling on/off
981 void SdDrawDocument::SetOnlineSpell(bool bIn
)
984 EEControlBits nCntrl
;
988 nCntrl
= mpOutliner
->GetControlWord();
991 nCntrl
|= EEControlBits::ONLINESPELLING
;
993 nCntrl
&= ~EEControlBits::ONLINESPELLING
;
995 mpOutliner
->SetControlWord(nCntrl
);
998 if (mpInternalOutliner
)
1000 nCntrl
= mpInternalOutliner
->GetControlWord();
1003 nCntrl
|= EEControlBits::ONLINESPELLING
;
1005 nCntrl
&= ~EEControlBits::ONLINESPELLING
;
1007 mpInternalOutliner
->SetControlWord(nCntrl
);
1010 ::Outliner
& rOutliner
= GetDrawOutliner();
1012 nCntrl
= rOutliner
.GetControlWord();
1015 nCntrl
|= EEControlBits::ONLINESPELLING
;
1017 nCntrl
&= ~EEControlBits::ONLINESPELLING
;
1019 rOutliner
.SetControlWord(nCntrl
);
1023 StartOnlineSpelling();
1027 StopOnlineSpelling();
1031 // OnlineSpelling: highlighting on/off
1032 uno::Reference
< frame::XModel
> SdDrawDocument::createUnoModel()
1034 uno::Reference
< frame::XModel
> xModel
;
1039 xModel
= mpDocSh
->GetModel();
1041 catch( uno::RuntimeException
& )
1048 SvxNumType
SdDrawDocument::GetPageNumType() const
1050 return mePageNumType
;
1053 void SdDrawDocument::SetPrinterIndependentLayout (sal_Int32 nMode
)
1057 case css::document::PrinterIndependentLayout::DISABLED
:
1058 case css::document::PrinterIndependentLayout::ENABLED
:
1059 // Just store supported modes and inform the doc shell
1060 mnPrinterIndependentLayout
= nMode
;
1062 // Since it is possible that a SdDrawDocument is constructed without a
1063 // SdDrawDocShell the pointer member mpDocSh needs to be tested
1064 // before the call is executed. This is e. g. used for copy/paste.
1067 mpDocSh
->UpdateRefDevice ();
1073 // Ignore unknown values
1078 void SdDrawDocument::SetStartWithPresentation(sal_uInt16 nStartingSlide
)
1080 mnStartWithPresentation
= nStartingSlide
;
1083 void SdDrawDocument::SetExitAfterPresenting( bool bExitAfterPresenting
)
1085 mbExitAfterPresenting
= bExitAfterPresenting
;
1088 void SdDrawDocument::PageListChanged()
1090 mpDrawPageListWatcher
->Invalidate();
1093 void SdDrawDocument::MasterPageListChanged()
1095 mpMasterPageListWatcher
->Invalidate();
1098 void SdDrawDocument::SetCalcFieldValueHdl(::Outliner
* pOutliner
)
1100 pOutliner
->SetCalcFieldValueHdl(LINK(SdModule::get(), SdModule
, CalcFieldValueHdl
));
1103 sal_uInt16
SdDrawDocument::GetAnnotationAuthorIndex( const OUString
& rAuthor
)
1105 // force current user to have first color
1106 if( maAnnotationAuthors
.empty() )
1108 SvtUserOptions aUserOptions
;
1109 maAnnotationAuthors
.push_back( aUserOptions
.GetFullName() );
1112 auto iter
= std::find(maAnnotationAuthors
.begin(), maAnnotationAuthors
.end(), rAuthor
);
1113 sal_uInt16 idx
= static_cast<sal_uInt16
>(std::distance(maAnnotationAuthors
.begin(), iter
));
1115 if( idx
== maAnnotationAuthors
.size() )
1117 maAnnotationAuthors
.push_back( rAuthor
);
1123 void SdDrawDocument::InitLayoutVector()
1125 if (comphelper::IsFuzzing())
1128 const Reference
<css::uno::XComponentContext
>& xContext(
1129 ::comphelper::getProcessComponentContext() );
1131 // get file list from configuration
1132 const Sequence
< OUString
> aFiles(
1133 officecfg::Office::Impress::Misc::LayoutListFiles::get() );
1135 if (aFiles
.getLength() == 0)
1137 const Reference
<XDocumentBuilder
> xDocBuilder
= DocumentBuilder::create( xContext
);
1139 for( const auto& rFile
: aFiles
)
1141 OUString sFilename
= comphelper::getExpandedUri(xContext
, rFile
);
1143 // load layout file into DOM
1147 // loop over every layout entry in current file
1148 const Reference
<XDocument
> xDoc
= xDocBuilder
->parseURI( sFilename
);
1149 const Reference
<XNodeList
> layoutlist
= xDoc
->getElementsByTagName(u
"layout"_ustr
);
1150 const int nElements
= layoutlist
->getLength();
1151 for(int index
=0; index
< nElements
; index
++)
1152 maLayoutInfo
.push_back( layoutlist
->item(index
) );
1154 catch (const uno::Exception
&)
1156 // skip missing config. files
1161 void SdDrawDocument::InitObjectVector()
1163 if (comphelper::IsFuzzing())
1166 const Reference
<css::uno::XComponentContext
>& xContext(
1167 ::comphelper::getProcessComponentContext() );
1169 // get file list from configuration
1170 const Sequence
< OUString
> aFiles(
1171 officecfg::Office::Impress::Misc::PresObjListFiles::get() );
1173 if (aFiles
.getLength() == 0)
1175 const Reference
<XDocumentBuilder
> xDocBuilder
= DocumentBuilder::create( xContext
);
1176 for( const auto& rFile
: aFiles
)
1178 OUString sFilename
= comphelper::getExpandedUri(xContext
, rFile
);
1180 // load presentation object file into DOM
1184 // loop over every object entry in current file
1185 const Reference
<XDocument
> xDoc
= xDocBuilder
->parseURI( sFilename
);
1186 const Reference
<XNodeList
> objectlist
= xDoc
->getElementsByTagName(u
"object"_ustr
);
1187 const int nElements
= objectlist
->getLength();
1188 for(int index
=0; index
< nElements
; index
++)
1189 maPresObjectInfo
.push_back( objectlist
->item(index
) );
1191 catch (const uno::Exception
&)
1193 // skip missing config. files
1198 void SdDrawDocument::dumpAsXml(xmlTextWriterPtr pWriter
) const
1203 pWriter
= xmlNewTextWriterFilename("model.xml", 0);
1204 xmlTextWriterSetIndent(pWriter
,1);
1205 (void)xmlTextWriterSetIndentString(pWriter
, BAD_CAST(" "));
1206 (void)xmlTextWriterStartDocument(pWriter
, nullptr, nullptr, nullptr);
1209 (void)xmlTextWriterStartElement(pWriter
, BAD_CAST("SdDrawDocument"));
1210 (void)xmlTextWriterWriteFormatAttribute(pWriter
, BAD_CAST("ptr"), "%p", this);
1213 mpOutliner
->dumpAsXml(pWriter
);
1214 FmFormModel::dumpAsXml(pWriter
);
1215 if (GetUndoManager())
1216 GetUndoManager()->dumpAsXml(pWriter
);
1218 (void)xmlTextWriterEndElement(pWriter
);
1221 (void)xmlTextWriterEndDocument(pWriter
);
1222 xmlFreeTextWriter(pWriter
);
1226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */