merge the formfield patch from ooo-build
[ooovba.git] / vbahelper / source / msforms / vbacombobox.cxx
blob7c27734c200cb2da3c183d112d6de1c72a9966d0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vbacombobox.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "vbacombobox.hxx"
31 #include <vector>
33 using namespace com::sun::star;
34 using namespace ooo::vba;
37 //SelectedItems list of integer indexes
38 //StringItemList list of items
40 const static rtl::OUString TEXT( RTL_CONSTASCII_USTRINGPARAM("Text") );
41 const static rtl::OUString SELECTEDITEMS( RTL_CONSTASCII_USTRINGPARAM("SelectedItems") );
42 const static rtl::OUString ITEMS( RTL_CONSTASCII_USTRINGPARAM("StringItemList") );
43 const static rtl::OUString CONTROLSOURCEPROP( RTL_CONSTASCII_USTRINGPARAM("DataFieldProperty") );
45 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, bool bDialogType ) : ComboBoxImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ), mbDialogType( bDialogType )
47 mpListHelper.reset( new ListControlHelper( m_xProps ) );
48 // grab the default value property name
49 m_xProps->getPropertyValue( CONTROLSOURCEPROP ) >>= sSourceName;
52 // Attributes
55 // Value, [read] e.g. getValue returns the value of ooo Text propery e.g. the value in
56 // the drop down
57 uno::Any SAL_CALL
58 ScVbaComboBox::getValue() throw (uno::RuntimeException)
60 return m_xProps->getPropertyValue( sSourceName );
63 void SAL_CALL
64 ScVbaComboBox::setListIndex( const uno::Any& _value ) throw (uno::RuntimeException)
66 sal_Int16 nIndex = 0;
67 if( _value >>= nIndex )
69 uno::Sequence< rtl::OUString > sItems;
70 m_xProps->getPropertyValue( ITEMS ) >>= sItems;
71 if( ( nIndex >= 0 ) && ( sItems.getLength() > nIndex ) )
73 rtl::OUString sText = sItems[ nIndex ];
74 m_xProps->setPropertyValue( TEXT, uno::makeAny( sText ) );
79 uno::Any SAL_CALL
80 ScVbaComboBox::getListIndex() throw (uno::RuntimeException)
82 uno::Sequence< rtl::OUString > sItems;
83 m_xProps->getPropertyValue( ITEMS ) >>= sItems;
84 // should really return the item that has focus regardless of
85 // it been selected
86 if ( sItems.getLength() > 0 )
88 rtl::OUString sText = getText();
89 sal_Int32 nLen = sItems.getLength();
90 for ( sal_Int32 index = 0; sText.getLength() && index < nLen; ++index )
92 if ( sItems[ index ].equals( sText ) )
94 OSL_TRACE("getListIndex returning %d", index );
95 return uno::makeAny( index );
100 OSL_TRACE("getListIndex returning %d", -1 );
101 return uno::makeAny( sal_Int32( -1 ) );
104 // Value, [write]e.g. setValue sets the value in the drop down, and if the value is one
105 // of the values in the list then the selection is also set
106 void SAL_CALL
107 ScVbaComboBox::setValue( const uno::Any& _value ) throw (uno::RuntimeException)
109 m_xProps->setPropertyValue( sSourceName, _value );
112 // see Value
114 ::rtl::OUString SAL_CALL
115 ScVbaComboBox::getText() throw (uno::RuntimeException)
117 rtl::OUString result;
118 getValue() >>= result;
119 return result;
122 void SAL_CALL
123 ScVbaComboBox::setText( const ::rtl::OUString& _text ) throw (uno::RuntimeException)
125 setValue( uno::makeAny( _text ) ); // seems the same
128 // Methods
129 void SAL_CALL
130 ScVbaComboBox::AddItem( const uno::Any& pvargItem, const uno::Any& pvargIndex ) throw (uno::RuntimeException)
132 mpListHelper->AddItem( pvargItem, pvargIndex );
135 void SAL_CALL
136 ScVbaComboBox::removeItem( const uno::Any& index ) throw (uno::RuntimeException)
138 mpListHelper->removeItem( index );
141 void SAL_CALL
142 ScVbaComboBox::Clear( ) throw (uno::RuntimeException)
144 mpListHelper->Clear();
147 void SAL_CALL
148 ScVbaComboBox::setRowSource( const rtl::OUString& _rowsource ) throw (css::uno::RuntimeException)
150 ScVbaControl::setRowSource( _rowsource );
151 mpListHelper->setRowSource( _rowsource );
154 sal_Int32 SAL_CALL
155 ScVbaComboBox::getListCount() throw (uno::RuntimeException)
157 return mpListHelper->getListCount();
160 uno::Any SAL_CALL
161 ScVbaComboBox::List( const ::uno::Any& pvargIndex, const uno::Any& pvarColumn ) throw (uno::RuntimeException)
163 return mpListHelper->List( pvargIndex, pvarColumn );
166 rtl::OUString&
167 ScVbaComboBox::getServiceImplName()
169 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaComboBox") );
170 return sImplName;
173 uno::Sequence< rtl::OUString >
174 ScVbaComboBox::getServiceNames()
176 static uno::Sequence< rtl::OUString > aServiceNames;
177 if ( aServiceNames.getLength() == 0 )
179 aServiceNames.realloc( 1 );
180 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.ComboBox" ) );
182 return aServiceNames;