merge the formfield patch from ooo-build
[ooovba.git] / vbahelper / source / msforms / vbatextbox.cxx
blobeb1b393b1e30ae721606866e44dddc94e6985c93
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vbatextbox.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include <com/sun/star/text/XTextRange.hpp>
32 #include "vbatextbox.hxx"
33 #include <vector>
35 using namespace com::sun::star;
36 using namespace ooo::vba;
40 ScVbaTextBox::ScVbaTextBox( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< uno::XInterface >& xControl, const uno::Reference< frame::XModel >& xModel, AbstractGeometryAttributes* pGeomHelper, bool bDialog ) : TextBoxImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ), mbDialog( bDialog )
44 // Attributes
45 uno::Any SAL_CALL
46 ScVbaTextBox::getValue() throw (css::uno::RuntimeException)
48 return uno::makeAny( getText() );
51 void SAL_CALL
52 ScVbaTextBox::setValue( const uno::Any& _value ) throw (css::uno::RuntimeException)
54 rtl::OUString sVal = getAnyAsString( _value );
55 setText( sVal );
58 //getString() will cause some imfo lose.
59 rtl::OUString SAL_CALL
60 ScVbaTextBox::getText() throw (css::uno::RuntimeException)
62 uno::Any aValue;
63 aValue = m_xProps->getPropertyValue
64 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ) ) );
65 rtl::OUString sString;
66 aValue >>= sString;
67 return sString;
70 void SAL_CALL
71 ScVbaTextBox::setText( const rtl::OUString& _text ) throw (css::uno::RuntimeException)
73 if ( !mbDialog )
75 uno::Reference< text::XTextRange > xTextRange( m_xProps, uno::UNO_QUERY_THROW );
76 xTextRange->setString( _text );
78 else
79 m_xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Text") ), uno::makeAny( _text ) );
82 sal_Int32 SAL_CALL
83 ScVbaTextBox::getMaxLength() throw (css::uno::RuntimeException)
85 uno::Any aValue;
86 aValue = m_xProps->getPropertyValue
87 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MaxTextLen" ) ) );
88 sal_Int32 nMaxLength = 0;
89 aValue >>= nMaxLength;
90 return nMaxLength;
93 void SAL_CALL
94 ScVbaTextBox::setMaxLength( sal_Int32 _maxlength ) throw (css::uno::RuntimeException)
96 sal_Int16 _maxlength16 = static_cast<sal_Int16> (_maxlength); //liuchen 2009-7-24, resolve the problem that MaxLength cannot be set correctly
97 uno::Any aValue( _maxlength16 ); //liuchen 2009-7-24, resolve the problem that MaxLength cannot be set correctly
98 m_xProps->setPropertyValue
99 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MaxTextLen" ) ), aValue);
102 sal_Bool SAL_CALL
103 ScVbaTextBox::getMultiline() throw (css::uno::RuntimeException)
105 uno::Any aValue;
106 aValue = m_xProps->getPropertyValue
107 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MultiLine" ) ) );
108 sal_Bool bRet = false;
109 aValue >>= bRet;
110 return bRet;
113 void SAL_CALL
114 ScVbaTextBox::setMultiline( sal_Bool _multiline ) throw (css::uno::RuntimeException)
116 uno::Any aValue( _multiline );
117 m_xProps->setPropertyValue
118 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MultiLine" ) ), aValue);
121 rtl::OUString&
122 ScVbaTextBox::getServiceImplName()
124 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaTextBox") );
125 return sImplName;
128 uno::Sequence< rtl::OUString >
129 ScVbaTextBox::getServiceNames()
131 static uno::Sequence< rtl::OUString > aServiceNames;
132 if ( aServiceNames.getLength() == 0 )
134 aServiceNames.realloc( 1 );
135 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.TextBox" ) );
137 return aServiceNames;