bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / func / fuinsert.cxx
blob7691f2dc01134c32c20ad2c4b9009b959227d9f7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "fuinsert.hxx"
22 #include <comphelper/storagehelper.hxx>
23 #include <comphelper/processfactory.hxx>
24 #include <toolkit/helper/vclunohelper.hxx>
25 #include <svx/svxdlg.hxx>
26 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
27 #include <com/sun/star/embed/XComponentSupplier.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>
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 <svtools/embedhlp.hxx>
45 #include <svx/pfiledlg.hxx>
46 #include <svx/dialogs.hrc>
47 #include <sfx2/linkmgr.hxx>
48 #include <svx/linkwarn.hxx>
49 #include <svx/svdetc.hxx>
50 #include <avmedia/mediawindow.hxx>
51 #include <unotools/ucbstreamhelper.hxx>
52 #include <sfx2/printer.hxx>
53 #include <comphelper/classids.hxx>
54 #include <svtools/sfxecode.hxx>
55 #include <svtools/transfer.hxx>
56 #include <svl/urlbmk.hxx>
57 #include <svx/svdobj.hxx>
58 #include <svx/svdograf.hxx>
59 #include <svx/svdoole2.hxx>
60 #include <svx/svdomedia.hxx>
61 #include <editeng/editeng.hxx>
62 #include <sot/storage.hxx>
63 #include <sot/formats.hxx>
64 #include <svx/svdpagv.hxx>
65 #include <vcl/msgbox.hxx>
66 #include <sfx2/opengrf.hxx>
67 #include <sfx2/viewfrm.hxx>
68 #include <svx/charthelper.hxx>
70 #include "app.hrc"
71 #include "sdresid.hxx"
72 #include "View.hxx"
73 #include "sdmod.hxx"
74 #include "Window.hxx"
75 #include "drawview.hxx"
76 #include "DrawViewShell.hxx"
77 #include "DrawDocShell.hxx"
78 #include "GraphicDocShell.hxx"
79 #include "strings.hrc"
80 #include "drawdoc.hxx"
81 #include "sdgrffilter.hxx"
82 #include "sdxfer.hxx"
83 #include <vcl/svapp.hxx>
84 #include "undo/undoobjects.hxx"
85 #include <boost/scoped_ptr.hpp>
86 #include "glob.hrc"
88 #include <config_features.h>
90 using namespace com::sun::star;
92 namespace sd {
94 TYPEINIT1( FuInsertGraphic, FuPoor );
95 TYPEINIT1( FuInsertClipboard, FuPoor );
96 TYPEINIT1( FuInsertOLE, FuPoor );
97 TYPEINIT1( FuInsertAVMedia, FuPoor );
99 FuInsertGraphic::FuInsertGraphic (
100 ViewShell* pViewSh,
101 ::sd::Window* pWin,
102 ::sd::View* pView,
103 SdDrawDocument* pDoc,
104 SfxRequest& rReq)
105 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
109 rtl::Reference<FuPoor> FuInsertGraphic::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
111 rtl::Reference<FuPoor> xFunc( new FuInsertGraphic( pViewSh, pWin, pView, pDoc, rReq ) );
112 xFunc->DoExecute(rReq);
113 return xFunc;
116 void FuInsertGraphic::DoExecute( SfxRequest& )
118 SvxOpenGraphicDialog aDlg(SdResId(STR_INSERTGRAPHIC));
120 if( aDlg.Execute() == GRFILTER_OK )
122 Graphic aGraphic;
123 int nError = aDlg.GetGraphic(aGraphic);
124 if( nError == GRFILTER_OK )
126 if( mpViewShell && mpViewShell->ISA(DrawViewShell))
128 sal_Int8 nAction = DND_ACTION_COPY;
129 SdrObject* pPickObj;
130 bool bSelectionReplaced(false);
132 if( ( pPickObj = mpView->GetSelectedSingleObject( mpView->GetPage() ) ) || ( pPickObj = mpView->GetEmptyPresentationObject( PRESOBJ_GRAPHIC ) ) )
134 nAction = DND_ACTION_LINK;
136 else if(1 == mpView->GetMarkedObjectCount())
138 pPickObj = mpView->GetMarkedObjectByIndex(0);
139 nAction = DND_ACTION_MOVE;
140 bSelectionReplaced = true;
143 Point aPos;
144 Rectangle aRect(aPos, mpWindow->GetOutputSizePixel() );
145 aPos = aRect.Center();
146 aPos = mpWindow->PixelToLogic(aPos);
147 SdrGrafObj* pGrafObj = mpView->InsertGraphic(aGraphic, nAction, aPos, pPickObj, NULL);
149 if(pGrafObj && aDlg.IsAsLink())
151 // really store as link only?
152 if( SvtMiscOptions().ShowLinkWarningDialog() )
154 ScopedVclPtrInstance< SvxLinkWarningDialog > aWarnDlg(mpWindow,aDlg.GetPath());
155 if( aWarnDlg->Execute() != RET_OK )
156 return; // don't store as link
159 // store as link
160 OUString aFltName(aDlg.GetCurrentFilter());
161 OUString aPath(aDlg.GetPath());
162 OUString aReferer;
163 if (mpDocSh->HasName()) {
164 aReferer = mpDocSh->GetMedium()->GetName();
166 pGrafObj->SetGraphicLink(aPath, aReferer, aFltName);
169 if(bSelectionReplaced && pGrafObj)
171 mpView->MarkObj(pGrafObj, mpView->GetSdrPageView());
175 else
177 SdGRFFilter::HandleGraphicFilterError( (sal_uInt16)nError, GraphicFilter::GetGraphicFilter().GetLastError().nStreamError );
182 FuInsertClipboard::FuInsertClipboard (
183 ViewShell* pViewSh,
184 ::sd::Window* pWin,
185 ::sd::View* pView,
186 SdDrawDocument* pDoc,
187 SfxRequest& rReq)
188 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
192 rtl::Reference<FuPoor> FuInsertClipboard::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
194 rtl::Reference<FuPoor> xFunc( new FuInsertClipboard( pViewSh, pWin, pView, pDoc, rReq ) );
195 xFunc->DoExecute(rReq);
196 return xFunc;
199 void FuInsertClipboard::DoExecute( SfxRequest& )
201 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpWindow ) );
202 SotClipboardFormatId nFormatId;
204 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
205 boost::scoped_ptr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog( mpViewShell->GetActiveWindow() ));
206 if ( pDlg )
208 ::com::sun::star::datatransfer::DataFlavor aFlavor;
210 pDlg->Insert( SotClipboardFormatId::EMBED_SOURCE, OUString() );
211 pDlg->Insert( SotClipboardFormatId::LINK_SOURCE, OUString() );
212 pDlg->Insert( SotClipboardFormatId::DRAWING, OUString() );
213 pDlg->Insert( SotClipboardFormatId::SVXB, OUString() );
214 pDlg->Insert( SotClipboardFormatId::GDIMETAFILE, OUString() );
215 pDlg->Insert( SotClipboardFormatId::BITMAP, OUString() );
216 pDlg->Insert( SotClipboardFormatId::NETSCAPE_BOOKMARK, OUString() );
217 pDlg->Insert( SotClipboardFormatId::STRING, OUString() );
218 pDlg->Insert( SotClipboardFormatId::HTML, OUString() );
219 pDlg->Insert( SotClipboardFormatId::RTF, OUString() );
220 pDlg->Insert( SotClipboardFormatId::EDITENGINE, OUString() );
222 //TODO/MBA: testing
223 nFormatId = pDlg->GetFormat( aDataHelper );
224 if( nFormatId != SotClipboardFormatId::NONE && aDataHelper.GetTransferable().is() )
226 sal_Int8 nAction = DND_ACTION_COPY;
228 if( !mpView->InsertData( aDataHelper,
229 mpWindow->PixelToLogic( Rectangle( Point(), mpWindow->GetOutputSizePixel() ).Center() ),
230 nAction, false, nFormatId ) &&
231 ( mpViewShell && mpViewShell->ISA( DrawViewShell ) ) )
233 DrawViewShell* pDrViewSh = static_cast<DrawViewShell*>(mpViewShell);
234 INetBookmark aINetBookmark( aEmptyStr, aEmptyStr );
236 if( ( aDataHelper.HasFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK ) &&
237 aDataHelper.GetINetBookmark( SotClipboardFormatId::NETSCAPE_BOOKMARK, aINetBookmark ) ) ||
238 ( aDataHelper.HasFormat( SotClipboardFormatId::FILEGRPDESCRIPTOR ) &&
239 aDataHelper.GetINetBookmark( SotClipboardFormatId::FILEGRPDESCRIPTOR, aINetBookmark ) ) ||
240 ( aDataHelper.HasFormat( SotClipboardFormatId::UNIFORMRESOURCELOCATOR ) &&
241 aDataHelper.GetINetBookmark( SotClipboardFormatId::UNIFORMRESOURCELOCATOR, aINetBookmark ) ) )
243 pDrViewSh->InsertURLField( aINetBookmark.GetURL(), aINetBookmark.GetDescription(), aEmptyStr, NULL );
250 FuInsertOLE::FuInsertOLE (
251 ViewShell* pViewSh,
252 ::sd::Window* pWin,
253 ::sd::View* pView,
254 SdDrawDocument* pDoc,
255 SfxRequest& rReq)
256 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
260 rtl::Reference<FuPoor> FuInsertOLE::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
262 rtl::Reference<FuPoor> xFunc( new FuInsertOLE( pViewSh, pWin, pView, pDoc, rReq ) );
263 xFunc->DoExecute(rReq);
264 return xFunc;
267 void FuInsertOLE::DoExecute( SfxRequest& rReq )
269 if ( nSlotId == SID_ATTR_TABLE ||
270 nSlotId == SID_INSERT_DIAGRAM ||
271 nSlotId == SID_INSERT_MATH )
273 PresObjKind ePresObjKind = (nSlotId == SID_INSERT_DIAGRAM) ? PRESOBJ_CHART : PRESOBJ_OBJECT;
275 SdrObject* pPickObj = mpView->GetEmptyPresentationObject( ePresObjKind );
277 // insert diagram or Calc table
278 OUString aObjName;
279 SvGlobalName aName;
280 if (nSlotId == SID_INSERT_DIAGRAM)
281 aName = SvGlobalName( SO3_SCH_CLASSID);
282 else if (nSlotId == SID_ATTR_TABLE)
283 aName = SvGlobalName(SO3_SC_CLASSID);
284 else if (nSlotId == SID_INSERT_MATH)
285 aName = SvGlobalName(SO3_SM_CLASSID);
287 uno::Reference < embed::XEmbeddedObject > xObj = mpViewShell->GetViewFrame()->GetObjectShell()->
288 GetEmbeddedObjectContainer().CreateEmbeddedObject( aName.GetByteSequence(), aObjName );
289 if ( xObj.is() )
291 uno::Reference<embed::XComponentSupplier> xCompSupp(xObj, uno::UNO_QUERY);
292 if (xCompSupp.is())
294 // Create default chart type.
295 uno::Reference<chart2::XChartDocument> xChartDoc(xCompSupp->getComponent(), uno::UNO_QUERY);
296 if (xChartDoc.is())
297 xChartDoc->createDefaultChart();
300 sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
302 MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
304 Rectangle aRect;
305 if( pPickObj )
307 aRect = pPickObj->GetLogicRect();
309 awt::Size aSz;
310 aSz.Width = aRect.GetWidth();
311 aSz.Height = aRect.GetHeight();
312 xObj->setVisualAreaSize( nAspect, aSz );
314 else
316 awt::Size aSz;
319 aSz = xObj->getVisualAreaSize( nAspect );
321 catch ( embed::NoVisualAreaSizeException& )
323 // the default size will be set later
326 Size aSize( aSz.Width, aSz.Height );
328 if (aSize.Height() == 0 || aSize.Width() == 0)
330 // rectangle with balanced edge ratio
331 aSize.Width() = 14100;
332 aSize.Height() = 10000;
333 Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aUnit );
334 aSz.Width = aTmp.Width();
335 aSz.Height = aTmp.Height();
336 xObj->setVisualAreaSize( nAspect, aSz );
338 else
340 aSize = OutputDevice::LogicToLogic(aSize, aUnit, MAP_100TH_MM);
343 Point aPos;
344 Rectangle aWinRect(aPos, mpWindow->GetOutputSizePixel() );
345 aPos = aWinRect.Center();
346 aPos = mpWindow->PixelToLogic(aPos);
347 aPos.X() -= aSize.Width() / 2;
348 aPos.Y() -= aSize.Height() / 2;
349 aRect = Rectangle(aPos, aSize);
352 SdrOle2Obj* pOleObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aObjName, aRect );
353 SdrPageView* pPV = mpView->GetSdrPageView();
355 // if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj
356 if( pPickObj )
358 SdPage* pPage = static_cast< SdPage* >(pPickObj->GetPage());
359 if(pPage && pPage->IsPresObj(pPickObj))
361 pPage->InsertPresObj( pOleObj, ePresObjKind );
362 pOleObj->SetUserCall(pPickObj->GetUserCall());
365 // #i123468# we need to end text edit before replacing the object. There cannot yet
366 // being text typed (else it would not be an EmptyPresObj anymore), but it may be
367 // in text edit mode
368 if (mpView->IsTextEdit())
370 mpView->SdrEndTextEdit();
374 bool bRet = true;
375 if( pPickObj )
376 mpView->ReplaceObjectAtView(pPickObj, *pPV, pOleObj, true );
377 else
378 bRet = mpView->InsertObjectAtView(pOleObj, *pPV, SdrInsertFlags::SETDEFLAYER);
380 if( bRet )
382 if (nSlotId == SID_INSERT_DIAGRAM)
384 pOleObj->SetProgName( OUString( "StarChart" ));
386 else if (nSlotId == SID_ATTR_TABLE)
388 pOleObj->SetProgName( OUString( "StarCalc" ) );
390 else if (nSlotId == SID_INSERT_MATH)
392 pOleObj->SetProgName( OUString( "StarMath" ) );
395 pOleObj->SetLogicRect(aRect);
396 Size aTmp( OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aUnit ) );
397 awt::Size aVisualSize;
398 aVisualSize.Width = aTmp.Width();
399 aVisualSize.Height = aTmp.Height();
400 xObj->setVisualAreaSize( nAspect, aVisualSize );
401 mpViewShell->ActivateObject(pOleObj, SVVERB_SHOW);
403 if (nSlotId == SID_INSERT_DIAGRAM)
405 // note, that this call modified the chart model which
406 // results in a change notification. So call this after
407 // everything else is finished.
408 ChartHelper::AdaptDefaultsForChart( xObj );
412 else
414 ErrorHandler::HandleError(* new StringErrorInfo(ERRCODE_SFX_OLEGENERAL,
415 aEmptyStr ) );
418 else
420 // insert object
421 sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
422 bool bCreateNew = false;
423 uno::Reference < embed::XEmbeddedObject > xObj;
424 uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
425 SvObjectServerList aServerLst;
426 OUString aName;
428 OUString aIconMediaType;
429 uno::Reference< io::XInputStream > xIconMetaFile;
431 SFX_REQUEST_ARG( rReq, pNameItem, SfxGlobalNameItem, SID_INSERT_OBJECT, false );
432 if ( nSlotId == SID_INSERT_OBJECT && pNameItem )
434 SvGlobalName aClassName = pNameItem->GetValue();
435 xObj = mpViewShell->GetViewFrame()->GetObjectShell()->
436 GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName.GetByteSequence(), aName );
438 else
440 switch ( nSlotId )
442 case SID_INSERT_OBJECT :
444 aServerLst.FillInsertObjects();
445 if (mpDoc->GetDocumentType() == DOCUMENT_TYPE_DRAW)
447 aServerLst.Remove( GraphicDocShell::Factory().GetClassId() );
449 else
451 aServerLst.Remove( DrawDocShell::Factory().GetClassId() );
454 // intentionally no break!
456 case SID_INSERT_PLUGIN :
457 case SID_INSERT_FLOATINGFRAME :
459 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
460 boost::scoped_ptr<SfxAbstractInsertObjectDialog> pDlg(
461 pFact->CreateInsertObjectDialog( mpViewShell->GetActiveWindow(), SD_MOD()->GetSlotPool()->GetSlot(nSlotId)->GetCommandString(),
462 xStorage, &aServerLst ));
463 if ( pDlg )
465 pDlg->Execute();
466 bCreateNew = pDlg->IsCreateNew();
467 xObj = pDlg->GetObject();
469 xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType );
470 if ( xIconMetaFile.is() )
471 nAspect = embed::Aspects::MSOLE_ICON;
473 if ( xObj.is() )
474 mpViewShell->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aName );
477 break;
479 case SID_INSERT_SOUND :
480 case SID_INSERT_VIDEO :
482 // create special filedialog for plugins
483 SvxPluginFileDlg aPluginFileDialog (mpWindow, nSlotId);
484 if( ERRCODE_NONE == aPluginFileDialog.Execute () )
486 // get URL
487 OUString aStrURL(aPluginFileDialog.GetPath());
488 INetURLObject aURL( aStrURL, INetProtocol::File );
489 if( aURL.GetProtocol() != INetProtocol::NotValid )
491 // create a plugin object
492 xObj = mpViewShell->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_PLUGIN_CLASSID ).GetByteSequence(), aName );
495 if ( xObj.is() && svt::EmbeddedObjectRef::TryRunningState( xObj ) )
497 // set properties from dialog
498 uno::Reference < embed::XComponentSupplier > xSup( xObj, uno::UNO_QUERY );
499 if ( xSup.is() )
501 uno::Reference < beans::XPropertySet > xSet( xSup->getComponent(), uno::UNO_QUERY );
502 if ( xSet.is() )
504 xSet->setPropertyValue("PluginURL",
505 uno::makeAny( OUString( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) );
509 else
511 // unable to create PlugIn
512 OUString aStrErr( SdResId( STR_ERROR_OBJNOCREATE_PLUGIN ) );
513 aStrErr = aStrErr.replaceFirst( "%", aStrURL );
514 ScopedVclPtrInstance<MessageDialog>::Create(mpWindow, aStrErr)->Execute();
523 if (xObj.is())
525 //TODO/LATER: needs status for RESIZEONPRINTERCHANGE
526 //if( SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE & xObj->getStatus( nAspect ) )
527 // aIPObj->OnDocumentPrinterChanged( mpDocSh->GetPrinter(sal_False) );
529 bool bInsertNewObject = true;
531 Size aSize;
532 MapUnit aMapUnit = MAP_100TH_MM;
533 if ( nAspect != embed::Aspects::MSOLE_ICON )
535 awt::Size aSz;
538 aSz = xObj->getVisualAreaSize( nAspect );
540 catch( embed::NoVisualAreaSizeException& )
542 // the default size will be set later
545 aSize =Size( aSz.Width, aSz.Height );
547 aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
548 if (aSize.Height() == 0 || aSize.Width() == 0)
550 // rectangle with balanced edge ratio
551 aSize.Width() = 14100;
552 aSize.Height() = 10000;
553 Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aMapUnit );
554 aSz.Width = aTmp.Width();
555 aSz.Height = aTmp.Height();
556 xObj->setVisualAreaSize( nAspect, aSz );
558 else
560 aSize = OutputDevice::LogicToLogic(aSize, aMapUnit, MAP_100TH_MM);
564 if ( mpView->AreObjectsMarked() )
566 // as an empty OLE object available?
567 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
569 if (rMarkList.GetMarkCount() == 1)
571 SdrMark* pMark = rMarkList.GetMark(0);
572 SdrObject* pObj = pMark->GetMarkedSdrObj();
574 if (pObj->GetObjInventor() == SdrInventor &&
575 pObj->GetObjIdentifier() == OBJ_OLE2)
577 if ( !static_cast<SdrOle2Obj*>(pObj)->GetObjRef().is() )
579 // the empty OLE object gets a new IPObj
580 bInsertNewObject = false;
581 pObj->SetEmptyPresObj(false);
582 static_cast<SdrOle2Obj*>(pObj)->SetOutlinerParaObject(NULL);
583 static_cast<SdrOle2Obj*>(pObj)->SetObjRef(xObj);
584 static_cast<SdrOle2Obj*>(pObj)->SetPersistName(aName);
585 static_cast<SdrOle2Obj*>(pObj)->SetName(aName);
586 static_cast<SdrOle2Obj*>(pObj)->SetAspect(nAspect);
587 Rectangle aRect = static_cast<SdrOle2Obj*>(pObj)->GetLogicRect();
589 if ( nAspect == embed::Aspects::MSOLE_ICON )
591 if( xIconMetaFile.is() )
592 static_cast<SdrOle2Obj*>(pObj)->SetGraphicToObj( xIconMetaFile, aIconMediaType );
594 else
596 Size aTmp = OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aMapUnit );
597 awt::Size aSz( aTmp.Width(), aTmp.Height() );
598 xObj->setVisualAreaSize( nAspect, aSz );
605 if (bInsertNewObject)
607 // we create a new OLE object
608 SdrPageView* pPV = mpView->GetSdrPageView();
609 Size aPageSize = pPV->GetPage()->GetSize();
611 // get the size from the iconified object
612 ::svt::EmbeddedObjectRef aObjRef( xObj, nAspect );
613 if ( nAspect == embed::Aspects::MSOLE_ICON )
615 aObjRef.SetGraphicStream( xIconMetaFile, aIconMediaType );
616 MapMode aMapMode( MAP_100TH_MM );
617 aSize = aObjRef.GetSize( &aMapMode );
620 Point aPnt ((aPageSize.Width() - aSize.Width()) / 2,
621 (aPageSize.Height() - aSize.Height()) / 2);
622 Rectangle aRect (aPnt, aSize);
624 SdrOle2Obj* pObj = new SdrOle2Obj( aObjRef, aName, aRect);
626 if( mpView->InsertObjectAtView(pObj, *pPV, SdrInsertFlags::SETDEFLAYER) )
628 // Math objects change their object size during InsertObject.
629 // New size must be set in SdrObject, or a wrong scale will be set at
630 // ActivateObject.
632 if ( nAspect != embed::Aspects::MSOLE_ICON )
636 awt::Size aSz = xObj->getVisualAreaSize( nAspect );
638 Size aNewSize = Window::LogicToLogic( Size( aSz.Width, aSz.Height ),
639 MapMode( aMapUnit ), MapMode( MAP_100TH_MM ) );
640 if ( aNewSize != aSize )
642 aRect.SetSize( aNewSize );
643 pObj->SetLogicRect( aRect );
646 catch( embed::NoVisualAreaSizeException& )
650 if (bCreateNew)
652 pObj->SetLogicRect(aRect);
654 if ( nAspect != embed::Aspects::MSOLE_ICON )
656 Size aTmp = OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aMapUnit );
657 awt::Size aSz( aTmp.Width(), aTmp.Height() );
658 xObj->setVisualAreaSize( nAspect, aSz );
661 mpViewShell->ActivateObject(pObj, SVVERB_SHOW);
664 Size aVisSizePixel = mpWindow->GetOutputSizePixel();
665 Rectangle aVisAreaWin = mpWindow->PixelToLogic( Rectangle( Point(0,0), aVisSizePixel) );
666 mpViewShell->VisAreaChanged(aVisAreaWin);
667 mpDocSh->SetVisArea(aVisAreaWin);
672 catch (uno::Exception&)
674 // For some reason the object can not be inserted. For example
675 // because it is password protected and is not properly unlocked.
680 FuInsertAVMedia::FuInsertAVMedia(
681 ViewShell* pViewSh,
682 ::sd::Window* pWin,
683 ::sd::View* pView,
684 SdDrawDocument* pDoc,
685 SfxRequest& rReq)
686 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
690 rtl::Reference<FuPoor> FuInsertAVMedia::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
692 rtl::Reference<FuPoor> xFunc( new FuInsertAVMedia( pViewSh, pWin, pView, pDoc, rReq ) );
693 xFunc->DoExecute(rReq);
694 return xFunc;
697 void FuInsertAVMedia::DoExecute( SfxRequest& rReq )
699 OUString aURL;
700 const SfxItemSet* pReqArgs = rReq.GetArgs();
701 bool bAPI = false;
703 if( pReqArgs )
705 const SfxStringItem* pStringItem = PTR_CAST( SfxStringItem, &pReqArgs->Get( rReq.GetSlot() ) );
707 if( pStringItem )
709 aURL = pStringItem->GetValue();
710 bAPI = !aURL.isEmpty();
714 bool bLink(true);
715 if (bAPI ||
716 ::avmedia::MediaWindow::executeMediaURLDialog(mpWindow, aURL, & bLink))
718 Size aPrefSize;
720 if( mpWindow )
721 mpWindow->EnterWait();
723 if( !::avmedia::MediaWindow::isMediaURL( aURL, "", true, &aPrefSize ) )
725 if( mpWindow )
726 mpWindow->LeaveWait();
728 if( !bAPI )
729 ::avmedia::MediaWindow::executeFormatErrorBox( mpWindow );
731 else
733 Point aPos;
734 Size aSize;
735 sal_Int8 nAction = DND_ACTION_COPY;
737 if( aPrefSize.Width() && aPrefSize.Height() )
739 if( mpWindow )
740 aSize = mpWindow->PixelToLogic( aPrefSize, MAP_100TH_MM );
741 else
742 aSize = Application::GetDefaultDevice()->PixelToLogic( aPrefSize, MAP_100TH_MM );
744 else
745 aSize = Size( 5000, 5000 );
747 if( mpWindow )
749 aPos = mpWindow->PixelToLogic( Rectangle( aPos, mpWindow->GetOutputSizePixel() ).Center() );
750 aPos.X() -= aSize.Width() >> 1;
751 aPos.Y() -= aSize.Height() >> 1;
754 mpView->InsertMediaURL( aURL, nAction, aPos, aSize, bLink ) ;
756 if( mpWindow )
757 mpWindow->LeaveWait();
762 #if HAVE_FEATURE_GLTF
763 TYPEINIT1( FuInsert3DModel, FuPoor );
765 FuInsert3DModel::FuInsert3DModel(
766 ViewShell* pViewSh,
767 ::sd::Window* pWin,
768 ::sd::View* pView,
769 SdDrawDocument* pDoc,
770 SfxRequest& rReq)
771 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
775 rtl::Reference<FuPoor> FuInsert3DModel::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
777 rtl::Reference<FuPoor> xFunc( new FuInsert3DModel( pViewSh, pWin, pView, pDoc, rReq ) );
778 xFunc->DoExecute(rReq);
779 return xFunc;
782 void FuInsert3DModel::DoExecute( SfxRequest& )
784 sfx2::FileDialogHelper aDlg( ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
786 aDlg.SetTitle( "Insert 3D Model" );
788 #if HAVE_FEATURE_COLLADA
789 aDlg.AddFilter( "All supported formats", "*.json;*.dae;*.kmz" );
790 #else
791 aDlg.AddFilter( "All supported formats", "*.json" );
792 #endif
794 aDlg.AddFilter( "JSON - GL Transmission Format", "*.json" );
796 #if HAVE_FEATURE_COLLADA
797 aDlg.AddFilter( "DAE - COLLADA", "*.dae" );
798 aDlg.AddFilter( "KMZ - Keyhole Markup language Zipped", "*.kmz" );
799 #endif
801 OUString sURL;
802 if( aDlg.Execute() == ERRCODE_NONE )
804 const INetURLObject aURL( aDlg.GetPath() );
805 sURL = aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
807 else if( !sURL.isEmpty() )
808 sURL.clear();
810 if (!sURL.isEmpty())
812 if( mpWindow )
813 mpWindow->EnterWait();
815 Point aPos;
816 sal_Int8 nAction = DND_ACTION_COPY;
818 Size aSize(480,360);
819 if( mpWindow )
820 aSize = mpWindow->PixelToLogic( aSize, MAP_100TH_MM );
821 else
822 aSize = Application::GetDefaultDevice()->PixelToLogic( aSize, MAP_100TH_MM );
824 if( mpWindow )
826 aPos = mpWindow->PixelToLogic( Rectangle( aPos, mpWindow->GetOutputSizePixel() ).Center() );
827 aPos.X() -= aSize.Width() >> 1;
828 aPos.Y() -= aSize.Height() >> 1;
831 mpView->Insert3DModelURL( sURL, nAction, aPos, aSize, false ) ;
833 if( mpWindow )
834 mpWindow->LeaveWait();
837 #endif
838 } // end of namespace sd
840 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */