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 "vbarow.hxx"
22 #include <cppuhelper/implbase.hxx>
23 
24 using namespace ::ooo::vba;
25 using namespace ::com::sun::star;
26 
27 namespace {
28 
29 class CellsEnumWrapper : public EnumerationHelper_BASE
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 mnLeft;
61  sal_Int32 mnTop;
62  sal_Int32 mnRight;
63  sal_Int32 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  {
77  if ( Index < 0 || Index >= getCount() )
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 }
107 
108 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 )
109 {
110 }
111 
112 ::sal_Int32 SAL_CALL SwVbaCells::getWidth()
113 {
114  uno::Reference< word::XCell > xCell( m_xIndexAccess->getByIndex( 0 ), uno::UNO_QUERY_THROW );
115  return xCell->getWidth();
116 }
117 
118 void SAL_CALL SwVbaCells::setWidth( ::sal_Int32 _width )
119 {
120  sal_Int32 nIndex = 0;
121  while( nIndex < m_xIndexAccess->getCount() )
122  {
123  uno::Reference< word::XCell > xCell( m_xIndexAccess->getByIndex( nIndex++ ), uno::UNO_QUERY_THROW );
124  xCell->setWidth( _width );
125  }
126 }
127 
129 {
130  uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, mnTop ) );
131  return xRow->getHeight();
132 }
133 
134 void SAL_CALL SwVbaCells::setHeight( const uno::Any& _height )
135 {
136  for( sal_Int32 row = mnTop; row <= mnBottom; row++ )
137  {
138  uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, row ) );
139  xRow->setHeight( _height );
140  }
141 }
142 
143 ::sal_Int32 SAL_CALL SwVbaCells::getHeightRule()
144 {
145  uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, mnTop ) );
146  return xRow->getHeightRule();
147 }
148 
149 void SAL_CALL SwVbaCells::setHeightRule( ::sal_Int32 _heightrule )
150 {
151  for( sal_Int32 row = mnTop; row <= mnBottom; row++ )
152  {
153  uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, row ) );
154  xRow->setHeightRule( _heightrule );
155  }
156 }
157 
158 void SAL_CALL SwVbaCells::SetWidth( float width, sal_Int32 rulestyle )
159 {
160  sal_Int32 nIndex = 0;
161  while( nIndex < m_xIndexAccess->getCount() )
162  {
163  uno::Reference< word::XCell > xCell( m_xIndexAccess->getByIndex( nIndex++ ), uno::UNO_QUERY_THROW );
164  xCell->SetWidth( width, rulestyle );
165  }
166 }
167 
168 void SAL_CALL SwVbaCells::SetHeight( float height, sal_Int32 heightrule )
169 {
170  for( sal_Int32 row = mnTop; row <= mnBottom; row++ )
171  {
172  uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, row ) );
173  xRow->SetHeight( height, heightrule );
174  }
175 }
176 
177 // XEnumerationAccess
178 uno::Type
180 {
182 }
183 
184 uno::Reference< container::XEnumeration >
186 {
187  uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
188  return xEnumAccess->createEnumeration();
189 }
190 
191 uno::Any
193 {
194  return aSource;
195 }
196 
197 OUString
199 {
200  return "SwVbaCells";
201 }
202 
203 uno::Sequence<OUString>
205 {
206  static uno::Sequence< OUString > const sNames
207  {
208  "ooo.vba.word.Cells"
209  };
210  return sNames;
211 }
212 
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL setHeightRule(::sal_Int32 _heightrule) override
Definition: vbacells.cxx:149
sal_Int32 mnRight
sal_Int32 nIndex
sal_Int32 mnLeft
virtual ::sal_Int32 SAL_CALL getHeightRule() override
Definition: vbacells.cxx:143
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
Definition: vbacells.cxx:192
virtual ::sal_Int32 SAL_CALL getWidth() override
Definition: vbacells.cxx:112
css::uno::Reference< css::container::XIndexAccess > m_xIndexAccess
uno::Reference< uno::XComponentContext > mxContext
WeakReference< XInterface > mxParent
Reference
sal_Int32 mnBottom
Definition: vbacells.hxx:33
::cppu::WeakImplHelper< css::container::XEnumeration > EnumerationHelper_BASE
virtual void SAL_CALL SetHeight(float height, sal_Int32 heightrule) override
Definition: vbacells.cxx:168
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:108
virtual OUString getServiceImplName() override
Definition: vbacells.cxx:198
uno::Reference< sdbc::XRow > xRow
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbacells.cxx:204
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
Definition: vbacells.cxx:185
unsigned char sal_Bool
virtual void SAL_CALL setHeight(const css::uno::Any &_height) override
Definition: vbacells.cxx:134
virtual css::uno::Any SAL_CALL getHeight() override
Definition: vbacells.cxx:128
css::uno::Type const & get()
virtual void SAL_CALL setWidth(::sal_Int32 _width) override
Definition: vbacells.cxx:118
sal_Int32 mnTop
virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent() override
virtual css::uno::Type SAL_CALL getElementType() override
Definition: vbacells.cxx:179
virtual void SAL_CALL SetWidth(float width, sal_Int32 rulestyle) override
Definition: vbacells.cxx:158
struct _ADOIndex Index
virtual ::sal_Int32 SAL_CALL getCount() override