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