Drop some needless mappings to identical strings
[LibreOffice.git] / sw / source / uibase / app / docshini.cxx
blob90d9629b1d2f93d43c1379ef204484fe591fcb43
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <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>
51 #include <prtopt.hxx>
52 #include <fmtcol.hxx>
53 #include <docsh.hxx>
54 #include <wdocsh.hxx>
55 #include <swmodule.hxx>
56 #include <doc.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>
63 #include <docfac.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>
73 #include <swwait.hxx>
74 #include <swerror.h>
75 #include <unochart.hxx>
76 #include <drawdoc.hxx>
78 #include <svx/CommonStyleManager.hxx>
80 #include <memory>
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;
89 // Load Document
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;
95 if( bRet )
97 AddLink(); // create m_xDoc / pIo if applicable
99 bool bWeb = dynamic_cast< const SwWebDocShell *>( this ) != nullptr;
100 if ( bWeb )
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 SwModule* mod = SwModule::get();
109 // set forbidden characters if necessary
110 const bool bFuzzing = comphelper::IsFuzzing();
111 if (!bFuzzing)
113 const Sequence<lang::Locale> aLocales = SvxAsianConfig::GetStartEndCharLocales();
114 for(const lang::Locale& rLocale : aLocales)
116 ForbiddenCharacters aForbidden;
117 SvxAsianConfig::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 !SvxAsianConfig::IsKerningWesternTextOnly());
123 m_xDoc->getIDocumentSettingAccess().setCharacterCompressionType(SvxAsianConfig::GetCharDistanceCompression());
124 m_xDoc->getIDocumentDeviceAccess().setPrintData(*mod->GetPrtOptions(bWeb));
127 SubInitNew();
129 // for all
131 SwStdFontConfig* pStdFont = mod->GetStdFontConfig();
132 SfxPrinter* pPrt = m_xDoc->getIDocumentDeviceAccess().getPrinter( false );
134 OUString sEntry;
135 static const sal_uInt16 aFontWhich[] =
136 { RES_CHRATR_FONT,
137 RES_CHRATR_CJK_FONT,
138 RES_CHRATR_CTL_FONT
140 static const sal_uInt16 aFontHeightWhich[] =
142 RES_CHRATR_FONTSIZE,
143 RES_CHRATR_CJK_FONTSIZE,
144 RES_CHRATR_CTL_FONTSIZE
146 static const sal_uInt16 aFontIds[] =
148 FONT_STANDARD,
149 FONT_STANDARD_CJK,
150 FONT_STANDARD_CTL
152 static const DefaultFontType nFontTypes[] =
154 DefaultFontType::LATIN_TEXT,
155 DefaultFontType::CJK_TEXT,
156 DefaultFontType::CTL_TEXT
158 static const sal_uInt16 aLangTypes[] =
160 RES_CHRATR_LANGUAGE,
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 ) );
177 if( pPrt )
179 aFont = pPrt->GetFontMetric( aFont );
182 pFontItem.reset(new SvxFontItem(aFont.GetFamilyType(), aFont.GetFamilyName(),
183 OUString(), aFont.GetPitch(), aFont.GetCharSet(), nFontWhich));
185 else
187 // #107782# OJ use korean language if latin was used
188 if ( i == 0 )
190 LanguageType eUiLanguage = Application::GetSettings().GetUILanguageTag().getLanguageType();
191 if (MsLangId::isKorean(eUiLanguage))
192 eLanguage = eUiLanguage;
195 vcl::Font aLangDefFont = OutputDevice::GetDefaultFont(
196 nFontTypes[i],
197 eLanguage,
198 GetDefaultFontFlags::OnlyOne );
199 pFontItem.reset(new SvxFontItem(aLangDefFont.GetFamilyType(), aLangDefFont.GetFamilyName(),
200 OUString(), aLangDefFont.GetPitch(), aLangDefFont.GetCharSet(), nFontWhich));
202 m_xDoc->SetDefault(*pFontItem);
203 if( !bHTMLTemplSet )
205 SwTextFormatColl *pColl = m_xDoc->getIDocumentStylePoolAccess().GetTextCollFromPool(RES_POOLCOLL_STANDARD);
206 pColl->ResetFormatAttr(nFontWhich);
208 pFontItem.reset();
209 sal_Int32 nFontHeight = pStdFont->GetFontHeight( FONT_STANDARD, i, eLanguage );
210 if(nFontHeight <= 0)
211 nFontHeight = SwStdFontConfig::GetDefaultHeightFor( nFontId, eLanguage );
212 m_xDoc->SetDefault(SvxFontHeightItem( nFontHeight, 100, aFontHeightWhich[i] ));
213 if( !bHTMLTemplSet )
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 TypedWhichId<SvxFontItem> nFontWhich = RES_CHRATR_FONT;
237 TypedWhichId<SvxFontHeightItem> 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)
243 if(nIdx == 8)
245 nFontWhich = RES_CHRATR_CJK_FONT;
246 nFontHeightWhich = RES_CHRATR_CJK_FONTSIZE;
247 eLanguage = m_xDoc->GetDefault( RES_CHRATR_CJK_LANGUAGE ).GetLanguage();
249 else if(nIdx == 16)
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 ) );
261 if( pPrt )
262 aFont = pPrt->GetFontMetric( aFont );
264 pColl = m_xDoc->getIDocumentStylePoolAccess().GetTextCollFromPool(aFontIdPoolId[nIdx + 1]);
265 assert(pColl);
266 if( !bHTMLTemplSet ||
267 SfxItemState::SET != pColl->GetAttrSet().GetItemState(
268 nFontWhich, false ) )
270 pColl->SetFormatAttr(SvxFontItem(aFont.GetFamilyType(), aFont.GetFamilyName(),
271 OUString(), aFont.GetPitch(), aFont.GetCharSet(), nFontWhich));
274 sal_Int32 nFontHeight = pStdFont->GetFontHeight( static_cast< sal_Int8 >(aFontIdPoolId[nIdx]), 0, eLanguage );
275 if(nFontHeight <= 0)
276 nFontHeight = SwStdFontConfig::GetDefaultHeightFor( aFontIdPoolId[nIdx], eLanguage );
277 if(!pColl)
278 pColl = m_xDoc->getIDocumentStylePoolAccess().GetTextCollFromPool(aFontIdPoolId[nIdx + 1]);
279 SvxFontHeightItem aFontHeight( pColl->GetFormatAttr( nFontHeightWhich ) );
280 if(aFontHeight.GetHeight() != sal::static_int_cast<sal_uInt32, sal_Int32>(nFontHeight))
282 aFontHeight.SetHeight(nFontHeight);
283 pColl->SetFormatAttr( aFontHeight );
287 // the default for documents created via 'File/New' should be 'on'
288 // (old documents, where this property was not yet implemented, will get the
289 // value 'false' in the SwDoc c-tor)
290 m_xDoc->getIDocumentSettingAccess().set( DocumentSettingId::MATH_BASELINE_ALIGNMENT,
291 mod->GetUsrPref( bWeb )->IsAlignMathObjectsToBaseline() );
292 m_xDoc->getIDocumentSettingAccess().set( DocumentSettingId::FOOTNOTE_IN_COLUMN_TO_PAGEEND, true);
295 /* #106748# If the default frame direction of a document is RTL
296 the default adjustment is to the right. */
297 if( !bHTMLTemplSet &&
298 SvxFrameDirection::Horizontal_RL_TB == GetDefaultFrameDirection(GetAppLanguage()) )
300 m_xDoc->SetDefault( SvxAdjustItem(SvxAdjust::Right, RES_PARATR_ADJUST ) );
303 // #i29550#
304 m_xDoc->SetDefault( SfxBoolItem( RES_COLLAPSING_BORDERS, true ) );
305 // <-- collapsing
307 //#i16874# AutoKerning as default for new documents
308 m_xDoc->SetDefault( SvxAutoKernItem( true, RES_CHRATR_AUTOKERN ) );
310 // #i42080# - Due to the several calls of method <SetDefault(..)>
311 // at the document instance, the document is modified. Thus, reset this
312 // status here. Note: In method <SubInitNew()> this is also done.
313 m_xDoc->getIDocumentState().ResetModified();
315 return bRet;
318 // Ctor with SfxCreateMode ?????
319 SwDocShell::SwDocShell( SfxObjectCreateMode const eMode )
320 : SfxObjectShell(eMode)
321 , m_IsInUpdateFontList(false)
322 , m_pStyleManager(new svx::CommonStyleManager(*this))
323 , m_pView(nullptr)
324 , m_pWrtShell(nullptr)
325 , m_nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG)
326 , m_IsATemplate(false)
327 , m_IsRemovedInvisibleContent(false)
329 Init_Impl();
332 // Ctor / Dtor
333 SwDocShell::SwDocShell( const SfxModelFlags i_nSfxCreationFlags )
334 : SfxObjectShell ( i_nSfxCreationFlags )
335 , m_IsInUpdateFontList(false)
336 , m_pStyleManager(new svx::CommonStyleManager(*this))
337 , m_pView(nullptr)
338 , m_pWrtShell(nullptr)
339 , m_nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG)
340 , m_IsATemplate(false)
341 , m_IsRemovedInvisibleContent(false)
343 Init_Impl();
346 // Ctor / Dtor
347 SwDocShell::SwDocShell( SwDoc& rD, SfxObjectCreateMode const eMode )
348 : SfxObjectShell(eMode)
349 , m_xDoc(&rD)
350 , m_IsInUpdateFontList(false)
351 , m_pStyleManager(new svx::CommonStyleManager(*this))
352 , m_pView(nullptr)
353 , m_pWrtShell(nullptr)
354 , m_nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG)
355 , m_IsATemplate(false)
356 , m_IsRemovedInvisibleContent(false)
358 Init_Impl();
361 // Dtor
362 SwDocShell::~SwDocShell()
364 // disable chart related objects now because in ~SwDoc it may be too late for this
365 if (m_xDoc)
367 m_xDoc->getIDocumentChartDataProviderAccess().GetChartControllerHelper().Disconnect();
368 SwChartDataProvider *pPCD = m_xDoc->getIDocumentChartDataProviderAccess().GetChartDataProvider();
369 if (pPCD)
370 pPCD->dispose();
373 RemoveLink();
374 m_pFontList.reset();
376 // we, as BroadCaster also become our own Listener
377 // (for DocInfo/FileNames/...)
378 EndListening( *this );
380 m_pOLEChildList.reset();
383 void SwDocShell::Init_Impl()
385 SetPool(&SwModule::get()->GetPool());
386 SetBaseModel(new SwXTextDocument(this));
387 // we, as BroadCaster also become our own Listener
388 // (for DocInfo/FileNames/...)
389 StartListening( *this );
390 //position of the "Automatic" style filter for the stylist (app.src)
391 SetAutoStyleFilterIndex(3);
393 // set map unit to twip
394 SetMapUnit( MapUnit::MapTwip );
397 void SwDocShell::AddLink()
399 if (!m_xDoc)
401 SwDocFac aFactory;
402 m_xDoc = &aFactory.GetDoc();
403 m_xDoc->getIDocumentSettingAccess().set(DocumentSettingId::HTML_MODE, dynamic_cast< const SwWebDocShell *>( this ) != nullptr );
405 m_xDoc->SetDocShell( this ); // set the DocShell-Pointer for Doc
406 rtl::Reference< SwXTextDocument > xDoc(GetBaseModel());
407 xDoc->Reactivate(this);
409 SetPool(&m_xDoc->GetAttrPool());
411 // most suitably not until a sdbcx::View is created!!!
412 m_xDoc->SetOle2Link(LINK(this, SwDocShell, Ole2ModifiedHdl));
415 // create new FontList Change Printer
416 void SwDocShell::UpdateFontList()
418 if (!m_IsInUpdateFontList)
420 m_IsInUpdateFontList = true;
421 OSL_ENSURE(m_xDoc, "No Doc no FontList");
422 if (m_xDoc)
424 m_pFontList.reset( new FontList( m_xDoc->getIDocumentDeviceAccess().getReferenceDevice(true) ) );
425 PutItem( SvxFontListItem( m_pFontList.get(), SID_ATTR_CHAR_FONTLIST ) );
427 m_IsInUpdateFontList = false;
431 void SwDocShell::RemoveLink()
433 // disconnect Uno-Object
434 rtl::Reference< SwXTextDocument > xDoc(GetBaseModel());
435 xDoc->Invalidate();
436 if (m_xDoc)
438 if (m_xBasePool.is())
440 m_xBasePool->dispose();
441 m_xBasePool.clear();
443 m_xDoc->SetOle2Link(Link<bool,void>());
444 m_xDoc->SetDocShell( nullptr );
445 m_xDoc.clear(); // we don't have the Doc anymore!!
448 void SwDocShell::InvalidateModel()
450 // disconnect Uno-Object
451 rtl::Reference< SwXTextDocument > xDoc(GetBaseModel());
452 xDoc->Invalidate();
454 void SwDocShell::ReactivateModel()
456 // disconnect Uno-Object
457 rtl::Reference< SwXTextDocument > xDoc(GetBaseModel());
458 xDoc->Reactivate(this);
461 // Load, Default-Format
462 bool SwDocShell::Load( SfxMedium& rMedium )
464 bool bRet = false;
466 if (SfxObjectShell::Load(rMedium))
468 comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer = getEmbeddedObjectContainer();
469 rEmbeddedObjectContainer.setUserAllowsLinkUpdate(false);
471 SAL_INFO( "sw.ui", "after SfxInPlaceObject::Load" );
472 if (m_xDoc) // for last version!!
473 RemoveLink(); // release the existing
475 AddLink(); // set Link and update Data!!
477 // Define some settings for legacy ODF files that have different default values now
478 // (if required, they will be overridden later when settings will be read)
479 if (IsOwnStorageFormat(rMedium))
481 SwDrawModel* pDrawModel = m_xDoc->getIDocumentDrawModelAccess().GetDrawModel();
482 if (pDrawModel)
484 pDrawModel->SetCompatibilityFlag(SdrCompatibilityFlag::AnchoredTextOverflowLegacy,
485 true); // legacy processing for tdf#99729
486 pDrawModel->SetCompatibilityFlag(SdrCompatibilityFlag::LegacyFontwork,
487 true); // legacy processing for tdf#148000
491 // Loading
492 // for MD
493 OSL_ENSURE( !m_xBasePool.is(), "who hasn't destroyed their Pool?" );
494 m_xBasePool = new SwDocStyleSheetPool( *m_xDoc, SfxObjectCreateMode::ORGANIZER == GetCreateMode() );
495 if(GetCreateMode() != SfxObjectCreateMode::ORGANIZER)
497 const SfxUInt16Item* pUpdateDocItem = rMedium.GetItemSet().GetItem(SID_UPDATEDOCMODE, false);
498 m_nUpdateDocMode = pUpdateDocItem ? pUpdateDocItem->GetValue() : document::UpdateDocMode::NO_UPDATE;
501 SwModule* mod = SwModule::get();
502 SwWait aWait( *this, true );
503 ErrCodeMsg nErr = ERR_SWG_READ_ERROR;
504 switch( GetCreateMode() )
506 case SfxObjectCreateMode::ORGANIZER:
508 if( ReadXML )
510 ReadXML->SetOrganizerMode( true );
511 SwReader aRdr(rMedium, OUString(), m_xDoc.get());
512 nErr = aRdr.Read( *ReadXML );
513 ReadXML->SetOrganizerMode( false );
516 break;
518 case SfxObjectCreateMode::INTERNAL:
519 case SfxObjectCreateMode::EMBEDDED:
521 SwTransferable::InitOle( this );
523 // suppress SfxProgress, when we are Embedded
524 mod->SetEmbeddedLoadSave( true );
525 [[fallthrough]];
527 case SfxObjectCreateMode::STANDARD:
529 Reader *pReader = ReadXML;
530 if( pReader )
532 // set Doc's DocInfo at DocShell-Medium
533 SAL_INFO( "sw.ui", "before ReadDocInfo" );
534 SwReader aRdr(rMedium, OUString(), m_xDoc.get());
535 SAL_INFO( "sw.ui", "before Read" );
536 nErr = aRdr.Read( *pReader );
537 SAL_INFO( "sw.ui", "after Read" );
538 // If a XML document is loaded, the global doc/web doc
539 // flags have to be set, because they aren't loaded
540 // by this formats.
541 if( dynamic_cast< const SwWebDocShell *>( this ) != nullptr )
543 if (!m_xDoc->getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE))
544 m_xDoc->getIDocumentSettingAccess().set(DocumentSettingId::HTML_MODE, true);
546 if( dynamic_cast< const SwGlobalDocShell *>( this ) != nullptr )
548 if (!m_xDoc->getIDocumentSettingAccess().get(DocumentSettingId::GLOBAL_DOCUMENT))
549 m_xDoc->getIDocumentSettingAccess().set(DocumentSettingId::GLOBAL_DOCUMENT, true);
553 break;
555 default:
556 OSL_ENSURE( false, "Load: new CreateMode?" );
559 UpdateFontList();
560 InitDrawModelAndDocShell(this, m_xDoc ? m_xDoc->getIDocumentDrawModelAccess().GetDrawModel()
561 : nullptr);
563 SetError(nErr);
564 bRet = !nErr.IsError();
566 if (bRet && !m_xDoc->IsInLoadAsynchron() &&
567 GetCreateMode() == SfxObjectCreateMode::STANDARD)
569 LoadingFinished();
572 // suppress SfxProgress, when we are Embedded
573 mod->SetEmbeddedLoadSave( false );
576 return bRet;
579 bool SwDocShell::LoadFrom( SfxMedium& rMedium )
581 bool bRet = false;
582 if (m_xDoc)
583 RemoveLink();
585 AddLink(); // set Link and update Data!!
587 do { // middle check loop
588 ErrCodeMsg nErr = ERR_SWG_READ_ERROR;
589 OUString aStreamName = u"styles.xml"_ustr;
590 uno::Reference < container::XNameAccess > xAccess = rMedium.GetStorage();
591 if ( xAccess->hasByName( aStreamName ) && rMedium.GetStorage()->isStreamElement( aStreamName ) )
593 // Loading
594 SwWait aWait( *this, true );
596 OSL_ENSURE( !m_xBasePool.is(), "who hasn't destroyed their Pool?" );
597 m_xBasePool = new SwDocStyleSheetPool( *m_xDoc, SfxObjectCreateMode::ORGANIZER == GetCreateMode() );
598 if( ReadXML )
600 ReadXML->SetOrganizerMode( true );
601 SwReader aRdr(rMedium, OUString(), m_xDoc.get());
602 nErr = aRdr.Read( *ReadXML );
603 ReadXML->SetOrganizerMode( false );
607 else
609 OSL_FAIL("Code removed!");
612 SetError(nErr);
613 bRet = !nErr.IsError();
615 } while( false );
617 SfxObjectShell::LoadFrom( rMedium );
618 m_xDoc->getIDocumentState().ResetModified();
619 return bRet;
622 void SwDocShell::SubInitNew()
624 OSL_ENSURE( !m_xBasePool.is(), "who hasn't destroyed their Pool?" );
625 m_xBasePool = new SwDocStyleSheetPool( *m_xDoc, SfxObjectCreateMode::ORGANIZER == GetCreateMode() );
626 UpdateFontList();
627 InitDrawModelAndDocShell(this, m_xDoc ? m_xDoc->getIDocumentDrawModelAccess().GetDrawModel() : nullptr);
629 m_xDoc->getIDocumentSettingAccess().setLinkUpdateMode( GLOBALSETTING );
630 m_xDoc->getIDocumentSettingAccess().setFieldUpdateFlags( AUTOUPD_GLOBALSETTING );
632 bool bWeb = dynamic_cast< const SwWebDocShell *>( this ) != nullptr;
634 static const WhichRangesContainer nRange1(svl::Items<
635 RES_CHRATR_COLOR, RES_CHRATR_COLOR,
636 RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE,
637 RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE,
638 RES_CHRATR_CTL_LANGUAGE, RES_CHRATR_CTL_LANGUAGE,
639 RES_PARATR_ADJUST, RES_PARATR_ADJUST
641 static const WhichRangesContainer nRange2(svl::Items<
642 RES_CHRATR_COLOR, RES_CHRATR_COLOR,
643 RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE,
644 RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE,
645 RES_CHRATR_CTL_LANGUAGE, RES_CHRATR_CTL_LANGUAGE,
646 RES_PARATR_ADJUST, RES_PARATR_ADJUST,
647 RES_PARATR_TABSTOP, RES_PARATR_HYPHENZONE
649 SfxItemSet aDfltSet( m_xDoc->GetAttrPool(), bWeb ? nRange1 : nRange2 );
651 //! get lingu options without loading lingu DLL
652 SvtLinguOptions aLinguOpt;
654 const bool bFuzzing = comphelper::IsFuzzing();
655 if (!bFuzzing)
656 SvtLinguConfig().GetOptions(aLinguOpt);
658 LanguageType nVal = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, css::i18n::ScriptType::LATIN),
659 eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, css::i18n::ScriptType::ASIAN),
660 eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, css::i18n::ScriptType::COMPLEX);
661 aDfltSet.Put( SvxLanguageItem( nVal, RES_CHRATR_LANGUAGE ) );
662 aDfltSet.Put( SvxLanguageItem( eCJK, RES_CHRATR_CJK_LANGUAGE ) );
663 aDfltSet.Put( SvxLanguageItem( eCTL, RES_CHRATR_CTL_LANGUAGE ) );
665 if(!bWeb)
667 SvxHyphenZoneItem aHyp( m_xDoc->GetDefault(RES_PARATR_HYPHENZONE) );
668 aHyp.GetMinLead() = static_cast< sal_uInt8 >(aLinguOpt.nHyphMinLeading);
669 aHyp.GetMinTrail() = static_cast< sal_uInt8 >(aLinguOpt.nHyphMinTrailing);
670 aHyp.GetMinWordLength() = static_cast< sal_uInt8 >(aLinguOpt.nHyphMinWordLength);
672 aDfltSet.Put( aHyp );
674 sal_uInt16 nNewPos = o3tl::toTwips(SwModule::get()->GetUsrPref(false)->GetDefTabInMm100(), o3tl::Length::mm100);
675 if( nNewPos )
676 aDfltSet.Put( SvxTabStopItem( 1, nNewPos,
677 SvxTabAdjust::Default, RES_PARATR_TABSTOP ) );
679 aDfltSet.Put( SvxColorItem( COL_AUTO, RES_CHRATR_COLOR ) );
681 m_xDoc->SetDefault( aDfltSet );
683 //default page mode for text grid
684 if(!bWeb)
686 bool bSquaredPageMode = SwModule::get()->GetUsrPref(false)->IsSquaredPageMode();
687 m_xDoc->SetDefaultPageMode( bSquaredPageMode );
689 // only set Widow/Orphan defaults on a new, non-web document - not an opened one
690 if (GetMedium() && GetMedium()->GetOrigURL().isEmpty() && !bFuzzing)
692 m_xDoc->SetDefault( SvxWidowsItem( sal_uInt8(2), RES_PARATR_WIDOWS) );
693 m_xDoc->SetDefault( SvxOrphansItem( sal_uInt8(2), RES_PARATR_ORPHANS) );
697 m_xDoc->getIDocumentState().ResetModified();
701 * Document Interface Access
703 IDocumentDeviceAccess& SwDocShell::getIDocumentDeviceAccess()
705 return m_xDoc->getIDocumentDeviceAccess();
708 IDocumentChartDataProviderAccess& SwDocShell::getIDocumentChartDataProviderAccess()
710 return m_xDoc->getIDocumentChartDataProviderAccess();
713 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */