LibreOffice Module sw (master) 1
vbarow.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#include "vbarow.hxx"
20#include <utility>
22#include <com/sun/star/frame/XModel.hpp>
23#include <com/sun/star/beans/XPropertySet.hpp>
24#include <com/sun/star/table/XCellRange.hpp>
25#include <com/sun/star/view/XSelectionSupplier.hpp>
26#include <ooo/vba/word/WdRowHeightRule.hpp>
27#include <ooo/vba/word/WdConstants.hpp>
28#include "vbatablehelper.hxx"
29
30using namespace ::ooo::vba;
31using namespace ::com::sun::star;
32
33SwVbaRow::SwVbaRow( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext,uno::Reference< text::XTextTable > xTextTable, sal_Int32 nIndex ) :
34 SwVbaRow_BASE( rParent, rContext ), mxTextTable(std::move( xTextTable )), mnIndex( nIndex )
35{
36 mxTableRows = mxTextTable->getRows();
37 mxRowProps.set( mxTableRows->getByIndex( mnIndex ), uno::UNO_QUERY_THROW );
38}
39
41{
42}
43
45{
46 if( getHeightRule() == word::WdRowHeightRule::wdRowHeightAuto )
47 return uno::Any( sal_Int32( word::WdConstants::wdUndefined ) );
48
49 sal_Int32 nHeight = 0;
50 mxRowProps->getPropertyValue("Height") >>= nHeight;
51 return uno::Any( static_cast<float>(Millimeter::getInPoints( nHeight )) );
52}
53
54void SAL_CALL SwVbaRow::setHeight( const uno::Any& _height )
55{
56 float height = 0;
57 _height >>= height;
58
59 sal_Int32 nHeight = Millimeter::getInHundredthsOfOneMillimeter( height );
60 mxRowProps->setPropertyValue("Height", uno::Any( nHeight ) );
61}
62
63::sal_Int32 SAL_CALL SwVbaRow::getHeightRule()
64{
65 bool isAutoHeight = false;
66 mxRowProps->getPropertyValue("IsAutoHeight") >>= isAutoHeight;
67 return isAutoHeight ? word::WdRowHeightRule::wdRowHeightAuto : word::WdRowHeightRule::wdRowHeightExactly;
68}
69
70void SAL_CALL SwVbaRow::setHeightRule( ::sal_Int32 _heightrule )
71{
72 bool isAutoHeight = ( _heightrule == word::WdRowHeightRule::wdRowHeightAuto );
73 mxRowProps->setPropertyValue("IsAutoHeight", uno::Any( isAutoHeight ) );
74}
75
76void SAL_CALL
78{
80}
81
82void SwVbaRow::SelectRow( const uno::Reference< frame::XModel >& xModel, const uno::Reference< text::XTextTable >& xTextTable, sal_Int32 nStartRow, sal_Int32 nEndRow )
83{
84 OUString sRangeName = "A" + OUString::number(nStartRow + 1);
85 SwVbaTableHelper aTableHelper( xTextTable );
86 sal_Int32 nColCount = aTableHelper.getTabColumnsCount( nEndRow );
87 // FIXME: the column count > 26
88 //char cCol = 'A' + nColCount - 1;
89 OUString sCol = SwVbaTableHelper::getColumnStr( nColCount - 1);
90 sRangeName += ":" + sCol + OUString::number(nEndRow + 1);
91
92 uno::Reference< table::XCellRange > xCellRange( xTextTable, uno::UNO_QUERY_THROW );
93 uno::Reference< table::XCellRange > xSelRange = xCellRange->getCellRangeByName( sRangeName );
94
95 uno::Reference< view::XSelectionSupplier > xSelection( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
96 xSelection->select( uno::Any( xSelRange ) );
97}
98
99void SAL_CALL SwVbaRow::SetHeight( float height, sal_Int32 heightrule )
100{
101 setHeightRule( heightrule );
102 setHeight( uno::Any( height ) );
103}
104
105OUString
107{
108 return "SwVbaRow";
109}
110
111uno::Sequence< OUString >
113{
114 static uno::Sequence< OUString > const aServiceNames
115 {
116 "ooo.vba.word.Row"
117 };
118 return aServiceNames;
119}
120
121/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::uno::XComponentContext > mxContext
sal_Int32 mnIndex
Definition: vbarow.hxx:35
css::uno::Reference< css::table::XTableRows > mxTableRows
Definition: vbarow.hxx:33
virtual void SAL_CALL setHeightRule(::sal_Int32 _heightrule) override
Definition: vbarow.cxx:70
static void SelectRow(const css::uno::Reference< css::frame::XModel > &xModel, const css::uno::Reference< css::text::XTextTable > &xTextTable, sal_Int32 nStartRow, sal_Int32 nEndRow)
Definition: vbarow.cxx:82
virtual void SAL_CALL Select() override
Definition: vbarow.cxx:77
virtual ::sal_Int32 SAL_CALL getHeightRule() override
Definition: vbarow.cxx:63
virtual ~SwVbaRow() override
Definition: vbarow.cxx:40
virtual OUString getServiceImplName() override
Definition: vbarow.cxx:106
virtual void SAL_CALL SetHeight(float height, sal_Int32 heightrule) override
Definition: vbarow.cxx:99
SwVbaRow(const css::uno::Reference< ooo::vba::XHelperInterface > &rParent, const css::uno::Reference< css::uno::XComponentContext > &rContext, css::uno::Reference< css::text::XTextTable > xTextTable, sal_Int32 nIndex)
Definition: vbarow.cxx:33
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbarow.cxx:112
css::uno::Reference< css::text::XTextTable > mxTextTable
Definition: vbarow.hxx:32
virtual void SAL_CALL setHeight(const css::uno::Any &_height) override
Definition: vbarow.cxx:54
virtual css::uno::Any SAL_CALL getHeight() override
Definition: vbarow.cxx:44
css::uno::Reference< css::beans::XPropertySet > mxRowProps
Definition: vbarow.hxx:34
sal_Int32 getTabColumnsCount(sal_Int32 nRowIndex)
static OUString getColumnStr(sal_Int32 nCol)
Sequence< OUString > aServiceNames
sal_Int32 nIndex
VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentWordDoc(const css::uno::Reference< css::uno::XComponentContext > &xContext)
Reference< XModel > xModel
sal_uInt32 mnIndex