xref: /trunk/main/sw/source/ui/dochdl/swdtflvr.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 #ifdef PRECOMPILED
31 #include "ui_pch.hxx"
32 #endif
33 
34 
35 #include <com/sun/star/embed/XVisualObject.hpp>
36 #include <com/sun/star/embed/XTransactedObject.hpp>
37 #include <com/sun/star/embed/Aspects.hpp>
38 #include <com/sun/star/embed/XEmbedObjectClipboardCreator.hpp>
39 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
40 
41 #include <svtools/embedtransfer.hxx>
42 #include <svtools/insdlg.hxx>
43 #include <unotools/tempfile.hxx>
44 #include <comphelper/storagehelper.hxx>
45 #include <comphelper/processfactory.hxx>
46 #include <unotools/ucbstreamhelper.hxx>
47 #include <sot/filelist.hxx>
48 #include <svx/svxdlg.hxx>
49 #include <toolkit/helper/vclunohelper.hxx>
50 #include <osl/endian.h>
51 #include <sfx2/linkmgr.hxx>
52 #include <tools/urlobj.hxx>
53 #include <vcl/wrkwin.hxx>
54 #include <vcl/msgbox.hxx>
55 #include <sfx2/dispatch.hxx>
56 #include <svl/stritem.hxx>
57 #include <svtools/imap.hxx>
58 #include <sot/storage.hxx>
59 #include <vcl/graph.hxx>
60 #include <svl/urihelper.hxx>
61 #include <svx/svdmodel.hxx>
62 #include <svx/xexch.hxx>
63 #include <svx/xmlexchg.hxx>
64 #include <svx/dbaexchange.hxx>
65 #include <svx/clipfmtitem.hxx>
66 #include <sfx2/mieclip.hxx>
67 #include <svx/svdetc.hxx>
68 #include <svx/xoutbmp.hxx>
69 #include <svl/urlbmk.hxx>
70 #include <svtools/htmlout.hxx>
71 #include <svx/hlnkitem.hxx>
72 #include <svtools/inetimg.hxx>
73 #include <editeng/paperinf.hxx>
74 #include <svx/fmview.hxx>
75 #include <editeng/scripttypeitem.hxx>
76 #include <sfx2/docfilt.hxx>
77 #include <svtools/imapobj.hxx>
78 #include <sfx2/docfile.hxx>
79 #include <unotools/transliterationwrapper.hxx>
80 #include <unotools/streamwrap.hxx>
81 #include <svtools/filter.hxx>
82 
83 #include <svx/unomodel.hxx>
84 #include <fmturl.hxx>
85 #include <fmtinfmt.hxx>
86 #include <fmtfsize.hxx>
87 #include <swdtflvr.hxx>
88 #include <shellio.hxx>
89 #include <ddefld.hxx>
90 #include <doc.hxx>
91 #include <IDocumentUndoRedo.hxx>
92 #include <pagedesc.hxx>
93 #include <IMark.hxx>
94 #include <docary.hxx>
95 #include <section.hxx>
96 #include <ndtxt.hxx>
97 #include <edtwin.hxx>
98 #include <navicont.hxx>
99 #include <swcont.hxx>
100 #include <wrtsh.hxx>
101 #include <swmodule.hxx>
102 #include <view.hxx>
103 #include <docsh.hxx>
104 #include <wdocsh.hxx>
105 #include <fldbas.hxx>       //DDE
106 #include <swundo.hxx>       // fuer Undo-Ids
107 #include <pam.hxx>
108 #include <ndole.hxx>
109 #include <swwait.hxx>
110 #include <viewopt.hxx>
111 #include <swunodef.hxx>
112 #include <vcl/sound.hxx>
113 #include <swerror.h>
114 #include <SwCapObjType.hxx>
115 #include <cmdid.h>
116 #include <dochdl.hrc>
117 #include <comcore.hrc> // #111827#
118 #include <sot/stg.hxx>
119 #include <svx/svditer.hxx>
120 #include <editeng/eeitem.hxx>
121 #include <editeng/fhgtitem.hxx>
122 #include <svx/svdpage.hxx>
123 #include <avmedia/mediawindow.hxx>
124 #include <swcrsr.hxx>
125 #include <SwRewriter.hxx>
126 #include <globals.hrc>
127 #include <vos/mutex.hxx>
128 #include <vcl/svapp.hxx>
129 #include <swserv.hxx>
130 #include <switerator.hxx>
131 
132 extern sal_Bool bFrmDrag;
133 extern sal_Bool bDDINetAttr;
134 extern sal_Bool bExecuteDrag;
135 
136 
137 #define OLESIZE 11905 - 2 * lMinBorder, 6 * MM50
138 
139 #define SWTRANSFER_OBJECTTYPE_DRAWMODEL         0x00000001
140 #define SWTRANSFER_OBJECTTYPE_HTML              0x00000002
141 #define SWTRANSFER_OBJECTTYPE_RTF               0x00000004
142 #define SWTRANSFER_OBJECTTYPE_STRING            0x00000008
143 #define SWTRANSFER_OBJECTTYPE_SWOLE             0x00000010
144 #define SWTRANSFER_OBJECTTYPE_DDE               0x00000020
145 
146 #define SWTRANSFER_GRAPHIC_INSERTED             0x00000040
147 
148 using namespace ::svx;
149 using ::rtl::OUString;
150 using namespace ::com::sun::star;
151 using namespace ::com::sun::star::uno;
152 using namespace ::com::sun::star::datatransfer;
153 using namespace nsTransferBufferType;
154 
155 #define DDE_TXT_ENCODING    gsl_getSystemTextEncoding()
156 
157 class SwTrnsfrDdeLink : public ::sfx2::SvBaseLink
158 {
159     String sName;
160     ::sfx2::SvLinkSourceRef refObj;
161     SwTransferable& rTrnsfr;
162     SwDocShell* pDocShell;
163     sal_uLong nOldTimeOut;
164     sal_Bool bDelBookmrk : 1;
165     sal_Bool bInDisconnect : 1;
166 
167     sal_Bool FindDocShell();
168 
169     using sfx2::SvBaseLink::Disconnect;
170 
171 protected:
172     virtual ~SwTrnsfrDdeLink();
173 
174 public:
175     SwTrnsfrDdeLink( SwTransferable& rTrans, SwWrtShell& rSh );
176 
177     virtual void DataChanged( const String& rMimeType,
178                               const uno::Any & rValue );
179     virtual void Closed();
180 
181     sal_Bool WriteData( SvStream& rStrm );
182 
183     void Disconnect( sal_Bool bRemoveDataAdvise );
184 };
185 
186 // helper class for Action and Undo enclosing
187 class SwTrnsfrActionAndUndo
188 {
189     SwWrtShell *pSh;
190     SwUndoId eUndoId;
191 public:
192     SwTrnsfrActionAndUndo( SwWrtShell *pS, SwUndoId nId,
193                            const SwRewriter * pRewriter = 0,
194                            sal_Bool bDelSel = sal_False)
195         : pSh( pS ), eUndoId( nId )
196     {
197         pSh->StartUndo( eUndoId, pRewriter );
198         if( bDelSel )
199             pSh->DelRight();
200         pSh->StartAllAction();
201     }
202     ~SwTrnsfrActionAndUndo()
203     {
204         pSh->EndUndo();
205         pSh->EndAllAction();
206     }
207 };
208 
209 
210 // -----------------------------------------------------------------------
211 
212 SwTransferable::SwTransferable( SwWrtShell& rSh )
213     : pWrtShell( &rSh ),
214     pCreatorView( 0 ),
215     pClpDocFac( 0 ),
216     pClpGraphic( 0 ),
217     pClpBitmap( 0 ),
218     pOrigGrf( 0 ),
219     pBkmk( 0 ),
220     pImageMap( 0 ),
221     pTargetURL( 0 ),
222     eBufferType( TRNSFR_NONE )
223 {
224     rSh.GetView().AddTransferable(*this);
225     SwDocShell* pDShell = rSh.GetDoc()->GetDocShell();
226     if( pDShell )
227     {
228         pDShell->FillTransferableObjectDescriptor( aObjDesc );
229         if( pDShell->GetMedium() )
230         {
231             const INetURLObject& rURLObj = pDShell->GetMedium()->GetURLObject();
232             aObjDesc.maDisplayName = URIHelper::removePassword(
233                                 rURLObj.GetMainURL( INetURLObject::NO_DECODE ),
234                                 INetURLObject::WAS_ENCODED,
235                                 INetURLObject::DECODE_UNAMBIGUOUS );
236         }
237 
238         PrepareOLE( aObjDesc );
239     }
240 }
241 
242 // -----------------------------------------------------------------------
243 
244 SwTransferable::~SwTransferable()
245 {
246     Application::GetSolarMutex().acquire();
247 
248     // der DDELink braucht noch die WrtShell!
249     if( refDdeLink.Is() )
250     {
251         ((SwTrnsfrDdeLink*)&refDdeLink)->Disconnect( sal_True );
252         refDdeLink.Clear();
253     }
254 
255     pWrtShell = 0;
256 
257     // dvo 2002-05-30, #99239#: release reference to the document so that
258     // aDocShellRef will delete it (if aDocShellRef is set). Otherwise, the OLE
259     // nodes keep references to their sub-storage when the storage is already
260     // dead.
261     delete pClpDocFac;
262 
263     //JP 22.04.95: erst schliessen, dann kann die Ref. auch gecleared werden,
264     //              so das die DocShell auch tatsaechlich geloescht wird!
265     if( aDocShellRef.Is() )
266     {
267         SfxObjectShell * pObj = aDocShellRef;
268         SwDocShell* pDocSh = (SwDocShell*)pObj;
269         pDocSh->DoClose();
270     }
271     aDocShellRef.Clear();
272 
273     SwModule* pMod = SW_MOD();
274     if(pMod)
275     {
276         if ( pMod->pDragDrop == this )
277             pMod->pDragDrop = 0;
278         else if ( pMod->pXSelection == this )
279             pMod->pXSelection = 0;
280     }
281 
282     delete pClpGraphic;
283     delete pClpBitmap;
284     delete pImageMap;
285     delete pTargetURL;
286     delete pBkmk;
287 
288 
289     eBufferType = TRNSFR_NONE;
290 
291     Application::GetSolarMutex().release();
292 }
293 
294 // -----------------------------------------------------------------------
295 
296 static SwDoc * lcl_GetDoc(SwDocFac & rDocFac)
297 {
298     SwDoc *const pDoc = rDocFac.GetDoc();
299     ASSERT( pDoc, "Document not found" );
300     if (pDoc)
301     {
302         pDoc->SetClipBoard( true );
303     }
304     return pDoc;
305 }
306 
307 // -----------------------------------------------------------------------
308 
309 void SwTransferable::ObjectReleased()
310 {
311     SwModule *pMod = SW_MOD();
312     if( this == pMod->pDragDrop )
313         pMod->pDragDrop = 0;
314     else if( this == pMod->pXSelection )
315         pMod->pXSelection = 0;
316 }
317 
318 // -----------------------------------------------------------------------
319 
320 void SwTransferable::AddSupportedFormats()
321 {
322     // only need if we are the current XSelection Object
323     SwModule *pMod = SW_MOD();
324     if( this == pMod->pXSelection )
325     {
326         SetDataForDragAndDrop( Point( 0,0) );
327     }
328 }
329 
330 // -----------------------------------------------------------------------
331 
332 void SwTransferable::InitOle( SfxObjectShell* pDoc, SwDoc& rDoc )
333 {
334     //OleVisArea einstellen. Linke obere Ecke der Seite und Groesse
335     //der RealSize in Twips.
336     const Size aSz( OLESIZE );
337     SwRect aVis( Point( DOCUMENTBORDER, DOCUMENTBORDER ), aSz );
338     pDoc->SetVisArea( aVis.SVRect() );
339     rDoc.set(IDocumentSettingAccess::BROWSE_MODE, true );
340 }
341 
342 // -----------------------------------------------------------------------
343 
344 uno::Reference < embed::XEmbeddedObject > SwTransferable::FindOLEObj( sal_Int64& nAspect ) const
345 {
346     uno::Reference < embed::XEmbeddedObject > xObj;
347     if( pClpDocFac )
348     {
349         SwIterator<SwCntntNode,SwFmtColl> aIter( *pClpDocFac->GetDoc()->GetDfltGrfFmtColl() );
350         for( SwCntntNode* pNd = aIter.First(); pNd; pNd = aIter.Next() )
351             if( ND_OLENODE == pNd->GetNodeType() )
352             {
353                 xObj = ((SwOLENode*)pNd)->GetOLEObj().GetOleRef();
354                 nAspect = ((SwOLENode*)pNd)->GetAspect();
355                 break;
356             }
357     }
358     return xObj;
359 }
360 
361 // -----------------------------------------------------------------------
362 
363 Graphic* SwTransferable::FindOLEReplacementGraphic() const
364 {
365     if( pClpDocFac )
366     {
367         SwIterator<SwCntntNode,SwFmtColl> aIter( *pClpDocFac->GetDoc()->GetDfltGrfFmtColl() );
368         for( SwCntntNode* pNd = aIter.First(); pNd; pNd = aIter.Next() )
369             if( ND_OLENODE == pNd->GetNodeType() )
370             {
371                 return ((SwOLENode*)pNd)->GetGraphic();
372             }
373     }
374 
375     return NULL;
376 }
377 
378 
379 // -----------------------------------------------------------------------
380 
381 void SwTransferable::RemoveDDELinkFormat( const Window& rWin )
382 {
383     RemoveFormat( SOT_FORMATSTR_ID_LINK );
384     CopyToClipboard( (Window*)&rWin );
385 }
386 
387 // -----------------------------------------------------------------------
388 
389 sal_Bool SwTransferable::GetData( const DATA_FLAVOR& rFlavor )
390 {
391     sal_uInt32  nFormat = SotExchange::GetFormat( rFlavor );
392 
393     // we can only fullfil the request if
394     // 1) we have data for this format
395     // 2) we have either a clipboard document (pClpDocFac), or
396     //    we have a SwWrtShell (so we can generate a new clipboard document)
397     if( !HasFormat( nFormat ) || ( pClpDocFac == NULL && pWrtShell == NULL ) )
398         return sal_False;
399 
400     if( !pClpDocFac )
401     {
402         SelectionType nSelectionType = pWrtShell->GetSelectionType();
403 
404 // SEL_GRF kommt vom ContentType der editsh
405         if( (nsSelectionType::SEL_GRF | nsSelectionType::SEL_DRW_FORM) & nSelectionType )
406         {
407             pClpGraphic = new Graphic;
408             if( !pWrtShell->GetDrawObjGraphic( FORMAT_GDIMETAFILE, *pClpGraphic ))
409                 pOrigGrf = pClpGraphic;
410             pClpBitmap = new Graphic;
411             if( !pWrtShell->GetDrawObjGraphic( FORMAT_BITMAP, *pClpBitmap ))
412                 pOrigGrf = pClpBitmap;
413 
414             // ist es ein URL-Button ?
415             String sURL, sDesc;
416             if( pWrtShell->GetURLFromButton( sURL, sDesc ) )
417             {
418                 pBkmk = new INetBookmark( sURL, sDesc );
419                 eBufferType = TRNSFR_INETFLD;
420             }
421         }
422 
423         pClpDocFac = new SwDocFac;
424         SwDoc *const pTmpDoc = lcl_GetDoc(*pClpDocFac);
425 
426         pTmpDoc->LockExpFlds();     // nie die Felder updaten - Text so belassen
427         pWrtShell->Copy( pTmpDoc );
428 
429         // es wurde in der CORE eine neu angelegt (OLE-Objekte kopiert!)
430         aDocShellRef = pTmpDoc->GetTmpDocShell();
431         if( aDocShellRef.Is() )
432             SwTransferable::InitOle( aDocShellRef, *pTmpDoc );
433         pTmpDoc->SetTmpDocShell( (SfxObjectShell*)NULL );
434 
435         if( nSelectionType & nsSelectionType::SEL_TXT && !pWrtShell->HasMark() )
436         {
437             SwContentAtPos aCntntAtPos( SwContentAtPos::SW_INETATTR );
438 
439             Point aPos( SwEditWin::GetDDStartPosX(), SwEditWin::GetDDStartPosY());
440 
441             sal_Bool bSelect = bExecuteDrag &&
442                             pWrtShell->GetView().GetDocShell() &&
443                             !pWrtShell->GetView().GetDocShell()->IsReadOnly();
444             if( pWrtShell->GetContentAtPos( aPos, aCntntAtPos, bSelect ) )
445             {
446                 pBkmk = new INetBookmark(
447                         ((SwFmtINetFmt*)aCntntAtPos.aFnd.pAttr)->GetValue(),
448                         aCntntAtPos.sStr );
449                 eBufferType = TRNSFR_INETFLD;
450                 if( bSelect )
451                     pWrtShell->SelectTxtAttr( RES_TXTATR_INETFMT );
452             }
453         }
454         if( pWrtShell->IsFrmSelected() )
455         {
456             SfxItemSet aSet( pWrtShell->GetAttrPool(), RES_URL, RES_URL );
457             pWrtShell->GetFlyFrmAttr( aSet );
458             const SwFmtURL& rURL = (SwFmtURL&)aSet.Get( RES_URL );
459             if( rURL.GetMap() )
460                 pImageMap = new ImageMap( *rURL.GetMap() );
461             else if( rURL.GetURL().Len() )
462                 pTargetURL = new INetImage( aEmptyStr, rURL.GetURL(),
463                                             rURL.GetTargetFrameName(),
464                                             aEmptyStr, Size() );
465         }
466     }
467 
468     sal_Bool    bOK = sal_False;
469     if( TRNSFR_OLE == eBufferType )
470     {
471         //TODO/MBA: testing - is this the "single OLE object" case?!
472         // aus dem ClipDoc das OLE-Object besorgen und von dem die Daten
473         // besorgen.
474         sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT; // will be set in the next statement
475         uno::Reference < embed::XEmbeddedObject > xObj = FindOLEObj( nAspect );
476         Graphic* pOLEGraph = FindOLEReplacementGraphic();
477         if( xObj.is() )
478         {
479             TransferableDataHelper aD( new SvEmbedTransferHelper( xObj, pOLEGraph, nAspect ) );
480             uno::Any aAny( aD.GetAny( rFlavor ));
481             if( aAny.hasValue() )
482                 bOK = SetAny( aAny, rFlavor );
483         }
484 
485         // the following solution will be used in the case when the object can not generate the image
486         // TODO/LATER: in future the transferhelper must probably be created based on object and the replacement stream
487         if ( nFormat == SOT_FORMAT_GDIMETAFILE )
488         {
489             pOLEGraph = FindOLEReplacementGraphic();
490             if ( pOLEGraph )
491                 bOK = SetGDIMetaFile( pOLEGraph->GetGDIMetaFile(), rFlavor );
492         }
493     }
494     else
495     {
496         switch( nFormat )
497         {
498         case SOT_FORMATSTR_ID_LINK:
499             if( refDdeLink.Is() )
500                 bOK = SetObject( &refDdeLink,
501                                     SWTRANSFER_OBJECTTYPE_DDE, rFlavor );
502             break;
503 
504         case SOT_FORMATSTR_ID_OBJECTDESCRIPTOR:
505         case SOT_FORMATSTR_ID_LINKSRCDESCRIPTOR:
506             bOK = SetTransferableObjectDescriptor( aObjDesc, rFlavor );
507             break;
508 
509         case SOT_FORMATSTR_ID_DRAWING:
510             {
511                 SwDoc *const pDoc = lcl_GetDoc(*pClpDocFac);
512                 bOK = SetObject( pDoc->GetDrawModel(),
513                                 SWTRANSFER_OBJECTTYPE_DRAWMODEL, rFlavor );
514             }
515             break;
516 
517         case SOT_FORMAT_STRING:
518         {
519             SwDoc *const pDoc = lcl_GetDoc(*pClpDocFac);
520             bOK = SetObject( pDoc, SWTRANSFER_OBJECTTYPE_STRING, rFlavor );
521         }
522         break;
523         case SOT_FORMAT_RTF:
524         {
525             SwDoc *const pDoc = lcl_GetDoc(*pClpDocFac);
526             bOK = SetObject( pDoc, SWTRANSFER_OBJECTTYPE_RTF, rFlavor );
527         }
528             break;
529 
530         case SOT_FORMATSTR_ID_HTML:
531         {
532             SwDoc *const pDoc = lcl_GetDoc(*pClpDocFac);
533             bOK = SetObject( pDoc, SWTRANSFER_OBJECTTYPE_HTML, rFlavor );
534         }
535             break;
536 
537         case SOT_FORMATSTR_ID_SVXB:
538             if( eBufferType & TRNSFR_GRAPHIC && pOrigGrf )
539                 bOK = SetGraphic( *pOrigGrf, rFlavor );
540             break;
541 
542         case SOT_FORMAT_GDIMETAFILE:
543             if( eBufferType & TRNSFR_GRAPHIC )
544                 bOK = SetGDIMetaFile( pClpGraphic->GetGDIMetaFile(), rFlavor );
545             break;
546         case SOT_FORMAT_BITMAP:
547             // #126398#  Neither pClpBitmap nor pClpGraphic are necessarily set
548             if( (eBufferType & TRNSFR_GRAPHIC) && (pClpBitmap != 0 || pClpGraphic != 0))
549                 bOK = SetBitmap( (pClpBitmap ? pClpBitmap
550                                              : pClpGraphic)->GetBitmap(),
551                                  rFlavor );
552             break;
553 
554         case SOT_FORMATSTR_ID_SVIM:
555             if( pImageMap )
556                 bOK = SetImageMap( *pImageMap, rFlavor );
557             break;
558 
559         case SOT_FORMATSTR_ID_INET_IMAGE:
560             if( pTargetURL )
561                 bOK = SetINetImage( *pTargetURL, rFlavor );
562             break;
563 
564         case SOT_FORMATSTR_ID_SOLK:
565         case SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK:
566         case SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR:
567         case SOT_FORMATSTR_ID_FILECONTENT:
568         case SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR:
569         case SOT_FORMAT_FILE:
570             if( (TRNSFR_INETFLD & eBufferType) && pBkmk )
571                 bOK = SetINetBookmark( *pBkmk, rFlavor );
572             break;
573 
574         case SOT_FORMATSTR_ID_EMBED_SOURCE:
575 //      default:
576             if( !aDocShellRef.Is() )
577             {
578                 SwDoc *const pDoc = lcl_GetDoc(*pClpDocFac);
579                 SwDocShell* pNewDocSh = new SwDocShell( pDoc,
580                                          SFX_CREATE_MODE_EMBEDDED );
581                 aDocShellRef = pNewDocSh;
582                 aDocShellRef->DoInitNew( NULL );
583                 SwTransferable::InitOle( aDocShellRef, *pDoc );
584             }
585             bOK = SetObject( &aDocShellRef, SWTRANSFER_OBJECTTYPE_SWOLE,
586                             rFlavor );
587             break;
588         }
589     }
590     return bOK;
591 }
592 
593 // -----------------------------------------------------------------------
594 
595 sal_Bool SwTransferable::WriteObject( SotStorageStreamRef& xStream,
596                                     void* pObject, sal_uInt32 nObjectType,
597                                     const DATA_FLAVOR& /*rFlavor*/ )
598 {
599     sal_Bool bRet = sal_False;
600     WriterRef xWrt;
601 
602     switch( nObjectType )
603     {
604     case SWTRANSFER_OBJECTTYPE_DRAWMODEL:
605         {
606             //JP 28.02.2001: dont change the sequence of commands - Bug 8
607             SdrModel *pModel = (SdrModel*)pObject;
608             xStream->SetBufferSize( 16348 );
609 
610             // #108584#
611             // for the changed pool defaults from drawing layer pool set those
612             // attributes as hard attributes to preserve them for saving
613             const SfxItemPool& rItemPool = pModel->GetItemPool();
614             const SvxFontHeightItem& rDefaultFontHeight = (const SvxFontHeightItem&)rItemPool.GetDefaultItem(EE_CHAR_FONTHEIGHT);
615 
616             // SW should have no MasterPages
617             DBG_ASSERT(0L == pModel->GetMasterPageCount(), "SW with MasterPages (!)");
618 
619             for(sal_uInt16 a(0); a < pModel->GetPageCount(); a++)
620             {
621                 const SdrPage* pPage = pModel->GetPage(a);
622                 SdrObjListIter aIter(*pPage, IM_DEEPNOGROUPS);
623 
624                 while(aIter.IsMore())
625                 {
626                     SdrObject* pObj = aIter.Next();
627                     const SvxFontHeightItem& rItem = (const SvxFontHeightItem&)pObj->GetMergedItem(EE_CHAR_FONTHEIGHT);
628 
629                     if(rItem.GetHeight() == rDefaultFontHeight.GetHeight())
630                     {
631                         pObj->SetMergedItem(rDefaultFontHeight);
632                     }
633                 }
634             }
635 
636             {
637                 uno::Reference<io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *xStream ) );
638                 if( SvxDrawingLayerExport( pModel, xDocOut ) )
639                     xStream->Commit();
640             }
641 
642             bRet = ERRCODE_NONE == xStream->GetError();
643         }
644         break;
645 
646     case SWTRANSFER_OBJECTTYPE_SWOLE:
647         {
648             SfxObjectShell*   pEmbObj = (SfxObjectShell*) pObject;
649             try
650             {
651                 ::utl::TempFile     aTempFile;
652                 aTempFile.EnableKillingFile();
653                 uno::Reference< embed::XStorage > xWorkStore =
654                     ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE );
655 
656                 // write document storage
657                 pEmbObj->SetupStorage( xWorkStore, SOFFICE_FILEFORMAT_CURRENT, sal_False );
658                 // mba: no BaseURL for clipboard
659                 SfxMedium aMedium( xWorkStore, String() );
660                 bRet = pEmbObj->DoSaveObjectAs( aMedium, sal_False );
661                 pEmbObj->DoSaveCompleted();
662 
663                 uno::Reference< embed::XTransactedObject > xTransact( xWorkStore, uno::UNO_QUERY );
664                 if ( xTransact.is() )
665                     xTransact->commit();
666 
667                 SvStream* pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), STREAM_READ );
668                 if( pSrcStm )
669                 {
670                     xStream->SetBufferSize( 0xff00 );
671                     *xStream << *pSrcStm;
672                     delete pSrcStm;
673                 }
674 
675                 bRet = sal_True;
676 
677                 xWorkStore->dispose();
678                 xWorkStore = uno::Reference < embed::XStorage >();
679                 xStream->Commit();
680             }
681             catch ( uno::Exception& )
682             {}
683 
684             bRet = ( xStream->GetError() == ERRCODE_NONE );
685         }
686         break;
687 
688 
689     case SWTRANSFER_OBJECTTYPE_DDE:
690         {
691             xStream->SetBufferSize( 1024 );
692             SwTrnsfrDdeLink* pDdeLnk = (SwTrnsfrDdeLink*)pObject;
693             if( pDdeLnk->WriteData( *xStream ) )
694             {
695                 xStream->Commit();
696                 bRet = ERRCODE_NONE == xStream->GetError();
697             }
698         }
699         break;
700 
701     case SWTRANSFER_OBJECTTYPE_HTML:
702         GetHTMLWriter( aEmptyStr, String(), xWrt );
703         break;
704 
705     case SWTRANSFER_OBJECTTYPE_RTF:
706         GetRTFWriter( aEmptyStr, String(), xWrt );
707         break;
708 
709     case SWTRANSFER_OBJECTTYPE_STRING:
710         GetASCWriter( aEmptyStr, String(), xWrt );
711         if( xWrt.Is() )
712         {
713             SwAsciiOptions aAOpt;
714             aAOpt.SetCharSet( RTL_TEXTENCODING_UTF8 );
715             xWrt->SetAsciiOptions( aAOpt );
716 
717             // #102841# no start char for clipboard
718             xWrt->bUCS2_WithStartChar = sal_False;
719         }
720         break;
721     }
722 
723     if( xWrt.Is() )
724     {
725         SwDoc* pDoc = (SwDoc*)pObject;
726         xWrt->bWriteClipboardDoc = sal_True;
727         xWrt->bWriteOnlyFirstTable = 0 != (TRNSFR_TABELLE & eBufferType);
728         xWrt->SetShowProgress( sal_False );
729         SwWriter aWrt( *xStream, *pDoc );
730         if( !IsError( aWrt.Write( xWrt )) )
731         {
732             *xStream << '\0';               // terminate with a zero
733             xStream->Commit();
734             bRet = sal_True;
735         }
736     }
737 
738     return bRet;
739 }
740 
741 // -----------------------------------------------------------------------
742 
743 int SwTransferable::Cut()
744 {
745     int nRet = Copy( sal_True );
746     if( nRet )
747         DeleteSelection();
748     return nRet;
749 }
750 
751 // -----------------------------------------------------------------------
752 
753 void SwTransferable::DeleteSelection()
754 {
755     if(!pWrtShell)
756         return;
757     // Selektionsart vor Action-Klammerung erfragen
758     const int nSelection = pWrtShell->GetSelectionType();
759     pWrtShell->StartUndo( UNDO_DELETE );
760     if( ( nsSelectionType::SEL_TXT | nsSelectionType::SEL_TBL ) & nSelection )
761         pWrtShell->IntelligentCut( nSelection );
762     pWrtShell->DelRight();
763     pWrtShell->EndUndo( UNDO_DELETE );
764 }
765 
766 // -----------------------------------------------------------------------
767 
768 int SwTransferable::PrepareForCopy( sal_Bool bIsCut )
769 {
770     int nRet = 1;
771     if(!pWrtShell)
772         return 0;;
773 
774     String sGrfNm;
775     const int nSelection = pWrtShell->GetSelectionType();
776     if( nSelection == nsSelectionType::SEL_GRF )
777     {
778         pClpGraphic = new Graphic;
779         if( !pWrtShell->GetDrawObjGraphic( FORMAT_GDIMETAFILE, *pClpGraphic ))
780             pOrigGrf = pClpGraphic;
781         pClpBitmap = new Graphic;
782         if( !pWrtShell->GetDrawObjGraphic( FORMAT_BITMAP, *pClpBitmap ))
783             pOrigGrf = pClpBitmap;
784 
785         pClpDocFac = new SwDocFac;
786         SwDoc *const pDoc = lcl_GetDoc(*pClpDocFac);
787         pWrtShell->Copy( pDoc );
788 
789         if (pOrigGrf && !pOrigGrf->GetBitmap().IsEmpty())
790           AddFormat( SOT_FORMATSTR_ID_SVXB );
791 
792         PrepareOLE( aObjDesc );
793         AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
794 
795         // --> OD 2005-02-09 #119353# - robust
796         const Graphic* pGrf = pWrtShell->GetGraphic();
797         if( pGrf && pGrf->IsSupportedGraphic() )
798         // <--
799         {
800             AddFormat( FORMAT_GDIMETAFILE );
801             AddFormat( FORMAT_BITMAP );
802         }
803         eBufferType = TRNSFR_GRAPHIC;
804         pWrtShell->GetGrfNms( &sGrfNm, 0 );
805     }
806     else if ( nSelection == nsSelectionType::SEL_OLE )
807     {
808         pClpDocFac = new SwDocFac;
809         SwDoc *const pDoc = lcl_GetDoc(*pClpDocFac);
810         aDocShellRef = new SwDocShell( pDoc, SFX_CREATE_MODE_EMBEDDED);
811         aDocShellRef->DoInitNew( NULL );
812         pWrtShell->Copy( pDoc );
813 
814         AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
815 
816         // --> OD #i98753#
817         // set size of embedded object at the object description structure
818         aObjDesc.maSize = OutputDevice::LogicToLogic( pWrtShell->GetObjSize(), MAP_TWIP, MAP_100TH_MM );
819         // <--
820         PrepareOLE( aObjDesc );
821         AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
822 
823         AddFormat( FORMAT_GDIMETAFILE );
824         eBufferType = TRNSFR_OLE;
825     }
826     //Gibt es ueberhaupt etwas zum bereitstellen?
827     else if ( pWrtShell->IsSelection() || pWrtShell->IsFrmSelected() ||
828               pWrtShell->IsObjSelected() )
829     {
830         SwWait *pWait = 0;
831         if( pWrtShell->ShouldWait() )
832             pWait = new SwWait( *pWrtShell->GetView().GetDocShell(), sal_True );
833 
834         pClpDocFac = new SwDocFac;
835 
836         // zusaetzlichen Cursor erzeugen, damit eine Gleichbehandlung
837         // von Tastatur- und Mausselektion moeglich ist.
838         // Im AddMode wird bei Tastaturselektion der neue Cursor erst
839         // beim Bewegen des Cursors nach Selektionsende erzeugt.
840         if( pWrtShell->IsAddMode() && pWrtShell->SwCrsrShell::HasSelection() )
841             pWrtShell->CreateCrsr();
842 
843         SwDoc *const pTmpDoc = lcl_GetDoc(*pClpDocFac);
844 
845         pTmpDoc->LockExpFlds();     // nie die Felder updaten - Text so belassen
846         pWrtShell->Copy( pTmpDoc );
847 
848         {
849             IDocumentMarkAccess* const pMarkAccess = pTmpDoc->getIDocumentMarkAccess();
850             ::std::vector< ::sw::mark::IMark* > vDdeMarks;
851             // find all DDE-Bookmarks
852             for(IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getMarksBegin();
853                 ppMark != pMarkAccess->getMarksEnd();
854                 ppMark++)
855             {
856                 if(IDocumentMarkAccess::DDE_BOOKMARK == IDocumentMarkAccess::GetType(**ppMark))
857                     vDdeMarks.push_back(ppMark->get());
858             }
859             // remove all DDE-Bookmarks, they are invalid inside the clipdoc!
860             for(::std::vector< ::sw::mark::IMark* >::iterator ppMark = vDdeMarks.begin();
861                 ppMark != vDdeMarks.end();
862                 ppMark++)
863                 pMarkAccess->deleteMark(*ppMark);
864         }
865 
866         // es wurde in der CORE eine neu angelegt (OLE-Objekte kopiert!)
867         aDocShellRef = pTmpDoc->GetTmpDocShell();
868         if( aDocShellRef.Is() )
869             SwTransferable::InitOle( aDocShellRef, *pTmpDoc );
870         pTmpDoc->SetTmpDocShell( (SfxObjectShell*)NULL );
871 
872         if( pWrtShell->IsObjSelected() )
873             eBufferType = TRNSFR_DRAWING;
874         else
875         {
876             eBufferType = TRNSFR_DOCUMENT;
877             if (pWrtShell->IntelligentCut(nSelection, sal_False) != SwWrtShell::NO_WORD)
878                 eBufferType = (TransferBufferType)(TRNSFR_DOCUMENT_WORD | eBufferType);
879         }
880 
881         int bDDELink = pWrtShell->IsSelection();
882         if( nSelection & nsSelectionType::SEL_TBL_CELLS )
883         {
884             eBufferType = (TransferBufferType)(TRNSFR_TABELLE | eBufferType);
885             bDDELink = pWrtShell->HasWholeTabSelection();
886         }
887 
888         //Wenn's einer braucht OLE'n wir ihm was.
889         AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
890 
891         //RTF vor das Metafile von OLE stellen, weil mit weniger verlusten
892         //behaftet.
893         if( !pWrtShell->IsObjSelected() )
894         {
895             AddFormat( FORMAT_RTF );
896             AddFormat( SOT_FORMATSTR_ID_HTML );
897         }
898         if( pWrtShell->IsSelection() )
899             AddFormat( FORMAT_STRING );
900 
901         if( nSelection & ( nsSelectionType::SEL_DRW | nsSelectionType::SEL_DRW_FORM ))
902         {
903             AddFormat( SOT_FORMATSTR_ID_DRAWING );
904             if ( nSelection & nsSelectionType::SEL_DRW )
905             {
906                 AddFormat( FORMAT_GDIMETAFILE );
907                 AddFormat( FORMAT_BITMAP );
908             }
909             eBufferType = (TransferBufferType)( TRNSFR_GRAPHIC | eBufferType );
910 
911             pClpGraphic = new Graphic;
912             if( !pWrtShell->GetDrawObjGraphic( FORMAT_GDIMETAFILE, *pClpGraphic ))
913                 pOrigGrf = pClpGraphic;
914             pClpBitmap = new Graphic;
915             if( !pWrtShell->GetDrawObjGraphic( FORMAT_BITMAP, *pClpBitmap ))
916                 pOrigGrf = pClpBitmap;
917 
918             // ist es ein URL-Button ?
919             String sURL, sDesc;
920             if( pWrtShell->GetURLFromButton( sURL, sDesc ) )
921             {
922                 AddFormat( FORMAT_STRING );
923                 AddFormat( SOT_FORMATSTR_ID_SOLK );
924                 AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK );
925                 AddFormat( SOT_FORMATSTR_ID_FILECONTENT );
926                 AddFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR );
927                 AddFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR );
928                 eBufferType = (TransferBufferType)( TRNSFR_INETFLD | eBufferType );
929                 nRet = sal_True;
930             }
931         }
932 
933         // beim Cut hat DDE-Link keinen Sinn!!
934         SwDocShell* pDShell;
935         if( !bIsCut && bDDELink &&
936             0 != ( pDShell = pWrtShell->GetDoc()->GetDocShell()) &&
937             SFX_CREATE_MODE_STANDARD == pDShell->GetCreateMode() )
938         {
939             AddFormat( SOT_FORMATSTR_ID_LINK );
940             refDdeLink = new SwTrnsfrDdeLink( *this, *pWrtShell );
941         }
942 
943         //ObjectDescriptor wurde bereits aus der alten DocShell gefuellt.
944         //Jetzt noch anpassen. Dadurch kann im GetData die erste Anfrage
945         //auch noch mit delayed rendering beantwortet werden.
946         aObjDesc.mbCanLink = sal_False;
947         Size aSz( OLESIZE );
948         aObjDesc.maSize = OutputDevice::LogicToLogic( aSz, MAP_TWIP, MAP_100TH_MM );
949 
950         PrepareOLE( aObjDesc );
951         AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
952 
953         delete pWait;
954     }
955     else
956         nRet = 0;
957 
958     if( pWrtShell->IsFrmSelected() )
959     {
960         SfxItemSet aSet( pWrtShell->GetAttrPool(), RES_URL, RES_URL );
961         pWrtShell->GetFlyFrmAttr( aSet );
962         const SwFmtURL& rURL = (SwFmtURL&)aSet.Get( RES_URL );
963         if( rURL.GetMap() )
964         {
965             pImageMap = new ImageMap( *rURL.GetMap() );
966             AddFormat( SOT_FORMATSTR_ID_SVIM );
967         }
968         else if( rURL.GetURL().Len() )
969         {
970             pTargetURL = new INetImage( sGrfNm, rURL.GetURL(),
971                                         rURL.GetTargetFrameName(),
972                                         aEmptyStr, Size() );
973             AddFormat( SOT_FORMATSTR_ID_INET_IMAGE );
974         }
975     }
976 
977     return nRet;
978 }
979 
980 int SwTransferable::Copy( sal_Bool bIsCut )
981 {
982     int nRet = PrepareForCopy( bIsCut );
983     if ( nRet )
984     {
985         CopyToClipboard( &pWrtShell->GetView().GetEditWin() );
986     }
987     return nRet;
988 }
989 
990 // -----------------------------------------------------------------------
991 
992 int SwTransferable::CalculateAndCopy()
993 {
994     if(!pWrtShell)
995         return 0;
996     SwWait aWait( *pWrtShell->GetView().GetDocShell(), sal_True );
997 
998     String aStr( pWrtShell->Calculate() );
999 
1000     pClpDocFac = new SwDocFac;
1001     SwDoc *const pDoc = lcl_GetDoc(*pClpDocFac);
1002     pWrtShell->Copy(pDoc, & aStr);
1003     eBufferType = TRNSFR_DOCUMENT;
1004     AddFormat( FORMAT_STRING );
1005 
1006     CopyToClipboard( &pWrtShell->GetView().GetEditWin() );
1007 
1008     return 1;
1009 }
1010 
1011 // -----------------------------------------------------------------------
1012 
1013 int SwTransferable::CopyGlossary( SwTextBlocks& rGlossary,
1014                                     const String& rStr )
1015 {
1016     if(!pWrtShell)
1017         return 0;
1018     SwWait aWait( *pWrtShell->GetView().GetDocShell(), sal_True );
1019 
1020     pClpDocFac = new SwDocFac;
1021     SwDoc *const pCDoc = lcl_GetDoc(*pClpDocFac);
1022 
1023     SwNodes& rNds = pCDoc->GetNodes();
1024     SwNodeIndex aNodeIdx( *rNds.GetEndOfContent().StartOfSectionNode() );
1025     SwCntntNode* pCNd = rNds.GoNext( &aNodeIdx ); // gehe zum 1. ContentNode
1026     SwPaM aPam( *pCNd );
1027 
1028     pCDoc->LockExpFlds();   // nie die Felder updaten - Text so belassen
1029 
1030     pCDoc->InsertGlossary( rGlossary, rStr, aPam, 0 );
1031 
1032     // es wurde in der CORE eine neu angelegt (OLE-Objekte kopiert!)
1033     aDocShellRef = pCDoc->GetTmpDocShell();
1034     if( aDocShellRef.Is() )
1035         SwTransferable::InitOle( aDocShellRef, *pCDoc );
1036     pCDoc->SetTmpDocShell( (SfxObjectShell*)NULL );
1037 
1038     eBufferType = TRNSFR_DOCUMENT;
1039 
1040     //Wenn's einer braucht OLE'n wir ihm was.
1041     AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
1042     AddFormat( FORMAT_RTF );
1043     AddFormat( SOT_FORMATSTR_ID_HTML );
1044     AddFormat( FORMAT_STRING );
1045 
1046     //ObjectDescriptor wurde bereits aus der alten DocShell gefuellt.
1047     //Jetzt noch anpassen. Dadurch kann im GetData die erste Anfrage
1048     //auch noch mit delayed rendering beantwortet werden.
1049     aObjDesc.mbCanLink = sal_False;
1050     Size aSz( OLESIZE );
1051     aObjDesc.maSize = OutputDevice::LogicToLogic( aSz, MAP_TWIP, MAP_100TH_MM );
1052 
1053     PrepareOLE( aObjDesc );
1054     AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
1055 
1056     CopyToClipboard( &pWrtShell->GetView().GetEditWin() );
1057 
1058     return 1;
1059 }
1060 
1061 static inline uno::Reference < XTransferable > * lcl_getTransferPointer ( uno::Reference < XTransferable > &xRef )
1062 {
1063     return &xRef;
1064 }
1065 // -----------------------------------------------------------------------
1066 
1067 sal_Bool SwTransferable::IsPaste( const SwWrtShell& rSh,
1068                               const TransferableDataHelper& rData )
1069 {
1070     // Check the common case first: We can always paste our own data!
1071     // #106503#: If _only_ the internal format can be pasted, this check will
1072     // yield 'true', while the one below would give a (wrong) result 'false'.
1073 
1074     bool bIsPaste = ( GetSwTransferable( rData ) != NULL );
1075 
1076     // if it's not our own data, we need to have a closer look:
1077     if( ! bIsPaste )
1078     {
1079         // determine the proper paste action, and return true if we find one
1080         uno::Reference<XTransferable> xTransferable( rData.GetXTransferable() );
1081 
1082         sal_uInt16 nDestination = SwTransferable::GetSotDestination( rSh );
1083         sal_uInt16 nSourceOptions =
1084                     (( EXCHG_DEST_DOC_TEXTFRAME == nDestination ||
1085                        EXCHG_DEST_SWDOC_FREE_AREA == nDestination ||
1086                        EXCHG_DEST_DOC_TEXTFRAME_WEB == nDestination ||
1087                        EXCHG_DEST_SWDOC_FREE_AREA_WEB == nDestination )
1088                                     ? EXCHG_IN_ACTION_COPY
1089                      : EXCHG_IN_ACTION_MOVE);
1090 
1091         sal_uLong nFormat;          // output param for GetExchangeAction
1092         sal_uInt16 nEventAction;    // output param for GetExchangeAction
1093         sal_uInt16 nAction = SotExchange::GetExchangeAction(
1094                                 rData.GetDataFlavorExVector(),
1095                                 nDestination,
1096                                 nSourceOptions,             /* ?? */
1097                                 EXCHG_IN_ACTION_DEFAULT,    /* ?? */
1098                                 nFormat, nEventAction, 0,
1099                                 lcl_getTransferPointer ( xTransferable ) );
1100 
1101         // if we find a suitable action, we can paste!
1102         bIsPaste = (EXCHG_INOUT_ACTION_NONE != nAction);
1103     }
1104 
1105     return bIsPaste;
1106 }
1107 
1108 // -----------------------------------------------------------------------
1109 
1110 int SwTransferable::Paste( SwWrtShell& rSh, TransferableDataHelper& rData )
1111 {
1112     sal_uInt16 nEventAction, nAction=0,
1113            nDestination = SwTransferable::GetSotDestination( rSh );
1114     sal_uLong nFormat = 0;
1115 
1116     if( GetSwTransferable( rData ) )
1117     {
1118         nAction = EXCHG_OUT_ACTION_INSERT_PRIVATE;
1119     }
1120     else
1121     {
1122         sal_uInt16 nSourceOptions =
1123                     (( EXCHG_DEST_DOC_TEXTFRAME == nDestination ||
1124                     EXCHG_DEST_SWDOC_FREE_AREA == nDestination ||
1125                     EXCHG_DEST_DOC_TEXTFRAME_WEB == nDestination ||
1126                     EXCHG_DEST_SWDOC_FREE_AREA_WEB == nDestination )
1127                                     ? EXCHG_IN_ACTION_COPY
1128                                     : EXCHG_IN_ACTION_MOVE);
1129         uno::Reference<XTransferable> xTransferable( rData.GetXTransferable() );
1130         nAction = SotExchange::GetExchangeAction(
1131                                     rData.GetDataFlavorExVector(),
1132                                     nDestination,
1133                                     nSourceOptions,             /* ?? */
1134                                     EXCHG_IN_ACTION_DEFAULT,    /* ?? */
1135                                     nFormat, nEventAction, 0,
1136                                     lcl_getTransferPointer ( xTransferable ) );
1137     }
1138 
1139     // special case for tables from draw application
1140     if( EXCHG_OUT_ACTION_INSERT_DRAWOBJ == (nAction & EXCHG_ACTION_MASK) )
1141     {
1142         if( rData.HasFormat( SOT_FORMAT_RTF ) )
1143         {
1144             nAction = EXCHG_OUT_ACTION_INSERT_STRING | (nAction & !EXCHG_ACTION_MASK);
1145             nFormat = SOT_FORMAT_RTF;
1146         }
1147     }
1148 
1149     return EXCHG_INOUT_ACTION_NONE != nAction &&
1150             SwTransferable::PasteData( rData, rSh, nAction, nFormat,
1151                                         nDestination, sal_False, sal_False );
1152 }
1153 
1154 // -----------------------------------------------------------------------
1155 
1156 int SwTransferable::PasteData( TransferableDataHelper& rData,
1157                             SwWrtShell& rSh, sal_uInt16 nAction, sal_uLong nFormat,
1158                             sal_uInt16 nDestination, sal_Bool bIsPasteFmt,
1159                             sal_Bool bIsDefault,
1160                             const Point* pPt, sal_Int8 nDropAction,
1161                             sal_Bool bPasteSelection )
1162 {
1163     SwWait aWait( *rSh.GetView().
1164         GetDocShell(), sal_False );
1165     SwTrnsfrActionAndUndo* pAction = 0;
1166     SwModule* pMod = SW_MOD();
1167 
1168     int nRet = 0;
1169     bool bCallAutoCaption = false;
1170 
1171     if( pPt )
1172     {
1173         // external Drop
1174         if( bPasteSelection ? !pMod->pXSelection : !pMod->pDragDrop )
1175         {
1176             switch( nDestination )
1177             {
1178             case EXCHG_DEST_DOC_LNKD_GRAPH_W_IMAP:
1179             case EXCHG_DEST_DOC_LNKD_GRAPHOBJ:
1180             case EXCHG_DEST_DOC_GRAPH_W_IMAP:
1181             case EXCHG_DEST_DOC_GRAPHOBJ:
1182             case EXCHG_DEST_DOC_OLEOBJ:
1183             case EXCHG_DEST_DOC_DRAWOBJ:
1184             case EXCHG_DEST_DOC_URLBUTTON:
1185             case EXCHG_DEST_DOC_GROUPOBJ:
1186                 // Rahmen/Objecte selektieren
1187                 SwTransferable::SetSelInShell( rSh, sal_True, pPt );
1188                 break;
1189 
1190             // case EXCHG_DEST_DOC_TEXTFRAME:
1191             // case EXCHG_DEST_SWDOC_FREE_AREA:
1192             // case EXCHG_DEST_DOC_URLFIELD:
1193             default:
1194                 SwTransferable::SetSelInShell( rSh, sal_False, pPt );
1195                 break;
1196             }
1197         }
1198     }
1199     else if( ( !GetSwTransferable( rData ) || bIsPasteFmt ) &&
1200             !rSh.IsTableMode() && rSh.HasSelection() )
1201     {
1202         // dann die Selektionen loeschen
1203 
1204         //Selektierten Inhalt loeschen,
1205         // - nicht bei Tabellen-Selektion
1206         // - nicht bei ReRead einer Grafik/DDEDaten
1207         // - nicht bei D&D, fuer die richtige Selektion wurde im
1208         //      Drop-Handler gesorgt
1209         sal_Bool bDelSel = sal_False;
1210         switch( nDestination )
1211         {
1212         case EXCHG_DEST_DOC_TEXTFRAME:
1213         case EXCHG_DEST_SWDOC_FREE_AREA:
1214         case EXCHG_DEST_DOC_TEXTFRAME_WEB:
1215         case EXCHG_DEST_SWDOC_FREE_AREA_WEB:
1216             bDelSel = sal_True;
1217             break;
1218         }
1219 
1220         if( bDelSel )
1221             // --> FME 2004-10-19 #i34830#
1222             pAction = new SwTrnsfrActionAndUndo( &rSh, UNDO_PASTE_CLIPBOARD, NULL,
1223                                                  sal_True );
1224             // <--
1225     }
1226 
1227     SwTransferable *pTrans=0, *pTunneledTrans=GetSwTransferable( rData );
1228 //    uno::Reference<XUnoTunnel> xTunnel( rData.GetTransferable(), UNO_QUERY );
1229 //    if ( xTunnel.is() )
1230 //    {
1231 //        sal_Int64 nHandle = xTunnel->getSomething( getUnoTunnelId() );
1232 //        if ( nHandle )
1233 //            pTunneledTrans = (SwTransferable*) (sal_IntPtr) nHandle;
1234 //    }
1235 
1236     if( pPt && ( bPasteSelection ? 0 != ( pTrans = pMod->pXSelection )
1237                                  : 0 != ( pTrans = pMod->pDragDrop) ))
1238     {
1239         // then internal Drag & Drop or XSelection
1240         nRet = pTrans->PrivateDrop( rSh, *pPt, DND_ACTION_MOVE == nDropAction,
1241                                     bPasteSelection );
1242     }
1243     else if( !pPt && pTunneledTrans &&
1244             EXCHG_OUT_ACTION_INSERT_PRIVATE == nAction )
1245     {
1246         // then internal paste
1247         nRet = pTunneledTrans->PrivatePaste( rSh );
1248     }
1249     else if( EXCHG_INOUT_ACTION_NONE != nAction )
1250     {
1251         if( !pAction )
1252         {
1253             // #111827#
1254             pAction = new SwTrnsfrActionAndUndo( &rSh, UNDO_PASTE_CLIPBOARD);
1255         }
1256 
1257         // im Drag&Drop duerfen keine MessageBoxen angezeigt werden
1258         sal_Bool bMsg = 0 == pPt;
1259         sal_uInt8 nActionFlags = static_cast< sal_uInt8 >(( nAction >> 8 ) & 0xFF);
1260 
1261         sal_uInt16 nClearedAction = ( nAction & EXCHG_ACTION_MASK );
1262         // Selektionen loeschen
1263 
1264         switch( nClearedAction )
1265         {
1266         case EXCHG_OUT_ACTION_INSERT_PRIVATE:
1267 ASSERT( pPt, "EXCHG_OUT_ACTION_INSERT_PRIVATE: was soll hier passieren?" );
1268             break;
1269 
1270         case EXCHG_OUT_ACTION_MOVE_PRIVATE:
1271 ASSERT( pPt, "EXCHG_OUT_ACTION_MOVE_PRIVATE: was soll hier passieren?" );
1272             break;
1273 
1274 
1275         case EXCHG_IN_ACTION_MOVE:
1276         case EXCHG_IN_ACTION_COPY:
1277         case EXCHG_IN_ACTION_LINK:
1278         case EXCHG_OUT_ACTION_INSERT_HTML:
1279         case EXCHG_OUT_ACTION_INSERT_STRING:
1280         case EXCHG_OUT_ACTION_INSERT_IMAGEMAP:
1281         case EXCHG_OUT_ACTION_REPLACE_IMAGEMAP:
1282 
1283             // dann muss ueber das Format gegangen werden
1284             switch( nFormat )
1285             {
1286             case SOT_FORMATSTR_ID_DRAWING:
1287                 nRet = SwTransferable::_PasteSdrFormat( rData, rSh,
1288                                                 SW_PASTESDR_INSERT, pPt,
1289                                                 nActionFlags );
1290                 break;
1291 
1292             case SOT_FORMATSTR_ID_HTML:
1293             case SOT_FORMATSTR_ID_HTML_SIMPLE:
1294             case SOT_FORMATSTR_ID_HTML_NO_COMMENT:
1295             case SOT_FORMAT_RTF:
1296             case SOT_FORMAT_STRING:
1297                 nRet = SwTransferable::_PasteFileContent( rData, rSh,
1298                                                             nFormat, bMsg );
1299                 break;
1300 
1301             case SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK:
1302                 {
1303                     INetBookmark aBkmk;
1304                     if( rData.GetINetBookmark( nFormat, aBkmk ) )
1305                     {
1306                         SwFmtINetFmt aFmt( aBkmk.GetURL(), aEmptyStr );
1307                         rSh.InsertURL( aFmt, aBkmk.GetDescription() );
1308                         nRet = 1;
1309                     }
1310                 }
1311                 break;
1312 
1313             case SOT_FORMATSTR_ID_SD_OLE:
1314                 nRet = SwTransferable::_PasteOLE( rData, rSh, nFormat,
1315                                                     nActionFlags, bMsg );
1316                 break;
1317 
1318             case SOT_FORMATSTR_ID_SVIM:
1319                 nRet = SwTransferable::_PasteImageMap( rData, rSh );
1320                 break;
1321 
1322             case SOT_FORMATSTR_ID_SVXB:
1323             case SOT_FORMAT_BITMAP:
1324             case SOT_FORMAT_GDIMETAFILE:
1325                 nRet = SwTransferable::_PasteGrf( rData, rSh, nFormat,
1326                                                 SW_PASTESDR_INSERT,pPt,
1327                                                 nActionFlags, bMsg );
1328                 break;
1329 
1330             case SOT_FORMATSTR_ID_XFORMS:
1331             case SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE:
1332             case SOT_FORMATSTR_ID_SBA_DATAEXCHANGE:
1333             case SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE:
1334                 nRet = SwTransferable::_PasteDBData( rData, rSh, nFormat,
1335                                             EXCHG_IN_ACTION_LINK == nClearedAction,
1336                                             pPt, bMsg );
1337                 break;
1338 
1339             case SOT_FORMAT_FILE:
1340                 nRet = SwTransferable::_PasteFileName( rData, rSh, nFormat,
1341                                 ( EXCHG_IN_ACTION_MOVE == nClearedAction
1342                                     ? SW_PASTESDR_REPLACE
1343                                     : EXCHG_IN_ACTION_LINK == nClearedAction
1344                                         ? SW_PASTESDR_SETATTR
1345                                         : SW_PASTESDR_INSERT),
1346                                 pPt, nActionFlags, bMsg );
1347                 break;
1348 
1349             case SOT_FORMAT_FILE_LIST:
1350                 // dann nur als Grafiken einfuegen
1351                 nRet = SwTransferable::_PasteFileList( rData, rSh,
1352                                     EXCHG_IN_ACTION_LINK == nClearedAction,
1353                                     pPt, bMsg );
1354                 break;
1355 
1356             case SOT_FORMATSTR_ID_SONLK:
1357                 if( pPt )
1358                 {
1359                     NaviContentBookmark aBkmk;
1360                     if( aBkmk.Paste( rData ) )
1361                     {
1362                         if(bIsDefault)
1363                         {
1364                             switch(aBkmk.GetDefaultDragType())
1365                             {
1366                                 case REGION_MODE_NONE: nClearedAction = EXCHG_IN_ACTION_COPY; break;
1367                                 case REGION_MODE_EMBEDDED: nClearedAction = EXCHG_IN_ACTION_MOVE; break;
1368                                 case REGION_MODE_LINK: nClearedAction = EXCHG_IN_ACTION_LINK; break;
1369                             }
1370                         }
1371                         rSh.NavigatorPaste( aBkmk, nClearedAction );
1372                         nRet = 1;
1373                     }
1374                 }
1375                 break;
1376 
1377             case SOT_FORMATSTR_ID_INET_IMAGE:
1378             case SOT_FORMATSTR_ID_NETSCAPE_IMAGE:
1379                 nRet = SwTransferable::_PasteTargetURL( rData, rSh,
1380                                                         SW_PASTESDR_INSERT,
1381                                                         pPt, sal_True );
1382                 break;
1383 
1384             default:
1385                 ASSERT( pPt, "unbekanntes Format" );
1386             }
1387             break;
1388 
1389         case EXCHG_OUT_ACTION_INSERT_FILE:
1390             nRet = SwTransferable::_PasteFileName( rData, rSh, nFormat,
1391                                         SW_PASTESDR_INSERT, pPt,
1392                                         nActionFlags, bMsg );
1393             if( nRet & SWTRANSFER_GRAPHIC_INSERTED )
1394                 bCallAutoCaption = true;
1395             break;
1396 
1397         case EXCHG_OUT_ACTION_INSERT_OLE:
1398             nRet = SwTransferable::_PasteOLE( rData, rSh, nFormat,
1399                                                 nActionFlags,bMsg );
1400             break;
1401 
1402         case EXCHG_OUT_ACTION_INSERT_DDE:
1403             {
1404                 sal_Bool bReRead = 0 != CNT_HasGrf( rSh.GetCntType() );
1405                 nRet = SwTransferable::_PasteDDE( rData, rSh, bReRead, bMsg );
1406             }
1407             break;
1408 
1409         case EXCHG_OUT_ACTION_INSERT_HYPERLINK:
1410             {
1411                 String sURL, sDesc;
1412                 if( SOT_FORMAT_FILE == nFormat )
1413                 {
1414                     if( rData.GetString( nFormat, sURL ) && sURL.Len() )
1415                     {
1416                         SwTransferable::_CheckForURLOrLNKFile( rData, sURL, &sDesc );
1417                         if( !sDesc.Len() )
1418                             sDesc = sURL;
1419                         nRet = 1;
1420                     }
1421                 }
1422                 else
1423                 {
1424                     INetBookmark aBkmk;
1425                     if( rData.GetINetBookmark( nFormat, aBkmk ) )
1426                     {
1427                         sURL = aBkmk.GetURL();
1428                         sDesc = aBkmk.GetDescription();
1429                         nRet = 1;
1430                     }
1431                 }
1432 
1433                 if( nRet )
1434                 {
1435                     SwFmtINetFmt aFmt( sURL, aEmptyStr );
1436                     rSh.InsertURL( aFmt, sDesc );
1437                 }
1438             }
1439             break;
1440 
1441         case EXCHG_OUT_ACTION_GET_ATTRIBUTES:
1442             switch( nFormat )
1443             {
1444             case SOT_FORMATSTR_ID_DRAWING:
1445                 nRet = SwTransferable::_PasteSdrFormat( rData, rSh,
1446                                                 SW_PASTESDR_SETATTR, pPt,
1447                                                 nActionFlags );
1448                 break;
1449             case SOT_FORMATSTR_ID_SVXB:
1450             case SOT_FORMAT_GDIMETAFILE:
1451             case SOT_FORMAT_BITMAP:
1452             case SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK:
1453             case SOT_FORMAT_FILE:
1454             case SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR:
1455             case SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR:
1456                 nRet = SwTransferable::_PasteGrf( rData, rSh, nFormat,
1457                                                 SW_PASTESDR_SETATTR, pPt,
1458                                                 nActionFlags, bMsg );
1459                 break;
1460             default:
1461                 ASSERT( sal_False, "unbekanntes Format" );
1462             }
1463 
1464             break;
1465 
1466         case EXCHG_OUT_ACTION_INSERT_DRAWOBJ:
1467             nRet = SwTransferable::_PasteSdrFormat( rData, rSh,
1468                                                 SW_PASTESDR_INSERT, pPt,
1469                                                 nActionFlags );
1470             break;
1471         case EXCHG_OUT_ACTION_INSERT_SVXB:
1472         case EXCHG_OUT_ACTION_INSERT_GDIMETAFILE:
1473         case EXCHG_OUT_ACTION_INSERT_BITMAP:
1474         case EXCHG_OUT_ACTION_INSERT_GRAPH:
1475             nRet = SwTransferable::_PasteGrf( rData, rSh, nFormat,
1476                                                 SW_PASTESDR_INSERT, pPt,
1477                                                 nActionFlags, bMsg );
1478             break;
1479 
1480         case EXCHG_OUT_ACTION_REPLACE_DRAWOBJ:
1481             nRet = SwTransferable::_PasteSdrFormat( rData, rSh,
1482                                                 SW_PASTESDR_REPLACE, pPt,
1483                                                 nActionFlags );
1484             break;
1485 
1486         case EXCHG_OUT_ACTION_REPLACE_SVXB:
1487         case EXCHG_OUT_ACTION_REPLACE_GDIMETAFILE:
1488         case EXCHG_OUT_ACTION_REPLACE_BITMAP:
1489         case EXCHG_OUT_ACTION_REPLACE_GRAPH:
1490             nRet = SwTransferable::_PasteGrf( rData, rSh, nFormat,
1491                                                 SW_PASTESDR_REPLACE,pPt,
1492                                                 nActionFlags, bMsg );
1493             break;
1494 
1495         case EXCHG_OUT_ACTION_INSERT_INTERACTIVE:
1496             nRet = SwTransferable::_PasteAsHyperlink( rData, rSh, nFormat );
1497             break;
1498 
1499         default:
1500             ASSERT( sal_False, "unbekannte Action" );
1501         }
1502     }
1503 
1504     if( !bPasteSelection && rSh.IsFrmSelected() )
1505     {
1506         rSh.EnterSelFrmMode();
1507         //force ::SelectShell
1508         rSh.GetView().StopShellTimer();
1509     }
1510 
1511     if( pAction )
1512         delete pAction;
1513     if( bCallAutoCaption )
1514         rSh.GetView().AutoCaption( GRAPHIC_CAP );
1515 
1516     return nRet;
1517 }
1518 
1519 // -----------------------------------------------------------------------
1520 
1521 sal_uInt16 SwTransferable::GetSotDestination( const SwWrtShell& rSh,
1522                                             const Point* pPt )
1523 {
1524     sal_uInt16 nRet = EXCHG_INOUT_ACTION_NONE;
1525 
1526     ObjCntType eOType;
1527     if( pPt )
1528     {
1529         SdrObject *pObj = 0;
1530         eOType = rSh.GetObjCntType( *pPt, pObj );
1531     }
1532     else
1533         eOType = rSh.GetObjCntTypeOfSelection();
1534 
1535     switch( eOType )
1536     {
1537     case OBJCNT_GRF:
1538         {
1539             sal_Bool bIMap, bLink;
1540             if( pPt )
1541             {
1542                 bIMap = 0 != rSh.GetFmtFromObj( *pPt )->GetURL().GetMap();
1543                 String aDummy;
1544                 rSh.GetGrfAtPos( *pPt, aDummy, bLink );
1545             }
1546             else
1547             {
1548                 bIMap = 0 != rSh.GetFlyFrmFmt()->GetURL().GetMap();
1549                 String aDummy;
1550                 rSh.GetGrfNms( &aDummy, 0 );
1551                 bLink = 0 != aDummy.Len();
1552             }
1553 
1554             if( bLink && bIMap )
1555                 nRet = EXCHG_DEST_DOC_LNKD_GRAPH_W_IMAP;
1556             else if( bLink )
1557                 nRet = EXCHG_DEST_DOC_LNKD_GRAPHOBJ;
1558             else if( bIMap )
1559                 nRet = EXCHG_DEST_DOC_GRAPH_W_IMAP;
1560             else
1561                 nRet = EXCHG_DEST_DOC_GRAPHOBJ;
1562         }
1563         break;
1564 
1565     case OBJCNT_FLY:
1566         if( rSh.GetView().GetDocShell()->ISA(SwWebDocShell) )
1567             nRet = EXCHG_DEST_DOC_TEXTFRAME_WEB;
1568         else
1569             nRet = EXCHG_DEST_DOC_TEXTFRAME;
1570         break;
1571     case OBJCNT_OLE:        nRet = EXCHG_DEST_DOC_OLEOBJ;       break;
1572 
1573     case OBJCNT_CONTROL:    /* no Action avail */
1574     case OBJCNT_SIMPLE:     nRet = EXCHG_DEST_DOC_DRAWOBJ;      break;
1575     case OBJCNT_URLBUTTON:  nRet = EXCHG_DEST_DOC_URLBUTTON;    break;
1576     case OBJCNT_GROUPOBJ:   nRet = EXCHG_DEST_DOC_GROUPOBJ;     break;
1577 
1578 // was mmchen wir bei Mehrfachselektion???
1579 //  case OBJCNT_DONTCARE:
1580     default:
1581         {
1582 /*
1583 JP 13.07.98: Bug 52637: es wird ein URL-Feld erkannt also werden nur die
1584                         Inhalte zugelassen. Das ist aber bestimmt nicht das
1585                         gewollte.
1586             SwContentAtPos aCntntAtPos( SwContentAtPos::SW_INETATTR );
1587             SfxItemSet aSet( (SfxItemPool&)rSh.GetAttrPool(),
1588                             RES_TXTATR_INETFMT, RES_TXTATR_INETFMT );
1589             if( pPt ? ((SwWrtShell&)rSh).GetContentAtPos( *pPt, aCntntAtPos, sal_False )
1590                      : (rSh.GetAttr( aSet ) && aSet.Count()) )
1591                 nRet = EXCHG_DEST_DOC_URLFIELD;
1592             else
1593 */
1594             if( rSh.GetView().GetDocShell()->ISA(SwWebDocShell) )
1595                 nRet = EXCHG_DEST_SWDOC_FREE_AREA_WEB;
1596             else
1597                 nRet = EXCHG_DEST_SWDOC_FREE_AREA;
1598         }
1599     }
1600 
1601     return nRet;
1602 }
1603 
1604 // -----------------------------------------------------------------------
1605 
1606 int SwTransferable::_PasteFileContent( TransferableDataHelper& rData,
1607                                     SwWrtShell& rSh, sal_uLong nFmt, sal_Bool bMsg )
1608 {
1609     sal_uInt16 nResId = MSG_CLPBRD_FORMAT_ERROR;
1610     int nRet = 0;
1611 
1612     MSE40HTMLClipFormatObj aMSE40ClpObj;
1613 
1614     SotStorageStreamRef xStrm;
1615     SvStream* pStream = 0;
1616     SwRead pRead = 0;
1617     rtl::OUString sData;
1618     switch( nFmt )
1619     {
1620     case SOT_FORMAT_STRING:
1621         {
1622             pRead = ReadAscii;
1623             if( rData.GetString( nFmt, sData ) )
1624             {
1625                 pStream = new SvMemoryStream( (void*)sData.getStr(),
1626                             sData.getLength() * sizeof( sal_Unicode ),
1627                             STREAM_READ );
1628 #ifdef OSL_BIGENDIAN
1629                 pStream->SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN );
1630 #else
1631                 pStream->SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
1632 #endif
1633 
1634                 SwAsciiOptions aAOpt;
1635                 aAOpt.SetCharSet( RTL_TEXTENCODING_UCS2 );
1636                 pRead->GetReaderOpt().SetASCIIOpts( aAOpt );
1637                 break;
1638             }
1639         }
1640         // no break - because then test if we get a stream
1641 
1642     default:
1643         if( rData.GetSotStorageStream( nFmt, xStrm ) )
1644         {
1645             if( ( SOT_FORMATSTR_ID_HTML_SIMPLE == nFmt ) ||
1646                 ( SOT_FORMATSTR_ID_HTML_NO_COMMENT == nFmt ) )
1647             {
1648                 pStream = aMSE40ClpObj.IsValid( *xStrm );
1649                 pRead = ReadHTML;
1650                 pRead->SetReadUTF8( sal_True );
1651                 //pRead->SetBaseURL( aMSE40ClpObj.GetBaseURL() );
1652 
1653                 sal_Bool bNoComments =
1654                     ( nFmt == SOT_FORMATSTR_ID_HTML_NO_COMMENT );
1655                 pRead->SetIgnoreHTMLComments( bNoComments );
1656             }
1657             else
1658             {
1659                 pStream = &xStrm;
1660                 if( SOT_FORMAT_RTF == nFmt )
1661                     pRead = SwReaderWriter::GetReader( READER_WRITER_RTF );
1662                 else if( !pRead )
1663                 {
1664                     pRead = ReadHTML;
1665                     pRead->SetReadUTF8( sal_True );
1666                 }
1667             }
1668         }
1669         break;
1670     }
1671 
1672     if( pStream && pRead )
1673     {
1674         Link aOldLink( rSh.GetChgLnk() );
1675         rSh.SetChgLnk( Link() );
1676 
1677         const SwPosition& rInsPos = *rSh.GetCrsr()->Start();
1678         SwReader aReader( *pStream, aEmptyStr, String(), *rSh.GetCrsr() );
1679         rSh.SaveTblBoxCntnt( &rInsPos );
1680         if( IsError( aReader.Read( *pRead )) )
1681             nResId = ERR_CLPBRD_READ;
1682         else
1683             nResId = 0, nRet = 1;
1684 
1685         rSh.SetChgLnk( aOldLink );
1686         if( nRet )
1687             rSh.CallChgLnk();
1688     }
1689     else
1690         nResId = MSG_CLPBRD_FORMAT_ERROR;
1691 
1692     // Exist a SvMemoryStream? (data in the OUString and xStrm is empty)
1693     if( pStream && !xStrm.Is() )
1694         delete pStream;
1695 
1696     if( bMsg && nResId )
1697     {
1698         InfoBox( 0, SW_RES( nResId )).Execute();
1699     }
1700     return nRet;
1701 }
1702 
1703 // -----------------------------------------------------------------------
1704 
1705 int SwTransferable::_PasteOLE( TransferableDataHelper& rData, SwWrtShell& rSh,
1706                                 sal_uLong nFmt, sal_uInt8 nActionFlags, sal_Bool bMsg )
1707 {
1708     int nRet = 0;
1709     TransferableObjectDescriptor aObjDesc;
1710     uno::Reference < io::XInputStream > xStrm;
1711     uno::Reference < embed::XStorage > xStore;
1712     Reader* pRead = 0;
1713 
1714     // Get the preferred format
1715     SotFormatStringId nId;
1716     if( rData.HasFormat( SOT_FORMATSTR_ID_EMBEDDED_OBJ ) )
1717         nId = SOT_FORMATSTR_ID_EMBEDDED_OBJ;
1718     else if( rData.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE ) &&
1719              rData.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ))
1720         nId = SOT_FORMATSTR_ID_EMBED_SOURCE;
1721     else
1722         nId = 0;
1723 
1724     if( nId && rData.GetInputStream( nId, xStrm ) && xStrm.is() )
1725     {
1726         // if there is an embedded object, first try if it's a writer object
1727         // this will be inserted into the document by using a Reader
1728         try
1729         {
1730             xStore = comphelper::OStorageHelper::GetStorageFromInputStream( xStrm );
1731             switch( SotStorage::GetFormatID( xStore ) )
1732             {
1733                 case SOT_FORMATSTR_ID_STARWRITER_60:
1734                 case SOT_FORMATSTR_ID_STARWRITERWEB_60:
1735                 case SOT_FORMATSTR_ID_STARWRITERGLOB_60:
1736                 case SOT_FORMATSTR_ID_STARWRITER_8:
1737                 case SOT_FORMATSTR_ID_STARWRITERWEB_8:
1738                 case SOT_FORMATSTR_ID_STARWRITERGLOB_8:
1739                     pRead = ReadXML;
1740                     break;
1741                 default:
1742                     try
1743                     {
1744                         uno::Reference < lang::XComponent > xComp( xStore, uno::UNO_QUERY );
1745                         xComp->dispose();
1746                         xStore = 0;
1747                     }
1748                     catch ( uno::Exception& )
1749                     {
1750                     }
1751 
1752                     break;
1753             }
1754         }
1755         catch ( uno::Exception& )
1756         {
1757             // it wasn't a storage, but maybe it's a useful stream
1758         }
1759 
1760         nFmt = nId;
1761     }
1762 
1763     if( pRead )
1764     {
1765         SwPaM &rPAM = *rSh.GetCrsr();
1766         SwReader aReader( xStore, aEmptyStr, rPAM );
1767         if( !IsError( aReader.Read( *pRead )) )
1768             nRet = 1;
1769         else if( bMsg )
1770             InfoBox( 0, SW_RES(ERR_CLPBRD_READ) ).Execute();
1771     }
1772     else
1773     {
1774         // temporary storage until the object is inserted
1775         uno::Reference< embed::XStorage > xTmpStor;
1776         uno::Reference < embed::XEmbeddedObject > xObj;
1777         ::rtl::OUString aName;
1778         comphelper::EmbeddedObjectContainer aCnt;
1779 
1780         if ( xStrm.is() )
1781         {
1782             if ( !rData.GetTransferableObjectDescriptor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aObjDesc ) )
1783             {
1784                 DBG_ASSERT( !xStrm.is(), "An object without descriptor in clipboard!");
1785             }
1786         }
1787         else
1788         {
1789             if( rData.HasFormat( nFmt = SOT_FORMATSTR_ID_OBJECTDESCRIPTOR_OLE ) && rData.GetTransferableObjectDescriptor( nFmt, aObjDesc ) )
1790             {
1791                 if ( !rData.GetInputStream( SOT_FORMATSTR_ID_EMBED_SOURCE_OLE, xStrm ) )
1792                     rData.GetInputStream( SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE, xStrm );
1793 
1794                 if ( !xStrm.is() )
1795                 {
1796                     // This is MSOLE object that should be created by direct using of system clipboard
1797                     try
1798                     {
1799                         xTmpStor = ::comphelper::OStorageHelper::GetTemporaryStorage();
1800                         uno::Reference < embed::XEmbedObjectClipboardCreator > xClipboardCreator(
1801                             ::comphelper::getProcessServiceFactory()->createInstance( ::rtl::OUString(
1802                                             RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.MSOLEObjectSystemCreator")) ),
1803                             uno::UNO_QUERY_THROW );
1804 
1805                         embed::InsertedObjectInfo aInfo = xClipboardCreator->createInstanceInitFromClipboard(
1806                                                             xTmpStor,
1807                                                             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "DummyName" ) ),
1808                                                             uno::Sequence< beans::PropertyValue >() );
1809 
1810                         // TODO/LATER: in future InsertedObjectInfo will be used to get container related information
1811                         // for example whether the object should be an iconified one
1812                         xObj = aInfo.Object;
1813                     }
1814                     catch( uno::Exception& )
1815                     {}
1816                 }
1817             }
1818         }
1819 
1820         if ( xStrm.is() && !xObj.is() )
1821             xObj = aCnt.InsertEmbeddedObject( xStrm, aName );
1822 
1823         if( xObj.is() )
1824         {
1825             svt::EmbeddedObjectRef xObjRef( xObj, aObjDesc.mnViewAspect );
1826 
1827             // try to get the replacement image from the clipboard
1828             Graphic aGraphic;
1829             sal_uLong nGrFormat = 0;
1830 
1831 // (wg. Selection Manager bei Trustet Solaris)
1832 #ifndef SOLARIS
1833 /*
1834             if( rData.GetGraphic( SOT_FORMATSTR_ID_SVXB, aGraphic ) )
1835                 nGrFormat = SOT_FORMATSTR_ID_SVXB;
1836             else if( rData.GetGraphic( FORMAT_GDIMETAFILE, aGraphic ) )
1837                 nGrFormat = SOT_FORMAT_GDIMETAFILE;
1838             else if( rData.GetGraphic( FORMAT_BITMAP, aGraphic ) )
1839                 nGrFormat = SOT_FORMAT_BITMAP;
1840 */
1841 #endif
1842 
1843             // insert replacement image ( if there is one ) into the object helper
1844             if ( nGrFormat )
1845             {
1846                 datatransfer::DataFlavor aDataFlavor;
1847                 SotExchange::GetFormatDataFlavor( nGrFormat, aDataFlavor );
1848                 xObjRef.SetGraphic( aGraphic, aDataFlavor.MimeType );
1849             }
1850             else if ( aObjDesc.mnViewAspect == embed::Aspects::MSOLE_ICON )
1851             {
1852                 // it is important to have an icon, let an empty graphic be used
1853                 // if no other graphic is provided
1854                 // TODO/LATER: in future a default bitmap could be used
1855                 ::rtl::OUString aMimeType;
1856                 MapMode aMapMode( MAP_100TH_MM );
1857                 aGraphic.SetPrefSize( Size( 2500, 2500 ) );
1858                 aGraphic.SetPrefMapMode( aMapMode );
1859                 xObjRef.SetGraphic( aGraphic, aMimeType );
1860             }
1861 
1862             //Size einstellen. Ist ein Hack wg. Auslieferung, die Size sollte
1863             //an das InsertOle uebergeben werden!!!!!!!!!!
1864             Size aSize;
1865             if ( aObjDesc.mnViewAspect == embed::Aspects::MSOLE_ICON )
1866             {
1867                 if( aObjDesc.maSize.Width() && aObjDesc.maSize.Height() )
1868                     aSize = aObjDesc.maSize;
1869                 else
1870                 {
1871                     MapMode aMapMode( MAP_100TH_MM );
1872                     aSize = xObjRef.GetSize( &aMapMode );
1873                 }
1874             }
1875             else if( aObjDesc.maSize.Width() && aObjDesc.maSize.Height() )
1876             {
1877                 aSize = Size( aObjDesc.maSize );    //immer 100TH_MM
1878                 MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( aObjDesc.mnViewAspect ) );
1879                 aSize = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aUnit );
1880                 awt::Size aSz;
1881                 try
1882                 {
1883                     aSz = xObj->getVisualAreaSize( aObjDesc.mnViewAspect );
1884                 }
1885                 catch( embed::NoVisualAreaSizeException& )
1886                 {
1887                     // in this case the provided size is used
1888                 }
1889 
1890                 if ( aSz.Width != aSize.Width() || aSz.Height != aSize.Height() )
1891                 {
1892                     aSz.Width = aSize.Width();
1893                     aSz.Height = aSize.Height();
1894                     xObj->setVisualAreaSize( aObjDesc.mnViewAspect, aSz );
1895                 }
1896             }
1897             else
1898             {
1899                 // the descriptor contains the wrong object size
1900                 // the following call will let the MSOLE objects cache the size if it is possible
1901                 // it should be done while the object is running
1902                 try
1903                 {
1904                     xObj->getVisualAreaSize( aObjDesc.mnViewAspect );
1905                 }
1906                 catch( uno::Exception& )
1907                 {
1908                 }
1909             }
1910             //Ende mit Hack!
1911 
1912             rSh.InsertOleObject( xObjRef );
1913             nRet = 1;
1914 
1915             if( nRet && ( nActionFlags &
1916                 ( EXCHG_OUT_ACTION_FLAG_INSERT_TARGETURL >> 8) ))
1917                 SwTransferable::_PasteTargetURL( rData, rSh, 0, 0, sal_False );
1918 
1919             // let the object be unloaded if possible
1920             SwOLEObj::UnloadObject( xObj, rSh.GetDoc(), embed::Aspects::MSOLE_CONTENT );
1921         }
1922     }
1923     return nRet;
1924 }
1925 
1926 // -----------------------------------------------------------------------
1927 
1928 
1929 // -----------------------------------------------------------------------
1930 
1931 int SwTransferable::_PasteTargetURL( TransferableDataHelper& rData,
1932                                     SwWrtShell& rSh, sal_uInt16 nAction,
1933                                     const Point* pPt, sal_Bool bInsertGRF )
1934 {
1935     int nRet = 0;
1936     INetImage aINetImg;
1937     if( ( rData.HasFormat( SOT_FORMATSTR_ID_INET_IMAGE ) &&
1938           rData.GetINetImage( SOT_FORMATSTR_ID_INET_IMAGE, aINetImg )) ||
1939         ( rData.HasFormat( SOT_FORMATSTR_ID_NETSCAPE_IMAGE ) &&
1940           rData.GetINetImage( SOT_FORMATSTR_ID_NETSCAPE_IMAGE, aINetImg )) )
1941     {
1942         if( aINetImg.GetImageURL().Len() && bInsertGRF )
1943         {
1944             String sURL( aINetImg.GetImageURL() );
1945             SwTransferable::_CheckForURLOrLNKFile( rData, sURL );
1946 
1947             //!!! auf FileSystem abpruefen - nur dann ist es sinnvoll die
1948             // Grafiken zu testen !!!!
1949             Graphic aGrf;
1950             GraphicFilter *pFlt = GraphicFilter::GetGraphicFilter();
1951             nRet = GRFILTER_OK == GraphicFilter::LoadGraphic( sURL, aEmptyStr, aGrf, pFlt );
1952             if( nRet )
1953             {
1954                 switch( nAction )
1955                 {
1956                 case SW_PASTESDR_INSERT:
1957                     SwTransferable::SetSelInShell( rSh, sal_False, pPt );
1958                     rSh.Insert( sURL, aEmptyStr, aGrf );
1959                     break;
1960 
1961                 case SW_PASTESDR_REPLACE:
1962                     if( rSh.IsObjSelected() )
1963                     {
1964                         rSh.ReplaceSdrObj( sURL, aEmptyStr, &aGrf );
1965                         Point aPt( pPt ? *pPt : rSh.GetCrsrDocPos() );
1966                         SwTransferable::SetSelInShell( rSh, sal_True, &aPt );
1967                     }
1968                     else
1969                         rSh.ReRead( sURL, aEmptyStr, &aGrf );
1970                     break;
1971 
1972                 case SW_PASTESDR_SETATTR:
1973                     if( rSh.IsObjSelected() )
1974                         rSh.Paste( aGrf );
1975                     else if( OBJCNT_GRF == rSh.GetObjCntTypeOfSelection() )
1976                         rSh.ReRead( sURL, aEmptyStr, &aGrf );
1977                     else
1978                     {
1979                         SwTransferable::SetSelInShell( rSh, sal_False, pPt );
1980                         rSh.Insert( sURL, aEmptyStr, aGrf );
1981                     }
1982                     break;
1983                 default:
1984                     nRet = 0;
1985                 }
1986             }
1987         }
1988         else
1989             nRet = 1;
1990     }
1991 
1992     if( nRet )
1993     {
1994         SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
1995         rSh.GetFlyFrmAttr( aSet );
1996         SwFmtURL aURL( (SwFmtURL&)aSet.Get( RES_URL ) );
1997 
1998         if( aURL.GetURL() != aINetImg.GetTargetURL() ||
1999             aURL.GetTargetFrameName() != aINetImg.GetTargetFrame() )
2000         {
2001             aURL.SetURL( aINetImg.GetTargetURL(), sal_False );
2002             aURL.SetTargetFrameName( aINetImg.GetTargetFrame() );
2003             aSet.Put( aURL );
2004             rSh.SetFlyFrmAttr( aSet );
2005         }
2006     }
2007     return nRet;
2008 }
2009 
2010 
2011 // -----------------------------------------------------------------------
2012 
2013 void SwTransferable::SetSelInShell( SwWrtShell& rSh, sal_Bool bSelectFrm,
2014                                         const Point* pPt )
2015 {
2016     if( bSelectFrm )
2017     {
2018         // Rahmen/Objecte selektieren
2019         if( pPt && !rSh.GetView().GetViewFrame()->GetDispatcher()->IsLocked() )
2020         {
2021             rSh.GetView().NoRotate();
2022             if( rSh.SelectObj( *pPt ))
2023             {
2024                 rSh.HideCrsr();
2025                 rSh.EnterSelFrmMode( pPt );
2026                 bFrmDrag = sal_True;
2027             }
2028         }
2029     }
2030     else
2031     {
2032         if( rSh.IsFrmSelected() || rSh.IsObjSelected() )
2033         {
2034             rSh.UnSelectFrm();
2035             rSh.LeaveSelFrmMode();
2036             rSh.GetView().GetEditWin().StopInsFrm();
2037             bFrmDrag = sal_False;
2038         }
2039         else if( rSh.GetView().GetDrawFuncPtr() )
2040             rSh.GetView().GetEditWin().StopInsFrm();
2041 
2042         rSh.EnterStdMode();
2043         if( pPt )
2044             rSh.SwCrsrShell::SetCrsr( *pPt, sal_True );
2045     }
2046 }
2047 
2048 // -----------------------------------------------------------------------
2049 
2050 int SwTransferable::_PasteDDE( TransferableDataHelper& rData,
2051                                 SwWrtShell& rWrtShell, sal_Bool bReReadGrf,
2052                                 sal_Bool bMsg )
2053 {
2054     // Daten aus dem Clipboardformat
2055     String aApp, aTopic, aItem;
2056 
2057     {
2058         SotStorageStreamRef xStrm;
2059         if( !rData.GetSotStorageStream( SOT_FORMATSTR_ID_LINK, xStrm ))
2060         {
2061             ASSERT( !&rWrtShell, "DDE Data not found." );
2062             return 0;
2063         }   //sinnvollen Fehler melden!!
2064 
2065         rtl_TextEncoding eEncoding = DDE_TXT_ENCODING;
2066         xStrm->ReadCString( aApp, eEncoding );
2067         xStrm->ReadCString( aTopic, eEncoding );
2068         xStrm->ReadCString( aItem, eEncoding );
2069     }
2070 
2071     String aCmd;
2072     sfx2::MakeLnkName( aCmd, &aApp, aTopic, aItem );
2073 
2074     // wollen wir jetzt eine Grafik einlesen ?
2075     sal_uLong nFormat;
2076     if( !rData.HasFormat( FORMAT_RTF ) &&
2077         !rData.HasFormat( SOT_FORMATSTR_ID_HTML ) &&
2078         !rData.HasFormat( FORMAT_STRING ) &&
2079         (rData.HasFormat( nFormat = FORMAT_GDIMETAFILE ) ||
2080          rData.HasFormat( nFormat = FORMAT_BITMAP )) )
2081     {
2082         Graphic aGrf;
2083         int nRet = rData.GetGraphic( nFormat, aGrf );
2084         if( nRet )
2085         {
2086             String sLnkTyp( String::CreateFromAscii(
2087                         RTL_CONSTASCII_STRINGPARAM( "DDE" )));
2088             if ( bReReadGrf )
2089                 rWrtShell.ReRead( aCmd, sLnkTyp, &aGrf );
2090             else
2091                 rWrtShell.Insert( aCmd, sLnkTyp, aGrf );
2092         }
2093         return nRet;
2094     }
2095 
2096     SwFieldType* pTyp = 0;
2097     sal_uInt16 i = 1,j;
2098     String aName;
2099     sal_Bool bAlreadyThere = sal_False, bDoublePaste = sal_False;
2100     sal_uInt16 nSize = rWrtShell.GetFldTypeCount();
2101     const ::utl::TransliterationWrapper& rColl = ::GetAppCmpStrIgnore();
2102 
2103     do {
2104         aName = aApp;
2105         aName += String::CreateFromInt32( i );
2106         for( j = INIT_FLDTYPES; j < nSize; j++ )
2107         {
2108             pTyp = rWrtShell.GetFldType( j );
2109             if( RES_DDEFLD == pTyp->Which() )
2110             {
2111                 String sTmp( ((SwDDEFieldType*)pTyp)->GetCmd() );
2112                 if( rColl.isEqual( sTmp, aCmd ) &&
2113                     sfx2::LINKUPDATE_ALWAYS == ((SwDDEFieldType*)pTyp)->GetType() )
2114                 {
2115                     aName = pTyp->GetName();
2116                     bDoublePaste = sal_True;
2117                     break;
2118                 }
2119                 else if( rColl.isEqual( aName, pTyp->GetName() ) )
2120                     break;
2121             }
2122         }
2123         if( j == nSize )
2124             bAlreadyThere = sal_False;
2125         else
2126         {
2127             bAlreadyThere = sal_True;
2128             i++;
2129         }
2130     }
2131     while( bAlreadyThere && !bDoublePaste );
2132 
2133     if( !bDoublePaste )
2134     {
2135         SwDDEFieldType aType( aName, aCmd, sfx2::LINKUPDATE_ALWAYS );
2136         pTyp = rWrtShell.InsertFldType( aType );
2137     }
2138 
2139 
2140     SwDDEFieldType* pDDETyp = (SwDDEFieldType*)pTyp;
2141 
2142     String aExpand;
2143     if( rData.GetString( FORMAT_STRING, aExpand ))
2144     {
2145         do {            // middle checked loop
2146 
2147             // Wenn die Daten von einer Tabellenkalkulation kommen
2148             // fuegen wir eine DDE-Tabelle ein
2149             if( ( rData.HasFormat( SOT_FORMATSTR_ID_SYLK ) ||
2150                   rData.HasFormat( SOT_FORMATSTR_ID_SYLK_BIGCAPS ) ) &&
2151                 aExpand.Len() &&
2152                  ( 1 < aExpand.GetTokenCount( '\n' ) ||
2153                        aExpand.GetTokenCount( '\t' )) )
2154             {
2155                 String sTmp( aExpand );
2156                 xub_StrLen nRows = sTmp.GetTokenCount( '\n' );
2157                 if( nRows )
2158                     --nRows;
2159                 sTmp = sTmp.GetToken( 0, '\n' );
2160                 xub_StrLen nCols = sTmp.GetTokenCount( '\t' );
2161 
2162                 // mindestens eine Spalte & Zeile muss vorhanden sein
2163                 if( !nRows || !nCols )
2164                 {
2165                     if( bMsg )
2166                         InfoBox(0, SW_RESSTR(STR_NO_TABLE)).Execute();
2167                     pDDETyp = 0;
2168                     break;
2169                 }
2170 
2171                 rWrtShell.InsertDDETable(
2172                     SwInsertTableOptions( tabopts::HEADLINE_NO_BORDER, 1 ), // TODO MULTIHEADER
2173                     pDDETyp, nRows, nCols );
2174             }
2175             else if( 1 < aExpand.GetTokenCount( '\n' ) )
2176             {
2177                 // mehrere Absaetze -> eine geschuetzte Section einfuegen
2178                 if( rWrtShell.HasSelection() )
2179                     rWrtShell.DelRight();
2180 
2181                 SwSectionData aSect( DDE_LINK_SECTION, aName );
2182                 aSect.SetLinkFileName( aCmd );
2183                 aSect.SetProtectFlag(true);
2184                 rWrtShell.InsertSection( aSect );
2185 
2186                 pDDETyp = 0;                // FeldTypen wieder entfernen
2187             }
2188             else
2189             {
2190                 // Einfuegen
2191                 SwDDEField aSwDDEField( pDDETyp );
2192                 rWrtShell.Insert( aSwDDEField );
2193             }
2194 
2195         } while( sal_False );
2196     }
2197     else
2198         pDDETyp = 0;                        // FeldTypen wieder entfernen
2199 
2200     if( !pDDETyp && !bDoublePaste )
2201     {
2202         // FeldTyp wieder entfernen - Fehler aufgetreten!
2203         for( j = nSize; j >= INIT_FLDTYPES; --j )
2204             if( pTyp == rWrtShell.GetFldType( j ) )
2205             {
2206                 rWrtShell.RemoveFldType( j );
2207                 break;
2208             }
2209     }
2210 
2211     return 1;
2212 }
2213 
2214 // -----------------------------------------------------------------------
2215 
2216 int SwTransferable::_PasteSdrFormat(  TransferableDataHelper& rData,
2217                                     SwWrtShell& rSh, sal_uInt16 nAction,
2218                                     const Point* pPt, sal_uInt8 nActionFlags )
2219 {
2220     int nRet = 0;
2221     SotStorageStreamRef xStrm;
2222     if( rData.GetSotStorageStream( SOT_FORMATSTR_ID_DRAWING, xStrm ))
2223     {
2224         xStrm->SetVersion( SOFFICE_FILEFORMAT_50 );
2225         rSh.Paste( *xStrm, nAction, pPt );
2226         nRet = 1;
2227 
2228         if( nRet && ( nActionFlags &
2229             ( EXCHG_OUT_ACTION_FLAG_INSERT_TARGETURL >> 8) ))
2230             SwTransferable::_PasteTargetURL( rData, rSh, 0, 0, sal_False );
2231     }
2232     return nRet;
2233 }
2234 
2235 // -----------------------------------------------------------------------
2236 
2237 int SwTransferable::_PasteGrf( TransferableDataHelper& rData, SwWrtShell& rSh,
2238                                 sal_uLong nFmt, sal_uInt16 nAction, const Point* pPt,
2239                                 sal_uInt8 nActionFlags, sal_Bool /*bMsg*/ )
2240 {
2241     int nRet = 0;
2242 
2243     Graphic aGrf;
2244     INetBookmark aBkmk;
2245     sal_Bool bCheckForGrf = sal_False, bCheckForImageMap = sal_False;
2246 
2247     switch( nFmt )
2248     {
2249     case SOT_FORMAT_BITMAP:
2250     case SOT_FORMAT_GDIMETAFILE:
2251         nRet = rData.GetGraphic( nFmt, aGrf );
2252         break;
2253 
2254     case SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK:
2255     case SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR:
2256     case SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR:
2257         if( 0 != ( nRet = rData.GetINetBookmark( nFmt, aBkmk ) ))
2258         {
2259 /*              if( SW_PASTESDR_SETATTR != nAction )
2260             {
2261                 INetURLObject aURL( aBkmk.GetURL() );
2262                 bCheckForGrf = INET_PROT_FILE == aURL.GetProtocol();
2263                 nRet = 0 != bCheckForGrf;
2264             }
2265 */
2266             if( SW_PASTESDR_SETATTR == nAction )
2267                 nFmt = SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK;
2268             else
2269                 bCheckForGrf = sal_True;
2270         }
2271         break;
2272 
2273     case SOT_FORMAT_FILE:
2274         {
2275             String sTxt;
2276             if( 0 != ( nRet = rData.GetString( nFmt, sTxt ) ) )
2277             {
2278                 String sDesc;
2279                 SwTransferable::_CheckForURLOrLNKFile( rData, sTxt, &sDesc );
2280 
2281                 aBkmk = INetBookmark(
2282                         URIHelper::SmartRel2Abs(INetURLObject(), sTxt, Link(), false ),
2283                         sDesc );
2284                 bCheckForGrf = sal_True;
2285                 bCheckForImageMap = SW_PASTESDR_REPLACE == nAction;
2286             }
2287         }
2288         break;
2289 
2290     default:
2291         nRet = rData.GetGraphic( nFmt, aGrf );
2292         break;
2293     }
2294 
2295     if( bCheckForGrf )
2296     {
2297         //!!! auf FileSystem abpruefen - nur dann ist es sinnvoll die
2298         // Grafiken zu testen !!!!
2299         GraphicFilter *pFlt = GraphicFilter::GetGraphicFilter();
2300         nRet = GRFILTER_OK == GraphicFilter::LoadGraphic( aBkmk.GetURL(), aEmptyStr,
2301                                             aGrf, pFlt );
2302         if( !nRet && SW_PASTESDR_SETATTR == nAction &&
2303             SOT_FORMAT_FILE == nFmt &&
2304             // Bug 63031 - nur bei Rahmenselektion
2305             rSh.IsFrmSelected() )
2306         {
2307             // dann als Hyperlink hinter die Grafik setzen
2308             nFmt = SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK;
2309             nRet = sal_True;
2310         }
2311     }
2312 
2313     if( nRet )
2314     {
2315         String sURL;
2316         if( rSh.GetView().GetDocShell()->ISA(SwWebDocShell) )
2317             sURL = aBkmk.GetURL();
2318 
2319         switch( nAction )
2320         {
2321         case SW_PASTESDR_INSERT:
2322             SwTransferable::SetSelInShell( rSh, sal_False, pPt );
2323             rSh.Insert( sURL, aEmptyStr, aGrf );
2324         break;
2325 
2326         case SW_PASTESDR_REPLACE:
2327             if( rSh.IsObjSelected() )
2328             {
2329                 rSh.ReplaceSdrObj( sURL, aEmptyStr, &aGrf );
2330                 Point aPt( pPt ? *pPt : rSh.GetCrsrDocPos() );
2331                 SwTransferable::SetSelInShell( rSh, sal_True, &aPt );
2332             }
2333             else
2334                 rSh.ReRead( sURL, aEmptyStr, &aGrf );
2335             break;
2336 
2337         case SW_PASTESDR_SETATTR:
2338             if( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK == nFmt )
2339             {
2340                 if( rSh.IsFrmSelected() )
2341                 {
2342                     SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
2343                     rSh.GetFlyFrmAttr( aSet );
2344                     SwFmtURL aURL( (SwFmtURL&)aSet.Get( RES_URL ) );
2345                     aURL.SetURL( aBkmk.GetURL(), sal_False );
2346                     aSet.Put( aURL );
2347                     rSh.SetFlyFrmAttr( aSet );
2348                 }
2349             }
2350             else if( rSh.IsObjSelected() )
2351                 rSh.Paste( aGrf );
2352             else if( OBJCNT_GRF == rSh.GetObjCntTypeOfSelection() )
2353                 rSh.ReRead( sURL, aEmptyStr, &aGrf );
2354             else
2355             {
2356                 SwTransferable::SetSelInShell( rSh, sal_False, pPt );
2357                 rSh.Insert( aBkmk.GetURL(), aEmptyStr, aGrf );
2358             }
2359             break;
2360         default:
2361             nRet = 0;
2362         }
2363     }
2364 
2365     if( nRet )
2366     {
2367 
2368         if( nActionFlags &
2369             (( EXCHG_OUT_ACTION_FLAG_INSERT_IMAGEMAP |
2370                 EXCHG_OUT_ACTION_FLAG_REPLACE_IMAGEMAP ) >> 8) )
2371             SwTransferable::_PasteImageMap( rData, rSh );
2372 
2373         if( nActionFlags &
2374             ( EXCHG_OUT_ACTION_FLAG_INSERT_TARGETURL >> 8) )
2375             SwTransferable::_PasteTargetURL( rData, rSh, 0, 0, sal_False );
2376     }
2377     else if( bCheckForImageMap )
2378     {
2379         // oder sollte das File ein ImageMap-File sein?
2380         ImageMap aMap;
2381         SfxMedium aMed( INetURLObject(aBkmk.GetURL()).GetFull(),
2382                             STREAM_STD_READ, sal_False );
2383         SvStream* pStream = aMed.GetInStream();
2384         if( pStream != NULL  &&
2385             !pStream->GetError()  &&
2386             // mba: no BaseURL for clipboard functionality
2387             aMap.Read( *pStream, IMAP_FORMAT_DETECT, String() ) == IMAP_ERR_OK &&
2388             aMap.GetIMapObjectCount() )
2389         {
2390             SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
2391             rSh.GetFlyFrmAttr( aSet );
2392             SwFmtURL aURL( (SwFmtURL&)aSet.Get( RES_URL ) );
2393             aURL.SetMap( &aMap );
2394             aSet.Put( aURL );
2395             rSh.SetFlyFrmAttr( aSet );
2396             nRet = 1;
2397         }
2398     }
2399 
2400     return nRet;
2401 }
2402 
2403 // -----------------------------------------------------------------------
2404 
2405 int SwTransferable::_PasteImageMap( TransferableDataHelper& rData,
2406                                     SwWrtShell& rSh )
2407 {
2408     int nRet = 0;
2409     if( rData.HasFormat( SOT_FORMATSTR_ID_SVIM ))
2410     {
2411         SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
2412         rSh.GetFlyFrmAttr( aSet );
2413         SwFmtURL aURL( (SwFmtURL&)aSet.Get( RES_URL ) );
2414         const ImageMap* pOld = aURL.GetMap();
2415 
2416         // setzen oder ersetzen ist hier die Frage
2417         ImageMap aImageMap;
2418         if( rData.GetImageMap( SOT_FORMATSTR_ID_SVIM, aImageMap ) &&
2419             ( !pOld || aImageMap != *pOld ))
2420         {
2421             aURL.SetMap( &aImageMap );
2422             aSet.Put( aURL );
2423             rSh.SetFlyFrmAttr( aSet );
2424         }
2425         nRet = 1;
2426     }
2427     return nRet;
2428 }
2429 
2430 // -----------------------------------------------------------------------
2431 
2432 int SwTransferable::_PasteAsHyperlink( TransferableDataHelper& rData,
2433                                         SwWrtShell& rSh, sal_uLong nFmt )
2434 {
2435     int nRet = 0;
2436     String sFile;
2437     if( rData.GetString( nFmt, sFile ) && sFile.Len() )
2438     {
2439         String sDesc;
2440         SwTransferable::_CheckForURLOrLNKFile( rData, sFile, &sDesc );
2441 
2442         //#41801# ersteinmal die URL absolut machen
2443         INetURLObject aURL;
2444         aURL.SetSmartProtocol( INET_PROT_FILE );
2445         aURL.SetSmartURL( sFile );
2446         sFile = aURL.GetMainURL( INetURLObject::NO_DECODE );
2447 
2448         switch( rSh.GetObjCntTypeOfSelection() )
2449         {
2450         case OBJCNT_FLY:
2451         case OBJCNT_GRF:
2452         case OBJCNT_OLE:
2453             {
2454                 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
2455                 rSh.GetFlyFrmAttr( aSet );
2456                 SwFmtURL aURL2( (SwFmtURL&)aSet.Get( RES_URL ) );
2457                 aURL2.SetURL( sFile, sal_False );
2458                 if( !aURL2.GetName().Len() )
2459                     aURL2.SetName( sFile );
2460                 aSet.Put( aURL2 );
2461                 rSh.SetFlyFrmAttr( aSet );
2462             }
2463             break;
2464 
2465         default:
2466             {
2467                 rSh.InsertURL( SwFmtINetFmt( sFile, aEmptyStr ),
2468                                 sDesc.Len() ? sDesc : sFile );
2469             }
2470         }
2471         nRet = sal_True;
2472     }
2473     return nRet;
2474 }
2475 
2476 // -----------------------------------------------------------------------
2477 
2478 int SwTransferable::_PasteFileName( TransferableDataHelper& rData,
2479                                     SwWrtShell& rSh, sal_uLong nFmt,
2480                                     sal_uInt16 nAction, const Point* pPt,
2481                                     sal_uInt8 nActionFlags, sal_Bool bMsg )
2482 {
2483     int nRet = SwTransferable::_PasteGrf( rData, rSh, nFmt, nAction,
2484                                             pPt, nActionFlags, bMsg );
2485     if( nRet )
2486         nRet |= SWTRANSFER_GRAPHIC_INSERTED;
2487     if( !nRet )
2488     {
2489         String sFile, sDesc;
2490         if( rData.GetString( nFmt, sFile ) && sFile.Len() )
2491         {
2492             INetURLObject aMediaURL;
2493 
2494             aMediaURL.SetSmartURL( sFile );
2495             const String aMediaURLStr( aMediaURL.GetMainURL( INetURLObject::NO_DECODE ) );
2496 
2497             if( ::avmedia::MediaWindow::isMediaURL( aMediaURLStr ) )
2498             {
2499                 const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, aMediaURLStr );
2500                 rSh.GetView().GetViewFrame()->GetDispatcher()->Execute(
2501                                 SID_INSERT_AVMEDIA, SFX_CALLMODE_SYNCHRON,
2502                                 &aMediaURLItem, 0L );
2503             }
2504             else
2505             {
2506                 sal_Bool bIsURLFile = SwTransferable::_CheckForURLOrLNKFile( rData, sFile, &sDesc );
2507 
2508                 //Eigenes FileFormat? -->Einfuegen, nicht fuer StarWriter/Web
2509                 String sFileURL = URIHelper::SmartRel2Abs(INetURLObject(), sFile, Link(), false );
2510                 const SfxFilter* pFlt = SW_PASTESDR_SETATTR == nAction
2511                         ? 0 : SwIoSystem::GetFileFilter(
2512                         sFileURL, aEmptyStr );
2513                 if( pFlt && !rSh.GetView().GetDocShell()->ISA(SwWebDocShell)
2514     /*
2515     JP 02.07.98: warum nur fuer die Formate ??
2516                     && ( pFlt->GetUserData() == FILTER_SW5 ||
2517                     pFlt->GetUserData() == FILTER_SW4 ||
2518                     pFlt->GetUserData() == FILTER_SW3 ||
2519                     pFlt->GetUserData() == FILTER_SWG )
2520     */
2521                     )
2522                 {
2523     // und dann per PostUser Event den Bereich-Einfuegen-Dialog hochreissen
2524                     SwSectionData * pSect = new SwSectionData(
2525                                     FILE_LINK_SECTION,
2526                                     rSh.GetDoc()->GetUniqueSectionName() );
2527                     pSect->SetLinkFileName( sFileURL );
2528                     pSect->SetProtectFlag( true );
2529 
2530                     Application::PostUserEvent( STATIC_LINK( &rSh, SwWrtShell,
2531                                                 InsertRegionDialog ), pSect );
2532                     nRet = 1;
2533                     }
2534                 else if( SW_PASTESDR_SETATTR == nAction ||
2535                         ( bIsURLFile && SW_PASTESDR_INSERT == nAction ))
2536                 {
2537                     //Fremde Files koennen wir immerhin noch als Links
2538                     //Einfuegen.
2539 
2540                     //#41801# ersteinmal die URL absolut machen
2541                     INetURLObject aURL;
2542                     aURL.SetSmartProtocol( INET_PROT_FILE );
2543                     aURL.SetSmartURL( sFile );
2544                     sFile = aURL.GetMainURL( INetURLObject::NO_DECODE );
2545 
2546                     switch( rSh.GetObjCntTypeOfSelection() )
2547                     {
2548                     case OBJCNT_FLY:
2549                     case OBJCNT_GRF:
2550                     case OBJCNT_OLE:
2551                         {
2552                             SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
2553                             rSh.GetFlyFrmAttr( aSet );
2554                             SwFmtURL aURL2( (SwFmtURL&)aSet.Get( RES_URL ) );
2555                             aURL2.SetURL( sFile, sal_False );
2556                             if( !aURL2.GetName().Len() )
2557                                 aURL2.SetName( sFile );
2558                             aSet.Put( aURL2 );
2559                             rSh.SetFlyFrmAttr( aSet );
2560                         }
2561                         break;
2562 
2563                     default:
2564                         {
2565                             rSh.InsertURL( SwFmtINetFmt( sFile, aEmptyStr ),
2566                                             sDesc.Len() ? sDesc : sFile );
2567                         }
2568                     }
2569                     nRet = sal_True;
2570                 }
2571             }
2572         }
2573     }
2574     return nRet;
2575 }
2576 
2577 // -----------------------------------------------------------------------
2578 
2579 int SwTransferable::_PasteDBData( TransferableDataHelper& rData,
2580                                     SwWrtShell& rSh, sal_uLong nFmt, sal_Bool bLink,
2581                                     const Point* pDragPt, sal_Bool bMsg )
2582 {
2583     int nRet = 0;
2584     String sTxt;
2585     if( rData.GetString( nFmt, sTxt ) && sTxt.Len() )
2586     {
2587         sal_uInt16 nWh = SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE == nFmt
2588                     ? 0
2589                     : SOT_FORMATSTR_ID_SBA_DATAEXCHANGE == nFmt
2590                                 ? (bLink
2591                                     ? FN_QRY_MERGE_FIELD
2592                                     : FN_QRY_INSERT)
2593                                 : (bLink
2594                                     ? 0
2595                                     : FN_QRY_INSERT_FIELD );
2596         DataFlavorExVector& rVector = rData.GetDataFlavorExVector();
2597         sal_Bool bHaveColumnDescriptor = OColumnTransferable::canExtractColumnDescriptor(rVector, CTF_COLUMN_DESCRIPTOR | CTF_CONTROL_EXCHANGE);
2598         if ( SOT_FORMATSTR_ID_XFORMS == nFmt )
2599         {
2600             SdrObject* pObj;
2601             rSh.MakeDrawView();
2602             FmFormView* pFmView = PTR_CAST( FmFormView, rSh.GetDrawView() );
2603             if(pFmView) {
2604                 const OXFormsDescriptor &rDesc = OXFormsTransferable::extractDescriptor(rData);
2605                 if(0 != (pObj = pFmView->CreateXFormsControl(rDesc)))
2606                 {
2607                     rSh.SwFEShell::InsertDrawObj( *pObj, *pDragPt );
2608                 }
2609             }
2610         }
2611         else if( nWh )
2612         {
2613             SfxUsrAnyItem* pConnectionItem  = 0;
2614             SfxUsrAnyItem* pCursorItem      = 0;
2615             SfxUsrAnyItem* pColumnItem      = 0;
2616             SfxUsrAnyItem* pSourceItem      = 0;
2617             SfxUsrAnyItem* pCommandItem     = 0;
2618             SfxUsrAnyItem* pCommandTypeItem = 0;
2619             SfxUsrAnyItem* pColumnNameItem  = 0;
2620             SfxUsrAnyItem* pSelectionItem   = 0;
2621 
2622             sal_Bool bDataAvailable = sal_True;
2623             ODataAccessDescriptor aDesc;
2624             if(bHaveColumnDescriptor)
2625                 aDesc = OColumnTransferable::extractColumnDescriptor(rData);
2626             else if(ODataAccessObjectTransferable::canExtractObjectDescriptor(rVector) )
2627                 aDesc = ODataAccessObjectTransferable::extractObjectDescriptor(rData);
2628             else
2629                 bDataAvailable = sal_False;
2630 
2631             if ( bDataAvailable )
2632             {
2633                 pConnectionItem = new SfxUsrAnyItem(FN_DB_CONNECTION_ANY, aDesc[daConnection]);
2634                 pColumnItem = new SfxUsrAnyItem(FN_DB_COLUMN_ANY, aDesc[daColumnObject]);
2635                 pSourceItem = new SfxUsrAnyItem(FN_DB_DATA_SOURCE_ANY, makeAny(aDesc.getDataSource()));
2636                 pCommandItem = new SfxUsrAnyItem(FN_DB_DATA_COMMAND_ANY, aDesc[daCommand]);
2637                 pCommandTypeItem = new SfxUsrAnyItem(FN_DB_DATA_COMMAND_TYPE_ANY, aDesc[daCommandType]);
2638                 pColumnNameItem = new SfxUsrAnyItem(FN_DB_DATA_COLUMN_NAME_ANY, aDesc[daColumnName]);
2639                 pSelectionItem = new SfxUsrAnyItem(FN_DB_DATA_SELECTION_ANY, aDesc[daSelection]);
2640                 pCursorItem = new SfxUsrAnyItem(FN_DB_DATA_CURSOR_ANY, aDesc[daCursor]);
2641             }
2642 
2643             SwView& rView = rSh.GetView();
2644             //force ::SelectShell
2645             rView.StopShellTimer();
2646 
2647             SfxStringItem aDataDesc( nWh, sTxt );
2648             rView.GetViewFrame()->GetDispatcher()->Execute(
2649                                 nWh, SFX_CALLMODE_ASYNCHRON, &aDataDesc,
2650                                 pConnectionItem, pColumnItem,
2651                                 pSourceItem, pCommandItem, pCommandTypeItem,
2652                                 pColumnNameItem, pSelectionItem, pCursorItem,0L);
2653             delete pConnectionItem;
2654             delete pColumnItem;
2655             delete pSourceItem;
2656             delete pCommandItem;
2657             delete pCommandTypeItem;
2658             delete pColumnNameItem;
2659             delete pCursorItem;
2660         }
2661         else
2662         {
2663             SdrObject* pObj;
2664             rSh.MakeDrawView();
2665             FmFormView* pFmView = PTR_CAST( FmFormView, rSh.GetDrawView() );
2666             if (pFmView && bHaveColumnDescriptor)
2667             {
2668                 if ( 0 != (pObj = pFmView->CreateFieldControl( OColumnTransferable::extractColumnDescriptor(rData) ) ) )
2669                     rSh.SwFEShell::InsertDrawObj( *pObj, *pDragPt );
2670             }
2671         }
2672         nRet = 1;
2673     }
2674     else if( bMsg )
2675     {
2676         InfoBox( 0, SW_RES(MSG_CLPBRD_FORMAT_ERROR)).Execute();
2677     }
2678     return nRet;
2679 }
2680 
2681 // -----------------------------------------------------------------------
2682 
2683 int SwTransferable::_PasteFileList( TransferableDataHelper& rData,
2684                                     SwWrtShell& rSh, sal_Bool bLink,
2685                                     const Point* pPt, sal_Bool bMsg )
2686 {
2687     int nRet = 0;
2688     FileList aFileList;
2689     if( rData.GetFileList( SOT_FORMAT_FILE_LIST, aFileList ) &&
2690         aFileList.Count() )
2691     {
2692         sal_uInt16 nAct = bLink ? SW_PASTESDR_SETATTR : SW_PASTESDR_INSERT;
2693         String sFlyNm;
2694         // iterate over the filelist
2695         for( sal_uLong n = 0, nEnd = aFileList.Count(); n < nEnd; ++n )
2696         {
2697             TransferDataContainer* pHlp = new TransferDataContainer;
2698             pHlp->CopyString( FORMAT_FILE, aFileList.GetFile( n ));
2699             TransferableDataHelper aData( pHlp );
2700 
2701             if( SwTransferable::_PasteFileName( aData, rSh, SOT_FORMAT_FILE, nAct,
2702                                             pPt, sal_False, bMsg ))
2703             {
2704                 if( bLink )
2705                 {
2706                     sFlyNm = rSh.GetFlyName();
2707                     SwTransferable::SetSelInShell( rSh, sal_False, pPt );
2708                 }
2709                 nRet = 1;
2710             }
2711         }
2712         if( sFlyNm.Len() )
2713             rSh.GotoFly( sFlyNm );
2714     }
2715     else if( bMsg )
2716     {
2717         InfoBox( 0, SW_RES(MSG_CLPBRD_FORMAT_ERROR)).Execute();
2718     }
2719     return nRet;
2720 }
2721 
2722 // -----------------------------------------------------------------------
2723 
2724 sal_Bool SwTransferable::_CheckForURLOrLNKFile( TransferableDataHelper& rData,
2725                                         String& rFileName, String* pTitle )
2726 {
2727     sal_Bool bIsURLFile = sal_False;
2728     INetBookmark aBkmk;
2729     if( rData.GetINetBookmark( SOT_FORMATSTR_ID_SOLK, aBkmk ) )
2730     {
2731         rFileName = aBkmk.GetURL();
2732         if( pTitle )
2733             *pTitle = aBkmk.GetDescription();
2734         bIsURLFile = sal_True;
2735     }
2736     else
2737     {
2738         xub_StrLen nLen = rFileName.Len();
2739         if( 4 < nLen && '.' == rFileName.GetChar( nLen - 4 ))
2740         {
2741             String sExt( rFileName.Copy( nLen - 3 ));
2742             if( sExt.EqualsIgnoreCaseAscii( "url" ))
2743             {
2744 ASSERT( !&rFileName, "how do we read today .URL - Files?" );
2745             }
2746         }
2747     }
2748     return bIsURLFile;
2749 }
2750 
2751 // -----------------------------------------------------------------------
2752 
2753 sal_Bool SwTransferable::IsPasteSpecial( const SwWrtShell& rWrtShell,
2754                                      const TransferableDataHelper& rData )
2755 {
2756     // we can paste-special if there's an entry in the paste-special-format list
2757     SvxClipboardFmtItem aClipboardFmtItem(0);
2758     FillClipFmtItem( rWrtShell, rData, aClipboardFmtItem);
2759     return aClipboardFmtItem.Count() > 0;
2760 }
2761 
2762 // -----------------------------------------------------------------------
2763 
2764 int SwTransferable::PasteFormat( SwWrtShell& rSh,
2765                                     TransferableDataHelper& rData,
2766                                     sal_uLong nFormat )
2767 {
2768     SwWait aWait( *rSh.GetView().GetDocShell(), sal_False );
2769     int nRet = 0;
2770 
2771     sal_uLong nPrivateFmt = FORMAT_PRIVATE;
2772     SwTransferable *pClipboard = GetSwTransferable( rData );
2773     if( pClipboard &&
2774         ((TRNSFR_DOCUMENT|TRNSFR_GRAPHIC|TRNSFR_OLE) & pClipboard->eBufferType ))
2775         nPrivateFmt = SOT_FORMATSTR_ID_EMBED_SOURCE;
2776 
2777     if( pClipboard && nPrivateFmt == nFormat )
2778         nRet = pClipboard->PrivatePaste( rSh );
2779     else if( rData.HasFormat( nFormat ) )
2780     {
2781         uno::Reference<XTransferable> xTransferable( rData.GetXTransferable() );
2782         sal_uInt16 nEventAction,
2783                nDestination = SwTransferable::GetSotDestination( rSh ),
2784                nSourceOptions =
2785                     (( EXCHG_DEST_DOC_TEXTFRAME == nDestination ||
2786                        EXCHG_DEST_SWDOC_FREE_AREA == nDestination ||
2787                        EXCHG_DEST_DOC_TEXTFRAME_WEB == nDestination ||
2788                        EXCHG_DEST_SWDOC_FREE_AREA_WEB == nDestination )
2789                                         ? EXCHG_IN_ACTION_COPY
2790                                         : EXCHG_IN_ACTION_MOVE),
2791                nAction = SotExchange::GetExchangeAction(
2792                                     rData.GetDataFlavorExVector(),
2793                                     nDestination,
2794                                     nSourceOptions,             /* ?? */
2795                                     EXCHG_IN_ACTION_DEFAULT,    /* ?? */
2796                                     nFormat, nEventAction, nFormat,
2797                                     lcl_getTransferPointer ( xTransferable ) );
2798 
2799         if( EXCHG_INOUT_ACTION_NONE != nAction )
2800             nRet = SwTransferable::PasteData( rData, rSh, nAction, nFormat,
2801                                                 nDestination, sal_True, sal_False );
2802     }
2803     return nRet;
2804 }
2805 
2806 // -----------------------------------------------------------------------
2807 
2808 int SwTransferable::_TestAllowedFormat( const TransferableDataHelper& rData,
2809                                         sal_uLong nFormat, sal_uInt16 nDestination )
2810 {
2811     sal_uInt16 nAction = EXCHG_INOUT_ACTION_NONE, nEventAction;
2812     if( rData.HasFormat( nFormat )) {
2813         uno::Reference<XTransferable> xTransferable( rData.GetXTransferable() );
2814         nAction = SotExchange::GetExchangeAction(
2815                         rData.GetDataFlavorExVector(),
2816                         nDestination, EXCHG_IN_ACTION_COPY,
2817                         EXCHG_IN_ACTION_COPY, nFormat,
2818                         nEventAction, nFormat,
2819                         lcl_getTransferPointer ( xTransferable ) );
2820     }
2821     return EXCHG_INOUT_ACTION_NONE != nAction;
2822 }
2823 
2824 // -----------------------------------------------------------------------
2825 
2826 /**
2827  * the list of formats which will be offered to the user in the 'Paste
2828  * Special...' dialog and the paste button menu
2829  */
2830 static sal_uInt16 aPasteSpecialIds[] =
2831 {
2832     SOT_FORMATSTR_ID_HTML,
2833     SOT_FORMATSTR_ID_HTML_SIMPLE,
2834     SOT_FORMATSTR_ID_HTML_NO_COMMENT,
2835     FORMAT_RTF,
2836     FORMAT_STRING,
2837     SOT_FORMATSTR_ID_SONLK,
2838     SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK,
2839     SOT_FORMATSTR_ID_DRAWING,
2840     SOT_FORMATSTR_ID_SVXB,
2841     FORMAT_GDIMETAFILE,
2842     FORMAT_BITMAP,
2843     SOT_FORMATSTR_ID_SVIM,
2844     SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR,
2845     0
2846 };
2847 
2848 
2849 int SwTransferable::PasteUnformatted( SwWrtShell& rSh, TransferableDataHelper& rData )
2850 {
2851     // Plain text == unformatted
2852     return SwTransferable::PasteFormat( rSh, rData, SOT_FORMAT_STRING );
2853 }
2854 
2855 // -----------------------------------------------------------------------
2856 
2857 int SwTransferable::PasteSpecial( SwWrtShell& rSh, TransferableDataHelper& rData, sal_uLong& rFormatUsed )
2858 {
2859     int nRet = 0;
2860     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
2861     SfxAbstractPasteDialog* pDlg = pFact->CreatePasteDialog( &rSh.GetView().GetEditWin() );
2862 
2863     DataFlavorExVector aFormats( rData.GetDataFlavorExVector() );
2864     TransferableObjectDescriptor aDesc;
2865 
2866     sal_uInt16 nDest = SwTransferable::GetSotDestination( rSh );
2867 
2868     SwTransferable *pClipboard = GetSwTransferable( rData );
2869     if( pClipboard )
2870     {
2871         aDesc = pClipboard->aObjDesc;
2872         sal_uInt16 nResId;
2873         if( pClipboard->eBufferType & TRNSFR_DOCUMENT )
2874             nResId = STR_PRIVATETEXT;
2875         else if( pClipboard->eBufferType & TRNSFR_GRAPHIC )
2876             nResId = STR_PRIVATEGRAPHIC;
2877         else if( pClipboard->eBufferType == TRNSFR_OLE )
2878             nResId = STR_PRIVATEOLE;
2879         else
2880             nResId = 0;
2881 
2882         if( nResId )
2883         {
2884             if( STR_PRIVATEOLE == nResId || STR_PRIVATEGRAPHIC == nResId )
2885             {
2886                 // add SOT_FORMATSTR_ID_EMBED_SOURCE to the formats. This
2887                 // format display then the private format name.
2888                 DataFlavorEx aFlavorEx;
2889                 aFlavorEx.mnSotId = SOT_FORMATSTR_ID_EMBED_SOURCE;
2890                 aFormats.insert( aFormats.begin(), aFlavorEx );
2891             }
2892             pDlg->SetObjName( pClipboard->aObjDesc.maClassName,
2893                                 SW_RES( nResId ) );
2894             pDlg->Insert( SOT_FORMATSTR_ID_EMBED_SOURCE, aEmptyStr );
2895         }
2896     }
2897     else
2898     {
2899         if( rData.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) )
2900             rData.GetTransferableObjectDescriptor(
2901                                 SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aDesc );
2902 
2903         if( SwTransferable::_TestAllowedFormat( rData, SOT_FORMATSTR_ID_EMBED_SOURCE, nDest ))
2904             pDlg->Insert( SOT_FORMATSTR_ID_EMBED_SOURCE, aEmptyStr );
2905         if( SwTransferable::_TestAllowedFormat( rData, SOT_FORMATSTR_ID_LINK_SOURCE, nDest ))
2906             pDlg->Insert( SOT_FORMATSTR_ID_LINK_SOURCE, aEmptyStr );
2907     }
2908 
2909     if( SwTransferable::_TestAllowedFormat( rData, SOT_FORMATSTR_ID_LINK, nDest ))
2910         pDlg->Insert( SOT_FORMATSTR_ID_LINK, SW_RES(STR_DDEFORMAT) );
2911 
2912     for( sal_uInt16* pIds = aPasteSpecialIds; *pIds; ++pIds )
2913         if( SwTransferable::_TestAllowedFormat( rData, *pIds, nDest ))
2914             pDlg->Insert( *pIds, aEmptyStr );
2915 
2916     sal_uLong nFormat = pDlg->GetFormat( rData.GetTransferable() );
2917 
2918     if( nFormat )
2919         nRet = SwTransferable::PasteFormat( rSh, rData, nFormat );
2920 
2921     if ( nRet )
2922         rFormatUsed = nFormat;
2923 
2924     delete pDlg;
2925     return nRet;
2926 }
2927 
2928 
2929 void SwTransferable::FillClipFmtItem( const SwWrtShell& rSh,
2930                                 const TransferableDataHelper& rData,
2931                                 SvxClipboardFmtItem & rToFill )
2932 {
2933     sal_uInt16 nDest = SwTransferable::GetSotDestination( rSh );
2934 
2935     SwTransferable *pClipboard = GetSwTransferable( rData );
2936     if( pClipboard )
2937     {
2938         sal_uInt16 nResId;
2939         if( pClipboard->eBufferType & TRNSFR_DOCUMENT )
2940             nResId = STR_PRIVATETEXT;
2941         else if( pClipboard->eBufferType & TRNSFR_GRAPHIC )
2942             nResId = STR_PRIVATEGRAPHIC;
2943         else if( pClipboard->eBufferType == TRNSFR_OLE )
2944             nResId = STR_PRIVATEOLE;
2945         else
2946             nResId = 0;
2947 
2948         if( nResId )
2949             rToFill.AddClipbrdFormat( SOT_FORMATSTR_ID_EMBED_SOURCE,
2950                                         SW_RES( nResId ) );
2951     }
2952     else
2953     {
2954         TransferableObjectDescriptor aDesc;
2955         if( rData.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) )
2956             ((TransferableDataHelper&)rData).GetTransferableObjectDescriptor(
2957                                 SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aDesc );
2958 
2959         if( SwTransferable::_TestAllowedFormat( rData, SOT_FORMATSTR_ID_EMBED_SOURCE, nDest ))
2960             rToFill.AddClipbrdFormat( SOT_FORMATSTR_ID_EMBED_SOURCE,
2961                                             aDesc.maTypeName );
2962         if( SwTransferable::_TestAllowedFormat( rData, SOT_FORMATSTR_ID_LINK_SOURCE, nDest ))
2963             rToFill.AddClipbrdFormat( SOT_FORMATSTR_ID_LINK_SOURCE );
2964 
2965         SotFormatStringId nFormat;
2966         if ( rData.HasFormat(nFormat = SOT_FORMATSTR_ID_EMBED_SOURCE_OLE) || rData.HasFormat(nFormat = SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE) )
2967         {
2968             String sName,sSource;
2969             if ( SvPasteObjectHelper::GetEmbeddedName(rData,sName,sSource,nFormat) )
2970                 rToFill.AddClipbrdFormat( nFormat, sName );
2971         }
2972     }
2973 
2974     if( SwTransferable::_TestAllowedFormat( rData, SOT_FORMATSTR_ID_LINK, nDest ))
2975         rToFill.AddClipbrdFormat( SOT_FORMATSTR_ID_LINK, SW_RES(STR_DDEFORMAT) );
2976 
2977     for( sal_uInt16* pIds = aPasteSpecialIds; *pIds; ++pIds )
2978         if( SwTransferable::_TestAllowedFormat( rData, *pIds, nDest ))
2979             rToFill.AddClipbrdFormat( *pIds, aEmptyStr );
2980 }
2981 
2982 void SwTransferable::SetDataForDragAndDrop( const Point& rSttPos )
2983 {
2984     if(!pWrtShell)
2985         return;
2986     String sGrfNm;
2987     const int nSelection = pWrtShell->GetSelectionType();
2988     if( nsSelectionType::SEL_GRF == nSelection)
2989     {
2990         AddFormat( SOT_FORMATSTR_ID_SVXB );
2991         // --> OD 2005-02-09 #119353# - robust
2992         const Graphic* pGrf = pWrtShell->GetGraphic();
2993         if ( pGrf && pGrf->IsSupportedGraphic() )
2994         // <--
2995         {
2996             AddFormat( FORMAT_GDIMETAFILE );
2997             AddFormat( FORMAT_BITMAP );
2998         }
2999         eBufferType = TRNSFR_GRAPHIC;
3000         pWrtShell->GetGrfNms( &sGrfNm, 0 );
3001     }
3002     else if( nsSelectionType::SEL_OLE == nSelection )
3003     {
3004         AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
3005         PrepareOLE( aObjDesc );
3006         AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
3007         AddFormat( FORMAT_GDIMETAFILE );
3008         eBufferType = TRNSFR_OLE;
3009     }
3010     //Gibt es ueberhaupt etwas zum bereitstellen?
3011     else if ( pWrtShell->IsSelection() || pWrtShell->IsFrmSelected() ||
3012               pWrtShell->IsObjSelected() )
3013     {
3014         if( pWrtShell->IsObjSelected() )
3015             eBufferType = TRNSFR_DRAWING;
3016         else
3017         {
3018             eBufferType = TRNSFR_DOCUMENT;
3019             if( SwWrtShell::NO_WORD !=
3020                 pWrtShell->IntelligentCut( nSelection, sal_False ))
3021                 eBufferType = TransferBufferType( TRNSFR_DOCUMENT_WORD
3022                                                     | eBufferType);
3023         }
3024 
3025         if( nSelection & nsSelectionType::SEL_TBL_CELLS )
3026             eBufferType = (TransferBufferType)(TRNSFR_TABELLE | eBufferType);
3027 
3028         AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
3029 
3030         //RTF vor das Metafile von OLE stellen, weil mit weniger verlusten
3031         //behaftet.
3032         if( !pWrtShell->IsObjSelected() )
3033         {
3034             AddFormat( FORMAT_RTF );
3035             AddFormat( SOT_FORMATSTR_ID_HTML );
3036         }
3037         if( pWrtShell->IsSelection() )
3038             AddFormat( FORMAT_STRING );
3039 
3040         if( nSelection & ( nsSelectionType::SEL_DRW | nsSelectionType::SEL_DRW_FORM ))
3041         {
3042             AddFormat( SOT_FORMATSTR_ID_DRAWING );
3043             if ( nSelection & nsSelectionType::SEL_DRW )
3044             {
3045                 AddFormat( FORMAT_GDIMETAFILE );
3046                 AddFormat( FORMAT_BITMAP );
3047             }
3048             eBufferType = (TransferBufferType)( TRNSFR_GRAPHIC | eBufferType );
3049 
3050             pClpGraphic = new Graphic;
3051             if( !pWrtShell->GetDrawObjGraphic( FORMAT_GDIMETAFILE, *pClpGraphic ))
3052                 pOrigGrf = pClpGraphic;
3053             pClpBitmap = new Graphic;
3054             if( !pWrtShell->GetDrawObjGraphic( FORMAT_BITMAP, *pClpBitmap ))
3055                 pOrigGrf = pClpBitmap;
3056 
3057             // ist es ein URL-Button ?
3058             String sURL, sDesc;
3059             if( pWrtShell->GetURLFromButton( sURL, sDesc ) )
3060             {
3061                 AddFormat( FORMAT_STRING );
3062                 AddFormat( SOT_FORMATSTR_ID_SOLK );
3063                 AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK );
3064                 AddFormat( SOT_FORMATSTR_ID_FILECONTENT );
3065                 AddFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR );
3066                 AddFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR );
3067                 eBufferType = (TransferBufferType)( TRNSFR_INETFLD | eBufferType );
3068             }
3069         }
3070 
3071         //ObjectDescriptor wurde bereits aus der alten DocShell gefuellt.
3072         //Jetzt noch anpassen. Dadurch kann im GetData die erste Anfrage
3073         //auch noch mit delayed rendering beantwortet werden.
3074         aObjDesc.mbCanLink = sal_False;
3075         aObjDesc.maDragStartPos = rSttPos;
3076         aObjDesc.maSize = OutputDevice::LogicToLogic( Size( OLESIZE ),
3077                                                 MAP_TWIP, MAP_100TH_MM );
3078         PrepareOLE( aObjDesc );
3079         AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
3080     }
3081     else if( nSelection & nsSelectionType::SEL_TXT && !pWrtShell->HasMark() )
3082     {
3083         // ist nur ein Feld - Selektiert?
3084         SwContentAtPos aCntntAtPos( SwContentAtPos::SW_INETATTR );
3085         Point aPos( SwEditWin::GetDDStartPosX(), SwEditWin::GetDDStartPosY());
3086 
3087         if( pWrtShell->GetContentAtPos( aPos, aCntntAtPos ) )
3088         {
3089             AddFormat( FORMAT_STRING );
3090             AddFormat( SOT_FORMATSTR_ID_SOLK );
3091             AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK );
3092             AddFormat( SOT_FORMATSTR_ID_FILECONTENT );
3093             AddFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR );
3094             AddFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR );
3095             eBufferType = TRNSFR_INETFLD;
3096         }
3097     }
3098 
3099     if( pWrtShell->IsFrmSelected() )
3100     {
3101         SfxItemSet aSet( pWrtShell->GetAttrPool(), RES_URL, RES_URL );
3102         pWrtShell->GetFlyFrmAttr( aSet );
3103         const SwFmtURL& rURL = (SwFmtURL&)aSet.Get( RES_URL );
3104         if( rURL.GetMap() )
3105         {
3106             pImageMap = new ImageMap( *rURL.GetMap() );
3107             AddFormat( SOT_FORMATSTR_ID_SVIM );
3108         }
3109         else if( rURL.GetURL().Len() )
3110         {
3111             pTargetURL = new INetImage( sGrfNm, rURL.GetURL(),
3112                                         rURL.GetTargetFrameName(),
3113                                         aEmptyStr, Size() );
3114             AddFormat( SOT_FORMATSTR_ID_INET_IMAGE );
3115         }
3116     }
3117 }
3118 
3119 void SwTransferable::StartDrag( Window* pWin, const Point& rPos )
3120 {
3121     if(!pWrtShell)
3122         return;
3123     bOldIdle = pWrtShell->GetViewOptions()->IsIdle();
3124     bCleanUp = sal_True;
3125 
3126     ((SwViewOption *)pWrtShell->GetViewOptions())->SetIdle( sal_False );
3127 
3128     if( pWrtShell->IsSelFrmMode() )
3129         pWrtShell->ShowCrsr();
3130 
3131     SW_MOD()->pDragDrop = this;
3132 
3133     SetDataForDragAndDrop( rPos );
3134 
3135     sal_Int8 nDragOptions = DND_ACTION_COPYMOVE | DND_ACTION_LINK;
3136     SwDocShell* pDShell = pWrtShell->GetView().GetDocShell();
3137     if( ( pDShell && pDShell->IsReadOnly() ) || pWrtShell->HasReadonlySel() )
3138         nDragOptions &= ~DND_ACTION_MOVE;
3139 
3140     TransferableHelper::StartDrag( pWin, nDragOptions );
3141 }
3142 
3143 void SwTransferable::DragFinished( sal_Int8 nAction )
3144 {
3145     //Und noch die letzten Nacharbeiten damit alle Stati stimmen.
3146     if( DND_ACTION_MOVE == nAction  )
3147     {
3148         if( bCleanUp )
3149         {
3150             //Es wurde auserhalb des Writers gedroped. Wir muessen noch
3151             //loeschen.
3152 
3153             pWrtShell->StartAllAction();
3154             pWrtShell->StartUndo( UNDO_UI_DRAG_AND_MOVE );
3155             if ( pWrtShell->IsTableMode() )
3156                 pWrtShell->DeleteTblSel();
3157             else
3158             {
3159                 if ( !(pWrtShell->IsSelFrmMode() || pWrtShell->IsObjSelected()) )
3160                     //SmartCut, eines der Blanks mitnehmen.
3161                     pWrtShell->IntelligentCut( pWrtShell->GetSelectionType(), sal_True );
3162                 pWrtShell->DelRight();
3163             }
3164             pWrtShell->EndUndo( UNDO_UI_DRAG_AND_MOVE );
3165             pWrtShell->EndAllAction();
3166         }
3167         else
3168         {
3169             const int nSelection = pWrtShell->GetSelectionType();
3170             if( ( nsSelectionType::SEL_FRM | nsSelectionType::SEL_GRF |
3171                  nsSelectionType::SEL_OLE | nsSelectionType::SEL_DRW ) & nSelection )
3172             {
3173                 pWrtShell->EnterSelFrmMode();
3174             }
3175         }
3176     }
3177     pWrtShell->GetView().GetEditWin().DragFinished();
3178 
3179     if( pWrtShell->IsSelFrmMode() )
3180         pWrtShell->HideCrsr();
3181     else
3182         pWrtShell->ShowCrsr();
3183 //!!    else if( DND_ACTION_NONE != nAction )
3184 //!!        pWrtShell->ShowCrsr();
3185 //!!    else
3186 //!!    {
3187 //!!        //Muss wohl sein weil gescrollt wurde und ?...?
3188 //!!        pWrtShell->StartAction();
3189 //!!        pWrtShell->EndAction();
3190 //!!    }
3191 
3192     ((SwViewOption *)pWrtShell->GetViewOptions())->SetIdle( bOldIdle );
3193 }
3194 
3195 
3196 /*  */
3197 
3198 int SwTransferable::PrivatePaste( SwWrtShell& rShell )
3199 {
3200     // erst den SelectionType erfragen, dann Action-Klammerung !!!!
3201     // (sonst wird nicht in eine TabellenSelektion gepastet!!!)
3202     ASSERT( !rShell.ActionPend(), "Paste darf nie eine Actionklammerung haben" );
3203     if ( !pClpDocFac )
3204         return sal_False; // the return value of the SwFEShell::Paste also is sal_Bool!
3205 
3206     const int nSelection = rShell.GetSelectionType();
3207 
3208     // #111827#
3209     SwRewriter aRewriter;
3210 
3211     SwTrnsfrActionAndUndo aAction( &rShell, UNDO_PASTE_CLIPBOARD);
3212 
3213     bool bKillPaMs = false;
3214 
3215     //Selektierten Inhalt loeschen, nicht bei Tabellen-Selektion und
3216     //Tabelle im Clipboard
3217     if( rShell.HasSelection() && !( nSelection & nsSelectionType::SEL_TBL_CELLS))
3218     {
3219         bKillPaMs = true;
3220         rShell.SetRetainSelection( true );
3221         rShell.DelRight();
3222         // war ein Fly selektiert, so muss jetzt fuer eine gueltige
3223         // Cursor-Position gesorgt werden! (geparkter Cursor!)
3224         if( ( nsSelectionType::SEL_FRM | nsSelectionType::SEL_GRF |
3225             nsSelectionType::SEL_OLE | nsSelectionType::SEL_DRW |
3226             nsSelectionType::SEL_DRW_FORM ) & nSelection )
3227         {
3228             // den Cursor wieder positionieren
3229             Point aPt( rShell.GetCharRect().Pos() );
3230             rShell.SwCrsrShell::SetCrsr( aPt, sal_True );
3231         }
3232         rShell.SetRetainSelection( false );
3233     }
3234 
3235     sal_Bool bInWrd = sal_False, bEndWrd = sal_False, bSttWrd = sal_False,
3236          bSmart = 0 != (TRNSFR_DOCUMENT_WORD & eBufferType);
3237     if( bSmart )
3238     {
3239 // #108491# Why not for other Scripts? If TRNSFR_DOCUMENT_WORD is set, we have
3240 // a word in the buffer, word in this context means 'something with spaces at
3241 // beginning and end'. In this case we definitely want these spaces to be inserted
3242 // here.
3243 //      if( SCRIPTTYPE_LATIN != rShell.GetScriptType() )
3244 //          bSmart = sal_False;
3245 //      else
3246 //      {
3247             bInWrd = rShell.IsInWrd();
3248             bEndWrd = rShell.IsEndWrd();
3249             bSmart = bInWrd || bEndWrd;
3250             if( bSmart )
3251             {
3252                 bSttWrd = rShell.IsSttWrd();
3253                 if( bSmart && !bSttWrd && (bInWrd || bEndWrd) )
3254                     rShell.SwEditShell::Insert(' ');
3255             }
3256 //      }
3257     }
3258 
3259     int nRet = rShell.Paste( pClpDocFac->GetDoc() );
3260 
3261     if( bKillPaMs )
3262         rShell.KillPams();
3263 
3264     // Wenn Smart Paste dann Leerzeichen einfuegen
3265     if( nRet && bSmart && ((bInWrd && !bEndWrd )|| bSttWrd) )
3266         rShell.SwEditShell::Insert(' ');
3267 
3268     return nRet;
3269 }
3270 
3271 int SwTransferable::PrivateDrop( SwWrtShell& rSh, const Point& rDragPt,
3272                                 sal_Bool bMove, sal_Bool bIsXSelection )
3273 {
3274     int cWord    = 0;
3275     sal_Bool bInWrd  = sal_False;
3276     sal_Bool bEndWrd = sal_False;
3277     sal_Bool bSttWrd = sal_False;
3278     sal_Bool bSttPara= sal_False;
3279     sal_Bool bTblSel = sal_False;
3280     sal_Bool bFrmSel = sal_False;
3281 
3282     SwWrtShell& rSrcSh = *GetShell();
3283 
3284     rSh.UnSetVisCrsr();
3285 
3286     if( TRNSFR_INETFLD == eBufferType )
3287     {
3288         if( rSh.GetFmtFromObj( rDragPt ) )
3289         {
3290             INetBookmark aTmp;
3291             if( (TRNSFR_INETFLD & eBufferType) && pBkmk )
3292                 aTmp = *pBkmk;
3293 
3294             // Zielgrafik selektieren
3295             if( rSh.SelectObj( rDragPt ) )
3296             {
3297                 rSh.HideCrsr();
3298                 rSh.EnterSelFrmMode( &rDragPt );
3299                 bFrmDrag = sal_True;
3300             }
3301 
3302             const int nSelection = rSh.GetSelectionType();
3303 
3304             // Draw-Objekte erstmal noch nicht beruecksichtigen
3305             if( nsSelectionType::SEL_GRF & nSelection )
3306             {
3307                 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
3308                 rSh.GetFlyFrmAttr( aSet );
3309                 SwFmtURL aURL( (SwFmtURL&)aSet.Get( RES_URL ) );
3310                 aURL.SetURL( aTmp.GetURL(), sal_False );
3311                 aSet.Put( aURL );
3312                 rSh.SetFlyFrmAttr( aSet );
3313                 return 1;
3314             }
3315 
3316             if( nsSelectionType::SEL_DRW & nSelection )
3317             {
3318                 rSh.LeaveSelFrmMode();
3319                 rSh.UnSelectFrm();
3320                 rSh.ShowCrsr();
3321                 bFrmDrag = sal_False;
3322             }
3323         }
3324     }
3325 
3326     if( &rSh != &rSrcSh && (nsSelectionType::SEL_GRF & rSh.GetSelectionType()) &&
3327         TRNSFR_GRAPHIC == eBufferType )
3328     {
3329         // ReRead auf die Grafik
3330         String sGrfNm, sFltNm;
3331         rSrcSh.GetGrfNms( &sGrfNm, &sFltNm );
3332         rSh.ReRead( sGrfNm, sFltNm, rSrcSh.GetGraphic() );
3333         return 1;
3334     }
3335 
3336     //Nicht in Selektionen oder selektierten Rahmen
3337     if( rSh.ChgCurrPam( rDragPt ) ||
3338         ( rSh.IsSelFrmMode() && rSh.IsInsideSelectedObj( rDragPt )) )
3339         return 0;
3340 
3341     if( rSrcSh.IsTableMode() )
3342         bTblSel = sal_True;
3343     else if( rSrcSh.IsSelFrmMode() || rSrcSh.IsObjSelected() )
3344     {
3345         // keine positionsgeschuetzten Objecte verschieben!
3346         if( bMove && rSrcSh.IsSelObjProtected( FLYPROTECT_POS ) )
3347             return 0;
3348 
3349         bFrmSel = sal_True;
3350     }
3351 
3352     const int nSel = rSrcSh.GetSelectionType();
3353 
3354     SwUndoId eUndoId = bMove ? UNDO_UI_DRAG_AND_MOVE : UNDO_UI_DRAG_AND_COPY;
3355 
3356     // #111827#
3357     SwRewriter aRewriter;
3358 
3359     aRewriter.AddRule(UNDO_ARG1, rSrcSh.GetSelDescr());
3360 
3361     if(rSrcSh.GetDoc() != rSh.GetDoc())
3362         rSrcSh.StartUndo( eUndoId, &aRewriter );
3363     rSh.StartUndo( eUndoId, &aRewriter );
3364 
3365     rSh.StartAction();
3366     rSrcSh.StartAction();
3367 
3368     if( &rSrcSh != &rSh )
3369     {
3370         rSh.EnterStdMode();
3371         rSh.SwCrsrShell::SetCrsr( rDragPt, sal_True );
3372         cWord = rSrcSh.IntelligentCut( nSel, sal_False );
3373     }
3374     else if( !bTblSel && !bFrmSel )
3375     {
3376         if( !rSh.IsAddMode() )
3377         {
3378             // --> OD 2008-03-19 #i87233#
3379             if ( rSh.IsBlockMode() )
3380             {
3381                 // preserve order of cursors for block mode
3382                 rSh.GoPrevCrsr();
3383             }
3384             // <--
3385             rSh.SwCrsrShell::CreateCrsr();
3386         }
3387         rSh.SwCrsrShell::SetCrsr( rDragPt, sal_True, false );
3388         rSh.GoPrevCrsr();
3389         cWord = rSh.IntelligentCut( rSh.GetSelectionType(), sal_False );
3390         rSh.GoNextCrsr();
3391     }
3392 
3393     bInWrd  = rSh.IsInWrd();
3394     bEndWrd = rSh.IsEndWrd();
3395     bSttWrd = !bEndWrd && rSh.IsSttWrd();
3396     bSttPara= rSh.IsSttPara();
3397 
3398     Point aSttPt( SwEditWin::GetDDStartPosX(), SwEditWin::GetDDStartPosY() );
3399 
3400     //JP 05.03.96: INetFelder erstmal selektieren !
3401     if( TRNSFR_INETFLD == eBufferType )
3402     {
3403         if( &rSrcSh == &rSh )
3404         {
3405             rSh.GoPrevCrsr();
3406             rSh.SwCrsrShell::SetCrsr( aSttPt, sal_True );
3407             rSh.SelectTxtAttr( RES_TXTATR_INETFMT );
3408             if( rSh.ChgCurrPam( rDragPt ) )
3409             {
3410                 // nicht in sich selbst kopieren/verschieben
3411                 rSh.DestroyCrsr();
3412                 rSh.EndUndo();
3413                 rSh.EndAction();
3414                 rSh.EndAction();
3415                 return 0;
3416             }
3417             rSh.GoNextCrsr();
3418         }
3419         else
3420         {
3421             rSrcSh.SwCrsrShell::SetCrsr( aSttPt, sal_True );
3422             rSrcSh.SelectTxtAttr( RES_TXTATR_INETFMT );
3423         }
3424 
3425         // ist am Einfuege Punkt ein URL-Attribut? Dann das ersetzen,
3426         // also einfach eine Selektion aufspannen?
3427         rSh.DelINetAttrWithText();
3428         bDDINetAttr = sal_True;
3429     }
3430 
3431     if ( rSrcSh.IsSelFrmMode() )
3432     {
3433         //Hack: Spezialbehandlung austricksen
3434         aSttPt -= aSttPt - rSrcSh.GetObjRect().Pos();
3435     }
3436 
3437     sal_Bool bRet = rSrcSh.SwFEShell::Copy( &rSh, aSttPt, rDragPt, bMove,
3438                                             !bIsXSelection );
3439 
3440     if( !bIsXSelection )
3441     {
3442         rSrcSh.Push();
3443         if ( bRet && bMove && !bFrmSel )
3444         {
3445             if ( bTblSel )
3446             {
3447                 /* #109590# delete table contents not cells */
3448                 rSrcSh.Delete();
3449             }
3450             else
3451             {
3452                 //SmartCut, eines der Blank mitnehmen.
3453                 rSh.SwCrsrShell::DestroyCrsr();
3454                 if ( cWord == SwWrtShell::WORD_SPACE_BEFORE )
3455                     rSh.ExtendSelection( sal_False );
3456                 else if ( cWord == SwWrtShell::WORD_SPACE_AFTER )
3457                     rSh.ExtendSelection();
3458                 rSrcSh.DelRight();
3459             }
3460         }
3461         rSrcSh.KillPams();
3462         rSrcSh.Pop( sal_False );
3463 
3464         /* #109590# after dragging a table selection inside one shell
3465             set cursor to the drop position. */
3466         if( &rSh == &rSrcSh && ( bTblSel || rSh.IsBlockMode() ) )
3467         {
3468             rSrcSh.SwCrsrShell::SetCrsr(rDragPt);
3469             rSrcSh.GetSwCrsr()->SetMark();
3470         }
3471     }
3472 
3473     if( bRet && !bTblSel && !bFrmSel )
3474     {
3475         if( (bInWrd || bEndWrd) &&
3476             (cWord == SwWrtShell::WORD_SPACE_AFTER ||
3477                 cWord == SwWrtShell::WORD_SPACE_BEFORE) )
3478         {
3479             if ( bSttWrd || (bInWrd && !bEndWrd))
3480                 rSh.SwEditShell::Insert(' ', bIsXSelection);
3481             if ( !bSttWrd || (bInWrd && !bSttPara) )
3482             {
3483                 rSh.SwapPam();
3484                 if ( !bSttWrd )
3485                     rSh.SwEditShell::Insert(' ', bIsXSelection);
3486                 rSh.SwapPam();
3487             }
3488         }
3489 
3490         if( bIsXSelection )
3491         {
3492             if( &rSrcSh == &rSh && !rSh.IsAddMode() )
3493             {
3494                 rSh.SwCrsrShell::DestroyCrsr();
3495                 rSh.GoPrevCrsr();
3496             }
3497             else
3498             {
3499                 rSh.SwapPam();
3500                 rSh.SwCrsrShell::ClearMark();
3501             }
3502         }
3503         else
3504         {
3505             if( rSh.IsAddMode() )
3506                 rSh.SwCrsrShell::CreateCrsr();
3507             else
3508             {
3509                 // Selektionsmodus einschalten
3510                 rSh.SttSelect();
3511                 rSh.EndSelect();
3512             }
3513         }
3514     }
3515 
3516     if( bRet && bMove && bFrmSel )
3517         rSrcSh.LeaveSelFrmMode();
3518 
3519     if( rSrcSh.GetDoc() != rSh.GetDoc() )
3520         rSrcSh.EndUndo();
3521     rSh.EndUndo();
3522 
3523         // Shell in den richtigen Status versetzen
3524     if( &rSrcSh != &rSh && ( rSh.IsFrmSelected() || rSh.IsObjSelected() ))
3525         rSh.EnterSelFrmMode();
3526 
3527     rSrcSh.EndAction();
3528     rSh.EndAction();
3529     return 1;
3530 }
3531 
3532 // Interfaces for Selection
3533 void SwTransferable::CreateSelection( SwWrtShell& rSh,
3534                                       const ViewShell * _pCreatorView )
3535 {
3536     SwModule *pMod = SW_MOD();
3537     SwTransferable* pNew = new SwTransferable( rSh );
3538 
3539     /* #96392#*/
3540     pNew->pCreatorView = _pCreatorView;
3541 
3542     uno::Reference<
3543             datatransfer::XTransferable > xRef( pNew );
3544     pMod->pXSelection = pNew;
3545     pNew->CopyToSelection( rSh.GetWin() );
3546 }
3547 
3548 void SwTransferable::ClearSelection( SwWrtShell& rSh,
3549                                      const ViewShell * _pCreatorView)
3550 {
3551     SwModule *pMod = SW_MOD();
3552     if( pMod->pXSelection &&
3553         ((!pMod->pXSelection->pWrtShell) || (pMod->pXSelection->pWrtShell == &rSh)) &&
3554         /* #96392# */
3555         (!_pCreatorView || (pMod->pXSelection->pCreatorView == _pCreatorView)) )
3556     {
3557         TransferableHelper::ClearSelection( rSh.GetWin() );
3558     }
3559 }
3560 /* -----------------3/31/2003 11:46AM----------------
3561 
3562  --------------------------------------------------*/
3563 const Sequence< sal_Int8 >& SwTransferable::getUnoTunnelId()
3564 {
3565     static Sequence< sal_Int8 > aSeq;
3566     if( !aSeq.getLength() )
3567     {
3568         static osl::Mutex           aCreateMutex;
3569         osl::Guard< osl::Mutex >    aGuard( aCreateMutex );
3570         aSeq.realloc( 16 );
3571         rtl_createUuid( reinterpret_cast< sal_uInt8* >( aSeq.getArray() ), 0, sal_True );
3572     }
3573     return aSeq;
3574 }
3575 /* -----------------3/31/2003 11:46AM----------------
3576 
3577  --------------------------------------------------*/
3578 sal_Int64 SwTransferable::getSomething( const Sequence< sal_Int8 >& rId ) throw( RuntimeException )
3579 {
3580     sal_Int64 nRet;
3581     if( ( rId.getLength() == 16 ) &&
3582         ( 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
3583     {
3584         nRet = sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ) );
3585     }
3586     else
3587         nRet = TransferableHelper::getSomething(rId);
3588     return nRet;
3589 }
3590 
3591 SwTransferable* SwTransferable::GetSwTransferable( const TransferableDataHelper& rData )
3592 {
3593     SwTransferable* pSwTransferable = NULL;
3594 
3595     uno::Reference<XUnoTunnel> xTunnel( rData.GetTransferable(), UNO_QUERY );
3596     if ( xTunnel.is() )
3597     {
3598         sal_Int64 nHandle = xTunnel->getSomething( getUnoTunnelId() );
3599         if ( nHandle )
3600             pSwTransferable = (SwTransferable*) (sal_IntPtr) nHandle;
3601     }
3602 
3603     return pSwTransferable;
3604 
3605 }
3606 
3607 /*  */
3608 
3609 // -----------------------------------------------------------------------
3610 
3611 SwTrnsfrDdeLink::SwTrnsfrDdeLink( SwTransferable& rTrans, SwWrtShell& rSh )
3612     : rTrnsfr( rTrans ), pDocShell( 0 ),
3613     bDelBookmrk( sal_False ), bInDisconnect( sal_False )
3614 {
3615     // hier kommen wir nur bei Tabellen- oder Text-Selection an
3616     const int nSelection = rSh.GetSelectionType();
3617     if( nsSelectionType::SEL_TBL_CELLS & nSelection )
3618     {
3619         SwFrmFmt* pFmt = rSh.GetTableFmt();
3620         if( pFmt )
3621             sName = pFmt->GetName();
3622     }
3623     else
3624     {
3625         // creating a temp. bookmark without undo
3626         sal_Bool bUndo = rSh.DoesUndo();
3627         rSh.DoUndo( sal_False );
3628         sal_Bool bIsModified = rSh.IsModified();
3629 
3630         ::sw::mark::IMark* pMark = rSh.SetBookmark(
3631             KeyCode(),
3632             ::rtl::OUString(),
3633             ::rtl::OUString(),
3634             IDocumentMarkAccess::DDE_BOOKMARK);
3635         if(pMark)
3636         {
3637             sName = pMark->GetName();
3638             bDelBookmrk = sal_True;
3639             if( !bIsModified )
3640                 rSh.ResetModified();
3641         }
3642         else
3643             sName.Erase();
3644         rSh.DoUndo( bUndo );
3645     }
3646 
3647     if( sName.Len() &&
3648         0 != ( pDocShell = rSh.GetDoc()->GetDocShell() ) )
3649     {
3650         // dann erzeugen wir uns mal unseren "Server" und connecten uns
3651         // zu diesem
3652         refObj = pDocShell->DdeCreateLinkSource( sName );
3653         if( refObj.Is() )
3654         {
3655             refObj->AddConnectAdvise( this );
3656             refObj->AddDataAdvise( this,
3657 //                          SotExchange::GetFormatMimeType( FORMAT_RTF ),
3658                             aEmptyStr,
3659                             ADVISEMODE_NODATA | ADVISEMODE_ONLYONCE );
3660             nOldTimeOut = refObj->GetUpdateTimeout();
3661             refObj->SetUpdateTimeout( 0 );
3662         }
3663     }
3664 }
3665 
3666 // -----------------------------------------------------------------------
3667 
3668 SwTrnsfrDdeLink::~SwTrnsfrDdeLink()
3669 {
3670     if( refObj.Is() )
3671         Disconnect( sal_True );
3672 }
3673 
3674 // -----------------------------------------------------------------------
3675 
3676 void SwTrnsfrDdeLink::DataChanged( const String& ,
3677                                     const uno::Any& )
3678 {
3679     // tja das wars dann mit dem Link
3680     if( !bInDisconnect )
3681     {
3682         if( FindDocShell() && pDocShell->GetView() )
3683             rTrnsfr.RemoveDDELinkFormat( pDocShell->GetView()->GetEditWin() );
3684         Disconnect( sal_False );
3685     }
3686 }
3687 
3688 // -----------------------------------------------------------------------
3689 
3690 sal_Bool SwTrnsfrDdeLink::WriteData( SvStream& rStrm )
3691 {
3692     if( !refObj.Is() || !FindDocShell() )
3693         return sal_False;
3694 
3695     rtl_TextEncoding eEncoding = DDE_TXT_ENCODING;
3696     const ByteString aAppNm( GetpApp()->GetAppName(), eEncoding );
3697     const ByteString aTopic( pDocShell->GetTitle( SFX_TITLE_FULLNAME ),
3698                             eEncoding );
3699     const ByteString aName( sName, eEncoding );
3700 
3701     sal_Char* pMem = new char[ aAppNm.Len() + aTopic.Len() + aName.Len() + 4 ];
3702 
3703     xub_StrLen nLen = aAppNm.Len();
3704     memcpy( pMem, aAppNm.GetBuffer(), nLen );
3705     pMem[ nLen++ ] = 0;
3706     memcpy( pMem + nLen, aTopic.GetBuffer(), aTopic.Len() );
3707     nLen = nLen + aTopic.Len();
3708     pMem[ nLen++ ] = 0;
3709     memcpy( pMem + nLen, aName.GetBuffer(), aName.Len() );
3710     nLen = nLen + aName.Len();
3711     pMem[ nLen++ ] = 0;
3712     pMem[ nLen++ ] = 0;
3713 
3714     rStrm.Write( pMem, nLen );
3715     delete[] pMem;
3716 
3717     //if( bDelBookmrk )
3718     //{
3719     //  // er wird das erstemal abgeholt, also ins Undo mitaufnehmen
3720     //  // aber wie??
3721     //}
3722 
3723     IDocumentMarkAccess* const pMarkAccess = pDocShell->GetDoc()->getIDocumentMarkAccess();
3724     IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->findMark(sName);
3725     if(ppMark != pMarkAccess->getMarksEnd()
3726         && IDocumentMarkAccess::GetType(**ppMark) != IDocumentMarkAccess::BOOKMARK)
3727     {
3728         // the mark is still a DdeBookmark
3729         // we replace it with a Bookmark, so it will get saved etc.
3730         ::sw::mark::IMark* const pMark = ppMark->get();
3731         SwServerObject* const pServerObject = dynamic_cast<SwServerObject *>(&refObj);
3732 
3733         // collecting state of old mark
3734         SwPaM aPaM(pMark->GetMarkStart());
3735         *aPaM.GetPoint() = pMark->GetMarkStart();
3736         if(pMark->IsExpanded())
3737         {
3738             aPaM.SetMark();
3739             *aPaM.GetMark() = pMark->GetMarkEnd();
3740         }
3741         ::rtl::OUString sMarkName = pMark->GetName();
3742 
3743         // remove mark
3744         pServerObject->SetNoServer(); // this removes the connection between SwServerObject and mark
3745         // N.B. ppMark was not loaded from file and cannot have xml:id
3746         pMarkAccess->deleteMark(ppMark);
3747 
3748         // recreate as Bookmark
3749         ::sw::mark::IMark* const pNewMark = pMarkAccess->makeMark(
3750             aPaM,
3751             sMarkName,
3752             IDocumentMarkAccess::BOOKMARK);
3753         pServerObject->SetDdeBookmark(*pNewMark);
3754     }
3755 
3756     bDelBookmrk = false;
3757     return true;
3758 }
3759 
3760 // -----------------------------------------------------------------------
3761 
3762 void SwTrnsfrDdeLink::Disconnect( sal_Bool bRemoveDataAdvise )
3763 {
3764     //JP 29.01.96 Bug 24432:
3765     //      kein DataChanged mehr entgegen nehmen, wenn man
3766     //      sich schon im Disconnet befindet!
3767     //      (DTOR vom Bookmark verschickt einen DataChanged!)
3768     sal_Bool bOldDisconnect = bInDisconnect;
3769     bInDisconnect = sal_True;
3770 
3771     // den nicht verwendeten Bookmark wieder zerstoeren (ohne Undo!)?
3772     if( bDelBookmrk && refObj.Is() && FindDocShell() )
3773     {
3774         SwDoc* pDoc = pDocShell->GetDoc();
3775         ::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
3776 
3777         // --> OD, CD, OS 2005-11-25 #i58448#
3778         Link aSavedOle2Link( pDoc->GetOle2Link() );
3779         pDoc->SetOle2Link( Link() );
3780         // <--
3781         sal_Bool bIsModified = pDoc->IsModified();
3782 
3783         IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
3784         pMarkAccess->deleteMark(pMarkAccess->findMark(sName));
3785 
3786         if( !bIsModified )
3787             pDoc->ResetModified();
3788         // --> OD, CD, OS 2005-11-25 #i58448#
3789         pDoc->SetOle2Link( aSavedOle2Link );
3790         // <--
3791 
3792         bDelBookmrk = sal_False;
3793     }
3794 
3795     if( refObj.Is() )
3796     {
3797         refObj->SetUpdateTimeout( nOldTimeOut );
3798         refObj->RemoveConnectAdvise( this );
3799         if( bRemoveDataAdvise )
3800             // in einem DataChanged darf das SelectionObject NIE geloescht
3801             // werden; wird schon von der Basisklasse erledigt
3802             // (ADVISEMODE_ONLYONCE!!!!)
3803             // Im normalen Disconnet aber schon!
3804             refObj->RemoveAllDataAdvise( this );
3805         refObj.Clear();
3806     }
3807     bInDisconnect = bOldDisconnect;
3808 }
3809 
3810 // -----------------------------------------------------------------------
3811 
3812 sal_Bool SwTrnsfrDdeLink::FindDocShell()
3813 {
3814     TypeId aType( TYPE( SwDocShell ) );
3815     SfxObjectShell* pTmpSh = SfxObjectShell::GetFirst( &aType );
3816     while( pTmpSh )
3817     {
3818         if( pTmpSh == pDocShell )       // die wollen wir haben
3819         {
3820             if( pDocShell->GetDoc() )
3821                 return sal_True;
3822             break;      // das Doc ist nicht mehr vorhanden, also raus!
3823         }
3824         pTmpSh = SfxObjectShell::GetNext( *pTmpSh, &aType );
3825     }
3826 
3827     pDocShell = 0;
3828     return sal_False;
3829 }
3830 
3831 // -----------------------------------------------------------------------
3832 
3833 void SwTrnsfrDdeLink::Closed()
3834 {
3835     if( !bInDisconnect && refObj.Is() )
3836     {
3837         refObj->RemoveAllDataAdvise( this );
3838         refObj->RemoveConnectAdvise( this );
3839         refObj.Clear();
3840     }
3841 }
3842