xref: /AOO41X/main/sd/source/ui/view/sdview4.cxx (revision 70d3707ac8de2c13f15b54a698b22c6ac9b73267)
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
10cdf0e10cSrcweir  *
115b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
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.
19cdf0e10cSrcweir  *
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 "View.hxx"
28cdf0e10cSrcweir #include <unotools/localfilehelper.hxx>
29cdf0e10cSrcweir #include <sfx2/request.hxx>
30cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
31cdf0e10cSrcweir #include <sfx2/fcontnr.hxx>
32cdf0e10cSrcweir #include <sfx2/docfile.hxx>
33cdf0e10cSrcweir #include <vcl/msgbox.hxx>
34cdf0e10cSrcweir #include <svl/urlbmk.hxx>
35cdf0e10cSrcweir #include <svx/svdpagv.hxx>
36cdf0e10cSrcweir #include <svx/xfillit.hxx>
37cdf0e10cSrcweir #include <svx/svdundo.hxx>
38cdf0e10cSrcweir #include <svx/xoutbmp.hxx>
39cdf0e10cSrcweir #include <svx/svdograf.hxx>
40cdf0e10cSrcweir #include <svx/svdomedia.hxx>
41cdf0e10cSrcweir #include <svx/svdoole2.hxx>
42cdf0e10cSrcweir #include <sot/storage.hxx>
43cdf0e10cSrcweir #include <sfx2/app.hxx>
44cdf0e10cSrcweir #include <avmedia/mediawindow.hxx>
45cdf0e10cSrcweir #include <svtools/ehdl.hxx>
46cdf0e10cSrcweir #include <svtools/sfxecode.hxx>
47cdf0e10cSrcweir #include <svtools/filter.hxx>
48cdf0e10cSrcweir #include "app.hrc"
49cdf0e10cSrcweir #include "Window.hxx"
50cdf0e10cSrcweir #include "DrawDocShell.hxx"
51cdf0e10cSrcweir #include "DrawViewShell.hxx"
52cdf0e10cSrcweir #include "fuinsfil.hxx"
53cdf0e10cSrcweir #include "drawdoc.hxx"
54cdf0e10cSrcweir #include "sdresid.hxx"
55cdf0e10cSrcweir #include "strings.hrc"
56cdf0e10cSrcweir #include "imapinfo.hxx"
57cdf0e10cSrcweir #include "sdpage.hxx"
58cdf0e10cSrcweir #include "view/SlideSorterView.hxx"
59cdf0e10cSrcweir #include "undo/undoobjects.hxx"
60cdf0e10cSrcweir 
61cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
62cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
63cdf0e10cSrcweir #include <com/sun/star/embed/XEmbedPersist.hpp>
64cdf0e10cSrcweir #include <com/sun/star/embed/Aspects.hpp>
65cdf0e10cSrcweir #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
66cdf0e10cSrcweir #include <svtools/soerr.hxx>
67cdf0e10cSrcweir 
68cdf0e10cSrcweir #include <sfx2/ipclient.hxx>
69cdf0e10cSrcweir 
70cdf0e10cSrcweir using namespace com::sun::star;
71cdf0e10cSrcweir 
72cdf0e10cSrcweir namespace sd {
73cdf0e10cSrcweir 
74cdf0e10cSrcweir #ifdef _MSC_VER
75cdf0e10cSrcweir #pragma optimize ( "", off )
76cdf0e10cSrcweir #endif
77cdf0e10cSrcweir 
78cdf0e10cSrcweir /*************************************************************************
79cdf0e10cSrcweir |*
80cdf0e10cSrcweir |* Graphik einfuegen
81cdf0e10cSrcweir |* Wird ein leeres Graphikobjekt uebergeben, so wird dieses gefuellt.
82cdf0e10cSrcweir |* Andernfalls wird ein an der gegebenen Position vorhandenes Objekt
83cdf0e10cSrcweir |* gefuellt. Ist an der Position kein Objekt vorhanden, so wird ein neues
84cdf0e10cSrcweir |* Objekt erzeugt und ein Pointer auf dieses Objekt zurueckgegeben.
85cdf0e10cSrcweir |*
86cdf0e10cSrcweir \************************************************************************/
87cdf0e10cSrcweir 
88cdf0e10cSrcweir SdrGrafObj* View::InsertGraphic( const Graphic& rGraphic, sal_Int8& rAction,
89cdf0e10cSrcweir 								   const Point& rPos, SdrObject* pObj, ImageMap* pImageMap )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir 	SdrEndTextEdit();
92cdf0e10cSrcweir 	mnAction = rAction;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	// Liegt ein Objekt an der Position rPos?
95cdf0e10cSrcweir 	SdrGrafObj*		pNewGrafObj = NULL;
96cdf0e10cSrcweir 	SdrPageView*	pPV = GetSdrPageView();
97cdf0e10cSrcweir 	SdrObject*		pPickObj = pObj;
98cdf0e10cSrcweir 	const bool bOnMaster = pPV && pPV->GetPage() && pPV->GetPage()->IsMasterPage();
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 	if(pPV && this->ISA(::sd::slidesorter::view::SlideSorterView))
101cdf0e10cSrcweir 	{
102cdf0e10cSrcweir 		if(!pPV->GetPageRect().IsInside(rPos))
103cdf0e10cSrcweir 			pPV = 0L;
104cdf0e10cSrcweir 	}
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	if( !pPickObj && pPV )
107cdf0e10cSrcweir 	{
108cdf0e10cSrcweir 		SdrPageView* pPageView = pPV;
109cdf0e10cSrcweir 		PickObj(rPos, getHitTolLog(), pPickObj, pPageView);
110cdf0e10cSrcweir 	}
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 	if( mnAction == DND_ACTION_LINK && pPickObj && pPV )
113cdf0e10cSrcweir 	{
114cdf0e10cSrcweir 		const bool bIsGraphic = pPickObj->ISA( SdrGrafObj );
115cdf0e10cSrcweir 		if( bIsGraphic || (pObj->IsEmptyPresObj() && !bOnMaster) )
116cdf0e10cSrcweir 		{
117cdf0e10cSrcweir 			if( IsUndoEnabled() )
118cdf0e10cSrcweir 				BegUndo(String(SdResId(STR_INSERTGRAPHIC)));
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 			SdPage* pPage = (SdPage*) pPickObj->GetPage();
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 			if( bIsGraphic )
123cdf0e10cSrcweir 			{
124cdf0e10cSrcweir 				// Das Objekt wird mit der Bitmap gefuellt
125cdf0e10cSrcweir 				pNewGrafObj = (SdrGrafObj*) pPickObj->Clone();
126cdf0e10cSrcweir 				pNewGrafObj->SetGraphic(rGraphic);
127cdf0e10cSrcweir 			}
128cdf0e10cSrcweir 			else
129cdf0e10cSrcweir 			{
130cdf0e10cSrcweir 				pNewGrafObj = new SdrGrafObj( rGraphic, pPickObj->GetLogicRect() );
131cdf0e10cSrcweir 				pNewGrafObj->SetEmptyPresObj(sal_True);
132cdf0e10cSrcweir 			}
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 			if ( pNewGrafObj->IsEmptyPresObj() )
135cdf0e10cSrcweir 			{
136cdf0e10cSrcweir 				Rectangle aRect( pNewGrafObj->GetLogicRect() );
137cdf0e10cSrcweir 				pNewGrafObj->AdjustToMaxRect( aRect, sal_False );
138cdf0e10cSrcweir 				pNewGrafObj->SetOutlinerParaObject(NULL);
139cdf0e10cSrcweir 				pNewGrafObj->SetEmptyPresObj(sal_False);
140cdf0e10cSrcweir 			}
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 			if (pPage && pPage->IsPresObj(pPickObj))
143cdf0e10cSrcweir 			{
144cdf0e10cSrcweir 				// Neues PresObj in die Liste eintragen
145cdf0e10cSrcweir 				pPage->InsertPresObj( pNewGrafObj, PRESOBJ_GRAPHIC );
146cdf0e10cSrcweir 				pNewGrafObj->SetUserCall(pPickObj->GetUserCall());
147cdf0e10cSrcweir 			}
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 			if (pImageMap)
150cdf0e10cSrcweir 				pNewGrafObj->InsertUserData(new SdIMapInfo(*pImageMap));
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 			ReplaceObjectAtView(pPickObj, *pPV, pNewGrafObj); // maybe ReplaceObjectAtView
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 			if( IsUndoEnabled() )
155cdf0e10cSrcweir 				EndUndo();
156cdf0e10cSrcweir 		}
157cdf0e10cSrcweir 		else if (pPickObj->IsClosedObj() && !pPickObj->ISA(SdrOle2Obj))
158cdf0e10cSrcweir 		{
159cdf0e10cSrcweir 			/******************************************************************
160cdf0e10cSrcweir 			* Das Objekt wird mit der Graphik gefuellt
161cdf0e10cSrcweir 			******************************************************************/
162cdf0e10cSrcweir 			if( IsUndoEnabled() )
163cdf0e10cSrcweir 			{
164cdf0e10cSrcweir 				BegUndo(String(SdResId(STR_UNDO_DRAGDROP)));
165cdf0e10cSrcweir 				AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoAttrObject(*pPickObj));
166cdf0e10cSrcweir 				EndUndo();
167cdf0e10cSrcweir 			}
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 			SfxItemSet aSet(mpDocSh->GetPool(), XATTR_FILLSTYLE, XATTR_FILLBITMAP);
170cdf0e10cSrcweir 			aSet.Put(XFillStyleItem(XFILL_BITMAP));
171*70d3707aSArmin Le Grand 			aSet.Put(XFillBitmapItem(&mpDocSh->GetPool(), rGraphic));
172cdf0e10cSrcweir 			pPickObj->SetMergedItemSetAndBroadcast(aSet);
173cdf0e10cSrcweir 		}
174cdf0e10cSrcweir 	}
175cdf0e10cSrcweir 	else if ( pPV )
176cdf0e10cSrcweir 	{
177cdf0e10cSrcweir 		// create  new object
178cdf0e10cSrcweir 		Size aSize;
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 		if ( rGraphic.GetPrefMapMode().GetMapUnit() == MAP_PIXEL )
181cdf0e10cSrcweir 		{
182cdf0e10cSrcweir 			::OutputDevice* pOutDev = 0;
183cdf0e10cSrcweir 			if( mpViewSh )
184cdf0e10cSrcweir 				pOutDev = mpViewSh->GetActiveWindow();
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 			if( !pOutDev )
187cdf0e10cSrcweir 				pOutDev = Application::GetDefaultDevice();
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 			if( pOutDev )
190cdf0e10cSrcweir 				aSize = pOutDev->PixelToLogic( rGraphic.GetPrefSize(), MAP_100TH_MM );
191cdf0e10cSrcweir 		}
192cdf0e10cSrcweir 		else
193cdf0e10cSrcweir 		{
194cdf0e10cSrcweir 			aSize = OutputDevice::LogicToLogic( rGraphic.GetPrefSize(),
195cdf0e10cSrcweir 											    rGraphic.GetPrefMapMode(),
196cdf0e10cSrcweir 											    MapMode( MAP_100TH_MM ) );
197cdf0e10cSrcweir 		}
198cdf0e10cSrcweir 
199cdf0e10cSrcweir 		pNewGrafObj = new SdrGrafObj( rGraphic, Rectangle( rPos, aSize ) );
200cdf0e10cSrcweir 		SdrPage* pPage = pPV->GetPage();
201cdf0e10cSrcweir 		Size aPageSize( pPage->GetSize() );
202cdf0e10cSrcweir 		aPageSize.Width()  -= pPage->GetLftBorder() + pPage->GetRgtBorder();
203cdf0e10cSrcweir 		aPageSize.Height() -= pPage->GetUppBorder() + pPage->GetLwrBorder();
204cdf0e10cSrcweir 		pNewGrafObj->AdjustToMaxRect( Rectangle( Point(), aPageSize ), sal_True );
205cdf0e10cSrcweir //		pNewGrafObj->AdjustToMaxRect( Rectangle( pPV->GetOffset(), aPageSize ), sal_True );
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 		sal_uLong	nOptions = SDRINSERT_SETDEFLAYER;
208cdf0e10cSrcweir 		sal_Bool	bIsPresTarget = sal_False;
209cdf0e10cSrcweir 
210cdf0e10cSrcweir         if ((mpViewSh
211cdf0e10cSrcweir                 && mpViewSh->GetViewShell()!=NULL
212cdf0e10cSrcweir                 && mpViewSh->GetViewShell()->GetIPClient()
213cdf0e10cSrcweir                 && mpViewSh->GetViewShell()->GetIPClient()->IsObjectInPlaceActive())
214cdf0e10cSrcweir             || this->ISA(::sd::slidesorter::view::SlideSorterView))
215cdf0e10cSrcweir 			nOptions |= SDRINSERT_DONTMARK;
216cdf0e10cSrcweir 
217cdf0e10cSrcweir 		if( ( mnAction & DND_ACTION_MOVE ) && pPickObj && (pPickObj->IsEmptyPresObj() || pPickObj->GetUserCall()) )
218cdf0e10cSrcweir 		{
219cdf0e10cSrcweir 			SdPage* pP = static_cast< SdPage* >( pPickObj->GetPage() );
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 			if ( pP && pP->IsMasterPage() )
222cdf0e10cSrcweir 				bIsPresTarget = pP->IsPresObj(pPickObj);
223cdf0e10cSrcweir 		}
224cdf0e10cSrcweir 
225cdf0e10cSrcweir 		if( ( mnAction & DND_ACTION_MOVE ) && pPickObj && !bIsPresTarget )
226cdf0e10cSrcweir 		{
227cdf0e10cSrcweir 			// replace object
228cdf0e10cSrcweir 			if (pImageMap)
229cdf0e10cSrcweir 				pNewGrafObj->InsertUserData(new SdIMapInfo(*pImageMap));
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 			Rectangle aPickObjRect(pPickObj->GetCurrentBoundRect());
232cdf0e10cSrcweir 			Size aPickObjSize(aPickObjRect.GetSize());
233cdf0e10cSrcweir 			Rectangle aObjRect(pNewGrafObj->GetCurrentBoundRect());
234cdf0e10cSrcweir 			Size aObjSize(aObjRect.GetSize());
235cdf0e10cSrcweir 
236cdf0e10cSrcweir 			Fraction aScaleWidth(aPickObjSize.Width(), aObjSize.Width());
237cdf0e10cSrcweir 			Fraction aScaleHeight(aPickObjSize.Height(), aObjSize.Height());
238cdf0e10cSrcweir 			pNewGrafObj->NbcResize(aObjRect.TopLeft(), aScaleWidth, aScaleHeight);
239cdf0e10cSrcweir 
240cdf0e10cSrcweir 			Point aVec = aPickObjRect.TopLeft() - aObjRect.TopLeft();
241cdf0e10cSrcweir 			pNewGrafObj->NbcMove(Size(aVec.X(), aVec.Y()));
242cdf0e10cSrcweir 
243cdf0e10cSrcweir 			const bool bUndo = IsUndoEnabled();
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 			if( bUndo )
246cdf0e10cSrcweir 				BegUndo(String(SdResId(STR_UNDO_DRAGDROP)));
247cdf0e10cSrcweir 			pNewGrafObj->NbcSetLayer(pPickObj->GetLayer());
248cdf0e10cSrcweir 			SdrPage* pP = pPV->GetPage();
249cdf0e10cSrcweir 			pP->InsertObject(pNewGrafObj);
250cdf0e10cSrcweir 			if( bUndo )
251cdf0e10cSrcweir 			{
252cdf0e10cSrcweir 				AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoNewObject(*pNewGrafObj));
253cdf0e10cSrcweir 				AddUndo(mpDoc->GetSdrUndoFactory().CreateUndoDeleteObject(*pPickObj));
254cdf0e10cSrcweir 			}
255cdf0e10cSrcweir 			pP->RemoveObject(pPickObj->GetOrdNum());
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 			if( bUndo )
258cdf0e10cSrcweir 			{
259cdf0e10cSrcweir 				EndUndo();
260cdf0e10cSrcweir 			}
261cdf0e10cSrcweir 			else
262cdf0e10cSrcweir 			{
263cdf0e10cSrcweir 				SdrObject::Free(pPickObj);
264cdf0e10cSrcweir 			}
265cdf0e10cSrcweir 			mnAction = DND_ACTION_COPY;
266cdf0e10cSrcweir 		}
267cdf0e10cSrcweir 		else
268cdf0e10cSrcweir 		{
269cdf0e10cSrcweir 			InsertObjectAtView(pNewGrafObj, *pPV, nOptions);
270cdf0e10cSrcweir 
271cdf0e10cSrcweir 			if( pImageMap )
272cdf0e10cSrcweir 				pNewGrafObj->InsertUserData(new SdIMapInfo(*pImageMap));
273cdf0e10cSrcweir 		}
274cdf0e10cSrcweir 	}
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 	rAction = mnAction;
277cdf0e10cSrcweir 
278cdf0e10cSrcweir 	return pNewGrafObj;
279cdf0e10cSrcweir }
280cdf0e10cSrcweir 
281cdf0e10cSrcweir // -----------------------------------------------------------------------------
282cdf0e10cSrcweir 
283cdf0e10cSrcweir SdrMediaObj* View::InsertMediaURL( const rtl::OUString& rMediaURL, sal_Int8& rAction,
284cdf0e10cSrcweir 								   const Point& rPos, const Size& rSize )
285cdf0e10cSrcweir {
286cdf0e10cSrcweir 	SdrEndTextEdit();
287cdf0e10cSrcweir 	mnAction = rAction;
288cdf0e10cSrcweir 
289cdf0e10cSrcweir 	SdrMediaObj*	pNewMediaObj = NULL;
290cdf0e10cSrcweir 	SdrPageView*	pPV = GetSdrPageView();
291cdf0e10cSrcweir 	SdrObject*		pPickObj = GetEmptyPresentationObject( PRESOBJ_MEDIA );
292cdf0e10cSrcweir 
293cdf0e10cSrcweir 	if(pPV && this->ISA(::sd::slidesorter::view::SlideSorterView ))
294cdf0e10cSrcweir 	{
295cdf0e10cSrcweir 		if(!pPV->GetPageRect().IsInside(rPos))
296cdf0e10cSrcweir 			pPV = 0L;
297cdf0e10cSrcweir 	}
298cdf0e10cSrcweir 
299cdf0e10cSrcweir 	if( !pPickObj && pPV )
300cdf0e10cSrcweir 	{
301cdf0e10cSrcweir 		SdrPageView* pPageView = pPV;
302cdf0e10cSrcweir 		PickObj(rPos, getHitTolLog(), pPickObj, pPageView);
303cdf0e10cSrcweir 	}
304cdf0e10cSrcweir 
305cdf0e10cSrcweir 	if( mnAction == DND_ACTION_LINK && pPickObj && pPV && pPickObj->ISA( SdrMediaObj ) )
306cdf0e10cSrcweir 	{
307cdf0e10cSrcweir 		pNewMediaObj = static_cast< SdrMediaObj* >( pPickObj->Clone() );
308cdf0e10cSrcweir 		pNewMediaObj->setURL( rMediaURL );
309cdf0e10cSrcweir 
310cdf0e10cSrcweir     	BegUndo(String(SdResId(STR_UNDO_DRAGDROP)));
311cdf0e10cSrcweir 		ReplaceObjectAtView(pPickObj, *pPV, pNewMediaObj);
312cdf0e10cSrcweir 		EndUndo();
313cdf0e10cSrcweir 	}
314cdf0e10cSrcweir 	else if( pPV )
315cdf0e10cSrcweir 	{
316cdf0e10cSrcweir 		Rectangle aRect( rPos, rSize );
317cdf0e10cSrcweir 		if( pPickObj )
318cdf0e10cSrcweir 			aRect = pPickObj->GetLogicRect();
319cdf0e10cSrcweir 
320cdf0e10cSrcweir 
321cdf0e10cSrcweir     	pNewMediaObj = new SdrMediaObj( aRect );
322cdf0e10cSrcweir 
323cdf0e10cSrcweir 		bool bIsPres = false;
324cdf0e10cSrcweir 		if( pPickObj )
325cdf0e10cSrcweir 		{
326cdf0e10cSrcweir 			SdPage* pPage = static_cast< SdPage* >(pPickObj->GetPage());
327cdf0e10cSrcweir 			bIsPres = pPage && pPage->IsPresObj(pPickObj);
328cdf0e10cSrcweir 			if( bIsPres )
329cdf0e10cSrcweir 			{
330cdf0e10cSrcweir 				pPage->InsertPresObj( pNewMediaObj, PRESOBJ_MEDIA );
331cdf0e10cSrcweir 			}
332cdf0e10cSrcweir 		}
333cdf0e10cSrcweir 
334cdf0e10cSrcweir 		if( pPickObj )
335cdf0e10cSrcweir 			ReplaceObjectAtView(pPickObj, *pPV, pNewMediaObj);
336cdf0e10cSrcweir 		else
337cdf0e10cSrcweir 			InsertObjectAtView( pNewMediaObj, *pPV, SDRINSERT_SETDEFLAYER );
338cdf0e10cSrcweir 
339cdf0e10cSrcweir 	    pNewMediaObj->setURL( rMediaURL );
340cdf0e10cSrcweir 
341cdf0e10cSrcweir 		if( pPickObj )
342cdf0e10cSrcweir 		{
343cdf0e10cSrcweir 			pNewMediaObj->AdjustToMaxRect( pPickObj->GetLogicRect() );
344cdf0e10cSrcweir 			if( bIsPres )
345cdf0e10cSrcweir 				pNewMediaObj->SetUserCall(pPickObj->GetUserCall());
346cdf0e10cSrcweir 		}
347cdf0e10cSrcweir 	}
348cdf0e10cSrcweir 
349cdf0e10cSrcweir 	rAction = mnAction;
350cdf0e10cSrcweir 
351cdf0e10cSrcweir 	return pNewMediaObj;
352cdf0e10cSrcweir }
353cdf0e10cSrcweir 
354cdf0e10cSrcweir /*************************************************************************
355cdf0e10cSrcweir |*
356cdf0e10cSrcweir |* Timer-Handler fuer InsertFile beim Drop()
357cdf0e10cSrcweir |*
358cdf0e10cSrcweir \************************************************************************/
359cdf0e10cSrcweir 
360cdf0e10cSrcweir IMPL_LINK( View, DropInsertFileHdl, Timer*, EMPTYARG )
361cdf0e10cSrcweir {
362cdf0e10cSrcweir 	DBG_ASSERT( mpViewSh, "sd::View::DropInsertFileHdl(), I need a view shell to work!" );
363cdf0e10cSrcweir 	if( !mpViewSh )
364cdf0e10cSrcweir 		return 0;
365cdf0e10cSrcweir 
366cdf0e10cSrcweir     SfxErrorContext aEc( ERRCTX_ERROR, mpViewSh->GetActiveWindow(), RID_SO_ERRCTX );
367cdf0e10cSrcweir     ErrCode nError = 0;
368cdf0e10cSrcweir 
369cdf0e10cSrcweir 	::std::vector< String >::const_iterator aIter( maDropFileVector.begin() );
370cdf0e10cSrcweir 
371cdf0e10cSrcweir     while( (aIter != maDropFileVector.end()) && !nError )
372cdf0e10cSrcweir     {
373cdf0e10cSrcweir 	    String          aCurrentDropFile( *aIter );
374cdf0e10cSrcweir         INetURLObject   aURL( aCurrentDropFile );
375cdf0e10cSrcweir 	    sal_Bool		    bOK = sal_False;
376cdf0e10cSrcweir 
377cdf0e10cSrcweir 	    if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
378cdf0e10cSrcweir 	    {
379cdf0e10cSrcweir 		    String aURLStr;
380cdf0e10cSrcweir 		    ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aCurrentDropFile, aURLStr );
381cdf0e10cSrcweir 		    aURL = INetURLObject( aURLStr );
382cdf0e10cSrcweir 	    }
383cdf0e10cSrcweir 
384cdf0e10cSrcweir         GraphicFilter*  pGraphicFilter = GraphicFilter::GetGraphicFilter();
385cdf0e10cSrcweir 	    Graphic			aGraphic;
386cdf0e10cSrcweir 
387cdf0e10cSrcweir         aCurrentDropFile = aURL.GetMainURL( INetURLObject::NO_DECODE );
388cdf0e10cSrcweir 
389cdf0e10cSrcweir 		if( !::avmedia::MediaWindow::isMediaURL( aCurrentDropFile ) )
390cdf0e10cSrcweir 		{
391cdf0e10cSrcweir 			if( !pGraphicFilter->ImportGraphic( aGraphic, aURL ) )
392cdf0e10cSrcweir 			{
393cdf0e10cSrcweir 				sal_Int8    nTempAction = ( aIter == maDropFileVector.begin() ) ? mnAction : 0;
394cdf0e10cSrcweir 				const bool bLink = ( ( nTempAction & DND_ACTION_LINK ) != 0 );
395cdf0e10cSrcweir 				SdrGrafObj* pGrafObj = InsertGraphic( aGraphic, nTempAction, maDropPos, NULL, NULL );
396cdf0e10cSrcweir 
397cdf0e10cSrcweir 				if(pGrafObj && bLink)
398ddde725dSArmin Le Grand                 {
399cdf0e10cSrcweir     				pGrafObj->SetGraphicLink( aCurrentDropFile, String() );
400ddde725dSArmin Le Grand                 }
401cdf0e10cSrcweir 
402cdf0e10cSrcweir 				// return action from first inserted graphic
403cdf0e10cSrcweir 				if( aIter == maDropFileVector.begin() )
404cdf0e10cSrcweir 					mnAction = nTempAction;
405cdf0e10cSrcweir 
406cdf0e10cSrcweir 				bOK = sal_True;
407cdf0e10cSrcweir 			}
408cdf0e10cSrcweir 			if( !bOK )
409cdf0e10cSrcweir 			{
410cdf0e10cSrcweir     			const SfxFilter*        pFoundFilter = NULL;
411cdf0e10cSrcweir 				SfxMedium	            aSfxMedium( aCurrentDropFile, STREAM_READ | STREAM_SHARE_DENYNONE, sal_False );
412cdf0e10cSrcweir 				ErrCode		            nErr = SFX_APP()->GetFilterMatcher().GuessFilter(  aSfxMedium, &pFoundFilter, SFX_FILTER_IMPORT, SFX_FILTER_NOTINSTALLED | SFX_FILTER_EXECUTABLE );
413cdf0e10cSrcweir 
414cdf0e10cSrcweir 				if( pFoundFilter && !nErr )
415cdf0e10cSrcweir 				{
416cdf0e10cSrcweir 					::std::vector< String > aFilterVector;
417cdf0e10cSrcweir 					const String	        aFilterName( pFoundFilter->GetFilterName() );
418cdf0e10cSrcweir 					String	        		aLowerAsciiFileName( aCurrentDropFile );
419cdf0e10cSrcweir 					aLowerAsciiFileName.ToLowerAscii();
420cdf0e10cSrcweir 
421cdf0e10cSrcweir 					FuInsertFile::GetSupportedFilterVector( aFilterVector );
422cdf0e10cSrcweir 
423cdf0e10cSrcweir 					if( ( ::std::find( aFilterVector.begin(), aFilterVector.end(), pFoundFilter->GetMimeType() ) != aFilterVector.end() ) ||
424cdf0e10cSrcweir 						aFilterName.SearchAscii( "Text" ) != STRING_NOTFOUND ||
425cdf0e10cSrcweir 						aFilterName.SearchAscii( "Rich" ) != STRING_NOTFOUND ||
426cdf0e10cSrcweir 						aFilterName.SearchAscii( "RTF" ) != STRING_NOTFOUND ||
427cdf0e10cSrcweir 						aFilterName.SearchAscii( "HTML" ) != STRING_NOTFOUND ||
428cdf0e10cSrcweir 						aLowerAsciiFileName.SearchAscii(".sdd") != STRING_NOTFOUND ||
429cdf0e10cSrcweir 						aLowerAsciiFileName.SearchAscii(".sda") != STRING_NOTFOUND ||
430cdf0e10cSrcweir 						aLowerAsciiFileName.SearchAscii(".sxd") != STRING_NOTFOUND ||
431cdf0e10cSrcweir 						aLowerAsciiFileName.SearchAscii(".sxi") != STRING_NOTFOUND ||
432cdf0e10cSrcweir 						aLowerAsciiFileName.SearchAscii(".std") != STRING_NOTFOUND ||
433cdf0e10cSrcweir 						aLowerAsciiFileName.SearchAscii(".sti") != STRING_NOTFOUND )
434cdf0e10cSrcweir 					{
435cdf0e10cSrcweir 						::sd::Window* pWin = mpViewSh->GetActiveWindow();
436cdf0e10cSrcweir 						SfxRequest      aReq(SID_INSERTFILE, 0, mpDoc->GetItemPool());
437cdf0e10cSrcweir 						SfxStringItem   aItem1( ID_VAL_DUMMY0, aCurrentDropFile ), aItem2( ID_VAL_DUMMY1, pFoundFilter->GetFilterName() );
438cdf0e10cSrcweir 
439cdf0e10cSrcweir 						aReq.AppendItem( aItem1 );
440cdf0e10cSrcweir 						aReq.AppendItem( aItem2 );
441cdf0e10cSrcweir 						FuInsertFile::Create( mpViewSh, pWin, this, mpDoc, aReq );
442cdf0e10cSrcweir 						bOK = sal_True;
443cdf0e10cSrcweir 					}
444cdf0e10cSrcweir 				}
445cdf0e10cSrcweir 			}
446cdf0e10cSrcweir 		}
447cdf0e10cSrcweir 
448cdf0e10cSrcweir 	    if( !bOK )
449cdf0e10cSrcweir 	    {
450cdf0e10cSrcweir 	        Size aPrefSize;
451cdf0e10cSrcweir 
452cdf0e10cSrcweir 	        if( ::avmedia::MediaWindow::isMediaURL( aCurrentDropFile ) &&
453cdf0e10cSrcweir 	            ::avmedia::MediaWindow::isMediaURL( aCurrentDropFile, true, &aPrefSize ) )
454cdf0e10cSrcweir 	        {
455cdf0e10cSrcweir 			    if( aPrefSize.Width() && aPrefSize.Height() )
456cdf0e10cSrcweir 			    {
457cdf0e10cSrcweir 					::sd::Window* pWin = mpViewSh->GetActiveWindow();
458cdf0e10cSrcweir 
459cdf0e10cSrcweir 				    if( pWin )
460cdf0e10cSrcweir 					    aPrefSize = pWin->PixelToLogic( aPrefSize, MAP_100TH_MM );
461cdf0e10cSrcweir 				    else
462cdf0e10cSrcweir 					    aPrefSize = Application::GetDefaultDevice()->PixelToLogic( aPrefSize, MAP_100TH_MM );
463cdf0e10cSrcweir 			    }
464cdf0e10cSrcweir 			    else
465cdf0e10cSrcweir 				    aPrefSize  = Size( 5000, 5000 );
466cdf0e10cSrcweir 
467cdf0e10cSrcweir     		    InsertMediaURL( aCurrentDropFile, mnAction, maDropPos, aPrefSize ) ;
468cdf0e10cSrcweir 	        }
469cdf0e10cSrcweir 	        else if( mnAction & DND_ACTION_LINK )
470cdf0e10cSrcweir 			    static_cast< DrawViewShell* >( mpViewSh )->InsertURLButton( aCurrentDropFile, aCurrentDropFile, String(), &maDropPos );
471cdf0e10cSrcweir 		    else
472cdf0e10cSrcweir 		    {
473cdf0e10cSrcweir 			    if( mpViewSh )
474cdf0e10cSrcweir 			    {
475cdf0e10cSrcweir 					try
476cdf0e10cSrcweir 					{
477cdf0e10cSrcweir 						//TODO/MBA: testing
478cdf0e10cSrcweir 						::rtl::OUString aName;
479cdf0e10cSrcweir 						uno::Sequence < beans::PropertyValue > aMedium(1);
480cdf0e10cSrcweir 						aMedium[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
481cdf0e10cSrcweir 						aMedium[0].Value <<= ::rtl::OUString( aCurrentDropFile );
482cdf0e10cSrcweir 
483cdf0e10cSrcweir 						uno::Reference < embed::XEmbeddedObject > xObj = mpDocSh->GetEmbeddedObjectContainer().
484cdf0e10cSrcweir 								InsertEmbeddedObject( aMedium, aName );
485cdf0e10cSrcweir 
486cdf0e10cSrcweir 						uno::Reference < embed::XEmbedPersist > xPersist( xObj, uno::UNO_QUERY );
487cdf0e10cSrcweir 						if ( xPersist.is())
488cdf0e10cSrcweir 						{
489cdf0e10cSrcweir 							// TODO/LEAN: VisualArea access can switch the object to running state
490cdf0e10cSrcweir 							sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
491cdf0e10cSrcweir 
492cdf0e10cSrcweir 							xPersist->storeOwn();
493cdf0e10cSrcweir 
494cdf0e10cSrcweir 							awt::Size aSz;
495cdf0e10cSrcweir 							try
496cdf0e10cSrcweir 							{
497cdf0e10cSrcweir 								aSz = xObj->getVisualAreaSize( nAspect );
498cdf0e10cSrcweir 							}
499cdf0e10cSrcweir 							catch( embed::NoVisualAreaSizeException& )
500cdf0e10cSrcweir 							{
501cdf0e10cSrcweir 								// the default size will be set later
502cdf0e10cSrcweir 							}
503cdf0e10cSrcweir 
504cdf0e10cSrcweir 							Size        aSize( aSz.Width, aSz.Height );
505cdf0e10cSrcweir 							Rectangle   aRect;
506cdf0e10cSrcweir 
507cdf0e10cSrcweir 							if (!aSize.Width() || !aSize.Height())
508cdf0e10cSrcweir 							{
509cdf0e10cSrcweir 								aSize.Width()   = 1410;
510cdf0e10cSrcweir 								aSize.Height()  = 1000;
511cdf0e10cSrcweir 							}
512cdf0e10cSrcweir 
513cdf0e10cSrcweir 							aRect = Rectangle( maDropPos, aSize );
514cdf0e10cSrcweir 
515cdf0e10cSrcweir 							SdrOle2Obj* pOleObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aName, aRect );
516cdf0e10cSrcweir 							sal_uLong       nOptions = SDRINSERT_SETDEFLAYER;
517cdf0e10cSrcweir 
518cdf0e10cSrcweir 							if (mpViewSh != NULL)
519cdf0e10cSrcweir 							{
520cdf0e10cSrcweir 								OSL_ASSERT (mpViewSh->GetViewShell()!=NULL);
521cdf0e10cSrcweir 								SfxInPlaceClient* pIpClient =
522cdf0e10cSrcweir 									mpViewSh->GetViewShell()->GetIPClient();
523cdf0e10cSrcweir 								if (pIpClient!=NULL && pIpClient->IsObjectInPlaceActive())
524cdf0e10cSrcweir 									nOptions |= SDRINSERT_DONTMARK;
525cdf0e10cSrcweir 							}
526cdf0e10cSrcweir 
527cdf0e10cSrcweir 							InsertObjectAtView( pOleObj, *GetSdrPageView(), nOptions );
528cdf0e10cSrcweir 							pOleObj->SetLogicRect( aRect );
529cdf0e10cSrcweir 							aSz.Width = aRect.GetWidth();
530cdf0e10cSrcweir 							aSz.Height = aRect.GetHeight();
531cdf0e10cSrcweir 							xObj->setVisualAreaSize( nAspect,aSz );
532cdf0e10cSrcweir 						}
533cdf0e10cSrcweir 					}
534cdf0e10cSrcweir 					catch( uno::Exception& )
535cdf0e10cSrcweir 					{
536cdf0e10cSrcweir 						nError = ERRCODE_IO_GENERAL;
537cdf0e10cSrcweir 						// TODO/LATER: better error handling
538cdf0e10cSrcweir 					}
539cdf0e10cSrcweir 				}
540cdf0e10cSrcweir 		    }
541cdf0e10cSrcweir 	    }
542cdf0e10cSrcweir 
543cdf0e10cSrcweir         ++aIter;
544cdf0e10cSrcweir     }
545cdf0e10cSrcweir 
546cdf0e10cSrcweir     if( nError )
547cdf0e10cSrcweir         ErrorHandler::HandleError( nError );
548cdf0e10cSrcweir 
549cdf0e10cSrcweir     return nError;
550cdf0e10cSrcweir }
551cdf0e10cSrcweir 
552cdf0e10cSrcweir /*************************************************************************
553cdf0e10cSrcweir |*
554cdf0e10cSrcweir |* Timer-Handler fuer Errorhandling beim Drop()
555cdf0e10cSrcweir |*
556cdf0e10cSrcweir \************************************************************************/
557cdf0e10cSrcweir 
558cdf0e10cSrcweir IMPL_LINK( View, DropErrorHdl, Timer*, EMPTYARG )
559cdf0e10cSrcweir {
560cdf0e10cSrcweir 	InfoBox( mpViewSh ? mpViewSh->GetActiveWindow() : 0, String(SdResId(STR_ACTION_NOTPOSSIBLE) ) ).Execute();
561cdf0e10cSrcweir 	return 0;
562cdf0e10cSrcweir }
563cdf0e10cSrcweir 
564cdf0e10cSrcweir #ifdef _MSC_VER
565cdf0e10cSrcweir #pragma optimize ( "", on )
566cdf0e10cSrcweir #endif
567cdf0e10cSrcweir 
568cdf0e10cSrcweir /*************************************************************************
569cdf0e10cSrcweir |*
570cdf0e10cSrcweir |* Redraw sperren oder erlauben
571cdf0e10cSrcweir |*
572cdf0e10cSrcweir \************************************************************************/
573cdf0e10cSrcweir 
574cdf0e10cSrcweir void View::LockRedraw(sal_Bool bLock)
575cdf0e10cSrcweir {
576cdf0e10cSrcweir 	if (bLock)
577cdf0e10cSrcweir 	{
578cdf0e10cSrcweir 		mnLockRedrawSmph++;
579cdf0e10cSrcweir 		DBG_ASSERT(mnLockRedrawSmph, "Ueberlauf im LockRedraw");
580cdf0e10cSrcweir 	}
581cdf0e10cSrcweir 	else
582cdf0e10cSrcweir 	{
583cdf0e10cSrcweir 		DBG_ASSERT(mnLockRedrawSmph, "Unterlauf im LockRedraw");
584cdf0e10cSrcweir 		mnLockRedrawSmph--;
585cdf0e10cSrcweir 
586cdf0e10cSrcweir 		// alle gespeicherten Redraws ausfuehren
587cdf0e10cSrcweir 		if (!mnLockRedrawSmph)
588cdf0e10cSrcweir 		{
589cdf0e10cSrcweir 			while (mpLockedRedraws && mpLockedRedraws->Count())
590cdf0e10cSrcweir 			{
591cdf0e10cSrcweir 				SdViewRedrawRec* pRec = (SdViewRedrawRec*)mpLockedRedraws->First();
592cdf0e10cSrcweir 				OutputDevice* pCurrentOut = pRec->mpOut;
593cdf0e10cSrcweir 				Rectangle aBoundRect(pRec->aRect);
594cdf0e10cSrcweir 				mpLockedRedraws->Remove(pRec);
595cdf0e10cSrcweir 				delete pRec;
596cdf0e10cSrcweir 
597cdf0e10cSrcweir 				pRec = (SdViewRedrawRec*)mpLockedRedraws->First();
598cdf0e10cSrcweir 				while (pRec)
599cdf0e10cSrcweir 				{
600cdf0e10cSrcweir 					if (pRec->mpOut == pCurrentOut)
601cdf0e10cSrcweir 					{
602cdf0e10cSrcweir 						aBoundRect.Union(pRec->aRect);
603cdf0e10cSrcweir 						mpLockedRedraws->Remove(pRec);
604cdf0e10cSrcweir 						delete pRec;
605cdf0e10cSrcweir 						pRec = (SdViewRedrawRec*)mpLockedRedraws->GetCurObject();
606cdf0e10cSrcweir 					}
607cdf0e10cSrcweir 					else
608cdf0e10cSrcweir 					{
609cdf0e10cSrcweir 						pRec = (SdViewRedrawRec*)mpLockedRedraws->Next();
610cdf0e10cSrcweir 					}
611cdf0e10cSrcweir 				}
612cdf0e10cSrcweir 
613cdf0e10cSrcweir 				CompleteRedraw(pCurrentOut, Region(aBoundRect));
614cdf0e10cSrcweir 			}
615cdf0e10cSrcweir 			delete mpLockedRedraws;
616cdf0e10cSrcweir 			mpLockedRedraws = NULL;
617cdf0e10cSrcweir 		}
618cdf0e10cSrcweir 	}
619cdf0e10cSrcweir }
620cdf0e10cSrcweir 
621cdf0e10cSrcweir 
622cdf0e10cSrcweir 
623cdf0e10cSrcweir 
624cdf0e10cSrcweir /*************************************************************************
625cdf0e10cSrcweir |*
626cdf0e10cSrcweir |* StyleSheet aus der Sleketion besorgen
627cdf0e10cSrcweir |*
628cdf0e10cSrcweir \************************************************************************/
629cdf0e10cSrcweir 
630cdf0e10cSrcweir SfxStyleSheet* View::GetStyleSheet() const
631cdf0e10cSrcweir {
632cdf0e10cSrcweir 	return SdrView::GetStyleSheet();
633cdf0e10cSrcweir }
634cdf0e10cSrcweir 
635cdf0e10cSrcweir } // end of namespace sd
636