1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 #include <vbahelper/helperdecl.hxx>
20 #include <com/sun/star/beans/XPropertySet.hpp>
21 #include <com/sun/star/drawing/TextFitToSizeType.hpp>
22 #include <com/sun/star/text/XText.hpp>
23 #include <vbahelper/vbatextframe.hxx>
24 
25 using namespace ::ooo::vba;
26 using namespace ::com::sun::star;
27 
VbaTextFrame(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext,uno::Reference<drawing::XShape> const & xShape)28 VbaTextFrame::VbaTextFrame( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, uno::Reference< drawing::XShape > const & xShape ) : VbaTextFrame_BASE( xParent, xContext ), m_xShape( xShape )
29 {
30     m_xPropertySet.set( m_xShape, uno::UNO_QUERY_THROW );
31 }
32 
33 void
setAsMSObehavior()34 VbaTextFrame::setAsMSObehavior()
35 {
36     //set property TextWordWrap default as False.
37     // TextFitToSize control the text content. It seems we should set the default as False.
38     // com.sun.star.drawing.TextFitToSizeType.NONE
39     m_xPropertySet->setPropertyValue( "TextWordWrap", uno::makeAny( false ) );
40     m_xPropertySet->setPropertyValue( "TextFitToSize", uno::makeAny( drawing::TextFitToSizeType_NONE ) );
41 }
42 
getMargin(const OUString & sMarginType)43 sal_Int32 VbaTextFrame::getMargin( const OUString& sMarginType )
44 {
45     sal_Int32 nMargin = 0;
46     uno::Any aMargin = m_xPropertySet->getPropertyValue( sMarginType );
47     aMargin >>= nMargin;
48     return nMargin;
49 }
50 
setMargin(const OUString & sMarginType,float fMargin)51 void VbaTextFrame::setMargin( const OUString& sMarginType, float fMargin )
52 {
53     sal_Int32 nMargin = Millimeter::getInHundredthsOfOneMillimeter( fMargin );
54     m_xPropertySet->setPropertyValue( sMarginType, uno::makeAny( nMargin ) );
55 }
56 
57 // Attributes
58 sal_Bool SAL_CALL
getAutoSize()59 VbaTextFrame::getAutoSize()
60 {
61     // I don't know why, but in OOo, TextAutoGrowHeight is the property control autosize. not TextFitToSize.
62     // TextFitToSize control the text content.
63     // and in mso, there isnot option TextWordWrap which means auto wrap. the default is False.
64     bool bAutosize = false;
65     uno::Any aTextAutoGrowHeight = m_xPropertySet->getPropertyValue( "TextAutoGrowHeight" );
66     aTextAutoGrowHeight >>= bAutosize;
67     return bAutosize;
68 }
69 
70 void SAL_CALL
setAutoSize(sal_Bool _autosize)71 VbaTextFrame::setAutoSize( sal_Bool _autosize )
72 {
73     setAsMSObehavior();
74     m_xPropertySet->setPropertyValue( "TextAutoGrowHeight", uno::makeAny( _autosize ) );
75 }
76 
77 float SAL_CALL
getMarginBottom()78 VbaTextFrame::getMarginBottom()
79 {
80     sal_Int32 nMargin = getMargin( "TextLowerDistance" );
81     float fMargin = static_cast<float>(Millimeter::getInPoints( nMargin ));
82     return fMargin;
83 }
84 
85 void SAL_CALL
setMarginBottom(float _marginbottom)86 VbaTextFrame::setMarginBottom( float _marginbottom )
87 {
88     setMargin( "TextLowerDistance", _marginbottom );
89 }
90 
91 float SAL_CALL
getMarginTop()92 VbaTextFrame::getMarginTop()
93 {
94     sal_Int32 nMargin = getMargin( "TextUpperDistance" );
95     float fMargin = static_cast<float>(Millimeter::getInPoints( nMargin ));
96     return fMargin;
97 }
98 
99 void SAL_CALL
setMarginTop(float _margintop)100 VbaTextFrame::setMarginTop( float _margintop )
101 {
102     setMargin( "TextUpperDistance", _margintop );
103 }
104 
105 float SAL_CALL
getMarginLeft()106 VbaTextFrame::getMarginLeft()
107 {
108     sal_Int32 nMargin = getMargin( "TextLeftDistance" );
109     float fMargin = static_cast<float>(Millimeter::getInPoints( nMargin ));
110     return fMargin;
111 }
112 
113 void SAL_CALL
setMarginLeft(float _marginleft)114 VbaTextFrame::setMarginLeft( float _marginleft )
115 {
116     setMargin( "TextLeftDistance", _marginleft );
117 }
118 
119 float SAL_CALL
getMarginRight()120 VbaTextFrame::getMarginRight()
121 {
122     sal_Int32 nMargin = getMargin( "TextRightDistance" );
123     float fMargin = static_cast<float>(Millimeter::getInPoints( nMargin ));
124     return fMargin;
125 }
126 
127 void SAL_CALL
setMarginRight(float _marginright)128 VbaTextFrame::setMarginRight( float _marginright )
129 {
130     setMargin( "TextRightDistance" , _marginright );
131 }
132 
133 
134 // Methods
135 uno::Any SAL_CALL
Characters()136 VbaTextFrame::Characters()
137 {
138     throw uno::RuntimeException( "Not implemented" );
139 }
140 
141 OUString
getServiceImplName()142 VbaTextFrame::getServiceImplName()
143 {
144     return "VbaTextFrame";
145 }
146 
147 uno::Sequence< OUString >
getServiceNames()148 VbaTextFrame::getServiceNames()
149 {
150     static uno::Sequence< OUString > const aServiceNames
151     {
152         "ooo.vba.msforms.TextFrame"
153     };
154     return aServiceNames;
155 }
156 
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
158