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