LCOV - code coverage report
Current view: top level - libreoffice/forms/source/component - entrylisthelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 114 0.0 %
Date: 2012-12-27 Functions: 0 22 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 "entrylisthelper.hxx"
      21             : #include "FormComponent.hxx"
      22             : 
      23             : #include <osl/diagnose.h>
      24             : #include <comphelper/sequence.hxx>
      25             : #include <comphelper/property.hxx>
      26             : #include <algorithm>
      27             : 
      28             : //.........................................................................
      29             : namespace frm
      30             : {
      31             : //.........................................................................
      32             : 
      33             :     using namespace ::com::sun::star::uno;
      34             :     using namespace ::com::sun::star::lang;
      35             :     using namespace ::com::sun::star::util;
      36             :     using namespace ::com::sun::star::form::binding;
      37             : 
      38             :     //=====================================================================
      39             :     //= OEntryListHelper
      40             :     //=====================================================================
      41             :     //---------------------------------------------------------------------
      42           0 :     OEntryListHelper::OEntryListHelper( OControlModel& _rControlModel )
      43             :         :m_rControlModel( _rControlModel )
      44           0 :         ,m_aRefreshListeners( _rControlModel.getInstanceMutex() )
      45             :     {
      46           0 :     }
      47             : 
      48             :     //---------------------------------------------------------------------
      49           0 :     OEntryListHelper::OEntryListHelper( const OEntryListHelper& _rSource, OControlModel& _rControlModel )
      50             :         :m_rControlModel( _rControlModel )
      51             :         ,m_xListSource ( _rSource.m_xListSource  )
      52             :         ,m_aStringItems( _rSource.m_aStringItems )
      53           0 :         ,m_aRefreshListeners( _rControlModel.getInstanceMutex() )
      54             :     {
      55           0 :     }
      56             : 
      57             :     //---------------------------------------------------------------------
      58           0 :     OEntryListHelper::~OEntryListHelper( )
      59             :     {
      60           0 :     }
      61             : 
      62             :     //---------------------------------------------------------------------
      63           0 :     void SAL_CALL OEntryListHelper::setListEntrySource( const Reference< XListEntrySource >& _rxSource ) throw (RuntimeException)
      64             :     {
      65           0 :         ControlModelLock aLock( m_rControlModel );
      66             : 
      67             :         // disconnect from the current external list source
      68           0 :         disconnectExternalListSource();
      69             : 
      70             :         // and connect to the new one
      71           0 :         if ( _rxSource.is() )
      72           0 :             connectExternalListSource( _rxSource, aLock );
      73           0 :     }
      74             : 
      75             :     //---------------------------------------------------------------------
      76           0 :     Reference< XListEntrySource > SAL_CALL OEntryListHelper::getListEntrySource(  ) throw (RuntimeException)
      77             :     {
      78           0 :         return m_xListSource;
      79             :     }
      80             : 
      81             : 
      82             :     //---------------------------------------------------------------------
      83           0 :     void SAL_CALL OEntryListHelper::entryChanged( const ListEntryEvent& _rEvent ) throw (RuntimeException)
      84             :     {
      85           0 :         ControlModelLock aLock( m_rControlModel );
      86             : 
      87             :         OSL_ENSURE( _rEvent.Source == m_xListSource,
      88             :             "OEntryListHelper::entryChanged: where did this come from?" );
      89             :         OSL_ENSURE( ( _rEvent.Position >= 0 ) && ( _rEvent.Position < m_aStringItems.getLength() ),
      90             :             "OEntryListHelper::entryChanged: invalid index!" );
      91             :         OSL_ENSURE( _rEvent.Entries.getLength() == 1,
      92             :             "OEntryListHelper::entryChanged: invalid string list!" );
      93             : 
      94           0 :         if  (   ( _rEvent.Position >= 0 )
      95           0 :             &&  ( _rEvent.Position < m_aStringItems.getLength() )
      96           0 :             &&  ( _rEvent.Entries.getLength() > 0 )
      97             :             )
      98             :         {
      99           0 :             m_aStringItems[ _rEvent.Position ] = _rEvent.Entries[ 0 ];
     100           0 :             stringItemListChanged( aLock );
     101           0 :         }
     102           0 :     }
     103             : 
     104             :     //---------------------------------------------------------------------
     105           0 :     void SAL_CALL OEntryListHelper::entryRangeInserted( const ListEntryEvent& _rEvent ) throw (RuntimeException)
     106             :     {
     107           0 :         ControlModelLock aLock( m_rControlModel );
     108             : 
     109             :         OSL_ENSURE( _rEvent.Source == m_xListSource,
     110             :             "OEntryListHelper::entryRangeInserted: where did this come from?" );
     111             :         OSL_ENSURE( ( _rEvent.Position > 0 ) && ( _rEvent.Position < m_aStringItems.getLength() ) && ( _rEvent.Entries.getLength() > 0 ),
     112             :             "OEntryListHelper::entryRangeRemoved: invalid count and/or position!" );
     113             : 
     114           0 :         if  (   ( _rEvent.Position > 0 )
     115           0 :             &&  ( _rEvent.Position < m_aStringItems.getLength() )
     116           0 :             &&  ( _rEvent.Entries.getLength() > 0 )
     117             :             )
     118             :         {
     119             :             // the entries *before* the insertion pos
     120             :             Sequence< ::rtl::OUString > aKeepEntries(
     121             :                 m_aStringItems.getConstArray(),
     122             :                 _rEvent.Position
     123           0 :             );
     124             :             // the entries *behind* the insertion pos
     125             :             Sequence< ::rtl::OUString > aMovedEntries(
     126           0 :                 m_aStringItems.getConstArray() + _rEvent.Position,
     127           0 :                 m_aStringItems.getLength() - _rEvent.Position
     128           0 :             );
     129             : 
     130             :             // concat all three parts
     131             :             m_aStringItems = ::comphelper::concatSequences(
     132             :                 aKeepEntries,
     133             :                 _rEvent.Entries,
     134             :                 aMovedEntries
     135           0 :             );
     136             : 
     137           0 :             stringItemListChanged( aLock );
     138           0 :         }
     139           0 :     }
     140             : 
     141             :     //---------------------------------------------------------------------
     142           0 :     void SAL_CALL OEntryListHelper::entryRangeRemoved( const ListEntryEvent& _rEvent ) throw (RuntimeException)
     143             :     {
     144           0 :         ControlModelLock aLock( m_rControlModel );
     145             : 
     146             :         OSL_ENSURE( _rEvent.Source == m_xListSource,
     147             :             "OEntryListHelper::entryRangeRemoved: where did this come from?" );
     148             :         OSL_ENSURE( ( _rEvent.Position > 0 ) && ( _rEvent.Count > 0 ) && ( _rEvent.Position + _rEvent.Count <= m_aStringItems.getLength() ),
     149             :             "OEntryListHelper::entryRangeRemoved: invalid count and/or position!" );
     150             : 
     151           0 :         if  (   ( _rEvent.Position > 0 )
     152             :             &&  ( _rEvent.Count > 0 )
     153           0 :             &&  ( _rEvent.Position + _rEvent.Count <= m_aStringItems.getLength() )
     154             :             )
     155             :         {
     156             :             // copy all items after the removed ones
     157             :             ::std::copy(
     158           0 :                 m_aStringItems.getConstArray() + _rEvent.Position + _rEvent.Count,
     159           0 :                 m_aStringItems.getConstArray() + m_aStringItems.getLength(),
     160           0 :                 m_aStringItems.getArray( ) + _rEvent.Position
     161           0 :             );
     162             :             // shrink the array
     163           0 :             m_aStringItems.realloc( m_aStringItems.getLength() - _rEvent.Count );
     164             : 
     165           0 :             stringItemListChanged( aLock );
     166           0 :         }
     167           0 :     }
     168             : 
     169             :     //---------------------------------------------------------------------
     170           0 :     void SAL_CALL OEntryListHelper::allEntriesChanged( const EventObject& _rEvent ) throw (RuntimeException)
     171             :     {
     172           0 :         ControlModelLock aLock( m_rControlModel );
     173             : 
     174             :         OSL_ENSURE( _rEvent.Source == m_xListSource,
     175             :             "OEntryListHelper::allEntriesChanged: where did this come from?" );
     176             : 
     177           0 :         Reference< XListEntrySource > xSource( _rEvent.Source, UNO_QUERY );
     178           0 :         if ( _rEvent.Source == m_xListSource )
     179             :         {
     180           0 :             impl_lock_refreshList( aLock );
     181           0 :         }
     182           0 :     }
     183             : 
     184             :     // XRefreshable
     185             :     //------------------------------------------------------------------------------
     186           0 :     void SAL_CALL OEntryListHelper::addRefreshListener(const Reference<XRefreshListener>& _rxListener) throw(RuntimeException)
     187             :     {
     188           0 :         if ( _rxListener.is() )
     189           0 :             m_aRefreshListeners.addInterface( _rxListener );
     190           0 :     }
     191             : 
     192             :     //------------------------------------------------------------------------------
     193           0 :     void SAL_CALL OEntryListHelper::removeRefreshListener(const Reference<XRefreshListener>& _rxListener) throw(RuntimeException)
     194             :     {
     195           0 :         if ( _rxListener.is() )
     196           0 :             m_aRefreshListeners.removeInterface( _rxListener );
     197           0 :     }
     198             : 
     199             :     //------------------------------------------------------------------------------
     200           0 :     void SAL_CALL OEntryListHelper::refresh() throw(RuntimeException)
     201             :     {
     202             :         {
     203           0 :             ControlModelLock aLock( m_rControlModel );
     204           0 :             impl_lock_refreshList( aLock );
     205             :         }
     206             : 
     207           0 :         EventObject aEvt( static_cast< XRefreshable* >( this ) );
     208           0 :         m_aRefreshListeners.notifyEach( &XRefreshListener::refreshed, aEvt );
     209           0 :     }
     210             : 
     211             :     //---------------------------------------------------------------------
     212           0 :     void OEntryListHelper::impl_lock_refreshList( ControlModelLock& _rInstanceLock )
     213             :     {
     214           0 :         if ( hasExternalListSource() )
     215             :         {
     216           0 :             m_aStringItems = m_xListSource->getAllListEntries( );
     217           0 :             stringItemListChanged( _rInstanceLock );
     218             :         }
     219             :         else
     220           0 :             refreshInternalEntryList();
     221           0 :     }
     222             : 
     223             :     //---------------------------------------------------------------------
     224           0 :     bool OEntryListHelper::handleDisposing( const EventObject& _rEvent )
     225             :     {
     226           0 :         if ( m_xListSource .is() && ( _rEvent.Source == m_xListSource ) )
     227             :         {
     228           0 :             disconnectExternalListSource( );
     229           0 :             return true;
     230             :         }
     231           0 :         return false;
     232             :     }
     233             : 
     234             :     //---------------------------------------------------------------------
     235           0 :     void OEntryListHelper::disposing( )
     236             :     {
     237           0 :         EventObject aEvt( static_cast< XRefreshable* >( this ) );
     238           0 :         m_aRefreshListeners.disposeAndClear(aEvt);
     239             : 
     240           0 :         if ( hasExternalListSource( ) )
     241           0 :             disconnectExternalListSource( );
     242           0 :     }
     243             : 
     244             :     //---------------------------------------------------------------------
     245           0 :     void OEntryListHelper::disconnectExternalListSource( )
     246             :     {
     247           0 :         if ( m_xListSource.is() )
     248           0 :             m_xListSource->removeListEntryListener( this );
     249             : 
     250           0 :         m_xListSource.clear();
     251             : 
     252           0 :         disconnectedExternalListSource();
     253           0 :     }
     254             : 
     255             :     //---------------------------------------------------------------------
     256           0 :     void OEntryListHelper::connectedExternalListSource( )
     257             :     {
     258             :         // nothing to do here
     259           0 :     }
     260             : 
     261             :     //---------------------------------------------------------------------
     262           0 :     void OEntryListHelper::disconnectedExternalListSource( )
     263             :     {
     264             :         // nothing to do here
     265           0 :     }
     266             : 
     267             :     //---------------------------------------------------------------------
     268           0 :     void OEntryListHelper::connectExternalListSource( const Reference< XListEntrySource >& _rxSource, ControlModelLock& _rInstanceLock )
     269             :     {
     270             :         OSL_ENSURE( !hasExternalListSource(), "OEntryListHelper::connectExternalListSource: only to be called if no external source is active!" );
     271             :         OSL_ENSURE( _rxSource.is(), "OEntryListHelper::connectExternalListSource: invalid list source!" );
     272             : 
     273             :         // remember it
     274           0 :         m_xListSource = _rxSource;
     275             : 
     276             :         // initially fill our item list
     277           0 :         if ( m_xListSource.is() )
     278             :         {
     279             :             // be notified when the list changes ...
     280           0 :             m_xListSource->addListEntryListener( this );
     281             : 
     282           0 :             m_aStringItems = m_xListSource->getAllListEntries( );
     283           0 :             stringItemListChanged( _rInstanceLock );
     284             : 
     285             :             // let derivees react on the new list source
     286           0 :             connectedExternalListSource();
     287             :         }
     288           0 :     }
     289             : 
     290             :     //---------------------------------------------------------------------
     291           0 :     sal_Bool OEntryListHelper::convertNewListSourceProperty( Any& _rConvertedValue,
     292             :         Any& _rOldValue, const Any& _rValue ) SAL_THROW( ( IllegalArgumentException ) )
     293             :     {
     294           0 :         if ( hasExternalListSource() )
     295           0 :             throw IllegalArgumentException( );
     296             :             // TODO: error message
     297             : 
     298           0 :         return ::comphelper::tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_aStringItems );
     299             :     }
     300             : 
     301             :     //---------------------------------------------------------------------
     302           0 :     void OEntryListHelper::setNewStringItemList( const ::com::sun::star::uno::Any& _rValue, ControlModelLock& _rInstanceLock )
     303             :     {
     304             :         OSL_PRECOND( !hasExternalListSource(), "OEntryListHelper::setNewStringItemList: this should never have survived convertNewListSourceProperty!" );
     305           0 :         OSL_VERIFY( _rValue >>= m_aStringItems );
     306           0 :         stringItemListChanged( _rInstanceLock );
     307           0 :     }
     308             : 
     309             : //.........................................................................
     310             : }   // namespace frm
     311             : //.........................................................................
     312             : 
     313             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10