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