LCOV - code coverage report
Current view: top level - libreoffice/vbahelper/source/msforms - vbalistbox.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 139 0.0 %
Date: 2012-12-27 Functions: 0 23 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 "vbalistbox.hxx"
      21             : #include "vbanewfont.hxx"
      22             : #include <comphelper/anytostring.hxx>
      23             : #include <com/sun/star/script/ArrayWrapper.hpp>
      24             : #include <com/sun/star/form/validation/XValidatableFormComponent.hpp>
      25             : 
      26             : using namespace com::sun::star;
      27             : using namespace ooo::vba;
      28             : 
      29           0 : const static OUString TEXT( "Text" );
      30           0 : const static OUString SELECTEDITEMS( "SelectedItems" );
      31           0 : const static OUString ITEMS( "StringItemList" );
      32             : 
      33             : 
      34           0 : ScVbaListBox::ScVbaListBox( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< css::uno::XInterface >& xControl, const uno::Reference< frame::XModel >& xModel, AbstractGeometryAttributes* pGeomHelper ) : ListBoxImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper )
      35             : {
      36           0 :     mpListHelper.reset( new ListControlHelper( m_xProps ) );
      37           0 : }
      38             : 
      39             : // Attributes
      40             : void SAL_CALL
      41           0 : ScVbaListBox::setListIndex( const uno::Any& _value ) throw (uno::RuntimeException)
      42             : {
      43           0 :     sal_Int32 nIndex = 0;
      44           0 :     _value >>= nIndex;
      45           0 :     uno::Reference< XPropValue > xPropVal( Selected( nIndex ), uno::UNO_QUERY_THROW );
      46           0 :     xPropVal->setValue( uno::makeAny( sal_True ) );
      47           0 : }
      48             : 
      49             : uno::Any SAL_CALL
      50           0 : ScVbaListBox::getListIndex() throw (uno::RuntimeException)
      51             : {
      52           0 :     uno::Sequence< sal_Int16 > sSelection;
      53           0 :     m_xProps->getPropertyValue( SELECTEDITEMS ) >>= sSelection;
      54           0 :     if ( sSelection.getLength() == 0 )
      55           0 :         return uno::Any( sal_Int32( -1 ) );
      56           0 :     return uno::Any( sSelection[ 0 ] );
      57             : }
      58             : 
      59             : uno::Any SAL_CALL
      60           0 : ScVbaListBox::getValue() throw (uno::RuntimeException)
      61             : {
      62           0 :     uno::Sequence< sal_Int16 > sSelection;
      63           0 :     uno::Sequence< OUString > sItems;
      64           0 :     m_xProps->getPropertyValue( SELECTEDITEMS ) >>= sSelection;
      65           0 :     m_xProps->getPropertyValue( ITEMS ) >>= sItems;
      66           0 :     if( getMultiSelect() )
      67           0 :         throw uno::RuntimeException( "Attribute use invalid." , uno::Reference< uno::XInterface >() );
      68           0 :     uno::Any aRet;
      69           0 :     if ( sSelection.getLength() )
      70           0 :         aRet = uno::makeAny( sItems[ sSelection[ 0 ] ] );
      71           0 :     return aRet;
      72             : }
      73             : 
      74             : void SAL_CALL
      75           0 : ScVbaListBox::setValue( const uno::Any& _value ) throw (uno::RuntimeException)
      76             : {
      77           0 :     if( getMultiSelect() )
      78             :     {
      79           0 :         throw uno::RuntimeException( "Attribute use invalid." , uno::Reference< uno::XInterface >() );
      80             :     }
      81           0 :     OUString sValue = getAnyAsString( _value );
      82           0 :     uno::Sequence< OUString > sList;
      83           0 :     m_xProps->getPropertyValue( ITEMS ) >>= sList;
      84           0 :     uno::Sequence< sal_Int16 > nList;
      85           0 :     sal_Int16 nLength = static_cast<sal_Int16>( sList.getLength() );
      86           0 :     sal_Int16 nValue = -1;
      87           0 :     sal_Int16 i = 0;
      88           0 :     for( i = 0; i < nLength; i++ )
      89             :     {
      90           0 :         if( sList[i].equals( sValue ) )
      91             :         {
      92           0 :             nValue = i;
      93           0 :             break;
      94             :         }
      95             :     }
      96           0 :     if( nValue == -1 )
      97           0 :         throw uno::RuntimeException( "Attribute use invalid." , uno::Reference< uno::XInterface >() );
      98             : 
      99           0 :     uno::Sequence< sal_Int16 > nSelectedIndices(1);
     100           0 :     uno::Sequence< sal_Int16 > nOldSelectedIndices;
     101           0 :     m_xProps->getPropertyValue( SELECTEDITEMS ) >>= nOldSelectedIndices;
     102           0 :     nSelectedIndices[ 0 ] = nValue;
     103           0 :     m_xProps->setPropertyValue( SELECTEDITEMS, uno::makeAny( nSelectedIndices ) );
     104           0 :     if ( nSelectedIndices != nOldSelectedIndices )
     105           0 :         fireClickEvent();
     106           0 :     m_xProps->setPropertyValue( TEXT, uno::makeAny( sValue ) );
     107           0 : }
     108             : 
     109             : OUString SAL_CALL
     110           0 : ScVbaListBox::getText() throw (uno::RuntimeException)
     111             : {
     112           0 :     OUString result;
     113           0 :     getValue() >>= result;
     114           0 :     return result;
     115             : }
     116             : 
     117             : void SAL_CALL
     118           0 : ScVbaListBox::setText( const OUString& _text ) throw (uno::RuntimeException)
     119             : {
     120           0 :     setValue( uno::makeAny( _text ) ); // seems the same
     121           0 : }
     122             : 
     123             : sal_Bool SAL_CALL
     124           0 : ScVbaListBox::getMultiSelect() throw (css::uno::RuntimeException)
     125             : {
     126           0 :     sal_Bool bMultiSelect = sal_False;
     127           0 :     m_xProps->getPropertyValue( "MultiSelection" ) >>= bMultiSelect;
     128           0 :     return bMultiSelect;
     129             : }
     130             : 
     131             : void SAL_CALL
     132           0 : ScVbaListBox::setMultiSelect( sal_Bool _multiselect ) throw (css::uno::RuntimeException)
     133             : {
     134           0 :     m_xProps->setPropertyValue( "MultiSelection" , uno::makeAny( _multiselect ) );
     135           0 : }
     136             : 
     137             : 
     138             : css::uno::Any SAL_CALL
     139           0 : ScVbaListBox::Selected( sal_Int32 index ) throw (css::uno::RuntimeException)
     140             : {
     141           0 :     uno::Sequence< OUString > sList;
     142           0 :     m_xProps->getPropertyValue( ITEMS ) >>= sList;
     143           0 :     sal_Int16 nLength = static_cast< sal_Int16 >( sList.getLength() );
     144             :     // no choice but to do a horror cast as internally
     145             :     // the indices are but sal_Int16
     146           0 :     sal_Int16 nIndex = static_cast< sal_Int16 >( index );
     147           0 :     if( nIndex < 0 || nIndex >= nLength )
     148           0 :         throw uno::RuntimeException( "Error Number." , uno::Reference< uno::XInterface >() );
     149           0 :     m_nIndex = nIndex;
     150           0 :     return uno::makeAny( uno::Reference< XPropValue > ( new ScVbaPropValue( this ) ) );
     151             : }
     152             : 
     153             : // Methods
     154             : void SAL_CALL
     155           0 : ScVbaListBox::AddItem( const uno::Any& pvargItem, const uno::Any& pvargIndex ) throw (uno::RuntimeException)
     156             : {
     157           0 :     mpListHelper->AddItem( pvargItem, pvargIndex );
     158           0 :         }
     159             : 
     160             : void SAL_CALL
     161           0 : ScVbaListBox::removeItem( const uno::Any& index ) throw (uno::RuntimeException)
     162             : {
     163           0 :     mpListHelper->removeItem( index );
     164           0 : }
     165             : 
     166             : void SAL_CALL
     167           0 : ScVbaListBox::Clear(  ) throw (uno::RuntimeException)
     168             : {
     169           0 :     mpListHelper->Clear();
     170           0 : }
     171             : 
     172             : // this is called when something like the following vba code is used
     173             : // to set the selected state of particular entries in the Listbox
     174             : // ListBox1.Selected( 3 ) = false
     175             : //PropListener
     176             : void
     177           0 : ScVbaListBox::setValueEvent( const uno::Any& value )
     178             : {
     179           0 :     sal_Bool bValue = sal_False;
     180           0 :     if( !(value >>= bValue) )
     181           0 :         throw uno::RuntimeException( "Invalid type\n. need boolean." , uno::Reference< uno::XInterface >() );
     182           0 :     uno::Sequence< sal_Int16 > nList;
     183           0 :     m_xProps->getPropertyValue( SELECTEDITEMS ) >>= nList;
     184           0 :     sal_Int16 nLength = static_cast<sal_Int16>( nList.getLength() );
     185           0 :     sal_Int16 nIndex = m_nIndex;
     186           0 :     for( sal_Int16 i = 0; i < nLength; i++ )
     187             :     {
     188           0 :         if( nList[i] == nIndex )
     189             :         {
     190           0 :             if( bValue )
     191             :                 return;
     192             :             else
     193             :             {
     194           0 :                 for( ; i < nLength - 1; i++ )
     195             :                 {
     196           0 :                     nList[i] = nList[i + 1];
     197             :                 }
     198           0 :                 nList.realloc( nLength - 1 );
     199             :                 //m_xProps->setPropertyValue( sSourceName, uno::makeAny( nList ) );
     200           0 :                 fireClickEvent();
     201           0 :         m_xProps->setPropertyValue( SELECTEDITEMS, uno::makeAny( nList ) );
     202             :                 return;
     203             :             }
     204             :         }
     205             :     }
     206           0 :     if( bValue )
     207             :     {
     208           0 :         if( getMultiSelect() )
     209             :         {
     210           0 :             nList.realloc( nLength + 1 );
     211           0 :             nList[nLength] = nIndex;
     212             :         }
     213             :         else
     214             :         {
     215           0 :             nList.realloc( 1 );
     216           0 :             nList[0] = nIndex;
     217             :         }
     218             :         //m_xProps->setPropertyValue( sSourceName, uno::makeAny( nList ) );
     219           0 :         fireClickEvent();
     220           0 :         m_xProps->setPropertyValue( SELECTEDITEMS, uno::makeAny( nList ) );
     221           0 :     }
     222             : }
     223             : 
     224             : // this is called when something like the following vba code is used
     225             : // to determine the selected state of particular entries in the Listbox
     226             : // msgbox ListBox1.Selected( 3 )
     227             : 
     228             : css::uno::Any
     229           0 : ScVbaListBox::getValueEvent()
     230             : {
     231           0 :     uno::Sequence< sal_Int16 > nList;
     232           0 :     m_xProps->getPropertyValue( "SelectedItems" ) >>= nList;
     233           0 :     sal_Int32 nLength = nList.getLength();
     234           0 :     sal_Int32 nIndex = m_nIndex;
     235             : 
     236           0 :     for( sal_Int32 i = 0; i < nLength; i++ )
     237             :     {
     238           0 :         if( nList[i] == nIndex )
     239           0 :             return uno::makeAny( sal_True );
     240             :     }
     241             : 
     242           0 :     return uno::makeAny( sal_False );
     243             : }
     244             : 
     245             : void SAL_CALL
     246           0 : ScVbaListBox::setRowSource( const OUString& _rowsource ) throw (uno::RuntimeException)
     247             : {
     248           0 :     ScVbaControl::setRowSource( _rowsource );
     249           0 :     mpListHelper->setRowSource( _rowsource );
     250           0 : }
     251             : 
     252             : sal_Int32 SAL_CALL
     253           0 : ScVbaListBox::getListCount() throw (uno::RuntimeException)
     254             : {
     255           0 :     return mpListHelper->getListCount();
     256             : }
     257             : 
     258             : uno::Any SAL_CALL
     259           0 : ScVbaListBox::List( const ::uno::Any& pvargIndex, const uno::Any& pvarColumn ) throw (uno::RuntimeException)
     260             : {
     261           0 :     return mpListHelper->List( pvargIndex, pvarColumn );
     262             : }
     263             : 
     264           0 : uno::Reference< msforms::XNewFont > SAL_CALL ScVbaListBox::getFont() throw (uno::RuntimeException)
     265             : {
     266           0 :     return new VbaNewFont( this, mxContext, m_xProps );
     267             : }
     268             : 
     269             : OUString
     270           0 : ScVbaListBox::getServiceImplName()
     271             : {
     272           0 :     return OUString("ScVbaListBox");
     273             : }
     274             : 
     275             : uno::Sequence< OUString >
     276           0 : ScVbaListBox::getServiceNames()
     277             : {
     278           0 :     static uno::Sequence< OUString > aServiceNames;
     279           0 :     if ( aServiceNames.getLength() == 0 )
     280             :     {
     281           0 :         aServiceNames.realloc( 1 );
     282           0 :         aServiceNames[ 0 ] = "ooo.vba.msforms.ScVbaListBox";
     283             :     }
     284           0 :     return aServiceNames;
     285           0 : }
     286             : 
     287             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10