1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fuinsert.cxx,v $
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>
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>
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>
84 #include <svx/opengrf.hxx>
86 #include <sfx2/viewfrm.hxx>
90 #include "sdresid.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
;
108 TYPEINIT1( FuInsertGraphic
, FuPoor
);
109 TYPEINIT1( FuInsertClipboard
, FuPoor
);
110 TYPEINIT1( FuInsertOLE
, FuPoor
);
111 TYPEINIT1( FuInsertAVMedia
, FuPoor
);
113 /*************************************************************************
115 |* FuInsertGraphic::Konstruktor
117 \************************************************************************/
119 FuInsertGraphic::FuInsertGraphic (
123 SdDrawDocument
* pDoc
,
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
);
137 #pragma optimize ( "", off )
140 void FuInsertGraphic::DoExecute( SfxRequest
& )
142 SvxOpenGraphicDialog
aDlg(SdResId(STR_INSERTGRAPHIC
));
144 if( aDlg
.Execute() == GRFILTER_OK
)
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
;
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
193 String
aFltName(aDlg
.GetCurrentFilter());
194 String
aPath(aDlg
.GetPath());
195 pGrafObj
->SetGraphicLink(aPath
, aFltName
);
201 SdGRFFilter::HandleGraphicFilterError( (USHORT
)nError
, GetGrfFilter()->GetLastError().nStreamError
);
207 #pragma optimize ( "", on )
210 /*************************************************************************
212 |* FuInsertClipboard::Konstruktor
214 \************************************************************************/
216 FuInsertClipboard::FuInsertClipboard (
220 SdDrawDocument
* pDoc
,
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
);
233 void FuInsertClipboard::DoExecute( SfxRequest
& )
235 TransferableDataHelper
aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpWindow
) );
238 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
239 SfxAbstractPasteDialog
* pDlg
= pFact
->CreatePasteDialog( mpViewShell
->GetActiveWindow() );
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
);
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
);
288 /*************************************************************************
290 |* FuInsertOLE::Konstruktor
292 \************************************************************************/
294 FuInsertOLE::FuInsertOLE (
298 SdDrawDocument
* pDoc
,
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
);
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
;
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
);
334 sal_Int64 nAspect
= embed::Aspects::MSOLE_CONTENT
;
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
);
359 aSize
= OutputDevice::LogicToLogic(aSize
, aUnit
, MAP_100TH_MM
);
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
);
404 ErrorHandler::HandleError(* new StringErrorInfo(ERRCODE_SFX_OLEGENERAL
,
410 /**********************************************************************
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
);
434 case SID_INSERT_OBJECT
:
436 aServerLst
.FillInsertObjects();
437 if (mpDoc
->GetDocumentType() == DOCUMENT_TYPE_DRAW
)
439 aServerLst
.Remove( GraphicDocShell::Factory().GetClassId() );
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
);
459 bCreateNew
= pDlg
->IsCreateNew();
460 xObj
= pDlg
->GetObject();
462 xIconMetaFile
= pDlg
->GetIconIfIconified( &aIconMediaType
);
463 if ( xIconMetaFile
.is() )
464 nAspect
= embed::Aspects::MSOLE_ICON
;
467 mpViewShell
->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj
, aName
);
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 () )
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
);
495 uno::Reference
< beans::XPropertySet
> xSet( xSup
->getComponent(), uno::UNO_QUERY
);
498 xSet
->setPropertyValue( ::rtl::OUString::createFromAscii("PluginURL"),
499 uno::makeAny( ::rtl::OUString( aURL
.GetMainURL( INetURLObject::NO_DECODE
) ) ) );
505 // PlugIn konnte nicht erzeugt werden
506 String
aStrErr( SdResId( STR_ERROR_OBJNOCREATE_PLUGIN
) );
508 aMask
+= sal_Unicode('%');
509 aStrErr
.SearchAndReplace( aMask
, aStrURL
);
510 ErrorBox( mpWindow
, WB_3DLOOK
| WB_OK
, aStrErr
).Execute();
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
;
528 MapUnit aMapUnit
= MAP_100TH_MM
;
529 if ( nAspect
!= embed::Aspects::MSOLE_ICON
)
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
);
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
);
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
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
& )
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(
696 SdDrawDocument
* pDoc
,
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
);
709 void FuInsertAVMedia::DoExecute( SfxRequest
& rReq
)
711 ::rtl::OUString aURL
;
712 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
717 const SfxStringItem
* pStringItem
= PTR_CAST( SfxStringItem
, &pReqArgs
->Get( rReq
.GetSlot() ) );
721 aURL
= pStringItem
->GetValue();
722 bAPI
= aURL
.getLength();
726 if( bAPI
|| ::avmedia::MediaWindow::executeMediaURLDialog( mpWindow
, aURL
) )
731 mpWindow
->EnterWait();
733 if( !::avmedia::MediaWindow::isMediaURL( aURL
, true, &aPrefSize
) )
736 mpWindow
->LeaveWait();
739 ::avmedia::MediaWindow::executeFormatErrorBox( mpWindow
);
745 sal_Int8 nAction
= DND_ACTION_COPY
;
747 if( aPrefSize
.Width() && aPrefSize
.Height() )
750 aSize
= mpWindow
->PixelToLogic( aPrefSize
, MAP_100TH_MM
);
752 aSize
= Application::GetDefaultDevice()->PixelToLogic( aPrefSize
, MAP_100TH_MM
);
755 aSize
= Size( 5000, 5000 );
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
) ;
767 mpWindow
->LeaveWait();
772 } // end of namespace sd