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