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/XComponentSupplier.hpp>
30 #include <com/sun/star/embed/Aspects.hpp>
31 #include <com/sun/star/embed/XEmbeddedObject.hpp>
32 #include <com/sun/star/chart2/XChartDocument.hpp>
34 #include <svl/stritem.hxx>
35 #include <sfx2/docfile.hxx>
36 #include <sfx2/msgpool.hxx>
37 #include <sfx2/msg.hxx>
38 #include <svtools/insdlg.hxx>
39 #include <sfx2/request.hxx>
40 #include <svl/globalnameitem.hxx>
41 #include <svtools/miscopt.hxx>
42 #include <svtools/embedhlp.hxx>
43 #include <svx/linkwarn.hxx>
44 #include <avmedia/mediawindow.hxx>
45 #include <comphelper/classids.hxx>
46 #include <svtools/sfxecode.hxx>
47 #include <vcl/transfer.hxx>
48 #include <svl/urlbmk.hxx>
49 #include <svx/svdobj.hxx>
50 #include <svx/svdograf.hxx>
51 #include <svx/svdoole2.hxx>
52 #include <sot/formats.hxx>
53 #include <svx/svdpagv.hxx>
54 #include <sfx2/opengrf.hxx>
55 #include <sfx2/viewfrm.hxx>
56 #include <svx/charthelper.hxx>
57 #include <svx/svxids.hrc>
59 #include <sdresid.hxx>
63 #include <DrawViewShell.hxx>
64 #include <DrawDocShell.hxx>
65 #include <GraphicDocShell.hxx>
66 #include <strings.hrc>
67 #include <drawdoc.hxx>
69 #include <sdgrffilter.hxx>
70 #include <vcl/svapp.hxx>
72 #include <vcl/weld.hxx>
73 #include <vcl/errinf.hxx>
74 #include <vcl/graphicfilter.hxx>
76 #include <vcl/GraphicNativeTransform.hxx>
77 #include <vcl/GraphicNativeMetadata.hxx>
79 using namespace com::sun::star
;
84 FuInsertGraphic::FuInsertGraphic (
90 bool replaceExistingImage
)
91 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
),
92 mbReplaceExistingImage(replaceExistingImage
)
96 rtl::Reference
<FuPoor
> FuInsertGraphic::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
,
97 SdDrawDocument
* pDoc
, SfxRequest
& rReq
, bool replaceExistingImage
)
99 rtl::Reference
<FuPoor
> xFunc( new FuInsertGraphic( pViewSh
, pWin
, pView
, pDoc
, rReq
, replaceExistingImage
) );
100 xFunc
->DoExecute(rReq
);
104 void FuInsertGraphic::DoExecute( SfxRequest
& rReq
)
107 OUString aFilterName
;
110 bool bAsLink
= false;
111 ErrCode nError
= ERRCODE_GRFILTER_OPENERROR
;
113 const SfxItemSet
* pArgs
= rReq
.GetArgs();
114 const SfxPoolItem
* pItem
;
117 pArgs
->GetItemState( SID_INSERT_GRAPHIC
, true, &pItem
) == SfxItemState::SET
)
119 aFileName
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
121 if ( pArgs
->GetItemState( FN_PARAM_FILTER
, true, &pItem
) == SfxItemState::SET
)
122 aFilterName
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
124 if ( pArgs
->GetItemState( FN_PARAM_1
, true, &pItem
) == SfxItemState::SET
)
125 bAsLink
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
127 nError
= GraphicFilter::LoadGraphic( aFileName
, aFilterName
, aGraphic
, &GraphicFilter::GetGraphicFilter() );
131 SvxOpenGraphicDialog
aDlg(SdResId(STR_INSERTGRAPHIC
), mpWindow
? mpWindow
->GetFrameWeld() : nullptr);
133 if( aDlg
.Execute() != ERRCODE_NONE
)
134 return; // cancel dialog
136 nError
= aDlg
.GetGraphic(aGraphic
);
137 bAsLink
= aDlg
.IsAsLink();
138 aFileName
= aDlg
.GetPath();
139 aFilterName
= aDlg
.GetDetectedFilter();
142 if( nError
== ERRCODE_NONE
)
144 GraphicNativeMetadata aMetadata
;
145 if ( aMetadata
.read(aGraphic
) )
147 const sal_uInt16 aRotation
= aMetadata
.getRotation();
150 std::unique_ptr
<weld::MessageDialog
> xQueryBox(Application::CreateMessageDialog(nullptr, VclMessageType::Question
,VclButtonsType::YesNo
,SdResId(STR_QUERYROTATION
)));
151 if (xQueryBox
->run() == RET_YES
)
153 GraphicNativeTransform
aTransform( aGraphic
);
154 aTransform
.rotate( aRotation
);
158 if( dynamic_cast< DrawViewShell
*>( mpViewShell
) )
160 sal_Int8 nAction
= DND_ACTION_COPY
;
163 if( ( ( pPickObj
= mpView
->GetSelectedSingleObject( mpView
->GetPage() ) ) && mbReplaceExistingImage
) || (pPickObj
= mpView
->GetEmptyPresentationObject( PRESOBJ_GRAPHIC
) ) )
165 nAction
= DND_ACTION_LINK
;
170 Point aPos
= mpWindow
->GetVisibleCenter();
171 SdrGrafObj
* pGrafObj
= mpView
->InsertGraphic(aGraphic
, nAction
, aPos
, pPickObj
, nullptr);
173 if(pGrafObj
&& bAsLink
)
175 // really store as link only?
176 if( SvtMiscOptions().ShowLinkWarningDialog() )
178 SvxLinkWarningDialog
aWarnDlg(mpWindow
->GetFrameWeld(), aFileName
);
179 if (aWarnDlg
.run() != RET_OK
)
180 return; // don't store as link
185 if (mpDocSh
->HasName()) {
186 aReferer
= mpDocSh
->GetMedium()->GetName();
188 pGrafObj
->SetGraphicLink(aFileName
, aReferer
, aFilterName
);
194 SdGRFFilter::HandleGraphicFilterError( nError
, GraphicFilter::GetGraphicFilter().GetLastError().nStreamError
);
198 FuInsertClipboard::FuInsertClipboard (
202 SdDrawDocument
* pDoc
,
204 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
208 rtl::Reference
<FuPoor
> FuInsertClipboard::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
210 rtl::Reference
<FuPoor
> xFunc( new FuInsertClipboard( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
211 xFunc
->DoExecute(rReq
);
215 void FuInsertClipboard::DoExecute( SfxRequest
& )
217 TransferableDataHelper
aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpWindow
) );
218 SotClipboardFormatId nFormatId
;
220 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
221 ScopedVclPtr
<SfxAbstractPasteDialog
> pDlg(pFact
->CreatePasteDialog(mpViewShell
->GetFrameWeld()));
222 pDlg
->Insert( SotClipboardFormatId::EMBED_SOURCE
, OUString() );
223 pDlg
->Insert( SotClipboardFormatId::LINK_SOURCE
, OUString() );
224 pDlg
->Insert( SotClipboardFormatId::DRAWING
, OUString() );
225 pDlg
->Insert( SotClipboardFormatId::SVXB
, OUString() );
226 pDlg
->Insert( SotClipboardFormatId::GDIMETAFILE
, OUString() );
227 pDlg
->Insert( SotClipboardFormatId::BITMAP
, OUString() );
228 pDlg
->Insert( SotClipboardFormatId::NETSCAPE_BOOKMARK
, OUString() );
229 pDlg
->Insert( SotClipboardFormatId::STRING
, OUString() );
230 pDlg
->Insert( SotClipboardFormatId::HTML
, OUString() );
231 pDlg
->Insert( SotClipboardFormatId::RTF
, OUString() );
232 pDlg
->Insert( SotClipboardFormatId::RICHTEXT
, OUString() );
233 pDlg
->Insert( SotClipboardFormatId::EDITENGINE_ODF_TEXT_FLAT
, OUString() );
236 nFormatId
= pDlg
->GetFormat( aDataHelper
);
237 if( nFormatId
== SotClipboardFormatId::NONE
|| !aDataHelper
.GetTransferable().is() )
240 sal_Int8 nAction
= DND_ACTION_COPY
;
241 DrawViewShell
* pDrViewSh
= nullptr;
243 if (!mpView
->InsertData( aDataHelper
,
244 mpWindow
->PixelToLogic( ::tools::Rectangle( Point(), mpWindow
->GetOutputSizePixel() ).Center() ),
245 nAction
, false, nFormatId
))
247 pDrViewSh
= dynamic_cast<DrawViewShell
*>(mpViewShell
);
253 INetBookmark
aINetBookmark( "", "" );
255 if( ( aDataHelper
.HasFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK
) &&
256 aDataHelper
.GetINetBookmark( SotClipboardFormatId::NETSCAPE_BOOKMARK
, aINetBookmark
) ) ||
257 ( aDataHelper
.HasFormat( SotClipboardFormatId::FILEGRPDESCRIPTOR
) &&
258 aDataHelper
.GetINetBookmark( SotClipboardFormatId::FILEGRPDESCRIPTOR
, aINetBookmark
) ) ||
259 ( aDataHelper
.HasFormat( SotClipboardFormatId::UNIFORMRESOURCELOCATOR
) &&
260 aDataHelper
.GetINetBookmark( SotClipboardFormatId::UNIFORMRESOURCELOCATOR
, aINetBookmark
) ) )
262 pDrViewSh
->InsertURLField( aINetBookmark
.GetURL(), aINetBookmark
.GetDescription(), "" );
266 FuInsertOLE::FuInsertOLE (
270 SdDrawDocument
* pDoc
,
272 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
276 rtl::Reference
<FuPoor
> FuInsertOLE::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
278 rtl::Reference
<FuPoor
> xFunc( new FuInsertOLE( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
279 xFunc
->DoExecute(rReq
);
283 void FuInsertOLE::DoExecute( SfxRequest
& rReq
)
285 if ( nSlotId
== SID_ATTR_TABLE
||
286 nSlotId
== SID_INSERT_DIAGRAM
||
287 nSlotId
== SID_INSERT_MATH
)
289 PresObjKind ePresObjKind
= (nSlotId
== SID_INSERT_DIAGRAM
) ? PRESOBJ_CHART
: PRESOBJ_OBJECT
;
291 SdrObject
* pPickObj
= mpView
->GetEmptyPresentationObject( ePresObjKind
);
293 // insert diagram or Calc table
296 if (nSlotId
== SID_INSERT_DIAGRAM
)
297 aName
= SvGlobalName( SO3_SCH_CLASSID
);
298 else if (nSlotId
== SID_ATTR_TABLE
)
299 aName
= SvGlobalName(SO3_SC_CLASSID
);
300 else if (nSlotId
== SID_INSERT_MATH
)
301 aName
= SvGlobalName(SO3_SM_CLASSID
);
303 uno::Reference
< embed::XEmbeddedObject
> xObj
= mpViewShell
->GetViewFrame()->GetObjectShell()->
304 GetEmbeddedObjectContainer().CreateEmbeddedObject( aName
.GetByteSequence(), aObjName
);
307 uno::Reference
<embed::XComponentSupplier
> xCompSupp(xObj
, uno::UNO_QUERY
);
310 // Create default chart type.
311 uno::Reference
<chart2::XChartDocument
> xChartDoc(xCompSupp
->getComponent(), uno::UNO_QUERY
);
313 xChartDoc
->createDefaultChart();
316 sal_Int64 nAspect
= embed::Aspects::MSOLE_CONTENT
;
318 MapUnit aUnit
= VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj
->getMapUnit( nAspect
) );
320 ::tools::Rectangle aRect
;
323 aRect
= pPickObj
->GetLogicRect();
326 aSz
.Width
= aRect
.GetWidth();
327 aSz
.Height
= aRect
.GetHeight();
328 xObj
->setVisualAreaSize( nAspect
, aSz
);
335 aSz
= xObj
->getVisualAreaSize( nAspect
);
337 catch ( embed::NoVisualAreaSizeException
& )
339 // the default size will be set later
342 Size
aSize( aSz
.Width
, aSz
.Height
);
344 if (aSize
.Height() == 0 || aSize
.Width() == 0)
346 // rectangle with balanced edge ratio
347 aSize
.setWidth( 14100 );
348 aSize
.setHeight( 10000 );
349 Size aTmp
= OutputDevice::LogicToLogic(aSize
, MapMode(MapUnit::Map100thMM
), MapMode(aUnit
));
350 aSz
.Width
= aTmp
.Width();
351 aSz
.Height
= aTmp
.Height();
352 xObj
->setVisualAreaSize( nAspect
, aSz
);
356 aSize
= OutputDevice::LogicToLogic(aSize
, MapMode(aUnit
), MapMode(MapUnit::Map100thMM
));
359 Point aPos
= mpWindow
->GetVisibleCenter();
360 aPos
.AdjustX( -(aSize
.Width() / 2) );
361 aPos
.AdjustY( -(aSize
.Height() / 2) );
362 aRect
= ::tools::Rectangle(aPos
, aSize
);
365 SdrOle2Obj
* pOleObj
= new SdrOle2Obj(
366 mpView
->getSdrModelFromSdrView(),
367 svt::EmbeddedObjectRef( xObj
, nAspect
),
370 SdrPageView
* pPV
= mpView
->GetSdrPageView();
372 // if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj
375 SdPage
* pPage
= static_cast< SdPage
* >(pPickObj
->getSdrPageFromSdrObject());
376 if(pPage
&& pPage
->IsPresObj(pPickObj
))
378 pPage
->InsertPresObj( pOleObj
, ePresObjKind
);
379 pOleObj
->SetUserCall(pPickObj
->GetUserCall());
382 // #i123468# we need to end text edit before replacing the object. There cannot yet
383 // being text typed (else it would not be an EmptyPresObj anymore), but it may be
385 if (mpView
->IsTextEdit())
387 mpView
->SdrEndTextEdit();
393 mpView
->ReplaceObjectAtView(pPickObj
, *pPV
, pOleObj
);
395 bRet
= mpView
->InsertObjectAtView(pOleObj
, *pPV
, SdrInsertFlags::SETDEFLAYER
);
399 if (nSlotId
== SID_INSERT_DIAGRAM
)
401 pOleObj
->SetProgName( "StarChart");
403 else if (nSlotId
== SID_ATTR_TABLE
)
405 pOleObj
->SetProgName( "StarCalc" );
407 else if (nSlotId
== SID_INSERT_MATH
)
409 pOleObj
->SetProgName( "StarMath" );
412 pOleObj
->SetLogicRect(aRect
);
413 Size
aTmp( OutputDevice::LogicToLogic(aRect
.GetSize(), MapMode(MapUnit::Map100thMM
), MapMode(aUnit
)) );
414 awt::Size aVisualSize
;
415 aVisualSize
.Width
= aTmp
.Width();
416 aVisualSize
.Height
= aTmp
.Height();
417 xObj
->setVisualAreaSize( nAspect
, aVisualSize
);
418 mpViewShell
->ActivateObject(pOleObj
, embed::EmbedVerbs::MS_OLEVERB_SHOW
);
420 if (nSlotId
== SID_INSERT_DIAGRAM
)
422 // note, that this call modified the chart model which
423 // results in a change notification. So call this after
424 // everything else is finished.
425 ChartHelper::AdaptDefaultsForChart( xObj
);
431 ErrorHandler::HandleError(* new StringErrorInfo(ERRCODE_SFX_OLEGENERAL
,
438 sal_Int64 nAspect
= embed::Aspects::MSOLE_CONTENT
;
439 bool bCreateNew
= false;
440 uno::Reference
< embed::XEmbeddedObject
> xObj
;
441 uno::Reference
< embed::XStorage
> xStorage
= comphelper::OStorageHelper::GetTemporaryStorage();
442 SvObjectServerList aServerLst
;
445 OUString aIconMediaType
;
446 uno::Reference
< io::XInputStream
> xIconMetaFile
;
448 const SfxGlobalNameItem
* pNameItem
= rReq
.GetArg
<SfxGlobalNameItem
>(SID_INSERT_OBJECT
);
449 if ( nSlotId
== SID_INSERT_OBJECT
&& pNameItem
)
451 const SvGlobalName
& aClassName
= pNameItem
->GetValue();
452 xObj
= mpViewShell
->GetViewFrame()->GetObjectShell()->
453 GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName
.GetByteSequence(), aName
);
459 case SID_INSERT_OBJECT
:
461 aServerLst
.FillInsertObjects();
462 if (mpDoc
->GetDocumentType() == DocumentType::Draw
)
464 aServerLst
.Remove( GraphicDocShell::Factory().GetClassId() );
468 aServerLst
.Remove( DrawDocShell::Factory().GetClassId() );
473 case SID_INSERT_FLOATINGFRAME
:
475 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
476 ScopedVclPtr
<SfxAbstractInsertObjectDialog
> pDlg(
477 pFact
->CreateInsertObjectDialog( mpViewShell
->GetFrameWeld(), SD_MOD()->GetSlotPool()->GetSlot(nSlotId
)->GetCommandString(),
478 xStorage
, &aServerLst
));
480 bCreateNew
= pDlg
->IsCreateNew();
481 xObj
= pDlg
->GetObject();
483 xIconMetaFile
= pDlg
->GetIconIfIconified( &aIconMediaType
);
484 if ( xIconMetaFile
.is() )
485 nAspect
= embed::Aspects::MSOLE_ICON
;
488 mpViewShell
->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj
, aName
);
499 bool bInsertNewObject
= true;
502 MapUnit aMapUnit
= MapUnit::Map100thMM
;
503 if ( nAspect
!= embed::Aspects::MSOLE_ICON
)
508 aSz
= xObj
->getVisualAreaSize( nAspect
);
510 catch( embed::NoVisualAreaSizeException
& )
512 // the default size will be set later
515 aSize
=Size( aSz
.Width
, aSz
.Height
);
517 aMapUnit
= VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj
->getMapUnit( nAspect
) );
518 if (aSize
.Height() == 0 || aSize
.Width() == 0)
520 // rectangle with balanced edge ratio
521 aSize
.setWidth( 14100 );
522 aSize
.setHeight( 10000 );
523 Size aTmp
= OutputDevice::LogicToLogic(aSize
, MapMode(MapUnit::Map100thMM
), MapMode(aMapUnit
));
524 aSz
.Width
= aTmp
.Width();
525 aSz
.Height
= aTmp
.Height();
526 xObj
->setVisualAreaSize( nAspect
, aSz
);
530 aSize
= OutputDevice::LogicToLogic(aSize
, MapMode(aMapUnit
), MapMode(MapUnit::Map100thMM
));
534 if ( mpView
->AreObjectsMarked() )
536 // as an empty OLE object available?
537 const SdrMarkList
& rMarkList
= mpView
->GetMarkedObjectList();
539 if (rMarkList
.GetMarkCount() == 1)
541 SdrMark
* pMark
= rMarkList
.GetMark(0);
542 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
544 if (pObj
->GetObjInventor() == SdrInventor::Default
&&
545 pObj
->GetObjIdentifier() == OBJ_OLE2
)
547 if ( !static_cast<SdrOle2Obj
*>(pObj
)->GetObjRef().is() )
549 // the empty OLE object gets a new IPObj
550 bInsertNewObject
= false;
551 pObj
->SetEmptyPresObj(false);
552 static_cast<SdrOle2Obj
*>(pObj
)->SetOutlinerParaObject(nullptr);
553 static_cast<SdrOle2Obj
*>(pObj
)->SetObjRef(xObj
);
554 static_cast<SdrOle2Obj
*>(pObj
)->SetPersistName(aName
);
555 static_cast<SdrOle2Obj
*>(pObj
)->SetName(aName
);
556 static_cast<SdrOle2Obj
*>(pObj
)->SetAspect(nAspect
);
557 ::tools::Rectangle aRect
= static_cast<SdrOle2Obj
*>(pObj
)->GetLogicRect();
559 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
561 if( xIconMetaFile
.is() )
562 static_cast<SdrOle2Obj
*>(pObj
)->SetGraphicToObj( xIconMetaFile
, aIconMediaType
);
566 Size aTmp
= OutputDevice::LogicToLogic(aRect
.GetSize(), MapMode(MapUnit::Map100thMM
), MapMode(aMapUnit
));
567 awt::Size
aSz( aTmp
.Width(), aTmp
.Height() );
568 xObj
->setVisualAreaSize( nAspect
, aSz
);
575 if (bInsertNewObject
)
577 // we create a new OLE object
578 SdrPageView
* pPV
= mpView
->GetSdrPageView();
579 Size aPageSize
= pPV
->GetPage()->GetSize();
581 // get the size from the iconified object
582 ::svt::EmbeddedObjectRef
aObjRef( xObj
, nAspect
);
583 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
585 aObjRef
.SetGraphicStream( xIconMetaFile
, aIconMediaType
);
586 MapMode
aMapMode( MapUnit::Map100thMM
);
587 aSize
= aObjRef
.GetSize( &aMapMode
);
590 Point
aPnt ((aPageSize
.Width() - aSize
.Width()) / 2,
591 (aPageSize
.Height() - aSize
.Height()) / 2);
592 ::tools::Rectangle
aRect (aPnt
, aSize
);
593 SdrOle2Obj
* pObj
= new SdrOle2Obj(
594 mpView
->getSdrModelFromSdrView(),
599 if( mpView
->InsertObjectAtView(pObj
, *pPV
, SdrInsertFlags::SETDEFLAYER
) )
601 // Math objects change their object size during InsertObject.
602 // New size must be set in SdrObject, or a wrong scale will be set at
605 if ( nAspect
!= embed::Aspects::MSOLE_ICON
)
609 awt::Size aSz
= xObj
->getVisualAreaSize( nAspect
);
611 Size aNewSize
= Window::LogicToLogic( Size( aSz
.Width
, aSz
.Height
),
612 MapMode( aMapUnit
), MapMode( MapUnit::Map100thMM
) );
613 if ( aNewSize
!= aSize
)
615 aRect
.SetSize( aNewSize
);
616 pObj
->SetLogicRect( aRect
);
619 catch( embed::NoVisualAreaSizeException
& )
625 pObj
->SetLogicRect(aRect
);
627 if ( nAspect
!= embed::Aspects::MSOLE_ICON
)
629 Size aTmp
= OutputDevice::LogicToLogic(aRect
.GetSize(), MapMode(MapUnit::Map100thMM
), MapMode(aMapUnit
));
630 awt::Size
aSz( aTmp
.Width(), aTmp
.Height() );
631 xObj
->setVisualAreaSize( nAspect
, aSz
);
634 mpViewShell
->ActivateObject(pObj
, embed::EmbedVerbs::MS_OLEVERB_SHOW
);
637 Size aVisSizePixel
= mpWindow
->GetOutputSizePixel();
638 ::tools::Rectangle aVisAreaWin
= mpWindow
->PixelToLogic( ::tools::Rectangle( Point(0,0), aVisSizePixel
) );
639 mpViewShell
->VisAreaChanged(aVisAreaWin
);
640 mpDocSh
->SetVisArea(aVisAreaWin
);
645 catch (uno::Exception
&)
647 // For some reason the object can not be inserted. For example
648 // because it is password protected and is not properly unlocked.
653 FuInsertAVMedia::FuInsertAVMedia(
657 SdDrawDocument
* pDoc
,
659 : FuPoor(pViewSh
, pWin
, pView
, pDoc
, rReq
)
663 rtl::Reference
<FuPoor
> FuInsertAVMedia::Create( ViewShell
* pViewSh
, ::sd::Window
* pWin
, ::sd::View
* pView
, SdDrawDocument
* pDoc
, SfxRequest
& rReq
)
665 rtl::Reference
<FuPoor
> xFunc( new FuInsertAVMedia( pViewSh
, pWin
, pView
, pDoc
, rReq
) );
666 xFunc
->DoExecute(rReq
);
670 void FuInsertAVMedia::DoExecute( SfxRequest
& rReq
)
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 #if HAVE_FEATURE_AVMEDIA
690 || ::avmedia::MediaWindow::executeMediaURLDialog(mpWindow
? mpWindow
->GetFrameWeld() : nullptr, aURL
, & bLink
)
698 mpWindow
->EnterWait();
700 #if HAVE_FEATURE_AVMEDIA
701 if( !::avmedia::MediaWindow::isMediaURL( aURL
, "", true, &aPrefSize
) )
704 mpWindow
->LeaveWait();
707 ::avmedia::MediaWindow::executeFormatErrorBox(mpWindow
->GetFrameWeld());
713 sal_Int8 nAction
= DND_ACTION_COPY
;
715 if( aPrefSize
.Width() && aPrefSize
.Height() )
718 aSize
= mpWindow
->PixelToLogic(aPrefSize
, MapMode(MapUnit::Map100thMM
));
720 aSize
= Application::GetDefaultDevice()->PixelToLogic(aPrefSize
, MapMode(MapUnit::Map100thMM
));
723 aSize
= Size( 5000, 5000 );
727 aPos
= mpWindow
->PixelToLogic( ::tools::Rectangle( aPos
, mpWindow
->GetOutputSizePixel() ).Center() );
728 aPos
.AdjustX( -(aSize
.Width() >> 1) );
729 aPos
.AdjustY( -(aSize
.Height() >> 1) );
732 mpView
->InsertMediaURL( aURL
, nAction
, aPos
, aSize
, bLink
) ;
735 mpWindow
->LeaveWait();
739 mpWindow
->LeaveWait();
745 } // end of namespace sd
747 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */