LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sd/source/ui/func - fuinsfil.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 364 0.3 %
Date: 2013-07-09 Functions: 2 15 13.3 %
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 "fuinsfil.hxx"
      22             : #include <vcl/wrkwin.hxx>
      23             : #include <sfx2/progress.hxx>
      24             : #include <editeng/outliner.hxx>
      25             : #include <editeng/outlobj.hxx>
      26             : #include <editeng/editeng.hxx>
      27             : #include <svl/stritem.hxx>
      28             : #include <sfx2/request.hxx>
      29             : #include <sfx2/app.hxx>
      30             : #include <vcl/msgbox.hxx>
      31             : #include <sfx2/printer.hxx>
      32             : #include <svx/svdorect.hxx>
      33             : #include <svx/svdundo.hxx>
      34             : #include <svx/svdoutl.hxx>
      35             : #include <sfx2/filedlghelper.hxx>
      36             : #include <sot/formats.hxx>
      37             : #include <svl/urihelper.hxx>
      38             : #include <editeng/forbiddencharacterstable.hxx>
      39             : #include <sfx2/docfile.hxx>
      40             : #include <sfx2/docfilt.hxx>
      41             : #include <sfx2/fcontnr.hxx>
      42             : #include <svx/svdpagv.hxx>
      43             : #include <svx/dialogs.hrc>
      44             : #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
      45             : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
      46             : #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
      47             : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      48             : 
      49             : #include "sdresid.hxx"
      50             : #include "drawdoc.hxx"
      51             : #include "Window.hxx"
      52             : #include "View.hxx"
      53             : #include "strings.hrc"
      54             : #include "stlpool.hxx"
      55             : #include "glob.hrc"
      56             : #include "sdpage.hxx"
      57             : #include "strmname.h"
      58             : #include "DrawViewShell.hxx"
      59             : #include "OutlineViewShell.hxx"
      60             : #include "DrawDocShell.hxx"
      61             : #include "GraphicDocShell.hxx"
      62             : #include "app.hrc"
      63             : #include "unmovss.hxx"
      64             : #include "Outliner.hxx"
      65             : #include "sdabstdlg.hxx"
      66             : 
      67             : using namespace ::com::sun::star::lang;
      68             : using namespace ::com::sun::star::uno;
      69             : using namespace ::com::sun::star::ui::dialogs;
      70             : using namespace ::com::sun::star;
      71             : 
      72             : namespace sd {
      73             : 
      74           0 : TYPEINIT1( FuInsertFile, FuPoor );
      75             : 
      76             : 
      77           0 : FuInsertFile::FuInsertFile (
      78             :     ViewShell*    pViewSh,
      79             :     ::sd::Window*      pWin,
      80             :     ::sd::View*        pView,
      81             :     SdDrawDocument* pDoc,
      82             :     SfxRequest&    rReq)
      83           0 :     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
      84             : {
      85           0 : }
      86             : 
      87           0 : FunctionReference FuInsertFile::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
      88             : {
      89           0 :     FunctionReference xFunc( new FuInsertFile( pViewSh, pWin, pView, pDoc, rReq ) );
      90           0 :     xFunc->DoExecute(rReq);
      91           0 :     return xFunc;
      92             : }
      93             : 
      94           0 : void FuInsertFile::DoExecute( SfxRequest& rReq )
      95             : {
      96           0 :     SfxFilterMatcher&       rMatcher = SFX_APP()->GetFilterMatcher();
      97           0 :     ::std::vector< OUString > aFilterVector;
      98           0 :     const SfxItemSet*       pArgs = rReq.GetArgs ();
      99             : 
     100           0 :     FuInsertFile::GetSupportedFilterVector( aFilterVector );
     101             : 
     102           0 :     if (!pArgs)
     103             :     {
     104             :         sfx2::FileDialogHelper      aFileDialog(
     105             :                 ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
     106           0 :                 SFXWB_INSERT );
     107           0 :         Reference< XFilePicker >    xFilePicker( aFileDialog.GetFilePicker(), UNO_QUERY );
     108           0 :         Reference< XFilterManager > xFilterManager( xFilePicker, UNO_QUERY );
     109           0 :         OUString aOwnCont;
     110           0 :         OUString aOtherCont;
     111           0 :         const SfxFilter*            pFilter = NULL;
     112             : 
     113           0 :         aFileDialog.SetTitle( String( SdResId(STR_DLG_INSERT_PAGES_FROM_FILE ) ) );
     114             : 
     115           0 :         if( mpDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS )
     116             :         {
     117           0 :             aOwnCont = "simpress";
     118           0 :             aOtherCont = "sdraw";
     119             :         }
     120             :         else
     121             :         {
     122           0 :             aOtherCont = "simpress";
     123           0 :             aOwnCont = "sdraw" ;
     124             :         }
     125             : 
     126           0 :         SfxFilterMatcher aMatch( aOwnCont );
     127             : 
     128           0 :         if( xFilterManager.is() )
     129             :         {
     130             :             // Get filter for current format
     131             :             try
     132             :             {
     133           0 :                 String  aExt;
     134           0 :                 String  aAllSpec( SdResId( STR_ALL_FILES ) );
     135             : 
     136           0 :                 xFilterManager->appendFilter( aAllSpec, OUString("*.*") );
     137           0 :                 xFilterManager->setCurrentFilter( aAllSpec ); // set default-filter (<All>)
     138             : 
     139             :                 // Get main filter
     140           0 :                 pFilter = SfxFilter::GetDefaultFilterFromFactory( aOwnCont );
     141           0 :                 if( pFilter )
     142           0 :                     xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
     143             : 
     144             :                 // get cross filter
     145           0 :                 pFilter = SfxFilter::GetDefaultFilterFromFactory( aOtherCont );
     146           0 :                 if( pFilter )
     147             :                 {
     148           0 :                     pFilter = aMatch.GetFilter4Extension( pFilter->GetDefaultExtension() );
     149           0 :                     if ( pFilter )
     150           0 :                         xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
     151             :                 }
     152             : 
     153             :                 // get femplate filter
     154           0 :                 if( mpDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS )
     155           0 :                     pFilter = DrawDocShell::Factory().GetTemplateFilter();
     156             :                 else
     157           0 :                     pFilter = GraphicDocShell::Factory().GetTemplateFilter();
     158           0 :                 if( pFilter )
     159           0 :                     xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
     160             : 
     161             :                 // get Powerpoint filter
     162           0 :                 aExt = OUString(".ppt");
     163           0 :                 pFilter = aMatch.GetFilter4Extension( aExt );
     164           0 :                 if( pFilter )
     165           0 :                     xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
     166             : 
     167             :                 // Get other draw/impress filters
     168           0 :                 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARIMPRESS_60, SFX_FILTER_IMPORT, SFX_FILTER_TEMPLATEPATH );
     169           0 :                 if( pFilter )
     170           0 :                     xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
     171             : 
     172           0 :                 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARIMPRESS_60, SFX_FILTER_TEMPLATEPATH );
     173           0 :                 if( pFilter )
     174           0 :                     xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
     175             : 
     176           0 :                 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_60, SFX_FILTER_IMPORT, SFX_FILTER_TEMPLATEPATH  );
     177           0 :                 if( pFilter )
     178           0 :                     xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
     179             : 
     180           0 :                 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_60, SFX_FILTER_TEMPLATEPATH  );
     181           0 :                 if( pFilter )
     182           0 :                     xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
     183             : 
     184           0 :                 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARIMPRESS_50, SFX_FILTER_IMPORT, SFX_FILTER_TEMPLATEPATH  );
     185           0 :                 if( pFilter )
     186           0 :                     xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
     187             : 
     188           0 :                 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARIMPRESS_50, SFX_FILTER_TEMPLATEPATH );
     189           0 :                 if( pFilter )
     190           0 :                     xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
     191             : 
     192           0 :                 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_50, SFX_FILTER_IMPORT, SFX_FILTER_TEMPLATEPATH  );
     193           0 :                 if( pFilter )
     194           0 :                     xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
     195             : 
     196           0 :                 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_50, SFX_FILTER_TEMPLATEPATH  );
     197           0 :                 if( pFilter )
     198           0 :                     xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
     199             : 
     200           0 :                 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_40, SFX_FILTER_IMPORT, SFX_FILTER_TEMPLATEPATH  );
     201           0 :                 if( pFilter )
     202           0 :                     xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
     203             : 
     204           0 :                 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW_40, SFX_FILTER_TEMPLATEPATH  );
     205           0 :                 if( pFilter )
     206           0 :                     xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
     207             : 
     208           0 :                 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW, SFX_FILTER_IMPORT, SFX_FILTER_TEMPLATEPATH  );
     209           0 :                 if( pFilter )
     210           0 :                     xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
     211             : 
     212           0 :                 pFilter = aMatch.GetFilter4ClipBoardId( SOT_FORMATSTR_ID_STARDRAW, SFX_FILTER_TEMPLATEPATH  );
     213           0 :                 if( pFilter )
     214           0 :                     xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
     215             : 
     216             :                 // add additional supported filters
     217           0 :                 ::std::vector< OUString >::const_iterator aIter( aFilterVector.begin() );
     218             : 
     219           0 :                 while( aIter != aFilterVector.end() )
     220             :                 {
     221           0 :                     if( ( pFilter = rMatcher.GetFilter4Mime( *aIter ) ) != NULL )
     222           0 :                         xFilterManager->appendFilter( pFilter->GetUIName(), pFilter->GetDefaultExtension() );
     223             : 
     224           0 :                     ++aIter;
     225           0 :                 }
     226             :             }
     227           0 :             catch (const IllegalArgumentException&)
     228             :             {
     229             :             }
     230             :         }
     231             : 
     232           0 :         if( aFileDialog.Execute() != ERRCODE_NONE )
     233           0 :             return;
     234             :         else
     235             :         {
     236           0 :             aFilterName = aFileDialog.GetCurrentFilter();
     237           0 :             aFile = aFileDialog.GetPath();
     238           0 :         }
     239             :     }
     240             :     else
     241             :     {
     242           0 :         SFX_REQUEST_ARG (rReq, pFileName, SfxStringItem, ID_VAL_DUMMY0, sal_False);
     243           0 :         SFX_REQUEST_ARG (rReq, pFilterName, SfxStringItem, ID_VAL_DUMMY1, sal_False);
     244             : 
     245           0 :         aFile = pFileName->GetValue ();
     246             : 
     247           0 :         if( pFilterName )
     248           0 :             aFilterName = pFilterName->GetValue ();
     249             :     }
     250             : 
     251           0 :     mpDocSh->SetWaitCursor( sal_True );
     252             : 
     253           0 :     SfxMedium*          pMedium = new SfxMedium( aFile, STREAM_READ | STREAM_NOCREATE );
     254           0 :     const SfxFilter*    pFilter = NULL;
     255             : 
     256           0 :     SFX_APP()->GetFilterMatcher().GuessFilter( *pMedium, &pFilter, SFX_FILTER_IMPORT, SFX_FILTER_NOTINSTALLED | SFX_FILTER_EXECUTABLE );
     257             : 
     258           0 :     sal_Bool                bDrawMode = mpViewShell && mpViewShell->ISA(DrawViewShell);
     259           0 :     sal_Bool                bInserted = sal_False;
     260             : 
     261           0 :     if( pFilter )
     262             :     {
     263           0 :         pMedium->SetFilter( pFilter );
     264           0 :         aFilterName = pFilter->GetFilterName();
     265             : 
     266           0 :         if( pMedium->IsStorage() || ( pMedium->GetInStream() && SotStorage::IsStorageFile( pMedium->GetInStream() ) ) )
     267             :         {
     268           0 :             if ( pFilter->GetServiceName() == "com.sun.star.presentation.PresentationDocument" ||
     269           0 :                  pFilter->GetServiceName() == "com.sun.star.drawing.DrawingDocument" )
     270             :             {
     271             :                 // Draw, Impress or PowerPoint document
     272             :                 // the ownership of the Medium is transferred
     273           0 :                 if( bDrawMode )
     274           0 :                     InsSDDinDrMode( pMedium );
     275             :                 else
     276           0 :                     InsSDDinOlMode( pMedium );
     277             : 
     278             :                 // don't delete Medium here, ownership of pMedium has changed in this case
     279           0 :                 bInserted = sal_True;
     280             :             }
     281             :         }
     282             :         else
     283             :         {
     284           0 :             sal_Bool bFound = ( ::std::find( aFilterVector.begin(), aFilterVector.end(), pFilter->GetMimeType() ) != aFilterVector.end() );
     285           0 :             if( !bFound &&
     286           0 :                 ( aFilterName.SearchAscii( "Text" ) != STRING_NOTFOUND ||
     287           0 :                 aFilterName.SearchAscii( "Rich" ) != STRING_NOTFOUND ||
     288           0 :                 aFilterName.SearchAscii( "RTF" )  != STRING_NOTFOUND ||
     289           0 :                 aFilterName.SearchAscii( "HTML" ) != STRING_NOTFOUND ) )
     290             :             {
     291           0 :                 bFound = sal_True;
     292             :             }
     293             : 
     294           0 :             if( bFound )
     295             :             {
     296           0 :                 if( bDrawMode )
     297           0 :                     InsTextOrRTFinDrMode(pMedium);
     298             :                 else
     299           0 :                     InsTextOrRTFinOlMode(pMedium);
     300             : 
     301           0 :                 bInserted = sal_True;
     302           0 :                 delete pMedium;
     303             :             }
     304             :         }
     305             :     }
     306             : 
     307           0 :     mpDocSh->SetWaitCursor( sal_False );
     308             : 
     309           0 :     if( !bInserted )
     310             :     {
     311           0 :         ErrorBox aErrorBox( mpWindow, WB_OK, String( SdResId( STR_READ_DATA_ERROR ) ) );
     312           0 :         aErrorBox.Execute();
     313           0 :         delete pMedium;
     314           0 :     }
     315             : }
     316             : 
     317             : // -----------------------------------------------------------------------------
     318             : 
     319           0 : sal_Bool FuInsertFile::InsSDDinDrMode(SfxMedium* pMedium)
     320             : {
     321           0 :     sal_Bool bOK = sal_False;
     322             : 
     323           0 :     mpDocSh->SetWaitCursor( sal_False );
     324           0 :     SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
     325           0 :     AbstractSdInsertPagesObjsDlg* pDlg = pFact ? pFact->CreateSdInsertPagesObjsDlg( NULL, mpDoc, pMedium, aFile ) : 0;
     326             : 
     327           0 :     if( !pDlg )
     328           0 :         return sal_False;
     329             : 
     330             :     /* Maybe a QueryBox is opened ("update links?"), therefore the dialog
     331             :        becomes the current DefModalDialogParent */
     332           0 :     ::Window* pDefParent = GetpApp()->GetDefDialogParent();
     333           0 :     GetpApp()->SetDefDialogParent(pDlg->GetWindow());
     334             : 
     335           0 :     sal_uInt16 nRet = pDlg->Execute();
     336             : 
     337           0 :     GetpApp()->SetDefDialogParent(pDefParent);
     338             : 
     339           0 :     mpDocSh->SetWaitCursor( sal_True );
     340             : 
     341           0 :     if( nRet == RET_OK )
     342             :     {
     343             :         /* list with page names (if NULL, then all pages)
     344             :            First, insert pages */
     345           0 :         std::vector<OUString> aBookmarkList = pDlg->GetList( 1 ); // pages
     346           0 :         sal_Bool bLink = pDlg->IsLink();
     347           0 :         sal_Bool bReplace = sal_False;
     348           0 :         SdPage* pPage = NULL;
     349           0 :         ::sd::View* pView = mpViewShell->GetView();
     350             : 
     351           0 :         if (pView->ISA(OutlineView))
     352             :         {
     353           0 :             pPage = static_cast<OutlineView*>(pView)->GetActualPage();
     354             :         }
     355             :         else
     356             :         {
     357           0 :             pPage = static_cast<SdPage*>(pView->GetSdrPageView()->GetPage());
     358             :         }
     359             : 
     360           0 :         sal_uInt16 nPos = 0xFFFF;
     361             : 
     362           0 :         if (pPage && !pPage->IsMasterPage())
     363             :         {
     364           0 :             if (pPage->GetPageKind() == PK_STANDARD)
     365             :             {
     366           0 :                 nPos = pPage->GetPageNum() + 2;
     367             :             }
     368           0 :             else if (pPage->GetPageKind() == PK_NOTES)
     369             :             {
     370           0 :                 nPos = pPage->GetPageNum() + 1;
     371             :             }
     372             :         }
     373             : 
     374             :         sal_Bool  bNameOK;
     375           0 :         std::vector<OUString> aExchangeList;
     376           0 :         std::vector<OUString> aObjectBookmarkList = pDlg->GetList( 2 ); // objects
     377             : 
     378             :         /* if pBookmarkList is NULL, we insert selected pages, and/or selected
     379             :            objects or everything. */
     380           0 :         if( !aBookmarkList.empty() || aObjectBookmarkList.empty() )
     381             :         {
     382             :             /* To ensure that all page names are unique, we check the ones we
     383             :                want to insert and insert them into a substitution list if
     384             :                necessary.
     385             :                bNameOK is sal_False if the user has canceled. */
     386           0 :             bNameOK = mpView->GetExchangeList( aExchangeList, aBookmarkList, 0 );
     387             : 
     388           0 :             if( bNameOK )
     389             :                 bOK = mpDoc->InsertBookmarkAsPage( aBookmarkList, &aExchangeList,
     390             :                                     bLink, bReplace, nPos,
     391           0 :                                     sal_False, NULL, sal_True, sal_True, sal_False );
     392             : 
     393           0 :             aBookmarkList.clear();
     394           0 :             aExchangeList.clear();
     395             :         }
     396             : 
     397             :         // to ensure ... (see above)
     398           0 :         bNameOK = mpView->GetExchangeList( aExchangeList, aObjectBookmarkList, 1 );
     399             : 
     400           0 :         if( bNameOK )
     401             :             bOK = mpDoc->InsertBookmarkAsObject( aObjectBookmarkList, aExchangeList,
     402           0 :                                 bLink, NULL, NULL);
     403             : 
     404           0 :         if( pDlg->IsRemoveUnnessesaryMasterPages() )
     405           0 :             mpDoc->RemoveUnnecessaryMasterPages();
     406             :     }
     407             : 
     408           0 :     delete pDlg;
     409             : 
     410           0 :     return (bOK);
     411             : }
     412             : 
     413             : // -----------------------------------------------------------------------------
     414             : 
     415           0 : void FuInsertFile::InsTextOrRTFinDrMode(SfxMedium* pMedium)
     416             : {
     417           0 :     SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
     418           0 :     AbstractSdInsertPagesObjsDlg* pDlg = pFact ? pFact->CreateSdInsertPagesObjsDlg(NULL, mpDoc, NULL, aFile ) : 0;
     419           0 :     if( !pDlg )
     420           0 :         return;
     421             : 
     422           0 :     mpDocSh->SetWaitCursor( sal_False );
     423             : 
     424           0 :     sal_uInt16 nRet = pDlg->Execute();
     425           0 :     mpDocSh->SetWaitCursor( sal_True );
     426             : 
     427           0 :     if( nRet == RET_OK )
     428             :     {
     429             :         // selected file format: text, RTF or HTML (default is text)
     430           0 :         sal_uInt16 nFormat = EE_FORMAT_TEXT;
     431             : 
     432           0 :         if( aFilterName.SearchAscii( "Rich") != STRING_NOTFOUND )
     433           0 :             nFormat = EE_FORMAT_RTF;
     434           0 :         else if( aFilterName.SearchAscii( "HTML" ) != STRING_NOTFOUND )
     435           0 :             nFormat = EE_FORMAT_HTML;
     436             : 
     437             :         /* create our own outline since:
     438             :            - it is possible that the document outliner is actually used in the
     439             :              structuring mode
     440             :            - the draw outliner of the drawing engine has to draw something in
     441             :              between
     442             :            - the global outliner could be used in SdPage::CreatePresObj */
     443           0 :         SdrOutliner* pOutliner = new ::sd::Outliner( mpDoc, OUTLINERMODE_TEXTOBJECT );
     444             : 
     445             :         // set reference device
     446           0 :         pOutliner->SetRefDevice( SD_MOD()->GetRefDevice( *mpDocSh ) );
     447             : 
     448           0 :         SdPage* pPage = static_cast<DrawViewShell*>(mpViewShell)->GetActualPage();
     449           0 :         aLayoutName = pPage->GetLayoutName();
     450           0 :         aLayoutName.Erase(aLayoutName.SearchAscii(SD_LT_SEPARATOR));
     451             : 
     452           0 :         pOutliner->SetPaperSize(pPage->GetSize());
     453             : 
     454           0 :         SvStream* pStream = pMedium->GetInStream();
     455             :         DBG_ASSERT( pStream, "No InStream!" );
     456           0 :         pStream->Seek( 0 );
     457             : 
     458           0 :         sal_uLong nErr = pOutliner->Read( *pStream, pMedium->GetBaseURL(), nFormat, mpDocSh->GetHeaderAttributes() );
     459             : 
     460           0 :         if (nErr || pOutliner->GetEditEngine().GetText().isEmpty())
     461             :         {
     462             :             ErrorBox aErrorBox( mpWindow, (WinBits)WB_OK,
     463           0 :                       String(SdResId(STR_READ_DATA_ERROR)));
     464           0 :             aErrorBox.Execute();
     465             :         }
     466             :         else
     467             :         {
     468             :             // is it a master page?
     469           0 :             if (static_cast<DrawViewShell*>(mpViewShell)->GetEditMode() == EM_MASTERPAGE &&
     470           0 :                 !pPage->IsMasterPage())
     471             :             {
     472           0 :                 pPage = (SdPage*)(&(pPage->TRG_GetMasterPage()));
     473             :             }
     474             : 
     475             :             DBG_ASSERT(pPage, "page not found");
     476             : 
     477             :             // if editing is going on right now, let it flow into this text object
     478           0 :             OutlinerView* pOutlinerView = mpView->GetTextEditOutlinerView();
     479           0 :             if( pOutlinerView )
     480             :             {
     481           0 :                 SdrObject* pObj = mpView->GetTextEditObject();
     482           0 :                 if( pObj &&
     483           0 :                     pObj->GetObjInventor()   == SdrInventor &&
     484           0 :                     pObj->GetObjIdentifier() == OBJ_TITLETEXT &&
     485           0 :                     pOutliner->GetParagraphCount() > 1 )
     486             :                 {
     487             :                     // in title objects, only one paragraph is allowed
     488           0 :                     while ( pOutliner->GetParagraphCount() > 1 )
     489             :                     {
     490           0 :                         Paragraph* pPara = pOutliner->GetParagraph( 0 );
     491           0 :                         sal_uLong nLen = pOutliner->GetText( pPara, 1 ).Len();
     492           0 :                         pOutliner->QuickDelete( ESelection( 0, (sal_uInt16) nLen, 1, 0 ) );
     493           0 :                         pOutliner->QuickInsertLineBreak( ESelection( 0, (sal_uInt16) nLen, 0, (sal_uInt16) nLen ) );
     494             :                     }
     495             :                 }
     496             :             }
     497             : 
     498           0 :             OutlinerParaObject* pOPO = pOutliner->CreateParaObject();
     499             : 
     500           0 :             if (pOutlinerView)
     501             :             {
     502           0 :                 pOutlinerView->InsertText(*pOPO);
     503           0 :                 delete pOPO;
     504             :             }
     505             :             else
     506             :             {
     507           0 :                 SdrRectObj* pTO = new SdrRectObj(OBJ_TEXT);
     508           0 :                 pTO->SetOutlinerParaObject(pOPO);
     509             : 
     510           0 :                 const bool bUndo = mpView->IsUndoEnabled();
     511           0 :                 if( bUndo )
     512           0 :                     mpView->BegUndo(String(SdResId(STR_UNDO_INSERT_TEXTFRAME)));
     513           0 :                 pPage->InsertObject(pTO);
     514             : 
     515             :                 /* can be bigger as the maximal allowed size:
     516             :                    limit object size if necessary */
     517           0 :                 Size aSize(pOutliner->CalcTextSize());
     518           0 :                 Size aMaxSize = mpDoc->GetMaxObjSize();
     519           0 :                 aSize.Height() = std::min(aSize.Height(), aMaxSize.Height());
     520           0 :                 aSize.Width()  = std::min(aSize.Width(), aMaxSize.Width());
     521           0 :                 aSize = mpWindow->LogicToPixel(aSize);
     522             : 
     523             :                 // put it at the center of the window
     524           0 :                 Size aTemp(mpWindow->GetOutputSizePixel());
     525           0 :                 Point aPos(aTemp.Width() / 2, aTemp.Height() / 2);
     526           0 :                 aPos.X() -= aSize.Width() / 2;
     527           0 :                 aPos.Y() -= aSize.Height() / 2;
     528           0 :                 aSize = mpWindow->PixelToLogic(aSize);
     529           0 :                 aPos = mpWindow->PixelToLogic(aPos);
     530           0 :                 pTO->SetLogicRect(Rectangle(aPos, aSize));
     531             : 
     532           0 :                 if (pDlg->IsLink())
     533             :                 {
     534           0 :                     pTO->SetTextLink(aFile, aFilterName, osl_getThreadTextEncoding() );
     535             :                 }
     536             : 
     537           0 :                 if( bUndo )
     538             :                 {
     539           0 :                     mpView->AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoInsertObject(*pTO));
     540           0 :                     mpView->EndUndo();
     541             :                 }
     542             :             }
     543             :         }
     544           0 :         delete pOutliner;
     545             :     }
     546             : 
     547           0 :     delete pDlg;
     548             : }
     549             : 
     550             : // -----------------------------------------------------------------------------
     551             : 
     552           0 : void FuInsertFile::InsTextOrRTFinOlMode(SfxMedium* pMedium)
     553             : {
     554             :     // selected file format: text, RTF or HTML (default is text)
     555           0 :     sal_uInt16 nFormat = EE_FORMAT_TEXT;
     556             : 
     557           0 :     if( aFilterName.SearchAscii( "Rich") != STRING_NOTFOUND )
     558           0 :         nFormat = EE_FORMAT_RTF;
     559           0 :     else if( aFilterName.SearchAscii( "HTML" ) != STRING_NOTFOUND )
     560           0 :         nFormat = EE_FORMAT_HTML;
     561             : 
     562           0 :     ::Outliner*    pDocliner = static_cast<OutlineView*>(mpView)->GetOutliner();
     563             : 
     564           0 :     std::vector<Paragraph*> aSelList;
     565           0 :     pDocliner->GetView(0)->CreateSelectionList(aSelList);
     566             : 
     567           0 :     Paragraph* pPara = aSelList.empty() ? NULL : *(aSelList.begin());
     568             : 
     569             :     // what should we insert?
     570           0 :     while( !pDocliner->HasParaFlag( pPara, PARAFLAG_ISPAGE ) )
     571           0 :         pPara = pDocliner->GetParent(pPara);
     572             : 
     573           0 :     sal_Int32 nTargetPos = pDocliner->GetAbsPos(pPara) + 1;
     574             : 
     575             :     // apply layout of predecessor page
     576           0 :     sal_uInt16 nPage = 0;
     577           0 :     pPara = pDocliner->GetParagraph( pDocliner->GetAbsPos( pPara ) - 1 );
     578           0 :     while (pPara)
     579             :     {
     580           0 :         sal_Int32 nPos = pDocliner->GetAbsPos( pPara );
     581           0 :         if ( pDocliner->HasParaFlag( pPara, PARAFLAG_ISPAGE ) )
     582           0 :             nPage++;
     583           0 :         pPara = pDocliner->GetParagraph( nPos - 1 );
     584             :     }
     585           0 :     SdPage* pPage = mpDoc->GetSdPage(nPage, PK_STANDARD);
     586           0 :     aLayoutName = pPage->GetLayoutName();
     587           0 :     aLayoutName.Erase(aLayoutName.SearchAscii(SD_LT_SEPARATOR));
     588             : 
     589             :     /* create our own outline since:
     590             :        - it is possible that the document outliner is actually used in the
     591             :          structuring mode
     592             :        - the draw outliner of the drawing engine has to draw something in
     593             :          between
     594             :        - the global outliner could be used in SdPage::CreatePresObj */
     595           0 :     ::Outliner* pOutliner = new ::Outliner( &mpDoc->GetItemPool(), OUTLINERMODE_OUTLINEOBJECT );
     596           0 :     pOutliner->SetStyleSheetPool((SfxStyleSheetPool*)mpDoc->GetStyleSheetPool());
     597             : 
     598             :     // set reference device
     599           0 :     pOutliner->SetRefDevice(SD_MOD()->GetRefDevice( *mpDocSh ));
     600           0 :     pOutliner->SetPaperSize(Size(0x7fffffff, 0x7fffffff));
     601             : 
     602           0 :     SvStream* pStream = pMedium->GetInStream();
     603             :     DBG_ASSERT( pStream, "No InStream!" );
     604           0 :     pStream->Seek( 0 );
     605             : 
     606           0 :     sal_uLong nErr = pOutliner->Read(*pStream, pMedium->GetBaseURL(), nFormat, mpDocSh->GetHeaderAttributes());
     607             : 
     608           0 :     if (nErr || pOutliner->GetEditEngine().GetText().isEmpty())
     609             :     {
     610             :         ErrorBox aErrorBox( mpWindow, (WinBits)WB_OK,
     611           0 :                   String(SdResId(STR_READ_DATA_ERROR)));
     612           0 :         aErrorBox.Execute();
     613             :     }
     614             :     else
     615             :     {
     616           0 :         sal_Int32 nParaCount = pOutliner->GetParagraphCount();
     617             : 
     618             :         // for progress bar: number of level-0-paragraphs
     619           0 :         sal_uInt16 nNewPages = 0;
     620           0 :         pPara = pOutliner->GetParagraph( 0 );
     621           0 :         while (pPara)
     622             :         {
     623           0 :             sal_Int32 nPos = pOutliner->GetAbsPos( pPara );
     624           0 :             if( pOutliner->HasParaFlag( pPara, PARAFLAG_ISPAGE ) )
     625           0 :                 nNewPages++;
     626           0 :             pPara = pOutliner->GetParagraph( ++nPos );
     627             :         }
     628             : 
     629           0 :         mpDocSh->SetWaitCursor( sal_False );
     630             : 
     631           0 :         SfxProgress* pProgress = new SfxProgress( mpDocSh, String( SdResId(STR_CREATE_PAGES)), nNewPages);
     632           0 :         if( pProgress )
     633           0 :             pProgress->SetState( 0, 100 );
     634             : 
     635           0 :         nNewPages = 0;
     636             : 
     637           0 :         pDocliner->GetUndoManager().EnterListAction(
     638           0 :                                     String(SdResId(STR_UNDO_INSERT_FILE)), String() );
     639             : 
     640           0 :         sal_Int32 nSourcePos = 0;
     641           0 :         SfxStyleSheet* pStyleSheet = pPage->GetStyleSheetForPresObj( PRESOBJ_OUTLINE );
     642           0 :         Paragraph* pSourcePara = pOutliner->GetParagraph( 0 );
     643           0 :         while (pSourcePara)
     644             :         {
     645           0 :             sal_Int32 nPos = pOutliner->GetAbsPos( pSourcePara );
     646           0 :             sal_Int16 nDepth = pOutliner->GetDepth( nPos );
     647             : 
     648             :             // only take the last paragraph if it is filled
     649           0 :             if (nSourcePos < nParaCount - 1 ||
     650           0 :                 pOutliner->GetText(pSourcePara).Len() > 0)
     651             :             {
     652           0 :                 pDocliner->Insert( pOutliner->GetText(pSourcePara), nTargetPos, nDepth );
     653           0 :                 String aStyleSheetName( pStyleSheet->GetName() );
     654           0 :                 aStyleSheetName.Erase( aStyleSheetName.Len()-1, 1 );
     655           0 :                 aStyleSheetName += OUString::number( nDepth <= 0 ? 1 : nDepth+1 );
     656           0 :                 SfxStyleSheetBasePool* pStylePool = mpDoc->GetStyleSheetPool();
     657           0 :                 SfxStyleSheet* pOutlStyle = (SfxStyleSheet*) pStylePool->Find( aStyleSheetName, pStyleSheet->GetFamily() );
     658           0 :                 pDocliner->SetStyleSheet( nTargetPos, pOutlStyle );
     659             :             }
     660             : 
     661           0 :             if( pDocliner->HasParaFlag( pSourcePara, PARAFLAG_ISPAGE ) )
     662             :             {
     663           0 :                 nNewPages++;
     664           0 :                 if( pProgress )
     665           0 :                     pProgress->SetState( nNewPages );
     666             :             }
     667             : 
     668           0 :             pSourcePara = pOutliner->GetParagraph( ++nPos );
     669           0 :             nTargetPos++;
     670           0 :             nSourcePos++;
     671             :         }
     672             : 
     673           0 :         pDocliner->GetUndoManager().LeaveListAction();
     674             : 
     675           0 :         if( pProgress )
     676           0 :             delete pProgress;
     677             : 
     678           0 :         mpDocSh->SetWaitCursor( sal_True );
     679             :     }
     680             : 
     681           0 :     delete pOutliner;
     682           0 : }
     683             : 
     684             : // -----------------------------------------------------------------------------
     685             : 
     686           0 : sal_Bool FuInsertFile::InsSDDinOlMode(SfxMedium* pMedium)
     687             : {
     688           0 :     OutlineView* pOlView = static_cast<OutlineView*>(mpView);
     689             : 
     690             :     // transfer Outliner content to SdDrawDocument
     691           0 :     pOlView->PrepareClose();
     692             : 
     693             :     // einlesen wie im Zeichenmodus
     694           0 :     if (InsSDDinDrMode(pMedium))
     695             :     {
     696           0 :         ::Outliner* pOutliner = pOlView->GetViewByWindow(mpWindow)->GetOutliner();
     697             : 
     698             :         // cut notification links temporarily
     699           0 :         Link aOldParagraphInsertedHdl = pOutliner->GetParaInsertedHdl();
     700           0 :         pOutliner->SetParaInsertedHdl( Link(NULL, NULL));
     701           0 :         Link aOldParagraphRemovingHdl = pOutliner->GetParaRemovingHdl();
     702           0 :         pOutliner->SetParaRemovingHdl( Link(NULL, NULL));
     703           0 :         Link aOldDepthChangedHdl      = pOutliner->GetDepthChangedHdl();
     704           0 :         pOutliner->SetDepthChangedHdl( Link(NULL, NULL));
     705           0 :         Link aOldBeginMovingHdl       = pOutliner->GetBeginMovingHdl();
     706           0 :         pOutliner->SetBeginMovingHdl( Link(NULL, NULL));
     707           0 :         Link aOldEndMovingHdl         = pOutliner->GetEndMovingHdl();
     708           0 :         pOutliner->SetEndMovingHdl( Link(NULL, NULL));
     709             : 
     710           0 :         Link aOldStatusEventHdl       = pOutliner->GetStatusEventHdl();
     711           0 :         pOutliner->SetStatusEventHdl(Link(NULL, NULL));
     712             : 
     713           0 :         pOutliner->Clear();
     714           0 :         pOlView->FillOutliner();
     715             : 
     716             :         // set links again
     717           0 :         pOutliner->SetParaInsertedHdl(aOldParagraphInsertedHdl);
     718           0 :         pOutliner->SetParaRemovingHdl(aOldParagraphRemovingHdl);
     719           0 :         pOutliner->SetDepthChangedHdl(aOldDepthChangedHdl);
     720           0 :         pOutliner->SetBeginMovingHdl(aOldBeginMovingHdl);
     721           0 :         pOutliner->SetEndMovingHdl(aOldEndMovingHdl);
     722           0 :         pOutliner->SetStatusEventHdl(aOldStatusEventHdl);
     723             : 
     724           0 :         return sal_True;
     725             :     }
     726             :     else
     727           0 :         return sal_False;
     728             : }
     729             : 
     730             : // -----------------------------------------------------------------------------
     731             : 
     732           0 : void FuInsertFile::GetSupportedFilterVector( ::std::vector< OUString >& rFilterVector )
     733             : {
     734           0 :     SfxFilterMatcher&   rMatcher = SFX_APP()->GetFilterMatcher();
     735           0 :     const SfxFilter*    pSearchFilter = NULL;
     736             : 
     737           0 :     rFilterVector.clear();
     738             : 
     739           0 :     if( ( pSearchFilter = rMatcher.GetFilter4Mime( "text/plain" )) != NULL )
     740           0 :         rFilterVector.push_back( pSearchFilter->GetMimeType() );
     741             : 
     742           0 :     if( ( pSearchFilter = rMatcher.GetFilter4Mime( "application/rtf" ) ) != NULL )
     743           0 :         rFilterVector.push_back( pSearchFilter->GetMimeType() );
     744             : 
     745           0 :     if( ( pSearchFilter = rMatcher.GetFilter4Mime( "text/html" ) ) != NULL )
     746           0 :         rFilterVector.push_back( pSearchFilter->GetMimeType() );
     747           0 : }
     748             : 
     749          33 : } // end of namespace sd
     750             : 
     751             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10