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 "vbacolumns.hxx"
22 #include "vbacolumn.hxx"
23 #include "vbatablehelper.hxx"
25 using namespace ::ooo::vba
;
26 using namespace ::com::sun::star
;
30 class ColumnsEnumWrapper
: public EnumerationHelper_BASE
32 uno::WeakReference
< XHelperInterface
> mxParent
;
33 uno::Reference
< uno::XComponentContext
> mxContext
;
34 uno::Reference
< text::XTextTable
> mxTextTable
;
35 uno::Reference
< container::XIndexAccess
> mxIndexAccess
;
39 ColumnsEnumWrapper( const uno::Reference
< XHelperInterface
>& xParent
, uno::Reference
< uno::XComponentContext
> xContext
, uno::Reference
< text::XTextTable
> xTextTable
) : mxParent( xParent
), mxContext(std::move( xContext
)), mxTextTable(std::move( xTextTable
)), mnIndex( 0 )
41 mxIndexAccess
= mxTextTable
->getColumns();
43 virtual sal_Bool SAL_CALL
hasMoreElements( ) override
45 return ( mnIndex
< mxIndexAccess
->getCount() );
48 virtual uno::Any SAL_CALL
nextElement( ) override
50 if( mnIndex
< mxIndexAccess
->getCount() )
52 return uno::Any( uno::Reference
< word::XColumn
> ( new SwVbaColumn( mxParent
, mxContext
, mxTextTable
, mnIndex
++ ) ) );
54 throw container::NoSuchElementException();
60 SwVbaColumns::SwVbaColumns( const uno::Reference
< XHelperInterface
>& xParent
, const uno::Reference
< uno::XComponentContext
> & xContext
, uno::Reference
< text::XTextTable
> xTextTable
, const uno::Reference
< table::XTableColumns
>& xTableColumns
) : SwVbaColumns_BASE( xParent
, xContext
, uno::Reference
< container::XIndexAccess
>( xTableColumns
, uno::UNO_QUERY_THROW
) ), mxTextTable(std::move( xTextTable
))
62 mnStartColumnIndex
= 0;
63 SwVbaTableHelper
aTableHelper( mxTextTable
);
64 mnEndColumnIndex
= aTableHelper
.getTabColumnsMaxCount( ) - 1;
67 SwVbaColumns::SwVbaColumns( const uno::Reference
< XHelperInterface
>& xParent
, const uno::Reference
< uno::XComponentContext
> & xContext
, uno::Reference
< text::XTextTable
> xTextTable
, const uno::Reference
< table::XTableColumns
>& xTableColumns
, sal_Int32 nStartCol
, sal_Int32 nEndCol
) : SwVbaColumns_BASE( xParent
, xContext
, uno::Reference
< container::XIndexAccess
>( xTableColumns
, uno::UNO_QUERY_THROW
) ), mxTextTable(std::move( xTextTable
)), mnStartColumnIndex( nStartCol
), mnEndColumnIndex( nEndCol
)
69 if( mnEndColumnIndex
< mnStartColumnIndex
)
70 throw uno::RuntimeException();
73 uno::Reference
< word::XColumn
> SwVbaColumns::getColumnAtIndex( sal_Int32 index
)
75 return uno::Reference
< word::XColumn
>( new SwVbaColumn( this, mxContext
, mxTextTable
, index
) );
78 ::sal_Int32 SAL_CALL
SwVbaColumns::getWidth()
80 return getColumnAtIndex( mnStartColumnIndex
)->getWidth();
83 void SAL_CALL
SwVbaColumns::setWidth( ::sal_Int32 _width
)
85 for( sal_Int32 index
= mnStartColumnIndex
; index
<= mnEndColumnIndex
; index
++ )
87 getColumnAtIndex( index
)->setWidth( _width
);
91 void SAL_CALL
SwVbaColumns::Select( )
93 SwVbaColumn::SelectColumn( getCurrentWordDoc(mxContext
), mxTextTable
, mnStartColumnIndex
, mnEndColumnIndex
);
96 ::sal_Int32 SAL_CALL
SwVbaColumns::getCount()
98 return ( mnEndColumnIndex
- mnStartColumnIndex
+ 1 );
101 uno::Any SAL_CALL
SwVbaColumns::Item( const uno::Any
& Index1
, const uno::Any
& /*not processed in this base class*/ )
103 sal_Int32 nIndex
= 0;
104 if( Index1
>>= nIndex
)
106 if( nIndex
<= 0 || nIndex
> getCount() )
108 throw lang::IndexOutOfBoundsException("Index out of bounds" );
110 return uno::Any( uno::Reference
< word::XColumn
>( new SwVbaColumn( this, mxContext
, mxTextTable
, nIndex
- 1 ) ) );
112 throw uno::RuntimeException("Index out of bounds" );
115 // XEnumerationAccess
117 SwVbaColumns::getElementType()
119 return cppu::UnoType
<word::XColumn
>::get();
121 uno::Reference
< container::XEnumeration
>
122 SwVbaColumns::createEnumeration()
124 return new ColumnsEnumWrapper( this, mxContext
, mxTextTable
);
128 SwVbaColumns::createCollectionObject( const uno::Any
& aSource
)
134 SwVbaColumns::getServiceImplName()
136 return "SwVbaColumns";
139 uno::Sequence
<OUString
>
140 SwVbaColumns::getServiceNames()
142 static uno::Sequence
< OUString
> const sNames
144 "ooo.vba.word.Columns"
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */