Update ooo320-m1
[ooovba.git] / sd / source / ui / func / fuinsert.cxx
blob3bd11fa900081d50dddfbbb8905b8ac5fbc0d5ba
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fuinsert.cxx,v $
10 * $Revision: 1.48 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "fuinsert.hxx"
36 #include <comphelper/storagehelper.hxx>
37 #include <comphelper/processfactory.hxx>
38 #include <toolkit/helper/vclunohelper.hxx>
39 #include <svx/svxdlg.hxx>
40 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
41 #include <com/sun/star/embed/Aspects.hpp>
42 #include <com/sun/star/beans/XPropertySet.hpp>
43 #include <com/sun/star/chart2/XChartDocument.hpp>
44 #include <com/sun/star/drawing/FillStyle.hpp>
45 #include <com/sun/star/embed/EmbedVerbs.hpp>
47 #include <tools/urlobj.hxx>
48 #include <svtools/urihelper.hxx>
50 #include <svtools/sores.hxx>
51 #include <svtools/insdlg.hxx>
52 #include <sfx2/request.hxx>
53 #include <svtools/globalnameitem.hxx>
54 #include <svtools/pathoptions.hxx>
55 #include <svtools/miscopt.hxx>
56 #include <svx/pfiledlg.hxx>
57 #include <svx/impgrf.hxx>
58 #include <svx/dialogs.hrc>
59 #include <svx/linkwarn.hxx>
60 #include <svx/linkmgr.hxx>
61 #include <svx/svdetc.hxx>
62 #include <avmedia/mediawindow.hxx>
63 #ifndef _UNOTOOLS_UCBSTREAMHELPER_HXX
64 #include <unotools/ucbstreamhelper.hxx>
65 #endif
66 #include <sfx2/printer.hxx>
67 #include <sot/clsids.hxx>
68 #include <svtools/sfxecode.hxx>
69 #include <svtools/transfer.hxx>
70 #include <svtools/urlbmk.hxx>
71 #include <svx/svdobj.hxx>
72 #include <svx/svdograf.hxx>
73 #include <svx/svdoole2.hxx>
74 #include <svx/svdomedia.hxx>
75 #ifndef _EDITENG_HXX //autogen
76 #include <svx/editeng.hxx>
77 #endif
78 #include <sot/storage.hxx>
79 #include <sot/formats.hxx>
80 #include <svx/svdpagv.hxx>
81 #ifndef _MSGBOX_HXX //autogen
82 #include <vcl/msgbox.hxx>
83 #endif
84 #include <svx/opengrf.hxx>
86 #include <sfx2/viewfrm.hxx>
88 #include "app.hrc"
89 #include "misc.hxx"
90 #include "sdresid.hxx"
91 #include "View.hxx"
92 #include "app.hxx"
93 #include "Window.hxx"
94 #include "drawview.hxx"
95 #include "DrawViewShell.hxx"
96 #include "DrawDocShell.hxx"
97 #include "GraphicDocShell.hxx"
98 #include "strings.hrc"
99 #include "drawdoc.hxx"
100 #include "sdgrffilter.hxx"
101 #include "sdxfer.hxx"
102 #include <vcl/svapp.hxx>
104 using namespace com::sun::star;
106 namespace sd {
108 TYPEINIT1( FuInsertGraphic, FuPoor );
109 TYPEINIT1( FuInsertClipboard, FuPoor );
110 TYPEINIT1( FuInsertOLE, FuPoor );
111 TYPEINIT1( FuInsertAVMedia, FuPoor );
113 /*************************************************************************
115 |* FuInsertGraphic::Konstruktor
117 \************************************************************************/
119 FuInsertGraphic::FuInsertGraphic (
120 ViewShell* pViewSh,
121 ::sd::Window* pWin,
122 ::sd::View* pView,
123 SdDrawDocument* pDoc,
124 SfxRequest& rReq)
125 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
129 FunctionReference FuInsertGraphic::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
131 FunctionReference xFunc( new FuInsertGraphic( pViewSh, pWin, pView, pDoc, rReq ) );
132 xFunc->DoExecute(rReq);
133 return xFunc;
136 #ifdef _MSC_VER
137 #pragma optimize ( "", off )
138 #endif
140 void FuInsertGraphic::DoExecute( SfxRequest& )
142 SvxOpenGraphicDialog aDlg(SdResId(STR_INSERTGRAPHIC));
144 if( aDlg.Execute() == GRFILTER_OK )
146 Graphic aGraphic;
147 int nError = aDlg.GetGraphic(aGraphic);
148 if( nError == GRFILTER_OK )
150 if( mpViewShell && mpViewShell->ISA(DrawViewShell))
152 sal_Int8 nAction = DND_ACTION_COPY;
153 SdrGrafObj* pEmptyGrafObj = NULL;
155 if ( mpView->AreObjectsMarked() )
157 /**********************************************************
158 * Is an empty graphic object available?
159 **********************************************************/
160 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
162 if (rMarkList.GetMarkCount() == 1)
164 SdrMark* pMark = rMarkList.GetMark(0);
165 SdrObject* pObj = pMark->GetMarkedSdrObj();
167 if (pObj->GetObjInventor() == SdrInventor &&
168 pObj->GetObjIdentifier() == OBJ_GRAF)
170 nAction = DND_ACTION_LINK;
171 pEmptyGrafObj = (SdrGrafObj*) pObj;
176 Point aPos;
177 Rectangle aRect(aPos, mpWindow->GetOutputSizePixel() );
178 aPos = aRect.Center();
179 aPos = mpWindow->PixelToLogic(aPos);
180 SdrGrafObj* pGrafObj = mpView->InsertGraphic(aGraphic, nAction, aPos, pEmptyGrafObj, NULL);
182 if(pGrafObj && aDlg.IsAsLink())
184 // really store as link only?
185 if( SvtMiscOptions().ShowLinkWarningDialog() )
187 SvxLinkWarningDialog aWarnDlg(mpWindow,aDlg.GetPath());
188 if( aWarnDlg.Execute() != RET_OK )
189 return; // don't store as link
192 // store as link
193 String aFltName(aDlg.GetCurrentFilter());
194 String aPath(aDlg.GetPath());
195 pGrafObj->SetGraphicLink(aPath, aFltName);
199 else
201 SdGRFFilter::HandleGraphicFilterError( (USHORT)nError, GetGrfFilter()->GetLastError().nStreamError );
206 #ifdef _MSC_VER
207 #pragma optimize ( "", on )
208 #endif
210 /*************************************************************************
212 |* FuInsertClipboard::Konstruktor
214 \************************************************************************/
216 FuInsertClipboard::FuInsertClipboard (
217 ViewShell* pViewSh,
218 ::sd::Window* pWin,
219 ::sd::View* pView,
220 SdDrawDocument* pDoc,
221 SfxRequest& rReq)
222 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
226 FunctionReference FuInsertClipboard::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
228 FunctionReference xFunc( new FuInsertClipboard( pViewSh, pWin, pView, pDoc, rReq ) );
229 xFunc->DoExecute(rReq);
230 return xFunc;
233 void FuInsertClipboard::DoExecute( SfxRequest& )
235 TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpWindow ) );
236 ULONG nFormatId;
238 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
239 SfxAbstractPasteDialog* pDlg = pFact->CreatePasteDialog( mpViewShell->GetActiveWindow() );
240 if ( pDlg )
242 const String aEmptyString;
243 ::com::sun::star::datatransfer::DataFlavor aFlavor;
245 pDlg->Insert( SOT_FORMATSTR_ID_EMBED_SOURCE, aEmptyString );
246 pDlg->Insert( SOT_FORMATSTR_ID_LINK_SOURCE, aEmptyString );
247 pDlg->Insert( SOT_FORMATSTR_ID_DRAWING, aEmptyString );
248 pDlg->Insert( SOT_FORMATSTR_ID_SVXB, aEmptyString );
249 pDlg->Insert( FORMAT_GDIMETAFILE, aEmptyString );
250 pDlg->Insert( FORMAT_BITMAP, aEmptyString );
251 pDlg->Insert( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aEmptyString );
252 pDlg->Insert( FORMAT_STRING, aEmptyString );
253 pDlg->Insert( SOT_FORMATSTR_ID_HTML, aEmptyString );
254 pDlg->Insert( FORMAT_RTF, aEmptyString );
255 pDlg->Insert( SOT_FORMATSTR_ID_EDITENGINE, aEmptyString );
257 //TODO/MBA: testing
258 nFormatId = pDlg->GetFormat( aDataHelper );
259 if( nFormatId && aDataHelper.GetTransferable().is() )
261 sal_Int8 nAction = DND_ACTION_COPY;
263 if( !mpView->InsertData( aDataHelper,
264 mpWindow->PixelToLogic( Rectangle( Point(), mpWindow->GetOutputSizePixel() ).Center() ),
265 nAction, FALSE, nFormatId ) &&
266 ( mpViewShell && mpViewShell->ISA( DrawViewShell ) ) )
268 DrawViewShell* pDrViewSh = static_cast<DrawViewShell*>(mpViewShell);
269 INetBookmark aINetBookmark( aEmptyStr, aEmptyStr );
271 if( ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ) &&
272 aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aINetBookmark ) ) ||
273 ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ) &&
274 aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR, aINetBookmark ) ) ||
275 ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ) &&
276 aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR, aINetBookmark ) ) )
278 pDrViewSh->InsertURLField( aINetBookmark.GetURL(), aINetBookmark.GetDescription(), aEmptyStr, NULL );
283 delete pDlg;
288 /*************************************************************************
290 |* FuInsertOLE::Konstruktor
292 \************************************************************************/
294 FuInsertOLE::FuInsertOLE (
295 ViewShell* pViewSh,
296 ::sd::Window* pWin,
297 ::sd::View* pView,
298 SdDrawDocument* pDoc,
299 SfxRequest& rReq)
300 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
304 FunctionReference FuInsertOLE::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
306 FunctionReference xFunc( new FuInsertOLE( pViewSh, pWin, pView, pDoc, rReq ) );
307 xFunc->DoExecute(rReq);
308 return xFunc;
311 void FuInsertOLE::DoExecute( SfxRequest& rReq )
313 if ( nSlotId == SID_ATTR_TABLE ||
314 nSlotId == SID_INSERT_DIAGRAM ||
315 nSlotId == SID_INSERT_MATH )
317 /**********************************************************************
318 * Diagramm oder StarCalc-Tabelle einfuegen
319 **********************************************************************/
321 ::rtl::OUString aObjName;
322 SvGlobalName aName;
323 if (nSlotId == SID_INSERT_DIAGRAM)
324 aName = SvGlobalName( SO3_SCH_CLASSID);
325 else if (nSlotId == SID_ATTR_TABLE)
326 aName = SvGlobalName(SO3_SC_CLASSID);
327 else if (nSlotId == SID_INSERT_MATH)
328 aName = SvGlobalName(SO3_SM_CLASSID);
330 uno::Reference < embed::XEmbeddedObject > xObj = mpViewShell->GetViewFrame()->GetObjectShell()->
331 GetEmbeddedObjectContainer().CreateEmbeddedObject( aName.GetByteSequence(), aObjName );
332 if ( xObj.is() )
334 sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
335 awt::Size aSz;
338 aSz = xObj->getVisualAreaSize( nAspect );
340 catch ( embed::NoVisualAreaSizeException& )
342 // the default size will be set later
345 Size aSize( aSz.Width, aSz.Height );
347 MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
348 if (aSize.Height() == 0 || aSize.Width() == 0)
350 // Rechteck mit ausgewogenem Kantenverhaeltnis
351 aSize.Width() = 14100;
352 aSize.Height() = 10000;
353 Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aUnit );
354 aSz.Width = aTmp.Width();
355 aSz.Height = aTmp.Height();
356 xObj->setVisualAreaSize( nAspect, aSz );
358 else
359 aSize = OutputDevice::LogicToLogic(aSize, aUnit, MAP_100TH_MM);
361 Point aPos;
362 Rectangle aWinRect(aPos, mpWindow->GetOutputSizePixel() );
363 aPos = aWinRect.Center();
364 aPos = mpWindow->PixelToLogic(aPos);
365 aPos.X() -= aSize.Width() / 2;
366 aPos.Y() -= aSize.Height() / 2;
367 Rectangle aRect (aPos, aSize);
368 SdrOle2Obj* pOleObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aObjName, aRect );
369 SdrPageView* pPV = mpView->GetSdrPageView();
370 if( mpView->InsertObjectAtView(pOleObj, *pPV, SDRINSERT_SETDEFLAYER) )
372 if (nSlotId == SID_INSERT_DIAGRAM)
374 pOleObj->SetProgName( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarChart" ) ) );
376 else if (nSlotId == SID_ATTR_TABLE)
378 pOleObj->SetProgName( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarCalc" ) ) );
380 else if (nSlotId == SID_INSERT_MATH)
382 pOleObj->SetProgName( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarMath" ) ) );
385 //HMHmpView->HideMarkHdl();
386 pOleObj->SetLogicRect(aRect);
387 Size aTmp = OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aUnit );
388 aSz.Width = aTmp.Width();
389 aSz.Height = aTmp.Height();
390 xObj->setVisualAreaSize( nAspect, aSz );
391 mpViewShell->ActivateObject(pOleObj, embed::EmbedVerbs::MS_OLEVERB_SHOW);
393 if (nSlotId == SID_INSERT_DIAGRAM)
395 // note, that this call modified the chart model which
396 // results in a change notification. So call this after
397 // everything else is finished.
398 mpViewShell->AdaptDefaultsForChart( xObj );
402 else
404 ErrorHandler::HandleError(* new StringErrorInfo(ERRCODE_SFX_OLEGENERAL,
405 aEmptyStr ) );
408 else
410 /**********************************************************************
411 * Objekt einfuegen
412 **********************************************************************/
413 sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
414 BOOL bCreateNew = FALSE;
415 uno::Reference < embed::XEmbeddedObject > xObj;
416 uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
417 SvObjectServerList aServerLst;
418 ::rtl::OUString aName;
420 ::rtl::OUString aIconMediaType;
421 uno::Reference< io::XInputStream > xIconMetaFile;
423 SFX_REQUEST_ARG( rReq, pNameItem, SfxGlobalNameItem, SID_INSERT_OBJECT, sal_False );
424 if ( nSlotId == SID_INSERT_OBJECT && pNameItem )
426 SvGlobalName aClassName = pNameItem->GetValue();
427 xObj = mpViewShell->GetViewFrame()->GetObjectShell()->
428 GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName.GetByteSequence(), aName );
430 else
432 switch ( nSlotId )
434 case SID_INSERT_OBJECT :
436 aServerLst.FillInsertObjects();
437 if (mpDoc->GetDocumentType() == DOCUMENT_TYPE_DRAW)
439 aServerLst.Remove( GraphicDocShell::Factory().GetClassId() );
441 else
443 aServerLst.Remove( DrawDocShell::Factory().GetClassId() );
446 // intentionally no break!
448 case SID_INSERT_PLUGIN :
449 case SID_INSERT_APPLET :
450 case SID_INSERT_FLOATINGFRAME :
452 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
453 SfxAbstractInsertObjectDialog* pDlg =
454 pFact->CreateInsertObjectDialog( mpViewShell->GetActiveWindow(), nSlotId,
455 xStorage, &aServerLst );
456 if ( pDlg )
458 pDlg->Execute();
459 bCreateNew = pDlg->IsCreateNew();
460 xObj = pDlg->GetObject();
462 xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType );
463 if ( xIconMetaFile.is() )
464 nAspect = embed::Aspects::MSOLE_ICON;
466 if ( xObj.is() )
467 mpViewShell->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aName );
468 DELETEZ( pDlg );
471 break;
473 case SID_INSERT_SOUND :
474 case SID_INSERT_VIDEO :
476 // create special filedialog for plugins
477 SvxPluginFileDlg aPluginFileDialog (mpWindow, nSlotId);
478 if( ERRCODE_NONE == aPluginFileDialog.Execute () )
480 // get URL
481 String aStrURL(aPluginFileDialog.GetPath());
482 INetURLObject aURL( aStrURL, INET_PROT_FILE );
483 if( aURL.GetProtocol() != INET_PROT_NOT_VALID )
485 // create a plugin object
486 xObj = mpViewShell->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_PLUGIN_CLASSID ).GetByteSequence(), aName );
489 if ( xObj.is() && svt::EmbeddedObjectRef::TryRunningState( xObj ) )
491 // set properties from dialog
492 uno::Reference < embed::XComponentSupplier > xSup( xObj, uno::UNO_QUERY );
493 if ( xSup.is() )
495 uno::Reference < beans::XPropertySet > xSet( xSup->getComponent(), uno::UNO_QUERY );
496 if ( xSet.is() )
498 xSet->setPropertyValue( ::rtl::OUString::createFromAscii("PluginURL"),
499 uno::makeAny( ::rtl::OUString( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) );
503 else
505 // PlugIn konnte nicht erzeugt werden
506 String aStrErr( SdResId( STR_ERROR_OBJNOCREATE_PLUGIN ) );
507 String aMask;
508 aMask += sal_Unicode('%');
509 aStrErr.SearchAndReplace( aMask, aStrURL );
510 ErrorBox( mpWindow, WB_3DLOOK | WB_OK, aStrErr ).Execute();
519 if (xObj.is())
521 //TODO/LATER: needs status for RESIZEONPRINTERCHANGE
522 //if( SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE & xObj->getStatus( nAspect ) )
523 // aIPObj->OnDocumentPrinterChanged( mpDocSh->GetPrinter(FALSE) );
525 BOOL bInsertNewObject = TRUE;
527 Size aSize;
528 MapUnit aMapUnit = MAP_100TH_MM;
529 if ( nAspect != embed::Aspects::MSOLE_ICON )
531 awt::Size aSz;
534 aSz = xObj->getVisualAreaSize( nAspect );
536 catch( embed::NoVisualAreaSizeException& )
538 // the default size will be set later
541 aSize =Size( aSz.Width, aSz.Height );
543 aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
544 if (aSize.Height() == 0 || aSize.Width() == 0)
546 // Rechteck mit ausgewogenem Kantenverhaeltnis
547 aSize.Width() = 14100;
548 aSize.Height() = 10000;
549 Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aMapUnit );
550 aSz.Width = aTmp.Width();
551 aSz.Height = aTmp.Height();
552 xObj->setVisualAreaSize( nAspect, aSz );
554 else
556 aSize = OutputDevice::LogicToLogic(aSize, aMapUnit, MAP_100TH_MM);
560 if ( mpView->AreObjectsMarked() )
562 /**********************************************************
563 * Ist ein leeres OLE-Objekt vorhanden?
564 **********************************************************/
565 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
567 if (rMarkList.GetMarkCount() == 1)
569 SdrMark* pMark = rMarkList.GetMark(0);
570 SdrObject* pObj = pMark->GetMarkedSdrObj();
572 if (pObj->GetObjInventor() == SdrInventor &&
573 pObj->GetObjIdentifier() == OBJ_OLE2)
575 if ( !( (SdrOle2Obj*) pObj)->GetObjRef().is() )
577 /**************************************************
578 * Das leere OLE-Objekt bekommt ein neues IPObj
579 **************************************************/
580 bInsertNewObject = FALSE;
581 pObj->SetEmptyPresObj(FALSE);
582 ( (SdrOle2Obj*) pObj)->SetOutlinerParaObject(NULL);
583 ( (SdrOle2Obj*) pObj)->SetObjRef(xObj);
584 ( (SdrOle2Obj*) pObj)->SetPersistName(aName);
585 ( (SdrOle2Obj*) pObj)->SetName(aName);
586 ( (SdrOle2Obj*) pObj)->SetAspect(nAspect);
587 Rectangle aRect = ( (SdrOle2Obj*) pObj)->GetLogicRect();
589 //HMHmpView->HideMarkHdl();
591 if ( nAspect == embed::Aspects::MSOLE_ICON )
593 if( xIconMetaFile.is() )
594 ( (SdrOle2Obj*) pObj)->SetGraphicToObj( xIconMetaFile, aIconMediaType );
596 else
598 Size aTmp = OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aMapUnit );
599 awt::Size aSz( aTmp.Width(), aTmp.Height() );
600 xObj->setVisualAreaSize( nAspect, aSz );
607 if (bInsertNewObject)
609 /**************************************************************
610 * Ein neues OLE-Objekt wird erzeugt
611 **************************************************************/
612 SdrPageView* pPV = mpView->GetSdrPageView();
613 Size aPageSize = pPV->GetPage()->GetSize();
615 // get the size from the iconified object
616 ::svt::EmbeddedObjectRef aObjRef( xObj, nAspect );
617 if ( nAspect == embed::Aspects::MSOLE_ICON )
619 aObjRef.SetGraphicStream( xIconMetaFile, aIconMediaType );
620 MapMode aMapMode( MAP_100TH_MM );
621 aSize = aObjRef.GetSize( &aMapMode );
624 Point aPnt ((aPageSize.Width() - aSize.Width()) / 2,
625 (aPageSize.Height() - aSize.Height()) / 2);
626 Rectangle aRect (aPnt, aSize);
628 SdrOle2Obj* pObj = new SdrOle2Obj( aObjRef, aName, aRect);
630 if( mpView->InsertObjectAtView(pObj, *pPV, SDRINSERT_SETDEFLAYER) )
632 // #73279# Math objects change their object size during InsertObject.
633 // New size must be set in SdrObject, or a wrong scale will be set at
634 // ActivateObject.
636 if ( nAspect != embed::Aspects::MSOLE_ICON )
640 awt::Size aSz = xObj->getVisualAreaSize( nAspect );
642 Size aNewSize = Window::LogicToLogic( Size( aSz.Width, aSz.Height ),
643 MapMode( aMapUnit ), MapMode( MAP_100TH_MM ) );
644 if ( aNewSize != aSize )
646 aRect.SetSize( aNewSize );
647 pObj->SetLogicRect( aRect );
650 catch( embed::NoVisualAreaSizeException& )
654 if (bCreateNew)
656 //HMHmpView->HideMarkHdl();
657 pObj->SetLogicRect(aRect);
659 if ( nAspect != embed::Aspects::MSOLE_ICON )
661 Size aTmp = OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aMapUnit );
662 awt::Size aSz( aTmp.Width(), aTmp.Height() );
663 xObj->setVisualAreaSize( nAspect, aSz );
666 mpViewShell->ActivateObject(pObj, embed::EmbedVerbs::MS_OLEVERB_SHOW);
669 Size aVisSizePixel = mpWindow->GetOutputSizePixel();
670 Rectangle aVisAreaWin = mpWindow->PixelToLogic( Rectangle( Point(0,0), aVisSizePixel) );
671 mpViewShell->VisAreaChanged(aVisAreaWin);
672 mpDocSh->SetVisArea(aVisAreaWin);
677 catch (uno::Exception&)
679 // For some reason the object can not be inserted. For example
680 // because it is password protected and is not properly unlocked.
686 /*************************************************************************
688 |* FuInsertAVMedia::Konstruktor
690 \************************************************************************/
692 FuInsertAVMedia::FuInsertAVMedia(
693 ViewShell* pViewSh,
694 ::sd::Window* pWin,
695 ::sd::View* pView,
696 SdDrawDocument* pDoc,
697 SfxRequest& rReq)
698 : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
702 FunctionReference FuInsertAVMedia::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
704 FunctionReference xFunc( new FuInsertAVMedia( pViewSh, pWin, pView, pDoc, rReq ) );
705 xFunc->DoExecute(rReq);
706 return xFunc;
709 void FuInsertAVMedia::DoExecute( SfxRequest& rReq )
711 ::rtl::OUString aURL;
712 const SfxItemSet* pReqArgs = rReq.GetArgs();
713 bool bAPI = false;
715 if( pReqArgs )
717 const SfxStringItem* pStringItem = PTR_CAST( SfxStringItem, &pReqArgs->Get( rReq.GetSlot() ) );
719 if( pStringItem )
721 aURL = pStringItem->GetValue();
722 bAPI = aURL.getLength();
726 if( bAPI || ::avmedia::MediaWindow::executeMediaURLDialog( mpWindow, aURL ) )
728 Size aPrefSize;
730 if( mpWindow )
731 mpWindow->EnterWait();
733 if( !::avmedia::MediaWindow::isMediaURL( aURL, true, &aPrefSize ) )
735 if( mpWindow )
736 mpWindow->LeaveWait();
738 if( !bAPI )
739 ::avmedia::MediaWindow::executeFormatErrorBox( mpWindow );
741 else
743 Point aPos;
744 Size aSize;
745 sal_Int8 nAction = DND_ACTION_COPY;
747 if( aPrefSize.Width() && aPrefSize.Height() )
749 if( mpWindow )
750 aSize = mpWindow->PixelToLogic( aPrefSize, MAP_100TH_MM );
751 else
752 aSize = Application::GetDefaultDevice()->PixelToLogic( aPrefSize, MAP_100TH_MM );
754 else
755 aSize = Size( 5000, 5000 );
757 if( mpWindow )
759 aPos = mpWindow->PixelToLogic( Rectangle( aPos, mpWindow->GetOutputSizePixel() ).Center() );
760 aPos.X() -= aSize.Width() >> 1;
761 aPos.Y() -= aSize.Height() >> 1;
764 mpView->InsertMediaURL( aURL, nAction, aPos, aSize ) ;
766 if( mpWindow )
767 mpWindow->LeaveWait();
772 } // end of namespace sd