1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "vbatextbox.hxx"
29 #include "vbanewfont.hxx"
30 #include <com/sun/star/text/XTextRange.hpp>
31 #include <ooo/vba/msforms/fmBorderStyle.hpp>
32 #include <ooo/vba/msforms/fmSpecialEffect.hpp>
33 
34 using namespace com::sun::star;
35 using namespace ooo::vba;
36 
37 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 )
38 {
39 }
40 
41 // Attributes
42 uno::Any SAL_CALL
43 ScVbaTextBox::getValue() throw (css::uno::RuntimeException)
44 {
45 	return uno::makeAny( getText() );
46 }
47 
48 void SAL_CALL
49 ScVbaTextBox::setValue( const uno::Any& _value ) throw (css::uno::RuntimeException)
50 {
51     // booleans are converted to uppercase strings
52 	rtl::OUString sVal = extractStringFromAny( _value, true );
53 	setText( sVal );
54 }
55 
56 //getString() will cause some imfo lose.
57 rtl::OUString SAL_CALL
58 ScVbaTextBox::getText() throw (css::uno::RuntimeException)
59 {
60     uno::Any aValue;
61     aValue = m_xProps->getPropertyValue
62             (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ) ) );
63     rtl::OUString sString;
64     aValue >>= sString;
65     return sString;
66 }
67 
68 void SAL_CALL
69 ScVbaTextBox::setText( const rtl::OUString& _text ) throw (css::uno::RuntimeException)
70 {
71     if ( !mbDialog )
72     {
73     uno::Reference< text::XTextRange > xTextRange( m_xProps, uno::UNO_QUERY_THROW );
74     xTextRange->setString( _text );
75 }
76     else
77         m_xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Text") ), uno::makeAny( _text ) );
78 }
79 
80 sal_Int32 SAL_CALL
81 ScVbaTextBox::getMaxLength() throw (css::uno::RuntimeException)
82 {
83     uno::Any aValue;
84     aValue = m_xProps->getPropertyValue
85             (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MaxTextLen" ) ) );
86     sal_Int32 nMaxLength = 0;
87     aValue >>= nMaxLength;
88     return nMaxLength;
89 }
90 
91 void SAL_CALL
92 ScVbaTextBox::setMaxLength( sal_Int32 _maxlength ) throw (css::uno::RuntimeException)
93 {
94     uno::Any aValue( _maxlength );
95     m_xProps->setPropertyValue
96             (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MaxTextLen" ) ), aValue);
97 }
98 
99 sal_Bool SAL_CALL
100 ScVbaTextBox::getMultiline() throw (css::uno::RuntimeException)
101 {
102     uno::Any aValue;
103     aValue = m_xProps->getPropertyValue
104             (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MultiLine" ) ) );
105     sal_Bool bRet = false;
106     aValue >>= bRet;
107     return bRet;
108 }
109 
110 void SAL_CALL
111 ScVbaTextBox::setMultiline( sal_Bool _multiline ) throw (css::uno::RuntimeException)
112 {
113     uno::Any aValue( _multiline );
114     m_xProps->setPropertyValue
115             (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MultiLine" ) ), aValue);
116 }
117 
118 sal_Int32 SAL_CALL ScVbaTextBox::getSpecialEffect() throw (uno::RuntimeException)
119 {
120     return msforms::fmSpecialEffect::fmSpecialEffectSunken;
121 }
122 
123 void SAL_CALL ScVbaTextBox::setSpecialEffect( sal_Int32 /*nSpecialEffect*/ ) throw (uno::RuntimeException)
124 {
125 }
126 
127 sal_Int32 SAL_CALL ScVbaTextBox::getBorderStyle() throw (uno::RuntimeException)
128 {
129     return msforms::fmBorderStyle::fmBorderStyleNone;
130 }
131 
132 void SAL_CALL ScVbaTextBox::setBorderStyle( sal_Int32 /*nBorderStyle*/ ) throw (uno::RuntimeException)
133 {
134 }
135 
136 sal_Int32 SAL_CALL ScVbaTextBox::getTextLength() throw (uno::RuntimeException)
137 {
138     return getText().getLength();
139 }
140 
141 uno::Reference< msforms::XNewFont > SAL_CALL ScVbaTextBox::getFont() throw (uno::RuntimeException)
142 {
143     return new VbaNewFont( this, mxContext, m_xProps );
144 }
145 
146 rtl::OUString&
147 ScVbaTextBox::getServiceImplName()
148 {
149 	static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaTextBox") );
150 	return sImplName;
151 }
152 
153 uno::Sequence< rtl::OUString >
154 ScVbaTextBox::getServiceNames()
155 {
156 	static uno::Sequence< rtl::OUString > aServiceNames;
157 	if ( aServiceNames.getLength() == 0 )
158 	{
159 		aServiceNames.realloc( 1 );
160 		aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.TextBox" ) );
161 	}
162 	return aServiceNames;
163 }
164