LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/ui/app - docsh2.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 149 846 17.6 %
Date: 2013-07-09 Functions: 12 23 52.2 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10