LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/ui/app - docsh.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 296 605 48.9 %
Date: 2013-07-09 Functions: 35 48 72.9 %
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             : #include <rtl/logfile.hxx>
      23             : #include <vcl/msgbox.hxx>
      24             : #include <vcl/svapp.hxx>
      25             : #include <vcl/wrkwin.hxx>
      26             : #include <vcl/jobset.hxx>
      27             : #include <svl/whiter.hxx>
      28             : #include <svl/zforlist.hxx>
      29             : #include <svl/eitem.hxx>
      30             : #include <svl/stritem.hxx>
      31             : #include <svl/PasswordHelper.hxx>
      32             : #include <editeng/adjustitem.hxx>
      33             : #include <basic/sbx.hxx>
      34             : #include <unotools/moduleoptions.hxx>
      35             : #include <unotools/misccfg.hxx>
      36             : #include <sfx2/request.hxx>
      37             : #include <sfx2/passwd.hxx>
      38             : #include <sfx2/bindings.hxx>
      39             : #include <sfx2/docfile.hxx>
      40             : #include <sfx2/evntconf.hxx>
      41             : #include <sfx2/docfilt.hxx>
      42             : #include <sfx2/printer.hxx>
      43             : #include <sfx2/linkmgr.hxx>
      44             : #include <svl/srchitem.hxx>
      45             : #include <editeng/flstitem.hxx>
      46             : #include <sfx2/htmlmode.hxx>
      47             : #include <svtools/soerr.hxx>
      48             : #include <comphelper/classids.hxx>
      49             : #include <basic/basmgr.hxx>
      50             : #include <basic/sbmod.hxx>
      51             : #include <swevent.hxx>
      52             : #include <fmtpdsc.hxx>
      53             : #include <fmtfsize.hxx>
      54             : #include <fmtfld.hxx>
      55             : #include <node.hxx>
      56             : #include <swwait.hxx>
      57             : #include <printdata.hxx>
      58             : #include <frmatr.hxx>
      59             : #include <view.hxx>         // for the current view
      60             : #include <edtwin.hxx>
      61             : #include <PostItMgr.hxx>
      62             : #include <wrtsh.hxx>        // connection to Core
      63             : #include <docsh.hxx>        // document creation
      64             : #include <basesh.hxx>
      65             : #include <viewopt.hxx>
      66             : #include <wdocsh.hxx>
      67             : #include <swmodule.hxx>
      68             : #include <globdoc.hxx>
      69             : #include <usrpref.hxx>
      70             : #include <shellio.hxx>      // I/O
      71             : #include <docstyle.hxx>
      72             : #include <doc.hxx>
      73             : #include <IDocumentUndoRedo.hxx>
      74             : #include <docstat.hxx>
      75             : #include <pagedesc.hxx>
      76             : #include <pview.hxx>
      77             : #include <mdiexp.hxx>
      78             : #include <swbaslnk.hxx>
      79             : #include <srcview.hxx>
      80             : #include <ndindex.hxx>
      81             : #include <ndole.hxx>
      82             : #include <swcli.hxx>
      83             : #include <txtftn.hxx>
      84             : #include <ftnidx.hxx>
      85             : #include <fldbas.hxx>
      86             : #include <docary.hxx>
      87             : #include <swerror.h>        // Error messages
      88             : #include <helpid.h>
      89             : #include <cmdid.h>
      90             : #include <globals.hrc>
      91             : #include <app.hrc>
      92             : 
      93             : #include <cfgid.h>
      94             : #include <unotools/fltrcfg.hxx>
      95             : #include <svtools/htmlcfg.hxx>
      96             : #include <sfx2/fcontnr.hxx>
      97             : #include <sfx2/objface.hxx>
      98             : #include <comphelper/storagehelper.hxx>
      99             : 
     100             : #define SwDocShell
     101             : #include <sfx2/msg.hxx>
     102             : #include <swslots.hxx>
     103             : #include <com/sun/star/document/UpdateDocMode.hpp>
     104             : 
     105             : #include <com/sun/star/document/XDocumentProperties.hpp>
     106             : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
     107             : 
     108             : #include <unomid.h>
     109             : 
     110             : #include <sfx2/Metadatable.hxx>
     111             : #include <switerator.hxx>
     112             : 
     113             : using namespace ::com::sun::star;
     114             : using namespace ::com::sun::star::uno;
     115             : using namespace ::com::sun::star::script;
     116             : using namespace ::com::sun::star::container;
     117             : 
     118             : 
     119       44644 : SFX_IMPL_INTERFACE( SwDocShell, SfxObjectShell, SW_RES(0) )
     120             : {
     121          33 : }
     122             : 
     123      388084 : TYPEINIT2(SwDocShell, SfxObjectShell, SfxListener);
     124             : 
     125      242568 : SFX_IMPL_OBJECTFACTORY(SwDocShell, SvGlobalName(SO3_SW_CLASSID), SFXOBJECTSHELL_STD_NORMAL|SFXOBJECTSHELL_HASMENU, "swriter"  )
     126             : 
     127             : // Prepare loading
     128          57 : Reader* SwDocShell::StartConvertFrom(SfxMedium& rMedium, SwReader** ppRdr,
     129             :                                     SwCrsrShell *pCrsrShell,
     130             :                                     SwPaM* pPaM )
     131             : {
     132          57 :     sal_Bool bAPICall = sal_False;
     133             :     const SfxPoolItem* pApiItem;
     134             :     const SfxItemSet* pMedSet;
     135         114 :     if( 0 != ( pMedSet = rMedium.GetItemSet() ) && SFX_ITEM_SET ==
     136          57 :             pMedSet->GetItemState( FN_API_CALL, sal_True, &pApiItem ) )
     137           0 :             bAPICall = ((const SfxBoolItem*)pApiItem)->GetValue();
     138             : 
     139          57 :     const SfxFilter* pFlt = rMedium.GetFilter();
     140          57 :     if( !pFlt )
     141             :     {
     142           0 :         if(!bAPICall)
     143             :         {
     144           0 :             InfoBox( 0, SW_RESSTR(STR_CANTOPEN)).Execute();
     145             :         }
     146           0 :         return 0;
     147             :     }
     148          57 :     String aFileName( rMedium.GetName() );
     149          57 :     SwRead pRead = SwReaderWriter::GetReader( pFlt->GetUserData() );
     150          57 :     if( !pRead )
     151           0 :         return 0;
     152             : 
     153         114 :     if( rMedium.IsStorage()
     154           0 :         ? SW_STORAGE_READER & pRead->GetReaderType()
     155          57 :         : SW_STREAM_READER & pRead->GetReaderType() )
     156             :     {
     157           0 :         *ppRdr = pPaM ? new SwReader( rMedium, aFileName, *pPaM ) :
     158             :             pCrsrShell ?
     159           0 :                 new SwReader( rMedium, aFileName, *pCrsrShell->GetCrsr() )
     160          57 :                     : new SwReader( rMedium, aFileName, pDoc );
     161             :     }
     162             :     else
     163           0 :         return 0;
     164             : 
     165             :     // Check password
     166         114 :     String aPasswd;
     167          57 :     if ((*ppRdr)->NeedsPasswd( *pRead ))
     168             :     {
     169           0 :         if(!bAPICall)
     170             :         {
     171             :             SfxPasswordDialog* pPasswdDlg =
     172           0 :                     new SfxPasswordDialog( 0 );
     173           0 :                 if(RET_OK == pPasswdDlg->Execute())
     174           0 :                     aPasswd = pPasswdDlg->GetPassword();
     175             :         }
     176             :         else
     177             :         {
     178           0 :             const SfxItemSet* pSet = rMedium.GetItemSet();
     179             :             const SfxPoolItem *pPassItem;
     180           0 :             if(pSet && SFX_ITEM_SET == pSet->GetItemState(SID_PASSWORD, sal_True, &pPassItem))
     181           0 :                 aPasswd = ((const SfxStringItem *)pPassItem)->GetValue();
     182             :         }
     183             : 
     184           0 :         if (!(*ppRdr)->CheckPasswd( aPasswd, *pRead ))
     185             :         {
     186           0 :             InfoBox( 0, SW_RES(MSG_ERROR_PASSWD)).Execute();
     187           0 :                 delete *ppRdr;
     188           0 :             return 0;
     189             :         }
     190             :     }
     191             : 
     192             :     // #i30171# set the UpdateDocMode at the SwDocShell
     193          57 :     SFX_ITEMSET_ARG( rMedium.GetItemSet(), pUpdateDocItem, SfxUInt16Item, SID_UPDATEDOCMODE, sal_False);
     194          57 :     nUpdateDocMode = pUpdateDocItem ? pUpdateDocItem->GetValue() : document::UpdateDocMode::NO_UPDATE;
     195             : 
     196          57 :     if (!pFlt->GetDefaultTemplate().isEmpty())
     197           0 :         pRead->SetTemplateName( pFlt->GetDefaultTemplate() );
     198             : 
     199          60 :     if( pRead == ReadAscii && 0 != rMedium.GetInStream() &&
     200           3 :         pFlt->GetUserData() == FILTER_TEXT_DLG )
     201             :     {
     202           3 :         SwAsciiOptions aOpt;
     203             :         const SfxItemSet* pSet;
     204             :         const SfxPoolItem* pItem;
     205           6 :         if( 0 != ( pSet = rMedium.GetItemSet() ) && SFX_ITEM_SET ==
     206           3 :             pSet->GetItemState( SID_FILE_FILTEROPTIONS, sal_True, &pItem ) )
     207           3 :             aOpt.ReadUserData( ((const SfxStringItem*)pItem)->GetValue() );
     208             : 
     209           3 :         if( pRead )
     210           3 :             pRead->GetReaderOpt().SetASCIIOpts( aOpt );
     211             :     }
     212             : 
     213         114 :     return pRead;
     214             : }
     215             : 
     216             : // Loading
     217          57 : sal_Bool SwDocShell::ConvertFrom( SfxMedium& rMedium )
     218             : {
     219             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::ConvertFrom" );
     220             : 
     221             :     SwReader* pRdr;
     222          57 :     SwRead pRead = StartConvertFrom(rMedium, &pRdr);
     223          57 :     if (!pRead)
     224           0 :       return sal_False; // #129881# return if no reader is found
     225          57 :     SotStorageRef pStg=pRead->getSotStorageRef(); // #i45333# save sot storage ref in case of recursive calls
     226             : 
     227         114 :     SwWait aWait( *this, sal_True );
     228             : 
     229             :         // Suppress SfxProgress, when we are Embedded
     230          57 :     SW_MOD()->SetEmbeddedLoadSave(
     231         114 :                             SFX_CREATE_MODE_EMBEDDED == GetCreateMode() );
     232             : 
     233          57 :     pRdr->GetDoc()->set(IDocumentSettingAccess::HTML_MODE, ISA(SwWebDocShell));
     234             : 
     235             :     /* #106748# Restore the pool default if reading a saved document. */
     236          57 :     pDoc->RemoveAllFmtLanguageDependencies();
     237             : 
     238          57 :     sal_uLong nErr = pRdr->Read( *pRead );
     239             : 
     240             :     // Maybe put away one old Doc
     241          57 :     if ( pDoc != pRdr->GetDoc() )
     242             :     {
     243           0 :         if( pDoc )
     244           0 :             RemoveLink();
     245           0 :         pDoc = pRdr->GetDoc();
     246             : 
     247           0 :         AddLink();
     248             : 
     249           0 :         if ( !mxBasePool.is() )
     250           0 :             mxBasePool = new SwDocStyleSheetPool( *pDoc, SFX_CREATE_MODE_ORGANIZER == GetCreateMode() );
     251             :     }
     252             : 
     253          57 :     UpdateFontList();
     254          57 :     InitDraw();
     255             : 
     256          57 :     delete pRdr;
     257             : 
     258          57 :     SW_MOD()->SetEmbeddedLoadSave( sal_False );
     259             : 
     260          57 :     SetError( nErr, OUString(  OSL_LOG_PREFIX  ) );
     261          57 :     sal_Bool bOk = !IsError( nErr );
     262             : 
     263          57 :     if ( bOk && !pDoc->IsInLoadAsynchron() )
     264             :     {
     265          54 :         LoadingFinished();
     266             :     }
     267             : 
     268          57 :     pRead->setSotStorageRef(pStg); // #i45333# save sot storage ref in case of recursive calls
     269             : 
     270         114 :     return bOk;
     271             : }
     272             : 
     273             : // Saving the Default-Format, Stg present
     274           0 : sal_Bool SwDocShell::Save()
     275             : {
     276             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::Save" );
     277             :     //#i3370# remove quick help to prevent saving of autocorrection suggestions
     278           0 :     if(pView)
     279           0 :         pView->GetEditWin().StopQuickHelp();
     280           0 :     SwWait aWait( *this, sal_True );
     281             : 
     282           0 :     CalcLayoutForOLEObjects();  // format for OLE objets
     283             :     // #i62875#
     284             :     // reset compatibility flag <DoNotCaptureDrawObjsOnPage>, if possible
     285           0 :     if ( pWrtShell && pDoc &&
     286           0 :          pDoc->get(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE) &&
     287           0 :          docfunc::AllDrawObjsOnPage( *pDoc ) )
     288             :     {
     289           0 :         pDoc->set(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE, false);
     290             :     }
     291             : 
     292           0 :     sal_uLong nErr = ERR_SWG_WRITE_ERROR, nVBWarning = ERRCODE_NONE;
     293           0 :     if( SfxObjectShell::Save() )
     294             :     {
     295           0 :         switch( GetCreateMode() )
     296             :         {
     297             :         case SFX_CREATE_MODE_INTERNAL:
     298           0 :             nErr = 0;
     299           0 :             break;
     300             : 
     301             :         case SFX_CREATE_MODE_ORGANIZER:
     302             :             {
     303           0 :                 WriterRef xWrt;
     304           0 :                 ::GetXMLWriter( aEmptyStr, GetMedium()->GetBaseURL( true ), xWrt );
     305           0 :                 xWrt->SetOrganizerMode( sal_True );
     306           0 :                 SwWriter aWrt( *GetMedium(), *pDoc );
     307           0 :                 nErr = aWrt.Write( xWrt );
     308           0 :                 xWrt->SetOrganizerMode( sal_False );
     309             :             }
     310           0 :             break;
     311             : 
     312             :         case SFX_CREATE_MODE_EMBEDDED:
     313             :             // Suppress SfxProgress, if we are Embedded
     314           0 :             SW_MOD()->SetEmbeddedLoadSave( sal_True );
     315             :             // no break;
     316             : 
     317             :         case SFX_CREATE_MODE_STANDARD:
     318             :         case SFX_CREATE_MODE_PREVIEW:
     319             :         default:
     320             :             {
     321           0 :                 if( pDoc->ContainsMSVBasic() )
     322             :                 {
     323           0 :                     if( SvtFilterOptions::Get().IsLoadWordBasicStorage() )
     324           0 :                         nVBWarning = GetSaveWarningOfMSVBAStorage( (SfxObjectShell&) (*this) );
     325           0 :                     pDoc->SetContainsMSVBasic( sal_False );
     326             :                 }
     327             : 
     328             :                 // End TableBox Edit!
     329           0 :                 if( pWrtShell )
     330           0 :                     pWrtShell->EndAllTblBoxEdit();
     331             : 
     332           0 :                 WriterRef xWrt;
     333           0 :                 ::GetXMLWriter( aEmptyStr, GetMedium()->GetBaseURL( true ), xWrt );
     334             : 
     335           0 :                 sal_Bool bLockedView(sal_False);
     336           0 :                 if ( pWrtShell )
     337             :                 {
     338           0 :                     bLockedView = pWrtShell->IsViewLocked();
     339           0 :                     pWrtShell->LockView( sal_True );    //lock visible section
     340             :                 }
     341             : 
     342           0 :                 SwWriter aWrt( *GetMedium(), *pDoc );
     343           0 :                 nErr = aWrt.Write( xWrt );
     344             : 
     345           0 :                 if ( pWrtShell )
     346           0 :                     pWrtShell->LockView( bLockedView );
     347             :             }
     348           0 :             break;
     349             :         }
     350           0 :         SW_MOD()->SetEmbeddedLoadSave( sal_False );
     351             :     }
     352           0 :     SetError( nErr ? nErr : nVBWarning, OUString(  OSL_LOG_PREFIX  ) );
     353             : 
     354           0 :     SfxViewFrame* pFrm = pWrtShell ? pWrtShell->GetView().GetViewFrame() : 0;
     355           0 :     if( pFrm )
     356             :     {
     357           0 :         pFrm->GetBindings().SetState(SfxBoolItem(SID_DOC_MODIFIED, sal_False));
     358             :     }
     359           0 :     return !IsError( nErr );
     360             : }
     361             : 
     362             : // Save using the Defaultformat
     363          15 : sal_Bool SwDocShell::SaveAs( SfxMedium& rMedium )
     364             : {
     365             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::SaveAs" );
     366             : 
     367          15 :     SwWait aWait( *this, sal_True );
     368             :     //#i3370# remove quick help to prevent saving of autocorrection suggestions
     369          15 :     if(pView)
     370          15 :         pView->GetEditWin().StopQuickHelp();
     371             : 
     372             :     //#i91811# mod if we have an active margin window, write back the text
     373          30 :     if ( pView &&
     374          30 :          pView->GetPostItMgr() &&
     375          15 :          pView->GetPostItMgr()->HasActiveSidebarWin() )
     376             :     {
     377           0 :         pView->GetPostItMgr()->UpdateDataOnActiveSidebarWin();
     378             :     }
     379             : 
     380          15 :     if( pDoc->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) &&
     381           0 :         !pDoc->get(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS) )
     382           0 :         RemoveOLEObjects();
     383             : 
     384             :     {
     385             :         // Task 75666 - is the Document imported by our Microsoft-Filters?
     386          15 :         const SfxFilter* pOldFilter = GetMedium()->GetFilter();
     387          30 :         if( pOldFilter &&
     388          30 :             ( pOldFilter->GetUserData() == FILTER_WW8 ||
     389          30 :               pOldFilter->GetUserData() == "CWW6" ||
     390          30 :               pOldFilter->GetUserData() == "WW6" ||
     391          15 :               pOldFilter->GetUserData() == "WW1" ) )
     392             :         {
     393             :             // when saving it in our own fileformat, then remove the template
     394             :             // name from the docinfo.
     395             :             uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
     396           0 :                 GetModel(), uno::UNO_QUERY_THROW);
     397             :             uno::Reference<document::XDocumentProperties> xDocProps
     398           0 :                 = xDPS->getDocumentProperties();
     399           0 :             xDocProps->setTemplateName(OUString());
     400           0 :             xDocProps->setTemplateURL(OUString());
     401           0 :             xDocProps->setTemplateDate(::util::DateTime());
     402             :         }
     403             :     }
     404             : 
     405          15 :     CalcLayoutForOLEObjects();  // format for OLE objets
     406             :     // #i62875#
     407             :     // reset compatibility flag <DoNotCaptureDrawObjsOnPage>, if possible
     408          45 :     if ( pWrtShell && pDoc &&
     409          30 :          pDoc->get(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE) &&
     410           0 :          docfunc::AllDrawObjsOnPage( *pDoc ) )
     411             :     {
     412           0 :         pDoc->set(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE, false);
     413             :     }
     414             : 
     415          15 :     sal_uLong nErr = ERR_SWG_WRITE_ERROR, nVBWarning = ERRCODE_NONE;
     416          30 :     uno::Reference < embed::XStorage > xStor = rMedium.GetOutputStorage();
     417          15 :     if( SfxObjectShell::SaveAs( rMedium ) )
     418             :     {
     419          15 :         if( GetDoc()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) && !ISA( SwGlobalDocShell ) )
     420             :         {
     421             :             // This is to set the correct class id if SaveAs is
     422             :             // called from SwDoc::SplitDoc to save a normal doc as
     423             :             // global doc. In this case, SaveAs is called at a
     424             :             // normal doc shell, therefore, SfxInplaceObject::SaveAs
     425             :             // will set the wrong class id.
     426           0 :             SvGlobalName aClassName;
     427             :             // The document is closed explicitly, but using SfxObjectShellLock is still more correct here
     428             :             SfxObjectShellLock xDocSh =
     429           0 :                 new SwGlobalDocShell( SFX_CREATE_MODE_INTERNAL );
     430             :             // the global document can not be a template
     431           0 :             xDocSh->SetupStorage( xStor, SotStorage::GetVersion( xStor ), sal_False );
     432           0 :             xDocSh->DoClose();
     433             :         }
     434             : 
     435          15 :         if( pDoc->ContainsMSVBasic() )
     436             :         {
     437           0 :             if( SvtFilterOptions::Get().IsLoadWordBasicStorage() )
     438           0 :                 nVBWarning = GetSaveWarningOfMSVBAStorage( (SfxObjectShell&) *this );
     439           0 :             pDoc->SetContainsMSVBasic( sal_False );
     440             :         }
     441             : 
     442             :         // End TableBox Edit!
     443          15 :         if( pWrtShell )
     444          15 :             pWrtShell->EndAllTblBoxEdit();
     445             : 
     446             :         // Remember and preserve Modified-Flag without calling the Link
     447             :         // (for OLE; after Statement from MM)
     448          15 :         sal_Bool bIsModified = pDoc->IsModified();
     449          15 :         pDoc->GetIDocumentUndoRedo().LockUndoNoModifiedPosition();
     450          15 :         Link aOldOLELnk( pDoc->GetOle2Link() );
     451          15 :         pDoc->SetOle2Link( Link() );
     452             : 
     453             :             // Suppress SfxProgress when we are Embedded
     454          15 :         SW_MOD()->SetEmbeddedLoadSave(
     455          30 :                             SFX_CREATE_MODE_EMBEDDED == GetCreateMode() );
     456             : 
     457          15 :         WriterRef xWrt;
     458          15 :         ::GetXMLWriter( aEmptyStr, rMedium.GetBaseURL( true ), xWrt );
     459             : 
     460          15 :         sal_Bool bLockedView(sal_False);
     461          15 :         if ( pWrtShell )
     462             :         {
     463          15 :             bLockedView = pWrtShell->IsViewLocked();
     464          15 :             pWrtShell->LockView( sal_True );    //lock visible section
     465             :         }
     466             : 
     467          30 :         SwWriter aWrt( rMedium, *pDoc );
     468          15 :         nErr = aWrt.Write( xWrt );
     469             : 
     470          15 :         if ( pWrtShell )
     471          15 :             pWrtShell->LockView( bLockedView );
     472             : 
     473          15 :         if( bIsModified )
     474             :         {
     475           4 :             pDoc->SetModified();
     476           4 :             pDoc->GetIDocumentUndoRedo().UnLockUndoNoModifiedPosition();
     477             :         }
     478          15 :         pDoc->SetOle2Link( aOldOLELnk );
     479             : 
     480          15 :         SW_MOD()->SetEmbeddedLoadSave( sal_False );
     481             : 
     482             :         // Increase RSID
     483          30 :         pDoc->setRsid( pDoc->getRsid() );
     484             :     }
     485          15 :     SetError( nErr ? nErr : nVBWarning, OUString(  OSL_LOG_PREFIX  ) );
     486             : 
     487          30 :     return !IsError( nErr );
     488             : }
     489             : 
     490             : // Save all Formats
     491           1 : static SwSrcView* lcl_GetSourceView( SwDocShell* pSh )
     492             : {
     493             :     // are we in SourceView?
     494           1 :     SfxViewFrame* pVFrame = SfxViewFrame::GetFirst( pSh );
     495           1 :     SfxViewShell* pViewShell = pVFrame ? pVFrame->GetViewShell() : 0;
     496           1 :     return PTR_CAST( SwSrcView, pViewShell);
     497             : }
     498             : 
     499          11 : sal_Bool SwDocShell::ConvertTo( SfxMedium& rMedium )
     500             : {
     501             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::ConvertTo" );
     502          11 :     const SfxFilter* pFlt = rMedium.GetFilter();
     503          11 :     if( !pFlt )
     504           0 :         return sal_False;
     505             : 
     506          11 :     WriterRef xWriter;
     507          11 :     SwReaderWriter::GetWriter( pFlt->GetUserData(), rMedium.GetBaseURL( true ), xWriter );
     508          11 :     if( !xWriter.Is() )
     509             :     {   // Filter not available
     510             :         InfoBox( 0,
     511           0 :                  SW_RESSTR(STR_DLLNOTFOUND) ).Execute();
     512           0 :         return sal_False;
     513             :     }
     514             : 
     515             :     //#i3370# remove quick help to prevent saving of autocorrection suggestions
     516          11 :     if(pView)
     517          10 :         pView->GetEditWin().StopQuickHelp();
     518             : 
     519             :     //#i91811# mod if we have an active margin window, write back the text
     520          21 :     if ( pView &&
     521          21 :          pView->GetPostItMgr() &&
     522          10 :          pView->GetPostItMgr()->HasActiveSidebarWin() )
     523             :     {
     524           0 :         pView->GetPostItMgr()->UpdateDataOnActiveSidebarWin();
     525             :     }
     526             : 
     527          11 :     sal_uLong nVBWarning = 0;
     528             : 
     529          11 :     if( pDoc->ContainsMSVBasic() )
     530             :     {
     531           0 :         sal_Bool bSave = pFlt->GetUserData() == "CWW8"
     532           0 :              && SvtFilterOptions::Get().IsLoadWordBasicStorage();
     533             : 
     534           0 :         if ( bSave )
     535             :         {
     536           0 :             SvStorageRef xStg = new SotStorage( rMedium.GetOutStream(), sal_False );
     537             :             OSL_ENSURE( !xStg->GetError(), "No storage available for storing VBA macros!" );
     538           0 :             if ( !xStg->GetError() )
     539             :             {
     540           0 :                 nVBWarning = SaveOrDelMSVBAStorage( (SfxObjectShell&) *this, *xStg, bSave, OUString("Macros") );
     541           0 :                 xStg->Commit();
     542           0 :                 pDoc->SetContainsMSVBasic( sal_True );
     543           0 :             }
     544             :         }
     545             :     }
     546             : 
     547             :     // End TableBox Edit!
     548          11 :     if( pWrtShell )
     549          10 :         pWrtShell->EndAllTblBoxEdit();
     550             : 
     551          11 :     if( pFlt->GetUserData() == "HTML" )
     552             :     {
     553             : #ifndef DISABLE_SCRIPTING
     554           2 :         SvxHtmlOptions& rHtmlOpt = SvxHtmlOptions::Get();
     555           2 :         if( !rHtmlOpt.IsStarBasic() && rHtmlOpt.IsStarBasicWarning() && HasBasic() )
     556             :         {
     557           2 :             uno::Reference< XLibraryContainer > xLibCont(GetBasicContainer(), UNO_QUERY);
     558           4 :             uno::Reference< XNameAccess > xLib;
     559           4 :             Sequence<OUString> aNames = xLibCont->getElementNames();
     560           2 :             const OUString* pNames = aNames.getConstArray();
     561           4 :             for(sal_Int32 nLib = 0; nLib < aNames.getLength(); nLib++)
     562             :             {
     563           2 :                 Any aLib = xLibCont->getByName(pNames[nLib]);
     564           2 :                 aLib >>= xLib;
     565           2 :                 if(xLib.is())
     566             :                 {
     567           2 :                     Sequence<OUString> aModNames = xLib->getElementNames();
     568           2 :                     if(aModNames.getLength())
     569             :                     {
     570           0 :                         SetError(WARN_SWG_HTML_NO_MACROS, OUString(  OSL_LOG_PREFIX  ) );
     571           0 :                         break;
     572           2 :                     }
     573             :                 }
     574           4 :             }
     575             :         }
     576             : #endif
     577           2 :         UpdateDocInfoForSave();
     578             :     }
     579             : 
     580             :     // #i76360# Update document statistics
     581          11 :     pDoc->UpdateDocStat();
     582             : 
     583          11 :     CalcLayoutForOLEObjects();  // format for OLE objets
     584             :     // #i62875#
     585             :     // reset compatibility flag <DoNotCaptureDrawObjsOnPage>, if possible
     586          31 :     if ( pWrtShell && pDoc &&
     587          21 :          pDoc->get(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE) &&
     588           0 :          docfunc::AllDrawObjsOnPage( *pDoc ) )
     589             :     {
     590           0 :         pDoc->set(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE, false);
     591             :     }
     592             : 
     593          19 :     if( xWriter->IsStgWriter() &&
     594          16 :         ( pFlt->GetUserData() == FILTER_XML ||
     595          16 :           pFlt->GetUserData() == FILTER_XMLV ||
     596           8 :           pFlt->GetUserData() == FILTER_XMLVW ) )
     597             :     {
     598             :         // determine the own Type
     599           0 :         sal_uInt8 nMyType = 0;
     600           0 :         if( ISA( SwWebDocShell) )
     601           0 :             nMyType = 1;
     602           0 :         else if( ISA( SwGlobalDocShell) )
     603           0 :             nMyType = 2;
     604             : 
     605             :         // determine the desired Type
     606           0 :         sal_uInt8 nSaveType = 0;
     607           0 :         sal_uLong nSaveClipId = pFlt->GetFormat();
     608           0 :         if( SOT_FORMATSTR_ID_STARWRITERWEB_8 == nSaveClipId ||
     609           0 :             SOT_FORMATSTR_ID_STARWRITERWEB_60 == nSaveClipId ||
     610           0 :             SOT_FORMATSTR_ID_STARWRITERWEB_50 == nSaveClipId ||
     611             :             SOT_FORMATSTR_ID_STARWRITERWEB_40 == nSaveClipId )
     612           0 :             nSaveType = 1;
     613           0 :         else if( SOT_FORMATSTR_ID_STARWRITERGLOB_8 == nSaveClipId ||
     614           0 :                  SOT_FORMATSTR_ID_STARWRITERGLOB_60 == nSaveClipId ||
     615           0 :                  SOT_FORMATSTR_ID_STARWRITERGLOB_50 == nSaveClipId ||
     616             :                  SOT_FORMATSTR_ID_STARWRITERGLOB_40 == nSaveClipId )
     617           0 :             nSaveType = 2;
     618             : 
     619             :         // Change Flags of the Document accordingly
     620           0 :         sal_Bool bIsHTMLModeSave = GetDoc()->get(IDocumentSettingAccess::HTML_MODE);
     621           0 :         sal_Bool bIsGlobalDocSave = GetDoc()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT);
     622           0 :         sal_Bool bIsGlblDocSaveLinksSave = GetDoc()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS);
     623           0 :         if( nMyType != nSaveType )
     624             :         {
     625           0 :             GetDoc()->set(IDocumentSettingAccess::HTML_MODE, 1 == nSaveType);
     626           0 :             GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT, 2 == nSaveType);
     627           0 :             if( 2 != nSaveType )
     628           0 :                 GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS, false);
     629             :         }
     630             : 
     631             :         // if the target format is storage based, then the output storage must be already created
     632           0 :         if ( rMedium.IsStorage() )
     633             :         {
     634             :             // set MediaType on target storage
     635             :             // (MediaType will be queried during SaveAs)
     636             :             try
     637             :             {
     638             :                 // TODO/MBA: testing
     639           0 :                 uno::Reference < beans::XPropertySet > xSet( rMedium.GetStorage(), uno::UNO_QUERY );
     640           0 :                 if ( xSet.is() )
     641           0 :                     xSet->setPropertyValue("MediaType", uno::makeAny( OUString( SotExchange::GetFormatMimeType( nSaveClipId ) ) ) );
     642             :             }
     643           0 :             catch (const uno::Exception&)
     644             :             {
     645             :             }
     646             :         }
     647             : 
     648             :         // Now normally save the Document
     649           0 :         sal_Bool bRet = SaveAs( rMedium );
     650             : 
     651           0 :         if( nMyType != nSaveType )
     652             :         {
     653           0 :             GetDoc()->set(IDocumentSettingAccess::HTML_MODE, bIsHTMLModeSave );
     654           0 :             GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT, bIsGlobalDocSave);
     655           0 :             GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS, bIsGlblDocSaveLinksSave);
     656             :         }
     657             : 
     658           0 :         return bRet;
     659             :     }
     660             : 
     661          11 :     if( pFlt->GetUserData() == FILTER_TEXT_DLG &&
     662           0 :         ( pWrtShell || !::lcl_GetSourceView( this ) ))
     663             :     {
     664           0 :         SwAsciiOptions aOpt;
     665           0 :         String sItemOpt;
     666             :         const SfxItemSet* pSet;
     667             :         const SfxPoolItem* pItem;
     668           0 :         if( 0 != ( pSet = rMedium.GetItemSet() ) )
     669             :         {
     670           0 :             if( SFX_ITEM_SET == pSet->GetItemState( SID_FILE_FILTEROPTIONS,
     671           0 :                                                     sal_True, &pItem ) )
     672           0 :                 sItemOpt = ((const SfxStringItem*)pItem)->GetValue();
     673             :         }
     674           0 :         if(sItemOpt.Len())
     675           0 :             aOpt.ReadUserData( sItemOpt );
     676             : 
     677           0 :         xWriter->SetAsciiOptions( aOpt );
     678             :     }
     679             : 
     680             :         // Suppress SfxProgress when we are Embedded
     681          11 :     SW_MOD()->SetEmbeddedLoadSave(
     682          22 :                             SFX_CREATE_MODE_EMBEDDED == GetCreateMode());
     683             : 
     684             :     // Span Context in order to suppress the Selection's View
     685             :     sal_uLong nErrno;
     686          22 :     String aFileName( rMedium.GetName() );
     687             : 
     688             :     // No View, so the whole Document!
     689          11 :     if ( pWrtShell )
     690             :     {
     691          10 :         SwWait aWait( *this, sal_True );
     692             :         // #i106906#
     693          10 :         const sal_Bool bFormerLockView = pWrtShell->IsViewLocked();
     694          10 :         pWrtShell->LockView( sal_True );
     695          10 :         pWrtShell->StartAllAction();
     696          10 :         pWrtShell->Push();
     697          20 :         SwWriter aWrt( rMedium, *pWrtShell, sal_True );
     698          10 :         nErrno = aWrt.Write( xWriter, &aFileName );
     699             :         //JP 16.05.97: In case the SFX revokes the View while saving
     700          10 :         if( pWrtShell )
     701             :         {
     702          10 :             pWrtShell->Pop(sal_False);
     703          10 :             pWrtShell->EndAllAction();
     704             :             // #i106906#
     705          10 :             pWrtShell->LockView( bFormerLockView );
     706          10 :         }
     707             :     }
     708             :     else
     709             :     {
     710             :         // are we in SourceView?
     711           1 :         SwSrcView* pSrcView = ::lcl_GetSourceView( this );
     712           1 :         if( pSrcView )
     713             :         {
     714           0 :             pSrcView->SaveContentTo(rMedium);
     715           0 :             nErrno = 0;
     716             :         }
     717             :         else
     718             :         {
     719           1 :             SwWriter aWrt( rMedium, *pDoc );
     720           1 :             nErrno = aWrt.Write( xWriter, &aFileName );
     721             :         }
     722             :     }
     723             : 
     724          11 :     SW_MOD()->SetEmbeddedLoadSave( sal_False );
     725          11 :     SetError( nErrno ? nErrno : nVBWarning, OUString(  OSL_LOG_PREFIX  ) );
     726          11 :     if( !rMedium.IsStorage() )
     727          11 :         rMedium.CloseOutStream();
     728             : 
     729          22 :     return !IsError( nErrno );
     730             : }
     731             : 
     732             : 
     733             : // Hands off
     734             : // do not yet activate, must deliver TRUE
     735          35 : sal_Bool SwDocShell::SaveCompleted( const uno::Reference < embed::XStorage >& xStor  )
     736             : {
     737             :     RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "SwDocShell::SaveCompleted" );
     738          35 :     sal_Bool bRet = SfxObjectShell::SaveCompleted( xStor );
     739          35 :     if( bRet )
     740             :     {
     741             :         // Do not decide until here, whether Saving was successful or not
     742          35 :         if( IsModified() )
     743           3 :             pDoc->SetModified();
     744             :         else
     745          32 :             pDoc->ResetModified();
     746             :     }
     747             : 
     748          35 :     if( pOLEChildList )
     749             :     {
     750           0 :         sal_Bool bResetModified = IsEnableSetModified();
     751           0 :         if( bResetModified )
     752           0 :             EnableSetModified( sal_False );
     753             : 
     754           0 :         uno::Sequence < OUString > aNames = pOLEChildList->GetObjectNames();
     755           0 :         for( sal_Int32 n = aNames.getLength(); n; n-- )
     756             :         {
     757           0 :             if ( !pOLEChildList->MoveEmbeddedObject( aNames[n-1], GetEmbeddedObjectContainer() ) )
     758             :             {
     759             :                 OSL_FAIL("Copying of objects didn't work!" );
     760             :             }
     761             :         }
     762             : 
     763           0 :         DELETEZ( pOLEChildList );
     764           0 :         if( bResetModified )
     765           0 :             EnableSetModified( sal_True );
     766             :     }
     767          35 :     return bRet;
     768             : }
     769             : 
     770             : // Draw()-Overload for OLE2 (Sfx)
     771          15 : void SwDocShell::Draw( OutputDevice* pDev, const JobSetup& rSetup,
     772             :                                sal_uInt16 nAspect )
     773             : {
     774             :     //fix #25341# Draw should not affect the Modified
     775             :     sal_Bool bResetModified;
     776          15 :     if ( sal_True == (bResetModified = IsEnableSetModified()) )
     777           0 :         EnableSetModified( sal_False );
     778             : 
     779             :     // When there is a JobSetup connected to the Document, we copy it to
     780             :     // reconnect it after PrtOle2. We don't use an empty JobSetup because
     781             :     // that would only lead to questionable results after expensive
     782             :     // reformatting (Preview!)
     783          15 :     JobSetup *pOrig = 0;
     784          15 :     if ( !rSetup.GetPrinterName().isEmpty() && ASPECT_THUMBNAIL != nAspect )
     785             :     {
     786           0 :         pOrig = const_cast<JobSetup*>(pDoc->getJobsetup());
     787           0 :         if( pOrig )         // then we copy that
     788           0 :             pOrig = new JobSetup( *pOrig );
     789           0 :         pDoc->setJobsetup( rSetup );
     790             :     }
     791             : 
     792             :     Rectangle aRect( nAspect == ASPECT_THUMBNAIL ?
     793          15 :             GetVisArea( nAspect ) : GetVisArea( ASPECT_CONTENT ) );
     794             : 
     795          15 :     pDev->Push();
     796          15 :     pDev->SetFillColor();
     797          15 :     pDev->SetLineColor();
     798          15 :     pDev->SetBackground();
     799          15 :     sal_Bool bWeb = 0 != PTR_CAST(SwWebDocShell, this);
     800          15 :     SwPrintData aOpts;
     801          15 :     ViewShell::PrtOle2( pDoc, SW_MOD()->GetUsrPref(bWeb), aOpts, pDev, aRect );
     802          15 :     pDev->Pop();
     803             : 
     804          15 :     if( pOrig )
     805             :     {
     806           0 :         pDoc->setJobsetup( *pOrig );
     807           0 :         delete pOrig;
     808             :     }
     809          15 :     if ( bResetModified )
     810           0 :         EnableSetModified( sal_True );
     811          15 : }
     812             : 
     813             : 
     814         108 : void SwDocShell::SetVisArea( const Rectangle &rRect )
     815             : {
     816         108 :     Rectangle aRect( rRect );
     817         108 :     if ( pView )
     818             :     {
     819           0 :         Size aSz( pView->GetDocSz() );
     820           0 :         aSz.Width() += DOCUMENTBORDER; aSz.Height() += DOCUMENTBORDER;
     821           0 :         long nMoveX = 0, nMoveY = 0;
     822           0 :         if ( aRect.Right() > aSz.Width() )
     823           0 :             nMoveX = aSz.Width() - aRect.Right();
     824           0 :         if ( aRect.Bottom() > aSz.Height() )
     825           0 :             nMoveY = aSz.Height() - aRect.Bottom();
     826           0 :         aRect.Move( nMoveX, nMoveY );
     827           0 :         nMoveX = aRect.Left() < 0 ? -aRect.Left() : 0;
     828           0 :         nMoveY = aRect.Top()  < 0 ? -aRect.Top()  : 0;
     829           0 :         aRect.Move( nMoveX, nMoveY );
     830             : 
     831             :         // Calls SfxInPlaceObject::SetVisArea()!
     832           0 :         pView->SetVisArea( aRect, sal_True );
     833             :     }
     834             :     else
     835         108 :         SfxObjectShell::SetVisArea( aRect );
     836         108 : }
     837             : 
     838             : 
     839        3555 : Rectangle SwDocShell::GetVisArea( sal_uInt16 nAspect ) const
     840             : {
     841        3555 :     if ( nAspect == ASPECT_THUMBNAIL )
     842             :     {
     843             :         // PreView: set VisArea to the first page.
     844          60 :         SwNodeIndex aIdx( pDoc->GetNodes().GetEndOfExtras(), 1 );
     845          60 :         SwCntntNode* pNd = pDoc->GetNodes().GoNext( &aIdx );
     846             : 
     847          60 :         const SwRect aPageRect = pNd->FindPageFrmRect( sal_False, 0, sal_False );
     848          60 :         return aPageRect.SVRect();
     849             :     }
     850        3495 :     return SfxObjectShell::GetVisArea( nAspect );
     851             : }
     852             : 
     853        1186 : Printer *SwDocShell::GetDocumentPrinter()
     854             : {
     855        1186 :     return pDoc->getPrinter( false );
     856             : }
     857             : 
     858         297 : OutputDevice* SwDocShell::GetDocumentRefDev()
     859             : {
     860         297 :     return pDoc->getReferenceDevice( false );
     861             : }
     862             : 
     863           0 : void SwDocShell::OnDocumentPrinterChanged( Printer * pNewPrinter )
     864             : {
     865           0 :     if ( pNewPrinter )
     866           0 :         GetDoc()->setJobsetup( pNewPrinter->GetJobSetup() );
     867             :     else
     868           0 :         GetDoc()->setPrinter( 0, true, true );
     869           0 : }
     870             : 
     871          10 : sal_uLong SwDocShell::GetMiscStatus() const
     872             : {
     873          10 :     return SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE;
     874             : }
     875             : 
     876             : // #i20883# Digital Signatures and Encryption
     877           0 : sal_uInt16 SwDocShell::GetHiddenInformationState( sal_uInt16 nStates )
     878             : {
     879             :     // get global state like HIDDENINFORMATION_DOCUMENTVERSIONS
     880           0 :     sal_uInt16 nState = SfxObjectShell::GetHiddenInformationState( nStates );
     881             : 
     882           0 :     if ( nStates & HIDDENINFORMATION_RECORDEDCHANGES )
     883             :     {
     884           0 :         if ( !GetDoc()->GetRedlineTbl().empty() )
     885           0 :             nState |= HIDDENINFORMATION_RECORDEDCHANGES;
     886             :     }
     887           0 :     if ( nStates & HIDDENINFORMATION_NOTES )
     888             :     {
     889             :         OSL_ENSURE( GetWrtShell(), "No SwWrtShell, no information" );
     890           0 :         if ( GetWrtShell() )
     891             :         {
     892           0 :             SwFieldType* pType = GetWrtShell()->GetFldType( RES_POSTITFLD, aEmptyStr );
     893           0 :             SwIterator<SwFmtFld,SwFieldType> aIter( *pType );
     894           0 :             SwFmtFld* pFirst = aIter.First();
     895           0 :             while( pFirst )
     896             :             {
     897           0 :                 if( pFirst->GetTxtFld() && pFirst->IsFldInDoc() )
     898             :                 {
     899           0 :                     nState |= HIDDENINFORMATION_NOTES;
     900           0 :                     break;
     901             :                 }
     902           0 :                 pFirst = aIter.Next();
     903           0 :             }
     904             :         }
     905             :     }
     906             : 
     907           0 :     return nState;
     908             : }
     909             : 
     910             : 
     911        1547 : void SwDocShell::GetState(SfxItemSet& rSet)
     912             : {
     913        1547 :     SfxWhichIter aIter(rSet);
     914        1547 :     sal_uInt16  nWhich  = aIter.FirstWhich();
     915             : 
     916        5452 :     while (nWhich)
     917             :     {
     918        2358 :         switch (nWhich)
     919             :         {
     920             :         case SID_PRINTPREVIEW:
     921             :         {
     922        1179 :             sal_Bool bDisable = IsInPlaceActive();
     923             :             // Disable "multiple layout"
     924        1179 :             if ( !bDisable )
     925             :             {
     926        1179 :                 SfxViewFrame *pTmpFrm = SfxViewFrame::GetFirst(this);
     927        3527 :                 while (pTmpFrm)     // Look for Preview
     928             :                 {
     929        2358 :                     if ( PTR_CAST(SwView, pTmpFrm->GetViewShell()) &&
     930        1179 :                          ((SwView*)pTmpFrm->GetViewShell())->GetWrtShell().GetViewOptions()->getBrowseMode() )
     931             :                     {
     932          10 :                         bDisable = sal_True;
     933          10 :                         break;
     934             :                     }
     935        1169 :                     pTmpFrm = pTmpFrm->GetNext(*pTmpFrm, this);
     936             :                 }
     937             :             }
     938             :             // End of disabled "multiple layout"
     939        1179 :             if ( bDisable )
     940          10 :                 rSet.DisableItem( SID_PRINTPREVIEW );
     941             :             else
     942             :             {
     943        1169 :                 SfxBoolItem aBool( SID_PRINTPREVIEW, sal_False );
     944        1169 :                 if( PTR_CAST( SwPagePreView, SfxViewShell::Current()) )
     945           0 :                     aBool.SetValue( sal_True );
     946        1169 :                 rSet.Put( aBool );
     947             :             }
     948             :         }
     949        1179 :         break;
     950             :         case SID_SOURCEVIEW:
     951             :         {
     952           2 :             SfxViewShell* pCurrView = GetView() ? (SfxViewShell*)GetView()
     953           2 :                                         : SfxViewShell::Current();
     954           2 :             sal_Bool bSourceView = 0 != PTR_CAST(SwSrcView, pCurrView);
     955           2 :             rSet.Put(SfxBoolItem(SID_SOURCEVIEW, bSourceView));
     956             :         }
     957           2 :         break;
     958             :         case SID_HTML_MODE:
     959           0 :             rSet.Put(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(this)));
     960           0 :         break;
     961             : 
     962             :         case FN_ABSTRACT_STARIMPRESS:
     963             :         case FN_OUTLINE_TO_IMPRESS:
     964             :             {
     965           0 :                 SvtModuleOptions aMOpt;
     966           0 :                 if ( !aMOpt.IsImpress() )
     967           0 :                     rSet.DisableItem( nWhich );
     968             :             }
     969             :             /* no break here */
     970             :         case FN_ABSTRACT_NEWDOC:
     971             :         case FN_OUTLINE_TO_CLIPBOARD:
     972             :             {
     973           0 :                 if ( GetDoc()->GetNodes().GetOutLineNds().empty() )
     974           0 :                     rSet.DisableItem( nWhich );
     975             :             }
     976           0 :             break;
     977             :         case SID_BROWSER_MODE:
     978             :         case FN_PRINT_LAYOUT:
     979             :             {
     980           0 :                 sal_Bool bState = GetDoc()->get(IDocumentSettingAccess::BROWSE_MODE);
     981           0 :                 if(FN_PRINT_LAYOUT == nWhich)
     982           0 :                     bState = !bState;
     983           0 :                 rSet.Put( SfxBoolItem( nWhich, bState));
     984             :             }
     985           0 :             break;
     986             : 
     987             :         case FN_NEW_GLOBAL_DOC:
     988           0 :             if ( ISA(SwGlobalDocShell) )
     989           0 :                 rSet.DisableItem( nWhich );
     990           0 :             break;
     991             : 
     992             :         case FN_NEW_HTML_DOC:
     993           0 :             if( ISA( SwWebDocShell ) )
     994           0 :                 rSet.DisableItem( nWhich );
     995           0 :             break;
     996             : 
     997             :         case FN_OPEN_FILE:
     998        1177 :             if( ISA( SwWebDocShell ) )
     999           0 :                 rSet.DisableItem( nWhich );
    1000        1177 :             break;
    1001             : 
    1002             :         case SID_ATTR_YEAR2000:
    1003             :             {
    1004           0 :                 const SvNumberFormatter* pFmtr = pDoc->GetNumberFormatter(sal_False);
    1005             :                 rSet.Put( SfxUInt16Item( nWhich,
    1006             :                         static_cast< sal_uInt16 >(
    1007           0 :                         pFmtr ? pFmtr->GetYear2000()
    1008           0 :                               : ::utl::MiscCfg().GetYear2000() )));
    1009             :             }
    1010           0 :             break;
    1011             :         case SID_ATTR_CHAR_FONTLIST:
    1012             :         {
    1013           0 :             rSet.Put( SvxFontListItem( pFontList, SID_ATTR_CHAR_FONTLIST ) );
    1014             :         }
    1015           0 :         break;
    1016             :         case SID_MAIL_PREPAREEXPORT:
    1017             :         {
    1018             :             //check if linked content or possibly hidden content is available
    1019             :             //pDoc->UpdateFlds( NULL, false );
    1020           0 :             sfx2::LinkManager& rLnkMgr = pDoc->GetLinkManager();
    1021           0 :             const ::sfx2::SvBaseLinks& rLnks = rLnkMgr.GetLinks();
    1022           0 :             sal_Bool bRet = sal_False;
    1023           0 :             if( !rLnks.empty() )
    1024           0 :                 bRet = sal_True;
    1025             :             else
    1026             :             {
    1027             :                 //sections with hidden flag, hidden character attribute, hidden paragraph/text or conditional text fields
    1028           0 :                 bRet = pDoc->HasInvisibleContent();
    1029             :             }
    1030           0 :             rSet.Put( SfxBoolItem( nWhich, bRet ) );
    1031             :         }
    1032           0 :         break;
    1033             : 
    1034             :         default: OSL_ENSURE(!this,"You cannot get here!");
    1035             : 
    1036             :         }
    1037        2358 :         nWhich = aIter.NextWhich();
    1038        1547 :     }
    1039        1547 : }
    1040             : 
    1041             : // OLE-Hdls
    1042      111006 : IMPL_LINK( SwDocShell, Ole2ModifiedHdl, void *, p )
    1043             : {
    1044             :     // the Status is handed over from Doc (see doc.cxx)
    1045             :     //  Bit 0:  -> old state
    1046             :     //  Bit 1:  -> new state
    1047       55503 :     sal_IntPtr nStatus = (sal_IntPtr)p;
    1048       55503 :     if( IsEnableSetModified() )
    1049       16159 :         SetModified( (nStatus & 2) ? sal_True : sal_False );
    1050       55503 :     return 0;
    1051             : }
    1052             : 
    1053             : // return Pool here, because virtual
    1054        9292 : SfxStyleSheetBasePool*  SwDocShell::GetStyleSheetPool()
    1055             : {
    1056        9292 :     return mxBasePool.get();
    1057             : }
    1058             : 
    1059             : 
    1060        2365 : void SwDocShell::SetView(SwView* pVw)
    1061             : {
    1062        2365 :     if ( 0 != (pView = pVw) )
    1063        1573 :         pWrtShell = &pView->GetWrtShell();
    1064             :     else
    1065         792 :         pWrtShell = 0;
    1066        2365 : }
    1067             : 
    1068             : 
    1069           0 : void SwDocShell::PrepareReload()
    1070             : {
    1071           0 :     ::DelAllGrfCacheEntries( pDoc );
    1072           0 : }
    1073             : 
    1074             : // #i59688#
    1075             : // linked graphics are now loaded on demand.
    1076             : // Thus, loading of linked graphics no longer needed and necessary for
    1077             : // the load of document being finished.
    1078         105 : void SwDocShell::LoadingFinished()
    1079             : {
    1080             :     // #i38810#
    1081             :     // Original fix fails after integration of cws xmlsec11:
    1082             :     // interface <SfxObjectShell::EnableSetModified(..)> no longer works, because
    1083             :     // <SfxObjectShell::FinishedLoading(..)> doesn't care about its status and
    1084             :     // enables the document modification again.
    1085             :     // Thus, manuell modify the document, if its modified and its links are updated
    1086             :     // before <FinishedLoading(..)> is called.
    1087         105 :     const bool bHasDocToStayModified( pDoc->IsModified() && pDoc->LinksUpdated() );
    1088             : 
    1089         105 :     FinishedLoading( SFX_LOADED_ALL );
    1090         105 :     SfxViewFrame* pVFrame = SfxViewFrame::GetFirst(this);
    1091         105 :     if(pVFrame)
    1092             :     {
    1093           0 :         SfxViewShell* pShell = pVFrame->GetViewShell();
    1094           0 :         if(PTR_CAST(SwSrcView, pShell))
    1095           0 :             ((SwSrcView*)pShell)->Load(this);
    1096             :     }
    1097             : 
    1098             :     // #i38810#
    1099         105 :     if ( bHasDocToStayModified && !pDoc->IsModified() )
    1100             :     {
    1101           0 :         pDoc->SetModified();
    1102             :     }
    1103         105 : }
    1104             : 
    1105             : // a Transfer is cancelled (is called from SFX)
    1106         789 : void SwDocShell::CancelTransfers()
    1107             : {
    1108             :     // Cancel all links from LinkManager
    1109         789 :     aFinishedTimer.Stop();
    1110         789 :     pDoc->GetLinkManager().CancelTransfers();
    1111         789 :     SfxObjectShell::CancelTransfers();
    1112         789 : }
    1113             : 
    1114           0 : SwFEShell* SwDocShell::GetFEShell()
    1115             : {
    1116           0 :     return pWrtShell;
    1117             : }
    1118             : 
    1119           0 : void SwDocShell::RemoveOLEObjects()
    1120             : {
    1121           0 :     SwIterator<SwCntntNode,SwFmtColl> aIter( *pDoc->GetDfltGrfFmtColl() );
    1122           0 :     for( SwCntntNode* pNd = aIter.First(); pNd; pNd = aIter.Next() )
    1123             :     {
    1124           0 :         SwOLENode* pOLENd = pNd->GetOLENode();
    1125           0 :         if( pOLENd && ( pOLENd->IsOLEObjectDeleted() ||
    1126           0 :                         pOLENd->IsInGlobalDocSection() ) )
    1127             :         {
    1128           0 :             if( !pOLEChildList )
    1129           0 :                 pOLEChildList = new comphelper::EmbeddedObjectContainer;
    1130             : 
    1131           0 :             OUString aObjName = pOLENd->GetOLEObj().GetCurrentPersistName();
    1132           0 :             GetEmbeddedObjectContainer().MoveEmbeddedObject( aObjName, *pOLEChildList );
    1133             :         }
    1134           0 :     }
    1135           0 : }
    1136             : 
    1137             : // When a document is loaded, SwDoc::PrtOLENotify is called to update
    1138             : // the sizes of math objects. However, for objects that do not have a
    1139             : // SwFrm at this time, only a flag is set (bIsOLESizeInvalid) and the
    1140             : // size change takes place later, while calculating the layout in the
    1141             : // idle handler. If this document is saved now, it is saved with invalid
    1142             : // sizes. For this reason, the layout has to be calculated before a document is
    1143             : // saved, but of course only id there are OLE objects with bOLESizeInvalid set.
    1144          26 : void SwDocShell::CalcLayoutForOLEObjects()
    1145             : {
    1146          26 :     if( !pWrtShell )
    1147          27 :         return;
    1148             : 
    1149          25 :     SwIterator<SwCntntNode,SwFmtColl> aIter( *pDoc->GetDfltGrfFmtColl() );
    1150          34 :     for( SwCntntNode* pNd = aIter.First(); pNd; pNd = aIter.Next() )
    1151             :     {
    1152           9 :         SwOLENode* pOLENd = pNd->GetOLENode();
    1153           9 :         if( pOLENd && pOLENd->IsOLESizeInvalid() )
    1154             :         {
    1155           0 :             pWrtShell->CalcLayout();
    1156           0 :             break;
    1157             :         }
    1158          25 :     }
    1159             : }
    1160             : 
    1161             : 
    1162             : // #i42634# Overwrites SfxObjectShell::UpdateLinks
    1163             : // This new function is necessary to trigger update of links in docs
    1164             : // read by the binary filter:
    1165         340 : void SwDocShell::UpdateLinks()
    1166             : {
    1167         340 :     GetDoc()->UpdateLinks(true);
    1168             :     // #i50703# Update footnote numbers
    1169         340 :     SwTxtFtn::SetUniqueSeqRefNo( *GetDoc() );
    1170         340 :     SwNodeIndex aTmp( GetDoc()->GetNodes() );
    1171         340 :     GetDoc()->GetFtnIdxs().UpdateFtn( aTmp );
    1172         340 : }
    1173             : 
    1174             : uno::Reference< frame::XController >
    1175           0 :                                 SwDocShell::GetController()
    1176             : {
    1177           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > aRet;
    1178             :     // #i82346# No view in page preview
    1179           0 :     if ( GetView() )
    1180           0 :         aRet = GetView()->GetController();
    1181           0 :     return aRet;
    1182             : }
    1183             : 
    1184             : static const char* s_EventNames[] =
    1185             : {
    1186             :     "OnPageCountChange",
    1187             :     "OnMailMerge",
    1188             :     "OnMailMergeFinished",
    1189             :     "OnFieldMerge",
    1190             :     "OnFieldMergeFinished",
    1191             :     "OnLayoutFinished"
    1192             : };
    1193             : static sal_Int32 const s_nEvents(sizeof(s_EventNames)/sizeof(s_EventNames[0]));
    1194             : 
    1195          18 : Sequence< OUString >    SwDocShell::GetEventNames()
    1196             : {
    1197          18 :     Sequence< OUString > aRet = SfxObjectShell::GetEventNames();
    1198          18 :     sal_Int32 nLen = aRet.getLength();
    1199          18 :     aRet.realloc(nLen + 6);
    1200          18 :     OUString* pNames = aRet.getArray();
    1201          18 :     pNames[nLen++] = GetEventName(0);
    1202          18 :     pNames[nLen++] = GetEventName(1);
    1203          18 :     pNames[nLen++] = GetEventName(2);
    1204          18 :     pNames[nLen++] = GetEventName(3);
    1205          18 :     pNames[nLen++] = GetEventName(4);
    1206          18 :     pNames[nLen]   = GetEventName(5);
    1207             : 
    1208          18 :     return aRet;
    1209             : }
    1210             : 
    1211         904 : OUString SwDocShell::GetEventName( sal_Int32 nIndex )
    1212             : {
    1213         904 :     if (nIndex < s_nEvents)
    1214             :     {
    1215         904 :         return OUString::createFromAscii(s_EventNames[nIndex]);
    1216             :     }
    1217           0 :     return OUString();
    1218             : }
    1219             : 
    1220           1 : const ::sfx2::IXmlIdRegistry* SwDocShell::GetXmlIdRegistry() const
    1221             : {
    1222           1 :     return pDoc ? &pDoc->GetXmlIdRegistry() : 0;
    1223             : }
    1224             : 
    1225             : 
    1226           0 : bool SwDocShell::IsChangeRecording() const
    1227             : {
    1228           0 :     return (pWrtShell->GetRedlineMode() & nsRedlineMode_t::REDLINE_ON) != 0;
    1229             : }
    1230             : 
    1231             : 
    1232           0 : bool SwDocShell::HasChangeRecordProtection() const
    1233             : {
    1234           0 :     return pWrtShell->getIDocumentRedlineAccess()->GetRedlinePassword().getLength() > 0;
    1235             : }
    1236             : 
    1237             : 
    1238           0 : void SwDocShell::SetChangeRecording( bool bActivate )
    1239             : {
    1240           0 :     sal_uInt16 nOn = bActivate ? nsRedlineMode_t::REDLINE_ON : 0;
    1241           0 :     sal_uInt16 nMode = pWrtShell->GetRedlineMode();
    1242           0 :     pWrtShell->SetRedlineModeAndCheckInsMode( (nMode & ~nsRedlineMode_t::REDLINE_ON) | nOn);
    1243           0 : }
    1244             : 
    1245             : 
    1246           0 : bool SwDocShell::SetProtectionPassword( const String &rNewPassword )
    1247             : {
    1248           0 :     const SfxAllItemSet aSet( GetPool() );
    1249           0 :     const SfxItemSet*   pArgs = &aSet;
    1250           0 :     const SfxPoolItem*  pItem = NULL;
    1251             : 
    1252           0 :     IDocumentRedlineAccess* pIDRA = pWrtShell->getIDocumentRedlineAccess();
    1253           0 :     Sequence< sal_Int8 > aPasswd = pIDRA->GetRedlinePassword();
    1254           0 :     if (pArgs && SFX_ITEM_SET == pArgs->GetItemState( FN_REDLINE_PROTECT, sal_False, &pItem )
    1255           0 :         && ((SfxBoolItem*)pItem)->GetValue() == (aPasswd.getLength() > 0))
    1256           0 :         return false;
    1257             : 
    1258           0 :     bool bRes = false;
    1259             : 
    1260           0 :     if (rNewPassword.Len())
    1261             :     {
    1262             :         // when password protection is applied change tracking must always be active
    1263           0 :         SetChangeRecording( true );
    1264             : 
    1265           0 :         Sequence< sal_Int8 > aNewPasswd;
    1266           0 :         SvPasswordHelper::GetHashPassword( aNewPasswd, rNewPassword );
    1267           0 :         pIDRA->SetRedlinePassword( aNewPasswd );
    1268           0 :         bRes = true;
    1269             :     }
    1270             :     else
    1271             :     {
    1272           0 :         pIDRA->SetRedlinePassword( Sequence< sal_Int8 >() );
    1273           0 :         bRes = true;
    1274             :     }
    1275             : 
    1276           0 :     return bRes;
    1277             : }
    1278             : 
    1279             : 
    1280           0 : bool SwDocShell::GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal_Int8 > &rPasswordHash )
    1281             : {
    1282           0 :     bool bRes = false;
    1283             : 
    1284           0 :     const SfxAllItemSet aSet( GetPool() );
    1285           0 :     const SfxItemSet*   pArgs = &aSet;
    1286           0 :     const SfxPoolItem*  pItem = NULL;
    1287             : 
    1288           0 :     IDocumentRedlineAccess* pIDRA = pWrtShell->getIDocumentRedlineAccess();
    1289           0 :     Sequence< sal_Int8 > aPasswdHash( pIDRA->GetRedlinePassword() );
    1290           0 :     if (pArgs && SFX_ITEM_SET == pArgs->GetItemState( FN_REDLINE_PROTECT, sal_False, &pItem )
    1291           0 :         && ((SfxBoolItem*)pItem)->GetValue() == (aPasswdHash.getLength() != 0))
    1292           0 :         return false;
    1293           0 :     rPasswordHash = aPasswdHash;
    1294           0 :     bRes = true;
    1295             : 
    1296           0 :     return bRes;
    1297          99 : }
    1298             : 
    1299             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10