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 .
19 #include "vbacells.hxx"
20 #include "vbacell.hxx"
22 #include <cppuhelper/implbase.hxx>
25 using namespace ::ooo::vba
;
26 using namespace ::com::sun::star
;
30 class CellsEnumWrapper
: public EnumerationHelper_BASE
32 uno::Reference
< container::XIndexAccess
> mxIndexAccess
;
36 explicit CellsEnumWrapper( uno::Reference
< container::XIndexAccess
> xIndexAccess
) : mxIndexAccess(std::move( xIndexAccess
)), mnIndex( 0 )
39 virtual sal_Bool SAL_CALL
hasMoreElements( ) override
41 return ( mnIndex
< mxIndexAccess
->getCount() );
44 virtual uno::Any SAL_CALL
nextElement( ) override
46 if( mnIndex
< mxIndexAccess
->getCount() )
48 return mxIndexAccess
->getByIndex( mnIndex
++ );
50 throw container::NoSuchElementException();
54 class CellCollectionHelper
: public ::cppu::WeakImplHelper
< container::XIndexAccess
,
55 container::XEnumerationAccess
>
58 uno::Reference
< XHelperInterface
> mxParent
;
59 uno::Reference
< uno::XComponentContext
> mxContext
;
60 uno::Reference
< css::text::XTextTable
> mxTextTable
;
67 /// @throws css::uno::RuntimeException
68 CellCollectionHelper( css::uno::Reference
< ov::XHelperInterface
> xParent
, css::uno::Reference
< css::uno::XComponentContext
> xContext
, css::uno::Reference
< css::text::XTextTable
> xTextTable
, sal_Int32 nLeft
, sal_Int32 nTop
, sal_Int32 nRight
, sal_Int32 nBottom
): mxParent(std::move( xParent
)), mxContext(std::move( xContext
)), mxTextTable(std::move( xTextTable
)), mnLeft( nLeft
), mnTop( nTop
), mnRight( nRight
), mnBottom( nBottom
)
72 virtual sal_Int32 SAL_CALL
getCount( ) override
74 return ( mnRight
- mnLeft
+ 1 ) * ( mnBottom
- mnTop
+ 1 );
76 virtual uno::Any SAL_CALL
getByIndex( sal_Int32 Index
) override
78 if ( Index
< 0 || Index
>= getCount() )
79 throw css::lang::IndexOutOfBoundsException();
81 for( sal_Int32 row
= mnTop
; row
<= mnBottom
; row
++ )
83 for( sal_Int32 col
= mnLeft
; col
<= mnRight
; col
++ )
85 if( Index
== ( ( row
- mnTop
) * ( mnRight
- mnLeft
+ 1 ) + ( col
- mnLeft
) ) )
86 return uno::Any( uno::Reference
< word::XCell
>( new SwVbaCell( mxParent
, mxContext
, mxTextTable
, col
, row
) ) );
89 throw css::lang::IndexOutOfBoundsException();
92 virtual uno::Type SAL_CALL
getElementType( ) override
94 return cppu::UnoType
<word::XCell
>::get();
96 virtual sal_Bool SAL_CALL
hasElements( ) override
100 // XEnumerationAccess
101 virtual uno::Reference
< container::XEnumeration
> SAL_CALL
createEnumeration( ) override
103 return new CellsEnumWrapper( this );
109 SwVbaCells::SwVbaCells( const uno::Reference
< XHelperInterface
>& xParent
, const uno::Reference
< uno::XComponentContext
> & xContext
, const uno::Reference
< text::XTextTable
>& xTextTable
, sal_Int32 nLeft
, sal_Int32 nTop
, sal_Int32 nRight
, sal_Int32 nBottom
) : SwVbaCells_BASE( xParent
, xContext
, uno::Reference
< container::XIndexAccess
>( new CellCollectionHelper( xParent
, xContext
, xTextTable
, nLeft
, nTop
, nRight
, nBottom
) ) ), mxTextTable( xTextTable
), mnTop( nTop
), mnBottom( nBottom
)
113 ::sal_Int32 SAL_CALL
SwVbaCells::getWidth()
115 uno::Reference
< word::XCell
> xCell( m_xIndexAccess
->getByIndex( 0 ), uno::UNO_QUERY_THROW
);
116 return xCell
->getWidth();
119 void SAL_CALL
SwVbaCells::setWidth( ::sal_Int32 _width
)
121 sal_Int32 nIndex
= 0;
122 while( nIndex
< m_xIndexAccess
->getCount() )
124 uno::Reference
< word::XCell
> xCell( m_xIndexAccess
->getByIndex( nIndex
++ ), uno::UNO_QUERY_THROW
);
125 xCell
->setWidth( _width
);
129 uno::Any SAL_CALL
SwVbaCells::getHeight()
131 uno::Reference
< word::XRow
> xRow( new SwVbaRow( getParent(), mxContext
, mxTextTable
, mnTop
) );
132 return xRow
->getHeight();
135 void SAL_CALL
SwVbaCells::setHeight( const uno::Any
& _height
)
137 for( sal_Int32 row
= mnTop
; row
<= mnBottom
; row
++ )
139 uno::Reference
< word::XRow
> xRow( new SwVbaRow( getParent(), mxContext
, mxTextTable
, row
) );
140 xRow
->setHeight( _height
);
144 ::sal_Int32 SAL_CALL
SwVbaCells::getHeightRule()
146 uno::Reference
< word::XRow
> xRow( new SwVbaRow( getParent(), mxContext
, mxTextTable
, mnTop
) );
147 return xRow
->getHeightRule();
150 void SAL_CALL
SwVbaCells::setHeightRule( ::sal_Int32 _heightrule
)
152 for( sal_Int32 row
= mnTop
; row
<= mnBottom
; row
++ )
154 uno::Reference
< word::XRow
> xRow( new SwVbaRow( getParent(), mxContext
, mxTextTable
, row
) );
155 xRow
->setHeightRule( _heightrule
);
159 void SAL_CALL
SwVbaCells::SetWidth( float width
, sal_Int32 rulestyle
)
161 sal_Int32 nIndex
= 0;
162 while( nIndex
< m_xIndexAccess
->getCount() )
164 uno::Reference
< word::XCell
> xCell( m_xIndexAccess
->getByIndex( nIndex
++ ), uno::UNO_QUERY_THROW
);
165 xCell
->SetWidth( width
, rulestyle
);
169 void SAL_CALL
SwVbaCells::SetHeight( float height
, sal_Int32 heightrule
)
171 for( sal_Int32 row
= mnTop
; row
<= mnBottom
; row
++ )
173 uno::Reference
< word::XRow
> xRow( new SwVbaRow( getParent(), mxContext
, mxTextTable
, row
) );
174 xRow
->SetHeight( height
, heightrule
);
178 // XEnumerationAccess
180 SwVbaCells::getElementType()
182 return cppu::UnoType
<word::XCell
>::get();
185 uno::Reference
< container::XEnumeration
>
186 SwVbaCells::createEnumeration()
188 uno::Reference
< container::XEnumerationAccess
> xEnumAccess( m_xIndexAccess
, uno::UNO_QUERY_THROW
);
189 return xEnumAccess
->createEnumeration();
193 SwVbaCells::createCollectionObject( const uno::Any
& aSource
)
199 SwVbaCells::getServiceImplName()
204 uno::Sequence
<OUString
>
205 SwVbaCells::getServiceNames()
207 static uno::Sequence
< OUString
> const sNames
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */