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