xref: /trunk/main/sw/source/ui/app/docshini.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 
32 #include <hintids.hxx>
33 
34 #include <svx/dialogs.hrc>
35 #include <i18npool/mslangid.hxx>
36 #include <sot/storinfo.hxx>
37 #include <sot/storage.hxx>
38 #include <svl/zforlist.hxx>
39 #include <svtools/ctrltool.hxx>
40 #include <unotools/lingucfg.hxx>
41 #include <sfx2/docfile.hxx>
42 #include <sfx2/sfxmodelfactory.hxx>
43 #include <sfx2/printer.hxx>
44 #include <sfx2/bindings.hxx>
45 #include <svl/asiancfg.hxx>
46 #include <editeng/unolingu.hxx>
47 #include <sfx2/request.hxx>
48 #include <svl/intitem.hxx>
49 #include <editeng/adjitem.hxx>
50 #include <editeng/akrnitem.hxx>
51 #include <linguistic/lngprops.hxx>
52 #include <com/sun/star/document/UpdateDocMode.hpp>
53 #include <com/sun/star/i18n/ScriptType.hpp>
54 #include <rtl/logfile.hxx>
55 #include <sfx2/docfilt.hxx>
56 #include <svx/xtable.hxx>
57 #include <svx/drawitem.hxx>
58 #include <editeng/fhgtitem.hxx>
59 #include <editeng/fontitem.hxx>
60 #include <editeng/flstitem.hxx>
61 #include <editeng/tstpitem.hxx>
62 #include <editeng/langitem.hxx>
63 #include <editeng/colritem.hxx>
64 #include <editeng/hyznitem.hxx>
65 #include <editeng/svxacorr.hxx>
66 #include <vcl/svapp.hxx>
67 #include <view.hxx>
68 #include <prtopt.hxx>
69 #include <fmtcol.hxx>
70 #include <docsh.hxx>
71 #include <wdocsh.hxx>
72 #include <swmodule.hxx>
73 #include <doc.hxx>
74 #include <docfac.hxx>
75 #include <docstyle.hxx>
76 #include <shellio.hxx>
77 #include <tox.hxx>
78 #include <swdtflvr.hxx>
79 #include <dbmgr.hxx>
80 #include <usrpref.hxx>
81 #include <fontcfg.hxx>
82 #include <poolfmt.hxx>
83 #include <modcfg.hxx>
84 #include <globdoc.hxx>
85 #include <ndole.hxx>
86 #include <mdiexp.hxx>
87 #include <unotxdoc.hxx>
88 #include <linkenum.hxx>
89 #include <swwait.hxx>
90 #include <wrtsh.hxx>
91 #include <swerror.h>
92 #include <globals.hrc>
93 
94 // #i18732#
95 #include <fmtfollowtextflow.hxx>
96 
97 #include <unochart.hxx>
98 
99 // text grid
100 #include <tgrditem.hxx>
101 
102 using namespace ::com::sun::star::i18n;
103 using namespace ::com::sun::star::lang;
104 using namespace ::com::sun::star::uno;
105 using namespace ::com::sun::star;
106 using ::rtl::OUString;
107 
108 /*-----------------21.09.96 15.29-------------------
109 
110 --------------------------------------------------*/
111 
112 
113 /*--------------------------------------------------------------------
114 	Beschreibung: Document laden
115  --------------------------------------------------------------------*/
116 
117 
118 sal_Bool SwDocShell::InitNew( const uno::Reference < embed::XStorage >& xStor )
119 {
120 	RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::InitNew" );
121 
122     sal_Bool bRet = SfxObjectShell::InitNew( xStor );
123 	ASSERT( GetMapUnit() == MAP_TWIP, "map unit is not twip!" );
124 	sal_Bool bHTMLTemplSet = sal_False;
125 	if( bRet )
126 	{
127 		AddLink();		// pDoc / pIo ggf. anlegen
128 
129         sal_Bool bWeb = ISA( SwWebDocShell );
130         if ( bWeb )
131 			bHTMLTemplSet = SetHTMLTemplate( *GetDoc() );//Styles aus HTML.vor
132 		else if( ISA( SwGlobalDocShell ) )
133 			GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT, true);		// Globaldokument
134 
135 
136 /*
137 		//JP 12.07.95: so einfach waere es fuer die neu Mimik
138 		pDoc->SetDefault( SvxTabStopItem( 1,
139 					GetStar Writer App()->GetUsrPref()->GetDefTabDist(),
140 					SVX_TAB_ADJUST_DEFAULT,
141 					RES_PARATR_TABSTOP));
142 */
143 		if ( GetCreateMode() ==  SFX_CREATE_MODE_EMBEDDED )
144             SwTransferable::InitOle( this, *pDoc );
145 
146         // set forbidden characters if necessary
147         SvxAsianConfig aAsian;
148         Sequence<Locale> aLocales =  aAsian.GetStartEndCharLocales();
149         if(aLocales.getLength())
150         {
151             const Locale* pLocales = aLocales.getConstArray();
152             for(sal_Int32 i = 0; i < aLocales.getLength(); i++)
153             {
154                 ForbiddenCharacters aForbidden;
155                 aAsian.GetStartEndChars( pLocales[i], aForbidden.beginLine, aForbidden.endLine);
156                 LanguageType  eLang = SvxLocaleToLanguage(pLocales[i]);
157                 pDoc->setForbiddenCharacters( eLang, aForbidden);
158             }
159         }
160         pDoc->set(IDocumentSettingAccess::KERN_ASIAN_PUNCTUATION,
161                   !aAsian.IsKerningWesternTextOnly());
162         pDoc->setCharacterCompressionType(static_cast<SwCharCompressType>(aAsian.GetCharDistanceCompression()));
163         pDoc->setPrintData(*SW_MOD()->GetPrtOptions(bWeb));
164 
165         SubInitNew();
166 
167         // fuer alle
168 
169 		SwStdFontConfig* pStdFont = SW_MOD()->GetStdFontConfig();
170         SfxPrinter* pPrt = pDoc->getPrinter( false );
171 
172 		String sEntry;
173         sal_uInt16 aFontWhich[] =
174         {   RES_CHRATR_FONT,
175             RES_CHRATR_CJK_FONT,
176             RES_CHRATR_CTL_FONT
177         };
178         sal_uInt16 aFontHeightWhich[] =
179         {
180             RES_CHRATR_FONTSIZE,
181             RES_CHRATR_CJK_FONTSIZE,
182             RES_CHRATR_CTL_FONTSIZE
183         };
184         sal_uInt16 aFontIds[] =
185         {
186             FONT_STANDARD,
187             FONT_STANDARD_CJK,
188             FONT_STANDARD_CTL
189         };
190         sal_uInt16 nFontTypes[] =
191         {
192             DEFAULTFONT_LATIN_TEXT,
193             DEFAULTFONT_CJK_TEXT,
194             DEFAULTFONT_CTL_TEXT
195         };
196         sal_uInt16 aLangTypes[] =
197         {
198             RES_CHRATR_LANGUAGE,
199             RES_CHRATR_CJK_LANGUAGE,
200             RES_CHRATR_CTL_LANGUAGE
201         };
202 
203         for(sal_uInt8 i = 0; i < 3; i++)
204         {
205             sal_uInt16 nFontWhich = aFontWhich[i];
206             sal_uInt16 nFontId = aFontIds[i];
207             SvxFontItem* pFontItem = 0;
208             const SvxLanguageItem& rLang = (const SvxLanguageItem&)pDoc->GetDefault( aLangTypes[i] );
209             LanguageType eLanguage = rLang.GetLanguage();
210             if(!pStdFont->IsFontDefault(nFontId))
211             {
212                 sEntry = pStdFont->GetFontFor(nFontId);
213 
214                 Font aFont( sEntry, Size( 0, 10 ) );
215                 if( pPrt )
216                 {
217                     aFont = pPrt->GetFontMetric( aFont );
218                 }
219 
220                 pFontItem = new SvxFontItem(aFont.GetFamily(), aFont.GetName(),
221                                             aEmptyStr, aFont.GetPitch(), aFont.GetCharSet(), nFontWhich);
222             }
223             else
224             {
225                 // #107782# OJ use korean language if latin was used
226                 if ( i == 0 )
227 				{
228 					LanguageType eUiLanguage = Application::GetSettings().GetUILanguage();
229 					switch( eUiLanguage )
230 					{
231 						case LANGUAGE_KOREAN:
232 						case LANGUAGE_KOREAN_JOHAB:
233 							eLanguage = eUiLanguage;
234 						break;
235 					}
236 				}
237 
238 				Font aLangDefFont = OutputDevice::GetDefaultFont(
239                     nFontTypes[i],
240                     eLanguage,
241                     DEFAULTFONT_FLAGS_ONLYONE );
242                 pFontItem = new SvxFontItem(aLangDefFont.GetFamily(), aLangDefFont.GetName(),
243                                     aEmptyStr, aLangDefFont.GetPitch(), aLangDefFont.GetCharSet(), nFontWhich);
244             }
245             pDoc->SetDefault(*pFontItem);
246 			if( !bHTMLTemplSet )
247 			{
248 				SwTxtFmtColl *pColl = pDoc->GetTxtCollFromPool(RES_POOLCOLL_STANDARD);
249                 pColl->ResetFmtAttr(nFontWhich);
250 			}
251             delete pFontItem;
252             sal_Int32 nFontHeight = pStdFont->GetFontHeight( FONT_STANDARD, i, eLanguage );
253             if(nFontHeight <= 0)
254                 nFontHeight = pStdFont->GetDefaultHeightFor( nFontId, eLanguage );
255             pDoc->SetDefault(SvxFontHeightItem( nFontHeight, 100, aFontHeightWhich[i] ));
256             if( !bHTMLTemplSet )
257             {
258                 SwTxtFmtColl *pColl = pDoc->GetTxtCollFromPool(RES_POOLCOLL_STANDARD);
259                 pColl->ResetFmtAttr(aFontHeightWhich[i]);
260             }
261 
262         }
263         sal_uInt16 aFontIdPoolId[] =
264         {
265             FONT_OUTLINE,       RES_POOLCOLL_HEADLINE_BASE,
266             FONT_LIST,          RES_POOLCOLL_NUMBUL_BASE,
267             FONT_CAPTION,       RES_POOLCOLL_LABEL,
268             FONT_INDEX,         RES_POOLCOLL_REGISTER_BASE,
269             FONT_OUTLINE_CJK,   RES_POOLCOLL_HEADLINE_BASE,
270             FONT_LIST_CJK,      RES_POOLCOLL_NUMBUL_BASE,
271             FONT_CAPTION_CJK,   RES_POOLCOLL_LABEL,
272             FONT_INDEX_CJK,     RES_POOLCOLL_REGISTER_BASE,
273             FONT_OUTLINE_CTL,   RES_POOLCOLL_HEADLINE_BASE,
274             FONT_LIST_CTL,      RES_POOLCOLL_NUMBUL_BASE,
275             FONT_CAPTION_CTL,   RES_POOLCOLL_LABEL,
276             FONT_INDEX_CTL,     RES_POOLCOLL_REGISTER_BASE
277         };
278 
279         sal_uInt16 nFontWhich = RES_CHRATR_FONT;
280         sal_uInt16 nFontHeightWhich = RES_CHRATR_FONTSIZE;
281         LanguageType eLanguage = static_cast<const SvxLanguageItem&>(pDoc->GetDefault( RES_CHRATR_LANGUAGE )).GetLanguage();
282         for(sal_uInt8 nIdx = 0; nIdx < 24; nIdx += 2)
283         {
284             if(nIdx == 8)
285             {
286                 nFontWhich = RES_CHRATR_CJK_FONT;
287                 nFontHeightWhich = RES_CHRATR_CJK_FONTSIZE;
288                 eLanguage = static_cast<const SvxLanguageItem&>(pDoc->GetDefault( RES_CHRATR_CJK_LANGUAGE )).GetLanguage();
289             }
290             else if(nIdx == 16)
291             {
292                 nFontWhich = RES_CHRATR_CTL_FONT;
293                 nFontHeightWhich = RES_CHRATR_CTL_FONTSIZE;
294                 eLanguage = static_cast<const SvxLanguageItem&>(pDoc->GetDefault( RES_CHRATR_CTL_LANGUAGE )).GetLanguage();
295             }
296             SwTxtFmtColl *pColl = 0;
297             if(!pStdFont->IsFontDefault(aFontIdPoolId[nIdx]))
298             {
299                 sEntry = pStdFont->GetFontFor(aFontIdPoolId[nIdx]);
300 
301                 Font aFont( sEntry, Size( 0, 10 ) );
302                 if( pPrt )
303                     aFont = pPrt->GetFontMetric( aFont );
304 
305                 pColl = pDoc->GetTxtCollFromPool(aFontIdPoolId[nIdx + 1]);
306                 if( !bHTMLTemplSet ||
307 					SFX_ITEM_SET != pColl->GetAttrSet().GetItemState(
308 													nFontWhich, sal_False ) )
309 				{
310                     pColl->SetFmtAttr(SvxFontItem(aFont.GetFamily(), aFont.GetName(),
311 										          aEmptyStr, aFont.GetPitch(), aFont.GetCharSet(), nFontWhich));
312 				}
313             }
314             sal_Int32 nFontHeight = pStdFont->GetFontHeight( static_cast< sal_Int8 >(aFontIdPoolId[nIdx]), 0, eLanguage );
315             if(nFontHeight <= 0)
316                 nFontHeight = pStdFont->GetDefaultHeightFor( aFontIdPoolId[nIdx], eLanguage );
317             if(!pColl)
318                 pColl = pDoc->GetTxtCollFromPool(aFontIdPoolId[nIdx + 1]);
319             SvxFontHeightItem aFontHeight( (const SvxFontHeightItem&)pColl->GetFmtAttr( nFontHeightWhich, sal_True ));
320             if(aFontHeight.GetHeight() != sal::static_int_cast<sal_uInt32, sal_Int32>(nFontHeight))
321             {
322                 aFontHeight.SetHeight(nFontHeight);
323                 pColl->SetFmtAttr( aFontHeight );
324             }
325         }
326 
327         // the default for documents created via 'File/New' should be 'on'
328         // (old documents, where this property was not yet implemented, will get the
329         // value 'false' in the SwDoc c-tor)
330         pDoc->set( IDocumentSettingAccess::MATH_BASELINE_ALIGNMENT,
331                 SW_MOD()->GetUsrPref( bWeb )->IsAlignMathObjectsToBaseline() );
332     }
333 
334     /* #106748# If the default frame direction of a document is RTL
335         the default adjusment is to the right. */
336     if( !bHTMLTemplSet &&
337 		FRMDIR_HORI_RIGHT_TOP == GetDefaultFrameDirection(GetAppLanguage()) )
338         pDoc->SetDefault( SvxAdjustItem(SVX_ADJUST_RIGHT, RES_PARATR_ADJUST ) );
339 
340     // OD 09.10.2003 #i18732# - set dynamic pool default for
341     // item RES_FOLLOW_TEXT_FLOW to sal_False for *new document*.
342     // Thus, redo this change in method <SwDoc::RemoveAllFmtLanguageDependencies()>,
343     // which is called from <SwDocShell::ConvertFrom(..)> in order to restore
344     // the static pool default.
345     pDoc->SetDefault( SwFmtFollowTextFlow( sal_False ) );
346 
347 // --> collapsing borders FME 2005-05-27 #i29550#
348     pDoc->SetDefault( SfxBoolItem( RES_COLLAPSING_BORDERS, sal_True ) );
349 // <-- collapsing
350 
351     //#i16874# AutoKerning as default for new documents
352     pDoc->SetDefault( SvxAutoKernItem( sal_True, RES_CHRATR_AUTOKERN ) );
353 
354 	pDoc->SetDrawDefaults();
355 
356     // --> OD 2005-02-10 #i42080# - Due to the several calls of method <SetDefault(..)>
357     // at the document instance, the document is modified. Thus, reset this
358     // status here. Note: In method <SubInitNew()> this is also done.
359     pDoc->ResetModified();
360     // <--
361 
362 	return bRet;
363 }
364 
365 /*--------------------------------------------------------------------
366 	Beschreibung:	Ctor mit SfxCreateMode ?????
367  --------------------------------------------------------------------*/
368 
369 
370 SwDocShell::SwDocShell( SfxObjectCreateMode eMode ) :
371     SfxObjectShell ( eMode ),
372 	pDoc(0),
373 	pFontList(0),
374 	pView( 0 ),
375     pWrtShell( 0 ),
376     pOLEChildList( 0 ),
377     nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG),
378     bInUpdateFontList(false)
379 {
380 	RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::SwDocShell" );
381     Init_Impl();
382 }
383 
384 /*--------------------------------------------------------------------
385 	Beschreibung: Ctor / Dtor
386  --------------------------------------------------------------------*/
387 
388 
389 SwDocShell::SwDocShell( const sal_uInt64 i_nSfxCreationFlags ) :
390     SfxObjectShell ( i_nSfxCreationFlags ),
391 	pDoc(0),
392 	pFontList(0),
393 	pView( 0 ),
394     pWrtShell( 0 ),
395     pOLEChildList( 0 ),
396     nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG),
397     bInUpdateFontList(false)
398 {
399 	RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::SwDocShell" );
400     Init_Impl();
401 }
402 
403 /*--------------------------------------------------------------------
404 	Beschreibung: Ctor / Dtor
405  --------------------------------------------------------------------*/
406 
407 
408 SwDocShell::SwDocShell( SwDoc *pD, SfxObjectCreateMode eMode ):
409     SfxObjectShell ( eMode ),
410 	pDoc(pD),
411 	pFontList(0),
412 	pView( 0 ),
413     pWrtShell( 0 ),
414     pOLEChildList( 0 ),
415     nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG),
416     bInUpdateFontList(false)
417 {
418 	RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::SwDocShell" );
419     Init_Impl();
420 }
421 
422 /*--------------------------------------------------------------------
423 	Beschreibung:	Dtor
424  --------------------------------------------------------------------*/
425 
426 
427  SwDocShell::~SwDocShell()
428 {
429     // disable chart related objects now because in ~SwDoc it may be to late for this
430     if( pDoc )
431     {
432         pDoc->GetChartControllerHelper().Disconnect();
433         SwChartDataProvider *pPCD = pDoc->GetChartDataProvider();
434         if (pPCD)
435             pPCD->dispose();
436     }
437 
438     RemoveLink();
439 	delete pFontList;
440 
441 	// wir als BroadCaster werden auch unser eigener Listener
442 	// (fuer DocInfo/FileNamen/....)
443 	EndListening( *this );
444 	SvxColorTableItem* pColItem = (SvxColorTableItem*)GetItem(SID_COLOR_TABLE);
445 	// wird nur die DocInfo fuer den Explorer gelesen, ist das Item nicht da
446 	if(pColItem)
447 	{
448 		XColorTable* pTable = pColItem->GetColorTable();
449 		// wurde eine neue Table angelegt, muss sie auch geloescht werden.
450 		if((void*)pTable  != (void*)(XColorTable::GetStdColorTable()) )
451 			delete pTable;
452 	}
453 
454     delete pOLEChildList;
455 }
456 /* -----------------------------10.09.2001 15:59------------------------------
457 
458  ---------------------------------------------------------------------------*/
459 void  SwDocShell::Init_Impl()
460 {
461     SetPool(&SW_MOD()->GetPool());
462 	SetBaseModel(new SwXTextDocument(this));
463 	// wir als BroadCaster werden auch unser eigener Listener
464 	// (fuer DocInfo/FileNamen/....)
465 	StartListening( *this );
466     //position of the "Automatic" style filter for the stylist (app.src)
467     SetAutoStyleFilterIndex(3);
468 
469 	// set map unit to twip
470 	SetMapUnit( MAP_TWIP );
471 }
472 /*--------------------------------------------------------------------
473 	Beschreibung: AddLink
474  --------------------------------------------------------------------*/
475 
476 
477 void SwDocShell::AddLink()
478 {
479 	if( !pDoc )
480 	{
481 		SwDocFac aFactory;
482 		pDoc = aFactory.GetDoc();
483 		pDoc->acquire();
484 		pDoc->set(IDocumentSettingAccess::HTML_MODE, ISA(SwWebDocShell) );
485 	}
486 	else
487 		pDoc->acquire();
488 	pDoc->SetDocShell( this );		// am Doc den DocShell-Pointer setzen
489 	uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), uno::UNO_QUERY);
490 	((SwXTextDocument*)xDoc.get())->Reactivate(this);
491 
492 	SetPool(&pDoc->GetAttrPool());
493 
494 	// am besten erst wenn eine sdbcx::View erzeugt wird !!!
495 	pDoc->SetOle2Link(LINK(this, SwDocShell, Ole2ModifiedHdl));
496 }
497 
498 /*--------------------------------------------------------------------
499 	Beschreibung:	neue FontList erzeugen Aenderung Drucker
500  --------------------------------------------------------------------*/
501 
502 
503 void SwDocShell::UpdateFontList()
504 {
505     if(!bInUpdateFontList)
506     {
507         bInUpdateFontList = true;
508         ASSERT(pDoc, "Kein Doc keine FontList");
509         if( pDoc )
510         {
511             delete pFontList;
512             pFontList = new FontList( pDoc->getReferenceDevice( true ) );
513             PutItem( SvxFontListItem( pFontList, SID_ATTR_CHAR_FONTLIST ) );
514         }
515         bInUpdateFontList = false;
516     }
517 }
518 
519 /*--------------------------------------------------------------------
520 	Beschreibung: RemoveLink
521  --------------------------------------------------------------------*/
522 
523 
524 void SwDocShell::RemoveLink()
525 {
526 	// Uno-Object abklemmen
527 	uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), uno::UNO_QUERY);
528 	((SwXTextDocument*)xDoc.get())->Invalidate();
529 	aFinishedTimer.Stop();
530 	if(pDoc)
531 	{
532 		if( mxBasePool.is() )
533 		{
534 			static_cast<SwDocStyleSheetPool*>(mxBasePool.get())->dispose();
535 			mxBasePool.clear();
536 		}
537         sal_Int8 nRefCt = static_cast< sal_Int8 >(pDoc->release());
538 		pDoc->SetOle2Link(Link());
539 		pDoc->SetDocShell( 0 );
540 		if( !nRefCt )
541 			delete pDoc;
542 		pDoc = 0;       // wir haben das Doc nicht mehr !!
543 	}
544 }
545 void SwDocShell::InvalidateModel()
546 {
547 	// Uno-Object abklemmen
548 	uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), uno::UNO_QUERY);
549 	((SwXTextDocument*)xDoc.get())->Invalidate();
550 }
551 void SwDocShell::ReactivateModel()
552 {
553 	// Uno-Object abklemmen
554 	uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), uno::UNO_QUERY);
555 	((SwXTextDocument*)xDoc.get())->Reactivate(this);
556 }
557 
558 /*--------------------------------------------------------------------
559 	Beschreibung: Laden, Default-Format
560  --------------------------------------------------------------------*/
561 
562 
563 sal_Bool  SwDocShell::Load( SfxMedium& rMedium )
564 {
565 	RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::Load" );
566 	sal_Bool bRet = sal_False;
567     if( SfxObjectShell::Load( rMedium ))
568 	{
569 		RTL_LOGFILE_CONTEXT_TRACE( aLog, "after SfxInPlaceObject::Load" );
570 		if( pDoc )              // fuer Letzte Version !!
571 			RemoveLink();       // das existierende Loslassen
572 
573 		AddLink();      // Link setzen und Daten updaten !!
574 
575 		// Das Laden
576 		// fuer MD
577 			ASSERT( !mxBasePool.is(), "wer hat seinen Pool nicht zerstoert?" );
578 			mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
579             if(GetCreateMode() != SFX_CREATE_MODE_ORGANIZER)
580             {
581                 SFX_ITEMSET_ARG( rMedium.GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, sal_False);
582                 nUpdateDocMode = pUpdateDocItem ? pUpdateDocItem->GetValue() : document::UpdateDocMode::NO_UPDATE;
583             }
584 
585 		SwWait aWait( *this, sal_True );
586 		sal_uInt32 nErr = ERR_SWG_READ_ERROR;
587 		switch( GetCreateMode() )
588 		{
589 //		case SFX_CREATE_MODE_INTERNAL:
590 //			nErr = 0;
591 //			break;
592 
593 		case SFX_CREATE_MODE_ORGANIZER:
594 			{
595 				if( ReadXML )
596 				{
597 					ReadXML->SetOrganizerMode( sal_True );
598                     SwReader aRdr( rMedium, aEmptyStr, pDoc );
599 					nErr = aRdr.Read( *ReadXML );
600 					ReadXML->SetOrganizerMode( sal_False );
601 				}
602 			}
603 			break;
604 
605 		case SFX_CREATE_MODE_INTERNAL:
606 		case SFX_CREATE_MODE_EMBEDDED:
607 			{
608 				// fuer MWERKS (Mac-Compiler): kann nicht selbststaendig casten
609                 SwTransferable::InitOle( this, *pDoc );
610 			}
611 			// SfxProgress unterdruecken, wenn man Embedded ist
612 			SW_MOD()->SetEmbeddedLoadSave( sal_True );
613 			// kein break;
614 
615 		case SFX_CREATE_MODE_STANDARD:
616 		case SFX_CREATE_MODE_PREVIEW:
617 			{
618                 Reader *pReader = ReadXML;
619 				if( pReader )
620 				{
621 					// die DocInfo vom Doc am DocShell-Medium setzen
622 					RTL_LOGFILE_CONTEXT_TRACE( aLog, "before ReadDocInfo" );
623                     SwReader aRdr( rMedium, aEmptyStr, pDoc );
624 					RTL_LOGFILE_CONTEXT_TRACE( aLog, "before Read" );
625 					nErr = aRdr.Read( *pReader );
626 					RTL_LOGFILE_CONTEXT_TRACE( aLog, "after Read" );
627 
628 					// If a XML document is loaded, the global doc/web doc
629 					// flags have to be set, because they aren't loaded
630 					// by this formats.
631 					if( ISA( SwWebDocShell ) )
632 					{
633 						if( !pDoc->get(IDocumentSettingAccess::HTML_MODE) )
634 							pDoc->set(IDocumentSettingAccess::HTML_MODE, true);
635 					}
636 					if( ISA( SwGlobalDocShell ) )
637 					{
638 						if( !pDoc->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) )
639 							pDoc->set(IDocumentSettingAccess::GLOBAL_DOCUMENT, true);
640 					}
641 				}
642 #ifdef DBG_UTIL
643 				else
644 					ASSERT( !this, "ohne Sw3Reader geht nichts" );
645 #endif
646 			}
647 			break;
648 
649 		default:
650 			ASSERT( !this, "Load: new CreateMode?" );
651 
652 		}
653 
654 		UpdateFontList();
655 		InitDraw();
656 
657 		SetError( nErr, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
658 		bRet = !IsError( nErr );
659 
660         // --> OD 2006-11-07 #i59688#
661 //        // StartFinishedLoading rufen.
662 //        if( bRet && !pDoc->IsInLoadAsynchron() &&
663 //            GetCreateMode() == SFX_CREATE_MODE_STANDARD )
664 //            StartLoadFinishedTimer();
665         if ( bRet && !pDoc->IsInLoadAsynchron() &&
666              GetCreateMode() == SFX_CREATE_MODE_STANDARD )
667         {
668             LoadingFinished();
669         }
670         // <--
671 
672 		// SfxProgress unterdruecken, wenn man Embedded ist
673 		SW_MOD()->SetEmbeddedLoadSave( sal_False );
674 	}
675 
676 	return bRet;
677 }
678 
679 /*--------------------------------------------------------------------
680 	Beschreibung:
681  --------------------------------------------------------------------*/
682 
683 
684 sal_Bool  SwDocShell::LoadFrom( SfxMedium& rMedium )
685 {
686 	RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::LoadFrom" );
687 	sal_Bool bRet = sal_False;
688 	if( pDoc )
689 		RemoveLink();
690 
691 	AddLink();		// Link setzen und Daten updaten !!
692 
693 	do {		// middle check loop
694 		sal_uInt32 nErr = ERR_SWG_READ_ERROR;
695         //const String& rNm = pStor->GetName();
696 		String aStreamName;
697         aStreamName = String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM("styles.xml"));
698         uno::Reference < container::XNameAccess > xAccess( rMedium.GetStorage(), uno::UNO_QUERY );
699         if ( xAccess->hasByName( aStreamName ) && rMedium.GetStorage()->isStreamElement( aStreamName ) )
700 		{
701 			// Das Laden
702 			SwWait aWait( *this, sal_True );
703 			{
704 				ASSERT( !mxBasePool.is(), "wer hat seinen Pool nicht zerstoert?" );
705 				mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
706 				if( ReadXML )
707 				{
708 					ReadXML->SetOrganizerMode( sal_True );
709                     SwReader aRdr( rMedium, aEmptyStr, pDoc );
710 					nErr = aRdr.Read( *ReadXML );
711 					ReadXML->SetOrganizerMode( sal_False );
712 				}
713 			}
714 		}
715         else
716         {
717             DBG_ERROR("Code removed!");
718         /*
719         //TODO/LATER: looks like some binary stuff?!
720 			// sollte es sich um eine 2. Vrolage handeln ??
721 			if( SvStorage::IsStorageFile( rNm ) )
722 				break;
723 
724 			const SfxFilter* pFltr = SwIoSystem::GetFileFilter( rNm, aEmptyStr );
725 			if( !pFltr || !pFltr->GetUserData().EqualsAscii( FILTER_SWG ))
726 				break;
727 
728 			SfxMedium aMed( rNm, STREAM_STD_READ, sal_False );
729 			if( 0 == ( nErr = aMed.GetInStream()->GetError() ) )
730 			{
731 				SwWait aWait( *this, sal_True );
732 				SwReader aRead( aMed, rNm, pDoc );
733 				nErr = aRead.Read( *ReadSwg );
734 			}
735          */
736         }
737 
738 		SetError( nErr, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
739 		bRet = !IsError( nErr );
740 
741 	} while( sal_False );
742 
743     SfxObjectShell::LoadFrom( rMedium );
744 	pDoc->ResetModified();
745 	return bRet;
746 }
747 
748 
749 void SwDocShell::SubInitNew()
750 {
751 	ASSERT( !mxBasePool.is(), "wer hat seinen Pool nicht zerstoert?" );
752 	mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
753 	UpdateFontList();
754 	InitDraw();
755 
756     pDoc->setLinkUpdateMode( GLOBALSETTING );
757     pDoc->setFieldUpdateFlags( AUTOUPD_GLOBALSETTING );
758 
759 	sal_Bool bWeb = ISA(SwWebDocShell);
760 
761 	sal_uInt16 nRange[] =	{
762         RES_PARATR_ADJUST, RES_PARATR_ADJUST,
763         RES_CHRATR_COLOR, RES_CHRATR_COLOR,
764         RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE,
765         RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE,
766         RES_CHRATR_CTL_LANGUAGE, RES_CHRATR_CTL_LANGUAGE,
767         0, 0, 0  };
768 	if(!bWeb)
769 	{
770         nRange[ (sizeof(nRange)/sizeof(nRange[0])) - 3 ] = RES_PARATR_TABSTOP;
771         nRange[ (sizeof(nRange)/sizeof(nRange[0])) - 2 ] = RES_PARATR_HYPHENZONE;
772 	}
773 	SfxItemSet aDfltSet( pDoc->GetAttrPool(), nRange );
774 
775     //! get lingu options without loading lingu DLL
776     SvtLinguOptions aLinguOpt;
777 
778     SvtLinguConfig().GetOptions( aLinguOpt );
779 
780     sal_Int16   nVal = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN),
781                 eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN),
782                 eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX);
783 	aDfltSet.Put( SvxLanguageItem( nVal, RES_CHRATR_LANGUAGE ) );
784     aDfltSet.Put( SvxLanguageItem( eCJK, RES_CHRATR_CJK_LANGUAGE ) );
785     aDfltSet.Put( SvxLanguageItem( eCTL, RES_CHRATR_CTL_LANGUAGE ) );
786 
787     if(!bWeb)
788 	{
789 		SvxHyphenZoneItem aHyp( (SvxHyphenZoneItem&) pDoc->GetDefault(
790 														RES_PARATR_HYPHENZONE) );
791         aHyp.GetMinLead()   = static_cast< sal_uInt8 >(aLinguOpt.nHyphMinLeading);
792         aHyp.GetMinTrail()  = static_cast< sal_uInt8 >(aLinguOpt.nHyphMinTrailing);
793 
794 		aDfltSet.Put( aHyp );
795 
796         sal_uInt16 nNewPos = static_cast< sal_uInt16 >(SW_MOD()->GetUsrPref(sal_False)->GetDefTab());
797 		if( nNewPos )
798 			aDfltSet.Put( SvxTabStopItem( 1, nNewPos,
799                                           SVX_TAB_ADJUST_DEFAULT, RES_PARATR_TABSTOP ) );
800 	}
801     aDfltSet.Put( SvxColorItem( Color( COL_AUTO ), RES_CHRATR_COLOR ) );
802 
803 	pDoc->SetDefault( aDfltSet );
804 
805 	//default page mode for text grid
806 	if(!bWeb)
807 	{
808 		sal_Bool bSquaredPageMode = SW_MOD()->GetUsrPref(sal_False)->IsSquaredPageMode();
809 		pDoc->SetDefaultPageMode( bSquaredPageMode );
810 	}
811 
812 	pDoc->ResetModified();
813 }
814 
815 /*
816  * Document Interface Access
817  */
818 IDocumentDeviceAccess* SwDocShell::getIDocumentDeviceAccess() { return pDoc; }
819 const IDocumentSettingAccess* SwDocShell::getIDocumentSettingAccess() const { return pDoc; }
820 IDocumentChartDataProviderAccess* SwDocShell::getIDocumentChartDataProviderAccess() { return pDoc; }
821