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

Generated by: LCOV version 1.10