xref: /aoo41x/main/sd/source/ui/func/fuinsert.cxx (revision 4bf7a51a)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 #include "fuinsert.hxx"
28 
29 #include <comphelper/storagehelper.hxx>
30 #include <comphelper/processfactory.hxx>
31 #include <toolkit/helper/vclunohelper.hxx>
32 #include <svx/svxdlg.hxx>
33 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
34 #include <com/sun/star/embed/Aspects.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/chart2/XChartDocument.hpp>
37 #include <com/sun/star/drawing/FillStyle.hpp>
38 
39 #include <tools/urlobj.hxx>
40 #include <svl/urihelper.hxx>
41 #include <sfx2/msgpool.hxx>
42 #include <svtools/sores.hxx>
43 #include <svtools/insdlg.hxx>
44 #include <sfx2/request.hxx>
45 #include <svl/globalnameitem.hxx>
46 #include <unotools/pathoptions.hxx>
47 #include <svx/pfiledlg.hxx>
48 #include <svx/dialogs.hrc>
49 #include <sfx2/linkmgr.hxx>
50 #include <svx/svdetc.hxx>
51 #include <avmedia/mediawindow.hxx>
52 #ifndef _UNOTOOLS_UCBSTREAMHELPER_HXX
53 #include <unotools/ucbstreamhelper.hxx>
54 #endif
55 #include <sfx2/printer.hxx>
56 #include <sot/clsids.hxx>
57 #include <svtools/sfxecode.hxx>
58 #include <svtools/transfer.hxx>
59 #include <svl/urlbmk.hxx>
60 #include <svx/svdobj.hxx>
61 #include <svx/svdograf.hxx>
62 #include <svx/svdoole2.hxx>
63 #include <svx/svdomedia.hxx>
64 #ifndef _EDITENG_HXX //autogen
65 #include <editeng/editeng.hxx>
66 #endif
67 #include <sot/storage.hxx>
68 #include <sot/formats.hxx>
69 #include <svx/svdpagv.hxx>
70 #ifndef _MSGBOX_HXX //autogen
71 #include <vcl/msgbox.hxx>
72 #endif
73 #include <sfx2/opengrf.hxx>
74 
75 #include <sfx2/viewfrm.hxx>
76 
77 #include "app.hrc"
78 #include "misc.hxx"
79 #include "sdresid.hxx"
80 #include "View.hxx"
81 #include "app.hxx"
82 #include "Window.hxx"
83 #include "drawview.hxx"
84 #include "DrawViewShell.hxx"
85 #include "DrawDocShell.hxx"
86 #include "GraphicDocShell.hxx"
87 #include "strings.hrc"
88 #include "drawdoc.hxx"
89 #include "sdgrffilter.hxx"
90 #include "sdxfer.hxx"
91 #include <vcl/svapp.hxx>
92 #include "undo/undoobjects.hxx"
93 #include "glob.hrc"
94 
95 using namespace com::sun::star;
96 
97 namespace sd {
98 
99 TYPEINIT1( FuInsertGraphic, FuPoor );
100 TYPEINIT1( FuInsertClipboard, FuPoor );
101 TYPEINIT1( FuInsertOLE, FuPoor );
102 TYPEINIT1( FuInsertAVMedia, FuPoor );
103 
104 /*************************************************************************
105 |*
106 |* FuInsertGraphic::Konstruktor
107 |*
108 \************************************************************************/
109 
110 FuInsertGraphic::FuInsertGraphic (
111     ViewShell* pViewSh,
112     ::sd::Window* pWin,
113     ::sd::View* pView,
114     SdDrawDocument* pDoc,
115     SfxRequest& rReq)
116     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
117 {
118 }
119 
120 FunctionReference FuInsertGraphic::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
121 {
122 	FunctionReference xFunc( new FuInsertGraphic( pViewSh, pWin, pView, pDoc, rReq ) );
123 	xFunc->DoExecute(rReq);
124 	return xFunc;
125 }
126 
127 #ifdef _MSC_VER
128 #pragma optimize ( "", off )
129 #endif
130 
131 void FuInsertGraphic::DoExecute( SfxRequest&  )
132 {
133 	SvxOpenGraphicDialog	aDlg(SdResId(STR_INSERTGRAPHIC));
134 
135 	if( aDlg.Execute() == GRFILTER_OK )
136 	{
137 		Graphic		aGraphic;
138 		int nError = aDlg.GetGraphic(aGraphic);
139 		if( nError == GRFILTER_OK )
140 		{
141 			if( mpViewShell && mpViewShell->ISA(DrawViewShell))
142 			{
143 				sal_Int8	nAction = DND_ACTION_COPY;
144 				SdrObject* pPickObj = mpView->GetEmptyPresentationObject( PRESOBJ_GRAPHIC );
145 				if( pPickObj )
146 					nAction = DND_ACTION_LINK;
147 
148 				Point aPos;
149 				Rectangle aRect(aPos, mpWindow->GetOutputSizePixel() );
150 				aPos = aRect.Center();
151 				aPos = mpWindow->PixelToLogic(aPos);
152 				SdrGrafObj* pGrafObj = mpView->InsertGraphic(aGraphic, nAction, aPos, pPickObj, NULL);
153 
154 				if(pGrafObj && aDlg.IsAsLink())
155 				{
156 					// store link only?
157 					String aFltName(aDlg.GetCurrentFilter());
158 					String aPath(aDlg.GetPath());
159 					pGrafObj->SetGraphicLink(aPath, aFltName);
160 				}
161 			}
162 		}
163 		else
164 		{
165 			SdGRFFilter::HandleGraphicFilterError( (sal_uInt16)nError, GraphicFilter::GetGraphicFilter()->GetLastError().nStreamError );
166 		}
167 	}
168 }
169 
170 #ifdef _MSC_VER
171 #pragma optimize ( "", on )
172 #endif
173 
174 /*************************************************************************
175 |*
176 |* FuInsertClipboard::Konstruktor
177 |*
178 \************************************************************************/
179 
180 FuInsertClipboard::FuInsertClipboard (
181     ViewShell* pViewSh,
182     ::sd::Window* pWin,
183     ::sd::View* pView,
184     SdDrawDocument* pDoc,
185     SfxRequest& rReq)
186     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
187 {
188 }
189 
190 FunctionReference FuInsertClipboard::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
191 {
192 	FunctionReference xFunc( new FuInsertClipboard( pViewSh, pWin, pView, pDoc, rReq ) );
193 	xFunc->DoExecute(rReq);
194 	return xFunc;
195 }
196 
197 void FuInsertClipboard::DoExecute( SfxRequest&  )
198 {
199 	TransferableDataHelper						aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpWindow ) );
200     sal_uLong                                       nFormatId;
201 
202     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
203     SfxAbstractPasteDialog* pDlg = pFact->CreatePasteDialog( mpViewShell->GetActiveWindow() );
204     if ( pDlg )
205     {
206         const String                                aEmptyString;
207         ::com::sun::star::datatransfer::DataFlavor  aFlavor;
208 
209         pDlg->Insert( SOT_FORMATSTR_ID_EMBED_SOURCE, aEmptyString );
210         pDlg->Insert( SOT_FORMATSTR_ID_LINK_SOURCE, aEmptyString );
211         pDlg->Insert( SOT_FORMATSTR_ID_DRAWING, aEmptyString );
212         pDlg->Insert( SOT_FORMATSTR_ID_SVXB, aEmptyString );
213         pDlg->Insert( FORMAT_GDIMETAFILE, aEmptyString );
214         pDlg->Insert( FORMAT_BITMAP, aEmptyString );
215         pDlg->Insert( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aEmptyString );
216         pDlg->Insert( FORMAT_STRING, aEmptyString );
217         pDlg->Insert( SOT_FORMATSTR_ID_HTML, aEmptyString );
218         pDlg->Insert( FORMAT_RTF, aEmptyString );
219         pDlg->Insert( SOT_FORMATSTR_ID_EDITENGINE, aEmptyString );
220 
221         //TODO/MBA: testing
222         nFormatId = pDlg->GetFormat( aDataHelper );
223         if( nFormatId && aDataHelper.GetTransferable().is() )
224         {
225             sal_Int8 nAction = DND_ACTION_COPY;
226 
227             if( !mpView->InsertData( aDataHelper,
228                                     mpWindow->PixelToLogic( Rectangle( Point(), mpWindow->GetOutputSizePixel() ).Center() ),
229                                     nAction, sal_False, nFormatId ) &&
230                 ( mpViewShell && mpViewShell->ISA( DrawViewShell ) ) )
231             {
232                 DrawViewShell* pDrViewSh = static_cast<DrawViewShell*>(mpViewShell);
233                 INetBookmark        aINetBookmark( aEmptyStr, aEmptyStr );
234 
235                 if( ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ) &&
236                     aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aINetBookmark ) ) ||
237                     ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ) &&
238                     aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR, aINetBookmark ) ) ||
239                     ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ) &&
240                     aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR, aINetBookmark ) ) )
241                 {
242                     pDrViewSh->InsertURLField( aINetBookmark.GetURL(), aINetBookmark.GetDescription(), aEmptyStr, NULL );
243                 }
244             }
245         }
246 
247         delete pDlg;
248     }
249 }
250 
251 
252 /*************************************************************************
253 |*
254 |* FuInsertOLE::Konstruktor
255 |*
256 \************************************************************************/
257 
258 FuInsertOLE::FuInsertOLE (
259     ViewShell* pViewSh,
260     ::sd::Window* pWin,
261     ::sd::View* pView,
262     SdDrawDocument* pDoc,
263     SfxRequest& rReq)
264 	: FuPoor(pViewSh, pWin, pView, pDoc, rReq)
265 {
266 }
267 
268 FunctionReference FuInsertOLE::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
269 {
270 	FunctionReference xFunc( new FuInsertOLE( pViewSh, pWin, pView, pDoc, rReq ) );
271 	xFunc->DoExecute(rReq);
272 	return xFunc;
273 }
274 
275 void FuInsertOLE::DoExecute( SfxRequest& rReq )
276 {
277 	if ( nSlotId == SID_ATTR_TABLE ||
278 		 nSlotId == SID_INSERT_DIAGRAM ||
279 		 nSlotId == SID_INSERT_MATH )
280 	{
281 		PresObjKind ePresObjKind = (nSlotId == SID_INSERT_DIAGRAM) ? PRESOBJ_CHART : PRESOBJ_OBJECT;
282 
283 		SdrObject* pPickObj = mpView->GetEmptyPresentationObject( ePresObjKind );
284 
285 		/**********************************************************************
286 		* Diagramm oder StarCalc-Tabelle einfuegen
287 		**********************************************************************/
288 
289         ::rtl::OUString aObjName;
290         SvGlobalName aName;
291 		if (nSlotId == SID_INSERT_DIAGRAM)
292             aName = SvGlobalName( SO3_SCH_CLASSID);
293         else if (nSlotId == SID_ATTR_TABLE)
294             aName = SvGlobalName(SO3_SC_CLASSID);
295         else if (nSlotId == SID_INSERT_MATH)
296             aName = SvGlobalName(SO3_SM_CLASSID);
297 
298         uno::Reference < embed::XEmbeddedObject > xObj = mpViewShell->GetViewFrame()->GetObjectShell()->
299                 GetEmbeddedObjectContainer().CreateEmbeddedObject( aName.GetByteSequence(), aObjName );
300         if ( xObj.is() )
301 		{
302             sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
303 
304 			MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
305 
306 			Rectangle aRect;
307 			if( pPickObj )
308 			{
309 				aRect = pPickObj->GetLogicRect();
310 
311         		awt::Size aSz;
312         		aSz.Width = aRect.GetWidth();
313         		aSz.Height = aRect.GetHeight();
314         		xObj->setVisualAreaSize( nAspect, aSz );
315 			}
316 			else
317 			{
318 				awt::Size aSz;
319 				try
320 				{
321 					aSz = xObj->getVisualAreaSize( nAspect );
322 				}
323 				catch ( embed::NoVisualAreaSizeException& )
324 				{
325 					// the default size will be set later
326 				}
327 
328 				Size aSize( aSz.Width, aSz.Height );
329 
330 				if (aSize.Height() == 0 || aSize.Width() == 0)
331 				{
332 					// Rechteck mit ausgewogenem Kantenverhaeltnis
333 					aSize.Width()  = 14100;
334 					aSize.Height() = 10000;
335 					Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aUnit );
336 					aSz.Width = aTmp.Width();
337 					aSz.Height = aTmp.Height();
338 					xObj->setVisualAreaSize( nAspect, aSz );
339 				}
340 				else
341 				{
342 					aSize = OutputDevice::LogicToLogic(aSize, aUnit, MAP_100TH_MM);
343 				}
344 
345 				Point aPos;
346 				Rectangle aWinRect(aPos, mpWindow->GetOutputSizePixel() );
347 				aPos = aWinRect.Center();
348 				aPos = mpWindow->PixelToLogic(aPos);
349 				aPos.X() -= aSize.Width() / 2;
350 				aPos.Y() -= aSize.Height() / 2;
351 				aRect = Rectangle(aPos, aSize);
352 			}
353 
354             SdrOle2Obj* pOleObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aObjName, aRect );
355 			SdrPageView* pPV = mpView->GetSdrPageView();
356 
357             if(pOleObj)
358             {
359                 // #119287#
360             	SdrModel* pModel = mpView ? mpView->GetModel() : 0;
361                 SfxStyleSheetBasePool* pSfxStyleSheetBasePool = pModel ? pModel->GetStyleSheetPool() : 0;
362 		        SfxStyleSheet* pSheet = pSfxStyleSheetBasePool ? dynamic_cast< SfxStyleSheet* >(pSfxStyleSheetBasePool->Find(String(SdResId(STR_POOLSHEET_OBJNOLINENOFILL)), SD_STYLE_FAMILY_GRAPHICS)) : 0;
363 
364 		        if(pSheet)
365 		        {
366 			        pOleObj->SetStyleSheet(pSheet, false);
367 		        }
368                 else
369                 {
370 		            pOleObj->SetMergedItem(XFillStyleItem(XFILL_NONE));
371 		            pOleObj->SetMergedItem(XLineStyleItem(XLINE_NONE));
372     		        OSL_ENSURE(false, "Style Sheet for OLE not found (!)");
373                 }
374             }
375 
376 			// if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj
377 			if( pPickObj )
378 			{
379 				SdPage* pPage = static_cast< SdPage* >(pPickObj->GetPage());
380 				if(pPage && pPage->IsPresObj(pPickObj))
381 				{
382 					pPage->InsertPresObj( pOleObj, ePresObjKind );
383 					pOleObj->SetUserCall(pPickObj->GetUserCall());
384 				}
385 			}
386 
387 			bool bRet = true;
388 			if( pPickObj )
389 			    mpView->ReplaceObjectAtView(pPickObj, *pPV, pOleObj, sal_True );
390 			else
391 				bRet = mpView->InsertObjectAtView(pOleObj, *pPV, SDRINSERT_SETDEFLAYER);
392 
393 			if( bRet )
394 			{
395 				if (nSlotId == SID_INSERT_DIAGRAM)
396 				{
397 					pOleObj->SetProgName( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarChart" ) ) );
398 				}
399 				else if (nSlotId == SID_ATTR_TABLE)
400 				{
401 					pOleObj->SetProgName( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarCalc" ) ) );
402 				}
403 				else if (nSlotId == SID_INSERT_MATH)
404 				{
405 					pOleObj->SetProgName( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarMath" ) ) );
406 				}
407 
408 				//HMHmpView->HideMarkHdl();
409 				pOleObj->SetLogicRect(aRect);
410                 Size aTmp( OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aUnit ) );
411                 awt::Size aVisualSize;
412 				aVisualSize.Width = aTmp.Width();
413                 aVisualSize.Height = aTmp.Height();
414                 xObj->setVisualAreaSize( nAspect, aVisualSize );
415                 mpViewShell->ActivateObject(pOleObj, SVVERB_SHOW);
416 
417                 if (nSlotId == SID_INSERT_DIAGRAM)
418                 {
419                     // note, that this call modified the chart model which
420                     // results in a change notification.  So call this after
421                     // everything else is finished.
422                     mpViewShell->AdaptDefaultsForChart( xObj );
423                 }
424 			}
425 		}
426 		else
427 		{
428 			ErrorHandler::HandleError(* new StringErrorInfo(ERRCODE_SFX_OLEGENERAL,
429 										aEmptyStr ) );
430         }
431 	}
432 	else
433 	{
434 		/**********************************************************************
435 		* Objekt einfuegen
436 		**********************************************************************/
437         sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
438         sal_Bool bCreateNew = sal_False;
439         uno::Reference < embed::XEmbeddedObject > xObj;
440         uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
441         SvObjectServerList aServerLst;
442         ::rtl::OUString aName;
443 
444 		::rtl::OUString aIconMediaType;
445 		uno::Reference< io::XInputStream > xIconMetaFile;
446 
447         SFX_REQUEST_ARG( rReq, pNameItem, SfxGlobalNameItem, SID_INSERT_OBJECT, sal_False );
448         if ( nSlotId == SID_INSERT_OBJECT && pNameItem )
449         {
450             SvGlobalName aClassName = pNameItem->GetValue();
451             xObj =  mpViewShell->GetViewFrame()->GetObjectShell()->
452                     GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName.GetByteSequence(), aName );
453         }
454         else
455         {
456             switch ( nSlotId )
457             {
458                 case SID_INSERT_OBJECT :
459                 {
460                     aServerLst.FillInsertObjects();
461                     if (mpDoc->GetDocumentType() == DOCUMENT_TYPE_DRAW)
462                     {
463                         aServerLst.Remove( GraphicDocShell::Factory().GetClassId() );
464                     }
465                     else
466                     {
467                         aServerLst.Remove( DrawDocShell::Factory().GetClassId() );
468                     }
469 
470                     // intentionally no break!
471                 }
472                 case SID_INSERT_PLUGIN :
473                 case SID_INSERT_FLOATINGFRAME :
474                 {
475                     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
476                     SfxAbstractInsertObjectDialog* pDlg =
477                             pFact->CreateInsertObjectDialog( mpViewShell->GetActiveWindow(), SD_MOD()->GetSlotPool()->GetSlot(nSlotId)->GetCommandString(),
478                             xStorage, &aServerLst );
479                     if ( pDlg )
480                     {
481                         pDlg->Execute();
482                         bCreateNew = pDlg->IsCreateNew();
483                         xObj = pDlg->GetObject();
484 
485 						xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType );
486 						if ( xIconMetaFile.is() )
487 							nAspect = embed::Aspects::MSOLE_ICON;
488 
489                         if ( xObj.is() )
490                             mpViewShell->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aName );
491                         DELETEZ( pDlg );
492                     }
493 
494                     break;
495                 }
496                 case SID_INSERT_SOUND :
497                 case SID_INSERT_VIDEO :
498                 {
499                     // create special filedialog for plugins
500                     SvxPluginFileDlg aPluginFileDialog (mpWindow, nSlotId);
501                     if( ERRCODE_NONE == aPluginFileDialog.Execute () )
502                     {
503                         // get URL
504                         String aStrURL(aPluginFileDialog.GetPath());
505                         INetURLObject aURL( aStrURL, INET_PROT_FILE );
506                         if( aURL.GetProtocol() != INET_PROT_NOT_VALID )
507                         {
508                             // create a plugin object
509                             xObj = mpViewShell->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_PLUGIN_CLASSID ).GetByteSequence(), aName );
510                         }
511 
512                         if ( xObj.is() && svt::EmbeddedObjectRef::TryRunningState( xObj ) )
513                         {
514                             // set properties from dialog
515                             uno::Reference < embed::XComponentSupplier > xSup( xObj, uno::UNO_QUERY );
516                             if ( xSup.is() )
517                             {
518                                 uno::Reference < beans::XPropertySet > xSet( xSup->getComponent(), uno::UNO_QUERY );
519                                 if ( xSet.is() )
520                                 {
521                                     xSet->setPropertyValue( ::rtl::OUString::createFromAscii("PluginURL"),
522                                             uno::makeAny( ::rtl::OUString( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) );
523                                 }
524                             }
525                         }
526                         else
527                         {
528                             // PlugIn konnte nicht erzeugt werden
529                             String aStrErr( SdResId( STR_ERROR_OBJNOCREATE_PLUGIN ) );
530                             String aMask;
531                             aMask += sal_Unicode('%');
532                             aStrErr.SearchAndReplace( aMask, aStrURL );
533                             ErrorBox( mpWindow, WB_3DLOOK | WB_OK, aStrErr ).Execute();
534                         }
535                     }
536                 }
537             }
538         }
539 
540         try
541         {
542             if (xObj.is())
543             {
544                 //TODO/LATER: needs status for RESIZEONPRINTERCHANGE
545                 //if( SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE & xObj->getStatus( nAspect ) )
546                 //    aIPObj->OnDocumentPrinterChanged( mpDocSh->GetPrinter(sal_False) );
547 
548                 sal_Bool bInsertNewObject = sal_True;
549 
550                 Size aSize;
551                 MapUnit aMapUnit = MAP_100TH_MM;
552                 if ( nAspect != embed::Aspects::MSOLE_ICON )
553                 {
554                     awt::Size aSz;
555                     try
556                     {
557                         aSz = xObj->getVisualAreaSize( nAspect );
558                     }
559                     catch( embed::NoVisualAreaSizeException& )
560                     {
561                         // the default size will be set later
562                     }
563 
564                     aSize =Size( aSz.Width, aSz.Height );
565 
566                     aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
567                     if (aSize.Height() == 0 || aSize.Width() == 0)
568                     {
569                         // Rechteck mit ausgewogenem Kantenverhaeltnis
570                         aSize.Width()  = 14100;
571                         aSize.Height() = 10000;
572                         Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aMapUnit );
573                         aSz.Width = aTmp.Width();
574                         aSz.Height = aTmp.Height();
575                         xObj->setVisualAreaSize( nAspect, aSz );
576                     }
577                     else
578                     {
579                         aSize = OutputDevice::LogicToLogic(aSize, aMapUnit, MAP_100TH_MM);
580                     }
581                 }
582 
583                 if ( mpView->AreObjectsMarked() )
584                 {
585                     /**********************************************************
586                         * Ist ein leeres OLE-Objekt vorhanden?
587                         **********************************************************/
588                     const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
589 
590                     if (rMarkList.GetMarkCount() == 1)
591                     {
592                         SdrMark* pMark = rMarkList.GetMark(0);
593                         SdrObject* pObj = pMark->GetMarkedSdrObj();
594 
595                         if (pObj->GetObjInventor() == SdrInventor &&
596                         pObj->GetObjIdentifier() == OBJ_OLE2)
597                         {
598                             if ( !( (SdrOle2Obj*) pObj)->GetObjRef().is() )
599                             {
600                                 /**************************************************
601                                     * Das leere OLE-Objekt bekommt ein neues IPObj
602                                     **************************************************/
603                                 bInsertNewObject = sal_False;
604                                 pObj->SetEmptyPresObj(sal_False);
605                                 ( (SdrOle2Obj*) pObj)->SetOutlinerParaObject(NULL);
606                                 ( (SdrOle2Obj*) pObj)->SetObjRef(xObj);
607                                 ( (SdrOle2Obj*) pObj)->SetPersistName(aName);
608                                 ( (SdrOle2Obj*) pObj)->SetName(aName);
609                                 ( (SdrOle2Obj*) pObj)->SetAspect(nAspect);
610                                 Rectangle aRect = ( (SdrOle2Obj*) pObj)->GetLogicRect();
611 
612                                 //HMHmpView->HideMarkHdl();
613 
614                                 if ( nAspect == embed::Aspects::MSOLE_ICON )
615                                 {
616                                     if( xIconMetaFile.is() )
617                                         ( (SdrOle2Obj*) pObj)->SetGraphicToObj( xIconMetaFile, aIconMediaType );
618                                 }
619                                 else
620                                 {
621                                     Size aTmp = OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aMapUnit );
622                                     awt::Size aSz( aTmp.Width(), aTmp.Height() );
623                                     xObj->setVisualAreaSize( nAspect, aSz );
624                                 }
625                             }
626                         }
627                     }
628                 }
629 
630                 if (bInsertNewObject)
631                 {
632                     /**************************************************************
633                         * Ein neues OLE-Objekt wird erzeugt
634                         **************************************************************/
635                     SdrPageView* pPV = mpView->GetSdrPageView();
636                     Size aPageSize = pPV->GetPage()->GetSize();
637 
638                     // get the size from the iconified object
639                     ::svt::EmbeddedObjectRef aObjRef( xObj, nAspect );
640                     if ( nAspect == embed::Aspects::MSOLE_ICON )
641                     {
642                         aObjRef.SetGraphicStream( xIconMetaFile, aIconMediaType );
643                         MapMode aMapMode( MAP_100TH_MM );
644                         aSize = aObjRef.GetSize( &aMapMode );
645                     }
646 
647                     Point aPnt ((aPageSize.Width()  - aSize.Width())  / 2,
648                         (aPageSize.Height() - aSize.Height()) / 2);
649                     Rectangle aRect (aPnt, aSize);
650 
651                     SdrOle2Obj* pObj = new SdrOle2Obj( aObjRef, aName, aRect);
652 
653                     if( mpView->InsertObjectAtView(pObj, *pPV, SDRINSERT_SETDEFLAYER) )
654                     {
655                         //  #73279# Math objects change their object size during InsertObject.
656                         //  New size must be set in SdrObject, or a wrong scale will be set at
657                         //  ActivateObject.
658 
659                         if ( nAspect != embed::Aspects::MSOLE_ICON )
660                         {
661                             try
662                             {
663                                 awt::Size aSz = xObj->getVisualAreaSize( nAspect );
664 
665                                 Size aNewSize = Window::LogicToLogic( Size( aSz.Width, aSz.Height ),
666                                     MapMode( aMapUnit ), MapMode( MAP_100TH_MM ) );
667                                 if ( aNewSize != aSize )
668                                 {
669                                     aRect.SetSize( aNewSize );
670                                     pObj->SetLogicRect( aRect );
671                                 }
672                             }
673                             catch( embed::NoVisualAreaSizeException& )
674                             {}
675                         }
676 
677                         if (bCreateNew)
678                         {
679                             //HMHmpView->HideMarkHdl();
680                             pObj->SetLogicRect(aRect);
681 
682                             if ( nAspect != embed::Aspects::MSOLE_ICON )
683                             {
684                                 Size aTmp = OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aMapUnit );
685                                 awt::Size aSz( aTmp.Width(), aTmp.Height() );
686                                 xObj->setVisualAreaSize( nAspect, aSz );
687                             }
688 
689                             mpViewShell->ActivateObject(pObj, SVVERB_SHOW);
690                         }
691 
692                         Size aVisSizePixel = mpWindow->GetOutputSizePixel();
693                         Rectangle aVisAreaWin = mpWindow->PixelToLogic( Rectangle( Point(0,0), aVisSizePixel) );
694                         mpViewShell->VisAreaChanged(aVisAreaWin);
695                         mpDocSh->SetVisArea(aVisAreaWin);
696                     }
697                 }
698             }
699         }
700         catch (uno::Exception&)
701         {
702             // For some reason the object can not be inserted.  For example
703             // because it is password protected and is not properly unlocked.
704         }
705     }
706 }
707 
708 
709 /*************************************************************************
710 |*
711 |* FuInsertAVMedia::Konstruktor
712 |*
713 \************************************************************************/
714 
715 FuInsertAVMedia::FuInsertAVMedia(
716     ViewShell* pViewSh,
717     ::sd::Window* pWin,
718     ::sd::View* pView,
719     SdDrawDocument* pDoc,
720     SfxRequest& rReq)
721     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
722 {
723 }
724 
725 FunctionReference FuInsertAVMedia::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
726 {
727 	FunctionReference xFunc( new FuInsertAVMedia( pViewSh, pWin, pView, pDoc, rReq ) );
728 	xFunc->DoExecute(rReq);
729 	return xFunc;
730 }
731 
732 void FuInsertAVMedia::DoExecute( SfxRequest& rReq )
733 {
734 	::rtl::OUString 	aURL;
735 	const SfxItemSet*	pReqArgs = rReq.GetArgs();
736 	bool				bAPI = false;
737 
738 	if( pReqArgs )
739 	{
740 		const SfxStringItem* pStringItem = PTR_CAST( SfxStringItem, &pReqArgs->Get( rReq.GetSlot() ) );
741 
742 		if( pStringItem )
743 		{
744 			aURL = pStringItem->GetValue();
745 			bAPI = aURL.getLength();
746 		}
747 	}
748 
749 	if( bAPI || ::avmedia::MediaWindow::executeMediaURLDialog( mpWindow, aURL ) )
750 	{
751 		Size aPrefSize;
752 
753 		if( mpWindow )
754 			mpWindow->EnterWait();
755 
756 		if( !::avmedia::MediaWindow::isMediaURL( aURL, true, &aPrefSize ) )
757 		{
758 			if( mpWindow )
759 				mpWindow->LeaveWait();
760 
761 			if( !bAPI )
762 				::avmedia::MediaWindow::executeFormatErrorBox( mpWindow );
763 		}
764 		else
765 		{
766 			Point	    aPos;
767 			Size	    aSize;
768 			sal_Int8    nAction = DND_ACTION_COPY;
769 
770 			if( aPrefSize.Width() && aPrefSize.Height() )
771 			{
772 				if( mpWindow )
773 					aSize = mpWindow->PixelToLogic( aPrefSize, MAP_100TH_MM );
774 				else
775 					aSize = Application::GetDefaultDevice()->PixelToLogic( aPrefSize, MAP_100TH_MM );
776 			}
777 			else
778 				aSize = Size( 5000, 5000 );
779 
780 			if( mpWindow )
781 			{
782 				aPos = mpWindow->PixelToLogic( Rectangle( aPos, mpWindow->GetOutputSizePixel() ).Center() );
783 				aPos.X() -= aSize.Width() >> 1;
784 				aPos.Y() -= aSize.Height() >> 1;
785 			}
786 
787 		    mpView->InsertMediaURL( aURL, nAction, aPos, aSize ) ;
788 
789 			if( mpWindow )
790 				mpWindow->LeaveWait();
791 		}
792 	}
793 }
794 
795 } // end of namespace sd
796