LCOV - code coverage report
Current view: top level - vcl/source/window - dndlcon.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 25 181 13.8 %
Date: 2015-06-13 12:38:46 Functions: 9 23 39.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <dndlcon.hxx>
      21             : 
      22             : using namespace ::cppu;
      23             : using namespace ::com::sun::star::uno;
      24             : using namespace ::com::sun::star::datatransfer;
      25             : using namespace ::com::sun::star::datatransfer::dnd;
      26             : 
      27       23393 : DNDListenerContainer::DNDListenerContainer( sal_Int8 nDefaultActions )
      28       23393 :     : WeakComponentImplHelper4< XDragGestureRecognizer, XDropTargetDragContext, XDropTargetDropContext, XDropTarget >(GetMutex())
      29             : {
      30       23393 :     m_bActive = true;
      31       23393 :     m_nDefaultActions = nDefaultActions;
      32       23393 : }
      33             : 
      34       40472 : DNDListenerContainer::~DNDListenerContainer()
      35             : {
      36       40472 : }
      37             : 
      38             : // DNDListenerContainer::addDragGestureListener
      39             : 
      40       18322 : void SAL_CALL DNDListenerContainer::addDragGestureListener( const Reference< XDragGestureListener >& dgl )
      41             :     throw(RuntimeException, std::exception)
      42             : {
      43       18322 :     rBHelper.addListener( cppu::UnoType<XDragGestureListener>::get(), dgl );
      44       18322 : }
      45             : 
      46             : // DNDListenerContainer::removeDragGestureListener
      47             : 
      48       15057 : void SAL_CALL DNDListenerContainer::removeDragGestureListener( const Reference< XDragGestureListener >& dgl )
      49             :     throw(RuntimeException, std::exception)
      50             : {
      51       15057 :     rBHelper.removeListener( cppu::UnoType<XDragGestureListener>::get(), dgl );
      52       15057 : }
      53             : 
      54             : // DNDListenerContainer::resetRecognizer
      55             : 
      56           0 : void SAL_CALL DNDListenerContainer::resetRecognizer(  )
      57             :     throw(RuntimeException, std::exception)
      58             : {
      59           0 : }
      60             : 
      61             : // DNDListenerContainer::addDropTargetListener
      62             : 
      63       29431 : void SAL_CALL DNDListenerContainer::addDropTargetListener( const Reference< XDropTargetListener >& dtl )
      64             :     throw(RuntimeException, std::exception)
      65             : {
      66       29431 :     rBHelper.addListener( cppu::UnoType<XDropTargetListener>::get(), dtl );
      67       29431 : }
      68             : 
      69             : // DNDListenerContainer::removeDropTargetListener
      70             : 
      71       24891 : void SAL_CALL DNDListenerContainer::removeDropTargetListener( const Reference< XDropTargetListener >& dtl )
      72             :     throw(RuntimeException, std::exception)
      73             : {
      74       24891 :     rBHelper.removeListener( cppu::UnoType<XDropTargetListener>::get(), dtl );
      75       24891 : }
      76             : 
      77             : // DNDListenerContainer::isActive
      78             : 
      79           0 : sal_Bool SAL_CALL DNDListenerContainer::isActive(  )
      80             :     throw(RuntimeException, std::exception)
      81             : {
      82           0 :     return m_bActive;
      83             : }
      84             : 
      85             : // DNDListenerContainer::setActive
      86             : 
      87       38021 : void SAL_CALL DNDListenerContainer::setActive( sal_Bool active )
      88             :     throw(RuntimeException, std::exception)
      89             : {
      90       38021 :     m_bActive = active;
      91       38021 : }
      92             : 
      93             : // DNDListenerContainer::getDefaultActions
      94             : 
      95           0 : sal_Int8 SAL_CALL DNDListenerContainer::getDefaultActions(  )
      96             :     throw(RuntimeException, std::exception)
      97             : {
      98           0 :     return m_nDefaultActions;
      99             : }
     100             : 
     101             : // DNDListenerContainer::setDefaultActions
     102             : 
     103       14293 : void SAL_CALL DNDListenerContainer::setDefaultActions( sal_Int8 actions )
     104             :     throw(RuntimeException, std::exception)
     105             : {
     106       14293 :     m_nDefaultActions = actions;
     107       14293 : }
     108             : 
     109             : // DNDListenerContainer::fireDropEvent
     110             : 
     111           0 : sal_uInt32 DNDListenerContainer::fireDropEvent( const Reference< XDropTargetDropContext >& context,
     112             :     sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions,
     113             :     const Reference< XTransferable >& transferable )
     114             : {
     115           0 :     sal_uInt32 nRet = 0;
     116             : 
     117             :     // fire DropTargetDropEvent on all XDropTargetListeners
     118           0 :     OInterfaceContainerHelper *pContainer = rBHelper.getContainer( cppu::UnoType<XDropTargetListener>::get());
     119             : 
     120           0 :     if( pContainer && m_bActive )
     121             :     {
     122           0 :         OInterfaceIteratorHelper aIterator( *pContainer );
     123             : 
     124             :         // remember context to use in own context methods
     125           0 :         m_xDropTargetDropContext = context;
     126             : 
     127             :         // do not construct the event before you are sure at least one listener is registered
     128             :         DropTargetDropEvent aEvent( static_cast < XDropTarget * > (this), 0,
     129             :             static_cast < XDropTargetDropContext * > (this), dropAction,
     130           0 :             locationX, locationY, sourceActions, transferable );
     131             : 
     132           0 :         while (aIterator.hasMoreElements())
     133             :         {
     134             :             // FIXME: this can be simplified as soon as the Iterator has a remove method
     135           0 :             Reference< XInterface > xElement( aIterator.next() );
     136             : 
     137             :             try
     138             :             {
     139             :                 // this may result in a runtime exception
     140           0 :                 Reference < XDropTargetListener > xListener( xElement, UNO_QUERY );
     141             : 
     142           0 :                 if( xListener.is() )
     143             :                 {
     144             :                     // fire drop until the first one has accepted
     145           0 :                     if( m_xDropTargetDropContext.is() )
     146           0 :                         xListener->drop( aEvent );
     147             :                     else
     148             :                     {
     149           0 :                         DropTargetEvent aDTEvent( static_cast < XDropTarget * > (this), 0 );
     150           0 :                         xListener->dragExit( aDTEvent );
     151             :                     }
     152             : 
     153           0 :                     nRet++;
     154           0 :                 }
     155             :             }
     156           0 :             catch (const RuntimeException&)
     157             :             {
     158           0 :                 pContainer->removeInterface( xElement );
     159             :             }
     160           0 :         }
     161             : 
     162             :         // if context still valid, then reject drop
     163           0 :         if( m_xDropTargetDropContext.is() )
     164             :         {
     165           0 :             m_xDropTargetDropContext.clear();
     166             : 
     167             :             try
     168             :             {
     169           0 :                 context->rejectDrop();
     170             :             }
     171           0 :             catch (const RuntimeException&)
     172             :             {
     173             :             }
     174           0 :         }
     175             :     }
     176             : 
     177           0 :     return nRet;
     178             : }
     179             : 
     180             : // DNDListenerContainer::fireDragExitEvent
     181             : 
     182           0 : sal_uInt32 DNDListenerContainer::fireDragExitEvent()
     183             : {
     184           0 :     sal_uInt32 nRet = 0;
     185             : 
     186             :     // fire DropTargetDropEvent on all XDropTargetListeners
     187           0 :     OInterfaceContainerHelper *pContainer = rBHelper.getContainer( cppu::UnoType<XDropTargetListener>::get());
     188             : 
     189           0 :     if( pContainer && m_bActive )
     190             :     {
     191           0 :         OInterfaceIteratorHelper aIterator( *pContainer );
     192             : 
     193             :         // do not construct the event before you are sure at least one listener is registered
     194           0 :         DropTargetEvent aEvent( static_cast < XDropTarget * > (this), 0 );
     195             : 
     196           0 :         while (aIterator.hasMoreElements())
     197             :         {
     198             :             // FIXME: this can be simplified as soon as the Iterator has a remove method
     199           0 :             Reference< XInterface > xElement( aIterator.next() );
     200             : 
     201             :             try
     202             :             {
     203             :                 // this may result in a runtime exception
     204           0 :                 Reference < XDropTargetListener > xListener( xElement, UNO_QUERY );
     205             : 
     206           0 :                 if( xListener.is() )
     207             :                 {
     208           0 :                        xListener->dragExit( aEvent );
     209           0 :                     nRet++;
     210           0 :                 }
     211             :             }
     212           0 :             catch (const RuntimeException&)
     213             :             {
     214           0 :                 pContainer->removeInterface( xElement );
     215             :             }
     216           0 :         }
     217             :     }
     218             : 
     219           0 :     return nRet;
     220             : }
     221             : 
     222             : // DNDListenerContainer::fireDragOverEvent
     223             : 
     224           0 : sal_uInt32 DNDListenerContainer::fireDragOverEvent( const Reference< XDropTargetDragContext >& context,
     225             :     sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions )
     226             : {
     227           0 :     sal_uInt32 nRet = 0;
     228             : 
     229             :     // fire DropTargetDropEvent on all XDropTargetListeners
     230           0 :     OInterfaceContainerHelper *pContainer = rBHelper.getContainer( cppu::UnoType<XDropTargetListener>::get());
     231             : 
     232           0 :     if( pContainer && m_bActive )
     233             :     {
     234           0 :         OInterfaceIteratorHelper aIterator( *pContainer );
     235             : 
     236             :         // remember context to use in own context methods
     237           0 :         m_xDropTargetDragContext = context;
     238             : 
     239             :         // do not construct the event before you are sure at least one listener is registered
     240             :         DropTargetDragEvent aEvent( static_cast < XDropTarget * > (this), 0,
     241             :             static_cast < XDropTargetDragContext * > (this),
     242           0 :             dropAction, locationX, locationY, sourceActions );
     243             : 
     244           0 :         while (aIterator.hasMoreElements())
     245             :         {
     246             :             // FIXME: this can be simplified as soon as the Iterator has a remove method
     247           0 :             Reference< XInterface > xElement( aIterator.next() );
     248             : 
     249             :             try
     250             :             {
     251             :                 // this may result in a runtime exception
     252           0 :                 Reference < XDropTargetListener > xListener( xElement, UNO_QUERY );
     253             : 
     254           0 :                 if( xListener.is() )
     255             :                 {
     256           0 :                     if( m_xDropTargetDragContext.is() )
     257           0 :                         xListener->dragOver( aEvent );
     258           0 :                       nRet++;
     259           0 :                 }
     260             :             }
     261           0 :             catch (const RuntimeException&)
     262             :             {
     263           0 :                 pContainer->removeInterface( xElement );
     264             :             }
     265           0 :         }
     266             : 
     267             :         // if context still valid, then reject drag
     268           0 :         if( m_xDropTargetDragContext.is() )
     269             :         {
     270           0 :             m_xDropTargetDragContext.clear();
     271             : 
     272             :             try
     273             :             {
     274           0 :                 context->rejectDrag();
     275             :             }
     276           0 :             catch (const RuntimeException&)
     277             :             {
     278             :             }
     279           0 :         }
     280             :     }
     281             : 
     282           0 :     return nRet;
     283             : }
     284             : 
     285             : // DNDListenerContainer::fireDragEnterEvent
     286             : 
     287           0 : sal_uInt32 DNDListenerContainer::fireDragEnterEvent( const Reference< XDropTargetDragContext >& context,
     288             :     sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions,
     289             :     const Sequence< DataFlavor >& dataFlavors )
     290             : {
     291           0 :     sal_uInt32 nRet = 0;
     292             : 
     293             :     // fire DropTargetDropEvent on all XDropTargetListeners
     294           0 :     OInterfaceContainerHelper *pContainer = rBHelper.getContainer( cppu::UnoType<XDropTargetListener>::get());
     295             : 
     296           0 :     if( pContainer && m_bActive )
     297             :     {
     298           0 :         OInterfaceIteratorHelper aIterator( *pContainer );
     299             : 
     300             :         // remember context to use in own context methods
     301           0 :         m_xDropTargetDragContext = context;
     302             : 
     303             :         // do not construct the event before you are sure at least one listener is registered
     304             :         DropTargetDragEnterEvent aEvent( static_cast < XDropTarget * > (this), 0,
     305             :             static_cast < XDropTargetDragContext * > (this),
     306           0 :             dropAction, locationX, locationY, sourceActions, dataFlavors );
     307             : 
     308           0 :         while (aIterator.hasMoreElements())
     309             :         {
     310             :             // FIXME: this can be simplified as soon as the Iterator has a remove method
     311           0 :             Reference< XInterface > xElement( aIterator.next() );
     312             : 
     313             :             try
     314             :             {
     315             :                 // this may result in a runtime exception
     316           0 :                 Reference < XDropTargetListener > xListener( xElement, UNO_QUERY );
     317             : 
     318           0 :                 if( xListener.is() )
     319             :                 {
     320           0 :                     if( m_xDropTargetDragContext.is() )
     321           0 :                         xListener->dragEnter( aEvent );
     322           0 :                     nRet++;
     323           0 :                 }
     324             :             }
     325           0 :             catch (const RuntimeException&)
     326             :             {
     327           0 :                 pContainer->removeInterface( xElement );
     328             :             }
     329           0 :         }
     330             : 
     331             :         // if context still valid, then reject drag
     332           0 :         if( m_xDropTargetDragContext.is() )
     333             :         {
     334           0 :             m_xDropTargetDragContext.clear();
     335             : 
     336             :             try
     337             :             {
     338           0 :                 context->rejectDrag();
     339             :             }
     340           0 :             catch (const RuntimeException&)
     341             :             {
     342             :             }
     343           0 :         }
     344             :     }
     345             : 
     346           0 :     return nRet;
     347             : }
     348             : 
     349             : // DNDListenerContainer::fireDropActionChangedEvent
     350             : 
     351           0 : sal_uInt32 DNDListenerContainer::fireDropActionChangedEvent( const Reference< XDropTargetDragContext >& context,
     352             :     sal_Int8 dropAction, sal_Int32 locationX, sal_Int32 locationY, sal_Int8 sourceActions )
     353             : {
     354           0 :     sal_uInt32 nRet = 0;
     355             : 
     356             :     // fire DropTargetDropEvent on all XDropTargetListeners
     357           0 :     OInterfaceContainerHelper *pContainer = rBHelper.getContainer( cppu::UnoType<XDropTargetListener>::get());
     358             : 
     359           0 :     if( pContainer && m_bActive )
     360             :     {
     361           0 :         OInterfaceIteratorHelper aIterator( *pContainer );
     362             : 
     363             :         // remember context to use in own context methods
     364           0 :         m_xDropTargetDragContext = context;
     365             : 
     366             :         // do not construct the event before you are sure at least one listener is registered
     367             :         DropTargetDragEvent aEvent( static_cast < XDropTarget * > (this), 0,
     368             :             static_cast < XDropTargetDragContext * > (this),
     369           0 :             dropAction, locationX, locationY, sourceActions );
     370             : 
     371           0 :         while (aIterator.hasMoreElements())
     372             :         {
     373             :             // FIXME: this can be simplified as soon as the Iterator has a remove method
     374           0 :             Reference< XInterface > xElement( aIterator.next() );
     375             : 
     376             :             try
     377             :             {
     378             :                 // this may result in a runtime exception
     379           0 :                 Reference < XDropTargetListener > xListener( xElement, UNO_QUERY );
     380             : 
     381           0 :                 if( xListener.is() )
     382             :                 {
     383           0 :                     if( m_xDropTargetDragContext.is() )
     384           0 :                         xListener->dropActionChanged( aEvent );
     385           0 :                        nRet++;
     386           0 :                 }
     387             :             }
     388           0 :             catch (const RuntimeException&)
     389             :             {
     390           0 :                 pContainer->removeInterface( xElement );
     391             :             }
     392           0 :         }
     393             : 
     394             :         // if context still valid, then reject drag
     395           0 :         if( m_xDropTargetDragContext.is() )
     396             :         {
     397           0 :             m_xDropTargetDragContext.clear();
     398             : 
     399             :             try
     400             :             {
     401           0 :                 context->rejectDrag();
     402             :             }
     403           0 :             catch (const RuntimeException&)
     404             :             {
     405             :             }
     406           0 :         }
     407             :     }
     408             : 
     409           0 :     return nRet;
     410             : }
     411             : 
     412             : // DNDListenerContainer::fireDragGestureEvent
     413             : 
     414           0 : sal_uInt32 DNDListenerContainer::fireDragGestureEvent( sal_Int8 dragAction, sal_Int32 dragOriginX,
     415             :     sal_Int32 dragOriginY, const Reference< XDragSource >& dragSource, const Any& triggerEvent )
     416             : {
     417           0 :     sal_uInt32 nRet = 0;
     418             : 
     419             :     // fire DropTargetDropEvent on all XDropTargetListeners
     420           0 :     OInterfaceContainerHelper *pContainer = rBHelper.getContainer( cppu::UnoType<XDragGestureListener>::get());
     421             : 
     422           0 :     if( pContainer )
     423             :     {
     424           0 :         OInterfaceIteratorHelper aIterator( *pContainer );
     425             : 
     426             :         // do not construct the event before you are sure at least one listener is registered
     427             :         DragGestureEvent aEvent( static_cast < XDragGestureRecognizer * > (this), dragAction,
     428           0 :             dragOriginX, dragOriginY, dragSource, triggerEvent );
     429             : 
     430           0 :         while( aIterator.hasMoreElements() )
     431             :         {
     432             :             // FIXME: this can be simplified as soon as the Iterator has a remove method
     433           0 :             Reference< XInterface > xElement( aIterator.next() );
     434             : 
     435             :             try
     436             :             {
     437             :                 // this may result in a runtime exception
     438           0 :                 Reference < XDragGestureListener > xListener( xElement, UNO_QUERY );
     439             : 
     440           0 :                 if( xListener.is() )
     441             :                 {
     442           0 :                     xListener->dragGestureRecognized( aEvent );
     443           0 :                     nRet++;
     444           0 :                 }
     445             :             }
     446           0 :             catch (const RuntimeException&)
     447             :             {
     448           0 :                 pContainer->removeInterface( xElement );
     449             :             }
     450           0 :         }
     451             :     }
     452             : 
     453           0 :     return nRet;
     454             : }
     455             : 
     456             : // DNDListenerContainer::acceptDrag
     457             : 
     458           0 : void SAL_CALL DNDListenerContainer::acceptDrag( sal_Int8 dragOperation ) throw (RuntimeException, std::exception)
     459             : {
     460           0 :     if( m_xDropTargetDragContext.is() )
     461             :     {
     462           0 :         m_xDropTargetDragContext->acceptDrag( dragOperation );
     463           0 :         m_xDropTargetDragContext.clear();
     464             :     }
     465           0 : }
     466             : 
     467             : // DNDListenerContainer::rejectDrag
     468             : 
     469           0 : void SAL_CALL DNDListenerContainer::rejectDrag(  ) throw (RuntimeException, std::exception)
     470             : {
     471             :     // nothing to do here
     472           0 : }
     473             : 
     474             : // DNDListenerContainer::acceptDrop
     475             : 
     476           0 : void SAL_CALL DNDListenerContainer::acceptDrop( sal_Int8 dropOperation ) throw (RuntimeException, std::exception)
     477             : {
     478           0 :     if( m_xDropTargetDropContext.is() )
     479           0 :         m_xDropTargetDropContext->acceptDrop( dropOperation );
     480           0 : }
     481             : 
     482             : // DNDListenerContainer::rejectDrop
     483             : 
     484           0 : void SAL_CALL DNDListenerContainer::rejectDrop(  ) throw (RuntimeException, std::exception)
     485             : {
     486             :     // nothing to do here
     487           0 : }
     488             : 
     489             : // DNDListenerContainer::dropComplete
     490             : 
     491           0 : void SAL_CALL DNDListenerContainer::dropComplete( sal_Bool success ) throw (RuntimeException, std::exception)
     492             : {
     493           0 :     if( m_xDropTargetDropContext.is() )
     494             :     {
     495           0 :         m_xDropTargetDropContext->dropComplete( success );
     496           0 :         m_xDropTargetDropContext.clear();
     497             :     }
     498           0 : }
     499             : 
     500             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11