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