Branch data Line data Source code
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"
21 : : #include <vector>
22 : : #include <filter/msfilter/msvbahelper.hxx>
23 : : #include <basic/sbstar.hxx>
24 : : #include <basic/sbmod.hxx>
25 : : #include "vbanewfont.hxx"
26 : : #include <ooo/vba/msforms/fmStyle.hpp>
27 : : #include <ooo/vba/msforms/fmDropButtonStyle.hpp>
28 : : #include <ooo/vba/msforms/fmDragBehavior.hpp>
29 : : #include <ooo/vba/msforms/fmEnterFieldBehavior.hpp>
30 : : #include <ooo/vba/msforms/fmListStyle.hpp>
31 : : #include <ooo/vba/msforms/fmTextAlign.hpp>
32 : :
33 : : using namespace com::sun::star;
34 : : using namespace ooo::vba;
35 : :
36 : :
37 : : //SelectedItems list of integer indexes
38 : : //StringItemList list of items
39 : :
40 : 0 : const static rtl::OUString TEXT( RTL_CONSTASCII_USTRINGPARAM("Text") );
41 : 0 : const static rtl::OUString ITEMS( RTL_CONSTASCII_USTRINGPARAM("StringItemList") );
42 : 0 : const static rtl::OUString CONTROLSOURCEPROP( RTL_CONSTASCII_USTRINGPARAM("DataFieldProperty") );
43 : :
44 : 0 : 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 )
45 : : {
46 : 0 : mpListHelper.reset( new ListControlHelper( m_xProps ) );
47 : : try
48 : : {
49 : : // grab the default value property name
50 : 0 : m_xProps->getPropertyValue( CONTROLSOURCEPROP ) >>= sSourceName;
51 : : }
52 : 0 : catch( uno::Exception& )
53 : : {
54 : : }
55 : 0 : if( sSourceName.isEmpty() )
56 : 0 : sSourceName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ) );
57 : 0 : }
58 : :
59 : : // Attributes
60 : :
61 : :
62 : : // Value, [read] e.g. getValue returns the value of ooo Text propery e.g. the value in
63 : : // the drop down
64 : : uno::Any SAL_CALL
65 : 0 : ScVbaComboBox::getValue() throw (uno::RuntimeException)
66 : : {
67 : 0 : return m_xProps->getPropertyValue( sSourceName );
68 : : }
69 : :
70 : : void SAL_CALL
71 : 0 : ScVbaComboBox::setListIndex( const uno::Any& _value ) throw (uno::RuntimeException)
72 : : {
73 : 0 : sal_Int16 nIndex = 0;
74 : 0 : if( _value >>= nIndex )
75 : : {
76 : 0 : sal_Int32 nOldIndex = -1;
77 : 0 : getListIndex() >>= nOldIndex;
78 : 0 : uno::Sequence< rtl::OUString > sItems;
79 : 0 : m_xProps->getPropertyValue( ITEMS ) >>= sItems;
80 : 0 : if( ( nIndex >= 0 ) && ( sItems.getLength() > nIndex ) )
81 : : {
82 : 0 : rtl::OUString sText = sItems[ nIndex ];
83 : 0 : m_xProps->setPropertyValue( TEXT, uno::makeAny( sText ) );
84 : :
85 : : // fire the _Change event
86 : 0 : if( nOldIndex != nIndex )
87 : 0 : fireClickEvent();
88 : 0 : }
89 : : }
90 : 0 : }
91 : :
92 : : uno::Any SAL_CALL
93 : 0 : ScVbaComboBox::getListIndex() throw (uno::RuntimeException)
94 : : {
95 : 0 : uno::Sequence< rtl::OUString > sItems;
96 : 0 : m_xProps->getPropertyValue( ITEMS ) >>= sItems;
97 : : // should really return the item that has focus regardless of
98 : : // it been selected
99 : 0 : if ( sItems.getLength() > 0 )
100 : : {
101 : 0 : rtl::OUString sText = getText();
102 : 0 : sal_Int32 nLen = sItems.getLength();
103 : 0 : for ( sal_Int32 index = 0; !sText.isEmpty() && index < nLen; ++index )
104 : : {
105 : 0 : if ( sItems[ index ].equals( sText ) )
106 : : {
107 : : OSL_TRACE("getListIndex returning %d", index );
108 : 0 : return uno::makeAny( index );
109 : : }
110 : :
111 : 0 : }
112 : : }
113 : : OSL_TRACE("getListIndex returning %d", -1 );
114 : 0 : return uno::makeAny( sal_Int32( -1 ) );
115 : : }
116 : :
117 : : // Value, [write]e.g. setValue sets the value in the drop down, and if the value is one
118 : : // of the values in the list then the selection is also set
119 : : void SAL_CALL
120 : 0 : ScVbaComboBox::setValue( const uno::Any& _value ) throw (uno::RuntimeException)
121 : : {
122 : 0 : rtl::OUString sOldValue, sNewValue;
123 : : // booleans are converted to uppercase strings
124 : 0 : sOldValue = extractStringFromAny( getValue(), ::rtl::OUString(), true );
125 : : // booleans are converted to uppercase strings
126 : 0 : sNewValue = extractStringFromAny( _value, ::rtl::OUString(), true );
127 : :
128 : 0 : m_xProps->setPropertyValue( sSourceName, uno::Any( sNewValue ) );
129 : :
130 : 0 : if ( sNewValue != sOldValue )
131 : : {
132 : : // If the new value is in current list, we should fire click event, otherwise fire the change event.
133 : 0 : sal_Int32 nListIndex = -1;
134 : 0 : getListIndex() >>= nListIndex;
135 : 0 : sal_Bool bIsInList = ( nListIndex >= 0 );
136 : 0 : if ( bIsInList )
137 : : {
138 : 0 : fireClickEvent();
139 : : }
140 : : else
141 : : {
142 : 0 : fireChangeEvent();
143 : : }
144 : 0 : }
145 : 0 : }
146 : :
147 : : // see Value
148 : :
149 : : ::rtl::OUString SAL_CALL
150 : 0 : ScVbaComboBox::getText() throw (uno::RuntimeException)
151 : : {
152 : 0 : rtl::OUString result;
153 : 0 : getValue() >>= result;
154 : 0 : return result;
155 : : }
156 : :
157 : : void SAL_CALL
158 : 0 : ScVbaComboBox::setText( const ::rtl::OUString& _text ) throw (uno::RuntimeException)
159 : : {
160 : 0 : setValue( uno::makeAny( _text ) ); // seems the same
161 : 0 : }
162 : :
163 : : // Methods
164 : : void SAL_CALL
165 : 0 : ScVbaComboBox::AddItem( const uno::Any& pvargItem, const uno::Any& pvargIndex ) throw (uno::RuntimeException)
166 : : {
167 : 0 : mpListHelper->AddItem( pvargItem, pvargIndex );
168 : 0 : }
169 : :
170 : : void SAL_CALL
171 : 0 : ScVbaComboBox::removeItem( const uno::Any& index ) throw (uno::RuntimeException)
172 : : {
173 : 0 : mpListHelper->removeItem( index );
174 : 0 : }
175 : :
176 : : void SAL_CALL
177 : 0 : ScVbaComboBox::Clear( ) throw (uno::RuntimeException)
178 : : {
179 : 0 : mpListHelper->Clear();
180 : 0 : }
181 : :
182 : : void SAL_CALL
183 : 0 : ScVbaComboBox::setRowSource( const rtl::OUString& _rowsource ) throw (css::uno::RuntimeException)
184 : : {
185 : 0 : ScVbaControl::setRowSource( _rowsource );
186 : 0 : mpListHelper->setRowSource( _rowsource );
187 : 0 : }
188 : :
189 : : sal_Int32 SAL_CALL
190 : 0 : ScVbaComboBox::getListCount() throw (uno::RuntimeException)
191 : : {
192 : 0 : return mpListHelper->getListCount();
193 : : }
194 : :
195 : : uno::Any SAL_CALL
196 : 0 : ScVbaComboBox::List( const ::uno::Any& pvargIndex, const uno::Any& pvarColumn ) throw (uno::RuntimeException)
197 : : {
198 : 0 : return mpListHelper->List( pvargIndex, pvarColumn );
199 : : }
200 : :
201 : 0 : sal_Int32 SAL_CALL ScVbaComboBox::getStyle() throw (uno::RuntimeException)
202 : : {
203 : 0 : return msforms::fmStyle::fmStyleDropDownCombo;
204 : : }
205 : :
206 : 0 : void SAL_CALL ScVbaComboBox::setStyle( sal_Int32 /*nStyle*/ ) throw (uno::RuntimeException)
207 : : {
208 : 0 : }
209 : :
210 : 0 : sal_Int32 SAL_CALL ScVbaComboBox::getDropButtonStyle() throw (uno::RuntimeException)
211 : : {
212 : 0 : return msforms::fmDropButtonStyle::fmDropButtonStyleArrow;
213 : : }
214 : :
215 : 0 : void SAL_CALL ScVbaComboBox::setDropButtonStyle( sal_Int32 /*nDropButtonStyle*/ ) throw (uno::RuntimeException)
216 : : {
217 : 0 : }
218 : :
219 : 0 : sal_Int32 SAL_CALL ScVbaComboBox::getDragBehavior() throw (uno::RuntimeException)
220 : : {
221 : 0 : return msforms::fmDragBehavior::fmDragBehaviorDisabled;
222 : : }
223 : :
224 : 0 : void SAL_CALL ScVbaComboBox::setDragBehavior( sal_Int32 /*nDragBehavior*/ ) throw (uno::RuntimeException)
225 : : {
226 : 0 : }
227 : :
228 : 0 : sal_Int32 SAL_CALL ScVbaComboBox::getEnterFieldBehavior() throw (uno::RuntimeException)
229 : : {
230 : 0 : return msforms::fmEnterFieldBehavior::fmEnterFieldBehaviorSelectAll;
231 : : }
232 : :
233 : 0 : void SAL_CALL ScVbaComboBox::setEnterFieldBehavior( sal_Int32 /*nEnterFieldBehavior*/ ) throw (uno::RuntimeException)
234 : : {
235 : 0 : }
236 : :
237 : 0 : sal_Int32 SAL_CALL ScVbaComboBox::getListStyle() throw (uno::RuntimeException)
238 : : {
239 : 0 : return msforms::fmListStyle::fmListStylePlain;
240 : : }
241 : :
242 : 0 : void SAL_CALL ScVbaComboBox::setListStyle( sal_Int32 /*nListStyle*/ ) throw (uno::RuntimeException)
243 : : {
244 : 0 : }
245 : :
246 : 0 : sal_Int32 SAL_CALL ScVbaComboBox::getTextAlign() throw (uno::RuntimeException)
247 : : {
248 : 0 : return msforms::fmTextAlign::fmTextAlignLeft;
249 : : }
250 : :
251 : 0 : void SAL_CALL ScVbaComboBox::setTextAlign( sal_Int32 /*nTextAlign*/ ) throw (uno::RuntimeException)
252 : : {
253 : 0 : }
254 : :
255 : 0 : sal_Int32 SAL_CALL ScVbaComboBox::getTextLength() throw (uno::RuntimeException)
256 : : {
257 : 0 : return getText().getLength();
258 : : }
259 : :
260 : 0 : uno::Reference< msforms::XNewFont > SAL_CALL ScVbaComboBox::getFont() throw (uno::RuntimeException)
261 : : {
262 : 0 : return new VbaNewFont( this, mxContext, m_xProps );
263 : : }
264 : :
265 : : rtl::OUString
266 : 0 : ScVbaComboBox::getServiceImplName()
267 : : {
268 : 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScVbaComboBox"));
269 : : }
270 : :
271 : 0 : sal_Int32 SAL_CALL ScVbaComboBox::getBackColor() throw (uno::RuntimeException)
272 : : {
273 : 0 : return ScVbaControl::getBackColor();
274 : : }
275 : :
276 : 0 : void SAL_CALL ScVbaComboBox::setBackColor( sal_Int32 nBackColor ) throw (uno::RuntimeException)
277 : : {
278 : 0 : ScVbaControl::setBackColor( nBackColor );
279 : 0 : }
280 : :
281 : 0 : sal_Bool SAL_CALL ScVbaComboBox::getAutoSize() throw (uno::RuntimeException)
282 : : {
283 : 0 : return ScVbaControl::getAutoSize();
284 : : }
285 : :
286 : 0 : void SAL_CALL ScVbaComboBox::setAutoSize( sal_Bool bAutoSize ) throw (uno::RuntimeException)
287 : : {
288 : 0 : ScVbaControl::setAutoSize( bAutoSize );
289 : 0 : }
290 : :
291 : 0 : sal_Bool SAL_CALL ScVbaComboBox::getLocked() throw (uno::RuntimeException)
292 : : {
293 : 0 : return ScVbaControl::getLocked();
294 : : }
295 : :
296 : 0 : void SAL_CALL ScVbaComboBox::setLocked( sal_Bool bLocked ) throw (uno::RuntimeException)
297 : : {
298 : 0 : ScVbaControl::setLocked( bLocked );
299 : 0 : }
300 : :
301 : : uno::Sequence< rtl::OUString >
302 : 0 : ScVbaComboBox::getServiceNames()
303 : : {
304 : 0 : static uno::Sequence< rtl::OUString > aServiceNames;
305 : 0 : if ( aServiceNames.getLength() == 0 )
306 : : {
307 : 0 : aServiceNames.realloc( 1 );
308 : 0 : aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.ComboBox" ) );
309 : : }
310 : 0 : return aServiceNames;
311 : 0 : }
312 : :
313 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|