merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / dochdl / swdtflvr.cxx
blobe991938aade42d99305d52b852abbe6f6b9af5ec
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: swdtflvr.cxx,v $
10 * $Revision: 1.120 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #ifdef PRECOMPILED
34 #include "ui_pch.hxx"
35 #endif
38 #include <com/sun/star/embed/XVisualObject.hpp>
39 #include <com/sun/star/embed/XTransactedObject.hpp>
40 #include <com/sun/star/embed/Aspects.hpp>
41 #include <com/sun/star/embed/XEmbedObjectClipboardCreator.hpp>
42 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
44 #include <svtools/embedtransfer.hxx>
45 #include <svtools/insdlg.hxx>
46 #include <unotools/tempfile.hxx>
47 #include <comphelper/storagehelper.hxx>
48 #include <comphelper/processfactory.hxx>
49 #include <unotools/ucbstreamhelper.hxx>
50 #include <sot/filelist.hxx>
51 #include <svx/svxdlg.hxx>
52 #include <toolkit/helper/vclunohelper.hxx>
53 #include <osl/endian.h>
54 #include <sfx2/linkmgr.hxx>
55 #include <tools/urlobj.hxx>
56 #ifndef _WRKWIN_HXX
57 #include <vcl/wrkwin.hxx>
58 #endif
59 #ifndef _MSGBOX_HXX
60 #include <vcl/msgbox.hxx>
61 #endif
62 #include <sfx2/dispatch.hxx>
63 #include <svtools/stritem.hxx>
64 #include <svtools/imap.hxx>
65 #include <sot/storage.hxx>
66 #ifndef _GRAPH_HXX
67 #include <vcl/graph.hxx>
68 #endif
69 #include <svtools/urihelper.hxx>
70 #include <svx/svdmodel.hxx>
71 #include <svx/xexch.hxx>
72 #include <svx/xmlexchg.hxx>
73 #include <svx/dbaexchange.hxx>
74 #include <svx/clipfmtitem.hxx>
75 #include <sfx2/mieclip.hxx>
76 #include <svx/svdetc.hxx>
77 #include <svx/xoutbmp.hxx>
78 #include <svtools/urlbmk.hxx>
79 #include <svtools/htmlout.hxx>
80 #include <svx/hlnkitem.hxx>
81 #include <svtools/inetimg.hxx>
82 #include <svx/paperinf.hxx>
83 #include <svx/fmview.hxx>
84 #include <svx/impgrf.hxx>
85 #include <svx/scripttypeitem.hxx>
86 #include <sfx2/docfilt.hxx>
87 #include <svtools/imapobj.hxx>
88 #include <sfx2/docfile.hxx>
89 #include <unotools/transliterationwrapper.hxx>
90 #include <unotools/streamwrap.hxx>
92 #include <svx/unomodel.hxx>
93 #include <fmturl.hxx>
94 #include <fmtinfmt.hxx>
95 #include <fmtfsize.hxx>
96 #include <swdtflvr.hxx>
97 #include <shellio.hxx>
98 #include <ddefld.hxx>
99 #include <doc.hxx>
100 #include <pagedesc.hxx>
101 #include <IMark.hxx>
102 #include <docary.hxx>
103 #include <section.hxx>
104 #include <ndtxt.hxx>
105 #include <edtwin.hxx>
106 #include <navicont.hxx>
107 #include <swcont.hxx>
108 #include <wrtsh.hxx>
109 #include <swmodule.hxx>
110 #ifndef _VIEW_HXX
111 #include <view.hxx>
112 #endif
113 #ifndef _DOCSH_HXX
114 #include <docsh.hxx>
115 #endif
116 #ifndef _WDOCSH_HXX
117 #include <wdocsh.hxx>
118 #endif
119 #include <fldbas.hxx> //DDE
120 #include <swundo.hxx> // fuer Undo-Ids
121 #include <pam.hxx>
122 #include <ndole.hxx>
123 #include <swwait.hxx>
124 #include <viewopt.hxx>
125 #include <swunodef.hxx>
126 #include <vcl/sound.hxx>
127 #include <swerror.h>
128 #include <SwCapObjType.hxx>
129 #ifndef _CMDID_H
130 #include <cmdid.h>
131 #endif
132 #ifndef _DOCHDL_HRC
133 #include <dochdl.hrc>
134 #endif
135 #ifndef _COMCORE_HRC
136 #include <comcore.hrc> // #111827#
137 #endif
138 #include <sot/stg.hxx>
140 // #108584#
141 #include <svx/svditer.hxx>
143 // #108584#
144 #include <svx/eeitem.hxx>
146 // #108584#
147 #include <svx/fhgtitem.hxx>
149 // #108584#
150 #include <svx/svdpage.hxx>
151 #include <avmedia/mediawindow.hxx>
153 // #109590#
154 #include <swcrsr.hxx>
155 #include <SwRewriter.hxx>
156 #include <undobj.hxx>
157 #ifndef _GLOBALS_HRC
158 #include <globals.hrc>
159 #endif
160 #include <vos/mutex.hxx>
161 #include <vcl/svapp.hxx>
162 #include <swserv.hxx>
164 extern BOOL bFrmDrag;
165 extern BOOL bDDINetAttr;
166 extern BOOL bExecuteDrag;
169 #define OLESIZE 11905 - 2 * lMinBorder, 6 * MM50
171 #define SWTRANSFER_OBJECTTYPE_DRAWMODEL 0x00000001
172 #define SWTRANSFER_OBJECTTYPE_HTML 0x00000002
173 #define SWTRANSFER_OBJECTTYPE_RTF 0x00000004
174 #define SWTRANSFER_OBJECTTYPE_STRING 0x00000008
175 #define SWTRANSFER_OBJECTTYPE_SWOLE 0x00000010
176 #define SWTRANSFER_OBJECTTYPE_DDE 0x00000020
178 #define SWTRANSFER_GRAPHIC_INSERTED 0x00000040
180 using namespace ::svx;
181 using ::rtl::OUString;
182 using namespace ::com::sun::star;
183 using namespace ::com::sun::star::uno;
184 using namespace ::com::sun::star::datatransfer;
185 using namespace nsTransferBufferType;
187 #define DDE_TXT_ENCODING gsl_getSystemTextEncoding()
189 //---------------------------------------------
190 // this struct conforms to the Microsoft
191 // OBJECTDESCRIPTOR -> see oleidl.h
192 // (MS platform sdk)
193 //---------------------------------------------
195 struct OleObjectDescriptor
197 sal_uInt32 cbSize;
198 ClsId clsid;
199 sal_uInt32 dwDrawAspect;
200 Size sizel;
201 Point pointl;
202 sal_uInt32 dwStatus;
203 sal_uInt32 dwFullUserTypeName;
204 sal_uInt32 dwSrcOfCopy;
207 class SwTrnsfrDdeLink : public ::sfx2::SvBaseLink
209 String sName;
210 ::sfx2::SvLinkSourceRef refObj;
211 SwTransferable& rTrnsfr;
212 SwDocShell* pDocShell;
213 ULONG nOldTimeOut;
214 BOOL bDelBookmrk : 1;
215 BOOL bInDisconnect : 1;
217 BOOL FindDocShell();
219 using sfx2::SvBaseLink::Disconnect;
221 protected:
222 virtual ~SwTrnsfrDdeLink();
224 public:
225 SwTrnsfrDdeLink( SwTransferable& rTrans, SwWrtShell& rSh );
227 virtual void DataChanged( const String& rMimeType,
228 const uno::Any & rValue );
229 virtual void Closed();
231 BOOL WriteData( SvStream& rStrm );
233 void Disconnect( BOOL bRemoveDataAdvise );
236 // helper class for Action and Undo enclosing
237 class SwTrnsfrActionAndUndo
239 SwWrtShell *pSh;
240 SwUndoId eUndoId;
241 public:
242 SwTrnsfrActionAndUndo( SwWrtShell *pS, SwUndoId nId,
243 const SwRewriter * pRewriter = 0,
244 BOOL bDelSel = FALSE)
245 : pSh( pS ), eUndoId( nId )
247 pSh->StartUndo( eUndoId, pRewriter );
248 if( bDelSel )
249 pSh->DelRight();
250 pSh->StartAllAction();
252 ~SwTrnsfrActionAndUndo()
254 pSh->EndUndo( eUndoId );
255 pSh->EndAllAction();
260 // -----------------------------------------------------------------------
262 SwTransferable::SwTransferable( SwWrtShell& rSh )
263 : pWrtShell( &rSh ),
264 pCreatorView( 0 ),
265 pClpDocFac( 0 ),
266 pClpGraphic( 0 ),
267 pClpBitmap( 0 ),
268 pOrigGrf( 0 ),
269 pBkmk( 0 ),
270 pImageMap( 0 ),
271 pTargetURL( 0 ),
272 eBufferType( TRNSFR_NONE )
274 rSh.GetView().AddTransferable(*this);
275 SwDocShell* pDShell = rSh.GetDoc()->GetDocShell();
276 if( pDShell )
278 pDShell->FillTransferableObjectDescriptor( aObjDesc );
279 if( pDShell->GetMedium() )
281 const INetURLObject& rURLObj = pDShell->GetMedium()->GetURLObject();
282 aObjDesc.maDisplayName = URIHelper::removePassword(
283 rURLObj.GetMainURL( INetURLObject::NO_DECODE ),
284 INetURLObject::WAS_ENCODED,
285 INetURLObject::DECODE_UNAMBIGUOUS );
288 PrepareOLE( aObjDesc );
292 // -----------------------------------------------------------------------
294 SwTransferable::~SwTransferable()
296 Application::GetSolarMutex().acquire();
298 // der DDELink braucht noch die WrtShell!
299 if( refDdeLink.Is() )
301 ((SwTrnsfrDdeLink*)&refDdeLink)->Disconnect( TRUE );
302 refDdeLink.Clear();
305 pWrtShell = 0;
307 // dvo 2002-05-30, #99239#: release reference to the document so that
308 // aDocShellRef will delete it (if aDocShellRef is set). Otherwise, the OLE
309 // nodes keep references to their sub-storage when the storage is already
310 // dead.
311 delete pClpDocFac;
313 //JP 22.04.95: erst schliessen, dann kann die Ref. auch gecleared werden,
314 // so das die DocShell auch tatsaechlich geloescht wird!
315 if( aDocShellRef.Is() )
317 SfxObjectShell * pObj = aDocShellRef;
318 SwDocShell* pDocSh = (SwDocShell*)pObj;
319 pDocSh->DoClose();
321 aDocShellRef.Clear();
323 SwModule* pMod = SW_MOD();
324 if(pMod)
326 if ( pMod->pClipboard == this )
327 pMod->pClipboard = 0;
328 else if ( pMod->pDragDrop == this )
329 pMod->pDragDrop = 0;
330 else if ( pMod->pXSelection == this )
331 pMod->pXSelection = 0;
334 delete pClpGraphic;
335 delete pClpBitmap;
336 delete pImageMap;
337 delete pTargetURL;
338 delete pBkmk;
341 eBufferType = TRNSFR_NONE;
343 Application::GetSolarMutex().release();
346 // -----------------------------------------------------------------------
348 void SwTransferable::ObjectReleased()
350 SwModule *pMod = SW_MOD();
351 if( this == pMod->pClipboard )
352 pMod->pClipboard = 0;
353 else if( this == pMod->pDragDrop )
354 pMod->pDragDrop = 0;
355 else if( this == pMod->pXSelection )
356 pMod->pXSelection = 0;
359 // -----------------------------------------------------------------------
361 void SwTransferable::AddSupportedFormats()
363 // only need if we are the current XSelection Object
364 SwModule *pMod = SW_MOD();
365 if( this == pMod->pXSelection )
367 SetDataForDragAndDrop( Point( 0,0) );
371 // -----------------------------------------------------------------------
373 void SwTransferable::InitOle( SfxObjectShell* pDoc, SwDoc& rDoc )
375 //OleVisArea einstellen. Linke obere Ecke der Seite und Groesse
376 //der RealSize in Twips.
377 const Size aSz( OLESIZE );
378 SwRect aVis( Point( DOCUMENTBORDER, DOCUMENTBORDER ), aSz );
379 pDoc->SetVisArea( aVis.SVRect() );
380 rDoc.set(IDocumentSettingAccess::BROWSE_MODE, true );
383 // -----------------------------------------------------------------------
385 uno::Reference < embed::XEmbeddedObject > SwTransferable::FindOLEObj( sal_Int64& nAspect ) const
387 uno::Reference < embed::XEmbeddedObject > xObj;
388 if( pClpDocFac )
390 SwClientIter aIter( *(SwModify*)pClpDocFac->GetDoc()->
391 GetDfltGrfFmtColl() );
392 for( SwCntntNode* pNd = (SwCntntNode*)aIter.First( TYPE( SwCntntNode ) );
393 pNd; pNd = (SwCntntNode*)aIter.Next() )
394 if( ND_OLENODE == pNd->GetNodeType() )
396 xObj = ((SwOLENode*)pNd)->GetOLEObj().GetOleRef();
397 nAspect = ((SwOLENode*)pNd)->GetAspect();
398 break;
401 return xObj;
404 // -----------------------------------------------------------------------
406 Graphic* SwTransferable::FindOLEReplacementGraphic() const
408 if( pClpDocFac )
410 SwClientIter aIter( *(SwModify*)pClpDocFac->GetDoc()->
411 GetDfltGrfFmtColl() );
412 for( SwCntntNode* pNd = (SwCntntNode*)aIter.First( TYPE( SwCntntNode ) );
413 pNd; pNd = (SwCntntNode*)aIter.Next() )
414 if( ND_OLENODE == pNd->GetNodeType() )
416 return ((SwOLENode*)pNd)->GetGraphic();
420 return NULL;
424 // -----------------------------------------------------------------------
426 void SwTransferable::RemoveDDELinkFormat( const Window& rWin )
428 RemoveFormat( SOT_FORMATSTR_ID_LINK );
429 CopyToClipboard( (Window*)&rWin );
432 // -----------------------------------------------------------------------
434 sal_Bool SwTransferable::GetData( const DATA_FLAVOR& rFlavor )
436 sal_uInt32 nFormat = SotExchange::GetFormat( rFlavor );
438 // we can only fullfil the request if
439 // 1) we have data for this format
440 // 2) we have either a clipboard document (pClpDocFac), or
441 // we have a SwWrtShell (so we can generate a new clipboard document)
442 if( !HasFormat( nFormat ) || ( pClpDocFac == NULL && pWrtShell == NULL ) )
443 return sal_False;
445 if( !pClpDocFac )
447 SelectionType nSelectionType = pWrtShell->GetSelectionType();
449 // SEL_GRF kommt vom ContentType der editsh
450 if( (nsSelectionType::SEL_GRF | nsSelectionType::SEL_DRW_FORM) & nSelectionType )
452 pClpGraphic = new Graphic;
453 if( !pWrtShell->GetDrawObjGraphic( FORMAT_GDIMETAFILE, *pClpGraphic ))
454 pOrigGrf = pClpGraphic;
455 pClpBitmap = new Graphic;
456 if( !pWrtShell->GetDrawObjGraphic( FORMAT_BITMAP, *pClpBitmap ))
457 pOrigGrf = pClpBitmap;
459 // ist es ein URL-Button ?
460 String sURL, sDesc;
461 if( pWrtShell->GetURLFromButton( sURL, sDesc ) )
463 pBkmk = new INetBookmark( sURL, sDesc );
464 eBufferType = TRNSFR_INETFLD;
468 pClpDocFac = new SwDocFac;
469 SwDoc* pTmpDoc = pClpDocFac->GetDoc();
471 pTmpDoc->SetRefForDocShell( boost::addressof(aDocShellRef) );
472 pTmpDoc->LockExpFlds(); // nie die Felder updaten - Text so belassen
473 pWrtShell->Copy( pTmpDoc );
475 // es wurde in der CORE eine neu angelegt (OLE-Objekte kopiert!)
476 if( aDocShellRef.Is() )
477 SwTransferable::InitOle( aDocShellRef, *pTmpDoc );
478 pTmpDoc->SetRefForDocShell( 0 );
480 if( nSelectionType & nsSelectionType::SEL_TXT && !pWrtShell->HasMark() )
482 SwContentAtPos aCntntAtPos( SwContentAtPos::SW_INETATTR );
484 Point aPos( SwEditWin::GetDDStartPosX(), SwEditWin::GetDDStartPosY());
486 BOOL bSelect = bExecuteDrag &&
487 pWrtShell->GetView().GetDocShell() &&
488 !pWrtShell->GetView().GetDocShell()->IsReadOnly();
489 if( pWrtShell->GetContentAtPos( aPos, aCntntAtPos, bSelect ) )
491 pBkmk = new INetBookmark(
492 ((SwFmtINetFmt*)aCntntAtPos.aFnd.pAttr)->GetValue(),
493 aCntntAtPos.sStr );
494 eBufferType = TRNSFR_INETFLD;
495 if( bSelect )
496 pWrtShell->SelectTxtAttr( RES_TXTATR_INETFMT );
499 if( pWrtShell->IsFrmSelected() )
501 SfxItemSet aSet( pWrtShell->GetAttrPool(), RES_URL, RES_URL );
502 pWrtShell->GetFlyFrmAttr( aSet );
503 const SwFmtURL& rURL = (SwFmtURL&)aSet.Get( RES_URL );
504 if( rURL.GetMap() )
505 pImageMap = new ImageMap( *rURL.GetMap() );
506 else if( rURL.GetURL().Len() )
507 pTargetURL = new INetImage( aEmptyStr, rURL.GetURL(),
508 rURL.GetTargetFrameName(),
509 aEmptyStr, Size() );
513 sal_Bool bOK = sal_False;
514 if( TRNSFR_OLE == eBufferType )
516 //TODO/MBA: testing - is this the "single OLE object" case?!
517 // aus dem ClipDoc das OLE-Object besorgen und von dem die Daten
518 // besorgen.
519 sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT; // will be set in the next statement
520 uno::Reference < embed::XEmbeddedObject > xObj = FindOLEObj( nAspect );
521 Graphic* pOLEGraph = FindOLEReplacementGraphic();
522 if( xObj.is() )
524 TransferableDataHelper aD( new SvEmbedTransferHelper( xObj, pOLEGraph, nAspect ) );
525 uno::Any aAny( aD.GetAny( rFlavor ));
526 if( aAny.hasValue() )
527 bOK = SetAny( aAny, rFlavor );
530 // the following solution will be used in the case when the object can not generate the image
531 // TODO/LATER: in future the transferhelper must probably be created based on object and the replacement stream
532 if ( nFormat == SOT_FORMAT_GDIMETAFILE )
534 pOLEGraph = FindOLEReplacementGraphic();
535 if ( pOLEGraph )
536 bOK = SetGDIMetaFile( pOLEGraph->GetGDIMetaFile(), rFlavor );
539 else
541 switch( nFormat )
543 case SOT_FORMATSTR_ID_LINK:
544 if( refDdeLink.Is() )
545 bOK = SetObject( &refDdeLink,
546 SWTRANSFER_OBJECTTYPE_DDE, rFlavor );
547 break;
549 case SOT_FORMATSTR_ID_OBJECTDESCRIPTOR:
550 case SOT_FORMATSTR_ID_LINKSRCDESCRIPTOR:
551 bOK = SetTransferableObjectDescriptor( aObjDesc, rFlavor );
552 break;
554 case SOT_FORMATSTR_ID_DRAWING:
556 SwDoc *pDoc = pClpDocFac->GetDoc();
557 ASSERT( pDoc, "Document not found" );
558 bOK = SetObject( pDoc->GetDrawModel(),
559 SWTRANSFER_OBJECTTYPE_DRAWMODEL, rFlavor );
561 break;
563 case SOT_FORMAT_STRING:
565 SwDoc* pDoc = pClpDocFac->GetDoc();
566 ASSERT( pDoc, "Document not found" );
567 pDoc->SetClipBoard( true );
568 bOK = SetObject( pDoc,
569 SWTRANSFER_OBJECTTYPE_STRING, rFlavor );
571 break;
572 case SOT_FORMAT_RTF:
573 bOK = SetObject( pClpDocFac->GetDoc(),
574 SWTRANSFER_OBJECTTYPE_RTF, rFlavor );
575 break;
577 case SOT_FORMATSTR_ID_HTML:
578 bOK = SetObject( pClpDocFac->GetDoc(),
579 SWTRANSFER_OBJECTTYPE_HTML, rFlavor );
580 break;
582 case SOT_FORMATSTR_ID_SVXB:
583 if( eBufferType & TRNSFR_GRAPHIC && pOrigGrf )
584 bOK = SetGraphic( *pOrigGrf, rFlavor );
585 break;
587 case SOT_FORMAT_GDIMETAFILE:
588 if( eBufferType & TRNSFR_GRAPHIC )
589 bOK = SetGDIMetaFile( pClpGraphic->GetGDIMetaFile(), rFlavor );
590 break;
591 case SOT_FORMAT_BITMAP:
592 // #126398# Neither pClpBitmap nor pClpGraphic are necessarily set
593 if( (eBufferType & TRNSFR_GRAPHIC) && (pClpBitmap != 0 || pClpGraphic != 0))
594 bOK = SetBitmap( (pClpBitmap ? pClpBitmap
595 : pClpGraphic)->GetBitmap(),
596 rFlavor );
597 break;
599 case SOT_FORMATSTR_ID_SVIM:
600 if( pImageMap )
601 bOK = SetImageMap( *pImageMap, rFlavor );
602 break;
604 case SOT_FORMATSTR_ID_INET_IMAGE:
605 if( pTargetURL )
606 bOK = SetINetImage( *pTargetURL, rFlavor );
607 break;
609 case SOT_FORMATSTR_ID_SOLK:
610 case SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK:
611 case SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR:
612 case SOT_FORMATSTR_ID_FILECONTENT:
613 case SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR:
614 case SOT_FORMAT_FILE:
615 if( (TRNSFR_INETFLD & eBufferType) && pBkmk )
616 bOK = SetINetBookmark( *pBkmk, rFlavor );
617 break;
619 case SOT_FORMATSTR_ID_EMBED_SOURCE:
620 // default:
621 if( !aDocShellRef.Is() )
623 SwDoc *pDoc = pClpDocFac->GetDoc();
624 SwDocShell* pNewDocSh = new SwDocShell( pDoc,
625 SFX_CREATE_MODE_EMBEDDED );
626 aDocShellRef = pNewDocSh;
627 aDocShellRef->DoInitNew( NULL );
628 SwTransferable::InitOle( aDocShellRef, *pDoc );
630 bOK = SetObject( &aDocShellRef, SWTRANSFER_OBJECTTYPE_SWOLE,
631 rFlavor );
632 break;
635 return bOK;
638 // -----------------------------------------------------------------------
640 sal_Bool SwTransferable::WriteObject( SotStorageStreamRef& xStream,
641 void* pObject, sal_uInt32 nObjectType,
642 const DATA_FLAVOR& /*rFlavor*/ )
644 sal_Bool bRet = sal_False;
645 WriterRef xWrt;
647 switch( nObjectType )
649 case SWTRANSFER_OBJECTTYPE_DRAWMODEL:
651 //JP 28.02.2001: dont change the sequence of commands - Bug 8
652 SdrModel *pModel = (SdrModel*)pObject;
653 xStream->SetBufferSize( 16348 );
655 // #108584#
656 // for the changed pool defaults from drawing layer pool set those
657 // attributes as hard attributes to preserve them for saving
658 const SfxItemPool& rItemPool = pModel->GetItemPool();
659 const SvxFontHeightItem& rDefaultFontHeight = (const SvxFontHeightItem&)rItemPool.GetDefaultItem(EE_CHAR_FONTHEIGHT);
661 // SW should have no MasterPages
662 DBG_ASSERT(0L == pModel->GetMasterPageCount(), "SW with MasterPages (!)");
664 for(sal_uInt16 a(0); a < pModel->GetPageCount(); a++)
666 const SdrPage* pPage = pModel->GetPage(a);
667 SdrObjListIter aIter(*pPage, IM_DEEPNOGROUPS);
669 while(aIter.IsMore())
671 SdrObject* pObj = aIter.Next();
672 const SvxFontHeightItem& rItem = (const SvxFontHeightItem&)pObj->GetMergedItem(EE_CHAR_FONTHEIGHT);
674 if(rItem.GetHeight() == rDefaultFontHeight.GetHeight())
676 pObj->SetMergedItem(rDefaultFontHeight);
682 uno::Reference<io::XOutputStream> xDocOut( new utl::OOutputStreamWrapper( *xStream ) );
683 if( SvxDrawingLayerExport( pModel, xDocOut ) )
684 xStream->Commit();
687 bRet = ERRCODE_NONE == xStream->GetError();
689 break;
691 case SWTRANSFER_OBJECTTYPE_SWOLE:
693 SfxObjectShell* pEmbObj = (SfxObjectShell*) pObject;
696 ::utl::TempFile aTempFile;
697 aTempFile.EnableKillingFile();
698 uno::Reference< embed::XStorage > xWorkStore =
699 ::comphelper::OStorageHelper::GetStorageFromURL( aTempFile.GetURL(), embed::ElementModes::READWRITE );
701 // write document storage
702 pEmbObj->SetupStorage( xWorkStore, SOFFICE_FILEFORMAT_CURRENT, sal_False );
703 // mba: no BaseURL for clipboard
704 SfxMedium aMedium( xWorkStore, String() );
705 bRet = pEmbObj->DoSaveObjectAs( aMedium, FALSE );
706 pEmbObj->DoSaveCompleted();
708 uno::Reference< embed::XTransactedObject > xTransact( xWorkStore, uno::UNO_QUERY );
709 if ( xTransact.is() )
710 xTransact->commit();
712 SvStream* pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), STREAM_READ );
713 if( pSrcStm )
715 xStream->SetBufferSize( 0xff00 );
716 *xStream << *pSrcStm;
717 delete pSrcStm;
720 bRet = TRUE;
722 xWorkStore->dispose();
723 xWorkStore = uno::Reference < embed::XStorage >();
724 xStream->Commit();
726 catch ( uno::Exception& )
729 bRet = ( xStream->GetError() == ERRCODE_NONE );
731 break;
734 case SWTRANSFER_OBJECTTYPE_DDE:
736 xStream->SetBufferSize( 1024 );
737 SwTrnsfrDdeLink* pDdeLnk = (SwTrnsfrDdeLink*)pObject;
738 if( pDdeLnk->WriteData( *xStream ) )
740 xStream->Commit();
741 bRet = ERRCODE_NONE == xStream->GetError();
744 break;
746 case SWTRANSFER_OBJECTTYPE_HTML:
747 GetHTMLWriter( aEmptyStr, String(), xWrt );
748 break;
750 case SWTRANSFER_OBJECTTYPE_RTF:
751 GetRTFWriter( aEmptyStr, String(), xWrt );
752 break;
754 case SWTRANSFER_OBJECTTYPE_STRING:
755 GetASCWriter( aEmptyStr, String(), xWrt );
756 if( xWrt.Is() )
758 SwAsciiOptions aAOpt;
759 aAOpt.SetCharSet( RTL_TEXTENCODING_UTF8 );
760 xWrt->SetAsciiOptions( aAOpt );
762 // #102841# no start char for clipboard
763 xWrt->bUCS2_WithStartChar = FALSE;
765 break;
768 if( xWrt.Is() )
770 SwDoc* pDoc = (SwDoc*)pObject;
771 xWrt->bWriteClipboardDoc = TRUE;
772 xWrt->bWriteOnlyFirstTable = 0 != (TRNSFR_TABELLE & eBufferType);
773 xWrt->SetShowProgress( FALSE );
774 SwWriter aWrt( *xStream, *pDoc );
775 if( !IsError( aWrt.Write( xWrt )) )
777 *xStream << '\0'; // terminate with a zero
778 xStream->Commit();
779 bRet = sal_True;
783 return bRet;
786 // -----------------------------------------------------------------------
788 int SwTransferable::Cut()
790 int nRet = Copy( TRUE );
791 if( nRet )
792 DeleteSelection();
793 return nRet;
796 // -----------------------------------------------------------------------
798 void SwTransferable::DeleteSelection()
800 if(!pWrtShell)
801 return;
802 // Selektionsart vor Action-Klammerung erfragen
803 const int nSelection = pWrtShell->GetSelectionType();
804 pWrtShell->StartUndo( UNDO_DELETE );
805 if( ( nsSelectionType::SEL_TXT | nsSelectionType::SEL_TBL ) & nSelection )
806 pWrtShell->IntelligentCut( nSelection );
807 pWrtShell->DelRight();
808 pWrtShell->EndUndo( UNDO_DELETE );
811 // -----------------------------------------------------------------------
813 int SwTransferable::PrepareForCopy( BOOL bIsCut )
815 int nRet = 1;
816 if(!pWrtShell)
817 return 0;;
819 String sGrfNm;
820 const int nSelection = pWrtShell->GetSelectionType();
821 if( nSelection == nsSelectionType::SEL_GRF )
823 pClpGraphic = new Graphic;
824 if( !pWrtShell->GetDrawObjGraphic( FORMAT_GDIMETAFILE, *pClpGraphic ))
825 pOrigGrf = pClpGraphic;
826 pClpBitmap = new Graphic;
827 if( !pWrtShell->GetDrawObjGraphic( FORMAT_BITMAP, *pClpBitmap ))
828 pOrigGrf = pClpBitmap;
830 pClpDocFac = new SwDocFac;
831 pWrtShell->Copy( pClpDocFac->GetDoc() );
833 if (pOrigGrf && !pOrigGrf->GetBitmap().IsEmpty())
834 AddFormat( SOT_FORMATSTR_ID_SVXB );
836 PrepareOLE( aObjDesc );
837 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
839 // --> OD 2005-02-09 #119353# - robust
840 const Graphic* pGrf = pWrtShell->GetGraphic();
841 if( pGrf && pGrf->IsSupportedGraphic() )
842 // <--
844 AddFormat( FORMAT_GDIMETAFILE );
845 AddFormat( FORMAT_BITMAP );
847 eBufferType = TRNSFR_GRAPHIC;
848 pWrtShell->GetGrfNms( &sGrfNm, 0 );
850 else if ( nSelection == nsSelectionType::SEL_OLE )
852 pClpDocFac = new SwDocFac;
853 SwDoc *pDoc = pClpDocFac->GetDoc();
854 aDocShellRef = new SwDocShell( pDoc, SFX_CREATE_MODE_EMBEDDED);
855 aDocShellRef->DoInitNew( NULL );
856 pWrtShell->Copy( pDoc );
858 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
860 PrepareOLE( aObjDesc );
861 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
863 AddFormat( FORMAT_GDIMETAFILE );
864 eBufferType = TRNSFR_OLE;
866 //Gibt es ueberhaupt etwas zum bereitstellen?
867 else if ( pWrtShell->IsSelection() || pWrtShell->IsFrmSelected() ||
868 pWrtShell->IsObjSelected() )
870 SwWait *pWait = 0;
871 if( pWrtShell->ShouldWait() )
872 pWait = new SwWait( *pWrtShell->GetView().GetDocShell(), TRUE );
874 pClpDocFac = new SwDocFac;
876 // zusaetzlichen Cursor erzeugen, damit eine Gleichbehandlung
877 // von Tastatur- und Mausselektion moeglich ist.
878 // Im AddMode wird bei Tastaturselektion der neue Cursor erst
879 // beim Bewegen des Cursors nach Selektionsende erzeugt.
880 if( pWrtShell->IsAddMode() && pWrtShell->SwCrsrShell::HasSelection() )
881 pWrtShell->CreateCrsr();
883 SwDoc* pTmpDoc = pClpDocFac->GetDoc();
884 pTmpDoc->SetClipBoard( true );
886 pTmpDoc->SetRefForDocShell( boost::addressof(aDocShellRef) );
887 pTmpDoc->LockExpFlds(); // nie die Felder updaten - Text so belassen
888 pWrtShell->Copy( pTmpDoc );
891 IDocumentMarkAccess* const pMarkAccess = pTmpDoc->getIDocumentMarkAccess();
892 ::std::vector< ::sw::mark::IMark* > vDdeMarks;
893 // find all DDE-Bookmarks
894 for(IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getMarksBegin();
895 ppMark != pMarkAccess->getMarksEnd();
896 ppMark++)
898 if(IDocumentMarkAccess::DDE_BOOKMARK == IDocumentMarkAccess::GetType(**ppMark))
899 vDdeMarks.push_back(ppMark->get());
901 // remove all DDE-Bookmarks, they are invalid inside the clipdoc!
902 for(::std::vector< ::sw::mark::IMark* >::iterator ppMark = vDdeMarks.begin();
903 ppMark != vDdeMarks.end();
904 ppMark++)
905 pMarkAccess->deleteMark(*ppMark);
908 // es wurde in der CORE eine neu angelegt (OLE-Objekte kopiert!)
909 if( aDocShellRef.Is() )
910 SwTransferable::InitOle( aDocShellRef, *pTmpDoc );
911 pTmpDoc->SetRefForDocShell( 0 );
913 if( pWrtShell->IsObjSelected() )
914 eBufferType = TRNSFR_DRAWING;
915 else
917 eBufferType = TRNSFR_DOCUMENT;
918 if (pWrtShell->IntelligentCut(nSelection, FALSE) != SwWrtShell::NO_WORD)
919 eBufferType = (TransferBufferType)(TRNSFR_DOCUMENT_WORD | eBufferType);
922 int bDDELink = pWrtShell->IsSelection();
923 if( nSelection & nsSelectionType::SEL_TBL_CELLS )
925 eBufferType = (TransferBufferType)(TRNSFR_TABELLE | eBufferType);
926 bDDELink = pWrtShell->HasWholeTabSelection();
929 //Wenn's einer braucht OLE'n wir ihm was.
930 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
932 //RTF vor das Metafile von OLE stellen, weil mit weniger verlusten
933 //behaftet.
934 if( !pWrtShell->IsObjSelected() )
936 AddFormat( FORMAT_RTF );
937 AddFormat( SOT_FORMATSTR_ID_HTML );
939 if( pWrtShell->IsSelection() )
940 AddFormat( FORMAT_STRING );
942 if( nSelection & ( nsSelectionType::SEL_DRW | nsSelectionType::SEL_DRW_FORM ))
944 AddFormat( SOT_FORMATSTR_ID_DRAWING );
945 if ( nSelection & nsSelectionType::SEL_DRW )
947 AddFormat( FORMAT_GDIMETAFILE );
948 AddFormat( FORMAT_BITMAP );
950 eBufferType = (TransferBufferType)( TRNSFR_GRAPHIC | eBufferType );
952 pClpGraphic = new Graphic;
953 if( !pWrtShell->GetDrawObjGraphic( FORMAT_GDIMETAFILE, *pClpGraphic ))
954 pOrigGrf = pClpGraphic;
955 pClpBitmap = new Graphic;
956 if( !pWrtShell->GetDrawObjGraphic( FORMAT_BITMAP, *pClpBitmap ))
957 pOrigGrf = pClpBitmap;
959 // ist es ein URL-Button ?
960 String sURL, sDesc;
961 if( pWrtShell->GetURLFromButton( sURL, sDesc ) )
963 AddFormat( FORMAT_STRING );
964 AddFormat( SOT_FORMATSTR_ID_SOLK );
965 AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK );
966 AddFormat( SOT_FORMATSTR_ID_FILECONTENT );
967 AddFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR );
968 AddFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR );
969 eBufferType = (TransferBufferType)( TRNSFR_INETFLD | eBufferType );
970 nRet = sal_True;
974 // beim Cut hat DDE-Link keinen Sinn!!
975 SwDocShell* pDShell;
976 if( !bIsCut && bDDELink &&
977 0 != ( pDShell = pWrtShell->GetDoc()->GetDocShell()) &&
978 SFX_CREATE_MODE_STANDARD == pDShell->GetCreateMode() )
980 AddFormat( SOT_FORMATSTR_ID_LINK );
981 refDdeLink = new SwTrnsfrDdeLink( *this, *pWrtShell );
984 //ObjectDescriptor wurde bereits aus der alten DocShell gefuellt.
985 //Jetzt noch anpassen. Dadurch kann im GetData die erste Anfrage
986 //auch noch mit delayed rendering beantwortet werden.
987 aObjDesc.mbCanLink = FALSE;
988 Size aSz( OLESIZE );
989 aObjDesc.maSize = OutputDevice::LogicToLogic( aSz, MAP_TWIP, MAP_100TH_MM );
991 PrepareOLE( aObjDesc );
992 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
994 delete pWait;
996 else
997 nRet = 0;
999 if( pWrtShell->IsFrmSelected() )
1001 SfxItemSet aSet( pWrtShell->GetAttrPool(), RES_URL, RES_URL );
1002 pWrtShell->GetFlyFrmAttr( aSet );
1003 const SwFmtURL& rURL = (SwFmtURL&)aSet.Get( RES_URL );
1004 if( rURL.GetMap() )
1006 pImageMap = new ImageMap( *rURL.GetMap() );
1007 AddFormat( SOT_FORMATSTR_ID_SVIM );
1009 else if( rURL.GetURL().Len() )
1011 pTargetURL = new INetImage( sGrfNm, rURL.GetURL(),
1012 rURL.GetTargetFrameName(),
1013 aEmptyStr, Size() );
1014 AddFormat( SOT_FORMATSTR_ID_INET_IMAGE );
1018 return nRet;
1021 int SwTransferable::Copy( BOOL bIsCut )
1023 int nRet = PrepareForCopy( bIsCut );
1024 if ( nRet )
1026 SW_MOD()->pClipboard = this;
1027 CopyToClipboard( &pWrtShell->GetView().GetEditWin() );
1029 return nRet;
1032 // -----------------------------------------------------------------------
1034 int SwTransferable::CalculateAndCopy()
1036 if(!pWrtShell)
1037 return 0;
1038 SwWait aWait( *pWrtShell->GetView().GetDocShell(), TRUE );
1040 String aStr( pWrtShell->Calculate() );
1042 pClpDocFac = new SwDocFac;
1043 pWrtShell->Copy( pClpDocFac->GetDoc(), &aStr);
1044 eBufferType = TRNSFR_DOCUMENT;
1045 AddFormat( FORMAT_STRING );
1047 SW_MOD()->pClipboard = this;
1048 CopyToClipboard( &pWrtShell->GetView().GetEditWin() );
1050 return 1;
1053 // -----------------------------------------------------------------------
1055 int SwTransferable::CopyGlossary( SwTextBlocks& rGlossary,
1056 const String& rStr )
1058 if(!pWrtShell)
1059 return 0;
1060 SwWait aWait( *pWrtShell->GetView().GetDocShell(), TRUE );
1062 pClpDocFac = new SwDocFac;
1063 SwDoc* pCDoc = pClpDocFac->GetDoc();
1065 SwNodes& rNds = pCDoc->GetNodes();
1066 SwNodeIndex aNodeIdx( *rNds.GetEndOfContent().StartOfSectionNode() );
1067 SwCntntNode* pCNd = rNds.GoNext( &aNodeIdx ); // gehe zum 1. ContentNode
1068 SwPaM aPam( *pCNd );
1070 pCDoc->SetRefForDocShell( boost::addressof(aDocShellRef) );
1071 pCDoc->LockExpFlds(); // nie die Felder updaten - Text so belassen
1073 pCDoc->InsertGlossary( rGlossary, rStr, aPam, 0 );
1075 // es wurde in der CORE eine neu angelegt (OLE-Objekte kopiert!)
1076 if( aDocShellRef.Is() )
1077 SwTransferable::InitOle( aDocShellRef, *pCDoc );
1078 pCDoc->SetRefForDocShell( 0 );
1080 eBufferType = TRNSFR_DOCUMENT;
1082 //Wenn's einer braucht OLE'n wir ihm was.
1083 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
1084 AddFormat( FORMAT_RTF );
1085 AddFormat( SOT_FORMATSTR_ID_HTML );
1086 AddFormat( FORMAT_STRING );
1088 //ObjectDescriptor wurde bereits aus der alten DocShell gefuellt.
1089 //Jetzt noch anpassen. Dadurch kann im GetData die erste Anfrage
1090 //auch noch mit delayed rendering beantwortet werden.
1091 aObjDesc.mbCanLink = FALSE;
1092 Size aSz( OLESIZE );
1093 aObjDesc.maSize = OutputDevice::LogicToLogic( aSz, MAP_TWIP, MAP_100TH_MM );
1095 PrepareOLE( aObjDesc );
1096 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
1098 SW_MOD()->pClipboard = this;
1099 CopyToClipboard( &pWrtShell->GetView().GetEditWin() );
1101 return 1;
1104 static inline uno::Reference < XTransferable > * lcl_getTransferPointer ( uno::Reference < XTransferable > &xRef )
1106 return &xRef;
1108 // -----------------------------------------------------------------------
1110 BOOL SwTransferable::IsPaste( const SwWrtShell& rSh,
1111 const TransferableDataHelper& rData )
1113 // Check the common case first: We can always paste our own data!
1114 // #106503#: If _only_ the internal format can be pasted, this check will
1115 // yield 'true', while the one below would give a (wrong) result 'false'.
1116 bool bIsPaste = ( SW_MOD()->pClipboard != NULL );
1118 // if it's not our own data, we need to have a closer look:
1119 if( ! bIsPaste )
1121 // determine the proper paste action, and return true if we find one
1122 uno::Reference<XTransferable> xTransferable( rData.GetXTransferable() );
1123 uno::Reference<XUnoTunnel> xTunnel( xTransferable, UNO_QUERY );
1124 if ( xTunnel.is() )
1126 sal_Int64 nHandle = xTunnel->getSomething( getUnoTunnelId() );
1127 if ( nHandle )
1128 return TRUE;
1131 USHORT nDestination = SwTransferable::GetSotDestination( rSh );
1132 USHORT nSourceOptions =
1133 (( EXCHG_DEST_DOC_TEXTFRAME == nDestination ||
1134 EXCHG_DEST_SWDOC_FREE_AREA == nDestination ||
1135 EXCHG_DEST_DOC_TEXTFRAME_WEB == nDestination ||
1136 EXCHG_DEST_SWDOC_FREE_AREA_WEB == nDestination )
1137 ? EXCHG_IN_ACTION_COPY
1138 : EXCHG_IN_ACTION_MOVE);
1140 ULONG nFormat; // output param for GetExchangeAction
1141 USHORT nEventAction; // output param for GetExchangeAction
1142 USHORT nAction = SotExchange::GetExchangeAction(
1143 rData.GetDataFlavorExVector(),
1144 nDestination,
1145 nSourceOptions, /* ?? */
1146 EXCHG_IN_ACTION_DEFAULT, /* ?? */
1147 nFormat, nEventAction, 0,
1148 lcl_getTransferPointer ( xTransferable ) );
1150 // if we find a suitable action, we can paste!
1151 bIsPaste = (EXCHG_INOUT_ACTION_NONE != nAction);
1154 return bIsPaste;
1157 // -----------------------------------------------------------------------
1159 int SwTransferable::Paste( SwWrtShell& rSh, TransferableDataHelper& rData )
1161 USHORT nEventAction, nAction=0,
1162 nDestination = SwTransferable::GetSotDestination( rSh );
1163 ULONG nFormat = 0;
1165 if( SW_MOD()->pClipboard )
1166 nAction = EXCHG_OUT_ACTION_INSERT_PRIVATE;
1167 else
1169 uno::Reference<XUnoTunnel> xTunnel( rData.GetTransferable(), UNO_QUERY );
1170 if ( xTunnel.is() )
1172 sal_Int64 nHandle = xTunnel->getSomething( getUnoTunnelId() );
1173 if ( nHandle )
1174 nAction = EXCHG_OUT_ACTION_INSERT_PRIVATE;
1177 if ( !nAction )
1179 USHORT nSourceOptions =
1180 (( EXCHG_DEST_DOC_TEXTFRAME == nDestination ||
1181 EXCHG_DEST_SWDOC_FREE_AREA == nDestination ||
1182 EXCHG_DEST_DOC_TEXTFRAME_WEB == nDestination ||
1183 EXCHG_DEST_SWDOC_FREE_AREA_WEB == nDestination )
1184 ? EXCHG_IN_ACTION_COPY
1185 : EXCHG_IN_ACTION_MOVE);
1186 uno::Reference<XTransferable> xTransferable( rData.GetXTransferable() );
1187 nAction = SotExchange::GetExchangeAction(
1188 rData.GetDataFlavorExVector(),
1189 nDestination,
1190 nSourceOptions, /* ?? */
1191 EXCHG_IN_ACTION_DEFAULT, /* ?? */
1192 nFormat, nEventAction, 0,
1193 lcl_getTransferPointer ( xTransferable ) );
1197 // special case for tables from draw application
1198 if( EXCHG_OUT_ACTION_INSERT_DRAWOBJ == (nAction & EXCHG_ACTION_MASK) )
1200 if( rData.HasFormat( SOT_FORMAT_RTF ) )
1202 nAction = EXCHG_OUT_ACTION_INSERT_STRING | (nAction & !EXCHG_ACTION_MASK);
1203 nFormat = SOT_FORMAT_RTF;
1207 return EXCHG_INOUT_ACTION_NONE != nAction &&
1208 SwTransferable::PasteData( rData, rSh, nAction, nFormat,
1209 nDestination, FALSE, FALSE );
1212 // -----------------------------------------------------------------------
1214 int SwTransferable::PasteData( TransferableDataHelper& rData,
1215 SwWrtShell& rSh, USHORT nAction, ULONG nFormat,
1216 USHORT nDestination, BOOL bIsPasteFmt,
1217 sal_Bool bIsDefault,
1218 const Point* pPt, sal_Int8 nDropAction,
1219 BOOL bPasteSelection )
1221 SwWait aWait( *rSh.GetView().
1222 GetDocShell(), FALSE );
1223 SwTrnsfrActionAndUndo* pAction = 0;
1224 SwModule* pMod = SW_MOD();
1226 int nRet = 0;
1227 bool bCallAutoCaption = false;
1229 if( pPt )
1231 // external Drop
1232 if( bPasteSelection ? !pMod->pXSelection : !pMod->pDragDrop )
1234 switch( nDestination )
1236 case EXCHG_DEST_DOC_LNKD_GRAPH_W_IMAP:
1237 case EXCHG_DEST_DOC_LNKD_GRAPHOBJ:
1238 case EXCHG_DEST_DOC_GRAPH_W_IMAP:
1239 case EXCHG_DEST_DOC_GRAPHOBJ:
1240 case EXCHG_DEST_DOC_OLEOBJ:
1241 case EXCHG_DEST_DOC_DRAWOBJ:
1242 case EXCHG_DEST_DOC_URLBUTTON:
1243 case EXCHG_DEST_DOC_GROUPOBJ:
1244 // Rahmen/Objecte selektieren
1245 SwTransferable::SetSelInShell( rSh, TRUE, pPt );
1246 break;
1248 // case EXCHG_DEST_DOC_TEXTFRAME:
1249 // case EXCHG_DEST_SWDOC_FREE_AREA:
1250 // case EXCHG_DEST_DOC_URLFIELD:
1251 default:
1252 SwTransferable::SetSelInShell( rSh, FALSE, pPt );
1253 break;
1257 else if( ( !pMod->pClipboard || bIsPasteFmt ) &&
1258 !rSh.IsTableMode() && rSh.HasSelection() )
1260 // dann die Selektionen loeschen
1262 //Selektierten Inhalt loeschen,
1263 // - nicht bei Tabellen-Selektion
1264 // - nicht bei ReRead einer Grafik/DDEDaten
1265 // - nicht bei D&D, fuer die richtige Selektion wurde im
1266 // Drop-Handler gesorgt
1267 BOOL bDelSel = FALSE;
1268 switch( nDestination )
1270 case EXCHG_DEST_DOC_TEXTFRAME:
1271 case EXCHG_DEST_SWDOC_FREE_AREA:
1272 case EXCHG_DEST_DOC_TEXTFRAME_WEB:
1273 case EXCHG_DEST_SWDOC_FREE_AREA_WEB:
1274 bDelSel = TRUE;
1275 break;
1278 if( bDelSel )
1279 // --> FME 2004-10-19 #i34830#
1280 pAction = new SwTrnsfrActionAndUndo( &rSh, UNDO_PASTE_CLIPBOARD, NULL,
1281 TRUE );
1282 // <--
1285 SwTransferable *pTrans=0, *pTunneledTrans=0;
1286 uno::Reference<XUnoTunnel> xTunnel( rData.GetTransferable(), UNO_QUERY );
1287 if ( xTunnel.is() )
1289 sal_Int64 nHandle = xTunnel->getSomething( getUnoTunnelId() );
1290 if ( nHandle )
1291 pTunneledTrans = (SwTransferable*) (sal_IntPtr) nHandle;
1294 if( pPt && ( bPasteSelection ? 0 != ( pTrans = pMod->pXSelection )
1295 : 0 != ( pTrans = pMod->pDragDrop) ))
1297 // then internal Drag & Drop or XSelection
1298 nRet = pTrans->PrivateDrop( rSh, *pPt, DND_ACTION_MOVE == nDropAction,
1299 bPasteSelection );
1301 else if( !pPt && ( pTunneledTrans || 0 != ( pTunneledTrans = pMod->pClipboard ) ) &&
1302 EXCHG_OUT_ACTION_INSERT_PRIVATE == nAction )
1304 // then internal paste
1305 nRet = pTunneledTrans->PrivatePaste( rSh );
1307 else if( EXCHG_INOUT_ACTION_NONE != nAction )
1309 if( !pAction )
1311 // #111827#
1312 pAction = new SwTrnsfrActionAndUndo( &rSh, UNDO_PASTE_CLIPBOARD);
1315 // im Drag&Drop duerfen keine MessageBoxen angezeigt werden
1316 BOOL bMsg = 0 == pPt;
1317 BYTE nActionFlags = static_cast< BYTE >(( nAction >> 8 ) & 0xFF);
1319 USHORT nClearedAction = ( nAction & EXCHG_ACTION_MASK );
1320 // Selektionen loeschen
1322 switch( nClearedAction )
1324 case EXCHG_OUT_ACTION_INSERT_PRIVATE:
1325 ASSERT( pPt, "EXCHG_OUT_ACTION_INSERT_PRIVATE: was soll hier passieren?" );
1326 break;
1328 case EXCHG_OUT_ACTION_MOVE_PRIVATE:
1329 ASSERT( pPt, "EXCHG_OUT_ACTION_MOVE_PRIVATE: was soll hier passieren?" );
1330 break;
1333 case EXCHG_IN_ACTION_MOVE:
1334 case EXCHG_IN_ACTION_COPY:
1335 case EXCHG_IN_ACTION_LINK:
1336 case EXCHG_OUT_ACTION_INSERT_HTML:
1337 case EXCHG_OUT_ACTION_INSERT_STRING:
1338 case EXCHG_OUT_ACTION_INSERT_IMAGEMAP:
1339 case EXCHG_OUT_ACTION_REPLACE_IMAGEMAP:
1341 // dann muss ueber das Format gegangen werden
1342 switch( nFormat )
1344 case SOT_FORMATSTR_ID_DRAWING:
1345 nRet = SwTransferable::_PasteSdrFormat( rData, rSh,
1346 SW_PASTESDR_INSERT, pPt,
1347 nActionFlags );
1348 break;
1350 case SOT_FORMATSTR_ID_HTML:
1351 case SOT_FORMATSTR_ID_HTML_SIMPLE:
1352 case SOT_FORMATSTR_ID_HTML_NO_COMMENT:
1353 case SOT_FORMAT_RTF:
1354 case SOT_FORMAT_STRING:
1355 nRet = SwTransferable::_PasteFileContent( rData, rSh,
1356 nFormat, bMsg );
1357 break;
1359 case SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK:
1361 INetBookmark aBkmk;
1362 if( rData.GetINetBookmark( nFormat, aBkmk ) )
1364 SwFmtINetFmt aFmt( aBkmk.GetURL(), aEmptyStr );
1365 rSh.InsertURL( aFmt, aBkmk.GetDescription() );
1366 nRet = 1;
1369 break;
1371 case SOT_FORMATSTR_ID_SD_OLE:
1372 nRet = SwTransferable::_PasteOLE( rData, rSh, nFormat,
1373 nActionFlags, bMsg );
1374 break;
1376 case SOT_FORMATSTR_ID_SVIM:
1377 nRet = SwTransferable::_PasteImageMap( rData, rSh );
1378 break;
1380 case SOT_FORMATSTR_ID_SVXB:
1381 case SOT_FORMAT_BITMAP:
1382 case SOT_FORMAT_GDIMETAFILE:
1383 nRet = SwTransferable::_PasteGrf( rData, rSh, nFormat,
1384 SW_PASTESDR_INSERT,pPt,
1385 nActionFlags, bMsg );
1386 break;
1388 case SOT_FORMATSTR_ID_XFORMS:
1389 case SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE:
1390 case SOT_FORMATSTR_ID_SBA_DATAEXCHANGE:
1391 case SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE:
1392 nRet = SwTransferable::_PasteDBData( rData, rSh, nFormat,
1393 EXCHG_IN_ACTION_LINK == nClearedAction,
1394 pPt, bMsg );
1395 break;
1397 case SOT_FORMAT_FILE:
1398 nRet = SwTransferable::_PasteFileName( rData, rSh, nFormat,
1399 ( EXCHG_IN_ACTION_MOVE == nClearedAction
1400 ? SW_PASTESDR_REPLACE
1401 : EXCHG_IN_ACTION_LINK == nClearedAction
1402 ? SW_PASTESDR_SETATTR
1403 : SW_PASTESDR_INSERT),
1404 pPt, nActionFlags, bMsg );
1405 break;
1407 case SOT_FORMAT_FILE_LIST:
1408 // dann nur als Grafiken einfuegen
1409 nRet = SwTransferable::_PasteFileList( rData, rSh,
1410 EXCHG_IN_ACTION_LINK == nClearedAction,
1411 pPt, bMsg );
1412 break;
1414 case SOT_FORMATSTR_ID_SONLK:
1415 if( pPt )
1417 NaviContentBookmark aBkmk;
1418 if( aBkmk.Paste( rData ) )
1420 if(bIsDefault)
1422 switch(aBkmk.GetDefaultDragType())
1424 case REGION_MODE_NONE: nClearedAction = EXCHG_IN_ACTION_COPY; break;
1425 case REGION_MODE_EMBEDDED: nClearedAction = EXCHG_IN_ACTION_MOVE; break;
1426 case REGION_MODE_LINK: nClearedAction = EXCHG_IN_ACTION_LINK; break;
1429 rSh.NavigatorPaste( aBkmk, nClearedAction );
1430 nRet = 1;
1433 break;
1435 case SOT_FORMATSTR_ID_INET_IMAGE:
1436 case SOT_FORMATSTR_ID_NETSCAPE_IMAGE:
1437 nRet = SwTransferable::_PasteTargetURL( rData, rSh,
1438 SW_PASTESDR_INSERT,
1439 pPt, TRUE );
1440 break;
1442 default:
1443 ASSERT( pPt, "unbekanntes Format" );
1445 break;
1447 case EXCHG_OUT_ACTION_INSERT_FILE:
1448 nRet = SwTransferable::_PasteFileName( rData, rSh, nFormat,
1449 SW_PASTESDR_INSERT, pPt,
1450 nActionFlags, bMsg );
1451 if( nRet & SWTRANSFER_GRAPHIC_INSERTED )
1452 bCallAutoCaption = true;
1453 break;
1455 case EXCHG_OUT_ACTION_INSERT_OLE:
1456 nRet = SwTransferable::_PasteOLE( rData, rSh, nFormat,
1457 nActionFlags,bMsg );
1458 break;
1460 case EXCHG_OUT_ACTION_INSERT_DDE:
1462 BOOL bReRead = 0 != CNT_HasGrf( rSh.GetCntType() );
1463 nRet = SwTransferable::_PasteDDE( rData, rSh, bReRead, bMsg );
1465 break;
1467 case EXCHG_OUT_ACTION_INSERT_HYPERLINK:
1469 String sURL, sDesc;
1470 if( SOT_FORMAT_FILE == nFormat )
1472 if( rData.GetString( nFormat, sURL ) && sURL.Len() )
1474 SwTransferable::_CheckForURLOrLNKFile( rData, sURL, &sDesc );
1475 if( !sDesc.Len() )
1476 sDesc = sURL;
1477 nRet = 1;
1480 else
1482 INetBookmark aBkmk;
1483 if( rData.GetINetBookmark( nFormat, aBkmk ) )
1485 sURL = aBkmk.GetURL();
1486 sDesc = aBkmk.GetDescription();
1487 nRet = 1;
1491 if( nRet )
1493 SwFmtINetFmt aFmt( sURL, aEmptyStr );
1494 rSh.InsertURL( aFmt, sDesc );
1497 break;
1499 case EXCHG_OUT_ACTION_GET_ATTRIBUTES:
1500 switch( nFormat )
1502 case SOT_FORMATSTR_ID_DRAWING:
1503 nRet = SwTransferable::_PasteSdrFormat( rData, rSh,
1504 SW_PASTESDR_SETATTR, pPt,
1505 nActionFlags );
1506 break;
1507 case SOT_FORMATSTR_ID_SVXB:
1508 case SOT_FORMAT_GDIMETAFILE:
1509 case SOT_FORMAT_BITMAP:
1510 case SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK:
1511 case SOT_FORMAT_FILE:
1512 case SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR:
1513 case SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR:
1514 nRet = SwTransferable::_PasteGrf( rData, rSh, nFormat,
1515 SW_PASTESDR_SETATTR, pPt,
1516 nActionFlags, bMsg );
1517 break;
1518 default:
1519 ASSERT( FALSE, "unbekanntes Format" );
1522 break;
1524 case EXCHG_OUT_ACTION_INSERT_DRAWOBJ:
1525 nRet = SwTransferable::_PasteSdrFormat( rData, rSh,
1526 SW_PASTESDR_INSERT, pPt,
1527 nActionFlags );
1528 break;
1529 case EXCHG_OUT_ACTION_INSERT_SVXB:
1530 case EXCHG_OUT_ACTION_INSERT_GDIMETAFILE:
1531 case EXCHG_OUT_ACTION_INSERT_BITMAP:
1532 case EXCHG_OUT_ACTION_INSERT_GRAPH:
1533 nRet = SwTransferable::_PasteGrf( rData, rSh, nFormat,
1534 SW_PASTESDR_INSERT, pPt,
1535 nActionFlags, bMsg );
1536 break;
1538 case EXCHG_OUT_ACTION_REPLACE_DRAWOBJ:
1539 nRet = SwTransferable::_PasteSdrFormat( rData, rSh,
1540 SW_PASTESDR_REPLACE, pPt,
1541 nActionFlags );
1542 break;
1544 case EXCHG_OUT_ACTION_REPLACE_SVXB:
1545 case EXCHG_OUT_ACTION_REPLACE_GDIMETAFILE:
1546 case EXCHG_OUT_ACTION_REPLACE_BITMAP:
1547 case EXCHG_OUT_ACTION_REPLACE_GRAPH:
1548 nRet = SwTransferable::_PasteGrf( rData, rSh, nFormat,
1549 SW_PASTESDR_REPLACE,pPt,
1550 nActionFlags, bMsg );
1551 break;
1553 case EXCHG_OUT_ACTION_INSERT_INTERACTIVE:
1554 nRet = SwTransferable::_PasteAsHyperlink( rData, rSh, nFormat );
1555 break;
1557 default:
1558 ASSERT( FALSE, "unbekannte Action" );
1562 if( !bPasteSelection && rSh.IsFrmSelected() )
1564 rSh.EnterSelFrmMode();
1565 //force ::SelectShell
1566 rSh.GetView().StopShellTimer();
1569 if( pAction )
1570 delete pAction;
1571 if( bCallAutoCaption )
1572 rSh.GetView().AutoCaption( GRAPHIC_CAP );
1574 return nRet;
1577 // -----------------------------------------------------------------------
1579 USHORT SwTransferable::GetSotDestination( const SwWrtShell& rSh,
1580 const Point* pPt )
1582 USHORT nRet = EXCHG_INOUT_ACTION_NONE;
1584 ObjCntType eOType;
1585 if( pPt )
1587 SdrObject *pObj = 0;
1588 eOType = rSh.GetObjCntType( *pPt, pObj );
1590 else
1591 eOType = rSh.GetObjCntTypeOfSelection();
1593 switch( eOType )
1595 case OBJCNT_GRF:
1597 BOOL bIMap, bLink;
1598 if( pPt )
1600 bIMap = 0 != rSh.GetFmtFromObj( *pPt )->GetURL().GetMap();
1601 String aDummy;
1602 rSh.GetGrfAtPos( *pPt, aDummy, bLink );
1604 else
1606 bIMap = 0 != rSh.GetFlyFrmFmt()->GetURL().GetMap();
1607 String aDummy;
1608 rSh.GetGrfNms( &aDummy, 0 );
1609 bLink = 0 != aDummy.Len();
1612 if( bLink && bIMap )
1613 nRet = EXCHG_DEST_DOC_LNKD_GRAPH_W_IMAP;
1614 else if( bLink )
1615 nRet = EXCHG_DEST_DOC_LNKD_GRAPHOBJ;
1616 else if( bIMap )
1617 nRet = EXCHG_DEST_DOC_GRAPH_W_IMAP;
1618 else
1619 nRet = EXCHG_DEST_DOC_GRAPHOBJ;
1621 break;
1623 case OBJCNT_FLY:
1624 if( rSh.GetView().GetDocShell()->ISA(SwWebDocShell) )
1625 nRet = EXCHG_DEST_DOC_TEXTFRAME_WEB;
1626 else
1627 nRet = EXCHG_DEST_DOC_TEXTFRAME;
1628 break;
1629 case OBJCNT_OLE: nRet = EXCHG_DEST_DOC_OLEOBJ; break;
1631 case OBJCNT_CONTROL: /* no Action avail */
1632 case OBJCNT_SIMPLE: nRet = EXCHG_DEST_DOC_DRAWOBJ; break;
1633 case OBJCNT_URLBUTTON: nRet = EXCHG_DEST_DOC_URLBUTTON; break;
1634 case OBJCNT_GROUPOBJ: nRet = EXCHG_DEST_DOC_GROUPOBJ; break;
1636 // was mmchen wir bei Mehrfachselektion???
1637 // case OBJCNT_DONTCARE:
1638 default:
1641 JP 13.07.98: Bug 52637: es wird ein URL-Feld erkannt also werden nur die
1642 Inhalte zugelassen. Das ist aber bestimmt nicht das
1643 gewollte.
1644 SwContentAtPos aCntntAtPos( SwContentAtPos::SW_INETATTR );
1645 SfxItemSet aSet( (SfxItemPool&)rSh.GetAttrPool(),
1646 RES_TXTATR_INETFMT, RES_TXTATR_INETFMT );
1647 if( pPt ? ((SwWrtShell&)rSh).GetContentAtPos( *pPt, aCntntAtPos, FALSE )
1648 : (rSh.GetAttr( aSet ) && aSet.Count()) )
1649 nRet = EXCHG_DEST_DOC_URLFIELD;
1650 else
1652 if( rSh.GetView().GetDocShell()->ISA(SwWebDocShell) )
1653 nRet = EXCHG_DEST_SWDOC_FREE_AREA_WEB;
1654 else
1655 nRet = EXCHG_DEST_SWDOC_FREE_AREA;
1659 return nRet;
1662 // -----------------------------------------------------------------------
1664 int SwTransferable::_PasteFileContent( TransferableDataHelper& rData,
1665 SwWrtShell& rSh, ULONG nFmt, BOOL bMsg )
1667 USHORT nResId = MSG_CLPBRD_FORMAT_ERROR;
1668 int nRet = 0;
1670 MSE40HTMLClipFormatObj aMSE40ClpObj;
1672 SotStorageStreamRef xStrm;
1673 SvStream* pStream = 0;
1674 SwRead pRead = 0;
1675 rtl::OUString sData;
1676 switch( nFmt )
1678 case SOT_FORMAT_STRING:
1680 pRead = ReadAscii;
1681 if( rData.GetString( nFmt, sData ) )
1683 pStream = new SvMemoryStream( (void*)sData.getStr(),
1684 sData.getLength() * sizeof( sal_Unicode ),
1685 STREAM_READ );
1686 #ifdef OSL_BIGENDIAN
1687 pStream->SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN );
1688 #else
1689 pStream->SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
1690 #endif
1692 SwAsciiOptions aAOpt;
1693 aAOpt.SetCharSet( RTL_TEXTENCODING_UCS2 );
1694 pRead->GetReaderOpt().SetASCIIOpts( aAOpt );
1695 break;
1698 // no break - because then test if we get a stream
1700 default:
1701 if( rData.GetSotStorageStream( nFmt, xStrm ) )
1703 if( ( SOT_FORMATSTR_ID_HTML_SIMPLE == nFmt ) ||
1704 ( SOT_FORMATSTR_ID_HTML_NO_COMMENT == nFmt ) )
1706 pStream = aMSE40ClpObj.IsValid( *xStrm );
1707 pRead = ReadHTML;
1708 pRead->SetReadUTF8( TRUE );
1709 //pRead->SetBaseURL( aMSE40ClpObj.GetBaseURL() );
1711 BOOL bNoComments =
1712 ( nFmt == SOT_FORMATSTR_ID_HTML_NO_COMMENT );
1713 pRead->SetIgnoreHTMLComments( bNoComments );
1715 else
1717 pStream = &xStrm;
1718 if( SOT_FORMAT_RTF == nFmt )
1719 pRead = SwReaderWriter::GetReader( READER_WRITER_RTF );
1720 else if( !pRead )
1722 pRead = ReadHTML;
1723 pRead->SetReadUTF8( TRUE );
1727 break;
1730 if( pStream && pRead )
1732 Link aOldLink( rSh.GetChgLnk() );
1733 rSh.SetChgLnk( Link() );
1735 SwReader aReader( *pStream, aEmptyStr, String(), *rSh.GetCrsr() );
1736 if( IsError( aReader.Read( *pRead )) )
1737 nResId = ERR_CLPBRD_READ;
1738 else
1739 nResId = 0, nRet = 1;
1741 rSh.SetChgLnk( aOldLink );
1742 if( nRet )
1743 rSh.CallChgLnk();
1745 else
1746 nResId = MSG_CLPBRD_FORMAT_ERROR;
1748 // Exist a SvMemoryStream? (data in the OUString and xStrm is empty)
1749 if( pStream && !xStrm.Is() )
1750 delete pStream;
1752 if( bMsg && nResId )
1754 InfoBox( 0, SW_RES( nResId )).Execute();
1756 return nRet;
1759 // -----------------------------------------------------------------------
1761 int SwTransferable::_PasteOLE( TransferableDataHelper& rData, SwWrtShell& rSh,
1762 ULONG nFmt, BYTE nActionFlags, BOOL bMsg )
1764 int nRet = 0;
1765 TransferableObjectDescriptor aObjDesc;
1766 uno::Reference < io::XInputStream > xStrm;
1767 uno::Reference < embed::XStorage > xStore;
1768 Reader* pRead = 0;
1770 // Get the preferred format
1771 SotFormatStringId nId;
1772 if( rData.HasFormat( SOT_FORMATSTR_ID_EMBEDDED_OBJ ) )
1773 nId = SOT_FORMATSTR_ID_EMBEDDED_OBJ;
1774 else if( rData.HasFormat( SOT_FORMATSTR_ID_EMBED_SOURCE ) &&
1775 rData.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ))
1776 nId = SOT_FORMATSTR_ID_EMBED_SOURCE;
1777 else
1778 nId = 0;
1780 if( nId && rData.GetInputStream( nId, xStrm ) && xStrm.is() )
1782 // if there is an embedded object, first try if it's a writer object
1783 // this will be inserted into the document by using a Reader
1786 xStore = comphelper::OStorageHelper::GetStorageFromInputStream( xStrm );
1787 switch( SotStorage::GetFormatID( xStore ) )
1789 case SOT_FORMATSTR_ID_STARWRITER_60:
1790 case SOT_FORMATSTR_ID_STARWRITERWEB_60:
1791 case SOT_FORMATSTR_ID_STARWRITERGLOB_60:
1792 case SOT_FORMATSTR_ID_STARWRITER_8:
1793 case SOT_FORMATSTR_ID_STARWRITERWEB_8:
1794 case SOT_FORMATSTR_ID_STARWRITERGLOB_8:
1795 pRead = ReadXML;
1796 break;
1797 default:
1800 uno::Reference < lang::XComponent > xComp( xStore, uno::UNO_QUERY );
1801 xComp->dispose();
1802 xStore = 0;
1804 catch ( uno::Exception& )
1808 break;
1811 catch ( uno::Exception& )
1813 // it wasn't a storage, but maybe it's a useful stream
1816 nFmt = nId;
1819 if( pRead )
1821 SwPaM &rPAM = *rSh.GetCrsr();
1822 SwReader aReader( xStore, aEmptyStr, rPAM );
1823 if( !IsError( aReader.Read( *pRead )) )
1824 nRet = 1;
1825 else if( bMsg )
1826 InfoBox( 0, SW_RES(ERR_CLPBRD_READ) ).Execute();
1828 else
1830 // temporary storage until the object is inserted
1831 uno::Reference< embed::XStorage > xTmpStor;
1832 uno::Reference < embed::XEmbeddedObject > xObj;
1833 ::rtl::OUString aName;
1834 comphelper::EmbeddedObjectContainer aCnt;
1836 if ( xStrm.is() )
1838 if ( !rData.GetTransferableObjectDescriptor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aObjDesc ) )
1840 DBG_ASSERT( !xStrm.is(), "An object without descriptor in clipboard!");
1843 else
1845 if( rData.HasFormat( nFmt = SOT_FORMATSTR_ID_OBJECTDESCRIPTOR_OLE ) && rData.GetTransferableObjectDescriptor( nFmt, aObjDesc ) )
1847 if ( !rData.GetInputStream( SOT_FORMATSTR_ID_EMBED_SOURCE_OLE, xStrm ) )
1848 rData.GetInputStream( SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE, xStrm );
1850 if ( !xStrm.is() )
1852 // This is MSOLE object that should be created by direct using of system clipboard
1855 xTmpStor = ::comphelper::OStorageHelper::GetTemporaryStorage();
1856 uno::Reference < embed::XEmbedObjectClipboardCreator > xClipboardCreator(
1857 ::comphelper::getProcessServiceFactory()->createInstance( ::rtl::OUString(
1858 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.MSOLEObjectSystemCreator")) ),
1859 uno::UNO_QUERY_THROW );
1861 embed::InsertedObjectInfo aInfo = xClipboardCreator->createInstanceInitFromClipboard(
1862 xTmpStor,
1863 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "DummyName" ) ),
1864 uno::Sequence< beans::PropertyValue >() );
1866 // TODO/LATER: in future InsertedObjectInfo will be used to get container related information
1867 // for example whether the object should be an iconified one
1868 xObj = aInfo.Object;
1870 catch( uno::Exception& )
1876 if ( xStrm.is() && !xObj.is() )
1877 xObj = aCnt.InsertEmbeddedObject( xStrm, aName );
1879 if( xObj.is() )
1881 svt::EmbeddedObjectRef xObjRef( xObj, aObjDesc.mnViewAspect );
1883 // try to get the replacement image from the clipboard
1884 Graphic aGraphic;
1885 ULONG nGrFormat = 0;
1887 // (wg. Selection Manager bei Trustet Solaris)
1888 #ifndef SOLARIS
1890 if( rData.GetGraphic( SOT_FORMATSTR_ID_SVXB, aGraphic ) )
1891 nGrFormat = SOT_FORMATSTR_ID_SVXB;
1892 else if( rData.GetGraphic( FORMAT_GDIMETAFILE, aGraphic ) )
1893 nGrFormat = SOT_FORMAT_GDIMETAFILE;
1894 else if( rData.GetGraphic( FORMAT_BITMAP, aGraphic ) )
1895 nGrFormat = SOT_FORMAT_BITMAP;
1897 #endif
1899 // insert replacement image ( if there is one ) into the object helper
1900 if ( nGrFormat )
1902 datatransfer::DataFlavor aDataFlavor;
1903 SotExchange::GetFormatDataFlavor( nGrFormat, aDataFlavor );
1904 xObjRef.SetGraphic( aGraphic, aDataFlavor.MimeType );
1906 else if ( aObjDesc.mnViewAspect == embed::Aspects::MSOLE_ICON )
1908 // it is important to have an icon, let an empty graphic be used
1909 // if no other graphic is provided
1910 // TODO/LATER: in future a default bitmap could be used
1911 ::rtl::OUString aMimeType;
1912 MapMode aMapMode( MAP_100TH_MM );
1913 aGraphic.SetPrefSize( Size( 2500, 2500 ) );
1914 aGraphic.SetPrefMapMode( aMapMode );
1915 xObjRef.SetGraphic( aGraphic, aMimeType );
1918 //Size einstellen. Ist ein Hack wg. Auslieferung, die Size sollte
1919 //an das InsertOle uebergeben werden!!!!!!!!!!
1920 Size aSize;
1921 if ( aObjDesc.mnViewAspect == embed::Aspects::MSOLE_ICON )
1923 if( aObjDesc.maSize.Width() && aObjDesc.maSize.Height() )
1924 aSize = aObjDesc.maSize;
1925 else
1927 MapMode aMapMode( MAP_100TH_MM );
1928 aSize = xObjRef.GetSize( &aMapMode );
1931 else if( aObjDesc.maSize.Width() && aObjDesc.maSize.Height() )
1933 aSize = Size( aObjDesc.maSize ); //immer 100TH_MM
1934 MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( aObjDesc.mnViewAspect ) );
1935 aSize = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aUnit );
1936 awt::Size aSz;
1939 aSz = xObj->getVisualAreaSize( aObjDesc.mnViewAspect );
1941 catch( embed::NoVisualAreaSizeException& )
1943 // in this case the provided size is used
1946 if ( aSz.Width != aSize.Width() || aSz.Height != aSize.Height() )
1948 aSz.Width = aSize.Width();
1949 aSz.Height = aSize.Height();
1950 xObj->setVisualAreaSize( aObjDesc.mnViewAspect, aSz );
1953 else
1955 // the descriptor contains the wrong object size
1956 // the following call will let the MSOLE objects cache the size if it is possible
1957 // it should be done while the object is running
1960 xObj->getVisualAreaSize( aObjDesc.mnViewAspect );
1962 catch( uno::Exception& )
1966 //Ende mit Hack!
1968 rSh.InsertOleObject( xObjRef );
1969 nRet = 1;
1971 if( nRet && ( nActionFlags &
1972 ( EXCHG_OUT_ACTION_FLAG_INSERT_TARGETURL >> 8) ))
1973 SwTransferable::_PasteTargetURL( rData, rSh, 0, 0, FALSE );
1975 // let the object be unloaded if possible
1976 SwOLEObj::UnloadObject( xObj, rSh.GetDoc(), embed::Aspects::MSOLE_CONTENT );
1979 return nRet;
1982 // -----------------------------------------------------------------------
1985 // -----------------------------------------------------------------------
1987 int SwTransferable::_PasteTargetURL( TransferableDataHelper& rData,
1988 SwWrtShell& rSh, USHORT nAction,
1989 const Point* pPt, BOOL bInsertGRF )
1991 int nRet = 0;
1992 INetImage aINetImg;
1993 if( ( rData.HasFormat( SOT_FORMATSTR_ID_INET_IMAGE ) &&
1994 rData.GetINetImage( SOT_FORMATSTR_ID_INET_IMAGE, aINetImg )) ||
1995 ( rData.HasFormat( SOT_FORMATSTR_ID_NETSCAPE_IMAGE ) &&
1996 rData.GetINetImage( SOT_FORMATSTR_ID_NETSCAPE_IMAGE, aINetImg )) )
1998 if( aINetImg.GetImageURL().Len() && bInsertGRF )
2000 String sURL( aINetImg.GetImageURL() );
2001 SwTransferable::_CheckForURLOrLNKFile( rData, sURL );
2003 //!!! auf FileSystem abpruefen - nur dann ist es sinnvoll die
2004 // Grafiken zu testen !!!!
2005 Graphic aGrf;
2006 GraphicFilter *pFlt = ::GetGrfFilter();
2007 nRet = GRFILTER_OK == ::LoadGraphic( sURL, aEmptyStr, aGrf, pFlt );
2008 if( nRet )
2010 switch( nAction )
2012 case SW_PASTESDR_INSERT:
2013 SwTransferable::SetSelInShell( rSh, FALSE, pPt );
2014 rSh.Insert( sURL, aEmptyStr, aGrf );
2015 break;
2017 case SW_PASTESDR_REPLACE:
2018 if( rSh.IsObjSelected() )
2020 rSh.ReplaceSdrObj( sURL, aEmptyStr, &aGrf );
2021 Point aPt( pPt ? *pPt : rSh.GetCrsrDocPos() );
2022 SwTransferable::SetSelInShell( rSh, TRUE, &aPt );
2024 else
2025 rSh.ReRead( sURL, aEmptyStr, &aGrf );
2026 break;
2028 case SW_PASTESDR_SETATTR:
2029 if( rSh.IsObjSelected() )
2030 rSh.Paste( aGrf );
2031 else if( OBJCNT_GRF == rSh.GetObjCntTypeOfSelection() )
2032 rSh.ReRead( sURL, aEmptyStr, &aGrf );
2033 else
2035 SwTransferable::SetSelInShell( rSh, FALSE, pPt );
2036 rSh.Insert( sURL, aEmptyStr, aGrf );
2038 break;
2039 default:
2040 nRet = 0;
2044 else
2045 nRet = 1;
2048 if( nRet )
2050 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
2051 rSh.GetFlyFrmAttr( aSet );
2052 SwFmtURL aURL( (SwFmtURL&)aSet.Get( RES_URL ) );
2054 if( aURL.GetURL() != aINetImg.GetTargetURL() ||
2055 aURL.GetTargetFrameName() != aINetImg.GetTargetFrame() )
2057 aURL.SetURL( aINetImg.GetTargetURL(), FALSE );
2058 aURL.SetTargetFrameName( aINetImg.GetTargetFrame() );
2059 aSet.Put( aURL );
2060 rSh.SetFlyFrmAttr( aSet );
2063 return nRet;
2067 // -----------------------------------------------------------------------
2069 void SwTransferable::SetSelInShell( SwWrtShell& rSh, BOOL bSelectFrm,
2070 const Point* pPt )
2072 if( bSelectFrm )
2074 // Rahmen/Objecte selektieren
2075 if( pPt && !rSh.GetView().GetViewFrame()->GetDispatcher()->IsLocked() )
2077 rSh.GetView().NoRotate();
2078 if( rSh.SelectObj( *pPt ))
2080 rSh.HideCrsr();
2081 rSh.EnterSelFrmMode( pPt );
2082 bFrmDrag = TRUE;
2086 else
2088 if( rSh.IsFrmSelected() || rSh.IsObjSelected() )
2090 rSh.UnSelectFrm();
2091 rSh.LeaveSelFrmMode();
2092 rSh.GetView().GetEditWin().StopInsFrm();
2093 bFrmDrag = FALSE;
2095 else if( rSh.GetView().GetDrawFuncPtr() )
2096 rSh.GetView().GetEditWin().StopInsFrm();
2098 rSh.EnterStdMode();
2099 if( pPt )
2100 rSh.SwCrsrShell::SetCrsr( *pPt, TRUE );
2104 // -----------------------------------------------------------------------
2106 int SwTransferable::_PasteDDE( TransferableDataHelper& rData,
2107 SwWrtShell& rWrtShell, BOOL bReReadGrf,
2108 BOOL bMsg )
2110 // Daten aus dem Clipboardformat
2111 String aApp, aTopic, aItem;
2114 SotStorageStreamRef xStrm;
2115 if( !rData.GetSotStorageStream( SOT_FORMATSTR_ID_LINK, xStrm ))
2117 ASSERT( !&rWrtShell, "DDE Data not found." );
2118 return 0;
2119 } //sinnvollen Fehler melden!!
2121 rtl_TextEncoding eEncoding = DDE_TXT_ENCODING;
2122 xStrm->ReadCString( aApp, eEncoding );
2123 xStrm->ReadCString( aTopic, eEncoding );
2124 xStrm->ReadCString( aItem, eEncoding );
2127 String aCmd;
2128 sfx2::MakeLnkName( aCmd, &aApp, aTopic, aItem );
2130 // wollen wir jetzt eine Grafik einlesen ?
2131 ULONG nFormat;
2132 if( !rData.HasFormat( FORMAT_RTF ) &&
2133 !rData.HasFormat( SOT_FORMATSTR_ID_HTML ) &&
2134 !rData.HasFormat( FORMAT_STRING ) &&
2135 (rData.HasFormat( nFormat = FORMAT_GDIMETAFILE ) ||
2136 rData.HasFormat( nFormat = FORMAT_BITMAP )) )
2138 Graphic aGrf;
2139 int nRet = rData.GetGraphic( nFormat, aGrf );
2140 if( nRet )
2142 String sLnkTyp( String::CreateFromAscii(
2143 RTL_CONSTASCII_STRINGPARAM( "DDE" )));
2144 if ( bReReadGrf )
2145 rWrtShell.ReRead( aCmd, sLnkTyp, &aGrf );
2146 else
2147 rWrtShell.Insert( aCmd, sLnkTyp, aGrf );
2149 return nRet;
2152 SwFieldType* pTyp = 0;
2153 USHORT i = 1,j;
2154 String aName;
2155 BOOL bAlreadyThere = FALSE, bDoublePaste = FALSE;
2156 USHORT nSize = rWrtShell.GetFldTypeCount();
2157 const ::utl::TransliterationWrapper& rColl = ::GetAppCmpStrIgnore();
2159 do {
2160 aName = aApp;
2161 aName += String::CreateFromInt32( i );
2162 for( j = INIT_FLDTYPES; j < nSize; j++ )
2164 pTyp = rWrtShell.GetFldType( j );
2165 if( RES_DDEFLD == pTyp->Which() )
2167 String sTmp( ((SwDDEFieldType*)pTyp)->GetCmd() );
2168 if( rColl.isEqual( sTmp, aCmd ) &&
2169 sfx2::LINKUPDATE_ALWAYS == ((SwDDEFieldType*)pTyp)->GetType() )
2171 aName = pTyp->GetName();
2172 bDoublePaste = TRUE;
2173 break;
2175 else if( rColl.isEqual( aName, pTyp->GetName() ) )
2176 break;
2179 if( j == nSize )
2180 bAlreadyThere = FALSE;
2181 else
2183 bAlreadyThere = TRUE;
2184 i++;
2187 while( bAlreadyThere && !bDoublePaste );
2189 if( !bDoublePaste )
2191 SwDDEFieldType aType( aName, aCmd, sfx2::LINKUPDATE_ALWAYS );
2192 pTyp = rWrtShell.InsertFldType( aType );
2196 SwDDEFieldType* pDDETyp = (SwDDEFieldType*)pTyp;
2198 String aExpand;
2199 if( rData.GetString( FORMAT_STRING, aExpand ))
2201 do { // middle checked loop
2203 // Wenn die Daten von einer Tabellenkalkulation kommen
2204 // fuegen wir eine DDE-Tabelle ein
2205 if( ( rData.HasFormat( SOT_FORMATSTR_ID_SYLK ) ||
2206 rData.HasFormat( SOT_FORMATSTR_ID_SYLK_BIGCAPS ) ) &&
2207 aExpand.Len() &&
2208 ( 1 < aExpand.GetTokenCount( '\n' ) ||
2209 aExpand.GetTokenCount( '\t' )) )
2211 String sTmp( aExpand );
2212 xub_StrLen nRows = sTmp.GetTokenCount( '\n' );
2213 if( nRows )
2214 --nRows;
2215 sTmp = sTmp.GetToken( 0, '\n' );
2216 xub_StrLen nCols = sTmp.GetTokenCount( '\t' );
2218 // mindestens eine Spalte & Zeile muss vorhanden sein
2219 if( !nRows || !nCols )
2221 if( bMsg )
2222 InfoBox(0, SW_RESSTR(STR_NO_TABLE)).Execute();
2223 pDDETyp = 0;
2224 break;
2227 rWrtShell.InsertDDETable(
2228 SwInsertTableOptions( tabopts::HEADLINE_NO_BORDER, 1 ), // TODO MULTIHEADER
2229 pDDETyp, nRows, nCols );
2231 else if( 1 < aExpand.GetTokenCount( '\n' ) )
2233 // mehrere Absaetze -> eine geschuetzte Section einfuegen
2234 if( rWrtShell.HasSelection() )
2235 rWrtShell.DelRight();
2237 SwSection aSect( DDE_LINK_SECTION, aName );
2238 aSect.SetLinkFileName( aCmd );
2239 aSect.SetProtect();
2240 rWrtShell.InsertSection( aSect );
2242 pDDETyp = 0; // FeldTypen wieder entfernen
2244 else
2246 // Einfuegen
2247 SwDDEField aSwDDEField( pDDETyp );
2248 rWrtShell.Insert( aSwDDEField );
2251 } while( FALSE );
2253 else
2254 pDDETyp = 0; // FeldTypen wieder entfernen
2256 if( !pDDETyp && !bDoublePaste )
2258 // FeldTyp wieder entfernen - Fehler aufgetreten!
2259 for( j = nSize; j >= INIT_FLDTYPES; --j )
2260 if( pTyp == rWrtShell.GetFldType( j ) )
2262 rWrtShell.RemoveFldType( j );
2263 break;
2267 return 1;
2270 // -----------------------------------------------------------------------
2272 int SwTransferable::_PasteSdrFormat( TransferableDataHelper& rData,
2273 SwWrtShell& rSh, USHORT nAction,
2274 const Point* pPt, BYTE nActionFlags )
2276 int nRet = 0;
2277 SotStorageStreamRef xStrm;
2278 if( rData.GetSotStorageStream( SOT_FORMATSTR_ID_DRAWING, xStrm ))
2280 xStrm->SetVersion( SOFFICE_FILEFORMAT_50 );
2281 rSh.Paste( *xStrm, nAction, pPt );
2282 nRet = 1;
2284 if( nRet && ( nActionFlags &
2285 ( EXCHG_OUT_ACTION_FLAG_INSERT_TARGETURL >> 8) ))
2286 SwTransferable::_PasteTargetURL( rData, rSh, 0, 0, FALSE );
2288 return nRet;
2291 // -----------------------------------------------------------------------
2293 int SwTransferable::_PasteGrf( TransferableDataHelper& rData, SwWrtShell& rSh,
2294 ULONG nFmt, USHORT nAction, const Point* pPt,
2295 BYTE nActionFlags, BOOL /*bMsg*/ )
2297 int nRet = 0;
2299 Graphic aGrf;
2300 INetBookmark aBkmk;
2301 BOOL bCheckForGrf = FALSE, bCheckForImageMap = FALSE;
2303 switch( nFmt )
2305 case SOT_FORMAT_BITMAP:
2306 case SOT_FORMAT_GDIMETAFILE:
2307 nRet = rData.GetGraphic( nFmt, aGrf );
2308 break;
2310 case SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK:
2311 case SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR:
2312 case SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR:
2313 if( 0 != ( nRet = rData.GetINetBookmark( nFmt, aBkmk ) ))
2315 /* if( SW_PASTESDR_SETATTR != nAction )
2317 INetURLObject aURL( aBkmk.GetURL() );
2318 bCheckForGrf = INET_PROT_FILE == aURL.GetProtocol();
2319 nRet = 0 != bCheckForGrf;
2322 if( SW_PASTESDR_SETATTR == nAction )
2323 nFmt = SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK;
2324 else
2325 bCheckForGrf = TRUE;
2327 break;
2329 case SOT_FORMAT_FILE:
2331 String sTxt;
2332 if( 0 != ( nRet = rData.GetString( nFmt, sTxt ) ) )
2334 String sDesc;
2335 SwTransferable::_CheckForURLOrLNKFile( rData, sTxt, &sDesc );
2337 aBkmk = INetBookmark(
2338 URIHelper::SmartRel2Abs(INetURLObject(), sTxt, Link(), false ),
2339 sDesc );
2340 bCheckForGrf = TRUE;
2341 bCheckForImageMap = SW_PASTESDR_REPLACE == nAction;
2344 break;
2346 default:
2347 nRet = rData.GetGraphic( nFmt, aGrf );
2348 break;
2351 if( bCheckForGrf )
2353 //!!! auf FileSystem abpruefen - nur dann ist es sinnvoll die
2354 // Grafiken zu testen !!!!
2355 GraphicFilter *pFlt = ::GetGrfFilter();
2356 nRet = GRFILTER_OK == ::LoadGraphic( aBkmk.GetURL(), aEmptyStr,
2357 aGrf, pFlt );
2358 if( !nRet && SW_PASTESDR_SETATTR == nAction &&
2359 SOT_FORMAT_FILE == nFmt &&
2360 // Bug 63031 - nur bei Rahmenselektion
2361 rSh.IsFrmSelected() )
2363 // dann als Hyperlink hinter die Grafik setzen
2364 nFmt = SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK;
2365 nRet = TRUE;
2369 if( nRet )
2371 String sURL;
2372 if( rSh.GetView().GetDocShell()->ISA(SwWebDocShell) )
2373 sURL = aBkmk.GetURL();
2375 switch( nAction )
2377 case SW_PASTESDR_INSERT:
2378 SwTransferable::SetSelInShell( rSh, FALSE, pPt );
2379 rSh.Insert( sURL, aEmptyStr, aGrf );
2380 break;
2382 case SW_PASTESDR_REPLACE:
2383 if( rSh.IsObjSelected() )
2385 rSh.ReplaceSdrObj( sURL, aEmptyStr, &aGrf );
2386 Point aPt( pPt ? *pPt : rSh.GetCrsrDocPos() );
2387 SwTransferable::SetSelInShell( rSh, TRUE, &aPt );
2389 else
2390 rSh.ReRead( sURL, aEmptyStr, &aGrf );
2391 break;
2393 case SW_PASTESDR_SETATTR:
2394 if( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK == nFmt )
2396 if( rSh.IsFrmSelected() )
2398 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
2399 rSh.GetFlyFrmAttr( aSet );
2400 SwFmtURL aURL( (SwFmtURL&)aSet.Get( RES_URL ) );
2401 aURL.SetURL( aBkmk.GetURL(), FALSE );
2402 aSet.Put( aURL );
2403 rSh.SetFlyFrmAttr( aSet );
2406 else if( rSh.IsObjSelected() )
2407 rSh.Paste( aGrf );
2408 else if( OBJCNT_GRF == rSh.GetObjCntTypeOfSelection() )
2409 rSh.ReRead( sURL, aEmptyStr, &aGrf );
2410 else
2412 SwTransferable::SetSelInShell( rSh, FALSE, pPt );
2413 rSh.Insert( aBkmk.GetURL(), aEmptyStr, aGrf );
2415 break;
2416 default:
2417 nRet = 0;
2421 if( nRet )
2424 if( nActionFlags &
2425 (( EXCHG_OUT_ACTION_FLAG_INSERT_IMAGEMAP |
2426 EXCHG_OUT_ACTION_FLAG_REPLACE_IMAGEMAP ) >> 8) )
2427 SwTransferable::_PasteImageMap( rData, rSh );
2429 if( nActionFlags &
2430 ( EXCHG_OUT_ACTION_FLAG_INSERT_TARGETURL >> 8) )
2431 SwTransferable::_PasteTargetURL( rData, rSh, 0, 0, FALSE );
2433 else if( bCheckForImageMap )
2435 // oder sollte das File ein ImageMap-File sein?
2436 ImageMap aMap;
2437 SfxMedium aMed( INetURLObject(aBkmk.GetURL()).GetFull(),
2438 STREAM_STD_READ, FALSE );
2439 SvStream* pStream = aMed.GetInStream();
2440 if( pStream != NULL &&
2441 !pStream->GetError() &&
2442 // mba: no BaseURL for clipboard functionality
2443 aMap.Read( *pStream, IMAP_FORMAT_DETECT, String() ) == IMAP_ERR_OK &&
2444 aMap.GetIMapObjectCount() )
2446 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
2447 rSh.GetFlyFrmAttr( aSet );
2448 SwFmtURL aURL( (SwFmtURL&)aSet.Get( RES_URL ) );
2449 aURL.SetMap( &aMap );
2450 aSet.Put( aURL );
2451 rSh.SetFlyFrmAttr( aSet );
2452 nRet = 1;
2456 return nRet;
2459 // -----------------------------------------------------------------------
2461 int SwTransferable::_PasteImageMap( TransferableDataHelper& rData,
2462 SwWrtShell& rSh )
2464 int nRet = 0;
2465 if( rData.HasFormat( SOT_FORMATSTR_ID_SVIM ))
2467 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
2468 rSh.GetFlyFrmAttr( aSet );
2469 SwFmtURL aURL( (SwFmtURL&)aSet.Get( RES_URL ) );
2470 const ImageMap* pOld = aURL.GetMap();
2472 // setzen oder ersetzen ist hier die Frage
2473 ImageMap aImageMap;
2474 if( rData.GetImageMap( SOT_FORMATSTR_ID_SVIM, aImageMap ) &&
2475 ( !pOld || aImageMap != *pOld ))
2477 aURL.SetMap( &aImageMap );
2478 aSet.Put( aURL );
2479 rSh.SetFlyFrmAttr( aSet );
2481 nRet = 1;
2483 return nRet;
2486 // -----------------------------------------------------------------------
2488 int SwTransferable::_PasteAsHyperlink( TransferableDataHelper& rData,
2489 SwWrtShell& rSh, ULONG nFmt )
2491 int nRet = 0;
2492 String sFile;
2493 if( rData.GetString( nFmt, sFile ) && sFile.Len() )
2495 String sDesc;
2496 SwTransferable::_CheckForURLOrLNKFile( rData, sFile, &sDesc );
2498 //#41801# ersteinmal die URL absolut machen
2499 INetURLObject aURL;
2500 aURL.SetSmartProtocol( INET_PROT_FILE );
2501 aURL.SetSmartURL( sFile );
2502 sFile = aURL.GetMainURL( INetURLObject::NO_DECODE );
2504 switch( rSh.GetObjCntTypeOfSelection() )
2506 case OBJCNT_FLY:
2507 case OBJCNT_GRF:
2508 case OBJCNT_OLE:
2510 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
2511 rSh.GetFlyFrmAttr( aSet );
2512 SwFmtURL aURL2( (SwFmtURL&)aSet.Get( RES_URL ) );
2513 aURL2.SetURL( sFile, FALSE );
2514 if( !aURL2.GetName().Len() )
2515 aURL2.SetName( sFile );
2516 aSet.Put( aURL2 );
2517 rSh.SetFlyFrmAttr( aSet );
2519 break;
2521 default:
2523 rSh.InsertURL( SwFmtINetFmt( sFile, aEmptyStr ),
2524 sDesc.Len() ? sDesc : sFile );
2527 nRet = TRUE;
2529 return nRet;
2532 // -----------------------------------------------------------------------
2534 int SwTransferable::_PasteFileName( TransferableDataHelper& rData,
2535 SwWrtShell& rSh, ULONG nFmt,
2536 USHORT nAction, const Point* pPt,
2537 BYTE nActionFlags, BOOL bMsg )
2539 int nRet = SwTransferable::_PasteGrf( rData, rSh, nFmt, nAction,
2540 pPt, nActionFlags, bMsg );
2541 if( nRet )
2542 nRet |= SWTRANSFER_GRAPHIC_INSERTED;
2543 if( !nRet )
2545 String sFile, sDesc;
2546 if( rData.GetString( nFmt, sFile ) && sFile.Len() )
2548 INetURLObject aMediaURL;
2550 aMediaURL.SetSmartURL( sFile );
2551 const String aMediaURLStr( aMediaURL.GetMainURL( INetURLObject::NO_DECODE ) );
2553 if( ::avmedia::MediaWindow::isMediaURL( aMediaURLStr ) )
2555 const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, aMediaURLStr );
2556 rSh.GetView().GetViewFrame()->GetDispatcher()->Execute(
2557 SID_INSERT_AVMEDIA, SFX_CALLMODE_SYNCHRON,
2558 &aMediaURLItem, 0L );
2560 else
2562 BOOL bIsURLFile = SwTransferable::_CheckForURLOrLNKFile( rData, sFile, &sDesc );
2564 //Eigenes FileFormat? -->Einfuegen, nicht fuer StarWriter/Web
2565 String sFileURL = URIHelper::SmartRel2Abs(INetURLObject(), sFile, Link(), false );
2566 const SfxFilter* pFlt = SW_PASTESDR_SETATTR == nAction
2567 ? 0 : SwIoSystem::GetFileFilter(
2568 sFileURL, aEmptyStr );
2569 if( pFlt && !rSh.GetView().GetDocShell()->ISA(SwWebDocShell)
2571 JP 02.07.98: warum nur fuer die Formate ??
2572 && ( pFlt->GetUserData() == FILTER_SW5 ||
2573 pFlt->GetUserData() == FILTER_SW4 ||
2574 pFlt->GetUserData() == FILTER_SW3 ||
2575 pFlt->GetUserData() == FILTER_SWG )
2579 // und dann per PostUser Event den Bereich-Einfuegen-Dialog hochreissen
2580 SwSection* pSect = new SwSection( FILE_LINK_SECTION,
2581 rSh.GetDoc()->GetUniqueSectionName() );
2582 pSect->SetLinkFileName( sFileURL );
2583 pSect->SetProtect( TRUE );
2585 Application::PostUserEvent( STATIC_LINK( &rSh, SwWrtShell,
2586 InsertRegionDialog ), pSect );
2587 nRet = 1;
2589 else if( SW_PASTESDR_SETATTR == nAction ||
2590 ( bIsURLFile && SW_PASTESDR_INSERT == nAction ))
2592 //Fremde Files koennen wir immerhin noch als Links
2593 //Einfuegen.
2595 //#41801# ersteinmal die URL absolut machen
2596 INetURLObject aURL;
2597 aURL.SetSmartProtocol( INET_PROT_FILE );
2598 aURL.SetSmartURL( sFile );
2599 sFile = aURL.GetMainURL( INetURLObject::NO_DECODE );
2601 switch( rSh.GetObjCntTypeOfSelection() )
2603 case OBJCNT_FLY:
2604 case OBJCNT_GRF:
2605 case OBJCNT_OLE:
2607 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
2608 rSh.GetFlyFrmAttr( aSet );
2609 SwFmtURL aURL2( (SwFmtURL&)aSet.Get( RES_URL ) );
2610 aURL2.SetURL( sFile, FALSE );
2611 if( !aURL2.GetName().Len() )
2612 aURL2.SetName( sFile );
2613 aSet.Put( aURL2 );
2614 rSh.SetFlyFrmAttr( aSet );
2616 break;
2618 default:
2620 rSh.InsertURL( SwFmtINetFmt( sFile, aEmptyStr ),
2621 sDesc.Len() ? sDesc : sFile );
2624 nRet = TRUE;
2629 return nRet;
2632 // -----------------------------------------------------------------------
2634 int SwTransferable::_PasteDBData( TransferableDataHelper& rData,
2635 SwWrtShell& rSh, ULONG nFmt, BOOL bLink,
2636 const Point* pDragPt, BOOL bMsg )
2638 int nRet = 0;
2639 String sTxt;
2640 if( rData.GetString( nFmt, sTxt ) && sTxt.Len() )
2642 USHORT nWh = SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE == nFmt
2644 : SOT_FORMATSTR_ID_SBA_DATAEXCHANGE == nFmt
2645 ? (bLink
2646 ? FN_QRY_MERGE_FIELD
2647 : FN_QRY_INSERT)
2648 : (bLink
2650 : FN_QRY_INSERT_FIELD );
2651 DataFlavorExVector& rVector = rData.GetDataFlavorExVector();
2652 sal_Bool bHaveColumnDescriptor = OColumnTransferable::canExtractColumnDescriptor(rVector, CTF_COLUMN_DESCRIPTOR | CTF_CONTROL_EXCHANGE);
2653 if ( SOT_FORMATSTR_ID_XFORMS == nFmt )
2655 SdrObject* pObj;
2656 rSh.MakeDrawView();
2657 FmFormView* pFmView = PTR_CAST( FmFormView, rSh.GetDrawView() );
2658 if(pFmView) {
2659 const OXFormsDescriptor &rDesc = OXFormsTransferable::extractDescriptor(rData);
2660 if(0 != (pObj = pFmView->CreateXFormsControl(rDesc)))
2661 rSh.SwFEShell::Insert( *pObj, 0, 0, pDragPt );
2664 else if( nWh )
2666 SfxUsrAnyItem* pConnectionItem = 0;
2667 SfxUsrAnyItem* pCursorItem = 0;
2668 SfxUsrAnyItem* pColumnItem = 0;
2669 SfxUsrAnyItem* pSourceItem = 0;
2670 SfxUsrAnyItem* pCommandItem = 0;
2671 SfxUsrAnyItem* pCommandTypeItem = 0;
2672 SfxUsrAnyItem* pColumnNameItem = 0;
2673 SfxUsrAnyItem* pSelectionItem = 0;
2675 BOOL bDataAvailable = TRUE;
2676 ODataAccessDescriptor aDesc;
2677 if(bHaveColumnDescriptor)
2678 aDesc = OColumnTransferable::extractColumnDescriptor(rData);
2679 else if(ODataAccessObjectTransferable::canExtractObjectDescriptor(rVector) )
2680 aDesc = ODataAccessObjectTransferable::extractObjectDescriptor(rData);
2681 else
2682 bDataAvailable = FALSE;
2684 if ( bDataAvailable )
2686 pConnectionItem = new SfxUsrAnyItem(FN_DB_CONNECTION_ANY, aDesc[daConnection]);
2687 pColumnItem = new SfxUsrAnyItem(FN_DB_COLUMN_ANY, aDesc[daColumnObject]);
2688 pSourceItem = new SfxUsrAnyItem(FN_DB_DATA_SOURCE_ANY, makeAny(aDesc.getDataSource()));
2689 pCommandItem = new SfxUsrAnyItem(FN_DB_DATA_COMMAND_ANY, aDesc[daCommand]);
2690 pCommandTypeItem = new SfxUsrAnyItem(FN_DB_DATA_COMMAND_TYPE_ANY, aDesc[daCommandType]);
2691 pColumnNameItem = new SfxUsrAnyItem(FN_DB_DATA_COLUMN_NAME_ANY, aDesc[daColumnName]);
2692 pSelectionItem = new SfxUsrAnyItem(FN_DB_DATA_SELECTION_ANY, aDesc[daSelection]);
2693 pCursorItem = new SfxUsrAnyItem(FN_DB_DATA_CURSOR_ANY, aDesc[daCursor]);
2696 SwView& rView = rSh.GetView();
2697 //force ::SelectShell
2698 rView.StopShellTimer();
2700 SfxStringItem aDataDesc( nWh, sTxt );
2701 rView.GetViewFrame()->GetDispatcher()->Execute(
2702 nWh, SFX_CALLMODE_ASYNCHRON, &aDataDesc,
2703 pConnectionItem, pColumnItem,
2704 pSourceItem, pCommandItem, pCommandTypeItem,
2705 pColumnNameItem, pSelectionItem, pCursorItem,0L);
2706 delete pConnectionItem;
2707 delete pColumnItem;
2708 delete pSourceItem;
2709 delete pCommandItem;
2710 delete pCommandTypeItem;
2711 delete pColumnNameItem;
2712 delete pCursorItem;
2714 else
2716 SdrObject* pObj;
2717 rSh.MakeDrawView();
2718 FmFormView* pFmView = PTR_CAST( FmFormView, rSh.GetDrawView() );
2719 if (pFmView && bHaveColumnDescriptor)
2721 if ( 0 != (pObj = pFmView->CreateFieldControl( OColumnTransferable::extractColumnDescriptor(rData) ) ) )
2722 rSh.SwFEShell::Insert( *pObj, 0, 0, pDragPt );
2725 nRet = 1;
2727 else if( bMsg )
2729 InfoBox( 0, SW_RES(MSG_CLPBRD_FORMAT_ERROR)).Execute();
2731 return nRet;
2734 // -----------------------------------------------------------------------
2736 int SwTransferable::_PasteFileList( TransferableDataHelper& rData,
2737 SwWrtShell& rSh, BOOL bLink,
2738 const Point* pPt, BOOL bMsg )
2740 int nRet = 0;
2741 FileList aFileList;
2742 if( rData.GetFileList( SOT_FORMAT_FILE_LIST, aFileList ) &&
2743 aFileList.Count() )
2745 USHORT nAct = bLink ? SW_PASTESDR_SETATTR : SW_PASTESDR_INSERT;
2746 String sFlyNm;
2747 // iterate over the filelist
2748 for( ULONG n = 0, nEnd = aFileList.Count(); n < nEnd; ++n )
2750 TransferDataContainer* pHlp = new TransferDataContainer;
2751 pHlp->CopyString( FORMAT_FILE, aFileList.GetFile( n ));
2752 TransferableDataHelper aData( pHlp );
2754 if( SwTransferable::_PasteFileName( aData, rSh, SOT_FORMAT_FILE, nAct,
2755 pPt, FALSE, bMsg ))
2757 if( bLink )
2759 sFlyNm = rSh.GetFlyName();
2760 SwTransferable::SetSelInShell( rSh, FALSE, pPt );
2762 nRet = 1;
2765 if( sFlyNm.Len() )
2766 rSh.GotoFly( sFlyNm );
2768 else if( bMsg )
2770 InfoBox( 0, SW_RES(MSG_CLPBRD_FORMAT_ERROR)).Execute();
2772 return nRet;
2775 // -----------------------------------------------------------------------
2777 BOOL SwTransferable::_CheckForURLOrLNKFile( TransferableDataHelper& rData,
2778 String& rFileName, String* pTitle )
2780 BOOL bIsURLFile = FALSE;
2781 INetBookmark aBkmk;
2782 if( rData.GetINetBookmark( SOT_FORMATSTR_ID_SOLK, aBkmk ) )
2784 rFileName = aBkmk.GetURL();
2785 if( pTitle )
2786 *pTitle = aBkmk.GetDescription();
2787 bIsURLFile = TRUE;
2789 else
2791 xub_StrLen nLen = rFileName.Len();
2792 if( 4 < nLen && '.' == rFileName.GetChar( nLen - 4 ))
2794 String sExt( rFileName.Copy( nLen - 3 ));
2795 if( sExt.EqualsIgnoreCaseAscii( "url" ))
2797 ASSERT( !&rFileName, "how do we read today .URL - Files?" );
2801 return bIsURLFile;
2804 // -----------------------------------------------------------------------
2806 BOOL SwTransferable::IsPasteSpecial( const SwWrtShell& rWrtShell,
2807 const TransferableDataHelper& rData )
2809 // we can paste-special if there's an entry in the paste-special-format list
2810 SvxClipboardFmtItem aClipboardFmtItem(0);
2811 FillClipFmtItem( rWrtShell, rData, aClipboardFmtItem);
2812 return aClipboardFmtItem.Count() > 0;
2815 // -----------------------------------------------------------------------
2817 int SwTransferable::PasteFormat( SwWrtShell& rSh,
2818 TransferableDataHelper& rData,
2819 ULONG nFormat )
2821 SwWait aWait( *rSh.GetView().GetDocShell(), FALSE );
2822 int nRet = 0;
2824 ULONG nPrivateFmt = FORMAT_PRIVATE;
2825 SwTransferable *pClipboard = SW_MOD()->pClipboard;
2826 if( pClipboard &&
2827 ((TRNSFR_DOCUMENT|TRNSFR_GRAPHIC|TRNSFR_OLE) & pClipboard->eBufferType ))
2828 nPrivateFmt = SOT_FORMATSTR_ID_EMBED_SOURCE;
2830 if( pClipboard && nPrivateFmt == nFormat )
2831 nRet = pClipboard->PrivatePaste( rSh );
2832 else if( rData.HasFormat( nFormat ) )
2834 uno::Reference<XTransferable> xTransferable( rData.GetXTransferable() );
2835 USHORT nEventAction,
2836 nDestination = SwTransferable::GetSotDestination( rSh ),
2837 nSourceOptions =
2838 (( EXCHG_DEST_DOC_TEXTFRAME == nDestination ||
2839 EXCHG_DEST_SWDOC_FREE_AREA == nDestination ||
2840 EXCHG_DEST_DOC_TEXTFRAME_WEB == nDestination ||
2841 EXCHG_DEST_SWDOC_FREE_AREA_WEB == nDestination )
2842 ? EXCHG_IN_ACTION_COPY
2843 : EXCHG_IN_ACTION_MOVE),
2844 nAction = SotExchange::GetExchangeAction(
2845 rData.GetDataFlavorExVector(),
2846 nDestination,
2847 nSourceOptions, /* ?? */
2848 EXCHG_IN_ACTION_DEFAULT, /* ?? */
2849 nFormat, nEventAction, nFormat,
2850 lcl_getTransferPointer ( xTransferable ) );
2852 if( EXCHG_INOUT_ACTION_NONE != nAction )
2853 nRet = SwTransferable::PasteData( rData, rSh, nAction, nFormat,
2854 nDestination, TRUE, FALSE );
2856 return nRet;
2859 // -----------------------------------------------------------------------
2861 int SwTransferable::_TestAllowedFormat( const TransferableDataHelper& rData,
2862 ULONG nFormat, USHORT nDestination )
2864 USHORT nAction = EXCHG_INOUT_ACTION_NONE, nEventAction;
2865 if( rData.HasFormat( nFormat )) {
2866 uno::Reference<XTransferable> xTransferable( rData.GetXTransferable() );
2867 nAction = SotExchange::GetExchangeAction(
2868 rData.GetDataFlavorExVector(),
2869 nDestination, EXCHG_IN_ACTION_COPY,
2870 EXCHG_IN_ACTION_COPY, nFormat,
2871 nEventAction, nFormat,
2872 lcl_getTransferPointer ( xTransferable ) );
2874 return EXCHG_INOUT_ACTION_NONE != nAction;
2877 // -----------------------------------------------------------------------
2880 * the list of formats which will be offered to the user in the 'Paste
2881 * Special...' dialog and the paste button menu
2883 static USHORT aPasteSpecialIds[] =
2885 SOT_FORMATSTR_ID_HTML,
2886 SOT_FORMATSTR_ID_HTML_SIMPLE,
2887 SOT_FORMATSTR_ID_HTML_NO_COMMENT,
2888 FORMAT_RTF,
2889 FORMAT_STRING,
2890 SOT_FORMATSTR_ID_SONLK,
2891 SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK,
2892 SOT_FORMATSTR_ID_DRAWING,
2893 SOT_FORMATSTR_ID_SVXB,
2894 FORMAT_GDIMETAFILE,
2895 FORMAT_BITMAP,
2896 SOT_FORMATSTR_ID_SVIM,
2897 SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR,
2902 int SwTransferable::PasteUnformatted( SwWrtShell& rSh, TransferableDataHelper& rData )
2904 // Plain text == unformatted
2905 return SwTransferable::PasteFormat( rSh, rData, SOT_FORMAT_STRING );
2908 // -----------------------------------------------------------------------
2910 int SwTransferable::PasteSpecial( SwWrtShell& rSh, TransferableDataHelper& rData, ULONG& rFormatUsed )
2912 int nRet = 0;
2913 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
2914 SfxAbstractPasteDialog* pDlg = pFact->CreatePasteDialog( &rSh.GetView().GetEditWin() );
2916 DataFlavorExVector aFormats( rData.GetDataFlavorExVector() );
2917 TransferableObjectDescriptor aDesc;
2919 USHORT nDest = SwTransferable::GetSotDestination( rSh );
2921 SwTransferable *pClipboard = SW_MOD()->pClipboard;
2922 if( pClipboard )
2924 aDesc = pClipboard->aObjDesc;
2925 USHORT nResId;
2926 if( pClipboard->eBufferType & TRNSFR_DOCUMENT )
2927 nResId = STR_PRIVATETEXT;
2928 else if( pClipboard->eBufferType & TRNSFR_GRAPHIC )
2929 nResId = STR_PRIVATEGRAPHIC;
2930 else if( pClipboard->eBufferType == TRNSFR_OLE )
2931 nResId = STR_PRIVATEOLE;
2932 else
2933 nResId = 0;
2935 if( nResId )
2937 if( STR_PRIVATEOLE == nResId || STR_PRIVATEGRAPHIC == nResId )
2939 // add SOT_FORMATSTR_ID_EMBED_SOURCE to the formats. This
2940 // format display then the private format name.
2941 DataFlavorEx aFlavorEx;
2942 aFlavorEx.mnSotId = SOT_FORMATSTR_ID_EMBED_SOURCE;
2943 aFormats.insert( aFormats.begin(), aFlavorEx );
2945 pDlg->SetObjName( pClipboard->aObjDesc.maClassName,
2946 SW_RES( nResId ) );
2947 pDlg->Insert( SOT_FORMATSTR_ID_EMBED_SOURCE, aEmptyStr );
2950 else
2952 if( rData.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) )
2953 rData.GetTransferableObjectDescriptor(
2954 SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aDesc );
2956 if( SwTransferable::_TestAllowedFormat( rData, SOT_FORMATSTR_ID_EMBED_SOURCE, nDest ))
2957 pDlg->Insert( SOT_FORMATSTR_ID_EMBED_SOURCE, aEmptyStr );
2958 if( SwTransferable::_TestAllowedFormat( rData, SOT_FORMATSTR_ID_LINK_SOURCE, nDest ))
2959 pDlg->Insert( SOT_FORMATSTR_ID_LINK_SOURCE, aEmptyStr );
2962 if( SwTransferable::_TestAllowedFormat( rData, SOT_FORMATSTR_ID_LINK, nDest ))
2963 pDlg->Insert( SOT_FORMATSTR_ID_LINK, SW_RES(STR_DDEFORMAT) );
2965 for( USHORT* pIds = aPasteSpecialIds; *pIds; ++pIds )
2966 if( SwTransferable::_TestAllowedFormat( rData, *pIds, nDest ))
2967 pDlg->Insert( *pIds, aEmptyStr );
2969 ULONG nFormat = pDlg->GetFormat( rData.GetTransferable() );
2971 if( nFormat )
2972 nRet = SwTransferable::PasteFormat( rSh, rData, nFormat );
2974 if ( nRet )
2975 rFormatUsed = nFormat;
2977 delete pDlg;
2978 return nRet;
2982 void SwTransferable::FillClipFmtItem( const SwWrtShell& rSh,
2983 const TransferableDataHelper& rData,
2984 SvxClipboardFmtItem & rToFill )
2986 USHORT nDest = SwTransferable::GetSotDestination( rSh );
2987 SwTransferable *pClipboard = SW_MOD()->pClipboard;
2988 if( pClipboard )
2990 USHORT nResId;
2991 if( pClipboard->eBufferType & TRNSFR_DOCUMENT )
2992 nResId = STR_PRIVATETEXT;
2993 else if( pClipboard->eBufferType & TRNSFR_GRAPHIC )
2994 nResId = STR_PRIVATEGRAPHIC;
2995 else if( pClipboard->eBufferType == TRNSFR_OLE )
2996 nResId = STR_PRIVATEOLE;
2997 else
2998 nResId = 0;
3000 if( nResId )
3001 rToFill.AddClipbrdFormat( SOT_FORMATSTR_ID_EMBED_SOURCE,
3002 SW_RES( nResId ) );
3004 else
3006 TransferableObjectDescriptor aDesc;
3007 if( rData.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) )
3008 ((TransferableDataHelper&)rData).GetTransferableObjectDescriptor(
3009 SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aDesc );
3011 if( SwTransferable::_TestAllowedFormat( rData, SOT_FORMATSTR_ID_EMBED_SOURCE, nDest ))
3012 rToFill.AddClipbrdFormat( SOT_FORMATSTR_ID_EMBED_SOURCE,
3013 aDesc.maTypeName );
3014 if( SwTransferable::_TestAllowedFormat( rData, SOT_FORMATSTR_ID_LINK_SOURCE, nDest ))
3015 rToFill.AddClipbrdFormat( SOT_FORMATSTR_ID_LINK_SOURCE );
3017 SotFormatStringId nFormat;
3018 if ( rData.HasFormat(nFormat = SOT_FORMATSTR_ID_EMBED_SOURCE_OLE) || rData.HasFormat(nFormat = SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE) )
3020 String sName,sSource;
3021 if ( SvPasteObjectHelper::GetEmbeddedName(rData,sName,sSource,nFormat) )
3022 rToFill.AddClipbrdFormat( nFormat, sName );
3026 if( SwTransferable::_TestAllowedFormat( rData, SOT_FORMATSTR_ID_LINK, nDest ))
3027 rToFill.AddClipbrdFormat( SOT_FORMATSTR_ID_LINK, SW_RES(STR_DDEFORMAT) );
3029 for( USHORT* pIds = aPasteSpecialIds; *pIds; ++pIds )
3030 if( SwTransferable::_TestAllowedFormat( rData, *pIds, nDest ))
3031 rToFill.AddClipbrdFormat( *pIds, aEmptyStr );
3034 void SwTransferable::SetDataForDragAndDrop( const Point& rSttPos )
3036 if(!pWrtShell)
3037 return;
3038 String sGrfNm;
3039 const int nSelection = pWrtShell->GetSelectionType();
3040 if( nsSelectionType::SEL_GRF == nSelection)
3042 AddFormat( SOT_FORMATSTR_ID_SVXB );
3043 // --> OD 2005-02-09 #119353# - robust
3044 const Graphic* pGrf = pWrtShell->GetGraphic();
3045 if ( pGrf && pGrf->IsSupportedGraphic() )
3046 // <--
3048 AddFormat( FORMAT_GDIMETAFILE );
3049 AddFormat( FORMAT_BITMAP );
3051 eBufferType = TRNSFR_GRAPHIC;
3052 pWrtShell->GetGrfNms( &sGrfNm, 0 );
3054 else if( nsSelectionType::SEL_OLE == nSelection )
3056 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
3057 PrepareOLE( aObjDesc );
3058 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
3059 AddFormat( FORMAT_GDIMETAFILE );
3060 eBufferType = TRNSFR_OLE;
3062 //Gibt es ueberhaupt etwas zum bereitstellen?
3063 else if ( pWrtShell->IsSelection() || pWrtShell->IsFrmSelected() ||
3064 pWrtShell->IsObjSelected() )
3066 if( pWrtShell->IsObjSelected() )
3067 eBufferType = TRNSFR_DRAWING;
3068 else
3070 eBufferType = TRNSFR_DOCUMENT;
3071 if( SwWrtShell::NO_WORD !=
3072 pWrtShell->IntelligentCut( nSelection, FALSE ))
3073 eBufferType = TransferBufferType( TRNSFR_DOCUMENT_WORD
3074 | eBufferType);
3077 if( nSelection & nsSelectionType::SEL_TBL_CELLS )
3078 eBufferType = (TransferBufferType)(TRNSFR_TABELLE | eBufferType);
3080 AddFormat( SOT_FORMATSTR_ID_EMBED_SOURCE );
3082 //RTF vor das Metafile von OLE stellen, weil mit weniger verlusten
3083 //behaftet.
3084 if( !pWrtShell->IsObjSelected() )
3086 AddFormat( FORMAT_RTF );
3087 AddFormat( SOT_FORMATSTR_ID_HTML );
3089 if( pWrtShell->IsSelection() )
3090 AddFormat( FORMAT_STRING );
3092 if( nSelection & ( nsSelectionType::SEL_DRW | nsSelectionType::SEL_DRW_FORM ))
3094 AddFormat( SOT_FORMATSTR_ID_DRAWING );
3095 if ( nSelection & nsSelectionType::SEL_DRW )
3097 AddFormat( FORMAT_GDIMETAFILE );
3098 AddFormat( FORMAT_BITMAP );
3100 eBufferType = (TransferBufferType)( TRNSFR_GRAPHIC | eBufferType );
3102 pClpGraphic = new Graphic;
3103 if( !pWrtShell->GetDrawObjGraphic( FORMAT_GDIMETAFILE, *pClpGraphic ))
3104 pOrigGrf = pClpGraphic;
3105 pClpBitmap = new Graphic;
3106 if( !pWrtShell->GetDrawObjGraphic( FORMAT_BITMAP, *pClpBitmap ))
3107 pOrigGrf = pClpBitmap;
3109 // ist es ein URL-Button ?
3110 String sURL, sDesc;
3111 if( pWrtShell->GetURLFromButton( sURL, sDesc ) )
3113 AddFormat( FORMAT_STRING );
3114 AddFormat( SOT_FORMATSTR_ID_SOLK );
3115 AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK );
3116 AddFormat( SOT_FORMATSTR_ID_FILECONTENT );
3117 AddFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR );
3118 AddFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR );
3119 eBufferType = (TransferBufferType)( TRNSFR_INETFLD | eBufferType );
3123 //ObjectDescriptor wurde bereits aus der alten DocShell gefuellt.
3124 //Jetzt noch anpassen. Dadurch kann im GetData die erste Anfrage
3125 //auch noch mit delayed rendering beantwortet werden.
3126 aObjDesc.mbCanLink = FALSE;
3127 aObjDesc.maDragStartPos = rSttPos;
3128 aObjDesc.maSize = OutputDevice::LogicToLogic( Size( OLESIZE ),
3129 MAP_TWIP, MAP_100TH_MM );
3130 PrepareOLE( aObjDesc );
3131 AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR );
3133 else if( nSelection & nsSelectionType::SEL_TXT && !pWrtShell->HasMark() )
3135 // ist nur ein Feld - Selektiert?
3136 SwContentAtPos aCntntAtPos( SwContentAtPos::SW_INETATTR );
3137 Point aPos( SwEditWin::GetDDStartPosX(), SwEditWin::GetDDStartPosY());
3139 if( pWrtShell->GetContentAtPos( aPos, aCntntAtPos ) )
3141 AddFormat( FORMAT_STRING );
3142 AddFormat( SOT_FORMATSTR_ID_SOLK );
3143 AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK );
3144 AddFormat( SOT_FORMATSTR_ID_FILECONTENT );
3145 AddFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR );
3146 AddFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR );
3147 eBufferType = TRNSFR_INETFLD;
3151 if( pWrtShell->IsFrmSelected() )
3153 SfxItemSet aSet( pWrtShell->GetAttrPool(), RES_URL, RES_URL );
3154 pWrtShell->GetFlyFrmAttr( aSet );
3155 const SwFmtURL& rURL = (SwFmtURL&)aSet.Get( RES_URL );
3156 if( rURL.GetMap() )
3158 pImageMap = new ImageMap( *rURL.GetMap() );
3159 AddFormat( SOT_FORMATSTR_ID_SVIM );
3161 else if( rURL.GetURL().Len() )
3163 pTargetURL = new INetImage( sGrfNm, rURL.GetURL(),
3164 rURL.GetTargetFrameName(),
3165 aEmptyStr, Size() );
3166 AddFormat( SOT_FORMATSTR_ID_INET_IMAGE );
3171 void SwTransferable::StartDrag( Window* pWin, const Point& rPos )
3173 if(!pWrtShell)
3174 return;
3175 bOldIdle = pWrtShell->GetViewOptions()->IsIdle();
3176 bCleanUp = TRUE;
3178 ((SwViewOption *)pWrtShell->GetViewOptions())->SetIdle( FALSE );
3180 if( pWrtShell->IsSelFrmMode() )
3181 pWrtShell->ShowCrsr();
3183 SW_MOD()->pDragDrop = this;
3185 SetDataForDragAndDrop( rPos );
3187 sal_Int8 nDragOptions = DND_ACTION_COPYMOVE | DND_ACTION_LINK;
3188 SwDocShell* pDShell = pWrtShell->GetView().GetDocShell();
3189 if( ( pDShell && pDShell->IsReadOnly() ) || pWrtShell->HasReadonlySel() )
3190 nDragOptions &= ~DND_ACTION_MOVE;
3192 TransferableHelper::StartDrag( pWin, nDragOptions );
3195 void SwTransferable::DragFinished( sal_Int8 nAction )
3197 //Und noch die letzten Nacharbeiten damit alle Stati stimmen.
3198 if( DND_ACTION_MOVE == nAction )
3200 if( bCleanUp )
3202 //Es wurde auserhalb des Writers gedroped. Wir muessen noch
3203 //loeschen.
3205 pWrtShell->StartAllAction();
3206 pWrtShell->StartUndo( UNDO_UI_DRAG_AND_MOVE );
3207 if ( pWrtShell->IsTableMode() )
3208 pWrtShell->DeleteTblSel();
3209 else
3211 if ( !(pWrtShell->IsSelFrmMode() || pWrtShell->IsObjSelected()) )
3212 //SmartCut, eines der Blanks mitnehmen.
3213 pWrtShell->IntelligentCut( pWrtShell->GetSelectionType(), TRUE );
3214 pWrtShell->DelRight();
3216 pWrtShell->EndUndo( UNDO_UI_DRAG_AND_MOVE );
3217 pWrtShell->EndAllAction();
3219 else
3221 const int nSelection = pWrtShell->GetSelectionType();
3222 if( ( nsSelectionType::SEL_FRM | nsSelectionType::SEL_GRF |
3223 nsSelectionType::SEL_OLE | nsSelectionType::SEL_DRW ) & nSelection )
3225 pWrtShell->EnterSelFrmMode();
3229 pWrtShell->GetView().GetEditWin().DragFinished();
3231 if( pWrtShell->IsSelFrmMode() )
3232 pWrtShell->HideCrsr();
3233 else
3234 pWrtShell->ShowCrsr();
3235 //!! else if( DND_ACTION_NONE != nAction )
3236 //!! pWrtShell->ShowCrsr();
3237 //!! else
3238 //!! {
3239 //!! //Muss wohl sein weil gescrollt wurde und ?...?
3240 //!! pWrtShell->StartAction();
3241 //!! pWrtShell->EndAction();
3242 //!! }
3244 ((SwViewOption *)pWrtShell->GetViewOptions())->SetIdle( bOldIdle );
3248 /* \f */
3250 int SwTransferable::PrivatePaste( SwWrtShell& rShell )
3252 // erst den SelectionType erfragen, dann Action-Klammerung !!!!
3253 // (sonst wird nicht in eine TabellenSelektion gepastet!!!)
3254 ASSERT( !rShell.ActionPend(), "Paste darf nie eine Actionklammerung haben" );
3255 if ( !pClpDocFac )
3256 return sal_False; // the return value of the SwFEShell::Paste also is BOOL!
3258 const int nSelection = rShell.GetSelectionType();
3260 // #111827#
3261 SwRewriter aRewriter;
3263 SwTrnsfrActionAndUndo aAction( &rShell, UNDO_PASTE_CLIPBOARD);
3265 bool bKillPaMs = false;
3267 //Selektierten Inhalt loeschen, nicht bei Tabellen-Selektion und
3268 //Tabelle im Clipboard
3269 if( rShell.HasSelection() && !( nSelection & nsSelectionType::SEL_TBL_CELLS))
3271 bKillPaMs = true;
3272 rShell.SetRetainSelection( true );
3273 rShell.DelRight();
3274 // war ein Fly selektiert, so muss jetzt fuer eine gueltige
3275 // Cursor-Position gesorgt werden! (geparkter Cursor!)
3276 if( ( nsSelectionType::SEL_FRM | nsSelectionType::SEL_GRF |
3277 nsSelectionType::SEL_OLE | nsSelectionType::SEL_DRW |
3278 nsSelectionType::SEL_DRW_FORM ) & nSelection )
3280 // den Cursor wieder positionieren
3281 Point aPt( rShell.GetCharRect().Pos() );
3282 rShell.SwCrsrShell::SetCrsr( aPt, TRUE );
3284 rShell.SetRetainSelection( false );
3287 BOOL bInWrd = FALSE, bEndWrd = FALSE, bSttWrd = FALSE,
3288 bSmart = 0 != (TRNSFR_DOCUMENT_WORD & eBufferType);
3289 if( bSmart )
3291 // #108491# Why not for other Scripts? If TRNSFR_DOCUMENT_WORD is set, we have
3292 // a word in the buffer, word in this context means 'something with spaces at
3293 // beginning and end'. In this case we definitely want these spaces to be inserted
3294 // here.
3295 // if( SCRIPTTYPE_LATIN != rShell.GetScriptType() )
3296 // bSmart = FALSE;
3297 // else
3298 // {
3299 bInWrd = rShell.IsInWrd();
3300 bEndWrd = rShell.IsEndWrd();
3301 bSmart = bInWrd || bEndWrd;
3302 if( bSmart )
3304 bSttWrd = rShell.IsSttWrd();
3305 if( bSmart && !bSttWrd && (bInWrd || bEndWrd) )
3306 rShell.SwEditShell::Insert(' ');
3308 // }
3311 int nRet = rShell.Paste( pClpDocFac->GetDoc() );
3313 if( bKillPaMs )
3314 rShell.KillPams();
3316 // Wenn Smart Paste dann Leerzeichen einfuegen
3317 if( nRet && bSmart && ((bInWrd && !bEndWrd )|| bSttWrd) )
3318 rShell.SwEditShell::Insert(' ');
3320 return nRet;
3323 int SwTransferable::PrivateDrop( SwWrtShell& rSh, const Point& rDragPt,
3324 BOOL bMove, BOOL bIsXSelection )
3326 int cWord = 0;
3327 BOOL bInWrd = FALSE;
3328 BOOL bEndWrd = FALSE;
3329 BOOL bSttWrd = FALSE;
3330 BOOL bSttPara= FALSE;
3331 BOOL bTblSel = FALSE;
3332 BOOL bFrmSel = FALSE;
3334 SwWrtShell& rSrcSh = *GetShell();
3336 rSh.UnSetVisCrsr();
3338 if( TRNSFR_INETFLD == eBufferType )
3340 if( rSh.GetFmtFromObj( rDragPt ) )
3342 INetBookmark aTmp;
3343 if( (TRNSFR_INETFLD & eBufferType) && pBkmk )
3344 aTmp = *pBkmk;
3346 // Zielgrafik selektieren
3347 if( rSh.SelectObj( rDragPt ) )
3349 rSh.HideCrsr();
3350 rSh.EnterSelFrmMode( &rDragPt );
3351 bFrmDrag = TRUE;
3354 const int nSelection = rSh.GetSelectionType();
3356 // Draw-Objekte erstmal noch nicht beruecksichtigen
3357 if( nsSelectionType::SEL_GRF & nSelection )
3359 SfxItemSet aSet( rSh.GetAttrPool(), RES_URL, RES_URL );
3360 rSh.GetFlyFrmAttr( aSet );
3361 SwFmtURL aURL( (SwFmtURL&)aSet.Get( RES_URL ) );
3362 aURL.SetURL( aTmp.GetURL(), FALSE );
3363 aSet.Put( aURL );
3364 rSh.SetFlyFrmAttr( aSet );
3365 return 1;
3368 if( nsSelectionType::SEL_DRW & nSelection )
3370 rSh.LeaveSelFrmMode();
3371 rSh.UnSelectFrm();
3372 rSh.ShowCrsr();
3373 bFrmDrag = FALSE;
3378 if( &rSh != &rSrcSh && (nsSelectionType::SEL_GRF & rSh.GetSelectionType()) &&
3379 TRNSFR_GRAPHIC == eBufferType )
3381 // ReRead auf die Grafik
3382 String sGrfNm, sFltNm;
3383 rSrcSh.GetGrfNms( &sGrfNm, &sFltNm );
3384 rSh.ReRead( sGrfNm, sFltNm, rSrcSh.GetGraphic() );
3385 return 1;
3388 //Nicht in Selektionen oder selektierten Rahmen
3389 if( rSh.ChgCurrPam( rDragPt ) ||
3390 ( rSh.IsSelFrmMode() && rSh.IsInsideSelectedObj( rDragPt )) )
3391 return 0;
3393 if( rSrcSh.IsTableMode() )
3394 bTblSel = TRUE;
3395 else if( rSrcSh.IsSelFrmMode() || rSrcSh.IsObjSelected() )
3397 // keine positionsgeschuetzten Objecte verschieben!
3398 if( bMove && rSrcSh.IsSelObjProtected( FLYPROTECT_POS ) )
3399 return 0;
3401 bFrmSel = TRUE;
3404 const int nSel = rSrcSh.GetSelectionType();
3406 SwUndoId eUndoId = bMove ? UNDO_UI_DRAG_AND_MOVE : UNDO_UI_DRAG_AND_COPY;
3408 // #111827#
3409 SwRewriter aRewriter;
3411 aRewriter.AddRule(UNDO_ARG1, rSrcSh.GetSelDescr());
3413 if(rSrcSh.GetDoc() != rSh.GetDoc())
3414 rSrcSh.StartUndo( eUndoId, &aRewriter );
3415 rSh.StartUndo( eUndoId, &aRewriter );
3417 rSh.StartAction();
3418 rSrcSh.StartAction();
3420 if( &rSrcSh != &rSh )
3422 rSh.EnterStdMode();
3423 rSh.SwCrsrShell::SetCrsr( rDragPt, TRUE );
3424 cWord = rSrcSh.IntelligentCut( nSel, FALSE );
3426 else if( !bTblSel && !bFrmSel )
3428 if( !rSh.IsAddMode() )
3430 // --> OD 2008-03-19 #i87233#
3431 if ( rSh.IsBlockMode() )
3433 // preserve order of cursors for block mode
3434 rSh.GoPrevCrsr();
3436 // <--
3437 rSh.SwCrsrShell::CreateCrsr();
3439 rSh.SwCrsrShell::SetCrsr( rDragPt, TRUE, false );
3440 rSh.GoPrevCrsr();
3441 cWord = rSh.IntelligentCut( rSh.GetSelectionType(), FALSE );
3442 rSh.GoNextCrsr();
3445 bInWrd = rSh.IsInWrd();
3446 bEndWrd = rSh.IsEndWrd();
3447 bSttWrd = !bEndWrd && rSh.IsSttWrd();
3448 bSttPara= rSh.IsSttPara();
3450 Point aSttPt( SwEditWin::GetDDStartPosX(), SwEditWin::GetDDStartPosY() );
3452 //JP 05.03.96: INetFelder erstmal selektieren !
3453 if( TRNSFR_INETFLD == eBufferType )
3455 if( &rSrcSh == &rSh )
3457 rSh.GoPrevCrsr();
3458 rSh.SwCrsrShell::SetCrsr( aSttPt, TRUE );
3459 rSh.SelectTxtAttr( RES_TXTATR_INETFMT );
3460 if( rSh.ChgCurrPam( rDragPt ) )
3462 // nicht in sich selbst kopieren/verschieben
3463 rSh.DestroyCrsr();
3464 rSh.EndUndo( eUndoId );
3465 rSh.EndAction();
3466 rSh.EndAction();
3467 return 0;
3469 rSh.GoNextCrsr();
3471 else
3473 rSrcSh.SwCrsrShell::SetCrsr( aSttPt, TRUE );
3474 rSrcSh.SelectTxtAttr( RES_TXTATR_INETFMT );
3477 // ist am Einfuege Punkt ein URL-Attribut? Dann das ersetzen,
3478 // also einfach eine Selektion aufspannen?
3479 rSh.DelINetAttrWithText();
3480 bDDINetAttr = TRUE;
3483 if ( rSrcSh.IsSelFrmMode() )
3485 //Hack: Spezialbehandlung austricksen
3486 aSttPt -= aSttPt - rSrcSh.GetObjRect().Pos();
3489 BOOL bRet = rSrcSh.SwFEShell::Copy( &rSh, aSttPt, rDragPt, bMove,
3490 !bIsXSelection );
3492 if( !bIsXSelection )
3494 rSrcSh.Push();
3495 if ( bRet && bMove && !bFrmSel )
3497 if ( bTblSel )
3499 /* #109590# delete table contents not cells */
3500 rSrcSh.Delete();
3502 else
3504 //SmartCut, eines der Blank mitnehmen.
3505 rSh.SwCrsrShell::DestroyCrsr();
3506 if ( cWord == SwWrtShell::WORD_SPACE_BEFORE )
3507 rSh.ExtendSelection( FALSE );
3508 else if ( cWord == SwWrtShell::WORD_SPACE_AFTER )
3509 rSh.ExtendSelection();
3510 rSrcSh.DelRight();
3513 rSrcSh.KillPams();
3514 rSrcSh.Pop( FALSE );
3516 /* #109590# after dragging a table selection inside one shell
3517 set cursor to the drop position. */
3518 if( &rSh == &rSrcSh && ( bTblSel || rSh.IsBlockMode() ) )
3520 rSrcSh.SwCrsrShell::SetCrsr(rDragPt);
3521 rSrcSh.GetSwCrsr()->SetMark();
3525 if( bRet && !bTblSel && !bFrmSel )
3527 if( (bInWrd || bEndWrd) &&
3528 (cWord == SwWrtShell::WORD_SPACE_AFTER ||
3529 cWord == SwWrtShell::WORD_SPACE_BEFORE) )
3531 if ( bSttWrd || (bInWrd && !bEndWrd))
3532 rSh.SwEditShell::Insert(' ', bIsXSelection);
3533 if ( !bSttWrd || (bInWrd && !bSttPara) )
3535 rSh.SwapPam();
3536 if ( !bSttWrd )
3537 rSh.SwEditShell::Insert(' ', bIsXSelection);
3538 rSh.SwapPam();
3542 if( bIsXSelection )
3544 if( &rSrcSh == &rSh && !rSh.IsAddMode() )
3546 rSh.SwCrsrShell::DestroyCrsr();
3547 rSh.GoPrevCrsr();
3549 else
3551 rSh.SwapPam();
3552 rSh.SwCrsrShell::ClearMark();
3555 else
3557 if( rSh.IsAddMode() )
3558 rSh.SwCrsrShell::CreateCrsr();
3559 else
3561 // Selektionsmodus einschalten
3562 rSh.SttSelect();
3563 rSh.EndSelect();
3568 if( bRet && bMove && bFrmSel )
3569 rSrcSh.LeaveSelFrmMode();
3571 if( rSrcSh.GetDoc() != rSh.GetDoc() )
3572 rSrcSh.EndUndo( eUndoId );
3573 rSh.EndUndo( eUndoId );
3575 // Shell in den richtigen Status versetzen
3576 if( &rSrcSh != &rSh && ( rSh.IsFrmSelected() || rSh.IsObjSelected() ))
3577 rSh.EnterSelFrmMode();
3579 rSrcSh.EndAction();
3580 rSh.EndAction();
3581 return 1;
3584 // Interfaces for Selection
3585 void SwTransferable::CreateSelection( SwWrtShell& rSh,
3586 const ViewShell * _pCreatorView )
3588 SwModule *pMod = SW_MOD();
3589 SwTransferable* pNew = new SwTransferable( rSh );
3591 /* #96392#*/
3592 pNew->pCreatorView = _pCreatorView;
3594 uno::Reference<
3595 datatransfer::XTransferable > xRef( pNew );
3596 pMod->pXSelection = pNew;
3597 pNew->CopyToSelection( rSh.GetWin() );
3600 void SwTransferable::ClearSelection( SwWrtShell& rSh,
3601 const ViewShell * _pCreatorView)
3603 SwModule *pMod = SW_MOD();
3604 if( pMod->pXSelection &&
3605 ((!pMod->pXSelection->pWrtShell) || (pMod->pXSelection->pWrtShell == &rSh)) &&
3606 /* #96392# */
3607 (!_pCreatorView || (pMod->pXSelection->pCreatorView == _pCreatorView)) )
3609 TransferableHelper::ClearSelection( rSh.GetWin() );
3612 /* -----------------3/31/2003 11:46AM----------------
3614 --------------------------------------------------*/
3615 const Sequence< sal_Int8 >& SwTransferable::getUnoTunnelId()
3617 static Sequence< sal_Int8 > aSeq;
3618 if( !aSeq.getLength() )
3620 static osl::Mutex aCreateMutex;
3621 osl::Guard< osl::Mutex > aGuard( aCreateMutex );
3622 aSeq.realloc( 16 );
3623 rtl_createUuid( reinterpret_cast< sal_uInt8* >( aSeq.getArray() ), 0, sal_True );
3625 return aSeq;
3627 /* -----------------3/31/2003 11:46AM----------------
3629 --------------------------------------------------*/
3630 sal_Int64 SwTransferable::getSomething( const Sequence< sal_Int8 >& rId ) throw( RuntimeException )
3632 sal_Int64 nRet;
3633 if( ( rId.getLength() == 16 ) &&
3634 ( 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
3636 nRet = sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ) );
3638 else
3639 nRet = TransferableHelper::getSomething(rId);
3640 return nRet;
3643 /* \f */
3645 // -----------------------------------------------------------------------
3647 SwTrnsfrDdeLink::SwTrnsfrDdeLink( SwTransferable& rTrans, SwWrtShell& rSh )
3648 : rTrnsfr( rTrans ), pDocShell( 0 ),
3649 bDelBookmrk( FALSE ), bInDisconnect( FALSE )
3651 // hier kommen wir nur bei Tabellen- oder Text-Selection an
3652 const int nSelection = rSh.GetSelectionType();
3653 if( nsSelectionType::SEL_TBL_CELLS & nSelection )
3655 SwFrmFmt* pFmt = rSh.GetTableFmt();
3656 if( pFmt )
3657 sName = pFmt->GetName();
3659 else
3661 // creating a temp. bookmark without undo
3662 BOOL bUndo = rSh.DoesUndo();
3663 rSh.DoUndo( FALSE );
3664 BOOL bIsModified = rSh.IsModified();
3666 ::sw::mark::IMark* pMark = rSh.SetBookmark(
3667 KeyCode(),
3668 ::rtl::OUString(),
3669 ::rtl::OUString(),
3670 IDocumentMarkAccess::DDE_BOOKMARK);
3671 if(pMark)
3673 sName = pMark->GetName();
3674 bDelBookmrk = TRUE;
3675 if( !bIsModified )
3676 rSh.ResetModified();
3678 else
3679 sName.Erase();
3680 rSh.DoUndo( bUndo );
3683 if( sName.Len() &&
3684 0 != ( pDocShell = rSh.GetDoc()->GetDocShell() ) )
3686 // dann erzeugen wir uns mal unseren "Server" und connecten uns
3687 // zu diesem
3688 refObj = pDocShell->DdeCreateLinkSource( sName );
3689 if( refObj.Is() )
3691 refObj->AddConnectAdvise( this );
3692 refObj->AddDataAdvise( this,
3693 // SotExchange::GetFormatMimeType( FORMAT_RTF ),
3694 aEmptyStr,
3695 ADVISEMODE_NODATA | ADVISEMODE_ONLYONCE );
3696 nOldTimeOut = refObj->GetUpdateTimeout();
3697 refObj->SetUpdateTimeout( 0 );
3702 // -----------------------------------------------------------------------
3704 SwTrnsfrDdeLink::~SwTrnsfrDdeLink()
3706 if( refObj.Is() )
3707 Disconnect( TRUE );
3710 // -----------------------------------------------------------------------
3712 void SwTrnsfrDdeLink::DataChanged( const String& ,
3713 const uno::Any& )
3715 // tja das wars dann mit dem Link
3716 if( !bInDisconnect )
3718 if( FindDocShell() && pDocShell->GetView() )
3719 rTrnsfr.RemoveDDELinkFormat( pDocShell->GetView()->GetEditWin() );
3720 Disconnect( FALSE );
3724 // -----------------------------------------------------------------------
3726 BOOL SwTrnsfrDdeLink::WriteData( SvStream& rStrm )
3728 if( !refObj.Is() || !FindDocShell() )
3729 return FALSE;
3731 rtl_TextEncoding eEncoding = DDE_TXT_ENCODING;
3732 const ByteString aAppNm( GetpApp()->GetAppName(), eEncoding );
3733 const ByteString aTopic( pDocShell->GetTitle( SFX_TITLE_FULLNAME ),
3734 eEncoding );
3735 const ByteString aName( sName, eEncoding );
3737 sal_Char* pMem = new char[ aAppNm.Len() + aTopic.Len() + aName.Len() + 4 ];
3739 xub_StrLen nLen = aAppNm.Len();
3740 memcpy( pMem, aAppNm.GetBuffer(), nLen );
3741 pMem[ nLen++ ] = 0;
3742 memcpy( pMem + nLen, aTopic.GetBuffer(), aTopic.Len() );
3743 nLen = nLen + aTopic.Len();
3744 pMem[ nLen++ ] = 0;
3745 memcpy( pMem + nLen, aName.GetBuffer(), aName.Len() );
3746 nLen = nLen + aName.Len();
3747 pMem[ nLen++ ] = 0;
3748 pMem[ nLen++ ] = 0;
3750 rStrm.Write( pMem, nLen );
3751 delete[] pMem;
3753 //if( bDelBookmrk )
3755 // // er wird das erstemal abgeholt, also ins Undo mitaufnehmen
3756 // // aber wie??
3759 IDocumentMarkAccess* const pMarkAccess = pDocShell->GetDoc()->getIDocumentMarkAccess();
3760 IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->findMark(sName);
3761 if(ppMark != pMarkAccess->getMarksEnd()
3762 && IDocumentMarkAccess::GetType(**ppMark) != IDocumentMarkAccess::BOOKMARK)
3764 // the mark is still a DdeBookmark
3765 // we replace it with a Bookmark, so it will get saved etc.
3766 ::sw::mark::IMark* const pMark = ppMark->get();
3767 SwServerObject* const pServerObject = dynamic_cast<SwServerObject *>(&refObj);
3769 // collecting state of old mark
3770 SwPaM aPaM(pMark->GetMarkStart());
3771 *aPaM.GetPoint() = pMark->GetMarkStart();
3772 if(pMark->IsExpanded())
3774 aPaM.SetMark();
3775 *aPaM.GetMark() = pMark->GetMarkEnd();
3777 ::rtl::OUString sMarkName = pMark->GetName();
3779 // remove mark
3780 pServerObject->SetNoServer(); // this removes the connection between SwServerObject and mark
3781 // N.B. ppMark was not loaded from file and cannot have xml:id
3782 pMarkAccess->deleteMark(ppMark);
3784 // recreate as Bookmark
3785 ::sw::mark::IMark* const pNewMark = pMarkAccess->makeMark(
3786 aPaM,
3787 sMarkName,
3788 IDocumentMarkAccess::BOOKMARK);
3789 pServerObject->SetDdeBookmark(*pNewMark);
3792 bDelBookmrk = false;
3793 return true;
3796 // -----------------------------------------------------------------------
3798 void SwTrnsfrDdeLink::Disconnect( BOOL bRemoveDataAdvise )
3800 //JP 29.01.96 Bug 24432:
3801 // kein DataChanged mehr entgegen nehmen, wenn man
3802 // sich schon im Disconnet befindet!
3803 // (DTOR vom Bookmark verschickt einen DataChanged!)
3804 BOOL bOldDisconnect = bInDisconnect;
3805 bInDisconnect = TRUE;
3807 // den nicht verwendeten Bookmark wieder zerstoeren (ohne Undo!)?
3808 if( bDelBookmrk && refObj.Is() && FindDocShell() )
3810 SwDoc* pDoc = pDocShell->GetDoc();
3811 BOOL bUndo = pDoc->DoesUndo();
3812 pDoc->DoUndo( FALSE );
3814 // --> OD, CD, OS 2005-11-25 #i58448#
3815 Link aSavedOle2Link( pDoc->GetOle2Link() );
3816 pDoc->SetOle2Link( Link() );
3817 // <--
3818 BOOL bIsModified = pDoc->IsModified();
3820 IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
3821 pMarkAccess->deleteMark(pMarkAccess->findMark(sName));
3823 if( !bIsModified )
3824 pDoc->ResetModified();
3825 // --> OD, CD, OS 2005-11-25 #i58448#
3826 pDoc->SetOle2Link( aSavedOle2Link );
3827 // <--
3829 pDoc->DoUndo( bUndo );
3830 bDelBookmrk = FALSE;
3833 if( refObj.Is() )
3835 refObj->SetUpdateTimeout( nOldTimeOut );
3836 refObj->RemoveConnectAdvise( this );
3837 if( bRemoveDataAdvise )
3838 // in einem DataChanged darf das SelectionObject NIE geloescht
3839 // werden; wird schon von der Basisklasse erledigt
3840 // (ADVISEMODE_ONLYONCE!!!!)
3841 // Im normalen Disconnet aber schon!
3842 refObj->RemoveAllDataAdvise( this );
3843 refObj.Clear();
3845 bInDisconnect = bOldDisconnect;
3848 // -----------------------------------------------------------------------
3850 BOOL SwTrnsfrDdeLink::FindDocShell()
3852 TypeId aType( TYPE( SwDocShell ) );
3853 SfxObjectShell* pTmpSh = SfxObjectShell::GetFirst( &aType );
3854 while( pTmpSh )
3856 if( pTmpSh == pDocShell ) // die wollen wir haben
3858 if( pDocShell->GetDoc() )
3859 return TRUE;
3860 break; // das Doc ist nicht mehr vorhanden, also raus!
3862 pTmpSh = SfxObjectShell::GetNext( *pTmpSh, &aType );
3865 pDocShell = 0;
3866 return FALSE;
3869 // -----------------------------------------------------------------------
3871 void SwTrnsfrDdeLink::Closed()
3873 if( !bInDisconnect && refObj.Is() )
3875 refObj->RemoveAllDataAdvise( this );
3876 refObj->RemoveConnectAdvise( this );
3877 refObj.Clear();