LCOV - code coverage report
Current view: top level - sw/source/uibase/app - docsh2.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 148 772 19.2 %
Date: 2015-06-13 12:38:46 Functions: 13 21 61.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             : #include <config_features.h>
      21             : 
      22             : #include <com/sun/star/drawing/ModuleDispatcher.hpp>
      23             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      24             : #include <com/sun/star/frame/DispatchHelper.hpp>
      25             : 
      26             : #include <comphelper/processfactory.hxx>
      27             : 
      28             : #include <edtwin.hxx>
      29             : #include <hintids.hxx>
      30             : #include <tools/urlobj.hxx>
      31             : #include <unotools/tempfile.hxx>
      32             : #include <vcl/wrkwin.hxx>
      33             : #include <vcl/msgbox.hxx>
      34             : #include <svl/lckbitem.hxx>
      35             : #include <svl/eitem.hxx>
      36             : #include <svl/zforlist.hxx>
      37             : #include <svl/zformat.hxx>
      38             : #include <unotools/pathoptions.hxx>
      39             : #include <svtools/transfer.hxx>
      40             : #include <sfx2/dialogs.hrc>
      41             : #include <sfx2/dinfdlg.hxx>
      42             : #include <sfx2/request.hxx>
      43             : #include <sfx2/dispatch.hxx>
      44             : #include <sfx2/new.hxx>
      45             : #include <sfx2/filedlghelper.hxx>
      46             : #include <sfx2/printer.hxx>
      47             : #include <sfx2/evntconf.hxx>
      48             : #include <svtools/sfxecode.hxx>
      49             : #include <sfx2/docfile.hxx>
      50             : #include <sfx2/docfilt.hxx>
      51             : #include <svx/svxids.hrc>
      52             : #include <svx/drawitem.hxx>
      53             : #include <editeng/svxacorr.hxx>
      54             : #include <editeng/langitem.hxx>
      55             : #include <svx/fmshell.hxx>
      56             : #include <sfx2/linkmgr.hxx>
      57             : 
      58             : #include <svtools/htmlcfg.hxx>
      59             : #include <svx/ofaitem.hxx>
      60             : #include <SwSmartTagMgr.hxx>
      61             : #include <sfx2/app.hxx>
      62             : #include <basic/sbstar.hxx>
      63             : #include <basic/basmgr.hxx>
      64             : #include <sot/storage.hxx>
      65             : #include <comphelper/classids.hxx>
      66             : #include <fmtcol.hxx>
      67             : #include <swevent.hxx>
      68             : #include <view.hxx>
      69             : #include <docsh.hxx>
      70             : #include <docary.hxx>
      71             : #include <wrtsh.hxx>
      72             : #include <fldbas.hxx>
      73             : #include <viewopt.hxx>
      74             : #include <globdoc.hxx>
      75             : #include <fldwrap.hxx>
      76             : #include <redlndlg.hxx>
      77             : #include <docstyle.hxx>
      78             : #include <doc.hxx>
      79             : #include <IDocumentUndoRedo.hxx>
      80             : #include <IDocumentSettingAccess.hxx>
      81             : #include <IDocumentDeviceAccess.hxx>
      82             : #include <IDocumentLinksAdministration.hxx>
      83             : #include <IDocumentFieldsAccess.hxx>
      84             : #include <IDocumentStatistics.hxx>
      85             : #include <IDocumentLayoutAccess.hxx>
      86             : #include <IDocumentState.hxx>
      87             : #include <pagedesc.hxx>
      88             : #include <shellio.hxx>
      89             : #include <pview.hxx>
      90             : #include <srcview.hxx>
      91             : #include <poolfmt.hxx>
      92             : #include <usrpref.hxx>
      93             : #include <wdocsh.hxx>
      94             : #include <unotxdoc.hxx>
      95             : #include <acmplwrd.hxx>
      96             : #include <swmodule.hxx>
      97             : #include <unobaseclass.hxx>
      98             : #include <swwait.hxx>
      99             : #include <swcli.hxx>
     100             : 
     101             : #include <cmdid.h>
     102             : #include <globals.h>
     103             : #include <helpid.h>
     104             : #include <app.hrc>
     105             : #include <poolfmt.hrc>
     106             : #include <globals.hrc>
     107             : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
     108             : #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
     109             : #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
     110             : #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
     111             : #include <com/sun/star/ui/dialogs/ListboxControlActions.hpp>
     112             : #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
     113             : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
     114             : #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
     115             : #include <com/sun/star/script/vba/VBAEventId.hpp>
     116             : #include <editeng/acorrcfg.hxx>
     117             : #include <SwStyleNameMapper.hxx>
     118             : #include <officecfg/Office/Security.hxx>
     119             : 
     120             : #include <sfx2/fcontnr.hxx>
     121             : 
     122             : #include "dialog.hrc"
     123             : #include "swabstdlg.hxx"
     124             : 
     125             : #include <ndtxt.hxx>
     126             : 
     127             : #include <boost/scoped_ptr.hpp>
     128             : 
     129             : using namespace ::com::sun::star::ui::dialogs;
     130             : using namespace ::com::sun::star::lang;
     131             : using namespace ::com::sun::star::uno;
     132             : using namespace ::com::sun::star;
     133             : using namespace ::sfx2;
     134             : 
     135             : // create DocInfo (virtual)
     136           0 : VclPtr<SfxDocumentInfoDialog> SwDocShell::CreateDocumentInfoDialog(
     137             :                                 vcl::Window *pParent, const SfxItemSet &rSet)
     138             : {
     139           0 :     VclPtr<SfxDocumentInfoDialog> pDlg = VclPtr<SfxDocumentInfoDialog>::Create(pParent, rSet);
     140             :     //only with statistics, when this document is being shown, not
     141             :     //from within the Doc-Manager
     142           0 :     SwDocShell* pDocSh = static_cast<SwDocShell*>( SfxObjectShell::Current());
     143           0 :     if( pDocSh == this )
     144             :     {
     145             :         //Not for SourceView.
     146           0 :         SfxViewShell *pVSh = SfxViewShell::Current();
     147           0 :         if ( pVSh && !pVSh->ISA(SwSrcView) )
     148             :         {
     149           0 :             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
     150             :             OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
     151           0 :             pDlg->AddFontTabPage();
     152           0 :             pDlg->AddTabPage(TP_DOC_STAT, SW_RESSTR(STR_DOC_STAT),pFact->GetTabPageCreatorFunc( TP_DOC_STAT ),0);
     153             :         }
     154             :     }
     155           0 :     return pDlg;
     156             : }
     157             : 
     158             : // Disable "multiple layout"
     159             : 
     160           1 : void SwDocShell::ToggleBrowserMode(bool bSet, SwView* _pView )
     161             : {
     162           1 :     GetDoc()->getIDocumentSettingAccess().set(DocumentSettingId::BROWSE_MODE, bSet );
     163           1 :     UpdateFontList();
     164           1 :     SwView* pTempView = _pView ? _pView : GetView();
     165           1 :     if( pTempView )
     166             :     {
     167           1 :         pTempView->GetViewFrame()->GetBindings().Invalidate(FN_SHADOWCURSOR);
     168           1 :         if( !GetDoc()->getIDocumentDeviceAccess().getPrinter( false ) )
     169           1 :             pTempView->SetPrinter( GetDoc()->getIDocumentDeviceAccess().getPrinter( false ), SfxPrinterChangeFlags::PRINTER | SfxPrinterChangeFlags::JOBSETUP );
     170           1 :         GetDoc()->CheckDefaultPageFormat();
     171           1 :         SfxViewFrame *pTmpFrm = SfxViewFrame::GetFirst(this, false);
     172           3 :         while (pTmpFrm)
     173             :         {
     174           1 :             if( pTmpFrm != pTempView->GetViewFrame() )
     175             :             {
     176           0 :                 pTmpFrm->DoClose();
     177           0 :                 pTmpFrm = SfxViewFrame::GetFirst(this, false);
     178             :             }
     179             :             else
     180           1 :                 pTmpFrm = SfxViewFrame::GetNext(*pTmpFrm, this, false);
     181             :         }
     182           1 :         const SwViewOption& rViewOptions = *pTempView->GetWrtShell().GetViewOptions();
     183           1 :         pTempView->GetWrtShell().CheckBrowseView( true );
     184           1 :         pTempView->CheckVisArea();
     185           1 :         if( bSet )
     186             :         {
     187           1 :             const SvxZoomType eType = (SvxZoomType)rViewOptions.GetZoomType();
     188           1 :             if ( SvxZoomType::PERCENT != eType)
     189           0 :                 static_cast<SwView*>(GetView())->SetZoom( eType );
     190             :         }
     191           1 :         pTempView->InvalidateBorder();
     192           1 :         pTempView->SetNewWindowAllowed(!bSet);
     193             :     }
     194           1 : }
     195             : // End of disabled "multiple layout"
     196             : 
     197             : // update text fields on document properties changes
     198        1812 : void SwDocShell::DoFlushDocInfo()
     199             : {
     200        3624 :     if (!m_pDoc) return;
     201             : 
     202        1812 :     bool bUnlockView(true);
     203        1812 :     if (m_pWrtShell)
     204             :     {
     205        1726 :         bUnlockView = !m_pWrtShell->IsViewLocked();
     206        1726 :         m_pWrtShell->LockView( true );    // lock visible section
     207        1726 :         m_pWrtShell->StartAllAction();
     208             :     }
     209             : 
     210        1812 :     m_pDoc->getIDocumentStatistics().DocInfoChgd();
     211             : 
     212        1812 :     if (m_pWrtShell)
     213             :     {
     214        1726 :         m_pWrtShell->EndAllAction();
     215        1726 :         if (bUnlockView)
     216             :         {
     217        1694 :             m_pWrtShell->LockView( false );
     218             :         }
     219             :     }
     220             : }
     221             : 
     222           0 : static void lcl_processCompatibleSfxHint( const uno::Reference< script::vba::XVBAEventProcessor >& xVbaEvents, const SfxHint& rHint )
     223             : {
     224             :     using namespace com::sun::star::script::vba::VBAEventId;
     225           0 :     if ( dynamic_cast<const SfxEventHint*>(&rHint) )
     226             :     {
     227           0 :         uno::Sequence< uno::Any > aArgs;
     228           0 :         sal_uLong nEventId = static_cast<const SfxEventHint&>(rHint).GetEventId();
     229           0 :         switch( nEventId )
     230             :         {
     231             :             case SFX_EVENT_CREATEDOC:
     232           0 :                 xVbaEvents->processVbaEvent( DOCUMENT_NEW, aArgs );
     233           0 :             break;
     234             :             case SFX_EVENT_OPENDOC:
     235           0 :                 xVbaEvents->processVbaEvent( DOCUMENT_OPEN, aArgs );
     236           0 :             break;
     237           0 :         }
     238             :     }
     239           0 : }
     240             : 
     241             : // Notification on DocInfo changes
     242      178898 : void SwDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
     243             : {
     244      178898 :     if (!m_pDoc)
     245             :     {
     246      178907 :         return ;
     247             :     }
     248             : 
     249             :     uno::Reference< script::vba::XVBAEventProcessor > const xVbaEvents =
     250      178889 :         m_pDoc->GetVbaEventProcessor();
     251      178889 :     if( xVbaEvents.is() )
     252           0 :         lcl_processCompatibleSfxHint( xVbaEvents, rHint );
     253             : 
     254      178889 :     sal_uInt16 nAction = 0;
     255      311491 :     if( dynamic_cast<const SfxSimpleHint*>(&rHint) )
     256             :     {
     257             :         // switch for more actions
     258      132602 :         switch( static_cast<const SfxSimpleHint&>( rHint).GetId() )
     259             :         {
     260             :             case SFX_HINT_TITLECHANGED:
     261        8668 :                 if( GetMedium() )
     262        8668 :                     nAction = 2;
     263        8668 :             break;
     264             :         }
     265             :     }
     266       71750 :     else if( dynamic_cast<const SfxEventHint*>(&rHint) &&
     267       46287 :         static_cast<const SfxEventHint&>( rHint).GetEventId() == SFX_EVENT_LOADFINISHED )
     268             :     {
     269             :         // #i38126# - own action id
     270        2404 :         nAction = 3;
     271             :     }
     272             : 
     273      178889 :     if( nAction )
     274             :     {
     275       11072 :         bool bUnlockView = true; //initializing prevents warning
     276       11072 :         if (m_pWrtShell)
     277             :         {
     278        3892 :             bUnlockView = !m_pWrtShell->IsViewLocked();
     279        3892 :             m_pWrtShell->LockView( true );    //lock visible section
     280        3892 :             m_pWrtShell->StartAllAction();
     281             :         }
     282       11072 :         switch( nAction )
     283             :         {
     284             :         case 2:
     285        8668 :             m_pDoc->getIDocumentFieldsAccess().GetSysFieldType( RES_FILENAMEFLD )->UpdateFields();
     286        8668 :             break;
     287             :         // #i38126# - own action for event LOADFINISHED
     288             :         // in order to avoid a modified document.
     289             :         // #i41679# - Also for the instance of <SwDoc>
     290             :         // it has to be assured, that it's not modified.
     291             :         // Perform the same as for action id 1, but disable <SetModified>.
     292             :         case 3:
     293             :             {
     294        2404 :                 const bool bResetModified = IsEnableSetModified();
     295        2404 :                 if ( bResetModified )
     296        2396 :                     EnableSetModified( false );
     297             :                 // #i41679#
     298        2404 :                 const bool bIsDocModified = m_pDoc->getIDocumentState().IsModified();
     299             : 
     300        2404 :                 m_pDoc->getIDocumentStatistics().DocInfoChgd( );
     301             : 
     302             :                 // #i41679#
     303        2404 :                 if ( !bIsDocModified )
     304        2396 :                     m_pDoc->getIDocumentState().ResetModified();
     305        2404 :                 if ( bResetModified )
     306        2396 :                     EnableSetModified( true );
     307             :             }
     308        2404 :             break;
     309             :         }
     310             : 
     311       11072 :         if (m_pWrtShell)
     312             :         {
     313        3892 :             m_pWrtShell->EndAllAction();
     314        3892 :             if( bUnlockView )
     315        3794 :                 m_pWrtShell->LockView( false );
     316             :         }
     317      178889 :     }
     318             : }
     319             : 
     320             : // Notification Close Doc
     321           5 : bool SwDocShell::PrepareClose( bool bUI )
     322             : {
     323           5 :     bool nRet = SfxObjectShell::PrepareClose( bUI );
     324             : 
     325           5 :     if( nRet )
     326           5 :         EndListening( *this );
     327             : 
     328           5 :     if (m_pDoc && IsInPrepareClose())
     329             :     {
     330             :         uno::Reference< script::vba::XVBAEventProcessor > const xVbaEvents =
     331           2 :             m_pDoc->GetVbaEventProcessor();
     332           2 :         if( xVbaEvents.is() )
     333             :         {
     334             :             using namespace com::sun::star::script::vba::VBAEventId;
     335           0 :             uno::Sequence< uno::Any > aArgs;
     336           0 :             xVbaEvents->processVbaEvent( DOCUMENT_CLOSE, aArgs );
     337           2 :         }
     338             :     }
     339           5 :     return nRet;
     340             : }
     341             : 
     342           2 : void SwDocShell::Execute(SfxRequest& rReq)
     343             : {
     344           2 :     const SfxItemSet* pArgs = rReq.GetArgs();
     345             :     const SfxPoolItem* pItem;
     346           2 :     sal_uInt16 nWhich = rReq.GetSlot();
     347           2 :     bool bDone = false;
     348           2 :     switch ( nWhich )
     349             :     {
     350             :         case SID_AUTO_CORRECT_DLG:
     351             :         {
     352           0 :             SvxSwAutoFormatFlags* pAFlags = &SvxAutoCorrCfg::Get().GetAutoCorrect()->GetSwFlags();
     353           0 :             SwAutoCompleteWord& rACW = SwDoc::GetAutoCompleteWords();
     354             : 
     355           0 :             bool bOldLocked = rACW.IsLockWordLstLocked(),
     356           0 :                  bOldAutoCmpltCollectWords = pAFlags->bAutoCmpltCollectWords;
     357             : 
     358           0 :             rACW.SetLockWordLstLocked( true );
     359             : 
     360           0 :             editeng::SortedAutoCompleteStrings aTmpLst( rACW.GetWordList() );
     361           0 :             pAFlags->m_pAutoCompleteList = &aTmpLst;
     362             : 
     363           0 :             SfxApplication* pApp = SfxGetpApp();
     364           0 :             SfxRequest aAppReq(SID_AUTO_CORRECT_DLG, SfxCallMode::SYNCHRON, pApp->GetPool());
     365           0 :             SfxBoolItem aSwOptions( SID_AUTO_CORRECT_DLG, true );
     366           0 :             aAppReq.AppendItem(aSwOptions);
     367             : 
     368           0 :             pAFlags->pSmartTagMgr = &SwSmartTagMgr::Get();
     369             : 
     370           0 :             SfxItemSet aSet( pApp->GetPool(), SID_AUTO_CORRECT_DLG, SID_AUTO_CORRECT_DLG, SID_OPEN_SMARTTAGOPTIONS, SID_OPEN_SMARTTAGOPTIONS, 0 );
     371           0 :             aSet.Put( aSwOptions );
     372             : 
     373           0 :             const SfxPoolItem* pOpenSmartTagOptionsItem = 0;
     374           0 :             if( pArgs && SfxItemState::SET == pArgs->GetItemState( SID_OPEN_SMARTTAGOPTIONS, false, &pOpenSmartTagOptionsItem ) )
     375           0 :                 aSet.Put( *static_cast<const SfxBoolItem*>(pOpenSmartTagOptionsItem) );
     376             : 
     377           0 :             SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
     378           0 :               SfxAbstractTabDialog* pDlg = pFact->CreateTabDialog( RID_OFA_AUTOCORR_DLG, NULL, &aSet, NULL );
     379           0 :               pDlg->Execute();
     380           0 :               delete pDlg;
     381             : 
     382           0 :             rACW.SetLockWordLstLocked( bOldLocked );
     383             : 
     384           0 :             SwEditShell::SetAutoFormatFlags( pAFlags );
     385           0 :             rACW.SetMinWordLen( pAFlags->nAutoCmpltWordLen );
     386           0 :             rACW.SetMaxCount( pAFlags->nAutoCmpltListLen );
     387           0 :             if (pAFlags->m_pAutoCompleteList)  // any changes?
     388             :             {
     389           0 :                 rACW.CheckChangedList( aTmpLst );
     390             :                 // clear the temp WordList pointer
     391           0 :                 pAFlags->m_pAutoCompleteList = 0;
     392             :             }
     393             :             // remove all pointer we never delete the strings
     394           0 :             aTmpLst.clear();
     395             : 
     396           0 :             if( !bOldAutoCmpltCollectWords && bOldAutoCmpltCollectWords !=
     397             :                 pAFlags->bAutoCmpltCollectWords )
     398             :             {
     399             :                 // call on all Docs the idle formatter to start
     400             :                 // the collection of Words
     401           0 :                 TypeId aType = TYPE(SwDocShell);
     402           0 :                 for( SwDocShell *pDocSh = static_cast<SwDocShell*>(SfxObjectShell::GetFirst(&aType));
     403             :                      pDocSh;
     404           0 :                      pDocSh = static_cast<SwDocShell*>(SfxObjectShell::GetNext( *pDocSh, &aType )) )
     405             :                 {
     406           0 :                     SwDoc* pTmp = pDocSh->GetDoc();
     407           0 :                     if ( pTmp->getIDocumentLayoutAccess().GetCurrentViewShell() )
     408           0 :                         pTmp->InvalidateAutoCompleteFlag();
     409             :                 }
     410           0 :             }
     411             :         }
     412           0 :         break;
     413             : 
     414             :         case SID_PRINTPREVIEW:
     415             :             {
     416           0 :                 bool bSet = false;
     417           0 :                 bool bFound = false, bOnly = true;
     418           0 :                 SfxViewFrame *pTmpFrm = SfxViewFrame::GetFirst(this);
     419           0 :                 SfxViewShell* pViewShell = SfxViewShell::Current();
     420           0 :                 SwView* pCurrView = dynamic_cast< SwView *> ( pViewShell );
     421           0 :                 bool bCurrent = IS_TYPE( SwPagePreview, pViewShell );
     422             : 
     423           0 :                 while( pTmpFrm )    // search Preview
     424             :                 {
     425           0 :                     if( IS_TYPE( SwView, pTmpFrm->GetViewShell()) )
     426           0 :                         bOnly = false;
     427           0 :                     else if( IS_TYPE( SwPagePreview, pTmpFrm->GetViewShell()))
     428             :                     {
     429           0 :                         pTmpFrm->GetFrame().Appear();
     430           0 :                         bFound = true;
     431             :                     }
     432           0 :                     if( bFound && !bOnly )
     433           0 :                         break;
     434           0 :                     pTmpFrm = SfxViewFrame::GetNext(*pTmpFrm, this);
     435             :                 }
     436             : 
     437           0 :                 if( pArgs && SfxItemState::SET ==
     438           0 :                     pArgs->GetItemState( SID_PRINTPREVIEW, false, &pItem ))
     439           0 :                     bSet = static_cast<const SfxBoolItem*>(pItem)->GetValue();
     440             :                 else
     441           0 :                     bSet = !bCurrent;
     442             : 
     443           0 :                 sal_uInt16 nSlotId = 0;
     444           0 :                 if( bSet && !bFound )   // Nothing found, so create new Preview
     445           0 :                         nSlotId = SID_VIEWSHELL1;
     446           0 :                 else if( bFound && !bSet )
     447           0 :                     nSlotId = bOnly ? SID_VIEWSHELL0 : SID_VIEWSHELL1;
     448             : 
     449           0 :                 if( nSlotId )
     450             :                 {
     451             :                     // PagePreview in the WebDocShell
     452             :                     // is found under Id VIEWSHELL2.
     453           0 :                     if( ISA(SwWebDocShell) && SID_VIEWSHELL1 == nSlotId )
     454           0 :                         nSlotId = SID_VIEWSHELL2;
     455             : 
     456           0 :                     if( pCurrView && pCurrView->GetDocShell() == this )
     457           0 :                         pTmpFrm = pCurrView->GetViewFrame();
     458             :                     else
     459           0 :                         pTmpFrm = SfxViewFrame::GetFirst( this );
     460             : 
     461           0 :                     if (pTmpFrm)
     462           0 :                         pTmpFrm->GetDispatcher()->Execute( nSlotId, SfxCallMode::ASYNCHRON );
     463             :                 }
     464             : 
     465           0 :                 rReq.SetReturnValue(SfxBoolItem(SID_PRINTPREVIEW, bSet ));
     466             :             }
     467           0 :             break;
     468             :         case SID_TEMPLATE_LOAD:
     469             :             {
     470           0 :                 OUString aFileName;
     471             :                 static bool bText = true;
     472             :                 static bool bFrame = false;
     473             :                 static bool bPage =  false;
     474             :                 static bool bNum =   false;
     475             :                 static bool bMerge = false;
     476           0 :                 sal_uInt16 nRet = USHRT_MAX;
     477             : 
     478           0 :                 SfxTemplateFlags nFlags = bFrame ? SfxTemplateFlags::LOAD_FRAME_STYLES : SfxTemplateFlags::NONE;
     479           0 :                 if(bPage)
     480           0 :                     nFlags |= SfxTemplateFlags::LOAD_PAGE_STYLES;
     481           0 :                 if(bNum)
     482           0 :                     nFlags |= SfxTemplateFlags::LOAD_NUM_STYLES;
     483           0 :                 if(nFlags == SfxTemplateFlags::NONE || bText)
     484           0 :                     nFlags |= SfxTemplateFlags::LOAD_TEXT_STYLES;
     485           0 :                 if(bMerge)
     486           0 :                     nFlags |= SfxTemplateFlags::MERGE_STYLES;
     487             : 
     488           0 :                 if ( pArgs )
     489             :                 {
     490           0 :                     SFX_REQUEST_ARG( rReq, pTemplateItem, SfxStringItem, SID_TEMPLATE_NAME, false );
     491           0 :                     if ( pTemplateItem )
     492             :                     {
     493           0 :                         aFileName = pTemplateItem->GetValue();
     494           0 :                         SFX_REQUEST_ARG( rReq, pFlagsItem, SfxInt32Item, SID_TEMPLATE_LOAD, false );
     495           0 :                         if ( pFlagsItem )
     496           0 :                             nFlags = static_cast<SfxTemplateFlags>((sal_uInt16) pFlagsItem->GetValue());
     497             :                     }
     498             :                 }
     499             : 
     500           0 :                 if ( aFileName.isEmpty() )
     501             :                 {
     502           0 :                     SvtPathOptions aPathOpt;
     503             :                     ScopedVclPtr<SfxNewFileDialog> pNewFileDlg(
     504           0 :                         VclPtr<SfxNewFileDialog>::Create(&GetView()->GetViewFrame()->GetWindow(), SFXWB_LOAD_TEMPLATE));
     505           0 :                     pNewFileDlg->SetTemplateFlags(nFlags);
     506             : 
     507           0 :                     nRet = pNewFileDlg->Execute();
     508           0 :                     if(RET_TEMPLATE_LOAD == nRet)
     509             :                     {
     510           0 :                         FileDialogHelper aDlgHelper( TemplateDescription::FILEOPEN_SIMPLE, 0 );
     511           0 :                         uno::Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
     512             : 
     513           0 :                         xFP->setDisplayDirectory( aPathOpt.GetWorkPath() );
     514             : 
     515           0 :                         SfxObjectFactory &rFact = GetFactory();
     516           0 :                         SfxFilterMatcher aMatcher( OUString::createFromAscii(rFact.GetShortName()) );
     517           0 :                         SfxFilterMatcherIter aIter( aMatcher );
     518           0 :                         uno::Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY);
     519           0 :                         const SfxFilter* pFlt = aIter.First();
     520           0 :                         while( pFlt )
     521             :                         {
     522             :                             // --> OD #i117339#
     523           0 :                             if( pFlt && pFlt->IsAllowedAsTemplate() &&
     524           0 :                                 ( pFlt->GetUserData() == "CXML" ||
     525           0 :                                   pFlt->GetUserData() == "CXMLV" ) )
     526             :                             {
     527           0 :                                 const OUString sWild = pFlt->GetWildcard().getGlob();
     528           0 :                                 xFltMgr->appendFilter( pFlt->GetUIName(), sWild );
     529             :                             }
     530           0 :                             pFlt = aIter.Next();
     531             :                         }
     532           0 :                         bool bWeb = 0 != dynamic_cast< SwWebDocShell *>( this );
     533             :                         const SfxFilter *pOwnFlt =
     534           0 :                                 SwDocShell::Factory().GetFilterContainer()->
     535           0 :                                 GetFilter4FilterName(OUString("writer8"));
     536             : 
     537             :                         // make sure the default file format is also available
     538           0 :                         if(bWeb)
     539             :                         {
     540           0 :                             const OUString sWild = pOwnFlt->GetWildcard().getGlob();
     541           0 :                             xFltMgr->appendFilter( pOwnFlt->GetUIName(), sWild );
     542             :                         }
     543             : 
     544           0 :                         bool bError = false;
     545             :                         // catch exception if wrong filter is selected - should not happen anymore
     546             :                         try
     547             :                         {
     548           0 :                             xFltMgr->setCurrentFilter( pOwnFlt->GetUIName() );
     549             :                         }
     550           0 :                         catch (const uno::Exception&)
     551             :                         {
     552           0 :                             bError = true;
     553             :                         }
     554             : 
     555           0 :                         if( !bError && ERRCODE_NONE == aDlgHelper.Execute() )
     556             :                         {
     557           0 :                             aFileName = xFP->getFiles().getConstArray()[0];
     558           0 :                         }
     559             :                     }
     560           0 :                     else if( RET_OK == nRet)
     561             :                     {
     562           0 :                         aFileName = pNewFileDlg->GetTemplateFileName();
     563             :                     }
     564             : 
     565           0 :                     nFlags = pNewFileDlg->GetTemplateFlags();
     566           0 :                     rReq.AppendItem( SfxStringItem( SID_TEMPLATE_NAME, aFileName ) );
     567           0 :                     rReq.AppendItem( SfxInt32Item( SID_TEMPLATE_LOAD, (long) nFlags ) );
     568             :                 }
     569             : 
     570           0 :                 if( !aFileName.isEmpty() )
     571             :                 {
     572           0 :                     SwgReaderOption aOpt;
     573           0 :                     aOpt.SetTextFormats(    bText  = bool(nFlags & SfxTemplateFlags::LOAD_TEXT_STYLES ));
     574           0 :                     aOpt.SetFrameFormats(    bFrame = bool(nFlags & SfxTemplateFlags::LOAD_FRAME_STYLES));
     575           0 :                     aOpt.SetPageDescs(  bPage  = bool(nFlags & SfxTemplateFlags::LOAD_PAGE_STYLES ));
     576           0 :                     aOpt.SetNumRules(   bNum   = bool(nFlags & SfxTemplateFlags::LOAD_NUM_STYLES  ));
     577             :                     //different meaning between SFX_MERGE_STYLES and aOpt.SetMerge!
     578           0 :                     bMerge = bool(nFlags & SfxTemplateFlags::MERGE_STYLES);
     579           0 :                     aOpt.SetMerge( !bMerge );
     580             : 
     581           0 :                     SetError( LoadStylesFromFile( aFileName, aOpt, false ), OUString( OSL_LOG_PREFIX ));
     582           0 :                     if ( !GetError() )
     583           0 :                         rReq.Done();
     584           0 :                 }
     585             :             }
     586           0 :             break;
     587             :             case SID_SOURCEVIEW:
     588             :             {
     589           0 :                 SfxViewShell* pViewShell = GetView()
     590             :                                             ? static_cast<SfxViewShell*>(GetView())
     591           0 :                                             : SfxViewShell::Current();
     592           0 :                 SfxViewFrame*  pViewFrm = pViewShell->GetViewFrame();
     593           0 :                 SwSrcView* pSrcView = dynamic_cast< SwSrcView *>( pViewShell );
     594           0 :                 if(!pSrcView)
     595             :                 {
     596             :                     // 3 possible state:
     597             :                     // 1 - file unsaved -> save as HTML
     598             :                     // 2 - file modified and HTML filter active -> save
     599             :                     // 3 - file saved in non-HTML -> QueryBox to save as HTML
     600             :                     const SfxFilter* pHtmlFlt =
     601             :                                     SwIoSystem::GetFilterOfFormat(
     602             :                                         OUString("HTML"),
     603           0 :                                         SwWebDocShell::Factory().GetFilterContainer() );
     604           0 :                     bool bLocalHasName = HasName();
     605           0 :                     if(bLocalHasName)
     606             :                     {
     607             :                         //check for filter type
     608           0 :                         const SfxFilter* pFlt = GetMedium()->GetFilter();
     609           0 :                         if(!pFlt || pFlt->GetUserData() != pHtmlFlt->GetUserData())
     610             :                         {
     611           0 :                             ScopedVclPtrInstance<MessageDialog> aQuery(&pViewFrm->GetWindow(),
     612           0 :                                                                        "SaveAsHTMLDialog", "modules/swriter/ui/saveashtmldialog.ui");
     613             : 
     614           0 :                             if(RET_YES == aQuery->Execute())
     615           0 :                                 bLocalHasName = false;
     616             :                             else
     617           0 :                                 break;
     618             :                         }
     619             :                     }
     620           0 :                     if(!bLocalHasName)
     621             :                     {
     622           0 :                         FileDialogHelper aDlgHelper( TemplateDescription::FILESAVE_AUTOEXTENSION, 0 );
     623           0 :                         aDlgHelper.AddFilter( pHtmlFlt->GetFilterName(), pHtmlFlt->GetDefaultExtension() );
     624           0 :                         aDlgHelper.SetCurrentFilter( pHtmlFlt->GetFilterName() );
     625           0 :                         if( ERRCODE_NONE != aDlgHelper.Execute())
     626             :                         {
     627           0 :                             break;
     628             :                         }
     629           0 :                         OUString sPath = aDlgHelper.GetPath();
     630           0 :                         SfxStringItem aName(SID_FILE_NAME, sPath);
     631           0 :                         SfxStringItem aFilter(SID_FILTER_NAME, pHtmlFlt->GetName());
     632             :                         const SfxBoolItem* pBool = static_cast<const SfxBoolItem*>(
     633             :                                 pViewFrm->GetDispatcher()->Execute(
     634           0 :                                         SID_SAVEASDOC, SfxCallMode::SYNCHRON, &aName, &aFilter, 0L ));
     635           0 :                         if(!pBool || !pBool->GetValue())
     636           0 :                             break;
     637             :                     }
     638             :                 }
     639             : 
     640             :                 OSL_ENSURE(dynamic_cast<SwWebDocShell*>(this),
     641             :                             "SourceView only in WebDocShell");
     642             : 
     643             :                 // the SourceView is not the 1 for SwWebDocShell
     644           0 :                 sal_uInt16 nSlot = SID_VIEWSHELL1;
     645           0 :                 bool bSetModified = false;
     646           0 :                 SfxPrinter* pSavePrinter = 0;
     647           0 :                 if( 0 != pSrcView)
     648             :                 {
     649           0 :                     SfxPrinter* pTemp = GetDoc()->getIDocumentDeviceAccess().getPrinter( false );
     650           0 :                     if(pTemp)
     651           0 :                         pSavePrinter = VclPtr<SfxPrinter>::Create(*pTemp);
     652           0 :                     bSetModified = IsModified() || pSrcView->IsModified();
     653           0 :                     if(pSrcView->IsModified()||pSrcView->HasSourceSaved())
     654             :                     {
     655           0 :                         utl::TempFile aTempFile;
     656           0 :                         aTempFile.EnableKillingFile();
     657           0 :                         pSrcView->SaveContent(aTempFile.GetURL());
     658           0 :                         bDone = true;
     659           0 :                         SvxMacro aMac(aEmptyOUStr, aEmptyOUStr, STARBASIC);
     660           0 :                         SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( GlobalEventId::OPENDOC ), aMac, this);
     661           0 :                         SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( GlobalEventId::PREPARECLOSEDOC ), aMac, this);
     662           0 :                         SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( GlobalEventId::ACTIVATEDOC ),     aMac, this);
     663           0 :                         SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( GlobalEventId::DEACTIVATEDOC ), aMac, this);
     664           0 :                         ReloadFromHtml(aTempFile.GetURL(), pSrcView);
     665           0 :                         nSlot = 0;
     666             :                     }
     667             :                     else
     668             :                     {
     669           0 :                         nSlot = SID_VIEWSHELL0;
     670             :                     }
     671             :                 }
     672           0 :                 if(nSlot)
     673           0 :                     pViewFrm->GetDispatcher()->Execute(nSlot, SfxCallMode::SYNCHRON);
     674           0 :                 if(bSetModified)
     675           0 :                     GetDoc()->getIDocumentState().SetModified();
     676           0 :                 if(pSavePrinter)
     677             :                 {
     678           0 :                     GetDoc()->getIDocumentDeviceAccess().setPrinter( pSavePrinter, true, true);
     679             :                     //pSavePrinter must not be deleted again
     680             :                 }
     681           0 :                 pViewFrm->GetBindings().SetState(SfxBoolItem(SID_SOURCEVIEW, nSlot == SID_VIEWSHELL2));
     682           0 :                 pViewFrm->GetBindings().Invalidate( SID_NEWWINDOW );
     683           0 :                 pViewFrm->GetBindings().Invalidate( SID_BROWSER_MODE );
     684           0 :                 pViewFrm->GetBindings().Invalidate( FN_PRINT_LAYOUT );
     685             :             }
     686           0 :             break;
     687             :             case SID_GET_COLORLIST:
     688             :             {
     689           0 :                 const SvxColorListItem* pColItem = static_cast<const SvxColorListItem*>(GetItem(SID_COLOR_TABLE));
     690           0 :                 XColorListRef pList = pColItem->GetColorList();
     691           0 :                 rReq.SetReturnValue(OfaRefItem<XColorList>(SID_GET_COLORLIST, pList));
     692             :             }
     693           0 :             break;
     694             :         case FN_ABSTRACT_STARIMPRESS:
     695             :         case FN_ABSTRACT_NEWDOC:
     696             :         {
     697           0 :             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
     698             :             OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
     699             : 
     700           0 :             boost::scoped_ptr<AbstractSwInsertAbstractDlg> pDlg(pFact->CreateSwInsertAbstractDlg(0));
     701             :             OSL_ENSURE(pDlg, "Dialog creation failed!");
     702           0 :             if(RET_OK == pDlg->Execute())
     703             :             {
     704           0 :                 sal_uInt8 nLevel = pDlg->GetLevel();
     705           0 :                 sal_uInt8 nPara = pDlg->GetPara();
     706           0 :                 SwDoc* pSmryDoc = new SwDoc();
     707           0 :                 SfxObjectShellLock xDocSh( new SwDocShell( pSmryDoc, SfxObjectCreateMode::STANDARD));
     708           0 :                 xDocSh->DoInitNew( 0 );
     709             : 
     710           0 :                 bool bImpress = FN_ABSTRACT_STARIMPRESS == nWhich;
     711           0 :                 m_pDoc->Summary( pSmryDoc, nLevel, nPara, bImpress );
     712           0 :                 if( bImpress )
     713             :                 {
     714           0 :                     WriterRef xWrt;
     715             :                     // mba: looks as if relative URLs don't make sense here
     716           0 :                     ::GetRTFWriter( aEmptyOUStr, OUString(), xWrt );
     717           0 :                     SvMemoryStream *pStrm = new SvMemoryStream();
     718           0 :                     pStrm->SetBufferSize( 16348 );
     719           0 :                     SwWriter aWrt( *pStrm, *pSmryDoc );
     720           0 :                     ErrCode eErr = aWrt.Write( xWrt );
     721           0 :                     if( !ERRCODE_TOERROR( eErr ) )
     722             :                     {
     723           0 :                         uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
     724           0 :                         uno::Reference< frame::XDispatchProvider > xProv = drawing::ModuleDispatcher::create( xContext );
     725             : 
     726           0 :                         OUString aCmd("SendOutlineToImpress");
     727           0 :                         uno::Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create(xContext) );
     728           0 :                         pStrm->Seek( STREAM_SEEK_TO_END );
     729           0 :                         pStrm->WriteChar( '\0' );
     730           0 :                         pStrm->Seek( STREAM_SEEK_TO_BEGIN );
     731             : 
     732             :                         // Transfer ownership of stream to a lockbytes object
     733           0 :                         SvLockBytes aLockBytes( pStrm, true );
     734           0 :                         SvLockBytesStat aStat;
     735           0 :                         if ( aLockBytes.Stat( &aStat, SVSTATFLAG_DEFAULT ) == ERRCODE_NONE )
     736             :                         {
     737           0 :                             sal_uInt32 nLen = aStat.nSize;
     738           0 :                             sal_uLong nRead = 0;
     739           0 :                             uno::Sequence< sal_Int8 > aSeq( nLen );
     740           0 :                             aLockBytes.ReadAt( 0, aSeq.getArray(), nLen, &nRead );
     741             : 
     742           0 :                             uno::Sequence< beans::PropertyValue > aArgs(1);
     743           0 :                             aArgs[0].Name = "RtfOutline";
     744           0 :                             aArgs[0].Value <<= aSeq;
     745           0 :                             xHelper->executeDispatch( xProv, aCmd, OUString(), 0, aArgs );
     746           0 :                         }
     747             :                     }
     748             :                     else
     749           0 :                         ErrorHandler::HandleError(ErrCode( eErr ));
     750             :                 }
     751             :                 else
     752             :                 {
     753             :                     // Create new document
     754           0 :                     SfxViewFrame *pFrame = SfxViewFrame::LoadDocument( *xDocSh, 0 );
     755           0 :                     SwView      *pCurrView = static_cast<SwView*>( pFrame->GetViewShell());
     756             : 
     757             :                     // Set document's title
     758           0 :                     OUString aTmp( SW_RES(STR_ABSTRACT_TITLE) );
     759           0 :                     aTmp += GetTitle();
     760           0 :                     xDocSh->SetTitle( aTmp );
     761           0 :                     pCurrView->GetWrtShell().SetNewDoc();
     762           0 :                     pFrame->Show();
     763           0 :                     pSmryDoc->getIDocumentState().SetModified();
     764           0 :                 }
     765             : 
     766           0 :             }
     767             :         }
     768           0 :         break;
     769             :         case FN_OUTLINE_TO_CLIPBOARD:
     770             :         case FN_OUTLINE_TO_IMPRESS:
     771             :             {
     772           0 :                 bool bEnable = IsEnableSetModified();
     773           0 :                 EnableSetModified( false );
     774           0 :                 WriterRef xWrt;
     775             :                 // mba: looks as if relative URLs don't make sense here
     776           0 :                 ::GetRTFWriter( OUString('O'), OUString(), xWrt );
     777           0 :                 SvMemoryStream *pStrm = new SvMemoryStream();
     778           0 :                 pStrm->SetBufferSize( 16348 );
     779           0 :                 SwWriter aWrt( *pStrm, *GetDoc() );
     780           0 :                 ErrCode eErr = aWrt.Write( xWrt );
     781           0 :                 EnableSetModified( bEnable );
     782           0 :                 if( !ERRCODE_TOERROR( eErr ) )
     783             :                 {
     784           0 :                     pStrm->Seek( STREAM_SEEK_TO_END );
     785           0 :                     pStrm->WriteChar( '\0' );
     786           0 :                     pStrm->Seek( STREAM_SEEK_TO_BEGIN );
     787           0 :                     if ( nWhich == FN_OUTLINE_TO_IMPRESS )
     788             :                     {
     789           0 :                         uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
     790           0 :                         uno::Reference< frame::XDispatchProvider > xProv = drawing::ModuleDispatcher::create( xContext );
     791             : 
     792           0 :                         OUString aCmd("SendOutlineToImpress");
     793           0 :                         uno::Reference< frame::XDispatchHelper > xHelper( frame::DispatchHelper::create(xContext) );
     794           0 :                         pStrm->Seek( STREAM_SEEK_TO_END );
     795           0 :                         pStrm->WriteChar( '\0' );
     796           0 :                         pStrm->Seek( STREAM_SEEK_TO_BEGIN );
     797             : 
     798             :                         // Transfer ownership of stream to a lockbytes object
     799           0 :                         SvLockBytes aLockBytes( pStrm, true );
     800           0 :                         SvLockBytesStat aStat;
     801           0 :                         if ( aLockBytes.Stat( &aStat, SVSTATFLAG_DEFAULT ) == ERRCODE_NONE )
     802             :                         {
     803           0 :                             sal_uInt32 nLen = aStat.nSize;
     804           0 :                             sal_uLong nRead = 0;
     805           0 :                             uno::Sequence< sal_Int8 > aSeq( nLen );
     806           0 :                             aLockBytes.ReadAt( 0, aSeq.getArray(), nLen, &nRead );
     807             : 
     808           0 :                             uno::Sequence< beans::PropertyValue > aArgs(1);
     809           0 :                             aArgs[0].Name = "RtfOutline";
     810           0 :                             aArgs[0].Value <<= aSeq;
     811           0 :                             xHelper->executeDispatch( xProv, aCmd, OUString(), 0, aArgs );
     812           0 :                         }
     813             :                     }
     814             :                     else
     815             :                     {
     816             :                         TransferDataContainer* pClipCntnr =
     817           0 :                                                     new TransferDataContainer;
     818             :                         ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >
     819           0 :                                                         xRef( pClipCntnr );
     820             : 
     821             :                         pClipCntnr->CopyAnyData( SotClipboardFormatId::RTF, static_cast<sal_Char const *>(
     822           0 :                                     pStrm->GetData()), pStrm->GetEndOfData() );
     823             :                         pClipCntnr->CopyToClipboard(
     824           0 :                             GetView()? &GetView()->GetEditWin() : 0 );
     825           0 :                         delete pStrm;
     826             :                     }
     827             :                 }
     828             :                 else
     829           0 :                     ErrorHandler::HandleError(ErrCode( eErr ));
     830             :             }
     831           0 :             break;
     832             :             case SID_SPELLCHECKER_CHANGED:
     833             :                 //! false, true, true is on the save side but a probably overdone
     834           0 :                 SwModule::CheckSpellChanges(false, true, true, false );
     835           0 :             break;
     836             : 
     837             :         case SID_MAIL_PREPAREEXPORT:
     838             :         {
     839             :             //pWrtShell is not set in page preview
     840           0 :             if (m_pWrtShell)
     841           0 :                 m_pWrtShell->StartAllAction();
     842           0 :             m_pDoc->getIDocumentFieldsAccess().UpdateFields( NULL, false );
     843           0 :             m_pDoc->getIDocumentLinksAdministration().EmbedAllLinks();
     844             :             m_IsRemovedInvisibleContent
     845           0 :                 = officecfg::Office::Security::HiddenContent::RemoveHiddenContent::get();
     846           0 :             if (m_IsRemovedInvisibleContent)
     847           0 :                 m_pDoc->RemoveInvisibleContent();
     848           0 :             if (m_pWrtShell)
     849           0 :                 m_pWrtShell->EndAllAction();
     850             :         }
     851           0 :         break;
     852             : 
     853             :         case SID_MAIL_EXPORT_FINISHED:
     854             :         {
     855           0 :                 if (m_pWrtShell)
     856           0 :                     m_pWrtShell->StartAllAction();
     857             :                 //try to undo the removal of invisible content
     858           0 :                 if (m_IsRemovedInvisibleContent)
     859           0 :                     m_pDoc->RestoreInvisibleContent();
     860           0 :                 if (m_pWrtShell)
     861           0 :                     m_pWrtShell->EndAllAction();
     862             :         }
     863           0 :         break;
     864             :         case FN_NEW_HTML_DOC:
     865             :         case FN_NEW_GLOBAL_DOC:
     866             :             {
     867           0 :                 bDone = false;
     868           0 :                 bool bCreateHtml = FN_NEW_HTML_DOC == nWhich;
     869             : 
     870           0 :                 bool bCreateByOutlineLevel = false;
     871           0 :                 sal_Int32  nTemplateOutlineLevel = 0;
     872             : 
     873           0 :                 OUString aFileName, aTemplateName;
     874           0 :                 if( pArgs && SfxItemState::SET == pArgs->GetItemState( nWhich, false, &pItem ) )
     875             :                 {
     876           0 :                     aFileName = static_cast<const SfxStringItem*>(pItem)->GetValue();
     877           0 :                     SFX_ITEMSET_ARG( pArgs, pTemplItem, SfxStringItem, SID_TEMPLATE_NAME, false );
     878           0 :                     if ( pTemplItem )
     879           0 :                         aTemplateName = pTemplItem->GetValue();
     880             :                 }
     881           0 :                 if ( aFileName.isEmpty() )
     882             :                 {
     883           0 :                     bool bError = false;
     884             : 
     885           0 :                     FileDialogHelper aDlgHelper( TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE, 0 );
     886             : 
     887             :                     const sal_Int16 nControlIds[] = {
     888             :                         CommonFilePickerElementIds::PUSHBUTTON_OK,
     889             :                         CommonFilePickerElementIds::PUSHBUTTON_CANCEL,
     890             :                         CommonFilePickerElementIds::LISTBOX_FILTER,
     891             :                         CommonFilePickerElementIds::CONTROL_FILEVIEW,
     892             :                         CommonFilePickerElementIds::EDIT_FILEURL,
     893             :                         ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION,
     894             :                         ExtendedFilePickerElementIds::LISTBOX_TEMPLATE,
     895             :                         0
     896           0 :                     };
     897             : 
     898             :                     const char* aHTMLHelpIds[] =
     899             :                     {
     900             :                          HID_SEND_HTML_CTRL_PUSHBUTTON_OK,
     901             :                          HID_SEND_HTML_CTRL_PUSHBUTTON_CANCEL,
     902             :                          HID_SEND_HTML_CTRL_LISTBOX_FILTER,
     903             :                          HID_SEND_HTML_CTRL_CONTROL_FILEVIEW,
     904             :                          HID_SEND_HTML_CTRL_EDIT_FILEURL,
     905             :                          HID_SEND_HTML_CTRL_CHECKBOX_AUTOEXTENSION,
     906             :                          HID_SEND_HTML_CTRL_LISTBOX_TEMPLATE,
     907             :                          ""
     908           0 :                     };
     909             : 
     910             :                     const char* aMasterHelpIds[] =
     911             :                     {
     912             :                          HID_SEND_MASTER_CTRL_PUSHBUTTON_OK,
     913             :                          HID_SEND_MASTER_CTRL_PUSHBUTTON_CANCEL,
     914             :                          HID_SEND_MASTER_CTRL_LISTBOX_FILTER,
     915             :                          HID_SEND_MASTER_CTRL_CONTROL_FILEVIEW,
     916             :                          HID_SEND_MASTER_CTRL_EDIT_FILEURL,
     917             :                          HID_SEND_MASTER_CTRL_CHECKBOX_AUTOEXTENSION,
     918             :                          HID_SEND_MASTER_CTRL_LISTBOX_TEMPLATE,
     919             :                          ""
     920           0 :                     };
     921             : 
     922           0 :                     const char** pHelpIds = bCreateHtml ? aHTMLHelpIds : aMasterHelpIds;
     923           0 :                     aDlgHelper.SetControlHelpIds( nControlIds, pHelpIds );
     924           0 :                     uno::Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
     925             : 
     926             :                     const SfxFilter* pFlt;
     927             :                     sal_uInt16 nStrId;
     928             : 
     929           0 :                     if( bCreateHtml )
     930             :                     {
     931             :                         // for HTML there is only one filter!!
     932             :                         pFlt = SwIoSystem::GetFilterOfFormat(
     933             :                                 OUString("HTML"),
     934           0 :                                 SwWebDocShell::Factory().GetFilterContainer() );
     935           0 :                         nStrId = STR_LOAD_HTML_DOC;
     936             :                     }
     937             :                     else
     938             :                     {
     939             :                         // for Global-documents we now only offer the current one.
     940           0 :                         pFlt = SwGlobalDocShell::Factory().GetFilterContainer()->
     941           0 :                                     GetFilter4Extension( OUString("odm")  );
     942           0 :                         nStrId = STR_LOAD_GLOBAL_DOC;
     943             :                     }
     944             : 
     945           0 :                     if( pFlt )
     946             :                     {
     947           0 :                         uno::Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY);
     948           0 :                         const OUString sWild = pFlt->GetWildcard().getGlob();
     949           0 :                         xFltMgr->appendFilter( pFlt->GetUIName(), sWild );
     950             :                         try
     951             :                         {
     952           0 :                             xFltMgr->setCurrentFilter( pFlt->GetUIName() ) ;
     953             :                         }
     954           0 :                         catch (const uno::Exception&)
     955             :                         {
     956           0 :                             bError = true;
     957           0 :                         }
     958             :                     }
     959           0 :                     if(!bError)
     960             :                     {
     961           0 :                         uno::Reference<XFilePickerControlAccess> xCtrlAcc(xFP, UNO_QUERY);
     962             : 
     963           0 :                         bool    bOutline[MAXLEVEL] = {false};
     964           0 :                         const SwOutlineNodes& rOutlNds = m_pDoc->GetNodes().GetOutLineNds();
     965           0 :                         if( !rOutlNds.empty() )
     966             :                         {
     967           0 :                             for( size_t n = 0; n < rOutlNds.size(); ++n )
     968             :                             {
     969           0 :                                 const int nLevel = rOutlNds[n]->GetTextNode()->GetAttrOutlineLevel();
     970           0 :                                 if( nLevel > 0 && ! bOutline[nLevel-1] )
     971             :                                 {
     972           0 :                                     bOutline[nLevel-1] = true;
     973             :                                 }
     974             :                             }
     975             :                         }
     976             : 
     977           0 :                         const sal_uInt16 nStyleCount = m_pDoc->GetTextFormatColls()->size();
     978           0 :                         Sequence<OUString> aListBoxEntries( MAXLEVEL + nStyleCount);
     979           0 :                         OUString* pEntries = aListBoxEntries.getArray();
     980           0 :                         sal_Int32   nIdx = 0 ;
     981             : 
     982           0 :                         OUString    sOutline( SW_RESSTR(STR_FDLG_OUTLINE_LEVEL) );
     983           0 :                         for( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
     984             :                         {
     985           0 :                             if( bOutline[i] )
     986           0 :                                 pEntries[nIdx++] = sOutline + OUString::number( i+1 );
     987             :                         }
     988             : 
     989           0 :                         OUString    sStyle( SW_RESSTR(STR_FDLG_STYLE) );
     990           0 :                         for(sal_uInt16 i = 0; i < nStyleCount; ++i)
     991             :                         {
     992           0 :                             SwTextFormatColl &rTextColl = *(*m_pDoc->GetTextFormatColls())[ i ];
     993           0 :                             if( !rTextColl.IsDefault() && rTextColl.IsAtDocNodeSet() )
     994             :                             {
     995           0 :                                 pEntries[nIdx++] = sStyle + rTextColl.GetName();
     996             :                             }
     997             :                         }
     998             : 
     999           0 :                         aListBoxEntries.realloc(nIdx);
    1000           0 :                         sal_Int16 nSelect = 0;
    1001             : 
    1002             :                         try
    1003             :                         {
    1004           0 :                             Any aTemplates(&aListBoxEntries, cppu::UnoType<decltype(aListBoxEntries)>::get());
    1005             : 
    1006           0 :                             xCtrlAcc->setValue( ExtendedFilePickerElementIds::LISTBOX_TEMPLATE,
    1007           0 :                                 ListboxControlActions::ADD_ITEMS , aTemplates );
    1008           0 :                             Any aSelectPos(&nSelect, cppu::UnoType<decltype(nSelect)>::get());
    1009           0 :                             xCtrlAcc->setValue( ExtendedFilePickerElementIds::LISTBOX_TEMPLATE,
    1010           0 :                                 ListboxControlActions::SET_SELECT_ITEM, aSelectPos );
    1011           0 :                             xCtrlAcc->setLabel( ExtendedFilePickerElementIds::LISTBOX_TEMPLATE,
    1012           0 :                                                     OUString(SW_RES( STR_FDLG_TEMPLATE_NAME )));
    1013             :                         }
    1014           0 :                         catch (const Exception&)
    1015             :                         {
    1016             :                             OSL_FAIL("control access failed");
    1017             :                         }
    1018             : 
    1019           0 :                         xFP->setTitle( SW_RESSTR( nStrId ));
    1020           0 :                         SvtPathOptions aPathOpt;
    1021           0 :                         xFP->setDisplayDirectory( aPathOpt.GetWorkPath() );
    1022           0 :                         if( ERRCODE_NONE == aDlgHelper.Execute())
    1023             :                         {
    1024           0 :                             aFileName = xFP->getFiles().getConstArray()[0];
    1025           0 :                             Any aTemplateValue = xCtrlAcc->getValue(
    1026             :                                 ExtendedFilePickerElementIds::LISTBOX_TEMPLATE,
    1027           0 :                                 ListboxControlActions::GET_SELECTED_ITEM );
    1028           0 :                             OUString sTmpl;
    1029           0 :                             aTemplateValue >>= sTmpl;
    1030             : 
    1031           0 :                             sal_Int32 nColonPos = sTmpl.indexOf( ':' );
    1032           0 :                             OUString sPrefix = sTmpl.copy( 0L, nColonPos );
    1033           0 :                             if ( sPrefix == "Style" )
    1034             :                             {
    1035           0 :                                 aTemplateName = sTmpl.copy( 7L );   //get string behind "Style: "
    1036             :                             }
    1037           0 :                             else if ( sPrefix == "Outline" )
    1038             :                             {
    1039           0 :                                 nTemplateOutlineLevel = ( sTmpl.copy( 15L )).toInt32(); //get string behind "Outline: Leve  ";
    1040           0 :                                 bCreateByOutlineLevel = true;
    1041             :                             }
    1042             : 
    1043           0 :                             if ( !aFileName.isEmpty() )
    1044             :                             {
    1045           0 :                                 rReq.AppendItem( SfxStringItem( nWhich, aFileName ) );
    1046           0 :                                 if( !aTemplateName.isEmpty() )
    1047           0 :                                     rReq.AppendItem( SfxStringItem( SID_TEMPLATE_NAME, aTemplateName ) );
    1048           0 :                             }
    1049           0 :                         }
    1050           0 :                     }
    1051             :                 }
    1052             : 
    1053           0 :                 if( !aFileName.isEmpty() )
    1054             :                 {
    1055           0 :                     if( PrepareClose( false ) )
    1056             :                     {
    1057           0 :                         SwWait aWait( *this, true );
    1058             : 
    1059           0 :                         if ( bCreateByOutlineLevel )
    1060             :                         {
    1061             :                             bDone = bCreateHtml
    1062           0 :                                 ? m_pDoc->GenerateHTMLDoc( aFileName, nTemplateOutlineLevel )
    1063           0 :                                 : m_pDoc->GenerateGlobalDoc( aFileName, nTemplateOutlineLevel );
    1064             :                         }
    1065             :                         else
    1066             :                         {
    1067           0 :                             const SwTextFormatColl* pSplitColl = 0;
    1068           0 :                             if ( !aTemplateName.isEmpty() )
    1069           0 :                                 pSplitColl = m_pDoc->FindTextFormatCollByName(aTemplateName);
    1070             :                             bDone = bCreateHtml
    1071           0 :                                 ? m_pDoc->GenerateHTMLDoc( aFileName, pSplitColl )
    1072           0 :                                 : m_pDoc->GenerateGlobalDoc( aFileName, pSplitColl );
    1073             :                         }
    1074           0 :                         if( bDone )
    1075             :                         {
    1076           0 :                             SfxStringItem aName( SID_FILE_NAME, aFileName );
    1077           0 :                             SfxStringItem aReferer( SID_REFERER, aEmptyOUStr );
    1078           0 :                             SfxViewShell* pViewShell = SfxViewShell::GetFirst();
    1079           0 :                             while(pViewShell)
    1080             :                             {
    1081             :                                 //search for the view that created the call
    1082           0 :                                 if(pViewShell->GetObjectShell() == this && pViewShell->GetDispatcher())
    1083             :                                 {
    1084             :                                     boost::scoped_ptr<SfxFrameItem> pFrameItem(new SfxFrameItem( SID_DOCFRAME,
    1085           0 :                                                         pViewShell->GetViewFrame() ));
    1086           0 :                                     SfxDispatcher* pDispatch = pViewShell->GetDispatcher();
    1087             :                                     pDispatch->Execute(
    1088             :                                             SID_OPENDOC,
    1089             :                                             SfxCallMode::ASYNCHRON,
    1090             :                                             &aName,
    1091             :                                             &aReferer,
    1092           0 :                                             pFrameItem.get(), 0L );
    1093           0 :                                     break;
    1094             :                                 }
    1095           0 :                                 pViewShell = SfxViewShell::GetNext(*pViewShell);
    1096           0 :                             }
    1097           0 :                         }
    1098             :                     }
    1099           0 :                     if( !bDone && !rReq.IsAPI() )
    1100             :                     {
    1101           0 :                         ScopedVclPtr<InfoBox>::Create( nullptr, SW_RESSTR( STR_CANTCREATE ))->Execute();
    1102             :                     }
    1103           0 :                 }
    1104             :             }
    1105           0 :             rReq.SetReturnValue(SfxBoolItem( nWhich, bDone ));
    1106           0 :             if (bDone)
    1107           0 :                 rReq.Done();
    1108             :             else
    1109           0 :                 rReq.Ignore();
    1110           0 :             break;
    1111             : 
    1112             :         case SID_ATTR_YEAR2000:
    1113           2 :             if ( pArgs && SfxItemState::SET == pArgs->GetItemState( nWhich , false, &pItem ))
    1114             :             {
    1115             :                 OSL_ENSURE(pItem->ISA(SfxUInt16Item), "wrong Item");
    1116           2 :                 sal_uInt16 nYear2K = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
    1117             :                 // iterate over Views and put the State to FormShells
    1118             : 
    1119           2 :                 SfxViewFrame* pVFrame = SfxViewFrame::GetFirst( this );
    1120           2 :                 SfxViewShell* pViewShell = pVFrame ? pVFrame->GetViewShell() : 0;
    1121           2 :                 SwView* pCurrView = dynamic_cast< SwView* >( pViewShell );
    1122           6 :                 while(pCurrView)
    1123             :                 {
    1124           2 :                     FmFormShell* pFormShell = pCurrView->GetFormShell();
    1125           2 :                     if(pFormShell)
    1126           2 :                         pFormShell->SetY2KState(nYear2K);
    1127           2 :                     pVFrame = SfxViewFrame::GetNext( *pVFrame, this );
    1128           2 :                     pViewShell = pVFrame ? pVFrame->GetViewShell() : 0;
    1129           2 :                     pCurrView = dynamic_cast<SwView*>( pViewShell );
    1130             :                 }
    1131           2 :                 m_pDoc->GetNumberFormatter(true)->SetYear2000(nYear2K);
    1132             :             }
    1133           2 :         break;
    1134             :         case FN_OPEN_FILE:
    1135             :         {
    1136           0 :             SfxViewShell* pViewShell = GetView();
    1137           0 :             if (!pViewShell)
    1138           0 :                 pViewShell = SfxViewShell::Current();
    1139             : 
    1140           0 :             if (!pViewShell)
    1141             :                 // Ok.  I did my best.
    1142           0 :                 break;
    1143             : 
    1144           0 :             SfxStringItem aApp(SID_DOC_SERVICE, OUString("com.sun.star.text.TextDocument"));
    1145           0 :             SfxStringItem aTarget(SID_TARGETNAME, OUString("_blank"));
    1146             :             pViewShell->GetDispatcher()->Execute(
    1147           0 :                 SID_OPENDOC, SfxCallMode::API|SfxCallMode::SYNCHRON, &aApp, &aTarget, 0L);
    1148             :         }
    1149           0 :         break;
    1150             : 
    1151             :         default: OSL_FAIL("wrong Dispatcher");
    1152             :     }
    1153           2 : }
    1154             : 
    1155             : #if defined WNT
    1156             : bool SwDocShell::DdeGetData( const OUString& rItem, const OUString& rMimeType,
    1157             :                              uno::Any & rValue )
    1158             : {
    1159             :     return m_pDoc->getIDocumentLinksAdministration().GetData( rItem, rMimeType, rValue );
    1160             : }
    1161             : 
    1162             : bool SwDocShell::DdeSetData( const OUString& rItem, const OUString& rMimeType,
    1163             :                              const uno::Any & rValue )
    1164             : {
    1165             :     return m_pDoc->getIDocumentLinksAdministration().SetData( rItem, rMimeType, rValue );
    1166             : }
    1167             : 
    1168             : #endif
    1169             : 
    1170           1 : ::sfx2::SvLinkSource* SwDocShell::DdeCreateLinkSource( const OUString& rItem )
    1171             : {
    1172           1 :     return m_pDoc->getIDocumentLinksAdministration().CreateLinkSource( rItem );
    1173             : }
    1174             : 
    1175         353 : void SwDocShell::ReconnectDdeLink(SfxObjectShell& rServer)
    1176             : {
    1177         353 :     if (m_pDoc)
    1178             :     {
    1179         257 :         ::sfx2::LinkManager& rLinkManager = m_pDoc->getIDocumentLinksAdministration().GetLinkManager();
    1180         257 :         rLinkManager.ReconnectDdeLink(rServer);
    1181             :     }
    1182         353 : }
    1183             : 
    1184        2670 : void SwDocShell::FillClass( SvGlobalName * pClassName,
    1185             :                                    SotClipboardFormatId * pClipFormat,
    1186             :                                    OUString * /*pAppName*/,
    1187             :                                    OUString * pLongUserName,
    1188             :                                    OUString * pUserName,
    1189             :                                    sal_Int32 nVersion,
    1190             :                                    bool bTemplate /* = false */) const
    1191             : {
    1192        2670 :     if (nVersion == SOFFICE_FILEFORMAT_60)
    1193             :     {
    1194           0 :         *pClassName     = SvGlobalName( SO3_SW_CLASSID_60 );
    1195           0 :         *pClipFormat    = SotClipboardFormatId::STARWRITER_60;
    1196           0 :         *pLongUserName = SW_RESSTR(STR_WRITER_DOCUMENT_FULLTYPE);
    1197             :     }
    1198        2670 :     else if (nVersion == SOFFICE_FILEFORMAT_8)
    1199             :     {
    1200        2670 :         *pClassName     = SvGlobalName( SO3_SW_CLASSID_60 );
    1201        2670 :         *pClipFormat    = bTemplate ? SotClipboardFormatId::STARWRITER_8_TEMPLATE : SotClipboardFormatId::STARWRITER_8;
    1202        2670 :         *pLongUserName = SW_RESSTR(STR_WRITER_DOCUMENT_FULLTYPE);
    1203             :     }
    1204             : // #FIXME check with new Event handling
    1205             : #if 0
    1206             :     uno::Reference< document::XVbaEventsHelper > xVbaEventsHelper = m_pDoc->GetVbaEventsHelper();
    1207             :     if( xVbaEventsHelper.is() )
    1208             :         lcl_processCompatibleSfxHint( xVbaEventsHelper, rHint );
    1209             : #endif
    1210             : 
    1211        2670 :     *pUserName = SW_RESSTR(STR_HUMAN_SWDOC_NAME);
    1212        2670 : }
    1213             : 
    1214      118756 : void SwDocShell::SetModified( bool bSet )
    1215             : {
    1216      118756 :     SfxObjectShell::SetModified( bSet );
    1217      118756 :     if( IsEnableSetModified())
    1218             :     {
    1219      117282 :          if (!m_pDoc->getIDocumentState().IsInCallModified())
    1220             :          {
    1221       14478 :             EnableSetModified( false );
    1222       14478 :             if( bSet )
    1223             :             {
    1224        6955 :                 bool const bOld = m_pDoc->getIDocumentState().IsModified();
    1225        6955 :                 m_pDoc->getIDocumentState().SetModified();
    1226        6955 :                 if( !bOld )
    1227             :                 {
    1228          41 :                     m_pDoc->GetIDocumentUndoRedo().SetUndoNoResetModified();
    1229             :                 }
    1230             :             }
    1231             :             else
    1232        7523 :                 m_pDoc->getIDocumentState().ResetModified();
    1233             : 
    1234       14478 :             EnableSetModified( true );
    1235             :          }
    1236             : 
    1237      117282 :         UpdateChildWindows();
    1238      117282 :         Broadcast(SfxSimpleHint(SFX_HINT_DOCCHANGED));
    1239             :     }
    1240      118756 : }
    1241             : 
    1242      117282 : void SwDocShell::UpdateChildWindows()
    1243             : {
    1244             :     // if necessary newly initialize Fielddlg (i.e. for TYP_SETVAR)
    1245      117282 :     if(!GetView())
    1246      200065 :         return;
    1247       34499 :     SfxViewFrame* pVFrame = GetView()->GetViewFrame();
    1248             :     SwFieldDlgWrapper *pWrp = static_cast<SwFieldDlgWrapper*>(pVFrame->
    1249       34499 :             GetChildWindow( SwFieldDlgWrapper::GetChildWindowId() ));
    1250       34499 :     if( pWrp )
    1251           0 :         pWrp->ReInitDlg( this );
    1252             : 
    1253             :     // if necessary newly initialize RedlineDlg
    1254             :     SwRedlineAcceptChild *pRed = static_cast<SwRedlineAcceptChild*>(pVFrame->
    1255       34499 :             GetChildWindow( SwRedlineAcceptChild::GetChildWindowId() ));
    1256       34499 :     if( pRed )
    1257           0 :         pRed->ReInitDlg( this );
    1258             : }
    1259             : 
    1260             : // #i48748#
    1261           0 : class SwReloadFromHtmlReader : public SwReader
    1262             : {
    1263             :     public:
    1264           0 :         SwReloadFromHtmlReader( SfxMedium& _rTmpMedium,
    1265             :                                 const OUString& _rFilename,
    1266             :                                 SwDoc* _pDoc )
    1267           0 :             : SwReader( _rTmpMedium, _rFilename, _pDoc )
    1268             :         {
    1269           0 :             SetBaseURL( _rFilename );
    1270           0 :         }
    1271             : };
    1272             : 
    1273           0 : void SwDocShell::ReloadFromHtml( const OUString& rStreamName, SwSrcView* pSrcView )
    1274             : {
    1275           0 :     bool bModified = IsModified();
    1276             : 
    1277             :     // The HTTP-Header fields have to be removed, otherwise
    1278             :     // there are some from Meta-Tags dublicated or triplicated afterwards.
    1279           0 :     ClearHeaderAttributesForSourceViewHack();
    1280             : 
    1281             : #if HAVE_FEATURE_SCRIPTING
    1282             :     // The Document-Basic also bites the dust ...
    1283             :     // A EnterBasicCall is not needed here, because nothing is called and
    1284             :     // there can't be any Dok-Basic, that has not yet been loaded inside
    1285             :     // of an HTML document.
    1286           0 :     SvxHtmlOptions& rHtmlOptions = SvxHtmlOptions::Get();
    1287             :     //#59620# HasBasic() shows, that there already is a BasicManager at the DocShell.
    1288             :     //          That was always generated in HTML-Import, when there are
    1289             :     //          Macros in the source code.
    1290           0 :     if( rHtmlOptions.IsStarBasic() && HasBasic())
    1291             :     {
    1292           0 :         BasicManager *pBasicMan = GetBasicManager();
    1293           0 :         if( pBasicMan && (pBasicMan != SfxApplication::GetBasicManager()) )
    1294             :         {
    1295           0 :             sal_uInt16 nLibCount = pBasicMan->GetLibCount();
    1296           0 :             while( nLibCount )
    1297             :             {
    1298           0 :                 StarBASIC *pBasic = pBasicMan->GetLib( --nLibCount );
    1299           0 :                 if( pBasic )
    1300             :                 {
    1301             :                     // Notify the IDE
    1302           0 :                     SfxUsrAnyItem aShellItem( SID_BASICIDE_ARG_DOCUMENT_MODEL, makeAny( GetModel() ) );
    1303           0 :                     OUString aLibName( pBasic->GetName() );
    1304           0 :                     SfxStringItem aLibNameItem( SID_BASICIDE_ARG_LIBNAME, aLibName );
    1305             :                     pSrcView->GetViewFrame()->GetDispatcher()->Execute(
    1306             :                                             SID_BASICIDE_LIBREMOVED,
    1307             :                                             SfxCallMode::SYNCHRON,
    1308           0 :                                             &aShellItem, &aLibNameItem, 0L );
    1309             : 
    1310             :                     // Only the modules are deleted from the standard-lib
    1311           0 :                     if( nLibCount )
    1312           0 :                         pBasicMan->RemoveLib( nLibCount, true );
    1313             :                     else
    1314           0 :                         pBasic->Clear();
    1315             :                 }
    1316             :             }
    1317             : 
    1318             :             OSL_ENSURE( pBasicMan->GetLibCount() <= 1,
    1319             :                     "Deleting Basics didn't work" );
    1320             :         }
    1321             :     }
    1322             : #endif
    1323           0 :     bool bWasBrowseMode = m_pDoc->getIDocumentSettingAccess().get(DocumentSettingId::BROWSE_MODE);
    1324           0 :     RemoveLink();
    1325             : 
    1326             :     // now also the UNO-Model has to be informed about the new Doc #51535#
    1327           0 :     uno::Reference<text::XTextDocument> xDoc(GetBaseModel(), uno::UNO_QUERY);
    1328           0 :     text::XTextDocument* pxDoc = xDoc.get();
    1329           0 :     static_cast<SwXTextDocument*>(pxDoc)->InitNewDoc();
    1330             : 
    1331           0 :     AddLink();
    1332             :     //#116402# update font list when new document is created
    1333           0 :     UpdateFontList();
    1334           0 :     m_pDoc->getIDocumentSettingAccess().set(DocumentSettingId::BROWSE_MODE, bWasBrowseMode);
    1335           0 :     pSrcView->SetPool(&GetPool());
    1336             : 
    1337           0 :     const OUString& rMedname = GetMedium()->GetName();
    1338             : 
    1339             :     // The HTML template still has to be set
    1340           0 :     SetHTMLTemplate( *GetDoc() );   //Styles from HTML.vor
    1341             : 
    1342           0 :     SfxViewShell* pViewShell = GetView() ? static_cast<SfxViewShell*>(GetView())
    1343           0 :                                          : SfxViewShell::Current();
    1344           0 :     SfxViewFrame*  pViewFrm = pViewShell->GetViewFrame();
    1345           0 :     pViewFrm->GetDispatcher()->Execute( SID_VIEWSHELL0, SfxCallMode::SYNCHRON );
    1346             : 
    1347           0 :     SubInitNew();
    1348             : 
    1349           0 :     SfxMedium aMed( rStreamName, StreamMode::READ );
    1350             :     // #i48748# - use class <SwReloadFromHtmlReader>, because
    1351             :     // the base URL has to be set to the filename of the document <rMedname>
    1352             :     // and not to the base URL of the temporary file <aMed> in order to get
    1353             :     // the URLs of the linked graphics correctly resolved.
    1354           0 :     SwReloadFromHtmlReader aReader( aMed, rMedname, m_pDoc );
    1355             : 
    1356           0 :     aReader.Read( *ReadHTML );
    1357             : 
    1358           0 :     const SwView* pCurrView = GetView();
    1359             :     //in print layout the first page(s) may have been formatted as a mix of browse
    1360             :     //and print layout
    1361           0 :     if(!bWasBrowseMode && pCurrView)
    1362             :     {
    1363           0 :         SwWrtShell& rWrtSh = pCurrView->GetWrtShell();
    1364           0 :         if( rWrtSh.GetLayout())
    1365           0 :             rWrtSh.CheckBrowseView( true );
    1366             :     }
    1367             : 
    1368             :     // Take HTTP-Header-Attibutes over into the DokInfo again.
    1369             :     // The Base-URL doesn't matter here because TLX uses the one from the document
    1370             :     // for absolutization.
    1371           0 :     SetHeaderAttributesForSourceViewHack();
    1372             : 
    1373           0 :     if(bModified && !IsReadOnly())
    1374           0 :         SetModified();
    1375             :     else
    1376           0 :         m_pDoc->getIDocumentState().ResetModified();
    1377           0 : }
    1378             : 
    1379           0 : sal_uLong SwDocShell::LoadStylesFromFile( const OUString& rURL,
    1380             :                     SwgReaderOption& rOpt, bool bUnoCall )
    1381             : {
    1382           0 :     sal_uLong nErr = 0;
    1383             : 
    1384             :     // Set filter:
    1385           0 :     OUString sFactory(OUString::createFromAscii(SwDocShell::Factory().GetShortName()));
    1386           0 :     SfxFilterMatcher aMatcher( sFactory );
    1387             : 
    1388             :     // search for filter in WebDocShell, too
    1389           0 :     SfxMedium aMed( rURL, STREAM_STD_READ );
    1390           0 :     const SfxFilter* pFlt = 0;
    1391           0 :     aMatcher.DetectFilter( aMed, &pFlt, false, false );
    1392           0 :     if(!pFlt)
    1393             :     {
    1394           0 :         OUString sWebFactory(OUString::createFromAscii(SwWebDocShell::Factory().GetShortName()));
    1395           0 :         SfxFilterMatcher aWebMatcher( sWebFactory );
    1396           0 :         aWebMatcher.DetectFilter( aMed, &pFlt, false, false );
    1397             :     }
    1398             :     // --> OD #i117339# - trigger import only for own formats
    1399           0 :     bool bImport( false );
    1400             :     {
    1401           0 :         if ( aMed.IsStorage() )
    1402             :         {
    1403             :             // As <SfxMedium.GetFilter().IsOwnFormat() resp. IsOwnTemplateFormat()
    1404             :             // does not work correct (e.g., MS Word 2007 XML Template),
    1405             :             // use workaround provided by MAV.
    1406           0 :             uno::Reference< embed::XStorage > xStorage = aMed.GetStorage();
    1407           0 :             if ( xStorage.is() )
    1408             :             {
    1409             :                 // use <try-catch> on retrieving <MediaType> in order to check,
    1410             :                 // if the storage is one of our own ones.
    1411             :                 try
    1412             :                 {
    1413           0 :                     uno::Reference< beans::XPropertySet > xProps( xStorage, uno::UNO_QUERY_THROW );
    1414           0 :                     const OUString aMediaTypePropName( "MediaType" );
    1415           0 :                     xProps->getPropertyValue( aMediaTypePropName );
    1416           0 :                     bImport = true;
    1417             :                 }
    1418           0 :                 catch (const uno::Exception&)
    1419             :                 {
    1420           0 :                     bImport = false;
    1421             :                 }
    1422           0 :             }
    1423             :         }
    1424             :     }
    1425           0 :     if ( bImport )
    1426             :     {
    1427           0 :         SwRead pRead =  ReadXML;
    1428           0 :         boost::scoped_ptr<SwReader> pReader;
    1429           0 :         boost::scoped_ptr<SwPaM> pPam;
    1430             :         // the SW3IO - Reader need the pam/wrtshell, because only then he
    1431             :         // insert the styles!
    1432           0 :         if( bUnoCall )
    1433             :         {
    1434           0 :             SwNodeIndex aIdx( m_pDoc->GetNodes().GetEndOfContent(), -1 );
    1435           0 :             pPam.reset(new SwPaM( aIdx ));
    1436           0 :             pReader.reset(new SwReader( aMed, rURL, *pPam ));
    1437             :         }
    1438             :         else
    1439             :         {
    1440           0 :             pReader.reset(new SwReader( aMed, rURL, *m_pWrtShell->GetCrsr() ));
    1441             :         }
    1442             : 
    1443           0 :         pRead->GetReaderOpt().SetTextFormats( rOpt.IsTextFormats() );
    1444           0 :         pRead->GetReaderOpt().SetFrameFormats( rOpt.IsFrameFormats() );
    1445           0 :         pRead->GetReaderOpt().SetPageDescs( rOpt.IsPageDescs() );
    1446           0 :         pRead->GetReaderOpt().SetNumRules( rOpt.IsNumRules() );
    1447           0 :         pRead->GetReaderOpt().SetMerge( rOpt.IsMerge() );
    1448             : 
    1449           0 :         if( bUnoCall )
    1450             :         {
    1451           0 :             UnoActionContext aAction( m_pDoc );
    1452           0 :             nErr = pReader->Read( *pRead );
    1453             :         }
    1454             :         else
    1455             :         {
    1456           0 :             m_pWrtShell->StartAllAction();
    1457           0 :             nErr = pReader->Read( *pRead );
    1458           0 :             m_pWrtShell->EndAllAction();
    1459           0 :         }
    1460             :     }
    1461             : 
    1462           0 :     return nErr;
    1463             : }
    1464             : 
    1465             : // Get a client for an embedded object if possible.
    1466          13 : SfxInPlaceClient* SwDocShell::GetIPClient( const ::svt::EmbeddedObjectRef& xObjRef )
    1467             : {
    1468          13 :     SfxInPlaceClient* pResult = NULL;
    1469             : 
    1470          13 :     SwWrtShell* pShell = GetWrtShell();
    1471          13 :     if ( pShell )
    1472             :     {
    1473           8 :         pResult = pShell->GetView().FindIPClient( xObjRef.GetObject(), &pShell->GetView().GetEditWin() );
    1474           8 :         if ( !pResult )
    1475           7 :             pResult = new SwOleClient( &pShell->GetView(), &pShell->GetView().GetEditWin(), xObjRef );
    1476             :     }
    1477             : 
    1478          13 :     return pResult;
    1479             : }
    1480             : 
    1481           0 : static bool lcl_MergePortions(SwNode *const& pNode, void *)
    1482             : {
    1483           0 :     if (pNode->IsTextNode())
    1484             :     {
    1485           0 :         pNode->GetTextNode()->FileLoadedInitHints();
    1486             :     }
    1487           0 :     return true;
    1488             : }
    1489             : 
    1490           0 : int SwFindDocShell( SfxObjectShellRef& xDocSh,
    1491             :                     SfxObjectShellLock& xLockRef,
    1492             :                     const OUString& rFileName,
    1493             :                     const OUString& rPasswd,
    1494             :                     const OUString& rFilter,
    1495             :                     sal_Int16 nVersion,
    1496             :                     SwDocShell* pDestSh )
    1497             : {
    1498           0 :     if ( rFileName.isEmpty() )
    1499           0 :         return 0;
    1500             : 
    1501             :     // 1. Does the file already exist in the list of all Documents?
    1502           0 :     INetURLObject aTmpObj( rFileName );
    1503           0 :     aTmpObj.SetMark( OUString() );
    1504             : 
    1505             :     // Iterate over the DocShell and get the ones with the name
    1506           0 :     TypeId aType( TYPE(SwDocShell) );
    1507             : 
    1508           0 :     SfxObjectShell* pShell = pDestSh;
    1509           0 :     bool bFirst = 0 != pShell;
    1510             : 
    1511           0 :     if( !bFirst )
    1512             :         // No DocShell passed, starting with the first from the DocShell list
    1513           0 :         pShell = SfxObjectShell::GetFirst( &aType );
    1514             : 
    1515           0 :     while( pShell )
    1516             :     {
    1517             :         // We want this one
    1518           0 :         SfxMedium* pMed = pShell->GetMedium();
    1519           0 :         if( pMed && pMed->GetURLObject() == aTmpObj )
    1520             :         {
    1521             :             const SfxPoolItem* pItem;
    1522           0 :             if( ( SfxItemState::SET == pMed->GetItemSet()->GetItemState(
    1523           0 :                                             SID_VERSION, false, &pItem ) )
    1524           0 :                     ? (nVersion == static_cast<const SfxInt16Item*>(pItem)->GetValue())
    1525             :                     : !nVersion )
    1526             :             {
    1527             :                 // Found, thus return
    1528           0 :                 xDocSh = pShell;
    1529           0 :                 return 1;
    1530             :             }
    1531             :         }
    1532             : 
    1533           0 :         if( bFirst )
    1534             :         {
    1535           0 :             bFirst = false;
    1536           0 :             pShell = SfxObjectShell::GetFirst( &aType );
    1537             :         }
    1538             :         else
    1539           0 :             pShell = SfxObjectShell::GetNext( *pShell, &aType );
    1540             :     }
    1541             : 
    1542             :     // 2. Open the file ourselves
    1543             :     SfxMedium* pMed = new SfxMedium( aTmpObj.GetMainURL(
    1544           0 :                              INetURLObject::NO_DECODE ), StreamMode::READ );
    1545           0 :     if( INetProtocol::File == aTmpObj.GetProtocol() )
    1546           0 :         pMed->Download(); // Touch the medium (download it)
    1547             : 
    1548           0 :     const SfxFilter* pSfxFlt = 0;
    1549           0 :     if( !pMed->GetError() )
    1550             :     {
    1551           0 :         SfxFilterMatcher aMatcher( OUString::createFromAscii(SwDocShell::Factory().GetShortName()) );
    1552             : 
    1553             :         // No Filter, so search for it. Else test if the one passed is a valid one
    1554           0 :         if( !rFilter.isEmpty() )
    1555             :         {
    1556           0 :             pSfxFlt = aMatcher.GetFilter4FilterName( rFilter );
    1557             :         }
    1558             : 
    1559           0 :         if( nVersion )
    1560           0 :             pMed->GetItemSet()->Put( SfxInt16Item( SID_VERSION, nVersion ));
    1561             : 
    1562           0 :         if( !rPasswd.isEmpty() )
    1563           0 :             pMed->GetItemSet()->Put( SfxStringItem( SID_PASSWORD, rPasswd ));
    1564             : 
    1565           0 :         if( !pSfxFlt )
    1566           0 :             aMatcher.DetectFilter( *pMed, &pSfxFlt, false, false );
    1567             : 
    1568           0 :         if( pSfxFlt )
    1569             :         {
    1570             :             // We cannot do anything without a Filter
    1571           0 :             pMed->SetFilter( pSfxFlt );
    1572             : 
    1573             :             // If the new shell is created, SfxObjectShellLock should be used to let it be closed later for sure
    1574           0 :             SwDocShell *const pNew(new SwDocShell(SfxObjectCreateMode::INTERNAL));
    1575           0 :             xLockRef = pNew;
    1576           0 :             xDocSh = static_cast<SfxObjectShell*>(xLockRef);
    1577           0 :             if( xDocSh->DoLoad( pMed ) )
    1578             :             {
    1579           0 :                 SwDoc const& rDoc(*pNew->GetDoc());
    1580           0 :                 const_cast<SwDoc&>(rDoc).GetNodes().ForEach(&lcl_MergePortions);
    1581           0 :                 return 2;
    1582             :             }
    1583           0 :         }
    1584             :     }
    1585             : 
    1586           0 :     if( !xDocSh.Is() ) // Medium still needs to be deleted
    1587           0 :         delete pMed;
    1588             : 
    1589           0 :     return 0;
    1590         177 : }
    1591             : 
    1592             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11