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 <editeng/forbiddencharacterstable.hxx>
30 #include <svx/svxids.hrc>
31 #include <svl/srchitem.hxx>
32 #include <editeng/eeitem.hxx>
33 #include <editeng/scriptspaceitem.hxx>
35 #include <unotools/configmgr.hxx>
36 #include <unotools/useroptions.hxx>
37 #include <officecfg/Office/Impress.hxx>
39 #include <sfx2/printer.hxx>
40 #include <sfx2/app.hxx>
41 #include <sfx2/linkmgr.hxx>
42 #include <svx/dialogs.hrc>
43 #include <Outliner.hxx>
45 #include <editeng/editstat.hxx>
46 #include <editeng/fontitem.hxx>
47 #include <svl/flagitem.hxx>
48 #include <svx/svdoattr.hxx>
49 #include <svx/svdotext.hxx>
50 #include <editeng/bulletitem.hxx>
51 #include <editeng/numitem.hxx>
52 #include <svx/svditer.hxx>
53 #include <editeng/unolingu.hxx>
54 #include <svl/itempool.hxx>
55 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
56 #include <svx/xtable.hxx>
57 #include <com/sun/star/linguistic2/XHyphenator.hpp>
58 #include <com/sun/star/linguistic2/XSpellChecker1.hpp>
59 #include <com/sun/star/beans/XPropertySet.hpp>
60 #include <editeng/outlobj.hxx>
61 #include <unotools/saveopt.hxx>
62 #include <comphelper/getexpandeduri.hxx>
63 #include <i18nlangtag/mslangid.hxx>
64 #include <i18nlangtag/languagetag.hxx>
65 #include <unotools/charclass.hxx>
66 #include <comphelper/processfactory.hxx>
67 #include <unotools/pathoptions.hxx>
68 #include <unotools/lingucfg.hxx>
69 #include <unotools/linguprops.hxx>
70 #include <com/sun/star/uno/Reference.hxx>
71 #include <com/sun/star/xml/dom/XDocumentBuilder.hpp>
72 #include <com/sun/star/xml/dom/XDocument.hpp>
73 #include <com/sun/star/xml/dom/XNode.hpp>
74 #include <com/sun/star/xml/dom/XNodeList.hpp>
75 #include <com/sun/star/xml/dom/DocumentBuilder.hpp>
76 #include <com/sun/star/uno/XComponentContext.hpp>
77 #include <rtl/ustring.hxx>
78 #include <rtl/uri.hxx>
80 #include <editeng/outliner.hxx>
81 #include <drawdoc.hxx>
85 #include <strings.hrc>
87 #include <stlpool.hxx>
88 #include <sdiocmpt.hxx>
89 #include <sdresid.hxx>
90 #include <cusshow.hxx>
91 #include <customshowlist.hxx>
92 #include <DrawDocShell.hxx>
93 #include <GraphicDocShell.hxx>
95 #include <ViewShell.hxx>
96 #include <optsitem.hxx>
97 #include <FrameView.hxx>
98 #include <undo/undomanager.hxx>
99 #include <sdundogr.hxx>
100 #include <undopage.hxx>
101 #include <tools/tenccvt.hxx>
102 #include <vcl/settings.hxx>
104 using namespace ::sd
;
105 using namespace ::com::sun::star
;
106 using namespace ::com::sun::star::uno
;
107 using namespace ::com::sun::star::lang
;
108 using namespace ::com::sun::star::linguistic2
;
110 using namespace com::sun::star::xml::dom
;
111 using ::com::sun::star::uno::Reference
;
112 using ::com::sun::star::lang::XMultiServiceFactory
;
115 SdDrawDocument
* SdDrawDocument::s_pDocLockedInsertingLinks
= nullptr;
117 PresentationSettings::PresentationSettings()
122 mbMouseVisible( false ),
123 mbMouseAsPen( false ),
124 mbLockedPages( false ),
125 mbAlwaysOnTop( false ),
126 mbFullScreen( true ),
127 mbAnimationAllowed( true ),
128 mnPauseTimeout( 10 ),
129 mbShowPauseLogo( false )
133 SdDrawDocument::SdDrawDocument(DocumentType eType
, SfxObjectShell
* pDrDocSh
)
134 : FmFormModel( !utl::ConfigManager::IsFuzzing() ? SvtPathOptions().GetPalettePath() : OUString(), nullptr, pDrDocSh
)
135 , mpOutliner(nullptr)
136 , mpInternalOutliner(nullptr)
137 , mpWorkStartupTimer(nullptr)
138 , mpOnlineSpellingIdle(nullptr)
139 , mpOnlineSpellingList(nullptr)
140 , mpOnlineSearchItem(nullptr)
141 , mpCustomShowList(nullptr)
142 , mpDocSh(static_cast< ::sd::DrawDocShell
*>(pDrDocSh
))
143 , mpCreatingTransferable( nullptr )
144 , mbHasOnlineSpellErrors(false)
145 , mbInitialOnlineSpellingEnabled(true)
146 , mbNewOrLoadCompleted(false)
147 , mbOnlineSpell(false)
148 , mbStartWithPresentation( false )
149 , mbExitAfterPresenting( false )
150 , meLanguage( LANGUAGE_SYSTEM
)
151 , meLanguageCJK( LANGUAGE_SYSTEM
)
152 , meLanguageCTL( LANGUAGE_SYSTEM
)
153 , mePageNumType(SVX_NUM_ARABIC
)
154 , mbAllocDocSh(false)
156 , mpCharClass(nullptr)
157 , mbUseEmbedFonts(false)
159 mpDrawPageListWatcher
.reset(new ImpDrawPageListWatcher(*this));
160 mpMasterPageListWatcher
.reset(new ImpMasterPageListWatcher(*this));
164 SetObjectShell(pDrDocSh
); // for VCDrawModel
171 // Set measuring unit (of the application) and scale (of SdMod)
173 SdOptions
* pOptions
= SD_MOD()->GetSdOptions(meDocType
);
174 pOptions
->GetScale( nX
, nY
);
176 // Allow UI scale only for draw documents.
177 if( eType
== DocumentType::Draw
)
178 SetUIUnit( static_cast<FieldUnit
>(pOptions
->GetMetric()), Fraction( nX
, nY
) ); // user-defined
180 SetUIUnit( static_cast<FieldUnit
>(pOptions
->GetMetric()), Fraction( 1, 1 ) ); // default
182 SetScaleUnit(MapUnit::Map100thMM
);
183 SetScaleFraction(Fraction(1, 1));
184 SetDefaultFontHeight(847); // 24p
186 pItemPool
->SetDefaultMetric(MapUnit::Map100thMM
);
187 pItemPool
->FreezeIdRanges();
190 // DrawingEngine has to know where it is...
191 FmFormModel::SetStyleSheetPool( new SdStyleSheetPool( GetPool(), this ) );
193 // Set StyleSheetPool for DrawOutliner, so text objects can be read correctly.
194 // The link to the StyleRequest handler of the document is set later, in
195 // NewOrLoadCompleted, because only then do all the templates exist.
196 SdrOutliner
& rOutliner
= GetDrawOutliner();
197 rOutliner
.SetStyleSheetPool(static_cast<SfxStyleSheetPool
*>(GetStyleSheetPool()));
198 SetCalcFieldValueHdl( &rOutliner
);
200 // set linguistic options
201 if (!utl::ConfigManager::IsFuzzing())
203 const SvtLinguConfig aLinguConfig
;
204 SvtLinguOptions aOptions
;
205 aLinguConfig
.GetOptions( aOptions
);
207 SetLanguage( MsLangId::resolveSystemLanguageByScriptType(aOptions
.nDefaultLanguage
,
208 css::i18n::ScriptType::LATIN
), EE_CHAR_LANGUAGE
);
209 SetLanguage( MsLangId::resolveSystemLanguageByScriptType(aOptions
.nDefaultLanguage_CJK
,
210 css::i18n::ScriptType::ASIAN
), EE_CHAR_LANGUAGE_CJK
);
211 SetLanguage( MsLangId::resolveSystemLanguageByScriptType(aOptions
.nDefaultLanguage_CTL
,
212 css::i18n::ScriptType::COMPLEX
), EE_CHAR_LANGUAGE_CTL
);
214 mbOnlineSpell
= aOptions
.bIsSpellAuto
;
217 LanguageType eRealLanguage
= MsLangId::getRealLanguage( meLanguage
);
218 LanguageTag
aLanguageTag( eRealLanguage
);
219 mpCharClass
.reset(new CharClass( aLanguageTag
));
221 // If the current application language is a language that uses right-to-left text...
222 LanguageType eRealCTLLanguage
= Application::GetSettings().GetLanguageTag().getLanguageType();
224 // for korean and japanese languages we have a different default for apply spacing between asian, latin and ctl text
225 if (MsLangId::isKorean(eRealCTLLanguage
) || (LANGUAGE_JAPANESE
== eRealCTLLanguage
))
227 GetPool().GetSecondaryPool()->SetPoolDefaultItem( SvxScriptSpaceItem( false, EE_PARA_ASIANCJKSPACING
) );
230 // Set DefTab and SpellOptions for the SD module
231 sal_uInt16 nDefTab
= pOptions
->GetDefTab();
232 SetDefaultTabulator( nDefTab
);
236 Reference
< XSpellChecker1
> xSpellChecker( LinguMgr::GetSpellChecker() );
237 if ( xSpellChecker
.is() )
238 rOutliner
.SetSpeller( xSpellChecker
);
240 Reference
< XHyphenator
> xHyphenator( LinguMgr::GetHyphenator() );
241 if( xHyphenator
.is() )
242 rOutliner
.SetHyphenator( xHyphenator
);
244 SetForbiddenCharsTable(SvxForbiddenCharactersTable::makeForbiddenCharactersTable(::comphelper::getProcessComponentContext()));
248 OSL_FAIL("Can't get SpellChecker");
251 rOutliner
.SetDefaultLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() );
255 SetLinkManager( new sfx2::LinkManager(mpDocSh
) );
258 EEControlBits nCntrl
= rOutliner
.GetControlWord();
259 nCntrl
|= EEControlBits::ALLOWBIGOBJS
;
262 nCntrl
|= EEControlBits::ONLINESPELLING
;
264 nCntrl
&= ~EEControlBits::ONLINESPELLING
;
266 nCntrl
&= ~ EEControlBits::ULSPACESUMMATION
;
267 if ( meDocType
!= DocumentType::Impress
)
268 SetSummationOfParagraphs( false );
271 SetSummationOfParagraphs( pOptions
->IsSummationOfParagraphs() );
272 if ( pOptions
->IsSummationOfParagraphs() )
273 nCntrl
|= EEControlBits::ULSPACESUMMATION
;
275 rOutliner
.SetControlWord(nCntrl
);
277 // Initialize the printer independent layout mode
278 SetPrinterIndependentLayout (pOptions
->GetPrinterIndependentLayout());
280 // Set the StyleSheetPool for HitTestOutliner.
281 // The link to the StyleRequest handler of the document is set later, in
282 // NewOrLoadCompleted, because only then do all the templates exist.
283 pHitTestOutliner
->SetStyleSheetPool( static_cast<SfxStyleSheetPool
*>(GetStyleSheetPool()) );
285 SetCalcFieldValueHdl( pHitTestOutliner
.get() );
289 Reference
< XSpellChecker1
> xSpellChecker( LinguMgr::GetSpellChecker() );
290 if ( xSpellChecker
.is() )
291 pHitTestOutliner
->SetSpeller( xSpellChecker
);
293 Reference
< XHyphenator
> xHyphenator( LinguMgr::GetHyphenator() );
294 if( xHyphenator
.is() )
295 pHitTestOutliner
->SetHyphenator( xHyphenator
);
299 OSL_FAIL("Can't get SpellChecker");
302 pHitTestOutliner
->SetDefaultLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() );
304 EEControlBits nCntrl2
= pHitTestOutliner
->GetControlWord();
305 nCntrl2
|= EEControlBits::ALLOWBIGOBJS
;
306 nCntrl2
&= ~EEControlBits::ONLINESPELLING
;
308 nCntrl2
&= ~ EEControlBits::ULSPACESUMMATION
;
309 if ( pOptions
->IsSummationOfParagraphs() )
310 nCntrl2
|= EEControlBits::ULSPACESUMMATION
;
312 pHitTestOutliner
->SetControlWord( nCntrl2
);
316 * We create the following default layers on all pages and master pages:
318 * STR_LAYOUT : default layer for drawing objects
320 * STR_BCKGRND : background of the master page
321 * (currently unused within normal pages)
323 * STR_BCKGRNDOBJ: objects on the background of master pages
324 * (currently unused within normal pages)
326 * STR_CONTROLS : default layer for controls
330 OUString
aControlLayerName( SdResId(STR_LAYER_CONTROLS
) );
332 SdrLayerAdmin
& rLayerAdmin
= GetLayerAdmin();
333 rLayerAdmin
.NewLayer( SdResId(STR_LAYER_LAYOUT
) );
334 rLayerAdmin
.NewLayer( SdResId(STR_LAYER_BCKGRND
) );
335 rLayerAdmin
.NewLayer( SdResId(STR_LAYER_BCKGRNDOBJ
) );
336 rLayerAdmin
.NewLayer( aControlLayerName
);
337 rLayerAdmin
.NewLayer( SdResId(STR_LAYER_MEASURELINES
) );
339 rLayerAdmin
.SetControlLayerName(aControlLayerName
);
345 SdDrawDocument::~SdDrawDocument()
347 Broadcast(SdrHint(SdrHintKind::ModelCleared
));
349 if (mpWorkStartupTimer
)
351 if ( mpWorkStartupTimer
->IsActive() )
352 mpWorkStartupTimer
->Stop();
354 mpWorkStartupTimer
.reset();
357 StopOnlineSpelling();
358 mpOnlineSearchItem
.reset();
361 SetAllocDocSh(false);
368 if ( !pLinkManager
->GetLinks().empty() )
370 pLinkManager
->Remove( 0, pLinkManager
->GetLinks().size() );
374 pLinkManager
= nullptr;
377 maFrameViewList
.clear();
379 if (mpCustomShowList
)
381 for (sal_uLong j
= 0; j
< mpCustomShowList
->size(); j
++)
383 // If necessary, delete CustomShows
384 SdCustomShow
* pCustomShow
= (*mpCustomShowList
)[j
];
388 mpCustomShowList
.reset();
392 mpInternalOutliner
.reset();
396 void SdDrawDocument::adaptSizeAndBorderForAllPages(
397 const Size
& rNewSize
,
403 const sal_uInt16
nMasterPageCnt(GetMasterSdPageCount(PageKind::Standard
));
404 const sal_uInt16
nPageCnt(GetSdPageCount(PageKind::Standard
));
406 if(0 == nMasterPageCnt
&& 0 == nPageCnt
)
411 SdPage
* pPage(0 != nPageCnt
? GetSdPage(0, PageKind::Standard
) : GetMasterSdPage(0, PageKind::Standard
));
413 // call fully implemented local version, including getting
414 // some more information from one of the Pages (1st one)
415 AdaptPageSizeForAllPages(
424 pPage
->GetOrientation(),
425 pPage
->GetPaperBin(),
426 pPage
->IsBackgroundFullSize());
428 // adjust handout page to new format of the standard page
431 GetSdPage(0, PageKind::Handout
)->CreateTitleAndLayout(true);
435 void SdDrawDocument::AdaptPageSizeForAllPages(
436 const Size
& rNewSize
,
438 SdUndoGroup
* pUndoGroup
,
444 Orientation eOrientation
,
445 sal_uInt16 nPaperBin
,
446 bool bBackgroundFullSize
)
449 const sal_uInt16
nMasterPageCnt(GetMasterSdPageCount(ePageKind
));
450 const sal_uInt16
nPageCnt(GetSdPageCount(ePageKind
));
452 if(0 == nMasterPageCnt
&& 0 == nPageCnt
)
457 for (i
= 0; i
< nMasterPageCnt
; i
++)
459 // first, handle all master pages
460 SdPage
* pPage(GetMasterSdPage(i
, ePageKind
));
465 new SdPageFormatUndoAction(
469 pPage
->GetLeftBorder(), pPage
->GetRightBorder(),
470 pPage
->GetUpperBorder(), pPage
->GetLowerBorder(),
471 pPage
->GetOrientation(),
472 pPage
->GetPaperBin(),
473 pPage
->IsBackgroundFullSize(),
480 bBackgroundFullSize
));
481 pUndoGroup
->AddAction(pUndo
);
484 if (rNewSize
.Width() > 0 || nLeft
>= 0 || nRight
>= 0 || nUpper
>= 0 || nLower
>= 0)
486 ::tools::Rectangle
aNewBorderRect(nLeft
, nUpper
, nRight
, nLower
);
487 pPage
->ScaleObjects(rNewSize
, aNewBorderRect
, bScaleAll
);
489 if (rNewSize
.Width() > 0)
491 pPage
->SetSize(rNewSize
);
495 if( nLeft
>= 0 || nRight
>= 0 || nUpper
>= 0 || nLower
>= 0 )
497 pPage
->SetBorder(nLeft
, nUpper
, nRight
, nLower
);
500 pPage
->SetOrientation(eOrientation
);
501 pPage
->SetPaperBin( nPaperBin
);
502 pPage
->SetBackgroundFullSize( bBackgroundFullSize
);
504 if ( ePageKind
== PageKind::Standard
)
506 GetMasterSdPage(i
, PageKind::Notes
)->CreateTitleAndLayout();
509 pPage
->CreateTitleAndLayout();
512 for (i
= 0; i
< nPageCnt
; i
++)
514 // then, handle all pages
515 SdPage
* pPage(GetSdPage(i
, ePageKind
));
520 new SdPageFormatUndoAction(
524 pPage
->GetLeftBorder(), pPage
->GetRightBorder(),
525 pPage
->GetUpperBorder(), pPage
->GetLowerBorder(),
526 pPage
->GetOrientation(),
527 pPage
->GetPaperBin(),
528 pPage
->IsBackgroundFullSize(),
535 bBackgroundFullSize
));
536 pUndoGroup
->AddAction(pUndo
);
539 if (rNewSize
.Width() > 0 || nLeft
>= 0 || nRight
>= 0 || nUpper
>= 0 || nLower
>= 0)
541 ::tools::Rectangle
aNewBorderRect(nLeft
, nUpper
, nRight
, nLower
);
542 pPage
->ScaleObjects(rNewSize
, aNewBorderRect
, bScaleAll
);
544 if (rNewSize
.Width() > 0)
546 pPage
->SetSize(rNewSize
);
550 if( nLeft
>= 0 || nRight
>= 0 || nUpper
>= 0 || nLower
>= 0 )
552 pPage
->SetBorder(nLeft
, nUpper
, nRight
, nLower
);
555 pPage
->SetOrientation(eOrientation
);
556 pPage
->SetPaperBin( nPaperBin
);
557 pPage
->SetBackgroundFullSize( bBackgroundFullSize
);
559 if ( ePageKind
== PageKind::Standard
)
561 SdPage
* pNotesPage
= GetSdPage(i
, PageKind::Notes
);
562 pNotesPage
->SetAutoLayout( pNotesPage
->GetAutoLayout() );
565 pPage
->SetAutoLayout( pPage
->GetAutoLayout() );
569 SdrModel
* SdDrawDocument::AllocModel() const
571 return AllocSdDrawDocument();
577 /// Copies all user-defined properties from pSource to pDestination.
578 void lcl_copyUserDefinedProperties(SfxObjectShell
* pSource
, SfxObjectShell
* pDestination
)
580 if (!pSource
|| !pDestination
)
583 uno::Reference
<document::XDocumentProperties
> xSource
= pSource
->getDocProperties();
584 uno::Reference
<document::XDocumentProperties
> xDestination
= pDestination
->getDocProperties();
585 uno::Reference
<beans::XPropertyContainer
> xSourcePropertyContainer
= xSource
->getUserDefinedProperties();
586 uno::Reference
<beans::XPropertyContainer
> xDestinationPropertyContainer
= xDestination
->getUserDefinedProperties();
587 uno::Reference
<beans::XPropertySet
> xSourcePropertySet(xSourcePropertyContainer
, uno::UNO_QUERY
);
588 uno::Sequence
<beans::Property
> aProperties
= xSourcePropertySet
->getPropertySetInfo()->getProperties();
590 for (const beans::Property
& rProperty
: aProperties
)
592 const OUString
& rKey
= rProperty
.Name
;
593 uno::Any aValue
= xSourcePropertySet
->getPropertyValue(rKey
);
594 // We know that pDestination was just created, so has no properties: addProperty() will never throw.
595 xDestinationPropertyContainer
->addProperty(rKey
, beans::PropertyAttribute::REMOVABLE
, aValue
);
601 // This method creates a new document (SdDrawDocument) and returns a pointer to
602 // said document. The drawing engine uses this method to put the document (or
603 // parts of it) into the clipboard/DragServer.
604 SdDrawDocument
* SdDrawDocument::AllocSdDrawDocument() const
606 SdDrawDocument
* pNewModel
= nullptr;
608 if( mpCreatingTransferable
)
610 // Document is created for drag & drop/clipboard. To be able to
611 // do this, the document has to know a DocShell (SvPersist).
612 SfxObjectShell
* pObj
= nullptr;
613 ::sd::DrawDocShell
* pNewDocSh
= nullptr;
615 if( meDocType
== DocumentType::Impress
)
616 mpCreatingTransferable
->SetDocShell( new ::sd::DrawDocShell(
617 SfxObjectCreateMode::EMBEDDED
, true, meDocType
) );
619 mpCreatingTransferable
->SetDocShell( new ::sd::GraphicDocShell(
620 SfxObjectCreateMode::EMBEDDED
, true, meDocType
) );
622 pNewDocSh
= static_cast< ::sd::DrawDocShell
*>( pObj
= mpCreatingTransferable
->GetDocShell().get() );
623 pNewDocSh
->DoInitNew();
624 pNewModel
= pNewDocSh
->GetDoc();
626 // Only necessary for clipboard -
627 // for drag & drop this is handled by DragServer
628 SdStyleSheetPool
* pOldStylePool
= static_cast<SdStyleSheetPool
*>( GetStyleSheetPool() );
629 SdStyleSheetPool
* pNewStylePool
= static_cast<SdStyleSheetPool
*>( pNewModel
->GetStyleSheetPool() );
631 pNewStylePool
->CopyGraphicSheets(*pOldStylePool
);
632 pNewStylePool
->CopyCellSheets(*pOldStylePool
);
633 pNewStylePool
->CopyTableStyles(*pOldStylePool
);
635 for (sal_uInt16 i
= 0; i
< GetMasterSdPageCount(PageKind::Standard
); i
++)
637 // Move with all of the master page's layouts
638 OUString
aOldLayoutName(const_cast<SdDrawDocument
*>(this)->GetMasterSdPage(i
, PageKind::Standard
)->GetLayoutName());
639 aOldLayoutName
= aOldLayoutName
.copy( 0, aOldLayoutName
.indexOf( SD_LT_SEPARATOR
) );
640 SdStyleSheetVector aCreatedSheets
;
641 pNewStylePool
->CopyLayoutSheets(aOldLayoutName
, *pOldStylePool
, aCreatedSheets
);
644 lcl_copyUserDefinedProperties(GetDocSh(), pNewDocSh
);
646 pNewModel
->NewOrLoadCompleted( DOC_LOADED
); // loaded from source document
648 else if( mbAllocDocSh
)
650 // Create a DocShell which is then returned with GetAllocedDocSh()
651 SdDrawDocument
* pDoc
= const_cast<SdDrawDocument
*>(this);
652 pDoc
->SetAllocDocSh(false);
653 pDoc
->mxAllocedDocShRef
= new ::sd::DrawDocShell(
654 SfxObjectCreateMode::EMBEDDED
, true, meDocType
);
655 pDoc
->mxAllocedDocShRef
->DoInitNew();
656 pNewModel
= pDoc
->mxAllocedDocShRef
->GetDoc();
660 pNewModel
= new SdDrawDocument(meDocType
, nullptr);
666 SdPage
* SdDrawDocument::AllocSdPage(bool bMasterPage
)
668 return new SdPage(*this, bMasterPage
);
671 // This method creates a new page (SdPage) and returns a pointer to said page.
672 // The drawing engine uses this method to create pages (whose types it does
673 // not know, as they are _derivatives_ of SdrPage) when loading.
674 SdrPage
* SdDrawDocument::AllocPage(bool bMasterPage
)
676 return AllocSdPage(bMasterPage
);
679 // When the model has changed
680 void SdDrawDocument::SetChanged(bool bFlag
)
684 if (mbNewOrLoadCompleted
&& mpDocSh
->IsEnableSetModified())
686 // Pass on to base class
687 FmFormModel::SetChanged(bFlag
);
689 // Forward to ObjectShell
690 mpDocSh
->SetModified(bFlag
);
695 // Pass on to base class
696 FmFormModel::SetChanged(bFlag
);
700 // The model changed, don't call anything else
701 void SdDrawDocument::NbcSetChanged(bool bFlag
)
703 // forward to baseclass
704 FmFormModel::SetChanged(bFlag
);
707 // NewOrLoadCompleted is called when the document is loaded, or when it is clear
708 // it won't load any more.
709 void SdDrawDocument::NewOrLoadCompleted(DocCreationMode eMode
)
711 if (eMode
== NEW_DOC
)
714 // create slideshow and default templates,
715 // create pool for virtual controls
716 CreateLayoutTemplates();
717 CreateDefaultCellStyles();
719 static_cast< SdStyleSheetPool
* >( mxStyleSheetPool
.get() )->CreatePseudosIfNecessary();
721 else if (eMode
== DOC_LOADED
)
723 // Document has finished loading
727 if ( GetMasterSdPageCount(PageKind::Standard
) > 1 )
728 RemoveUnnecessaryMasterPages( nullptr, true, false );
730 for ( sal_uInt16 i
= 0; i
< GetPageCount(); i
++ )
732 // Check for correct layout names
733 SdPage
* pPage
= static_cast<SdPage
*>( GetPage( i
) );
735 if(pPage
->TRG_HasMasterPage())
737 SdPage
& rMaster
= static_cast<SdPage
&>(pPage
->TRG_GetMasterPage() );
739 if(rMaster
.GetLayoutName() != pPage
->GetLayoutName())
741 pPage
->SetLayoutName(rMaster
.GetLayoutName());
746 for ( sal_uInt16 nPage
= 0; nPage
< GetMasterPageCount(); nPage
++)
748 // LayoutName and PageName must be the same
749 SdPage
* pPage
= static_cast<SdPage
*>( GetMasterPage( nPage
) );
751 OUString
aName( pPage
->GetLayoutName() );
752 aName
= aName
.copy( 0, aName
.indexOf( SD_LT_SEPARATOR
) );
754 if( aName
!= pPage
->GetName() )
755 pPage
->SetName( aName
);
758 // Create names of the default layers in the user's language
761 // Create names of the styles in the user's language
762 static_cast<SdStyleSheetPool
*>(mxStyleSheetPool
.get())->UpdateStdNames();
764 // Create any missing styles - eg. formerly, there was no Subtitle style
765 static_cast<SdStyleSheetPool
*>(mxStyleSheetPool
.get())->CreatePseudosIfNecessary();
768 // Set default style of Drawing Engine
769 OUString
aName( SdResId(STR_STANDARD_STYLESHEET_NAME
));
770 SetDefaultStyleSheet(static_cast<SfxStyleSheet
*>(mxStyleSheetPool
->Find(aName
, SfxStyleFamily::Para
)));
772 // #i119287# Set default StyleSheet for SdrGrafObj and SdrOle2Obj
773 SetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj(static_cast<SfxStyleSheet
*>(mxStyleSheetPool
->Find(SdResId(STR_POOLSHEET_OBJNOLINENOFILL
), SfxStyleFamily::Para
)));
775 // Initialize DrawOutliner and DocumentOutliner, but don't initialize the
776 // global outliner, as it is not document specific like StyleSheetPool and
777 // StyleRequestHandler are.
778 ::Outliner
& rDrawOutliner
= GetDrawOutliner();
779 rDrawOutliner
.SetStyleSheetPool(static_cast<SfxStyleSheetPool
*>(GetStyleSheetPool()));
780 EEControlBits nCntrl
= rDrawOutliner
.GetControlWord();
782 nCntrl
|= EEControlBits::ONLINESPELLING
;
784 nCntrl
&= ~EEControlBits::ONLINESPELLING
;
785 rDrawOutliner
.SetControlWord(nCntrl
);
787 // Initialize HitTestOutliner and DocumentOutliner, but don't initialize the
788 // global outliner, as it is not document specific like StyleSheetPool and
789 // StyleRequestHandler are.
790 pHitTestOutliner
->SetStyleSheetPool(static_cast<SfxStyleSheetPool
*>(GetStyleSheetPool()));
794 mpOutliner
->SetStyleSheetPool(static_cast<SfxStyleSheetPool
*>(GetStyleSheetPool()));
796 if(mpInternalOutliner
)
798 mpInternalOutliner
->SetStyleSheetPool(static_cast<SfxStyleSheetPool
*>(GetStyleSheetPool()));
801 if ( eMode
== DOC_LOADED
)
803 // Make presentation objects listeners of the appropriate styles
804 SdStyleSheetPool
* pSPool
= static_cast<SdStyleSheetPool
*>( GetStyleSheetPool() );
805 sal_uInt16 nPage
, nPageCount
;
807 // create missing layout style sheets for broken documents
808 // that where created with the 5.2
809 nPageCount
= GetMasterSdPageCount( PageKind::Standard
);
810 for (nPage
= 0; nPage
< nPageCount
; nPage
++)
812 SdPage
* pPage
= GetMasterSdPage(nPage
, PageKind::Standard
);
813 pSPool
->CreateLayoutStyleSheets( pPage
->GetName(), true );
816 // Default and notes pages:
817 for (nPage
= 0; nPage
< GetPageCount(); nPage
++)
819 SdPage
* pPage
= static_cast<SdPage
*>(GetPage(nPage
));
820 NewOrLoadCompleted( pPage
, pSPool
);
824 for (nPage
= 0; nPage
< GetMasterPageCount(); nPage
++)
826 SdPage
* pPage
= static_cast<SdPage
*>(GetMasterPage(nPage
));
828 NewOrLoadCompleted( pPage
, pSPool
);
832 mbNewOrLoadCompleted
= true;
837 /** updates all links, only links in this document should by resolved */
838 void SdDrawDocument::UpdateAllLinks()
840 if (!s_pDocLockedInsertingLinks
&& pLinkManager
&& !pLinkManager
->GetLinks().empty())
842 s_pDocLockedInsertingLinks
= this; // lock inserting links. only links in this document should by resolved
846 comphelper::EmbeddedObjectContainer
& rEmbeddedObjectContainer
= mpDocSh
->getEmbeddedObjectContainer();
847 rEmbeddedObjectContainer
.setUserAllowsLinkUpdate(true);
850 pLinkManager
->UpdateAllLinks(true, false, nullptr); // query box: update all links?
852 if (s_pDocLockedInsertingLinks
== this)
853 s_pDocLockedInsertingLinks
= nullptr; // unlock inserting links
857 /** this loops over the presentation objects of a page and repairs some new settings
858 from old binary files and resets all default strings for empty presentation objects.
860 void SdDrawDocument::NewOrLoadCompleted( SdPage
* pPage
, SdStyleSheetPool
* pSPool
)
862 sd::ShapeList
& rPresentationShapes( pPage
->GetPresentationShapeList() );
863 if(!rPresentationShapes
.isEmpty())
865 // Create lists of title and outline styles
866 OUString aName
= pPage
->GetLayoutName();
867 aName
= aName
.copy( 0, aName
.indexOf( SD_LT_SEPARATOR
) );
869 std::vector
<SfxStyleSheetBase
*> aOutlineList
;
870 pSPool
->CreateOutlineSheetList(aName
,aOutlineList
);
872 SfxStyleSheet
* pTitleSheet
= static_cast<SfxStyleSheet
*>(pSPool
->GetTitleSheet(aName
));
874 SdrObject
* pObj
= nullptr;
875 rPresentationShapes
.seekShape(0);
877 // Now look for title and outline text objects, then make those objects
879 while( (pObj
= rPresentationShapes
.getNextShape()) )
881 if (pObj
->GetObjInventor() == SdrInventor::Default
)
883 OutlinerParaObject
* pOPO
= pObj
->GetOutlinerParaObject();
884 sal_uInt16 nId
= pObj
->GetObjIdentifier();
886 if (nId
== OBJ_TITLETEXT
)
888 if( pOPO
&& pOPO
->GetOutlinerMode() == OutlinerMode::DontKnow
)
889 pOPO
->SetOutlinerMode( OutlinerMode::TitleObject
);
891 // sal_True: don't delete "hard" attributes when doing this.
893 pObj
->SetStyleSheet(pTitleSheet
, true);
895 else if (nId
== OBJ_OUTLINETEXT
)
897 if( pOPO
&& pOPO
->GetOutlinerMode() == OutlinerMode::DontKnow
)
898 pOPO
->SetOutlinerMode( OutlinerMode::OutlineObject
);
900 std::vector
<SfxStyleSheetBase
*>::iterator iter
;
901 for (iter
= aOutlineList
.begin(); iter
!= aOutlineList
.end(); ++iter
)
903 SfxStyleSheet
* pSheet
= static_cast<SfxStyleSheet
*>(*iter
);
907 pObj
->StartListening(*pSheet
);
909 if( iter
== aOutlineList
.begin())
910 // text frame listens to stylesheet of layer 1
911 pObj
->NbcSetStyleSheet(pSheet
, true);
916 if( dynamic_cast< const SdrTextObj
*>( pObj
) != nullptr && pObj
->IsEmptyPresObj())
918 PresObjKind ePresObjKind
= pPage
->GetPresObjKind(pObj
);
919 OUString
aString( pPage
->GetPresObjText(ePresObjKind
) );
921 if (!aString
.isEmpty())
923 SdOutliner
* pInternalOutl
= GetInternalOutliner();
924 pPage
->SetObjText( static_cast<SdrTextObj
*>(pObj
), pInternalOutl
, ePresObjKind
, aString
);
925 pObj
->NbcSetStyleSheet( pPage
->GetStyleSheetForPresObj( ePresObjKind
), true );
926 pInternalOutl
->Clear();
934 // Local outliner that is used for outline mode. In this outliner, OutlinerViews
936 SdOutliner
* SdDrawDocument::GetOutliner(bool bCreateOutliner
)
938 if (!mpOutliner
&& bCreateOutliner
)
940 mpOutliner
.reset(new SdOutliner( this, OutlinerMode::TextObject
));
943 mpOutliner
->SetRefDevice( SD_MOD()->GetVirtualRefDevice() );
945 mpOutliner
->SetDefTab( nDefaultTabulator
);
946 mpOutliner
->SetStyleSheetPool(static_cast<SfxStyleSheetPool
*>(GetStyleSheetPool()));
949 return mpOutliner
.get();
952 // Internal outliner that is used to create text objects. We don't insert any
953 // OutlinerViews into this outliner!
954 SdOutliner
* SdDrawDocument::GetInternalOutliner(bool bCreateOutliner
)
956 if ( !mpInternalOutliner
&& bCreateOutliner
)
958 mpInternalOutliner
.reset( new SdOutliner( this, OutlinerMode::TextObject
) );
960 // This outliner is only used to create special text objects. As no
961 // information about portions is saved in this outliner, the update mode
962 // can/should always remain sal_False.
963 mpInternalOutliner
->SetUpdateMode( false );
964 mpInternalOutliner
->EnableUndo( false );
967 mpInternalOutliner
->SetRefDevice( SD_MOD()->GetVirtualRefDevice() );
969 mpInternalOutliner
->SetDefTab( nDefaultTabulator
);
970 mpInternalOutliner
->SetStyleSheetPool(static_cast<SfxStyleSheetPool
*>(GetStyleSheetPool()));
973 DBG_ASSERT( !mpInternalOutliner
|| ( ! mpInternalOutliner
->GetUpdateMode() ) , "InternalOutliner: UpdateMode = sal_True !" );
974 DBG_ASSERT( !mpInternalOutliner
|| ( ! mpInternalOutliner
->IsUndoEnabled() ), "InternalOutliner: Undo = sal_True !" );
976 // If you add stuff here, always clear it out.
978 // a) no unnecessary Clear calls
979 // b) no wasted memory
980 DBG_ASSERT( !mpInternalOutliner
|| ( ( mpInternalOutliner
->GetParagraphCount() == 1 ) && ( mpInternalOutliner
->GetText( mpInternalOutliner
->GetParagraph( 0 ) ).isEmpty() ) ), "InternalOutliner: not empty!" );
982 return mpInternalOutliner
.get();
985 // OnlineSpelling on/off
986 void SdDrawDocument::SetOnlineSpell(bool bIn
)
989 EEControlBits nCntrl
;
993 nCntrl
= mpOutliner
->GetControlWord();
996 nCntrl
|= EEControlBits::ONLINESPELLING
;
998 nCntrl
&= ~EEControlBits::ONLINESPELLING
;
1000 mpOutliner
->SetControlWord(nCntrl
);
1003 if (mpInternalOutliner
)
1005 nCntrl
= mpInternalOutliner
->GetControlWord();
1008 nCntrl
|= EEControlBits::ONLINESPELLING
;
1010 nCntrl
&= ~EEControlBits::ONLINESPELLING
;
1012 mpInternalOutliner
->SetControlWord(nCntrl
);
1015 ::Outliner
& rOutliner
= GetDrawOutliner();
1017 nCntrl
= rOutliner
.GetControlWord();
1020 nCntrl
|= EEControlBits::ONLINESPELLING
;
1022 nCntrl
&= ~EEControlBits::ONLINESPELLING
;
1024 rOutliner
.SetControlWord(nCntrl
);
1028 StartOnlineSpelling();
1032 StopOnlineSpelling();
1036 // OnlineSpelling: highlighting on/off
1037 uno::Reference
< uno::XInterface
> SdDrawDocument::createUnoModel()
1039 uno::Reference
< uno::XInterface
> xModel
;
1044 xModel
= mpDocSh
->GetModel();
1046 catch( uno::RuntimeException
& )
1053 SvxNumType
SdDrawDocument::GetPageNumType() const
1055 return mePageNumType
;
1058 void SdDrawDocument::SetPrinterIndependentLayout (sal_Int32 nMode
)
1062 case css::document::PrinterIndependentLayout::DISABLED
:
1063 case css::document::PrinterIndependentLayout::ENABLED
:
1064 // Just store supported modes and inform the doc shell
1065 mnPrinterIndependentLayout
= nMode
;
1067 // Since it is possible that a SdDrawDocument is constructed without a
1068 // SdDrawDocShell the pointer member mpDocSh needs to be tested
1069 // before the call is executed. This is e. g. used for copy/paste.
1072 mpDocSh
->UpdateRefDevice ();
1078 // Ignore unknown values
1083 void SdDrawDocument::SetStartWithPresentation( bool bStartWithPresentation
)
1085 mbStartWithPresentation
= bStartWithPresentation
;
1088 void SdDrawDocument::SetExitAfterPresenting( bool bExitAfterPresenting
)
1090 mbExitAfterPresenting
= bExitAfterPresenting
;
1093 void SdDrawDocument::PageListChanged()
1095 mpDrawPageListWatcher
->Invalidate();
1098 void SdDrawDocument::MasterPageListChanged()
1100 mpMasterPageListWatcher
->Invalidate();
1103 void SdDrawDocument::SetCalcFieldValueHdl(::Outliner
* pOutliner
)
1105 pOutliner
->SetCalcFieldValueHdl(LINK(SD_MOD(), SdModule
, CalcFieldValueHdl
));
1108 sal_uInt16
SdDrawDocument::GetAnnotationAuthorIndex( const OUString
& rAuthor
)
1110 // force current user to have first color
1111 if( maAnnotationAuthors
.empty() )
1113 SvtUserOptions aUserOptions
;
1114 maAnnotationAuthors
.push_back( aUserOptions
.GetFullName() );
1118 const std::vector
< OUString
>::const_iterator
aEnd( maAnnotationAuthors
.end());
1119 for( std::vector
< OUString
>::const_iterator
iter( maAnnotationAuthors
.begin() ); iter
!= aEnd
; ++iter
)
1121 if( (*iter
) == rAuthor
)
1128 if( idx
== maAnnotationAuthors
.size() )
1130 maAnnotationAuthors
.push_back( rAuthor
);
1136 void SdDrawDocument::InitLayoutVector()
1138 if (utl::ConfigManager::IsFuzzing())
1141 const Reference
<css::uno::XComponentContext
> xContext(
1142 ::comphelper::getProcessComponentContext() );
1144 // get file list from configuration
1145 Sequence
< rtl::OUString
> aFiles(
1146 officecfg::Office::Impress::Misc::LayoutListFiles::get(xContext
) );
1148 rtl::OUString sFilename
;
1149 for( sal_Int32 i
=0; i
< aFiles
.getLength(); ++i
)
1151 sFilename
= comphelper::getExpandedUri(xContext
, aFiles
[i
]);
1153 // load layout file into DOM
1154 Reference
< XMultiServiceFactory
> xServiceFactory(
1155 xContext
->getServiceManager() , UNO_QUERY_THROW
);
1156 const Reference
<XDocumentBuilder
> xDocBuilder(
1157 DocumentBuilder::create( comphelper::getComponentContext (xServiceFactory
) ));
1161 // loop over every layout entry in current file
1162 const Reference
<XDocument
> xDoc
= xDocBuilder
->parseURI( sFilename
);
1163 const Reference
<XNodeList
> layoutlist
= xDoc
->getElementsByTagName("layout");
1164 const int nElements
= layoutlist
->getLength();
1165 for(int index
=0; index
< nElements
; index
++)
1166 maLayoutInfo
.push_back( layoutlist
->item(index
) );
1168 catch (const uno::Exception
&)
1170 // skip missing config. files
1175 void SdDrawDocument::InitObjectVector()
1177 if (utl::ConfigManager::IsFuzzing())
1180 const Reference
<css::uno::XComponentContext
> xContext(
1181 ::comphelper::getProcessComponentContext() );
1183 // get file list from configuration
1184 Sequence
< rtl::OUString
> aFiles(
1185 officecfg::Office::Impress::Misc::PresObjListFiles::get(xContext
) );
1187 rtl::OUString sFilename
;
1188 for( sal_Int32 i
=0; i
< aFiles
.getLength(); ++i
)
1190 sFilename
= comphelper::getExpandedUri(xContext
, aFiles
[i
]);
1192 // load presentation object file into DOM
1193 Reference
< XMultiServiceFactory
> xServiceFactory(
1194 xContext
->getServiceManager() , UNO_QUERY_THROW
);
1195 const Reference
<XDocumentBuilder
> xDocBuilder(
1196 DocumentBuilder::create( comphelper::getComponentContext (xServiceFactory
) ));
1200 // loop over every object entry in current file
1201 const Reference
<XDocument
> xDoc
= xDocBuilder
->parseURI( sFilename
);
1202 const Reference
<XNodeList
> objectlist
= xDoc
->getElementsByTagName("object");
1203 const int nElements
= objectlist
->getLength();
1204 for(int index
=0; index
< nElements
; index
++)
1205 maPresObjectInfo
.push_back( objectlist
->item(index
) );
1207 catch (const uno::Exception
&)
1209 // skip missing config. files
1214 void SdDrawDocument::dumpAsXml(xmlTextWriterPtr pWriter
) const
1219 pWriter
= xmlNewTextWriterFilename("model.xml", 0);
1220 xmlTextWriterSetIndent(pWriter
,1);
1221 xmlTextWriterSetIndentString(pWriter
, BAD_CAST(" "));
1222 xmlTextWriterStartDocument(pWriter
, nullptr, nullptr, nullptr);
1225 xmlTextWriterStartElement(pWriter
, BAD_CAST("SdDrawDocument"));
1226 xmlTextWriterWriteFormatAttribute(pWriter
, BAD_CAST("ptr"), "%p", this);
1229 mpOutliner
->dumpAsXml(pWriter
);
1230 FmFormModel::dumpAsXml(pWriter
);
1231 if (GetUndoManager())
1232 GetUndoManager()->dumpAsXml(pWriter
);
1234 xmlTextWriterEndElement(pWriter
);
1237 xmlTextWriterEndDocument(pWriter
);
1238 xmlFreeTextWriter(pWriter
);
1242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */