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"
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>
33 using namespace com::sun::star
;
34 using namespace ooo::vba
;
37 //SelectedItems list of integer indexes
38 //StringItemList list of items
40 const static OUString
TEXT( "Text" );
41 const static OUString
ITEMS( "StringItemList" );
42 const static OUString
CONTROLSOURCEPROP( "DataFieldProperty" );
44 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
)
46 mpListHelper
.reset( new ListControlHelper( m_xProps
) );
49 // grab the default value property name
50 m_xProps
->getPropertyValue( CONTROLSOURCEPROP
) >>= sSourceName
;
52 catch( uno::Exception
& )
55 if( sSourceName
.isEmpty() )
62 // Value, [read] e.g. getValue returns the value of ooo Text propery e.g. the value in
65 ScVbaComboBox::getValue() throw (uno::RuntimeException
)
67 return m_xProps
->getPropertyValue( sSourceName
);
71 ScVbaComboBox::setListIndex( const uno::Any
& _value
) throw (uno::RuntimeException
)
74 if( _value
>>= nIndex
)
76 sal_Int32 nOldIndex
= -1;
77 getListIndex() >>= nOldIndex
;
78 uno::Sequence
< OUString
> sItems
;
79 m_xProps
->getPropertyValue( ITEMS
) >>= sItems
;
80 if( ( nIndex
>= 0 ) && ( sItems
.getLength() > nIndex
) )
82 OUString sText
= sItems
[ nIndex
];
83 m_xProps
->setPropertyValue( TEXT
, uno::makeAny( sText
) );
85 // fire the _Change event
86 if( nOldIndex
!= nIndex
)
93 ScVbaComboBox::getListIndex() throw (uno::RuntimeException
)
95 uno::Sequence
< OUString
> sItems
;
96 m_xProps
->getPropertyValue( ITEMS
) >>= sItems
;
97 // should really return the item that has focus regardless of
99 if ( sItems
.getLength() > 0 )
101 OUString sText
= getText();
102 sal_Int32 nLen
= sItems
.getLength();
103 for ( sal_Int32 index
= 0; !sText
.isEmpty() && index
< nLen
; ++index
)
105 if ( sItems
[ index
].equals( sText
) )
107 SAL_INFO("vbahelper", "getListIndex returning " << index
);
108 return uno::makeAny( index
);
113 SAL_INFO("vbahelper", "getListIndex returning -1" );
114 return uno::makeAny( sal_Int32( -1 ) );
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
120 ScVbaComboBox::setValue( const uno::Any
& _value
) throw (uno::RuntimeException
)
122 // booleans are converted to uppercase strings
123 OUString oldValue
= extractStringFromAny( getValue(), OUString(), true );
124 m_xProps
->setPropertyValue( sSourceName
, uno::Any( extractStringFromAny( _value
, OUString(), true ) ) );
125 OUString newValue
= extractStringFromAny( getValue(), OUString(), true );
126 if ( oldValue
!= newValue
)
129 uno::Any aIndex
= getListIndex();
141 ScVbaComboBox::getText() throw (uno::RuntimeException
)
144 getValue() >>= result
;
149 ScVbaComboBox::setText( const OUString
& _text
) throw (uno::RuntimeException
)
151 setValue( uno::makeAny( _text
) ); // seems the same
156 ScVbaComboBox::AddItem( const uno::Any
& pvargItem
, const uno::Any
& pvargIndex
) throw (uno::RuntimeException
)
158 mpListHelper
->AddItem( pvargItem
, pvargIndex
);
162 ScVbaComboBox::removeItem( const uno::Any
& index
) throw (uno::RuntimeException
)
164 mpListHelper
->removeItem( index
);
168 ScVbaComboBox::Clear( ) throw (uno::RuntimeException
)
170 mpListHelper
->Clear();
174 ScVbaComboBox::setRowSource( const OUString
& _rowsource
) throw (css::uno::RuntimeException
)
176 ScVbaControl::setRowSource( _rowsource
);
177 mpListHelper
->setRowSource( _rowsource
);
181 ScVbaComboBox::getListCount() throw (uno::RuntimeException
)
183 return mpListHelper
->getListCount();
187 ScVbaComboBox::List( const ::uno::Any
& pvargIndex
, const uno::Any
& pvarColumn
) throw (uno::RuntimeException
)
189 return mpListHelper
->List( pvargIndex
, pvarColumn
);
192 sal_Int32 SAL_CALL
ScVbaComboBox::getStyle() throw (uno::RuntimeException
)
194 return msforms::fmStyle::fmStyleDropDownCombo
;
197 void SAL_CALL
ScVbaComboBox::setStyle( sal_Int32
/*nStyle*/ ) throw (uno::RuntimeException
)
201 sal_Int32 SAL_CALL
ScVbaComboBox::getDropButtonStyle() throw (uno::RuntimeException
)
203 return msforms::fmDropButtonStyle::fmDropButtonStyleArrow
;
206 void SAL_CALL
ScVbaComboBox::setDropButtonStyle( sal_Int32
/*nDropButtonStyle*/ ) throw (uno::RuntimeException
)
210 sal_Int32 SAL_CALL
ScVbaComboBox::getDragBehavior() throw (uno::RuntimeException
)
212 return msforms::fmDragBehavior::fmDragBehaviorDisabled
;
215 void SAL_CALL
ScVbaComboBox::setDragBehavior( sal_Int32
/*nDragBehavior*/ ) throw (uno::RuntimeException
)
219 sal_Int32 SAL_CALL
ScVbaComboBox::getEnterFieldBehavior() throw (uno::RuntimeException
)
221 return msforms::fmEnterFieldBehavior::fmEnterFieldBehaviorSelectAll
;
224 void SAL_CALL
ScVbaComboBox::setEnterFieldBehavior( sal_Int32
/*nEnterFieldBehavior*/ ) throw (uno::RuntimeException
)
228 sal_Int32 SAL_CALL
ScVbaComboBox::getListStyle() throw (uno::RuntimeException
)
230 return msforms::fmListStyle::fmListStylePlain
;
233 void SAL_CALL
ScVbaComboBox::setListStyle( sal_Int32
/*nListStyle*/ ) throw (uno::RuntimeException
)
237 sal_Int32 SAL_CALL
ScVbaComboBox::getTextAlign() throw (uno::RuntimeException
)
239 return msforms::fmTextAlign::fmTextAlignLeft
;
242 void SAL_CALL
ScVbaComboBox::setTextAlign( sal_Int32
/*nTextAlign*/ ) throw (uno::RuntimeException
)
246 sal_Int32 SAL_CALL
ScVbaComboBox::getTextLength() throw (uno::RuntimeException
)
248 return getText().getLength();
251 uno::Reference
< msforms::XNewFont
> SAL_CALL
ScVbaComboBox::getFont() throw (uno::RuntimeException
)
253 return new VbaNewFont( this, mxContext
, m_xProps
);
257 ScVbaComboBox::getServiceImplName()
259 return OUString("ScVbaComboBox");
262 sal_Int32 SAL_CALL
ScVbaComboBox::getBackColor() throw (uno::RuntimeException
)
264 return ScVbaControl::getBackColor();
267 void SAL_CALL
ScVbaComboBox::setBackColor( sal_Int32 nBackColor
) throw (uno::RuntimeException
)
269 ScVbaControl::setBackColor( nBackColor
);
272 sal_Bool SAL_CALL
ScVbaComboBox::getAutoSize() throw (uno::RuntimeException
)
274 return ScVbaControl::getAutoSize();
277 void SAL_CALL
ScVbaComboBox::setAutoSize( sal_Bool bAutoSize
) throw (uno::RuntimeException
)
279 ScVbaControl::setAutoSize( bAutoSize
);
282 sal_Bool SAL_CALL
ScVbaComboBox::getLocked() throw (uno::RuntimeException
)
284 return ScVbaControl::getLocked();
287 void SAL_CALL
ScVbaComboBox::setLocked( sal_Bool bLocked
) throw (uno::RuntimeException
)
289 ScVbaControl::setLocked( bLocked
);
292 OUString SAL_CALL
ScVbaComboBox::getLinkedCell() throw (uno::RuntimeException
)
294 return ScVbaControl::getControlSource();
297 void SAL_CALL
ScVbaComboBox::setLinkedCell( const OUString
& _linkedcell
) throw (uno::RuntimeException
)
299 ScVbaControl::setControlSource( _linkedcell
);
302 uno::Sequence
< OUString
>
303 ScVbaComboBox::getServiceNames()
305 static uno::Sequence
< OUString
> aServiceNames
;
306 if ( aServiceNames
.getLength() == 0 )
308 aServiceNames
.realloc( 1 );
309 aServiceNames
[ 0 ] = "ooo.vba.msforms.ComboBox";
311 return aServiceNames
;
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */