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 #include <vbahelper/helperdecl.hxx>
24 #include <com/sun/star/drawing/TextFitToSizeType.hpp>
25 #include <com/sun/star/text/XText.hpp>
26 #include <vbahelper/vbatextframe.hxx>
27
28 using namespace ::ooo::vba;
29 using namespace ::com::sun::star;
30
VbaTextFrame(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext,uno::Reference<drawing::XShape> xShape)31 VbaTextFrame::VbaTextFrame( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, uno::Reference< drawing::XShape > xShape ) : VbaTextFrame_BASE( xParent, xContext ), m_xShape( xShape )
32 {
33 m_xPropertySet.set( m_xShape, uno::UNO_QUERY_THROW );
34 }
35
36 void
setAsMSObehavior()37 VbaTextFrame::setAsMSObehavior()
38 {
39 //set property TextWordWrap default as False.
40 // TextFitToSize control the text content. it seems we should set the default as False.
41 // com.sun.star.drawing.TextFitToSizeType.NONE
42 m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "TextWordWrap" ), uno::makeAny( sal_False ) );
43 m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "TextFitToSize" ), uno::makeAny( drawing::TextFitToSizeType_NONE ) );
44 }
45
getMargin(rtl::OUString sMarginType)46 sal_Int32 VbaTextFrame::getMargin( rtl::OUString sMarginType )
47 {
48 sal_Int32 nMargin = 0;
49 uno::Any aMargin = m_xPropertySet->getPropertyValue( sMarginType );
50 aMargin >>= nMargin;
51 return nMargin;
52 }
53
setMargin(rtl::OUString sMarginType,float fMargin)54 void VbaTextFrame::setMargin( rtl::OUString sMarginType, float fMargin )
55 {
56 sal_Int32 nMargin = Millimeter::getInHundredthsOfOneMillimeter( fMargin );
57 m_xPropertySet->setPropertyValue( sMarginType, uno::makeAny( nMargin ) );
58 }
59
60 // Attributes
61 sal_Bool SAL_CALL
getAutoSize()62 VbaTextFrame::getAutoSize() throw (uno::RuntimeException)
63 {
64 // I don't know why, but in OOo, TextAutoGrowHeight is the property control autosize. not TextFitToSize.
65 // TextFitToSize control the text content.
66 // and in mso, there isnot option TextWordWrap which means auto wrap. the default is False.
67 sal_Bool bAutosize = sal_False;
68 uno::Any aTextAutoGrowHeight = m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii( "TextAutoGrowHeight" ) );
69 aTextAutoGrowHeight >>= bAutosize;
70 return bAutosize;
71 }
72
73 void SAL_CALL
setAutoSize(sal_Bool _autosize)74 VbaTextFrame::setAutoSize( sal_Bool _autosize ) throw (uno::RuntimeException)
75 {
76 setAsMSObehavior();
77 m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "TextAutoGrowHeight" ), uno::makeAny( _autosize ) );
78 }
79
80 float SAL_CALL
getMarginBottom()81 VbaTextFrame::getMarginBottom() throw (uno::RuntimeException)
82 {
83 sal_Int32 nMargin = getMargin( rtl::OUString::createFromAscii( "TextLowerDistance" ) );
84 float fMargin = (float)Millimeter::getInPoints( nMargin );
85 return fMargin;
86 }
87
88 void SAL_CALL
setMarginBottom(float _marginbottom)89 VbaTextFrame::setMarginBottom( float _marginbottom ) throw (uno::RuntimeException)
90 {
91 setMargin( rtl::OUString::createFromAscii( "TextLowerDistance" ), _marginbottom );
92 }
93
94 float SAL_CALL
getMarginTop()95 VbaTextFrame::getMarginTop() throw (uno::RuntimeException)
96 {
97 sal_Int32 nMargin = getMargin( rtl::OUString::createFromAscii( "TextUpperDistance" ) );
98 float fMargin = (float)Millimeter::getInPoints( nMargin );
99 return fMargin;
100 }
101
102 void SAL_CALL
setMarginTop(float _margintop)103 VbaTextFrame::setMarginTop( float _margintop ) throw (uno::RuntimeException)
104 {
105 setMargin( rtl::OUString::createFromAscii( "TextUpperDistance" ), _margintop );
106 }
107
108 float SAL_CALL
getMarginLeft()109 VbaTextFrame::getMarginLeft() throw (uno::RuntimeException)
110 {
111 sal_Int32 nMargin = getMargin( rtl::OUString::createFromAscii( "TextLeftDistance" ) );
112 float fMargin = (float)Millimeter::getInPoints( nMargin );
113 return fMargin;
114 }
115
116 void SAL_CALL
setMarginLeft(float _marginleft)117 VbaTextFrame::setMarginLeft( float _marginleft ) throw (uno::RuntimeException)
118 {
119 setMargin( rtl::OUString::createFromAscii( "TextLeftDistance" ), _marginleft );
120 }
121
122 float SAL_CALL
getMarginRight()123 VbaTextFrame::getMarginRight() throw (uno::RuntimeException)
124 {
125 sal_Int32 nMargin = getMargin( rtl::OUString::createFromAscii( "TextRightDistance" ) );
126 float fMargin = (float)Millimeter::getInPoints( nMargin );
127 return fMargin;
128 }
129
130 void SAL_CALL
setMarginRight(float _marginright)131 VbaTextFrame::setMarginRight( float _marginright ) throw (uno::RuntimeException)
132 {
133 setMargin( rtl::OUString::createFromAscii( "TextRightDistance" ), _marginright );
134 }
135
136
137 // Methods
138 uno::Any SAL_CALL
Characters()139 VbaTextFrame::Characters() throw (uno::RuntimeException)
140 {
141 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
142 }
143
144 rtl::OUString&
getServiceImplName()145 VbaTextFrame::getServiceImplName()
146 {
147 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("VbaTextFrame") );
148 return sImplName;
149 }
150
151 uno::Sequence< rtl::OUString >
getServiceNames()152 VbaTextFrame::getServiceNames()
153 {
154 static uno::Sequence< rtl::OUString > aServiceNames;
155 if ( aServiceNames.getLength() == 0 )
156 {
157 aServiceNames.realloc( 1 );
158 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.TextFrame" ) );
159 }
160 return aServiceNames;
161 }
162
163