LCOV - code coverage report
Current view: top level - chart2/source/inc - WeakListenerAdapter.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 12 15 80.0 %
Date: 2012-08-25 Functions: 4 10 40.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 9 32 28.1 %

           Branch data     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                 :            : #ifndef CHART2_WEAKLISTENERADAPTER_HXX
      20                 :            : #define CHART2_WEAKLISTENERADAPTER_HXX
      21                 :            : 
      22                 :            : #include <com/sun/star/uno/XWeak.hpp>
      23                 :            : #include <com/sun/star/lang/XEventListener.hpp>
      24                 :            : #include <com/sun/star/util/XModifyListener.hpp>
      25                 :            : #include <com/sun/star/view/XSelectionChangeListener.hpp>
      26                 :            : #include <cppuhelper/weakref.hxx>
      27                 :            : #include <cppuhelper/implbase1.hxx>
      28                 :            : 
      29                 :            : namespace chart
      30                 :            : {
      31                 :            : // --------------------------------------------------------------------------------
      32                 :            : 
      33                 :            : /** Adapter that enables adding listeners as weak UNO references.  Thus, adding
      34                 :            :     an object as listener to a broadcaster does not increase its reference
      35                 :            :     count.
      36                 :            : 
      37                 :            :     <p>The helper class, of course, is held as hard reference at the
      38                 :            :     broadcaster, but this should never be a problem as the adapter's life time
      39                 :            :     depends on no other object.</p>
      40                 :            : 
      41                 :            :     <p>Note that in order to remove an object as listener, you have to remove
      42                 :            :     the same wrapper that you added, i.e., you should store the adapter as a
      43                 :            :     member in the adaptee class for later use.</p>
      44                 :            :  */
      45                 :            : template< class Listener >
      46                 :            :     class WeakListenerAdapter : public
      47                 :            :     ::cppu::WeakImplHelper1< Listener >
      48                 :            : {
      49                 :            : public:
      50                 :          0 :     explicit WeakListenerAdapter( const ::com::sun::star::uno::Reference< Listener > & xListener ) :
      51         [ #  # ]:          0 :             m_xListener( xListener )
      52                 :          0 :     {}
      53                 :      15662 :     explicit WeakListenerAdapter( const ::com::sun::star::uno::WeakReference< Listener > & xListener ) :
      54         [ +  - ]:      15662 :             m_xListener( xListener )
      55                 :      15662 :     {}
      56                 :      15662 :     virtual ~WeakListenerAdapter()
      57 [ #  # ][ #  # ]:      15662 :     {}
         [ +  - ][ -  + ]
      58                 :            : 
      59                 :            : protected:
      60                 :            :     // ____ XEventListener (base of all listeners) ____
      61                 :        146 :     virtual void SAL_CALL disposing(
      62                 :            :         const ::com::sun::star::lang::EventObject& Source )
      63                 :            :         throw (::com::sun::star::uno::RuntimeException)
      64                 :            :     {
      65                 :            :         ::com::sun::star::uno::Reference<
      66                 :            :               ::com::sun::star::lang::XEventListener > xEventListener =
      67                 :            :           ::com::sun::star::uno::Reference<
      68                 :            :               ::com::sun::star::lang::XEventListener >(
      69 [ +  - ][ +  - ]:        146 :                   ::com::sun::star::uno::Reference< Listener >( m_xListener), ::com::sun::star::uno::UNO_QUERY );
         [ #  # ][ #  # ]
      70   [ +  +  #  # ]:        146 :         if( xEventListener.is())
      71 [ +  - ][ +  - ]:        146 :             xEventListener->disposing( Source );
         [ #  # ][ #  # ]
      72                 :        146 :     }
      73                 :            : 
      74                 :      20069 :     ::com::sun::star::uno::Reference< Listener > getListener() const
      75                 :            :     {
      76                 :      20069 :         return m_xListener;
      77                 :            :     }
      78                 :            : 
      79                 :            : private:
      80                 :            :     ::com::sun::star::uno::WeakReference< Listener > m_xListener;
      81                 :            : };
      82                 :            : 
      83                 :            : // --------------------------------------------------------------------------------
      84                 :            : 
      85                 :            : class WeakModifyListenerAdapter :
      86                 :            :         public WeakListenerAdapter< ::com::sun::star::util::XModifyListener >
      87                 :            : {
      88                 :            : public:
      89                 :            :     explicit WeakModifyListenerAdapter(
      90                 :            :         const ::com::sun::star::uno::WeakReference< ::com::sun::star::util::XModifyListener > & xListener );
      91                 :            :     virtual ~WeakModifyListenerAdapter();
      92                 :            : 
      93                 :            : protected:
      94                 :            :     // ____ XModifyListener ____
      95                 :            :     virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent )
      96                 :            :         throw (::com::sun::star::uno::RuntimeException);
      97                 :            : };
      98                 :            : 
      99                 :            : // --------------------------------------------------------------------------------
     100                 :            : 
     101                 :            : class WeakSelectionChangeListenerAdapter :
     102                 :            :         public WeakListenerAdapter< ::com::sun::star::view::XSelectionChangeListener >
     103                 :            : {
     104                 :            : public:
     105                 :            :     explicit WeakSelectionChangeListenerAdapter(
     106                 :            :         const ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionChangeListener > & xListener );
     107                 :            :     virtual ~WeakSelectionChangeListenerAdapter();
     108                 :            : 
     109                 :            : protected:
     110                 :            :     // ____ XSelectionChangeListener ____
     111                 :            :     virtual void SAL_CALL selectionChanged(
     112                 :            :         const ::com::sun::star::lang::EventObject& aEvent )
     113                 :            :         throw (::com::sun::star::uno::RuntimeException);
     114                 :            : };
     115                 :            : 
     116                 :            : } //  namespace chart
     117                 :            : 
     118                 :            : // CHART2_WEAKLISTENERADAPTER_HXX
     119                 :            : #endif
     120                 :            : 
     121                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10