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