Line data Source code
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 "fuinsert.hxx"
21 :
22 : #include <comphelper/storagehelper.hxx>
23 : #include <comphelper/processfactory.hxx>
24 : #include <toolkit/helper/vclunohelper.hxx>
25 : #include <svx/svxdlg.hxx>
26 : #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
27 : #include <com/sun/star/embed/XComponentSupplier.hpp>
28 : #include <com/sun/star/embed/Aspects.hpp>
29 : #include <com/sun/star/beans/XPropertySet.hpp>
30 : #include <com/sun/star/chart2/XChartDocument.hpp>
31 : #include <com/sun/star/drawing/FillStyle.hpp>
32 : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
33 :
34 : #include <tools/urlobj.hxx>
35 : #include <svl/urihelper.hxx>
36 : #include <sfx2/docfile.hxx>
37 : #include <sfx2/msgpool.hxx>
38 : #include <svtools/sores.hxx>
39 : #include <svtools/insdlg.hxx>
40 : #include <sfx2/request.hxx>
41 : #include <svl/globalnameitem.hxx>
42 : #include <unotools/pathoptions.hxx>
43 : #include <svtools/miscopt.hxx>
44 : #include <svtools/embedhlp.hxx>
45 : #include <svx/pfiledlg.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 <unotools/ucbstreamhelper.hxx>
52 : #include <sfx2/printer.hxx>
53 : #include <comphelper/classids.hxx>
54 : #include <svtools/sfxecode.hxx>
55 : #include <svtools/transfer.hxx>
56 : #include <svl/urlbmk.hxx>
57 : #include <svx/svdobj.hxx>
58 : #include <svx/svdograf.hxx>
59 : #include <svx/svdoole2.hxx>
60 : #include <svx/svdomedia.hxx>
61 : #include <editeng/editeng.hxx>
62 : #include <sot/storage.hxx>
63 : #include <sot/formats.hxx>
64 : #include <svx/svdpagv.hxx>
65 : #include <vcl/msgbox.hxx>
66 : #include <sfx2/opengrf.hxx>
67 : #include <sfx2/viewfrm.hxx>
68 : #include <svx/charthelper.hxx>
69 :
70 : #include "app.hrc"
71 : #include "sdresid.hxx"
72 : #include "View.hxx"
73 : #include "sdmod.hxx"
74 : #include "Window.hxx"
75 : #include "drawview.hxx"
76 : #include "DrawViewShell.hxx"
77 : #include "DrawDocShell.hxx"
78 : #include "GraphicDocShell.hxx"
79 : #include "strings.hrc"
80 : #include "drawdoc.hxx"
81 : #include "sdgrffilter.hxx"
82 : #include "sdxfer.hxx"
83 : #include <vcl/svapp.hxx>
84 : #include "undo/undoobjects.hxx"
85 : #include <boost/scoped_ptr.hpp>
86 : #include "glob.hrc"
87 :
88 : #include <config_features.h>
89 :
90 : using namespace com::sun::star;
91 :
92 : namespace sd {
93 :
94 0 : TYPEINIT1( FuInsertGraphic, FuPoor );
95 0 : TYPEINIT1( FuInsertClipboard, FuPoor );
96 0 : TYPEINIT1( FuInsertOLE, FuPoor );
97 0 : TYPEINIT1( FuInsertAVMedia, FuPoor );
98 :
99 0 : FuInsertGraphic::FuInsertGraphic (
100 : ViewShell* pViewSh,
101 : ::sd::Window* pWin,
102 : ::sd::View* pView,
103 : SdDrawDocument* pDoc,
104 : SfxRequest& rReq)
105 0 : : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
106 : {
107 0 : }
108 :
109 0 : rtl::Reference<FuPoor> FuInsertGraphic::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
110 : {
111 0 : rtl::Reference<FuPoor> xFunc( new FuInsertGraphic( pViewSh, pWin, pView, pDoc, rReq ) );
112 0 : xFunc->DoExecute(rReq);
113 0 : return xFunc;
114 : }
115 :
116 0 : void FuInsertGraphic::DoExecute( SfxRequest& )
117 : {
118 0 : SvxOpenGraphicDialog aDlg(SdResId(STR_INSERTGRAPHIC));
119 :
120 0 : if( aDlg.Execute() == GRFILTER_OK )
121 : {
122 0 : Graphic aGraphic;
123 0 : int nError = aDlg.GetGraphic(aGraphic);
124 0 : if( nError == GRFILTER_OK )
125 : {
126 0 : if( mpViewShell && mpViewShell->ISA(DrawViewShell))
127 : {
128 0 : sal_Int8 nAction = DND_ACTION_COPY;
129 : SdrObject* pPickObj;
130 0 : bool bSelectionReplaced(false);
131 :
132 0 : if( ( pPickObj = mpView->GetSelectedSingleObject( mpView->GetPage() ) ) || ( pPickObj = mpView->GetEmptyPresentationObject( PRESOBJ_GRAPHIC ) ) )
133 : {
134 0 : nAction = DND_ACTION_LINK;
135 : }
136 0 : else if(1 == mpView->GetMarkedObjectCount())
137 : {
138 0 : pPickObj = mpView->GetMarkedObjectByIndex(0);
139 0 : nAction = DND_ACTION_MOVE;
140 0 : bSelectionReplaced = true;
141 : }
142 :
143 0 : Point aPos;
144 0 : Rectangle aRect(aPos, mpWindow->GetOutputSizePixel() );
145 0 : aPos = aRect.Center();
146 0 : aPos = mpWindow->PixelToLogic(aPos);
147 0 : SdrGrafObj* pGrafObj = mpView->InsertGraphic(aGraphic, nAction, aPos, pPickObj, NULL);
148 :
149 0 : if(pGrafObj && aDlg.IsAsLink())
150 : {
151 : // really store as link only?
152 0 : if( SvtMiscOptions().ShowLinkWarningDialog() )
153 : {
154 0 : ScopedVclPtrInstance< SvxLinkWarningDialog > aWarnDlg(mpWindow,aDlg.GetPath());
155 0 : if( aWarnDlg->Execute() != RET_OK )
156 0 : return; // don't store as link
157 : }
158 :
159 : // store as link
160 0 : OUString aFltName(aDlg.GetCurrentFilter());
161 0 : OUString aPath(aDlg.GetPath());
162 0 : OUString aReferer;
163 0 : if (mpDocSh->HasName()) {
164 0 : aReferer = mpDocSh->GetMedium()->GetName();
165 : }
166 0 : pGrafObj->SetGraphicLink(aPath, aReferer, aFltName);
167 : }
168 :
169 0 : if(bSelectionReplaced && pGrafObj)
170 : {
171 0 : mpView->MarkObj(pGrafObj, mpView->GetSdrPageView());
172 : }
173 : }
174 : }
175 : else
176 : {
177 0 : SdGRFFilter::HandleGraphicFilterError( (sal_uInt16)nError, GraphicFilter::GetGraphicFilter().GetLastError().nStreamError );
178 0 : }
179 0 : }
180 : }
181 :
182 0 : FuInsertClipboard::FuInsertClipboard (
183 : ViewShell* pViewSh,
184 : ::sd::Window* pWin,
185 : ::sd::View* pView,
186 : SdDrawDocument* pDoc,
187 : SfxRequest& rReq)
188 0 : : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
189 : {
190 0 : }
191 :
192 0 : rtl::Reference<FuPoor> FuInsertClipboard::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
193 : {
194 0 : rtl::Reference<FuPoor> xFunc( new FuInsertClipboard( pViewSh, pWin, pView, pDoc, rReq ) );
195 0 : xFunc->DoExecute(rReq);
196 0 : return xFunc;
197 : }
198 :
199 0 : void FuInsertClipboard::DoExecute( SfxRequest& )
200 : {
201 0 : TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpWindow ) );
202 : SotClipboardFormatId nFormatId;
203 :
204 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
205 0 : boost::scoped_ptr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog( mpViewShell->GetActiveWindow() ));
206 0 : if ( pDlg )
207 : {
208 0 : ::com::sun::star::datatransfer::DataFlavor aFlavor;
209 :
210 0 : pDlg->Insert( SotClipboardFormatId::EMBED_SOURCE, OUString() );
211 0 : pDlg->Insert( SotClipboardFormatId::LINK_SOURCE, OUString() );
212 0 : pDlg->Insert( SotClipboardFormatId::DRAWING, OUString() );
213 0 : pDlg->Insert( SotClipboardFormatId::SVXB, OUString() );
214 0 : pDlg->Insert( SotClipboardFormatId::GDIMETAFILE, OUString() );
215 0 : pDlg->Insert( SotClipboardFormatId::BITMAP, OUString() );
216 0 : pDlg->Insert( SotClipboardFormatId::NETSCAPE_BOOKMARK, OUString() );
217 0 : pDlg->Insert( SotClipboardFormatId::STRING, OUString() );
218 0 : pDlg->Insert( SotClipboardFormatId::HTML, OUString() );
219 0 : pDlg->Insert( SotClipboardFormatId::RTF, OUString() );
220 0 : pDlg->Insert( SotClipboardFormatId::EDITENGINE, OUString() );
221 :
222 : //TODO/MBA: testing
223 0 : nFormatId = pDlg->GetFormat( aDataHelper );
224 0 : if( nFormatId != SotClipboardFormatId::NONE && aDataHelper.GetTransferable().is() )
225 : {
226 0 : sal_Int8 nAction = DND_ACTION_COPY;
227 :
228 0 : if( !mpView->InsertData( aDataHelper,
229 0 : mpWindow->PixelToLogic( Rectangle( Point(), mpWindow->GetOutputSizePixel() ).Center() ),
230 0 : nAction, false, nFormatId ) &&
231 0 : ( mpViewShell && mpViewShell->ISA( DrawViewShell ) ) )
232 : {
233 0 : DrawViewShell* pDrViewSh = static_cast<DrawViewShell*>(mpViewShell);
234 0 : INetBookmark aINetBookmark( aEmptyStr, aEmptyStr );
235 :
236 0 : if( ( aDataHelper.HasFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK ) &&
237 0 : aDataHelper.GetINetBookmark( SotClipboardFormatId::NETSCAPE_BOOKMARK, aINetBookmark ) ) ||
238 0 : ( aDataHelper.HasFormat( SotClipboardFormatId::FILEGRPDESCRIPTOR ) &&
239 0 : aDataHelper.GetINetBookmark( SotClipboardFormatId::FILEGRPDESCRIPTOR, aINetBookmark ) ) ||
240 0 : ( aDataHelper.HasFormat( SotClipboardFormatId::UNIFORMRESOURCELOCATOR ) &&
241 0 : aDataHelper.GetINetBookmark( SotClipboardFormatId::UNIFORMRESOURCELOCATOR, aINetBookmark ) ) )
242 : {
243 0 : pDrViewSh->InsertURLField( aINetBookmark.GetURL(), aINetBookmark.GetDescription(), aEmptyStr, NULL );
244 0 : }
245 : }
246 0 : }
247 0 : }
248 0 : }
249 :
250 0 : FuInsertOLE::FuInsertOLE (
251 : ViewShell* pViewSh,
252 : ::sd::Window* pWin,
253 : ::sd::View* pView,
254 : SdDrawDocument* pDoc,
255 : SfxRequest& rReq)
256 0 : : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
257 : {
258 0 : }
259 :
260 0 : rtl::Reference<FuPoor> FuInsertOLE::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
261 : {
262 0 : rtl::Reference<FuPoor> xFunc( new FuInsertOLE( pViewSh, pWin, pView, pDoc, rReq ) );
263 0 : xFunc->DoExecute(rReq);
264 0 : return xFunc;
265 : }
266 :
267 0 : void FuInsertOLE::DoExecute( SfxRequest& rReq )
268 : {
269 0 : if ( nSlotId == SID_ATTR_TABLE ||
270 0 : nSlotId == SID_INSERT_DIAGRAM ||
271 0 : nSlotId == SID_INSERT_MATH )
272 : {
273 0 : PresObjKind ePresObjKind = (nSlotId == SID_INSERT_DIAGRAM) ? PRESOBJ_CHART : PRESOBJ_OBJECT;
274 :
275 0 : SdrObject* pPickObj = mpView->GetEmptyPresentationObject( ePresObjKind );
276 :
277 : // insert diagram or Calc table
278 0 : OUString aObjName;
279 0 : SvGlobalName aName;
280 0 : if (nSlotId == SID_INSERT_DIAGRAM)
281 0 : aName = SvGlobalName( SO3_SCH_CLASSID);
282 0 : else if (nSlotId == SID_ATTR_TABLE)
283 0 : aName = SvGlobalName(SO3_SC_CLASSID);
284 0 : else if (nSlotId == SID_INSERT_MATH)
285 0 : aName = SvGlobalName(SO3_SM_CLASSID);
286 :
287 0 : uno::Reference < embed::XEmbeddedObject > xObj = mpViewShell->GetViewFrame()->GetObjectShell()->
288 0 : GetEmbeddedObjectContainer().CreateEmbeddedObject( aName.GetByteSequence(), aObjName );
289 0 : if ( xObj.is() )
290 : {
291 0 : uno::Reference<embed::XComponentSupplier> xCompSupp(xObj, uno::UNO_QUERY);
292 0 : if (xCompSupp.is())
293 : {
294 : // Create default chart type.
295 0 : uno::Reference<chart2::XChartDocument> xChartDoc(xCompSupp->getComponent(), uno::UNO_QUERY);
296 0 : if (xChartDoc.is())
297 0 : xChartDoc->createDefaultChart();
298 : }
299 :
300 0 : sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
301 :
302 0 : MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
303 :
304 0 : Rectangle aRect;
305 0 : if( pPickObj )
306 : {
307 0 : aRect = pPickObj->GetLogicRect();
308 :
309 0 : awt::Size aSz;
310 0 : aSz.Width = aRect.GetWidth();
311 0 : aSz.Height = aRect.GetHeight();
312 0 : xObj->setVisualAreaSize( nAspect, aSz );
313 : }
314 : else
315 : {
316 0 : awt::Size aSz;
317 : try
318 : {
319 0 : aSz = xObj->getVisualAreaSize( nAspect );
320 : }
321 0 : catch ( embed::NoVisualAreaSizeException& )
322 : {
323 : // the default size will be set later
324 : }
325 :
326 0 : Size aSize( aSz.Width, aSz.Height );
327 :
328 0 : if (aSize.Height() == 0 || aSize.Width() == 0)
329 : {
330 : // rectangle with balanced edge ratio
331 0 : aSize.Width() = 14100;
332 0 : aSize.Height() = 10000;
333 0 : Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aUnit );
334 0 : aSz.Width = aTmp.Width();
335 0 : aSz.Height = aTmp.Height();
336 0 : xObj->setVisualAreaSize( nAspect, aSz );
337 : }
338 : else
339 : {
340 0 : aSize = OutputDevice::LogicToLogic(aSize, aUnit, MAP_100TH_MM);
341 : }
342 :
343 0 : Point aPos;
344 0 : Rectangle aWinRect(aPos, mpWindow->GetOutputSizePixel() );
345 0 : aPos = aWinRect.Center();
346 0 : aPos = mpWindow->PixelToLogic(aPos);
347 0 : aPos.X() -= aSize.Width() / 2;
348 0 : aPos.Y() -= aSize.Height() / 2;
349 0 : aRect = Rectangle(aPos, aSize);
350 : }
351 :
352 0 : SdrOle2Obj* pOleObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aObjName, aRect );
353 0 : SdrPageView* pPV = mpView->GetSdrPageView();
354 :
355 : // if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj
356 0 : if( pPickObj )
357 : {
358 0 : SdPage* pPage = static_cast< SdPage* >(pPickObj->GetPage());
359 0 : if(pPage && pPage->IsPresObj(pPickObj))
360 : {
361 0 : pPage->InsertPresObj( pOleObj, ePresObjKind );
362 0 : pOleObj->SetUserCall(pPickObj->GetUserCall());
363 : }
364 :
365 : // #i123468# we need to end text edit before replacing the object. There cannot yet
366 : // being text typed (else it would not be an EmptyPresObj anymore), but it may be
367 : // in text edit mode
368 0 : if (mpView->IsTextEdit())
369 : {
370 0 : mpView->SdrEndTextEdit();
371 : }
372 : }
373 :
374 0 : bool bRet = true;
375 0 : if( pPickObj )
376 0 : mpView->ReplaceObjectAtView(pPickObj, *pPV, pOleObj, true );
377 : else
378 0 : bRet = mpView->InsertObjectAtView(pOleObj, *pPV, SdrInsertFlags::SETDEFLAYER);
379 :
380 0 : if( bRet )
381 : {
382 0 : if (nSlotId == SID_INSERT_DIAGRAM)
383 : {
384 0 : pOleObj->SetProgName( OUString( "StarChart" ));
385 : }
386 0 : else if (nSlotId == SID_ATTR_TABLE)
387 : {
388 0 : pOleObj->SetProgName( OUString( "StarCalc" ) );
389 : }
390 0 : else if (nSlotId == SID_INSERT_MATH)
391 : {
392 0 : pOleObj->SetProgName( OUString( "StarMath" ) );
393 : }
394 :
395 0 : pOleObj->SetLogicRect(aRect);
396 0 : Size aTmp( OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aUnit ) );
397 0 : awt::Size aVisualSize;
398 0 : aVisualSize.Width = aTmp.Width();
399 0 : aVisualSize.Height = aTmp.Height();
400 0 : xObj->setVisualAreaSize( nAspect, aVisualSize );
401 0 : mpViewShell->ActivateObject(pOleObj, SVVERB_SHOW);
402 :
403 0 : if (nSlotId == SID_INSERT_DIAGRAM)
404 : {
405 : // note, that this call modified the chart model which
406 : // results in a change notification. So call this after
407 : // everything else is finished.
408 0 : ChartHelper::AdaptDefaultsForChart( xObj );
409 : }
410 0 : }
411 : }
412 : else
413 : {
414 : ErrorHandler::HandleError(* new StringErrorInfo(ERRCODE_SFX_OLEGENERAL,
415 0 : aEmptyStr ) );
416 0 : }
417 : }
418 : else
419 : {
420 : // insert object
421 0 : sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
422 0 : bool bCreateNew = false;
423 0 : uno::Reference < embed::XEmbeddedObject > xObj;
424 0 : uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
425 0 : SvObjectServerList aServerLst;
426 0 : OUString aName;
427 :
428 0 : OUString aIconMediaType;
429 0 : uno::Reference< io::XInputStream > xIconMetaFile;
430 :
431 0 : SFX_REQUEST_ARG( rReq, pNameItem, SfxGlobalNameItem, SID_INSERT_OBJECT, false );
432 0 : if ( nSlotId == SID_INSERT_OBJECT && pNameItem )
433 : {
434 0 : SvGlobalName aClassName = pNameItem->GetValue();
435 0 : xObj = mpViewShell->GetViewFrame()->GetObjectShell()->
436 0 : GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName.GetByteSequence(), aName );
437 : }
438 : else
439 : {
440 0 : switch ( nSlotId )
441 : {
442 : case SID_INSERT_OBJECT :
443 : {
444 0 : aServerLst.FillInsertObjects();
445 0 : if (mpDoc->GetDocumentType() == DOCUMENT_TYPE_DRAW)
446 : {
447 0 : aServerLst.Remove( GraphicDocShell::Factory().GetClassId() );
448 : }
449 : else
450 : {
451 0 : aServerLst.Remove( DrawDocShell::Factory().GetClassId() );
452 : }
453 :
454 : // intentionally no break!
455 : }
456 : case SID_INSERT_PLUGIN :
457 : case SID_INSERT_FLOATINGFRAME :
458 : {
459 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
460 : boost::scoped_ptr<SfxAbstractInsertObjectDialog> pDlg(
461 0 : pFact->CreateInsertObjectDialog( mpViewShell->GetActiveWindow(), SD_MOD()->GetSlotPool()->GetSlot(nSlotId)->GetCommandString(),
462 0 : xStorage, &aServerLst ));
463 0 : if ( pDlg )
464 : {
465 0 : pDlg->Execute();
466 0 : bCreateNew = pDlg->IsCreateNew();
467 0 : xObj = pDlg->GetObject();
468 :
469 0 : xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType );
470 0 : if ( xIconMetaFile.is() )
471 0 : nAspect = embed::Aspects::MSOLE_ICON;
472 :
473 0 : if ( xObj.is() )
474 0 : mpViewShell->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aName );
475 : }
476 :
477 0 : break;
478 : }
479 : case SID_INSERT_SOUND :
480 : case SID_INSERT_VIDEO :
481 : {
482 : // create special filedialog for plugins
483 0 : SvxPluginFileDlg aPluginFileDialog (mpWindow, nSlotId);
484 0 : if( ERRCODE_NONE == aPluginFileDialog.Execute () )
485 : {
486 : // get URL
487 0 : OUString aStrURL(aPluginFileDialog.GetPath());
488 0 : INetURLObject aURL( aStrURL, INetProtocol::File );
489 0 : if( aURL.GetProtocol() != INetProtocol::NotValid )
490 : {
491 : // create a plugin object
492 0 : xObj = mpViewShell->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_PLUGIN_CLASSID ).GetByteSequence(), aName );
493 : }
494 :
495 0 : if ( xObj.is() && svt::EmbeddedObjectRef::TryRunningState( xObj ) )
496 : {
497 : // set properties from dialog
498 0 : uno::Reference < embed::XComponentSupplier > xSup( xObj, uno::UNO_QUERY );
499 0 : if ( xSup.is() )
500 : {
501 0 : uno::Reference < beans::XPropertySet > xSet( xSup->getComponent(), uno::UNO_QUERY );
502 0 : if ( xSet.is() )
503 : {
504 0 : xSet->setPropertyValue("PluginURL",
505 0 : uno::makeAny( OUString( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) );
506 0 : }
507 0 : }
508 : }
509 : else
510 : {
511 : // unable to create PlugIn
512 0 : OUString aStrErr( SdResId( STR_ERROR_OBJNOCREATE_PLUGIN ) );
513 0 : aStrErr = aStrErr.replaceFirst( "%", aStrURL );
514 0 : ScopedVclPtrInstance<MessageDialog>::Create(mpWindow, aStrErr)->Execute();
515 0 : }
516 0 : }
517 : }
518 : }
519 : }
520 :
521 : try
522 : {
523 0 : if (xObj.is())
524 : {
525 : //TODO/LATER: needs status for RESIZEONPRINTERCHANGE
526 : //if( SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE & xObj->getStatus( nAspect ) )
527 : // aIPObj->OnDocumentPrinterChanged( mpDocSh->GetPrinter(sal_False) );
528 :
529 0 : bool bInsertNewObject = true;
530 :
531 0 : Size aSize;
532 0 : MapUnit aMapUnit = MAP_100TH_MM;
533 0 : if ( nAspect != embed::Aspects::MSOLE_ICON )
534 : {
535 0 : awt::Size aSz;
536 : try
537 : {
538 0 : aSz = xObj->getVisualAreaSize( nAspect );
539 : }
540 0 : catch( embed::NoVisualAreaSizeException& )
541 : {
542 : // the default size will be set later
543 : }
544 :
545 0 : aSize =Size( aSz.Width, aSz.Height );
546 :
547 0 : aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
548 0 : if (aSize.Height() == 0 || aSize.Width() == 0)
549 : {
550 : // rectangle with balanced edge ratio
551 0 : aSize.Width() = 14100;
552 0 : aSize.Height() = 10000;
553 0 : Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aMapUnit );
554 0 : aSz.Width = aTmp.Width();
555 0 : aSz.Height = aTmp.Height();
556 0 : xObj->setVisualAreaSize( nAspect, aSz );
557 : }
558 : else
559 : {
560 0 : aSize = OutputDevice::LogicToLogic(aSize, aMapUnit, MAP_100TH_MM);
561 : }
562 : }
563 :
564 0 : if ( mpView->AreObjectsMarked() )
565 : {
566 : // as an empty OLE object available?
567 0 : const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
568 :
569 0 : if (rMarkList.GetMarkCount() == 1)
570 : {
571 0 : SdrMark* pMark = rMarkList.GetMark(0);
572 0 : SdrObject* pObj = pMark->GetMarkedSdrObj();
573 :
574 0 : if (pObj->GetObjInventor() == SdrInventor &&
575 0 : pObj->GetObjIdentifier() == OBJ_OLE2)
576 : {
577 0 : if ( !static_cast<SdrOle2Obj*>(pObj)->GetObjRef().is() )
578 : {
579 : // the empty OLE object gets a new IPObj
580 0 : bInsertNewObject = false;
581 0 : pObj->SetEmptyPresObj(false);
582 0 : static_cast<SdrOle2Obj*>(pObj)->SetOutlinerParaObject(NULL);
583 0 : static_cast<SdrOle2Obj*>(pObj)->SetObjRef(xObj);
584 0 : static_cast<SdrOle2Obj*>(pObj)->SetPersistName(aName);
585 0 : static_cast<SdrOle2Obj*>(pObj)->SetName(aName);
586 0 : static_cast<SdrOle2Obj*>(pObj)->SetAspect(nAspect);
587 0 : Rectangle aRect = static_cast<SdrOle2Obj*>(pObj)->GetLogicRect();
588 :
589 0 : if ( nAspect == embed::Aspects::MSOLE_ICON )
590 : {
591 0 : if( xIconMetaFile.is() )
592 0 : static_cast<SdrOle2Obj*>(pObj)->SetGraphicToObj( xIconMetaFile, aIconMediaType );
593 : }
594 : else
595 : {
596 0 : Size aTmp = OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aMapUnit );
597 0 : awt::Size aSz( aTmp.Width(), aTmp.Height() );
598 0 : xObj->setVisualAreaSize( nAspect, aSz );
599 : }
600 : }
601 : }
602 : }
603 : }
604 :
605 0 : if (bInsertNewObject)
606 : {
607 : // we create a new OLE object
608 0 : SdrPageView* pPV = mpView->GetSdrPageView();
609 0 : Size aPageSize = pPV->GetPage()->GetSize();
610 :
611 : // get the size from the iconified object
612 0 : ::svt::EmbeddedObjectRef aObjRef( xObj, nAspect );
613 0 : if ( nAspect == embed::Aspects::MSOLE_ICON )
614 : {
615 0 : aObjRef.SetGraphicStream( xIconMetaFile, aIconMediaType );
616 0 : MapMode aMapMode( MAP_100TH_MM );
617 0 : aSize = aObjRef.GetSize( &aMapMode );
618 : }
619 :
620 0 : Point aPnt ((aPageSize.Width() - aSize.Width()) / 2,
621 0 : (aPageSize.Height() - aSize.Height()) / 2);
622 0 : Rectangle aRect (aPnt, aSize);
623 :
624 0 : SdrOle2Obj* pObj = new SdrOle2Obj( aObjRef, aName, aRect);
625 :
626 0 : if( mpView->InsertObjectAtView(pObj, *pPV, SdrInsertFlags::SETDEFLAYER) )
627 : {
628 : // Math objects change their object size during InsertObject.
629 : // New size must be set in SdrObject, or a wrong scale will be set at
630 : // ActivateObject.
631 :
632 0 : if ( nAspect != embed::Aspects::MSOLE_ICON )
633 : {
634 : try
635 : {
636 0 : awt::Size aSz = xObj->getVisualAreaSize( nAspect );
637 :
638 : Size aNewSize = Window::LogicToLogic( Size( aSz.Width, aSz.Height ),
639 0 : MapMode( aMapUnit ), MapMode( MAP_100TH_MM ) );
640 0 : if ( aNewSize != aSize )
641 : {
642 0 : aRect.SetSize( aNewSize );
643 0 : pObj->SetLogicRect( aRect );
644 : }
645 : }
646 0 : catch( embed::NoVisualAreaSizeException& )
647 : {}
648 : }
649 :
650 0 : if (bCreateNew)
651 : {
652 0 : pObj->SetLogicRect(aRect);
653 :
654 0 : if ( nAspect != embed::Aspects::MSOLE_ICON )
655 : {
656 0 : Size aTmp = OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aMapUnit );
657 0 : awt::Size aSz( aTmp.Width(), aTmp.Height() );
658 0 : xObj->setVisualAreaSize( nAspect, aSz );
659 : }
660 :
661 0 : mpViewShell->ActivateObject(pObj, SVVERB_SHOW);
662 : }
663 :
664 0 : Size aVisSizePixel = mpWindow->GetOutputSizePixel();
665 0 : Rectangle aVisAreaWin = mpWindow->PixelToLogic( Rectangle( Point(0,0), aVisSizePixel) );
666 0 : mpViewShell->VisAreaChanged(aVisAreaWin);
667 0 : mpDocSh->SetVisArea(aVisAreaWin);
668 0 : }
669 : }
670 : }
671 : }
672 0 : catch (uno::Exception&)
673 : {
674 : // For some reason the object can not be inserted. For example
675 : // because it is password protected and is not properly unlocked.
676 0 : }
677 : }
678 0 : }
679 :
680 0 : FuInsertAVMedia::FuInsertAVMedia(
681 : ViewShell* pViewSh,
682 : ::sd::Window* pWin,
683 : ::sd::View* pView,
684 : SdDrawDocument* pDoc,
685 : SfxRequest& rReq)
686 0 : : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
687 : {
688 0 : }
689 :
690 0 : rtl::Reference<FuPoor> FuInsertAVMedia::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
691 : {
692 0 : rtl::Reference<FuPoor> xFunc( new FuInsertAVMedia( pViewSh, pWin, pView, pDoc, rReq ) );
693 0 : xFunc->DoExecute(rReq);
694 0 : return xFunc;
695 : }
696 :
697 0 : void FuInsertAVMedia::DoExecute( SfxRequest& rReq )
698 : {
699 0 : OUString aURL;
700 0 : const SfxItemSet* pReqArgs = rReq.GetArgs();
701 0 : bool bAPI = false;
702 :
703 0 : if( pReqArgs )
704 : {
705 0 : const SfxStringItem* pStringItem = PTR_CAST( SfxStringItem, &pReqArgs->Get( rReq.GetSlot() ) );
706 :
707 0 : if( pStringItem )
708 : {
709 0 : aURL = pStringItem->GetValue();
710 0 : bAPI = !aURL.isEmpty();
711 : }
712 : }
713 :
714 0 : bool bLink(true);
715 0 : if (bAPI ||
716 0 : ::avmedia::MediaWindow::executeMediaURLDialog(mpWindow, aURL, & bLink))
717 : {
718 0 : Size aPrefSize;
719 :
720 0 : if( mpWindow )
721 0 : mpWindow->EnterWait();
722 :
723 0 : if( !::avmedia::MediaWindow::isMediaURL( aURL, "", true, &aPrefSize ) )
724 : {
725 0 : if( mpWindow )
726 0 : mpWindow->LeaveWait();
727 :
728 0 : if( !bAPI )
729 0 : ::avmedia::MediaWindow::executeFormatErrorBox( mpWindow );
730 : }
731 : else
732 : {
733 0 : Point aPos;
734 0 : Size aSize;
735 0 : sal_Int8 nAction = DND_ACTION_COPY;
736 :
737 0 : if( aPrefSize.Width() && aPrefSize.Height() )
738 : {
739 0 : if( mpWindow )
740 0 : aSize = mpWindow->PixelToLogic( aPrefSize, MAP_100TH_MM );
741 : else
742 0 : aSize = Application::GetDefaultDevice()->PixelToLogic( aPrefSize, MAP_100TH_MM );
743 : }
744 : else
745 0 : aSize = Size( 5000, 5000 );
746 :
747 0 : if( mpWindow )
748 : {
749 0 : aPos = mpWindow->PixelToLogic( Rectangle( aPos, mpWindow->GetOutputSizePixel() ).Center() );
750 0 : aPos.X() -= aSize.Width() >> 1;
751 0 : aPos.Y() -= aSize.Height() >> 1;
752 : }
753 :
754 0 : mpView->InsertMediaURL( aURL, nAction, aPos, aSize, bLink ) ;
755 :
756 0 : if( mpWindow )
757 0 : mpWindow->LeaveWait();
758 : }
759 0 : }
760 0 : }
761 :
762 : #if HAVE_FEATURE_GLTF
763 0 : TYPEINIT1( FuInsert3DModel, FuPoor );
764 :
765 0 : FuInsert3DModel::FuInsert3DModel(
766 : ViewShell* pViewSh,
767 : ::sd::Window* pWin,
768 : ::sd::View* pView,
769 : SdDrawDocument* pDoc,
770 : SfxRequest& rReq)
771 0 : : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
772 : {
773 0 : }
774 :
775 0 : rtl::Reference<FuPoor> FuInsert3DModel::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
776 : {
777 0 : rtl::Reference<FuPoor> xFunc( new FuInsert3DModel( pViewSh, pWin, pView, pDoc, rReq ) );
778 0 : xFunc->DoExecute(rReq);
779 0 : return xFunc;
780 : }
781 :
782 0 : void FuInsert3DModel::DoExecute( SfxRequest& )
783 : {
784 0 : sfx2::FileDialogHelper aDlg( ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
785 :
786 0 : aDlg.SetTitle( "Insert 3D Model" );
787 :
788 : #if HAVE_FEATURE_COLLADA
789 0 : aDlg.AddFilter( "All supported formats", "*.json;*.dae;*.kmz" );
790 : #else
791 : aDlg.AddFilter( "All supported formats", "*.json" );
792 : #endif
793 :
794 0 : aDlg.AddFilter( "JSON - GL Transmission Format", "*.json" );
795 :
796 : #if HAVE_FEATURE_COLLADA
797 0 : aDlg.AddFilter( "DAE - COLLADA", "*.dae" );
798 0 : aDlg.AddFilter( "KMZ - Keyhole Markup language Zipped", "*.kmz" );
799 : #endif
800 :
801 0 : OUString sURL;
802 0 : if( aDlg.Execute() == ERRCODE_NONE )
803 : {
804 0 : const INetURLObject aURL( aDlg.GetPath() );
805 0 : sURL = aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
806 : }
807 0 : else if( !sURL.isEmpty() )
808 0 : sURL.clear();
809 :
810 0 : if (!sURL.isEmpty())
811 : {
812 0 : if( mpWindow )
813 0 : mpWindow->EnterWait();
814 :
815 0 : Point aPos;
816 0 : sal_Int8 nAction = DND_ACTION_COPY;
817 :
818 0 : Size aSize(480,360);
819 0 : if( mpWindow )
820 0 : aSize = mpWindow->PixelToLogic( aSize, MAP_100TH_MM );
821 : else
822 0 : aSize = Application::GetDefaultDevice()->PixelToLogic( aSize, MAP_100TH_MM );
823 :
824 0 : if( mpWindow )
825 : {
826 0 : aPos = mpWindow->PixelToLogic( Rectangle( aPos, mpWindow->GetOutputSizePixel() ).Center() );
827 0 : aPos.X() -= aSize.Width() >> 1;
828 0 : aPos.Y() -= aSize.Height() >> 1;
829 : }
830 :
831 0 : mpView->Insert3DModelURL( sURL, nAction, aPos, aSize, false ) ;
832 :
833 0 : if( mpWindow )
834 0 : mpWindow->LeaveWait();
835 0 : }
836 0 : }
837 : #endif
838 66 : } // end of namespace sd
839 :
840 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|