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