Files
libreoffice/vcl/source/window/dndlcon.cxx

573 lines
20 KiB
C++
Raw Normal View History

2001-02-05 08:45:05 +00:00
/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
2001-02-05 08:45:05 +00:00
*
* $RCSfile: dndlcon.cxx,v $
2001-02-05 08:45:05 +00:00
*
* $Revision: 1.8 $
2001-02-05 08:45:05 +00:00
*
* last change: $Author: rt $ $Date: 2005-09-09 12:24:26 $
2001-02-05 08:45:05 +00:00
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
2001-02-05 08:45:05 +00:00
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
2001-02-05 08:45:05 +00:00
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
2001-02-05 08:45:05 +00:00
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
2001-02-05 08:45:05 +00:00
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
2001-02-05 08:45:05 +00:00
*
************************************************************************/
#include<dndlcon.hxx>
using namespace ::cppu;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::datatransfer;
using namespace ::com::sun::star::datatransfer::dnd;
//==================================================================================================
//
//==================================================================================================
DNDListenerContainer::DNDListenerContainer( sal_Int8 nDefaultActions )
: WeakComponentImplHelper4< XDragGestureRecognizer, XDropTargetDragContext, XDropTargetDropContext, XDropTarget >(GetMutex())
2001-02-05 08:45:05 +00:00
{
2001-02-14 15:37:54 +00:00
m_bActive = sal_True;
2001-02-09 14:59:18 +00:00
m_nDefaultActions = nDefaultActions;
2001-02-05 08:45:05 +00:00
}
//==================================================================================================
//
//==================================================================================================
DNDListenerContainer::~DNDListenerContainer()
{
}
//==================================================================================================
// DNDListenerContainer::addDragGestureListener
//==================================================================================================
void SAL_CALL DNDListenerContainer::addDragGestureListener( const Reference< XDragGestureListener >& dgl )
throw(RuntimeException)
{
rBHelper.addListener( getCppuType( ( const Reference< XDragGestureListener > * ) 0 ), dgl );
}
//==================================================================================================
// DNDListenerContainer::removeDragGestureListener
//==================================================================================================
void SAL_CALL DNDListenerContainer::removeDragGestureListener( const Reference< XDragGestureListener >& dgl )
throw(RuntimeException)
{
rBHelper.removeListener( getCppuType( ( const Reference< XDragGestureListener > * ) 0 ), dgl );
}
//==================================================================================================
// DNDListenerContainer::resetRecognizer
//==================================================================================================
void SAL_CALL DNDListenerContainer::resetRecognizer( )
throw(RuntimeException)
{
}
//==================================================================================================
// DNDListenerContainer::addDropTargetListener
//==================================================================================================
void SAL_CALL DNDListenerContainer::addDropTargetListener( const Reference< XDropTargetListener >& dtl )
throw(RuntimeException)
{
rBHelper.addListener( getCppuType( ( const Reference< XDropTargetListener > * ) 0 ), dtl );
}
//==================================================================================================
// DNDListenerContainer::removeDropTargetListener
//==================================================================================================
void SAL_CALL DNDListenerContainer::removeDropTargetListener( const Reference< XDropTargetListener >& dtl )
throw(RuntimeException)
{
rBHelper.removeListener( getCppuType( ( const Reference< XDropTargetListener > * ) 0 ), dtl );
}
//==================================================================================================
// DNDListenerContainer::isActive
//==================================================================================================
sal_Bool SAL_CALL DNDListenerContainer::isActive( )
throw(RuntimeException)
{
return m_bActive;
}
//==================================================================================================
// DNDListenerContainer::setActive
//==================================================================================================
void SAL_CALL DNDListenerContainer::setActive( sal_Bool active )
throw(RuntimeException)
{
m_bActive = active;
}
//==================================================================================================
// DNDListenerContainer::getDefaultActions
//==================================================================================================
sal_Int8 SAL_CALL DNDListenerContainer::getDefaultActions( )
throw(RuntimeException)
{
return m_nDefaultActions;
}
//==================================================================================================
// DNDListenerContainer::setDefaultActions
//==================================================================================================
void SAL_CALL DNDListenerContainer::setDefaultActions( sal_Int8 actions )
throw(RuntimeException)
{
m_nDefaultActions = actions;
}
//==================================================================================================
// DNDListenerContainer::fireDropEvent
//==================================================================================================
sal_uInt32 DNDListenerContainer::fireDropEvent( const Reference< XDropTargetDropContext >& context,
2001-02-20 10:17:45 +00:00
sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions,
2001-02-05 08:45:05 +00:00
const Reference< XTransferable >& transferable )
{
sal_uInt32 nRet = 0;
// fire DropTargetDropEvent on all XDropTargetListeners
OInterfaceContainerHelper *pContainer = rBHelper.getContainer( getCppuType( ( Reference < XDropTargetListener > * ) 0) );
2001-02-14 15:37:54 +00:00
if( pContainer && m_bActive )
2001-02-05 08:45:05 +00:00
{
OInterfaceIteratorHelper aIterator( *pContainer );
// remember context to use in own context methods
m_xDropTargetDropContext = context;
2001-02-20 10:17:45 +00:00
// do not construct the event before you are sure at least one listener is registered
DropTargetDropEvent aEvent( static_cast < XDropTarget * > (this), 0,
static_cast < XDropTargetDropContext * > (this), dropAction,
2001-02-20 10:17:45 +00:00
locationX, locationY, sourceActions, transferable );
2001-02-05 08:45:05 +00:00
while (aIterator.hasMoreElements())
{
// FIXME: this can be simplified as soon as the Iterator has a remove method
Reference< XInterface > xElement( aIterator.next() );
try
{
// this may result in a runtime exception
Reference < XDropTargetListener > xListener( xElement, UNO_QUERY );
if( xListener.is() )
{
// fire drop until the first one has accepted
if( m_xDropTargetDropContext.is() )
xListener->drop( aEvent );
else
{
DropTargetEvent aEvent( static_cast < XDropTarget * > (this), 0 );
xListener->dragExit( aEvent );
}
2001-02-05 08:45:05 +00:00
nRet++;
}
}
catch( RuntimeException exc )
{
pContainer->removeInterface( xElement );
}
}
// if context still valid, then reject drop
if( m_xDropTargetDropContext.is() )
{
m_xDropTargetDropContext.clear();
try
{
context->rejectDrop();
}
catch( RuntimeException exc )
{
}
}
2001-02-05 08:45:05 +00:00
}
return nRet;
}
//==================================================================================================
// DNDListenerContainer::fireDragExitEvent
//==================================================================================================
sal_uInt32 DNDListenerContainer::fireDragExitEvent()
{
sal_uInt32 nRet = 0;
// fire DropTargetDropEvent on all XDropTargetListeners
OInterfaceContainerHelper *pContainer = rBHelper.getContainer( getCppuType( ( Reference < XDropTargetListener > * ) 0) );
2001-02-14 15:37:54 +00:00
if( pContainer && m_bActive )
2001-02-05 08:45:05 +00:00
{
2001-02-20 10:17:45 +00:00
OInterfaceIteratorHelper aIterator( *pContainer );
2001-02-05 08:45:05 +00:00
// do not construct the event before you are sure at least one listener is registered
DropTargetEvent aEvent( static_cast < XDropTarget * > (this), 0 );
while (aIterator.hasMoreElements())
{
// FIXME: this can be simplified as soon as the Iterator has a remove method
Reference< XInterface > xElement( aIterator.next() );
try
{
// this may result in a runtime exception
Reference < XDropTargetListener > xListener( xElement, UNO_QUERY );
if( xListener.is() )
{
xListener->dragExit( aEvent );
2001-02-05 08:45:05 +00:00
nRet++;
}
}
catch( RuntimeException exc )
{
pContainer->removeInterface( xElement );
}
}
}
return nRet;
}
//==================================================================================================
// DNDListenerContainer::fireDragOverEvent
//==================================================================================================
sal_uInt32 DNDListenerContainer::fireDragOverEvent( const Reference< XDropTargetDragContext >& context,
2001-02-20 10:17:45 +00:00
sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions )
2001-02-05 08:45:05 +00:00
{
sal_uInt32 nRet = 0;
// fire DropTargetDropEvent on all XDropTargetListeners
OInterfaceContainerHelper *pContainer = rBHelper.getContainer( getCppuType( ( Reference < XDropTargetListener > * ) 0) );
2001-02-14 15:37:54 +00:00
if( pContainer && m_bActive )
2001-02-05 08:45:05 +00:00
{
OInterfaceIteratorHelper aIterator( *pContainer );
// remember context to use in own context methods
m_xDropTargetDragContext = context;
2001-02-20 10:17:45 +00:00
// do not construct the event before you are sure at least one listener is registered
DropTargetDragEvent aEvent( static_cast < XDropTarget * > (this), 0,
static_cast < XDropTargetDragContext * > (this),
dropAction, locationX, locationY, sourceActions );
2001-02-20 10:17:45 +00:00
2001-02-05 08:45:05 +00:00
while (aIterator.hasMoreElements())
{
// FIXME: this can be simplified as soon as the Iterator has a remove method
Reference< XInterface > xElement( aIterator.next() );
try
{
// this may result in a runtime exception
Reference < XDropTargetListener > xListener( xElement, UNO_QUERY );
if( xListener.is() )
{
if( m_xDropTargetDragContext.is() )
xListener->dragOver( aEvent );
nRet++;
2001-02-05 08:45:05 +00:00
}
}
catch( RuntimeException exc )
{
pContainer->removeInterface( xElement );
}
}
// if context still valid, then reject drag
if( m_xDropTargetDragContext.is() )
{
m_xDropTargetDragContext.clear();
try
{
context->rejectDrag();
}
catch( RuntimeException exc )
{
}
}
2001-02-05 08:45:05 +00:00
}
return nRet;
}
//==================================================================================================
// DNDListenerContainer::fireDragEnterEvent
//==================================================================================================
sal_uInt32 DNDListenerContainer::fireDragEnterEvent( const Reference< XDropTargetDragContext >& context,
2001-02-20 10:17:45 +00:00
sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions,
const Sequence< DataFlavor >& dataFlavors )
2001-02-05 08:45:05 +00:00
{
sal_uInt32 nRet = 0;
// fire DropTargetDropEvent on all XDropTargetListeners
OInterfaceContainerHelper *pContainer = rBHelper.getContainer( getCppuType( ( Reference < XDropTargetListener > * ) 0) );
2001-02-14 15:37:54 +00:00
if( pContainer && m_bActive )
2001-02-05 08:45:05 +00:00
{
OInterfaceIteratorHelper aIterator( *pContainer );
// remember context to use in own context methods
m_xDropTargetDragContext = context;
2001-02-20 10:17:45 +00:00
// do not construct the event before you are sure at least one listener is registered
DropTargetDragEnterEvent aEvent( static_cast < XDropTarget * > (this), 0,
static_cast < XDropTargetDragContext * > (this),
dropAction, locationX, locationY, sourceActions, dataFlavors );
2001-02-20 10:17:45 +00:00
2001-02-05 08:45:05 +00:00
while (aIterator.hasMoreElements())
{
// FIXME: this can be simplified as soon as the Iterator has a remove method
Reference< XInterface > xElement( aIterator.next() );
try
{
// this may result in a runtime exception
Reference < XDropTargetListener > xListener( xElement, UNO_QUERY );
if( xListener.is() )
{
if( m_xDropTargetDragContext.is() )
xListener->dragEnter( aEvent );
2001-02-05 08:45:05 +00:00
nRet++;
}
}
catch( RuntimeException exc )
{
pContainer->removeInterface( xElement );
}
}
// if context still valid, then reject drag
if( m_xDropTargetDragContext.is() )
{
m_xDropTargetDragContext.clear();
try
{
context->rejectDrag();
}
catch( RuntimeException exc )
{
}
}
2001-02-05 08:45:05 +00:00
}
return nRet;
}
//==================================================================================================
// DNDListenerContainer::fireDropActionChangedEvent
//==================================================================================================
sal_uInt32 DNDListenerContainer::fireDropActionChangedEvent( const Reference< XDropTargetDragContext >& context,
2001-02-20 10:17:45 +00:00
sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions )
2001-02-05 08:45:05 +00:00
{
sal_uInt32 nRet = 0;
// fire DropTargetDropEvent on all XDropTargetListeners
OInterfaceContainerHelper *pContainer = rBHelper.getContainer( getCppuType( ( Reference < XDropTargetListener > * ) 0) );
2001-02-14 15:37:54 +00:00
if( pContainer && m_bActive )
2001-02-05 08:45:05 +00:00
{
OInterfaceIteratorHelper aIterator( *pContainer );
// remember context to use in own context methods
m_xDropTargetDragContext = context;
2001-02-20 10:17:45 +00:00
// do not construct the event before you are sure at least one listener is registered
DropTargetDragEvent aEvent( static_cast < XDropTarget * > (this), 0,
static_cast < XDropTargetDragContext * > (this),
dropAction, locationX, locationY, sourceActions );
2001-02-20 10:17:45 +00:00
2001-02-05 08:45:05 +00:00
while (aIterator.hasMoreElements())
{
// FIXME: this can be simplified as soon as the Iterator has a remove method
Reference< XInterface > xElement( aIterator.next() );
try
{
// this may result in a runtime exception
Reference < XDropTargetListener > xListener( xElement, UNO_QUERY );
if( xListener.is() )
{
if( m_xDropTargetDragContext.is() )
xListener->dropActionChanged( aEvent );
nRet++;
2001-02-05 08:45:05 +00:00
}
}
catch( RuntimeException exc )
{
pContainer->removeInterface( xElement );
}
}
// if context still valid, then reject drag
if( m_xDropTargetDragContext.is() )
{
m_xDropTargetDragContext.clear();
try
{
context->rejectDrag();
}
catch( RuntimeException exc )
{
}
}
2001-02-05 08:45:05 +00:00
}
return nRet;
}
//==================================================================================================
// DNDListenerContainer::fireDragGestureEvent
//==================================================================================================
sal_uInt32 DNDListenerContainer::fireDragGestureEvent( sal_Int8 dragAction, sal_Int32 dragOriginX,
2001-02-20 10:17:45 +00:00
sal_Int32 dragOriginY, const Reference< XDragSource >& dragSource, const Any& triggerEvent )
2001-02-05 08:45:05 +00:00
{
sal_uInt32 nRet = 0;
// fire DropTargetDropEvent on all XDropTargetListeners
OInterfaceContainerHelper *pContainer = rBHelper.getContainer( getCppuType( ( Reference < XDragGestureListener > * ) 0) );
if( pContainer )
{
OInterfaceIteratorHelper aIterator( *pContainer );
2001-02-20 10:17:45 +00:00
// do not construct the event before you are sure at least one listener is registered
DragGestureEvent aEvent( static_cast < XDragGestureRecognizer * > (this), dragAction,
dragOriginX, dragOriginY, dragSource, triggerEvent );
2001-02-05 08:45:05 +00:00
while( aIterator.hasMoreElements() )
{
// FIXME: this can be simplified as soon as the Iterator has a remove method
Reference< XInterface > xElement( aIterator.next() );
try
{
// this may result in a runtime exception
Reference < XDragGestureListener > xListener( xElement, UNO_QUERY );
if( xListener.is() )
{
xListener->dragGestureRecognized( aEvent );
nRet++;
}
}
catch( RuntimeException exc )
{
pContainer->removeInterface( xElement );
}
}
}
return nRet;
}
//==================================================================================================
// DNDListenerContainer::acceptDrag
//==================================================================================================
void SAL_CALL DNDListenerContainer::acceptDrag( sal_Int8 dragOperation ) throw (RuntimeException)
{
if( m_xDropTargetDragContext.is() )
{
m_xDropTargetDragContext->acceptDrag( dragOperation );
m_xDropTargetDragContext.clear();
}
}
//==================================================================================================
// DNDListenerContainer::rejectDrag
//==================================================================================================
void SAL_CALL DNDListenerContainer::rejectDrag( ) throw (RuntimeException)
{
// nothing to do here
}
//==================================================================================================
// DNDListenerContainer::acceptDrop
//==================================================================================================
void SAL_CALL DNDListenerContainer::acceptDrop( sal_Int8 dropOperation ) throw (RuntimeException)
{
if( m_xDropTargetDropContext.is() )
m_xDropTargetDropContext->acceptDrop( dropOperation );
}
//==================================================================================================
// DNDListenerContainer::rejectDrop
//==================================================================================================
void SAL_CALL DNDListenerContainer::rejectDrop( ) throw (RuntimeException)
{
// nothing to do here
}
//==================================================================================================
// DNDListenerContainer::dropComplete
//==================================================================================================
void SAL_CALL DNDListenerContainer::dropComplete( sal_Bool success ) throw (RuntimeException)
{
if( m_xDropTargetDropContext.is() )
{
m_xDropTargetDropContext->dropComplete( success );
m_xDropTargetDropContext.clear();
}
}