xref: /trunk/main/sw/source/ui/app/docshini.cxx (revision 1396af09)
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 	SvxColorTableItem* pColItem = (SvxColorTableItem*)GetItem(SID_COLOR_TABLE);
439 	// wird nur die DocInfo fuer den Explorer gelesen, ist das Item nicht da
440 	if(pColItem)
441 	{
442 		XColorTable* pTable = pColItem->GetColorTable();
443 		// wurde eine neue Table angelegt, muss sie auch geloescht werden.
444 		if((void*)pTable  != (void*)(XColorTable::GetStdColorTable()) )
445 			delete pTable;
446 	}
447 
448     delete pOLEChildList;
449 }
450 /* -----------------------------10.09.2001 15:59------------------------------
451 
452  ---------------------------------------------------------------------------*/
453 void  SwDocShell::Init_Impl()
454 {
455     SetPool(&SW_MOD()->GetPool());
456 	SetBaseModel(new SwXTextDocument(this));
457 	// wir als BroadCaster werden auch unser eigener Listener
458 	// (fuer DocInfo/FileNamen/....)
459 	StartListening( *this );
460     //position of the "Automatic" style filter for the stylist (app.src)
461     SetAutoStyleFilterIndex(3);
462 
463 	// set map unit to twip
464 	SetMapUnit( MAP_TWIP );
465 }
466 /*--------------------------------------------------------------------
467 	Beschreibung: AddLink
468  --------------------------------------------------------------------*/
469 
470 
471 void SwDocShell::AddLink()
472 {
473 	if( !pDoc )
474 	{
475 		SwDocFac aFactory;
476 		pDoc = aFactory.GetDoc();
477 		pDoc->acquire();
478 		pDoc->set(IDocumentSettingAccess::HTML_MODE, ISA(SwWebDocShell) );
479 	}
480 	else
481 		pDoc->acquire();
482 	pDoc->SetDocShell( this );		// am Doc den DocShell-Pointer setzen
483 	uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), uno::UNO_QUERY);
484 	((SwXTextDocument*)xDoc.get())->Reactivate(this);
485 
486 	SetPool(&pDoc->GetAttrPool());
487 
488 	// am besten erst wenn eine sdbcx::View erzeugt wird !!!
489 	pDoc->SetOle2Link(LINK(this, SwDocShell, Ole2ModifiedHdl));
490 }
491 
492 /*--------------------------------------------------------------------
493 	Beschreibung:	neue FontList erzeugen Aenderung Drucker
494  --------------------------------------------------------------------*/
495 
496 
497 void SwDocShell::UpdateFontList()
498 {
499     if(!bInUpdateFontList)
500     {
501         bInUpdateFontList = true;
502         ASSERT(pDoc, "Kein Doc keine FontList");
503         if( pDoc )
504         {
505             delete pFontList;
506             pFontList = new FontList( pDoc->getReferenceDevice( true ) );
507             PutItem( SvxFontListItem( pFontList, SID_ATTR_CHAR_FONTLIST ) );
508         }
509         bInUpdateFontList = false;
510     }
511 }
512 
513 /*--------------------------------------------------------------------
514 	Beschreibung: RemoveLink
515  --------------------------------------------------------------------*/
516 
517 
518 void SwDocShell::RemoveLink()
519 {
520 	// Uno-Object abklemmen
521 	uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), uno::UNO_QUERY);
522 	((SwXTextDocument*)xDoc.get())->Invalidate();
523 	aFinishedTimer.Stop();
524 	if(pDoc)
525 	{
526 		if( mxBasePool.is() )
527 		{
528 			static_cast<SwDocStyleSheetPool*>(mxBasePool.get())->dispose();
529 			mxBasePool.clear();
530 		}
531         sal_Int8 nRefCt = static_cast< sal_Int8 >(pDoc->release());
532 		pDoc->SetOle2Link(Link());
533 		pDoc->SetDocShell( 0 );
534 		if( !nRefCt )
535 			delete pDoc;
536 		pDoc = 0;       // wir haben das Doc nicht mehr !!
537 	}
538 }
539 void SwDocShell::InvalidateModel()
540 {
541 	// Uno-Object abklemmen
542 	uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), uno::UNO_QUERY);
543 	((SwXTextDocument*)xDoc.get())->Invalidate();
544 }
545 void SwDocShell::ReactivateModel()
546 {
547 	// Uno-Object abklemmen
548 	uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), uno::UNO_QUERY);
549 	((SwXTextDocument*)xDoc.get())->Reactivate(this);
550 }
551 
552 /*--------------------------------------------------------------------
553 	Beschreibung: Laden, Default-Format
554  --------------------------------------------------------------------*/
555 
556 
557 sal_Bool  SwDocShell::Load( SfxMedium& rMedium )
558 {
559 	RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::Load" );
560 	sal_Bool bRet = sal_False;
561     if( SfxObjectShell::Load( rMedium ))
562 	{
563 		RTL_LOGFILE_CONTEXT_TRACE( aLog, "after SfxInPlaceObject::Load" );
564 		if( pDoc )              // fuer Letzte Version !!
565 			RemoveLink();       // das existierende Loslassen
566 
567 		AddLink();      // Link setzen und Daten updaten !!
568 
569 		// Das Laden
570 		// fuer MD
571 			ASSERT( !mxBasePool.is(), "wer hat seinen Pool nicht zerstoert?" );
572 			mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
573             if(GetCreateMode() != SFX_CREATE_MODE_ORGANIZER)
574             {
575                 SFX_ITEMSET_ARG( rMedium.GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, sal_False);
576                 nUpdateDocMode = pUpdateDocItem ? pUpdateDocItem->GetValue() : document::UpdateDocMode::NO_UPDATE;
577             }
578 
579 		SwWait aWait( *this, sal_True );
580 		sal_uInt32 nErr = ERR_SWG_READ_ERROR;
581 		switch( GetCreateMode() )
582 		{
583 //		case SFX_CREATE_MODE_INTERNAL:
584 //			nErr = 0;
585 //			break;
586 
587 		case SFX_CREATE_MODE_ORGANIZER:
588 			{
589 				if( ReadXML )
590 				{
591 					ReadXML->SetOrganizerMode( sal_True );
592                     SwReader aRdr( rMedium, aEmptyStr, pDoc );
593 					nErr = aRdr.Read( *ReadXML );
594 					ReadXML->SetOrganizerMode( sal_False );
595 				}
596 			}
597 			break;
598 
599 		case SFX_CREATE_MODE_INTERNAL:
600 		case SFX_CREATE_MODE_EMBEDDED:
601 			{
602 				// fuer MWERKS (Mac-Compiler): kann nicht selbststaendig casten
603                 SwTransferable::InitOle( this, *pDoc );
604 			}
605 			// SfxProgress unterdruecken, wenn man Embedded ist
606 			SW_MOD()->SetEmbeddedLoadSave( sal_True );
607 			// kein break;
608 
609 		case SFX_CREATE_MODE_STANDARD:
610 		case SFX_CREATE_MODE_PREVIEW:
611 			{
612                 Reader *pReader = ReadXML;
613 				if( pReader )
614 				{
615 					// die DocInfo vom Doc am DocShell-Medium setzen
616 					RTL_LOGFILE_CONTEXT_TRACE( aLog, "before ReadDocInfo" );
617                     SwReader aRdr( rMedium, aEmptyStr, pDoc );
618 					RTL_LOGFILE_CONTEXT_TRACE( aLog, "before Read" );
619 					nErr = aRdr.Read( *pReader );
620 					RTL_LOGFILE_CONTEXT_TRACE( aLog, "after Read" );
621 
622 					// If a XML document is loaded, the global doc/web doc
623 					// flags have to be set, because they aren't loaded
624 					// by this formats.
625 					if( ISA( SwWebDocShell ) )
626 					{
627 						if( !pDoc->get(IDocumentSettingAccess::HTML_MODE) )
628 							pDoc->set(IDocumentSettingAccess::HTML_MODE, true);
629 					}
630 					if( ISA( SwGlobalDocShell ) )
631 					{
632 						if( !pDoc->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) )
633 							pDoc->set(IDocumentSettingAccess::GLOBAL_DOCUMENT, true);
634 					}
635 				}
636 #ifdef DBG_UTIL
637 				else
638 					ASSERT( !this, "ohne Sw3Reader geht nichts" );
639 #endif
640 			}
641 			break;
642 
643 		default:
644 			ASSERT( !this, "Load: new CreateMode?" );
645 
646 		}
647 
648 		UpdateFontList();
649 		InitDraw();
650 
651 		SetError( nErr, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
652 		bRet = !IsError( nErr );
653 
654         // --> OD 2006-11-07 #i59688#
655 //        // StartFinishedLoading rufen.
656 //        if( bRet && !pDoc->IsInLoadAsynchron() &&
657 //            GetCreateMode() == SFX_CREATE_MODE_STANDARD )
658 //            StartLoadFinishedTimer();
659         if ( bRet && !pDoc->IsInLoadAsynchron() &&
660              GetCreateMode() == SFX_CREATE_MODE_STANDARD )
661         {
662             LoadingFinished();
663         }
664         // <--
665 
666 		// SfxProgress unterdruecken, wenn man Embedded ist
667 		SW_MOD()->SetEmbeddedLoadSave( sal_False );
668 	}
669 
670 	return bRet;
671 }
672 
673 /*--------------------------------------------------------------------
674 	Beschreibung:
675  --------------------------------------------------------------------*/
676 
677 
678 sal_Bool  SwDocShell::LoadFrom( SfxMedium& rMedium )
679 {
680 	RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::LoadFrom" );
681 	sal_Bool bRet = sal_False;
682 	if( pDoc )
683 		RemoveLink();
684 
685 	AddLink();		// Link setzen und Daten updaten !!
686 
687 	do {		// middle check loop
688 		sal_uInt32 nErr = ERR_SWG_READ_ERROR;
689         //const String& rNm = pStor->GetName();
690 		String aStreamName;
691         aStreamName = String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM("styles.xml"));
692         uno::Reference < container::XNameAccess > xAccess( rMedium.GetStorage(), uno::UNO_QUERY );
693         if ( xAccess->hasByName( aStreamName ) && rMedium.GetStorage()->isStreamElement( aStreamName ) )
694 		{
695 			// Das Laden
696 			SwWait aWait( *this, sal_True );
697 			{
698 				ASSERT( !mxBasePool.is(), "wer hat seinen Pool nicht zerstoert?" );
699 				mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
700 				if( ReadXML )
701 				{
702 					ReadXML->SetOrganizerMode( sal_True );
703                     SwReader aRdr( rMedium, aEmptyStr, pDoc );
704 					nErr = aRdr.Read( *ReadXML );
705 					ReadXML->SetOrganizerMode( sal_False );
706 				}
707 			}
708 		}
709         else
710         {
711             DBG_ERROR("Code removed!");
712         /*
713         //TODO/LATER: looks like some binary stuff?!
714 			// sollte es sich um eine 2. Vrolage handeln ??
715 			if( SvStorage::IsStorageFile( rNm ) )
716 				break;
717 
718 			const SfxFilter* pFltr = SwIoSystem::GetFileFilter( rNm, aEmptyStr );
719 			if( !pFltr || !pFltr->GetUserData().EqualsAscii( FILTER_SWG ))
720 				break;
721 
722 			SfxMedium aMed( rNm, STREAM_STD_READ, sal_False );
723 			if( 0 == ( nErr = aMed.GetInStream()->GetError() ) )
724 			{
725 				SwWait aWait( *this, sal_True );
726 				SwReader aRead( aMed, rNm, pDoc );
727 				nErr = aRead.Read( *ReadSwg );
728 			}
729          */
730         }
731 
732 		SetError( nErr, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
733 		bRet = !IsError( nErr );
734 
735 	} while( sal_False );
736 
737     SfxObjectShell::LoadFrom( rMedium );
738 	pDoc->ResetModified();
739 	return bRet;
740 }
741 
742 
743 void SwDocShell::SubInitNew()
744 {
745 	ASSERT( !mxBasePool.is(), "wer hat seinen Pool nicht zerstoert?" );
746 	mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
747 	UpdateFontList();
748 	InitDraw();
749 
750     pDoc->setLinkUpdateMode( GLOBALSETTING );
751     pDoc->setFieldUpdateFlags( AUTOUPD_GLOBALSETTING );
752 
753 	sal_Bool bWeb = ISA(SwWebDocShell);
754 
755 	sal_uInt16 nRange[] =	{
756         RES_PARATR_ADJUST, RES_PARATR_ADJUST,
757         RES_CHRATR_COLOR, RES_CHRATR_COLOR,
758         RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE,
759         RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE,
760         RES_CHRATR_CTL_LANGUAGE, RES_CHRATR_CTL_LANGUAGE,
761         0, 0, 0  };
762 	if(!bWeb)
763 	{
764         nRange[ (sizeof(nRange)/sizeof(nRange[0])) - 3 ] = RES_PARATR_TABSTOP;
765         nRange[ (sizeof(nRange)/sizeof(nRange[0])) - 2 ] = RES_PARATR_HYPHENZONE;
766 	}
767 	SfxItemSet aDfltSet( pDoc->GetAttrPool(), nRange );
768 
769     //! get lingu options without loading lingu DLL
770     SvtLinguOptions aLinguOpt;
771 
772     SvtLinguConfig().GetOptions( aLinguOpt );
773 
774     sal_Int16   nVal = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN),
775                 eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN),
776                 eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX);
777 	aDfltSet.Put( SvxLanguageItem( nVal, RES_CHRATR_LANGUAGE ) );
778     aDfltSet.Put( SvxLanguageItem( eCJK, RES_CHRATR_CJK_LANGUAGE ) );
779     aDfltSet.Put( SvxLanguageItem( eCTL, RES_CHRATR_CTL_LANGUAGE ) );
780 
781     if(!bWeb)
782 	{
783 		SvxHyphenZoneItem aHyp( (SvxHyphenZoneItem&) pDoc->GetDefault(
784 														RES_PARATR_HYPHENZONE) );
785         aHyp.GetMinLead()   = static_cast< sal_uInt8 >(aLinguOpt.nHyphMinLeading);
786         aHyp.GetMinTrail()  = static_cast< sal_uInt8 >(aLinguOpt.nHyphMinTrailing);
787 
788 		aDfltSet.Put( aHyp );
789 
790         sal_uInt16 nNewPos = static_cast< sal_uInt16 >(SW_MOD()->GetUsrPref(sal_False)->GetDefTab());
791 		if( nNewPos )
792 			aDfltSet.Put( SvxTabStopItem( 1, nNewPos,
793                                           SVX_TAB_ADJUST_DEFAULT, RES_PARATR_TABSTOP ) );
794 	}
795     aDfltSet.Put( SvxColorItem( Color( COL_AUTO ), RES_CHRATR_COLOR ) );
796 
797 	pDoc->SetDefault( aDfltSet );
798 
799 	//default page mode for text grid
800 	if(!bWeb)
801 	{
802 		sal_Bool bSquaredPageMode = SW_MOD()->GetUsrPref(sal_False)->IsSquaredPageMode();
803 		pDoc->SetDefaultPageMode( bSquaredPageMode );
804 	}
805 
806 	pDoc->ResetModified();
807 }
808 
809 /*
810  * Document Interface Access
811  */
812 IDocumentDeviceAccess* SwDocShell::getIDocumentDeviceAccess() { return pDoc; }
813 const IDocumentSettingAccess* SwDocShell::getIDocumentSettingAccess() const { return pDoc; }
814 IDocumentChartDataProviderAccess* SwDocShell::getIDocumentChartDataProviderAccess() { return pDoc; }
815