bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / func / fuinsert.cxx
blobabe5311e27ff3ae57ef67cc39838a631dca964d3
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 .
21 #include "fuinsert.hxx"
23 #include <comphelper/storagehelper.hxx>
24 #include <comphelper/processfactory.hxx>
25 #include <toolkit/helper/vclunohelper.hxx>
26 #include <svx/svxdlg.hxx>
27 #include <com/sun/star/embed/NoVisualAreaSizeException.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>
33 #include <tools/urlobj.hxx>
34 #include <svl/urihelper.hxx>
35 #include <sfx2/msgpool.hxx>
36 #include <svtools/sores.hxx>
37 #include <svtools/insdlg.hxx>
38 #include <sfx2/request.hxx>
39 #include <svl/globalnameitem.hxx>
40 #include <unotools/pathoptions.hxx>
41 #include <svtools/miscopt.hxx>
42 #include <svx/pfiledlg.hxx>
43 #include <svx/dialogs.hrc>
44 #include <sfx2/linkmgr.hxx>
45 #include <svx/linkwarn.hxx>
46 #include <svx/svdetc.hxx>
47 #include <avmedia/mediawindow.hxx>
48 #include <unotools/ucbstreamhelper.hxx>
49 #include <sfx2/printer.hxx>
50 #include <comphelper/classids.hxx>
51 #include <svtools/sfxecode.hxx>
52 #include <svtools/transfer.hxx>
53 #include <svl/urlbmk.hxx>
54 #include <svx/svdobj.hxx>
55 #include <svx/svdograf.hxx>
56 #include <svx/svdoole2.hxx>
57 #include <svx/svdomedia.hxx>
58 #include <editeng/editeng.hxx>
59 #include <sot/storage.hxx>
60 #include <sot/formats.hxx>
61 #include <svx/svdpagv.hxx>
62 #include <vcl/msgbox.hxx>
63 #include <sfx2/opengrf.hxx>
65 #include <sfx2/viewfrm.hxx>
67 #include "app.hrc"
68 #include "sdresid.hxx"
69 #include "View.hxx"
70 #include "sdmod.hxx"
71 #include "Window.hxx"
72 #include "drawview.hxx"
73 #include "DrawViewShell.hxx"
74 #include "DrawDocShell.hxx"
75 #include "GraphicDocShell.hxx"
76 #include "strings.hrc"
77 #include "drawdoc.hxx"
78 #include "sdgrffilter.hxx"
79 #include "sdxfer.hxx"
80 #include <vcl/svapp.hxx>
81 #include "undo/undoobjects.hxx"
82 #include "glob.hrc"
84 using namespace com::sun::star;
86 namespace sd {
88 TYPEINIT1( FuInsertGraphic, FuPoor );
89 TYPEINIT1( FuInsertClipboard, FuPoor );
90 TYPEINIT1( FuInsertOLE, FuPoor );
91 TYPEINIT1( FuInsertAVMedia, FuPoor );
93 FuInsertGraphic::FuInsertGraphic (
94 ViewShell* pViewSh,
95 ::sd::Window* pWin,
96 ::sd::View* pView,
97 SdDrawDocument* pDoc,
98 SfxRequest& rReq)
99 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
103 FunctionReference FuInsertGraphic::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
105 FunctionReference xFunc( new FuInsertGraphic( pViewSh, pWin, pView, pDoc, rReq ) );
106 xFunc->DoExecute(rReq);
107 return xFunc;
110 void FuInsertGraphic::DoExecute( SfxRequest& )
112 SvxOpenGraphicDialog aDlg(SdResId(STR_INSERTGRAPHIC));
114 if( aDlg.Execute() == GRFILTER_OK )
116 Graphic aGraphic;
117 int nError = aDlg.GetGraphic(aGraphic);
118 if( nError == GRFILTER_OK )
120 if( mpViewShell && mpViewShell->ISA(DrawViewShell))
122 sal_Int8 nAction = DND_ACTION_COPY;
123 SdrObject* pPickObj;
125 if( ( pPickObj = mpView->GetSelectedSingleObject( mpView->GetPage() ) ) || ( pPickObj = mpView->GetEmptyPresentationObject( PRESOBJ_GRAPHIC ) ) )
126 nAction = DND_ACTION_LINK;
128 Point aPos;
129 Rectangle aRect(aPos, mpWindow->GetOutputSizePixel() );
130 aPos = aRect.Center();
131 aPos = mpWindow->PixelToLogic(aPos);
132 SdrGrafObj* pGrafObj = mpView->InsertGraphic(aGraphic, nAction, aPos, pPickObj, NULL);
134 if(pGrafObj && aDlg.IsAsLink())
136 // really store as link only?
137 if( SvtMiscOptions().ShowLinkWarningDialog() )
139 SvxLinkWarningDialog aWarnDlg(mpWindow,aDlg.GetPath());
140 if( aWarnDlg.Execute() != RET_OK )
141 return; // don't store as link
144 // store as link
145 String aFltName(aDlg.GetCurrentFilter());
146 String aPath(aDlg.GetPath());
147 pGrafObj->SetGraphicLink(aPath, aFltName);
151 else
153 SdGRFFilter::HandleGraphicFilterError( (sal_uInt16)nError, GraphicFilter::GetGraphicFilter().GetLastError().nStreamError );
159 FuInsertClipboard::FuInsertClipboard (
160 ViewShell* pViewSh,
161 ::sd::Window* pWin,
162 ::sd::View* pView,
163 SdDrawDocument* pDoc,
164 SfxRequest& rReq)
165 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
169 FunctionReference FuInsertClipboard::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
171 FunctionReference xFunc( new FuInsertClipboard( pViewSh, pWin, pView, pDoc, rReq ) );
172 xFunc->DoExecute(rReq);
173 return xFunc;
176 void FuInsertClipboard::DoExecute( SfxRequest& )
178 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpWindow ) );
179 sal_uLong nFormatId;
181 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
182 SfxAbstractPasteDialog* pDlg = pFact->CreatePasteDialog( mpViewShell->GetActiveWindow() );
183 if ( pDlg )
185 const String aEmptyString;
186 ::com::sun::star::datatransfer::DataFlavor aFlavor;
188 pDlg->Insert( SOT_FORMATSTR_ID_EMBED_SOURCE, aEmptyString );
189 pDlg->Insert( SOT_FORMATSTR_ID_LINK_SOURCE, aEmptyString );
190 pDlg->Insert( SOT_FORMATSTR_ID_DRAWING, aEmptyString );
191 pDlg->Insert( SOT_FORMATSTR_ID_SVXB, aEmptyString );
192 pDlg->Insert( FORMAT_GDIMETAFILE, aEmptyString );
193 pDlg->Insert( FORMAT_BITMAP, aEmptyString );
194 pDlg->Insert( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aEmptyString );
195 pDlg->Insert( FORMAT_STRING, aEmptyString );
196 pDlg->Insert( SOT_FORMATSTR_ID_HTML, aEmptyString );
197 pDlg->Insert( FORMAT_RTF, aEmptyString );
198 pDlg->Insert( SOT_FORMATSTR_ID_EDITENGINE, aEmptyString );
200 //TODO/MBA: testing
201 nFormatId = pDlg->GetFormat( aDataHelper );
202 if( nFormatId && aDataHelper.GetTransferable().is() )
204 sal_Int8 nAction = DND_ACTION_COPY;
206 if( !mpView->InsertData( aDataHelper,
207 mpWindow->PixelToLogic( Rectangle( Point(), mpWindow->GetOutputSizePixel() ).Center() ),
208 nAction, sal_False, nFormatId ) &&
209 ( mpViewShell && mpViewShell->ISA( DrawViewShell ) ) )
211 DrawViewShell* pDrViewSh = static_cast<DrawViewShell*>(mpViewShell);
212 INetBookmark aINetBookmark( aEmptyStr, aEmptyStr );
214 if( ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ) &&
215 aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aINetBookmark ) ) ||
216 ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ) &&
217 aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR, aINetBookmark ) ) ||
218 ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ) &&
219 aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR, aINetBookmark ) ) )
221 pDrViewSh->InsertURLField( aINetBookmark.GetURL(), aINetBookmark.GetDescription(), aEmptyStr, NULL );
226 delete pDlg;
232 FuInsertOLE::FuInsertOLE (
233 ViewShell* pViewSh,
234 ::sd::Window* pWin,
235 ::sd::View* pView,
236 SdDrawDocument* pDoc,
237 SfxRequest& rReq)
238 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
242 FunctionReference FuInsertOLE::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
244 FunctionReference xFunc( new FuInsertOLE( pViewSh, pWin, pView, pDoc, rReq ) );
245 xFunc->DoExecute(rReq);
246 return xFunc;
249 void FuInsertOLE::DoExecute( SfxRequest& rReq )
251 if ( nSlotId == SID_ATTR_TABLE ||
252 nSlotId == SID_INSERT_DIAGRAM ||
253 nSlotId == SID_INSERT_MATH )
255 PresObjKind ePresObjKind = (nSlotId == SID_INSERT_DIAGRAM) ? PRESOBJ_CHART : PRESOBJ_OBJECT;
257 SdrObject* pPickObj = mpView->GetEmptyPresentationObject( ePresObjKind );
259 // insert diagram or Calc table
260 OUString aObjName;
261 SvGlobalName aName;
262 if (nSlotId == SID_INSERT_DIAGRAM)
263 aName = SvGlobalName( SO3_SCH_CLASSID);
264 else if (nSlotId == SID_ATTR_TABLE)
265 aName = SvGlobalName(SO3_SC_CLASSID);
266 else if (nSlotId == SID_INSERT_MATH)
267 aName = SvGlobalName(SO3_SM_CLASSID);
269 uno::Reference < embed::XEmbeddedObject > xObj = mpViewShell->GetViewFrame()->GetObjectShell()->
270 GetEmbeddedObjectContainer().CreateEmbeddedObject( aName.GetByteSequence(), aObjName );
271 if ( xObj.is() )
273 sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
275 MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
277 Rectangle aRect;
278 if( pPickObj )
280 aRect = pPickObj->GetLogicRect();
282 awt::Size aSz;
283 aSz.Width = aRect.GetWidth();
284 aSz.Height = aRect.GetHeight();
285 xObj->setVisualAreaSize( nAspect, aSz );
287 else
289 awt::Size aSz;
292 aSz = xObj->getVisualAreaSize( nAspect );
294 catch ( embed::NoVisualAreaSizeException& )
296 // the default size will be set later
299 Size aSize( aSz.Width, aSz.Height );
301 if (aSize.Height() == 0 || aSize.Width() == 0)
303 // rectangle with balanced edge ratio
304 aSize.Width() = 14100;
305 aSize.Height() = 10000;
306 Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aUnit );
307 aSz.Width = aTmp.Width();
308 aSz.Height = aTmp.Height();
309 xObj->setVisualAreaSize( nAspect, aSz );
311 else
313 aSize = OutputDevice::LogicToLogic(aSize, aUnit, MAP_100TH_MM);
316 Point aPos;
317 Rectangle aWinRect(aPos, mpWindow->GetOutputSizePixel() );
318 aPos = aWinRect.Center();
319 aPos = mpWindow->PixelToLogic(aPos);
320 aPos.X() -= aSize.Width() / 2;
321 aPos.Y() -= aSize.Height() / 2;
322 aRect = Rectangle(aPos, aSize);
325 SdrOle2Obj* pOleObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aObjName, aRect );
326 SdrPageView* pPV = mpView->GetSdrPageView();
328 // if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj
329 if( pPickObj )
331 SdPage* pPage = static_cast< SdPage* >(pPickObj->GetPage());
332 if(pPage && pPage->IsPresObj(pPickObj))
334 pPage->InsertPresObj( pOleObj, ePresObjKind );
335 pOleObj->SetUserCall(pPickObj->GetUserCall());
339 bool bRet = true;
340 if( pPickObj )
341 mpView->ReplaceObjectAtView(pPickObj, *pPV, pOleObj, sal_True );
342 else
343 bRet = mpView->InsertObjectAtView(pOleObj, *pPV, SDRINSERT_SETDEFLAYER);
345 if( bRet )
347 if (nSlotId == SID_INSERT_DIAGRAM)
349 pOleObj->SetProgName( OUString( "StarChart" ));
351 else if (nSlotId == SID_ATTR_TABLE)
353 pOleObj->SetProgName( OUString( "StarCalc" ) );
355 else if (nSlotId == SID_INSERT_MATH)
357 pOleObj->SetProgName( OUString( "StarMath" ) );
360 pOleObj->SetLogicRect(aRect);
361 Size aTmp( OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aUnit ) );
362 awt::Size aVisualSize;
363 aVisualSize.Width = aTmp.Width();
364 aVisualSize.Height = aTmp.Height();
365 xObj->setVisualAreaSize( nAspect, aVisualSize );
366 mpViewShell->ActivateObject(pOleObj, SVVERB_SHOW);
368 if (nSlotId == SID_INSERT_DIAGRAM)
370 // note, that this call modified the chart model which
371 // results in a change notification. So call this after
372 // everything else is finished.
373 mpViewShell->AdaptDefaultsForChart( xObj );
377 else
379 ErrorHandler::HandleError(* new StringErrorInfo(ERRCODE_SFX_OLEGENERAL,
380 aEmptyStr ) );
383 else
385 // insert object
386 sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
387 sal_Bool bCreateNew = sal_False;
388 uno::Reference < embed::XEmbeddedObject > xObj;
389 uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
390 SvObjectServerList aServerLst;
391 OUString aName;
393 OUString aIconMediaType;
394 uno::Reference< io::XInputStream > xIconMetaFile;
396 SFX_REQUEST_ARG( rReq, pNameItem, SfxGlobalNameItem, SID_INSERT_OBJECT, sal_False );
397 if ( nSlotId == SID_INSERT_OBJECT && pNameItem )
399 SvGlobalName aClassName = pNameItem->GetValue();
400 xObj = mpViewShell->GetViewFrame()->GetObjectShell()->
401 GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName.GetByteSequence(), aName );
403 else
405 switch ( nSlotId )
407 case SID_INSERT_OBJECT :
409 aServerLst.FillInsertObjects();
410 if (mpDoc->GetDocumentType() == DOCUMENT_TYPE_DRAW)
412 aServerLst.Remove( GraphicDocShell::Factory().GetClassId() );
414 else
416 aServerLst.Remove( DrawDocShell::Factory().GetClassId() );
419 // intentionally no break!
421 case SID_INSERT_PLUGIN :
422 case SID_INSERT_FLOATINGFRAME :
424 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
425 SfxAbstractInsertObjectDialog* pDlg =
426 pFact->CreateInsertObjectDialog( mpViewShell->GetActiveWindow(), SD_MOD()->GetSlotPool()->GetSlot(nSlotId)->GetCommandString(),
427 xStorage, &aServerLst );
428 if ( pDlg )
430 pDlg->Execute();
431 bCreateNew = pDlg->IsCreateNew();
432 xObj = pDlg->GetObject();
434 xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType );
435 if ( xIconMetaFile.is() )
436 nAspect = embed::Aspects::MSOLE_ICON;
438 if ( xObj.is() )
439 mpViewShell->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aName );
440 DELETEZ( pDlg );
443 break;
445 case SID_INSERT_SOUND :
446 case SID_INSERT_VIDEO :
448 // create special filedialog for plugins
449 SvxPluginFileDlg aPluginFileDialog (mpWindow, nSlotId);
450 if( ERRCODE_NONE == aPluginFileDialog.Execute () )
452 // get URL
453 String aStrURL(aPluginFileDialog.GetPath());
454 INetURLObject aURL( aStrURL, INET_PROT_FILE );
455 if( aURL.GetProtocol() != INET_PROT_NOT_VALID )
457 // create a plugin object
458 xObj = mpViewShell->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_PLUGIN_CLASSID ).GetByteSequence(), aName );
461 if ( xObj.is() && svt::EmbeddedObjectRef::TryRunningState( xObj ) )
463 // set properties from dialog
464 uno::Reference < embed::XComponentSupplier > xSup( xObj, uno::UNO_QUERY );
465 if ( xSup.is() )
467 uno::Reference < beans::XPropertySet > xSet( xSup->getComponent(), uno::UNO_QUERY );
468 if ( xSet.is() )
470 xSet->setPropertyValue("PluginURL",
471 uno::makeAny( OUString( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) );
475 else
477 // unable to create PlugIn
478 String aStrErr( SdResId( STR_ERROR_OBJNOCREATE_PLUGIN ) );
479 String aMask;
480 aMask += sal_Unicode('%');
481 aStrErr.SearchAndReplace( aMask, aStrURL );
482 ErrorBox( mpWindow, WB_3DLOOK | WB_OK, aStrErr ).Execute();
491 if (xObj.is())
493 //TODO/LATER: needs status for RESIZEONPRINTERCHANGE
494 //if( SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE & xObj->getStatus( nAspect ) )
495 // aIPObj->OnDocumentPrinterChanged( mpDocSh->GetPrinter(sal_False) );
497 sal_Bool bInsertNewObject = sal_True;
499 Size aSize;
500 MapUnit aMapUnit = MAP_100TH_MM;
501 if ( nAspect != embed::Aspects::MSOLE_ICON )
503 awt::Size aSz;
506 aSz = xObj->getVisualAreaSize( nAspect );
508 catch( embed::NoVisualAreaSizeException& )
510 // the default size will be set later
513 aSize =Size( aSz.Width, aSz.Height );
515 aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
516 if (aSize.Height() == 0 || aSize.Width() == 0)
518 // rectangle with balanced edge ratio
519 aSize.Width() = 14100;
520 aSize.Height() = 10000;
521 Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aMapUnit );
522 aSz.Width = aTmp.Width();
523 aSz.Height = aTmp.Height();
524 xObj->setVisualAreaSize( nAspect, aSz );
526 else
528 aSize = OutputDevice::LogicToLogic(aSize, aMapUnit, MAP_100TH_MM);
532 if ( mpView->AreObjectsMarked() )
534 // as an empty OLE object available?
535 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
537 if (rMarkList.GetMarkCount() == 1)
539 SdrMark* pMark = rMarkList.GetMark(0);
540 SdrObject* pObj = pMark->GetMarkedSdrObj();
542 if (pObj->GetObjInventor() == SdrInventor &&
543 pObj->GetObjIdentifier() == OBJ_OLE2)
545 if ( !( (SdrOle2Obj*) pObj)->GetObjRef().is() )
547 // the empty OLE object gets a new IPObj
548 bInsertNewObject = sal_False;
549 pObj->SetEmptyPresObj(sal_False);
550 ( (SdrOle2Obj*) pObj)->SetOutlinerParaObject(NULL);
551 ( (SdrOle2Obj*) pObj)->SetObjRef(xObj);
552 ( (SdrOle2Obj*) pObj)->SetPersistName(aName);
553 ( (SdrOle2Obj*) pObj)->SetName(aName);
554 ( (SdrOle2Obj*) pObj)->SetAspect(nAspect);
555 Rectangle aRect = ( (SdrOle2Obj*) pObj)->GetLogicRect();
557 if ( nAspect == embed::Aspects::MSOLE_ICON )
559 if( xIconMetaFile.is() )
560 ( (SdrOle2Obj*) pObj)->SetGraphicToObj( xIconMetaFile, aIconMediaType );
562 else
564 Size aTmp = OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aMapUnit );
565 awt::Size aSz( aTmp.Width(), aTmp.Height() );
566 xObj->setVisualAreaSize( nAspect, aSz );
573 if (bInsertNewObject)
575 // we create a new OLE object
576 SdrPageView* pPV = mpView->GetSdrPageView();
577 Size aPageSize = pPV->GetPage()->GetSize();
579 // get the size from the iconified object
580 ::svt::EmbeddedObjectRef aObjRef( xObj, nAspect );
581 if ( nAspect == embed::Aspects::MSOLE_ICON )
583 aObjRef.SetGraphicStream( xIconMetaFile, aIconMediaType );
584 MapMode aMapMode( MAP_100TH_MM );
585 aSize = aObjRef.GetSize( &aMapMode );
588 Point aPnt ((aPageSize.Width() - aSize.Width()) / 2,
589 (aPageSize.Height() - aSize.Height()) / 2);
590 Rectangle aRect (aPnt, aSize);
592 SdrOle2Obj* pObj = new SdrOle2Obj( aObjRef, aName, aRect);
594 if( mpView->InsertObjectAtView(pObj, *pPV, SDRINSERT_SETDEFLAYER) )
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.
600 if ( nAspect != embed::Aspects::MSOLE_ICON )
604 awt::Size aSz = xObj->getVisualAreaSize( nAspect );
606 Size aNewSize = Window::LogicToLogic( Size( aSz.Width, aSz.Height ),
607 MapMode( aMapUnit ), MapMode( MAP_100TH_MM ) );
608 if ( aNewSize != aSize )
610 aRect.SetSize( aNewSize );
611 pObj->SetLogicRect( aRect );
614 catch( embed::NoVisualAreaSizeException& )
618 if (bCreateNew)
620 pObj->SetLogicRect(aRect);
622 if ( nAspect != embed::Aspects::MSOLE_ICON )
624 Size aTmp = OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aMapUnit );
625 awt::Size aSz( aTmp.Width(), aTmp.Height() );
626 xObj->setVisualAreaSize( nAspect, aSz );
629 mpViewShell->ActivateObject(pObj, SVVERB_SHOW);
632 Size aVisSizePixel = mpWindow->GetOutputSizePixel();
633 Rectangle aVisAreaWin = mpWindow->PixelToLogic( Rectangle( Point(0,0), aVisSizePixel) );
634 mpViewShell->VisAreaChanged(aVisAreaWin);
635 mpDocSh->SetVisArea(aVisAreaWin);
640 catch (uno::Exception&)
642 // For some reason the object can not be inserted. For example
643 // because it is password protected and is not properly unlocked.
650 FuInsertAVMedia::FuInsertAVMedia(
651 ViewShell* pViewSh,
652 ::sd::Window* pWin,
653 ::sd::View* pView,
654 SdDrawDocument* pDoc,
655 SfxRequest& rReq)
656 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
660 FunctionReference FuInsertAVMedia::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
662 FunctionReference xFunc( new FuInsertAVMedia( pViewSh, pWin, pView, pDoc, rReq ) );
663 xFunc->DoExecute(rReq);
664 return xFunc;
667 void FuInsertAVMedia::DoExecute( SfxRequest& rReq )
669 OUString aURL;
670 const SfxItemSet* pReqArgs = rReq.GetArgs();
671 bool bAPI = false;
673 if( pReqArgs )
675 const SfxStringItem* pStringItem = PTR_CAST( SfxStringItem, &pReqArgs->Get( rReq.GetSlot() ) );
677 if( pStringItem )
679 aURL = pStringItem->GetValue();
680 bAPI = !aURL.isEmpty();
684 bool bLink(true);
685 if (bAPI ||
686 ::avmedia::MediaWindow::executeMediaURLDialog(mpWindow, aURL, & bLink))
688 Size aPrefSize;
690 if( mpWindow )
691 mpWindow->EnterWait();
693 if( !::avmedia::MediaWindow::isMediaURL( aURL, true, &aPrefSize ) )
695 if( mpWindow )
696 mpWindow->LeaveWait();
698 if( !bAPI )
699 ::avmedia::MediaWindow::executeFormatErrorBox( mpWindow );
701 else
703 Point aPos;
704 Size aSize;
705 sal_Int8 nAction = DND_ACTION_COPY;
707 if( aPrefSize.Width() && aPrefSize.Height() )
709 if( mpWindow )
710 aSize = mpWindow->PixelToLogic( aPrefSize, MAP_100TH_MM );
711 else
712 aSize = Application::GetDefaultDevice()->PixelToLogic( aPrefSize, MAP_100TH_MM );
714 else
715 aSize = Size( 5000, 5000 );
717 if( mpWindow )
719 aPos = mpWindow->PixelToLogic( Rectangle( aPos, mpWindow->GetOutputSizePixel() ).Center() );
720 aPos.X() -= aSize.Width() >> 1;
721 aPos.Y() -= aSize.Height() >> 1;
724 mpView->InsertMediaURL( aURL, nAction, aPos, aSize, bLink ) ;
726 if( mpWindow )
727 mpWindow->LeaveWait();
732 } // end of namespace sd
734 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */