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