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