LibreOffice Module sw (master)  1
vbacells.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 "vbacells.hxx"
20 #include "vbacell.hxx"
21 #include "wordvbahelper.hxx"
22 #include "vbatablehelper.hxx"
23 #include "vbarow.hxx"
24 #include <cppuhelper/implbase.hxx>
25 
26 using namespace ::ooo::vba;
27 using namespace ::com::sun::star;
28 
30 {
31  uno::Reference< container::XIndexAccess > mxIndexAccess;
32  sal_Int32 nIndex;
33 
34 public:
35  explicit CellsEnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess ) : mxIndexAccess( xIndexAccess ), nIndex( 0 )
36  {
37  }
38  virtual sal_Bool SAL_CALL hasMoreElements( ) override
39  {
40  return ( nIndex < mxIndexAccess->getCount() );
41  }
42 
43  virtual uno::Any SAL_CALL nextElement( ) override
44  {
45  if( nIndex < mxIndexAccess->getCount() )
46  {
47  return mxIndexAccess->getByIndex( nIndex++ );
48  }
49  throw container::NoSuchElementException();
50  }
51 };
52 
53 class CellCollectionHelper : public ::cppu::WeakImplHelper< container::XIndexAccess,
54  container::XEnumerationAccess >
55 {
56 private:
57  uno::Reference< XHelperInterface > mxParent;
58  uno::Reference< uno::XComponentContext > mxContext;
59  uno::Reference< css::text::XTextTable > mxTextTable;
60  sal_Int32 const mnLeft;
61  sal_Int32 const mnTop;
62  sal_Int32 const mnRight;
63  sal_Int32 const mnBottom;
64 
65 public:
67  CellCollectionHelper( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::text::XTextTable >& xTextTable, sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ): mxParent( xParent ), mxContext( xContext ), mxTextTable( xTextTable ), mnLeft( nLeft ), mnTop( nTop ), mnRight( nRight ), mnBottom( nBottom )
68  {
69  }
70 
71  virtual sal_Int32 SAL_CALL getCount( ) override
72  {
73  return ( mnRight - mnLeft + 1 ) * ( mnBottom - mnTop + 1 );
74  }
75  virtual uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override
76  {
78  throw css::lang::IndexOutOfBoundsException();
79 
80  for( sal_Int32 row = mnTop; row <= mnBottom; row++ )
81  {
82  for( sal_Int32 col = mnLeft; col <= mnRight; col++ )
83  {
84  if( Index == ( ( row - mnTop ) * ( mnRight - mnLeft + 1 ) + ( col - mnLeft ) ) )
85  return uno::makeAny( uno::Reference< word::XCell >( new SwVbaCell( mxParent, mxContext, mxTextTable, col, row ) ) );
86  }
87  }
88  throw css::lang::IndexOutOfBoundsException();
89 
90  }
91  virtual uno::Type SAL_CALL getElementType( ) override
92  {
94  }
95  virtual sal_Bool SAL_CALL hasElements( ) override
96  {
97  return true;
98  }
99  // XEnumerationAccess
100  virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) override
101  {
102  return new CellsEnumWrapper( this );
103  }
104 };
105 
106 SwVbaCells::SwVbaCells( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< text::XTextTable >& xTextTable, sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ) : SwVbaCells_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( new CellCollectionHelper( xParent, xContext, xTextTable, nLeft, nTop, nRight, nBottom ) ) ), mxTextTable( xTextTable ), mnTop( nTop ), mnBottom( nBottom )
107 {
108 }
109 
110 ::sal_Int32 SAL_CALL SwVbaCells::getWidth()
111 {
112  uno::Reference< word::XCell > xCell( m_xIndexAccess->getByIndex( 0 ), uno::UNO_QUERY_THROW );
113  return xCell->getWidth();
114 }
115 
116 void SAL_CALL SwVbaCells::setWidth( ::sal_Int32 _width )
117 {
118  sal_Int32 nIndex = 0;
119  while( nIndex < m_xIndexAccess->getCount() )
120  {
121  uno::Reference< word::XCell > xCell( m_xIndexAccess->getByIndex( nIndex++ ), uno::UNO_QUERY_THROW );
122  xCell->setWidth( _width );
123  }
124 }
125 
127 {
128  uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, mnTop ) );
129  return xRow->getHeight();
130 }
131 
132 void SAL_CALL SwVbaCells::setHeight( const uno::Any& _height )
133 {
134  for( sal_Int32 row = mnTop; row <= mnBottom; row++ )
135  {
136  uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, row ) );
137  xRow->setHeight( _height );
138  }
139 }
140 
141 ::sal_Int32 SAL_CALL SwVbaCells::getHeightRule()
142 {
143  uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, mnTop ) );
144  return xRow->getHeightRule();
145 }
146 
147 void SAL_CALL SwVbaCells::setHeightRule( ::sal_Int32 _heightrule )
148 {
149  for( sal_Int32 row = mnTop; row <= mnBottom; row++ )
150  {
151  uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, row ) );
152  xRow->setHeightRule( _heightrule );
153  }
154 }
155 
156 void SAL_CALL SwVbaCells::SetWidth( float width, sal_Int32 rulestyle )
157 {
158  sal_Int32 nIndex = 0;
159  while( nIndex < m_xIndexAccess->getCount() )
160  {
161  uno::Reference< word::XCell > xCell( m_xIndexAccess->getByIndex( nIndex++ ), uno::UNO_QUERY_THROW );
162  xCell->SetWidth( width, rulestyle );
163  }
164 }
165 
166 void SAL_CALL SwVbaCells::SetHeight( float height, sal_Int32 heightrule )
167 {
168  for( sal_Int32 row = mnTop; row <= mnBottom; row++ )
169  {
170  uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, row ) );
171  xRow->SetHeight( height, heightrule );
172  }
173 }
174 
175 // XEnumerationAccess
176 uno::Type
178 {
180 }
181 
182 uno::Reference< container::XEnumeration >
184 {
185  uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
186  return xEnumAccess->createEnumeration();
187 }
188 
189 uno::Any
191 {
192  return aSource;
193 }
194 
195 OUString
197 {
198  return OUString("SwVbaCells");
199 }
200 
201 uno::Sequence<OUString>
203 {
204  static uno::Sequence< OUString > const sNames
205  {
206  "ooo.vba.word.Cells"
207  };
208  return sNames;
209 }
210 
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL setHeightRule(::sal_Int32 _heightrule) override
Definition: vbacells.cxx:147
sal_Int32 const mnLeft
Definition: vbacells.cxx:60
virtual ::sal_Int32 SAL_CALL getHeightRule() override
Definition: vbacells.cxx:141
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
Definition: vbacells.cxx:190
virtual ::sal_Int32 SAL_CALL getWidth() override
Definition: vbacells.cxx:110
css::uno::Reference< css::container::XIndexAccess > m_xIndexAccess
sal_Int32 const mnBottom
Definition: vbacells.hxx:34
uno::Reference< uno::XComponentContext > mxContext
Definition: vbacells.cxx:58
Reference
sal_Int32 const mnTop
Definition: vbacells.hxx:33
sal_Int32 const mnRight
Definition: vbacells.cxx:62
virtual sal_Bool SAL_CALL hasElements() override
Definition: vbacells.cxx:95
::cppu::WeakImplHelper< css::container::XEnumeration > EnumerationHelper_BASE
virtual uno::Any SAL_CALL nextElement() override
Definition: vbacells.cxx:43
virtual void SAL_CALL SetHeight(float height, sal_Int32 heightrule) override
Definition: vbacells.cxx:166
sal_Int32 mnBottom
SwVbaCells(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::text::XTextTable > &xTextTable, sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom)
Definition: vbacells.cxx:106
virtual OUString getServiceImplName() override
Definition: vbacells.cxx:196
sal_Int32 nIndex
Definition: vbacells.cxx:32
virtual uno::Type SAL_CALL getElementType() override
Definition: vbacells.cxx:91
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbacells.cxx:202
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
Definition: vbacells.cxx:183
sal_Int32 const mnBottom
Definition: vbacells.cxx:63
sal_Int32 const mnTop
Definition: vbacells.cxx:61
CellsEnumWrapper(const uno::Reference< container::XIndexAccess > &xIndexAccess)
Definition: vbacells.cxx:35
unsigned char sal_Bool
virtual void SAL_CALL setHeight(const css::uno::Any &_height) override
Definition: vbacells.cxx:132
virtual css::uno::Any SAL_CALL getHeight() override
Definition: vbacells.cxx:126
uno::Reference< XHelperInterface > mxParent
Definition: vbacells.cxx:57
virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration() override
Definition: vbacells.cxx:100
css::uno::Type const & get()
virtual sal_Bool SAL_CALL hasMoreElements() override
Definition: vbacells.cxx:38
virtual void SAL_CALL setWidth(::sal_Int32 _width) override
Definition: vbacells.cxx:116
sal_Int32 mnTop
virtual sal_Int32 SAL_CALL getCount() override
Definition: vbacells.cxx:71
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent() override
virtual css::uno::Type SAL_CALL getElementType() override
Definition: vbacells.cxx:177
uno::Reference< container::XIndexAccess > mxIndexAccess
Definition: vbacells.cxx:31
css::uno::Reference< css::text::XTextTable > mxTextTable
Definition: vbacells.hxx:32
uno::Reference< css::text::XTextTable > mxTextTable
Definition: vbacells.cxx:59
virtual uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
Definition: vbacells.cxx:75
virtual void SAL_CALL SetWidth(float width, sal_Int32 rulestyle) override
Definition: vbacells.cxx:156
CellCollectionHelper(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::text::XTextTable > &xTextTable, sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom)
Definition: vbacells.cxx:67
virtual ::sal_Int32 SAL_CALL getCount() override