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