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

Generated by: LCOV version 1.10