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