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