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