LCOV - code coverage report
Current view: top level - vbahelper/source/msforms - vbalistbox.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 139 0.0 %
Date: 2012-08-25 Functions: 0 23 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     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 rtl::OUString TEXT( "Text" );
      30                 :          0 : const static rtl::OUString SELECTEDITEMS( "SelectedItems" );
      31                 :          0 : const static rtl::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< rtl::OUString > sItems;
      64                 :          0 :     m_xProps->getPropertyValue( SELECTEDITEMS ) >>= sSelection;
      65                 :          0 :     m_xProps->getPropertyValue( ITEMS ) >>= sItems;
      66                 :          0 :     if( getMultiSelect() )
      67                 :            :         throw uno::RuntimeException( rtl::OUString(
      68                 :          0 :                     "Attribute use invalid." ), uno::Reference< uno::XInterface >() );
      69                 :          0 :     uno::Any aRet;
      70                 :          0 :     if ( sSelection.getLength() )
      71                 :          0 :         aRet = uno::makeAny( sItems[ sSelection[ 0 ] ] );
      72                 :          0 :     return aRet;
      73                 :            : }
      74                 :            : 
      75                 :            : void SAL_CALL
      76                 :          0 : ScVbaListBox::setValue( const uno::Any& _value ) throw (uno::RuntimeException)
      77                 :            : {
      78                 :          0 :     if( getMultiSelect() )
      79                 :            :     {
      80                 :            :         throw uno::RuntimeException( rtl::OUString(
      81                 :          0 :                     "Attribute use invalid." ), uno::Reference< uno::XInterface >() );
      82                 :            :     }
      83                 :          0 :     rtl::OUString sValue = getAnyAsString( _value );
      84                 :          0 :     uno::Sequence< rtl::OUString > sList;
      85                 :          0 :     m_xProps->getPropertyValue( ITEMS ) >>= sList;
      86                 :          0 :     uno::Sequence< sal_Int16 > nList;
      87                 :          0 :     sal_Int16 nLength = static_cast<sal_Int16>( sList.getLength() );
      88                 :          0 :     sal_Int16 nValue = -1;
      89                 :          0 :     sal_Int16 i = 0;
      90                 :          0 :     for( i = 0; i < nLength; i++ )
      91                 :            :     {
      92                 :          0 :         if( sList[i].equals( sValue ) )
      93                 :            :         {
      94                 :          0 :             nValue = i;
      95                 :          0 :             break;
      96                 :            :         }
      97                 :            :     }
      98                 :          0 :     if( nValue == -1 )
      99                 :            :         throw uno::RuntimeException( rtl::OUString(
     100                 :          0 :                     "Attribute use invalid." ), uno::Reference< uno::XInterface >() );
     101                 :            : 
     102                 :          0 :     uno::Sequence< sal_Int16 > nSelectedIndices(1);
     103                 :          0 :     uno::Sequence< sal_Int16 > nOldSelectedIndices;
     104                 :          0 :     m_xProps->getPropertyValue( SELECTEDITEMS ) >>= nOldSelectedIndices;
     105                 :          0 :     nSelectedIndices[ 0 ] = nValue;
     106                 :          0 :     m_xProps->setPropertyValue( SELECTEDITEMS, uno::makeAny( nSelectedIndices ) );
     107                 :          0 :     if ( nSelectedIndices != nOldSelectedIndices )
     108                 :          0 :         fireClickEvent();
     109                 :            :     //m_xProps->setPropertyValue( TEXT, uno::makeAny( sValue ) );
     110                 :          0 : }
     111                 :            : 
     112                 :            : ::rtl::OUString SAL_CALL
     113                 :          0 : ScVbaListBox::getText() throw (uno::RuntimeException)
     114                 :            : {
     115                 :          0 :     rtl::OUString result;
     116                 :          0 :     getValue() >>= result;
     117                 :          0 :     return result;
     118                 :            : }
     119                 :            : 
     120                 :            : void SAL_CALL
     121                 :          0 : ScVbaListBox::setText( const ::rtl::OUString& _text ) throw (uno::RuntimeException)
     122                 :            : {
     123                 :          0 :     setValue( uno::makeAny( _text ) ); // seems the same
     124                 :          0 : }
     125                 :            : 
     126                 :            : sal_Int32 SAL_CALL
     127                 :          0 : ScVbaListBox::getMultiSelect() throw (css::uno::RuntimeException)
     128                 :            : {
     129                 :          0 :     sal_Bool bMultiSelect = sal_False;
     130                 :          0 :     m_xProps->getPropertyValue( rtl::OUString(  "MultiSelection"  ) ) >>= bMultiSelect;
     131                 :          0 :     return bMultiSelect ? 1 : 0 ;
     132                 :            : }
     133                 :            : 
     134                 :            : void SAL_CALL
     135                 :          0 : ScVbaListBox::setMultiSelect( sal_Int32 _multiselect ) throw (css::uno::RuntimeException)
     136                 :            : {
     137                 :          0 :     sal_Bool bMultiSelect = _multiselect == 1 ? 1 : 0;
     138                 :          0 :     m_xProps->setPropertyValue( rtl::OUString(  "MultiSelection"  ), uno::makeAny( bMultiSelect ) );
     139                 :          0 : }
     140                 :            : 
     141                 :            : 
     142                 :            : css::uno::Any SAL_CALL
     143                 :          0 : ScVbaListBox::Selected( sal_Int32 index ) throw (css::uno::RuntimeException)
     144                 :            : {
     145                 :          0 :     uno::Sequence< rtl::OUString > sList;
     146                 :          0 :     m_xProps->getPropertyValue( ITEMS ) >>= sList;
     147                 :          0 :     sal_Int16 nLength = static_cast< sal_Int16 >( sList.getLength() );
     148                 :            :     // no choice but to do a horror cast as internally
     149                 :            :     // the indices are but sal_Int16
     150                 :          0 :     sal_Int16 nIndex = static_cast< sal_Int16 >( index );
     151                 :          0 :     if( nIndex < 0 || nIndex >= nLength )
     152                 :            :         throw uno::RuntimeException( rtl::OUString(
     153                 :          0 :                     "Error Number." ), uno::Reference< uno::XInterface >() );
     154                 :          0 :     m_nIndex = nIndex;
     155                 :          0 :     return uno::makeAny( uno::Reference< XPropValue > ( new ScVbaPropValue( this ) ) );
     156                 :            : }
     157                 :            : 
     158                 :            : // Methods
     159                 :            : void SAL_CALL
     160                 :          0 : ScVbaListBox::AddItem( const uno::Any& pvargItem, const uno::Any& pvargIndex ) throw (uno::RuntimeException)
     161                 :            : {
     162                 :          0 :     mpListHelper->AddItem( pvargItem, pvargIndex );
     163                 :          0 :         }
     164                 :            : 
     165                 :            : void SAL_CALL
     166                 :          0 : ScVbaListBox::removeItem( const uno::Any& index ) throw (uno::RuntimeException)
     167                 :            : {
     168                 :          0 :     mpListHelper->removeItem( index );
     169                 :          0 : }
     170                 :            : 
     171                 :            : void SAL_CALL
     172                 :          0 : ScVbaListBox::Clear(  ) throw (uno::RuntimeException)
     173                 :            : {
     174                 :          0 :     mpListHelper->Clear();
     175                 :          0 : }
     176                 :            : 
     177                 :            : // this is called when something like the following vba code is used
     178                 :            : // to set the selected state of particular entries in the Listbox
     179                 :            : // ListBox1.Selected( 3 ) = false
     180                 :            : //PropListener
     181                 :            : void
     182                 :          0 : ScVbaListBox::setValueEvent( const uno::Any& value )
     183                 :            : {
     184                 :          0 :     sal_Bool bValue = sal_False;
     185                 :          0 :     if( !(value >>= bValue) )
     186                 :            :         throw uno::RuntimeException( rtl::OUString(
     187                 :          0 :                     "Invalid type\n. need boolean." ), uno::Reference< uno::XInterface >() );
     188                 :          0 :     uno::Sequence< sal_Int16 > nList;
     189                 :          0 :     m_xProps->getPropertyValue( SELECTEDITEMS ) >>= nList;
     190                 :          0 :     sal_Int16 nLength = static_cast<sal_Int16>( nList.getLength() );
     191                 :          0 :     sal_Int16 nIndex = m_nIndex;
     192                 :          0 :     for( sal_Int16 i = 0; i < nLength; i++ )
     193                 :            :     {
     194                 :          0 :         if( nList[i] == nIndex )
     195                 :            :         {
     196                 :          0 :             if( bValue )
     197                 :            :                 return;
     198                 :            :             else
     199                 :            :             {
     200                 :          0 :                 for( ; i < nLength - 1; i++ )
     201                 :            :                 {
     202                 :          0 :                     nList[i] = nList[i + 1];
     203                 :            :                 }
     204                 :          0 :                 nList.realloc( nLength - 1 );
     205                 :            :                 //m_xProps->setPropertyValue( sSourceName, uno::makeAny( nList ) );
     206                 :          0 :                 fireClickEvent();
     207                 :          0 :         m_xProps->setPropertyValue( SELECTEDITEMS, uno::makeAny( nList ) );
     208                 :            :                 return;
     209                 :            :             }
     210                 :            :         }
     211                 :            :     }
     212                 :          0 :     if( bValue )
     213                 :            :     {
     214                 :          0 :         if( getMultiSelect() )
     215                 :            :         {
     216                 :          0 :             nList.realloc( nLength + 1 );
     217                 :          0 :             nList[nLength] = nIndex;
     218                 :            :         }
     219                 :            :         else
     220                 :            :         {
     221                 :          0 :             nList.realloc( 1 );
     222                 :          0 :             nList[0] = nIndex;
     223                 :            :         }
     224                 :            :         //m_xProps->setPropertyValue( sSourceName, uno::makeAny( nList ) );
     225                 :          0 :         fireClickEvent();
     226                 :          0 :         m_xProps->setPropertyValue( SELECTEDITEMS, uno::makeAny( nList ) );
     227                 :          0 :     }
     228                 :            : }
     229                 :            : 
     230                 :            : // this is called when something like the following vba code is used
     231                 :            : // to determine the selected state of particular entries in the Listbox
     232                 :            : // msgbox ListBox1.Selected( 3 )
     233                 :            : 
     234                 :            : css::uno::Any
     235                 :          0 : ScVbaListBox::getValueEvent()
     236                 :            : {
     237                 :          0 :     uno::Sequence< sal_Int16 > nList;
     238                 :          0 :     m_xProps->getPropertyValue( rtl::OUString(  "SelectedItems"  ) ) >>= nList;
     239                 :          0 :     sal_Int32 nLength = nList.getLength();
     240                 :          0 :     sal_Int32 nIndex = m_nIndex;
     241                 :            : 
     242                 :          0 :     for( sal_Int32 i = 0; i < nLength; i++ )
     243                 :            :     {
     244                 :          0 :         if( nList[i] == nIndex )
     245                 :          0 :             return uno::makeAny( sal_True );
     246                 :            :     }
     247                 :            : 
     248                 :          0 :     return uno::makeAny( sal_False );
     249                 :            : }
     250                 :            : 
     251                 :            : void SAL_CALL
     252                 :          0 : ScVbaListBox::setRowSource( const rtl::OUString& _rowsource ) throw (uno::RuntimeException)
     253                 :            : {
     254                 :          0 :     ScVbaControl::setRowSource( _rowsource );
     255                 :          0 :     mpListHelper->setRowSource( _rowsource );
     256                 :          0 : }
     257                 :            : 
     258                 :            : sal_Int32 SAL_CALL
     259                 :          0 : ScVbaListBox::getListCount() throw (uno::RuntimeException)
     260                 :            : {
     261                 :          0 :     return mpListHelper->getListCount();
     262                 :            : }
     263                 :            : 
     264                 :            : uno::Any SAL_CALL
     265                 :          0 : ScVbaListBox::List( const ::uno::Any& pvargIndex, const uno::Any& pvarColumn ) throw (uno::RuntimeException)
     266                 :            : {
     267                 :          0 :     return mpListHelper->List( pvargIndex, pvarColumn );
     268                 :            : }
     269                 :            : 
     270                 :          0 : uno::Reference< msforms::XNewFont > SAL_CALL ScVbaListBox::getFont() throw (uno::RuntimeException)
     271                 :            : {
     272                 :          0 :     return new VbaNewFont( this, mxContext, m_xProps );
     273                 :            : }
     274                 :            : 
     275                 :            : rtl::OUString
     276                 :          0 : ScVbaListBox::getServiceImplName()
     277                 :            : {
     278                 :          0 :     return rtl::OUString("ScVbaListBox");
     279                 :            : }
     280                 :            : 
     281                 :            : uno::Sequence< rtl::OUString >
     282                 :          0 : ScVbaListBox::getServiceNames()
     283                 :            : {
     284                 :          0 :     static uno::Sequence< rtl::OUString > aServiceNames;
     285                 :          0 :     if ( aServiceNames.getLength() == 0 )
     286                 :            :     {
     287                 :          0 :         aServiceNames.realloc( 1 );
     288                 :          0 :         aServiceNames[ 0 ] = rtl::OUString( "ooo.vba.msforms.ScVbaListBox"  );
     289                 :            :     }
     290                 :          0 :     return aServiceNames;
     291                 :          0 : }
     292                 :            : 
     293                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10