1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir package ifc.sheet;
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir import com.sun.star.sheet.XCellRangesQuery;
30*cdf0e10cSrcweir import com.sun.star.sheet.XSheetCellRanges;
31*cdf0e10cSrcweir import lib.MultiMethodTest;
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir import com.sun.star.sheet.XSheetOutline;
34*cdf0e10cSrcweir import com.sun.star.table.CellRangeAddress;
35*cdf0e10cSrcweir import com.sun.star.table.TableOrientation;
36*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
37*cdf0e10cSrcweir import lib.Status;
38*cdf0e10cSrcweir import lib.StatusException;
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir /**
41*cdf0e10cSrcweir  *
42*cdf0e10cSrcweir  */
43*cdf0e10cSrcweir public class _XSheetOutline extends MultiMethodTest {
44*cdf0e10cSrcweir     public XSheetOutline oObj = null;
45*cdf0e10cSrcweir     CellRangeAddress address = null;
46*cdf0e10cSrcweir     CellRangeAddress subaddress = null;
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir     public void before() {
49*cdf0e10cSrcweir         address = (CellRangeAddress)tEnv.getObjRelation("CellRangeAddress");
50*cdf0e10cSrcweir         subaddress = (CellRangeAddress)tEnv.getObjRelation("CellRangeSubAddress");
51*cdf0e10cSrcweir         if (address == null)
52*cdf0e10cSrcweir             throw new StatusException(Status.failed("Object relation CellRangeAddress not found"));
53*cdf0e10cSrcweir         if (subaddress == null)
54*cdf0e10cSrcweir             throw new StatusException(Status.failed("Object relation CellRangeSubAddress not found"));
55*cdf0e10cSrcweir     }
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir     public void _autoOutline() {
58*cdf0e10cSrcweir         executeMethod("ungroup()");
59*cdf0e10cSrcweir         boolean result = false;
60*cdf0e10cSrcweir         oObj.autoOutline(address);
61*cdf0e10cSrcweir         // initially the range is grouped and shown
62*cdf0e10cSrcweir         result = isCellShown(subaddress);
63*cdf0e10cSrcweir         oObj.hideDetail(address);
64*cdf0e10cSrcweir         // here only a part of the address is hidden: subaddress must be that part
65*cdf0e10cSrcweir         result &= !isCellShown(subaddress);
66*cdf0e10cSrcweir         tRes.tested("autoOutline()", result);
67*cdf0e10cSrcweir     }
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir     public void _clearOutline() {
70*cdf0e10cSrcweir         executeMethod("autoOutline()");
71*cdf0e10cSrcweir         boolean result = false;
72*cdf0e10cSrcweir         oObj.clearOutline();
73*cdf0e10cSrcweir         result = isCellShown(subaddress);
74*cdf0e10cSrcweir         oObj.hideDetail(address);
75*cdf0e10cSrcweir         result &= isCellShown(subaddress);
76*cdf0e10cSrcweir         tRes.tested("clearOutline()", result);
77*cdf0e10cSrcweir     }
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir     public void _group() {
80*cdf0e10cSrcweir         oObj.group(address, TableOrientation.COLUMNS);
81*cdf0e10cSrcweir         oObj.group(address, TableOrientation.ROWS);
82*cdf0e10cSrcweir         tRes.tested("group()", true);
83*cdf0e10cSrcweir     }
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir     public void _ungroup() {
86*cdf0e10cSrcweir         executeMethod("showDetail()");
87*cdf0e10cSrcweir         oObj.ungroup(address, TableOrientation.COLUMNS);
88*cdf0e10cSrcweir         oObj.ungroup(address, TableOrientation.ROWS);
89*cdf0e10cSrcweir         oObj.hideDetail(address);
90*cdf0e10cSrcweir         tRes.tested("ungroup()", isCellShown(address));
91*cdf0e10cSrcweir     }
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir     public void _hideDetail() {
94*cdf0e10cSrcweir         requiredMethod("group()");
95*cdf0e10cSrcweir         oObj.hideDetail(address);
96*cdf0e10cSrcweir         tRes.tested("hideDetail()", !isCellShown(address));
97*cdf0e10cSrcweir     }
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir     public void _showDetail() {
100*cdf0e10cSrcweir         executeMethod("showLevel()");
101*cdf0e10cSrcweir         oObj.showDetail(address);
102*cdf0e10cSrcweir         tRes.tested("showDetail()", isCellShown(address));
103*cdf0e10cSrcweir     }
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir     public void _showLevel() {
106*cdf0e10cSrcweir         executeMethod("hideDetail()");
107*cdf0e10cSrcweir         boolean result = false;
108*cdf0e10cSrcweir         oObj.showLevel((short)2, TableOrientation.COLUMNS);
109*cdf0e10cSrcweir         oObj.showLevel((short)2, TableOrientation.ROWS);
110*cdf0e10cSrcweir         result = isCellShown(address);
111*cdf0e10cSrcweir         oObj.showLevel((short)0, TableOrientation.COLUMNS);
112*cdf0e10cSrcweir         oObj.showLevel((short)0, TableOrientation.ROWS);
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir         result &= !isCellShown(address);
115*cdf0e10cSrcweir         tRes.tested("showLevel()", result);
116*cdf0e10cSrcweir     }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir     private boolean isCellShown(CellRangeAddress range) {
119*cdf0e10cSrcweir         boolean isNotShown = true;
120*cdf0e10cSrcweir         XCellRangesQuery xCellRangesQuery = (XCellRangesQuery)UnoRuntime.queryInterface(XCellRangesQuery.class, oObj);
121*cdf0e10cSrcweir         if (xCellRangesQuery != null) {
122*cdf0e10cSrcweir             XSheetCellRanges xRanges = xCellRangesQuery.queryVisibleCells();
123*cdf0e10cSrcweir             CellRangeAddress[] visibleRanges = xRanges.getRangeAddresses();
124*cdf0e10cSrcweir             for (int i=0; i<visibleRanges.length; i++) {
125*cdf0e10cSrcweir                 isNotShown &= dotIsOutsideRange(range.StartRow, range.StartColumn, visibleRanges[i]);
126*cdf0e10cSrcweir                 isNotShown &= dotIsOutsideRange(range.StartRow, range.EndColumn, visibleRanges[i]);
127*cdf0e10cSrcweir                 isNotShown &= dotIsOutsideRange(range.EndRow, range.StartColumn, visibleRanges[i]);
128*cdf0e10cSrcweir                 isNotShown &= dotIsOutsideRange(range.EndRow, range.EndColumn, visibleRanges[i]);
129*cdf0e10cSrcweir                 log.println(isNotShown?"\tisOutSide":"\tisInside");
130*cdf0e10cSrcweir             }
131*cdf0e10cSrcweir         }
132*cdf0e10cSrcweir         return !isNotShown;
133*cdf0e10cSrcweir     }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir     private boolean dotIsOutsideRange(int dotRow, int dotColumn, CellRangeAddress range) {
136*cdf0e10cSrcweir         log.println("Checking dot(" + dotRow + "," + dotColumn + ") against row["
137*cdf0e10cSrcweir                     + range.StartRow + ":" + range.EndRow + "]  column["
138*cdf0e10cSrcweir                     + range.StartColumn + ":" + range.EndColumn + "]");
139*cdf0e10cSrcweir         boolean isInside = true;
140*cdf0e10cSrcweir         if (dotRow >= range.StartRow && dotRow <= range.EndRow)
141*cdf0e10cSrcweir             if (dotColumn >= range.StartColumn && dotColumn <= range.EndColumn)
142*cdf0e10cSrcweir                 isInside = false;
143*cdf0e10cSrcweir         return isInside;
144*cdf0e10cSrcweir     }
145*cdf0e10cSrcweir }
146