LCOV - code coverage report
Current view: top level - libreoffice/sd/source/ui/func - fuinsert.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 335 0.3 %
Date: 2012-12-27 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 <sot/clsids.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             : 
      65             : #include <sfx2/viewfrm.hxx>
      66             : 
      67             : #include "app.hrc"
      68             : #include "sdresid.hxx"
      69             : #include "View.hxx"
      70             : #include "app.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             : 
      83             : using namespace com::sun::star;
      84             : 
      85             : namespace sd {
      86             : 
      87           0 : TYPEINIT1( FuInsertGraphic, FuPoor );
      88           0 : TYPEINIT1( FuInsertClipboard, FuPoor );
      89           0 : TYPEINIT1( FuInsertOLE, FuPoor );
      90           0 : TYPEINIT1( FuInsertAVMedia, FuPoor );
      91             : 
      92             : /*************************************************************************
      93             : |*
      94             : |* FuInsertGraphic::Konstruktor
      95             : |*
      96             : \************************************************************************/
      97             : 
      98           0 : FuInsertGraphic::FuInsertGraphic (
      99             :     ViewShell* pViewSh,
     100             :     ::sd::Window* pWin,
     101             :     ::sd::View* pView,
     102             :     SdDrawDocument* pDoc,
     103             :     SfxRequest& rReq)
     104           0 :     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
     105             : {
     106           0 : }
     107             : 
     108           0 : FunctionReference FuInsertGraphic::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
     109             : {
     110           0 :     FunctionReference xFunc( new FuInsertGraphic( pViewSh, pWin, pView, pDoc, rReq ) );
     111           0 :     xFunc->DoExecute(rReq);
     112           0 :     return xFunc;
     113             : }
     114             : 
     115             : #ifdef _MSC_VER
     116             : #pragma optimize ( "", off )
     117             : #endif
     118             : 
     119           0 : void FuInsertGraphic::DoExecute( SfxRequest&  )
     120             : {
     121           0 :     SvxOpenGraphicDialog    aDlg(SdResId(STR_INSERTGRAPHIC));
     122             : 
     123           0 :     if( aDlg.Execute() == GRFILTER_OK )
     124             :     {
     125           0 :         Graphic     aGraphic;
     126           0 :         int nError = aDlg.GetGraphic(aGraphic);
     127           0 :         if( nError == GRFILTER_OK )
     128             :         {
     129           0 :             if( mpViewShell && mpViewShell->ISA(DrawViewShell))
     130             :             {
     131           0 :                 sal_Int8    nAction = DND_ACTION_COPY;
     132             :                 SdrObject* pPickObj;
     133             : 
     134           0 :                 if( ( pPickObj = mpView->GetSelectedSingleObject( mpView->GetPage() ) ) || ( pPickObj = mpView->GetEmptyPresentationObject( PRESOBJ_GRAPHIC ) ) )
     135           0 :                     nAction = DND_ACTION_LINK;
     136             : 
     137           0 :                 Point aPos;
     138           0 :                 Rectangle aRect(aPos, mpWindow->GetOutputSizePixel() );
     139           0 :                 aPos = aRect.Center();
     140           0 :                 aPos = mpWindow->PixelToLogic(aPos);
     141           0 :                 SdrGrafObj* pGrafObj = mpView->InsertGraphic(aGraphic, nAction, aPos, pPickObj, NULL);
     142             : 
     143           0 :                 if(pGrafObj && aDlg.IsAsLink())
     144             :                 {
     145             :                     // really store as link only?
     146           0 :                     if( SvtMiscOptions().ShowLinkWarningDialog() )
     147             :                     {
     148           0 :                         SvxLinkWarningDialog aWarnDlg(mpWindow,aDlg.GetPath());
     149           0 :                         if( aWarnDlg.Execute() != RET_OK )
     150           0 :                             return; // don't store as link
     151             :                     }
     152             : 
     153             :                     // store as link
     154           0 :                     String aFltName(aDlg.GetCurrentFilter());
     155           0 :                     String aPath(aDlg.GetPath());
     156           0 :                     pGrafObj->SetGraphicLink(aPath, aFltName);
     157             :                 }
     158             :             }
     159             :         }
     160             :         else
     161             :         {
     162           0 :             SdGRFFilter::HandleGraphicFilterError( (sal_uInt16)nError, GraphicFilter::GetGraphicFilter().GetLastError().nStreamError );
     163           0 :         }
     164           0 :     }
     165             : }
     166             : 
     167             : #ifdef _MSC_VER
     168             : #pragma optimize ( "", on )
     169             : #endif
     170             : 
     171             : /*************************************************************************
     172             : |*
     173             : |* FuInsertClipboard::Konstruktor
     174             : |*
     175             : \************************************************************************/
     176             : 
     177           0 : FuInsertClipboard::FuInsertClipboard (
     178             :     ViewShell* pViewSh,
     179             :     ::sd::Window* pWin,
     180             :     ::sd::View* pView,
     181             :     SdDrawDocument* pDoc,
     182             :     SfxRequest& rReq)
     183           0 :     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
     184             : {
     185           0 : }
     186             : 
     187           0 : FunctionReference FuInsertClipboard::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
     188             : {
     189           0 :     FunctionReference xFunc( new FuInsertClipboard( pViewSh, pWin, pView, pDoc, rReq ) );
     190           0 :     xFunc->DoExecute(rReq);
     191           0 :     return xFunc;
     192             : }
     193             : 
     194           0 : void FuInsertClipboard::DoExecute( SfxRequest&  )
     195             : {
     196           0 :     TransferableDataHelper                      aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpWindow ) );
     197             :     sal_uLong                                       nFormatId;
     198             : 
     199           0 :     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     200           0 :     SfxAbstractPasteDialog* pDlg = pFact->CreatePasteDialog( mpViewShell->GetActiveWindow() );
     201           0 :     if ( pDlg )
     202             :     {
     203           0 :         const String                                aEmptyString;
     204           0 :         ::com::sun::star::datatransfer::DataFlavor  aFlavor;
     205             : 
     206           0 :         pDlg->Insert( SOT_FORMATSTR_ID_EMBED_SOURCE, aEmptyString );
     207           0 :         pDlg->Insert( SOT_FORMATSTR_ID_LINK_SOURCE, aEmptyString );
     208           0 :         pDlg->Insert( SOT_FORMATSTR_ID_DRAWING, aEmptyString );
     209           0 :         pDlg->Insert( SOT_FORMATSTR_ID_SVXB, aEmptyString );
     210           0 :         pDlg->Insert( FORMAT_GDIMETAFILE, aEmptyString );
     211           0 :         pDlg->Insert( FORMAT_BITMAP, aEmptyString );
     212           0 :         pDlg->Insert( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aEmptyString );
     213           0 :         pDlg->Insert( FORMAT_STRING, aEmptyString );
     214           0 :         pDlg->Insert( SOT_FORMATSTR_ID_HTML, aEmptyString );
     215           0 :         pDlg->Insert( FORMAT_RTF, aEmptyString );
     216           0 :         pDlg->Insert( SOT_FORMATSTR_ID_EDITENGINE, aEmptyString );
     217             : 
     218             :         //TODO/MBA: testing
     219           0 :         nFormatId = pDlg->GetFormat( aDataHelper );
     220           0 :         if( nFormatId && aDataHelper.GetTransferable().is() )
     221             :         {
     222           0 :             sal_Int8 nAction = DND_ACTION_COPY;
     223             : 
     224           0 :             if( !mpView->InsertData( aDataHelper,
     225           0 :                                     mpWindow->PixelToLogic( Rectangle( Point(), mpWindow->GetOutputSizePixel() ).Center() ),
     226           0 :                                     nAction, sal_False, nFormatId ) &&
     227           0 :                 ( mpViewShell && mpViewShell->ISA( DrawViewShell ) ) )
     228             :             {
     229           0 :                 DrawViewShell* pDrViewSh = static_cast<DrawViewShell*>(mpViewShell);
     230           0 :                 INetBookmark        aINetBookmark( aEmptyStr, aEmptyStr );
     231             : 
     232           0 :                 if( ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ) &&
     233           0 :                     aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aINetBookmark ) ) ||
     234           0 :                     ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ) &&
     235           0 :                     aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR, aINetBookmark ) ) ||
     236           0 :                     ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ) &&
     237           0 :                     aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR, aINetBookmark ) ) )
     238             :                 {
     239           0 :                     pDrViewSh->InsertURLField( aINetBookmark.GetURL(), aINetBookmark.GetDescription(), aEmptyStr, NULL );
     240           0 :                 }
     241             :             }
     242             :         }
     243             : 
     244           0 :         delete pDlg;
     245           0 :     }
     246           0 : }
     247             : 
     248             : 
     249             : /*************************************************************************
     250             : |*
     251             : |* FuInsertOLE::Konstruktor
     252             : |*
     253             : \************************************************************************/
     254             : 
     255           0 : FuInsertOLE::FuInsertOLE (
     256             :     ViewShell* pViewSh,
     257             :     ::sd::Window* pWin,
     258             :     ::sd::View* pView,
     259             :     SdDrawDocument* pDoc,
     260             :     SfxRequest& rReq)
     261           0 :     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
     262             : {
     263           0 : }
     264             : 
     265           0 : FunctionReference FuInsertOLE::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
     266             : {
     267           0 :     FunctionReference xFunc( new FuInsertOLE( pViewSh, pWin, pView, pDoc, rReq ) );
     268           0 :     xFunc->DoExecute(rReq);
     269           0 :     return xFunc;
     270             : }
     271             : 
     272           0 : void FuInsertOLE::DoExecute( SfxRequest& rReq )
     273             : {
     274           0 :     if ( nSlotId == SID_ATTR_TABLE ||
     275             :          nSlotId == SID_INSERT_DIAGRAM ||
     276             :          nSlotId == SID_INSERT_MATH )
     277             :     {
     278           0 :         PresObjKind ePresObjKind = (nSlotId == SID_INSERT_DIAGRAM) ? PRESOBJ_CHART : PRESOBJ_OBJECT;
     279             : 
     280           0 :         SdrObject* pPickObj = mpView->GetEmptyPresentationObject( ePresObjKind );
     281             : 
     282             :         /**********************************************************************
     283             :         * Diagramm oder StarCalc-Tabelle einfuegen
     284             :         **********************************************************************/
     285             : 
     286           0 :         ::rtl::OUString aObjName;
     287           0 :         SvGlobalName aName;
     288           0 :         if (nSlotId == SID_INSERT_DIAGRAM)
     289           0 :             aName = SvGlobalName( SO3_SCH_CLASSID);
     290           0 :         else if (nSlotId == SID_ATTR_TABLE)
     291           0 :             aName = SvGlobalName(SO3_SC_CLASSID);
     292           0 :         else if (nSlotId == SID_INSERT_MATH)
     293           0 :             aName = SvGlobalName(SO3_SM_CLASSID);
     294             : 
     295           0 :         uno::Reference < embed::XEmbeddedObject > xObj = mpViewShell->GetViewFrame()->GetObjectShell()->
     296           0 :                 GetEmbeddedObjectContainer().CreateEmbeddedObject( aName.GetByteSequence(), aObjName );
     297           0 :         if ( xObj.is() )
     298             :         {
     299           0 :             sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
     300             : 
     301           0 :             MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
     302             : 
     303           0 :             Rectangle aRect;
     304           0 :             if( pPickObj )
     305             :             {
     306           0 :                 aRect = pPickObj->GetLogicRect();
     307             : 
     308           0 :                 awt::Size aSz;
     309           0 :                 aSz.Width = aRect.GetWidth();
     310           0 :                 aSz.Height = aRect.GetHeight();
     311           0 :                 xObj->setVisualAreaSize( nAspect, aSz );
     312             :             }
     313             :             else
     314             :             {
     315           0 :                 awt::Size aSz;
     316             :                 try
     317             :                 {
     318           0 :                     aSz = xObj->getVisualAreaSize( nAspect );
     319             :                 }
     320           0 :                 catch ( embed::NoVisualAreaSizeException& )
     321             :                 {
     322             :                     // the default size will be set later
     323             :                 }
     324             : 
     325           0 :                 Size aSize( aSz.Width, aSz.Height );
     326             : 
     327           0 :                 if (aSize.Height() == 0 || aSize.Width() == 0)
     328             :                 {
     329             :                     // Rechteck mit ausgewogenem Kantenverhaeltnis
     330           0 :                     aSize.Width()  = 14100;
     331           0 :                     aSize.Height() = 10000;
     332           0 :                     Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aUnit );
     333           0 :                     aSz.Width = aTmp.Width();
     334           0 :                     aSz.Height = aTmp.Height();
     335           0 :                     xObj->setVisualAreaSize( nAspect, aSz );
     336             :                 }
     337             :                 else
     338             :                 {
     339           0 :                     aSize = OutputDevice::LogicToLogic(aSize, aUnit, MAP_100TH_MM);
     340             :                 }
     341             : 
     342           0 :                 Point aPos;
     343           0 :                 Rectangle aWinRect(aPos, mpWindow->GetOutputSizePixel() );
     344           0 :                 aPos = aWinRect.Center();
     345           0 :                 aPos = mpWindow->PixelToLogic(aPos);
     346           0 :                 aPos.X() -= aSize.Width() / 2;
     347           0 :                 aPos.Y() -= aSize.Height() / 2;
     348           0 :                 aRect = Rectangle(aPos, aSize);
     349             :             }
     350             : 
     351           0 :             SdrOle2Obj* pOleObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aObjName, aRect );
     352           0 :             SdrPageView* pPV = mpView->GetSdrPageView();
     353             : 
     354             :             // if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj
     355           0 :             if( pPickObj )
     356             :             {
     357           0 :                 SdPage* pPage = static_cast< SdPage* >(pPickObj->GetPage());
     358           0 :                 if(pPage && pPage->IsPresObj(pPickObj))
     359             :                 {
     360           0 :                     pPage->InsertPresObj( pOleObj, ePresObjKind );
     361           0 :                     pOleObj->SetUserCall(pPickObj->GetUserCall());
     362             :                 }
     363             :             }
     364             : 
     365           0 :             bool bRet = true;
     366           0 :             if( pPickObj )
     367           0 :                 mpView->ReplaceObjectAtView(pPickObj, *pPV, pOleObj, sal_True );
     368             :             else
     369           0 :                 bRet = mpView->InsertObjectAtView(pOleObj, *pPV, SDRINSERT_SETDEFLAYER);
     370             : 
     371           0 :             if( bRet )
     372             :             {
     373           0 :                 if (nSlotId == SID_INSERT_DIAGRAM)
     374             :                 {
     375           0 :                     pOleObj->SetProgName( rtl::OUString( "StarChart" ));
     376             :                 }
     377           0 :                 else if (nSlotId == SID_ATTR_TABLE)
     378             :                 {
     379           0 :                     pOleObj->SetProgName( rtl::OUString( "StarCalc" ) );
     380             :                 }
     381           0 :                 else if (nSlotId == SID_INSERT_MATH)
     382             :                 {
     383           0 :                     pOleObj->SetProgName( rtl::OUString( "StarMath" ) );
     384             :                 }
     385             : 
     386           0 :                 pOleObj->SetLogicRect(aRect);
     387           0 :                 Size aTmp( OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aUnit ) );
     388           0 :                 awt::Size aVisualSize;
     389           0 :                 aVisualSize.Width = aTmp.Width();
     390           0 :                 aVisualSize.Height = aTmp.Height();
     391           0 :                 xObj->setVisualAreaSize( nAspect, aVisualSize );
     392           0 :                 mpViewShell->ActivateObject(pOleObj, SVVERB_SHOW);
     393             : 
     394           0 :                 if (nSlotId == SID_INSERT_DIAGRAM)
     395             :                 {
     396             :                     // note, that this call modified the chart model which
     397             :                     // results in a change notification.  So call this after
     398             :                     // everything else is finished.
     399           0 :                     mpViewShell->AdaptDefaultsForChart( xObj );
     400             :                 }
     401             :             }
     402             :         }
     403             :         else
     404             :         {
     405             :             ErrorHandler::HandleError(* new StringErrorInfo(ERRCODE_SFX_OLEGENERAL,
     406           0 :                                         aEmptyStr ) );
     407           0 :         }
     408             :     }
     409             :     else
     410             :     {
     411             :         /**********************************************************************
     412             :         * Objekt einfuegen
     413             :         **********************************************************************/
     414           0 :         sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
     415           0 :         sal_Bool bCreateNew = sal_False;
     416           0 :         uno::Reference < embed::XEmbeddedObject > xObj;
     417           0 :         uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
     418           0 :         SvObjectServerList aServerLst;
     419           0 :         ::rtl::OUString aName;
     420             : 
     421           0 :         ::rtl::OUString aIconMediaType;
     422           0 :         uno::Reference< io::XInputStream > xIconMetaFile;
     423             : 
     424           0 :         SFX_REQUEST_ARG( rReq, pNameItem, SfxGlobalNameItem, SID_INSERT_OBJECT, sal_False );
     425           0 :         if ( nSlotId == SID_INSERT_OBJECT && pNameItem )
     426             :         {
     427           0 :             SvGlobalName aClassName = pNameItem->GetValue();
     428           0 :             xObj =  mpViewShell->GetViewFrame()->GetObjectShell()->
     429           0 :                     GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName.GetByteSequence(), aName );
     430             :         }
     431             :         else
     432             :         {
     433           0 :             switch ( nSlotId )
     434             :             {
     435             :                 case SID_INSERT_OBJECT :
     436             :                 {
     437           0 :                     aServerLst.FillInsertObjects();
     438           0 :                     if (mpDoc->GetDocumentType() == DOCUMENT_TYPE_DRAW)
     439             :                     {
     440           0 :                         aServerLst.Remove( GraphicDocShell::Factory().GetClassId() );
     441             :                     }
     442             :                     else
     443             :                     {
     444           0 :                         aServerLst.Remove( DrawDocShell::Factory().GetClassId() );
     445             :                     }
     446             : 
     447             :                     // intentionally no break!
     448             :                 }
     449             :                 case SID_INSERT_PLUGIN :
     450             :                 case SID_INSERT_FLOATINGFRAME :
     451             :                 {
     452           0 :                     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     453             :                     SfxAbstractInsertObjectDialog* pDlg =
     454           0 :                             pFact->CreateInsertObjectDialog( mpViewShell->GetActiveWindow(), SD_MOD()->GetSlotPool()->GetSlot(nSlotId)->GetCommandString(),
     455           0 :                             xStorage, &aServerLst );
     456           0 :                     if ( pDlg )
     457             :                     {
     458           0 :                         pDlg->Execute();
     459           0 :                         bCreateNew = pDlg->IsCreateNew();
     460           0 :                         xObj = pDlg->GetObject();
     461             : 
     462           0 :                         xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType );
     463           0 :                         if ( xIconMetaFile.is() )
     464           0 :                             nAspect = embed::Aspects::MSOLE_ICON;
     465             : 
     466           0 :                         if ( xObj.is() )
     467           0 :                             mpViewShell->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aName );
     468           0 :                         DELETEZ( pDlg );
     469             :                     }
     470             : 
     471           0 :                     break;
     472             :                 }
     473             :                 case SID_INSERT_SOUND :
     474             :                 case SID_INSERT_VIDEO :
     475             :                 {
     476             :                     // create special filedialog for plugins
     477           0 :                     SvxPluginFileDlg aPluginFileDialog (mpWindow, nSlotId);
     478           0 :                     if( ERRCODE_NONE == aPluginFileDialog.Execute () )
     479             :                     {
     480             :                         // get URL
     481           0 :                         String aStrURL(aPluginFileDialog.GetPath());
     482           0 :                         INetURLObject aURL( aStrURL, INET_PROT_FILE );
     483           0 :                         if( aURL.GetProtocol() != INET_PROT_NOT_VALID )
     484             :                         {
     485             :                             // create a plugin object
     486           0 :                             xObj = mpViewShell->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_PLUGIN_CLASSID ).GetByteSequence(), aName );
     487             :                         }
     488             : 
     489           0 :                         if ( xObj.is() && svt::EmbeddedObjectRef::TryRunningState( xObj ) )
     490             :                         {
     491             :                             // set properties from dialog
     492           0 :                             uno::Reference < embed::XComponentSupplier > xSup( xObj, uno::UNO_QUERY );
     493           0 :                             if ( xSup.is() )
     494             :                             {
     495           0 :                                 uno::Reference < beans::XPropertySet > xSet( xSup->getComponent(), uno::UNO_QUERY );
     496           0 :                                 if ( xSet.is() )
     497             :                                 {
     498           0 :                                     xSet->setPropertyValue("PluginURL",
     499           0 :                                             uno::makeAny( ::rtl::OUString( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) );
     500           0 :                                 }
     501           0 :                             }
     502             :                         }
     503             :                         else
     504             :                         {
     505             :                             // PlugIn konnte nicht erzeugt werden
     506           0 :                             String aStrErr( SdResId( STR_ERROR_OBJNOCREATE_PLUGIN ) );
     507           0 :                             String aMask;
     508           0 :                             aMask += sal_Unicode('%');
     509           0 :                             aStrErr.SearchAndReplace( aMask, aStrURL );
     510           0 :                             ErrorBox( mpWindow, WB_3DLOOK | WB_OK, aStrErr ).Execute();
     511           0 :                         }
     512           0 :                     }
     513             :                 }
     514             :             }
     515             :         }
     516             : 
     517             :         try
     518             :         {
     519           0 :             if (xObj.is())
     520             :             {
     521             :                 //TODO/LATER: needs status for RESIZEONPRINTERCHANGE
     522             :                 //if( SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE & xObj->getStatus( nAspect ) )
     523             :                 //    aIPObj->OnDocumentPrinterChanged( mpDocSh->GetPrinter(sal_False) );
     524             : 
     525           0 :                 sal_Bool bInsertNewObject = sal_True;
     526             : 
     527           0 :                 Size aSize;
     528           0 :                 MapUnit aMapUnit = MAP_100TH_MM;
     529           0 :                 if ( nAspect != embed::Aspects::MSOLE_ICON )
     530             :                 {
     531           0 :                     awt::Size aSz;
     532             :                     try
     533             :                     {
     534           0 :                         aSz = xObj->getVisualAreaSize( nAspect );
     535             :                     }
     536           0 :                     catch( embed::NoVisualAreaSizeException& )
     537             :                     {
     538             :                         // the default size will be set later
     539             :                     }
     540             : 
     541           0 :                     aSize =Size( aSz.Width, aSz.Height );
     542             : 
     543           0 :                     aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
     544           0 :                     if (aSize.Height() == 0 || aSize.Width() == 0)
     545             :                     {
     546             :                         // Rechteck mit ausgewogenem Kantenverhaeltnis
     547           0 :                         aSize.Width()  = 14100;
     548           0 :                         aSize.Height() = 10000;
     549           0 :                         Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aMapUnit );
     550           0 :                         aSz.Width = aTmp.Width();
     551           0 :                         aSz.Height = aTmp.Height();
     552           0 :                         xObj->setVisualAreaSize( nAspect, aSz );
     553             :                     }
     554             :                     else
     555             :                     {
     556           0 :                         aSize = OutputDevice::LogicToLogic(aSize, aMapUnit, MAP_100TH_MM);
     557             :                     }
     558             :                 }
     559             : 
     560           0 :                 if ( mpView->AreObjectsMarked() )
     561             :                 {
     562             :                     /**********************************************************
     563             :                         * Ist ein leeres OLE-Objekt vorhanden?
     564             :                         **********************************************************/
     565           0 :                     const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
     566             : 
     567           0 :                     if (rMarkList.GetMarkCount() == 1)
     568             :                     {
     569           0 :                         SdrMark* pMark = rMarkList.GetMark(0);
     570           0 :                         SdrObject* pObj = pMark->GetMarkedSdrObj();
     571             : 
     572           0 :                         if (pObj->GetObjInventor() == SdrInventor &&
     573           0 :                         pObj->GetObjIdentifier() == OBJ_OLE2)
     574             :                         {
     575           0 :                             if ( !( (SdrOle2Obj*) pObj)->GetObjRef().is() )
     576             :                             {
     577             :                                 /**************************************************
     578             :                                     * Das leere OLE-Objekt bekommt ein neues IPObj
     579             :                                     **************************************************/
     580           0 :                                 bInsertNewObject = sal_False;
     581           0 :                                 pObj->SetEmptyPresObj(sal_False);
     582           0 :                                 ( (SdrOle2Obj*) pObj)->SetOutlinerParaObject(NULL);
     583           0 :                                 ( (SdrOle2Obj*) pObj)->SetObjRef(xObj);
     584           0 :                                 ( (SdrOle2Obj*) pObj)->SetPersistName(aName);
     585           0 :                                 ( (SdrOle2Obj*) pObj)->SetName(aName);
     586           0 :                                 ( (SdrOle2Obj*) pObj)->SetAspect(nAspect);
     587           0 :                                 Rectangle aRect = ( (SdrOle2Obj*) pObj)->GetLogicRect();
     588             : 
     589           0 :                                 if ( nAspect == embed::Aspects::MSOLE_ICON )
     590             :                                 {
     591           0 :                                     if( xIconMetaFile.is() )
     592           0 :                                         ( (SdrOle2Obj*) pObj)->SetGraphicToObj( xIconMetaFile, aIconMediaType );
     593             :                                 }
     594             :                                 else
     595             :                                 {
     596           0 :                                     Size aTmp = OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aMapUnit );
     597           0 :                                     awt::Size aSz( aTmp.Width(), aTmp.Height() );
     598           0 :                                     xObj->setVisualAreaSize( nAspect, aSz );
     599             :                                 }
     600             :                             }
     601             :                         }
     602             :                     }
     603             :                 }
     604             : 
     605           0 :                 if (bInsertNewObject)
     606             :                 {
     607             :                     /**************************************************************
     608             :                         * Ein neues OLE-Objekt wird erzeugt
     609             :                         **************************************************************/
     610           0 :                     SdrPageView* pPV = mpView->GetSdrPageView();
     611           0 :                     Size aPageSize = pPV->GetPage()->GetSize();
     612             : 
     613             :                     // get the size from the iconified object
     614           0 :                     ::svt::EmbeddedObjectRef aObjRef( xObj, nAspect );
     615           0 :                     if ( nAspect == embed::Aspects::MSOLE_ICON )
     616             :                     {
     617           0 :                         aObjRef.SetGraphicStream( xIconMetaFile, aIconMediaType );
     618           0 :                         MapMode aMapMode( MAP_100TH_MM );
     619           0 :                         aSize = aObjRef.GetSize( &aMapMode );
     620             :                     }
     621             : 
     622           0 :                     Point aPnt ((aPageSize.Width()  - aSize.Width())  / 2,
     623           0 :                         (aPageSize.Height() - aSize.Height()) / 2);
     624           0 :                     Rectangle aRect (aPnt, aSize);
     625             : 
     626           0 :                     SdrOle2Obj* pObj = new SdrOle2Obj( aObjRef, aName, aRect);
     627             : 
     628           0 :                     if( mpView->InsertObjectAtView(pObj, *pPV, SDRINSERT_SETDEFLAYER) )
     629             :                     {
     630             :                         //  Math objects change their object size during InsertObject.
     631             :                         //  New size must be set in SdrObject, or a wrong scale will be set at
     632             :                         //  ActivateObject.
     633             : 
     634           0 :                         if ( nAspect != embed::Aspects::MSOLE_ICON )
     635             :                         {
     636             :                             try
     637             :                             {
     638           0 :                                 awt::Size aSz = xObj->getVisualAreaSize( nAspect );
     639             : 
     640             :                                 Size aNewSize = Window::LogicToLogic( Size( aSz.Width, aSz.Height ),
     641           0 :                                     MapMode( aMapUnit ), MapMode( MAP_100TH_MM ) );
     642           0 :                                 if ( aNewSize != aSize )
     643             :                                 {
     644           0 :                                     aRect.SetSize( aNewSize );
     645           0 :                                     pObj->SetLogicRect( aRect );
     646             :                                 }
     647             :                             }
     648           0 :                             catch( embed::NoVisualAreaSizeException& )
     649             :                             {}
     650             :                         }
     651             : 
     652           0 :                         if (bCreateNew)
     653             :                         {
     654           0 :                             pObj->SetLogicRect(aRect);
     655             : 
     656           0 :                             if ( nAspect != embed::Aspects::MSOLE_ICON )
     657             :                             {
     658           0 :                                 Size aTmp = OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aMapUnit );
     659           0 :                                 awt::Size aSz( aTmp.Width(), aTmp.Height() );
     660           0 :                                 xObj->setVisualAreaSize( nAspect, aSz );
     661             :                             }
     662             : 
     663           0 :                             mpViewShell->ActivateObject(pObj, SVVERB_SHOW);
     664             :                         }
     665             : 
     666           0 :                         Size aVisSizePixel = mpWindow->GetOutputSizePixel();
     667           0 :                         Rectangle aVisAreaWin = mpWindow->PixelToLogic( Rectangle( Point(0,0), aVisSizePixel) );
     668           0 :                         mpViewShell->VisAreaChanged(aVisAreaWin);
     669           0 :                         mpDocSh->SetVisArea(aVisAreaWin);
     670           0 :                     }
     671             :                 }
     672             :             }
     673             :         }
     674           0 :         catch (uno::Exception&)
     675             :         {
     676             :             // For some reason the object can not be inserted.  For example
     677             :             // because it is password protected and is not properly unlocked.
     678           0 :         }
     679             :     }
     680           0 : }
     681             : 
     682             : 
     683             : /*************************************************************************
     684             : |*
     685             : |* FuInsertAVMedia::Konstruktor
     686             : |*
     687             : \************************************************************************/
     688             : 
     689           0 : FuInsertAVMedia::FuInsertAVMedia(
     690             :     ViewShell* pViewSh,
     691             :     ::sd::Window* pWin,
     692             :     ::sd::View* pView,
     693             :     SdDrawDocument* pDoc,
     694             :     SfxRequest& rReq)
     695           0 :     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
     696             : {
     697           0 : }
     698             : 
     699           0 : FunctionReference FuInsertAVMedia::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
     700             : {
     701           0 :     FunctionReference xFunc( new FuInsertAVMedia( pViewSh, pWin, pView, pDoc, rReq ) );
     702           0 :     xFunc->DoExecute(rReq);
     703           0 :     return xFunc;
     704             : }
     705             : 
     706           0 : void FuInsertAVMedia::DoExecute( SfxRequest& rReq )
     707             : {
     708           0 :     ::rtl::OUString     aURL;
     709           0 :     const SfxItemSet*   pReqArgs = rReq.GetArgs();
     710           0 :     bool                bAPI = false;
     711             : 
     712           0 :     if( pReqArgs )
     713             :     {
     714           0 :         const SfxStringItem* pStringItem = PTR_CAST( SfxStringItem, &pReqArgs->Get( rReq.GetSlot() ) );
     715             : 
     716           0 :         if( pStringItem )
     717             :         {
     718           0 :             aURL = pStringItem->GetValue();
     719           0 :             bAPI = !aURL.isEmpty();
     720             :         }
     721             :     }
     722             : 
     723           0 :     bool bLink(true);
     724           0 :     if (bAPI ||
     725           0 :         ::avmedia::MediaWindow::executeMediaURLDialog(mpWindow, aURL, & bLink))
     726             :     {
     727           0 :         Size aPrefSize;
     728             : 
     729           0 :         if( mpWindow )
     730           0 :             mpWindow->EnterWait();
     731             : 
     732           0 :         if( !::avmedia::MediaWindow::isMediaURL( aURL, true, &aPrefSize ) )
     733             :         {
     734           0 :             if( mpWindow )
     735           0 :                 mpWindow->LeaveWait();
     736             : 
     737           0 :             if( !bAPI )
     738           0 :                 ::avmedia::MediaWindow::executeFormatErrorBox( mpWindow );
     739             :         }
     740             :         else
     741             :         {
     742           0 :             Point       aPos;
     743           0 :             Size        aSize;
     744           0 :             sal_Int8    nAction = DND_ACTION_COPY;
     745             : 
     746           0 :             if( aPrefSize.Width() && aPrefSize.Height() )
     747             :             {
     748           0 :                 if( mpWindow )
     749           0 :                     aSize = mpWindow->PixelToLogic( aPrefSize, MAP_100TH_MM );
     750             :                 else
     751           0 :                     aSize = Application::GetDefaultDevice()->PixelToLogic( aPrefSize, MAP_100TH_MM );
     752             :             }
     753             :             else
     754           0 :                 aSize = Size( 5000, 5000 );
     755             : 
     756           0 :             if( mpWindow )
     757             :             {
     758           0 :                 aPos = mpWindow->PixelToLogic( Rectangle( aPos, mpWindow->GetOutputSizePixel() ).Center() );
     759           0 :                 aPos.X() -= aSize.Width() >> 1;
     760           0 :                 aPos.Y() -= aSize.Height() >> 1;
     761             :             }
     762             : 
     763           0 :             mpView->InsertMediaURL( aURL, nAction, aPos, aSize, bLink ) ;
     764             : 
     765           0 :             if( mpWindow )
     766           0 :                 mpWindow->LeaveWait();
     767             :         }
     768           0 :     }
     769           0 : }
     770             : 
     771           9 : } // end of namespace sd
     772             : 
     773             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10