LibreOffice Module sw (master) 1
vbacolumns.cxx
Go to the documentation of this file.
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 <utility>
20
21#include "vbacolumns.hxx"
22#include "vbacolumn.hxx"
23#include "vbatablehelper.hxx"
24
25using namespace ::ooo::vba;
26using namespace ::com::sun::star;
27
28namespace {
29
30class ColumnsEnumWrapper : public EnumerationHelper_BASE
31{
32 uno::WeakReference< XHelperInterface > mxParent;
33 uno::Reference< uno::XComponentContext > mxContext;
34 uno::Reference< text::XTextTable > mxTextTable;
35 uno::Reference< container::XIndexAccess > mxIndexAccess;
36 sal_Int32 mnIndex;
37
38public:
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 )
40 {
41 mxIndexAccess = mxTextTable->getColumns();
42 }
43 virtual sal_Bool SAL_CALL hasMoreElements( ) override
44 {
45 return ( mnIndex < mxIndexAccess->getCount() );
46 }
47
48 virtual uno::Any SAL_CALL nextElement( ) override
49 {
50 if( mnIndex < mxIndexAccess->getCount() )
51 {
52 return uno::Any( uno::Reference< word::XColumn > ( new SwVbaColumn( mxParent, mxContext, mxTextTable, mnIndex++ ) ) );
53 }
54 throw container::NoSuchElementException();
55 }
56};
57
58}
59
60SwVbaColumns::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 ))
61{
62 mnStartColumnIndex = 0;
63 SwVbaTableHelper aTableHelper( mxTextTable );
64 mnEndColumnIndex = aTableHelper.getTabColumnsMaxCount( ) - 1;
65}
66
67SwVbaColumns::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 )
68{
69 if( mnEndColumnIndex < mnStartColumnIndex )
70 throw uno::RuntimeException();
71}
72
73uno::Reference< word::XColumn > SwVbaColumns::getColumnAtIndex( sal_Int32 index )
74{
75 return uno::Reference< word::XColumn >( new SwVbaColumn( this, mxContext, mxTextTable, index ) );
76}
77
78::sal_Int32 SAL_CALL SwVbaColumns::getWidth()
79{
80 return getColumnAtIndex( mnStartColumnIndex )->getWidth();
81}
82
83void SAL_CALL SwVbaColumns::setWidth( ::sal_Int32 _width )
84{
85 for( sal_Int32 index = mnStartColumnIndex; index <= mnEndColumnIndex; index++ )
86 {
87 getColumnAtIndex( index )->setWidth( _width );
88 }
89}
90
91void SAL_CALL SwVbaColumns::Select( )
92{
94}
95
96::sal_Int32 SAL_CALL SwVbaColumns::getCount()
97{
98 return ( mnEndColumnIndex - mnStartColumnIndex + 1 );
99}
100
101uno::Any SAL_CALL SwVbaColumns::Item( const uno::Any& Index1, const uno::Any& /*not processed in this base class*/ )
102{
103 sal_Int32 nIndex = 0;
104 if( Index1 >>= nIndex )
105 {
106 if( nIndex <= 0 || nIndex > getCount() )
107 {
108 throw lang::IndexOutOfBoundsException("Index out of bounds" );
109 }
110 return uno::Any( uno::Reference< word::XColumn >( new SwVbaColumn( this, mxContext, mxTextTable, nIndex - 1 ) ) );
111 }
112 throw uno::RuntimeException("Index out of bounds" );
113}
114
115// XEnumerationAccess
118{
120}
121uno::Reference< container::XEnumeration >
123{
124 return new ColumnsEnumWrapper( this, mxContext, mxTextTable );
125}
126
129{
130 return aSource;
131}
132
133OUString
135{
136 return "SwVbaColumns";
137}
138
139uno::Sequence<OUString>
141{
142 static uno::Sequence< OUString > const sNames
143 {
144 "ooo.vba.word.Columns"
145 };
146 return sNames;
147}
148
149/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
unotools::WeakReference< AnimationNode > mxParent
css::uno::Reference< css::uno::XComponentContext > mxContext
static void SelectColumn(const css::uno::Reference< css::frame::XModel > &xModel, const css::uno::Reference< css::text::XTextTable > &xTextTable, sal_Int32 nStartColumn, sal_Int32 nEndColumn)
Definition: vbacolumn.cxx:60
virtual sal_Int32 SAL_CALL getWidth() override
Definition: vbacolumns.cxx:78
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
Definition: vbacolumns.cxx:122
css::uno::Reference< css::text::XTextTable > mxTextTable
Definition: vbacolumns.hxx:33
SwVbaColumns(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, css::uno::Reference< css::text::XTextTable > xTextTable, const css::uno::Reference< css::table::XTableColumns > &xTableColumns)
virtual ::sal_Int32 SAL_CALL getCount() override
Definition: vbacolumns.cxx:96
virtual css::uno::Type SAL_CALL getElementType() override
Definition: vbacolumns.cxx:117
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbacolumns.cxx:140
sal_Int32 mnStartColumnIndex
Definition: vbacolumns.hxx:34
sal_Int32 mnEndColumnIndex
Definition: vbacolumns.hxx:35
virtual void SAL_CALL setWidth(sal_Int32 _width) override
Definition: vbacolumns.cxx:83
virtual OUString getServiceImplName() override
Definition: vbacolumns.cxx:134
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
Definition: vbacolumns.cxx:128
virtual void SAL_CALL Select() override
Definition: vbacolumns.cxx:91
css::uno::Reference< ooo::vba::word::XColumn > getColumnAtIndex(sal_Int32 index)
Definition: vbacolumns.cxx:73
virtual css::uno::Any SAL_CALL Item(const css::uno::Any &Index1, const css::uno::Any &) override
Definition: vbacolumns.cxx:101
css::uno::Type const & get()
uno::Reference< uno::XComponentContext > mxContext
sal_Int32 nIndex
Reference
index
VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentWordDoc(const css::uno::Reference< css::uno::XComponentContext > &xContext)
sal_uInt32 mnIndex
unsigned char sal_Bool
::cppu::WeakImplHelper< css::container::XEnumeration > EnumerationHelper_BASE