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