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