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