ITEM: Refactor ItemType
[LibreOffice.git] / sw / source / ui / vba / vbarow.cxx
blob7b63286ab63c81094dce13c81e413a4031db1624
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #include "vbarow.hxx"
20 #include <utility>
21 #include <vbahelper/vbahelper.hxx>
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 #include "wordvbahelper.hxx"
30 #include <unotxdoc.hxx>
32 using namespace ::ooo::vba;
33 using namespace ::ooo::vba::word;
34 using namespace ::com::sun::star;
36 SwVbaRow::SwVbaRow( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext,uno::Reference< text::XTextTable > xTextTable, sal_Int32 nIndex ) :
37 SwVbaRow_BASE( rParent, rContext ), mxTextTable(std::move( xTextTable )), mnIndex( nIndex )
39 mxTableRows = mxTextTable->getRows();
40 mxRowProps.set( mxTableRows->getByIndex( mnIndex ), uno::UNO_QUERY_THROW );
43 SwVbaRow::~SwVbaRow()
47 uno::Any SAL_CALL SwVbaRow::getHeight()
49 if( getHeightRule() == word::WdRowHeightRule::wdRowHeightAuto )
50 return uno::Any( sal_Int32( word::WdConstants::wdUndefined ) );
52 sal_Int32 nHeight = 0;
53 mxRowProps->getPropertyValue(u"Height"_ustr) >>= nHeight;
54 return uno::Any( static_cast<float>(Millimeter::getInPoints( nHeight )) );
57 void SAL_CALL SwVbaRow::setHeight( const uno::Any& _height )
59 float height = 0;
60 _height >>= height;
62 sal_Int32 nHeight = Millimeter::getInHundredthsOfOneMillimeter( height );
63 mxRowProps->setPropertyValue(u"Height"_ustr, uno::Any( nHeight ) );
66 ::sal_Int32 SAL_CALL SwVbaRow::getHeightRule()
68 bool isAutoHeight = false;
69 mxRowProps->getPropertyValue(u"IsAutoHeight"_ustr) >>= isAutoHeight;
70 return isAutoHeight ? word::WdRowHeightRule::wdRowHeightAuto : word::WdRowHeightRule::wdRowHeightExactly;
73 void SAL_CALL SwVbaRow::setHeightRule( ::sal_Int32 _heightrule )
75 bool isAutoHeight = ( _heightrule == word::WdRowHeightRule::wdRowHeightAuto );
76 mxRowProps->setPropertyValue(u"IsAutoHeight"_ustr, uno::Any( isAutoHeight ) );
79 void SAL_CALL
80 SwVbaRow::Select( )
82 SelectRow( getCurrentWordDoc(mxContext), mxTextTable, mnIndex, mnIndex );
85 void SwVbaRow::SelectRow( const rtl::Reference< SwXTextDocument >& xModel, const uno::Reference< text::XTextTable >& xTextTable, sal_Int32 nStartRow, sal_Int32 nEndRow )
87 OUString sRangeName = "A" + OUString::number(nStartRow + 1);
88 SwVbaTableHelper aTableHelper( xTextTable );
89 sal_Int32 nColCount = aTableHelper.getTabColumnsCount( nEndRow );
90 // FIXME: the column count > 26
91 //char cCol = 'A' + nColCount - 1;
92 OUString sCol = SwVbaTableHelper::getColumnStr( nColCount - 1);
93 sRangeName += ":" + sCol + OUString::number(nEndRow + 1);
95 uno::Reference< table::XCellRange > xCellRange( xTextTable, uno::UNO_QUERY_THROW );
96 uno::Reference< table::XCellRange > xSelRange = xCellRange->getCellRangeByName( sRangeName );
98 uno::Reference< view::XSelectionSupplier > xSelection( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
99 xSelection->select( uno::Any( xSelRange ) );
102 void SAL_CALL SwVbaRow::SetHeight( float height, sal_Int32 heightrule )
104 setHeightRule( heightrule );
105 setHeight( uno::Any( height ) );
108 OUString
109 SwVbaRow::getServiceImplName()
111 return u"SwVbaRow"_ustr;
114 uno::Sequence< OUString >
115 SwVbaRow::getServiceNames()
117 static uno::Sequence< OUString > const aServiceNames
119 u"ooo.vba.word.Row"_ustr
121 return aServiceNames;
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */