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