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