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