tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / vbahelper / source / msforms / vbacombobox.cxx
blob6da823948cfb015133243fbbcaa18bf6af53e5ab
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 <comphelper/sequence.hxx>
22 #include "vbanewfont.hxx"
23 #include <ooo/vba/msforms/fmStyle.hpp>
24 #include <ooo/vba/msforms/fmDropButtonStyle.hpp>
25 #include <ooo/vba/msforms/fmDragBehavior.hpp>
26 #include <ooo/vba/msforms/fmEnterFieldBehavior.hpp>
27 #include <ooo/vba/msforms/fmListStyle.hpp>
28 #include <ooo/vba/msforms/fmTextAlign.hpp>
29 #include <sal/log.hxx>
31 using namespace com::sun::star;
32 using namespace ooo::vba;
35 //SelectedItems list of integer indexes
36 //StringItemList list of items
38 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 )
39 : ComboBoxImpl_BASE( xParent, xContext, xControl, xModel, std::move(pGeomHelper) )
40 , maListHelper( m_xProps )
42 try
44 // grab the default value property name
45 m_xProps->getPropertyValue( u"DataFieldProperty"_ustr ) >>= sSourceName;
47 catch( uno::Exception& )
50 if( sSourceName.isEmpty() )
51 sSourceName = "Text";
54 // Attributes
57 // Value, [read] e.g. getValue returns the value of ooo Text property e.g. the value in
58 // the drop down
59 uno::Any SAL_CALL
60 ScVbaComboBox::getValue()
62 return m_xProps->getPropertyValue( sSourceName );
65 void SAL_CALL
66 ScVbaComboBox::setListIndex( const uno::Any& _value )
68 sal_Int16 nIndex = 0;
69 if( !(_value >>= nIndex) )
70 return;
72 sal_Int32 nOldIndex = -1;
73 getListIndex() >>= nOldIndex;
74 uno::Sequence< OUString > sItems;
75 m_xProps->getPropertyValue( u"StringItemList"_ustr ) >>= sItems;
76 if( ( nIndex >= 0 ) && ( sItems.getLength() > nIndex ) )
78 const OUString& sText = sItems[ nIndex ];
79 m_xProps->setPropertyValue( u"Text"_ustr, uno::Any( sText ) );
81 // fire the _Change event
82 if( nOldIndex != nIndex )
83 fireClickEvent();
87 uno::Any SAL_CALL
88 ScVbaComboBox::getListIndex()
90 uno::Sequence< OUString > sItems;
91 m_xProps->getPropertyValue( u"StringItemList"_ustr ) >>= sItems;
92 // should really return the item that has focus regardless of
93 // it been selected
94 if ( sItems.hasElements() )
96 OUString sText = getText();
97 if (!sText.isEmpty())
99 sal_Int32 index = comphelper::findValue(sItems, sText);
100 if (index != -1)
102 SAL_INFO("vbahelper", "getListIndex returning " << index );
103 return uno::Any( index );
107 SAL_INFO("vbahelper", "getListIndex returning -1" );
108 return uno::Any( sal_Int32( -1 ) );
111 // Value, [write]e.g. setValue sets the value in the drop down, and if the value is one
112 // of the values in the list then the selection is also set
113 void SAL_CALL
114 ScVbaComboBox::setValue( const uno::Any& _value )
116 // booleans are converted to uppercase strings
117 OUString oldValue = extractStringFromAny( getValue(), OUString(), true );
118 m_xProps->setPropertyValue( sSourceName, uno::Any( extractStringFromAny( _value, OUString(), true ) ) );
119 OUString newValue = extractStringFromAny( getValue(), OUString(), true );
120 if ( oldValue != newValue )
122 sal_Int32 index = 0;
123 uno::Any aIndex = getListIndex();
124 aIndex >>= index;
125 if ( index < 0 )
126 fireChangeEvent();
127 else
128 fireClickEvent();
132 // see Value
134 OUString SAL_CALL
135 ScVbaComboBox::getText()
137 OUString result;
138 getValue() >>= result;
139 return result;
142 void SAL_CALL
143 ScVbaComboBox::setText( const OUString& _text )
145 setValue( uno::Any( _text ) ); // seems the same
148 // Methods
149 void SAL_CALL
150 ScVbaComboBox::AddItem( const uno::Any& pvargItem, const uno::Any& pvargIndex )
152 maListHelper.AddItem( pvargItem, pvargIndex );
155 void SAL_CALL
156 ScVbaComboBox::removeItem( const uno::Any& index )
158 maListHelper.removeItem( index );
161 void SAL_CALL
162 ScVbaComboBox::Clear( )
164 maListHelper.Clear();
167 void SAL_CALL
168 ScVbaComboBox::setRowSource( const OUString& _rowsource )
170 ScVbaControl::setRowSource( _rowsource );
171 maListHelper.setRowSource( _rowsource );
174 sal_Int32 SAL_CALL
175 ScVbaComboBox::getListCount()
177 return maListHelper.getListCount();
180 uno::Any SAL_CALL
181 ScVbaComboBox::List( const ::uno::Any& pvargIndex, const uno::Any& pvarColumn )
183 return maListHelper.List( pvargIndex, pvarColumn );
186 sal_Int32 SAL_CALL ScVbaComboBox::getStyle()
188 return msforms::fmStyle::fmStyleDropDownCombo;
191 void SAL_CALL ScVbaComboBox::setStyle( sal_Int32 /*nStyle*/ )
195 sal_Int32 SAL_CALL ScVbaComboBox::getDropButtonStyle()
197 return msforms::fmDropButtonStyle::fmDropButtonStyleArrow;
200 void SAL_CALL ScVbaComboBox::setDropButtonStyle( sal_Int32 /*nDropButtonStyle*/ )
204 sal_Int32 SAL_CALL ScVbaComboBox::getDragBehavior()
206 return msforms::fmDragBehavior::fmDragBehaviorDisabled;
209 void SAL_CALL ScVbaComboBox::setDragBehavior( sal_Int32 /*nDragBehavior*/ )
213 sal_Int32 SAL_CALL ScVbaComboBox::getEnterFieldBehavior()
215 return msforms::fmEnterFieldBehavior::fmEnterFieldBehaviorSelectAll;
218 void SAL_CALL ScVbaComboBox::setEnterFieldBehavior( sal_Int32 /*nEnterFieldBehavior*/ )
222 sal_Int32 SAL_CALL ScVbaComboBox::getListStyle()
224 return msforms::fmListStyle::fmListStylePlain;
227 void SAL_CALL ScVbaComboBox::setListStyle( sal_Int32 /*nListStyle*/ )
231 sal_Int32 SAL_CALL ScVbaComboBox::getTextAlign()
233 return msforms::fmTextAlign::fmTextAlignLeft;
236 void SAL_CALL ScVbaComboBox::setTextAlign( sal_Int32 /*nTextAlign*/ )
240 sal_Int32 SAL_CALL ScVbaComboBox::getTextLength()
242 return getText().getLength();
245 uno::Reference< msforms::XNewFont > SAL_CALL ScVbaComboBox::getFont()
247 return new VbaNewFont( m_xProps );
250 OUString
251 ScVbaComboBox::getServiceImplName()
253 return u"ScVbaComboBox"_ustr;
256 sal_Int32 SAL_CALL ScVbaComboBox::getBackColor()
258 return ScVbaControl::getBackColor();
261 void SAL_CALL ScVbaComboBox::setBackColor( sal_Int32 nBackColor )
263 ScVbaControl::setBackColor( nBackColor );
266 sal_Bool SAL_CALL ScVbaComboBox::getAutoSize()
268 return ScVbaControl::getAutoSize();
271 void SAL_CALL ScVbaComboBox::setAutoSize( sal_Bool bAutoSize )
273 ScVbaControl::setAutoSize( bAutoSize );
276 sal_Bool SAL_CALL ScVbaComboBox::getLocked()
278 return ScVbaControl::getLocked();
281 void SAL_CALL ScVbaComboBox::setLocked( sal_Bool bLocked )
283 ScVbaControl::setLocked( bLocked );
286 OUString SAL_CALL ScVbaComboBox::getLinkedCell()
288 return ScVbaControl::getControlSource();
291 void SAL_CALL ScVbaComboBox::setLinkedCell( const OUString& _linkedcell )
293 ScVbaControl::setControlSource( _linkedcell );
296 uno::Sequence< OUString >
297 ScVbaComboBox::getServiceNames()
299 static uno::Sequence< OUString > const aServiceNames
301 u"ooo.vba.msforms.ComboBox"_ustr
303 return aServiceNames;
306 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */