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