merged tag ooo/DEV300_m102
[LibreOffice.git] / toolkit / test / accessibility / AccessibleCellHandler.java
blob19b4a9df67ad777414fe81e629a7478dc24c8b1c
2 import com.sun.star.uno.UnoRuntime;
3 import com.sun.star.accessibility.XAccessibleContext;
4 import com.sun.star.accessibility.XAccessibleTable;
5 import com.sun.star.accessibility.XAccessible;
8 class AccessibleCellHandler extends NodeHandler
10 public NodeHandler createHandler (XAccessibleContext xContext)
12 AccessibleCellHandler aCellHandler = null;
13 if (xContext != null)
15 XAccessible xParent = xContext.getAccessibleParent();
16 if (xParent != null)
18 XAccessibleTable xTable =
19 (XAccessibleTable) UnoRuntime.queryInterface (
20 XAccessibleTable.class, xParent.getAccessibleContext());
21 if (xTable != null)
22 aCellHandler = new AccessibleCellHandler (xTable);
25 return aCellHandler;
29 public AccessibleCellHandler ()
33 public AccessibleCellHandler (XAccessibleTable xTable)
35 if (xTable != null)
36 maChildList.setSize (8);
39 protected static XAccessibleTable getTable(Object aObject)
41 return (XAccessibleTable) UnoRuntime.queryInterface (
42 XAccessibleTable.class, aObject);
45 public AccessibleTreeNode createChild (AccessibleTreeNode aParent, int nIndex)
47 AccessibleTreeNode aChild = null;
48 XAccessibleTable xTable = null;
49 XAccessibleContext xContext = null;
50 AccessibleTreeNode aGrandParent = aParent.getParent();
51 if (aGrandParent instanceof AccTreeNode)
53 xTable = ((AccTreeNode)aGrandParent).getTable();
54 xContext = ((AccTreeNode)aGrandParent).getContext();
56 if (aParent instanceof AccTreeNode)
58 xContext = ((AccTreeNode)aParent).getContext();
60 try
62 if( xTable != null && xContext != null )
64 switch( nIndex )
66 case 0:
68 int nChild = xContext.getAccessibleIndexInParent();
69 int nRow = xTable.getAccessibleRow( nChild );
71 aChild = new StringNode ("# table row: " + nRow, aParent);
73 break;
74 case 1:
76 int nChild = xContext.getAccessibleIndexInParent();
77 int nCol = xTable.getAccessibleColumn( nChild );
79 aChild = new StringNode ("# table column: " + nCol, aParent);
81 break;
82 case 2:
84 int nChild = xContext.getAccessibleIndexInParent();
85 int nRow = xTable.getAccessibleRow( nChild );
86 int nCol = xTable.getAccessibleColumn( nChild );
87 int nExt = xTable.getAccessibleRowExtentAt( nRow, nCol );
89 aChild = new StringNode ("# table row extend: " + nExt, aParent);
91 break;
92 case 3:
94 int nChild = xContext.getAccessibleIndexInParent();
95 int nRow = xTable.getAccessibleRow( nChild );
96 int nCol = xTable.getAccessibleColumn( nChild );
97 int nExt = xTable.getAccessibleColumnExtentAt( nRow, nCol );
99 aChild = new StringNode ("# table column extend: " + nExt, aParent);
101 break;
102 case 4:
104 int nChild = xContext.getAccessibleIndexInParent();
105 int nRow = xTable.getAccessibleRow( nChild );
106 int nCol = xTable.getAccessibleColumn( nChild );
107 XAccessible xChild =
108 xTable.getAccessibleCellAt( nRow, nCol );
110 aChild = new StringNode ("# cell name retrieved from table: " + xChild.getAccessibleContext().getAccessibleName(), aParent);
112 break;
113 case 5:
115 int nChild = xContext.getAccessibleIndexInParent();
116 int nRow = xTable.getAccessibleRow( nChild );
117 int nCol = xTable.getAccessibleColumn( nChild );
118 boolean bSelected =
119 xTable.isAccessibleSelected( nRow, nCol );
121 aChild = new StringNode ("cell is selected: " + bSelected, aParent);
123 break;
124 case 6:
126 int nChild = xContext.getAccessibleIndexInParent();
127 int nRow = xTable.getAccessibleRow( nChild );
128 boolean bSelected =
129 xTable.isAccessibleRowSelected( nRow );
131 aChild = new StringNode ("table row is selected: " + bSelected, aParent);
133 break;
134 case 7:
136 int nChild = xContext.getAccessibleIndexInParent();
137 int nCol = xTable.getAccessibleColumn( nChild );
138 boolean bSelected =
139 xTable.isAccessibleColumnSelected( nCol );
141 aChild = new StringNode ("table column is selected: " + bSelected, aParent);
143 break;
144 default:
145 aChild = new StringNode ("unknown child index " + nIndex, aParent);
149 catch (Exception e)
151 // Return empty child.
154 return aChild;