1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3 <script:module xmlns:script="http://openoffice.org/2000/script" script:name="table_XCellCursor" script:language="StarBasic">
4 
5 
6 '*************************************************************************
7 '
8 '  Licensed to the Apache Software Foundation (ASF) under one
9 '  or more contributor license agreements.  See the NOTICE file
10 '  distributed with this work for additional information
11 '  regarding copyright ownership.  The ASF licenses this file
12 '  to you under the Apache License, Version 2.0 (the
13 '  "License"); you may not use this file except in compliance
14 '  with the License.  You may obtain a copy of the License at
15 '
16 '    http://www.apache.org/licenses/LICENSE-2.0
17 '
18 '  Unless required by applicable law or agreed to in writing,
19 '  software distributed under the License is distributed on an
20 '  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 '  KIND, either express or implied.  See the License for the
22 '  specific language governing permissions and limitations
23 '  under the License.
24 '
25 '*************************************************************************
26 
27 
28 
29 
30 
31 ' Be sure that all variables are dimensioned:
32 option explicit
33 
34 '*************************************************************************
35 'XCellCursor walks in a range of data. That
36 ' means: If you have the range (A1:B10) filled
37 ' with data gotoStart() goes to (A1), gotoEnd()
38 ' goes to (B10). But: you must insite this range.
39 ' If you are in (C3) you will nerver go to (A1).
40 
41 '*************************************************************************
42 
43 
44 
45 
46 
47 
48 Sub RunTest()
49 
50 '*************************************************************************
51 ' INTERFACE:
52 ' com.sun.star.table.XCellCursor
53 '*************************************************************************
54 On Error Goto ErrHndl
55     Dim bOK As Boolean
56     Dim bSupport As Boolean
57     Dim ResetCols As Integer, ResetRows As Long
58     Dim nStartSCol, nStartECol As Integer
59     Dim nStartSRow, nStartERow As Long
60     Dim nNextECol As Integer, nNextERow As Long
61     Dim nEndECol As Integer, nEndERow As Long
62     Dim nPrevECol As Integer, nPrevERow As Long
63     Dim nOffECol As Integer, nOffERow As Long
64     Dim oAddress As Object
65 
66     if hasUnoInterfaces(oObj, "com.sun.star.sheet.XSheetCellCursor") then
67         bSupport = true
68         ResetCols = oObj.getColumns().getCount()
69         ResetRows = oObj.getRows().getCount()
70     else
71         bSupport = false
72     end if
73 
74     Test.StartMethod("gotoStart()")
75     bOK = true
76     oObj.gotoStart()
77     oAddress = oObj.getRangeAddress()
78     nStartSCol = oAddress.StartColumn
79     nStartECol = oAddress.EndColumn
80     nStartSRow = oAddress.StartRow
81     nStartERow = oAddress.EndRow
82     bOK = bOK AND (nStartSCol = nStartECol) AND (nStartSRow = nStartERow)
83     Out.Log("nStartSCol = " &amp; nStartSCol &amp; " nStartECol = " &amp; nStartECol &amp;_
84            " nStartSRow = " &amp; nStartSRow &amp; " nStartERow = " &amp; nStartERow)
85     Test.MethodTested("gotoStart()", bOK)
86 
87     Test.StartMethod("gotoNext()")
88     bOK = true
89     oObj.gotoNext()
90     oAddress = oObj.getRangeAddress()
91     nNextECol = oAddress.EndColumn
92     nNextERow = oAddress.EndRow
93     bOK = bOK AND ((nNextECol = nStartSCol + 1) OR (nNextERow = nStartSRow + 1))
94     Out.Log("nNextECol = " &amp; nNextECol &amp; " nNextERow = " &amp; nNextERow)
95     Test.MethodTested("gotoNext()", bOK)
96 
97     Test.StartMethod("gotoEnd()")
98     bOK = true
99     oObj.gotoEnd()
100     oAddress = oObj.getRangeAddress()
101     nEndECol = oAddress.EndColumn
102     nEndERow = oAddress.EndRow
103     bOK = bOK AND ((nEndECol &gt; nStartECol) OR (nEndERow &gt; nStartERow))
104     Out.Log("nEndSCol = " &amp; nEndECol &amp; " nEndERow = " &amp; nEndERow)
105     Test.MethodTested("gotoEnd()", bOK)
106 
107     Test.StartMethod("gotoPrevious()")
108     bOK = true
109     oObj.gotoPrevious()
110     oAddress = oObj.getRangeAddress()
111     nPrevECol = oAddress.EndColumn
112     nPrevERow = oAddress.EndRow
113     bOK = bOK AND ((nPrevECol &lt; nEndECol) OR (nPrevERow &lt; nEndERow))
114     Out.Log("nPrevECol = " &amp; nPrevECol &amp; " nPrevERow = " &amp; nPrevERow)
115     Test.MethodTested("gotoPrevious()", bOK)
116 
117     Test.StartMethod("gotoOffset()")
118     bOK = true
119     oObj.gotoStart()
120     oObj.gotoOffset(1,1)
121     oAddress = oObj.getRangeAddress()
122     nOffECol = oAddress.EndColumn
123     nOffERow = oAddress.EndRow
124     bOK = bOK AND (nOffECol = nStartSCol + 1) AND (nOffERow = nStartSRow + 1)
125     Out.Log("nOffECol = " &amp; nOffECol &amp; " nOffERow = " &amp; nOffERow)
126     Test.MethodTested("gotoOffset()", bOK)
127 
128     if bSupport then
129         Out.Log("Reset to old range: " &amp; ResetCols &amp; "," &amp; ResetRows)
130         oObj.collapseToSize(ResetCols, ResetRows)
131     end if
132 
133 Exit Sub
134 ErrHndl:
135     Test.Exception()
136     bOK = false
137     resume next
138 End Sub
139 </script:module>
140