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