1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include <hintids.hxx>
21
22 #include <sal/log.hxx>
23 #include <i18nlangtag/mslangid.hxx>
24 #include <sot/storinfo.hxx>
25 #include <sot/storage.hxx>
26 #include <svl/zforlist.hxx>
27 #include <svtools/ctrltool.hxx>
28 #include <unotools/configmgr.hxx>
29 #include <unotools/lingucfg.hxx>
30 #include <sfx2/docfile.hxx>
31 #include <sfx2/sfxmodelfactory.hxx>
32 #include <sfx2/printer.hxx>
33 #include <sfx2/bindings.hxx>
34 #include <svl/asiancfg.hxx>
35 #include <editeng/unolingu.hxx>
36 #include <sfx2/request.hxx>
37 #include <svl/intitem.hxx>
38 #include <editeng/adjustitem.hxx>
39 #include <editeng/autokernitem.hxx>
40 #include <linguistic/lngprops.hxx>
41 #include <com/sun/star/document/UpdateDocMode.hpp>
42 #include <com/sun/star/i18n/ScriptType.hpp>
43 #include <sfx2/docfilt.hxx>
44 #include <svx/xtable.hxx>
45 #include <svx/drawitem.hxx>
46 #include <svx/svxids.hrc>
47 #include <editeng/fhgtitem.hxx>
48 #include <editeng/fontitem.hxx>
49 #include <editeng/flstitem.hxx>
50 #include <editeng/tstpitem.hxx>
51 #include <editeng/langitem.hxx>
52 #include <editeng/colritem.hxx>
53 #include <editeng/orphitem.hxx>
54 #include <editeng/widwitem.hxx>
55 #include <editeng/hyphenzoneitem.hxx>
56 #include <editeng/svxacorr.hxx>
57 #include <vcl/svapp.hxx>
58 #include <vcl/settings.hxx>
59 #include <view.hxx>
60 #include <prtopt.hxx>
61 #include <fmtcol.hxx>
62 #include <docsh.hxx>
63 #include <wdocsh.hxx>
64 #include <swmodule.hxx>
65 #include <doc.hxx>
66 #include <IDocumentSettingAccess.hxx>
67 #include <IDocumentDeviceAccess.hxx>
68 #include <IDocumentDrawModelAccess.hxx>
69 #include <IDocumentStylePoolAccess.hxx>
70 #include <IDocumentChartDataProviderAccess.hxx>
71 #include <IDocumentState.hxx>
72 #include <docfac.hxx>
73 #include <docstyle.hxx>
74 #include <shellio.hxx>
75 #include <tox.hxx>
76 #include <swdtflvr.hxx>
77 #include <dbmgr.hxx>
78 #include <usrpref.hxx>
79 #include <fontcfg.hxx>
80 #include <poolfmt.hxx>
81 #include <modcfg.hxx>
82 #include <globdoc.hxx>
83 #include <ndole.hxx>
84 #include <mdiexp.hxx>
85 #include <unotxdoc.hxx>
86 #include <linkenum.hxx>
87 #include <swwait.hxx>
88 #include <wrtsh.hxx>
89 #include <swerror.h>
90 #include <globals.hrc>
91 #include <unochart.hxx>
92 #include <drawdoc.hxx>
93 #include <DocumentSettingManager.hxx>
94
95 #include <svx/CommonStyleManager.hxx>
96
97 // text grid
98 #include <tgrditem.hxx>
99 #include <memory>
100
101 using namespace ::com::sun::star::i18n;
102 using namespace ::com::sun::star::lang;
103 using namespace ::com::sun::star::uno;
104 using namespace ::com::sun::star;
105
106 // Load Document
InitNew(const uno::Reference<embed::XStorage> & xStor)107 bool SwDocShell::InitNew( const uno::Reference < embed::XStorage >& xStor )
108 {
109 bool bRet = SfxObjectShell::InitNew( xStor );
110 OSL_ENSURE( GetMapUnit() == MapUnit::MapTwip, "map unit is not twip!" );
111 bool bHTMLTemplSet = false;
112 if( bRet )
113 {
114 AddLink(); // create m_xDoc / pIo if applicable
115
116 bool bWeb = dynamic_cast< const SwWebDocShell *>( this ) != nullptr;
117 if ( bWeb )
118 bHTMLTemplSet = SetHTMLTemplate( *GetDoc() );// Styles from HTML.vor
119 else if( dynamic_cast< const SwGlobalDocShell *>( this ) != nullptr )
120 GetDoc()->getIDocumentSettingAccess().set(DocumentSettingId::GLOBAL_DOCUMENT, true); // Globaldokument
121
122 if ( GetCreateMode() == SfxObjectCreateMode::EMBEDDED )
123 SwTransferable::InitOle( this );
124
125 // set forbidden characters if necessary
126 if (!utl::ConfigManager::IsFuzzing())
127 {
128 SvxAsianConfig aAsian;
129 const Sequence<lang::Locale> aLocales = aAsian.GetStartEndCharLocales();
130 for(const lang::Locale& rLocale : aLocales)
131 {
132 ForbiddenCharacters aForbidden;
133 aAsian.GetStartEndChars( rLocale, aForbidden.beginLine, aForbidden.endLine);
134 LanguageType eLang = LanguageTag::convertToLanguageType(rLocale);
135 m_xDoc->getIDocumentSettingAccess().setForbiddenCharacters( eLang, aForbidden);
136 }
137 m_xDoc->getIDocumentSettingAccess().set(DocumentSettingId::KERN_ASIAN_PUNCTUATION,
138 !aAsian.IsKerningWesternTextOnly());
139 m_xDoc->getIDocumentSettingAccess().setCharacterCompressionType(aAsian.GetCharDistanceCompression());
140 m_xDoc->getIDocumentDeviceAccess().setPrintData(*SW_MOD()->GetPrtOptions(bWeb));
141 }
142
143 SubInitNew();
144
145 // for all
146
147 SwStdFontConfig* pStdFont = SW_MOD()->GetStdFontConfig();
148 SfxPrinter* pPrt = m_xDoc->getIDocumentDeviceAccess().getPrinter( false );
149
150 OUString sEntry;
151 static const sal_uInt16 aFontWhich[] =
152 { RES_CHRATR_FONT,
153 RES_CHRATR_CJK_FONT,
154 RES_CHRATR_CTL_FONT
155 };
156 static const sal_uInt16 aFontHeightWhich[] =
157 {
158 RES_CHRATR_FONTSIZE,
159 RES_CHRATR_CJK_FONTSIZE,
160 RES_CHRATR_CTL_FONTSIZE
161 };
162 static const sal_uInt16 aFontIds[] =
163 {
164 FONT_STANDARD,
165 FONT_STANDARD_CJK,
166 FONT_STANDARD_CTL
167 };
168 static const DefaultFontType nFontTypes[] =
169 {
170 DefaultFontType::LATIN_TEXT,
171 DefaultFontType::CJK_TEXT,
172 DefaultFontType::CTL_TEXT
173 };
174 static const sal_uInt16 aLangTypes[] =
175 {
176 RES_CHRATR_LANGUAGE,
177 RES_CHRATR_CJK_LANGUAGE,
178 RES_CHRATR_CTL_LANGUAGE
179 };
180
181 for(sal_uInt8 i = 0; i < 3; i++)
182 {
183 sal_uInt16 nFontWhich = aFontWhich[i];
184 sal_uInt16 nFontId = aFontIds[i];
185 std::unique_ptr<SvxFontItem> pFontItem;
186 const SvxLanguageItem& rLang = static_cast<const SvxLanguageItem&>(m_xDoc->GetDefault( aLangTypes[i] ));
187 LanguageType eLanguage = rLang.GetLanguage();
188 if(!pStdFont->IsFontDefault(nFontId))
189 {
190 sEntry = pStdFont->GetFontFor(nFontId);
191
192 vcl::Font aFont( sEntry, Size( 0, 10 ) );
193 if( pPrt )
194 {
195 aFont = pPrt->GetFontMetric( aFont );
196 }
197
198 pFontItem.reset(new SvxFontItem(aFont.GetFamilyType(), aFont.GetFamilyName(),
199 OUString(), aFont.GetPitch(), aFont.GetCharSet(), nFontWhich));
200 }
201 else
202 {
203 // #107782# OJ use korean language if latin was used
204 if ( i == 0 )
205 {
206 LanguageType eUiLanguage = Application::GetSettings().GetUILanguageTag().getLanguageType();
207 if (MsLangId::isKorean(eUiLanguage))
208 eLanguage = eUiLanguage;
209 }
210
211 vcl::Font aLangDefFont = OutputDevice::GetDefaultFont(
212 nFontTypes[i],
213 eLanguage,
214 GetDefaultFontFlags::OnlyOne );
215 pFontItem.reset(new SvxFontItem(aLangDefFont.GetFamilyType(), aLangDefFont.GetFamilyName(),
216 OUString(), aLangDefFont.GetPitch(), aLangDefFont.GetCharSet(), nFontWhich));
217 }
218 m_xDoc->SetDefault(*pFontItem);
219 if( !bHTMLTemplSet )
220 {
221 SwTextFormatColl *pColl = m_xDoc->getIDocumentStylePoolAccess().GetTextCollFromPool(RES_POOLCOLL_STANDARD);
222 pColl->ResetFormatAttr(nFontWhich);
223 }
224 pFontItem.reset();
225 sal_Int32 nFontHeight = pStdFont->GetFontHeight( FONT_STANDARD, i, eLanguage );
226 if(nFontHeight <= 0)
227 nFontHeight = SwStdFontConfig::GetDefaultHeightFor( nFontId, eLanguage );
228 m_xDoc->SetDefault(SvxFontHeightItem( nFontHeight, 100, aFontHeightWhich[i] ));
229 if( !bHTMLTemplSet )
230 {
231 SwTextFormatColl *pColl = m_xDoc->getIDocumentStylePoolAccess().GetTextCollFromPool(RES_POOLCOLL_STANDARD);
232 pColl->ResetFormatAttr(aFontHeightWhich[i]);
233 }
234
235 }
236 sal_uInt16 aFontIdPoolId[] =
237 {
238 FONT_OUTLINE, RES_POOLCOLL_HEADLINE_BASE,
239 FONT_LIST, RES_POOLCOLL_NUMBUL_BASE,
240 FONT_CAPTION, RES_POOLCOLL_LABEL,
241 FONT_INDEX, RES_POOLCOLL_REGISTER_BASE,
242 FONT_OUTLINE_CJK, RES_POOLCOLL_HEADLINE_BASE,
243 FONT_LIST_CJK, RES_POOLCOLL_NUMBUL_BASE,
244 FONT_CAPTION_CJK, RES_POOLCOLL_LABEL,
245 FONT_INDEX_CJK, RES_POOLCOLL_REGISTER_BASE,
246 FONT_OUTLINE_CTL, RES_POOLCOLL_HEADLINE_BASE,
247 FONT_LIST_CTL, RES_POOLCOLL_NUMBUL_BASE,
248 FONT_CAPTION_CTL, RES_POOLCOLL_LABEL,
249 FONT_INDEX_CTL, RES_POOLCOLL_REGISTER_BASE
250 };
251
252 sal_uInt16 nFontWhich = RES_CHRATR_FONT;
253 sal_uInt16 nFontHeightWhich = RES_CHRATR_FONTSIZE;
254 LanguageType eLanguage = m_xDoc->GetDefault( RES_CHRATR_LANGUAGE ).GetLanguage();
255 for(sal_uInt8 nIdx = 0; nIdx < 24; nIdx += 2)
256 {
257 if(nIdx == 8)
258 {
259 nFontWhich = RES_CHRATR_CJK_FONT;
260 nFontHeightWhich = RES_CHRATR_CJK_FONTSIZE;
261 eLanguage = m_xDoc->GetDefault( RES_CHRATR_CJK_LANGUAGE ).GetLanguage();
262 }
263 else if(nIdx == 16)
264 {
265 nFontWhich = RES_CHRATR_CTL_FONT;
266 nFontHeightWhich = RES_CHRATR_CTL_FONTSIZE;
267 eLanguage = m_xDoc->GetDefault( RES_CHRATR_CTL_LANGUAGE ).GetLanguage();
268 }
269 SwTextFormatColl *pColl = nullptr;
270 if(!pStdFont->IsFontDefault(aFontIdPoolId[nIdx]))
271 {
272 sEntry = pStdFont->GetFontFor(aFontIdPoolId[nIdx]);
273
274 vcl::Font aFont( sEntry, Size( 0, 10 ) );
275 if( pPrt )
276 aFont = pPrt->GetFontMetric( aFont );
277
278 pColl = m_xDoc->getIDocumentStylePoolAccess().GetTextCollFromPool(aFontIdPoolId[nIdx + 1]);
279 if( !bHTMLTemplSet ||
280 SfxItemState::SET != pColl->GetAttrSet().GetItemState(
281 nFontWhich, false ) )
282 {
283 pColl->SetFormatAttr(SvxFontItem(aFont.GetFamilyType(), aFont.GetFamilyName(),
284 OUString(), aFont.GetPitch(), aFont.GetCharSet(), nFontWhich));
285 }
286 }
287 sal_Int32 nFontHeight = pStdFont->GetFontHeight( static_cast< sal_Int8 >(aFontIdPoolId[nIdx]), 0, eLanguage );
288 if(nFontHeight <= 0)
289 nFontHeight = SwStdFontConfig::GetDefaultHeightFor( aFontIdPoolId[nIdx], eLanguage );
290 if(!pColl)
291 pColl = m_xDoc->getIDocumentStylePoolAccess().GetTextCollFromPool(aFontIdPoolId[nIdx + 1]);
292 SvxFontHeightItem aFontHeight( static_cast<const SvxFontHeightItem&>(pColl->GetFormatAttr( nFontHeightWhich )));
293 if(aFontHeight.GetHeight() != sal::static_int_cast<sal_uInt32, sal_Int32>(nFontHeight))
294 {
295 aFontHeight.SetHeight(nFontHeight);
296 pColl->SetFormatAttr( aFontHeight );
297 }
298 }
299
300 // the default for documents created via 'File/New' should be 'on'
301 // (old documents, where this property was not yet implemented, will get the
302 // value 'false' in the SwDoc c-tor)
303 m_xDoc->getIDocumentSettingAccess().set( DocumentSettingId::MATH_BASELINE_ALIGNMENT,
304 SW_MOD()->GetUsrPref( bWeb )->IsAlignMathObjectsToBaseline() );
305 }
306
307 /* #106748# If the default frame direction of a document is RTL
308 the default adjustment is to the right. */
309 if( !bHTMLTemplSet &&
310 SvxFrameDirection::Horizontal_RL_TB == GetDefaultFrameDirection(GetAppLanguage()) )
311 {
312 m_xDoc->SetDefault( SvxAdjustItem(SvxAdjust::Right, RES_PARATR_ADJUST ) );
313 }
314
315 // #i29550#
316 m_xDoc->SetDefault( SfxBoolItem( RES_COLLAPSING_BORDERS, true ) );
317 // <-- collapsing
318
319 //#i16874# AutoKerning as default for new documents
320 m_xDoc->SetDefault( SvxAutoKernItem( true, RES_CHRATR_AUTOKERN ) );
321
322 // #i42080# - Due to the several calls of method <SetDefault(..)>
323 // at the document instance, the document is modified. Thus, reset this
324 // status here. Note: In method <SubInitNew()> this is also done.
325 m_xDoc->getIDocumentState().ResetModified();
326
327 return bRet;
328 }
329
330 // Ctor with SfxCreateMode ?????
SwDocShell(SfxObjectCreateMode const eMode)331 SwDocShell::SwDocShell( SfxObjectCreateMode const eMode )
332 : SfxObjectShell(eMode)
333 , m_IsInUpdateFontList(false)
334 , m_pStyleManager(new svx::CommonStyleManager(*this))
335 , m_pView(nullptr)
336 , m_pWrtShell(nullptr)
337 , m_nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG)
338 , m_IsATemplate(false)
339 , m_IsRemovedInvisibleContent(false)
340 {
341 Init_Impl();
342 }
343
344 // Ctor / Dtor
SwDocShell(const SfxModelFlags i_nSfxCreationFlags)345 SwDocShell::SwDocShell( const SfxModelFlags i_nSfxCreationFlags )
346 : SfxObjectShell ( i_nSfxCreationFlags )
347 , m_IsInUpdateFontList(false)
348 , m_pStyleManager(new svx::CommonStyleManager(*this))
349 , m_pView(nullptr)
350 , m_pWrtShell(nullptr)
351 , m_nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG)
352 , m_IsATemplate(false)
353 , m_IsRemovedInvisibleContent(false)
354 {
355 Init_Impl();
356 }
357
358 // Ctor / Dtor
SwDocShell(SwDoc * const pD,SfxObjectCreateMode const eMode)359 SwDocShell::SwDocShell( SwDoc *const pD, SfxObjectCreateMode const eMode )
360 : SfxObjectShell(eMode)
361 , m_xDoc(pD)
362 , m_IsInUpdateFontList(false)
363 , m_pStyleManager(new svx::CommonStyleManager(*this))
364 , m_pView(nullptr)
365 , m_pWrtShell(nullptr)
366 , m_nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG)
367 , m_IsATemplate(false)
368 , m_IsRemovedInvisibleContent(false)
369 {
370 Init_Impl();
371 }
372
373 // Dtor
~SwDocShell()374 SwDocShell::~SwDocShell()
375 {
376 // disable chart related objects now because in ~SwDoc it may be too late for this
377 if (m_xDoc)
378 {
379 m_xDoc->getIDocumentChartDataProviderAccess().GetChartControllerHelper().Disconnect();
380 SwChartDataProvider *pPCD = m_xDoc->getIDocumentChartDataProviderAccess().GetChartDataProvider();
381 if (pPCD)
382 pPCD->dispose();
383 }
384
385 RemoveLink();
386 m_pFontList.reset();
387
388 // we, as BroadCaster also become our own Listener
389 // (for DocInfo/FileNames/...)
390 EndListening( *this );
391
392 m_pOLEChildList.reset();
393 }
394
Init_Impl()395 void SwDocShell::Init_Impl()
396 {
397 SetPool(&SW_MOD()->GetPool());
398 SetBaseModel(new SwXTextDocument(this));
399 // we, as BroadCaster also become our own Listener
400 // (for DocInfo/FileNames/...)
401 StartListening( *this );
402 //position of the "Automatic" style filter for the stylist (app.src)
403 SetAutoStyleFilterIndex(3);
404
405 // set map unit to twip
406 SetMapUnit( MapUnit::MapTwip );
407 }
408
AddLink()409 void SwDocShell::AddLink()
410 {
411 if (!m_xDoc)
412 {
413 SwDocFac aFactory;
414 m_xDoc = aFactory.GetDoc();
415 m_xDoc->getIDocumentSettingAccess().set(DocumentSettingId::HTML_MODE, dynamic_cast< const SwWebDocShell *>( this ) != nullptr );
416 }
417 m_xDoc->SetDocShell( this ); // set the DocShell-Pointer for Doc
418 uno::Reference< text::XTextDocument > xDoc(GetBaseModel(), uno::UNO_QUERY);
419 static_cast<SwXTextDocument*>(xDoc.get())->Reactivate(this);
420
421 SetPool(&m_xDoc->GetAttrPool());
422
423 // most suitably not until a sdbcx::View is created!!!
424 m_xDoc->SetOle2Link(LINK(this, SwDocShell, Ole2ModifiedHdl));
425 }
426
427 // create new FontList Change Printer
UpdateFontList()428 void SwDocShell::UpdateFontList()
429 {
430 if (!m_IsInUpdateFontList)
431 {
432 m_IsInUpdateFontList = true;
433 OSL_ENSURE(m_xDoc, "No Doc no FontList");
434 if (m_xDoc)
435 {
436 m_pFontList.reset( new FontList( m_xDoc->getIDocumentDeviceAccess().getReferenceDevice(true) ) );
437 PutItem( SvxFontListItem( m_pFontList.get(), SID_ATTR_CHAR_FONTLIST ) );
438 }
439 m_IsInUpdateFontList = false;
440 }
441 }
442
RemoveLink()443 void SwDocShell::RemoveLink()
444 {
445 // disconnect Uno-Object
446 uno::Reference< text::XTextDocument > xDoc(GetBaseModel(), uno::UNO_QUERY);
447 static_cast<SwXTextDocument*>(xDoc.get())->Invalidate();
448 if (m_xDoc)
449 {
450 if (m_xBasePool.is())
451 {
452 static_cast<SwDocStyleSheetPool*>(m_xBasePool.get())->dispose();
453 m_xBasePool.clear();
454 }
455 m_xDoc->SetOle2Link(Link<bool,void>());
456 m_xDoc->SetDocShell( nullptr );
457 m_xDoc.clear(); // we don't have the Doc anymore!!
458 }
459 }
InvalidateModel()460 void SwDocShell::InvalidateModel()
461 {
462 // disconnect Uno-Object
463 uno::Reference< text::XTextDocument > xDoc(GetBaseModel(), uno::UNO_QUERY);
464 static_cast<SwXTextDocument*>(xDoc.get())->Invalidate();
465 }
ReactivateModel()466 void SwDocShell::ReactivateModel()
467 {
468 // disconnect Uno-Object
469 uno::Reference< text::XTextDocument > xDoc(GetBaseModel(), uno::UNO_QUERY);
470 static_cast<SwXTextDocument*>(xDoc.get())->Reactivate(this);
471 }
472
473 // Load, Default-Format
Load(SfxMedium & rMedium)474 bool SwDocShell::Load( SfxMedium& rMedium )
475 {
476 bool bRet = false;
477
478 if (SfxObjectShell::Load(rMedium))
479 {
480 comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer = getEmbeddedObjectContainer();
481 rEmbeddedObjectContainer.setUserAllowsLinkUpdate(false);
482
483 SAL_INFO( "sw.ui", "after SfxInPlaceObject::Load" );
484 if (m_xDoc) // for last version!!
485 RemoveLink(); // release the existing
486
487 AddLink(); // set Link and update Data!!
488
489 // Define some settings for legacy ODF files that have different default values now
490 // (if required, they will be overridden later when settings will be read)
491 if (IsOwnStorageFormat(rMedium))
492 {
493 // legacy processing for tdf#99729
494 if (m_xDoc->getIDocumentDrawModelAccess().GetDrawModel())
495 m_xDoc->getIDocumentDrawModelAccess().GetDrawModel()->SetAnchoredTextOverflowLegacy(
496 true);
497 // legacy behaviour (not hiding paragraph) for Database (MailMerge) fields
498 m_xDoc->GetDocumentSettingManager().set(DocumentSettingId::EMPTY_DB_FIELD_HIDES_PARA,
499 false);
500 }
501
502 // Loading
503 // for MD
504 OSL_ENSURE( !m_xBasePool.is(), "who hasn't destroyed their Pool?" );
505 m_xBasePool = new SwDocStyleSheetPool( *m_xDoc, SfxObjectCreateMode::ORGANIZER == GetCreateMode() );
506 if(GetCreateMode() != SfxObjectCreateMode::ORGANIZER)
507 {
508 const SfxUInt16Item* pUpdateDocItem = SfxItemSet::GetItem<SfxUInt16Item>(rMedium.GetItemSet(), SID_UPDATEDOCMODE, false);
509 m_nUpdateDocMode = pUpdateDocItem ? pUpdateDocItem->GetValue() : document::UpdateDocMode::NO_UPDATE;
510 }
511
512 SwWait aWait( *this, true );
513 ErrCode nErr = ERR_SWG_READ_ERROR;
514 switch( GetCreateMode() )
515 {
516 case SfxObjectCreateMode::ORGANIZER:
517 {
518 if( ReadXML )
519 {
520 ReadXML->SetOrganizerMode( true );
521 SwReader aRdr(rMedium, OUString(), m_xDoc.get());
522 nErr = aRdr.Read( *ReadXML );
523 ReadXML->SetOrganizerMode( false );
524 }
525 }
526 break;
527
528 case SfxObjectCreateMode::INTERNAL:
529 case SfxObjectCreateMode::EMBEDDED:
530 {
531 SwTransferable::InitOle( this );
532 }
533 // suppress SfxProgress, when we are Embedded
534 SW_MOD()->SetEmbeddedLoadSave( true );
535 [[fallthrough]];
536
537 case SfxObjectCreateMode::STANDARD:
538 {
539 Reader *pReader = ReadXML;
540 if( pReader )
541 {
542 // set Doc's DocInfo at DocShell-Medium
543 SAL_INFO( "sw.ui", "before ReadDocInfo" );
544 SwReader aRdr(rMedium, OUString(), m_xDoc.get());
545 SAL_INFO( "sw.ui", "before Read" );
546 nErr = aRdr.Read( *pReader );
547 SAL_INFO( "sw.ui", "after Read" );
548 // If a XML document is loaded, the global doc/web doc
549 // flags have to be set, because they aren't loaded
550 // by this formats.
551 if( dynamic_cast< const SwWebDocShell *>( this ) != nullptr )
552 {
553 if (!m_xDoc->getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE))
554 m_xDoc->getIDocumentSettingAccess().set(DocumentSettingId::HTML_MODE, true);
555 }
556 if( dynamic_cast< const SwGlobalDocShell *>( this ) != nullptr )
557 {
558 if (!m_xDoc->getIDocumentSettingAccess().get(DocumentSettingId::GLOBAL_DOCUMENT))
559 m_xDoc->getIDocumentSettingAccess().set(DocumentSettingId::GLOBAL_DOCUMENT, true);
560 }
561 }
562 }
563 break;
564
565 default:
566 OSL_ENSURE( false, "Load: new CreateMode?" );
567 }
568
569 UpdateFontList();
570 InitDrawModelAndDocShell(this, m_xDoc ? m_xDoc->getIDocumentDrawModelAccess().GetDrawModel()
571 : nullptr);
572
573 SetError(nErr);
574 bRet = !nErr.IsError();
575
576 if (bRet && !m_xDoc->IsInLoadAsynchron() &&
577 GetCreateMode() == SfxObjectCreateMode::STANDARD)
578 {
579 LoadingFinished();
580 }
581
582 // suppress SfxProgress, when we are Embedded
583 SW_MOD()->SetEmbeddedLoadSave( false );
584 }
585
586 return bRet;
587 }
588
LoadFrom(SfxMedium & rMedium)589 bool SwDocShell::LoadFrom( SfxMedium& rMedium )
590 {
591 bool bRet = false;
592 if (m_xDoc)
593 RemoveLink();
594
595 AddLink(); // set Link and update Data!!
596
597 do { // middle check loop
598 ErrCode nErr = ERR_SWG_READ_ERROR;
599 OUString aStreamName = "styles.xml";
600 uno::Reference < container::XNameAccess > xAccess = rMedium.GetStorage();
601 if ( xAccess->hasByName( aStreamName ) && rMedium.GetStorage()->isStreamElement( aStreamName ) )
602 {
603 // Loading
604 SwWait aWait( *this, true );
605 {
606 OSL_ENSURE( !m_xBasePool.is(), "who hasn't destroyed their Pool?" );
607 m_xBasePool = new SwDocStyleSheetPool( *m_xDoc, SfxObjectCreateMode::ORGANIZER == GetCreateMode() );
608 if( ReadXML )
609 {
610 ReadXML->SetOrganizerMode( true );
611 SwReader aRdr(rMedium, OUString(), m_xDoc.get());
612 nErr = aRdr.Read( *ReadXML );
613 ReadXML->SetOrganizerMode( false );
614 }
615 }
616 }
617 else
618 {
619 OSL_FAIL("Code removed!");
620 }
621
622 SetError(nErr);
623 bRet = !nErr.IsError();
624
625 } while( false );
626
627 SfxObjectShell::LoadFrom( rMedium );
628 m_xDoc->getIDocumentState().ResetModified();
629 return bRet;
630 }
631
SubInitNew()632 void SwDocShell::SubInitNew()
633 {
634 OSL_ENSURE( !m_xBasePool.is(), "who hasn't destroyed their Pool?" );
635 m_xBasePool = new SwDocStyleSheetPool( *m_xDoc, SfxObjectCreateMode::ORGANIZER == GetCreateMode() );
636 UpdateFontList();
637 InitDrawModelAndDocShell(this, m_xDoc ? m_xDoc->getIDocumentDrawModelAccess().GetDrawModel() : nullptr);
638
639 m_xDoc->getIDocumentSettingAccess().setLinkUpdateMode( GLOBALSETTING );
640 m_xDoc->getIDocumentSettingAccess().setFieldUpdateFlags( AUTOUPD_GLOBALSETTING );
641
642 bool bWeb = dynamic_cast< const SwWebDocShell *>( this ) != nullptr;
643
644 sal_uInt16 nRange[] = {
645 RES_PARATR_ADJUST, RES_PARATR_ADJUST,
646 RES_CHRATR_COLOR, RES_CHRATR_COLOR,
647 RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE,
648 RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE,
649 RES_CHRATR_CTL_LANGUAGE, RES_CHRATR_CTL_LANGUAGE,
650 0, 0, 0 };
651 if(!bWeb)
652 {
653 nRange[ SAL_N_ELEMENTS(nRange) - 3 ] = RES_PARATR_TABSTOP;
654 nRange[ SAL_N_ELEMENTS(nRange) - 2 ] = RES_PARATR_HYPHENZONE;
655 }
656 SfxItemSet aDfltSet( m_xDoc->GetAttrPool(), nRange );
657
658 //! get lingu options without loading lingu DLL
659 SvtLinguOptions aLinguOpt;
660
661 if (!utl::ConfigManager::IsFuzzing())
662 SvtLinguConfig().GetOptions(aLinguOpt);
663
664 LanguageType nVal = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, css::i18n::ScriptType::LATIN),
665 eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, css::i18n::ScriptType::ASIAN),
666 eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, css::i18n::ScriptType::COMPLEX);
667 aDfltSet.Put( SvxLanguageItem( nVal, RES_CHRATR_LANGUAGE ) );
668 aDfltSet.Put( SvxLanguageItem( eCJK, RES_CHRATR_CJK_LANGUAGE ) );
669 aDfltSet.Put( SvxLanguageItem( eCTL, RES_CHRATR_CTL_LANGUAGE ) );
670
671 if(!bWeb)
672 {
673 SvxHyphenZoneItem aHyp( m_xDoc->GetDefault(RES_PARATR_HYPHENZONE) );
674 aHyp.GetMinLead() = static_cast< sal_uInt8 >(aLinguOpt.nHyphMinLeading);
675 aHyp.GetMinTrail() = static_cast< sal_uInt8 >(aLinguOpt.nHyphMinTrailing);
676
677 aDfltSet.Put( aHyp );
678
679 sal_uInt16 nNewPos = static_cast< sal_uInt16 >(convertMm100ToTwip(SW_MOD()->GetUsrPref(false)->GetDefTabInMm100()));
680 if( nNewPos )
681 aDfltSet.Put( SvxTabStopItem( 1, nNewPos,
682 SvxTabAdjust::Default, RES_PARATR_TABSTOP ) );
683 }
684 aDfltSet.Put( SvxColorItem( COL_AUTO, RES_CHRATR_COLOR ) );
685
686 m_xDoc->SetDefault( aDfltSet );
687
688 //default page mode for text grid
689 if(!bWeb)
690 {
691 bool bSquaredPageMode = SW_MOD()->GetUsrPref(false)->IsSquaredPageMode();
692 m_xDoc->SetDefaultPageMode( bSquaredPageMode );
693
694 // only set Widow/Orphan defaults on a new, non-web document - not an opened one
695 if( GetMedium() && GetMedium()->GetOrigURL().isEmpty() )
696 {
697 m_xDoc->SetDefault( SvxWidowsItem( sal_uInt8(2), RES_PARATR_WIDOWS) );
698 m_xDoc->SetDefault( SvxOrphansItem( sal_uInt8(2), RES_PARATR_ORPHANS) );
699 }
700 }
701
702 m_xDoc->getIDocumentState().ResetModified();
703 }
704
705 /*
706 * Document Interface Access
707 */
getIDocumentDeviceAccess()708 IDocumentDeviceAccess& SwDocShell::getIDocumentDeviceAccess()
709 {
710 return m_xDoc->getIDocumentDeviceAccess();
711 }
712
getIDocumentChartDataProviderAccess()713 IDocumentChartDataProviderAccess& SwDocShell::getIDocumentChartDataProviderAccess()
714 {
715 return m_xDoc->getIDocumentChartDataProviderAccess();
716 }
717
718 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
719