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 <hintids.hxx>
22 #include <osl/diagnose.h>
23 #include <sal/log.hxx>
24 #include <i18nlangtag/languagetag.hxx>
25 #include <i18nlangtag/mslangid.hxx>
26 #include <svtools/ctrltool.hxx>
27 #include <unotools/configmgr.hxx>
28 #include <unotools/lingucfg.hxx>
29 #include <sfx2/docfile.hxx>
30 #include <sfx2/sfxmodelfactory.hxx>
31 #include <sfx2/printer.hxx>
32 #include <svl/asiancfg.hxx>
33 #include <svl/intitem.hxx>
34 #include <editeng/adjustitem.hxx>
35 #include <editeng/autokernitem.hxx>
36 #include <com/sun/star/document/UpdateDocMode.hpp>
37 #include <com/sun/star/i18n/ScriptType.hpp>
38 #include <svx/compatflags.hxx>
39 #include <svx/svxids.hrc>
40 #include <editeng/fhgtitem.hxx>
41 #include <editeng/fontitem.hxx>
42 #include <editeng/flstitem.hxx>
43 #include <editeng/tstpitem.hxx>
44 #include <editeng/langitem.hxx>
45 #include <editeng/colritem.hxx>
46 #include <editeng/orphitem.hxx>
47 #include <editeng/widwitem.hxx>
48 #include <editeng/hyphenzoneitem.hxx>
49 #include <vcl/svapp.hxx>
50 #include <vcl/settings.hxx>
55 #include <swmodule.hxx>
57 #include <IDocumentSettingAccess.hxx>
58 #include <IDocumentDeviceAccess.hxx>
59 #include <IDocumentDrawModelAccess.hxx>
60 #include <IDocumentStylePoolAccess.hxx>
61 #include <IDocumentChartDataProviderAccess.hxx>
62 #include <IDocumentState.hxx>
64 #include <docstyle.hxx>
65 #include <shellio.hxx>
66 #include <swdtflvr.hxx>
67 #include <usrpref.hxx>
68 #include <fontcfg.hxx>
69 #include <poolfmt.hxx>
70 #include <globdoc.hxx>
71 #include <unotxdoc.hxx>
72 #include <linkenum.hxx>
75 #include <unochart.hxx>
76 #include <drawdoc.hxx>
78 #include <svx/CommonStyleManager.hxx>
82 #include <officecfg/Office/Common.hxx>
84 using namespace ::com::sun::star::i18n
;
85 using namespace ::com::sun::star::lang
;
86 using namespace ::com::sun::star::uno
;
87 using namespace ::com::sun::star
;
90 bool SwDocShell::InitNew( const uno::Reference
< embed::XStorage
>& xStor
)
92 bool bRet
= SfxObjectShell::InitNew( xStor
);
93 OSL_ENSURE( GetMapUnit() == MapUnit::MapTwip
, "map unit is not twip!" );
94 bool bHTMLTemplSet
= false;
97 AddLink(); // create m_xDoc / pIo if applicable
99 bool bWeb
= dynamic_cast< const SwWebDocShell
*>( this ) != nullptr;
101 bHTMLTemplSet
= SetHTMLTemplate( *GetDoc() );// Styles from HTML.vor
102 else if( dynamic_cast< const SwGlobalDocShell
*>( this ) != nullptr )
103 GetDoc()->getIDocumentSettingAccess().set(DocumentSettingId::GLOBAL_DOCUMENT
, true); // Globaldokument
105 if ( GetCreateMode() == SfxObjectCreateMode::EMBEDDED
)
106 SwTransferable::InitOle( this );
108 // set forbidden characters if necessary
109 const bool bFuzzing
= utl::ConfigManager::IsFuzzing();
112 SvxAsianConfig aAsian
;
113 const Sequence
<lang::Locale
> aLocales
= aAsian
.GetStartEndCharLocales();
114 for(const lang::Locale
& rLocale
: aLocales
)
116 ForbiddenCharacters aForbidden
;
117 aAsian
.GetStartEndChars( rLocale
, aForbidden
.beginLine
, aForbidden
.endLine
);
118 LanguageType eLang
= LanguageTag::convertToLanguageType(rLocale
);
119 m_xDoc
->getIDocumentSettingAccess().setForbiddenCharacters( eLang
, aForbidden
);
121 m_xDoc
->getIDocumentSettingAccess().set(DocumentSettingId::KERN_ASIAN_PUNCTUATION
,
122 !aAsian
.IsKerningWesternTextOnly());
123 m_xDoc
->getIDocumentSettingAccess().setCharacterCompressionType(aAsian
.GetCharDistanceCompression());
124 m_xDoc
->getIDocumentDeviceAccess().setPrintData(*SW_MOD()->GetPrtOptions(bWeb
));
131 SwStdFontConfig
* pStdFont
= SW_MOD()->GetStdFontConfig();
132 SfxPrinter
* pPrt
= m_xDoc
->getIDocumentDeviceAccess().getPrinter( false );
135 static const sal_uInt16 aFontWhich
[] =
140 static const sal_uInt16 aFontHeightWhich
[] =
143 RES_CHRATR_CJK_FONTSIZE
,
144 RES_CHRATR_CTL_FONTSIZE
146 static const sal_uInt16 aFontIds
[] =
152 static const DefaultFontType nFontTypes
[] =
154 DefaultFontType::LATIN_TEXT
,
155 DefaultFontType::CJK_TEXT
,
156 DefaultFontType::CTL_TEXT
158 static const sal_uInt16 aLangTypes
[] =
161 RES_CHRATR_CJK_LANGUAGE
,
162 RES_CHRATR_CTL_LANGUAGE
165 for(sal_uInt8 i
= 0; i
< 3; i
++)
167 sal_uInt16 nFontWhich
= aFontWhich
[i
];
168 sal_uInt16 nFontId
= aFontIds
[i
];
169 std::unique_ptr
<SvxFontItem
> pFontItem
;
170 const SvxLanguageItem
& rLang
= static_cast<const SvxLanguageItem
&>(m_xDoc
->GetDefault( aLangTypes
[i
] ));
171 LanguageType eLanguage
= rLang
.GetLanguage();
172 if(!pStdFont
->IsFontDefault(nFontId
))
174 sEntry
= pStdFont
->GetFontFor(nFontId
);
176 vcl::Font
aFont( sEntry
, Size( 0, 10 ) );
179 aFont
= pPrt
->GetFontMetric( aFont
);
182 pFontItem
.reset(new SvxFontItem(aFont
.GetFamilyType(), aFont
.GetFamilyName(),
183 OUString(), aFont
.GetPitch(), aFont
.GetCharSet(), nFontWhich
));
187 // #107782# OJ use korean language if latin was used
190 LanguageType eUiLanguage
= Application::GetSettings().GetUILanguageTag().getLanguageType();
191 if (MsLangId::isKorean(eUiLanguage
))
192 eLanguage
= eUiLanguage
;
195 vcl::Font aLangDefFont
= OutputDevice::GetDefaultFont(
198 GetDefaultFontFlags::OnlyOne
);
199 pFontItem
.reset(new SvxFontItem(aLangDefFont
.GetFamilyType(), aLangDefFont
.GetFamilyName(),
200 OUString(), aLangDefFont
.GetPitch(), aLangDefFont
.GetCharSet(), nFontWhich
));
202 m_xDoc
->SetDefault(*pFontItem
);
205 SwTextFormatColl
*pColl
= m_xDoc
->getIDocumentStylePoolAccess().GetTextCollFromPool(RES_POOLCOLL_STANDARD
);
206 pColl
->ResetFormatAttr(nFontWhich
);
209 sal_Int32 nFontHeight
= pStdFont
->GetFontHeight( FONT_STANDARD
, i
, eLanguage
);
211 nFontHeight
= SwStdFontConfig::GetDefaultHeightFor( nFontId
, eLanguage
);
212 m_xDoc
->SetDefault(SvxFontHeightItem( nFontHeight
, 100, aFontHeightWhich
[i
] ));
215 SwTextFormatColl
*pColl
= m_xDoc
->getIDocumentStylePoolAccess().GetTextCollFromPool(RES_POOLCOLL_STANDARD
);
216 pColl
->ResetFormatAttr(aFontHeightWhich
[i
]);
220 sal_uInt16 aFontIdPoolId
[] =
222 FONT_OUTLINE
, RES_POOLCOLL_HEADLINE_BASE
,
223 FONT_LIST
, RES_POOLCOLL_NUMBER_BULLET_BASE
,
224 FONT_CAPTION
, RES_POOLCOLL_LABEL
,
225 FONT_INDEX
, RES_POOLCOLL_REGISTER_BASE
,
226 FONT_OUTLINE_CJK
, RES_POOLCOLL_HEADLINE_BASE
,
227 FONT_LIST_CJK
, RES_POOLCOLL_NUMBER_BULLET_BASE
,
228 FONT_CAPTION_CJK
, RES_POOLCOLL_LABEL
,
229 FONT_INDEX_CJK
, RES_POOLCOLL_REGISTER_BASE
,
230 FONT_OUTLINE_CTL
, RES_POOLCOLL_HEADLINE_BASE
,
231 FONT_LIST_CTL
, RES_POOLCOLL_NUMBER_BULLET_BASE
,
232 FONT_CAPTION_CTL
, RES_POOLCOLL_LABEL
,
233 FONT_INDEX_CTL
, RES_POOLCOLL_REGISTER_BASE
236 sal_uInt16 nFontWhich
= RES_CHRATR_FONT
;
237 sal_uInt16 nFontHeightWhich
= RES_CHRATR_FONTSIZE
;
238 LanguageType eLanguage
= m_xDoc
->GetDefault( RES_CHRATR_LANGUAGE
).GetLanguage();
239 bool bDisableBuiltinStyles
= !bFuzzing
&& officecfg::Office::Common::Load::DisableBuiltinStyles::get();
240 sal_uInt8 nLimit
= bDisableBuiltinStyles
? 0 : 24;
241 for(sal_uInt8 nIdx
= 0; nIdx
< nLimit
; nIdx
+= 2)
245 nFontWhich
= RES_CHRATR_CJK_FONT
;
246 nFontHeightWhich
= RES_CHRATR_CJK_FONTSIZE
;
247 eLanguage
= m_xDoc
->GetDefault( RES_CHRATR_CJK_LANGUAGE
).GetLanguage();
251 nFontWhich
= RES_CHRATR_CTL_FONT
;
252 nFontHeightWhich
= RES_CHRATR_CTL_FONTSIZE
;
253 eLanguage
= m_xDoc
->GetDefault( RES_CHRATR_CTL_LANGUAGE
).GetLanguage();
255 SwTextFormatColl
*pColl
= nullptr;
256 if(!pStdFont
->IsFontDefault(aFontIdPoolId
[nIdx
]))
258 sEntry
= pStdFont
->GetFontFor(aFontIdPoolId
[nIdx
]);
260 vcl::Font
aFont( sEntry
, Size( 0, 10 ) );
262 aFont
= pPrt
->GetFontMetric( aFont
);
264 pColl
= m_xDoc
->getIDocumentStylePoolAccess().GetTextCollFromPool(aFontIdPoolId
[nIdx
+ 1]);
265 if( !bHTMLTemplSet
||
266 SfxItemState::SET
!= pColl
->GetAttrSet().GetItemState(
267 nFontWhich
, false ) )
269 pColl
->SetFormatAttr(SvxFontItem(aFont
.GetFamilyType(), aFont
.GetFamilyName(),
270 OUString(), aFont
.GetPitch(), aFont
.GetCharSet(), nFontWhich
));
273 sal_Int32 nFontHeight
= pStdFont
->GetFontHeight( static_cast< sal_Int8
>(aFontIdPoolId
[nIdx
]), 0, eLanguage
);
275 nFontHeight
= SwStdFontConfig::GetDefaultHeightFor( aFontIdPoolId
[nIdx
], eLanguage
);
277 pColl
= m_xDoc
->getIDocumentStylePoolAccess().GetTextCollFromPool(aFontIdPoolId
[nIdx
+ 1]);
278 SvxFontHeightItem
aFontHeight( static_cast<const SvxFontHeightItem
&>(pColl
->GetFormatAttr( nFontHeightWhich
)));
279 if(aFontHeight
.GetHeight() != sal::static_int_cast
<sal_uInt32
, sal_Int32
>(nFontHeight
))
281 aFontHeight
.SetHeight(nFontHeight
);
282 pColl
->SetFormatAttr( aFontHeight
);
286 // the default for documents created via 'File/New' should be 'on'
287 // (old documents, where this property was not yet implemented, will get the
288 // value 'false' in the SwDoc c-tor)
289 m_xDoc
->getIDocumentSettingAccess().set( DocumentSettingId::MATH_BASELINE_ALIGNMENT
,
290 SW_MOD()->GetUsrPref( bWeb
)->IsAlignMathObjectsToBaseline() );
291 m_xDoc
->getIDocumentSettingAccess().set( DocumentSettingId::FOOTNOTE_IN_COLUMN_TO_PAGEEND
, true);
294 /* #106748# If the default frame direction of a document is RTL
295 the default adjustment is to the right. */
296 if( !bHTMLTemplSet
&&
297 SvxFrameDirection::Horizontal_RL_TB
== GetDefaultFrameDirection(GetAppLanguage()) )
299 m_xDoc
->SetDefault( SvxAdjustItem(SvxAdjust::Right
, RES_PARATR_ADJUST
) );
303 m_xDoc
->SetDefault( SfxBoolItem( RES_COLLAPSING_BORDERS
, true ) );
306 //#i16874# AutoKerning as default for new documents
307 m_xDoc
->SetDefault( SvxAutoKernItem( true, RES_CHRATR_AUTOKERN
) );
309 // #i42080# - Due to the several calls of method <SetDefault(..)>
310 // at the document instance, the document is modified. Thus, reset this
311 // status here. Note: In method <SubInitNew()> this is also done.
312 m_xDoc
->getIDocumentState().ResetModified();
317 // Ctor with SfxCreateMode ?????
318 SwDocShell::SwDocShell( SfxObjectCreateMode
const eMode
)
319 : SfxObjectShell(eMode
)
320 , m_IsInUpdateFontList(false)
321 , m_pStyleManager(new svx::CommonStyleManager(*this))
323 , m_pWrtShell(nullptr)
324 , m_nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG
)
325 , m_IsATemplate(false)
326 , m_IsRemovedInvisibleContent(false)
332 SwDocShell::SwDocShell( const SfxModelFlags i_nSfxCreationFlags
)
333 : SfxObjectShell ( i_nSfxCreationFlags
)
334 , m_IsInUpdateFontList(false)
335 , m_pStyleManager(new svx::CommonStyleManager(*this))
337 , m_pWrtShell(nullptr)
338 , m_nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG
)
339 , m_IsATemplate(false)
340 , m_IsRemovedInvisibleContent(false)
346 SwDocShell::SwDocShell( SwDoc
& rD
, SfxObjectCreateMode
const eMode
)
347 : SfxObjectShell(eMode
)
349 , m_IsInUpdateFontList(false)
350 , m_pStyleManager(new svx::CommonStyleManager(*this))
352 , m_pWrtShell(nullptr)
353 , m_nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG
)
354 , m_IsATemplate(false)
355 , m_IsRemovedInvisibleContent(false)
361 SwDocShell::~SwDocShell()
363 // disable chart related objects now because in ~SwDoc it may be too late for this
366 m_xDoc
->getIDocumentChartDataProviderAccess().GetChartControllerHelper().Disconnect();
367 SwChartDataProvider
*pPCD
= m_xDoc
->getIDocumentChartDataProviderAccess().GetChartDataProvider();
375 // we, as BroadCaster also become our own Listener
376 // (for DocInfo/FileNames/...)
377 EndListening( *this );
379 m_pOLEChildList
.reset();
382 void SwDocShell::Init_Impl()
384 SetPool(&SW_MOD()->GetPool());
385 SetBaseModel(new SwXTextDocument(this));
386 // we, as BroadCaster also become our own Listener
387 // (for DocInfo/FileNames/...)
388 StartListening( *this );
389 //position of the "Automatic" style filter for the stylist (app.src)
390 SetAutoStyleFilterIndex(3);
392 // set map unit to twip
393 SetMapUnit( MapUnit::MapTwip
);
396 void SwDocShell::AddLink()
401 m_xDoc
= &aFactory
.GetDoc();
402 m_xDoc
->getIDocumentSettingAccess().set(DocumentSettingId::HTML_MODE
, dynamic_cast< const SwWebDocShell
*>( this ) != nullptr );
404 m_xDoc
->SetDocShell( this ); // set the DocShell-Pointer for Doc
405 uno::Reference
< text::XTextDocument
> xDoc(GetBaseModel(), uno::UNO_QUERY
);
406 static_cast<SwXTextDocument
*>(xDoc
.get())->Reactivate(this);
408 SetPool(&m_xDoc
->GetAttrPool());
410 // most suitably not until a sdbcx::View is created!!!
411 m_xDoc
->SetOle2Link(LINK(this, SwDocShell
, Ole2ModifiedHdl
));
414 // create new FontList Change Printer
415 void SwDocShell::UpdateFontList()
417 if (!m_IsInUpdateFontList
)
419 m_IsInUpdateFontList
= true;
420 OSL_ENSURE(m_xDoc
, "No Doc no FontList");
423 m_pFontList
.reset( new FontList( m_xDoc
->getIDocumentDeviceAccess().getReferenceDevice(true) ) );
424 PutItem( SvxFontListItem( m_pFontList
.get(), SID_ATTR_CHAR_FONTLIST
) );
426 m_IsInUpdateFontList
= false;
430 void SwDocShell::RemoveLink()
432 // disconnect Uno-Object
433 uno::Reference
< text::XTextDocument
> xDoc(GetBaseModel(), uno::UNO_QUERY
);
434 static_cast<SwXTextDocument
*>(xDoc
.get())->Invalidate();
437 if (m_xBasePool
.is())
439 static_cast<SwDocStyleSheetPool
*>(m_xBasePool
.get())->dispose();
442 m_xDoc
->SetOle2Link(Link
<bool,void>());
443 m_xDoc
->SetDocShell( nullptr );
444 m_xDoc
.clear(); // we don't have the Doc anymore!!
447 void SwDocShell::InvalidateModel()
449 // disconnect Uno-Object
450 uno::Reference
< text::XTextDocument
> xDoc(GetBaseModel(), uno::UNO_QUERY
);
451 static_cast<SwXTextDocument
*>(xDoc
.get())->Invalidate();
453 void SwDocShell::ReactivateModel()
455 // disconnect Uno-Object
456 uno::Reference
< text::XTextDocument
> xDoc(GetBaseModel(), uno::UNO_QUERY
);
457 static_cast<SwXTextDocument
*>(xDoc
.get())->Reactivate(this);
460 // Load, Default-Format
461 bool SwDocShell::Load( SfxMedium
& rMedium
)
465 if (SfxObjectShell::Load(rMedium
))
467 comphelper::EmbeddedObjectContainer
& rEmbeddedObjectContainer
= getEmbeddedObjectContainer();
468 rEmbeddedObjectContainer
.setUserAllowsLinkUpdate(false);
470 SAL_INFO( "sw.ui", "after SfxInPlaceObject::Load" );
471 if (m_xDoc
) // for last version!!
472 RemoveLink(); // release the existing
474 AddLink(); // set Link and update Data!!
476 // Define some settings for legacy ODF files that have different default values now
477 // (if required, they will be overridden later when settings will be read)
478 if (IsOwnStorageFormat(rMedium
))
480 SwDrawModel
* pDrawModel
= m_xDoc
->getIDocumentDrawModelAccess().GetDrawModel();
483 pDrawModel
->SetCompatibilityFlag(SdrCompatibilityFlag::AnchoredTextOverflowLegacy
,
484 true); // legacy processing for tdf#99729
485 pDrawModel
->SetCompatibilityFlag(SdrCompatibilityFlag::LegacySingleLineFontwork
,
486 true); // legacy processing for tdf#148000
492 OSL_ENSURE( !m_xBasePool
.is(), "who hasn't destroyed their Pool?" );
493 m_xBasePool
= new SwDocStyleSheetPool( *m_xDoc
, SfxObjectCreateMode::ORGANIZER
== GetCreateMode() );
494 if(GetCreateMode() != SfxObjectCreateMode::ORGANIZER
)
496 const SfxUInt16Item
* pUpdateDocItem
= SfxItemSet::GetItem
<SfxUInt16Item
>(rMedium
.GetItemSet(), SID_UPDATEDOCMODE
, false);
497 m_nUpdateDocMode
= pUpdateDocItem
? pUpdateDocItem
->GetValue() : document::UpdateDocMode::NO_UPDATE
;
500 SwWait
aWait( *this, true );
501 ErrCode nErr
= ERR_SWG_READ_ERROR
;
502 switch( GetCreateMode() )
504 case SfxObjectCreateMode::ORGANIZER
:
508 ReadXML
->SetOrganizerMode( true );
509 SwReader
aRdr(rMedium
, OUString(), m_xDoc
.get());
510 nErr
= aRdr
.Read( *ReadXML
);
511 ReadXML
->SetOrganizerMode( false );
516 case SfxObjectCreateMode::INTERNAL
:
517 case SfxObjectCreateMode::EMBEDDED
:
519 SwTransferable::InitOle( this );
521 // suppress SfxProgress, when we are Embedded
522 SW_MOD()->SetEmbeddedLoadSave( true );
525 case SfxObjectCreateMode::STANDARD
:
527 Reader
*pReader
= ReadXML
;
530 // set Doc's DocInfo at DocShell-Medium
531 SAL_INFO( "sw.ui", "before ReadDocInfo" );
532 SwReader
aRdr(rMedium
, OUString(), m_xDoc
.get());
533 SAL_INFO( "sw.ui", "before Read" );
534 nErr
= aRdr
.Read( *pReader
);
535 SAL_INFO( "sw.ui", "after Read" );
536 // If a XML document is loaded, the global doc/web doc
537 // flags have to be set, because they aren't loaded
539 if( dynamic_cast< const SwWebDocShell
*>( this ) != nullptr )
541 if (!m_xDoc
->getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE
))
542 m_xDoc
->getIDocumentSettingAccess().set(DocumentSettingId::HTML_MODE
, true);
544 if( dynamic_cast< const SwGlobalDocShell
*>( this ) != nullptr )
546 if (!m_xDoc
->getIDocumentSettingAccess().get(DocumentSettingId::GLOBAL_DOCUMENT
))
547 m_xDoc
->getIDocumentSettingAccess().set(DocumentSettingId::GLOBAL_DOCUMENT
, true);
554 OSL_ENSURE( false, "Load: new CreateMode?" );
558 InitDrawModelAndDocShell(this, m_xDoc
? m_xDoc
->getIDocumentDrawModelAccess().GetDrawModel()
562 bRet
= !nErr
.IsError();
564 if (bRet
&& !m_xDoc
->IsInLoadAsynchron() &&
565 GetCreateMode() == SfxObjectCreateMode::STANDARD
)
570 // suppress SfxProgress, when we are Embedded
571 SW_MOD()->SetEmbeddedLoadSave( false );
577 bool SwDocShell::LoadFrom( SfxMedium
& rMedium
)
583 AddLink(); // set Link and update Data!!
585 do { // middle check loop
586 ErrCode nErr
= ERR_SWG_READ_ERROR
;
587 OUString aStreamName
= "styles.xml";
588 uno::Reference
< container::XNameAccess
> xAccess
= rMedium
.GetStorage();
589 if ( xAccess
->hasByName( aStreamName
) && rMedium
.GetStorage()->isStreamElement( aStreamName
) )
592 SwWait
aWait( *this, true );
594 OSL_ENSURE( !m_xBasePool
.is(), "who hasn't destroyed their Pool?" );
595 m_xBasePool
= new SwDocStyleSheetPool( *m_xDoc
, SfxObjectCreateMode::ORGANIZER
== GetCreateMode() );
598 ReadXML
->SetOrganizerMode( true );
599 SwReader
aRdr(rMedium
, OUString(), m_xDoc
.get());
600 nErr
= aRdr
.Read( *ReadXML
);
601 ReadXML
->SetOrganizerMode( false );
607 OSL_FAIL("Code removed!");
611 bRet
= !nErr
.IsError();
615 SfxObjectShell::LoadFrom( rMedium
);
616 m_xDoc
->getIDocumentState().ResetModified();
620 void SwDocShell::SubInitNew()
622 OSL_ENSURE( !m_xBasePool
.is(), "who hasn't destroyed their Pool?" );
623 m_xBasePool
= new SwDocStyleSheetPool( *m_xDoc
, SfxObjectCreateMode::ORGANIZER
== GetCreateMode() );
625 InitDrawModelAndDocShell(this, m_xDoc
? m_xDoc
->getIDocumentDrawModelAccess().GetDrawModel() : nullptr);
627 m_xDoc
->getIDocumentSettingAccess().setLinkUpdateMode( GLOBALSETTING
);
628 m_xDoc
->getIDocumentSettingAccess().setFieldUpdateFlags( AUTOUPD_GLOBALSETTING
);
630 bool bWeb
= dynamic_cast< const SwWebDocShell
*>( this ) != nullptr;
632 static const WhichRangesContainer
nRange1(svl::Items
<
633 RES_CHRATR_COLOR
, RES_CHRATR_COLOR
,
634 RES_CHRATR_LANGUAGE
, RES_CHRATR_LANGUAGE
,
635 RES_CHRATR_CJK_LANGUAGE
, RES_CHRATR_CJK_LANGUAGE
,
636 RES_CHRATR_CTL_LANGUAGE
, RES_CHRATR_CTL_LANGUAGE
,
637 RES_PARATR_ADJUST
, RES_PARATR_ADJUST
639 static const WhichRangesContainer
nRange2(svl::Items
<
640 RES_CHRATR_COLOR
, RES_CHRATR_COLOR
,
641 RES_CHRATR_LANGUAGE
, RES_CHRATR_LANGUAGE
,
642 RES_CHRATR_CJK_LANGUAGE
, RES_CHRATR_CJK_LANGUAGE
,
643 RES_CHRATR_CTL_LANGUAGE
, RES_CHRATR_CTL_LANGUAGE
,
644 RES_PARATR_ADJUST
, RES_PARATR_ADJUST
,
645 RES_PARATR_TABSTOP
, RES_PARATR_HYPHENZONE
647 SfxItemSet
aDfltSet( m_xDoc
->GetAttrPool(), bWeb
? nRange1
: nRange2
);
649 //! get lingu options without loading lingu DLL
650 SvtLinguOptions aLinguOpt
;
652 const bool bFuzzing
= utl::ConfigManager::IsFuzzing();
654 SvtLinguConfig().GetOptions(aLinguOpt
);
656 LanguageType nVal
= MsLangId::resolveSystemLanguageByScriptType(aLinguOpt
.nDefaultLanguage
, css::i18n::ScriptType::LATIN
),
657 eCJK
= MsLangId::resolveSystemLanguageByScriptType(aLinguOpt
.nDefaultLanguage_CJK
, css::i18n::ScriptType::ASIAN
),
658 eCTL
= MsLangId::resolveSystemLanguageByScriptType(aLinguOpt
.nDefaultLanguage_CTL
, css::i18n::ScriptType::COMPLEX
);
659 aDfltSet
.Put( SvxLanguageItem( nVal
, RES_CHRATR_LANGUAGE
) );
660 aDfltSet
.Put( SvxLanguageItem( eCJK
, RES_CHRATR_CJK_LANGUAGE
) );
661 aDfltSet
.Put( SvxLanguageItem( eCTL
, RES_CHRATR_CTL_LANGUAGE
) );
665 SvxHyphenZoneItem
aHyp( m_xDoc
->GetDefault(RES_PARATR_HYPHENZONE
) );
666 aHyp
.GetMinLead() = static_cast< sal_uInt8
>(aLinguOpt
.nHyphMinLeading
);
667 aHyp
.GetMinTrail() = static_cast< sal_uInt8
>(aLinguOpt
.nHyphMinTrailing
);
668 aHyp
.GetMinWordLength() = static_cast< sal_uInt8
>(aLinguOpt
.nHyphMinWordLength
);
670 aDfltSet
.Put( aHyp
);
672 sal_uInt16 nNewPos
= o3tl::toTwips(SW_MOD()->GetUsrPref(false)->GetDefTabInMm100(), o3tl::Length::mm100
);
674 aDfltSet
.Put( SvxTabStopItem( 1, nNewPos
,
675 SvxTabAdjust::Default
, RES_PARATR_TABSTOP
) );
677 aDfltSet
.Put( SvxColorItem( COL_AUTO
, RES_CHRATR_COLOR
) );
679 m_xDoc
->SetDefault( aDfltSet
);
681 //default page mode for text grid
684 bool bSquaredPageMode
= SW_MOD()->GetUsrPref(false)->IsSquaredPageMode();
685 m_xDoc
->SetDefaultPageMode( bSquaredPageMode
);
687 // only set Widow/Orphan defaults on a new, non-web document - not an opened one
688 if (GetMedium() && GetMedium()->GetOrigURL().isEmpty() && !bFuzzing
)
690 m_xDoc
->SetDefault( SvxWidowsItem( sal_uInt8(2), RES_PARATR_WIDOWS
) );
691 m_xDoc
->SetDefault( SvxOrphansItem( sal_uInt8(2), RES_PARATR_ORPHANS
) );
695 m_xDoc
->getIDocumentState().ResetModified();
699 * Document Interface Access
701 IDocumentDeviceAccess
& SwDocShell::getIDocumentDeviceAccess()
703 return m_xDoc
->getIDocumentDeviceAccess();
706 IDocumentChartDataProviderAccess
& SwDocShell::getIDocumentChartDataProviderAccess()
708 return m_xDoc
->getIDocumentChartDataProviderAccess();
711 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */