LCOV - code coverage report
Current view: top level - vbahelper/source/msforms - vbacombobox.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 36 128 28.1 %
Date: 2014-11-03 Functions: 7 39 17.9 %
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 "vbacombobox.hxx"
      21             : #include <filter/msfilter/msvbahelper.hxx>
      22             : #include <basic/sbstar.hxx>
      23             : #include <basic/sbmod.hxx>
      24             : #include "vbanewfont.hxx"
      25             : #include <ooo/vba/msforms/fmStyle.hpp>
      26             : #include <ooo/vba/msforms/fmDropButtonStyle.hpp>
      27             : #include <ooo/vba/msforms/fmDragBehavior.hpp>
      28             : #include <ooo/vba/msforms/fmEnterFieldBehavior.hpp>
      29             : #include <ooo/vba/msforms/fmListStyle.hpp>
      30             : #include <ooo/vba/msforms/fmTextAlign.hpp>
      31             : 
      32             : using namespace com::sun::star;
      33             : using namespace ooo::vba;
      34             : 
      35             : 
      36             : //SelectedItems list of integer indexes
      37             : //StringItemList list of items
      38             : 
      39          14 : ScVbaComboBox::ScVbaComboBox( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< uno::XInterface >& xControl, const uno::Reference< frame::XModel >& xModel, AbstractGeometryAttributes* pGeomHelper ) : ComboBoxImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper )
      40             : {
      41          14 :     mpListHelper.reset( new ListControlHelper( m_xProps ) );
      42             :     try
      43             :     {
      44             :        // grab the default value property name
      45          14 :        m_xProps->getPropertyValue( "DataFieldProperty" ) >>= sSourceName;
      46             :     }
      47           0 :     catch( uno::Exception& )
      48             :     {
      49             :     }
      50          14 :     if( sSourceName.isEmpty() )
      51           0 :         sSourceName = "Text";
      52          14 : }
      53             : 
      54             : // Attributes
      55             : 
      56             : 
      57             : // Value, [read] e.g. getValue returns the value of ooo Text propery e.g. the value in
      58             : // the drop down
      59             : uno::Any SAL_CALL
      60          32 : ScVbaComboBox::getValue() throw (uno::RuntimeException, std::exception)
      61             : {
      62          32 :     return m_xProps->getPropertyValue( sSourceName );
      63             : }
      64             : 
      65             : void SAL_CALL
      66           0 : ScVbaComboBox::setListIndex( const uno::Any& _value ) throw (uno::RuntimeException, std::exception)
      67             : {
      68           0 :     sal_Int16 nIndex = 0;
      69           0 :     if( _value >>= nIndex )
      70             :     {
      71           0 :         sal_Int32 nOldIndex = -1;
      72           0 :         getListIndex() >>= nOldIndex;
      73           0 :         uno::Sequence< OUString > sItems;
      74           0 :         m_xProps->getPropertyValue( "StringItemList" ) >>= sItems;
      75           0 :         if( ( nIndex >= 0 ) && ( sItems.getLength() > nIndex ) )
      76             :         {
      77           0 :             OUString sText = sItems[ nIndex ];
      78           0 :             m_xProps->setPropertyValue( "Text", uno::makeAny( sText ) );
      79             : 
      80             :             // fire the _Change event
      81           0 :             if( nOldIndex != nIndex )
      82           0 :                 fireClickEvent();
      83           0 :         }
      84             :     }
      85           0 : }
      86             : 
      87             : uno::Any SAL_CALL
      88           6 : ScVbaComboBox::getListIndex() throw (uno::RuntimeException, std::exception)
      89             : {
      90           6 :     uno::Sequence< OUString > sItems;
      91           6 :     m_xProps->getPropertyValue( "StringItemList" ) >>= sItems;
      92             :     // should really return the item that has focus regardless of
      93             :     // it been selected
      94           6 :     if ( sItems.getLength() > 0 )
      95             :     {
      96           6 :         OUString sText = getText();
      97           6 :         sal_Int32 nLen = sItems.getLength();
      98          14 :         for ( sal_Int32 index = 0; !sText.isEmpty() && index < nLen; ++index )
      99             :         {
     100          10 :             if ( sItems[ index ].equals( sText ) )
     101             :             {
     102             :                 SAL_INFO("vbahelper", "getListIndex returning " << index );
     103           4 :                 return uno::makeAny( index );
     104             :             }
     105             : 
     106           4 :         }
     107             :      }
     108             :     SAL_INFO("vbahelper", "getListIndex returning -1" );
     109           4 :     return uno::makeAny( sal_Int32( -1 ) );
     110             : }
     111             : 
     112             : // Value, [write]e.g. setValue sets the value in the drop down, and if the value is one
     113             : // of the values in the list then the selection is also set
     114             : void SAL_CALL
     115           6 : ScVbaComboBox::setValue( const uno::Any& _value ) throw (uno::RuntimeException, std::exception)
     116             : {
     117             :     // booleans are converted to uppercase strings
     118           6 :     OUString oldValue = extractStringFromAny( getValue(), OUString(), true );
     119           6 :     m_xProps->setPropertyValue( sSourceName, uno::Any( extractStringFromAny( _value, OUString(), true ) ) );
     120          12 :     OUString newValue = extractStringFromAny( getValue(), OUString(), true );
     121           6 :     if ( oldValue != newValue )
     122             :     {
     123           6 :         sal_Int32 index = 0;
     124           6 :         uno::Any aIndex = getListIndex();
     125           6 :         aIndex >>= index;
     126           6 :         if ( index < 0 )
     127           4 :             fireChangeEvent();
     128             :         else
     129           2 :             fireClickEvent();
     130           6 :     }
     131           6 : }
     132             : 
     133             : // see Value
     134             : 
     135             : OUString SAL_CALL
     136           6 : ScVbaComboBox::getText() throw (uno::RuntimeException, std::exception)
     137             : {
     138           6 :     OUString result;
     139           6 :     getValue() >>= result;
     140           6 :     return result;
     141             : }
     142             : 
     143             : void SAL_CALL
     144           0 : ScVbaComboBox::setText( const OUString& _text ) throw (uno::RuntimeException, std::exception)
     145             : {
     146           0 :     setValue( uno::makeAny( _text ) ); // seems the same
     147           0 : }
     148             : 
     149             : // Methods
     150             : void SAL_CALL
     151           0 : ScVbaComboBox::AddItem( const uno::Any& pvargItem, const uno::Any& pvargIndex ) throw (uno::RuntimeException, std::exception)
     152             : {
     153           0 :     mpListHelper->AddItem( pvargItem, pvargIndex );
     154           0 : }
     155             : 
     156             : void SAL_CALL
     157           0 : ScVbaComboBox::removeItem( const uno::Any& index ) throw (uno::RuntimeException, std::exception)
     158             : {
     159           0 :     mpListHelper->removeItem( index );
     160           0 : }
     161             : 
     162             : void SAL_CALL
     163           0 : ScVbaComboBox::Clear(  ) throw (uno::RuntimeException, std::exception)
     164             : {
     165           0 :     mpListHelper->Clear();
     166           0 : }
     167             : 
     168             : void SAL_CALL
     169           0 : ScVbaComboBox::setRowSource( const OUString& _rowsource ) throw (css::uno::RuntimeException, std::exception)
     170             : {
     171           0 :     ScVbaControl::setRowSource( _rowsource );
     172           0 :     mpListHelper->setRowSource( _rowsource );
     173           0 : }
     174             : 
     175             : sal_Int32 SAL_CALL
     176           0 : ScVbaComboBox::getListCount() throw (uno::RuntimeException, std::exception)
     177             : {
     178           0 :     return mpListHelper->getListCount();
     179             : }
     180             : 
     181             : uno::Any SAL_CALL
     182           0 : ScVbaComboBox::List( const ::uno::Any& pvargIndex, const uno::Any& pvarColumn ) throw (uno::RuntimeException, std::exception)
     183             : {
     184           0 :     return mpListHelper->List( pvargIndex, pvarColumn );
     185             : }
     186             : 
     187           0 : sal_Int32 SAL_CALL ScVbaComboBox::getStyle() throw (uno::RuntimeException, std::exception)
     188             : {
     189           0 :     return msforms::fmStyle::fmStyleDropDownCombo;
     190             : }
     191             : 
     192           0 : void SAL_CALL ScVbaComboBox::setStyle( sal_Int32 /*nStyle*/ ) throw (uno::RuntimeException, std::exception)
     193             : {
     194           0 : }
     195             : 
     196           0 : sal_Int32 SAL_CALL ScVbaComboBox::getDropButtonStyle() throw (uno::RuntimeException, std::exception)
     197             : {
     198           0 :     return msforms::fmDropButtonStyle::fmDropButtonStyleArrow;
     199             : }
     200             : 
     201           0 : void SAL_CALL ScVbaComboBox::setDropButtonStyle( sal_Int32 /*nDropButtonStyle*/ ) throw (uno::RuntimeException, std::exception)
     202             : {
     203           0 : }
     204             : 
     205           0 : sal_Int32 SAL_CALL ScVbaComboBox::getDragBehavior() throw (uno::RuntimeException, std::exception)
     206             : {
     207           0 :     return msforms::fmDragBehavior::fmDragBehaviorDisabled;
     208             : }
     209             : 
     210           0 : void SAL_CALL ScVbaComboBox::setDragBehavior( sal_Int32 /*nDragBehavior*/ ) throw (uno::RuntimeException, std::exception)
     211             : {
     212           0 : }
     213             : 
     214           0 : sal_Int32 SAL_CALL ScVbaComboBox::getEnterFieldBehavior() throw (uno::RuntimeException, std::exception)
     215             : {
     216           0 :     return msforms::fmEnterFieldBehavior::fmEnterFieldBehaviorSelectAll;
     217             : }
     218             : 
     219           0 : void SAL_CALL ScVbaComboBox::setEnterFieldBehavior( sal_Int32 /*nEnterFieldBehavior*/ ) throw (uno::RuntimeException, std::exception)
     220             : {
     221           0 : }
     222             : 
     223           0 : sal_Int32 SAL_CALL ScVbaComboBox::getListStyle() throw (uno::RuntimeException, std::exception)
     224             : {
     225           0 :     return msforms::fmListStyle::fmListStylePlain;
     226             : }
     227             : 
     228           0 : void SAL_CALL ScVbaComboBox::setListStyle( sal_Int32 /*nListStyle*/ ) throw (uno::RuntimeException, std::exception)
     229             : {
     230           0 : }
     231             : 
     232           0 : sal_Int32 SAL_CALL ScVbaComboBox::getTextAlign() throw (uno::RuntimeException, std::exception)
     233             : {
     234           0 :     return msforms::fmTextAlign::fmTextAlignLeft;
     235             : }
     236             : 
     237           0 : void SAL_CALL ScVbaComboBox::setTextAlign( sal_Int32 /*nTextAlign*/ ) throw (uno::RuntimeException, std::exception)
     238             : {
     239           0 : }
     240             : 
     241           0 : sal_Int32 SAL_CALL ScVbaComboBox::getTextLength() throw (uno::RuntimeException, std::exception)
     242             : {
     243           0 :     return getText().getLength();
     244             : }
     245             : 
     246           0 : uno::Reference< msforms::XNewFont > SAL_CALL ScVbaComboBox::getFont() throw (uno::RuntimeException, std::exception)
     247             : {
     248           0 :     return new VbaNewFont( m_xProps );
     249             : }
     250             : 
     251             : OUString
     252           0 : ScVbaComboBox::getServiceImplName()
     253             : {
     254           0 :     return OUString("ScVbaComboBox");
     255             : }
     256             : 
     257           0 : sal_Int32 SAL_CALL ScVbaComboBox::getBackColor() throw (uno::RuntimeException, std::exception)
     258             : {
     259           0 :     return ScVbaControl::getBackColor();
     260             : }
     261             : 
     262           0 : void SAL_CALL ScVbaComboBox::setBackColor( sal_Int32 nBackColor ) throw (uno::RuntimeException, std::exception)
     263             : {
     264           0 :     ScVbaControl::setBackColor( nBackColor );
     265           0 : }
     266             : 
     267           0 : sal_Bool SAL_CALL ScVbaComboBox::getAutoSize() throw (uno::RuntimeException, std::exception)
     268             : {
     269           0 :     return ScVbaControl::getAutoSize();
     270             : }
     271             : 
     272           0 : void SAL_CALL ScVbaComboBox::setAutoSize( sal_Bool bAutoSize ) throw (uno::RuntimeException, std::exception)
     273             : {
     274           0 :     ScVbaControl::setAutoSize( bAutoSize );
     275           0 : }
     276             : 
     277           0 : sal_Bool SAL_CALL ScVbaComboBox::getLocked() throw (uno::RuntimeException, std::exception)
     278             : {
     279           0 :     return ScVbaControl::getLocked();
     280             : }
     281             : 
     282           0 : void SAL_CALL ScVbaComboBox::setLocked( sal_Bool bLocked ) throw (uno::RuntimeException, std::exception)
     283             : {
     284           0 :     ScVbaControl::setLocked( bLocked );
     285           0 : }
     286             : 
     287           0 : OUString SAL_CALL ScVbaComboBox::getLinkedCell() throw (uno::RuntimeException, std::exception)
     288             : {
     289           0 :     return ScVbaControl::getControlSource();
     290             : }
     291             : 
     292           0 : void SAL_CALL ScVbaComboBox::setLinkedCell( const OUString& _linkedcell ) throw (uno::RuntimeException, std::exception)
     293             : {
     294           0 :     ScVbaControl::setControlSource( _linkedcell );
     295           0 : }
     296             : 
     297             : uno::Sequence< OUString >
     298           0 : ScVbaComboBox::getServiceNames()
     299             : {
     300           0 :     static uno::Sequence< OUString > aServiceNames;
     301           0 :     if ( aServiceNames.getLength() == 0 )
     302             :     {
     303           0 :         aServiceNames.realloc( 1 );
     304           0 :         aServiceNames[ 0 ] = "ooo.vba.msforms.ComboBox";
     305             :     }
     306           0 :     return aServiceNames;
     307           6 : }
     308             : 
     309             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10