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 <toolkit/helper/vclunohelper.hxx>
25 #include <svx/svxdlg.hxx>
26 #include <com/sun/star/embed/EmbedVerbs.hpp>
27 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
28 #include <com/sun/star/embed/XComponentSupplier.hpp>
29 #include <com/sun/star/embed/Aspects.hpp>
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <com/sun/star/chart2/XChartDocument.hpp>
32 #include <com/sun/star/drawing/FillStyle.hpp>
33 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
35 #include <tools/urlobj.hxx>
36 #include <svl/urihelper.hxx>
37 #include <sfx2/docfile.hxx>
38 #include <sfx2/msgpool.hxx>
39 #include <sfx2/filedlghelper.hxx>
40 #include <svtools/insdlg.hxx>
41 #include <sfx2/request.hxx>
42 #include <svl/globalnameitem.hxx>
43 #include <unotools/pathoptions.hxx>
44 #include <svtools/miscopt.hxx>
45 #include <svtools/embedhlp.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 <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 <sfx2/opengrf.hxx>
65 #include <sfx2/viewfrm.hxx>
66 #include <svx/charthelper.hxx>
69 #include <sdresid.hxx>
73 #include <drawview.hxx>
74 #include <DrawViewShell.hxx>
75 #include <DrawDocShell.hxx>
76 #include <GraphicDocShell.hxx>
77 #include <strings.hrc>
78 #include <drawdoc.hxx>
79 #include <sdgrffilter.hxx>
81 #include <vcl/svapp.hxx>
82 #include <undo/undoobjects.hxx>
84 #include <vcl/weld.hxx>
86 #include <vcl/GraphicNativeTransform.hxx>
87 #include <vcl/GraphicNativeMetadata.hxx>
89 using namespace com::sun::star
;
94 FuInsertGraphic::FuInsertGraphic (
100 bool replaceExistingImage
)
101 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
),
102 mbReplaceExistingImage(replaceExistingImage
)
106 rtl::Reference
<FuPoor
> FuInsertGraphic::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
,
107 SdDrawDocument
* pDoc
, SfxRequest
& rReq
, bool replaceExistingImage
)
109 rtl::Reference
<FuPoor
> xFunc( new FuInsertGraphic( pViewSh
, pWin
, pView
, pDoc
, rReq
, replaceExistingImage
) );
110 xFunc
->DoExecute(rReq
);
114 void FuInsertGraphic::DoExecute( SfxRequest
& rReq
)
117 OUString aFilterName
;
120 bool bAsLink
= false;
121 ErrCode nError
= ERRCODE_GRFILTER_OPENERROR
;
123 const SfxItemSet
* pArgs
= rReq
.GetArgs();
124 const SfxPoolItem
* pItem
;
127 pArgs
->GetItemState( SID_INSERT_GRAPHIC
, true, &pItem
) == SfxItemState::SET
)
129 aFileName
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
131 if ( pArgs
->GetItemState( FN_PARAM_FILTER
, true, &pItem
) == SfxItemState::SET
)
132 aFilterName
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
134 if ( pArgs
->GetItemState( FN_PARAM_1
, true, &pItem
) == SfxItemState::SET
)
135 bAsLink
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
137 nError
= GraphicFilter::LoadGraphic( aFileName
, aFilterName
, aGraphic
, &GraphicFilter::GetGraphicFilter() );
141 SvxOpenGraphicDialog
aDlg(SdResId(STR_INSERTGRAPHIC
), mpWindow
? mpWindow
->GetFrameWeld() : nullptr);
143 if( aDlg
.Execute() != ERRCODE_NONE
)
144 return; // cancel dialog
146 nError
= aDlg
.GetGraphic(aGraphic
);
147 bAsLink
= aDlg
.IsAsLink();
148 aFileName
= aDlg
.GetPath();
149 aFilterName
= aDlg
.GetDetectedFilter();
152 if( nError
== ERRCODE_NONE
)
154 GraphicNativeMetadata aMetadata
;
155 if ( aMetadata
.read(aGraphic
) )
157 const sal_uInt16 aRotation
= aMetadata
.getRotation();
160 std::unique_ptr
<weld::MessageDialog
> xQueryBox(Application::CreateMessageDialog(nullptr, VclMessageType::Question
,VclButtonsType::YesNo
,SdResId(STR_QUERYROTATION
)));
161 if (xQueryBox
->run() == RET_YES
)
163 GraphicNativeTransform
aTransform( aGraphic
);
164 aTransform
.rotate( aRotation
);
168 if( mpViewShell
&& dynamic_cast< DrawViewShell
*>( mpViewShell
) != nullptr)
170 sal_Int8 nAction
= DND_ACTION_COPY
;
173 if( ( ( pPickObj
= mpView
->GetSelectedSingleObject( mpView
->GetPage() ) ) && mbReplaceExistingImage
) || (pPickObj
= mpView
->GetEmptyPresentationObject( PRESOBJ_GRAPHIC
) ) )
175 nAction
= DND_ACTION_LINK
;
180 Point aPos
= mpWindow
->GetVisibleCenter();
181 SdrGrafObj
* pGrafObj
= mpView
->InsertGraphic(aGraphic
, nAction
, aPos
, pPickObj
, nullptr);
183 if(pGrafObj
&& bAsLink
)
185 // really store as link only?
186 if( SvtMiscOptions().ShowLinkWarningDialog() )
188 SvxLinkWarningDialog
aWarnDlg(mpWindow
->GetFrameWeld(), aFileName
);
189 if (aWarnDlg
.run() != RET_OK
)
190 return; // don't store as link
195 if (mpDocSh
->HasName()) {
196 aReferer
= mpDocSh
->GetMedium()->GetName();
198 pGrafObj
->SetGraphicLink(aFileName
, aReferer
, aFilterName
);
204 SdGRFFilter::HandleGraphicFilterError( nError
, GraphicFilter::GetGraphicFilter().GetLastError().nStreamError
);
208 FuInsertClipboard::FuInsertClipboard (
212 SdDrawDocument
* pDoc
,
214 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
218 rtl::Reference
<FuPoor
> FuInsertClipboard::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
220 rtl::Reference
<FuPoor
> xFunc( new FuInsertClipboard( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
221 xFunc
->DoExecute(rReq
);
225 void FuInsertClipboard::DoExecute( SfxRequest
& )
227 TransferableDataHelper
aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpWindow
) );
228 SotClipboardFormatId nFormatId
;
230 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
231 ScopedVclPtr
<SfxAbstractPasteDialog
> pDlg(pFact
->CreatePasteDialog(mpViewShell
->GetFrameWeld()));
234 pDlg
->Insert( SotClipboardFormatId::EMBED_SOURCE
, OUString() );
235 pDlg
->Insert( SotClipboardFormatId::LINK_SOURCE
, OUString() );
236 pDlg
->Insert( SotClipboardFormatId::DRAWING
, OUString() );
237 pDlg
->Insert( SotClipboardFormatId::SVXB
, OUString() );
238 pDlg
->Insert( SotClipboardFormatId::GDIMETAFILE
, OUString() );
239 pDlg
->Insert( SotClipboardFormatId::BITMAP
, OUString() );
240 pDlg
->Insert( SotClipboardFormatId::NETSCAPE_BOOKMARK
, OUString() );
241 pDlg
->Insert( SotClipboardFormatId::STRING
, OUString() );
242 pDlg
->Insert( SotClipboardFormatId::HTML
, OUString() );
243 pDlg
->Insert( SotClipboardFormatId::RTF
, OUString() );
244 pDlg
->Insert( SotClipboardFormatId::RICHTEXT
, OUString() );
245 pDlg
->Insert( SotClipboardFormatId::EDITENGINE_ODF_TEXT_FLAT
, OUString() );
248 nFormatId
= pDlg
->GetFormat( aDataHelper
);
249 if( nFormatId
!= SotClipboardFormatId::NONE
&& aDataHelper
.GetTransferable().is() )
251 sal_Int8 nAction
= DND_ACTION_COPY
;
252 DrawViewShell
* pDrViewSh
= nullptr;
254 if (!mpView
->InsertData( aDataHelper
,
255 mpWindow
->PixelToLogic( ::tools::Rectangle( Point(), mpWindow
->GetOutputSizePixel() ).Center() ),
256 nAction
, false, nFormatId
))
258 pDrViewSh
= dynamic_cast<DrawViewShell
*>(mpViewShell
);
263 INetBookmark
aINetBookmark( "", "" );
265 if( ( aDataHelper
.HasFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK
) &&
266 aDataHelper
.GetINetBookmark( SotClipboardFormatId::NETSCAPE_BOOKMARK
, aINetBookmark
) ) ||
267 ( aDataHelper
.HasFormat( SotClipboardFormatId::FILEGRPDESCRIPTOR
) &&
268 aDataHelper
.GetINetBookmark( SotClipboardFormatId::FILEGRPDESCRIPTOR
, aINetBookmark
) ) ||
269 ( aDataHelper
.HasFormat( SotClipboardFormatId::UNIFORMRESOURCELOCATOR
) &&
270 aDataHelper
.GetINetBookmark( SotClipboardFormatId::UNIFORMRESOURCELOCATOR
, aINetBookmark
) ) )
272 pDrViewSh
->InsertURLField( aINetBookmark
.GetURL(), aINetBookmark
.GetDescription(), "" );
279 FuInsertOLE::FuInsertOLE (
283 SdDrawDocument
* pDoc
,
285 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
289 rtl::Reference
<FuPoor
> FuInsertOLE::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
291 rtl::Reference
<FuPoor
> xFunc( new FuInsertOLE( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
292 xFunc
->DoExecute(rReq
);
296 void FuInsertOLE::DoExecute( SfxRequest
& rReq
)
298 if ( nSlotId
== SID_ATTR_TABLE
||
299 nSlotId
== SID_INSERT_DIAGRAM
||
300 nSlotId
== SID_INSERT_MATH
)
302 PresObjKind ePresObjKind
= (nSlotId
== SID_INSERT_DIAGRAM
) ? PRESOBJ_CHART
: PRESOBJ_OBJECT
;
304 SdrObject
* pPickObj
= mpView
->GetEmptyPresentationObject( ePresObjKind
);
306 // insert diagram or Calc table
309 if (nSlotId
== SID_INSERT_DIAGRAM
)
310 aName
= SvGlobalName( SO3_SCH_CLASSID
);
311 else if (nSlotId
== SID_ATTR_TABLE
)
312 aName
= SvGlobalName(SO3_SC_CLASSID
);
313 else if (nSlotId
== SID_INSERT_MATH
)
314 aName
= SvGlobalName(SO3_SM_CLASSID
);
316 uno::Reference
< embed::XEmbeddedObject
> xObj
= mpViewShell
->GetViewFrame()->GetObjectShell()->
317 GetEmbeddedObjectContainer().CreateEmbeddedObject( aName
.GetByteSequence(), aObjName
);
320 uno::Reference
<embed::XComponentSupplier
> xCompSupp(xObj
, uno::UNO_QUERY
);
323 // Create default chart type.
324 uno::Reference
<chart2::XChartDocument
> xChartDoc(xCompSupp
->getComponent(), uno::UNO_QUERY
);
326 xChartDoc
->createDefaultChart();
329 sal_Int64 nAspect
= embed::Aspects::MSOLE_CONTENT
;
331 MapUnit aUnit
= VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj
->getMapUnit( nAspect
) );
333 ::tools::Rectangle aRect
;
336 aRect
= pPickObj
->GetLogicRect();
339 aSz
.Width
= aRect
.GetWidth();
340 aSz
.Height
= aRect
.GetHeight();
341 xObj
->setVisualAreaSize( nAspect
, aSz
);
348 aSz
= xObj
->getVisualAreaSize( nAspect
);
350 catch ( embed::NoVisualAreaSizeException
& )
352 // the default size will be set later
355 Size
aSize( aSz
.Width
, aSz
.Height
);
357 if (aSize
.Height() == 0 || aSize
.Width() == 0)
359 // rectangle with balanced edge ratio
360 aSize
.setWidth( 14100 );
361 aSize
.setHeight( 10000 );
362 Size aTmp
= OutputDevice::LogicToLogic(aSize
, MapMode(MapUnit::Map100thMM
), MapMode(aUnit
));
363 aSz
.Width
= aTmp
.Width();
364 aSz
.Height
= aTmp
.Height();
365 xObj
->setVisualAreaSize( nAspect
, aSz
);
369 aSize
= OutputDevice::LogicToLogic(aSize
, MapMode(aUnit
), MapMode(MapUnit::Map100thMM
));
372 Point aPos
= mpWindow
->GetVisibleCenter();
373 aPos
.AdjustX( -(aSize
.Width() / 2) );
374 aPos
.AdjustY( -(aSize
.Height() / 2) );
375 aRect
= ::tools::Rectangle(aPos
, aSize
);
378 SdrOle2Obj
* pOleObj
= new SdrOle2Obj(
379 mpView
->getSdrModelFromSdrView(),
380 svt::EmbeddedObjectRef( xObj
, nAspect
),
383 SdrPageView
* pPV
= mpView
->GetSdrPageView();
385 // if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj
388 SdPage
* pPage
= static_cast< SdPage
* >(pPickObj
->GetPage());
389 if(pPage
&& pPage
->IsPresObj(pPickObj
))
391 pPage
->InsertPresObj( pOleObj
, ePresObjKind
);
392 pOleObj
->SetUserCall(pPickObj
->GetUserCall());
395 // #i123468# we need to end text edit before replacing the object. There cannot yet
396 // being text typed (else it would not be an EmptyPresObj anymore), but it may be
398 if (mpView
->IsTextEdit())
400 mpView
->SdrEndTextEdit();
406 mpView
->ReplaceObjectAtView(pPickObj
, *pPV
, pOleObj
);
408 bRet
= mpView
->InsertObjectAtView(pOleObj
, *pPV
, SdrInsertFlags::SETDEFLAYER
);
412 if (nSlotId
== SID_INSERT_DIAGRAM
)
414 pOleObj
->SetProgName( "StarChart");
416 else if (nSlotId
== SID_ATTR_TABLE
)
418 pOleObj
->SetProgName( "StarCalc" );
420 else if (nSlotId
== SID_INSERT_MATH
)
422 pOleObj
->SetProgName( "StarMath" );
425 pOleObj
->SetLogicRect(aRect
);
426 Size
aTmp( OutputDevice::LogicToLogic(aRect
.GetSize(), MapMode(MapUnit::Map100thMM
), MapMode(aUnit
)) );
427 awt::Size aVisualSize
;
428 aVisualSize
.Width
= aTmp
.Width();
429 aVisualSize
.Height
= aTmp
.Height();
430 xObj
->setVisualAreaSize( nAspect
, aVisualSize
);
431 mpViewShell
->ActivateObject(pOleObj
, embed::EmbedVerbs::MS_OLEVERB_SHOW
);
433 if (nSlotId
== SID_INSERT_DIAGRAM
)
435 // note, that this call modified the chart model which
436 // results in a change notification. So call this after
437 // everything else is finished.
438 ChartHelper::AdaptDefaultsForChart( xObj
);
444 ErrorHandler::HandleError(* new StringErrorInfo(ERRCODE_SFX_OLEGENERAL
,
451 sal_Int64 nAspect
= embed::Aspects::MSOLE_CONTENT
;
452 bool bCreateNew
= false;
453 uno::Reference
< embed::XEmbeddedObject
> xObj
;
454 uno::Reference
< embed::XStorage
> xStorage
= comphelper::OStorageHelper::GetTemporaryStorage();
455 SvObjectServerList aServerLst
;
458 OUString aIconMediaType
;
459 uno::Reference
< io::XInputStream
> xIconMetaFile
;
461 const SfxGlobalNameItem
* pNameItem
= rReq
.GetArg
<SfxGlobalNameItem
>(SID_INSERT_OBJECT
);
462 if ( nSlotId
== SID_INSERT_OBJECT
&& pNameItem
)
464 SvGlobalName aClassName
= pNameItem
->GetValue();
465 xObj
= mpViewShell
->GetViewFrame()->GetObjectShell()->
466 GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName
.GetByteSequence(), aName
);
472 case SID_INSERT_OBJECT
:
474 aServerLst
.FillInsertObjects();
475 if (mpDoc
->GetDocumentType() == DocumentType::Draw
)
477 aServerLst
.Remove( GraphicDocShell::Factory().GetClassId() );
481 aServerLst
.Remove( DrawDocShell::Factory().GetClassId() );
486 case SID_INSERT_FLOATINGFRAME
:
488 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
489 ScopedVclPtr
<SfxAbstractInsertObjectDialog
> pDlg(
490 pFact
->CreateInsertObjectDialog( mpViewShell
->GetFrameWeld(), SD_MOD()->GetSlotPool()->GetSlot(nSlotId
)->GetCommandString(),
491 xStorage
, &aServerLst
));
495 bCreateNew
= pDlg
->IsCreateNew();
496 xObj
= pDlg
->GetObject();
498 xIconMetaFile
= pDlg
->GetIconIfIconified( &aIconMediaType
);
499 if ( xIconMetaFile
.is() )
500 nAspect
= embed::Aspects::MSOLE_ICON
;
503 mpViewShell
->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj
, aName
);
515 bool bInsertNewObject
= true;
518 MapUnit aMapUnit
= MapUnit::Map100thMM
;
519 if ( nAspect
!= embed::Aspects::MSOLE_ICON
)
524 aSz
= xObj
->getVisualAreaSize( nAspect
);
526 catch( embed::NoVisualAreaSizeException
& )
528 // the default size will be set later
531 aSize
=Size( aSz
.Width
, aSz
.Height
);
533 aMapUnit
= VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj
->getMapUnit( nAspect
) );
534 if (aSize
.Height() == 0 || aSize
.Width() == 0)
536 // rectangle with balanced edge ratio
537 aSize
.setWidth( 14100 );
538 aSize
.setHeight( 10000 );
539 Size aTmp
= OutputDevice::LogicToLogic(aSize
, MapMode(MapUnit::Map100thMM
), MapMode(aMapUnit
));
540 aSz
.Width
= aTmp
.Width();
541 aSz
.Height
= aTmp
.Height();
542 xObj
->setVisualAreaSize( nAspect
, aSz
);
546 aSize
= OutputDevice::LogicToLogic(aSize
, MapMode(aMapUnit
), MapMode(MapUnit::Map100thMM
));
550 if ( mpView
->AreObjectsMarked() )
552 // as an empty OLE object available?
553 const SdrMarkList
& rMarkList
= mpView
->GetMarkedObjectList();
555 if (rMarkList
.GetMarkCount() == 1)
557 SdrMark
* pMark
= rMarkList
.GetMark(0);
558 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
560 if (pObj
->GetObjInventor() == SdrInventor::Default
&&
561 pObj
->GetObjIdentifier() == OBJ_OLE2
)
563 if ( !static_cast<SdrOle2Obj
*>(pObj
)->GetObjRef().is() )
565 // the empty OLE object gets a new IPObj
566 bInsertNewObject
= false;
567 pObj
->SetEmptyPresObj(false);
568 static_cast<SdrOle2Obj
*>(pObj
)->SetOutlinerParaObject(nullptr);
569 static_cast<SdrOle2Obj
*>(pObj
)->SetObjRef(xObj
);
570 static_cast<SdrOle2Obj
*>(pObj
)->SetPersistName(aName
);
571 static_cast<SdrOle2Obj
*>(pObj
)->SetName(aName
);
572 static_cast<SdrOle2Obj
*>(pObj
)->SetAspect(nAspect
);
573 ::tools::Rectangle aRect
= static_cast<SdrOle2Obj
*>(pObj
)->GetLogicRect();
575 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
577 if( xIconMetaFile
.is() )
578 static_cast<SdrOle2Obj
*>(pObj
)->SetGraphicToObj( xIconMetaFile
, aIconMediaType
);
582 Size aTmp
= OutputDevice::LogicToLogic(aRect
.GetSize(), MapMode(MapUnit::Map100thMM
), MapMode(aMapUnit
));
583 awt::Size
aSz( aTmp
.Width(), aTmp
.Height() );
584 xObj
->setVisualAreaSize( nAspect
, aSz
);
591 if (bInsertNewObject
)
593 // we create a new OLE object
594 SdrPageView
* pPV
= mpView
->GetSdrPageView();
595 Size aPageSize
= pPV
->GetPage()->GetSize();
597 // get the size from the iconified object
598 ::svt::EmbeddedObjectRef
aObjRef( xObj
, nAspect
);
599 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
601 aObjRef
.SetGraphicStream( xIconMetaFile
, aIconMediaType
);
602 MapMode
aMapMode( MapUnit::Map100thMM
);
603 aSize
= aObjRef
.GetSize( &aMapMode
);
606 Point
aPnt ((aPageSize
.Width() - aSize
.Width()) / 2,
607 (aPageSize
.Height() - aSize
.Height()) / 2);
608 ::tools::Rectangle
aRect (aPnt
, aSize
);
609 SdrOle2Obj
* pObj
= new SdrOle2Obj(
610 mpView
->getSdrModelFromSdrView(),
615 if( mpView
->InsertObjectAtView(pObj
, *pPV
, SdrInsertFlags::SETDEFLAYER
) )
617 // Math objects change their object size during InsertObject.
618 // New size must be set in SdrObject, or a wrong scale will be set at
621 if ( nAspect
!= embed::Aspects::MSOLE_ICON
)
625 awt::Size aSz
= xObj
->getVisualAreaSize( nAspect
);
627 Size aNewSize
= Window::LogicToLogic( Size( aSz
.Width
, aSz
.Height
),
628 MapMode( aMapUnit
), MapMode( MapUnit::Map100thMM
) );
629 if ( aNewSize
!= aSize
)
631 aRect
.SetSize( aNewSize
);
632 pObj
->SetLogicRect( aRect
);
635 catch( embed::NoVisualAreaSizeException
& )
641 pObj
->SetLogicRect(aRect
);
643 if ( nAspect
!= embed::Aspects::MSOLE_ICON
)
645 Size aTmp
= OutputDevice::LogicToLogic(aRect
.GetSize(), MapMode(MapUnit::Map100thMM
), MapMode(aMapUnit
));
646 awt::Size
aSz( aTmp
.Width(), aTmp
.Height() );
647 xObj
->setVisualAreaSize( nAspect
, aSz
);
650 mpViewShell
->ActivateObject(pObj
, embed::EmbedVerbs::MS_OLEVERB_SHOW
);
653 Size aVisSizePixel
= mpWindow
->GetOutputSizePixel();
654 ::tools::Rectangle aVisAreaWin
= mpWindow
->PixelToLogic( ::tools::Rectangle( Point(0,0), aVisSizePixel
) );
655 mpViewShell
->VisAreaChanged(aVisAreaWin
);
656 mpDocSh
->SetVisArea(aVisAreaWin
);
661 catch (uno::Exception
&)
663 // For some reason the object can not be inserted. For example
664 // because it is password protected and is not properly unlocked.
669 FuInsertAVMedia::FuInsertAVMedia(
673 SdDrawDocument
* pDoc
,
675 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
679 rtl::Reference
<FuPoor
> FuInsertAVMedia::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
681 rtl::Reference
<FuPoor
> xFunc( new FuInsertAVMedia( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
682 xFunc
->DoExecute(rReq
);
686 void FuInsertAVMedia::DoExecute( SfxRequest
& rReq
)
689 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
694 const SfxStringItem
* pStringItem
= dynamic_cast<const SfxStringItem
*>( &pReqArgs
->Get( rReq
.GetSlot() ) );
698 aURL
= pStringItem
->GetValue();
699 bAPI
= !aURL
.isEmpty();
705 #if HAVE_FEATURE_AVMEDIA
706 || ::avmedia::MediaWindow::executeMediaURLDialog(mpWindow
? mpWindow
->GetFrameWeld() : nullptr, aURL
, & bLink
)
713 mpWindow
->EnterWait();
715 #if HAVE_FEATURE_AVMEDIA
716 if( !::avmedia::MediaWindow::isMediaURL( aURL
, "", true, &aPrefSize
) )
719 mpWindow
->LeaveWait();
722 ::avmedia::MediaWindow::executeFormatErrorBox(mpWindow
->GetFrameWeld());
728 sal_Int8 nAction
= DND_ACTION_COPY
;
730 if( aPrefSize
.Width() && aPrefSize
.Height() )
733 aSize
= mpWindow
->PixelToLogic(aPrefSize
, MapMode(MapUnit::Map100thMM
));
735 aSize
= Application::GetDefaultDevice()->PixelToLogic(aPrefSize
, MapMode(MapUnit::Map100thMM
));
738 aSize
= Size( 5000, 5000 );
742 aPos
= mpWindow
->PixelToLogic( ::tools::Rectangle( aPos
, mpWindow
->GetOutputSizePixel() ).Center() );
743 aPos
.AdjustX( -(aSize
.Width() >> 1) );
744 aPos
.AdjustY( -(aSize
.Height() >> 1) );
747 mpView
->InsertMediaURL( aURL
, nAction
, aPos
, aSize
, bLink
) ;
750 mpWindow
->LeaveWait();
754 mpWindow
->LeaveWait();
761 } // end of namespace sd
763 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */