1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "vbacombobox.hxx"
31 #include <filter/msfilter/msvbahelper.hxx>
32 #include <basic/sbstar.hxx>
33 #include <basic/sbmod.hxx>
34 #include "vbanewfont.hxx"
35 #include <ooo/vba/msforms/fmStyle.hpp>
36 #include <ooo/vba/msforms/fmDropButtonStyle.hpp>
37 #include <ooo/vba/msforms/fmDragBehavior.hpp>
38 #include <ooo/vba/msforms/fmEnterFieldBehavior.hpp>
39 #include <ooo/vba/msforms/fmListStyle.hpp>
40 #include <ooo/vba/msforms/fmTextAlign.hpp>
42 using namespace com::sun::star
;
43 using namespace ooo::vba
;
46 //SelectedItems list of integer indexes
47 //StringItemList list of items
49 const static rtl::OUString
TEXT( RTL_CONSTASCII_USTRINGPARAM("Text") );
50 const static rtl::OUString
ITEMS( RTL_CONSTASCII_USTRINGPARAM("StringItemList") );
51 const static rtl::OUString
CONTROLSOURCEPROP( RTL_CONSTASCII_USTRINGPARAM("DataFieldProperty") );
53 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
)
55 mpListHelper
.reset( new ListControlHelper( m_xProps
) );
58 // grab the default value property name
59 m_xProps
->getPropertyValue( CONTROLSOURCEPROP
) >>= sSourceName
;
61 catch( uno::Exception
& )
64 if( sSourceName
.isEmpty() )
65 sSourceName
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ) );
71 // Value, [read] e.g. getValue returns the value of ooo Text propery e.g. the value in
74 ScVbaComboBox::getValue() throw (uno::RuntimeException
)
76 return m_xProps
->getPropertyValue( sSourceName
);
80 ScVbaComboBox::setListIndex( const uno::Any
& _value
) throw (uno::RuntimeException
)
83 if( _value
>>= nIndex
)
85 sal_Int32 nOldIndex
= -1;
86 getListIndex() >>= nOldIndex
;
87 uno::Sequence
< rtl::OUString
> sItems
;
88 m_xProps
->getPropertyValue( ITEMS
) >>= sItems
;
89 if( ( nIndex
>= 0 ) && ( sItems
.getLength() > nIndex
) )
91 rtl::OUString sText
= sItems
[ nIndex
];
92 m_xProps
->setPropertyValue( TEXT
, uno::makeAny( sText
) );
94 // fire the _Change event
95 if( nOldIndex
!= nIndex
)
102 ScVbaComboBox::getListIndex() throw (uno::RuntimeException
)
104 uno::Sequence
< rtl::OUString
> sItems
;
105 m_xProps
->getPropertyValue( ITEMS
) >>= sItems
;
106 // should really return the item that has focus regardless of
108 if ( sItems
.getLength() > 0 )
110 rtl::OUString sText
= getText();
111 sal_Int32 nLen
= sItems
.getLength();
112 for ( sal_Int32 index
= 0; !sText
.isEmpty() && index
< nLen
; ++index
)
114 if ( sItems
[ index
].equals( sText
) )
116 OSL_TRACE("getListIndex returning %d", index
);
117 return uno::makeAny( index
);
122 OSL_TRACE("getListIndex returning %d", -1 );
123 return uno::makeAny( sal_Int32( -1 ) );
126 // Value, [write]e.g. setValue sets the value in the drop down, and if the value is one
127 // of the values in the list then the selection is also set
129 ScVbaComboBox::setValue( const uno::Any
& _value
) throw (uno::RuntimeException
)
131 rtl::OUString sOldValue
, sNewValue
;
132 // booleans are converted to uppercase strings
133 sOldValue
= extractStringFromAny( getValue(), ::rtl::OUString(), true );
134 // booleans are converted to uppercase strings
135 sNewValue
= extractStringFromAny( _value
, ::rtl::OUString(), true );
137 m_xProps
->setPropertyValue( sSourceName
, uno::Any( sNewValue
) );
139 if ( sNewValue
!= sOldValue
)
141 // If the new value is in current list, we should fire click event, otherwise fire the change event.
142 sal_Int32 nListIndex
= -1;
143 getListIndex() >>= nListIndex
;
144 sal_Bool bIsInList
= ( nListIndex
>= 0 );
158 ::rtl::OUString SAL_CALL
159 ScVbaComboBox::getText() throw (uno::RuntimeException
)
161 rtl::OUString result
;
162 getValue() >>= result
;
167 ScVbaComboBox::setText( const ::rtl::OUString
& _text
) throw (uno::RuntimeException
)
169 setValue( uno::makeAny( _text
) ); // seems the same
174 ScVbaComboBox::AddItem( const uno::Any
& pvargItem
, const uno::Any
& pvargIndex
) throw (uno::RuntimeException
)
176 mpListHelper
->AddItem( pvargItem
, pvargIndex
);
180 ScVbaComboBox::removeItem( const uno::Any
& index
) throw (uno::RuntimeException
)
182 mpListHelper
->removeItem( index
);
186 ScVbaComboBox::Clear( ) throw (uno::RuntimeException
)
188 mpListHelper
->Clear();
192 ScVbaComboBox::setRowSource( const rtl::OUString
& _rowsource
) throw (css::uno::RuntimeException
)
194 ScVbaControl::setRowSource( _rowsource
);
195 mpListHelper
->setRowSource( _rowsource
);
199 ScVbaComboBox::getListCount() throw (uno::RuntimeException
)
201 return mpListHelper
->getListCount();
205 ScVbaComboBox::List( const ::uno::Any
& pvargIndex
, const uno::Any
& pvarColumn
) throw (uno::RuntimeException
)
207 return mpListHelper
->List( pvargIndex
, pvarColumn
);
210 sal_Int32 SAL_CALL
ScVbaComboBox::getStyle() throw (uno::RuntimeException
)
212 return msforms::fmStyle::fmStyleDropDownCombo
;
215 void SAL_CALL
ScVbaComboBox::setStyle( sal_Int32
/*nStyle*/ ) throw (uno::RuntimeException
)
219 sal_Int32 SAL_CALL
ScVbaComboBox::getDropButtonStyle() throw (uno::RuntimeException
)
221 return msforms::fmDropButtonStyle::fmDropButtonStyleArrow
;
224 void SAL_CALL
ScVbaComboBox::setDropButtonStyle( sal_Int32
/*nDropButtonStyle*/ ) throw (uno::RuntimeException
)
228 sal_Int32 SAL_CALL
ScVbaComboBox::getDragBehavior() throw (uno::RuntimeException
)
230 return msforms::fmDragBehavior::fmDragBehaviorDisabled
;
233 void SAL_CALL
ScVbaComboBox::setDragBehavior( sal_Int32
/*nDragBehavior*/ ) throw (uno::RuntimeException
)
237 sal_Int32 SAL_CALL
ScVbaComboBox::getEnterFieldBehavior() throw (uno::RuntimeException
)
239 return msforms::fmEnterFieldBehavior::fmEnterFieldBehaviorSelectAll
;
242 void SAL_CALL
ScVbaComboBox::setEnterFieldBehavior( sal_Int32
/*nEnterFieldBehavior*/ ) throw (uno::RuntimeException
)
246 sal_Int32 SAL_CALL
ScVbaComboBox::getListStyle() throw (uno::RuntimeException
)
248 return msforms::fmListStyle::fmListStylePlain
;
251 void SAL_CALL
ScVbaComboBox::setListStyle( sal_Int32
/*nListStyle*/ ) throw (uno::RuntimeException
)
255 sal_Int32 SAL_CALL
ScVbaComboBox::getTextAlign() throw (uno::RuntimeException
)
257 return msforms::fmTextAlign::fmTextAlignLeft
;
260 void SAL_CALL
ScVbaComboBox::setTextAlign( sal_Int32
/*nTextAlign*/ ) throw (uno::RuntimeException
)
264 sal_Int32 SAL_CALL
ScVbaComboBox::getTextLength() throw (uno::RuntimeException
)
266 return getText().getLength();
269 uno::Reference
< msforms::XNewFont
> SAL_CALL
ScVbaComboBox::getFont() throw (uno::RuntimeException
)
271 return new VbaNewFont( this, mxContext
, m_xProps
);
275 ScVbaComboBox::getServiceImplName()
277 return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScVbaComboBox"));
280 sal_Int32 SAL_CALL
ScVbaComboBox::getBackColor() throw (uno::RuntimeException
)
282 return ScVbaControl::getBackColor();
285 void SAL_CALL
ScVbaComboBox::setBackColor( sal_Int32 nBackColor
) throw (uno::RuntimeException
)
287 ScVbaControl::setBackColor( nBackColor
);
290 sal_Bool SAL_CALL
ScVbaComboBox::getAutoSize() throw (uno::RuntimeException
)
292 return ScVbaControl::getAutoSize();
295 void SAL_CALL
ScVbaComboBox::setAutoSize( sal_Bool bAutoSize
) throw (uno::RuntimeException
)
297 ScVbaControl::setAutoSize( bAutoSize
);
300 sal_Bool SAL_CALL
ScVbaComboBox::getLocked() throw (uno::RuntimeException
)
302 return ScVbaControl::getLocked();
305 void SAL_CALL
ScVbaComboBox::setLocked( sal_Bool bLocked
) throw (uno::RuntimeException
)
307 ScVbaControl::setLocked( bLocked
);
310 uno::Sequence
< rtl::OUString
>
311 ScVbaComboBox::getServiceNames()
313 static uno::Sequence
< rtl::OUString
> aServiceNames
;
314 if ( aServiceNames
.getLength() == 0 )
316 aServiceNames
.realloc( 1 );
317 aServiceNames
[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.ComboBox" ) );
319 return aServiceNames
;
322 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */