1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <filter/msfilter/msvbahelper.hxx>
22 #include <basic/sbstar.hxx>
23 #include <basic/sbmod.hxx>
24 #include "vbanewfont.hxx"
25 #include <ooo/vba/msforms/fmStyle.hpp>
26 #include <ooo/vba/msforms/fmDropButtonStyle.hpp>
27 #include <ooo/vba/msforms/fmDragBehavior.hpp>
28 #include <ooo/vba/msforms/fmEnterFieldBehavior.hpp>
29 #include <ooo/vba/msforms/fmListStyle.hpp>
30 #include <ooo/vba/msforms/fmTextAlign.hpp>
32 using namespace com::sun::star
;
33 using namespace ooo::vba
;
36 //SelectedItems list of integer indexes
37 //StringItemList list of items
39 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
)
41 mpListHelper
.reset( new ListControlHelper( m_xProps
) );
44 // grab the default value property name
45 m_xProps
->getPropertyValue( "DataFieldProperty" ) >>= sSourceName
;
47 catch( uno::Exception
& )
50 if( sSourceName
.isEmpty() )
57 // Value, [read] e.g. getValue returns the value of ooo Text propery e.g. the value in
60 ScVbaComboBox::getValue() throw (uno::RuntimeException
, std::exception
)
62 return m_xProps
->getPropertyValue( sSourceName
);
66 ScVbaComboBox::setListIndex( const uno::Any
& _value
) throw (uno::RuntimeException
, std::exception
)
69 if( _value
>>= nIndex
)
71 sal_Int32 nOldIndex
= -1;
72 getListIndex() >>= nOldIndex
;
73 uno::Sequence
< OUString
> sItems
;
74 m_xProps
->getPropertyValue( "StringItemList" ) >>= sItems
;
75 if( ( nIndex
>= 0 ) && ( sItems
.getLength() > nIndex
) )
77 OUString sText
= sItems
[ nIndex
];
78 m_xProps
->setPropertyValue( "Text", uno::makeAny( sText
) );
80 // fire the _Change event
81 if( nOldIndex
!= nIndex
)
88 ScVbaComboBox::getListIndex() throw (uno::RuntimeException
, std::exception
)
90 uno::Sequence
< OUString
> sItems
;
91 m_xProps
->getPropertyValue( "StringItemList" ) >>= sItems
;
92 // should really return the item that has focus regardless of
94 if ( sItems
.getLength() > 0 )
96 OUString sText
= getText();
97 sal_Int32 nLen
= sItems
.getLength();
98 for ( sal_Int32 index
= 0; !sText
.isEmpty() && index
< nLen
; ++index
)
100 if ( sItems
[ index
].equals( sText
) )
102 SAL_INFO("vbahelper", "getListIndex returning " << index
);
103 return uno::makeAny( index
);
108 SAL_INFO("vbahelper", "getListIndex returning -1" );
109 return uno::makeAny( sal_Int32( -1 ) );
112 // Value, [write]e.g. setValue sets the value in the drop down, and if the value is one
113 // of the values in the list then the selection is also set
115 ScVbaComboBox::setValue( const uno::Any
& _value
) throw (uno::RuntimeException
, std::exception
)
117 // booleans are converted to uppercase strings
118 OUString oldValue
= extractStringFromAny( getValue(), OUString(), true );
119 m_xProps
->setPropertyValue( sSourceName
, uno::Any( extractStringFromAny( _value
, OUString(), true ) ) );
120 OUString newValue
= extractStringFromAny( getValue(), OUString(), true );
121 if ( oldValue
!= newValue
)
124 uno::Any aIndex
= getListIndex();
136 ScVbaComboBox::getText() throw (uno::RuntimeException
, std::exception
)
139 getValue() >>= result
;
144 ScVbaComboBox::setText( const OUString
& _text
) throw (uno::RuntimeException
, std::exception
)
146 setValue( uno::makeAny( _text
) ); // seems the same
151 ScVbaComboBox::AddItem( const uno::Any
& pvargItem
, const uno::Any
& pvargIndex
) throw (uno::RuntimeException
, std::exception
)
153 mpListHelper
->AddItem( pvargItem
, pvargIndex
);
157 ScVbaComboBox::removeItem( const uno::Any
& index
) throw (uno::RuntimeException
, std::exception
)
159 mpListHelper
->removeItem( index
);
163 ScVbaComboBox::Clear( ) throw (uno::RuntimeException
, std::exception
)
165 mpListHelper
->Clear();
169 ScVbaComboBox::setRowSource( const OUString
& _rowsource
) throw (css::uno::RuntimeException
, std::exception
)
171 ScVbaControl::setRowSource( _rowsource
);
172 mpListHelper
->setRowSource( _rowsource
);
176 ScVbaComboBox::getListCount() throw (uno::RuntimeException
, std::exception
)
178 return mpListHelper
->getListCount();
182 ScVbaComboBox::List( const ::uno::Any
& pvargIndex
, const uno::Any
& pvarColumn
) throw (uno::RuntimeException
, std::exception
)
184 return mpListHelper
->List( pvargIndex
, pvarColumn
);
187 sal_Int32 SAL_CALL
ScVbaComboBox::getStyle() throw (uno::RuntimeException
, std::exception
)
189 return msforms::fmStyle::fmStyleDropDownCombo
;
192 void SAL_CALL
ScVbaComboBox::setStyle( sal_Int32
/*nStyle*/ ) throw (uno::RuntimeException
, std::exception
)
196 sal_Int32 SAL_CALL
ScVbaComboBox::getDropButtonStyle() throw (uno::RuntimeException
, std::exception
)
198 return msforms::fmDropButtonStyle::fmDropButtonStyleArrow
;
201 void SAL_CALL
ScVbaComboBox::setDropButtonStyle( sal_Int32
/*nDropButtonStyle*/ ) throw (uno::RuntimeException
, std::exception
)
205 sal_Int32 SAL_CALL
ScVbaComboBox::getDragBehavior() throw (uno::RuntimeException
, std::exception
)
207 return msforms::fmDragBehavior::fmDragBehaviorDisabled
;
210 void SAL_CALL
ScVbaComboBox::setDragBehavior( sal_Int32
/*nDragBehavior*/ ) throw (uno::RuntimeException
, std::exception
)
214 sal_Int32 SAL_CALL
ScVbaComboBox::getEnterFieldBehavior() throw (uno::RuntimeException
, std::exception
)
216 return msforms::fmEnterFieldBehavior::fmEnterFieldBehaviorSelectAll
;
219 void SAL_CALL
ScVbaComboBox::setEnterFieldBehavior( sal_Int32
/*nEnterFieldBehavior*/ ) throw (uno::RuntimeException
, std::exception
)
223 sal_Int32 SAL_CALL
ScVbaComboBox::getListStyle() throw (uno::RuntimeException
, std::exception
)
225 return msforms::fmListStyle::fmListStylePlain
;
228 void SAL_CALL
ScVbaComboBox::setListStyle( sal_Int32
/*nListStyle*/ ) throw (uno::RuntimeException
, std::exception
)
232 sal_Int32 SAL_CALL
ScVbaComboBox::getTextAlign() throw (uno::RuntimeException
, std::exception
)
234 return msforms::fmTextAlign::fmTextAlignLeft
;
237 void SAL_CALL
ScVbaComboBox::setTextAlign( sal_Int32
/*nTextAlign*/ ) throw (uno::RuntimeException
, std::exception
)
241 sal_Int32 SAL_CALL
ScVbaComboBox::getTextLength() throw (uno::RuntimeException
, std::exception
)
243 return getText().getLength();
246 uno::Reference
< msforms::XNewFont
> SAL_CALL
ScVbaComboBox::getFont() throw (uno::RuntimeException
, std::exception
)
248 return new VbaNewFont( m_xProps
);
252 ScVbaComboBox::getServiceImplName()
254 return OUString("ScVbaComboBox");
257 sal_Int32 SAL_CALL
ScVbaComboBox::getBackColor() throw (uno::RuntimeException
, std::exception
)
259 return ScVbaControl::getBackColor();
262 void SAL_CALL
ScVbaComboBox::setBackColor( sal_Int32 nBackColor
) throw (uno::RuntimeException
, std::exception
)
264 ScVbaControl::setBackColor( nBackColor
);
267 sal_Bool SAL_CALL
ScVbaComboBox::getAutoSize() throw (uno::RuntimeException
, std::exception
)
269 return ScVbaControl::getAutoSize();
272 void SAL_CALL
ScVbaComboBox::setAutoSize( sal_Bool bAutoSize
) throw (uno::RuntimeException
, std::exception
)
274 ScVbaControl::setAutoSize( bAutoSize
);
277 sal_Bool SAL_CALL
ScVbaComboBox::getLocked() throw (uno::RuntimeException
, std::exception
)
279 return ScVbaControl::getLocked();
282 void SAL_CALL
ScVbaComboBox::setLocked( sal_Bool bLocked
) throw (uno::RuntimeException
, std::exception
)
284 ScVbaControl::setLocked( bLocked
);
287 OUString SAL_CALL
ScVbaComboBox::getLinkedCell() throw (uno::RuntimeException
, std::exception
)
289 return ScVbaControl::getControlSource();
292 void SAL_CALL
ScVbaComboBox::setLinkedCell( const OUString
& _linkedcell
) throw (uno::RuntimeException
, std::exception
)
294 ScVbaControl::setControlSource( _linkedcell
);
297 uno::Sequence
< OUString
>
298 ScVbaComboBox::getServiceNames()
300 static uno::Sequence
< OUString
> aServiceNames
;
301 if ( aServiceNames
.getLength() == 0 )
303 aServiceNames
.realloc( 1 );
304 aServiceNames
[ 0 ] = "ooo.vba.msforms.ComboBox";
306 return aServiceNames
;
309 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */