Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2008 by Sun Microsystems, Inc.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #include "vbacells.hxx"
29 : : #include "vbacell.hxx"
30 : : #include "wordvbahelper.hxx"
31 : : #include "vbatablehelper.hxx"
32 : : #include "vbarow.hxx"
33 : :
34 : : using namespace ::ooo::vba;
35 : : using namespace ::com::sun::star;
36 : :
37 : : typedef ::cppu::WeakImplHelper2< container::XIndexAccess, container::XEnumerationAccess > CellCollectionHelper_Base;
38 : :
39 [ # # ]: 0 : class CellsEnumWrapper : public EnumerationHelper_BASE
40 : : {
41 : : uno::Reference< container::XIndexAccess > mxIndexAccess;
42 : : sal_Int32 nIndex;
43 : :
44 : : public:
45 : 0 : CellsEnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess ) : mxIndexAccess( xIndexAccess ), nIndex( 0 )
46 : : {
47 : 0 : }
48 : 0 : virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException)
49 : : {
50 : 0 : return ( nIndex < mxIndexAccess->getCount() );
51 : : }
52 : :
53 : 0 : virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
54 : : {
55 [ # # ]: 0 : if( nIndex < mxIndexAccess->getCount() )
56 : : {
57 : 0 : return mxIndexAccess->getByIndex( nIndex++ );
58 : : }
59 [ # # ]: 0 : throw container::NoSuchElementException();
60 : : }
61 : : };
62 : :
63 : : class CellCollectionHelper : public CellCollectionHelper_Base
64 : : {
65 : : private:
66 : : uno::Reference< XHelperInterface > mxParent;
67 : : uno::Reference< uno::XComponentContext > mxContext;
68 : : uno::Reference< css::text::XTextTable > mxTextTable;
69 : : sal_Int32 mnLeft;
70 : : sal_Int32 mnTop;
71 : : sal_Int32 mnRight;
72 : : sal_Int32 mnBottom;
73 : :
74 : : public:
75 : 0 : 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 ) throw ( css::uno::RuntimeException ): mxParent( xParent ), mxContext( xContext ), mxTextTable( xTextTable ), mnLeft( nLeft ), mnTop( nTop ), mnRight( nRight ), mnBottom( nBottom )
76 : : {
77 : 0 : }
78 [ # # ]: 0 : virtual ~CellCollectionHelper() {}
79 : :
80 : 0 : virtual sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException)
81 : : {
82 : 0 : return ( mnRight - mnLeft + 1 ) * ( mnBottom - mnTop + 1 );
83 : : }
84 : 0 : virtual uno::Any SAL_CALL getByIndex( sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
85 : : {
86 [ # # ][ # # ]: 0 : if ( Index < 0 || Index >= getCount() )
[ # # ]
87 [ # # ]: 0 : throw css::lang::IndexOutOfBoundsException();
88 : :
89 [ # # ]: 0 : for( sal_Int32 row = mnTop; row <= mnBottom; row++ )
90 : : {
91 [ # # ]: 0 : for( sal_Int32 col = mnLeft; col <= mnRight; col++ )
92 : : {
93 [ # # ]: 0 : if( Index == ( ( row - mnTop ) * ( mnRight - mnLeft + 1 ) + ( col - mnLeft ) ) )
94 [ # # ][ # # ]: 0 : return uno::makeAny( uno::Reference< word::XCell >( new SwVbaCell( mxParent, mxContext, mxTextTable, col, row ) ) );
[ # # ]
95 : : }
96 : : }
97 [ # # ]: 0 : throw css::lang::IndexOutOfBoundsException();
98 : :
99 : : }
100 : 0 : virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException)
101 : : {
102 : 0 : return word::XCell::static_type(0);
103 : : }
104 : 0 : virtual sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException)
105 : : {
106 : 0 : return sal_True;
107 : : }
108 : : // XEnumerationAccess
109 : 0 : virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException)
110 : : {
111 [ # # ][ # # ]: 0 : return new CellsEnumWrapper( this );
[ # # ]
112 : : }
113 : : };
114 : :
115 [ # # ][ # # ]: 0 : 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 ) throw (uno::RuntimeException) : SwVbaCells_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( new CellCollectionHelper( xParent, xContext, xTextTable, nLeft, nTop, nRight, nBottom ) ) ), mxTextTable( xTextTable ), mnLeft( nLeft ), mnTop( nTop ), mnRight( nRight ), mnBottom( nBottom )
[ # # ]
116 : : {
117 : 0 : }
118 : :
119 : 0 : ::sal_Int32 SAL_CALL SwVbaCells::getWidth() throw (css::uno::RuntimeException)
120 : : {
121 [ # # ][ # # ]: 0 : uno::Reference< word::XCell > xCell( m_xIndexAccess->getByIndex( 0 ), uno::UNO_QUERY_THROW );
[ # # ]
122 [ # # ][ # # ]: 0 : return xCell->getWidth();
123 : : }
124 : :
125 : 0 : void SAL_CALL SwVbaCells::setWidth( ::sal_Int32 _width ) throw (css::uno::RuntimeException)
126 : : {
127 : 0 : sal_Int32 nIndex = 0;
128 [ # # ]: 0 : while( nIndex < m_xIndexAccess->getCount() )
129 : : {
130 [ # # ][ # # ]: 0 : uno::Reference< word::XCell > xCell( m_xIndexAccess->getByIndex( nIndex++ ), uno::UNO_QUERY_THROW );
[ # # ]
131 [ # # ][ # # ]: 0 : xCell->setWidth( _width );
132 : 0 : }
133 : 0 : }
134 : :
135 : 0 : uno::Any SAL_CALL SwVbaCells::getHeight() throw (css::uno::RuntimeException)
136 : : {
137 [ # # ][ # # ]: 0 : uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, mnTop ) );
[ # # ][ # # ]
138 [ # # ][ # # ]: 0 : return xRow->getHeight();
139 : : }
140 : :
141 : 0 : void SAL_CALL SwVbaCells::setHeight( const uno::Any& _height ) throw (css::uno::RuntimeException)
142 : : {
143 [ # # ]: 0 : for( sal_Int32 row = mnTop; row <= mnBottom; row++ )
144 : : {
145 [ # # ][ # # ]: 0 : uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, row ) );
[ # # ][ # # ]
146 [ # # ][ # # ]: 0 : xRow->setHeight( _height );
147 : 0 : }
148 : 0 : }
149 : :
150 : 0 : ::sal_Int32 SAL_CALL SwVbaCells::getHeightRule() throw (css::uno::RuntimeException)
151 : : {
152 [ # # ][ # # ]: 0 : uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, mnTop ) );
[ # # ][ # # ]
153 [ # # ][ # # ]: 0 : return xRow->getHeightRule();
154 : : }
155 : :
156 : 0 : void SAL_CALL SwVbaCells::setHeightRule( ::sal_Int32 _heightrule ) throw (css::uno::RuntimeException)
157 : : {
158 [ # # ]: 0 : for( sal_Int32 row = mnTop; row <= mnBottom; row++ )
159 : : {
160 [ # # ][ # # ]: 0 : uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, row ) );
[ # # ][ # # ]
161 [ # # ][ # # ]: 0 : xRow->setHeightRule( _heightrule );
162 : 0 : }
163 : 0 : }
164 : :
165 : 0 : void SAL_CALL SwVbaCells::SetWidth( float width, sal_Int32 rulestyle ) throw (css::uno::RuntimeException)
166 : : {
167 : 0 : sal_Int32 nIndex = 0;
168 [ # # ]: 0 : while( nIndex < m_xIndexAccess->getCount() )
169 : : {
170 [ # # ][ # # ]: 0 : uno::Reference< word::XCell > xCell( m_xIndexAccess->getByIndex( nIndex++ ), uno::UNO_QUERY_THROW );
[ # # ]
171 [ # # ][ # # ]: 0 : xCell->SetWidth( width, rulestyle );
172 : 0 : }
173 : 0 : }
174 : :
175 : 0 : void SAL_CALL SwVbaCells::SetHeight( float height, sal_Int32 heightrule ) throw (css::uno::RuntimeException)
176 : : {
177 [ # # ]: 0 : for( sal_Int32 row = mnTop; row <= mnBottom; row++ )
178 : : {
179 [ # # ][ # # ]: 0 : uno::Reference< word::XRow > xRow( new SwVbaRow( getParent(), mxContext, mxTextTable, row ) );
[ # # ][ # # ]
180 [ # # ][ # # ]: 0 : xRow->SetHeight( height, heightrule );
181 : 0 : }
182 : 0 : }
183 : :
184 : : // XEnumerationAccess
185 : : uno::Type
186 : 0 : SwVbaCells::getElementType() throw (uno::RuntimeException)
187 : : {
188 : 0 : return word::XCell::static_type(0);
189 : : }
190 : :
191 : : uno::Reference< container::XEnumeration >
192 : 0 : SwVbaCells::createEnumeration() throw (uno::RuntimeException)
193 : : {
194 [ # # ]: 0 : uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
195 [ # # ][ # # ]: 0 : return xEnumAccess->createEnumeration();
196 : : }
197 : :
198 : : uno::Any
199 : 0 : SwVbaCells::createCollectionObject( const uno::Any& aSource )
200 : : {
201 : 0 : return aSource;
202 : : }
203 : :
204 : : rtl::OUString
205 : 0 : SwVbaCells::getServiceImplName()
206 : : {
207 : 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaCells"));
208 : : }
209 : :
210 : : uno::Sequence<rtl::OUString>
211 : 0 : SwVbaCells::getServiceNames()
212 : : {
213 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > sNames;
[ # # ][ # # ]
214 [ # # ]: 0 : if ( sNames.getLength() == 0 )
215 : : {
216 : 0 : sNames.realloc( 1 );
217 [ # # ]: 0 : sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Cells") );
218 : : }
219 : 0 : return sNames;
220 : : }
221 : :
222 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|