LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/ui/app - docshini.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 238 288 82.6 %
Date: 2013-07-09 Functions: 19 24 79.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include <hintids.hxx>
      22             : 
      23             : #include <svx/dialogs.hrc>
      24             : #include <i18nlangtag/mslangid.hxx>
      25             : #include <sot/storinfo.hxx>
      26             : #include <sot/storage.hxx>
      27             : #include <svl/zforlist.hxx>
      28             : #include <svtools/ctrltool.hxx>
      29             : #include <unotools/lingucfg.hxx>
      30             : #include <sfx2/docfile.hxx>
      31             : #include <sfx2/sfxmodelfactory.hxx>
      32             : #include <sfx2/printer.hxx>
      33             : #include <sfx2/bindings.hxx>
      34             : #include <svl/asiancfg.hxx>
      35             : #include <editeng/unolingu.hxx>
      36             : #include <sfx2/request.hxx>
      37             : #include <svl/intitem.hxx>
      38             : #include <editeng/adjustitem.hxx>
      39             : #include <editeng/autokernitem.hxx>
      40             : #include <linguistic/lngprops.hxx>
      41             : #include <com/sun/star/document/UpdateDocMode.hpp>
      42             : #include <com/sun/star/i18n/ScriptType.hpp>
      43             : #include <rtl/logfile.hxx>
      44             : #include <sfx2/docfilt.hxx>
      45             : #include <svx/xtable.hxx>
      46             : #include <svx/drawitem.hxx>
      47             : #include <editeng/fhgtitem.hxx>
      48             : #include <editeng/fontitem.hxx>
      49             : #include <editeng/flstitem.hxx>
      50             : #include <editeng/tstpitem.hxx>
      51             : #include <editeng/langitem.hxx>
      52             : #include <editeng/colritem.hxx>
      53             : #include <editeng/hyphenzoneitem.hxx>
      54             : #include <editeng/svxacorr.hxx>
      55             : #include <vcl/svapp.hxx>
      56             : #include <view.hxx>
      57             : #include <prtopt.hxx>
      58             : #include <fmtcol.hxx>
      59             : #include <docsh.hxx>
      60             : #include <wdocsh.hxx>
      61             : #include <swmodule.hxx>
      62             : #include <doc.hxx>
      63             : #include <docfac.hxx>
      64             : #include <docstyle.hxx>
      65             : #include <shellio.hxx>
      66             : #include <tox.hxx>
      67             : #include <swdtflvr.hxx>
      68             : #include <dbmgr.hxx>
      69             : #include <usrpref.hxx>
      70             : #include <fontcfg.hxx>
      71             : #include <poolfmt.hxx>
      72             : #include <modcfg.hxx>
      73             : #include <globdoc.hxx>
      74             : #include <ndole.hxx>
      75             : #include <mdiexp.hxx>
      76             : #include <unotxdoc.hxx>
      77             : #include <linkenum.hxx>
      78             : #include <swwait.hxx>
      79             : #include <wrtsh.hxx>
      80             : #include <swerror.h>
      81             : #include <globals.hrc>
      82             : #include <unochart.hxx>
      83             : 
      84             : // text grid
      85             : #include <tgrditem.hxx>
      86             : 
      87             : using namespace ::com::sun::star::i18n;
      88             : using namespace ::com::sun::star::lang;
      89             : using namespace ::com::sun::star::uno;
      90             : using namespace ::com::sun::star;
      91             : 
      92             : // Load Document
      93         847 : sal_Bool SwDocShell::InitNew( const uno::Reference < embed::XStorage >& xStor )
      94             : {
      95             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::InitNew" );
      96             : 
      97         847 :     sal_Bool bRet = SfxObjectShell::InitNew( xStor );
      98             :     OSL_ENSURE( GetMapUnit() == MAP_TWIP, "map unit is not twip!" );
      99         847 :     sal_Bool bHTMLTemplSet = sal_False;
     100         847 :     if( bRet )
     101             :     {
     102         846 :         AddLink();      // create pDoc / pIo if applicable
     103             : 
     104         846 :         sal_Bool bWeb = ISA( SwWebDocShell );
     105         846 :         if ( bWeb )
     106           2 :             bHTMLTemplSet = SetHTMLTemplate( *GetDoc() );// Styles from HTML.vor
     107         844 :         else if( ISA( SwGlobalDocShell ) )
     108           0 :             GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT, true);       // Globaldokument
     109             : 
     110             : 
     111         846 :         if ( GetCreateMode() ==  SFX_CREATE_MODE_EMBEDDED )
     112          43 :             SwTransferable::InitOle( this, *pDoc );
     113             : 
     114             :         // set forbidden characters if necessary
     115         846 :         SvxAsianConfig aAsian;
     116        1692 :         Sequence<lang::Locale> aLocales =  aAsian.GetStartEndCharLocales();
     117         846 :         if(aLocales.getLength())
     118             :         {
     119           0 :             const lang::Locale* pLocales = aLocales.getConstArray();
     120           0 :             for(sal_Int32 i = 0; i < aLocales.getLength(); i++)
     121             :             {
     122           0 :                 ForbiddenCharacters aForbidden;
     123           0 :                 aAsian.GetStartEndChars( pLocales[i], aForbidden.beginLine, aForbidden.endLine);
     124           0 :                 LanguageType  eLang = LanguageTag(pLocales[i]).getLanguageType();
     125           0 :                 pDoc->setForbiddenCharacters( eLang, aForbidden);
     126           0 :             }
     127             :         }
     128             :         pDoc->set(IDocumentSettingAccess::KERN_ASIAN_PUNCTUATION,
     129         846 :                   !aAsian.IsKerningWesternTextOnly());
     130         846 :         pDoc->setCharacterCompressionType(static_cast<SwCharCompressType>(aAsian.GetCharDistanceCompression()));
     131         846 :         pDoc->setPrintData(*SW_MOD()->GetPrtOptions(bWeb));
     132             : 
     133         846 :         SubInitNew();
     134             : 
     135             :         // for all
     136             : 
     137         846 :         SwStdFontConfig* pStdFont = SW_MOD()->GetStdFontConfig();
     138         846 :         SfxPrinter* pPrt = pDoc->getPrinter( false );
     139             : 
     140        1692 :         String sEntry;
     141             :         sal_uInt16 aFontWhich[] =
     142             :         {   RES_CHRATR_FONT,
     143             :             RES_CHRATR_CJK_FONT,
     144             :             RES_CHRATR_CTL_FONT
     145         846 :         };
     146             :         sal_uInt16 aFontHeightWhich[] =
     147             :         {
     148             :             RES_CHRATR_FONTSIZE,
     149             :             RES_CHRATR_CJK_FONTSIZE,
     150             :             RES_CHRATR_CTL_FONTSIZE
     151         846 :         };
     152             :         sal_uInt16 aFontIds[] =
     153             :         {
     154             :             FONT_STANDARD,
     155             :             FONT_STANDARD_CJK,
     156             :             FONT_STANDARD_CTL
     157         846 :         };
     158             :         sal_uInt16 nFontTypes[] =
     159             :         {
     160             :             DEFAULTFONT_LATIN_TEXT,
     161             :             DEFAULTFONT_CJK_TEXT,
     162             :             DEFAULTFONT_CTL_TEXT
     163         846 :         };
     164             :         sal_uInt16 aLangTypes[] =
     165             :         {
     166             :             RES_CHRATR_LANGUAGE,
     167             :             RES_CHRATR_CJK_LANGUAGE,
     168             :             RES_CHRATR_CTL_LANGUAGE
     169         846 :         };
     170             : 
     171        3384 :         for(sal_uInt8 i = 0; i < 3; i++)
     172             :         {
     173        2538 :             sal_uInt16 nFontWhich = aFontWhich[i];
     174        2538 :             sal_uInt16 nFontId = aFontIds[i];
     175        2538 :             SvxFontItem* pFontItem = 0;
     176        2538 :             const SvxLanguageItem& rLang = (const SvxLanguageItem&)pDoc->GetDefault( aLangTypes[i] );
     177        2538 :             LanguageType eLanguage = rLang.GetLanguage();
     178        2538 :             if(!pStdFont->IsFontDefault(nFontId))
     179             :             {
     180        1236 :                 sEntry = pStdFont->GetFontFor(nFontId);
     181             : 
     182        1236 :                 Font aFont( sEntry, Size( 0, 10 ) );
     183        1236 :                 if( pPrt )
     184             :                 {
     185           0 :                     aFont = pPrt->GetFontMetric( aFont );
     186             :                 }
     187             : 
     188             :                 pFontItem = new SvxFontItem(aFont.GetFamily(), aFont.GetName(),
     189        1236 :                                             aEmptyStr, aFont.GetPitch(), aFont.GetCharSet(), nFontWhich);
     190             :             }
     191             :             else
     192             :             {
     193             :                 // #107782# OJ use korean language if latin was used
     194        1302 :                 if ( i == 0 )
     195             :                 {
     196         434 :                         LanguageType eUiLanguage = Application::GetSettings().GetUILanguageTag().getLanguageType();
     197         434 :                     if (MsLangId::isKorean(eUiLanguage))
     198           0 :                         eLanguage = eUiLanguage;
     199             :                 }
     200             : 
     201             :                 Font aLangDefFont = OutputDevice::GetDefaultFont(
     202        1302 :                     nFontTypes[i],
     203             :                     eLanguage,
     204        2604 :                     DEFAULTFONT_FLAGS_ONLYONE );
     205             :                 pFontItem = new SvxFontItem(aLangDefFont.GetFamily(), aLangDefFont.GetName(),
     206        1302 :                                     aEmptyStr, aLangDefFont.GetPitch(), aLangDefFont.GetCharSet(), nFontWhich);
     207             :             }
     208        2538 :             pDoc->SetDefault(*pFontItem);
     209        2538 :             if( !bHTMLTemplSet )
     210             :             {
     211        2532 :                 SwTxtFmtColl *pColl = pDoc->GetTxtCollFromPool(RES_POOLCOLL_STANDARD);
     212        2532 :                 pColl->ResetFmtAttr(nFontWhich);
     213             :             }
     214        2538 :             delete pFontItem;
     215        2538 :             sal_Int32 nFontHeight = pStdFont->GetFontHeight( FONT_STANDARD, i, eLanguage );
     216        2538 :             if(nFontHeight <= 0)
     217           0 :                 nFontHeight = pStdFont->GetDefaultHeightFor( nFontId, eLanguage );
     218        2538 :             pDoc->SetDefault(SvxFontHeightItem( nFontHeight, 100, aFontHeightWhich[i] ));
     219        2538 :             if( !bHTMLTemplSet )
     220             :             {
     221        2532 :                 SwTxtFmtColl *pColl = pDoc->GetTxtCollFromPool(RES_POOLCOLL_STANDARD);
     222        2532 :                 pColl->ResetFmtAttr(aFontHeightWhich[i]);
     223             :             }
     224             : 
     225             :         }
     226             :         sal_uInt16 aFontIdPoolId[] =
     227             :         {
     228             :             FONT_OUTLINE,       RES_POOLCOLL_HEADLINE_BASE,
     229             :             FONT_LIST,          RES_POOLCOLL_NUMBUL_BASE,
     230             :             FONT_CAPTION,       RES_POOLCOLL_LABEL,
     231             :             FONT_INDEX,         RES_POOLCOLL_REGISTER_BASE,
     232             :             FONT_OUTLINE_CJK,   RES_POOLCOLL_HEADLINE_BASE,
     233             :             FONT_LIST_CJK,      RES_POOLCOLL_NUMBUL_BASE,
     234             :             FONT_CAPTION_CJK,   RES_POOLCOLL_LABEL,
     235             :             FONT_INDEX_CJK,     RES_POOLCOLL_REGISTER_BASE,
     236             :             FONT_OUTLINE_CTL,   RES_POOLCOLL_HEADLINE_BASE,
     237             :             FONT_LIST_CTL,      RES_POOLCOLL_NUMBUL_BASE,
     238             :             FONT_CAPTION_CTL,   RES_POOLCOLL_LABEL,
     239             :             FONT_INDEX_CTL,     RES_POOLCOLL_REGISTER_BASE
     240         846 :         };
     241             : 
     242         846 :         sal_uInt16 nFontWhich = RES_CHRATR_FONT;
     243         846 :         sal_uInt16 nFontHeightWhich = RES_CHRATR_FONTSIZE;
     244         846 :         LanguageType eLanguage = static_cast<const SvxLanguageItem&>(pDoc->GetDefault( RES_CHRATR_LANGUAGE )).GetLanguage();
     245       10998 :         for(sal_uInt8 nIdx = 0; nIdx < 24; nIdx += 2)
     246             :         {
     247       10152 :             if(nIdx == 8)
     248             :             {
     249         846 :                 nFontWhich = RES_CHRATR_CJK_FONT;
     250         846 :                 nFontHeightWhich = RES_CHRATR_CJK_FONTSIZE;
     251         846 :                 eLanguage = static_cast<const SvxLanguageItem&>(pDoc->GetDefault( RES_CHRATR_CJK_LANGUAGE )).GetLanguage();
     252             :             }
     253        9306 :             else if(nIdx == 16)
     254             :             {
     255         846 :                 nFontWhich = RES_CHRATR_CTL_FONT;
     256         846 :                 nFontHeightWhich = RES_CHRATR_CTL_FONTSIZE;
     257         846 :                 eLanguage = static_cast<const SvxLanguageItem&>(pDoc->GetDefault( RES_CHRATR_CTL_LANGUAGE )).GetLanguage();
     258             :             }
     259       10152 :             SwTxtFmtColl *pColl = 0;
     260       10152 :             if(!pStdFont->IsFontDefault(aFontIdPoolId[nIdx]))
     261             :             {
     262        6246 :                 sEntry = pStdFont->GetFontFor(aFontIdPoolId[nIdx]);
     263             : 
     264        6246 :                 Font aFont( sEntry, Size( 0, 10 ) );
     265        6246 :                 if( pPrt )
     266           0 :                     aFont = pPrt->GetFontMetric( aFont );
     267             : 
     268        6246 :                 pColl = pDoc->GetTxtCollFromPool(aFontIdPoolId[nIdx + 1]);
     269        6252 :                 if( !bHTMLTemplSet ||
     270           6 :                     SFX_ITEM_SET != pColl->GetAttrSet().GetItemState(
     271          12 :                                                     nFontWhich, sal_False ) )
     272             :                 {
     273        6240 :                     pColl->SetFmtAttr(SvxFontItem(aFont.GetFamily(), aFont.GetName(),
     274       12480 :                                                   aEmptyStr, aFont.GetPitch(), aFont.GetCharSet(), nFontWhich));
     275        6246 :                 }
     276             :             }
     277       10152 :             sal_Int32 nFontHeight = pStdFont->GetFontHeight( static_cast< sal_Int8 >(aFontIdPoolId[nIdx]), 0, eLanguage );
     278       10152 :             if(nFontHeight <= 0)
     279           0 :                 nFontHeight = pStdFont->GetDefaultHeightFor( aFontIdPoolId[nIdx], eLanguage );
     280       10152 :             if(!pColl)
     281        3906 :                 pColl = pDoc->GetTxtCollFromPool(aFontIdPoolId[nIdx + 1]);
     282       10152 :             SvxFontHeightItem aFontHeight( (const SvxFontHeightItem&)pColl->GetFmtAttr( nFontHeightWhich, sal_True ));
     283       10152 :             if(aFontHeight.GetHeight() != sal::static_int_cast<sal_uInt32, sal_Int32>(nFontHeight))
     284             :             {
     285        4224 :                 aFontHeight.SetHeight(nFontHeight);
     286        4224 :                 pColl->SetFmtAttr( aFontHeight );
     287             :             }
     288       10152 :         }
     289             : 
     290             :         // the default for documents created via 'File/New' should be 'on'
     291             :         // (old documents, where this property was not yet implemented, will get the
     292             :         // value 'false' in the SwDoc c-tor)
     293             :         pDoc->set( IDocumentSettingAccess::MATH_BASELINE_ALIGNMENT,
     294        1692 :                 SW_MOD()->GetUsrPref( bWeb )->IsAlignMathObjectsToBaseline() );
     295             :     }
     296             : 
     297             :     /* #106748# If the default frame direction of a document is RTL
     298             :         the default adjusment is to the right. */
     299        1692 :     if( !bHTMLTemplSet &&
     300         845 :         FRMDIR_HORI_RIGHT_TOP == GetDefaultFrameDirection(GetAppLanguage()) )
     301           0 :         pDoc->SetDefault( SvxAdjustItem(SVX_ADJUST_RIGHT, RES_PARATR_ADJUST ) );
     302             : 
     303             : // #i29550#
     304         847 :     pDoc->SetDefault( SfxBoolItem( RES_COLLAPSING_BORDERS, sal_True ) );
     305             : // <-- collapsing
     306             : 
     307             :     //#i16874# AutoKerning as default for new documents
     308         847 :     pDoc->SetDefault( SvxAutoKernItem( sal_True, RES_CHRATR_AUTOKERN ) );
     309             : 
     310             :     // #i42080# - Due to the several calls of method <SetDefault(..)>
     311             :     // at the document instance, the document is modified. Thus, reset this
     312             :     // status here. Note: In method <SubInitNew()> this is also done.
     313         847 :     pDoc->ResetModified();
     314             : 
     315         847 :     return bRet;
     316             : }
     317             : 
     318             : // Ctor with SfxCreateMode ?????
     319          97 : SwDocShell::SwDocShell( SfxObjectCreateMode eMode ) :
     320             :     SfxObjectShell ( eMode ),
     321             :     pDoc(0),
     322             :     pFontList(0),
     323             :     pView( 0 ),
     324             :     pWrtShell( 0 ),
     325             :     pOLEChildList( 0 ),
     326             :     nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG),
     327          97 :     bInUpdateFontList(false)
     328             : {
     329             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::SwDocShell" );
     330          97 :     Init_Impl();
     331          97 : }
     332             : 
     333             : // Ctor / Dtor
     334         793 : SwDocShell::SwDocShell( const sal_uInt64 i_nSfxCreationFlags ) :
     335             :     SfxObjectShell ( i_nSfxCreationFlags ),
     336             :     pDoc(0),
     337             :     pFontList(0),
     338             :     pView( 0 ),
     339             :     pWrtShell( 0 ),
     340             :     pOLEChildList( 0 ),
     341             :     nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG),
     342         793 :     bInUpdateFontList(false)
     343             : {
     344             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::SwDocShell" );
     345         793 :     Init_Impl();
     346         793 : }
     347             : 
     348             : // Ctor / Dtor
     349          12 : SwDocShell::SwDocShell( SwDoc *pD, SfxObjectCreateMode eMode ):
     350             :     SfxObjectShell ( eMode ),
     351             :     pDoc(pD),
     352             :     pFontList(0),
     353             :     pView( 0 ),
     354             :     pWrtShell( 0 ),
     355             :     pOLEChildList( 0 ),
     356             :     nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG),
     357          12 :     bInUpdateFontList(false)
     358             : {
     359             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::SwDocShell" );
     360          12 :     Init_Impl();
     361          12 : }
     362             : 
     363             : // Dtor
     364        3542 : SwDocShell::~SwDocShell()
     365             : {
     366             :     // disable chart related objects now because in ~SwDoc it may be to late for this
     367         887 :     if( pDoc )
     368             :     {
     369         884 :         pDoc->GetChartControllerHelper().Disconnect();
     370         884 :         SwChartDataProvider *pPCD = pDoc->GetChartDataProvider();
     371         884 :         if (pPCD)
     372           0 :             pPCD->dispose();
     373             :     }
     374             : 
     375         887 :     RemoveLink();
     376         887 :     delete pFontList;
     377             : 
     378             :     // we, as BroadCaster also become our own Listener
     379             :     // (for DocInfo/FileNames/....)
     380         887 :     EndListening( *this );
     381             : 
     382         887 :     delete pOLEChildList;
     383        2655 : }
     384             : 
     385         902 : void  SwDocShell::Init_Impl()
     386             : {
     387         902 :     SetPool(&SW_MOD()->GetPool());
     388         902 :     SetBaseModel(new SwXTextDocument(this));
     389             :     // we, as BroadCaster also become our own Listener
     390             :     // (for DocInfo/FileNames/....)
     391         902 :     StartListening( *this );
     392             :     //position of the "Automatic" style filter for the stylist (app.src)
     393         902 :     SetAutoStyleFilterIndex(3);
     394             : 
     395             :     // set map unit to twip
     396         902 :     SetMapUnit( MAP_TWIP );
     397         902 : }
     398             : 
     399             : // AddLink
     400         897 : void SwDocShell::AddLink()
     401             : {
     402         897 :     if( !pDoc )
     403             :     {
     404         886 :         SwDocFac aFactory;
     405         886 :         pDoc = aFactory.GetDoc();
     406         886 :         pDoc->acquire();
     407         886 :         pDoc->set(IDocumentSettingAccess::HTML_MODE, ISA(SwWebDocShell) );
     408             :     }
     409             :     else
     410          11 :         pDoc->acquire();
     411         897 :     pDoc->SetDocShell( this );      // set the DocShell-Pointer for Doc
     412         897 :     uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), uno::UNO_QUERY);
     413         897 :     ((SwXTextDocument*)xDoc.get())->Reactivate(this);
     414             : 
     415         897 :     SetPool(&pDoc->GetAttrPool());
     416             : 
     417             :     // most suitably not until a sdbcx::View is created!!!
     418         897 :     pDoc->SetOle2Link(LINK(this, SwDocShell, Ole2ModifiedHdl));
     419         897 : }
     420             : 
     421             : // create new FontList Change Printer
     422         962 : void SwDocShell::UpdateFontList()
     423             : {
     424         962 :     if(!bInUpdateFontList)
     425             :     {
     426         959 :         bInUpdateFontList = true;
     427             :         OSL_ENSURE(pDoc, "No Doc no FontList");
     428         959 :         if( pDoc )
     429             :         {
     430         959 :             delete pFontList;
     431         959 :             pFontList = new FontList( pDoc->getReferenceDevice( true ) );
     432         959 :             PutItem( SvxFontListItem( pFontList, SID_ATTR_CHAR_FONTLIST ) );
     433             :         }
     434         959 :         bInUpdateFontList = false;
     435             :     }
     436         962 : }
     437             : 
     438             : // RemoveLink
     439         887 : void SwDocShell::RemoveLink()
     440             : {
     441             :     // disconnect Uno-Object
     442         887 :     uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), uno::UNO_QUERY);
     443         887 :     ((SwXTextDocument*)xDoc.get())->Invalidate();
     444         887 :     aFinishedTimer.Stop();
     445         887 :     if(pDoc)
     446             :     {
     447         884 :         if( mxBasePool.is() )
     448             :         {
     449         884 :             static_cast<SwDocStyleSheetPool*>(mxBasePool.get())->dispose();
     450         884 :             mxBasePool.clear();
     451             :         }
     452         884 :         sal_Int8 nRefCt = static_cast< sal_Int8 >(pDoc->release());
     453         884 :         pDoc->SetOle2Link(Link());
     454         884 :         pDoc->SetDocShell( 0 );
     455         884 :         if( !nRefCt )
     456         825 :             delete pDoc;
     457         884 :         pDoc = 0;       // we don't have the Doc anymore!!
     458         887 :     }
     459         887 : }
     460          11 : void SwDocShell::InvalidateModel()
     461             : {
     462             :     // disconnect Uno-Object
     463          11 :     uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), uno::UNO_QUERY);
     464          11 :     ((SwXTextDocument*)xDoc.get())->Invalidate();
     465          11 : }
     466          11 : void SwDocShell::ReactivateModel()
     467             : {
     468             :     // disconnect Uno-Object
     469          11 :     uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), uno::UNO_QUERY);
     470          11 :     ((SwXTextDocument*)xDoc.get())->Reactivate(this);
     471          11 : }
     472             : 
     473             : // Load, Default-Format
     474          51 : sal_Bool  SwDocShell::Load( SfxMedium& rMedium )
     475             : {
     476             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::Load" );
     477          51 :     sal_Bool bRet = sal_False;
     478          51 :     if( SfxObjectShell::Load( rMedium ))
     479             :     {
     480             :         RTL_LOGFILE_CONTEXT_TRACE( aLog, "after SfxInPlaceObject::Load" );
     481          51 :         if( pDoc )              // for last version!!
     482           0 :             RemoveLink();       // release the existing
     483             : 
     484          51 :         AddLink();      // set Link and update Data!!
     485             : 
     486             :         // Loading
     487             :         // for MD
     488             :         OSL_ENSURE( !mxBasePool.is(), "who hasn't destroyed their Pool?" );
     489          51 :         mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
     490          51 :         if(GetCreateMode() != SFX_CREATE_MODE_ORGANIZER)
     491             :         {
     492          51 :             SFX_ITEMSET_ARG( rMedium.GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, sal_False);
     493          51 :             nUpdateDocMode = pUpdateDocItem ? pUpdateDocItem->GetValue() : document::UpdateDocMode::NO_UPDATE;
     494             :         }
     495             : 
     496          51 :         SwWait aWait( *this, sal_True );
     497          51 :         sal_uInt32 nErr = ERR_SWG_READ_ERROR;
     498          51 :         switch( GetCreateMode() )
     499             :         {
     500             :             case SFX_CREATE_MODE_ORGANIZER:
     501             :                 {
     502           0 :                     if( ReadXML )
     503             :                     {
     504           0 :                         ReadXML->SetOrganizerMode( sal_True );
     505           0 :                         SwReader aRdr( rMedium, aEmptyStr, pDoc );
     506           0 :                         nErr = aRdr.Read( *ReadXML );
     507           0 :                         ReadXML->SetOrganizerMode( sal_False );
     508             :                     }
     509             :                 }
     510           0 :                 break;
     511             : 
     512             :             case SFX_CREATE_MODE_INTERNAL:
     513             :             case SFX_CREATE_MODE_EMBEDDED:
     514             :                 {
     515             :                     // for MWERKS (Mac-Compiler): can't cast autonomously
     516           1 :                     SwTransferable::InitOle( this, *pDoc );
     517             :                 }
     518             :                 // suppress SfxProgress, when we are Embedded
     519           1 :                 SW_MOD()->SetEmbeddedLoadSave( sal_True );
     520             :                 // no break;
     521             : 
     522             :             case SFX_CREATE_MODE_STANDARD:
     523             :             case SFX_CREATE_MODE_PREVIEW:
     524             :                 {
     525          51 :                     Reader *pReader = ReadXML;
     526          51 :                     if( pReader )
     527             :                     {
     528             :                         // set Doc's DocInfo at DocShell-Medium
     529             :                         RTL_LOGFILE_CONTEXT_TRACE( aLog, "before ReadDocInfo" );
     530          51 :                         SwReader aRdr( rMedium, aEmptyStr, pDoc );
     531             :                         RTL_LOGFILE_CONTEXT_TRACE( aLog, "before Read" );
     532          51 :                         nErr = aRdr.Read( *pReader );
     533             :                         RTL_LOGFILE_CONTEXT_TRACE( aLog, "after Read" );
     534             : 
     535             :                         // If a XML document is loaded, the global doc/web doc
     536             :                         // flags have to be set, because they aren't loaded
     537             :                         // by this formats.
     538          51 :                         if( ISA( SwWebDocShell ) )
     539             :                         {
     540           0 :                             if( !pDoc->get(IDocumentSettingAccess::HTML_MODE) )
     541           0 :                                 pDoc->set(IDocumentSettingAccess::HTML_MODE, true);
     542             :                         }
     543          51 :                         if( ISA( SwGlobalDocShell ) )
     544             :                         {
     545           0 :                             if( !pDoc->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) )
     546           0 :                                 pDoc->set(IDocumentSettingAccess::GLOBAL_DOCUMENT, true);
     547          51 :                         }
     548             :                     }
     549             :                 }
     550          51 :                 break;
     551             : 
     552             :             default:
     553             :                 OSL_ENSURE( !this, "Load: new CreateMode?" );
     554             :         }
     555             : 
     556          51 :         UpdateFontList();
     557          51 :         InitDraw();
     558             : 
     559          51 :         SetError( nErr, OUString( OSL_LOG_PREFIX ) );
     560          51 :         bRet = !IsError( nErr );
     561             : 
     562         102 :         if ( bRet && !pDoc->IsInLoadAsynchron() &&
     563          51 :              GetCreateMode() == SFX_CREATE_MODE_STANDARD )
     564             :         {
     565          50 :             LoadingFinished();
     566             :         }
     567             : 
     568             :         // suppress SfxProgress, when we are Embedded
     569          51 :         SW_MOD()->SetEmbeddedLoadSave( sal_False );
     570             :     }
     571             : 
     572          51 :     return bRet;
     573             : }
     574             : 
     575           0 : sal_Bool  SwDocShell::LoadFrom( SfxMedium& rMedium )
     576             : {
     577             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::LoadFrom" );
     578           0 :     sal_Bool bRet = sal_False;
     579           0 :     if( pDoc )
     580           0 :         RemoveLink();
     581             : 
     582           0 :     AddLink();      // set Link and update Data!!
     583             : 
     584             :     do {        // middle check loop
     585           0 :         sal_uInt32 nErr = ERR_SWG_READ_ERROR;
     586           0 :         String aStreamName;
     587           0 :         aStreamName = OUString("styles.xml");
     588           0 :         uno::Reference < container::XNameAccess > xAccess( rMedium.GetStorage(), uno::UNO_QUERY );
     589           0 :         if ( xAccess->hasByName( aStreamName ) && rMedium.GetStorage()->isStreamElement( aStreamName ) )
     590             :         {
     591             :             // Loading
     592           0 :             SwWait aWait( *this, sal_True );
     593             :             {
     594             :                 OSL_ENSURE( !mxBasePool.is(), "who hasn't destroyed their Pool?" );
     595           0 :                 mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
     596           0 :                 if( ReadXML )
     597             :                 {
     598           0 :                     ReadXML->SetOrganizerMode( sal_True );
     599           0 :                     SwReader aRdr( rMedium, aEmptyStr, pDoc );
     600           0 :                     nErr = aRdr.Read( *ReadXML );
     601           0 :                     ReadXML->SetOrganizerMode( sal_False );
     602             :                 }
     603           0 :             }
     604             :         }
     605             :         else
     606             :         {
     607             :             OSL_FAIL("Code removed!");
     608             :         }
     609             : 
     610           0 :         SetError( nErr, OUString( OSL_LOG_PREFIX ) );
     611           0 :         bRet = !IsError( nErr );
     612             : 
     613             :     } while( false );
     614             : 
     615           0 :     SfxObjectShell::LoadFrom( rMedium );
     616           0 :     pDoc->ResetModified();
     617           0 :     return bRet;
     618             : }
     619             : 
     620             : 
     621         846 : void SwDocShell::SubInitNew()
     622             : {
     623             :     OSL_ENSURE( !mxBasePool.is(), "who hasn't destroyed their Pool?" );
     624         846 :     mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
     625         846 :     UpdateFontList();
     626         846 :     InitDraw();
     627             : 
     628         846 :     pDoc->setLinkUpdateMode( GLOBALSETTING );
     629         846 :     pDoc->setFieldUpdateFlags( AUTOUPD_GLOBALSETTING );
     630             : 
     631         846 :     sal_Bool bWeb = ISA(SwWebDocShell);
     632             : 
     633             :     sal_uInt16 nRange[] =   {
     634             :         RES_PARATR_ADJUST, RES_PARATR_ADJUST,
     635             :         RES_CHRATR_COLOR, RES_CHRATR_COLOR,
     636             :         RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE,
     637             :         RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE,
     638             :         RES_CHRATR_CTL_LANGUAGE, RES_CHRATR_CTL_LANGUAGE,
     639         846 :         0, 0, 0  };
     640         846 :     if(!bWeb)
     641             :     {
     642         844 :         nRange[ (sizeof(nRange)/sizeof(nRange[0])) - 3 ] = RES_PARATR_TABSTOP;
     643         844 :         nRange[ (sizeof(nRange)/sizeof(nRange[0])) - 2 ] = RES_PARATR_HYPHENZONE;
     644             :     }
     645         846 :     SfxItemSet aDfltSet( pDoc->GetAttrPool(), nRange );
     646             : 
     647             :     //! get lingu options without loading lingu DLL
     648        1692 :     SvtLinguOptions aLinguOpt;
     649             : 
     650         846 :     SvtLinguConfig().GetOptions( aLinguOpt );
     651             : 
     652         846 :     sal_Int16   nVal = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN),
     653         846 :                 eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN),
     654         846 :                 eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX);
     655         846 :     aDfltSet.Put( SvxLanguageItem( nVal, RES_CHRATR_LANGUAGE ) );
     656         846 :     aDfltSet.Put( SvxLanguageItem( eCJK, RES_CHRATR_CJK_LANGUAGE ) );
     657         846 :     aDfltSet.Put( SvxLanguageItem( eCTL, RES_CHRATR_CTL_LANGUAGE ) );
     658             : 
     659         846 :     if(!bWeb)
     660             :     {
     661             :         SvxHyphenZoneItem aHyp( (SvxHyphenZoneItem&) pDoc->GetDefault(
     662         844 :                                                         RES_PARATR_HYPHENZONE) );
     663         844 :         aHyp.GetMinLead()   = static_cast< sal_uInt8 >(aLinguOpt.nHyphMinLeading);
     664         844 :         aHyp.GetMinTrail()  = static_cast< sal_uInt8 >(aLinguOpt.nHyphMinTrailing);
     665             : 
     666         844 :         aDfltSet.Put( aHyp );
     667             : 
     668         844 :         sal_uInt16 nNewPos = static_cast< sal_uInt16 >(SW_MOD()->GetUsrPref(sal_False)->GetDefTab());
     669         844 :         if( nNewPos )
     670             :             aDfltSet.Put( SvxTabStopItem( 1, nNewPos,
     671         844 :                                           SVX_TAB_ADJUST_DEFAULT, RES_PARATR_TABSTOP ) );
     672             :     }
     673         846 :     aDfltSet.Put( SvxColorItem( Color( COL_AUTO ), RES_CHRATR_COLOR ) );
     674             : 
     675         846 :     pDoc->SetDefault( aDfltSet );
     676             : 
     677             :     //default page mode for text grid
     678         846 :     if(!bWeb)
     679             :     {
     680         844 :         sal_Bool bSquaredPageMode = SW_MOD()->GetUsrPref(sal_False)->IsSquaredPageMode();
     681         844 :         pDoc->SetDefaultPageMode( bSquaredPageMode );
     682             :     }
     683             : 
     684        1692 :     pDoc->ResetModified();
     685         846 : }
     686             : 
     687             : /*
     688             :  * Document Interface Access
     689             :  */
     690           0 : IDocumentDeviceAccess* SwDocShell::getIDocumentDeviceAccess() { return pDoc; }
     691        1000 : const IDocumentSettingAccess* SwDocShell::getIDocumentSettingAccess() const { return pDoc; }
     692          99 : IDocumentChartDataProviderAccess* SwDocShell::getIDocumentChartDataProviderAccess() { return pDoc; }
     693             : 
     694             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10