LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sd/source/ui/func - fuinsert.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 337 0.3 %
Date: 2013-07-09 Functions: 2 34 5.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "fuinsert.hxx"
      22             : 
      23             : #include <comphelper/storagehelper.hxx>
      24             : #include <comphelper/processfactory.hxx>
      25             : #include <toolkit/helper/vclunohelper.hxx>
      26             : #include <svx/svxdlg.hxx>
      27             : #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
      28             : #include <com/sun/star/embed/Aspects.hpp>
      29             : #include <com/sun/star/beans/XPropertySet.hpp>
      30             : #include <com/sun/star/chart2/XChartDocument.hpp>
      31             : #include <com/sun/star/drawing/FillStyle.hpp>
      32             : 
      33             : #include <tools/urlobj.hxx>
      34             : #include <svl/urihelper.hxx>
      35             : #include <sfx2/msgpool.hxx>
      36             : #include <svtools/sores.hxx>
      37             : #include <svtools/insdlg.hxx>
      38             : #include <sfx2/request.hxx>
      39             : #include <svl/globalnameitem.hxx>
      40             : #include <unotools/pathoptions.hxx>
      41             : #include <svtools/miscopt.hxx>
      42             : #include <svx/pfiledlg.hxx>
      43             : #include <svx/dialogs.hrc>
      44             : #include <sfx2/linkmgr.hxx>
      45             : #include <svx/linkwarn.hxx>
      46             : #include <svx/svdetc.hxx>
      47             : #include <avmedia/mediawindow.hxx>
      48             : #include <unotools/ucbstreamhelper.hxx>
      49             : #include <sfx2/printer.hxx>
      50             : #include <comphelper/classids.hxx>
      51             : #include <svtools/sfxecode.hxx>
      52             : #include <svtools/transfer.hxx>
      53             : #include <svl/urlbmk.hxx>
      54             : #include <svx/svdobj.hxx>
      55             : #include <svx/svdograf.hxx>
      56             : #include <svx/svdoole2.hxx>
      57             : #include <svx/svdomedia.hxx>
      58             : #include <editeng/editeng.hxx>
      59             : #include <sot/storage.hxx>
      60             : #include <sot/formats.hxx>
      61             : #include <svx/svdpagv.hxx>
      62             : #include <vcl/msgbox.hxx>
      63             : #include <sfx2/opengrf.hxx>
      64             : #include <sfx2/viewfrm.hxx>
      65             : #include <svx/charthelper.hxx>
      66             : 
      67             : #include "app.hrc"
      68             : #include "sdresid.hxx"
      69             : #include "View.hxx"
      70             : #include "sdmod.hxx"
      71             : #include "Window.hxx"
      72             : #include "drawview.hxx"
      73             : #include "DrawViewShell.hxx"
      74             : #include "DrawDocShell.hxx"
      75             : #include "GraphicDocShell.hxx"
      76             : #include "strings.hrc"
      77             : #include "drawdoc.hxx"
      78             : #include "sdgrffilter.hxx"
      79             : #include "sdxfer.hxx"
      80             : #include <vcl/svapp.hxx>
      81             : #include "undo/undoobjects.hxx"
      82             : #include "glob.hrc"
      83             : 
      84             : using namespace com::sun::star;
      85             : 
      86             : namespace sd {
      87             : 
      88           0 : TYPEINIT1( FuInsertGraphic, FuPoor );
      89           0 : TYPEINIT1( FuInsertClipboard, FuPoor );
      90           0 : TYPEINIT1( FuInsertOLE, FuPoor );
      91           0 : TYPEINIT1( FuInsertAVMedia, FuPoor );
      92             : 
      93           0 : FuInsertGraphic::FuInsertGraphic (
      94             :     ViewShell* pViewSh,
      95             :     ::sd::Window* pWin,
      96             :     ::sd::View* pView,
      97             :     SdDrawDocument* pDoc,
      98             :     SfxRequest& rReq)
      99           0 :     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
     100             : {
     101           0 : }
     102             : 
     103           0 : FunctionReference FuInsertGraphic::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
     104             : {
     105           0 :     FunctionReference xFunc( new FuInsertGraphic( pViewSh, pWin, pView, pDoc, rReq ) );
     106           0 :     xFunc->DoExecute(rReq);
     107           0 :     return xFunc;
     108             : }
     109             : 
     110           0 : void FuInsertGraphic::DoExecute( SfxRequest&  )
     111             : {
     112           0 :     SvxOpenGraphicDialog    aDlg(SdResId(STR_INSERTGRAPHIC));
     113             : 
     114           0 :     if( aDlg.Execute() == GRFILTER_OK )
     115             :     {
     116           0 :         Graphic     aGraphic;
     117           0 :         int nError = aDlg.GetGraphic(aGraphic);
     118           0 :         if( nError == GRFILTER_OK )
     119             :         {
     120           0 :             if( mpViewShell && mpViewShell->ISA(DrawViewShell))
     121             :             {
     122           0 :                 sal_Int8    nAction = DND_ACTION_COPY;
     123             :                 SdrObject* pPickObj;
     124             : 
     125           0 :                 if( ( pPickObj = mpView->GetSelectedSingleObject( mpView->GetPage() ) ) || ( pPickObj = mpView->GetEmptyPresentationObject( PRESOBJ_GRAPHIC ) ) )
     126           0 :                     nAction = DND_ACTION_LINK;
     127             : 
     128           0 :                 Point aPos;
     129           0 :                 Rectangle aRect(aPos, mpWindow->GetOutputSizePixel() );
     130           0 :                 aPos = aRect.Center();
     131           0 :                 aPos = mpWindow->PixelToLogic(aPos);
     132           0 :                 SdrGrafObj* pGrafObj = mpView->InsertGraphic(aGraphic, nAction, aPos, pPickObj, NULL);
     133             : 
     134           0 :                 if(pGrafObj && aDlg.IsAsLink())
     135             :                 {
     136             :                     // really store as link only?
     137           0 :                     if( SvtMiscOptions().ShowLinkWarningDialog() )
     138             :                     {
     139           0 :                         SvxLinkWarningDialog aWarnDlg(mpWindow,aDlg.GetPath());
     140           0 :                         if( aWarnDlg.Execute() != RET_OK )
     141           0 :                             return; // don't store as link
     142             :                     }
     143             : 
     144             :                     // store as link
     145           0 :                     String aFltName(aDlg.GetCurrentFilter());
     146           0 :                     String aPath(aDlg.GetPath());
     147           0 :                     pGrafObj->SetGraphicLink(aPath, aFltName);
     148             :                 }
     149             :             }
     150             :         }
     151             :         else
     152             :         {
     153           0 :             SdGRFFilter::HandleGraphicFilterError( (sal_uInt16)nError, GraphicFilter::GetGraphicFilter().GetLastError().nStreamError );
     154           0 :         }
     155           0 :     }
     156             : }
     157             : 
     158             : 
     159           0 : FuInsertClipboard::FuInsertClipboard (
     160             :     ViewShell* pViewSh,
     161             :     ::sd::Window* pWin,
     162             :     ::sd::View* pView,
     163             :     SdDrawDocument* pDoc,
     164             :     SfxRequest& rReq)
     165           0 :     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
     166             : {
     167           0 : }
     168             : 
     169           0 : FunctionReference FuInsertClipboard::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
     170             : {
     171           0 :     FunctionReference xFunc( new FuInsertClipboard( pViewSh, pWin, pView, pDoc, rReq ) );
     172           0 :     xFunc->DoExecute(rReq);
     173           0 :     return xFunc;
     174             : }
     175             : 
     176           0 : void FuInsertClipboard::DoExecute( SfxRequest&  )
     177             : {
     178           0 :     TransferableDataHelper                      aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpWindow ) );
     179             :     sal_uLong                                       nFormatId;
     180             : 
     181           0 :     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     182           0 :     SfxAbstractPasteDialog* pDlg = pFact->CreatePasteDialog( mpViewShell->GetActiveWindow() );
     183           0 :     if ( pDlg )
     184             :     {
     185           0 :         const String                                aEmptyString;
     186           0 :         ::com::sun::star::datatransfer::DataFlavor  aFlavor;
     187             : 
     188           0 :         pDlg->Insert( SOT_FORMATSTR_ID_EMBED_SOURCE, aEmptyString );
     189           0 :         pDlg->Insert( SOT_FORMATSTR_ID_LINK_SOURCE, aEmptyString );
     190           0 :         pDlg->Insert( SOT_FORMATSTR_ID_DRAWING, aEmptyString );
     191           0 :         pDlg->Insert( SOT_FORMATSTR_ID_SVXB, aEmptyString );
     192           0 :         pDlg->Insert( FORMAT_GDIMETAFILE, aEmptyString );
     193           0 :         pDlg->Insert( FORMAT_BITMAP, aEmptyString );
     194           0 :         pDlg->Insert( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aEmptyString );
     195           0 :         pDlg->Insert( FORMAT_STRING, aEmptyString );
     196           0 :         pDlg->Insert( SOT_FORMATSTR_ID_HTML, aEmptyString );
     197           0 :         pDlg->Insert( FORMAT_RTF, aEmptyString );
     198           0 :         pDlg->Insert( SOT_FORMATSTR_ID_EDITENGINE, aEmptyString );
     199             : 
     200             :         //TODO/MBA: testing
     201           0 :         nFormatId = pDlg->GetFormat( aDataHelper );
     202           0 :         if( nFormatId && aDataHelper.GetTransferable().is() )
     203             :         {
     204           0 :             sal_Int8 nAction = DND_ACTION_COPY;
     205             : 
     206           0 :             if( !mpView->InsertData( aDataHelper,
     207           0 :                                     mpWindow->PixelToLogic( Rectangle( Point(), mpWindow->GetOutputSizePixel() ).Center() ),
     208           0 :                                     nAction, sal_False, nFormatId ) &&
     209           0 :                 ( mpViewShell && mpViewShell->ISA( DrawViewShell ) ) )
     210             :             {
     211           0 :                 DrawViewShell* pDrViewSh = static_cast<DrawViewShell*>(mpViewShell);
     212           0 :                 INetBookmark        aINetBookmark( aEmptyStr, aEmptyStr );
     213             : 
     214           0 :                 if( ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ) &&
     215           0 :                     aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aINetBookmark ) ) ||
     216           0 :                     ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ) &&
     217           0 :                     aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR, aINetBookmark ) ) ||
     218           0 :                     ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ) &&
     219           0 :                     aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR, aINetBookmark ) ) )
     220             :                 {
     221           0 :                     pDrViewSh->InsertURLField( aINetBookmark.GetURL(), aINetBookmark.GetDescription(), aEmptyStr, NULL );
     222           0 :                 }
     223             :             }
     224             :         }
     225             : 
     226           0 :         delete pDlg;
     227           0 :     }
     228           0 : }
     229             : 
     230             : 
     231             : 
     232           0 : FuInsertOLE::FuInsertOLE (
     233             :     ViewShell* pViewSh,
     234             :     ::sd::Window* pWin,
     235             :     ::sd::View* pView,
     236             :     SdDrawDocument* pDoc,
     237             :     SfxRequest& rReq)
     238           0 :     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
     239             : {
     240           0 : }
     241             : 
     242           0 : FunctionReference FuInsertOLE::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
     243             : {
     244           0 :     FunctionReference xFunc( new FuInsertOLE( pViewSh, pWin, pView, pDoc, rReq ) );
     245           0 :     xFunc->DoExecute(rReq);
     246           0 :     return xFunc;
     247             : }
     248             : 
     249           0 : void FuInsertOLE::DoExecute( SfxRequest& rReq )
     250             : {
     251           0 :     if ( nSlotId == SID_ATTR_TABLE ||
     252           0 :          nSlotId == SID_INSERT_DIAGRAM ||
     253           0 :          nSlotId == SID_INSERT_MATH )
     254             :     {
     255           0 :         PresObjKind ePresObjKind = (nSlotId == SID_INSERT_DIAGRAM) ? PRESOBJ_CHART : PRESOBJ_OBJECT;
     256             : 
     257           0 :         SdrObject* pPickObj = mpView->GetEmptyPresentationObject( ePresObjKind );
     258             : 
     259             :         // insert diagram or Calc table
     260           0 :         OUString aObjName;
     261           0 :         SvGlobalName aName;
     262           0 :         if (nSlotId == SID_INSERT_DIAGRAM)
     263           0 :             aName = SvGlobalName( SO3_SCH_CLASSID);
     264           0 :         else if (nSlotId == SID_ATTR_TABLE)
     265           0 :             aName = SvGlobalName(SO3_SC_CLASSID);
     266           0 :         else if (nSlotId == SID_INSERT_MATH)
     267           0 :             aName = SvGlobalName(SO3_SM_CLASSID);
     268             : 
     269           0 :         uno::Reference < embed::XEmbeddedObject > xObj = mpViewShell->GetViewFrame()->GetObjectShell()->
     270           0 :                 GetEmbeddedObjectContainer().CreateEmbeddedObject( aName.GetByteSequence(), aObjName );
     271           0 :         if ( xObj.is() )
     272             :         {
     273           0 :             sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
     274             : 
     275           0 :             MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
     276             : 
     277           0 :             Rectangle aRect;
     278           0 :             if( pPickObj )
     279             :             {
     280           0 :                 aRect = pPickObj->GetLogicRect();
     281             : 
     282           0 :                 awt::Size aSz;
     283           0 :                 aSz.Width = aRect.GetWidth();
     284           0 :                 aSz.Height = aRect.GetHeight();
     285           0 :                 xObj->setVisualAreaSize( nAspect, aSz );
     286             :             }
     287             :             else
     288             :             {
     289           0 :                 awt::Size aSz;
     290             :                 try
     291             :                 {
     292           0 :                     aSz = xObj->getVisualAreaSize( nAspect );
     293             :                 }
     294           0 :                 catch ( embed::NoVisualAreaSizeException& )
     295             :                 {
     296             :                     // the default size will be set later
     297             :                 }
     298             : 
     299           0 :                 Size aSize( aSz.Width, aSz.Height );
     300             : 
     301           0 :                 if (aSize.Height() == 0 || aSize.Width() == 0)
     302             :                 {
     303             :                     // rectangle with balanced edge ratio
     304           0 :                     aSize.Width()  = 14100;
     305           0 :                     aSize.Height() = 10000;
     306           0 :                     Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aUnit );
     307           0 :                     aSz.Width = aTmp.Width();
     308           0 :                     aSz.Height = aTmp.Height();
     309           0 :                     xObj->setVisualAreaSize( nAspect, aSz );
     310             :                 }
     311             :                 else
     312             :                 {
     313           0 :                     aSize = OutputDevice::LogicToLogic(aSize, aUnit, MAP_100TH_MM);
     314             :                 }
     315             : 
     316           0 :                 Point aPos;
     317           0 :                 Rectangle aWinRect(aPos, mpWindow->GetOutputSizePixel() );
     318           0 :                 aPos = aWinRect.Center();
     319           0 :                 aPos = mpWindow->PixelToLogic(aPos);
     320           0 :                 aPos.X() -= aSize.Width() / 2;
     321           0 :                 aPos.Y() -= aSize.Height() / 2;
     322           0 :                 aRect = Rectangle(aPos, aSize);
     323             :             }
     324             : 
     325           0 :             SdrOle2Obj* pOleObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aObjName, aRect );
     326           0 :             SdrPageView* pPV = mpView->GetSdrPageView();
     327             : 
     328             :             // if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj
     329           0 :             if( pPickObj )
     330             :             {
     331           0 :                 SdPage* pPage = static_cast< SdPage* >(pPickObj->GetPage());
     332           0 :                 if(pPage && pPage->IsPresObj(pPickObj))
     333             :                 {
     334           0 :                     pPage->InsertPresObj( pOleObj, ePresObjKind );
     335           0 :                     pOleObj->SetUserCall(pPickObj->GetUserCall());
     336             :                 }
     337             :             }
     338             : 
     339           0 :             bool bRet = true;
     340           0 :             if( pPickObj )
     341           0 :                 mpView->ReplaceObjectAtView(pPickObj, *pPV, pOleObj, sal_True );
     342             :             else
     343           0 :                 bRet = mpView->InsertObjectAtView(pOleObj, *pPV, SDRINSERT_SETDEFLAYER);
     344             : 
     345           0 :             if( bRet )
     346             :             {
     347           0 :                 if (nSlotId == SID_INSERT_DIAGRAM)
     348             :                 {
     349           0 :                     pOleObj->SetProgName( OUString( "StarChart" ));
     350             :                 }
     351           0 :                 else if (nSlotId == SID_ATTR_TABLE)
     352             :                 {
     353           0 :                     pOleObj->SetProgName( OUString( "StarCalc" ) );
     354             :                 }
     355           0 :                 else if (nSlotId == SID_INSERT_MATH)
     356             :                 {
     357           0 :                     pOleObj->SetProgName( OUString( "StarMath" ) );
     358             :                 }
     359             : 
     360           0 :                 pOleObj->SetLogicRect(aRect);
     361           0 :                 Size aTmp( OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aUnit ) );
     362           0 :                 awt::Size aVisualSize;
     363           0 :                 aVisualSize.Width = aTmp.Width();
     364           0 :                 aVisualSize.Height = aTmp.Height();
     365           0 :                 xObj->setVisualAreaSize( nAspect, aVisualSize );
     366           0 :                 mpViewShell->ActivateObject(pOleObj, SVVERB_SHOW);
     367             : 
     368           0 :                 if (nSlotId == SID_INSERT_DIAGRAM)
     369             :                 {
     370             :                     // note, that this call modified the chart model which
     371             :                     // results in a change notification.  So call this after
     372             :                     // everything else is finished.
     373           0 :                     ChartHelper::AdaptDefaultsForChart( xObj );
     374             :                 }
     375             :             }
     376             :         }
     377             :         else
     378             :         {
     379             :             ErrorHandler::HandleError(* new StringErrorInfo(ERRCODE_SFX_OLEGENERAL,
     380           0 :                                         aEmptyStr ) );
     381           0 :         }
     382             :     }
     383             :     else
     384             :     {
     385             :         // insert object
     386           0 :         sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
     387           0 :         sal_Bool bCreateNew = sal_False;
     388           0 :         uno::Reference < embed::XEmbeddedObject > xObj;
     389           0 :         uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
     390           0 :         SvObjectServerList aServerLst;
     391           0 :         OUString aName;
     392             : 
     393           0 :         OUString aIconMediaType;
     394           0 :         uno::Reference< io::XInputStream > xIconMetaFile;
     395             : 
     396           0 :         SFX_REQUEST_ARG( rReq, pNameItem, SfxGlobalNameItem, SID_INSERT_OBJECT, sal_False );
     397           0 :         if ( nSlotId == SID_INSERT_OBJECT && pNameItem )
     398             :         {
     399           0 :             SvGlobalName aClassName = pNameItem->GetValue();
     400           0 :             xObj =  mpViewShell->GetViewFrame()->GetObjectShell()->
     401           0 :                     GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName.GetByteSequence(), aName );
     402             :         }
     403             :         else
     404             :         {
     405           0 :             switch ( nSlotId )
     406             :             {
     407             :                 case SID_INSERT_OBJECT :
     408             :                 {
     409           0 :                     aServerLst.FillInsertObjects();
     410           0 :                     if (mpDoc->GetDocumentType() == DOCUMENT_TYPE_DRAW)
     411             :                     {
     412           0 :                         aServerLst.Remove( GraphicDocShell::Factory().GetClassId() );
     413             :                     }
     414             :                     else
     415             :                     {
     416           0 :                         aServerLst.Remove( DrawDocShell::Factory().GetClassId() );
     417             :                     }
     418             : 
     419             :                     // intentionally no break!
     420             :                 }
     421             :                 case SID_INSERT_PLUGIN :
     422             :                 case SID_INSERT_FLOATINGFRAME :
     423             :                 {
     424           0 :                     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     425             :                     SfxAbstractInsertObjectDialog* pDlg =
     426           0 :                             pFact->CreateInsertObjectDialog( mpViewShell->GetActiveWindow(), SD_MOD()->GetSlotPool()->GetSlot(nSlotId)->GetCommandString(),
     427           0 :                             xStorage, &aServerLst );
     428           0 :                     if ( pDlg )
     429             :                     {
     430           0 :                         pDlg->Execute();
     431           0 :                         bCreateNew = pDlg->IsCreateNew();
     432           0 :                         xObj = pDlg->GetObject();
     433             : 
     434           0 :                         xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType );
     435           0 :                         if ( xIconMetaFile.is() )
     436           0 :                             nAspect = embed::Aspects::MSOLE_ICON;
     437             : 
     438           0 :                         if ( xObj.is() )
     439           0 :                             mpViewShell->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aName );
     440           0 :                         DELETEZ( pDlg );
     441             :                     }
     442             : 
     443           0 :                     break;
     444             :                 }
     445             :                 case SID_INSERT_SOUND :
     446             :                 case SID_INSERT_VIDEO :
     447             :                 {
     448             :                     // create special filedialog for plugins
     449           0 :                     SvxPluginFileDlg aPluginFileDialog (mpWindow, nSlotId);
     450           0 :                     if( ERRCODE_NONE == aPluginFileDialog.Execute () )
     451             :                     {
     452             :                         // get URL
     453           0 :                         String aStrURL(aPluginFileDialog.GetPath());
     454           0 :                         INetURLObject aURL( aStrURL, INET_PROT_FILE );
     455           0 :                         if( aURL.GetProtocol() != INET_PROT_NOT_VALID )
     456             :                         {
     457             :                             // create a plugin object
     458           0 :                             xObj = mpViewShell->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_PLUGIN_CLASSID ).GetByteSequence(), aName );
     459             :                         }
     460             : 
     461           0 :                         if ( xObj.is() && svt::EmbeddedObjectRef::TryRunningState( xObj ) )
     462             :                         {
     463             :                             // set properties from dialog
     464           0 :                             uno::Reference < embed::XComponentSupplier > xSup( xObj, uno::UNO_QUERY );
     465           0 :                             if ( xSup.is() )
     466             :                             {
     467           0 :                                 uno::Reference < beans::XPropertySet > xSet( xSup->getComponent(), uno::UNO_QUERY );
     468           0 :                                 if ( xSet.is() )
     469             :                                 {
     470           0 :                                     xSet->setPropertyValue("PluginURL",
     471           0 :                                             uno::makeAny( OUString( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) );
     472           0 :                                 }
     473           0 :                             }
     474             :                         }
     475             :                         else
     476             :                         {
     477             :                             // unable to create PlugIn
     478           0 :                             String aStrErr( SdResId( STR_ERROR_OBJNOCREATE_PLUGIN ) );
     479           0 :                             String aMask;
     480           0 :                             aMask += sal_Unicode('%');
     481           0 :                             aStrErr.SearchAndReplace( aMask, aStrURL );
     482           0 :                             ErrorBox( mpWindow, WB_3DLOOK | WB_OK, aStrErr ).Execute();
     483           0 :                         }
     484           0 :                     }
     485             :                 }
     486             :             }
     487             :         }
     488             : 
     489             :         try
     490             :         {
     491           0 :             if (xObj.is())
     492             :             {
     493             :                 //TODO/LATER: needs status for RESIZEONPRINTERCHANGE
     494             :                 //if( SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE & xObj->getStatus( nAspect ) )
     495             :                 //    aIPObj->OnDocumentPrinterChanged( mpDocSh->GetPrinter(sal_False) );
     496             : 
     497           0 :                 sal_Bool bInsertNewObject = sal_True;
     498             : 
     499           0 :                 Size aSize;
     500           0 :                 MapUnit aMapUnit = MAP_100TH_MM;
     501           0 :                 if ( nAspect != embed::Aspects::MSOLE_ICON )
     502             :                 {
     503           0 :                     awt::Size aSz;
     504             :                     try
     505             :                     {
     506           0 :                         aSz = xObj->getVisualAreaSize( nAspect );
     507             :                     }
     508           0 :                     catch( embed::NoVisualAreaSizeException& )
     509             :                     {
     510             :                         // the default size will be set later
     511             :                     }
     512             : 
     513           0 :                     aSize =Size( aSz.Width, aSz.Height );
     514             : 
     515           0 :                     aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
     516           0 :                     if (aSize.Height() == 0 || aSize.Width() == 0)
     517             :                     {
     518             :                         // rectangle with balanced edge ratio
     519           0 :                         aSize.Width()  = 14100;
     520           0 :                         aSize.Height() = 10000;
     521           0 :                         Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aMapUnit );
     522           0 :                         aSz.Width = aTmp.Width();
     523           0 :                         aSz.Height = aTmp.Height();
     524           0 :                         xObj->setVisualAreaSize( nAspect, aSz );
     525             :                     }
     526             :                     else
     527             :                     {
     528           0 :                         aSize = OutputDevice::LogicToLogic(aSize, aMapUnit, MAP_100TH_MM);
     529             :                     }
     530             :                 }
     531             : 
     532           0 :                 if ( mpView->AreObjectsMarked() )
     533             :                 {
     534             :                     // as an empty OLE object available?
     535           0 :                     const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
     536             : 
     537           0 :                     if (rMarkList.GetMarkCount() == 1)
     538             :                     {
     539           0 :                         SdrMark* pMark = rMarkList.GetMark(0);
     540           0 :                         SdrObject* pObj = pMark->GetMarkedSdrObj();
     541             : 
     542           0 :                         if (pObj->GetObjInventor() == SdrInventor &&
     543           0 :                         pObj->GetObjIdentifier() == OBJ_OLE2)
     544             :                         {
     545           0 :                             if ( !( (SdrOle2Obj*) pObj)->GetObjRef().is() )
     546             :                             {
     547             :                                 // the empty OLE object gets a new IPObj
     548           0 :                                 bInsertNewObject = sal_False;
     549           0 :                                 pObj->SetEmptyPresObj(sal_False);
     550           0 :                                 ( (SdrOle2Obj*) pObj)->SetOutlinerParaObject(NULL);
     551           0 :                                 ( (SdrOle2Obj*) pObj)->SetObjRef(xObj);
     552           0 :                                 ( (SdrOle2Obj*) pObj)->SetPersistName(aName);
     553           0 :                                 ( (SdrOle2Obj*) pObj)->SetName(aName);
     554           0 :                                 ( (SdrOle2Obj*) pObj)->SetAspect(nAspect);
     555           0 :                                 Rectangle aRect = ( (SdrOle2Obj*) pObj)->GetLogicRect();
     556             : 
     557           0 :                                 if ( nAspect == embed::Aspects::MSOLE_ICON )
     558             :                                 {
     559           0 :                                     if( xIconMetaFile.is() )
     560           0 :                                         ( (SdrOle2Obj*) pObj)->SetGraphicToObj( xIconMetaFile, aIconMediaType );
     561             :                                 }
     562             :                                 else
     563             :                                 {
     564           0 :                                     Size aTmp = OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aMapUnit );
     565           0 :                                     awt::Size aSz( aTmp.Width(), aTmp.Height() );
     566           0 :                                     xObj->setVisualAreaSize( nAspect, aSz );
     567             :                                 }
     568             :                             }
     569             :                         }
     570             :                     }
     571             :                 }
     572             : 
     573           0 :                 if (bInsertNewObject)
     574             :                 {
     575             :                     // we create a new OLE object
     576           0 :                     SdrPageView* pPV = mpView->GetSdrPageView();
     577           0 :                     Size aPageSize = pPV->GetPage()->GetSize();
     578             : 
     579             :                     // get the size from the iconified object
     580           0 :                     ::svt::EmbeddedObjectRef aObjRef( xObj, nAspect );
     581           0 :                     if ( nAspect == embed::Aspects::MSOLE_ICON )
     582             :                     {
     583           0 :                         aObjRef.SetGraphicStream( xIconMetaFile, aIconMediaType );
     584           0 :                         MapMode aMapMode( MAP_100TH_MM );
     585           0 :                         aSize = aObjRef.GetSize( &aMapMode );
     586             :                     }
     587             : 
     588           0 :                     Point aPnt ((aPageSize.Width()  - aSize.Width())  / 2,
     589           0 :                         (aPageSize.Height() - aSize.Height()) / 2);
     590           0 :                     Rectangle aRect (aPnt, aSize);
     591             : 
     592           0 :                     SdrOle2Obj* pObj = new SdrOle2Obj( aObjRef, aName, aRect);
     593             : 
     594           0 :                     if( mpView->InsertObjectAtView(pObj, *pPV, SDRINSERT_SETDEFLAYER) )
     595             :                     {
     596             :                         //  Math objects change their object size during InsertObject.
     597             :                         //  New size must be set in SdrObject, or a wrong scale will be set at
     598             :                         //  ActivateObject.
     599             : 
     600           0 :                         if ( nAspect != embed::Aspects::MSOLE_ICON )
     601             :                         {
     602             :                             try
     603             :                             {
     604           0 :                                 awt::Size aSz = xObj->getVisualAreaSize( nAspect );
     605             : 
     606             :                                 Size aNewSize = Window::LogicToLogic( Size( aSz.Width, aSz.Height ),
     607           0 :                                     MapMode( aMapUnit ), MapMode( MAP_100TH_MM ) );
     608           0 :                                 if ( aNewSize != aSize )
     609             :                                 {
     610           0 :                                     aRect.SetSize( aNewSize );
     611           0 :                                     pObj->SetLogicRect( aRect );
     612             :                                 }
     613             :                             }
     614           0 :                             catch( embed::NoVisualAreaSizeException& )
     615             :                             {}
     616             :                         }
     617             : 
     618           0 :                         if (bCreateNew)
     619             :                         {
     620           0 :                             pObj->SetLogicRect(aRect);
     621             : 
     622           0 :                             if ( nAspect != embed::Aspects::MSOLE_ICON )
     623             :                             {
     624           0 :                                 Size aTmp = OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aMapUnit );
     625           0 :                                 awt::Size aSz( aTmp.Width(), aTmp.Height() );
     626           0 :                                 xObj->setVisualAreaSize( nAspect, aSz );
     627             :                             }
     628             : 
     629           0 :                             mpViewShell->ActivateObject(pObj, SVVERB_SHOW);
     630             :                         }
     631             : 
     632           0 :                         Size aVisSizePixel = mpWindow->GetOutputSizePixel();
     633           0 :                         Rectangle aVisAreaWin = mpWindow->PixelToLogic( Rectangle( Point(0,0), aVisSizePixel) );
     634           0 :                         mpViewShell->VisAreaChanged(aVisAreaWin);
     635           0 :                         mpDocSh->SetVisArea(aVisAreaWin);
     636           0 :                     }
     637             :                 }
     638             :             }
     639             :         }
     640           0 :         catch (uno::Exception&)
     641             :         {
     642             :             // For some reason the object can not be inserted.  For example
     643             :             // because it is password protected and is not properly unlocked.
     644           0 :         }
     645             :     }
     646           0 : }
     647             : 
     648             : 
     649             : 
     650           0 : FuInsertAVMedia::FuInsertAVMedia(
     651             :     ViewShell* pViewSh,
     652             :     ::sd::Window* pWin,
     653             :     ::sd::View* pView,
     654             :     SdDrawDocument* pDoc,
     655             :     SfxRequest& rReq)
     656           0 :     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
     657             : {
     658           0 : }
     659             : 
     660           0 : FunctionReference FuInsertAVMedia::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
     661             : {
     662           0 :     FunctionReference xFunc( new FuInsertAVMedia( pViewSh, pWin, pView, pDoc, rReq ) );
     663           0 :     xFunc->DoExecute(rReq);
     664           0 :     return xFunc;
     665             : }
     666             : 
     667           0 : void FuInsertAVMedia::DoExecute( SfxRequest& rReq )
     668             : {
     669           0 :     OUString     aURL;
     670           0 :     const SfxItemSet*   pReqArgs = rReq.GetArgs();
     671           0 :     bool                bAPI = false;
     672             : 
     673           0 :     if( pReqArgs )
     674             :     {
     675           0 :         const SfxStringItem* pStringItem = PTR_CAST( SfxStringItem, &pReqArgs->Get( rReq.GetSlot() ) );
     676             : 
     677           0 :         if( pStringItem )
     678             :         {
     679           0 :             aURL = pStringItem->GetValue();
     680           0 :             bAPI = !aURL.isEmpty();
     681             :         }
     682             :     }
     683             : 
     684           0 :     bool bLink(true);
     685           0 :     if (bAPI ||
     686           0 :         ::avmedia::MediaWindow::executeMediaURLDialog(mpWindow, aURL, & bLink))
     687             :     {
     688           0 :         Size aPrefSize;
     689             : 
     690           0 :         if( mpWindow )
     691           0 :             mpWindow->EnterWait();
     692             : 
     693           0 :         if( !::avmedia::MediaWindow::isMediaURL( aURL, true, &aPrefSize ) )
     694             :         {
     695           0 :             if( mpWindow )
     696           0 :                 mpWindow->LeaveWait();
     697             : 
     698           0 :             if( !bAPI )
     699           0 :                 ::avmedia::MediaWindow::executeFormatErrorBox( mpWindow );
     700             :         }
     701             :         else
     702             :         {
     703           0 :             Point       aPos;
     704           0 :             Size        aSize;
     705           0 :             sal_Int8    nAction = DND_ACTION_COPY;
     706             : 
     707           0 :             if( aPrefSize.Width() && aPrefSize.Height() )
     708             :             {
     709           0 :                 if( mpWindow )
     710           0 :                     aSize = mpWindow->PixelToLogic( aPrefSize, MAP_100TH_MM );
     711             :                 else
     712           0 :                     aSize = Application::GetDefaultDevice()->PixelToLogic( aPrefSize, MAP_100TH_MM );
     713             :             }
     714             :             else
     715           0 :                 aSize = Size( 5000, 5000 );
     716             : 
     717           0 :             if( mpWindow )
     718             :             {
     719           0 :                 aPos = mpWindow->PixelToLogic( Rectangle( aPos, mpWindow->GetOutputSizePixel() ).Center() );
     720           0 :                 aPos.X() -= aSize.Width() >> 1;
     721           0 :                 aPos.Y() -= aSize.Height() >> 1;
     722             :             }
     723             : 
     724           0 :             mpView->InsertMediaURL( aURL, nAction, aPos, aSize, bLink ) ;
     725             : 
     726           0 :             if( mpWindow )
     727           0 :                 mpWindow->LeaveWait();
     728             :         }
     729           0 :     }
     730           0 : }
     731             : 
     732          33 : } // end of namespace sd
     733             : 
     734             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10