LCOV - code coverage report
Current view: top level - libreoffice/comphelper/source/misc - SelectionMultiplex.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 57 0.0 %
Date: 2012-12-27 Functions: 0 12 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             :  * 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             : 
      21             : #include <comphelper/SelectionMultiplex.hxx>
      22             : #include <osl/diagnose.h>
      23             : 
      24             : //.........................................................................
      25             : namespace comphelper
      26             : {
      27             : //.........................................................................
      28             : 
      29             : using namespace ::com::sun::star::uno;
      30             : using namespace ::com::sun::star::lang;
      31             : using namespace ::com::sun::star::view;
      32             : 
      33             : //========================================================================
      34             : //= OSelectionChangeListener
      35             : //========================================================================
      36             : //------------------------------------------------------------------------
      37           0 : OSelectionChangeListener::~OSelectionChangeListener()
      38             : {
      39           0 :     if (m_pAdapter)
      40           0 :         m_pAdapter->dispose();
      41           0 : }
      42             : 
      43             : //------------------------------------------------------------------
      44           0 : void OSelectionChangeListener::_disposing(const EventObject&) throw( RuntimeException)
      45             : {
      46             :     // nothing to do here
      47           0 : }
      48             : 
      49             : //------------------------------------------------------------------
      50           0 : void OSelectionChangeListener::setAdapter(OSelectionChangeMultiplexer* pAdapter)
      51             : {
      52           0 :     if (m_pAdapter)
      53             :     {
      54           0 :         ::osl::MutexGuard aGuard(m_rMutex);
      55           0 :         m_pAdapter->release();
      56           0 :         m_pAdapter = NULL;
      57             :     }
      58             : 
      59           0 :     if (pAdapter)
      60             :     {
      61           0 :         ::osl::MutexGuard aGuard(m_rMutex);
      62           0 :         m_pAdapter = pAdapter;
      63           0 :         m_pAdapter->acquire();
      64             :     }
      65           0 : }
      66             : 
      67             : //========================================================================
      68             : //= OSelectionChangeMultiplexer
      69             : //========================================================================
      70             : //------------------------------------------------------------------
      71           0 : OSelectionChangeMultiplexer::OSelectionChangeMultiplexer(OSelectionChangeListener* _pListener, const  Reference< XSelectionSupplier>& _rxSet, sal_Bool _bAutoReleaseSet)
      72             :             :m_xSet(_rxSet)
      73             :             ,m_pListener(_pListener)
      74             :             ,m_nLockCount(0)
      75             :             ,m_bListening(sal_False)
      76           0 :             ,m_bAutoSetRelease(_bAutoReleaseSet)
      77             : {
      78           0 :     m_pListener->setAdapter(this);
      79           0 :     osl_atomic_increment(&m_refCount);
      80             :     {
      81           0 :         Reference< XSelectionChangeListener> xPreventDelete(this);
      82           0 :         m_xSet->addSelectionChangeListener(xPreventDelete);
      83             :     }
      84           0 :     osl_atomic_decrement(&m_refCount);
      85           0 : }
      86             : 
      87             : //------------------------------------------------------------------
      88           0 : OSelectionChangeMultiplexer::~OSelectionChangeMultiplexer()
      89             : {
      90           0 : }
      91             : 
      92             : //------------------------------------------------------------------
      93           0 : void OSelectionChangeMultiplexer::lock()
      94             : {
      95           0 :     ++m_nLockCount;
      96           0 : }
      97             : 
      98             : //------------------------------------------------------------------
      99           0 : void OSelectionChangeMultiplexer::unlock()
     100             : {
     101           0 :     --m_nLockCount;
     102           0 : }
     103             : 
     104             : //------------------------------------------------------------------
     105           0 : void OSelectionChangeMultiplexer::dispose()
     106             : {
     107           0 :     if (m_bListening)
     108             :     {
     109           0 :         Reference< XSelectionChangeListener> xPreventDelete(this);
     110             : 
     111           0 :         m_xSet->removeSelectionChangeListener(xPreventDelete);
     112             : 
     113           0 :         m_pListener->setAdapter(NULL);
     114             : 
     115           0 :         m_pListener = NULL;
     116           0 :         m_bListening = sal_False;
     117             : 
     118           0 :         if (m_bAutoSetRelease)
     119           0 :             m_xSet = NULL;
     120             :     }
     121           0 : }
     122             : 
     123             : // XEventListener
     124             : //------------------------------------------------------------------
     125           0 : void SAL_CALL OSelectionChangeMultiplexer::disposing( const  EventObject& _rSource) throw( RuntimeException)
     126             : {
     127           0 :     if (m_pListener)
     128             :     {
     129             :          // tell the listener
     130           0 :         if (!locked())
     131           0 :             m_pListener->_disposing(_rSource);
     132             :         // disconnect the listener
     133           0 :         if (m_pListener)    // may have been reset whilest calling into _disposing
     134           0 :             m_pListener->setAdapter(NULL);
     135             :     }
     136             : 
     137           0 :     m_pListener = NULL;
     138           0 :     m_bListening = sal_False;
     139             : 
     140           0 :     if (m_bAutoSetRelease)
     141           0 :         m_xSet = NULL;
     142           0 : }
     143             : 
     144             : // XSelectionChangeListener
     145             : //------------------------------------------------------------------
     146           0 : void SAL_CALL OSelectionChangeMultiplexer::selectionChanged( const  EventObject& _rEvent ) throw( RuntimeException)
     147             : {
     148           0 :     if (m_pListener && !locked())
     149           0 :         m_pListener->_selectionChanged(_rEvent);
     150           0 : }
     151             : //.........................................................................
     152             : }
     153             : //.........................................................................
     154             : 
     155             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10