bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / func / fuinsert.cxx
blob3ce7708cb4f9f90c05a0e711be743ebb32b7484d
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 <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>
60 #include <View.hxx>
61 #include <sdmod.hxx>
62 #include <Window.hxx>
63 #include <DrawViewShell.hxx>
64 #include <DrawDocShell.hxx>
65 #include <GraphicDocShell.hxx>
66 #include <strings.hrc>
67 #include <drawdoc.hxx>
68 #include <sdpage.hxx>
69 #include <sdgrffilter.hxx>
70 #include <vcl/svapp.hxx>
71 #include <memory>
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;
81 namespace sd {
84 FuInsertGraphic::FuInsertGraphic (
85 ViewShell* pViewSh,
86 ::sd::Window* pWin,
87 ::sd::View* pView,
88 SdDrawDocument* pDoc,
89 SfxRequest& rReq,
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);
101 return xFunc;
104 void FuInsertGraphic::DoExecute( SfxRequest& rReq )
106 OUString aFileName;
107 OUString aFilterName;
108 Graphic aGraphic;
110 bool bAsLink = false;
111 ErrCode nError = ERRCODE_GRFILTER_OPENERROR;
113 const SfxItemSet* pArgs = rReq.GetArgs();
114 const SfxPoolItem* pItem;
116 if ( pArgs &&
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() );
129 else
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();
148 if (aRotation != 0)
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;
161 SdrObject* pPickObj;
163 if( ( ( pPickObj = mpView->GetSelectedSingleObject( mpView->GetPage() ) ) && mbReplaceExistingImage ) || (pPickObj = mpView->GetEmptyPresentationObject( PRESOBJ_GRAPHIC ) ) )
165 nAction = DND_ACTION_LINK;
166 } else {
167 pPickObj = nullptr;
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
183 // store as link
184 OUString aReferer;
185 if (mpDocSh->HasName()) {
186 aReferer = mpDocSh->GetMedium()->GetName();
188 pGrafObj->SetGraphicLink(aFileName, aReferer, aFilterName);
192 else
194 SdGRFFilter::HandleGraphicFilterError( nError, GraphicFilter::GetGraphicFilter().GetLastError().nStreamError );
198 FuInsertClipboard::FuInsertClipboard (
199 ViewShell* pViewSh,
200 ::sd::Window* pWin,
201 ::sd::View* pView,
202 SdDrawDocument* pDoc,
203 SfxRequest& rReq)
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);
212 return xFunc;
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() );
235 //TODO/MBA: testing
236 nFormatId = pDlg->GetFormat( aDataHelper );
237 if( nFormatId == SotClipboardFormatId::NONE || !aDataHelper.GetTransferable().is() )
238 return;
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);
250 if (!pDrViewSh)
251 return;
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 (
267 ViewShell* pViewSh,
268 ::sd::Window* pWin,
269 ::sd::View* pView,
270 SdDrawDocument* pDoc,
271 SfxRequest& rReq)
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);
280 return xFunc;
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
294 OUString aObjName;
295 SvGlobalName aName;
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 );
305 if ( xObj.is() )
307 uno::Reference<embed::XComponentSupplier> xCompSupp(xObj, uno::UNO_QUERY);
308 if (xCompSupp.is())
310 // Create default chart type.
311 uno::Reference<chart2::XChartDocument> xChartDoc(xCompSupp->getComponent(), uno::UNO_QUERY);
312 if (xChartDoc.is())
313 xChartDoc->createDefaultChart();
316 sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
318 MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
320 ::tools::Rectangle aRect;
321 if( pPickObj )
323 aRect = pPickObj->GetLogicRect();
325 awt::Size aSz;
326 aSz.Width = aRect.GetWidth();
327 aSz.Height = aRect.GetHeight();
328 xObj->setVisualAreaSize( nAspect, aSz );
330 else
332 awt::Size 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 );
354 else
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 ),
368 aObjName,
369 aRect);
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
373 if( pPickObj )
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
384 // in text edit mode
385 if (mpView->IsTextEdit())
387 mpView->SdrEndTextEdit();
391 bool bRet = true;
392 if( pPickObj )
393 mpView->ReplaceObjectAtView(pPickObj, *pPV, pOleObj );
394 else
395 bRet = mpView->InsertObjectAtView(pOleObj, *pPV, SdrInsertFlags::SETDEFLAYER);
397 if( bRet )
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 );
429 else
431 ErrorHandler::HandleError(* new StringErrorInfo(ERRCODE_SFX_OLEGENERAL,
432 "" ) );
435 else
437 // insert object
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;
443 OUString aName;
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 );
455 else
457 switch ( nSlotId )
459 case SID_INSERT_OBJECT :
461 aServerLst.FillInsertObjects();
462 if (mpDoc->GetDocumentType() == DocumentType::Draw)
464 aServerLst.Remove( GraphicDocShell::Factory().GetClassId() );
466 else
468 aServerLst.Remove( DrawDocShell::Factory().GetClassId() );
471 [[fallthrough]];
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 ));
479 pDlg->Execute();
480 bCreateNew = pDlg->IsCreateNew();
481 xObj = pDlg->GetObject();
483 xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType );
484 if ( xIconMetaFile.is() )
485 nAspect = embed::Aspects::MSOLE_ICON;
487 if ( xObj.is() )
488 mpViewShell->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aName );
490 break;
497 if (xObj.is())
499 bool bInsertNewObject = true;
501 Size aSize;
502 MapUnit aMapUnit = MapUnit::Map100thMM;
503 if ( nAspect != embed::Aspects::MSOLE_ICON )
505 awt::Size aSz;
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 );
528 else
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 );
564 else
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(),
595 aObjRef,
596 aName,
597 aRect);
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
603 // ActivateObject.
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& )
623 if (bCreateNew)
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(
654 ViewShell* pViewSh,
655 ::sd::Window* pWin,
656 ::sd::View* pView,
657 SdDrawDocument* pDoc,
658 SfxRequest& rReq)
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);
667 return xFunc;
670 void FuInsertAVMedia::DoExecute( SfxRequest& rReq )
672 OUString aURL;
673 const SfxItemSet* pReqArgs = rReq.GetArgs();
674 bool bAPI = false;
676 if( pReqArgs )
678 const SfxStringItem* pStringItem = dynamic_cast<const SfxStringItem*>( &pReqArgs->Get( rReq.GetSlot() ) );
680 if( pStringItem )
682 aURL = pStringItem->GetValue();
683 bAPI = !aURL.isEmpty();
687 bool bLink(true);
688 if (!(bAPI
689 #if HAVE_FEATURE_AVMEDIA
690 || ::avmedia::MediaWindow::executeMediaURLDialog(mpWindow ? mpWindow->GetFrameWeld() : nullptr, aURL, & bLink)
691 #endif
693 return;
695 Size aPrefSize;
697 if( mpWindow )
698 mpWindow->EnterWait();
700 #if HAVE_FEATURE_AVMEDIA
701 if( !::avmedia::MediaWindow::isMediaURL( aURL, "", true, &aPrefSize ) )
703 if( mpWindow )
704 mpWindow->LeaveWait();
706 if( !bAPI )
707 ::avmedia::MediaWindow::executeFormatErrorBox(mpWindow->GetFrameWeld());
709 else
711 Point aPos;
712 Size aSize;
713 sal_Int8 nAction = DND_ACTION_COPY;
715 if( aPrefSize.Width() && aPrefSize.Height() )
717 if( mpWindow )
718 aSize = mpWindow->PixelToLogic(aPrefSize, MapMode(MapUnit::Map100thMM));
719 else
720 aSize = Application::GetDefaultDevice()->PixelToLogic(aPrefSize, MapMode(MapUnit::Map100thMM));
722 else
723 aSize = Size( 5000, 5000 );
725 if( mpWindow )
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 ) ;
734 if( mpWindow )
735 mpWindow->LeaveWait();
737 #else
738 if( mpWindow )
739 mpWindow->LeaveWait();
740 (void) aPrefSize;
741 (void) bLink;
742 #endif
745 } // end of namespace sd
747 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */