1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_svtools.hxx" 30*cdf0e10cSrcweir #include <vos/mutex.hxx> 31*cdf0e10cSrcweir #include <tools/debug.hxx> 32*cdf0e10cSrcweir #include <tools/urlobj.hxx> 33*cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx> 34*cdf0e10cSrcweir #include <sot/exchange.hxx> 35*cdf0e10cSrcweir #include <sot/storage.hxx> 36*cdf0e10cSrcweir #include <vcl/bitmap.hxx> 37*cdf0e10cSrcweir #include <vcl/gdimtf.hxx> 38*cdf0e10cSrcweir #include <vcl/graph.hxx> 39*cdf0e10cSrcweir #include <vcl/svapp.hxx> 40*cdf0e10cSrcweir #include <vcl/window.hxx> 41*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 42*cdf0e10cSrcweir #include <com/sun/star/datatransfer/dnd/XDropTargetDragContext.hpp> 43*cdf0e10cSrcweir #include "svl/urlbmk.hxx" 44*cdf0e10cSrcweir #include <svtools/inetimg.hxx> 45*cdf0e10cSrcweir #include <svtools/imap.hxx> 46*cdf0e10cSrcweir #include <svtools/transfer.hxx> 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir // -------------- 49*cdf0e10cSrcweir // - Namespaces - 50*cdf0e10cSrcweir // -------------- 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 53*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 54*cdf0e10cSrcweir using namespace ::com::sun::star::io; 55*cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer; 56*cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer::clipboard; 57*cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer::dnd; 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir // ----------------------------------------- 60*cdf0e10cSrcweir // - DragSourceHelper::DragGestureListener - 61*cdf0e10cSrcweir // ----------------------------------------- 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir DragSourceHelper::DragGestureListener::DragGestureListener( DragSourceHelper& rDragSourceHelper ) : 64*cdf0e10cSrcweir mrParent( rDragSourceHelper ) 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir DragSourceHelper::DragGestureListener::~DragGestureListener() 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir void SAL_CALL DragSourceHelper::DragGestureListener::disposing( const EventObject& ) throw( RuntimeException ) 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir void SAL_CALL DragSourceHelper::DragGestureListener::dragGestureRecognized( const DragGestureEvent& rDGE ) throw( RuntimeException ) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir const Point aPtPixel( rDGE.DragOriginX, rDGE.DragOriginY ); 87*cdf0e10cSrcweir mrParent.StartDrag( rDGE.DragAction, aPtPixel ); 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir // -------------------- 91*cdf0e10cSrcweir // - DragSourceHelper - 92*cdf0e10cSrcweir // -------------------- 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir DragSourceHelper::DragSourceHelper( Window* pWindow ) : 95*cdf0e10cSrcweir mxDragGestureRecognizer( pWindow->GetDragGestureRecognizer() ) 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir if( mxDragGestureRecognizer.is() ) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir mxDragGestureListener = new DragSourceHelper::DragGestureListener( *this ); 100*cdf0e10cSrcweir mxDragGestureRecognizer->addDragGestureListener( mxDragGestureListener ); 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir DragSourceHelper::~DragSourceHelper() 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir if( mxDragGestureRecognizer.is() ) 109*cdf0e10cSrcweir mxDragGestureRecognizer->removeDragGestureListener( mxDragGestureListener ); 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir void DragSourceHelper::StartDrag( sal_Int8, const Point& ) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir // ---------------------------------------- 119*cdf0e10cSrcweir // - DropTargetHelper::DropTargetListener - 120*cdf0e10cSrcweir // ---------------------------------------- 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir DropTargetHelper::DropTargetListener::DropTargetListener( DropTargetHelper& rDropTargetHelper ) : 123*cdf0e10cSrcweir mrParent( rDropTargetHelper ), 124*cdf0e10cSrcweir mpLastDragOverEvent( NULL ) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir DropTargetHelper::DropTargetListener::~DropTargetListener() 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir delete mpLastDragOverEvent; 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir void SAL_CALL DropTargetHelper::DropTargetListener::disposing( const EventObject& ) throw( RuntimeException ) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir void SAL_CALL DropTargetHelper::DropTargetListener::drop( const DropTargetDropEvent& rDTDE ) throw( RuntimeException ) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir try 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir AcceptDropEvent aAcceptEvent; 150*cdf0e10cSrcweir ExecuteDropEvent aExecuteEvt( rDTDE.DropAction & ~DNDConstants::ACTION_DEFAULT, Point( rDTDE.LocationX, rDTDE.LocationY ), rDTDE ); 151*cdf0e10cSrcweir sal_Int8 nRet = DNDConstants::ACTION_NONE; 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir aExecuteEvt.mbDefault = ( ( rDTDE.DropAction & DNDConstants::ACTION_DEFAULT ) != 0 ); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir // in case of a default action, call ::AcceptDrop first and use the returned 156*cdf0e10cSrcweir // accepted action as the execute action in the call to ::ExecuteDrop 157*cdf0e10cSrcweir aAcceptEvent.mnAction = aExecuteEvt.mnAction; 158*cdf0e10cSrcweir aAcceptEvent.maPosPixel = aExecuteEvt.maPosPixel; 159*cdf0e10cSrcweir (DropTargetEvent&)( aAcceptEvent.maDragEvent ) = (DropTargetEvent&) rDTDE; 160*cdf0e10cSrcweir ( (DropTargetDragEvent&)( aAcceptEvent.maDragEvent ) ).DropAction = rDTDE.DropAction; 161*cdf0e10cSrcweir ( (DropTargetDragEvent&)( aAcceptEvent.maDragEvent ) ).LocationX = rDTDE.LocationX; 162*cdf0e10cSrcweir ( (DropTargetDragEvent&)( aAcceptEvent.maDragEvent ) ).LocationY = rDTDE.LocationY; 163*cdf0e10cSrcweir ( (DropTargetDragEvent&)( aAcceptEvent.maDragEvent ) ).SourceActions = rDTDE.SourceActions; 164*cdf0e10cSrcweir aAcceptEvent.mbLeaving = sal_False; 165*cdf0e10cSrcweir aAcceptEvent.mbDefault = aExecuteEvt.mbDefault; 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir nRet = mrParent.AcceptDrop( aAcceptEvent ); 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir if( DNDConstants::ACTION_NONE != nRet ) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir rDTDE.Context->acceptDrop( nRet ); 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir if( aExecuteEvt.mbDefault ) 174*cdf0e10cSrcweir aExecuteEvt.mnAction = nRet; 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir nRet = mrParent.ExecuteDrop( aExecuteEvt ); 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir rDTDE.Context->dropComplete( DNDConstants::ACTION_NONE != nRet ); 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir if( mpLastDragOverEvent ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir delete mpLastDragOverEvent; 184*cdf0e10cSrcweir mpLastDragOverEvent = NULL; 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir void SAL_CALL DropTargetHelper::DropTargetListener::dragEnter( const DropTargetDragEnterEvent& rDTDEE ) throw( RuntimeException ) 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir try 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir mrParent.ImplBeginDrag( rDTDEE.SupportedDataFlavors ); 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir dragOver( rDTDEE ); 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir void SAL_CALL DropTargetHelper::DropTargetListener::dragOver( const DropTargetDragEvent& rDTDE ) throw( RuntimeException ) 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir try 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir if( mpLastDragOverEvent ) 218*cdf0e10cSrcweir delete mpLastDragOverEvent; 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir mpLastDragOverEvent = new AcceptDropEvent( rDTDE.DropAction & ~DNDConstants::ACTION_DEFAULT, Point( rDTDE.LocationX, rDTDE.LocationY ), rDTDE ); 221*cdf0e10cSrcweir mpLastDragOverEvent->mbDefault = ( ( rDTDE.DropAction & DNDConstants::ACTION_DEFAULT ) != 0 ); 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir const sal_Int8 nRet = mrParent.AcceptDrop( *mpLastDragOverEvent ); 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir if( DNDConstants::ACTION_NONE == nRet ) 226*cdf0e10cSrcweir rDTDE.Context->rejectDrag(); 227*cdf0e10cSrcweir else 228*cdf0e10cSrcweir rDTDE.Context->acceptDrag( nRet ); 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir void SAL_CALL DropTargetHelper::DropTargetListener::dragExit( const DropTargetEvent& ) throw( RuntimeException ) 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir try 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir if( mpLastDragOverEvent ) 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir mpLastDragOverEvent->mbLeaving = sal_True; 246*cdf0e10cSrcweir mrParent.AcceptDrop( *mpLastDragOverEvent ); 247*cdf0e10cSrcweir delete mpLastDragOverEvent; 248*cdf0e10cSrcweir mpLastDragOverEvent = NULL; 249*cdf0e10cSrcweir } 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir mrParent.ImplEndDrag(); 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir void SAL_CALL DropTargetHelper::DropTargetListener::dropActionChanged( const DropTargetDragEvent& ) throw( RuntimeException ) 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir // -------------------- 266*cdf0e10cSrcweir // - DropTargetHelper - 267*cdf0e10cSrcweir // -------------------- 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir DropTargetHelper::DropTargetHelper( Window* pWindow ) : 270*cdf0e10cSrcweir mxDropTarget( pWindow->GetDropTarget() ), 271*cdf0e10cSrcweir mpFormats( new DataFlavorExVector ) 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir ImplConstruct(); 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir DropTargetHelper::DropTargetHelper( const Reference< XDropTarget >& rxDropTarget ) : 279*cdf0e10cSrcweir mxDropTarget( rxDropTarget ), 280*cdf0e10cSrcweir mpFormats( new DataFlavorExVector ) 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir ImplConstruct(); 283*cdf0e10cSrcweir } 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir DropTargetHelper::~DropTargetHelper() 288*cdf0e10cSrcweir { 289*cdf0e10cSrcweir if( mxDropTarget.is() ) 290*cdf0e10cSrcweir mxDropTarget->removeDropTargetListener( mxDropTargetListener ); 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir delete mpFormats; 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir void DropTargetHelper::ImplConstruct() 298*cdf0e10cSrcweir { 299*cdf0e10cSrcweir if( mxDropTarget.is() ) 300*cdf0e10cSrcweir { 301*cdf0e10cSrcweir mxDropTargetListener = new DropTargetHelper::DropTargetListener( *this ); 302*cdf0e10cSrcweir mxDropTarget->addDropTargetListener( mxDropTargetListener ); 303*cdf0e10cSrcweir mxDropTarget->setActive( sal_True ); 304*cdf0e10cSrcweir } 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir void DropTargetHelper::ImplBeginDrag( const Sequence< DataFlavor >& rSupportedDataFlavors ) 310*cdf0e10cSrcweir { 311*cdf0e10cSrcweir mpFormats->clear(); 312*cdf0e10cSrcweir TransferableDataHelper::FillDataFlavorExVector( rSupportedDataFlavors, *mpFormats ); 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir void DropTargetHelper::ImplEndDrag() 318*cdf0e10cSrcweir { 319*cdf0e10cSrcweir mpFormats->clear(); 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir sal_Int8 DropTargetHelper::AcceptDrop( const AcceptDropEvent& ) 325*cdf0e10cSrcweir { 326*cdf0e10cSrcweir return( DNDConstants::ACTION_NONE ); 327*cdf0e10cSrcweir } 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir sal_Int8 DropTargetHelper::ExecuteDrop( const ExecuteDropEvent& ) 332*cdf0e10cSrcweir { 333*cdf0e10cSrcweir return( DNDConstants::ACTION_NONE ); 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir sal_Bool DropTargetHelper::IsDropFormatSupported( SotFormatStringId nFormat ) 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir DataFlavorExVector::iterator aIter( mpFormats->begin() ), aEnd( mpFormats->end() ); 341*cdf0e10cSrcweir sal_Bool bRet = sal_False; 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir while( aIter != aEnd ) 344*cdf0e10cSrcweir { 345*cdf0e10cSrcweir if( nFormat == (*aIter++).mnSotId ) 346*cdf0e10cSrcweir { 347*cdf0e10cSrcweir bRet = sal_True; 348*cdf0e10cSrcweir aIter = aEnd; 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir } 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir return bRet; 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir sal_Bool DropTargetHelper::IsDropFormatSupported( const DataFlavor& rFlavor ) 358*cdf0e10cSrcweir { 359*cdf0e10cSrcweir DataFlavorExVector::iterator aIter( mpFormats->begin() ), aEnd( mpFormats->end() ); 360*cdf0e10cSrcweir sal_Bool bRet = sal_False; 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir while( aIter != aEnd ) 363*cdf0e10cSrcweir { 364*cdf0e10cSrcweir if( TransferableDataHelper::IsEqual( rFlavor, *aIter++ ) ) 365*cdf0e10cSrcweir { 366*cdf0e10cSrcweir bRet = sal_True; 367*cdf0e10cSrcweir aIter = aEnd; 368*cdf0e10cSrcweir } 369*cdf0e10cSrcweir } 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir return bRet; 372*cdf0e10cSrcweir } 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 375*cdf0e10cSrcweir // TransferDataContainer 376*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 377*cdf0e10cSrcweir 378*cdf0e10cSrcweir struct TDataCntnrEntry_Impl 379*cdf0e10cSrcweir { 380*cdf0e10cSrcweir ::com::sun::star::uno::Any aAny; 381*cdf0e10cSrcweir SotFormatStringId nId; 382*cdf0e10cSrcweir }; 383*cdf0e10cSrcweir 384*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir typedef ::std::list< TDataCntnrEntry_Impl > TDataCntnrEntryList; 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 389*cdf0e10cSrcweir 390*cdf0e10cSrcweir struct TransferDataContainer_Impl 391*cdf0e10cSrcweir { 392*cdf0e10cSrcweir TDataCntnrEntryList aFmtList; 393*cdf0e10cSrcweir Link aFinshedLnk; 394*cdf0e10cSrcweir INetBookmark* pBookmk; 395*cdf0e10cSrcweir Graphic* pGrf; 396*cdf0e10cSrcweir 397*cdf0e10cSrcweir TransferDataContainer_Impl() 398*cdf0e10cSrcweir : pBookmk( 0 ), pGrf( 0 ) 399*cdf0e10cSrcweir { 400*cdf0e10cSrcweir } 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir ~TransferDataContainer_Impl() 403*cdf0e10cSrcweir { 404*cdf0e10cSrcweir delete pBookmk; 405*cdf0e10cSrcweir delete pGrf; 406*cdf0e10cSrcweir } 407*cdf0e10cSrcweir }; 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 410*cdf0e10cSrcweir 411*cdf0e10cSrcweir TransferDataContainer::TransferDataContainer() 412*cdf0e10cSrcweir : pImpl( new TransferDataContainer_Impl ) 413*cdf0e10cSrcweir { 414*cdf0e10cSrcweir } 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir TransferDataContainer::~TransferDataContainer() 419*cdf0e10cSrcweir { 420*cdf0e10cSrcweir delete pImpl; 421*cdf0e10cSrcweir } 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 424*cdf0e10cSrcweir 425*cdf0e10cSrcweir void TransferDataContainer::AddSupportedFormats() 426*cdf0e10cSrcweir { 427*cdf0e10cSrcweir } 428*cdf0e10cSrcweir 429*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 430*cdf0e10cSrcweir 431*cdf0e10cSrcweir sal_Bool TransferDataContainer::GetData( const 432*cdf0e10cSrcweir ::com::sun::star::datatransfer::DataFlavor& rFlavor ) 433*cdf0e10cSrcweir { 434*cdf0e10cSrcweir TDataCntnrEntryList::iterator aIter( pImpl->aFmtList.begin() ), 435*cdf0e10cSrcweir aEnd( pImpl->aFmtList.end() ); 436*cdf0e10cSrcweir sal_Bool bFnd = sal_False; 437*cdf0e10cSrcweir sal_uLong nFmtId = SotExchange::GetFormat( rFlavor ); 438*cdf0e10cSrcweir 439*cdf0e10cSrcweir // test first the list 440*cdf0e10cSrcweir for( ; aIter != aEnd; ++aIter ) 441*cdf0e10cSrcweir { 442*cdf0e10cSrcweir TDataCntnrEntry_Impl& rEntry = (TDataCntnrEntry_Impl&)*aIter; 443*cdf0e10cSrcweir if( nFmtId == rEntry.nId ) 444*cdf0e10cSrcweir { 445*cdf0e10cSrcweir bFnd = SetAny( rEntry.aAny, rFlavor ); 446*cdf0e10cSrcweir break; 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir } 449*cdf0e10cSrcweir 450*cdf0e10cSrcweir // test second the bookmark pointer 451*cdf0e10cSrcweir if( !bFnd ) 452*cdf0e10cSrcweir switch( nFmtId ) 453*cdf0e10cSrcweir { 454*cdf0e10cSrcweir case SOT_FORMAT_STRING: 455*cdf0e10cSrcweir case SOT_FORMATSTR_ID_SOLK: 456*cdf0e10cSrcweir case SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK: 457*cdf0e10cSrcweir case SOT_FORMATSTR_ID_FILECONTENT: 458*cdf0e10cSrcweir case SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR: 459*cdf0e10cSrcweir case SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR: 460*cdf0e10cSrcweir if( pImpl->pBookmk ) 461*cdf0e10cSrcweir bFnd = SetINetBookmark( *pImpl->pBookmk, rFlavor ); 462*cdf0e10cSrcweir break; 463*cdf0e10cSrcweir 464*cdf0e10cSrcweir case SOT_FORMATSTR_ID_SVXB: 465*cdf0e10cSrcweir case SOT_FORMAT_BITMAP: 466*cdf0e10cSrcweir case SOT_FORMAT_GDIMETAFILE: 467*cdf0e10cSrcweir if( pImpl->pGrf ) 468*cdf0e10cSrcweir bFnd = SetGraphic( *pImpl->pGrf, rFlavor ); 469*cdf0e10cSrcweir break; 470*cdf0e10cSrcweir } 471*cdf0e10cSrcweir 472*cdf0e10cSrcweir return bFnd; 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir 475*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 476*cdf0e10cSrcweir 477*cdf0e10cSrcweir void TransferDataContainer::ClearData() 478*cdf0e10cSrcweir { 479*cdf0e10cSrcweir delete pImpl; 480*cdf0e10cSrcweir pImpl = new TransferDataContainer_Impl; 481*cdf0e10cSrcweir ClearFormats(); 482*cdf0e10cSrcweir } 483*cdf0e10cSrcweir 484*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 485*cdf0e10cSrcweir 486*cdf0e10cSrcweir void TransferDataContainer::CopyINetBookmark( const INetBookmark& rBkmk ) 487*cdf0e10cSrcweir { 488*cdf0e10cSrcweir if( !pImpl->pBookmk ) 489*cdf0e10cSrcweir pImpl->pBookmk = new INetBookmark( rBkmk ); 490*cdf0e10cSrcweir else 491*cdf0e10cSrcweir *pImpl->pBookmk = rBkmk; 492*cdf0e10cSrcweir 493*cdf0e10cSrcweir AddFormat( SOT_FORMAT_STRING ); 494*cdf0e10cSrcweir AddFormat( SOT_FORMATSTR_ID_SOLK ); 495*cdf0e10cSrcweir AddFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ); 496*cdf0e10cSrcweir AddFormat( SOT_FORMATSTR_ID_FILECONTENT ); 497*cdf0e10cSrcweir AddFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ); 498*cdf0e10cSrcweir AddFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ); 499*cdf0e10cSrcweir } 500*cdf0e10cSrcweir 501*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir void TransferDataContainer::CopyAnyData( sal_uLong nFormatId, 504*cdf0e10cSrcweir const sal_Char* pData, sal_uLong nLen ) 505*cdf0e10cSrcweir { 506*cdf0e10cSrcweir if( nLen ) 507*cdf0e10cSrcweir { 508*cdf0e10cSrcweir TDataCntnrEntry_Impl aEntry; 509*cdf0e10cSrcweir aEntry.nId = nFormatId; 510*cdf0e10cSrcweir 511*cdf0e10cSrcweir Sequence< sal_Int8 > aSeq( nLen ); 512*cdf0e10cSrcweir memcpy( aSeq.getArray(), pData, nLen ); 513*cdf0e10cSrcweir aEntry.aAny <<= aSeq; 514*cdf0e10cSrcweir pImpl->aFmtList.push_back( aEntry ); 515*cdf0e10cSrcweir AddFormat( nFormatId ); 516*cdf0e10cSrcweir } 517*cdf0e10cSrcweir } 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 520*cdf0e10cSrcweir 521*cdf0e10cSrcweir void TransferDataContainer::CopyByteString( sal_uLong nFormatId, 522*cdf0e10cSrcweir const ByteString& rStr ) 523*cdf0e10cSrcweir { 524*cdf0e10cSrcweir CopyAnyData( nFormatId, rStr.GetBuffer(), rStr.Len() ); 525*cdf0e10cSrcweir } 526*cdf0e10cSrcweir 527*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir void TransferDataContainer::CopyINetImage( const INetImage& rINtImg ) 530*cdf0e10cSrcweir { 531*cdf0e10cSrcweir SvMemoryStream aMemStm( 1024, 1024 ); 532*cdf0e10cSrcweir aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 ); 533*cdf0e10cSrcweir rINtImg.Write( aMemStm, SOT_FORMATSTR_ID_INET_IMAGE ); 534*cdf0e10cSrcweir CopyAnyData( SOT_FORMATSTR_ID_INET_IMAGE, (sal_Char*)aMemStm.GetData(), 535*cdf0e10cSrcweir aMemStm.Seek( STREAM_SEEK_TO_END ) ); 536*cdf0e10cSrcweir } 537*cdf0e10cSrcweir 538*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 539*cdf0e10cSrcweir 540*cdf0e10cSrcweir void TransferDataContainer::CopyImageMap( const ImageMap& rImgMap ) 541*cdf0e10cSrcweir { 542*cdf0e10cSrcweir SvMemoryStream aMemStm( 8192, 8192 ); 543*cdf0e10cSrcweir aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 ); 544*cdf0e10cSrcweir rImgMap.Write( aMemStm, String() ); 545*cdf0e10cSrcweir CopyAnyData( SOT_FORMATSTR_ID_SVIM, (sal_Char*)aMemStm.GetData(), 546*cdf0e10cSrcweir aMemStm.Seek( STREAM_SEEK_TO_END ) ); 547*cdf0e10cSrcweir } 548*cdf0e10cSrcweir 549*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 550*cdf0e10cSrcweir 551*cdf0e10cSrcweir void TransferDataContainer::CopyGraphic( const Graphic& rGrf ) 552*cdf0e10cSrcweir { 553*cdf0e10cSrcweir GraphicType nType = rGrf.GetType(); 554*cdf0e10cSrcweir if( GRAPHIC_NONE != nType ) 555*cdf0e10cSrcweir { 556*cdf0e10cSrcweir if( !pImpl->pGrf ) 557*cdf0e10cSrcweir pImpl->pGrf = new Graphic( rGrf ); 558*cdf0e10cSrcweir else 559*cdf0e10cSrcweir *pImpl->pGrf = rGrf; 560*cdf0e10cSrcweir 561*cdf0e10cSrcweir AddFormat( SOT_FORMATSTR_ID_SVXB ); 562*cdf0e10cSrcweir if( GRAPHIC_BITMAP == nType ) 563*cdf0e10cSrcweir AddFormat( SOT_FORMAT_BITMAP ); 564*cdf0e10cSrcweir else if( GRAPHIC_GDIMETAFILE == nType ) 565*cdf0e10cSrcweir AddFormat( SOT_FORMAT_GDIMETAFILE ); 566*cdf0e10cSrcweir } 567*cdf0e10cSrcweir } 568*cdf0e10cSrcweir 569*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 570*cdf0e10cSrcweir 571*cdf0e10cSrcweir void TransferDataContainer::CopyString( sal_uInt16 nFmt, const String& rStr ) 572*cdf0e10cSrcweir { 573*cdf0e10cSrcweir if( rStr.Len() ) 574*cdf0e10cSrcweir { 575*cdf0e10cSrcweir TDataCntnrEntry_Impl aEntry; 576*cdf0e10cSrcweir aEntry.nId = nFmt; 577*cdf0e10cSrcweir rtl::OUString aStr( rStr ); 578*cdf0e10cSrcweir aEntry.aAny <<= aStr; 579*cdf0e10cSrcweir pImpl->aFmtList.push_back( aEntry ); 580*cdf0e10cSrcweir AddFormat( aEntry.nId ); 581*cdf0e10cSrcweir } 582*cdf0e10cSrcweir } 583*cdf0e10cSrcweir 584*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 585*cdf0e10cSrcweir 586*cdf0e10cSrcweir void TransferDataContainer::CopyString( const String& rStr ) 587*cdf0e10cSrcweir { 588*cdf0e10cSrcweir CopyString( SOT_FORMAT_STRING, rStr ); 589*cdf0e10cSrcweir } 590*cdf0e10cSrcweir 591*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 592*cdf0e10cSrcweir 593*cdf0e10cSrcweir void TransferDataContainer::CopyAny( sal_uInt16 nFmt, 594*cdf0e10cSrcweir const ::com::sun::star::uno::Any& rAny ) 595*cdf0e10cSrcweir { 596*cdf0e10cSrcweir TDataCntnrEntry_Impl aEntry; 597*cdf0e10cSrcweir aEntry.nId = nFmt; 598*cdf0e10cSrcweir aEntry.aAny = rAny; 599*cdf0e10cSrcweir pImpl->aFmtList.push_back( aEntry ); 600*cdf0e10cSrcweir AddFormat( aEntry.nId ); 601*cdf0e10cSrcweir } 602*cdf0e10cSrcweir 603*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 604*cdf0e10cSrcweir 605*cdf0e10cSrcweir sal_Bool TransferDataContainer::HasAnyData() const 606*cdf0e10cSrcweir { 607*cdf0e10cSrcweir return pImpl->aFmtList.begin() != pImpl->aFmtList.end() || 608*cdf0e10cSrcweir 0 != pImpl->pBookmk; 609*cdf0e10cSrcweir } 610*cdf0e10cSrcweir 611*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 612*cdf0e10cSrcweir 613*cdf0e10cSrcweir void TransferDataContainer::StartDrag( 614*cdf0e10cSrcweir Window* pWindow, sal_Int8 nDragSourceActions, 615*cdf0e10cSrcweir const Link& rLnk, sal_Int32 nDragPointer, sal_Int32 nDragImage ) 616*cdf0e10cSrcweir { 617*cdf0e10cSrcweir pImpl->aFinshedLnk = rLnk; 618*cdf0e10cSrcweir TransferableHelper::StartDrag( pWindow, nDragSourceActions, 619*cdf0e10cSrcweir nDragPointer, nDragImage ); 620*cdf0e10cSrcweir } 621*cdf0e10cSrcweir 622*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 623*cdf0e10cSrcweir 624*cdf0e10cSrcweir void TransferDataContainer::DragFinished( sal_Int8 nDropAction ) 625*cdf0e10cSrcweir { 626*cdf0e10cSrcweir if( pImpl->aFinshedLnk.IsSet() ) 627*cdf0e10cSrcweir pImpl->aFinshedLnk.Call( &nDropAction ); 628*cdf0e10cSrcweir } 629