Bump version to 4.1-6
[LibreOffice.git] / vbahelper / source / msforms / vbacombobox.cxx
blob8c5401a4e36c6c16bafbec956ccea6876949aba8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
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 OUString TEXT( "Text" );
41 const static OUString ITEMS( "StringItemList" );
42 const static OUString CONTROLSOURCEPROP( "DataFieldProperty" );
44 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 )
46 mpListHelper.reset( new ListControlHelper( m_xProps ) );
47 try
49 // grab the default value property name
50 m_xProps->getPropertyValue( CONTROLSOURCEPROP ) >>= sSourceName;
52 catch( uno::Exception& )
55 if( sSourceName.isEmpty() )
56 sSourceName = "Text";
59 // Attributes
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 ScVbaComboBox::getValue() throw (uno::RuntimeException)
67 return m_xProps->getPropertyValue( sSourceName );
70 void SAL_CALL
71 ScVbaComboBox::setListIndex( const uno::Any& _value ) throw (uno::RuntimeException)
73 sal_Int16 nIndex = 0;
74 if( _value >>= nIndex )
76 sal_Int32 nOldIndex = -1;
77 getListIndex() >>= nOldIndex;
78 uno::Sequence< OUString > sItems;
79 m_xProps->getPropertyValue( ITEMS ) >>= sItems;
80 if( ( nIndex >= 0 ) && ( sItems.getLength() > nIndex ) )
82 OUString sText = sItems[ nIndex ];
83 m_xProps->setPropertyValue( TEXT, uno::makeAny( sText ) );
85 // fire the _Change event
86 if( nOldIndex != nIndex )
87 fireClickEvent();
92 uno::Any SAL_CALL
93 ScVbaComboBox::getListIndex() throw (uno::RuntimeException)
95 uno::Sequence< OUString > sItems;
96 m_xProps->getPropertyValue( ITEMS ) >>= sItems;
97 // should really return the item that has focus regardless of
98 // it been selected
99 if ( sItems.getLength() > 0 )
101 OUString sText = getText();
102 sal_Int32 nLen = sItems.getLength();
103 for ( sal_Int32 index = 0; !sText.isEmpty() && index < nLen; ++index )
105 if ( sItems[ index ].equals( sText ) )
107 SAL_INFO("vbahelper", "getListIndex returning " << index );
108 return uno::makeAny( index );
113 SAL_INFO("vbahelper", "getListIndex returning -1" );
114 return uno::makeAny( sal_Int32( -1 ) );
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 ScVbaComboBox::setValue( const uno::Any& _value ) throw (uno::RuntimeException)
122 // booleans are converted to uppercase strings
123 OUString oldValue = extractStringFromAny( getValue(), OUString(), true );
124 m_xProps->setPropertyValue( sSourceName, uno::Any( extractStringFromAny( _value, OUString(), true ) ) );
125 OUString newValue = extractStringFromAny( getValue(), OUString(), true );
126 if ( oldValue != newValue )
128 sal_Int32 index = 0;
129 uno::Any aIndex = getListIndex();
130 aIndex >>= index;
131 if ( index < 0 )
132 fireChangeEvent();
133 else
134 fireClickEvent();
138 // see Value
140 OUString SAL_CALL
141 ScVbaComboBox::getText() throw (uno::RuntimeException)
143 OUString result;
144 getValue() >>= result;
145 return result;
148 void SAL_CALL
149 ScVbaComboBox::setText( const OUString& _text ) throw (uno::RuntimeException)
151 setValue( uno::makeAny( _text ) ); // seems the same
154 // Methods
155 void SAL_CALL
156 ScVbaComboBox::AddItem( const uno::Any& pvargItem, const uno::Any& pvargIndex ) throw (uno::RuntimeException)
158 mpListHelper->AddItem( pvargItem, pvargIndex );
161 void SAL_CALL
162 ScVbaComboBox::removeItem( const uno::Any& index ) throw (uno::RuntimeException)
164 mpListHelper->removeItem( index );
167 void SAL_CALL
168 ScVbaComboBox::Clear( ) throw (uno::RuntimeException)
170 mpListHelper->Clear();
173 void SAL_CALL
174 ScVbaComboBox::setRowSource( const OUString& _rowsource ) throw (css::uno::RuntimeException)
176 ScVbaControl::setRowSource( _rowsource );
177 mpListHelper->setRowSource( _rowsource );
180 sal_Int32 SAL_CALL
181 ScVbaComboBox::getListCount() throw (uno::RuntimeException)
183 return mpListHelper->getListCount();
186 uno::Any SAL_CALL
187 ScVbaComboBox::List( const ::uno::Any& pvargIndex, const uno::Any& pvarColumn ) throw (uno::RuntimeException)
189 return mpListHelper->List( pvargIndex, pvarColumn );
192 sal_Int32 SAL_CALL ScVbaComboBox::getStyle() throw (uno::RuntimeException)
194 return msforms::fmStyle::fmStyleDropDownCombo;
197 void SAL_CALL ScVbaComboBox::setStyle( sal_Int32 /*nStyle*/ ) throw (uno::RuntimeException)
201 sal_Int32 SAL_CALL ScVbaComboBox::getDropButtonStyle() throw (uno::RuntimeException)
203 return msforms::fmDropButtonStyle::fmDropButtonStyleArrow;
206 void SAL_CALL ScVbaComboBox::setDropButtonStyle( sal_Int32 /*nDropButtonStyle*/ ) throw (uno::RuntimeException)
210 sal_Int32 SAL_CALL ScVbaComboBox::getDragBehavior() throw (uno::RuntimeException)
212 return msforms::fmDragBehavior::fmDragBehaviorDisabled;
215 void SAL_CALL ScVbaComboBox::setDragBehavior( sal_Int32 /*nDragBehavior*/ ) throw (uno::RuntimeException)
219 sal_Int32 SAL_CALL ScVbaComboBox::getEnterFieldBehavior() throw (uno::RuntimeException)
221 return msforms::fmEnterFieldBehavior::fmEnterFieldBehaviorSelectAll;
224 void SAL_CALL ScVbaComboBox::setEnterFieldBehavior( sal_Int32 /*nEnterFieldBehavior*/ ) throw (uno::RuntimeException)
228 sal_Int32 SAL_CALL ScVbaComboBox::getListStyle() throw (uno::RuntimeException)
230 return msforms::fmListStyle::fmListStylePlain;
233 void SAL_CALL ScVbaComboBox::setListStyle( sal_Int32 /*nListStyle*/ ) throw (uno::RuntimeException)
237 sal_Int32 SAL_CALL ScVbaComboBox::getTextAlign() throw (uno::RuntimeException)
239 return msforms::fmTextAlign::fmTextAlignLeft;
242 void SAL_CALL ScVbaComboBox::setTextAlign( sal_Int32 /*nTextAlign*/ ) throw (uno::RuntimeException)
246 sal_Int32 SAL_CALL ScVbaComboBox::getTextLength() throw (uno::RuntimeException)
248 return getText().getLength();
251 uno::Reference< msforms::XNewFont > SAL_CALL ScVbaComboBox::getFont() throw (uno::RuntimeException)
253 return new VbaNewFont( this, mxContext, m_xProps );
256 OUString
257 ScVbaComboBox::getServiceImplName()
259 return OUString("ScVbaComboBox");
262 sal_Int32 SAL_CALL ScVbaComboBox::getBackColor() throw (uno::RuntimeException)
264 return ScVbaControl::getBackColor();
267 void SAL_CALL ScVbaComboBox::setBackColor( sal_Int32 nBackColor ) throw (uno::RuntimeException)
269 ScVbaControl::setBackColor( nBackColor );
272 sal_Bool SAL_CALL ScVbaComboBox::getAutoSize() throw (uno::RuntimeException)
274 return ScVbaControl::getAutoSize();
277 void SAL_CALL ScVbaComboBox::setAutoSize( sal_Bool bAutoSize ) throw (uno::RuntimeException)
279 ScVbaControl::setAutoSize( bAutoSize );
282 sal_Bool SAL_CALL ScVbaComboBox::getLocked() throw (uno::RuntimeException)
284 return ScVbaControl::getLocked();
287 void SAL_CALL ScVbaComboBox::setLocked( sal_Bool bLocked ) throw (uno::RuntimeException)
289 ScVbaControl::setLocked( bLocked );
292 OUString SAL_CALL ScVbaComboBox::getLinkedCell() throw (uno::RuntimeException)
294 return ScVbaControl::getControlSource();
297 void SAL_CALL ScVbaComboBox::setLinkedCell( const OUString& _linkedcell ) throw (uno::RuntimeException)
299 ScVbaControl::setControlSource( _linkedcell );
302 uno::Sequence< OUString >
303 ScVbaComboBox::getServiceNames()
305 static uno::Sequence< OUString > aServiceNames;
306 if ( aServiceNames.getLength() == 0 )
308 aServiceNames.realloc( 1 );
309 aServiceNames[ 0 ] = "ooo.vba.msforms.ComboBox";
311 return aServiceNames;
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */