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