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

Generated by: LCOV version 1.10