LCOV - code coverage report
Current view: top level - sd/source/ui/func - fuinsert.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 380 0.0 %
Date: 2014-04-14 Functions: 0 42 0.0 %
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             : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      33             : 
      34             : #include <tools/urlobj.hxx>
      35             : #include <svl/urihelper.hxx>
      36             : #include <sfx2/docfile.hxx>
      37             : #include <sfx2/msgpool.hxx>
      38             : #include <svtools/sores.hxx>
      39             : #include <svtools/insdlg.hxx>
      40             : #include <sfx2/request.hxx>
      41             : #include <svl/globalnameitem.hxx>
      42             : #include <unotools/pathoptions.hxx>
      43             : #include <svtools/miscopt.hxx>
      44             : #include <svx/pfiledlg.hxx>
      45             : #include <svx/dialogs.hrc>
      46             : #include <sfx2/linkmgr.hxx>
      47             : #include <svx/linkwarn.hxx>
      48             : #include <svx/svdetc.hxx>
      49             : #include <avmedia/mediawindow.hxx>
      50             : #include <unotools/ucbstreamhelper.hxx>
      51             : #include <sfx2/printer.hxx>
      52             : #include <comphelper/classids.hxx>
      53             : #include <svtools/sfxecode.hxx>
      54             : #include <svtools/transfer.hxx>
      55             : #include <svl/urlbmk.hxx>
      56             : #include <svx/svdobj.hxx>
      57             : #include <svx/svdograf.hxx>
      58             : #include <svx/svdoole2.hxx>
      59             : #include <svx/svdomedia.hxx>
      60             : #include <editeng/editeng.hxx>
      61             : #include <sot/storage.hxx>
      62             : #include <sot/formats.hxx>
      63             : #include <svx/svdpagv.hxx>
      64             : #include <vcl/msgbox.hxx>
      65             : #include <sfx2/opengrf.hxx>
      66             : #include <sfx2/viewfrm.hxx>
      67             : #include <svx/charthelper.hxx>
      68             : 
      69             : #include "app.hrc"
      70             : #include "sdresid.hxx"
      71             : #include "View.hxx"
      72             : #include "sdmod.hxx"
      73             : #include "Window.hxx"
      74             : #include "drawview.hxx"
      75             : #include "DrawViewShell.hxx"
      76             : #include "DrawDocShell.hxx"
      77             : #include "GraphicDocShell.hxx"
      78             : #include "strings.hrc"
      79             : #include "drawdoc.hxx"
      80             : #include "sdgrffilter.hxx"
      81             : #include "sdxfer.hxx"
      82             : #include <vcl/svapp.hxx>
      83             : #include "undo/undoobjects.hxx"
      84             : #include "glob.hrc"
      85             : 
      86             : using namespace com::sun::star;
      87             : 
      88             : namespace sd {
      89             : 
      90           0 : TYPEINIT1( FuInsertGraphic, FuPoor );
      91           0 : TYPEINIT1( FuInsertClipboard, FuPoor );
      92           0 : TYPEINIT1( FuInsertOLE, FuPoor );
      93           0 : TYPEINIT1( FuInsertAVMedia, FuPoor );
      94           0 : TYPEINIT1( FuInsert3DModel, FuPoor );
      95             : 
      96           0 : FuInsertGraphic::FuInsertGraphic (
      97             :     ViewShell* pViewSh,
      98             :     ::sd::Window* pWin,
      99             :     ::sd::View* pView,
     100             :     SdDrawDocument* pDoc,
     101             :     SfxRequest& rReq)
     102           0 :     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
     103             : {
     104           0 : }
     105             : 
     106           0 : rtl::Reference<FuPoor> FuInsertGraphic::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
     107             : {
     108           0 :     rtl::Reference<FuPoor> xFunc( new FuInsertGraphic( pViewSh, pWin, pView, pDoc, rReq ) );
     109           0 :     xFunc->DoExecute(rReq);
     110           0 :     return xFunc;
     111             : }
     112             : 
     113           0 : void FuInsertGraphic::DoExecute( SfxRequest&  )
     114             : {
     115           0 :     SvxOpenGraphicDialog    aDlg(SdResId(STR_INSERTGRAPHIC));
     116             : 
     117           0 :     if( aDlg.Execute() == GRFILTER_OK )
     118             :     {
     119           0 :         Graphic     aGraphic;
     120           0 :         int nError = aDlg.GetGraphic(aGraphic);
     121           0 :         if( nError == GRFILTER_OK )
     122             :         {
     123           0 :             if( mpViewShell && mpViewShell->ISA(DrawViewShell))
     124             :             {
     125           0 :                 sal_Int8    nAction = DND_ACTION_COPY;
     126             :                 SdrObject* pPickObj;
     127           0 :                 bool bSelectionReplaced(false);
     128             : 
     129           0 :                 if( ( pPickObj = mpView->GetSelectedSingleObject( mpView->GetPage() ) ) || ( pPickObj = mpView->GetEmptyPresentationObject( PRESOBJ_GRAPHIC ) ) )
     130             :                 {
     131           0 :                     nAction = DND_ACTION_LINK;
     132             :                 }
     133           0 :                 else if(1 == mpView->GetMarkedObjectCount())
     134             :                 {
     135           0 :                     pPickObj = mpView->GetMarkedObjectByIndex(0);
     136           0 :                     nAction = DND_ACTION_MOVE;
     137           0 :                     bSelectionReplaced = true;
     138             :                 }
     139             : 
     140           0 :                 Point aPos;
     141           0 :                 Rectangle aRect(aPos, mpWindow->GetOutputSizePixel() );
     142           0 :                 aPos = aRect.Center();
     143           0 :                 aPos = mpWindow->PixelToLogic(aPos);
     144           0 :                 SdrGrafObj* pGrafObj = mpView->InsertGraphic(aGraphic, nAction, aPos, pPickObj, NULL);
     145             : 
     146           0 :                 if(pGrafObj && aDlg.IsAsLink())
     147             :                 {
     148             :                     // really store as link only?
     149           0 :                     if( SvtMiscOptions().ShowLinkWarningDialog() )
     150             :                     {
     151           0 :                         SvxLinkWarningDialog aWarnDlg(mpWindow,aDlg.GetPath());
     152           0 :                         if( aWarnDlg.Execute() != RET_OK )
     153           0 :                             return; // don't store as link
     154             :                     }
     155             : 
     156             :                     // store as link
     157           0 :                     OUString aFltName(aDlg.GetCurrentFilter());
     158           0 :                     OUString aPath(aDlg.GetPath());
     159           0 :                     OUString aReferer;
     160           0 :                     if (mpDocSh->HasName()) {
     161           0 :                         aReferer = mpDocSh->GetMedium()->GetName();
     162             :                     }
     163           0 :                     pGrafObj->SetGraphicLink(aPath, aReferer, aFltName);
     164             :                 }
     165             : 
     166           0 :                 if(bSelectionReplaced && pGrafObj)
     167             :                 {
     168           0 :                     mpView->MarkObj(pGrafObj, mpView->GetSdrPageView());
     169             :                 }
     170             :             }
     171             :         }
     172             :         else
     173             :         {
     174           0 :             SdGRFFilter::HandleGraphicFilterError( (sal_uInt16)nError, GraphicFilter::GetGraphicFilter().GetLastError().nStreamError );
     175           0 :         }
     176           0 :     }
     177             : }
     178             : 
     179             : 
     180           0 : FuInsertClipboard::FuInsertClipboard (
     181             :     ViewShell* pViewSh,
     182             :     ::sd::Window* pWin,
     183             :     ::sd::View* pView,
     184             :     SdDrawDocument* pDoc,
     185             :     SfxRequest& rReq)
     186           0 :     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
     187             : {
     188           0 : }
     189             : 
     190           0 : rtl::Reference<FuPoor> FuInsertClipboard::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
     191             : {
     192           0 :     rtl::Reference<FuPoor> xFunc( new FuInsertClipboard( pViewSh, pWin, pView, pDoc, rReq ) );
     193           0 :     xFunc->DoExecute(rReq);
     194           0 :     return xFunc;
     195             : }
     196             : 
     197           0 : void FuInsertClipboard::DoExecute( SfxRequest&  )
     198             : {
     199           0 :     TransferableDataHelper                      aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpWindow ) );
     200             :     sal_uLong                                       nFormatId;
     201             : 
     202           0 :     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     203           0 :     SfxAbstractPasteDialog* pDlg = pFact->CreatePasteDialog( mpViewShell->GetActiveWindow() );
     204           0 :     if ( pDlg )
     205             :     {
     206           0 :         ::com::sun::star::datatransfer::DataFlavor  aFlavor;
     207             : 
     208           0 :         pDlg->Insert( SOT_FORMATSTR_ID_EMBED_SOURCE, OUString() );
     209           0 :         pDlg->Insert( SOT_FORMATSTR_ID_LINK_SOURCE, OUString() );
     210           0 :         pDlg->Insert( SOT_FORMATSTR_ID_DRAWING, OUString() );
     211           0 :         pDlg->Insert( SOT_FORMATSTR_ID_SVXB, OUString() );
     212           0 :         pDlg->Insert( FORMAT_GDIMETAFILE, OUString() );
     213           0 :         pDlg->Insert( FORMAT_BITMAP, OUString() );
     214           0 :         pDlg->Insert( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, OUString() );
     215           0 :         pDlg->Insert( FORMAT_STRING, OUString() );
     216           0 :         pDlg->Insert( SOT_FORMATSTR_ID_HTML, OUString() );
     217           0 :         pDlg->Insert( FORMAT_RTF, OUString() );
     218           0 :         pDlg->Insert( SOT_FORMATSTR_ID_EDITENGINE, OUString() );
     219             : 
     220             :         //TODO/MBA: testing
     221           0 :         nFormatId = pDlg->GetFormat( aDataHelper );
     222           0 :         if( nFormatId && aDataHelper.GetTransferable().is() )
     223             :         {
     224           0 :             sal_Int8 nAction = DND_ACTION_COPY;
     225             : 
     226           0 :             if( !mpView->InsertData( aDataHelper,
     227           0 :                                     mpWindow->PixelToLogic( Rectangle( Point(), mpWindow->GetOutputSizePixel() ).Center() ),
     228           0 :                                     nAction, sal_False, nFormatId ) &&
     229           0 :                 ( mpViewShell && mpViewShell->ISA( DrawViewShell ) ) )
     230             :             {
     231           0 :                 DrawViewShell* pDrViewSh = static_cast<DrawViewShell*>(mpViewShell);
     232           0 :                 INetBookmark        aINetBookmark( aEmptyStr, aEmptyStr );
     233             : 
     234           0 :                 if( ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ) &&
     235           0 :                     aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aINetBookmark ) ) ||
     236           0 :                     ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ) &&
     237           0 :                     aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR, aINetBookmark ) ) ||
     238           0 :                     ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ) &&
     239           0 :                     aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR, aINetBookmark ) ) )
     240             :                 {
     241           0 :                     pDrViewSh->InsertURLField( aINetBookmark.GetURL(), aINetBookmark.GetDescription(), aEmptyStr, NULL );
     242           0 :                 }
     243             :             }
     244             :         }
     245             : 
     246           0 :         delete pDlg;
     247           0 :     }
     248           0 : }
     249             : 
     250             : 
     251             : 
     252           0 : FuInsertOLE::FuInsertOLE (
     253             :     ViewShell* pViewSh,
     254             :     ::sd::Window* pWin,
     255             :     ::sd::View* pView,
     256             :     SdDrawDocument* pDoc,
     257             :     SfxRequest& rReq)
     258           0 :     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
     259             : {
     260           0 : }
     261             : 
     262           0 : rtl::Reference<FuPoor> FuInsertOLE::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
     263             : {
     264           0 :     rtl::Reference<FuPoor> xFunc( new FuInsertOLE( pViewSh, pWin, pView, pDoc, rReq ) );
     265           0 :     xFunc->DoExecute(rReq);
     266           0 :     return xFunc;
     267             : }
     268             : 
     269           0 : void FuInsertOLE::DoExecute( SfxRequest& rReq )
     270             : {
     271           0 :     if ( nSlotId == SID_ATTR_TABLE ||
     272           0 :          nSlotId == SID_INSERT_DIAGRAM ||
     273           0 :          nSlotId == SID_INSERT_MATH )
     274             :     {
     275           0 :         PresObjKind ePresObjKind = (nSlotId == SID_INSERT_DIAGRAM) ? PRESOBJ_CHART : PRESOBJ_OBJECT;
     276             : 
     277           0 :         SdrObject* pPickObj = mpView->GetEmptyPresentationObject( ePresObjKind );
     278             : 
     279             :         // insert diagram or Calc table
     280           0 :         OUString aObjName;
     281           0 :         SvGlobalName aName;
     282           0 :         if (nSlotId == SID_INSERT_DIAGRAM)
     283           0 :             aName = SvGlobalName( SO3_SCH_CLASSID);
     284           0 :         else if (nSlotId == SID_ATTR_TABLE)
     285           0 :             aName = SvGlobalName(SO3_SC_CLASSID);
     286           0 :         else if (nSlotId == SID_INSERT_MATH)
     287           0 :             aName = SvGlobalName(SO3_SM_CLASSID);
     288             : 
     289           0 :         uno::Reference < embed::XEmbeddedObject > xObj = mpViewShell->GetViewFrame()->GetObjectShell()->
     290           0 :                 GetEmbeddedObjectContainer().CreateEmbeddedObject( aName.GetByteSequence(), aObjName );
     291           0 :         if ( xObj.is() )
     292             :         {
     293           0 :             sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
     294             : 
     295           0 :             MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
     296             : 
     297           0 :             Rectangle aRect;
     298           0 :             if( pPickObj )
     299             :             {
     300           0 :                 aRect = pPickObj->GetLogicRect();
     301             : 
     302           0 :                 awt::Size aSz;
     303           0 :                 aSz.Width = aRect.GetWidth();
     304           0 :                 aSz.Height = aRect.GetHeight();
     305           0 :                 xObj->setVisualAreaSize( nAspect, aSz );
     306             :             }
     307             :             else
     308             :             {
     309           0 :                 awt::Size aSz;
     310             :                 try
     311             :                 {
     312           0 :                     aSz = xObj->getVisualAreaSize( nAspect );
     313             :                 }
     314           0 :                 catch ( embed::NoVisualAreaSizeException& )
     315             :                 {
     316             :                     // the default size will be set later
     317             :                 }
     318             : 
     319           0 :                 Size aSize( aSz.Width, aSz.Height );
     320             : 
     321           0 :                 if (aSize.Height() == 0 || aSize.Width() == 0)
     322             :                 {
     323             :                     // rectangle with balanced edge ratio
     324           0 :                     aSize.Width()  = 14100;
     325           0 :                     aSize.Height() = 10000;
     326           0 :                     Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aUnit );
     327           0 :                     aSz.Width = aTmp.Width();
     328           0 :                     aSz.Height = aTmp.Height();
     329           0 :                     xObj->setVisualAreaSize( nAspect, aSz );
     330             :                 }
     331             :                 else
     332             :                 {
     333           0 :                     aSize = OutputDevice::LogicToLogic(aSize, aUnit, MAP_100TH_MM);
     334             :                 }
     335             : 
     336           0 :                 Point aPos;
     337           0 :                 Rectangle aWinRect(aPos, mpWindow->GetOutputSizePixel() );
     338           0 :                 aPos = aWinRect.Center();
     339           0 :                 aPos = mpWindow->PixelToLogic(aPos);
     340           0 :                 aPos.X() -= aSize.Width() / 2;
     341           0 :                 aPos.Y() -= aSize.Height() / 2;
     342           0 :                 aRect = Rectangle(aPos, aSize);
     343             :             }
     344             : 
     345           0 :             SdrOle2Obj* pOleObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aObjName, aRect );
     346           0 :             SdrPageView* pPV = mpView->GetSdrPageView();
     347             : 
     348             :             // if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj
     349           0 :             if( pPickObj )
     350             :             {
     351           0 :                 SdPage* pPage = static_cast< SdPage* >(pPickObj->GetPage());
     352           0 :                 if(pPage && pPage->IsPresObj(pPickObj))
     353             :                 {
     354           0 :                     pPage->InsertPresObj( pOleObj, ePresObjKind );
     355           0 :                     pOleObj->SetUserCall(pPickObj->GetUserCall());
     356             :                 }
     357             : 
     358             :                 // #i123468# we need to end text edit before replacing the object. There cannot yet
     359             :                 // being text typed (else it would not be an EmptyPresObj anymore), but it may be
     360             :                 // in text edit mode
     361           0 :                 if (mpView->IsTextEdit())
     362             :                 {
     363           0 :                     mpView->SdrEndTextEdit();
     364             :                 }
     365             :             }
     366             : 
     367           0 :             bool bRet = true;
     368           0 :             if( pPickObj )
     369           0 :                 mpView->ReplaceObjectAtView(pPickObj, *pPV, pOleObj, true );
     370             :             else
     371           0 :                 bRet = mpView->InsertObjectAtView(pOleObj, *pPV, SDRINSERT_SETDEFLAYER);
     372             : 
     373           0 :             if( bRet )
     374             :             {
     375           0 :                 if (nSlotId == SID_INSERT_DIAGRAM)
     376             :                 {
     377           0 :                     pOleObj->SetProgName( OUString( "StarChart" ));
     378             :                 }
     379           0 :                 else if (nSlotId == SID_ATTR_TABLE)
     380             :                 {
     381           0 :                     pOleObj->SetProgName( OUString( "StarCalc" ) );
     382             :                 }
     383           0 :                 else if (nSlotId == SID_INSERT_MATH)
     384             :                 {
     385           0 :                     pOleObj->SetProgName( OUString( "StarMath" ) );
     386             :                 }
     387             : 
     388           0 :                 pOleObj->SetLogicRect(aRect);
     389           0 :                 Size aTmp( OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aUnit ) );
     390           0 :                 awt::Size aVisualSize;
     391           0 :                 aVisualSize.Width = aTmp.Width();
     392           0 :                 aVisualSize.Height = aTmp.Height();
     393           0 :                 xObj->setVisualAreaSize( nAspect, aVisualSize );
     394           0 :                 mpViewShell->ActivateObject(pOleObj, SVVERB_SHOW);
     395             : 
     396           0 :                 if (nSlotId == SID_INSERT_DIAGRAM)
     397             :                 {
     398             :                     // note, that this call modified the chart model which
     399             :                     // results in a change notification.  So call this after
     400             :                     // everything else is finished.
     401           0 :                     ChartHelper::AdaptDefaultsForChart( xObj );
     402             :                 }
     403             :             }
     404             :         }
     405             :         else
     406             :         {
     407             :             ErrorHandler::HandleError(* new StringErrorInfo(ERRCODE_SFX_OLEGENERAL,
     408           0 :                                         aEmptyStr ) );
     409           0 :         }
     410             :     }
     411             :     else
     412             :     {
     413             :         // insert object
     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 :         OUString aName;
     420             : 
     421           0 :         OUString aIconMediaType;
     422           0 :         uno::Reference< io::XInputStream > xIconMetaFile;
     423             : 
     424           0 :         SFX_REQUEST_ARG( rReq, pNameItem, SfxGlobalNameItem, SID_INSERT_OBJECT, 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 :                         OUString 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( OUString( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) );
     500           0 :                                 }
     501           0 :                             }
     502             :                         }
     503             :                         else
     504             :                         {
     505             :                             // unable to create PlugIn
     506           0 :                             OUString aStrErr( SdResId( STR_ERROR_OBJNOCREATE_PLUGIN ) );
     507           0 :                             aStrErr = aStrErr.replaceFirst( "%", aStrURL );
     508           0 :                             ErrorBox( mpWindow, WB_3DLOOK | WB_OK, aStrErr ).Execute();
     509           0 :                         }
     510           0 :                     }
     511             :                 }
     512             :             }
     513             :         }
     514             : 
     515             :         try
     516             :         {
     517           0 :             if (xObj.is())
     518             :             {
     519             :                 //TODO/LATER: needs status for RESIZEONPRINTERCHANGE
     520             :                 //if( SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE & xObj->getStatus( nAspect ) )
     521             :                 //    aIPObj->OnDocumentPrinterChanged( mpDocSh->GetPrinter(sal_False) );
     522             : 
     523           0 :                 sal_Bool bInsertNewObject = sal_True;
     524             : 
     525           0 :                 Size aSize;
     526           0 :                 MapUnit aMapUnit = MAP_100TH_MM;
     527           0 :                 if ( nAspect != embed::Aspects::MSOLE_ICON )
     528             :                 {
     529           0 :                     awt::Size aSz;
     530             :                     try
     531             :                     {
     532           0 :                         aSz = xObj->getVisualAreaSize( nAspect );
     533             :                     }
     534           0 :                     catch( embed::NoVisualAreaSizeException& )
     535             :                     {
     536             :                         // the default size will be set later
     537             :                     }
     538             : 
     539           0 :                     aSize =Size( aSz.Width, aSz.Height );
     540             : 
     541           0 :                     aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
     542           0 :                     if (aSize.Height() == 0 || aSize.Width() == 0)
     543             :                     {
     544             :                         // rectangle with balanced edge ratio
     545           0 :                         aSize.Width()  = 14100;
     546           0 :                         aSize.Height() = 10000;
     547           0 :                         Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aMapUnit );
     548           0 :                         aSz.Width = aTmp.Width();
     549           0 :                         aSz.Height = aTmp.Height();
     550           0 :                         xObj->setVisualAreaSize( nAspect, aSz );
     551             :                     }
     552             :                     else
     553             :                     {
     554           0 :                         aSize = OutputDevice::LogicToLogic(aSize, aMapUnit, MAP_100TH_MM);
     555             :                     }
     556             :                 }
     557             : 
     558           0 :                 if ( mpView->AreObjectsMarked() )
     559             :                 {
     560             :                     // as an empty OLE object available?
     561           0 :                     const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
     562             : 
     563           0 :                     if (rMarkList.GetMarkCount() == 1)
     564             :                     {
     565           0 :                         SdrMark* pMark = rMarkList.GetMark(0);
     566           0 :                         SdrObject* pObj = pMark->GetMarkedSdrObj();
     567             : 
     568           0 :                         if (pObj->GetObjInventor() == SdrInventor &&
     569           0 :                         pObj->GetObjIdentifier() == OBJ_OLE2)
     570             :                         {
     571           0 :                             if ( !( (SdrOle2Obj*) pObj)->GetObjRef().is() )
     572             :                             {
     573             :                                 // the empty OLE object gets a new IPObj
     574           0 :                                 bInsertNewObject = sal_False;
     575           0 :                                 pObj->SetEmptyPresObj(false);
     576           0 :                                 ( (SdrOle2Obj*) pObj)->SetOutlinerParaObject(NULL);
     577           0 :                                 ( (SdrOle2Obj*) pObj)->SetObjRef(xObj);
     578           0 :                                 ( (SdrOle2Obj*) pObj)->SetPersistName(aName);
     579           0 :                                 ( (SdrOle2Obj*) pObj)->SetName(aName);
     580           0 :                                 ( (SdrOle2Obj*) pObj)->SetAspect(nAspect);
     581           0 :                                 Rectangle aRect = ( (SdrOle2Obj*) pObj)->GetLogicRect();
     582             : 
     583           0 :                                 if ( nAspect == embed::Aspects::MSOLE_ICON )
     584             :                                 {
     585           0 :                                     if( xIconMetaFile.is() )
     586           0 :                                         ( (SdrOle2Obj*) pObj)->SetGraphicToObj( xIconMetaFile, aIconMediaType );
     587             :                                 }
     588             :                                 else
     589             :                                 {
     590           0 :                                     Size aTmp = OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aMapUnit );
     591           0 :                                     awt::Size aSz( aTmp.Width(), aTmp.Height() );
     592           0 :                                     xObj->setVisualAreaSize( nAspect, aSz );
     593             :                                 }
     594             :                             }
     595             :                         }
     596             :                     }
     597             :                 }
     598             : 
     599           0 :                 if (bInsertNewObject)
     600             :                 {
     601             :                     // we create a new OLE object
     602           0 :                     SdrPageView* pPV = mpView->GetSdrPageView();
     603           0 :                     Size aPageSize = pPV->GetPage()->GetSize();
     604             : 
     605             :                     // get the size from the iconified object
     606           0 :                     ::svt::EmbeddedObjectRef aObjRef( xObj, nAspect );
     607           0 :                     if ( nAspect == embed::Aspects::MSOLE_ICON )
     608             :                     {
     609           0 :                         aObjRef.SetGraphicStream( xIconMetaFile, aIconMediaType );
     610           0 :                         MapMode aMapMode( MAP_100TH_MM );
     611           0 :                         aSize = aObjRef.GetSize( &aMapMode );
     612             :                     }
     613             : 
     614           0 :                     Point aPnt ((aPageSize.Width()  - aSize.Width())  / 2,
     615           0 :                         (aPageSize.Height() - aSize.Height()) / 2);
     616           0 :                     Rectangle aRect (aPnt, aSize);
     617             : 
     618           0 :                     SdrOle2Obj* pObj = new SdrOle2Obj( aObjRef, aName, aRect);
     619             : 
     620           0 :                     if( mpView->InsertObjectAtView(pObj, *pPV, SDRINSERT_SETDEFLAYER) )
     621             :                     {
     622             :                         //  Math objects change their object size during InsertObject.
     623             :                         //  New size must be set in SdrObject, or a wrong scale will be set at
     624             :                         //  ActivateObject.
     625             : 
     626           0 :                         if ( nAspect != embed::Aspects::MSOLE_ICON )
     627             :                         {
     628             :                             try
     629             :                             {
     630           0 :                                 awt::Size aSz = xObj->getVisualAreaSize( nAspect );
     631             : 
     632             :                                 Size aNewSize = Window::LogicToLogic( Size( aSz.Width, aSz.Height ),
     633           0 :                                     MapMode( aMapUnit ), MapMode( MAP_100TH_MM ) );
     634           0 :                                 if ( aNewSize != aSize )
     635             :                                 {
     636           0 :                                     aRect.SetSize( aNewSize );
     637           0 :                                     pObj->SetLogicRect( aRect );
     638             :                                 }
     639             :                             }
     640           0 :                             catch( embed::NoVisualAreaSizeException& )
     641             :                             {}
     642             :                         }
     643             : 
     644           0 :                         if (bCreateNew)
     645             :                         {
     646           0 :                             pObj->SetLogicRect(aRect);
     647             : 
     648           0 :                             if ( nAspect != embed::Aspects::MSOLE_ICON )
     649             :                             {
     650           0 :                                 Size aTmp = OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aMapUnit );
     651           0 :                                 awt::Size aSz( aTmp.Width(), aTmp.Height() );
     652           0 :                                 xObj->setVisualAreaSize( nAspect, aSz );
     653             :                             }
     654             : 
     655           0 :                             mpViewShell->ActivateObject(pObj, SVVERB_SHOW);
     656             :                         }
     657             : 
     658           0 :                         Size aVisSizePixel = mpWindow->GetOutputSizePixel();
     659           0 :                         Rectangle aVisAreaWin = mpWindow->PixelToLogic( Rectangle( Point(0,0), aVisSizePixel) );
     660           0 :                         mpViewShell->VisAreaChanged(aVisAreaWin);
     661           0 :                         mpDocSh->SetVisArea(aVisAreaWin);
     662           0 :                     }
     663             :                 }
     664             :             }
     665             :         }
     666           0 :         catch (uno::Exception&)
     667             :         {
     668             :             // For some reason the object can not be inserted.  For example
     669             :             // because it is password protected and is not properly unlocked.
     670           0 :         }
     671             :     }
     672           0 : }
     673             : 
     674             : 
     675             : 
     676           0 : FuInsertAVMedia::FuInsertAVMedia(
     677             :     ViewShell* pViewSh,
     678             :     ::sd::Window* pWin,
     679             :     ::sd::View* pView,
     680             :     SdDrawDocument* pDoc,
     681             :     SfxRequest& rReq)
     682           0 :     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
     683             : {
     684           0 : }
     685             : 
     686           0 : rtl::Reference<FuPoor> FuInsertAVMedia::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
     687             : {
     688           0 :     rtl::Reference<FuPoor> xFunc( new FuInsertAVMedia( pViewSh, pWin, pView, pDoc, rReq ) );
     689           0 :     xFunc->DoExecute(rReq);
     690           0 :     return xFunc;
     691             : }
     692             : 
     693           0 : void FuInsertAVMedia::DoExecute( SfxRequest& rReq )
     694             : {
     695           0 :     OUString     aURL;
     696           0 :     const SfxItemSet*   pReqArgs = rReq.GetArgs();
     697           0 :     bool                bAPI = false;
     698             : 
     699           0 :     if( pReqArgs )
     700             :     {
     701           0 :         const SfxStringItem* pStringItem = PTR_CAST( SfxStringItem, &pReqArgs->Get( rReq.GetSlot() ) );
     702             : 
     703           0 :         if( pStringItem )
     704             :         {
     705           0 :             aURL = pStringItem->GetValue();
     706           0 :             bAPI = !aURL.isEmpty();
     707             :         }
     708             :     }
     709             : 
     710           0 :     bool bLink(true);
     711           0 :     if (bAPI ||
     712           0 :         ::avmedia::MediaWindow::executeMediaURLDialog(mpWindow, aURL, & bLink))
     713             :     {
     714           0 :         Size aPrefSize;
     715             : 
     716           0 :         if( mpWindow )
     717           0 :             mpWindow->EnterWait();
     718             : 
     719           0 :         if( !::avmedia::MediaWindow::isMediaURL( aURL, "", true, &aPrefSize ) )
     720             :         {
     721           0 :             if( mpWindow )
     722           0 :                 mpWindow->LeaveWait();
     723             : 
     724           0 :             if( !bAPI )
     725           0 :                 ::avmedia::MediaWindow::executeFormatErrorBox( mpWindow );
     726             :         }
     727             :         else
     728             :         {
     729           0 :             Point       aPos;
     730           0 :             Size        aSize;
     731           0 :             sal_Int8    nAction = DND_ACTION_COPY;
     732             : 
     733           0 :             if( aPrefSize.Width() && aPrefSize.Height() )
     734             :             {
     735           0 :                 if( mpWindow )
     736           0 :                     aSize = mpWindow->PixelToLogic( aPrefSize, MAP_100TH_MM );
     737             :                 else
     738           0 :                     aSize = Application::GetDefaultDevice()->PixelToLogic( aPrefSize, MAP_100TH_MM );
     739             :             }
     740             :             else
     741           0 :                 aSize = Size( 5000, 5000 );
     742             : 
     743           0 :             if( mpWindow )
     744             :             {
     745           0 :                 aPos = mpWindow->PixelToLogic( Rectangle( aPos, mpWindow->GetOutputSizePixel() ).Center() );
     746           0 :                 aPos.X() -= aSize.Width() >> 1;
     747           0 :                 aPos.Y() -= aSize.Height() >> 1;
     748             :             }
     749             : 
     750           0 :             mpView->InsertMediaURL( aURL, nAction, aPos, aSize, bLink ) ;
     751             : 
     752           0 :             if( mpWindow )
     753           0 :                 mpWindow->LeaveWait();
     754             :         }
     755           0 :     }
     756           0 : }
     757             : 
     758           0 : FuInsert3DModel::FuInsert3DModel(
     759             :     ViewShell* pViewSh,
     760             :     ::sd::Window* pWin,
     761             :     ::sd::View* pView,
     762             :     SdDrawDocument* pDoc,
     763             :     SfxRequest& rReq)
     764           0 :     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
     765             : {
     766           0 : }
     767             : 
     768           0 : rtl::Reference<FuPoor> FuInsert3DModel::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
     769             : {
     770           0 :     rtl::Reference<FuPoor> xFunc( new FuInsert3DModel( pViewSh, pWin, pView, pDoc, rReq ) );
     771           0 :     xFunc->DoExecute(rReq);
     772           0 :     return xFunc;
     773             : }
     774             : 
     775           0 : void FuInsert3DModel::DoExecute( SfxRequest& )
     776             : {
     777           0 :     sfx2::FileDialogHelper aDlg( ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
     778             : 
     779           0 :     aDlg.SetTitle( "Insert 3D Model" );
     780           0 :     aDlg.AddFilter( "GL Transmission Format", "*.json" );
     781           0 :     aDlg.AddFilter( "All files", "*.*"  );
     782             : 
     783           0 :     OUString sURL;
     784           0 :     if( aDlg.Execute() == ERRCODE_NONE )
     785             :     {
     786           0 :         const INetURLObject aURL( aDlg.GetPath() );
     787           0 :         sURL = aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
     788             :     }
     789           0 :     else if( !sURL.isEmpty() )
     790           0 :         sURL = OUString();
     791             : 
     792           0 :     if (!sURL.isEmpty())
     793             :     {
     794           0 :         if( mpWindow )
     795           0 :             mpWindow->EnterWait();
     796             : 
     797           0 :         Point aPos;
     798           0 :         Size aSize(480,360);
     799           0 :         sal_Int8 nAction = DND_ACTION_COPY;
     800             : 
     801           0 :         if( mpWindow )
     802             :         {
     803           0 :             aPos = mpWindow->PixelToLogic( Rectangle( aPos, mpWindow->GetOutputSizePixel() ).Center() );
     804           0 :             aPos.X() -= aSize.Width() >> 1;
     805           0 :             aPos.Y() -= aSize.Height() >> 1;
     806             :         }
     807             : 
     808           0 :         mpView->Insert3DModelURL( sURL, nAction, aPos, aSize, false ) ;
     809             : 
     810           0 :         if( mpWindow )
     811           0 :             mpWindow->LeaveWait();
     812           0 :     }
     813           0 : }
     814             : 
     815           0 : } // end of namespace sd
     816             : 
     817             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10