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

Generated by: LCOV version 1.10