xref: /aoo41x/main/sw/source/ui/app/docshini.cxx (revision 233d87e4)
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 	pDoc->SetDrawDefaults();
351 
352     // --> OD 2005-02-10 #i42080# - Due to the several calls of method <SetDefault(..)>
353     // at the document instance, the document is modified. Thus, reset this
354     // status here. Note: In method <SubInitNew()> this is also done.
355     pDoc->ResetModified();
356     // <--
357 
358 	return bRet;
359 }
360 
361 //#115580# When creating a new document, if needed, set the default
362 // font and languague attributes.
363 void SwDocShell::InitDefaultFontAttr( SwDoc* pDoc )
364 {
365 	sal_uInt16 aFontWhich[] =
366 	{
367 		RES_CHRATR_FONT,
368 		RES_CHRATR_CJK_FONT,
369 		RES_CHRATR_CTL_FONT
370 	};
371 	sal_uInt16 aFontHeightWhich[] =
372 	{
373 		RES_CHRATR_FONTSIZE,
374 		RES_CHRATR_CJK_FONTSIZE,
375 		RES_CHRATR_CTL_FONTSIZE
376 	};
377 	sal_uInt16 aFontIds[] =
378 	{
379 		FONT_STANDARD,
380 		FONT_STANDARD_CJK,
381 		FONT_STANDARD_CTL
382 	};
383 	sal_uInt16 nFontTypes[] =
384 	{
385 		DEFAULTFONT_LATIN_TEXT,
386 		DEFAULTFONT_CJK_TEXT,
387 		DEFAULTFONT_CTL_TEXT
388 	};
389 
390 	sal_uInt16 aLangWhich[] =
391 	{
392 		RES_CHRATR_LANGUAGE,
393 		RES_CHRATR_CJK_LANGUAGE,
394 		RES_CHRATR_CTL_LANGUAGE
395 	};
396 	sal_uInt16 aLangTypes[] =
397 	{
398 		LANGUAGE_ENGLISH_US,
399 		LANGUAGE_ENGLISH_US,
400 		LANGUAGE_ARABIC_SAUDI_ARABIA
401 	};
402 
403 	SwStdFontConfig* pStdFont = SW_MOD()->GetStdFontConfig();
404 	String sEntry;
405 
406 	for(sal_uInt8 i = 0; i < 3; i++)
407 	{
408 		sal_uInt16 nFontWhich = aFontWhich[i];
409 		sal_uInt16 nFontId = aFontIds[i];
410 		SvxFontItem* pFontItem = 0;
411 		const SvxLanguageItem& rLang = (const SvxLanguageItem&)pDoc->GetDefault( aLangWhich[i] );
412 		LanguageType eLanguage = rLang.GetLanguage();
413 		if ( (eLanguage == LANGUAGE_DONTKNOW) || (eLanguage == LANGUAGE_NONE) )
414 			eLanguage = aLangTypes[i];
415 		{
416 			if ( i == 0 )
417 			{//At present, just supports for the following languages: english, french and german.
418 				LanguageType eUiLanguage = Application::GetSettings().GetUILanguage();
419 				switch( eUiLanguage )
420 				{
421 				case LANGUAGE_ENGLISH_US:
422 				case LANGUAGE_FRENCH:
423 				case LANGUAGE_FRENCH_BELGIAN:
424 				case LANGUAGE_FRENCH_CAMEROON:
425 				case LANGUAGE_FRENCH_CANADIAN:
426 				case LANGUAGE_FRENCH_COTE_D_IVOIRE:
427 				case LANGUAGE_FRENCH_HAITI:
428 				case LANGUAGE_FRENCH_LUXEMBOURG:
429 				case LANGUAGE_FRENCH_MALI:
430 				case LANGUAGE_FRENCH_MONACO:
431 				case LANGUAGE_FRENCH_MOROCCO:
432 				case LANGUAGE_FRENCH_NORTH_AFRICA:
433 				case LANGUAGE_FRENCH_REUNION:
434 				case LANGUAGE_FRENCH_SENEGAL:
435 				case LANGUAGE_FRENCH_SWISS:
436 				case LANGUAGE_FRENCH_WEST_INDIES:
437 				case LANGUAGE_FRENCH_ZAIRE:
438 				case LANGUAGE_GERMAN:
439 				case LANGUAGE_GERMAN_AUSTRIAN:
440 				case LANGUAGE_GERMAN_LIECHTENSTEIN:
441 				case LANGUAGE_GERMAN_LUXEMBOURG:
442 				case LANGUAGE_GERMAN_SWISS:
443 					eLanguage = eUiLanguage;
444 					break;
445 
446 				}
447 			}
448 
449 			if ( i == 2 ) //CTL,just supports for HINDI and ARABIC_SAUDI_ARABIA
450 			{
451 				LanguageType eUiLanguage = Application::GetSettings().GetUILanguage();
452 				switch( eUiLanguage )
453 				{
454 				case LANGUAGE_HINDI:
455 					eLanguage = eUiLanguage;
456 					break;
457 
458 				}
459 			}
460 
461 			if ( i == 1 ) //CJK
462 			{
463 				LanguageType eUiLanguage = Application::GetSettings().GetUILanguage();
464 				switch( eUiLanguage )
465 				{
466 				case LANGUAGE_KOREAN:
467 				case LANGUAGE_KOREAN_JOHAB:
468 				case LANGUAGE_CHINESE:
469 				case LANGUAGE_CHINESE_HONGKONG:
470 				case LANGUAGE_CHINESE_MACAU:
471 				case LANGUAGE_CHINESE_SIMPLIFIED:
472 				case LANGUAGE_CHINESE_SINGAPORE:
473 				case LANGUAGE_CHINESE_TRADITIONAL:
474 				case LANGUAGE_JAPANESE:
475 					eLanguage = eUiLanguage;
476 					break;
477 				}
478 			}
479 
480 			Font aLangDefFont = OutputDevice::GetDefaultFont(
481 				nFontTypes[i],
482 				eLanguage,
483 				DEFAULTFONT_FLAGS_ONLYONE );
484 			pFontItem = new SvxFontItem(aLangDefFont.GetFamily(), aLangDefFont.GetName(),
485 				aEmptyStr, aLangDefFont.GetPitch(), aLangDefFont.GetCharSet(), nFontWhich);
486 		}
487 
488 		pDoc->SetDefault(*pFontItem);
489 		delete pFontItem;
490 
491 		sal_Int32 nFontHeight = pStdFont->GetFontHeight( FONT_STANDARD, i, eLanguage );
492 		if(nFontHeight <= 0)
493 			nFontHeight = pStdFont->GetDefaultHeightFor( nFontId, eLanguage );
494 		pDoc->SetDefault(SvxFontHeightItem( nFontHeight, 100, aFontHeightWhich[i] ));
495 		pDoc->SetDefault( SvxLanguageItem( eLanguage, aLangWhich[i] ) );
496 	}
497 }
498 
499 /*--------------------------------------------------------------------
500 	Beschreibung:	Ctor mit SfxCreateMode ?????
501  --------------------------------------------------------------------*/
502 
503 
504 SwDocShell::SwDocShell( SfxObjectCreateMode eMode ) :
505     SfxObjectShell ( eMode ),
506 	pDoc(0),
507 	pFontList(0),
508 	pView( 0 ),
509     pWrtShell( 0 ),
510     pOLEChildList( 0 ),
511     nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG),
512     bInUpdateFontList(false)
513 {
514 	RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::SwDocShell" );
515     Init_Impl();
516 }
517 
518 /*--------------------------------------------------------------------
519 	Beschreibung: Ctor / Dtor
520  --------------------------------------------------------------------*/
521 
522 
523 SwDocShell::SwDocShell( const sal_uInt64 i_nSfxCreationFlags ) :
524     SfxObjectShell ( i_nSfxCreationFlags ),
525 	pDoc(0),
526 	pFontList(0),
527 	pView( 0 ),
528     pWrtShell( 0 ),
529     pOLEChildList( 0 ),
530     nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG),
531     bInUpdateFontList(false)
532 {
533 	RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::SwDocShell" );
534     Init_Impl();
535 }
536 
537 /*--------------------------------------------------------------------
538 	Beschreibung: Ctor / Dtor
539  --------------------------------------------------------------------*/
540 
541 
542 SwDocShell::SwDocShell( SwDoc *pD, SfxObjectCreateMode eMode ):
543     SfxObjectShell ( eMode ),
544 	pDoc(pD),
545 	pFontList(0),
546 	pView( 0 ),
547     pWrtShell( 0 ),
548     pOLEChildList( 0 ),
549     nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG),
550     bInUpdateFontList(false)
551 {
552 	RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::SwDocShell" );
553     Init_Impl();
554 }
555 
556 /*--------------------------------------------------------------------
557 	Beschreibung:	Dtor
558  --------------------------------------------------------------------*/
559 
560 
561  SwDocShell::~SwDocShell()
562 {
563     // disable chart related objects now because in ~SwDoc it may be to late for this
564     if( pDoc )
565     {
566         pDoc->GetChartControllerHelper().Disconnect();
567         SwChartDataProvider *pPCD = pDoc->GetChartDataProvider();
568         if (pPCD)
569             pPCD->dispose();
570     }
571 
572     RemoveLink();
573 	delete pFontList;
574 
575 	// wir als BroadCaster werden auch unser eigener Listener
576 	// (fuer DocInfo/FileNamen/....)
577 	EndListening( *this );
578 	SvxColorTableItem* pColItem = (SvxColorTableItem*)GetItem(SID_COLOR_TABLE);
579 	// wird nur die DocInfo fuer den Explorer gelesen, ist das Item nicht da
580 	if(pColItem)
581 	{
582 		XColorTable* pTable = pColItem->GetColorTable();
583 		// wurde eine neue Table angelegt, muss sie auch geloescht werden.
584 		if((void*)pTable  != (void*)(XColorTable::GetStdColorTable()) )
585 			delete pTable;
586 	}
587 
588     delete pOLEChildList;
589 }
590 /* -----------------------------10.09.2001 15:59------------------------------
591 
592  ---------------------------------------------------------------------------*/
593 void  SwDocShell::Init_Impl()
594 {
595     SetPool(&SW_MOD()->GetPool());
596 	SetBaseModel(new SwXTextDocument(this));
597 	// wir als BroadCaster werden auch unser eigener Listener
598 	// (fuer DocInfo/FileNamen/....)
599 	StartListening( *this );
600     //position of the "Automatic" style filter for the stylist (app.src)
601     SetAutoStyleFilterIndex(3);
602 
603 	// set map unit to twip
604 	SetMapUnit( MAP_TWIP );
605 }
606 /*--------------------------------------------------------------------
607 	Beschreibung: AddLink
608  --------------------------------------------------------------------*/
609 
610 
611 void SwDocShell::AddLink()
612 {
613 	if( !pDoc )
614 	{
615 		SwDocFac aFactory;
616 		pDoc = aFactory.GetDoc();
617 		pDoc->acquire();
618 		pDoc->set(IDocumentSettingAccess::HTML_MODE, ISA(SwWebDocShell) );
619 	}
620 	else
621 		pDoc->acquire();
622 	pDoc->SetDocShell( this );		// am Doc den DocShell-Pointer setzen
623 	uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), uno::UNO_QUERY);
624 	((SwXTextDocument*)xDoc.get())->Reactivate(this);
625 
626 	SetPool(&pDoc->GetAttrPool());
627 
628 	// am besten erst wenn eine sdbcx::View erzeugt wird !!!
629 	pDoc->SetOle2Link(LINK(this, SwDocShell, Ole2ModifiedHdl));
630 }
631 
632 /*--------------------------------------------------------------------
633 	Beschreibung:	neue FontList erzeugen Aenderung Drucker
634  --------------------------------------------------------------------*/
635 
636 
637 void SwDocShell::UpdateFontList()
638 {
639     if(!bInUpdateFontList)
640     {
641         bInUpdateFontList = true;
642         ASSERT(pDoc, "Kein Doc keine FontList");
643         if( pDoc )
644         {
645             delete pFontList;
646             pFontList = new FontList( pDoc->getReferenceDevice( true ) );
647             PutItem( SvxFontListItem( pFontList, SID_ATTR_CHAR_FONTLIST ) );
648         }
649         bInUpdateFontList = false;
650     }
651 }
652 
653 /*--------------------------------------------------------------------
654 	Beschreibung: RemoveLink
655  --------------------------------------------------------------------*/
656 
657 
658 void SwDocShell::RemoveLink()
659 {
660 	// Uno-Object abklemmen
661 	uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), uno::UNO_QUERY);
662 	((SwXTextDocument*)xDoc.get())->Invalidate();
663 	aFinishedTimer.Stop();
664 	if(pDoc)
665 	{
666 		if( mxBasePool.is() )
667 		{
668 			static_cast<SwDocStyleSheetPool*>(mxBasePool.get())->dispose();
669 			mxBasePool.clear();
670 		}
671         sal_Int8 nRefCt = static_cast< sal_Int8 >(pDoc->release());
672 		pDoc->SetOle2Link(Link());
673 		pDoc->SetDocShell( 0 );
674 		if( !nRefCt )
675 			delete pDoc;
676 		pDoc = 0;       // wir haben das Doc nicht mehr !!
677 	}
678 }
679 void SwDocShell::InvalidateModel()
680 {
681 	// Uno-Object abklemmen
682 	uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), uno::UNO_QUERY);
683 	((SwXTextDocument*)xDoc.get())->Invalidate();
684 }
685 void SwDocShell::ReactivateModel()
686 {
687 	// Uno-Object abklemmen
688 	uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), uno::UNO_QUERY);
689 	((SwXTextDocument*)xDoc.get())->Reactivate(this);
690 }
691 
692 /*--------------------------------------------------------------------
693 	Beschreibung: Laden, Default-Format
694  --------------------------------------------------------------------*/
695 
696 
697 sal_Bool  SwDocShell::Load( SfxMedium& rMedium )
698 {
699 	RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::Load" );
700 	sal_Bool bRet = sal_False;
701     if( SfxObjectShell::Load( rMedium ))
702 	{
703 		RTL_LOGFILE_CONTEXT_TRACE( aLog, "after SfxInPlaceObject::Load" );
704 		if( pDoc )              // fuer Letzte Version !!
705 			RemoveLink();       // das existierende Loslassen
706 
707 		AddLink();      // Link setzen und Daten updaten !!
708 
709 		// Das Laden
710 		// fuer MD
711 			ASSERT( !mxBasePool.is(), "wer hat seinen Pool nicht zerstoert?" );
712 			mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
713             if(GetCreateMode() != SFX_CREATE_MODE_ORGANIZER)
714             {
715                 SFX_ITEMSET_ARG( rMedium.GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, sal_False);
716                 nUpdateDocMode = pUpdateDocItem ? pUpdateDocItem->GetValue() : document::UpdateDocMode::NO_UPDATE;
717             }
718 
719 		SwWait aWait( *this, sal_True );
720 		sal_uInt32 nErr = ERR_SWG_READ_ERROR;
721 		switch( GetCreateMode() )
722 		{
723 //		case SFX_CREATE_MODE_INTERNAL:
724 //			nErr = 0;
725 //			break;
726 
727 		case SFX_CREATE_MODE_ORGANIZER:
728 			{
729 				if( ReadXML )
730 				{
731 					ReadXML->SetOrganizerMode( sal_True );
732                     SwReader aRdr( rMedium, aEmptyStr, pDoc );
733 					nErr = aRdr.Read( *ReadXML );
734 					ReadXML->SetOrganizerMode( sal_False );
735 				}
736 			}
737 			break;
738 
739 		case SFX_CREATE_MODE_INTERNAL:
740 		case SFX_CREATE_MODE_EMBEDDED:
741 			{
742 				// fuer MWERKS (Mac-Compiler): kann nicht selbststaendig casten
743                 SwTransferable::InitOle( this, *pDoc );
744 			}
745 			// SfxProgress unterdruecken, wenn man Embedded ist
746 			SW_MOD()->SetEmbeddedLoadSave( sal_True );
747 			// kein break;
748 
749 		case SFX_CREATE_MODE_STANDARD:
750 		case SFX_CREATE_MODE_PREVIEW:
751 			{
752                 Reader *pReader = ReadXML;
753 				if( pReader )
754 				{
755 					// die DocInfo vom Doc am DocShell-Medium setzen
756 					RTL_LOGFILE_CONTEXT_TRACE( aLog, "before ReadDocInfo" );
757                     SwReader aRdr( rMedium, aEmptyStr, pDoc );
758 					RTL_LOGFILE_CONTEXT_TRACE( aLog, "before Read" );
759 					nErr = aRdr.Read( *pReader );
760 					RTL_LOGFILE_CONTEXT_TRACE( aLog, "after Read" );
761 
762 					// If a XML document is loaded, the global doc/web doc
763 					// flags have to be set, because they aren't loaded
764 					// by this formats.
765 					if( ISA( SwWebDocShell ) )
766 					{
767 						if( !pDoc->get(IDocumentSettingAccess::HTML_MODE) )
768 							pDoc->set(IDocumentSettingAccess::HTML_MODE, true);
769 					}
770 					if( ISA( SwGlobalDocShell ) )
771 					{
772 						if( !pDoc->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) )
773 							pDoc->set(IDocumentSettingAccess::GLOBAL_DOCUMENT, true);
774 					}
775 				}
776 #ifdef DBG_UTIL
777 				else
778 					ASSERT( !this, "ohne Sw3Reader geht nichts" );
779 #endif
780 			}
781 			break;
782 
783 		default:
784 			ASSERT( !this, "Load: new CreateMode?" );
785 
786 		}
787 
788 		UpdateFontList();
789 		InitDraw();
790 
791 		SetError( nErr, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
792 		bRet = !IsError( nErr );
793 
794         // --> OD 2006-11-07 #i59688#
795 //        // StartFinishedLoading rufen.
796 //        if( bRet && !pDoc->IsInLoadAsynchron() &&
797 //            GetCreateMode() == SFX_CREATE_MODE_STANDARD )
798 //            StartLoadFinishedTimer();
799         if ( bRet && !pDoc->IsInLoadAsynchron() &&
800              GetCreateMode() == SFX_CREATE_MODE_STANDARD )
801         {
802             LoadingFinished();
803         }
804         // <--
805 
806 		// SfxProgress unterdruecken, wenn man Embedded ist
807 		SW_MOD()->SetEmbeddedLoadSave( sal_False );
808 	}
809 
810 	return bRet;
811 }
812 
813 /*--------------------------------------------------------------------
814 	Beschreibung:
815  --------------------------------------------------------------------*/
816 
817 
818 sal_Bool  SwDocShell::LoadFrom( SfxMedium& rMedium )
819 {
820 	RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::LoadFrom" );
821 	sal_Bool bRet = sal_False;
822 	if( pDoc )
823 		RemoveLink();
824 
825 	AddLink();		// Link setzen und Daten updaten !!
826 
827 	do {		// middle check loop
828 		sal_uInt32 nErr = ERR_SWG_READ_ERROR;
829         //const String& rNm = pStor->GetName();
830 		String aStreamName;
831         aStreamName = String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM("styles.xml"));
832         uno::Reference < container::XNameAccess > xAccess( rMedium.GetStorage(), uno::UNO_QUERY );
833         if ( xAccess->hasByName( aStreamName ) && rMedium.GetStorage()->isStreamElement( aStreamName ) )
834 		{
835 			// Das Laden
836 			SwWait aWait( *this, sal_True );
837 			{
838 				ASSERT( !mxBasePool.is(), "wer hat seinen Pool nicht zerstoert?" );
839 				mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
840 				if( ReadXML )
841 				{
842 					ReadXML->SetOrganizerMode( sal_True );
843                     SwReader aRdr( rMedium, aEmptyStr, pDoc );
844 					nErr = aRdr.Read( *ReadXML );
845 					ReadXML->SetOrganizerMode( sal_False );
846 				}
847 			}
848 		}
849         else
850         {
851             DBG_ERROR("Code removed!");
852         /*
853         //TODO/LATER: looks like some binary stuff?!
854 			// sollte es sich um eine 2. Vrolage handeln ??
855 			if( SvStorage::IsStorageFile( rNm ) )
856 				break;
857 
858 			const SfxFilter* pFltr = SwIoSystem::GetFileFilter( rNm, aEmptyStr );
859 			if( !pFltr || !pFltr->GetUserData().EqualsAscii( FILTER_SWG ))
860 				break;
861 
862 			SfxMedium aMed( rNm, STREAM_STD_READ, sal_False );
863 			if( 0 == ( nErr = aMed.GetInStream()->GetError() ) )
864 			{
865 				SwWait aWait( *this, sal_True );
866 				SwReader aRead( aMed, rNm, pDoc );
867 				nErr = aRead.Read( *ReadSwg );
868 			}
869          */
870         }
871 
872 		SetError( nErr, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
873 		bRet = !IsError( nErr );
874 
875 	} while( sal_False );
876 
877     SfxObjectShell::LoadFrom( rMedium );
878 	pDoc->ResetModified();
879 	return bRet;
880 }
881 
882 
883 void SwDocShell::SubInitNew()
884 {
885 	ASSERT( !mxBasePool.is(), "wer hat seinen Pool nicht zerstoert?" );
886 	mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
887 	UpdateFontList();
888 	InitDraw();
889 
890     pDoc->setLinkUpdateMode( GLOBALSETTING );
891     pDoc->setFieldUpdateFlags( AUTOUPD_GLOBALSETTING );
892 
893 	sal_Bool bWeb = ISA(SwWebDocShell);
894 
895 	sal_uInt16 nRange[] =	{
896         RES_PARATR_ADJUST, RES_PARATR_ADJUST,
897         RES_CHRATR_COLOR, RES_CHRATR_COLOR,
898         RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE,
899         RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE,
900         RES_CHRATR_CTL_LANGUAGE, RES_CHRATR_CTL_LANGUAGE,
901         0, 0, 0  };
902 	if(!bWeb)
903 	{
904         nRange[ (sizeof(nRange)/sizeof(nRange[0])) - 3 ] = RES_PARATR_TABSTOP;
905         nRange[ (sizeof(nRange)/sizeof(nRange[0])) - 2 ] = RES_PARATR_HYPHENZONE;
906 	}
907 	SfxItemSet aDfltSet( pDoc->GetAttrPool(), nRange );
908 
909     //! get lingu options without loading lingu DLL
910     SvtLinguOptions aLinguOpt;
911 
912     SvtLinguConfig().GetOptions( aLinguOpt );
913 
914     sal_Int16   nVal = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN),
915                 eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN),
916                 eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX);
917 	aDfltSet.Put( SvxLanguageItem( nVal, RES_CHRATR_LANGUAGE ) );
918     aDfltSet.Put( SvxLanguageItem( eCJK, RES_CHRATR_CJK_LANGUAGE ) );
919     aDfltSet.Put( SvxLanguageItem( eCTL, RES_CHRATR_CTL_LANGUAGE ) );
920 
921     if(!bWeb)
922 	{
923 		SvxHyphenZoneItem aHyp( (SvxHyphenZoneItem&) pDoc->GetDefault(
924 														RES_PARATR_HYPHENZONE) );
925         aHyp.GetMinLead()   = static_cast< sal_uInt8 >(aLinguOpt.nHyphMinLeading);
926         aHyp.GetMinTrail()  = static_cast< sal_uInt8 >(aLinguOpt.nHyphMinTrailing);
927 
928 		aDfltSet.Put( aHyp );
929 
930         sal_uInt16 nNewPos = static_cast< sal_uInt16 >(SW_MOD()->GetUsrPref(sal_False)->GetDefTab());
931 		if( nNewPos )
932 			aDfltSet.Put( SvxTabStopItem( 1, nNewPos,
933                                           SVX_TAB_ADJUST_DEFAULT, RES_PARATR_TABSTOP ) );
934 	}
935     aDfltSet.Put( SvxColorItem( Color( COL_AUTO ), RES_CHRATR_COLOR ) );
936 
937 	pDoc->SetDefault( aDfltSet );
938 
939 	//default page mode for text grid
940 	if(!bWeb)
941 	{
942 		sal_Bool bSquaredPageMode = SW_MOD()->GetUsrPref(sal_False)->IsSquaredPageMode();
943 		pDoc->SetDefaultPageMode( bSquaredPageMode );
944 	}
945 
946 	pDoc->ResetModified();
947 }
948 
949 /*
950  * Document Interface Access
951  */
952 IDocumentDeviceAccess* SwDocShell::getIDocumentDeviceAccess() { return pDoc; }
953 const IDocumentSettingAccess* SwDocShell::getIDocumentSettingAccess() const { return pDoc; }
954 IDocumentChartDataProviderAccess* SwDocShell::getIDocumentChartDataProviderAccess() { return pDoc; }
955