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 <editeng/outlobj.hxx>
25 #include <toolkit/helper/vclunohelper.hxx>
26 #include <svx/svxdlg.hxx>
27 #include <com/sun/star/embed/EmbedVerbs.hpp>
28 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
29 #include <com/sun/star/embed/Aspects.hpp>
30 #include <com/sun/star/embed/XEmbeddedObject.hpp>
31 #include <com/sun/star/chart2/XChartDocument.hpp>
33 #include <svl/stritem.hxx>
34 #include <sfx2/docfile.hxx>
35 #include <sfx2/msgpool.hxx>
36 #include <sfx2/msg.hxx>
37 #include <svtools/insdlg.hxx>
38 #include <sfx2/request.hxx>
39 #include <svl/globalnameitem.hxx>
40 #include <svtools/miscopt.hxx>
41 #include <svtools/embedhlp.hxx>
42 #include <svx/linkwarn.hxx>
43 #include <avmedia/mediawindow.hxx>
44 #include <comphelper/classids.hxx>
45 #include <svtools/sfxecode.hxx>
46 #include <vcl/transfer.hxx>
47 #include <svl/urlbmk.hxx>
48 #include <svx/svdobj.hxx>
49 #include <svx/svdograf.hxx>
50 #include <svx/svdoole2.hxx>
51 #include <sot/formats.hxx>
52 #include <svx/svdpagv.hxx>
53 #include <sfx2/opengrf.hxx>
54 #include <sfx2/viewfrm.hxx>
55 #include <svx/charthelper.hxx>
56 #include <svx/svxids.hrc>
58 #include <sdresid.hxx>
62 #include <DrawViewShell.hxx>
63 #include <DrawDocShell.hxx>
64 #include <GraphicDocShell.hxx>
65 #include <strings.hrc>
66 #include <drawdoc.hxx>
68 #include <sdgrffilter.hxx>
69 #include <vcl/svapp.hxx>
71 #include <vcl/weld.hxx>
72 #include <vcl/errinf.hxx>
73 #include <vcl/graphicfilter.hxx>
75 #include <vcl/GraphicNativeTransform.hxx>
76 #include <vcl/GraphicNativeMetadata.hxx>
78 #include <comphelper/lok.hxx>
80 using namespace com::sun::star
;
85 FuInsertGraphic::FuInsertGraphic (
91 bool replaceExistingImage
)
92 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
),
93 mbReplaceExistingImage(replaceExistingImage
)
97 rtl::Reference
<FuPoor
> FuInsertGraphic::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
,
98 SdDrawDocument
* pDoc
, SfxRequest
& rReq
, bool replaceExistingImage
)
100 rtl::Reference
<FuPoor
> xFunc( new FuInsertGraphic( pViewSh
, pWin
, pView
, pDoc
, rReq
, replaceExistingImage
) );
101 xFunc
->DoExecute(rReq
);
105 void FuInsertGraphic::DoExecute( SfxRequest
& rReq
)
108 OUString aFilterName
;
111 bool bAsLink
= false;
112 ErrCode nError
= ERRCODE_GRFILTER_OPENERROR
;
114 const SfxItemSet
* pArgs
= rReq
.GetArgs();
115 const SfxPoolItem
* pItem
;
118 pArgs
->GetItemState( SID_INSERT_GRAPHIC
, true, &pItem
) == SfxItemState::SET
)
120 aFileName
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
122 if ( pArgs
->GetItemState( FN_PARAM_FILTER
, true, &pItem
) == SfxItemState::SET
)
123 aFilterName
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
125 if ( pArgs
->GetItemState( FN_PARAM_1
, true, &pItem
) == SfxItemState::SET
)
126 bAsLink
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
128 nError
= GraphicFilter::LoadGraphic( aFileName
, aFilterName
, aGraphic
, &GraphicFilter::GetGraphicFilter() );
132 SvxOpenGraphicDialog
aDlg(SdResId(STR_INSERTGRAPHIC
), mpWindow
? mpWindow
->GetFrameWeld() : nullptr);
134 if( aDlg
.Execute() != ERRCODE_NONE
)
135 return; // cancel dialog
137 nError
= aDlg
.GetGraphic(aGraphic
);
138 bAsLink
= aDlg
.IsAsLink();
139 aFileName
= aDlg
.GetPath();
140 aFilterName
= aDlg
.GetDetectedFilter();
143 if( nError
== ERRCODE_NONE
)
145 GraphicNativeMetadata aMetadata
;
146 if ( aMetadata
.read(aGraphic
) )
148 const sal_uInt16 aRotation
= aMetadata
.getRotation();
151 std::unique_ptr
<weld::MessageDialog
> xQueryBox(Application::CreateMessageDialog(nullptr, VclMessageType::Question
,VclButtonsType::YesNo
,SdResId(STR_QUERYROTATION
)));
152 if (xQueryBox
->run() == RET_YES
)
154 GraphicNativeTransform
aTransform( aGraphic
);
155 aTransform
.rotate( aRotation
);
159 if( dynamic_cast< DrawViewShell
*>( mpViewShell
) )
161 sal_Int8 nAction
= DND_ACTION_COPY
;
164 if( ( ( pPickObj
= mpView
->GetSelectedSingleObject( mpView
->GetPage() ) ) && mbReplaceExistingImage
) || (pPickObj
= mpView
->GetEmptyPresentationObject( PRESOBJ_GRAPHIC
) ) )
166 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( SvtMiscOptions().ShowLinkWarningDialog() )
179 SvxLinkWarningDialog
aWarnDlg(mpWindow
->GetFrameWeld(), aFileName
);
180 if (aWarnDlg
.run() != RET_OK
)
181 return; // don't store as link
186 if (mpDocSh
->HasName()) {
187 aReferer
= mpDocSh
->GetMedium()->GetName();
189 pGrafObj
->SetGraphicLink(aFileName
, aReferer
, aFilterName
);
195 SdGRFFilter::HandleGraphicFilterError( nError
, GraphicFilter::GetGraphicFilter().GetLastError().nStreamError
);
199 FuInsertClipboard::FuInsertClipboard (
203 SdDrawDocument
* pDoc
,
205 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
209 rtl::Reference
<FuPoor
> FuInsertClipboard::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
211 rtl::Reference
<FuPoor
> xFunc( new FuInsertClipboard( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
212 xFunc
->DoExecute(rReq
);
216 void FuInsertClipboard::DoExecute( SfxRequest
& )
218 TransferableDataHelper
aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpWindow
) );
219 SotClipboardFormatId nFormatId
;
221 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
222 ScopedVclPtr
<SfxAbstractPasteDialog
> pDlg(pFact
->CreatePasteDialog(mpViewShell
->GetFrameWeld()));
223 pDlg
->Insert( SotClipboardFormatId::EMBED_SOURCE
, OUString() );
224 pDlg
->Insert( SotClipboardFormatId::LINK_SOURCE
, OUString() );
225 pDlg
->Insert( SotClipboardFormatId::DRAWING
, OUString() );
226 pDlg
->Insert( SotClipboardFormatId::SVXB
, OUString() );
227 pDlg
->Insert( SotClipboardFormatId::GDIMETAFILE
, OUString() );
228 pDlg
->Insert( SotClipboardFormatId::BITMAP
, OUString() );
229 pDlg
->Insert( SotClipboardFormatId::NETSCAPE_BOOKMARK
, OUString() );
230 pDlg
->Insert( SotClipboardFormatId::STRING
, OUString() );
231 pDlg
->Insert( SotClipboardFormatId::HTML
, OUString() );
232 pDlg
->Insert( SotClipboardFormatId::RTF
, OUString() );
233 pDlg
->Insert( SotClipboardFormatId::RICHTEXT
, OUString() );
234 pDlg
->Insert( SotClipboardFormatId::EDITENGINE_ODF_TEXT_FLAT
, OUString() );
237 nFormatId
= pDlg
->GetFormat( aDataHelper
);
238 if( nFormatId
== SotClipboardFormatId::NONE
|| !aDataHelper
.GetTransferable().is() )
241 sal_Int8 nAction
= DND_ACTION_COPY
;
242 DrawViewShell
* pDrViewSh
= nullptr;
244 if (!mpView
->InsertData( aDataHelper
,
245 mpWindow
->PixelToLogic( ::tools::Rectangle( Point(), mpWindow
->GetOutputSizePixel() ).Center() ),
246 nAction
, false, nFormatId
))
248 pDrViewSh
= dynamic_cast<DrawViewShell
*>(mpViewShell
);
254 INetBookmark
aINetBookmark( "", "" );
256 if( ( aDataHelper
.HasFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK
) &&
257 aDataHelper
.GetINetBookmark( SotClipboardFormatId::NETSCAPE_BOOKMARK
, aINetBookmark
) ) ||
258 ( aDataHelper
.HasFormat( SotClipboardFormatId::FILEGRPDESCRIPTOR
) &&
259 aDataHelper
.GetINetBookmark( SotClipboardFormatId::FILEGRPDESCRIPTOR
, aINetBookmark
) ) ||
260 ( aDataHelper
.HasFormat( SotClipboardFormatId::UNIFORMRESOURCELOCATOR
) &&
261 aDataHelper
.GetINetBookmark( SotClipboardFormatId::UNIFORMRESOURCELOCATOR
, aINetBookmark
) ) )
263 pDrViewSh
->InsertURLField( aINetBookmark
.GetURL(), aINetBookmark
.GetDescription(), "" );
267 FuInsertOLE::FuInsertOLE (
271 SdDrawDocument
* pDoc
,
273 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
277 rtl::Reference
<FuPoor
> FuInsertOLE::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
279 rtl::Reference
<FuPoor
> xFunc( new FuInsertOLE( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
280 xFunc
->DoExecute(rReq
);
284 void FuInsertOLE::DoExecute( SfxRequest
& rReq
)
286 if ( nSlotId
== SID_ATTR_TABLE
||
287 nSlotId
== SID_INSERT_DIAGRAM
||
288 nSlotId
== SID_INSERT_MATH
)
290 PresObjKind ePresObjKind
= (nSlotId
== SID_INSERT_DIAGRAM
) ? PRESOBJ_CHART
: PRESOBJ_OBJECT
;
292 SdrObject
* pPickObj
= mpView
->GetEmptyPresentationObject( ePresObjKind
);
294 // insert diagram or Calc table
297 if (nSlotId
== SID_INSERT_DIAGRAM
)
298 aName
= SvGlobalName( SO3_SCH_CLASSID
);
299 else if (nSlotId
== SID_ATTR_TABLE
)
300 aName
= SvGlobalName(SO3_SC_CLASSID
);
301 else if (nSlotId
== SID_INSERT_MATH
)
302 aName
= SvGlobalName(SO3_SM_CLASSID
);
304 uno::Reference
< embed::XEmbeddedObject
> xObj
= mpViewShell
->GetViewFrame()->GetObjectShell()->
305 GetEmbeddedObjectContainer().CreateEmbeddedObject( aName
.GetByteSequence(), aObjName
);
308 // Create default chart type.
309 uno::Reference
<chart2::XChartDocument
> xChartDoc(xObj
->getComponent(), uno::UNO_QUERY
);
311 xChartDoc
->createDefaultChart();
313 sal_Int64 nAspect
= embed::Aspects::MSOLE_CONTENT
;
315 MapUnit aUnit
= VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj
->getMapUnit( nAspect
) );
317 ::tools::Rectangle aRect
;
320 aRect
= pPickObj
->GetLogicRect();
323 aSz
.Width
= aRect
.GetWidth();
324 aSz
.Height
= aRect
.GetHeight();
325 xObj
->setVisualAreaSize( nAspect
, aSz
);
332 aSz
= xObj
->getVisualAreaSize( nAspect
);
334 catch ( embed::NoVisualAreaSizeException
& )
336 // the default size will be set later
339 Size
aSize( aSz
.Width
, aSz
.Height
);
341 if (aSize
.Height() == 0 || aSize
.Width() == 0)
343 // rectangle with balanced edge ratio
344 aSize
.setWidth( 14100 );
345 aSize
.setHeight( 10000 );
346 Size aTmp
= OutputDevice::LogicToLogic(aSize
, MapMode(MapUnit::Map100thMM
), MapMode(aUnit
));
347 aSz
.Width
= aTmp
.Width();
348 aSz
.Height
= aTmp
.Height();
349 xObj
->setVisualAreaSize( nAspect
, aSz
);
353 aSize
= OutputDevice::LogicToLogic(aSize
, MapMode(aUnit
), MapMode(MapUnit::Map100thMM
));
356 Point aPos
= mpWindow
->GetVisibleCenter();
357 aPos
.AdjustX( -(aSize
.Width() / 2) );
358 aPos
.AdjustY( -(aSize
.Height() / 2) );
359 aRect
= ::tools::Rectangle(aPos
, aSize
);
362 SdrOle2Obj
* pOleObj
= new SdrOle2Obj(
363 mpView
->getSdrModelFromSdrView(),
364 svt::EmbeddedObjectRef( xObj
, nAspect
),
367 SdrPageView
* pPV
= mpView
->GetSdrPageView();
369 // if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj
372 SdPage
* pPage
= static_cast< SdPage
* >(pPickObj
->getSdrPageFromSdrObject());
373 if(pPage
&& pPage
->IsPresObj(pPickObj
))
375 pPage
->InsertPresObj( pOleObj
, ePresObjKind
);
376 pOleObj
->SetUserCall(pPickObj
->GetUserCall());
379 // #i123468# we need to end text edit before replacing the object. There cannot yet
380 // being text typed (else it would not be an EmptyPresObj anymore), but it may be
382 if (mpView
->IsTextEdit())
384 mpView
->SdrEndTextEdit();
390 mpView
->ReplaceObjectAtView(pPickObj
, *pPV
, pOleObj
);
392 bRet
= mpView
->InsertObjectAtView(pOleObj
, *pPV
, SdrInsertFlags::SETDEFLAYER
);
394 if (bRet
&& !comphelper::LibreOfficeKit::isActive())
396 // Let the chart be activated after the inserting (unless
397 // via LibreOfficeKit)
398 if (nSlotId
== SID_INSERT_DIAGRAM
)
400 pOleObj
->SetProgName( "StarChart");
402 else if (nSlotId
== SID_ATTR_TABLE
)
404 pOleObj
->SetProgName( "StarCalc" );
406 else if (nSlotId
== SID_INSERT_MATH
)
408 pOleObj
->SetProgName( "StarMath" );
411 pOleObj
->SetLogicRect(aRect
);
412 Size
aTmp( OutputDevice::LogicToLogic(aRect
.GetSize(), MapMode(MapUnit::Map100thMM
), MapMode(aUnit
)) );
413 awt::Size aVisualSize
;
414 aVisualSize
.Width
= aTmp
.Width();
415 aVisualSize
.Height
= aTmp
.Height();
416 xObj
->setVisualAreaSize( nAspect
, aVisualSize
);
417 mpViewShell
->ActivateObject(pOleObj
, embed::EmbedVerbs::MS_OLEVERB_SHOW
);
419 if (nSlotId
== SID_INSERT_DIAGRAM
)
421 // note, that this call modified the chart model which
422 // results in a change notification. So call this after
423 // everything else is finished.
424 ChartHelper::AdaptDefaultsForChart( xObj
);
430 ErrorHandler::HandleError(* new StringErrorInfo(ERRCODE_SFX_OLEGENERAL
,
437 sal_Int64 nAspect
= embed::Aspects::MSOLE_CONTENT
;
438 bool bCreateNew
= false;
439 uno::Reference
< embed::XEmbeddedObject
> xObj
;
440 uno::Reference
< embed::XStorage
> xStorage
= comphelper::OStorageHelper::GetTemporaryStorage();
441 SvObjectServerList aServerLst
;
444 OUString aIconMediaType
;
445 uno::Reference
< io::XInputStream
> xIconMetaFile
;
447 const SfxGlobalNameItem
* pNameItem
= rReq
.GetArg
<SfxGlobalNameItem
>(SID_INSERT_OBJECT
);
448 if ( nSlotId
== SID_INSERT_OBJECT
&& pNameItem
)
450 const SvGlobalName
& aClassName
= pNameItem
->GetValue();
451 xObj
= mpViewShell
->GetViewFrame()->GetObjectShell()->
452 GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName
.GetByteSequence(), aName
);
458 case SID_INSERT_OBJECT
:
460 aServerLst
.FillInsertObjects();
461 if (mpDoc
->GetDocumentType() == DocumentType::Draw
)
463 aServerLst
.Remove( GraphicDocShell::Factory().GetClassId() );
467 aServerLst
.Remove( DrawDocShell::Factory().GetClassId() );
472 case SID_INSERT_FLOATINGFRAME
:
474 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
475 ScopedVclPtr
<SfxAbstractInsertObjectDialog
> pDlg(
476 pFact
->CreateInsertObjectDialog( mpViewShell
->GetFrameWeld(), SD_MOD()->GetSlotPool()->GetSlot(nSlotId
)->GetCommandString(),
477 xStorage
, &aServerLst
));
479 bCreateNew
= pDlg
->IsCreateNew();
480 xObj
= pDlg
->GetObject();
482 xIconMetaFile
= pDlg
->GetIconIfIconified( &aIconMediaType
);
483 if ( xIconMetaFile
.is() )
484 nAspect
= embed::Aspects::MSOLE_ICON
;
487 mpViewShell
->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj
, aName
);
498 bool bInsertNewObject
= true;
501 MapUnit aMapUnit
= MapUnit::Map100thMM
;
502 if ( nAspect
!= embed::Aspects::MSOLE_ICON
)
507 aSz
= xObj
->getVisualAreaSize( nAspect
);
509 catch( embed::NoVisualAreaSizeException
& )
511 // the default size will be set later
514 aSize
=Size( aSz
.Width
, aSz
.Height
);
516 aMapUnit
= VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj
->getMapUnit( nAspect
) );
517 if (aSize
.Height() == 0 || aSize
.Width() == 0)
519 // rectangle with balanced edge ratio
520 aSize
.setWidth( 14100 );
521 aSize
.setHeight( 10000 );
522 Size aTmp
= OutputDevice::LogicToLogic(aSize
, MapMode(MapUnit::Map100thMM
), MapMode(aMapUnit
));
523 aSz
.Width
= aTmp
.Width();
524 aSz
.Height
= aTmp
.Height();
525 xObj
->setVisualAreaSize( nAspect
, aSz
);
529 aSize
= OutputDevice::LogicToLogic(aSize
, MapMode(aMapUnit
), MapMode(MapUnit::Map100thMM
));
533 if ( mpView
->AreObjectsMarked() )
535 // as an empty OLE object available?
536 const SdrMarkList
& rMarkList
= mpView
->GetMarkedObjectList();
538 if (rMarkList
.GetMarkCount() == 1)
540 SdrMark
* pMark
= rMarkList
.GetMark(0);
541 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
543 if (pObj
->GetObjInventor() == SdrInventor::Default
&&
544 pObj
->GetObjIdentifier() == OBJ_OLE2
)
546 if ( !static_cast<SdrOle2Obj
*>(pObj
)->GetObjRef().is() )
548 // the empty OLE object gets a new IPObj
549 bInsertNewObject
= false;
550 pObj
->SetEmptyPresObj(false);
551 static_cast<SdrOle2Obj
*>(pObj
)->SetOutlinerParaObject(nullptr);
552 static_cast<SdrOle2Obj
*>(pObj
)->SetObjRef(xObj
);
553 static_cast<SdrOle2Obj
*>(pObj
)->SetPersistName(aName
);
554 static_cast<SdrOle2Obj
*>(pObj
)->SetName(aName
);
555 static_cast<SdrOle2Obj
*>(pObj
)->SetAspect(nAspect
);
556 ::tools::Rectangle aRect
= static_cast<SdrOle2Obj
*>(pObj
)->GetLogicRect();
558 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
560 if( xIconMetaFile
.is() )
561 static_cast<SdrOle2Obj
*>(pObj
)->SetGraphicToObj( xIconMetaFile
, aIconMediaType
);
565 Size aTmp
= OutputDevice::LogicToLogic(aRect
.GetSize(), MapMode(MapUnit::Map100thMM
), MapMode(aMapUnit
));
566 awt::Size
aSz( aTmp
.Width(), aTmp
.Height() );
567 xObj
->setVisualAreaSize( nAspect
, aSz
);
574 if (bInsertNewObject
)
576 // we create a new OLE object
577 SdrPageView
* pPV
= mpView
->GetSdrPageView();
578 Size aPageSize
= pPV
->GetPage()->GetSize();
580 // get the size from the iconified object
581 ::svt::EmbeddedObjectRef
aObjRef( xObj
, nAspect
);
582 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
584 aObjRef
.SetGraphicStream( xIconMetaFile
, aIconMediaType
);
585 MapMode
aMapMode( MapUnit::Map100thMM
);
586 aSize
= aObjRef
.GetSize( &aMapMode
);
589 Point
aPnt ((aPageSize
.Width() - aSize
.Width()) / 2,
590 (aPageSize
.Height() - aSize
.Height()) / 2);
591 ::tools::Rectangle
aRect (aPnt
, aSize
);
592 SdrOle2Obj
* pObj
= new SdrOle2Obj(
593 mpView
->getSdrModelFromSdrView(),
598 if( mpView
->InsertObjectAtView(pObj
, *pPV
, SdrInsertFlags::SETDEFLAYER
) )
600 // Math objects change their object size during InsertObject.
601 // New size must be set in SdrObject, or a wrong scale will be set at
604 if ( nAspect
!= embed::Aspects::MSOLE_ICON
)
608 awt::Size aSz
= xObj
->getVisualAreaSize( nAspect
);
610 Size aNewSize
= Window::LogicToLogic( Size( aSz
.Width
, aSz
.Height
),
611 MapMode( aMapUnit
), MapMode( MapUnit::Map100thMM
) );
612 if ( aNewSize
!= aSize
)
614 aRect
.SetSize( aNewSize
);
615 pObj
->SetLogicRect( aRect
);
618 catch( embed::NoVisualAreaSizeException
& )
624 pObj
->SetLogicRect(aRect
);
626 if ( nAspect
!= embed::Aspects::MSOLE_ICON
)
628 Size aTmp
= OutputDevice::LogicToLogic(aRect
.GetSize(), MapMode(MapUnit::Map100thMM
), MapMode(aMapUnit
));
629 awt::Size
aSz( aTmp
.Width(), aTmp
.Height() );
630 xObj
->setVisualAreaSize( nAspect
, aSz
);
633 mpViewShell
->ActivateObject(pObj
, embed::EmbedVerbs::MS_OLEVERB_SHOW
);
636 Size aVisSizePixel
= mpWindow
->GetOutputSizePixel();
637 ::tools::Rectangle aVisAreaWin
= mpWindow
->PixelToLogic( ::tools::Rectangle( Point(0,0), aVisSizePixel
) );
638 mpViewShell
->VisAreaChanged(aVisAreaWin
);
639 mpDocSh
->SetVisArea(aVisAreaWin
);
644 catch (uno::Exception
&)
646 // For some reason the object can not be inserted. For example
647 // because it is password protected and is not properly unlocked.
652 FuInsertAVMedia::FuInsertAVMedia(
656 SdDrawDocument
* pDoc
,
658 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
662 rtl::Reference
<FuPoor
> FuInsertAVMedia::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
664 rtl::Reference
<FuPoor
> xFunc( new FuInsertAVMedia( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
665 xFunc
->DoExecute(rReq
);
669 void FuInsertAVMedia::DoExecute( SfxRequest
& rReq
)
671 #if HAVE_FEATURE_AVMEDIA
673 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
678 const SfxStringItem
* pStringItem
= dynamic_cast<const SfxStringItem
*>( &pReqArgs
->Get( rReq
.GetSlot() ) );
682 aURL
= pStringItem
->GetValue();
683 bAPI
= !aURL
.isEmpty();
689 || ::avmedia::MediaWindow::executeMediaURLDialog(mpWindow
? mpWindow
->GetFrameWeld() : nullptr, aURL
, & bLink
)
696 mpWindow
->EnterWait();
698 if( !::avmedia::MediaWindow::isMediaURL( aURL
, "", true, &aPrefSize
) )
701 mpWindow
->LeaveWait();
704 ::avmedia::MediaWindow::executeFormatErrorBox(mpWindow
->GetFrameWeld());
710 sal_Int8 nAction
= DND_ACTION_COPY
;
712 if( aPrefSize
.Width() && aPrefSize
.Height() )
715 aSize
= mpWindow
->PixelToLogic(aPrefSize
, MapMode(MapUnit::Map100thMM
));
717 aSize
= Application::GetDefaultDevice()->PixelToLogic(aPrefSize
, MapMode(MapUnit::Map100thMM
));
720 aSize
= Size( 5000, 5000 );
724 aPos
= mpWindow
->PixelToLogic( ::tools::Rectangle( aPos
, mpWindow
->GetOutputSizePixel() ).Center() );
725 aPos
.AdjustX( -(aSize
.Width() >> 1) );
726 aPos
.AdjustY( -(aSize
.Height() >> 1) );
729 mpView
->InsertMediaURL( aURL
, nAction
, aPos
, aSize
, bLink
) ;
732 mpWindow
->LeaveWait();
739 } // end of namespace sd
741 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */