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