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