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