1*e6ed5fbcSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*e6ed5fbcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*e6ed5fbcSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*e6ed5fbcSAndrew Rist * distributed with this work for additional information 6*e6ed5fbcSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*e6ed5fbcSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*e6ed5fbcSAndrew Rist * "License"); you may not use this file except in compliance 9*e6ed5fbcSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*e6ed5fbcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*e6ed5fbcSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*e6ed5fbcSAndrew Rist * software distributed under the License is distributed on an 15*e6ed5fbcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*e6ed5fbcSAndrew Rist * KIND, either express or implied. See the License for the 17*e6ed5fbcSAndrew Rist * specific language governing permissions and limitations 18*e6ed5fbcSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*e6ed5fbcSAndrew Rist *************************************************************/ 21*e6ed5fbcSAndrew Rist 22*e6ed5fbcSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "vbacombobox.hxx" 25cdf0e10cSrcweir #include "vbanewfont.hxx" 26cdf0e10cSrcweir #include <ooo/vba/msforms/fmStyle.hpp> 27cdf0e10cSrcweir #include <ooo/vba/msforms/fmDropButtonStyle.hpp> 28cdf0e10cSrcweir #include <ooo/vba/msforms/fmDragBehavior.hpp> 29cdf0e10cSrcweir #include <ooo/vba/msforms/fmEnterFieldBehavior.hpp> 30cdf0e10cSrcweir #include <ooo/vba/msforms/fmListStyle.hpp> 31cdf0e10cSrcweir #include <ooo/vba/msforms/fmTextAlign.hpp> 32cdf0e10cSrcweir 33cdf0e10cSrcweir using namespace com::sun::star; 34cdf0e10cSrcweir using namespace ooo::vba; 35cdf0e10cSrcweir 36cdf0e10cSrcweir 37cdf0e10cSrcweir //SelectedItems list of integer indexes 38cdf0e10cSrcweir //StringItemList list of items 39cdf0e10cSrcweir 40cdf0e10cSrcweir const static rtl::OUString TEXT( RTL_CONSTASCII_USTRINGPARAM("Text") ); 41cdf0e10cSrcweir const static rtl::OUString SELECTEDITEMS( RTL_CONSTASCII_USTRINGPARAM("SelectedItems") ); 42cdf0e10cSrcweir const static rtl::OUString ITEMS( RTL_CONSTASCII_USTRINGPARAM("StringItemList") ); 43cdf0e10cSrcweir const static rtl::OUString CONTROLSOURCEPROP( RTL_CONSTASCII_USTRINGPARAM("DataFieldProperty") ); 44cdf0e10cSrcweir 45cdf0e10cSrcweir 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 ) 46cdf0e10cSrcweir { 47cdf0e10cSrcweir mpListHelper.reset( new ListControlHelper( m_xProps ) ); 48cdf0e10cSrcweir try 49cdf0e10cSrcweir { 50cdf0e10cSrcweir // grab the default value property name 51cdf0e10cSrcweir m_xProps->getPropertyValue( CONTROLSOURCEPROP ) >>= sSourceName; 52cdf0e10cSrcweir } 53cdf0e10cSrcweir catch( uno::Exception& ) 54cdf0e10cSrcweir { 55cdf0e10cSrcweir } 56cdf0e10cSrcweir if( sSourceName.getLength() == 0 ) 57cdf0e10cSrcweir sSourceName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ) ); 58cdf0e10cSrcweir } 59cdf0e10cSrcweir 60cdf0e10cSrcweir // Attributes 61cdf0e10cSrcweir 62cdf0e10cSrcweir 63cdf0e10cSrcweir // Value, [read] e.g. getValue returns the value of ooo Text propery e.g. the value in 64cdf0e10cSrcweir // the drop down 65cdf0e10cSrcweir uno::Any SAL_CALL 66cdf0e10cSrcweir ScVbaComboBox::getValue() throw (uno::RuntimeException) 67cdf0e10cSrcweir { 68cdf0e10cSrcweir return m_xProps->getPropertyValue( sSourceName ); 69cdf0e10cSrcweir } 70cdf0e10cSrcweir 71cdf0e10cSrcweir void SAL_CALL 72cdf0e10cSrcweir ScVbaComboBox::setListIndex( const uno::Any& _value ) throw (uno::RuntimeException) 73cdf0e10cSrcweir { 74cdf0e10cSrcweir sal_Int16 nIndex = 0; 75cdf0e10cSrcweir if( _value >>= nIndex ) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir uno::Sequence< rtl::OUString > sItems; 78cdf0e10cSrcweir m_xProps->getPropertyValue( ITEMS ) >>= sItems; 79cdf0e10cSrcweir if( ( nIndex >= 0 ) && ( sItems.getLength() > nIndex ) ) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir rtl::OUString sText = sItems[ nIndex ]; 82cdf0e10cSrcweir m_xProps->setPropertyValue( TEXT, uno::makeAny( sText ) ); 83cdf0e10cSrcweir } 84cdf0e10cSrcweir } 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir uno::Any SAL_CALL 88cdf0e10cSrcweir ScVbaComboBox::getListIndex() throw (uno::RuntimeException) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir uno::Sequence< rtl::OUString > sItems; 91cdf0e10cSrcweir m_xProps->getPropertyValue( ITEMS ) >>= sItems; 92cdf0e10cSrcweir // should really return the item that has focus regardless of 93cdf0e10cSrcweir // it been selected 94cdf0e10cSrcweir if ( sItems.getLength() > 0 ) 95cdf0e10cSrcweir { 96cdf0e10cSrcweir rtl::OUString sText = getText(); 97cdf0e10cSrcweir sal_Int32 nLen = sItems.getLength(); 98cdf0e10cSrcweir for ( sal_Int32 index = 0; sText.getLength() && index < nLen; ++index ) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir if ( sItems[ index ].equals( sText ) ) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir OSL_TRACE("getListIndex returning %d", index ); 103cdf0e10cSrcweir return uno::makeAny( index ); 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir } 107cdf0e10cSrcweir } 108cdf0e10cSrcweir OSL_TRACE("getListIndex returning %d", -1 ); 109cdf0e10cSrcweir return uno::makeAny( sal_Int32( -1 ) ); 110cdf0e10cSrcweir } 111cdf0e10cSrcweir 112cdf0e10cSrcweir // Value, [write]e.g. setValue sets the value in the drop down, and if the value is one 113cdf0e10cSrcweir // of the values in the list then the selection is also set 114cdf0e10cSrcweir void SAL_CALL 115cdf0e10cSrcweir ScVbaComboBox::setValue( const uno::Any& _value ) throw (uno::RuntimeException) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir // booleans are converted to uppercase strings 118cdf0e10cSrcweir m_xProps->setPropertyValue( sSourceName, uno::Any( extractStringFromAny( _value, ::rtl::OUString(), true ) ) ); 119cdf0e10cSrcweir } 120cdf0e10cSrcweir 121cdf0e10cSrcweir // see Value 122cdf0e10cSrcweir 123cdf0e10cSrcweir ::rtl::OUString SAL_CALL 124cdf0e10cSrcweir ScVbaComboBox::getText() throw (uno::RuntimeException) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir rtl::OUString result; 127cdf0e10cSrcweir getValue() >>= result; 128cdf0e10cSrcweir return result; 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131cdf0e10cSrcweir void SAL_CALL 132cdf0e10cSrcweir ScVbaComboBox::setText( const ::rtl::OUString& _text ) throw (uno::RuntimeException) 133cdf0e10cSrcweir { 134cdf0e10cSrcweir setValue( uno::makeAny( _text ) ); // seems the same 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir // Methods 138cdf0e10cSrcweir void SAL_CALL 139cdf0e10cSrcweir ScVbaComboBox::AddItem( const uno::Any& pvargItem, const uno::Any& pvargIndex ) throw (uno::RuntimeException) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir mpListHelper->AddItem( pvargItem, pvargIndex ); 142cdf0e10cSrcweir } 143cdf0e10cSrcweir 144cdf0e10cSrcweir void SAL_CALL 145cdf0e10cSrcweir ScVbaComboBox::removeItem( const uno::Any& index ) throw (uno::RuntimeException) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir mpListHelper->removeItem( index ); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir void SAL_CALL 151cdf0e10cSrcweir ScVbaComboBox::Clear( ) throw (uno::RuntimeException) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir mpListHelper->Clear(); 154cdf0e10cSrcweir } 155cdf0e10cSrcweir 156cdf0e10cSrcweir void SAL_CALL 157cdf0e10cSrcweir ScVbaComboBox::setRowSource( const rtl::OUString& _rowsource ) throw (css::uno::RuntimeException) 158cdf0e10cSrcweir { 159cdf0e10cSrcweir ScVbaControl::setRowSource( _rowsource ); 160cdf0e10cSrcweir mpListHelper->setRowSource( _rowsource ); 161cdf0e10cSrcweir } 162cdf0e10cSrcweir 163cdf0e10cSrcweir sal_Int32 SAL_CALL 164cdf0e10cSrcweir ScVbaComboBox::getListCount() throw (uno::RuntimeException) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir return mpListHelper->getListCount(); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir uno::Any SAL_CALL 170cdf0e10cSrcweir ScVbaComboBox::List( const ::uno::Any& pvargIndex, const uno::Any& pvarColumn ) throw (uno::RuntimeException) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir return mpListHelper->List( pvargIndex, pvarColumn ); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir 175cdf0e10cSrcweir sal_Int32 SAL_CALL ScVbaComboBox::getStyle() throw (uno::RuntimeException) 176cdf0e10cSrcweir { 177cdf0e10cSrcweir return msforms::fmStyle::fmStyleDropDownCombo; 178cdf0e10cSrcweir } 179cdf0e10cSrcweir 180cdf0e10cSrcweir void SAL_CALL ScVbaComboBox::setStyle( sal_Int32 /*nStyle*/ ) throw (uno::RuntimeException) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir } 183cdf0e10cSrcweir 184cdf0e10cSrcweir sal_Int32 SAL_CALL ScVbaComboBox::getDropButtonStyle() throw (uno::RuntimeException) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir return msforms::fmDropButtonStyle::fmDropButtonStyleArrow; 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir void SAL_CALL ScVbaComboBox::setDropButtonStyle( sal_Int32 /*nDropButtonStyle*/ ) throw (uno::RuntimeException) 190cdf0e10cSrcweir { 191cdf0e10cSrcweir } 192cdf0e10cSrcweir 193cdf0e10cSrcweir sal_Int32 SAL_CALL ScVbaComboBox::getDragBehavior() throw (uno::RuntimeException) 194cdf0e10cSrcweir { 195cdf0e10cSrcweir return msforms::fmDragBehavior::fmDragBehaviorDisabled; 196cdf0e10cSrcweir } 197cdf0e10cSrcweir 198cdf0e10cSrcweir void SAL_CALL ScVbaComboBox::setDragBehavior( sal_Int32 /*nDragBehavior*/ ) throw (uno::RuntimeException) 199cdf0e10cSrcweir { 200cdf0e10cSrcweir } 201cdf0e10cSrcweir 202cdf0e10cSrcweir sal_Int32 SAL_CALL ScVbaComboBox::getEnterFieldBehavior() throw (uno::RuntimeException) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir return msforms::fmEnterFieldBehavior::fmEnterFieldBehaviorSelectAll; 205cdf0e10cSrcweir } 206cdf0e10cSrcweir 207cdf0e10cSrcweir void SAL_CALL ScVbaComboBox::setEnterFieldBehavior( sal_Int32 /*nEnterFieldBehavior*/ ) throw (uno::RuntimeException) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir } 210cdf0e10cSrcweir 211cdf0e10cSrcweir sal_Int32 SAL_CALL ScVbaComboBox::getListStyle() throw (uno::RuntimeException) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir return msforms::fmListStyle::fmListStylePlain; 214cdf0e10cSrcweir } 215cdf0e10cSrcweir 216cdf0e10cSrcweir void SAL_CALL ScVbaComboBox::setListStyle( sal_Int32 /*nListStyle*/ ) throw (uno::RuntimeException) 217cdf0e10cSrcweir { 218cdf0e10cSrcweir } 219cdf0e10cSrcweir 220cdf0e10cSrcweir sal_Int32 SAL_CALL ScVbaComboBox::getTextAlign() throw (uno::RuntimeException) 221cdf0e10cSrcweir { 222cdf0e10cSrcweir return msforms::fmTextAlign::fmTextAlignLeft; 223cdf0e10cSrcweir } 224cdf0e10cSrcweir 225cdf0e10cSrcweir void SAL_CALL ScVbaComboBox::setTextAlign( sal_Int32 /*nTextAlign*/ ) throw (uno::RuntimeException) 226cdf0e10cSrcweir { 227cdf0e10cSrcweir } 228cdf0e10cSrcweir 229cdf0e10cSrcweir sal_Int32 SAL_CALL ScVbaComboBox::getTextLength() throw (uno::RuntimeException) 230cdf0e10cSrcweir { 231cdf0e10cSrcweir return getText().getLength(); 232cdf0e10cSrcweir } 233cdf0e10cSrcweir 234cdf0e10cSrcweir uno::Reference< msforms::XNewFont > SAL_CALL ScVbaComboBox::getFont() throw (uno::RuntimeException) 235cdf0e10cSrcweir { 236cdf0e10cSrcweir return new VbaNewFont( this, mxContext, m_xProps ); 237cdf0e10cSrcweir } 238cdf0e10cSrcweir 239cdf0e10cSrcweir rtl::OUString& 240cdf0e10cSrcweir ScVbaComboBox::getServiceImplName() 241cdf0e10cSrcweir { 242cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaComboBox") ); 243cdf0e10cSrcweir return sImplName; 244cdf0e10cSrcweir } 245cdf0e10cSrcweir 246cdf0e10cSrcweir uno::Sequence< rtl::OUString > 247cdf0e10cSrcweir ScVbaComboBox::getServiceNames() 248cdf0e10cSrcweir { 249cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames; 250cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 ) 251cdf0e10cSrcweir { 252cdf0e10cSrcweir aServiceNames.realloc( 1 ); 253cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.ComboBox" ) ); 254cdf0e10cSrcweir } 255cdf0e10cSrcweir return aServiceNames; 256cdf0e10cSrcweir } 257