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