1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir package ifc.sheet; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import com.sun.star.sheet.XCellRangesQuery; 26cdf0e10cSrcweir import com.sun.star.sheet.XSheetCellRanges; 27cdf0e10cSrcweir import lib.MultiMethodTest; 28cdf0e10cSrcweir 29cdf0e10cSrcweir import com.sun.star.sheet.XSheetOutline; 30cdf0e10cSrcweir import com.sun.star.table.CellRangeAddress; 31cdf0e10cSrcweir import com.sun.star.table.TableOrientation; 32cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 33cdf0e10cSrcweir import lib.Status; 34cdf0e10cSrcweir import lib.StatusException; 35cdf0e10cSrcweir 36cdf0e10cSrcweir /** 37cdf0e10cSrcweir * 38cdf0e10cSrcweir */ 39cdf0e10cSrcweir public class _XSheetOutline extends MultiMethodTest { 40cdf0e10cSrcweir public XSheetOutline oObj = null; 41cdf0e10cSrcweir CellRangeAddress address = null; 42cdf0e10cSrcweir CellRangeAddress subaddress = null; 43cdf0e10cSrcweir before()44cdf0e10cSrcweir public void before() { 45cdf0e10cSrcweir address = (CellRangeAddress)tEnv.getObjRelation("CellRangeAddress"); 46cdf0e10cSrcweir subaddress = (CellRangeAddress)tEnv.getObjRelation("CellRangeSubAddress"); 47cdf0e10cSrcweir if (address == null) 48cdf0e10cSrcweir throw new StatusException(Status.failed("Object relation CellRangeAddress not found")); 49cdf0e10cSrcweir if (subaddress == null) 50cdf0e10cSrcweir throw new StatusException(Status.failed("Object relation CellRangeSubAddress not found")); 51cdf0e10cSrcweir } 52cdf0e10cSrcweir _autoOutline()53cdf0e10cSrcweir public void _autoOutline() { 54cdf0e10cSrcweir executeMethod("ungroup()"); 55cdf0e10cSrcweir boolean result = false; 56cdf0e10cSrcweir oObj.autoOutline(address); 57cdf0e10cSrcweir // initially the range is grouped and shown 58cdf0e10cSrcweir result = isCellShown(subaddress); 59cdf0e10cSrcweir oObj.hideDetail(address); 60cdf0e10cSrcweir // here only a part of the address is hidden: subaddress must be that part 61cdf0e10cSrcweir result &= !isCellShown(subaddress); 62cdf0e10cSrcweir tRes.tested("autoOutline()", result); 63cdf0e10cSrcweir } 64cdf0e10cSrcweir _clearOutline()65cdf0e10cSrcweir public void _clearOutline() { 66cdf0e10cSrcweir executeMethod("autoOutline()"); 67cdf0e10cSrcweir boolean result = false; 68cdf0e10cSrcweir oObj.clearOutline(); 69cdf0e10cSrcweir result = isCellShown(subaddress); 70cdf0e10cSrcweir oObj.hideDetail(address); 71cdf0e10cSrcweir result &= isCellShown(subaddress); 72cdf0e10cSrcweir tRes.tested("clearOutline()", result); 73cdf0e10cSrcweir } 74cdf0e10cSrcweir _group()75cdf0e10cSrcweir public void _group() { 76cdf0e10cSrcweir oObj.group(address, TableOrientation.COLUMNS); 77cdf0e10cSrcweir oObj.group(address, TableOrientation.ROWS); 78cdf0e10cSrcweir tRes.tested("group()", true); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir _ungroup()81cdf0e10cSrcweir public void _ungroup() { 82cdf0e10cSrcweir executeMethod("showDetail()"); 83cdf0e10cSrcweir oObj.ungroup(address, TableOrientation.COLUMNS); 84cdf0e10cSrcweir oObj.ungroup(address, TableOrientation.ROWS); 85cdf0e10cSrcweir oObj.hideDetail(address); 86cdf0e10cSrcweir tRes.tested("ungroup()", isCellShown(address)); 87cdf0e10cSrcweir } 88cdf0e10cSrcweir _hideDetail()89cdf0e10cSrcweir public void _hideDetail() { 90cdf0e10cSrcweir requiredMethod("group()"); 91cdf0e10cSrcweir oObj.hideDetail(address); 92cdf0e10cSrcweir tRes.tested("hideDetail()", !isCellShown(address)); 93cdf0e10cSrcweir } 94cdf0e10cSrcweir _showDetail()95cdf0e10cSrcweir public void _showDetail() { 96cdf0e10cSrcweir executeMethod("showLevel()"); 97cdf0e10cSrcweir oObj.showDetail(address); 98cdf0e10cSrcweir tRes.tested("showDetail()", isCellShown(address)); 99cdf0e10cSrcweir } 100cdf0e10cSrcweir _showLevel()101cdf0e10cSrcweir public void _showLevel() { 102cdf0e10cSrcweir executeMethod("hideDetail()"); 103cdf0e10cSrcweir boolean result = false; 104cdf0e10cSrcweir oObj.showLevel((short)2, TableOrientation.COLUMNS); 105cdf0e10cSrcweir oObj.showLevel((short)2, TableOrientation.ROWS); 106cdf0e10cSrcweir result = isCellShown(address); 107cdf0e10cSrcweir oObj.showLevel((short)0, TableOrientation.COLUMNS); 108cdf0e10cSrcweir oObj.showLevel((short)0, TableOrientation.ROWS); 109cdf0e10cSrcweir 110cdf0e10cSrcweir result &= !isCellShown(address); 111cdf0e10cSrcweir tRes.tested("showLevel()", result); 112cdf0e10cSrcweir } 113cdf0e10cSrcweir isCellShown(CellRangeAddress range)114cdf0e10cSrcweir private boolean isCellShown(CellRangeAddress range) { 115cdf0e10cSrcweir boolean isNotShown = true; 116cdf0e10cSrcweir XCellRangesQuery xCellRangesQuery = (XCellRangesQuery)UnoRuntime.queryInterface(XCellRangesQuery.class, oObj); 117cdf0e10cSrcweir if (xCellRangesQuery != null) { 118cdf0e10cSrcweir XSheetCellRanges xRanges = xCellRangesQuery.queryVisibleCells(); 119cdf0e10cSrcweir CellRangeAddress[] visibleRanges = xRanges.getRangeAddresses(); 120cdf0e10cSrcweir for (int i=0; i<visibleRanges.length; i++) { 121cdf0e10cSrcweir isNotShown &= dotIsOutsideRange(range.StartRow, range.StartColumn, visibleRanges[i]); 122cdf0e10cSrcweir isNotShown &= dotIsOutsideRange(range.StartRow, range.EndColumn, visibleRanges[i]); 123cdf0e10cSrcweir isNotShown &= dotIsOutsideRange(range.EndRow, range.StartColumn, visibleRanges[i]); 124cdf0e10cSrcweir isNotShown &= dotIsOutsideRange(range.EndRow, range.EndColumn, visibleRanges[i]); 125cdf0e10cSrcweir log.println(isNotShown?"\tisOutSide":"\tisInside"); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir } 128cdf0e10cSrcweir return !isNotShown; 129cdf0e10cSrcweir } 130cdf0e10cSrcweir dotIsOutsideRange(int dotRow, int dotColumn, CellRangeAddress range)131cdf0e10cSrcweir private boolean dotIsOutsideRange(int dotRow, int dotColumn, CellRangeAddress range) { 132cdf0e10cSrcweir log.println("Checking dot(" + dotRow + "," + dotColumn + ") against row[" 133cdf0e10cSrcweir + range.StartRow + ":" + range.EndRow + "] column[" 134cdf0e10cSrcweir + range.StartColumn + ":" + range.EndColumn + "]"); 135cdf0e10cSrcweir boolean isInside = true; 136cdf0e10cSrcweir if (dotRow >= range.StartRow && dotRow <= range.EndRow) 137cdf0e10cSrcweir if (dotColumn >= range.StartColumn && dotColumn <= range.EndColumn) 138cdf0e10cSrcweir isInside = false; 139cdf0e10cSrcweir return isInside; 140cdf0e10cSrcweir } 141cdf0e10cSrcweir } 142