LCOV - code coverage report
Current view: top level - sc/source/ui/unoobj - listenercalls.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 18 19 94.7 %
Date: 2014-04-11 Functions: 4 4 100.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             : #include <com/sun/star/util/XModifyListener.hpp>
      21             : 
      22             : #include "listenercalls.hxx"
      23             : 
      24             : using namespace com::sun::star;
      25             : 
      26           3 : ScUnoListenerCalls::ScUnoListenerCalls()
      27             : {
      28           3 : }
      29             : 
      30           3 : ScUnoListenerCalls::~ScUnoListenerCalls()
      31             : {
      32             :     OSL_ENSURE( aEntries.empty(), "unhandled listener calls remaining" );
      33           3 : }
      34             : 
      35          20 : void ScUnoListenerCalls::Add( const uno::Reference<util::XModifyListener>& rListener,
      36             :                                 const lang::EventObject& rEvent )
      37             : {
      38          20 :     if ( rListener.is() )
      39          20 :         aEntries.push_back( ScUnoListenerEntry( rListener, rEvent ) );
      40          20 : }
      41             : 
      42          15 : void ScUnoListenerCalls::ExecuteAndClear()
      43             : {
      44             :     //  Execute all stored calls and remove them from the list.
      45             :     //  During each modified() call, Add may be called again.
      46             :     //  These new calls are executed here, too.
      47             : 
      48          15 :     if (!aEntries.empty())
      49             :     {
      50           3 :         std::list<ScUnoListenerEntry>::iterator aItr(aEntries.begin());
      51           3 :         std::list<ScUnoListenerEntry>::iterator aEndItr(aEntries.end());
      52          26 :         while ( aItr != aEndItr )
      53             :         {
      54          20 :             ScUnoListenerEntry aEntry = *aItr;
      55             :             try
      56             :             {
      57          20 :                 aEntry.xListener->modified( aEntry.aEvent );
      58             :             }
      59           0 :             catch ( const uno::RuntimeException& )
      60             :             {
      61             :                 // the listener is an external object and may throw a RuntimeException
      62             :                 // for reasons we don't know
      63             :             }
      64             : 
      65             :             //  New calls that are added during the modified() call are appended to the end
      66             :             //  of aEntries, so the loop will catch them, too (as long as erase happens
      67             :             //  after modified).
      68             : 
      69          20 :             aItr = aEntries.erase(aItr);
      70          20 :         }
      71             :     }
      72          15 : }
      73             : 
      74             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10