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