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