LibreOffice Module vbahelper (master) 1
vbacombobox.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "vbacombobox.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>
30
31using namespace com::sun::star;
32using namespace ooo::vba;
33
34
35//SelectedItems list of integer indexes
36//StringItemList list of items
37
38ScVbaComboBox::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 )
41{
42 try
43 {
44 // grab the default value property name
45 m_xProps->getPropertyValue( "DataFieldProperty" ) >>= sSourceName;
46 }
47 catch( uno::Exception& )
48 {
49 }
50 if( sSourceName.isEmpty() )
51 sSourceName = "Text";
52}
53
54// Attributes
55
56
57// Value, [read] e.g. getValue returns the value of ooo Text property e.g. the value in
58// the drop down
59uno::Any SAL_CALL
61{
62 return m_xProps->getPropertyValue( sSourceName );
63}
64
65void SAL_CALL
67{
68 sal_Int16 nIndex = 0;
69 if( !(_value >>= nIndex) )
70 return;
71
72 sal_Int32 nOldIndex = -1;
73 getListIndex() >>= nOldIndex;
74 uno::Sequence< OUString > sItems;
75 m_xProps->getPropertyValue( "StringItemList" ) >>= sItems;
76 if( ( nIndex >= 0 ) && ( sItems.getLength() > nIndex ) )
77 {
78 OUString sText = sItems[ nIndex ];
79 m_xProps->setPropertyValue( "Text", uno::Any( sText ) );
80
81 // fire the _Change event
82 if( nOldIndex != nIndex )
83 fireClickEvent();
84 }
85}
86
87uno::Any SAL_CALL
89{
90 uno::Sequence< OUString > sItems;
91 m_xProps->getPropertyValue( "StringItemList" ) >>= sItems;
92 // should really return the item that has focus regardless of
93 // it been selected
94 if ( sItems.hasElements() )
95 {
96 OUString sText = getText();
97 if (!sText.isEmpty())
98 {
99 sal_Int32 index = comphelper::findValue(sItems, sText);
100 if (index != -1)
101 {
102 SAL_INFO("vbahelper", "getListIndex returning " << index );
103 return uno::Any( index );
104 }
105 }
106 }
107 SAL_INFO("vbahelper", "getListIndex returning -1" );
108 return uno::Any( sal_Int32( -1 ) );
109}
110
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
113void SAL_CALL
115{
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 )
121 {
122 sal_Int32 index = 0;
124 aIndex >>= index;
125 if ( index < 0 )
126 fireChangeEvent();
127 else
128 fireClickEvent();
129 }
130}
131
132// see Value
133
134OUString SAL_CALL
136{
137 OUString result;
138 getValue() >>= result;
139 return result;
140}
141
142void SAL_CALL
143ScVbaComboBox::setText( const OUString& _text )
144{
145 setValue( uno::Any( _text ) ); // seems the same
146}
147
148// Methods
149void SAL_CALL
150ScVbaComboBox::AddItem( const uno::Any& pvargItem, const uno::Any& pvargIndex )
151{
152 maListHelper.AddItem( pvargItem, pvargIndex );
153}
154
155void SAL_CALL
157{
159}
160
161void SAL_CALL
163{
165}
166
167void SAL_CALL
168ScVbaComboBox::setRowSource( const OUString& _rowsource )
169{
170 ScVbaControl::setRowSource( _rowsource );
171 maListHelper.setRowSource( _rowsource );
172}
173
174sal_Int32 SAL_CALL
176{
177 return maListHelper.getListCount();
178}
179
180uno::Any SAL_CALL
181ScVbaComboBox::List( const ::uno::Any& pvargIndex, const uno::Any& pvarColumn )
182{
183 return maListHelper.List( pvargIndex, pvarColumn );
184}
185
186sal_Int32 SAL_CALL ScVbaComboBox::getStyle()
187{
188 return msforms::fmStyle::fmStyleDropDownCombo;
189}
190
191void SAL_CALL ScVbaComboBox::setStyle( sal_Int32 /*nStyle*/ )
192{
193}
194
196{
197 return msforms::fmDropButtonStyle::fmDropButtonStyleArrow;
198}
199
200void SAL_CALL ScVbaComboBox::setDropButtonStyle( sal_Int32 /*nDropButtonStyle*/ )
201{
202}
203
205{
206 return msforms::fmDragBehavior::fmDragBehaviorDisabled;
207}
208
209void SAL_CALL ScVbaComboBox::setDragBehavior( sal_Int32 /*nDragBehavior*/ )
210{
211}
212
214{
215 return msforms::fmEnterFieldBehavior::fmEnterFieldBehaviorSelectAll;
216}
217
218void SAL_CALL ScVbaComboBox::setEnterFieldBehavior( sal_Int32 /*nEnterFieldBehavior*/ )
219{
220}
221
222sal_Int32 SAL_CALL ScVbaComboBox::getListStyle()
223{
224 return msforms::fmListStyle::fmListStylePlain;
225}
226
227void SAL_CALL ScVbaComboBox::setListStyle( sal_Int32 /*nListStyle*/ )
228{
229}
230
231sal_Int32 SAL_CALL ScVbaComboBox::getTextAlign()
232{
233 return msforms::fmTextAlign::fmTextAlignLeft;
234}
235
236void SAL_CALL ScVbaComboBox::setTextAlign( sal_Int32 /*nTextAlign*/ )
237{
238}
239
241{
242 return getText().getLength();
243}
244
245uno::Reference< msforms::XNewFont > SAL_CALL ScVbaComboBox::getFont()
246{
247 return new VbaNewFont( m_xProps );
248}
249
250OUString
252{
253 return "ScVbaComboBox";
254}
255
256sal_Int32 SAL_CALL ScVbaComboBox::getBackColor()
257{
259}
260
261void SAL_CALL ScVbaComboBox::setBackColor( sal_Int32 nBackColor )
262{
263 ScVbaControl::setBackColor( nBackColor );
264}
265
267{
269}
270
271void SAL_CALL ScVbaComboBox::setAutoSize( sal_Bool bAutoSize )
272{
273 ScVbaControl::setAutoSize( bAutoSize );
274}
275
277{
279}
280
281void SAL_CALL ScVbaComboBox::setLocked( sal_Bool bLocked )
282{
283 ScVbaControl::setLocked( bLocked );
284}
285
287{
289}
290
291void SAL_CALL ScVbaComboBox::setLinkedCell( const OUString& _linkedcell )
292{
293 ScVbaControl::setControlSource( _linkedcell );
294}
295
296uno::Sequence< OUString >
298{
299 static uno::Sequence< OUString > const aServiceNames
300 {
301 "ooo.vba.msforms.ComboBox"
302 };
303 return aServiceNames;
304}
305
306/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XPropertySet > m_xProps
void removeItem(const css::uno::Any &index)
void setRowSource(std::u16string_view _rowsource)
css::uno::Any List(const css::uno::Any &pvargIndex, const css::uno::Any &pvarColumn)
void AddItem(const css::uno::Any &pvargItem, const css::uno::Any &pvargIndex)
virtual sal_Bool SAL_CALL getLocked() override
virtual sal_Bool SAL_CALL getAutoSize() override
ListControlHelper maListHelper
Definition: vbacombobox.hxx:37
virtual void SAL_CALL removeItem(const css::uno::Any &index) override
virtual void SAL_CALL setLinkedCell(const OUString &_linkedcell) override
virtual css::uno::Any SAL_CALL List(const css::uno::Any &pvargIndex, const css::uno::Any &pvarColumn) override
virtual css::uno::Any SAL_CALL getValue() override
Definition: vbacombobox.cxx:60
virtual sal_Int32 SAL_CALL getDragBehavior() override
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual void SAL_CALL setTextAlign(sal_Int32 nTextAlign) override
virtual void SAL_CALL setDragBehavior(sal_Int32 nDragBehavior) override
virtual sal_Int32 SAL_CALL getBackColor() override
virtual sal_Int32 SAL_CALL getTextAlign() override
virtual sal_Int32 SAL_CALL getListStyle() override
virtual OUString SAL_CALL getLinkedCell() override
virtual void SAL_CALL setListStyle(sal_Int32 nListStyle) override
virtual void SAL_CALL setLocked(sal_Bool bAutoSize) override
virtual void SAL_CALL setValue(const css::uno::Any &_value) override
virtual OUString getServiceImplName() override
virtual void SAL_CALL setDropButtonStyle(sal_Int32 nDropButtonStyle) override
virtual void SAL_CALL setEnterFieldBehavior(sal_Int32 nEnterFieldBehavior) override
virtual sal_Int32 SAL_CALL getStyle() override
virtual void SAL_CALL setBackColor(sal_Int32 nBackColor) override
virtual ::sal_Int32 SAL_CALL getListCount() override
virtual sal_Int32 SAL_CALL getTextLength() override
virtual void SAL_CALL setStyle(sal_Int32 nStyle) override
ScVbaComboBox(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::uno::XInterface > &xControl, const css::uno::Reference< css::frame::XModel > &xModel, std::unique_ptr< ov::AbstractGeometryAttributes > pGeomHelper)
Definition: vbacombobox.cxx:38
virtual sal_Int32 SAL_CALL getEnterFieldBehavior() override
virtual void SAL_CALL AddItem(const css::uno::Any &pvargItem, const css::uno::Any &pvargIndex) override
virtual css::uno::Any SAL_CALL getListIndex() override
Definition: vbacombobox.cxx:88
virtual void SAL_CALL setListIndex(const css::uno::Any &_value) override
Definition: vbacombobox.cxx:66
virtual void SAL_CALL setRowSource(const OUString &_rowsource) override
virtual void SAL_CALL setAutoSize(sal_Bool bAutoSize) override
virtual void SAL_CALL setText(const OUString &_text) override
OUString sSourceName
Definition: vbacombobox.hxx:38
virtual css::uno::Reference< ov::msforms::XNewFont > SAL_CALL getFont() override
virtual void SAL_CALL Clear() override
virtual OUString SAL_CALL getText() override
virtual sal_Int32 SAL_CALL getDropButtonStyle() override
bool getLocked()
Definition: vbacontrol.cxx:745
sal_Int32 getBackColor()
Definition: vbacontrol.cxx:708
bool getAutoSize() const
Definition: vbacontrol.cxx:726
void setAutoSize(bool bAutoSize)
Definition: vbacontrol.cxx:737
virtual void SAL_CALL setRowSource(const OUString &_rowsource) override
Definition: vbacontrol.cxx:388
void setBackColor(sal_Int32 nBackColor)
Definition: vbacontrol.cxx:715
void setLocked(bool bAutoSize)
Definition: vbacontrol.cxx:752
virtual void SAL_CALL setControlSource(const OUString &_controlsource) override
Definition: vbacontrol.cxx:324
virtual OUString SAL_CALL getControlSource() override
Definition: vbacontrol.cxx:297
std::deque< AttacherIndex_Impl > aIndex
Sequence< OUString > aServiceNames
sal_Int32 nIndex
#define SAL_INFO(area, stream)
sal_Int32 findValue(const css::uno::Sequence< T1 > &_rList, const T2 &_rValue)
index
OUString extractStringFromAny(const uno::Any &rAny, bool bUppercaseBool)
Definition: vbahelper.cxx:465
Reference< XModel > xModel
unsigned char sal_Bool
Any result
cppu::ImplInheritanceHelper< ScVbaControl, ov::msforms::XComboBox, css::script::XDefaultProperty > ComboBoxImpl_BASE
Definition: vbacombobox.hxx:34