LCOV - code coverage report
Current view: top level - extensions/source/bibliography - formcontrolcontainer.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 54 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 14 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 "formcontrolcontainer.hxx"
      21             : #include <tools/debug.hxx>
      22             : 
      23             : #include <algorithm>
      24             : #include <functional>
      25             : 
      26             : 
      27             : namespace bib
      28             : {
      29             : 
      30             : 
      31             :     using namespace ::com::sun::star::uno;
      32             :     using namespace ::com::sun::star::form;
      33             :     using namespace ::com::sun::star::lang;
      34             :     using namespace ::com::sun::star::awt;
      35             : 
      36           0 :     FormControlContainer::FormControlContainer( )
      37             :         :OLoadListener( m_aMutex )
      38           0 :         ,m_pFormAdapter( NULL )
      39             :     {
      40           0 :     }
      41             : 
      42           0 :     FormControlContainer::~FormControlContainer( )
      43             :     {
      44             :         DBG_ASSERT( !isFormConnected(), "FormControlContainer::~FormControlContainer: you should disconnect in your derived class!" );
      45           0 :         if ( isFormConnected() )
      46           0 :             disconnectForm();
      47           0 :     }
      48             : 
      49           0 :     void FormControlContainer::disconnectForm()
      50             :     {
      51           0 :         ::osl::MutexGuard aGuard( m_aMutex );
      52             :         DBG_ASSERT( isFormConnected(), "FormControlContainer::connectForm: not connected!" );
      53           0 :         if ( isFormConnected() )
      54             :         {
      55           0 :             m_pFormAdapter->dispose();
      56           0 :             m_pFormAdapter->release();
      57           0 :             m_pFormAdapter = NULL;
      58           0 :         }
      59           0 :     }
      60             : 
      61           0 :     void FormControlContainer::connectForm( const Reference< XLoadable >& _rxForm )
      62             :     {
      63             :         DBG_ASSERT( !isFormConnected(), "FormControlContainer::connectForm: already connected!" );
      64             : 
      65             :         DBG_ASSERT( _rxForm.is(), "FormControlContainer::connectForm: invalid form!" );
      66           0 :         if ( !isFormConnected() && _rxForm.is() )
      67             :         {
      68           0 :             m_pFormAdapter = new OLoadListenerAdapter( _rxForm );
      69           0 :             m_pFormAdapter->acquire();
      70           0 :             m_pFormAdapter->Init( this );
      71             : 
      72           0 :             ensureDesignMode();
      73             :         }
      74             : 
      75           0 :         m_xForm = _rxForm;
      76           0 :     }
      77             : 
      78             :     struct ControlModeSwitch : public ::std::unary_function< Reference< XControl >, void >
      79             :     {
      80             :         bool bDesign;
      81           0 :         ControlModeSwitch( bool _bDesign ) : bDesign( _bDesign ) { }
      82             : 
      83           0 :         void operator() ( const Reference< XControl >& _rxControl ) const
      84             :         {
      85           0 :             if ( _rxControl.is() )
      86           0 :                 _rxControl->setDesignMode( bDesign );
      87           0 :         }
      88             :     };
      89             : 
      90           0 :     void FormControlContainer::implSetDesignMode( bool _bDesign )
      91             :     {
      92             :         try
      93             :         {
      94           0 :             Reference< XControlContainer > xControlCont = getControlContainer();
      95           0 :             Sequence< Reference< XControl > > aControls;
      96           0 :             if ( xControlCont.is() )
      97           0 :                 aControls = xControlCont->getControls();
      98             : 
      99             :             ::std::for_each(
     100             :                 aControls.getConstArray(),
     101           0 :                 aControls.getConstArray() + aControls.getLength(),
     102             :                 ControlModeSwitch( _bDesign )
     103           0 :             );
     104             :         }
     105           0 :         catch( const Exception& e)
     106             :         {
     107             :             (void) e;   // make compiler happy
     108             :             OSL_FAIL( "FormControlContainer::implSetDesignMode: caught an exception!" );
     109             :         }
     110           0 :     }
     111             : 
     112           0 :     void FormControlContainer::ensureDesignMode()
     113             :     {
     114           0 :         implSetDesignMode( !m_xForm.is() || !m_xForm->isLoaded() );
     115           0 :     }
     116             : 
     117           0 :     void FormControlContainer::_loaded( const ::com::sun::star::lang::EventObject& /*_rEvent*/ )
     118             :     {
     119           0 :         implSetDesignMode( false );
     120           0 :     }
     121             : 
     122           0 :     void FormControlContainer::_unloading( const ::com::sun::star::lang::EventObject& /*_rEvent*/ )
     123             :     {
     124           0 :         implSetDesignMode( true );
     125           0 :     }
     126             : 
     127           0 :     void FormControlContainer::_unloaded( const ::com::sun::star::lang::EventObject& /*_rEvent*/ )
     128             :     {
     129           0 :     }
     130             : 
     131           0 :     void FormControlContainer::_reloading( const ::com::sun::star::lang::EventObject& /*_rEvent*/ )
     132             :     {
     133           0 :         implSetDesignMode( true );
     134           0 :     }
     135             : 
     136           0 :     void FormControlContainer::_reloaded( const ::com::sun::star::lang::EventObject& /*_rEvent*/ )
     137             :     {
     138           0 :         implSetDesignMode( false );
     139           0 :     }
     140             : 
     141             : 
     142             : }   // namespace bib
     143             : 
     144             : 
     145             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11