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