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