LibreOffice Module sd (master) 1
fuinsert.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <config_features.h>
21
22#include <fuinsert.hxx>
25#include <editeng/sizeitem.hxx>
26#include <officecfg/Office/Common.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>
36
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>
44#include <svtools/embedhlp.hxx>
45#include <svx/linkwarn.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>
60
61#include <sdresid.hxx>
62#include <View.hxx>
63#include <sdmod.hxx>
64#include <Window.hxx>
65#include <DrawViewShell.hxx>
66#include <DrawDocShell.hxx>
67#include <GraphicDocShell.hxx>
68#include <strings.hrc>
69#include <drawdoc.hxx>
70#include <sdpage.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>
76
79
80#include <comphelper/lok.hxx>
81
82using namespace com::sun::star;
83
84namespace sd {
85
86
88 ViewShell* pViewSh,
89 ::sd::Window* pWin,
90 ::sd::View* pView,
91 SdDrawDocument* pDoc,
92 SfxRequest& rReq,
93 bool replaceExistingImage)
94 : FuPoor(pViewSh, pWin, pView, pDoc, rReq),
95 mbReplaceExistingImage(replaceExistingImage)
96{
97}
98
100 SdDrawDocument* pDoc, SfxRequest& rReq, bool replaceExistingImage )
101{
102 rtl::Reference<FuPoor> xFunc( new FuInsertGraphic( pViewSh, pWin, pView, pDoc, rReq, replaceExistingImage ) );
103 xFunc->DoExecute(rReq);
104 return xFunc;
105}
106
108{
109 OUString aFileName;
110 Graphic aGraphic;
111
112 bool bAsLink = false;
114
115 const SfxItemSet* pArgs = rReq.GetArgs();
116 const SfxPoolItem* pItem;
117
118 if ( pArgs &&
119 pArgs->GetItemState( SID_INSERT_GRAPHIC, true, &pItem ) == SfxItemState::SET )
120 {
121 aFileName = static_cast<const SfxStringItem*>(pItem)->GetValue();
122
123 OUString aFilterName;
124 if ( const SfxStringItem* pFilterItem = pArgs->GetItemIfSet( FN_PARAM_FILTER ) )
125 aFilterName = pFilterItem->GetValue();
126
127 if ( pArgs->GetItemState( FN_PARAM_1, true, &pItem ) == SfxItemState::SET )
128 bAsLink = static_cast<const SfxBoolItem*>(pItem)->GetValue();
129
130 nError = GraphicFilter::LoadGraphic( aFileName, aFilterName, aGraphic, &GraphicFilter::GetGraphicFilter() );
131 }
132 else
133 {
134 SvxOpenGraphicDialog aDlg(SdResId(STR_INSERTGRAPHIC), mpWindow ? mpWindow->GetFrameWeld() : nullptr);
135
136 if( aDlg.Execute() != ERRCODE_NONE )
137 return; // cancel dialog
138
139 nError = aDlg.GetGraphic(aGraphic);
140 bAsLink = aDlg.IsAsLink();
141 aFileName = aDlg.GetPath();
142 }
143
144 if( nError == ERRCODE_NONE )
145 {
146 GraphicNativeMetadata aMetadata;
147 if ( aMetadata.read(aGraphic) )
148 {
149 const Degree10 aRotation = aMetadata.getRotation();
150 if (aRotation)
151 {
152 GraphicNativeTransform aTransform( aGraphic );
153 aTransform.rotate( aRotation );
154 }
155 }
156 if( dynamic_cast< DrawViewShell *>( mpViewShell ) )
157 {
158 sal_Int8 nAction = DND_ACTION_COPY;
159 SdrObject* pPickObj = nullptr;
162 if (pPickObj)
163 nAction = DND_ACTION_LINK;
164 else
165 {
167 if (pPickObj)
168 nAction = DND_ACTION_LINK;
169 }
170
171 Point aPos = mpWindow->GetVisibleCenter();
172 SdrGrafObj* pGrafObj = mpView->InsertGraphic(aGraphic, nAction, aPos, pPickObj, nullptr);
173
174 if(pGrafObj && bAsLink )
175 {
176 // really store as link only?
177 if( officecfg::Office::Common::Misc::ShowLinkWarningDialog::get() )
178 {
179 SvxLinkWarningDialog aWarnDlg(mpWindow->GetFrameWeld(), aFileName);
180 if (aWarnDlg.run() != RET_OK)
181 return; // don't store as link
182 }
183
184 // store as link
185 pGrafObj->SetGraphicLink(aFileName);
186 }
187 }
188 }
189 else
190 {
192 }
193}
194
196 ViewShell* pViewSh,
197 ::sd::Window* pWin,
198 ::sd::View* pView,
199 SdDrawDocument* pDoc,
200 SfxRequest& rReq)
201 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
202{
203}
204
206{
207 rtl::Reference<FuPoor> xFunc( new FuInsertClipboard( pViewSh, pWin, pView, pDoc, rReq ) );
208 xFunc->DoExecute(rReq);
209 return xFunc;
210}
211
213{
215 SotClipboardFormatId nFormatId;
216
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() );
231
232 //TODO/MBA: testing
233 nFormatId = pDlg->GetFormat( aDataHelper );
234 if( nFormatId == SotClipboardFormatId::NONE || !aDataHelper.GetTransferable().is() )
235 return;
236
237 sal_Int8 nAction = DND_ACTION_COPY;
238 DrawViewShell* pDrViewSh = nullptr;
239
240 if (!mpView->InsertData( aDataHelper,
241 mpWindow->PixelToLogic( ::tools::Rectangle( Point(), mpWindow->GetOutputSizePixel() ).Center() ),
242 nAction, false, nFormatId ))
243 {
244 pDrViewSh = dynamic_cast<DrawViewShell*>(mpViewShell);
245 }
246
247 if (!pDrViewSh)
248 return;
249
250 INetBookmark aINetBookmark( "", "" );
251
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 ) ) )
258 {
259 pDrViewSh->InsertURLField( aINetBookmark.GetURL(), aINetBookmark.GetDescription(), "" );
260 }
261}
262
264 ViewShell* pViewSh,
265 ::sd::Window* pWin,
266 ::sd::View* pView,
267 SdDrawDocument* pDoc,
268 SfxRequest& rReq)
269 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
270{
271}
272
274{
275 rtl::Reference<FuPoor> xFunc( new FuInsertOLE( pViewSh, pWin, pView, pDoc, rReq ) );
276 xFunc->DoExecute(rReq);
277 return xFunc;
278}
279
281{
282 if ( nSlotId == SID_ATTR_TABLE ||
283 nSlotId == SID_INSERT_DIAGRAM ||
284 nSlotId == SID_INSERT_MATH )
285 {
286 PresObjKind ePresObjKind = (nSlotId == SID_INSERT_DIAGRAM) ? PresObjKind::Chart : PresObjKind::Object;
287
288 SdrObject* pPickObj = mpView->GetEmptyPresentationObject( ePresObjKind );
289
290 // insert diagram or Calc table
291 OUString aObjName;
293 if (nSlotId == SID_INSERT_DIAGRAM)
295 else if (nSlotId == SID_ATTR_TABLE)
297 else if (nSlotId == SID_INSERT_MATH)
299
300 uno::Reference < embed::XEmbeddedObject > xObj = mpViewShell->GetViewFrame()->GetObjectShell()->
301 GetEmbeddedObjectContainer().CreateEmbeddedObject( aName.GetByteSequence(), aObjName );
302 if ( xObj.is() )
303 {
304 // Create default chart type.
305 uno::Reference<chart2::XChartDocument> xChartDoc(xObj->getComponent(), uno::UNO_QUERY);
306 if (xChartDoc.is())
307 xChartDoc->createDefaultChart();
308
309 sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
310
311 MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
312
313 ::tools::Rectangle aRect;
314 if( pPickObj )
315 {
316 aRect = pPickObj->GetLogicRect();
317
318 awt::Size aSz;
319 aSz.Width = aRect.GetWidth();
320 aSz.Height = aRect.GetHeight();
321 xObj->setVisualAreaSize( nAspect, aSz );
322 }
323 else
324 {
325 awt::Size aSz;
326 try
327 {
328 aSz = xObj->getVisualAreaSize( nAspect );
329 }
330 catch ( embed::NoVisualAreaSizeException& )
331 {
332 // the default size will be set later
333 }
334
335 Size aSize( aSz.Width, aSz.Height );
336
337 if (aSize.IsEmpty())
338 {
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 );
346 }
347 else
348 {
349 aSize = OutputDevice::LogicToLogic(aSize, MapMode(aUnit), MapMode(MapUnit::Map100thMM));
350 }
351
352 Point aPos = mpWindow->GetVisibleCenter();
353 aPos.AdjustX( -(aSize.Width() / 2) );
354 aPos.AdjustY( -(aSize.Height() / 2) );
355 aRect = ::tools::Rectangle(aPos, aSize);
356 }
357
360 svt::EmbeddedObjectRef( xObj, nAspect ),
361 aObjName,
362 aRect);
364
365 // if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj
366 if( pPickObj )
367 {
368 SdPage* pPage = static_cast< SdPage* >(pPickObj->getSdrPageFromSdrObject());
369 if(pPage && pPage->IsPresObj(pPickObj))
370 {
371 pPage->InsertPresObj( pOleObj.get(), ePresObjKind );
372 pOleObj->SetUserCall(pPickObj->GetUserCall());
373 }
374
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
377 // in text edit mode
378 if (mpView->IsTextEdit())
379 {
381 }
382 }
383
384 bool bRet = true;
385 if( pPickObj )
386 mpView->ReplaceObjectAtView(pPickObj, *pPV, pOleObj.get() );
387 else
388 bRet = mpView->InsertObjectAtView(pOleObj.get(), *pPV, SdrInsertFlags::SETDEFLAYER);
389
391 {
392 // Let the chart be activated after the inserting (unless
393 // via LibreOfficeKit)
394 if (nSlotId == SID_INSERT_DIAGRAM)
395 {
396 pOleObj->SetProgName( "StarChart");
397 }
398 else if (nSlotId == SID_ATTR_TABLE)
399 {
400 pOleObj->SetProgName( "StarCalc" );
401 }
402 else if (nSlotId == SID_INSERT_MATH)
403 {
404 pOleObj->SetProgName( "StarMath" );
405 }
406
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);
414
415 if (nSlotId == SID_INSERT_DIAGRAM)
416 {
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.
421 }
422 }
423 }
424 else
425 {
427 "" ) );
428 }
429 }
430 else
431 {
432 // insert object
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;
438 OUString aName;
439
440 OUString aIconMediaType;
441 uno::Reference< io::XInputStream > xIconMetaFile;
442
443 const SfxGlobalNameItem* pNameItem = rReq.GetArg<SfxGlobalNameItem>(SID_INSERT_OBJECT);
444 if ( nSlotId == SID_INSERT_OBJECT && pNameItem )
445 {
446 const SvGlobalName& aClassName = pNameItem->GetValue();
448 GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName.GetByteSequence(), aName );
449 }
450 else
451 {
452 switch ( nSlotId )
453 {
454 case SID_INSERT_OBJECT :
455 {
456 aServerLst.FillInsertObjects();
458 {
459 aServerLst.Remove( GraphicDocShell::Factory().GetClassId() );
460 }
461 else
462 {
463 aServerLst.Remove( DrawDocShell::Factory().GetClassId() );
464 }
465
466 [[fallthrough]];
467 }
468 case SID_INSERT_FLOATINGFRAME :
469 {
472 pFact->CreateInsertObjectDialog( mpViewShell->GetFrameWeld(), SD_MOD()->GetSlotPool()->GetSlot(nSlotId)->GetCommand(),
473 xStorage, &aServerLst ));
474 pDlg->Execute();
475 bCreateNew = pDlg->IsCreateNew();
476 xObj = pDlg->GetObject();
477
478 xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType );
479 if ( xIconMetaFile.is() )
480 nAspect = embed::Aspects::MSOLE_ICON;
481
482 if ( xObj.is() )
484
485 break;
486 }
487 }
488 }
489
490 try
491 {
492 if (xObj.is())
493 {
494 bool bInsertNewObject = true;
495
496 Size aSize;
497 MapUnit aMapUnit = MapUnit::Map100thMM;
498 if ( nAspect != embed::Aspects::MSOLE_ICON )
499 {
500 awt::Size aSz;
501 try
502 {
503 aSz = xObj->getVisualAreaSize( nAspect );
504 }
505 catch( embed::NoVisualAreaSizeException& )
506 {
507 // the default size will be set later
508 }
509
510 aSize =Size( aSz.Width, aSz.Height );
511
512 aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
513 if (aSize.IsEmpty())
514 {
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 );
522 }
523 else
524 {
525 aSize = OutputDevice::LogicToLogic(aSize, MapMode(aMapUnit), MapMode(MapUnit::Map100thMM));
526 }
527 }
528
529 if ( mpView->AreObjectsMarked() )
530 {
531 // as an empty OLE object available?
532 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
533
534 if (rMarkList.GetMarkCount() == 1)
535 {
536 SdrMark* pMark = rMarkList.GetMark(0);
537 SdrObject* pObj = pMark->GetMarkedSdrObj();
538
539 if (pObj->GetObjInventor() == SdrInventor::Default &&
540 pObj->GetObjIdentifier() == SdrObjKind::OLE2)
541 {
542 if ( !static_cast<SdrOle2Obj*>(pObj)->GetObjRef().is() )
543 {
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();
553
554 if ( nAspect == embed::Aspects::MSOLE_ICON )
555 {
556 if( xIconMetaFile.is() )
557 static_cast<SdrOle2Obj*>(pObj)->SetGraphicToObj( xIconMetaFile, aIconMediaType );
558 }
559 else
560 {
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 );
564 }
565 }
566 }
567 }
568 }
569
570 if (bInsertNewObject)
571 {
572 // we create a new OLE object
574 Size aPageSize = pPV->GetPage()->GetSize();
575
576 // get the size from the iconified object
577 ::svt::EmbeddedObjectRef aObjRef( xObj, nAspect );
578 if ( nAspect == embed::Aspects::MSOLE_ICON )
579 {
580 aObjRef.SetGraphicStream( xIconMetaFile, aIconMediaType );
581 MapMode aMapMode( MapUnit::Map100thMM );
582 aSize = aObjRef.GetSize( &aMapMode );
583 }
584
585 Point aPnt ((aPageSize.Width() - aSize.Width()) / 2,
586 (aPageSize.Height() - aSize.Height()) / 2);
587 ::tools::Rectangle aRect (aPnt, aSize);
590 aObjRef,
591 aName,
592 aRect);
593
594 if( mpView->InsertObjectAtView(pObj.get(), *pPV, SdrInsertFlags::SETDEFLAYER) )
595 {
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
598 // ActivateObject.
599
600 if ( nAspect != embed::Aspects::MSOLE_ICON )
601 {
602 try
603 {
604 awt::Size aSz = xObj->getVisualAreaSize( nAspect );
605
606 Size aNewSize = OutputDevice::LogicToLogic( Size( aSz.Width, aSz.Height ),
607 MapMode( aMapUnit ), MapMode( MapUnit::Map100thMM ) );
608 if ( aNewSize != aSize )
609 {
610 aRect.SetSize( aNewSize );
611 pObj->SetLogicRect( aRect );
612 }
613 }
614 catch( embed::NoVisualAreaSizeException& )
615 {}
616 }
617
618 if (bCreateNew)
619 {
620 pObj->SetLogicRect(aRect);
621
622 if ( nAspect != embed::Aspects::MSOLE_ICON )
623 {
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 );
627 }
628
629 mpViewShell->ActivateObject(pObj.get(), embed::EmbedVerbs::MS_OLEVERB_SHOW);
630 }
631
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);
636 }
637 }
638 }
639 }
640 catch (uno::Exception&)
641 {
642 // For some reason the object can not be inserted. For example
643 // because it is password protected and is not properly unlocked.
644 }
645 }
646}
647
649 ViewShell* pViewSh,
650 ::sd::Window* pWin,
651 ::sd::View* pView,
652 SdDrawDocument* pDoc,
653 SfxRequest& rReq)
654 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
655{
656}
657
659{
660 rtl::Reference<FuPoor> xFunc( new FuInsertAVMedia( pViewSh, pWin, pView, pDoc, rReq ) );
661 xFunc->DoExecute(rReq);
662 return xFunc;
663}
664
666{
667#if HAVE_FEATURE_AVMEDIA
668 OUString aURL;
669 const SfxItemSet* pReqArgs = rReq.GetArgs();
670 bool bAPI = false;
671
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;
675 Size aPrefSize;
676
677 if( pReqArgs )
678 {
679 const SfxStringItem* pStringItem = dynamic_cast<const SfxStringItem*>( &pReqArgs->Get( rReq.GetSlot() ) );
680
681 if( pStringItem )
682 {
683 aURL = pStringItem->GetValue();
684 bAPI = !aURL.isEmpty();
685 }
686 }
687
688 bool bLink(pLinkItem ? pLinkItem->GetValue() : true);
689 if (!(bAPI
690 || ::avmedia::MediaWindow::executeMediaURLDialog(mpWindow ? mpWindow->GetFrameWeld() : nullptr, aURL, & bLink)
691 ))
692 return;
693
694 if (!bSizeUnknown)
695 {
696 aPrefSize = pSizeItem->GetSize();
697 }
698 else
699 {
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.
702 if( mpWindow )
703 mpWindow->EnterWait();
704
705 css::uno::Reference<css::frame::XDispatchProvider> xDispatchProvider(mpViewShell->GetViewFrame()->GetFrame().GetFrameInterface(), css::uno::UNO_QUERY);
706
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);
711 }));
712
713 const bool bIsMediaURL = ::avmedia::MediaWindow::isMediaURL(aURL, "", true, xPlayerListener);
714
715 if( mpWindow )
716 mpWindow->LeaveWait();
717
718 if (!bIsMediaURL && !bAPI)
720
721 return;
722 }
723
724 InsertMediaURL(aURL, aPrefSize, bLink);
725
726#else
727 (void)rReq;
728#endif
729}
730
731#if HAVE_FEATURE_AVMEDIA
732void FuInsertAVMedia::InsertMediaURL(const OUString& rURL, const Size& rPrefSize, bool bLink)
733{
734 if( mpWindow )
735 mpWindow->EnterWait();
736
737 Point aPos;
738 Size aSize;
739 sal_Int8 nAction = DND_ACTION_COPY;
740
741 if (rPrefSize.Width() && rPrefSize.Height())
742 {
743 if( mpWindow )
744 aSize = mpWindow->PixelToLogic(rPrefSize, MapMode(MapUnit::Map100thMM));
745 else
746 aSize = Application::GetDefaultDevice()->PixelToLogic(rPrefSize, MapMode(MapUnit::Map100thMM));
747 }
748 else
749 aSize = Size( 5000, 5000 );
750
751 if( mpWindow )
752 {
753 aPos = mpWindow->PixelToLogic( ::tools::Rectangle( aPos, mpWindow->GetOutputSizePixel() ).Center() );
754 aPos.AdjustX( -(aSize.Width() >> 1) );
755 aPos.AdjustY( -(aSize.Height() >> 1) );
756 }
757
758 mpView->InsertMediaURL(rURL, nAction, aPos, aSize, bLink);
759
760 if( mpWindow )
761 mpWindow->LeaveWait();
762}
763#endif
764
765} // end of namespace sd
766
767/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static OutputDevice * GetDefaultDevice()
static void AdaptDefaultsForChart(const css::uno::Reference< css::embed::XEmbeddedObject > &xEmbObj)
const OUString & GetValue() const
static DialogMask HandleError(ErrCode nId, weld::Window *pParent=nullptr, DialogMask nMask=DialogMask::MAX)
static GraphicFilter & GetGraphicFilter()
static ErrCode LoadGraphic(const OUString &rPath, const OUString &rFilter, Graphic &rGraphic, GraphicFilter *pFilter=nullptr, sal_uInt16 *pDeterminedFormat=nullptr)
Degree10 getRotation() const
bool read(Graphic const &rGraphic)
void rotate(Degree10 aRotation)
const OUString & GetDescription() const
const OUString & GetURL() const
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
tools::Long AdjustY(tools::Long nVertMove)
tools::Long AdjustX(tools::Long nHorzMove)
SAL_DLLPRIVATE DocumentType GetDocumentType() const
Definition: drawdoc.hxx:251
static void HandleGraphicFilterError(ErrCode nFilterError, ErrCode nStreamError)
bool IsPresObj(const SdrObject *pObj)
Definition: sdpage.cxx:2322
void InsertPresObj(SdrObject *pObj, PresObjKind eKind)
inserts the given SdrObject into the presentation object list
Definition: sdpage.cxx:2338
void ReplaceObjectAtView(SdrObject *pOldObj, SdrPageView &rPV, SdrObject *pNewObj, bool bMark=true)
bool InsertObjectAtView(SdrObject *pObj, SdrPageView &rPV, SdrInsertFlags nOptions=SdrInsertFlags::NONE)
void SetGraphicLink(const OUString &rFileName)
size_t GetMarkCount() const
SdrMark * GetMark(size_t nNum) const
const SdrMarkList & GetMarkedObjectList() const
bool AreObjectsMarked() const
SdrObject * GetMarkedSdrObj() const
virtual bool IsTextEdit() const final override
SdrObjUserCall * GetUserCall() const
void SetEmptyPresObj(bool bEpt)
virtual SdrInventor GetObjInventor() const
virtual SdrObjKind GetObjIdentifier() const
SdrPage * getSdrPageFromSdrObject() const
virtual const tools::Rectangle & GetLogicRect() const
void SetGraphicToObj(const Graphic &aGraphic)
SdrPage * GetPage() const
Size GetSize() const
SdrModel & getSdrModelFromSdrView() const
SdrPageView * GetSdrPageView() const
bool GetValue() const
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
const SvGlobalName & GetValue() const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
comphelper::EmbeddedObjectContainer & GetEmbeddedObjectContainer() const
virtual void SetVisArea(const tools::Rectangle &rVisArea)
sal_uInt16 GetSlot() const
const SfxItemSet * GetArgs() const
const T * GetArg(sal_uInt16 nSlotId) const
virtual SfxObjectShell * GetObjectShell()
SfxFrame & GetFrame() const
virtual SfxObjectShell * GetObjectShell() override
bool IsEmpty() const
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
css::uno::Sequence< sal_Int8 > GetByteSequence() const
void Remove(const SvGlobalName &)
static SvxAbstractDialogFactory * Create()
OUString GetPath() const
ErrCode GetGraphic(Graphic &) const
bool IsAsLink() const
const Size & GetSize() const
static TransferableDataHelper CreateFromSystemClipboard(vcl::Window *pWindow)
bool HasFormat(SotClipboardFormatId nFormat) const
const css::uno::Reference< css::datatransfer::XTransferable > & GetTransferable() const
bool GetINetBookmark(SotClipboardFormatId nFormat, INetBookmark &rBmk) const
static MapUnit UnoEmbed2VCLMapUnit(sal_Int32 nUnoEmbedMapUnit)
static void dispatchInsertAVMedia(const css::uno::Reference< css::frame::XDispatchProvider > &, const css::awt::Size &rSize, const OUString &rURL, bool bLink)
static bool executeMediaURLDialog(weld::Window *pParent, OUString &rURL, bool *const o_pbLink)
static bool isMediaURL(std::u16string_view rURL, const OUString &rReferer, bool bDeep=false, rtl::Reference< PlayerListener > xPreferredPixelSizeListener=nullptr)
static void executeFormatErrorBox(weld::Window *pParent)
bool InsertEmbeddedObject(const css::uno::Reference< css::embed::XEmbeddedObject > &, OUString &)
static css::uno::Reference< css::embed::XStorage > GetTemporaryStorage(const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
#define SO3_SCH_CLASSID
#define SO3_SC_CLASSID
#define SO3_SM_CLASSID
Base class of the stacked shells that provide graphical views to Draw and Impress documents and editi...
void InsertURLField(const OUString &rURL, const OUString &rText, const OUString &rTarget)
Definition: drviewse.cxx:1481
virtual void DoExecute(SfxRequest &rReq) override
Definition: fuinsert.cxx:665
static rtl::Reference< FuPoor > Create(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
Definition: fuinsert.cxx:658
FuInsertAVMedia(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
Definition: fuinsert.cxx:648
virtual void DoExecute(SfxRequest &rReq) override
Definition: fuinsert.cxx:212
static rtl::Reference< FuPoor > Create(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
Definition: fuinsert.cxx:205
FuInsertClipboard(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
Definition: fuinsert.cxx:195
FuInsertGraphic(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq, bool replaceExistingImage)
Definition: fuinsert.cxx:87
bool mbReplaceExistingImage
Definition: fuinsert.hxx:47
static rtl::Reference< FuPoor > Create(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq, bool replaceExistingImage)
Definition: fuinsert.cxx:99
virtual void DoExecute(SfxRequest &rReq) override
Definition: fuinsert.cxx:107
FuInsertOLE(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
Definition: fuinsert.cxx:263
static rtl::Reference< FuPoor > Create(ViewShell *pViewSh, ::sd::Window *pWin, ::sd::View *pView, SdDrawDocument *pDoc, SfxRequest &rReq)
Definition: fuinsert.cxx:273
virtual void DoExecute(SfxRequest &rReq) override
Definition: fuinsert.cxx:280
Base class for all functions.
Definition: fupoor.hxx:48
SdDrawDocument * mpDoc
Definition: fupoor.hxx:148
VclPtr< ::sd::Window > mpWindow
Definition: fupoor.hxx:146
ViewShell * mpViewShell
Definition: fupoor.hxx:145
sal_uInt16 nSlotId
Definition: fupoor.hxx:150
DrawDocShell * mpDocSh
Definition: fupoor.hxx:147
::sd::View * mpView
Definition: fupoor.hxx:144
Base class of the stacked shell hierarchy.
Definition: ViewShell.hxx:92
virtual bool ActivateObject(SdrOle2Obj *pObj, sal_Int32 nVerb)
Definition: viewshe2.cxx:624
virtual void VisAreaChanged(const ::tools::Rectangle &rRect)
this method is called when the visible area of the view from this viewshell is changed
Definition: viewshe2.cxx:902
SD_DLLPUBLIC weld::Window * GetFrameWeld() const
Definition: viewshel.cxx:1582
SD_DLLPUBLIC SfxViewFrame * GetViewFrame() const
Definition: viewshel.cxx:118
SdrGrafObj * InsertGraphic(const Graphic &rGraphic, sal_Int8 &rAction, const Point &rPos, SdrObject *pSelectedObj, ImageMap const *pImageMap)
If an empty graphic object is provided, we fill it.
Definition: sdview4.cxx:78
SdrObject * GetSelectedSingleObject(SdPage const *pPage)
Definition: sdview5.cxx:58
bool InsertData(const TransferableDataHelper &rDataHelper, const Point &rPos, sal_Int8 &rDnDAction, bool bDrag, SotClipboardFormatId nFormat=SotClipboardFormatId::NONE, sal_uInt16 nPage=SDRPAGE_NOTFOUND, SdrLayerID nLayer=SDRLAYER_NOTFOUND)
Definition: sdview3.cxx:254
virtual SdrEndTextEditKind SdrEndTextEdit(bool bDontDeleteReally=false) override
ends current text editing
Definition: sdview.cxx:772
SdrObject * GetEmptyPresentationObject(PresObjKind eKind)
Definition: sdview5.cxx:79
SdPage * GetPage()
Definition: sdview5.cxx:45
void InsertMediaURL(const OUString &rMediaURL, sal_Int8 &rAction, const Point &rPos, const Size &rSize, bool const bLink)
Definition: sdview4.cxx:301
An SdWindow contains the actual working area of ViewShell.
Definition: Window.hxx:45
void SetGraphicStream(const css::uno::Reference< css::io::XInputStream > &xInGrStream, const OUString &rMediaType)
Size GetSize(MapMode const *pTargetMapMode) const
constexpr Point Center() const
constexpr tools::Long GetWidth() const
void SetSize(const Size &)
constexpr Size GetSize() const
constexpr tools::Long GetHeight() const
URL aURL
#define ERRCODE_NONE
SotClipboardFormatId
#define ERRCODE_GRFILTER_OPENERROR
OUString aName
MapUnit
const char GetValue[]
PresObjKind
Definition: pres.hxx:22
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83
#define SD_MOD()
Definition: sdmod.hxx:184
#define ERRCODE_SFX_OLEGENERAL
#define DND_ACTION_COPY
#define DND_ACTION_LINK
signed char sal_Int8
RET_OK