xref: /aoo41x/main/sd/source/ui/func/fuinsert.cxx (revision 6f0b96b4)
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 #include <sfx2/viewfrm.hxx>
75 #include <svx/charthelper.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 we have a pick obj we need to make this new ole a pres obj replacing the current pick obj
358 			if( pPickObj )
359 			{
360 				SdPage* pPage = static_cast< SdPage* >(pPickObj->GetPage());
361 				if(pPage && pPage->IsPresObj(pPickObj))
362 				{
363 					pPage->InsertPresObj( pOleObj, ePresObjKind );
364 					pOleObj->SetUserCall(pPickObj->GetUserCall());
365 				}
366 			}
367 
368 			bool bRet = true;
369 			if( pPickObj )
370 			    mpView->ReplaceObjectAtView(pPickObj, *pPV, pOleObj, sal_True );
371 			else
372 				bRet = mpView->InsertObjectAtView(pOleObj, *pPV, SDRINSERT_SETDEFLAYER);
373 
374 			if( bRet )
375 			{
376 				if (nSlotId == SID_INSERT_DIAGRAM)
377 				{
378 					pOleObj->SetProgName( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarChart" ) ) );
379 				}
380 				else if (nSlotId == SID_ATTR_TABLE)
381 				{
382 					pOleObj->SetProgName( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarCalc" ) ) );
383 				}
384 				else if (nSlotId == SID_INSERT_MATH)
385 				{
386 					pOleObj->SetProgName( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarMath" ) ) );
387 				}
388 
389 				//HMHmpView->HideMarkHdl();
390 				pOleObj->SetLogicRect(aRect);
391                 Size aTmp( OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aUnit ) );
392                 awt::Size aVisualSize;
393 				aVisualSize.Width = aTmp.Width();
394                 aVisualSize.Height = aTmp.Height();
395                 xObj->setVisualAreaSize( nAspect, aVisualSize );
396                 mpViewShell->ActivateObject(pOleObj, SVVERB_SHOW);
397 
398                 if (nSlotId == SID_INSERT_DIAGRAM)
399                 {
400                     // note, that this call modified the chart model which
401                     // results in a change notification.  So call this after
402                     // everything else is finished.
403                     ChartHelper::AdaptDefaultsForChart( xObj );
404                 }
405 			}
406 		}
407 		else
408 		{
409 			ErrorHandler::HandleError(* new StringErrorInfo(ERRCODE_SFX_OLEGENERAL,
410 										aEmptyStr ) );
411         }
412 	}
413 	else
414 	{
415 		/**********************************************************************
416 		* Objekt einfuegen
417 		**********************************************************************/
418         sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
419         sal_Bool bCreateNew = sal_False;
420         uno::Reference < embed::XEmbeddedObject > xObj;
421         uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
422         SvObjectServerList aServerLst;
423         ::rtl::OUString aName;
424 
425 		::rtl::OUString aIconMediaType;
426 		uno::Reference< io::XInputStream > xIconMetaFile;
427 
428         SFX_REQUEST_ARG( rReq, pNameItem, SfxGlobalNameItem, SID_INSERT_OBJECT, sal_False );
429         if ( nSlotId == SID_INSERT_OBJECT && pNameItem )
430         {
431             SvGlobalName aClassName = pNameItem->GetValue();
432             xObj =  mpViewShell->GetViewFrame()->GetObjectShell()->
433                     GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName.GetByteSequence(), aName );
434         }
435         else
436         {
437             switch ( nSlotId )
438             {
439                 case SID_INSERT_OBJECT :
440                 {
441                     aServerLst.FillInsertObjects();
442                     if (mpDoc->GetDocumentType() == DOCUMENT_TYPE_DRAW)
443                     {
444                         aServerLst.Remove( GraphicDocShell::Factory().GetClassId() );
445                     }
446                     else
447                     {
448                         aServerLst.Remove( DrawDocShell::Factory().GetClassId() );
449                     }
450 
451                     // intentionally no break!
452                 }
453                 case SID_INSERT_PLUGIN :
454                 case SID_INSERT_FLOATINGFRAME :
455                 {
456                     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
457                     SfxAbstractInsertObjectDialog* pDlg =
458                             pFact->CreateInsertObjectDialog( mpViewShell->GetActiveWindow(), SD_MOD()->GetSlotPool()->GetSlot(nSlotId)->GetCommandString(),
459                             xStorage, &aServerLst );
460                     if ( pDlg )
461                     {
462                         pDlg->Execute();
463                         bCreateNew = pDlg->IsCreateNew();
464                         xObj = pDlg->GetObject();
465 
466 						xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType );
467 						if ( xIconMetaFile.is() )
468 							nAspect = embed::Aspects::MSOLE_ICON;
469 
470                         if ( xObj.is() )
471                             mpViewShell->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aName );
472                         DELETEZ( pDlg );
473                     }
474 
475                     break;
476                 }
477                 case SID_INSERT_SOUND :
478                 case SID_INSERT_VIDEO :
479                 {
480                     // create special filedialog for plugins
481                     SvxPluginFileDlg aPluginFileDialog (mpWindow, nSlotId);
482                     if( ERRCODE_NONE == aPluginFileDialog.Execute () )
483                     {
484                         // get URL
485                         String aStrURL(aPluginFileDialog.GetPath());
486                         INetURLObject aURL( aStrURL, INET_PROT_FILE );
487                         if( aURL.GetProtocol() != INET_PROT_NOT_VALID )
488                         {
489                             // create a plugin object
490                             xObj = mpViewShell->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_PLUGIN_CLASSID ).GetByteSequence(), aName );
491                         }
492 
493                         if ( xObj.is() && svt::EmbeddedObjectRef::TryRunningState( xObj ) )
494                         {
495                             // set properties from dialog
496                             uno::Reference < embed::XComponentSupplier > xSup( xObj, uno::UNO_QUERY );
497                             if ( xSup.is() )
498                             {
499                                 uno::Reference < beans::XPropertySet > xSet( xSup->getComponent(), uno::UNO_QUERY );
500                                 if ( xSet.is() )
501                                 {
502                                     xSet->setPropertyValue( ::rtl::OUString::createFromAscii("PluginURL"),
503                                             uno::makeAny( ::rtl::OUString( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) );
504                                 }
505                             }
506                         }
507                         else
508                         {
509                             // PlugIn konnte nicht erzeugt werden
510                             String aStrErr( SdResId( STR_ERROR_OBJNOCREATE_PLUGIN ) );
511                             String aMask;
512                             aMask += sal_Unicode('%');
513                             aStrErr.SearchAndReplace( aMask, aStrURL );
514                             ErrorBox( mpWindow, WB_3DLOOK | WB_OK, aStrErr ).Execute();
515                         }
516                     }
517                 }
518             }
519         }
520 
521         try
522         {
523             if (xObj.is())
524             {
525                 //TODO/LATER: needs status for RESIZEONPRINTERCHANGE
526                 //if( SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE & xObj->getStatus( nAspect ) )
527                 //    aIPObj->OnDocumentPrinterChanged( mpDocSh->GetPrinter(sal_False) );
528 
529                 sal_Bool bInsertNewObject = sal_True;
530 
531                 Size aSize;
532                 MapUnit aMapUnit = MAP_100TH_MM;
533                 if ( nAspect != embed::Aspects::MSOLE_ICON )
534                 {
535                     awt::Size aSz;
536                     try
537                     {
538                         aSz = xObj->getVisualAreaSize( nAspect );
539                     }
540                     catch( embed::NoVisualAreaSizeException& )
541                     {
542                         // the default size will be set later
543                     }
544 
545                     aSize =Size( aSz.Width, aSz.Height );
546 
547                     aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
548                     if (aSize.Height() == 0 || aSize.Width() == 0)
549                     {
550                         // Rechteck mit ausgewogenem Kantenverhaeltnis
551                         aSize.Width()  = 14100;
552                         aSize.Height() = 10000;
553                         Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aMapUnit );
554                         aSz.Width = aTmp.Width();
555                         aSz.Height = aTmp.Height();
556                         xObj->setVisualAreaSize( nAspect, aSz );
557                     }
558                     else
559                     {
560                         aSize = OutputDevice::LogicToLogic(aSize, aMapUnit, MAP_100TH_MM);
561                     }
562                 }
563 
564                 if ( mpView->AreObjectsMarked() )
565                 {
566                     /**********************************************************
567                         * Ist ein leeres OLE-Objekt vorhanden?
568                         **********************************************************/
569                     const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
570 
571                     if (rMarkList.GetMarkCount() == 1)
572                     {
573                         SdrMark* pMark = rMarkList.GetMark(0);
574                         SdrObject* pObj = pMark->GetMarkedSdrObj();
575 
576                         if (pObj->GetObjInventor() == SdrInventor &&
577                         pObj->GetObjIdentifier() == OBJ_OLE2)
578                         {
579                             if ( !( (SdrOle2Obj*) pObj)->GetObjRef().is() )
580                             {
581                                 /**************************************************
582                                     * Das leere OLE-Objekt bekommt ein neues IPObj
583                                     **************************************************/
584                                 bInsertNewObject = sal_False;
585                                 pObj->SetEmptyPresObj(sal_False);
586                                 ( (SdrOle2Obj*) pObj)->SetOutlinerParaObject(NULL);
587                                 ( (SdrOle2Obj*) pObj)->SetObjRef(xObj);
588                                 ( (SdrOle2Obj*) pObj)->SetPersistName(aName);
589                                 ( (SdrOle2Obj*) pObj)->SetName(aName);
590                                 ( (SdrOle2Obj*) pObj)->SetAspect(nAspect);
591                                 Rectangle aRect = ( (SdrOle2Obj*) pObj)->GetLogicRect();
592 
593                                 //HMHmpView->HideMarkHdl();
594 
595                                 if ( nAspect == embed::Aspects::MSOLE_ICON )
596                                 {
597                                     if( xIconMetaFile.is() )
598                                         ( (SdrOle2Obj*) pObj)->SetGraphicToObj( xIconMetaFile, aIconMediaType );
599                                 }
600                                 else
601                                 {
602                                     Size aTmp = OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aMapUnit );
603                                     awt::Size aSz( aTmp.Width(), aTmp.Height() );
604                                     xObj->setVisualAreaSize( nAspect, aSz );
605                                 }
606                             }
607                         }
608                     }
609                 }
610 
611                 if (bInsertNewObject)
612                 {
613                     /**************************************************************
614                         * Ein neues OLE-Objekt wird erzeugt
615                         **************************************************************/
616                     SdrPageView* pPV = mpView->GetSdrPageView();
617                     Size aPageSize = pPV->GetPage()->GetSize();
618 
619                     // get the size from the iconified object
620                     ::svt::EmbeddedObjectRef aObjRef( xObj, nAspect );
621                     if ( nAspect == embed::Aspects::MSOLE_ICON )
622                     {
623                         aObjRef.SetGraphicStream( xIconMetaFile, aIconMediaType );
624                         MapMode aMapMode( MAP_100TH_MM );
625                         aSize = aObjRef.GetSize( &aMapMode );
626                     }
627 
628                     Point aPnt ((aPageSize.Width()  - aSize.Width())  / 2,
629                         (aPageSize.Height() - aSize.Height()) / 2);
630                     Rectangle aRect (aPnt, aSize);
631 
632                     SdrOle2Obj* pObj = new SdrOle2Obj( aObjRef, aName, aRect);
633 
634                     if( mpView->InsertObjectAtView(pObj, *pPV, SDRINSERT_SETDEFLAYER) )
635                     {
636                         //  #73279# Math objects change their object size during InsertObject.
637                         //  New size must be set in SdrObject, or a wrong scale will be set at
638                         //  ActivateObject.
639 
640                         if ( nAspect != embed::Aspects::MSOLE_ICON )
641                         {
642                             try
643                             {
644                                 awt::Size aSz = xObj->getVisualAreaSize( nAspect );
645 
646                                 Size aNewSize = Window::LogicToLogic( Size( aSz.Width, aSz.Height ),
647                                     MapMode( aMapUnit ), MapMode( MAP_100TH_MM ) );
648                                 if ( aNewSize != aSize )
649                                 {
650                                     aRect.SetSize( aNewSize );
651                                     pObj->SetLogicRect( aRect );
652                                 }
653                             }
654                             catch( embed::NoVisualAreaSizeException& )
655                             {}
656                         }
657 
658                         if (bCreateNew)
659                         {
660                             //HMHmpView->HideMarkHdl();
661                             pObj->SetLogicRect(aRect);
662 
663                             if ( nAspect != embed::Aspects::MSOLE_ICON )
664                             {
665                                 Size aTmp = OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aMapUnit );
666                                 awt::Size aSz( aTmp.Width(), aTmp.Height() );
667                                 xObj->setVisualAreaSize( nAspect, aSz );
668                             }
669 
670                             mpViewShell->ActivateObject(pObj, SVVERB_SHOW);
671                         }
672 
673                         Size aVisSizePixel = mpWindow->GetOutputSizePixel();
674                         Rectangle aVisAreaWin = mpWindow->PixelToLogic( Rectangle( Point(0,0), aVisSizePixel) );
675                         mpViewShell->VisAreaChanged(aVisAreaWin);
676                         mpDocSh->SetVisArea(aVisAreaWin);
677                     }
678                 }
679             }
680         }
681         catch (uno::Exception&)
682         {
683             // For some reason the object can not be inserted.  For example
684             // because it is password protected and is not properly unlocked.
685         }
686     }
687 }
688 
689 
690 /*************************************************************************
691 |*
692 |* FuInsertAVMedia::Konstruktor
693 |*
694 \************************************************************************/
695 
696 FuInsertAVMedia::FuInsertAVMedia(
697     ViewShell* pViewSh,
698     ::sd::Window* pWin,
699     ::sd::View* pView,
700     SdDrawDocument* pDoc,
701     SfxRequest& rReq)
702     : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
703 {
704 }
705 
706 FunctionReference FuInsertAVMedia::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
707 {
708 	FunctionReference xFunc( new FuInsertAVMedia( pViewSh, pWin, pView, pDoc, rReq ) );
709 	xFunc->DoExecute(rReq);
710 	return xFunc;
711 }
712 
713 void FuInsertAVMedia::DoExecute( SfxRequest& rReq )
714 {
715 	::rtl::OUString 	aURL;
716 	const SfxItemSet*	pReqArgs = rReq.GetArgs();
717 	bool				bAPI = false;
718 
719 	if( pReqArgs )
720 	{
721 		const SfxStringItem* pStringItem = PTR_CAST( SfxStringItem, &pReqArgs->Get( rReq.GetSlot() ) );
722 
723 		if( pStringItem )
724 		{
725 			aURL = pStringItem->GetValue();
726 			bAPI = aURL.getLength();
727 		}
728 	}
729 
730 	if( bAPI || ::avmedia::MediaWindow::executeMediaURLDialog( mpWindow, aURL ) )
731 	{
732 		Size aPrefSize;
733 
734 		if( mpWindow )
735 			mpWindow->EnterWait();
736 
737 		if( !::avmedia::MediaWindow::isMediaURL( aURL, true, &aPrefSize ) )
738 		{
739 			if( mpWindow )
740 				mpWindow->LeaveWait();
741 
742 			if( !bAPI )
743 				::avmedia::MediaWindow::executeFormatErrorBox( mpWindow );
744 		}
745 		else
746 		{
747 			Point	    aPos;
748 			Size	    aSize;
749 			sal_Int8    nAction = DND_ACTION_COPY;
750 
751 			if( aPrefSize.Width() && aPrefSize.Height() )
752 			{
753 				if( mpWindow )
754 					aSize = mpWindow->PixelToLogic( aPrefSize, MAP_100TH_MM );
755 				else
756 					aSize = Application::GetDefaultDevice()->PixelToLogic( aPrefSize, MAP_100TH_MM );
757 			}
758 			else
759 				aSize = Size( 5000, 5000 );
760 
761 			if( mpWindow )
762 			{
763 				aPos = mpWindow->PixelToLogic( Rectangle( aPos, mpWindow->GetOutputSizePixel() ).Center() );
764 				aPos.X() -= aSize.Width() >> 1;
765 				aPos.Y() -= aSize.Height() >> 1;
766 			}
767 
768 		    mpView->InsertMediaURL( aURL, nAction, aPos, aSize ) ;
769 
770 			if( mpWindow )
771 				mpWindow->LeaveWait();
772 		}
773 	}
774 }
775 
776 } // end of namespace sd
777