xref: /aoo41x/main/sd/source/ui/view/sdview3.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #include "View.hxx"
32 #include <com/sun/star/embed/XEmbedObjectClipboardCreator.hpp>
33 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
34 #include <com/sun/star/lang/XComponent.hpp>
35 #include <sot/filelist.hxx>
36 #include <unotools/pathoptions.hxx>
37 #include <editeng/editdata.hxx>
38 #include <svl/urlbmk.hxx>
39 #include <svx/xexch.hxx>
40 #include <svx/xflclit.hxx>
41 #include <svx/xlnclit.hxx>
42 #include <svx/svdpagv.hxx>
43 #include <editeng/eeitem.hxx>
44 #include <editeng/colritem.hxx>
45 #include <sfx2/docfile.hxx>
46 #include <svx/svditer.hxx>
47 #include <svx/svdogrp.hxx>
48 #include <svx/svdoole2.hxx>
49 #include <svx/svdograf.hxx>
50 #include <svx/svdetc.hxx>
51 #include <svx/svdundo.hxx>
52 #include <sfx2/app.hxx>
53 #include <svl/itempool.hxx>
54 #include <sot/clsids.hxx>
55 #include <svx/fmmodel.hxx>
56 #include <sot/formats.hxx>
57 #include <editeng/outliner.hxx>
58 #include <editeng/editeng.hxx>
59 #include <svx/obj3d.hxx>
60 #include <svx/e3dundo.hxx>
61 #include <svx/dbexch.hrc>
62 #include <svx/unomodel.hxx>
63 #include <unotools/streamwrap.hxx>
64 #include <vcl/metaact.hxx>
65 #include <svx/svxids.hrc>
66 #include <toolkit/helper/vclunohelper.hxx>
67 
68 #include "DrawDocShell.hxx"
69 #include "fupoor.hxx"
70 #include "Window.hxx"
71 #include "sdxfer.hxx"
72 #include "sdpage.hxx"
73 #include "DrawViewShell.hxx"
74 #include "drawdoc.hxx"
75 #include "sdresid.hxx"
76 #include "strings.hrc"
77 #include "imapinfo.hxx"
78 #include "SlideSorterViewShell.hxx"
79 #include "strmname.h"
80 #include "unomodel.hxx"
81 #include "ViewClipboard.hxx"
82 
83 #include <sfx2/ipclient.hxx>
84 #include <comphelper/storagehelper.hxx>
85 #include <comphelper/processfactory.hxx>
86 #include <tools/stream.hxx>
87 #include <vcl/cvtgrf.hxx>
88 #include <svx/sdrhittesthelper.hxx>
89 
90 // --------------
91 // - Namespaces -
92 // --------------
93 
94 using namespace ::com::sun::star;
95 using namespace ::com::sun::star::lang;
96 using namespace ::com::sun::star::uno;
97 using namespace ::com::sun::star::io;
98 using namespace ::com::sun::star::datatransfer;
99 using namespace ::com::sun::star::datatransfer::clipboard;
100 
101 namespace sd {
102 
103 #define CHECK_FORMAT_TRANS( _def_Type ) ( ( nFormat == (_def_Type) || !nFormat ) && aDataHelper.HasFormat( _def_Type ) )
104 
105 /*************************************************************************
106 |*
107 |* Paste
108 |*
109 \************************************************************************/
110 
111 // #83525#
112 struct ImpRememberOrigAndClone
113 {
114 	SdrObject*		pOrig;
115 	SdrObject*		pClone;
116 };
117 
118 SdrObject* ImpGetClone(Container& aConnectorContainer, SdrObject* pConnObj)
119 {
120 	for(sal_uInt32 a(0); a < aConnectorContainer.Count(); a++)
121 	{
122 		if(pConnObj == ((ImpRememberOrigAndClone*)aConnectorContainer.GetObject(a))->pOrig)
123 			return ((ImpRememberOrigAndClone*)aConnectorContainer.GetObject(a))->pClone;
124 	}
125 	return 0L;
126 }
127 
128 // #90129# restrict movement to WorkArea
129 void ImpCheckInsertPos(Point& rPos, const Size& rSize, const Rectangle& rWorkArea)
130 {
131 	if(!rWorkArea.IsEmpty())
132 	{
133 		Rectangle aMarkRect(Point(rPos.X() - (rSize.Width() / 2), rPos.Y() - (rSize.Height() / 2)), rSize);
134 
135 		if(!aMarkRect.IsInside(rWorkArea))
136 		{
137 			if(aMarkRect.Left() < rWorkArea.Left())
138 			{
139 				rPos.X() += rWorkArea.Left() - aMarkRect.Left();
140 			}
141 
142 			if(aMarkRect.Right() > rWorkArea.Right())
143 			{
144 				rPos.X() -= aMarkRect.Right() - rWorkArea.Right();
145 			}
146 
147 			if(aMarkRect.Top() < rWorkArea.Top())
148 			{
149 				rPos.Y() += rWorkArea.Top() - aMarkRect.Top();
150 			}
151 
152 			if(aMarkRect.Bottom() > rWorkArea.Bottom())
153 			{
154 				rPos.Y() -= aMarkRect.Bottom() - rWorkArea.Bottom();
155 			}
156 		}
157 	}
158 }
159 
160 bool View::InsertMetaFile( TransferableDataHelper& rDataHelper, const Point& rPos, ImageMap* pImageMap, bool bOptimize )
161 {
162 	GDIMetaFile aMtf;
163 
164 	if( !rDataHelper.GetGDIMetaFile( FORMAT_GDIMETAFILE, aMtf ) )
165 		return false;
166 
167 /*
168 SvFileStream	aSvOutputStream( String( RTL_CONSTASCII_USTRINGPARAM( "/tmp/test.png" ) ), STREAM_WRITE | STREAM_TRUNC );
169 Graphic			aMtfGraphic( aMtf );
170 Size			aPreviewSizePixel( OutputDevice::LogicToLogic( aMtf.GetPrefSize(), aMtf.GetPrefMapMode(), MAP_PIXEL ) );
171 
172 if( aPreviewSizePixel.Width() && aPreviewSizePixel.Height() )
173 {
174 	const double fWH = static_cast< double >( aPreviewSizePixel.Width() ) / static_cast< double >( aPreviewSizePixel.Height() );
175 
176 	if( fWH <= 1.0 )
177 		aPreviewSizePixel.Width() = static_cast< long >( 128.0 * fWH ), aPreviewSizePixel.Height() = 128;
178 	else
179 		aPreviewSizePixel.Width() = 128, aPreviewSizePixel.Height() = static_cast< long >( 128.0 / fWH );
180 
181 	if( GraphicConverter::Export( aSvOutputStream, aMtfGraphic.GetBitmapEx( &aPreviewSizePixel ), CVT_PNG ) )
182 	{
183 		// handle errror case here
184 	}
185 	else
186 	{
187 		// Success
188 	}
189 }
190 */
191 	bool bVector = false;
192 	Graphic aGraphic;
193 
194 	// check if metafile only contains a pixel image, if so insert a bitmap instead
195 	if( bOptimize )
196 	{
197 		MetaAction* pAction = aMtf.FirstAction();
198 		while( pAction && !bVector )
199 		{
200 			switch( pAction->GetType() )
201 			{
202 				case META_POINT_ACTION:
203 				case META_LINE_ACTION:
204 				case META_RECT_ACTION:
205 				case META_ROUNDRECT_ACTION:
206 				case META_ELLIPSE_ACTION:
207 				case META_ARC_ACTION:
208 				case META_PIE_ACTION:
209 				case META_CHORD_ACTION:
210 				case META_POLYLINE_ACTION:
211 				case META_POLYGON_ACTION:
212 				case META_POLYPOLYGON_ACTION:
213 				case META_TEXT_ACTION:
214 				case META_TEXTARRAY_ACTION:
215 				case META_STRETCHTEXT_ACTION:
216 				case META_TEXTRECT_ACTION:
217 				case META_GRADIENT_ACTION:
218 				case META_HATCH_ACTION:
219 				case META_WALLPAPER_ACTION:
220 				case META_EPS_ACTION:
221 				case META_TEXTLINE_ACTION:
222 				case META_FLOATTRANSPARENT_ACTION:
223 				case META_GRADIENTEX_ACTION:
224 				case META_BMPSCALEPART_ACTION:
225 				case META_BMPEXSCALEPART_ACTION:
226 				case META_RENDERGRAPHIC_ACTION:
227 					bVector = true;
228 					break;
229 				case META_BMP_ACTION:
230 				case META_BMPSCALE_ACTION:
231 				case META_BMPEX_ACTION:
232 				case META_BMPEXSCALE_ACTION:
233 					if( aGraphic.GetType() != GRAPHIC_NONE )
234 					{
235 						bVector = true;
236 					}
237 					else switch( pAction->GetType() )
238 					{
239 						case META_BMP_ACTION:
240 							{
241 								MetaBmpAction* pBmpAction = dynamic_cast< MetaBmpAction* >( pAction );
242 								if( pBmpAction )
243 									aGraphic = Graphic( pBmpAction->GetBitmap() );
244 							}
245 							break;
246 						case META_BMPSCALE_ACTION:
247 							{
248 								MetaBmpScaleAction* pBmpScaleAction = dynamic_cast< MetaBmpScaleAction* >( pAction );
249 								if( pBmpScaleAction )
250 									aGraphic = Graphic( pBmpScaleAction->GetBitmap() );
251 							}
252 							break;
253 						case META_BMPEX_ACTION:
254 							{
255 								MetaBmpExAction* pBmpExAction = dynamic_cast< MetaBmpExAction* >( pAction );
256 								if( pBmpExAction )
257 									aGraphic = Graphic( pBmpExAction->GetBitmapEx() );
258 							}
259 							break;
260 						case META_BMPEXSCALE_ACTION:
261 							{
262 								MetaBmpExScaleAction* pBmpExScaleAction = dynamic_cast< MetaBmpExScaleAction* >( pAction );
263 								if( pBmpExScaleAction )
264 									aGraphic = Graphic( pBmpExScaleAction->GetBitmapEx() );
265 							}
266 							break;
267 					}
268 			}
269 
270 			pAction = aMtf.NextAction();
271 		}
272 	}
273 
274 	// it is not a vector metafile but it also has no graphic?
275 	if( !bVector && (aGraphic.GetType() == GRAPHIC_NONE) )
276 		bVector = true;
277 
278 	// #90129# restrict movement to WorkArea
279 	Point aInsertPos( rPos );
280 	Size aImageSize;
281 	aImageSize = bVector ? aMtf.GetPrefSize() : aGraphic.GetSizePixel();
282 	ImpCheckInsertPos(aInsertPos, aImageSize, GetWorkArea());
283 
284 	if( bVector )
285 		aGraphic = Graphic( aMtf );
286 
287 	aGraphic.SetPrefMapMode( aMtf.GetPrefMapMode() );
288 	aGraphic.SetPrefSize( aMtf.GetPrefSize() );
289 	InsertGraphic( aGraphic, mnAction, aInsertPos, NULL, pImageMap );
290 
291 	return true;
292 }
293 
294 sal_Bool View::InsertData( const TransferableDataHelper& rDataHelper,
295 						 const Point& rPos, sal_Int8& rDnDAction, sal_Bool bDrag,
296 						 sal_uLong nFormat, sal_uInt16 nPage, sal_uInt16 nLayer )
297 {
298 	maDropPos = rPos;
299 	mnAction = rDnDAction;
300 	mbIsDropAllowed = sal_False;
301 
302 	TransferableDataHelper	aDataHelper( rDataHelper );
303 	SdrObject*				pPickObj = NULL;
304 	SdPage*					pPage = NULL;
305 	ImageMap*				pImageMap = NULL;
306 	sal_Bool					bReturn = sal_False;
307 	sal_Bool					bLink = ( ( mnAction & DND_ACTION_LINK ) != 0 );
308 	sal_Bool					bCopy = ( ( ( mnAction & DND_ACTION_COPY ) != 0 ) || bLink );
309 	sal_uLong					nPasteOptions = SDRINSERT_SETDEFLAYER;
310 
311     if (mpViewSh != NULL)
312     {
313         OSL_ASSERT (mpViewSh->GetViewShell()!=NULL);
314         SfxInPlaceClient* pIpClient = mpViewSh->GetViewShell()->GetIPClient();
315         if( mpViewSh->ISA(::sd::slidesorter::SlideSorterViewShell)
316             || (pIpClient!=NULL && pIpClient->IsObjectInPlaceActive()))
317         nPasteOptions |= SDRINSERT_DONTMARK;
318     }
319 
320 	if( bDrag )
321 	{
322 		SdrPageView* pPV = NULL;
323 		PickObj( rPos, getHitTolLog(), pPickObj, pPV );
324 	}
325 
326 	if( nPage != SDRPAGE_NOTFOUND )
327 		pPage = (SdPage*) mpDoc->GetPage( nPage );
328 
329 	SdTransferable* pOwnData = NULL;
330     SdTransferable* pImplementation = SdTransferable::getImplementation( aDataHelper.GetTransferable() );
331 
332 	// try to get own transfer data
333 	if( pImplementation )
334 	{
335 		if( SD_MOD()->pTransferClip == (SdTransferable*) pImplementation )
336 			pOwnData = SD_MOD()->pTransferClip;
337 		else if( SD_MOD()->pTransferDrag == (SdTransferable*) pImplementation )
338 			pOwnData = SD_MOD()->pTransferDrag;
339 		else if( SD_MOD()->pTransferSelection == (SdTransferable*) pImplementation )
340 			pOwnData = SD_MOD()->pTransferSelection;
341 	}
342 
343 	// ImageMap?
344 	if( !pOwnData && aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVIM ) )
345 	{
346 		SotStorageStreamRef xStm;
347 
348 		if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_SVIM, xStm ) )
349 		{
350 			pImageMap = new ImageMap;
351             // mba: clipboard always must contain absolute URLs (could be from alien source)
352             pImageMap->Read( *xStm, String() );
353 		}
354 	}
355 
356 	bool bTable = false;
357 	// check special cases for pasting table formats as RTL
358 	if( !bLink && (!nFormat || (nFormat == SOT_FORMAT_RTF)) )
359 	{
360 		// if the objekt supports rtf and there is a table involved, default is to create a table
361 		if( aDataHelper.HasFormat( SOT_FORMAT_RTF ) && ! aDataHelper.HasFormat( SOT_FORMATSTR_ID_DRAWING ) )
362 		{
363 			SotStorageStreamRef xStm;
364 
365 			if( aDataHelper.GetSotStorageStream( FORMAT_RTF, xStm ) )
366 			{
367 				xStm->Seek( 0 );
368 
369 				ByteString aLine;
370 				while( xStm->ReadLine(aLine) )
371 				{
372 					xub_StrLen x = aLine.Search( "\\trowd" );
373 					if( x != STRING_NOTFOUND )
374 					{
375 						bTable = true;
376 						nFormat = FORMAT_RTF;
377 						break;
378 					}
379 				}
380 			}
381 		}
382 	}
383 
384 	if( pOwnData && !nFormat )
385 	{
386 		const View* pSourceView = pOwnData->GetView();
387 
388 
389         if( pOwnData->GetDocShell() && pOwnData->IsPageTransferable() && ISA( View ) )
390 		{
391             mpClipboard->HandlePageDrop (*pOwnData);
392 		}
393         else if( pSourceView )
394 		{
395 			if( pSourceView == this )
396 			{
397 				// same view
398 				if( nLayer != SDRLAYER_NOTFOUND )
399 				{
400 					// drop on layer tab bar
401 					SdrLayerAdmin&	rLayerAdmin = mpDoc->GetLayerAdmin();
402 					SdrLayer*		pLayer = rLayerAdmin.GetLayerPerID( nLayer );
403 					SdrPageView*	pPV = GetSdrPageView();
404 					String			aLayer( pLayer->GetName() );
405 
406 					if( !pPV->IsLayerLocked( aLayer ) )
407 					{
408 						pOwnData->SetInternalMove( sal_True );
409 						SortMarkedObjects();
410 
411 						for( sal_uLong nM = 0; nM < GetMarkedObjectCount(); nM++ )
412 						{
413 							SdrMark*	pM = GetSdrMarkByIndex( nM );
414 							SdrObject*	pO = pM->GetMarkedSdrObj();
415 
416 							if( pO )
417 							{
418 								// #i11702#
419 								if( IsUndoEnabled() )
420 								{
421 									BegUndo(String(SdResId(STR_MODIFYLAYER)));
422 									AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoObjectLayerChange(*pO, pO->GetLayer(), (SdrLayerID)nLayer));
423 									EndUndo();
424 								}
425 
426 								pO->SetLayer( (SdrLayerID) nLayer );
427 							}
428 						}
429 
430 						bReturn = sal_True;
431 					}
432 				}
433 				else
434 				{
435 					SdrPageView*	pPV = GetSdrPageView();
436 					sal_Bool			bDropOnTabBar = sal_True;
437 
438 					if( !pPage && pPV->GetPage()->GetPageNum() != mnDragSrcPgNum )
439 					{
440 						pPage = (SdPage*) pPV->GetPage();
441 						bDropOnTabBar = sal_False;
442 					}
443 
444 					if( pPage )
445 					{
446 						// drop on other page
447 						String aActiveLayer( GetActiveLayer() );
448 
449 						if( !pPV->IsLayerLocked( aActiveLayer ) )
450 						{
451 							if( !IsPresObjSelected() )
452 							{
453 								SdrMarkList* pMarkList;
454 
455 								if( (mnDragSrcPgNum != SDRPAGE_NOTFOUND) && (mnDragSrcPgNum != pPV->GetPage()->GetPageNum()) )
456 								{
457 									pMarkList = mpDragSrcMarkList;
458 								}
459 								else
460 								{
461 									// actual mark list is used
462 									pMarkList = new SdrMarkList( GetMarkedObjectList());
463 								}
464 
465 								pMarkList->ForceSort();
466 
467 								// #83525# stuff to remember originals and clones
468 								Container	aConnectorContainer(0);
469 								sal_uInt32	a, nConnectorCount(0L);
470 								Point		aCurPos;
471 
472 								// calculate real position of current
473 								// source objects, if necessary (#103207)
474 								if( pOwnData == SD_MOD()->pTransferSelection )
475 								{
476 									Rectangle aCurBoundRect;
477 
478 									if( pMarkList->TakeBoundRect( pPV, aCurBoundRect ) )
479 										aCurPos = aCurBoundRect.TopLeft();
480 									else
481 										aCurPos = pOwnData->GetStartPos();
482 								}
483 								else
484 									aCurPos = pOwnData->GetStartPos();
485 
486 								const Size aVector( maDropPos.X() - aCurPos.X(), maDropPos.Y() - aCurPos.Y() );
487 
488 								for(a = 0; a < pMarkList->GetMarkCount(); a++)
489 								{
490 									SdrMark* pM = pMarkList->GetMark(a);
491 									SdrObject* pObj = pM->GetMarkedSdrObj()->Clone();
492 
493 									if(pObj)
494 									{
495 										if(!bDropOnTabBar)
496 										{
497 											// #83525# do a NbcMove(...) instead of setting SnapRects here
498 											pObj->NbcMove(aVector);
499 										}
500 
501 										pPage->InsertObject(pObj);
502 
503 										if( IsUndoEnabled() )
504 										{
505 											BegUndo(String(SdResId(STR_UNDO_DRAGDROP)));
506 											AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoNewObject(*pObj));
507 											EndUndo();
508 										}
509 
510 										// #83525#
511 										ImpRememberOrigAndClone* pRem = new ImpRememberOrigAndClone;
512 										pRem->pOrig = pM->GetMarkedSdrObj();
513 										pRem->pClone = pObj;
514 										aConnectorContainer.Insert(pRem, CONTAINER_APPEND);
515 
516 										if(pObj->ISA(SdrEdgeObj))
517 											nConnectorCount++;
518 									}
519 								}
520 
521 								// #83525# try to re-establish connections at clones
522 								if(nConnectorCount)
523 								{
524 									for(a = 0; a < aConnectorContainer.Count(); a++)
525 									{
526 										ImpRememberOrigAndClone* pRem = (ImpRememberOrigAndClone*)aConnectorContainer.GetObject(a);
527 
528 										if(pRem->pClone->ISA(SdrEdgeObj))
529 										{
530 											SdrEdgeObj* pOrigEdge = (SdrEdgeObj*)pRem->pOrig;
531 											SdrEdgeObj* pCloneEdge = (SdrEdgeObj*)pRem->pClone;
532 
533 											// test first connection
534 											SdrObjConnection& rConn0 = pOrigEdge->GetConnection(sal_False);
535 											SdrObject* pConnObj = rConn0.GetObject();
536 											if(pConnObj)
537 											{
538 												SdrObject* pConnClone = ImpGetClone(aConnectorContainer, pConnObj);
539 												if(pConnClone)
540 												{
541 													// if dest obj was cloned, too, re-establish connection
542 													pCloneEdge->ConnectToNode(sal_False, pConnClone);
543 													pCloneEdge->GetConnection(sal_False).SetConnectorId(rConn0.GetConnectorId());
544 												}
545 												else
546 												{
547 													// set position of connection point of original connected object
548 													const SdrGluePointList* pGlueList = pConnObj->GetGluePointList();
549 													if(pGlueList)
550 													{
551 														sal_uInt16 nInd = pGlueList->FindGluePoint(rConn0.GetConnectorId());
552 
553 														if(SDRGLUEPOINT_NOTFOUND != nInd)
554 														{
555 															const SdrGluePoint& rGluePoint = (*pGlueList)[nInd];
556 															Point aPosition = rGluePoint.GetAbsolutePos(*pConnObj);
557 															aPosition.X() += aVector.A();
558 															aPosition.Y() += aVector.B();
559 															pCloneEdge->SetTailPoint(sal_False, aPosition);
560 														}
561 													}
562 												}
563 											}
564 
565 											// test second connection
566 											SdrObjConnection& rConn1 = pOrigEdge->GetConnection(sal_True);
567 											pConnObj = rConn1.GetObject();
568 											if(pConnObj)
569 											{
570 												SdrObject* pConnClone = ImpGetClone(aConnectorContainer, pConnObj);
571 												if(pConnClone)
572 												{
573 													// if dest obj was cloned, too, re-establish connection
574 													pCloneEdge->ConnectToNode(sal_True, pConnClone);
575 													pCloneEdge->GetConnection(sal_True).SetConnectorId(rConn1.GetConnectorId());
576 												}
577 												else
578 												{
579 													// set position of connection point of original connected object
580 													const SdrGluePointList* pGlueList = pConnObj->GetGluePointList();
581 													if(pGlueList)
582 													{
583 														sal_uInt16 nInd = pGlueList->FindGluePoint(rConn1.GetConnectorId());
584 
585 														if(SDRGLUEPOINT_NOTFOUND != nInd)
586 														{
587 															const SdrGluePoint& rGluePoint = (*pGlueList)[nInd];
588 															Point aPosition = rGluePoint.GetAbsolutePos(*pConnObj);
589 															aPosition.X() += aVector.A();
590 															aPosition.Y() += aVector.B();
591 															pCloneEdge->SetTailPoint(sal_True, aPosition);
592 														}
593 													}
594 												}
595 											}
596 										}
597 									}
598 								}
599 
600 								// #83525# cleanup remember classes
601 								for(a = 0; a < aConnectorContainer.Count(); a++)
602 									delete (ImpRememberOrigAndClone*)aConnectorContainer.GetObject(a);
603 
604 								if( pMarkList != mpDragSrcMarkList )
605 									delete pMarkList;
606 
607 								bReturn = sal_True;
608 							}
609 							else
610 							{
611 								maDropErrorTimer.Start();
612 								bReturn = sal_False;
613 							}
614 						}
615 					}
616 					else
617 					{
618 						pOwnData->SetInternalMove( sal_True );
619 						MoveAllMarked( Size( maDropPos.X() - pOwnData->GetStartPos().X(),
620 											 maDropPos.Y() - pOwnData->GetStartPos().Y() ), bCopy );
621 						bReturn = sal_True;
622 					}
623 				}
624 			}
625 			else
626 			{
627 				// different views
628 				if( !pSourceView->IsPresObjSelected() )
629 				{
630 					// model is owned by from AllocModel() created DocShell
631 					SdDrawDocument* pSourceDoc = (SdDrawDocument*) pSourceView->GetModel();
632 					pSourceDoc->CreatingDataObj( pOwnData );
633 					SdDrawDocument* pModel = (SdDrawDocument*) pSourceView->GetAllMarkedModel();
634 					bReturn = Paste( *pModel, maDropPos, pPage, nPasteOptions );
635 
636 					if( !pPage )
637 						pPage = (SdPage*) GetSdrPageView()->GetPage();
638 
639 					String aLayout( pPage->GetLayoutName() );
640 					aLayout.Erase( aLayout.SearchAscii( SD_LT_SEPARATOR ) );
641 					pPage->SetPresentationLayout( aLayout, sal_False, sal_False );
642 					pSourceDoc->CreatingDataObj( NULL );
643 				}
644 				else
645 				{
646 					maDropErrorTimer.Start();
647 					bReturn = sal_False;
648 				}
649 			}
650 		}
651 		else
652 		{
653 		    SdDrawDocument*	pWorkModel = (SdDrawDocument*) pOwnData->GetWorkDocument();
654 		    SdPage*			pWorkPage = (SdPage*) pWorkModel->GetSdPage( 0, PK_STANDARD );
655 
656 		    pWorkPage->SetRectsDirty();
657 
658 			// #104148# Use SnapRect, not BoundRect
659 		    Size aSize( pWorkPage->GetAllObjSnapRect().GetSize() );
660 
661 		    maDropPos.X() = pOwnData->GetStartPos().X() + ( aSize.Width() >> 1 );
662 		    maDropPos.Y() = pOwnData->GetStartPos().Y() + ( aSize.Height() >> 1 );
663 
664 		    // delete pages, that are not of any interest for us
665 		    for( long i = ( pWorkModel->GetPageCount() - 1 ); i >= 0; i-- )
666 		    {
667 			    SdPage* pP = static_cast< SdPage* >( pWorkModel->GetPage( (sal_uInt16) i ) );
668 
669 			    if( pP->GetPageKind() != PK_STANDARD )
670 				    pWorkModel->DeletePage( (sal_uInt16) i );
671 		    }
672 
673 		    bReturn = Paste( *pWorkModel, maDropPos, pPage, nPasteOptions );
674 
675 		    if( !pPage )
676 			    pPage = (SdPage*) GetSdrPageView()->GetPage();
677 
678 		    String aLayout(pPage->GetLayoutName());
679 		    aLayout.Erase(aLayout.SearchAscii(SD_LT_SEPARATOR));
680 		    pPage->SetPresentationLayout( aLayout, sal_False, sal_False );
681 	   }
682 	}
683 	else if( CHECK_FORMAT_TRANS( SOT_FORMATSTR_ID_DRAWING ) )
684 	{
685 		SotStorageStreamRef xStm;
686 
687 		if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_DRAWING, xStm ) )
688 		{
689 			sal_Bool bChanged = sal_False;
690 
691             DrawDocShellRef xShell = new DrawDocShell(SFX_CREATE_MODE_INTERNAL);
692             xShell->DoInitNew(0);
693 
694 			SdDrawDocument* pModel = xShell->GetDoc();
695             pModel->InsertPage(pModel->AllocPage(false));
696 
697             Reference< XComponent > xComponent( xShell->GetModel(), UNO_QUERY );
698 			xStm->Seek( 0 );
699 
700 			com::sun::star::uno::Reference< com::sun::star::io::XInputStream > xInputStream( new utl::OInputStreamWrapper( *xStm ) );
701 			bReturn = SvxDrawingLayerImport( pModel, xInputStream, xComponent, "com.sun.star.comp.Impress.XMLOasisImporter" );
702 
703 			if( pModel->GetPageCount() == 0 )
704 			{
705 				DBG_ERROR("empty or invalid drawing xml document on clipboard!" );
706 			}
707 			else
708 			{
709 				if( bReturn )
710 				{
711 					if( pModel->GetSdPage( 0, PK_STANDARD )->GetObjCount() == 1 )
712 					{
713 						// only one object
714 						SdrObject*		pObj = pModel->GetSdPage( 0, PK_STANDARD )->GetObj( 0 );
715 						SdrObject*		pPickObj2 = NULL;
716 						SdrPageView*	pPV = NULL;
717 						PickObj( rPos, getHitTolLog(), pPickObj2, pPV );
718 
719 						if( ( mnAction & DND_ACTION_MOVE ) && pPickObj2 && pObj )
720 						{
721 							// replace object
722 							SdrObject*	pNewObj = pObj->Clone();
723 							Rectangle	aPickObjRect( pPickObj2->GetCurrentBoundRect() );
724 							Size		aPickObjSize( aPickObjRect.GetSize() );
725 							Point		aVec( aPickObjRect.TopLeft() );
726 							Rectangle	aObjRect( pNewObj->GetCurrentBoundRect() );
727 							Size		aObjSize( aObjRect.GetSize() );
728 
729 							Fraction aScaleWidth( aPickObjSize.Width(), aObjSize.Width() );
730 							Fraction aScaleHeight( aPickObjSize.Height(), aObjSize.Height() );
731 							pNewObj->NbcResize( aObjRect.TopLeft(), aScaleWidth, aScaleHeight );
732 
733 							aVec -= aObjRect.TopLeft();
734 							pNewObj->NbcMove( Size( aVec.X(), aVec.Y() ) );
735 
736 							const bool bUndo = IsUndoEnabled();
737 
738 							if( bUndo )
739 								BegUndo( String( SdResId(STR_UNDO_DRAGDROP ) ) );
740 							pNewObj->NbcSetLayer( pPickObj->GetLayer() );
741 							SdrPage* pWorkPage = GetSdrPageView()->GetPage();
742 							pWorkPage->InsertObject( pNewObj );
743 							if( bUndo )
744 							{
745 								AddUndo( mpDoc->GetSdrUndoFactory().CreateUndoNewObject( *pNewObj ) );
746 								AddUndo( mpDoc->GetSdrUndoFactory().CreateUndoDeleteObject( *pPickObj2 ) );
747 							}
748 							pWorkPage->RemoveObject( pPickObj2->GetOrdNum() );
749 
750 							if( bUndo )
751 							{
752 								EndUndo();
753 							}
754 							else
755 							{
756 								SdrObject::Free(pPickObj2 );
757 							}
758 							bChanged = sal_True;
759 							mnAction = DND_ACTION_COPY;
760 						}
761 						else if( ( mnAction & DND_ACTION_LINK ) && pPickObj && pObj && !pPickObj->ISA( SdrGrafObj ) && !pPickObj->ISA( SdrOle2Obj ) )
762 						{
763 							SfxItemSet aSet( mpDoc->GetPool() );
764 
765 							// set new attributes to object
766 							const bool bUndo = IsUndoEnabled();
767 							if( bUndo )
768 							{
769 								BegUndo( String( SdResId( STR_UNDO_DRAGDROP ) ) );
770 								AddUndo( mpDoc->GetSdrUndoFactory().CreateUndoAttrObject( *pPickObj ) );
771 							}
772 							aSet.Put( pObj->GetMergedItemSet() );
773 
774 							// Eckenradius soll nicht uebernommen werden.
775 							// In der Gallery stehen Farbverlauefe (Rechtecke)
776 							// welche den Eckenradius == 0 haben. Dieser soll
777 							// nicht auf das Objekt uebertragen werden.
778 							aSet.ClearItem( SDRATTR_ECKENRADIUS );
779 
780 							pPickObj->SetMergedItemSetAndBroadcast( aSet );
781 
782 							if( pPickObj->ISA( E3dObject ) && pObj->ISA( E3dObject ) )
783 							{
784 								// Zusaetzlich 3D Attribute handeln
785 								SfxItemSet aNewSet( mpDoc->GetPool(), SID_ATTR_3D_START, SID_ATTR_3D_END, 0 );
786 								SfxItemSet aOldSet( mpDoc->GetPool(), SID_ATTR_3D_START, SID_ATTR_3D_END, 0 );
787 
788 								aOldSet.Put(pPickObj->GetMergedItemSet());
789 								aNewSet.Put( pObj->GetMergedItemSet() );
790 
791 								if( bUndo )
792 									AddUndo( new E3dAttributesUndoAction( *mpDoc, this, (E3dObject*) pPickObj, aNewSet, aOldSet, sal_False ) );
793 								pPickObj->SetMergedItemSetAndBroadcast( aNewSet );
794 							}
795 
796 							if( bUndo )
797 								EndUndo();
798 							bChanged = sal_True;
799 						}
800 					}
801 				}
802 
803 				if( !bChanged )
804 				{
805 					SdrPage* pWorkPage = pModel->GetSdPage( 0, PK_STANDARD );
806 
807 					pWorkPage->SetRectsDirty();
808 
809 					if( pOwnData )
810 					{
811 						// #104148# Use SnapRect, not BoundRect
812 						Size aSize( pWorkPage->GetAllObjSnapRect().GetSize() );
813 
814 						maDropPos.X() = pOwnData->GetStartPos().X() + ( aSize.Width() >> 1 );
815 						maDropPos.Y() = pOwnData->GetStartPos().Y() + ( aSize.Height() >> 1 );
816 					}
817 
818 					bReturn = Paste( *pModel, maDropPos, pPage, nPasteOptions );
819 				}
820 
821                 xShell->DoClose();
822 			}
823 		}
824 	}
825 	else if( CHECK_FORMAT_TRANS( SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE ) )
826 	{
827 		::rtl::OUString aOUString;
828 
829 		if( aDataHelper.GetString( SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE, aOUString ) )
830 		{
831 			SdrObject* pObj = CreateFieldControl( aOUString );
832 
833 			if( pObj )
834 			{
835 				Rectangle	aRect( pObj->GetLogicRect() );
836 				Size		aSize( aRect.GetSize() );
837 
838 				maDropPos.X() -= ( aSize.Width() >> 1 );
839 				maDropPos.Y() -= ( aSize.Height() >> 1 );
840 
841 				aRect.SetPos( maDropPos );
842 				pObj->SetLogicRect( aRect );
843 				InsertObjectAtView( pObj, *GetSdrPageView(), SDRINSERT_SETDEFLAYER );
844 				bReturn = sal_True;
845 			}
846 		}
847 	}
848 	else if( !bLink &&
849 			 ( CHECK_FORMAT_TRANS( SOT_FORMATSTR_ID_EMBED_SOURCE ) ||
850 			   CHECK_FORMAT_TRANS( SOT_FORMATSTR_ID_EMBEDDED_OBJ ) )  &&
851 			   aDataHelper.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) )
852 	{
853         //TODO/LATER: is it possible that this format is binary?! (from old versions of SO)
854         uno::Reference < io::XInputStream > xStm;
855 		TransferableObjectDescriptor	aObjDesc;
856 
857 		if( aDataHelper.GetTransferableObjectDescriptor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aObjDesc ) &&
858             ( aDataHelper.GetInputStream( nFormat ? nFormat : SOT_FORMATSTR_ID_EMBED_SOURCE, xStm ) ||
859               aDataHelper.GetInputStream( SOT_FORMATSTR_ID_EMBEDDED_OBJ, xStm ) ) )
860 		{
861 			if( mpDoc->GetDocSh() && ( mpDoc->GetDocSh()->GetClassName() == aObjDesc.maClassName ) )
862 			{
863                 uno::Reference < embed::XStorage > xStore( ::comphelper::OStorageHelper::GetStorageFromInputStream( xStm ) );
864 				::sd::DrawDocShellRef xDocShRef( new ::sd::DrawDocShell( SFX_CREATE_MODE_EMBEDDED, sal_True, mpDoc->GetDocumentType() ) );
865 
866                 // mba: BaseURL doesn't make sense for clipboard functionality
867                 SfxMedium *pMedium = new SfxMedium( xStore, String() );
868                 if( xDocShRef->DoLoad( pMedium ) )
869                 {
870 					SdDrawDocument*	pModel = (SdDrawDocument*) xDocShRef->GetDoc();
871 					SdPage*			pWorkPage = (SdPage*) pModel->GetSdPage( 0, PK_STANDARD );
872 
873 					pWorkPage->SetRectsDirty();
874 
875 					if( pOwnData )
876 					{
877 						// #104148# Use SnapRect, not BoundRect
878 						Size aSize( pWorkPage->GetAllObjSnapRect().GetSize() );
879 
880 						maDropPos.X() = pOwnData->GetStartPos().X() + ( aSize.Width() >> 1 );
881 						maDropPos.Y() = pOwnData->GetStartPos().Y() + ( aSize.Height() >> 1 );
882 					}
883 
884 					// delete pages, that are not of any interest for us
885 					for( long i = ( pModel->GetPageCount() - 1 ); i >= 0; i-- )
886 					{
887 						SdPage* pP = static_cast< SdPage* >( pModel->GetPage( (sal_uInt16) i ) );
888 
889 						if( pP->GetPageKind() != PK_STANDARD )
890 							pModel->DeletePage( (sal_uInt16) i );
891 					}
892 
893 					bReturn = Paste( *pModel, maDropPos, pPage, nPasteOptions );
894 
895 					if( !pPage )
896 						pPage = (SdPage*) GetSdrPageView()->GetPage();
897 
898 					String aLayout(pPage->GetLayoutName());
899 					aLayout.Erase(aLayout.SearchAscii(SD_LT_SEPARATOR));
900 					pPage->SetPresentationLayout( aLayout, sal_False, sal_False );
901 				}
902 
903 				xDocShRef->DoClose();
904 				xDocShRef.Clear();
905 
906 			}
907 			else
908 			{
909                 ::rtl::OUString aName;
910                 uno::Reference < embed::XEmbeddedObject > xObj = mpDocSh->GetEmbeddedObjectContainer().InsertEmbeddedObject( xStm, aName );
911                 if ( xObj.is() )
912                 {
913 					svt::EmbeddedObjectRef aObjRef( xObj, aObjDesc.mnViewAspect );
914 
915 					// try to get the replacement image from the clipboard
916 					Graphic aGraphic;
917 					sal_uLong nGrFormat = 0;
918 
919 // (wg. Selection Manager bei Trustet Solaris)
920 #ifndef SOLARIS
921 /*
922                     if( aDataHelper.GetGraphic( SOT_FORMATSTR_ID_SVXB, aGraphic ) )
923 						nGrFormat = SOT_FORMATSTR_ID_SVXB;
924 					else if( aDataHelper.GetGraphic( FORMAT_GDIMETAFILE, aGraphic ) )
925 						nGrFormat = SOT_FORMAT_GDIMETAFILE;
926 					else if( aDataHelper.GetGraphic( FORMAT_BITMAP, aGraphic ) )
927 						nGrFormat = SOT_FORMAT_BITMAP;
928 */
929 #endif
930 
931 					// insert replacement image ( if there is one ) into the object helper
932 					if ( nGrFormat )
933 					{
934 						datatransfer::DataFlavor aDataFlavor;
935 						SotExchange::GetFormatDataFlavor( nGrFormat, aDataFlavor );
936 						aObjRef.SetGraphic( aGraphic, aDataFlavor.MimeType );
937 					}
938 
939 					Size aSize;
940 					if ( aObjDesc.mnViewAspect == embed::Aspects::MSOLE_ICON )
941 					{
942                     	if( aObjDesc.maSize.Width() && aObjDesc.maSize.Height() )
943 							aSize = aObjDesc.maSize;
944 						else
945 						{
946 							MapMode aMapMode( MAP_100TH_MM );
947 							aSize = aObjRef.GetSize( &aMapMode );
948 						}
949 					}
950 					else
951 					{
952                     	awt::Size aSz;
953                     	MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( aObjDesc.mnViewAspect ) );
954                     	if( aObjDesc.maSize.Width() && aObjDesc.maSize.Height() )
955                     	{
956                         	Size aTmp( OutputDevice::LogicToLogic( aObjDesc.maSize, MAP_100TH_MM, aMapUnit ) );
957                         	aSz.Width = aTmp.Width();
958                         	aSz.Height = aTmp.Height();
959                         	xObj->setVisualAreaSize( aObjDesc.mnViewAspect, aSz );
960                     	}
961 
962 						try
963 						{
964                     		aSz = xObj->getVisualAreaSize( aObjDesc.mnViewAspect );
965 						}
966 						catch( embed::NoVisualAreaSizeException& )
967 						{
968 							// if the size still was not set the default size will be set later
969 						}
970 
971                     	aSize = Size( aSz.Width, aSz.Height );
972 
973                     	if( !aSize.Width() || !aSize.Height() )
974                     	{
975                         	aSize.Width()  = 14100;
976                         	aSize.Height() = 10000;
977                         	aSize = OutputDevice::LogicToLogic( Size(14100, 10000), MAP_100TH_MM, aMapUnit );
978                         	aSz.Width = aSize.Width();
979                         	aSz.Height = aSize.Height();
980                         	xObj->setVisualAreaSize( aObjDesc.mnViewAspect, aSz );
981                     	}
982 
983                     	aSize = OutputDevice::LogicToLogic( aSize, aMapUnit, MAP_100TH_MM );
984 					}
985 
986                     Size aMaxSize( mpDoc->GetMaxObjSize() );
987 
988                     maDropPos.X() -= Min( aSize.Width(), aMaxSize.Width() ) >> 1;
989                     maDropPos.Y() -= Min( aSize.Height(), aMaxSize.Height() ) >> 1;
990 
991                     Rectangle       aRect( maDropPos, aSize );
992                     SdrOle2Obj*     pObj = new SdrOle2Obj( aObjRef, aName, aRect );
993                     SdrPageView*    pPV = GetSdrPageView();
994                     sal_uLong           nOptions = SDRINSERT_SETDEFLAYER;
995 
996                     if (mpViewSh!=NULL)
997                     {
998                         OSL_ASSERT (mpViewSh->GetViewShell()!=NULL);
999                         SfxInPlaceClient* pIpClient
1000                             = mpViewSh->GetViewShell()->GetIPClient();
1001                         if (pIpClient!=NULL && pIpClient->IsObjectInPlaceActive())
1002                             nOptions |= SDRINSERT_DONTMARK;
1003                     }
1004 
1005                     InsertObjectAtView( pObj, *pPV, nOptions );
1006 
1007                     if( pImageMap )
1008                         pObj->InsertUserData( new SdIMapInfo( *pImageMap ) );
1009 
1010                     if ( pObj && pObj->IsChart() )
1011                     {
1012                         bool bDisableDataTableDialog = false;
1013                         svt::EmbeddedObjectRef::TryRunningState( xObj );
1014                         uno::Reference< beans::XPropertySet > xProps( xObj->getComponent(), uno::UNO_QUERY );
1015                         if ( xProps.is() &&
1016                              ( xProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DisableDataTableDialog" ) ) ) >>= bDisableDataTableDialog ) &&
1017                              bDisableDataTableDialog )
1018                         {
1019                             xProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DisableDataTableDialog" ) ),
1020                                 uno::makeAny( sal_False ) );
1021                             xProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DisableComplexChartTypes" ) ),
1022                                 uno::makeAny( sal_False ) );
1023                             uno::Reference< util::XModifiable > xModifiable( xProps, uno::UNO_QUERY );
1024                             if ( xModifiable.is() )
1025                             {
1026                                 xModifiable->setModified( sal_True );
1027                             }
1028                         }
1029                     }
1030 
1031                     bReturn = sal_True;
1032                 }
1033 			}
1034 		}
1035 	}
1036 	else if( !bLink &&
1037 			 ( CHECK_FORMAT_TRANS( SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE ) ||
1038 			   CHECK_FORMAT_TRANS( SOT_FORMATSTR_ID_EMBED_SOURCE_OLE ) ) &&
1039 			   aDataHelper.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR_OLE ) )
1040 	{
1041 		// online insert ole if format is forced or no gdi metafile is available
1042 		if( (nFormat != 0) || !aDataHelper.HasFormat( FORMAT_GDIMETAFILE ) )
1043 		{
1044 			uno::Reference < io::XInputStream > xStm;
1045 			TransferableObjectDescriptor	aObjDesc;
1046 
1047 			if ( aDataHelper.GetTransferableObjectDescriptor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR_OLE, aObjDesc ) )
1048 			{
1049 				uno::Reference < embed::XEmbeddedObject > xObj;
1050 				::rtl::OUString aName;
1051 
1052 				if ( aDataHelper.GetInputStream( nFormat ? nFormat : SOT_FORMATSTR_ID_EMBED_SOURCE_OLE, xStm ) ||
1053 					aDataHelper.GetInputStream( SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE, xStm ) )
1054 				{
1055             		xObj = mpDocSh->GetEmbeddedObjectContainer().InsertEmbeddedObject( xStm, aName );
1056 				}
1057 				else
1058 				{
1059 					try
1060 					{
1061 						uno::Reference< embed::XStorage > xTmpStor = ::comphelper::OStorageHelper::GetTemporaryStorage();
1062 						uno::Reference < embed::XEmbedObjectClipboardCreator > xClipboardCreator(
1063 							::comphelper::getProcessServiceFactory()->createInstance(
1064                            		::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.MSOLEObjectSystemCreator")) ),
1065 							uno::UNO_QUERY_THROW );
1066 
1067 						embed::InsertedObjectInfo aInfo = xClipboardCreator->createInstanceInitFromClipboard(
1068 																xTmpStor,
1069 																::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "DummyName" ) ),
1070 																uno::Sequence< beans::PropertyValue >() );
1071 
1072 						// TODO/LATER: in future InsertedObjectInfo will be used to get container related information
1073 						// for example whether the object should be an iconified one
1074 						xObj = aInfo.Object;
1075 						if ( xObj.is() )
1076 							mpDocSh->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aName );
1077 					}
1078 					catch( uno::Exception& )
1079 					{}
1080 				}
1081 
1082 				if ( xObj.is() )
1083 				{
1084 					svt::EmbeddedObjectRef aObjRef( xObj, aObjDesc.mnViewAspect );
1085 
1086 					// try to get the replacement image from the clipboard
1087 					Graphic aGraphic;
1088 					sal_uLong nGrFormat = 0;
1089 
1090 // (wg. Selection Manager bei Trustet Solaris)
1091 #ifndef SOLARIS
1092                     if( aDataHelper.GetGraphic( SOT_FORMATSTR_ID_SVXB, aGraphic ) )
1093 						nGrFormat = SOT_FORMATSTR_ID_SVXB;
1094 					else if( aDataHelper.GetGraphic( FORMAT_GDIMETAFILE, aGraphic ) )
1095 						nGrFormat = SOT_FORMAT_GDIMETAFILE;
1096 					else if( aDataHelper.GetGraphic( FORMAT_BITMAP, aGraphic ) )
1097 						nGrFormat = SOT_FORMAT_BITMAP;
1098 #endif
1099 
1100 					// insert replacement image ( if there is one ) into the object helper
1101 					if ( nGrFormat )
1102 					{
1103 						datatransfer::DataFlavor aDataFlavor;
1104 						SotExchange::GetFormatDataFlavor( nGrFormat, aDataFlavor );
1105 						aObjRef.SetGraphic( aGraphic, aDataFlavor.MimeType );
1106 					}
1107 
1108 					Size aSize;
1109 					if ( aObjDesc.mnViewAspect == embed::Aspects::MSOLE_ICON )
1110 					{
1111                     	if( aObjDesc.maSize.Width() && aObjDesc.maSize.Height() )
1112 							aSize = aObjDesc.maSize;
1113 						else
1114 						{
1115 							MapMode aMapMode( MAP_100TH_MM );
1116 							aSize = aObjRef.GetSize( &aMapMode );
1117 						}
1118 					}
1119 					else
1120 					{
1121             			MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( aObjDesc.mnViewAspect ) );
1122 
1123             			awt::Size aSz;
1124 						try{
1125 							aSz = xObj->getVisualAreaSize( aObjDesc.mnViewAspect );
1126 						}
1127 						catch( embed::NoVisualAreaSizeException& )
1128 						{
1129 							// the default size will be set later
1130 						}
1131 
1132             			if( aObjDesc.maSize.Width() && aObjDesc.maSize.Height() )
1133             			{
1134                 			Size aTmp( OutputDevice::LogicToLogic( aObjDesc.maSize, MAP_100TH_MM, aMapUnit ) );
1135 							if ( aSz.Width != aTmp.Width() || aSz.Height != aTmp.Height() )
1136 							{
1137                 				aSz.Width = aTmp.Width();
1138                 				aSz.Height = aTmp.Height();
1139                 				xObj->setVisualAreaSize( aObjDesc.mnViewAspect, aSz );
1140 							}
1141             			}
1142 
1143             			aSize = Size( aSz.Width, aSz.Height );
1144 
1145             			if( !aSize.Width() || !aSize.Height() )
1146             			{
1147                 			aSize = OutputDevice::LogicToLogic( Size(14100, 10000), MAP_100TH_MM, aMapUnit );
1148                 			aSz.Width = aSize.Width();
1149                 			aSz.Height = aSize.Height();
1150                 			xObj->setVisualAreaSize( aObjDesc.mnViewAspect, aSz );
1151             			}
1152 
1153             			aSize = OutputDevice::LogicToLogic( aSize, aMapUnit, MAP_100TH_MM );
1154 					}
1155 
1156             		Size aMaxSize( mpDoc->GetMaxObjSize() );
1157 
1158             		maDropPos.X() -= Min( aSize.Width(), aMaxSize.Width() ) >> 1;
1159             		maDropPos.Y() -= Min( aSize.Height(), aMaxSize.Height() ) >> 1;
1160 
1161             		Rectangle       aRect( maDropPos, aSize );
1162             		SdrOle2Obj*     pObj = new SdrOle2Obj( aObjRef, aName, aRect );
1163             		SdrPageView*    pPV = GetSdrPageView();
1164             		sal_uLong           nOptions = SDRINSERT_SETDEFLAYER;
1165 
1166             		if (mpViewSh!=NULL)
1167             		{
1168                 		OSL_ASSERT (mpViewSh->GetViewShell()!=NULL);
1169                 		SfxInPlaceClient* pIpClient
1170                     		= mpViewSh->GetViewShell()->GetIPClient();
1171                 		if (pIpClient!=NULL && pIpClient->IsObjectInPlaceActive())
1172                     		nOptions |= SDRINSERT_DONTMARK;
1173             		}
1174 
1175             		InsertObjectAtView( pObj, *pPV, nOptions );
1176 
1177             		if( pImageMap )
1178                 		pObj->InsertUserData( new SdIMapInfo( *pImageMap ) );
1179 
1180 					// let the object stay in loaded state after insertion
1181 					pObj->Unload();
1182             		bReturn = sal_True;
1183 				}
1184 			}
1185 		}
1186 
1187 		if( !bReturn && aDataHelper.HasFormat( FORMAT_GDIMETAFILE ) )
1188 		{
1189 			// if no object was inserted, insert a picture
1190 			InsertMetaFile( aDataHelper, rPos, pImageMap, true );
1191 		}
1192 	}
1193 	else if( ( !bLink || pPickObj ) && CHECK_FORMAT_TRANS( SOT_FORMATSTR_ID_SVXB ) )
1194 	{
1195 		SotStorageStreamRef xStm;
1196 
1197 		if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_SVXB, xStm ) )
1198 		{
1199 			Point   aInsertPos( rPos );
1200 			Graphic aGraphic;
1201 
1202 			*xStm >> aGraphic;
1203 
1204 			if( pOwnData && pOwnData->GetWorkDocument() )
1205 			{
1206 		        const SdDrawDocument*	pWorkModel = pOwnData->GetWorkDocument();
1207                 SdrPage*	            pWorkPage = (SdrPage*) ( ( pWorkModel->GetPageCount() > 1 ) ?
1208                                                     pWorkModel->GetSdPage( 0, PK_STANDARD ) :
1209                                                     pWorkModel->GetPage( 0 ) );
1210 
1211 				pWorkPage->SetRectsDirty();
1212 
1213 				// #104148# Use SnapRect, not BoundRect
1214 				Size aSize( pWorkPage->GetAllObjSnapRect().GetSize() );
1215 
1216 				aInsertPos.X() = pOwnData->GetStartPos().X() + ( aSize.Width() >> 1 );
1217 				aInsertPos.Y() = pOwnData->GetStartPos().Y() + ( aSize.Height() >> 1 );
1218 			}
1219 
1220 			// #90129# restrict movement to WorkArea
1221 			Size aImageMapSize = OutputDevice::LogicToLogic(aGraphic.GetPrefSize(),
1222 				aGraphic.GetPrefMapMode(), MapMode(MAP_100TH_MM));
1223 
1224 			ImpCheckInsertPos(aInsertPos, aImageMapSize, GetWorkArea());
1225 
1226 			InsertGraphic( aGraphic, mnAction, aInsertPos, NULL, pImageMap );
1227 			bReturn = sal_True;
1228 		}
1229 	}
1230 	else if( ( !bLink || pPickObj ) && CHECK_FORMAT_TRANS( FORMAT_GDIMETAFILE ) )
1231 	{
1232 		Point aInsertPos( rPos );
1233 
1234 		if( pOwnData && pOwnData->GetWorkDocument() )
1235 
1236 		{
1237 			const SdDrawDocument*	pWorkModel = pOwnData->GetWorkDocument();
1238             SdrPage*	            pWorkPage = (SdrPage*) ( ( pWorkModel->GetPageCount() > 1 ) ?
1239                                                 pWorkModel->GetSdPage( 0, PK_STANDARD ) :
1240                                                 pWorkModel->GetPage( 0 ) );
1241 
1242 			pWorkPage->SetRectsDirty();
1243 
1244 			// #104148# Use SnapRect, not BoundRect
1245 			Size aSize( pWorkPage->GetAllObjSnapRect().GetSize() );
1246 
1247 			aInsertPos.X() = pOwnData->GetStartPos().X() + ( aSize.Width() >> 1 );
1248 			aInsertPos.Y() = pOwnData->GetStartPos().Y() + ( aSize.Height() >> 1 );
1249 		}
1250 
1251 		bReturn = InsertMetaFile( aDataHelper, aInsertPos, pImageMap, nFormat == 0 ? true : false ) ? sal_True : sal_False;
1252 	}
1253 	else if( ( !bLink || pPickObj ) && CHECK_FORMAT_TRANS( FORMAT_BITMAP ) )
1254 	{
1255 		Bitmap aBmp;
1256 
1257 		if( aDataHelper.GetBitmap( FORMAT_BITMAP, aBmp ) )
1258 		{
1259 			Point aInsertPos( rPos );
1260 
1261 			if( pOwnData && pOwnData->GetWorkDocument() )
1262 			{
1263 			    const SdDrawDocument*	pWorkModel = pOwnData->GetWorkDocument();
1264                 SdrPage*	            pWorkPage = (SdrPage*) ( ( pWorkModel->GetPageCount() > 1 ) ?
1265                                                     pWorkModel->GetSdPage( 0, PK_STANDARD ) :
1266                                                     pWorkModel->GetPage( 0 ) );
1267 
1268 				pWorkPage->SetRectsDirty();
1269 
1270 				// #104148# Use SnapRect, not BoundRect
1271 				Size aSize( pWorkPage->GetAllObjSnapRect().GetSize() );
1272 
1273 				aInsertPos.X() = pOwnData->GetStartPos().X() + ( aSize.Width() >> 1 );
1274 				aInsertPos.Y() = pOwnData->GetStartPos().Y() + ( aSize.Height() >> 1 );
1275 			}
1276 
1277 			// #90129# restrict movement to WorkArea
1278 			Size aImageMapSize(aBmp.GetPrefSize());
1279 			ImpCheckInsertPos(aInsertPos, aImageMapSize, GetWorkArea());
1280 
1281 			InsertGraphic( aBmp, mnAction, aInsertPos, NULL, pImageMap );
1282 			bReturn = sal_True;
1283 		}
1284 	}
1285 	else if( pPickObj && CHECK_FORMAT_TRANS( SOT_FORMATSTR_ID_XFA ) )
1286 	{
1287 		SotStorageStreamRef xStm;
1288 
1289 		if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_XFA, xStm ) )
1290 		{
1291 			XFillExchangeData aFillData( XFillAttrSetItem( &mpDoc->GetPool() ) );
1292 
1293 			*xStm >> aFillData;
1294 
1295 			if( IsUndoEnabled() )
1296 			{
1297 				BegUndo( String( SdResId( STR_UNDO_DRAGDROP ) ) );
1298 				AddUndo( GetModel()->GetSdrUndoFactory().CreateUndoAttrObject( *pPickObj ) );
1299 				EndUndo();
1300 			}
1301 
1302 			XFillAttrSetItem*	pSetItem = aFillData.GetXFillAttrSetItem();
1303 			SfxItemSet			rSet = pSetItem->GetItemSet();
1304 			XFillStyle			eFill= ( (XFillStyleItem&) rSet.Get( XATTR_FILLSTYLE ) ).GetValue();
1305 
1306 			if( eFill == XFILL_SOLID || eFill == XFILL_NONE )
1307 			{
1308 				const XFillColorItem&	rColItem = (XFillColorItem&) rSet.Get( XATTR_FILLCOLOR );
1309 				Color					aColor( rColItem.GetColorValue() );
1310 				String					aName( rColItem.GetName() );
1311 				SfxItemSet				aSet( mpDoc->GetPool() );
1312 				sal_Bool					bClosed = pPickObj->IsClosedObj();
1313 				::sd::Window* pWin = mpViewSh->GetActiveWindow();
1314 				sal_uInt16 nHitLog = (sal_uInt16) pWin->PixelToLogic(
1315                     Size(FuPoor::HITPIX, 0 ) ).Width();
1316 				const long				n2HitLog = nHitLog << 1;
1317 				Point					aHitPosR( rPos );
1318 				Point					aHitPosL( rPos );
1319 				Point					aHitPosT( rPos );
1320 				Point					aHitPosB( rPos );
1321 				const SetOfByte*		pVisiLayer = &GetSdrPageView()->GetVisibleLayers();
1322 
1323 				aHitPosR.X() += n2HitLog;
1324 				aHitPosL.X() -= n2HitLog;
1325 				aHitPosT.Y() += n2HitLog;
1326 				aHitPosB.Y() -= n2HitLog;
1327 
1328 				if( bClosed &&
1329 					SdrObjectPrimitiveHit(*pPickObj, aHitPosR, nHitLog, *GetSdrPageView(), pVisiLayer, false) &&
1330 					SdrObjectPrimitiveHit(*pPickObj, aHitPosL, nHitLog, *GetSdrPageView(), pVisiLayer, false) &&
1331 					SdrObjectPrimitiveHit(*pPickObj, aHitPosT, nHitLog, *GetSdrPageView(), pVisiLayer, false) &&
1332 					SdrObjectPrimitiveHit(*pPickObj, aHitPosB, nHitLog, *GetSdrPageView(), pVisiLayer, false) )
1333 				{
1334 					// area fill
1335 					if(eFill == XFILL_SOLID )
1336 						aSet.Put(XFillColorItem(aName, aColor));
1337 
1338 					aSet.Put( XFillStyleItem( eFill ) );
1339 				}
1340 				else
1341 					aSet.Put( XLineColorItem( aName, aColor ) );
1342 
1343 				// Textfarbe hinzufuegen
1344 				pPickObj->SetMergedItemSetAndBroadcast( aSet );
1345 			}
1346 		}
1347 	}
1348 	else if( !bLink && CHECK_FORMAT_TRANS( SOT_FORMATSTR_ID_HTML ) )
1349 	{
1350 		SotStorageStreamRef xStm;
1351 
1352 		if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_HTML, xStm ) )
1353 		{
1354 			xStm->Seek( 0 );
1355             // mba: clipboard always must contain absolute URLs (could be from alien source)
1356             bReturn = SdrView::Paste( *xStm, String(), EE_FORMAT_HTML, maDropPos, pPage, nPasteOptions );
1357 		}
1358 	}
1359 	else if( !bLink && CHECK_FORMAT_TRANS( SOT_FORMATSTR_ID_EDITENGINE ) )
1360 	{
1361 		SotStorageStreamRef xStm;
1362 
1363 		if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_EDITENGINE, xStm ) )
1364 		{
1365 			OutlinerView* pOLV = GetTextEditOutlinerView();
1366 
1367             xStm->Seek( 0 );
1368 
1369 			if( pOLV )
1370 			{
1371 				Rectangle   aRect( pOLV->GetOutputArea() );
1372    				Point       aPos( pOLV->GetWindow()->PixelToLogic( maDropPos ) );
1373 
1374 				if( aRect.IsInside( aPos ) || ( !bDrag && IsTextEdit() ) )
1375 				{
1376                     // mba: clipboard always must contain absolute URLs (could be from alien source)
1377                     pOLV->Read( *xStm, String(), EE_FORMAT_BIN, sal_False, mpDocSh->GetHeaderAttributes() );
1378 					bReturn = sal_True;
1379 				}
1380 			}
1381 
1382 			if( !bReturn )
1383                 // mba: clipboard always must contain absolute URLs (could be from alien source)
1384                 bReturn = SdrView::Paste( *xStm, String(), EE_FORMAT_BIN, maDropPos, pPage, nPasteOptions );
1385 		}
1386 	}
1387 	else if( !bLink && CHECK_FORMAT_TRANS( FORMAT_RTF ) )
1388 	{
1389 		SotStorageStreamRef xStm;
1390 
1391 		if( aDataHelper.GetSotStorageStream( FORMAT_RTF, xStm ) )
1392 		{
1393             xStm->Seek( 0 );
1394 
1395 			if( bTable )
1396 			{
1397 				bReturn = PasteRTFTable( xStm, pPage, nPasteOptions );
1398 			}
1399 			else
1400 			{
1401 				OutlinerView* pOLV = GetTextEditOutlinerView();
1402 
1403 				if( pOLV )
1404 				{
1405 					Rectangle   aRect( pOLV->GetOutputArea() );
1406    					Point       aPos( pOLV->GetWindow()->PixelToLogic( maDropPos ) );
1407 
1408 					if( aRect.IsInside( aPos ) || ( !bDrag && IsTextEdit() ) )
1409 					{
1410 						// mba: clipboard always must contain absolute URLs (could be from alien source)
1411 						pOLV->Read( *xStm, String(), EE_FORMAT_RTF, sal_False, mpDocSh->GetHeaderAttributes() );
1412 						bReturn = sal_True;
1413 					}
1414 				}
1415 
1416 				if( !bReturn )
1417 					// mba: clipboard always must contain absolute URLs (could be from alien source)
1418 					bReturn = SdrView::Paste( *xStm, String(), EE_FORMAT_RTF, maDropPos, pPage, nPasteOptions );
1419 			}
1420 		}
1421 	}
1422 	else if( CHECK_FORMAT_TRANS( FORMAT_FILE_LIST ) )
1423 	{
1424         FileList aDropFileList;
1425 
1426         if( aDataHelper.GetFileList( FORMAT_FILE_LIST, aDropFileList ) )
1427         {
1428             maDropFileVector.clear();
1429 
1430             for( sal_uLong i = 0, nCount = aDropFileList.Count(); i < nCount; i++ )
1431                 maDropFileVector.push_back( aDropFileList.GetFile( i ) );
1432 
1433             maDropInsertFileTimer.Start();
1434         }
1435 
1436 		bReturn = sal_True;
1437 	}
1438 	else if( CHECK_FORMAT_TRANS( FORMAT_FILE ) )
1439 	{
1440         String aDropFile;
1441 
1442         if( aDataHelper.GetString( FORMAT_FILE, aDropFile ) )
1443         {
1444             maDropFileVector.clear();
1445             maDropFileVector.push_back( aDropFile );
1446 			maDropInsertFileTimer.Start();
1447         }
1448 
1449 		bReturn = sal_True;
1450 	}
1451 	else if( !bLink && CHECK_FORMAT_TRANS( FORMAT_STRING ) )
1452 	{
1453 		if( ( FORMAT_STRING == nFormat ) ||
1454             ( !aDataHelper.HasFormat( SOT_FORMATSTR_ID_SOLK ) &&
1455 			  !aDataHelper.HasFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ) &&
1456 			  !aDataHelper.HasFormat( SOT_FORMATSTR_ID_FILENAME ) ) )
1457 		{
1458 			::rtl::OUString aOUString;
1459 
1460 			if( aDataHelper.GetString( FORMAT_STRING, aOUString ) )
1461 			{
1462 				OutlinerView* pOLV = GetTextEditOutlinerView();
1463 
1464 				if( pOLV )
1465 				{
1466 					pOLV->InsertText( aOUString );
1467 					bReturn = sal_True;
1468 				}
1469 
1470                 if( !bReturn )
1471                     bReturn = SdrView::Paste( aOUString, maDropPos, pPage, nPasteOptions );
1472 			}
1473 		}
1474 	}
1475 
1476 	MarkListHasChanged();
1477 	mbIsDropAllowed = sal_True;
1478 	rDnDAction = mnAction;
1479 	delete pImageMap;
1480 
1481 	return bReturn;
1482 }
1483 
1484 extern void CreateTableFromRTF( SvStream& rStream, SdDrawDocument* pModel  );
1485 
1486 bool View::PasteRTFTable( SotStorageStreamRef xStm, SdrPage* pPage, sal_uLong nPasteOptions )
1487 {
1488 	SdDrawDocument* pModel = new SdDrawDocument( DOCUMENT_TYPE_IMPRESS, mpDocSh );
1489 	pModel->NewOrLoadCompleted(NEW_DOC);
1490 	pModel->GetItemPool().SetDefaultMetric(SFX_MAPUNIT_100TH_MM);
1491 	pModel->InsertPage(pModel->AllocPage(false));
1492 
1493 	Reference< XComponent > xComponent( new SdXImpressDocument( pModel, sal_True ) );
1494 	pModel->setUnoModel( Reference< XInterface >::query( xComponent ) );
1495 
1496 	CreateTableFromRTF( *xStm, pModel );
1497 	bool bRet = Paste( *pModel, maDropPos, pPage, nPasteOptions );
1498 
1499 	xComponent->dispose();
1500 	xComponent.clear();
1501 
1502 	delete pModel;
1503 
1504 	return bRet;
1505 }
1506 
1507 } // end of namespace sd
1508