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>
31 #include <sal/log.hxx>
33 using namespace com::sun::star
;
34 using namespace ooo::vba
;
37 //SelectedItems list of integer indexes
38 //StringItemList list of items
40 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
, std::unique_ptr
<ov::AbstractGeometryAttributes
> pGeomHelper
)
41 : ComboBoxImpl_BASE( xParent
, xContext
, xControl
, xModel
, std::move(pGeomHelper
) )
43 mpListHelper
.reset( new ListControlHelper( m_xProps
) );
46 // grab the default value property name
47 m_xProps
->getPropertyValue( "DataFieldProperty" ) >>= sSourceName
;
49 catch( uno::Exception
& )
52 if( sSourceName
.isEmpty() )
59 // Value, [read] e.g. getValue returns the value of ooo Text property e.g. the value in
62 ScVbaComboBox::getValue()
64 return m_xProps
->getPropertyValue( sSourceName
);
68 ScVbaComboBox::setListIndex( const uno::Any
& _value
)
71 if( _value
>>= nIndex
)
73 sal_Int32 nOldIndex
= -1;
74 getListIndex() >>= nOldIndex
;
75 uno::Sequence
< OUString
> sItems
;
76 m_xProps
->getPropertyValue( "StringItemList" ) >>= sItems
;
77 if( ( nIndex
>= 0 ) && ( sItems
.getLength() > nIndex
) )
79 OUString sText
= sItems
[ nIndex
];
80 m_xProps
->setPropertyValue( "Text", uno::makeAny( sText
) );
82 // fire the _Change event
83 if( nOldIndex
!= nIndex
)
90 ScVbaComboBox::getListIndex()
92 uno::Sequence
< OUString
> sItems
;
93 m_xProps
->getPropertyValue( "StringItemList" ) >>= sItems
;
94 // should really return the item that has focus regardless of
96 if ( sItems
.hasElements() )
98 OUString sText
= getText();
99 sal_Int32 nLen
= sItems
.getLength();
100 for ( sal_Int32 index
= 0; !sText
.isEmpty() && index
< nLen
; ++index
)
102 if ( sItems
[ index
] == sText
)
104 SAL_INFO("vbahelper", "getListIndex returning " << index
);
105 return uno::makeAny( index
);
110 SAL_INFO("vbahelper", "getListIndex returning -1" );
111 return uno::makeAny( sal_Int32( -1 ) );
114 // Value, [write]e.g. setValue sets the value in the drop down, and if the value is one
115 // of the values in the list then the selection is also set
117 ScVbaComboBox::setValue( const uno::Any
& _value
)
119 // booleans are converted to uppercase strings
120 OUString oldValue
= extractStringFromAny( getValue(), OUString(), true );
121 m_xProps
->setPropertyValue( sSourceName
, uno::Any( extractStringFromAny( _value
, OUString(), true ) ) );
122 OUString newValue
= extractStringFromAny( getValue(), OUString(), true );
123 if ( oldValue
!= newValue
)
126 uno::Any aIndex
= getListIndex();
138 ScVbaComboBox::getText()
141 getValue() >>= result
;
146 ScVbaComboBox::setText( const OUString
& _text
)
148 setValue( uno::makeAny( _text
) ); // seems the same
153 ScVbaComboBox::AddItem( const uno::Any
& pvargItem
, const uno::Any
& pvargIndex
)
155 mpListHelper
->AddItem( pvargItem
, pvargIndex
);
159 ScVbaComboBox::removeItem( const uno::Any
& index
)
161 mpListHelper
->removeItem( index
);
165 ScVbaComboBox::Clear( )
167 mpListHelper
->Clear();
171 ScVbaComboBox::setRowSource( const OUString
& _rowsource
)
173 ScVbaControl::setRowSource( _rowsource
);
174 mpListHelper
->setRowSource( _rowsource
);
178 ScVbaComboBox::getListCount()
180 return mpListHelper
->getListCount();
184 ScVbaComboBox::List( const ::uno::Any
& pvargIndex
, const uno::Any
& pvarColumn
)
186 return mpListHelper
->List( pvargIndex
, pvarColumn
);
189 sal_Int32 SAL_CALL
ScVbaComboBox::getStyle()
191 return msforms::fmStyle::fmStyleDropDownCombo
;
194 void SAL_CALL
ScVbaComboBox::setStyle( sal_Int32
/*nStyle*/ )
198 sal_Int32 SAL_CALL
ScVbaComboBox::getDropButtonStyle()
200 return msforms::fmDropButtonStyle::fmDropButtonStyleArrow
;
203 void SAL_CALL
ScVbaComboBox::setDropButtonStyle( sal_Int32
/*nDropButtonStyle*/ )
207 sal_Int32 SAL_CALL
ScVbaComboBox::getDragBehavior()
209 return msforms::fmDragBehavior::fmDragBehaviorDisabled
;
212 void SAL_CALL
ScVbaComboBox::setDragBehavior( sal_Int32
/*nDragBehavior*/ )
216 sal_Int32 SAL_CALL
ScVbaComboBox::getEnterFieldBehavior()
218 return msforms::fmEnterFieldBehavior::fmEnterFieldBehaviorSelectAll
;
221 void SAL_CALL
ScVbaComboBox::setEnterFieldBehavior( sal_Int32
/*nEnterFieldBehavior*/ )
225 sal_Int32 SAL_CALL
ScVbaComboBox::getListStyle()
227 return msforms::fmListStyle::fmListStylePlain
;
230 void SAL_CALL
ScVbaComboBox::setListStyle( sal_Int32
/*nListStyle*/ )
234 sal_Int32 SAL_CALL
ScVbaComboBox::getTextAlign()
236 return msforms::fmTextAlign::fmTextAlignLeft
;
239 void SAL_CALL
ScVbaComboBox::setTextAlign( sal_Int32
/*nTextAlign*/ )
243 sal_Int32 SAL_CALL
ScVbaComboBox::getTextLength()
245 return getText().getLength();
248 uno::Reference
< msforms::XNewFont
> SAL_CALL
ScVbaComboBox::getFont()
250 return new VbaNewFont( m_xProps
);
254 ScVbaComboBox::getServiceImplName()
256 return OUString("ScVbaComboBox");
259 sal_Int32 SAL_CALL
ScVbaComboBox::getBackColor()
261 return ScVbaControl::getBackColor();
264 void SAL_CALL
ScVbaComboBox::setBackColor( sal_Int32 nBackColor
)
266 ScVbaControl::setBackColor( nBackColor
);
269 sal_Bool SAL_CALL
ScVbaComboBox::getAutoSize()
271 return ScVbaControl::getAutoSize();
274 void SAL_CALL
ScVbaComboBox::setAutoSize( sal_Bool bAutoSize
)
276 ScVbaControl::setAutoSize( bAutoSize
);
279 sal_Bool SAL_CALL
ScVbaComboBox::getLocked()
281 return ScVbaControl::getLocked();
284 void SAL_CALL
ScVbaComboBox::setLocked( sal_Bool bLocked
)
286 ScVbaControl::setLocked( bLocked
);
289 OUString SAL_CALL
ScVbaComboBox::getLinkedCell()
291 return ScVbaControl::getControlSource();
294 void SAL_CALL
ScVbaComboBox::setLinkedCell( const OUString
& _linkedcell
)
296 ScVbaControl::setControlSource( _linkedcell
);
299 uno::Sequence
< OUString
>
300 ScVbaComboBox::getServiceNames()
302 static uno::Sequence
< OUString
> const aServiceNames
304 "ooo.vba.msforms.ComboBox"
306 return aServiceNames
;
309 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */