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