1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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"
30 using namespace ::ooo::vba
;
31 using namespace ::com::sun::star
;
33 SwVbaRow::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
)
36 mxTableRows
= mxTextTable
->getRows();
37 mxRowProps
.set( mxTableRows
->getByIndex( mnIndex
), uno::UNO_QUERY_THROW
);
44 uno::Any SAL_CALL
SwVbaRow::getHeight()
46 if( getHeightRule() == word::WdRowHeightRule::wdRowHeightAuto
)
47 return uno::Any( sal_Int32( word::WdConstants::wdUndefined
) );
49 sal_Int32 nHeight
= 0;
50 mxRowProps
->getPropertyValue("Height") >>= nHeight
;
51 return uno::Any( static_cast<float>(Millimeter::getInPoints( nHeight
)) );
54 void SAL_CALL
SwVbaRow::setHeight( const uno::Any
& _height
)
59 sal_Int32 nHeight
= Millimeter::getInHundredthsOfOneMillimeter( height
);
60 mxRowProps
->setPropertyValue("Height", uno::Any( nHeight
) );
63 ::sal_Int32 SAL_CALL
SwVbaRow::getHeightRule()
65 bool isAutoHeight
= false;
66 mxRowProps
->getPropertyValue("IsAutoHeight") >>= isAutoHeight
;
67 return isAutoHeight
? word::WdRowHeightRule::wdRowHeightAuto
: word::WdRowHeightRule::wdRowHeightExactly
;
70 void SAL_CALL
SwVbaRow::setHeightRule( ::sal_Int32 _heightrule
)
72 bool isAutoHeight
= ( _heightrule
== word::WdRowHeightRule::wdRowHeightAuto
);
73 mxRowProps
->setPropertyValue("IsAutoHeight", uno::Any( isAutoHeight
) );
79 SelectRow( getCurrentWordDoc(mxContext
), mxTextTable
, mnIndex
, mnIndex
);
82 void SwVbaRow::SelectRow( const uno::Reference
< frame::XModel
>& xModel
, const uno::Reference
< text::XTextTable
>& xTextTable
, sal_Int32 nStartRow
, sal_Int32 nEndRow
)
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);
92 uno::Reference
< table::XCellRange
> xCellRange( xTextTable
, uno::UNO_QUERY_THROW
);
93 uno::Reference
< table::XCellRange
> xSelRange
= xCellRange
->getCellRangeByName( sRangeName
);
95 uno::Reference
< view::XSelectionSupplier
> xSelection( xModel
->getCurrentController(), uno::UNO_QUERY_THROW
);
96 xSelection
->select( uno::Any( xSelRange
) );
99 void SAL_CALL
SwVbaRow::SetHeight( float height
, sal_Int32 heightrule
)
101 setHeightRule( heightrule
);
102 setHeight( uno::Any( height
) );
106 SwVbaRow::getServiceImplName()
111 uno::Sequence
< OUString
>
112 SwVbaRow::getServiceNames()
114 static uno::Sequence
< OUString
> const aServiceNames
118 return aServiceNames
;
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */