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_vcl.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <dndlcon.hxx> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir using namespace ::cppu; 34*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 35*cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer; 36*cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer::dnd; 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir //================================================================================================== 39*cdf0e10cSrcweir // 40*cdf0e10cSrcweir //================================================================================================== 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir DNDListenerContainer::DNDListenerContainer( sal_Int8 nDefaultActions ) 43*cdf0e10cSrcweir : WeakComponentImplHelper4< XDragGestureRecognizer, XDropTargetDragContext, XDropTargetDropContext, XDropTarget >(GetMutex()) 44*cdf0e10cSrcweir { 45*cdf0e10cSrcweir m_bActive = sal_True; 46*cdf0e10cSrcweir m_nDefaultActions = nDefaultActions; 47*cdf0e10cSrcweir } 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir //================================================================================================== 50*cdf0e10cSrcweir // 51*cdf0e10cSrcweir //================================================================================================== 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir DNDListenerContainer::~DNDListenerContainer() 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir } 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir //================================================================================================== 58*cdf0e10cSrcweir // DNDListenerContainer::addDragGestureListener 59*cdf0e10cSrcweir //================================================================================================== 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir void SAL_CALL DNDListenerContainer::addDragGestureListener( const Reference< XDragGestureListener >& dgl ) 62*cdf0e10cSrcweir throw(RuntimeException) 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir rBHelper.addListener( getCppuType( ( const Reference< XDragGestureListener > * ) 0 ), dgl ); 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir //================================================================================================== 68*cdf0e10cSrcweir // DNDListenerContainer::removeDragGestureListener 69*cdf0e10cSrcweir //================================================================================================== 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir void SAL_CALL DNDListenerContainer::removeDragGestureListener( const Reference< XDragGestureListener >& dgl ) 72*cdf0e10cSrcweir throw(RuntimeException) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir rBHelper.removeListener( getCppuType( ( const Reference< XDragGestureListener > * ) 0 ), dgl ); 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir //================================================================================================== 78*cdf0e10cSrcweir // DNDListenerContainer::resetRecognizer 79*cdf0e10cSrcweir //================================================================================================== 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir void SAL_CALL DNDListenerContainer::resetRecognizer( ) 82*cdf0e10cSrcweir throw(RuntimeException) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir //================================================================================================== 87*cdf0e10cSrcweir // DNDListenerContainer::addDropTargetListener 88*cdf0e10cSrcweir //================================================================================================== 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir void SAL_CALL DNDListenerContainer::addDropTargetListener( const Reference< XDropTargetListener >& dtl ) 91*cdf0e10cSrcweir throw(RuntimeException) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir rBHelper.addListener( getCppuType( ( const Reference< XDropTargetListener > * ) 0 ), dtl ); 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir //================================================================================================== 97*cdf0e10cSrcweir // DNDListenerContainer::removeDropTargetListener 98*cdf0e10cSrcweir //================================================================================================== 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir void SAL_CALL DNDListenerContainer::removeDropTargetListener( const Reference< XDropTargetListener >& dtl ) 101*cdf0e10cSrcweir throw(RuntimeException) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir rBHelper.removeListener( getCppuType( ( const Reference< XDropTargetListener > * ) 0 ), dtl ); 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir //================================================================================================== 107*cdf0e10cSrcweir // DNDListenerContainer::isActive 108*cdf0e10cSrcweir //================================================================================================== 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir sal_Bool SAL_CALL DNDListenerContainer::isActive( ) 111*cdf0e10cSrcweir throw(RuntimeException) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir return m_bActive; 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir //================================================================================================== 117*cdf0e10cSrcweir // DNDListenerContainer::setActive 118*cdf0e10cSrcweir //================================================================================================== 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir void SAL_CALL DNDListenerContainer::setActive( sal_Bool active ) 121*cdf0e10cSrcweir throw(RuntimeException) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir m_bActive = active; 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir //================================================================================================== 127*cdf0e10cSrcweir // DNDListenerContainer::getDefaultActions 128*cdf0e10cSrcweir //================================================================================================== 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir sal_Int8 SAL_CALL DNDListenerContainer::getDefaultActions( ) 131*cdf0e10cSrcweir throw(RuntimeException) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir return m_nDefaultActions; 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir //================================================================================================== 137*cdf0e10cSrcweir // DNDListenerContainer::setDefaultActions 138*cdf0e10cSrcweir //================================================================================================== 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir void SAL_CALL DNDListenerContainer::setDefaultActions( sal_Int8 actions ) 141*cdf0e10cSrcweir throw(RuntimeException) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir m_nDefaultActions = actions; 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir //================================================================================================== 147*cdf0e10cSrcweir // DNDListenerContainer::fireDropEvent 148*cdf0e10cSrcweir //================================================================================================== 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir sal_uInt32 DNDListenerContainer::fireDropEvent( const Reference< XDropTargetDropContext >& context, 151*cdf0e10cSrcweir sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions, 152*cdf0e10cSrcweir const Reference< XTransferable >& transferable ) 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir sal_uInt32 nRet = 0; 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir // fire DropTargetDropEvent on all XDropTargetListeners 157*cdf0e10cSrcweir OInterfaceContainerHelper *pContainer = rBHelper.getContainer( getCppuType( ( Reference < XDropTargetListener > * ) 0) ); 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir if( pContainer && m_bActive ) 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir OInterfaceIteratorHelper aIterator( *pContainer ); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir // remember context to use in own context methods 164*cdf0e10cSrcweir m_xDropTargetDropContext = context; 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir // do not construct the event before you are sure at least one listener is registered 167*cdf0e10cSrcweir DropTargetDropEvent aEvent( static_cast < XDropTarget * > (this), 0, 168*cdf0e10cSrcweir static_cast < XDropTargetDropContext * > (this), dropAction, 169*cdf0e10cSrcweir locationX, locationY, sourceActions, transferable ); 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir while (aIterator.hasMoreElements()) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir // FIXME: this can be simplified as soon as the Iterator has a remove method 174*cdf0e10cSrcweir Reference< XInterface > xElement( aIterator.next() ); 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir try 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir // this may result in a runtime exception 179*cdf0e10cSrcweir Reference < XDropTargetListener > xListener( xElement, UNO_QUERY ); 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir if( xListener.is() ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir // fire drop until the first one has accepted 184*cdf0e10cSrcweir if( m_xDropTargetDropContext.is() ) 185*cdf0e10cSrcweir xListener->drop( aEvent ); 186*cdf0e10cSrcweir else 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir DropTargetEvent aDTEvent( static_cast < XDropTarget * > (this), 0 ); 189*cdf0e10cSrcweir xListener->dragExit( aDTEvent ); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir nRet++; 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir catch( RuntimeException exc ) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir pContainer->removeInterface( xElement ); 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir // if context still valid, then reject drop 203*cdf0e10cSrcweir if( m_xDropTargetDropContext.is() ) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir m_xDropTargetDropContext.clear(); 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir try 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir context->rejectDrop(); 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir catch( RuntimeException exc ) 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir return nRet; 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir //================================================================================================== 222*cdf0e10cSrcweir // DNDListenerContainer::fireDragExitEvent 223*cdf0e10cSrcweir //================================================================================================== 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir sal_uInt32 DNDListenerContainer::fireDragExitEvent() 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir sal_uInt32 nRet = 0; 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir // fire DropTargetDropEvent on all XDropTargetListeners 230*cdf0e10cSrcweir OInterfaceContainerHelper *pContainer = rBHelper.getContainer( getCppuType( ( Reference < XDropTargetListener > * ) 0) ); 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir if( pContainer && m_bActive ) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir OInterfaceIteratorHelper aIterator( *pContainer ); 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir // do not construct the event before you are sure at least one listener is registered 237*cdf0e10cSrcweir DropTargetEvent aEvent( static_cast < XDropTarget * > (this), 0 ); 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir while (aIterator.hasMoreElements()) 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir // FIXME: this can be simplified as soon as the Iterator has a remove method 242*cdf0e10cSrcweir Reference< XInterface > xElement( aIterator.next() ); 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir try 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir // this may result in a runtime exception 247*cdf0e10cSrcweir Reference < XDropTargetListener > xListener( xElement, UNO_QUERY ); 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir if( xListener.is() ) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir xListener->dragExit( aEvent ); 252*cdf0e10cSrcweir nRet++; 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir } 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir catch( RuntimeException exc ) 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir pContainer->removeInterface( xElement ); 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir } 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir return nRet; 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir //================================================================================================== 267*cdf0e10cSrcweir // DNDListenerContainer::fireDragOverEvent 268*cdf0e10cSrcweir //================================================================================================== 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir sal_uInt32 DNDListenerContainer::fireDragOverEvent( const Reference< XDropTargetDragContext >& context, 271*cdf0e10cSrcweir sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions ) 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir sal_uInt32 nRet = 0; 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir // fire DropTargetDropEvent on all XDropTargetListeners 276*cdf0e10cSrcweir OInterfaceContainerHelper *pContainer = rBHelper.getContainer( getCppuType( ( Reference < XDropTargetListener > * ) 0) ); 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir if( pContainer && m_bActive ) 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir OInterfaceIteratorHelper aIterator( *pContainer ); 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir // remember context to use in own context methods 283*cdf0e10cSrcweir m_xDropTargetDragContext = context; 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir // do not construct the event before you are sure at least one listener is registered 286*cdf0e10cSrcweir DropTargetDragEvent aEvent( static_cast < XDropTarget * > (this), 0, 287*cdf0e10cSrcweir static_cast < XDropTargetDragContext * > (this), 288*cdf0e10cSrcweir dropAction, locationX, locationY, sourceActions ); 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir while (aIterator.hasMoreElements()) 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir // FIXME: this can be simplified as soon as the Iterator has a remove method 293*cdf0e10cSrcweir Reference< XInterface > xElement( aIterator.next() ); 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir try 296*cdf0e10cSrcweir { 297*cdf0e10cSrcweir // this may result in a runtime exception 298*cdf0e10cSrcweir Reference < XDropTargetListener > xListener( xElement, UNO_QUERY ); 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir if( xListener.is() ) 301*cdf0e10cSrcweir { 302*cdf0e10cSrcweir if( m_xDropTargetDragContext.is() ) 303*cdf0e10cSrcweir xListener->dragOver( aEvent ); 304*cdf0e10cSrcweir nRet++; 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir catch( RuntimeException exc ) 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir pContainer->removeInterface( xElement ); 311*cdf0e10cSrcweir } 312*cdf0e10cSrcweir } 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir // if context still valid, then reject drag 315*cdf0e10cSrcweir if( m_xDropTargetDragContext.is() ) 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir m_xDropTargetDragContext.clear(); 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir try 320*cdf0e10cSrcweir { 321*cdf0e10cSrcweir context->rejectDrag(); 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir catch( RuntimeException exc ) 325*cdf0e10cSrcweir { 326*cdf0e10cSrcweir } 327*cdf0e10cSrcweir } 328*cdf0e10cSrcweir } 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir return nRet; 331*cdf0e10cSrcweir } 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir //================================================================================================== 334*cdf0e10cSrcweir // DNDListenerContainer::fireDragEnterEvent 335*cdf0e10cSrcweir //================================================================================================== 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir sal_uInt32 DNDListenerContainer::fireDragEnterEvent( const Reference< XDropTargetDragContext >& context, 338*cdf0e10cSrcweir sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions, 339*cdf0e10cSrcweir const Sequence< DataFlavor >& dataFlavors ) 340*cdf0e10cSrcweir { 341*cdf0e10cSrcweir sal_uInt32 nRet = 0; 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir // fire DropTargetDropEvent on all XDropTargetListeners 344*cdf0e10cSrcweir OInterfaceContainerHelper *pContainer = rBHelper.getContainer( getCppuType( ( Reference < XDropTargetListener > * ) 0) ); 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir if( pContainer && m_bActive ) 347*cdf0e10cSrcweir { 348*cdf0e10cSrcweir OInterfaceIteratorHelper aIterator( *pContainer ); 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir // remember context to use in own context methods 351*cdf0e10cSrcweir m_xDropTargetDragContext = context; 352*cdf0e10cSrcweir 353*cdf0e10cSrcweir // do not construct the event before you are sure at least one listener is registered 354*cdf0e10cSrcweir DropTargetDragEnterEvent aEvent( static_cast < XDropTarget * > (this), 0, 355*cdf0e10cSrcweir static_cast < XDropTargetDragContext * > (this), 356*cdf0e10cSrcweir dropAction, locationX, locationY, sourceActions, dataFlavors ); 357*cdf0e10cSrcweir 358*cdf0e10cSrcweir while (aIterator.hasMoreElements()) 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir // FIXME: this can be simplified as soon as the Iterator has a remove method 361*cdf0e10cSrcweir Reference< XInterface > xElement( aIterator.next() ); 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir try 364*cdf0e10cSrcweir { 365*cdf0e10cSrcweir // this may result in a runtime exception 366*cdf0e10cSrcweir Reference < XDropTargetListener > xListener( xElement, UNO_QUERY ); 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir if( xListener.is() ) 369*cdf0e10cSrcweir { 370*cdf0e10cSrcweir if( m_xDropTargetDragContext.is() ) 371*cdf0e10cSrcweir xListener->dragEnter( aEvent ); 372*cdf0e10cSrcweir nRet++; 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir } 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir catch( RuntimeException exc ) 377*cdf0e10cSrcweir { 378*cdf0e10cSrcweir pContainer->removeInterface( xElement ); 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir } 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir // if context still valid, then reject drag 383*cdf0e10cSrcweir if( m_xDropTargetDragContext.is() ) 384*cdf0e10cSrcweir { 385*cdf0e10cSrcweir m_xDropTargetDragContext.clear(); 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir try 388*cdf0e10cSrcweir { 389*cdf0e10cSrcweir context->rejectDrag(); 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir catch( RuntimeException exc ) 393*cdf0e10cSrcweir { 394*cdf0e10cSrcweir } 395*cdf0e10cSrcweir } 396*cdf0e10cSrcweir } 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir return nRet; 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir //================================================================================================== 402*cdf0e10cSrcweir // DNDListenerContainer::fireDropActionChangedEvent 403*cdf0e10cSrcweir //================================================================================================== 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir sal_uInt32 DNDListenerContainer::fireDropActionChangedEvent( const Reference< XDropTargetDragContext >& context, 406*cdf0e10cSrcweir sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions ) 407*cdf0e10cSrcweir { 408*cdf0e10cSrcweir sal_uInt32 nRet = 0; 409*cdf0e10cSrcweir 410*cdf0e10cSrcweir // fire DropTargetDropEvent on all XDropTargetListeners 411*cdf0e10cSrcweir OInterfaceContainerHelper *pContainer = rBHelper.getContainer( getCppuType( ( Reference < XDropTargetListener > * ) 0) ); 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir if( pContainer && m_bActive ) 414*cdf0e10cSrcweir { 415*cdf0e10cSrcweir OInterfaceIteratorHelper aIterator( *pContainer ); 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir // remember context to use in own context methods 418*cdf0e10cSrcweir m_xDropTargetDragContext = context; 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir // do not construct the event before you are sure at least one listener is registered 421*cdf0e10cSrcweir DropTargetDragEvent aEvent( static_cast < XDropTarget * > (this), 0, 422*cdf0e10cSrcweir static_cast < XDropTargetDragContext * > (this), 423*cdf0e10cSrcweir dropAction, locationX, locationY, sourceActions ); 424*cdf0e10cSrcweir 425*cdf0e10cSrcweir while (aIterator.hasMoreElements()) 426*cdf0e10cSrcweir { 427*cdf0e10cSrcweir // FIXME: this can be simplified as soon as the Iterator has a remove method 428*cdf0e10cSrcweir Reference< XInterface > xElement( aIterator.next() ); 429*cdf0e10cSrcweir 430*cdf0e10cSrcweir try 431*cdf0e10cSrcweir { 432*cdf0e10cSrcweir // this may result in a runtime exception 433*cdf0e10cSrcweir Reference < XDropTargetListener > xListener( xElement, UNO_QUERY ); 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir if( xListener.is() ) 436*cdf0e10cSrcweir { 437*cdf0e10cSrcweir if( m_xDropTargetDragContext.is() ) 438*cdf0e10cSrcweir xListener->dropActionChanged( aEvent ); 439*cdf0e10cSrcweir nRet++; 440*cdf0e10cSrcweir } 441*cdf0e10cSrcweir } 442*cdf0e10cSrcweir 443*cdf0e10cSrcweir catch( RuntimeException exc ) 444*cdf0e10cSrcweir { 445*cdf0e10cSrcweir pContainer->removeInterface( xElement ); 446*cdf0e10cSrcweir } 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir // if context still valid, then reject drag 450*cdf0e10cSrcweir if( m_xDropTargetDragContext.is() ) 451*cdf0e10cSrcweir { 452*cdf0e10cSrcweir m_xDropTargetDragContext.clear(); 453*cdf0e10cSrcweir 454*cdf0e10cSrcweir try 455*cdf0e10cSrcweir { 456*cdf0e10cSrcweir context->rejectDrag(); 457*cdf0e10cSrcweir } 458*cdf0e10cSrcweir 459*cdf0e10cSrcweir catch( RuntimeException exc ) 460*cdf0e10cSrcweir { 461*cdf0e10cSrcweir } 462*cdf0e10cSrcweir } 463*cdf0e10cSrcweir } 464*cdf0e10cSrcweir 465*cdf0e10cSrcweir return nRet; 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir //================================================================================================== 469*cdf0e10cSrcweir // DNDListenerContainer::fireDragGestureEvent 470*cdf0e10cSrcweir //================================================================================================== 471*cdf0e10cSrcweir 472*cdf0e10cSrcweir sal_uInt32 DNDListenerContainer::fireDragGestureEvent( sal_Int8 dragAction, sal_Int32 dragOriginX, 473*cdf0e10cSrcweir sal_Int32 dragOriginY, const Reference< XDragSource >& dragSource, const Any& triggerEvent ) 474*cdf0e10cSrcweir { 475*cdf0e10cSrcweir sal_uInt32 nRet = 0; 476*cdf0e10cSrcweir 477*cdf0e10cSrcweir // fire DropTargetDropEvent on all XDropTargetListeners 478*cdf0e10cSrcweir OInterfaceContainerHelper *pContainer = rBHelper.getContainer( getCppuType( ( Reference < XDragGestureListener > * ) 0) ); 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir if( pContainer ) 481*cdf0e10cSrcweir { 482*cdf0e10cSrcweir OInterfaceIteratorHelper aIterator( *pContainer ); 483*cdf0e10cSrcweir 484*cdf0e10cSrcweir // do not construct the event before you are sure at least one listener is registered 485*cdf0e10cSrcweir DragGestureEvent aEvent( static_cast < XDragGestureRecognizer * > (this), dragAction, 486*cdf0e10cSrcweir dragOriginX, dragOriginY, dragSource, triggerEvent ); 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir while( aIterator.hasMoreElements() ) 489*cdf0e10cSrcweir { 490*cdf0e10cSrcweir // FIXME: this can be simplified as soon as the Iterator has a remove method 491*cdf0e10cSrcweir Reference< XInterface > xElement( aIterator.next() ); 492*cdf0e10cSrcweir 493*cdf0e10cSrcweir try 494*cdf0e10cSrcweir { 495*cdf0e10cSrcweir // this may result in a runtime exception 496*cdf0e10cSrcweir Reference < XDragGestureListener > xListener( xElement, UNO_QUERY ); 497*cdf0e10cSrcweir 498*cdf0e10cSrcweir if( xListener.is() ) 499*cdf0e10cSrcweir { 500*cdf0e10cSrcweir xListener->dragGestureRecognized( aEvent ); 501*cdf0e10cSrcweir nRet++; 502*cdf0e10cSrcweir } 503*cdf0e10cSrcweir } 504*cdf0e10cSrcweir 505*cdf0e10cSrcweir catch( RuntimeException exc ) 506*cdf0e10cSrcweir { 507*cdf0e10cSrcweir pContainer->removeInterface( xElement ); 508*cdf0e10cSrcweir } 509*cdf0e10cSrcweir } 510*cdf0e10cSrcweir } 511*cdf0e10cSrcweir 512*cdf0e10cSrcweir return nRet; 513*cdf0e10cSrcweir } 514*cdf0e10cSrcweir 515*cdf0e10cSrcweir //================================================================================================== 516*cdf0e10cSrcweir // DNDListenerContainer::acceptDrag 517*cdf0e10cSrcweir //================================================================================================== 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir void SAL_CALL DNDListenerContainer::acceptDrag( sal_Int8 dragOperation ) throw (RuntimeException) 520*cdf0e10cSrcweir { 521*cdf0e10cSrcweir if( m_xDropTargetDragContext.is() ) 522*cdf0e10cSrcweir { 523*cdf0e10cSrcweir m_xDropTargetDragContext->acceptDrag( dragOperation ); 524*cdf0e10cSrcweir m_xDropTargetDragContext.clear(); 525*cdf0e10cSrcweir } 526*cdf0e10cSrcweir } 527*cdf0e10cSrcweir 528*cdf0e10cSrcweir //================================================================================================== 529*cdf0e10cSrcweir // DNDListenerContainer::rejectDrag 530*cdf0e10cSrcweir //================================================================================================== 531*cdf0e10cSrcweir 532*cdf0e10cSrcweir void SAL_CALL DNDListenerContainer::rejectDrag( ) throw (RuntimeException) 533*cdf0e10cSrcweir { 534*cdf0e10cSrcweir // nothing to do here 535*cdf0e10cSrcweir } 536*cdf0e10cSrcweir 537*cdf0e10cSrcweir //================================================================================================== 538*cdf0e10cSrcweir // DNDListenerContainer::acceptDrop 539*cdf0e10cSrcweir //================================================================================================== 540*cdf0e10cSrcweir 541*cdf0e10cSrcweir void SAL_CALL DNDListenerContainer::acceptDrop( sal_Int8 dropOperation ) throw (RuntimeException) 542*cdf0e10cSrcweir { 543*cdf0e10cSrcweir if( m_xDropTargetDropContext.is() ) 544*cdf0e10cSrcweir m_xDropTargetDropContext->acceptDrop( dropOperation ); 545*cdf0e10cSrcweir } 546*cdf0e10cSrcweir 547*cdf0e10cSrcweir //================================================================================================== 548*cdf0e10cSrcweir // DNDListenerContainer::rejectDrop 549*cdf0e10cSrcweir //================================================================================================== 550*cdf0e10cSrcweir 551*cdf0e10cSrcweir void SAL_CALL DNDListenerContainer::rejectDrop( ) throw (RuntimeException) 552*cdf0e10cSrcweir { 553*cdf0e10cSrcweir // nothing to do here 554*cdf0e10cSrcweir } 555*cdf0e10cSrcweir 556*cdf0e10cSrcweir //================================================================================================== 557*cdf0e10cSrcweir // DNDListenerContainer::dropComplete 558*cdf0e10cSrcweir //================================================================================================== 559*cdf0e10cSrcweir 560*cdf0e10cSrcweir void SAL_CALL DNDListenerContainer::dropComplete( sal_Bool success ) throw (RuntimeException) 561*cdf0e10cSrcweir { 562*cdf0e10cSrcweir if( m_xDropTargetDropContext.is() ) 563*cdf0e10cSrcweir { 564*cdf0e10cSrcweir m_xDropTargetDropContext->dropComplete( success ); 565*cdf0e10cSrcweir m_xDropTargetDropContext.clear(); 566*cdf0e10cSrcweir } 567*cdf0e10cSrcweir } 568