LCOV - code coverage report
Current view: top level - libreoffice/unotools/source/misc - closeveto.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 36 0.0 %
Date: 2012-12-27 Functions: 0 13 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             : #include <unotools/closeveto.hxx>
      21             : 
      22             : #include <com/sun/star/util/XCloseable.hpp>
      23             : 
      24             : #include <cppuhelper/implbase1.hxx>
      25             : #include <rtl/ref.hxx>
      26             : #include <tools/diagnose_ex.h>
      27             : 
      28             : //......................................................................................................................
      29             : namespace utl
      30             : {
      31             : //......................................................................................................................
      32             : 
      33             :     /** === begin UNO using === **/
      34             :     using ::com::sun::star::uno::Reference;
      35             :     using ::com::sun::star::uno::XInterface;
      36             :     using ::com::sun::star::uno::UNO_QUERY;
      37             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      38             :     using ::com::sun::star::uno::UNO_SET_THROW;
      39             :     using ::com::sun::star::uno::Exception;
      40             :     using ::com::sun::star::uno::RuntimeException;
      41             :     using ::com::sun::star::uno::Any;
      42             :     using ::com::sun::star::uno::makeAny;
      43             :     using ::com::sun::star::uno::Sequence;
      44             :     using ::com::sun::star::uno::Type;
      45             :     using ::com::sun::star::util::XCloseable;
      46             :     using ::com::sun::star::util::XCloseListener;
      47             :     using ::com::sun::star::util::CloseVetoException;
      48             :     using ::com::sun::star::lang::EventObject;
      49             :     /** === end UNO using === **/
      50             : 
      51             :     //==================================================================================================================
      52             :     //= CloseListener_Impl
      53             :     //==================================================================================================================
      54             :     typedef ::cppu::WeakImplHelper1 <   XCloseListener
      55             :                                     >   CloseListener_Base;
      56             :     class SAL_DLLPRIVATE CloseListener_Impl : public CloseListener_Base
      57             :     {
      58             :     public:
      59           0 :         CloseListener_Impl()
      60           0 :             :m_bHasOwnership( false )
      61             :         {
      62           0 :         }
      63             : 
      64             :         // XCloseListener
      65             :         virtual void SAL_CALL queryClosing( const EventObject& Source, ::sal_Bool GetsOwnership ) throw (CloseVetoException, RuntimeException);
      66             :         virtual void SAL_CALL notifyClosing( const EventObject& Source ) throw (RuntimeException);
      67             : 
      68             :         // XEventListener
      69             :         virtual void SAL_CALL disposing( const EventObject& Source) throw (RuntimeException);
      70             : 
      71           0 :         bool hasOwnership() const { return m_bHasOwnership; }
      72             : 
      73             :     protected:
      74           0 :         ~CloseListener_Impl()
      75           0 :         {
      76           0 :         }
      77             : 
      78             :     private:
      79             :         bool    m_bHasOwnership;
      80             :     };
      81             : 
      82             :     //------------------------------------------------------------------------------------------------------------------
      83           0 :     void SAL_CALL CloseListener_Impl::queryClosing( const EventObject& i_source, ::sal_Bool i_deliverOwnership ) throw (CloseVetoException, RuntimeException)
      84             :     {
      85             :         (void)i_source;
      86             : 
      87           0 :         if ( !m_bHasOwnership )
      88           0 :             m_bHasOwnership = i_deliverOwnership;
      89             : 
      90           0 :         throw CloseVetoException();
      91             :     }
      92             : 
      93             :     //------------------------------------------------------------------------------------------------------------------
      94           0 :     void SAL_CALL CloseListener_Impl::notifyClosing( const EventObject& i_source ) throw (RuntimeException)
      95             :     {
      96             :         (void)i_source;
      97           0 :     }
      98             : 
      99             :     //------------------------------------------------------------------------------------------------------------------
     100           0 :     void SAL_CALL CloseListener_Impl::disposing( const EventObject& i_source ) throw (RuntimeException)
     101             :     {
     102             :         (void)i_source;
     103           0 :     }
     104             : 
     105             :     //==================================================================================================================
     106             :     //= CloseVeto_Data
     107             :     //==================================================================================================================
     108           0 :     struct SAL_DLLPRIVATE CloseVeto_Data
     109             :     {
     110             :         Reference< XCloseable >                 xCloseable;
     111             :         ::rtl::Reference< CloseListener_Impl >  pListener;
     112             :     };
     113             : 
     114             :     //==================================================================================================================
     115             :     //= operations
     116             :     //==================================================================================================================
     117             :     namespace
     118             :     {
     119             :         //--------------------------------------------------------------------------------------------------------------
     120           0 :         void lcl_init( CloseVeto_Data& i_data, const Reference< XInterface >& i_closeable )
     121             :         {
     122           0 :             i_data.xCloseable.set( i_closeable, UNO_QUERY );
     123           0 :             ENSURE_OR_RETURN_VOID( i_data.xCloseable.is(), "CloseVeto: the component is not closeable!" );
     124             : 
     125           0 :             i_data.pListener = new CloseListener_Impl;
     126           0 :             i_data.xCloseable->addCloseListener( i_data.pListener.get() );
     127             :         }
     128             : 
     129             :         //--------------------------------------------------------------------------------------------------------------
     130           0 :         void lcl_deinit( CloseVeto_Data& i_data )
     131             :         {
     132           0 :             if ( !i_data.xCloseable.is() )
     133           0 :                 return;
     134             : 
     135           0 :             i_data.xCloseable->removeCloseListener( i_data.pListener.get() );
     136           0 :             if ( i_data.pListener->hasOwnership() )
     137             :             {
     138             :                 try
     139             :                 {
     140           0 :                     i_data.xCloseable->close( sal_True );
     141             :                 }
     142           0 :                 catch( const CloseVetoException& ) { }
     143           0 :                 catch( const Exception& )
     144             :                 {
     145             :                     DBG_UNHANDLED_EXCEPTION();
     146             :                 }
     147             :             }
     148             :         }
     149             :     }
     150             : 
     151             :     //==================================================================================================================
     152             :     //= CloseVeto
     153             :     //==================================================================================================================
     154             :     //------------------------------------------------------------------------------------------------------------------
     155           0 :     CloseVeto::CloseVeto( const Reference< XInterface >& i_closeable )
     156           0 :         :m_pData( new CloseVeto_Data )
     157             :     {
     158           0 :         lcl_init( *m_pData, i_closeable );
     159           0 :     }
     160             : 
     161             :     //------------------------------------------------------------------------------------------------------------------
     162           0 :     CloseVeto::~CloseVeto()
     163             :     {
     164           0 :         lcl_deinit( *m_pData );
     165           0 :     }
     166             : 
     167             : //......................................................................................................................
     168             : } // namespace utl
     169             : //......................................................................................................................
     170             : 
     171             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10