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