1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <config_features.h>
22 #include <fuinsert.hxx>
23 #include <comphelper/storagehelper.hxx>
24 #include <comphelper/propertysequence.hxx>
25 #include <editeng/sizeitem.hxx>
26 #include <officecfg/Office/Common.hxx>
27 #include <toolkit/helper/vclunohelper.hxx>
28 #include <svx/svxdlg.hxx>
29 #include <com/sun/star/chart2/XChartDocument.hpp>
30 #include <com/sun/star/embed/EmbedVerbs.hpp>
31 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
32 #include <com/sun/star/embed/Aspects.hpp>
33 #include <com/sun/star/embed/XEmbeddedObject.hpp>
34 #include <com/sun/star/frame/XDispatchProvider.hpp>
35 #include <com/sun/star/media/XPlayer.hpp>
37 #include <svl/stritem.hxx>
38 #include <sfx2/dispatch.hxx>
39 #include <sfx2/msgpool.hxx>
40 #include <sfx2/msg.hxx>
41 #include <svtools/insdlg.hxx>
42 #include <sfx2/request.hxx>
43 #include <svl/globalnameitem.hxx>
44 #include <svtools/embedhlp.hxx>
45 #include <svx/linkwarn.hxx>
46 #include <avmedia/mediawindow.hxx>
47 #include <comphelper/classids.hxx>
48 #include <svtools/sfxecode.hxx>
49 #include <vcl/transfer.hxx>
50 #include <svl/urlbmk.hxx>
51 #include <svx/svdobj.hxx>
52 #include <svx/svdograf.hxx>
53 #include <svx/svdoole2.hxx>
54 #include <sot/formats.hxx>
55 #include <svx/svdpagv.hxx>
56 #include <sfx2/opengrf.hxx>
57 #include <sfx2/viewfrm.hxx>
58 #include <svx/charthelper.hxx>
59 #include <svx/svxids.hrc>
61 #include <sdresid.hxx>
65 #include <DrawViewShell.hxx>
66 #include <DrawDocShell.hxx>
67 #include <GraphicDocShell.hxx>
68 #include <strings.hrc>
69 #include <drawdoc.hxx>
71 #include <sdgrffilter.hxx>
72 #include <vcl/svapp.hxx>
73 #include <vcl/weld.hxx>
74 #include <vcl/errinf.hxx>
75 #include <vcl/graphicfilter.hxx>
77 #include <vcl/GraphicNativeTransform.hxx>
78 #include <vcl/GraphicNativeMetadata.hxx>
80 #include <comphelper/lok.hxx>
82 using namespace com::sun::star
;
87 FuInsertGraphic::FuInsertGraphic (
93 bool replaceExistingImage
)
94 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
),
95 mbReplaceExistingImage(replaceExistingImage
)
99 rtl::Reference
<FuPoor
> FuInsertGraphic::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
,
100 SdDrawDocument
* pDoc
, SfxRequest
& rReq
, bool replaceExistingImage
)
102 rtl::Reference
<FuPoor
> xFunc( new FuInsertGraphic( pViewSh
, pWin
, pView
, pDoc
, rReq
, replaceExistingImage
) );
103 xFunc
->DoExecute(rReq
);
107 void FuInsertGraphic::DoExecute( SfxRequest
& rReq
)
112 bool bAsLink
= false;
113 ErrCode nError
= ERRCODE_GRFILTER_OPENERROR
;
115 const SfxItemSet
* pArgs
= rReq
.GetArgs();
116 const SfxPoolItem
* pItem
;
119 pArgs
->GetItemState( SID_INSERT_GRAPHIC
, true, &pItem
) == SfxItemState::SET
)
121 aFileName
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
123 OUString aFilterName
;
124 if ( const SfxStringItem
* pFilterItem
= pArgs
->GetItemIfSet( FN_PARAM_FILTER
) )
125 aFilterName
= pFilterItem
->GetValue();
127 if ( pArgs
->GetItemState( FN_PARAM_1
, true, &pItem
) == SfxItemState::SET
)
128 bAsLink
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
130 nError
= GraphicFilter::LoadGraphic( aFileName
, aFilterName
, aGraphic
, &GraphicFilter::GetGraphicFilter() );
134 SvxOpenGraphicDialog
aDlg(SdResId(STR_INSERTGRAPHIC
), mpWindow
? mpWindow
->GetFrameWeld() : nullptr);
136 if( aDlg
.Execute() != ERRCODE_NONE
)
137 return; // cancel dialog
139 nError
= aDlg
.GetGraphic(aGraphic
);
140 bAsLink
= aDlg
.IsAsLink();
141 aFileName
= aDlg
.GetPath();
144 if( nError
== ERRCODE_NONE
)
146 GraphicNativeMetadata aMetadata
;
147 if ( aMetadata
.read(aGraphic
) )
149 const Degree10 aRotation
= aMetadata
.getRotation();
152 GraphicNativeTransform
aTransform( aGraphic
);
153 aTransform
.rotate( aRotation
);
156 if( dynamic_cast< DrawViewShell
*>( mpViewShell
) )
158 sal_Int8 nAction
= DND_ACTION_COPY
;
159 SdrObject
* pPickObj
= nullptr;
160 if (mbReplaceExistingImage
)
161 pPickObj
= mpView
->GetSelectedSingleObject( mpView
->GetPage() );
163 nAction
= DND_ACTION_LINK
;
166 pPickObj
= mpView
->GetEmptyPresentationObject( PresObjKind::Graphic
);
168 nAction
= DND_ACTION_LINK
;
171 Point aPos
= mpWindow
->GetVisibleCenter();
172 SdrGrafObj
* pGrafObj
= mpView
->InsertGraphic(aGraphic
, nAction
, aPos
, pPickObj
, nullptr);
174 if(pGrafObj
&& bAsLink
)
176 // really store as link only?
177 if( officecfg::Office::Common::Misc::ShowLinkWarningDialog::get() )
179 SvxLinkWarningDialog
aWarnDlg(mpWindow
->GetFrameWeld(), aFileName
);
180 if (aWarnDlg
.run() != RET_OK
)
181 return; // don't store as link
185 pGrafObj
->SetGraphicLink(aFileName
);
191 SdGRFFilter::HandleGraphicFilterError( nError
, GraphicFilter::GetGraphicFilter().GetLastError() );
195 FuInsertClipboard::FuInsertClipboard (
199 SdDrawDocument
* pDoc
,
201 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
205 rtl::Reference
<FuPoor
> FuInsertClipboard::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
207 rtl::Reference
<FuPoor
> xFunc( new FuInsertClipboard( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
208 xFunc
->DoExecute(rReq
);
212 void FuInsertClipboard::DoExecute( SfxRequest
& )
214 TransferableDataHelper
aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpWindow
) );
215 SotClipboardFormatId nFormatId
;
217 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
218 ScopedVclPtr
<SfxAbstractPasteDialog
> pDlg(pFact
->CreatePasteDialog(mpViewShell
->GetFrameWeld()));
219 pDlg
->Insert( SotClipboardFormatId::EMBED_SOURCE
, OUString() );
220 pDlg
->Insert( SotClipboardFormatId::LINK_SOURCE
, OUString() );
221 pDlg
->Insert( SotClipboardFormatId::DRAWING
, OUString() );
222 pDlg
->Insert( SotClipboardFormatId::SVXB
, OUString() );
223 pDlg
->Insert( SotClipboardFormatId::GDIMETAFILE
, OUString() );
224 pDlg
->Insert( SotClipboardFormatId::BITMAP
, OUString() );
225 pDlg
->Insert( SotClipboardFormatId::NETSCAPE_BOOKMARK
, OUString() );
226 pDlg
->Insert( SotClipboardFormatId::STRING
, OUString() );
227 pDlg
->Insert( SotClipboardFormatId::HTML
, OUString() );
228 pDlg
->Insert( SotClipboardFormatId::RTF
, OUString() );
229 pDlg
->Insert( SotClipboardFormatId::RICHTEXT
, OUString() );
230 pDlg
->Insert( SotClipboardFormatId::EDITENGINE_ODF_TEXT_FLAT
, OUString() );
233 nFormatId
= pDlg
->GetFormat( aDataHelper
);
234 if( nFormatId
== SotClipboardFormatId::NONE
|| !aDataHelper
.GetTransferable().is() )
237 sal_Int8 nAction
= DND_ACTION_COPY
;
238 DrawViewShell
* pDrViewSh
= nullptr;
240 if (!mpView
->InsertData( aDataHelper
,
241 mpWindow
->PixelToLogic( ::tools::Rectangle( Point(), mpWindow
->GetOutputSizePixel() ).Center() ),
242 nAction
, false, nFormatId
))
244 pDrViewSh
= dynamic_cast<DrawViewShell
*>(mpViewShell
);
250 INetBookmark
aINetBookmark( "", "" );
252 if( ( aDataHelper
.HasFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK
) &&
253 aDataHelper
.GetINetBookmark( SotClipboardFormatId::NETSCAPE_BOOKMARK
, aINetBookmark
) ) ||
254 ( aDataHelper
.HasFormat( SotClipboardFormatId::FILEGRPDESCRIPTOR
) &&
255 aDataHelper
.GetINetBookmark( SotClipboardFormatId::FILEGRPDESCRIPTOR
, aINetBookmark
) ) ||
256 ( aDataHelper
.HasFormat( SotClipboardFormatId::UNIFORMRESOURCELOCATOR
) &&
257 aDataHelper
.GetINetBookmark( SotClipboardFormatId::UNIFORMRESOURCELOCATOR
, aINetBookmark
) ) )
259 pDrViewSh
->InsertURLField( aINetBookmark
.GetURL(), aINetBookmark
.GetDescription(), "" );
263 FuInsertOLE::FuInsertOLE (
267 SdDrawDocument
* pDoc
,
269 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
273 rtl::Reference
<FuPoor
> FuInsertOLE::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
275 rtl::Reference
<FuPoor
> xFunc( new FuInsertOLE( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
276 xFunc
->DoExecute(rReq
);
280 void FuInsertOLE::DoExecute( SfxRequest
& rReq
)
282 if ( nSlotId
== SID_ATTR_TABLE
||
283 nSlotId
== SID_INSERT_DIAGRAM
||
284 nSlotId
== SID_INSERT_MATH
)
286 PresObjKind ePresObjKind
= (nSlotId
== SID_INSERT_DIAGRAM
) ? PresObjKind::Chart
: PresObjKind::Object
;
288 SdrObject
* pPickObj
= mpView
->GetEmptyPresentationObject( ePresObjKind
);
290 // insert diagram or Calc table
293 if (nSlotId
== SID_INSERT_DIAGRAM
)
294 aName
= SvGlobalName( SO3_SCH_CLASSID
);
295 else if (nSlotId
== SID_ATTR_TABLE
)
296 aName
= SvGlobalName(SO3_SC_CLASSID
);
297 else if (nSlotId
== SID_INSERT_MATH
)
298 aName
= SvGlobalName(SO3_SM_CLASSID
);
300 uno::Reference
< embed::XEmbeddedObject
> xObj
= mpViewShell
->GetViewFrame()->GetObjectShell()->
301 GetEmbeddedObjectContainer().CreateEmbeddedObject( aName
.GetByteSequence(), aObjName
);
304 // Create default chart type.
305 uno::Reference
<chart2::XChartDocument
> xChartDoc(xObj
->getComponent(), uno::UNO_QUERY
);
307 xChartDoc
->createDefaultChart();
309 sal_Int64 nAspect
= embed::Aspects::MSOLE_CONTENT
;
311 MapUnit aUnit
= VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj
->getMapUnit( nAspect
) );
313 ::tools::Rectangle aRect
;
316 aRect
= pPickObj
->GetLogicRect();
319 aSz
.Width
= aRect
.GetWidth();
320 aSz
.Height
= aRect
.GetHeight();
321 xObj
->setVisualAreaSize( nAspect
, aSz
);
328 aSz
= xObj
->getVisualAreaSize( nAspect
);
330 catch ( embed::NoVisualAreaSizeException
& )
332 // the default size will be set later
335 Size
aSize( aSz
.Width
, aSz
.Height
);
339 // rectangle with balanced edge ratio
340 aSize
.setWidth( 14100 );
341 aSize
.setHeight( 10000 );
342 Size aTmp
= OutputDevice::LogicToLogic(aSize
, MapMode(MapUnit::Map100thMM
), MapMode(aUnit
));
343 aSz
.Width
= aTmp
.Width();
344 aSz
.Height
= aTmp
.Height();
345 xObj
->setVisualAreaSize( nAspect
, aSz
);
349 aSize
= OutputDevice::LogicToLogic(aSize
, MapMode(aUnit
), MapMode(MapUnit::Map100thMM
));
352 Point aPos
= mpWindow
->GetVisibleCenter();
353 aPos
.AdjustX( -(aSize
.Width() / 2) );
354 aPos
.AdjustY( -(aSize
.Height() / 2) );
355 aRect
= ::tools::Rectangle(aPos
, aSize
);
358 rtl::Reference
<SdrOle2Obj
> pOleObj
= new SdrOle2Obj(
359 mpView
->getSdrModelFromSdrView(),
360 svt::EmbeddedObjectRef( xObj
, nAspect
),
363 SdrPageView
* pPV
= mpView
->GetSdrPageView();
365 // if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj
368 SdPage
* pPage
= static_cast< SdPage
* >(pPickObj
->getSdrPageFromSdrObject());
369 if(pPage
&& pPage
->IsPresObj(pPickObj
))
371 pPage
->InsertPresObj( pOleObj
.get(), ePresObjKind
);
372 pOleObj
->SetUserCall(pPickObj
->GetUserCall());
375 // #i123468# we need to end text edit before replacing the object. There cannot yet
376 // being text typed (else it would not be an EmptyPresObj anymore), but it may be
378 if (mpView
->IsTextEdit())
380 mpView
->SdrEndTextEdit();
386 mpView
->ReplaceObjectAtView(pPickObj
, *pPV
, pOleObj
.get() );
388 bRet
= mpView
->InsertObjectAtView(pOleObj
.get(), *pPV
, SdrInsertFlags::SETDEFLAYER
);
390 if (bRet
&& !comphelper::LibreOfficeKit::isActive())
392 // Let the chart be activated after the inserting (unless
393 // via LibreOfficeKit)
394 if (nSlotId
== SID_INSERT_DIAGRAM
)
396 pOleObj
->SetProgName( "StarChart");
398 else if (nSlotId
== SID_ATTR_TABLE
)
400 pOleObj
->SetProgName( "StarCalc" );
402 else if (nSlotId
== SID_INSERT_MATH
)
404 pOleObj
->SetProgName( "StarMath" );
407 pOleObj
->SetLogicRect(aRect
);
408 Size
aTmp( OutputDevice::LogicToLogic(aRect
.GetSize(), MapMode(MapUnit::Map100thMM
), MapMode(aUnit
)) );
409 awt::Size aVisualSize
;
410 aVisualSize
.Width
= aTmp
.Width();
411 aVisualSize
.Height
= aTmp
.Height();
412 xObj
->setVisualAreaSize( nAspect
, aVisualSize
);
413 mpViewShell
->ActivateObject(pOleObj
.get(), embed::EmbedVerbs::MS_OLEVERB_SHOW
);
415 if (nSlotId
== SID_INSERT_DIAGRAM
)
417 // note, that this call modified the chart model which
418 // results in a change notification. So call this after
419 // everything else is finished.
420 ChartHelper::AdaptDefaultsForChart( xObj
);
426 ErrorHandler::HandleError(* new StringErrorInfo(ERRCODE_SFX_OLEGENERAL
,
433 sal_Int64 nAspect
= embed::Aspects::MSOLE_CONTENT
;
434 bool bCreateNew
= false;
435 uno::Reference
< embed::XEmbeddedObject
> xObj
;
436 uno::Reference
< embed::XStorage
> xStorage
= comphelper::OStorageHelper::GetTemporaryStorage();
437 SvObjectServerList aServerLst
;
440 OUString aIconMediaType
;
441 uno::Reference
< io::XInputStream
> xIconMetaFile
;
443 const SfxGlobalNameItem
* pNameItem
= rReq
.GetArg
<SfxGlobalNameItem
>(SID_INSERT_OBJECT
);
444 if ( nSlotId
== SID_INSERT_OBJECT
&& pNameItem
)
446 const SvGlobalName
& aClassName
= pNameItem
->GetValue();
447 xObj
= mpViewShell
->GetViewFrame()->GetObjectShell()->
448 GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName
.GetByteSequence(), aName
);
454 case SID_INSERT_OBJECT
:
456 aServerLst
.FillInsertObjects();
457 if (mpDoc
->GetDocumentType() == DocumentType::Draw
)
459 aServerLst
.Remove( GraphicDocShell::Factory().GetClassId() );
463 aServerLst
.Remove( DrawDocShell::Factory().GetClassId() );
468 case SID_INSERT_FLOATINGFRAME
:
470 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
471 ScopedVclPtr
<SfxAbstractInsertObjectDialog
> pDlg(
472 pFact
->CreateInsertObjectDialog( mpViewShell
->GetFrameWeld(), SD_MOD()->GetSlotPool()->GetSlot(nSlotId
)->GetCommand(),
473 xStorage
, &aServerLst
));
475 bCreateNew
= pDlg
->IsCreateNew();
476 xObj
= pDlg
->GetObject();
478 xIconMetaFile
= pDlg
->GetIconIfIconified( &aIconMediaType
);
479 if ( xIconMetaFile
.is() )
480 nAspect
= embed::Aspects::MSOLE_ICON
;
483 mpViewShell
->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj
, aName
);
494 bool bInsertNewObject
= true;
497 MapUnit aMapUnit
= MapUnit::Map100thMM
;
498 if ( nAspect
!= embed::Aspects::MSOLE_ICON
)
503 aSz
= xObj
->getVisualAreaSize( nAspect
);
505 catch( embed::NoVisualAreaSizeException
& )
507 // the default size will be set later
510 aSize
=Size( aSz
.Width
, aSz
.Height
);
512 aMapUnit
= VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj
->getMapUnit( nAspect
) );
515 // rectangle with balanced edge ratio
516 aSize
.setWidth( 14100 );
517 aSize
.setHeight( 10000 );
518 Size aTmp
= OutputDevice::LogicToLogic(aSize
, MapMode(MapUnit::Map100thMM
), MapMode(aMapUnit
));
519 aSz
.Width
= aTmp
.Width();
520 aSz
.Height
= aTmp
.Height();
521 xObj
->setVisualAreaSize( nAspect
, aSz
);
525 aSize
= OutputDevice::LogicToLogic(aSize
, MapMode(aMapUnit
), MapMode(MapUnit::Map100thMM
));
529 if ( mpView
->AreObjectsMarked() )
531 // as an empty OLE object available?
532 const SdrMarkList
& rMarkList
= mpView
->GetMarkedObjectList();
534 if (rMarkList
.GetMarkCount() == 1)
536 SdrMark
* pMark
= rMarkList
.GetMark(0);
537 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
539 if (pObj
->GetObjInventor() == SdrInventor::Default
&&
540 pObj
->GetObjIdentifier() == SdrObjKind::OLE2
)
542 if ( !static_cast<SdrOle2Obj
*>(pObj
)->GetObjRef().is() )
544 // the empty OLE object gets a new IPObj
545 bInsertNewObject
= false;
546 pObj
->SetEmptyPresObj(false);
547 static_cast<SdrOle2Obj
*>(pObj
)->SetOutlinerParaObject(std::nullopt
);
548 static_cast<SdrOle2Obj
*>(pObj
)->SetObjRef(xObj
);
549 static_cast<SdrOle2Obj
*>(pObj
)->SetPersistName(aName
);
550 static_cast<SdrOle2Obj
*>(pObj
)->SetName(aName
);
551 static_cast<SdrOle2Obj
*>(pObj
)->SetAspect(nAspect
);
552 ::tools::Rectangle aRect
= static_cast<SdrOle2Obj
*>(pObj
)->GetLogicRect();
554 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
556 if( xIconMetaFile
.is() )
557 static_cast<SdrOle2Obj
*>(pObj
)->SetGraphicToObj( xIconMetaFile
, aIconMediaType
);
561 Size aTmp
= OutputDevice::LogicToLogic(aRect
.GetSize(), MapMode(MapUnit::Map100thMM
), MapMode(aMapUnit
));
562 awt::Size
aSz( aTmp
.Width(), aTmp
.Height() );
563 xObj
->setVisualAreaSize( nAspect
, aSz
);
570 if (bInsertNewObject
)
572 // we create a new OLE object
573 SdrPageView
* pPV
= mpView
->GetSdrPageView();
574 Size aPageSize
= pPV
->GetPage()->GetSize();
576 // get the size from the iconified object
577 ::svt::EmbeddedObjectRef
aObjRef( xObj
, nAspect
);
578 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
580 aObjRef
.SetGraphicStream( xIconMetaFile
, aIconMediaType
);
581 MapMode
aMapMode( MapUnit::Map100thMM
);
582 aSize
= aObjRef
.GetSize( &aMapMode
);
585 Point
aPnt ((aPageSize
.Width() - aSize
.Width()) / 2,
586 (aPageSize
.Height() - aSize
.Height()) / 2);
587 ::tools::Rectangle
aRect (aPnt
, aSize
);
588 rtl::Reference
<SdrOle2Obj
> pObj
= new SdrOle2Obj(
589 mpView
->getSdrModelFromSdrView(),
594 if( mpView
->InsertObjectAtView(pObj
.get(), *pPV
, SdrInsertFlags::SETDEFLAYER
) )
596 // Math objects change their object size during InsertObject.
597 // New size must be set in SdrObject, or a wrong scale will be set at
600 if ( nAspect
!= embed::Aspects::MSOLE_ICON
)
604 awt::Size aSz
= xObj
->getVisualAreaSize( nAspect
);
606 Size aNewSize
= OutputDevice::LogicToLogic( Size( aSz
.Width
, aSz
.Height
),
607 MapMode( aMapUnit
), MapMode( MapUnit::Map100thMM
) );
608 if ( aNewSize
!= aSize
)
610 aRect
.SetSize( aNewSize
);
611 pObj
->SetLogicRect( aRect
);
614 catch( embed::NoVisualAreaSizeException
& )
620 pObj
->SetLogicRect(aRect
);
622 if ( nAspect
!= embed::Aspects::MSOLE_ICON
)
624 Size aTmp
= OutputDevice::LogicToLogic(aRect
.GetSize(), MapMode(MapUnit::Map100thMM
), MapMode(aMapUnit
));
625 awt::Size
aSz( aTmp
.Width(), aTmp
.Height() );
626 xObj
->setVisualAreaSize( nAspect
, aSz
);
629 mpViewShell
->ActivateObject(pObj
.get(), embed::EmbedVerbs::MS_OLEVERB_SHOW
);
632 Size aVisSizePixel
= mpWindow
->GetOutputSizePixel();
633 ::tools::Rectangle aVisAreaWin
= mpWindow
->PixelToLogic( ::tools::Rectangle( Point(0,0), aVisSizePixel
) );
634 mpViewShell
->VisAreaChanged(aVisAreaWin
);
635 mpDocSh
->SetVisArea(aVisAreaWin
);
640 catch (uno::Exception
&)
642 // For some reason the object can not be inserted. For example
643 // because it is password protected and is not properly unlocked.
648 FuInsertAVMedia::FuInsertAVMedia(
652 SdDrawDocument
* pDoc
,
654 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
658 rtl::Reference
<FuPoor
> FuInsertAVMedia::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
660 rtl::Reference
<FuPoor
> xFunc( new FuInsertAVMedia( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
661 xFunc
->DoExecute(rReq
);
665 void FuInsertAVMedia::DoExecute( SfxRequest
& rReq
)
667 #if HAVE_FEATURE_AVMEDIA
669 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
672 const SvxSizeItem
* pSizeItem
= rReq
.GetArg
<SvxSizeItem
>(FN_PARAM_1
);
673 const SfxBoolItem
* pLinkItem
= rReq
.GetArg
<SfxBoolItem
>(FN_PARAM_2
);
674 const bool bSizeUnknown
= !pSizeItem
;
679 const SfxStringItem
* pStringItem
= dynamic_cast<const SfxStringItem
*>( &pReqArgs
->Get( rReq
.GetSlot() ) );
683 aURL
= pStringItem
->GetValue();
684 bAPI
= !aURL
.isEmpty();
688 bool bLink(pLinkItem
? pLinkItem
->GetValue() : true);
690 || ::avmedia::MediaWindow::executeMediaURLDialog(mpWindow
? mpWindow
->GetFrameWeld() : nullptr, aURL
, & bLink
)
696 aPrefSize
= pSizeItem
->GetSize();
700 // If we don't have a size then try and find that out, the resulted might be deliver async, so dispatch a follow up
701 // effort to insert the video, this time with a size.
703 mpWindow
->EnterWait();
705 css::uno::Reference
<css::frame::XDispatchProvider
> xDispatchProvider(mpViewShell
->GetViewFrame()->GetFrame().GetFrameInterface(), css::uno::UNO_QUERY
);
707 rtl::Reference
<avmedia::PlayerListener
> xPlayerListener(new avmedia::PlayerListener(
708 [xDispatchProvider
, aURL
, bLink
](const css::uno::Reference
<css::media::XPlayer
>& rPlayer
){
709 css::awt::Size aSize
= rPlayer
->getPreferredPlayerWindowSize();
710 avmedia::MediaWindow::dispatchInsertAVMedia(xDispatchProvider
, aSize
, aURL
, bLink
);
713 const bool bIsMediaURL
= ::avmedia::MediaWindow::isMediaURL(aURL
, "", true, xPlayerListener
);
716 mpWindow
->LeaveWait();
718 if (!bIsMediaURL
&& !bAPI
)
719 ::avmedia::MediaWindow::executeFormatErrorBox(mpWindow
->GetFrameWeld());
724 InsertMediaURL(aURL
, aPrefSize
, bLink
);
731 #if HAVE_FEATURE_AVMEDIA
732 void FuInsertAVMedia::InsertMediaURL(const OUString
& rURL
, const Size
& rPrefSize
, bool bLink
)
735 mpWindow
->EnterWait();
739 sal_Int8 nAction
= DND_ACTION_COPY
;
741 if (rPrefSize
.Width() && rPrefSize
.Height())
744 aSize
= mpWindow
->PixelToLogic(rPrefSize
, MapMode(MapUnit::Map100thMM
));
746 aSize
= Application::GetDefaultDevice()->PixelToLogic(rPrefSize
, MapMode(MapUnit::Map100thMM
));
749 aSize
= Size( 5000, 5000 );
753 aPos
= mpWindow
->PixelToLogic( ::tools::Rectangle( aPos
, mpWindow
->GetOutputSizePixel() ).Center() );
754 aPos
.AdjustX( -(aSize
.Width() >> 1) );
755 aPos
.AdjustY( -(aSize
.Height() >> 1) );
758 mpView
->InsertMediaURL(rURL
, nAction
, aPos
, aSize
, bLink
);
761 mpWindow
->LeaveWait();
765 } // end of namespace sd
767 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */