LCOV - code coverage report
Current view: top level - extensions/source/plugin/base - multiplx.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 147 0.0 %
Date: 2014-04-14 Functions: 0 30 0.0 %
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             :  *
       4             :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5             :  *
       6             :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7             :  *
       8             :  * OpenOffice.org - a multi-platform office productivity suite
       9             :  *
      10             :  * This file is part of OpenOffice.org.
      11             :  *
      12             :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13             :  * it under the terms of the GNU Lesser General Public License version 3
      14             :  * only, as published by the Free Software Foundation.
      15             :  *
      16             :  * OpenOffice.org is distributed in the hope that it will be useful,
      17             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19             :  * GNU Lesser General Public License version 3 for more details
      20             :  * (a copy is included in the LICENSE file that accompanied this code).
      21             :  *
      22             :  * You should have received a copy of the GNU Lesser General Public License
      23             :  * version 3 along with OpenOffice.org.  If not, see
      24             :  * <http://www.openoffice.org/license.html>
      25             :  * for a copy of the LGPLv3 License.
      26             :  *
      27             :  ************************************************************************/
      28             : 
      29             : #include <osl/diagnose.h>
      30             : #include <plugin/multiplx.hxx>
      31             : 
      32             : 
      33             : //  class MRCListenerMultiplexerHelper
      34             : 
      35           0 : MRCListenerMultiplexerHelper::MRCListenerMultiplexerHelper
      36             : (
      37             :       const Reference< ::com::sun::star::awt::XWindow >  & rControl
      38             :     , const Reference< ::com::sun::star::awt::XWindow >  & rPeer
      39             : )
      40             :     : xPeer( rPeer )
      41             :     , xControl( Reference< ::com::sun::star::awt::XControl >( rControl, UNO_QUERY ) )
      42           0 :     , aListenerHolder( aMutex )
      43             : {
      44           0 : }
      45             : 
      46             : 
      47           0 : void MRCListenerMultiplexerHelper::setPeer( const Reference< ::com::sun::star::awt::XWindow >  & rPeer )
      48             : {
      49           0 :     ::osl::Guard< ::osl::Mutex > aGuard( aMutex );
      50           0 :     if( xPeer != rPeer )
      51             :     {
      52           0 :         if( xPeer.is() )
      53             :         {
      54             :             // get all uiks from the listener added to the peer
      55           0 :             Sequence<Type> aContainedTypes = aListenerHolder.getContainedTypes();
      56           0 :             const Type* pArray = aContainedTypes.getConstArray();
      57           0 :             sal_Int32 nCount = aContainedTypes.getLength();
      58             :             // loop over all listener types and remove the listeners from the peer
      59           0 :             for( sal_Int32 i = 0; i < nCount; i++ )
      60           0 :                 unadviseFromPeer( xPeer, pArray[i] );
      61             :         }
      62           0 :         xPeer = rPeer;
      63           0 :         if( xPeer.is() )
      64             :         {
      65             :             // get all uiks from the listener added to the peer
      66           0 :             Sequence<Type> aContainedTypes = aListenerHolder.getContainedTypes();
      67           0 :             const Type * pArray = aContainedTypes.getConstArray();
      68           0 :             sal_Int32 nCount = aContainedTypes.getLength();
      69             :             // loop over all listener types and add the listeners to the peer
      70           0 :             for( sal_Int32 i = 0; i < nCount; i++ )
      71           0 :                 adviseToPeer( xPeer, pArray[i] );
      72             :         }
      73           0 :     }
      74           0 : }
      75             : 
      76             : // MRCListenerMultiplexerHelper
      77           0 : void MRCListenerMultiplexerHelper::disposeAndClear()
      78             : {
      79           0 :     ::com::sun::star::lang::EventObject aEvt;
      80           0 :     aEvt.Source = xControl;
      81           0 :     aListenerHolder.disposeAndClear( aEvt );
      82           0 : }
      83             : 
      84             : // MRCListenerMultiplexerHelper
      85           0 : void MRCListenerMultiplexerHelper::adviseToPeer( const Reference< ::com::sun::star::awt::XWindow >  & rPeer, const Type & type )
      86             : {
      87             :     // add a listener to the source (peer)
      88           0 :     if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XWindowListener >*)0) )
      89           0 :         rPeer->addWindowListener( this );
      90           0 :     else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XKeyListener >*)0) )
      91           0 :         rPeer->addKeyListener( this );
      92           0 :     else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XFocusListener >*)0) )
      93           0 :         rPeer->addFocusListener( this );
      94           0 :     else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XMouseListener >*)0) )
      95           0 :         rPeer->addMouseListener( this );
      96           0 :     else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XMouseMotionListener >*)0) )
      97           0 :         rPeer->addMouseMotionListener( this );
      98           0 :     else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XPaintListener >*)0) )
      99           0 :         rPeer->addPaintListener( this );
     100           0 :     else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XTopWindowListener >*)0) )
     101             :     {
     102           0 :         Reference< ::com::sun::star::awt::XTopWindow >  xTop( rPeer, UNO_QUERY );
     103           0 :         if( xTop.is() )
     104           0 :             xTop->addTopWindowListener( this );
     105             :     }
     106             :     else
     107             :     {
     108             :         OSL_FAIL( "unknown listener" );
     109             :     }
     110           0 : }
     111             : 
     112             : // MRCListenerMultiplexerHelper
     113           0 : void MRCListenerMultiplexerHelper::unadviseFromPeer( const Reference< ::com::sun::star::awt::XWindow >  & rPeer, const Type & type )
     114             : {
     115             :     // the last listener is removed, remove the listener from the source (peer)
     116           0 :     if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XWindowListener >*)0) )
     117           0 :         rPeer->removeWindowListener( this );
     118           0 :     else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XKeyListener >*)0) )
     119           0 :         rPeer->removeKeyListener( this );
     120           0 :     else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XFocusListener >*)0) )
     121           0 :         rPeer->removeFocusListener( this );
     122           0 :     else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XMouseListener >*)0) )
     123           0 :         rPeer->removeMouseListener( this );
     124           0 :     else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XMouseMotionListener >*)0) )
     125           0 :         rPeer->removeMouseMotionListener( this );
     126           0 :     else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XPaintListener >*)0) )
     127           0 :         rPeer->removePaintListener( this );
     128           0 :     else if( type == ::getCppuType((const Reference< ::com::sun::star::awt::XTopWindowListener >*)0) )
     129             :     {
     130           0 :         Reference< ::com::sun::star::awt::XTopWindow >  xTop( rPeer, UNO_QUERY );
     131           0 :         if( xTop.is() )
     132           0 :             xTop->removeTopWindowListener( this );
     133             :     }
     134             :     else
     135             :     {
     136             :         OSL_FAIL( "unknown listener" );
     137             :     }
     138           0 : }
     139             : 
     140             : // MRCListenerMultiplexerHelper
     141           0 : void MRCListenerMultiplexerHelper::advise( const Type & type, const Reference< XInterface > & listener)
     142             : {
     143           0 :     ::osl::Guard< ::osl::Mutex > aGuard( aMutex );
     144           0 :     if( 1 == aListenerHolder.addInterface( type, listener ) )
     145             :     {
     146             :         // the first listener is added
     147           0 :         if( xPeer.is() )
     148           0 :             adviseToPeer( xPeer, type );
     149           0 :     }
     150           0 : }
     151             : 
     152             : // MRCListenerMultiplexerHelper
     153           0 : void MRCListenerMultiplexerHelper::unadvise(const Type & type, const Reference< XInterface > & listener)
     154             : {
     155           0 :     ::osl::Guard< ::osl::Mutex > aGuard( aMutex );
     156           0 :     ::cppu::OInterfaceContainerHelper * pCont = aListenerHolder.getContainer( type );
     157           0 :     if( pCont )
     158             :     {
     159           0 :         if( 0 == pCont->removeInterface( listener ) && xPeer.is() )
     160             :             // the last listener is removed
     161           0 :             unadviseFromPeer( xPeer, type );
     162           0 :     }
     163           0 : }
     164             : 
     165             : // ::com::sun::star::lang::XEventListener
     166           0 : void MRCListenerMultiplexerHelper::disposing(const ::com::sun::star::lang::EventObject& ) throw(std::exception)
     167             : {
     168           0 :     ::osl::Guard< ::osl::Mutex > aGuard( aMutex );
     169             :     // peer is disposed, clear the reference
     170           0 :     xPeer = Reference< ::com::sun::star::awt::XWindow > ();
     171           0 : }
     172             : 
     173             : #define MULTIPLEX( InterfaceName, MethodName, EventName )                   \
     174             : ::cppu::OInterfaceContainerHelper * pCont;                                          \
     175             : pCont = aListenerHolder.getContainer( ::getCppuType((const Reference< InterfaceName >*)0) );        \
     176             : if( pCont )                                                                 \
     177             : {                                                                           \
     178             :     ::cppu::OInterfaceIteratorHelper    aIt( *pCont );                              \
     179             :     EventName aEvt = e;                                                     \
     180             :     /* Remark: The control is the event source not the peer. We must change */  \
     181             :     /* the source of the event */                                               \
     182             :     aEvt.Source = xControl;\
     183             :     /*.is the control not destroyed */                                      \
     184             :     if( aEvt.Source.is() )                                                  \
     185             :     {                                                                       \
     186             :         if( aIt.hasMoreElements() )                                         \
     187             :         {                                                                   \
     188             :             InterfaceName * pListener = (InterfaceName *)aIt.next();        \
     189             :             try                                                             \
     190             :             {                                                               \
     191             :                 pListener->MethodName( aEvt );                              \
     192             :             }                                                               \
     193             :             catch(const RuntimeException&)                                  \
     194             :             {                                                               \
     195             :                 /* ignore all usr system exceptions from the listener */    \
     196             :             }                                                               \
     197             :         }                                                                   \
     198             :     }                                                                       \
     199             : }
     200             : 
     201             : // ::com::sun::star::awt::XFocusListener
     202           0 : void MRCListenerMultiplexerHelper::focusGained(const ::com::sun::star::awt::FocusEvent& e) throw(std::exception)
     203             : {
     204           0 :     MULTIPLEX( ::com::sun::star::awt::XFocusListener, focusGained, ::com::sun::star::awt::FocusEvent )
     205           0 : }
     206             : 
     207             : // ::com::sun::star::awt::XFocusListener
     208           0 : void MRCListenerMultiplexerHelper::focusLost(const ::com::sun::star::awt::FocusEvent& e) throw(std::exception)
     209             : {
     210           0 :     MULTIPLEX( ::com::sun::star::awt::XFocusListener, focusLost, ::com::sun::star::awt::FocusEvent )
     211           0 : }
     212             : 
     213             : // ::com::sun::star::awt::XWindowListener
     214           0 : void MRCListenerMultiplexerHelper::windowResized(const ::com::sun::star::awt::WindowEvent& e) throw(std::exception)
     215             : {
     216           0 :     MULTIPLEX( ::com::sun::star::awt::XWindowListener, windowResized, ::com::sun::star::awt::WindowEvent )
     217           0 : }
     218             : 
     219             : // ::com::sun::star::awt::XWindowListener
     220           0 : void MRCListenerMultiplexerHelper::windowMoved(const ::com::sun::star::awt::WindowEvent& e) throw(std::exception)
     221             : {
     222           0 :     MULTIPLEX( ::com::sun::star::awt::XWindowListener, windowMoved, ::com::sun::star::awt::WindowEvent )
     223           0 : }
     224             : 
     225             : // ::com::sun::star::awt::XWindowListener
     226           0 : void MRCListenerMultiplexerHelper::windowShown(const ::com::sun::star::lang::EventObject& e) throw(std::exception)
     227             : {
     228           0 :     MULTIPLEX( ::com::sun::star::awt::XWindowListener, windowShown, ::com::sun::star::lang::EventObject )
     229           0 : }
     230             : 
     231             : // ::com::sun::star::awt::XWindowListener
     232           0 : void MRCListenerMultiplexerHelper::windowHidden(const ::com::sun::star::lang::EventObject& e) throw(std::exception)
     233             : {
     234           0 :     MULTIPLEX( ::com::sun::star::awt::XWindowListener, windowHidden, ::com::sun::star::lang::EventObject )
     235           0 : }
     236             : 
     237             : // ::com::sun::star::awt::XKeyListener
     238           0 : void MRCListenerMultiplexerHelper::keyPressed(const ::com::sun::star::awt::KeyEvent& e) throw(std::exception)
     239             : {
     240           0 :     MULTIPLEX( ::com::sun::star::awt::XKeyListener, keyPressed, ::com::sun::star::awt::KeyEvent )
     241           0 : }
     242             : 
     243             : // ::com::sun::star::awt::XKeyListener
     244           0 : void MRCListenerMultiplexerHelper::keyReleased(const ::com::sun::star::awt::KeyEvent& e) throw(std::exception)
     245             : {
     246           0 :     MULTIPLEX( ::com::sun::star::awt::XKeyListener, keyReleased, ::com::sun::star::awt::KeyEvent )
     247           0 : }
     248             : 
     249             : // ::com::sun::star::awt::XMouseListener
     250           0 : void MRCListenerMultiplexerHelper::mousePressed(const ::com::sun::star::awt::MouseEvent& e) throw(std::exception)
     251             : {
     252           0 :     MULTIPLEX( ::com::sun::star::awt::XMouseListener, mousePressed, ::com::sun::star::awt::MouseEvent )
     253           0 : }
     254             : 
     255             : // ::com::sun::star::awt::XMouseListener
     256           0 : void MRCListenerMultiplexerHelper::mouseReleased(const ::com::sun::star::awt::MouseEvent& e) throw(std::exception)
     257             : {
     258           0 :     MULTIPLEX( ::com::sun::star::awt::XMouseListener, mouseReleased, ::com::sun::star::awt::MouseEvent )
     259           0 : }
     260             : 
     261             : // ::com::sun::star::awt::XMouseListener
     262           0 : void MRCListenerMultiplexerHelper::mouseEntered(const ::com::sun::star::awt::MouseEvent& e) throw(std::exception)
     263             : {
     264           0 :     MULTIPLEX( ::com::sun::star::awt::XMouseListener, mouseEntered, ::com::sun::star::awt::MouseEvent )
     265           0 : }
     266             : 
     267             : // ::com::sun::star::awt::XMouseListener
     268           0 : void MRCListenerMultiplexerHelper::mouseExited(const ::com::sun::star::awt::MouseEvent& e) throw(std::exception)
     269             : {
     270           0 :     MULTIPLEX( ::com::sun::star::awt::XMouseListener, mouseExited, ::com::sun::star::awt::MouseEvent )
     271           0 : }
     272             : 
     273             : // ::com::sun::star::awt::XMouseMotionListener
     274           0 : void MRCListenerMultiplexerHelper::mouseDragged(const ::com::sun::star::awt::MouseEvent& e) throw(std::exception)
     275             : {
     276           0 :     MULTIPLEX( ::com::sun::star::awt::XMouseMotionListener, mouseDragged, ::com::sun::star::awt::MouseEvent )
     277           0 : }
     278             : 
     279             : // ::com::sun::star::awt::XMouseMotionListener
     280           0 : void MRCListenerMultiplexerHelper::mouseMoved(const ::com::sun::star::awt::MouseEvent& e) throw(std::exception)
     281             : {
     282           0 :     MULTIPLEX( ::com::sun::star::awt::XMouseMotionListener, mouseMoved, ::com::sun::star::awt::MouseEvent )
     283           0 : }
     284             : 
     285             : // ::com::sun::star::awt::XPaintListener
     286           0 : void MRCListenerMultiplexerHelper::windowPaint(const ::com::sun::star::awt::PaintEvent& e) throw(std::exception)
     287             : {
     288           0 :     MULTIPLEX( ::com::sun::star::awt::XPaintListener, windowPaint, ::com::sun::star::awt::PaintEvent )
     289           0 : }
     290             : 
     291             : // ::com::sun::star::awt::XTopWindowListener
     292           0 : void MRCListenerMultiplexerHelper::windowOpened(const ::com::sun::star::lang::EventObject& e) throw(std::exception)
     293             : {
     294           0 :     MULTIPLEX( ::com::sun::star::awt::XTopWindowListener, windowOpened, ::com::sun::star::lang::EventObject )
     295           0 : }
     296             : 
     297             : // ::com::sun::star::awt::XTopWindowListener
     298           0 : void MRCListenerMultiplexerHelper::windowClosing( const ::com::sun::star::lang::EventObject& e ) throw(std::exception)
     299             : {
     300           0 :     MULTIPLEX( ::com::sun::star::awt::XTopWindowListener, windowClosing, ::com::sun::star::lang::EventObject )
     301           0 : }
     302             : 
     303             : // ::com::sun::star::awt::XTopWindowListener
     304           0 : void MRCListenerMultiplexerHelper::windowClosed( const ::com::sun::star::lang::EventObject& e ) throw(std::exception)
     305             : {
     306           0 :     MULTIPLEX( ::com::sun::star::awt::XTopWindowListener, windowClosed, ::com::sun::star::lang::EventObject )
     307           0 : }
     308             : 
     309             : // ::com::sun::star::awt::XTopWindowListener
     310           0 : void MRCListenerMultiplexerHelper::windowMinimized( const ::com::sun::star::lang::EventObject& e ) throw(std::exception)
     311             : {
     312           0 :     MULTIPLEX( ::com::sun::star::awt::XTopWindowListener, windowMinimized, ::com::sun::star::lang::EventObject )
     313           0 : }
     314             : 
     315             : // ::com::sun::star::awt::XTopWindowListener
     316           0 : void MRCListenerMultiplexerHelper::windowNormalized( const ::com::sun::star::lang::EventObject& e ) throw(std::exception)
     317             : {
     318           0 :     MULTIPLEX( ::com::sun::star::awt::XTopWindowListener, windowNormalized, ::com::sun::star::lang::EventObject )
     319           0 : }
     320             : 
     321             : // ::com::sun::star::awt::XTopWindowListener
     322           0 : void MRCListenerMultiplexerHelper::windowActivated( const ::com::sun::star::lang::EventObject& e ) throw(std::exception)
     323             : {
     324           0 :     MULTIPLEX( ::com::sun::star::awt::XTopWindowListener, windowActivated, ::com::sun::star::lang::EventObject )
     325           0 : }
     326             : 
     327             : // ::com::sun::star::awt::XTopWindowListener
     328           0 : void MRCListenerMultiplexerHelper::windowDeactivated( const ::com::sun::star::lang::EventObject& e ) throw(std::exception)
     329             : {
     330           0 :     MULTIPLEX( ::com::sun::star::awt::XTopWindowListener, windowDeactivated, ::com::sun::star::lang::EventObject )
     331           0 : }
     332             : 
     333             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10