LCOV - code coverage report
Current view: top level - libreoffice/vbahelper/source/msforms - vbacombobox.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 116 0.0 %
Date: 2012-12-27 Functions: 0 37 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)
      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)
      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)
      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             :                 OSL_TRACE("getListIndex returning %d", index );
     108           0 :                 return uno::makeAny( index );
     109             :             }
     110             : 
     111           0 :         }
     112             :      }
     113             :     OSL_TRACE("getListIndex returning %d", -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)
     121             : {
     122             :     // booleans are converted to uppercase strings
     123           0 :     m_xProps->setPropertyValue( sSourceName, uno::Any( extractStringFromAny( _value, ::rtl::OUString(), true ) ) );
     124           0 : }
     125             : 
     126             : // see Value
     127             : 
     128             : OUString SAL_CALL
     129           0 : ScVbaComboBox::getText() throw (uno::RuntimeException)
     130             : {
     131           0 :     OUString result;
     132           0 :     getValue() >>= result;
     133           0 :     return result;
     134             : }
     135             : 
     136             : void SAL_CALL
     137           0 : ScVbaComboBox::setText( const OUString& _text ) throw (uno::RuntimeException)
     138             : {
     139           0 :     setValue( uno::makeAny( _text ) ); // seems the same
     140           0 : }
     141             : 
     142             : // Methods
     143             : void SAL_CALL
     144           0 : ScVbaComboBox::AddItem( const uno::Any& pvargItem, const uno::Any& pvargIndex ) throw (uno::RuntimeException)
     145             : {
     146           0 :     mpListHelper->AddItem( pvargItem, pvargIndex );
     147           0 : }
     148             : 
     149             : void SAL_CALL
     150           0 : ScVbaComboBox::removeItem( const uno::Any& index ) throw (uno::RuntimeException)
     151             : {
     152           0 :     mpListHelper->removeItem( index );
     153           0 : }
     154             : 
     155             : void SAL_CALL
     156           0 : ScVbaComboBox::Clear(  ) throw (uno::RuntimeException)
     157             : {
     158           0 :     mpListHelper->Clear();
     159           0 : }
     160             : 
     161             : void SAL_CALL
     162           0 : ScVbaComboBox::setRowSource( const OUString& _rowsource ) throw (css::uno::RuntimeException)
     163             : {
     164           0 :     ScVbaControl::setRowSource( _rowsource );
     165           0 :     mpListHelper->setRowSource( _rowsource );
     166           0 : }
     167             : 
     168             : sal_Int32 SAL_CALL
     169           0 : ScVbaComboBox::getListCount() throw (uno::RuntimeException)
     170             : {
     171           0 :     return mpListHelper->getListCount();
     172             : }
     173             : 
     174             : uno::Any SAL_CALL
     175           0 : ScVbaComboBox::List( const ::uno::Any& pvargIndex, const uno::Any& pvarColumn ) throw (uno::RuntimeException)
     176             : {
     177           0 :     return mpListHelper->List( pvargIndex, pvarColumn );
     178             : }
     179             : 
     180           0 : sal_Int32 SAL_CALL ScVbaComboBox::getStyle() throw (uno::RuntimeException)
     181             : {
     182           0 :     return msforms::fmStyle::fmStyleDropDownCombo;
     183             : }
     184             : 
     185           0 : void SAL_CALL ScVbaComboBox::setStyle( sal_Int32 /*nStyle*/ ) throw (uno::RuntimeException)
     186             : {
     187           0 : }
     188             : 
     189           0 : sal_Int32 SAL_CALL ScVbaComboBox::getDropButtonStyle() throw (uno::RuntimeException)
     190             : {
     191           0 :     return msforms::fmDropButtonStyle::fmDropButtonStyleArrow;
     192             : }
     193             : 
     194           0 : void SAL_CALL ScVbaComboBox::setDropButtonStyle( sal_Int32 /*nDropButtonStyle*/ ) throw (uno::RuntimeException)
     195             : {
     196           0 : }
     197             : 
     198           0 : sal_Int32 SAL_CALL ScVbaComboBox::getDragBehavior() throw (uno::RuntimeException)
     199             : {
     200           0 :     return msforms::fmDragBehavior::fmDragBehaviorDisabled;
     201             : }
     202             : 
     203           0 : void SAL_CALL ScVbaComboBox::setDragBehavior( sal_Int32 /*nDragBehavior*/ ) throw (uno::RuntimeException)
     204             : {
     205           0 : }
     206             : 
     207           0 : sal_Int32 SAL_CALL ScVbaComboBox::getEnterFieldBehavior() throw (uno::RuntimeException)
     208             : {
     209           0 :     return msforms::fmEnterFieldBehavior::fmEnterFieldBehaviorSelectAll;
     210             : }
     211             : 
     212           0 : void SAL_CALL ScVbaComboBox::setEnterFieldBehavior( sal_Int32 /*nEnterFieldBehavior*/ ) throw (uno::RuntimeException)
     213             : {
     214           0 : }
     215             : 
     216           0 : sal_Int32 SAL_CALL ScVbaComboBox::getListStyle() throw (uno::RuntimeException)
     217             : {
     218           0 :     return msforms::fmListStyle::fmListStylePlain;
     219             : }
     220             : 
     221           0 : void SAL_CALL ScVbaComboBox::setListStyle( sal_Int32 /*nListStyle*/ ) throw (uno::RuntimeException)
     222             : {
     223           0 : }
     224             : 
     225           0 : sal_Int32 SAL_CALL ScVbaComboBox::getTextAlign() throw (uno::RuntimeException)
     226             : {
     227           0 :     return msforms::fmTextAlign::fmTextAlignLeft;
     228             : }
     229             : 
     230           0 : void SAL_CALL ScVbaComboBox::setTextAlign( sal_Int32 /*nTextAlign*/ ) throw (uno::RuntimeException)
     231             : {
     232           0 : }
     233             : 
     234           0 : sal_Int32 SAL_CALL ScVbaComboBox::getTextLength() throw (uno::RuntimeException)
     235             : {
     236           0 :     return getText().getLength();
     237             : }
     238             : 
     239           0 : uno::Reference< msforms::XNewFont > SAL_CALL ScVbaComboBox::getFont() throw (uno::RuntimeException)
     240             : {
     241           0 :     return new VbaNewFont( this, mxContext, m_xProps );
     242             : }
     243             : 
     244             : OUString
     245           0 : ScVbaComboBox::getServiceImplName()
     246             : {
     247           0 :     return OUString("ScVbaComboBox");
     248             : }
     249             : 
     250           0 : sal_Int32 SAL_CALL ScVbaComboBox::getBackColor() throw (uno::RuntimeException)
     251             : {
     252           0 :     return ScVbaControl::getBackColor();
     253             : }
     254             : 
     255           0 : void SAL_CALL ScVbaComboBox::setBackColor( sal_Int32 nBackColor ) throw (uno::RuntimeException)
     256             : {
     257           0 :     ScVbaControl::setBackColor( nBackColor );
     258           0 : }
     259             : 
     260           0 : sal_Bool SAL_CALL ScVbaComboBox::getAutoSize() throw (uno::RuntimeException)
     261             : {
     262           0 :     return ScVbaControl::getAutoSize();
     263             : }
     264             : 
     265           0 : void SAL_CALL ScVbaComboBox::setAutoSize( sal_Bool bAutoSize ) throw (uno::RuntimeException)
     266             : {
     267           0 :     ScVbaControl::setAutoSize( bAutoSize );
     268           0 : }
     269             : 
     270           0 : sal_Bool SAL_CALL ScVbaComboBox::getLocked() throw (uno::RuntimeException)
     271             : {
     272           0 :     return ScVbaControl::getLocked();
     273             : }
     274             : 
     275           0 : void SAL_CALL ScVbaComboBox::setLocked( sal_Bool bLocked ) throw (uno::RuntimeException)
     276             : {
     277           0 :     ScVbaControl::setLocked( bLocked );
     278           0 : }
     279             : 
     280             : uno::Sequence< OUString >
     281           0 : ScVbaComboBox::getServiceNames()
     282             : {
     283           0 :     static uno::Sequence< OUString > aServiceNames;
     284           0 :     if ( aServiceNames.getLength() == 0 )
     285             :     {
     286           0 :         aServiceNames.realloc( 1 );
     287           0 :         aServiceNames[ 0 ] = "ooo.vba.msforms.ComboBox";
     288             :     }
     289           0 :     return aServiceNames;
     290           0 : }
     291             : 
     292             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10