1 /* 2 * This file is part of the LibreOffice project. 3 * 4 * This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 * 8 * This file incorporates work covered by the following license notice: 9 * 10 * Licensed to the Apache Software Foundation (ASF) under one or more 11 * contributor license agreements. See the NOTICE file distributed 12 * with this work for additional information regarding copyright 13 * ownership. The ASF licenses this file to you under the Apache 14 * License, Version 2.0 (the "License"); you may not use this file 15 * except in compliance with the License. You may obtain a copy of 16 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 17 */ 18 19 import com.sun.star.uno.UnoRuntime; 20 import com.sun.star.accessibility.XAccessibleContext; 21 import com.sun.star.accessibility.XAccessibleTable; 22 import com.sun.star.accessibility.XAccessible; 23 24 25 class AccessibleCellHandler extends NodeHandler 26 { 27 @Override createHandler(XAccessibleContext xContext)28 public NodeHandler createHandler (XAccessibleContext xContext) 29 { 30 if (xContext == null) 31 return null; 32 33 AccessibleCellHandler aCellHandler = null; 34 XAccessible xParent = xContext.getAccessibleParent(); 35 if (xParent != null) 36 { 37 XAccessibleTable xTable = 38 UnoRuntime.queryInterface ( 39 XAccessibleTable.class, xParent.getAccessibleContext()); 40 if (xTable != null) 41 aCellHandler = new AccessibleCellHandler (xTable); 42 } 43 return aCellHandler; 44 } 45 AccessibleCellHandler()46 public AccessibleCellHandler () 47 { 48 } 49 AccessibleCellHandler(XAccessibleTable xTable)50 private AccessibleCellHandler (XAccessibleTable xTable) 51 { 52 if (xTable != null) 53 maChildList.setSize (8); 54 } 55 56 @Override createChild(AccessibleTreeNode aParent, int nIndex)57 public AccessibleTreeNode createChild (AccessibleTreeNode aParent, int nIndex) 58 { 59 AccessibleTreeNode aChild = null; 60 XAccessibleTable xTable = null; 61 XAccessibleContext xContext = null; 62 AccessibleTreeNode aGrandParent = aParent.getParent(); 63 if (aGrandParent instanceof AccTreeNode) 64 { 65 xTable = ((AccTreeNode)aGrandParent).getTable(); 66 xContext = ((AccTreeNode)aGrandParent).getContext(); 67 } 68 if (aParent instanceof AccTreeNode) 69 { 70 xContext = ((AccTreeNode)aParent).getContext(); 71 } 72 try 73 { 74 if( xTable != null && xContext != null ) 75 { 76 switch( nIndex ) 77 { 78 case 0: 79 { 80 int nChild = xContext.getAccessibleIndexInParent(); 81 int nRow = xTable.getAccessibleRow( nChild ); 82 83 aChild = new StringNode ("# table row: " + nRow, aParent); 84 } 85 break; 86 case 1: 87 { 88 int nChild = xContext.getAccessibleIndexInParent(); 89 int nCol = xTable.getAccessibleColumn( nChild ); 90 91 aChild = new StringNode ("# table column: " + nCol, aParent); 92 } 93 break; 94 case 2: 95 { 96 int nChild = xContext.getAccessibleIndexInParent(); 97 int nRow = xTable.getAccessibleRow( nChild ); 98 int nCol = xTable.getAccessibleColumn( nChild ); 99 int nExt = xTable.getAccessibleRowExtentAt( nRow, nCol ); 100 101 aChild = new StringNode ("# table row extend: " + nExt, aParent); 102 } 103 break; 104 case 3: 105 { 106 int nChild = xContext.getAccessibleIndexInParent(); 107 int nRow = xTable.getAccessibleRow( nChild ); 108 int nCol = xTable.getAccessibleColumn( nChild ); 109 int nExt = xTable.getAccessibleColumnExtentAt( nRow, nCol ); 110 111 aChild = new StringNode ("# table column extend: " + nExt, aParent); 112 } 113 break; 114 case 4: 115 { 116 int nChild = xContext.getAccessibleIndexInParent(); 117 int nRow = xTable.getAccessibleRow( nChild ); 118 int nCol = xTable.getAccessibleColumn( nChild ); 119 XAccessible xChild = 120 xTable.getAccessibleCellAt( nRow, nCol ); 121 122 aChild = new StringNode ("# cell name retrieved from table: " + xChild.getAccessibleContext().getAccessibleName(), aParent); 123 } 124 break; 125 case 5: 126 { 127 int nChild = xContext.getAccessibleIndexInParent(); 128 int nRow = xTable.getAccessibleRow( nChild ); 129 int nCol = xTable.getAccessibleColumn( nChild ); 130 boolean bSelected = 131 xTable.isAccessibleSelected( nRow, nCol ); 132 133 aChild = new StringNode ("cell is selected: " + bSelected, aParent); 134 } 135 break; 136 case 6: 137 { 138 int nChild = xContext.getAccessibleIndexInParent(); 139 int nRow = xTable.getAccessibleRow( nChild ); 140 boolean bSelected = 141 xTable.isAccessibleRowSelected( nRow ); 142 143 aChild = new StringNode ("table row is selected: " + bSelected, aParent); 144 } 145 break; 146 case 7: 147 { 148 int nChild = xContext.getAccessibleIndexInParent(); 149 int nCol = xTable.getAccessibleColumn( nChild ); 150 boolean bSelected = 151 xTable.isAccessibleColumnSelected( nCol ); 152 153 aChild = new StringNode ("table column is selected: " + bSelected, aParent); 154 } 155 break; 156 default: 157 aChild = new StringNode ("unknown child index " + nIndex, aParent); 158 } 159 } 160 } 161 catch (Exception e) 162 { 163 // Return empty child. 164 } 165 166 return aChild; 167 } 168 } 169