LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/app - docshini.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 228 290 78.6 %
Date: 2012-12-17 Functions: 13 22 59.1 %
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 <i18npool/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/adjitem.hxx>
      39             : #include <editeng/akrnitem.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/hyznitem.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             : 
      83             : // #i18732#
      84             : #include <fmtfollowtextflow.hxx>
      85             : 
      86             : #include <unochart.hxx>
      87             : 
      88             : // text grid
      89             : #include <tgrditem.hxx>
      90             : 
      91             : using namespace ::com::sun::star::i18n;
      92             : using namespace ::com::sun::star::lang;
      93             : using namespace ::com::sun::star::uno;
      94             : using namespace ::com::sun::star;
      95             : using ::rtl::OUString;
      96             : 
      97             : 
      98             : 
      99             : /*--------------------------------------------------------------------
     100             :     Description: Load Document
     101             :  --------------------------------------------------------------------*/
     102             : 
     103             : 
     104         521 : sal_Bool SwDocShell::InitNew( const uno::Reference < embed::XStorage >& xStor )
     105             : {
     106             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::InitNew" );
     107             : 
     108         521 :     sal_Bool bRet = SfxObjectShell::InitNew( xStor );
     109             :     OSL_ENSURE( GetMapUnit() == MAP_TWIP, "map unit is not twip!" );
     110         521 :     sal_Bool bHTMLTemplSet = sal_False;
     111         521 :     if( bRet )
     112             :     {
     113         519 :         AddLink();      // create pDoc / pIo if applicable
     114             : 
     115         519 :         sal_Bool bWeb = ISA( SwWebDocShell );
     116         519 :         if ( bWeb )
     117           0 :             bHTMLTemplSet = SetHTMLTemplate( *GetDoc() );// Styles from HTML.vor
     118         519 :         else if( ISA( SwGlobalDocShell ) )
     119           0 :             GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT, true);       // Globaldokument
     120             : 
     121             : 
     122         519 :         if ( GetCreateMode() ==  SFX_CREATE_MODE_EMBEDDED )
     123          74 :             SwTransferable::InitOle( this, *pDoc );
     124             : 
     125             :         // set forbidden characters if necessary
     126         519 :         SvxAsianConfig aAsian;
     127         519 :         Sequence<lang::Locale> aLocales =  aAsian.GetStartEndCharLocales();
     128         519 :         if(aLocales.getLength())
     129             :         {
     130           0 :             const lang::Locale* pLocales = aLocales.getConstArray();
     131           0 :             for(sal_Int32 i = 0; i < aLocales.getLength(); i++)
     132             :             {
     133           0 :                 ForbiddenCharacters aForbidden;
     134           0 :                 aAsian.GetStartEndChars( pLocales[i], aForbidden.beginLine, aForbidden.endLine);
     135           0 :                 LanguageType  eLang = LanguageTag(pLocales[i]).getLanguageType();
     136           0 :                 pDoc->setForbiddenCharacters( eLang, aForbidden);
     137           0 :             }
     138             :         }
     139             :         pDoc->set(IDocumentSettingAccess::KERN_ASIAN_PUNCTUATION,
     140         519 :                   !aAsian.IsKerningWesternTextOnly());
     141         519 :         pDoc->setCharacterCompressionType(static_cast<SwCharCompressType>(aAsian.GetCharDistanceCompression()));
     142         519 :         pDoc->setPrintData(*SW_MOD()->GetPrtOptions(bWeb));
     143             : 
     144         519 :         SubInitNew();
     145             : 
     146             :         // for all
     147             : 
     148         519 :         SwStdFontConfig* pStdFont = SW_MOD()->GetStdFontConfig();
     149         519 :         SfxPrinter* pPrt = pDoc->getPrinter( false );
     150             : 
     151         519 :         String sEntry;
     152             :         sal_uInt16 aFontWhich[] =
     153             :         {   RES_CHRATR_FONT,
     154             :             RES_CHRATR_CJK_FONT,
     155             :             RES_CHRATR_CTL_FONT
     156         519 :         };
     157             :         sal_uInt16 aFontHeightWhich[] =
     158             :         {
     159             :             RES_CHRATR_FONTSIZE,
     160             :             RES_CHRATR_CJK_FONTSIZE,
     161             :             RES_CHRATR_CTL_FONTSIZE
     162         519 :         };
     163             :         sal_uInt16 aFontIds[] =
     164             :         {
     165             :             FONT_STANDARD,
     166             :             FONT_STANDARD_CJK,
     167             :             FONT_STANDARD_CTL
     168         519 :         };
     169             :         sal_uInt16 nFontTypes[] =
     170             :         {
     171             :             DEFAULTFONT_LATIN_TEXT,
     172             :             DEFAULTFONT_CJK_TEXT,
     173             :             DEFAULTFONT_CTL_TEXT
     174         519 :         };
     175             :         sal_uInt16 aLangTypes[] =
     176             :         {
     177             :             RES_CHRATR_LANGUAGE,
     178             :             RES_CHRATR_CJK_LANGUAGE,
     179             :             RES_CHRATR_CTL_LANGUAGE
     180         519 :         };
     181             : 
     182        2076 :         for(sal_uInt8 i = 0; i < 3; i++)
     183             :         {
     184        1557 :             sal_uInt16 nFontWhich = aFontWhich[i];
     185        1557 :             sal_uInt16 nFontId = aFontIds[i];
     186        1557 :             SvxFontItem* pFontItem = 0;
     187        1557 :             const SvxLanguageItem& rLang = (const SvxLanguageItem&)pDoc->GetDefault( aLangTypes[i] );
     188        1557 :             LanguageType eLanguage = rLang.GetLanguage();
     189        1557 :             if(!pStdFont->IsFontDefault(nFontId))
     190             :             {
     191        1554 :                 sEntry = pStdFont->GetFontFor(nFontId);
     192             : 
     193        1554 :                 Font aFont( sEntry, Size( 0, 10 ) );
     194        1554 :                 if( pPrt )
     195             :                 {
     196           0 :                     aFont = pPrt->GetFontMetric( aFont );
     197             :                 }
     198             : 
     199             :                 pFontItem = new SvxFontItem(aFont.GetFamily(), aFont.GetName(),
     200        1554 :                                             aEmptyStr, aFont.GetPitch(), aFont.GetCharSet(), nFontWhich);
     201             :             }
     202             :             else
     203             :             {
     204             :                 // #107782# OJ use korean language if latin was used
     205           3 :                 if ( i == 0 )
     206             :                 {
     207           1 :                         LanguageType eUiLanguage = Application::GetSettings().GetUILanguageTag().getLanguageType();
     208           1 :                     if (MsLangId::isKorean(eUiLanguage))
     209           0 :                         eLanguage = eUiLanguage;
     210             :                 }
     211             : 
     212             :                 Font aLangDefFont = OutputDevice::GetDefaultFont(
     213           3 :                     nFontTypes[i],
     214             :                     eLanguage,
     215           6 :                     DEFAULTFONT_FLAGS_ONLYONE );
     216             :                 pFontItem = new SvxFontItem(aLangDefFont.GetFamily(), aLangDefFont.GetName(),
     217           3 :                                     aEmptyStr, aLangDefFont.GetPitch(), aLangDefFont.GetCharSet(), nFontWhich);
     218             :             }
     219        1557 :             pDoc->SetDefault(*pFontItem);
     220        1557 :             if( !bHTMLTemplSet )
     221             :             {
     222        1557 :                 SwTxtFmtColl *pColl = pDoc->GetTxtCollFromPool(RES_POOLCOLL_STANDARD);
     223        1557 :                 pColl->ResetFmtAttr(nFontWhich);
     224             :             }
     225        1557 :             delete pFontItem;
     226        1557 :             sal_Int32 nFontHeight = pStdFont->GetFontHeight( FONT_STANDARD, i, eLanguage );
     227        1557 :             if(nFontHeight <= 0)
     228           0 :                 nFontHeight = pStdFont->GetDefaultHeightFor( nFontId, eLanguage );
     229        1557 :             pDoc->SetDefault(SvxFontHeightItem( nFontHeight, 100, aFontHeightWhich[i] ));
     230        1557 :             if( !bHTMLTemplSet )
     231             :             {
     232        1557 :                 SwTxtFmtColl *pColl = pDoc->GetTxtCollFromPool(RES_POOLCOLL_STANDARD);
     233        1557 :                 pColl->ResetFmtAttr(aFontHeightWhich[i]);
     234             :             }
     235             : 
     236             :         }
     237             :         sal_uInt16 aFontIdPoolId[] =
     238             :         {
     239             :             FONT_OUTLINE,       RES_POOLCOLL_HEADLINE_BASE,
     240             :             FONT_LIST,          RES_POOLCOLL_NUMBUL_BASE,
     241             :             FONT_CAPTION,       RES_POOLCOLL_LABEL,
     242             :             FONT_INDEX,         RES_POOLCOLL_REGISTER_BASE,
     243             :             FONT_OUTLINE_CJK,   RES_POOLCOLL_HEADLINE_BASE,
     244             :             FONT_LIST_CJK,      RES_POOLCOLL_NUMBUL_BASE,
     245             :             FONT_CAPTION_CJK,   RES_POOLCOLL_LABEL,
     246             :             FONT_INDEX_CJK,     RES_POOLCOLL_REGISTER_BASE,
     247             :             FONT_OUTLINE_CTL,   RES_POOLCOLL_HEADLINE_BASE,
     248             :             FONT_LIST_CTL,      RES_POOLCOLL_NUMBUL_BASE,
     249             :             FONT_CAPTION_CTL,   RES_POOLCOLL_LABEL,
     250             :             FONT_INDEX_CTL,     RES_POOLCOLL_REGISTER_BASE
     251         519 :         };
     252             : 
     253         519 :         sal_uInt16 nFontWhich = RES_CHRATR_FONT;
     254         519 :         sal_uInt16 nFontHeightWhich = RES_CHRATR_FONTSIZE;
     255         519 :         LanguageType eLanguage = static_cast<const SvxLanguageItem&>(pDoc->GetDefault( RES_CHRATR_LANGUAGE )).GetLanguage();
     256        6747 :         for(sal_uInt8 nIdx = 0; nIdx < 24; nIdx += 2)
     257             :         {
     258        6228 :             if(nIdx == 8)
     259             :             {
     260         519 :                 nFontWhich = RES_CHRATR_CJK_FONT;
     261         519 :                 nFontHeightWhich = RES_CHRATR_CJK_FONTSIZE;
     262         519 :                 eLanguage = static_cast<const SvxLanguageItem&>(pDoc->GetDefault( RES_CHRATR_CJK_LANGUAGE )).GetLanguage();
     263             :             }
     264        5709 :             else if(nIdx == 16)
     265             :             {
     266         519 :                 nFontWhich = RES_CHRATR_CTL_FONT;
     267         519 :                 nFontHeightWhich = RES_CHRATR_CTL_FONTSIZE;
     268         519 :                 eLanguage = static_cast<const SvxLanguageItem&>(pDoc->GetDefault( RES_CHRATR_CTL_LANGUAGE )).GetLanguage();
     269             :             }
     270        6228 :             SwTxtFmtColl *pColl = 0;
     271        6228 :             if(!pStdFont->IsFontDefault(aFontIdPoolId[nIdx]))
     272             :             {
     273        6219 :                 sEntry = pStdFont->GetFontFor(aFontIdPoolId[nIdx]);
     274             : 
     275        6219 :                 Font aFont( sEntry, Size( 0, 10 ) );
     276        6219 :                 if( pPrt )
     277           0 :                     aFont = pPrt->GetFontMetric( aFont );
     278             : 
     279        6219 :                 pColl = pDoc->GetTxtCollFromPool(aFontIdPoolId[nIdx + 1]);
     280        6219 :                 if( !bHTMLTemplSet ||
     281           0 :                     SFX_ITEM_SET != pColl->GetAttrSet().GetItemState(
     282           0 :                                                     nFontWhich, sal_False ) )
     283             :                 {
     284        6219 :                     pColl->SetFmtAttr(SvxFontItem(aFont.GetFamily(), aFont.GetName(),
     285       12438 :                                                   aEmptyStr, aFont.GetPitch(), aFont.GetCharSet(), nFontWhich));
     286        6219 :                 }
     287             :             }
     288        6228 :             sal_Int32 nFontHeight = pStdFont->GetFontHeight( static_cast< sal_Int8 >(aFontIdPoolId[nIdx]), 0, eLanguage );
     289        6228 :             if(nFontHeight <= 0)
     290           0 :                 nFontHeight = pStdFont->GetDefaultHeightFor( aFontIdPoolId[nIdx], eLanguage );
     291        6228 :             if(!pColl)
     292           9 :                 pColl = pDoc->GetTxtCollFromPool(aFontIdPoolId[nIdx + 1]);
     293        6228 :             SvxFontHeightItem aFontHeight( (const SvxFontHeightItem&)pColl->GetFmtAttr( nFontHeightWhich, sal_True ));
     294        6228 :             if(aFontHeight.GetHeight() != sal::static_int_cast<sal_uInt32, sal_Int32>(nFontHeight))
     295             :             {
     296        2595 :                 aFontHeight.SetHeight(nFontHeight);
     297        2595 :                 pColl->SetFmtAttr( aFontHeight );
     298             :             }
     299        6228 :         }
     300             : 
     301             :         // the default for documents created via 'File/New' should be 'on'
     302             :         // (old documents, where this property was not yet implemented, will get the
     303             :         // value 'false' in the SwDoc c-tor)
     304             :         pDoc->set( IDocumentSettingAccess::MATH_BASELINE_ALIGNMENT,
     305         519 :                 SW_MOD()->GetUsrPref( bWeb )->IsAlignMathObjectsToBaseline() );
     306             :     }
     307             : 
     308             :     /* #106748# If the default frame direction of a document is RTL
     309             :         the default adjusment is to the right. */
     310        1042 :     if( !bHTMLTemplSet &&
     311         521 :         FRMDIR_HORI_RIGHT_TOP == GetDefaultFrameDirection(GetAppLanguage()) )
     312           0 :         pDoc->SetDefault( SvxAdjustItem(SVX_ADJUST_RIGHT, RES_PARATR_ADJUST ) );
     313             : 
     314             :     // OD 09.10.2003 #i18732# - set dynamic pool default for
     315             :     // item RES_FOLLOW_TEXT_FLOW to sal_False for *new document*.
     316             :     // Thus, redo this change in method <SwDoc::RemoveAllFmtLanguageDependencies()>,
     317             :     // which is called from <SwDocShell::ConvertFrom(..)> in order to restore
     318             :     // the static pool default.
     319         521 :     pDoc->SetDefault( SwFmtFollowTextFlow( sal_False ) );
     320             : 
     321             : // #i29550#
     322         521 :     pDoc->SetDefault( SfxBoolItem( RES_COLLAPSING_BORDERS, sal_True ) );
     323             : // <-- collapsing
     324             : 
     325             :     //#i16874# AutoKerning as default for new documents
     326         521 :     pDoc->SetDefault( SvxAutoKernItem( sal_True, RES_CHRATR_AUTOKERN ) );
     327             : 
     328         521 :     pDoc->SetDrawDefaults();
     329             : 
     330             :     // #i42080# - Due to the several calls of method <SetDefault(..)>
     331             :     // at the document instance, the document is modified. Thus, reset this
     332             :     // status here. Note: In method <SubInitNew()> this is also done.
     333         521 :     pDoc->ResetModified();
     334             : 
     335         521 :     return bRet;
     336             : }
     337             : 
     338             : /*--------------------------------------------------------------------
     339             :     Description:    Ctor with SfxCreateMode ?????
     340             :  --------------------------------------------------------------------*/
     341             : 
     342             : 
     343          62 : SwDocShell::SwDocShell( SfxObjectCreateMode eMode ) :
     344             :     SfxObjectShell ( eMode ),
     345             :     pDoc(0),
     346             :     pFontList(0),
     347             :     pView( 0 ),
     348             :     pWrtShell( 0 ),
     349             :     pOLEChildList( 0 ),
     350             :     nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG),
     351          62 :     bInUpdateFontList(false)
     352             : {
     353             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::SwDocShell" );
     354          62 :     Init_Impl();
     355          62 : }
     356             : 
     357             : /*--------------------------------------------------------------------
     358             :     Description: Ctor / Dtor
     359             :  --------------------------------------------------------------------*/
     360             : 
     361             : 
     362         484 : SwDocShell::SwDocShell( const sal_uInt64 i_nSfxCreationFlags ) :
     363             :     SfxObjectShell ( i_nSfxCreationFlags ),
     364             :     pDoc(0),
     365             :     pFontList(0),
     366             :     pView( 0 ),
     367             :     pWrtShell( 0 ),
     368             :     pOLEChildList( 0 ),
     369             :     nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG),
     370         484 :     bInUpdateFontList(false)
     371             : {
     372             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::SwDocShell" );
     373         484 :     Init_Impl();
     374         484 : }
     375             : 
     376             : /*--------------------------------------------------------------------
     377             :     Description: Ctor / Dtor
     378             :  --------------------------------------------------------------------*/
     379             : 
     380             : 
     381          18 : SwDocShell::SwDocShell( SwDoc *pD, SfxObjectCreateMode eMode ):
     382             :     SfxObjectShell ( eMode ),
     383             :     pDoc(pD),
     384             :     pFontList(0),
     385             :     pView( 0 ),
     386             :     pWrtShell( 0 ),
     387             :     pOLEChildList( 0 ),
     388             :     nUpdateDocMode(document::UpdateDocMode::ACCORDING_TO_CONFIG),
     389          18 :     bInUpdateFontList(false)
     390             : {
     391             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::SwDocShell" );
     392          18 :     Init_Impl();
     393          18 : }
     394             : 
     395             : /*--------------------------------------------------------------------
     396             :     Description:    Dtor
     397             :  --------------------------------------------------------------------*/
     398             : 
     399             : 
     400         690 :  SwDocShell::~SwDocShell()
     401             : {
     402             :     // disable chart related objects now because in ~SwDoc it may be to late for this
     403         138 :     if( pDoc )
     404             :     {
     405         134 :         pDoc->GetChartControllerHelper().Disconnect();
     406         134 :         SwChartDataProvider *pPCD = pDoc->GetChartDataProvider();
     407         134 :         if (pPCD)
     408           0 :             pPCD->dispose();
     409             :     }
     410             : 
     411         138 :     RemoveLink();
     412         138 :     delete pFontList;
     413             : 
     414             :     // we, as BroadCaster also become our own Listener
     415             :     // (for DocInfo/FileNames/....)
     416         138 :     EndListening( *this );
     417             : 
     418         138 :     delete pOLEChildList;
     419         552 : }
     420             : 
     421         564 : void  SwDocShell::Init_Impl()
     422             : {
     423         564 :     SetPool(&SW_MOD()->GetPool());
     424         564 :     SetBaseModel(new SwXTextDocument(this));
     425             :     // we, as BroadCaster also become our own Listener
     426             :     // (for DocInfo/FileNames/....)
     427         564 :     StartListening( *this );
     428             :     //position of the "Automatic" style filter for the stylist (app.src)
     429         564 :     SetAutoStyleFilterIndex(3);
     430             : 
     431             :     // set map unit to twip
     432         564 :     SetMapUnit( MAP_TWIP );
     433         564 : }
     434             : /*--------------------------------------------------------------------
     435             :     Description: AddLink
     436             :  --------------------------------------------------------------------*/
     437             : 
     438             : 
     439         556 : void SwDocShell::AddLink()
     440             : {
     441         556 :     if( !pDoc )
     442             :     {
     443         540 :         SwDocFac aFactory;
     444         540 :         pDoc = aFactory.GetDoc();
     445         540 :         pDoc->acquire();
     446         540 :         pDoc->set(IDocumentSettingAccess::HTML_MODE, ISA(SwWebDocShell) );
     447             :     }
     448             :     else
     449          16 :         pDoc->acquire();
     450         556 :     pDoc->SetDocShell( this );      // set the DocShell-Pointer for Doc
     451         556 :     uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), uno::UNO_QUERY);
     452         556 :     ((SwXTextDocument*)xDoc.get())->Reactivate(this);
     453             : 
     454         556 :     SetPool(&pDoc->GetAttrPool());
     455             : 
     456             :     // most suitably not until a sdbcx::View is created!!!
     457         556 :     pDoc->SetOle2Link(LINK(this, SwDocShell, Ole2ModifiedHdl));
     458         556 : }
     459             : 
     460             : /*--------------------------------------------------------------------
     461             :     Description:    create new FontList Change Printer
     462             :  --------------------------------------------------------------------*/
     463             : 
     464             : 
     465         658 : void SwDocShell::UpdateFontList()
     466             : {
     467         658 :     if(!bInUpdateFontList)
     468             :     {
     469         652 :         bInUpdateFontList = true;
     470             :         OSL_ENSURE(pDoc, "No Doc no FontList");
     471         652 :         if( pDoc )
     472             :         {
     473         652 :             delete pFontList;
     474         652 :             pFontList = new FontList( pDoc->getReferenceDevice( true ) );
     475         652 :             PutItem( SvxFontListItem( pFontList, SID_ATTR_CHAR_FONTLIST ) );
     476             :         }
     477         652 :         bInUpdateFontList = false;
     478             :     }
     479         658 : }
     480             : 
     481             : /*--------------------------------------------------------------------
     482             :     Description: RemoveLink
     483             :  --------------------------------------------------------------------*/
     484             : 
     485             : 
     486         138 : void SwDocShell::RemoveLink()
     487             : {
     488             :     // disconnect Uno-Object
     489         138 :     uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), uno::UNO_QUERY);
     490         138 :     ((SwXTextDocument*)xDoc.get())->Invalidate();
     491         138 :     aFinishedTimer.Stop();
     492         138 :     if(pDoc)
     493             :     {
     494         134 :         if( mxBasePool.is() )
     495             :         {
     496         134 :             static_cast<SwDocStyleSheetPool*>(mxBasePool.get())->dispose();
     497         134 :             mxBasePool.clear();
     498             :         }
     499         134 :         sal_Int8 nRefCt = static_cast< sal_Int8 >(pDoc->release());
     500         134 :         pDoc->SetOle2Link(Link());
     501         134 :         pDoc->SetDocShell( 0 );
     502         134 :         if( !nRefCt )
     503         134 :             delete pDoc;
     504         134 :         pDoc = 0;       // we don't have the Doc anymore!!
     505         138 :     }
     506         138 : }
     507           0 : void SwDocShell::InvalidateModel()
     508             : {
     509             :     // disconnect Uno-Object
     510           0 :     uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), uno::UNO_QUERY);
     511           0 :     ((SwXTextDocument*)xDoc.get())->Invalidate();
     512           0 : }
     513           0 : void SwDocShell::ReactivateModel()
     514             : {
     515             :     // disconnect Uno-Object
     516           0 :     uno::Reference< text::XTextDocument >  xDoc(GetBaseModel(), uno::UNO_QUERY);
     517           0 :     ((SwXTextDocument*)xDoc.get())->Reactivate(this);
     518           0 : }
     519             : 
     520             : /*--------------------------------------------------------------------
     521             :     Description: Load, Default-Format
     522             :  --------------------------------------------------------------------*/
     523             : 
     524             : 
     525          37 : sal_Bool  SwDocShell::Load( SfxMedium& rMedium )
     526             : {
     527             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::Load" );
     528          37 :     sal_Bool bRet = sal_False;
     529          37 :     if( SfxObjectShell::Load( rMedium ))
     530             :     {
     531             :         RTL_LOGFILE_CONTEXT_TRACE( aLog, "after SfxInPlaceObject::Load" );
     532          37 :         if( pDoc )              // for last version!!
     533           0 :             RemoveLink();       // release the existing
     534             : 
     535          37 :         AddLink();      // set Link and update Data!!
     536             : 
     537             :         // Loading
     538             :         // for MD
     539             :             OSL_ENSURE( !mxBasePool.is(), "who hasn't destroyed their Pool?" );
     540          37 :             mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
     541          37 :             if(GetCreateMode() != SFX_CREATE_MODE_ORGANIZER)
     542             :             {
     543          37 :                 SFX_ITEMSET_ARG( rMedium.GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, sal_False);
     544          37 :                 nUpdateDocMode = pUpdateDocItem ? pUpdateDocItem->GetValue() : document::UpdateDocMode::NO_UPDATE;
     545             :             }
     546             : 
     547          37 :         SwWait aWait( *this, sal_True );
     548          37 :         sal_uInt32 nErr = ERR_SWG_READ_ERROR;
     549          37 :         switch( GetCreateMode() )
     550             :         {
     551             : 
     552             :         case SFX_CREATE_MODE_ORGANIZER:
     553             :             {
     554           0 :                 if( ReadXML )
     555             :                 {
     556           0 :                     ReadXML->SetOrganizerMode( sal_True );
     557           0 :                     SwReader aRdr( rMedium, aEmptyStr, pDoc );
     558           0 :                     nErr = aRdr.Read( *ReadXML );
     559           0 :                     ReadXML->SetOrganizerMode( sal_False );
     560             :                 }
     561             :             }
     562           0 :             break;
     563             : 
     564             :         case SFX_CREATE_MODE_INTERNAL:
     565             :         case SFX_CREATE_MODE_EMBEDDED:
     566             :             {
     567             :                 // for MWERKS (Mac-Compiler): can't cast autonomously
     568           4 :                 SwTransferable::InitOle( this, *pDoc );
     569             :             }
     570             :             // suppress SfxProgress, when we are Embedded
     571           4 :             SW_MOD()->SetEmbeddedLoadSave( sal_True );
     572             :             // no break;
     573             : 
     574             :         case SFX_CREATE_MODE_STANDARD:
     575             :         case SFX_CREATE_MODE_PREVIEW:
     576             :             {
     577          37 :                 Reader *pReader = ReadXML;
     578          37 :                 if( pReader )
     579             :                 {
     580             :                     // set Doc's DocInfo at DocShell-Medium
     581             :                     RTL_LOGFILE_CONTEXT_TRACE( aLog, "before ReadDocInfo" );
     582          37 :                     SwReader aRdr( rMedium, aEmptyStr, pDoc );
     583             :                     RTL_LOGFILE_CONTEXT_TRACE( aLog, "before Read" );
     584          37 :                     nErr = aRdr.Read( *pReader );
     585             :                     RTL_LOGFILE_CONTEXT_TRACE( aLog, "after Read" );
     586             : 
     587             :                     // If a XML document is loaded, the global doc/web doc
     588             :                     // flags have to be set, because they aren't loaded
     589             :                     // by this formats.
     590          37 :                     if( ISA( SwWebDocShell ) )
     591             :                     {
     592           0 :                         if( !pDoc->get(IDocumentSettingAccess::HTML_MODE) )
     593           0 :                             pDoc->set(IDocumentSettingAccess::HTML_MODE, true);
     594             :                     }
     595          37 :                     if( ISA( SwGlobalDocShell ) )
     596             :                     {
     597           0 :                         if( !pDoc->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) )
     598           0 :                             pDoc->set(IDocumentSettingAccess::GLOBAL_DOCUMENT, true);
     599          37 :                     }
     600             :                 }
     601             :             }
     602          37 :             break;
     603             : 
     604             :         default:
     605             :             OSL_ENSURE( !this, "Load: new CreateMode?" );
     606             : 
     607             :         }
     608             : 
     609          37 :         UpdateFontList();
     610          37 :         InitDraw();
     611             : 
     612          37 :         SetError( nErr, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
     613          37 :         bRet = !IsError( nErr );
     614             : 
     615          72 :         if ( bRet && !pDoc->IsInLoadAsynchron() &&
     616          35 :              GetCreateMode() == SFX_CREATE_MODE_STANDARD )
     617             :         {
     618          33 :             LoadingFinished();
     619             :         }
     620             : 
     621             :         // suppress SfxProgress, when we are Embedded
     622          37 :         SW_MOD()->SetEmbeddedLoadSave( sal_False );
     623             :     }
     624             : 
     625          37 :     return bRet;
     626             : }
     627             : 
     628           0 : sal_Bool  SwDocShell::LoadFrom( SfxMedium& rMedium )
     629             : {
     630             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::LoadFrom" );
     631           0 :     sal_Bool bRet = sal_False;
     632           0 :     if( pDoc )
     633           0 :         RemoveLink();
     634             : 
     635           0 :     AddLink();      // set Link and update Data!!
     636             : 
     637             :     do {        // middle check loop
     638           0 :         sal_uInt32 nErr = ERR_SWG_READ_ERROR;
     639           0 :         String aStreamName;
     640           0 :         aStreamName = rtl::OUString("styles.xml");
     641           0 :         uno::Reference < container::XNameAccess > xAccess( rMedium.GetStorage(), uno::UNO_QUERY );
     642           0 :         if ( xAccess->hasByName( aStreamName ) && rMedium.GetStorage()->isStreamElement( aStreamName ) )
     643             :         {
     644             :             // Loading
     645           0 :             SwWait aWait( *this, sal_True );
     646             :             {
     647             :                 OSL_ENSURE( !mxBasePool.is(), "who hasn't destroyed their Pool?" );
     648           0 :                 mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
     649           0 :                 if( ReadXML )
     650             :                 {
     651           0 :                     ReadXML->SetOrganizerMode( sal_True );
     652           0 :                     SwReader aRdr( rMedium, aEmptyStr, pDoc );
     653           0 :                     nErr = aRdr.Read( *ReadXML );
     654           0 :                     ReadXML->SetOrganizerMode( sal_False );
     655             :                 }
     656           0 :             }
     657             :         }
     658             :         else
     659             :         {
     660             :             OSL_FAIL("Code removed!");
     661             :         }
     662             : 
     663           0 :         SetError( nErr, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
     664           0 :         bRet = !IsError( nErr );
     665             : 
     666             :     } while( sal_False );
     667             : 
     668           0 :     SfxObjectShell::LoadFrom( rMedium );
     669           0 :     pDoc->ResetModified();
     670           0 :     return bRet;
     671             : }
     672             : 
     673             : 
     674         519 : void SwDocShell::SubInitNew()
     675             : {
     676             :     OSL_ENSURE( !mxBasePool.is(), "who hasn't destroyed their Pool?" );
     677         519 :     mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
     678         519 :     UpdateFontList();
     679         519 :     InitDraw();
     680             : 
     681         519 :     pDoc->setLinkUpdateMode( GLOBALSETTING );
     682         519 :     pDoc->setFieldUpdateFlags( AUTOUPD_GLOBALSETTING );
     683             : 
     684         519 :     sal_Bool bWeb = ISA(SwWebDocShell);
     685             : 
     686             :     sal_uInt16 nRange[] =   {
     687             :         RES_PARATR_ADJUST, RES_PARATR_ADJUST,
     688             :         RES_CHRATR_COLOR, RES_CHRATR_COLOR,
     689             :         RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE,
     690             :         RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE,
     691             :         RES_CHRATR_CTL_LANGUAGE, RES_CHRATR_CTL_LANGUAGE,
     692         519 :         0, 0, 0  };
     693         519 :     if(!bWeb)
     694             :     {
     695         519 :         nRange[ (sizeof(nRange)/sizeof(nRange[0])) - 3 ] = RES_PARATR_TABSTOP;
     696         519 :         nRange[ (sizeof(nRange)/sizeof(nRange[0])) - 2 ] = RES_PARATR_HYPHENZONE;
     697             :     }
     698         519 :     SfxItemSet aDfltSet( pDoc->GetAttrPool(), nRange );
     699             : 
     700             :     //! get lingu options without loading lingu DLL
     701         519 :     SvtLinguOptions aLinguOpt;
     702             : 
     703         519 :     SvtLinguConfig().GetOptions( aLinguOpt );
     704             : 
     705         519 :     sal_Int16   nVal = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN),
     706         519 :                 eCJK = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN),
     707         519 :                 eCTL = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX);
     708         519 :     aDfltSet.Put( SvxLanguageItem( nVal, RES_CHRATR_LANGUAGE ) );
     709         519 :     aDfltSet.Put( SvxLanguageItem( eCJK, RES_CHRATR_CJK_LANGUAGE ) );
     710         519 :     aDfltSet.Put( SvxLanguageItem( eCTL, RES_CHRATR_CTL_LANGUAGE ) );
     711             : 
     712         519 :     if(!bWeb)
     713             :     {
     714             :         SvxHyphenZoneItem aHyp( (SvxHyphenZoneItem&) pDoc->GetDefault(
     715         519 :                                                         RES_PARATR_HYPHENZONE) );
     716         519 :         aHyp.GetMinLead()   = static_cast< sal_uInt8 >(aLinguOpt.nHyphMinLeading);
     717         519 :         aHyp.GetMinTrail()  = static_cast< sal_uInt8 >(aLinguOpt.nHyphMinTrailing);
     718             : 
     719         519 :         aDfltSet.Put( aHyp );
     720             : 
     721         519 :         sal_uInt16 nNewPos = static_cast< sal_uInt16 >(SW_MOD()->GetUsrPref(sal_False)->GetDefTab());
     722         519 :         if( nNewPos )
     723             :             aDfltSet.Put( SvxTabStopItem( 1, nNewPos,
     724         519 :                                           SVX_TAB_ADJUST_DEFAULT, RES_PARATR_TABSTOP ) );
     725             :     }
     726         519 :     aDfltSet.Put( SvxColorItem( Color( COL_AUTO ), RES_CHRATR_COLOR ) );
     727             : 
     728         519 :     pDoc->SetDefault( aDfltSet );
     729             : 
     730             :     //default page mode for text grid
     731         519 :     if(!bWeb)
     732             :     {
     733         519 :         sal_Bool bSquaredPageMode = SW_MOD()->GetUsrPref(sal_False)->IsSquaredPageMode();
     734         519 :         pDoc->SetDefaultPageMode( bSquaredPageMode );
     735             :     }
     736             : 
     737         519 :     pDoc->ResetModified();
     738         519 : }
     739             : 
     740             : /*
     741             :  * Document Interface Access
     742             :  */
     743           0 : IDocumentDeviceAccess* SwDocShell::getIDocumentDeviceAccess() { return pDoc; }
     744           6 : const IDocumentSettingAccess* SwDocShell::getIDocumentSettingAccess() const { return pDoc; }
     745           0 : IDocumentChartDataProviderAccess* SwDocShell::getIDocumentChartDataProviderAccess() { return pDoc; }
     746             : 
     747             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10