1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #include "vbatextbox.hxx" 25 #include "vbanewfont.hxx" 26 #include <com/sun/star/text/XTextRange.hpp> 27 #include <ooo/vba/msforms/fmBorderStyle.hpp> 28 #include <ooo/vba/msforms/fmSpecialEffect.hpp> 29 30 using namespace com::sun::star; 31 using namespace ooo::vba; 32 33 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 ) 34 { 35 } 36 37 // Attributes 38 uno::Any SAL_CALL 39 ScVbaTextBox::getValue() throw (css::uno::RuntimeException) 40 { 41 return uno::makeAny( getText() ); 42 } 43 44 void SAL_CALL 45 ScVbaTextBox::setValue( const uno::Any& _value ) throw (css::uno::RuntimeException) 46 { 47 // booleans are converted to uppercase strings 48 rtl::OUString sVal = extractStringFromAny( _value, true ); 49 setText( sVal ); 50 } 51 52 //getString() will cause some imfo lose. 53 rtl::OUString SAL_CALL 54 ScVbaTextBox::getText() throw (css::uno::RuntimeException) 55 { 56 uno::Any aValue; 57 aValue = m_xProps->getPropertyValue 58 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ) ) ); 59 rtl::OUString sString; 60 aValue >>= sString; 61 return sString; 62 } 63 64 void SAL_CALL 65 ScVbaTextBox::setText( const rtl::OUString& _text ) throw (css::uno::RuntimeException) 66 { 67 if ( !mbDialog ) 68 { 69 uno::Reference< text::XTextRange > xTextRange( m_xProps, uno::UNO_QUERY_THROW ); 70 xTextRange->setString( _text ); 71 } 72 else 73 m_xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Text") ), uno::makeAny( _text ) ); 74 } 75 76 sal_Int32 SAL_CALL 77 ScVbaTextBox::getMaxLength() throw (css::uno::RuntimeException) 78 { 79 uno::Any aValue; 80 aValue = m_xProps->getPropertyValue 81 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MaxTextLen" ) ) ); 82 sal_Int32 nMaxLength = 0; 83 aValue >>= nMaxLength; 84 return nMaxLength; 85 } 86 87 void SAL_CALL 88 ScVbaTextBox::setMaxLength( sal_Int32 _maxlength ) throw (css::uno::RuntimeException) 89 { 90 uno::Any aValue( _maxlength ); 91 m_xProps->setPropertyValue 92 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MaxTextLen" ) ), aValue); 93 } 94 95 sal_Bool SAL_CALL 96 ScVbaTextBox::getMultiline() throw (css::uno::RuntimeException) 97 { 98 uno::Any aValue; 99 aValue = m_xProps->getPropertyValue 100 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MultiLine" ) ) ); 101 sal_Bool bRet = false; 102 aValue >>= bRet; 103 return bRet; 104 } 105 106 void SAL_CALL 107 ScVbaTextBox::setMultiline( sal_Bool _multiline ) throw (css::uno::RuntimeException) 108 { 109 uno::Any aValue( _multiline ); 110 m_xProps->setPropertyValue 111 (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MultiLine" ) ), aValue); 112 } 113 114 sal_Int32 SAL_CALL ScVbaTextBox::getSpecialEffect() throw (uno::RuntimeException) 115 { 116 return msforms::fmSpecialEffect::fmSpecialEffectSunken; 117 } 118 119 void SAL_CALL ScVbaTextBox::setSpecialEffect( sal_Int32 /*nSpecialEffect*/ ) throw (uno::RuntimeException) 120 { 121 } 122 123 sal_Int32 SAL_CALL ScVbaTextBox::getBorderStyle() throw (uno::RuntimeException) 124 { 125 return msforms::fmBorderStyle::fmBorderStyleNone; 126 } 127 128 void SAL_CALL ScVbaTextBox::setBorderStyle( sal_Int32 /*nBorderStyle*/ ) throw (uno::RuntimeException) 129 { 130 } 131 132 sal_Int32 SAL_CALL ScVbaTextBox::getTextLength() throw (uno::RuntimeException) 133 { 134 return getText().getLength(); 135 } 136 137 uno::Reference< msforms::XNewFont > SAL_CALL ScVbaTextBox::getFont() throw (uno::RuntimeException) 138 { 139 return new VbaNewFont( this, mxContext, m_xProps ); 140 } 141 142 rtl::OUString& 143 ScVbaTextBox::getServiceImplName() 144 { 145 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaTextBox") ); 146 return sImplName; 147 } 148 149 uno::Sequence< rtl::OUString > 150 ScVbaTextBox::getServiceNames() 151 { 152 static uno::Sequence< rtl::OUString > aServiceNames; 153 if ( aServiceNames.getLength() == 0 ) 154 { 155 aServiceNames.realloc( 1 ); 156 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.TextBox" ) ); 157 } 158 return aServiceNames; 159 } 160