xref: /AOO41X/main/toolkit/test/accessibility/AccessibleCellHandler.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir 
2*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
3*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleContext;
4*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleTable;
5*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessible;
6*cdf0e10cSrcweir 
7*cdf0e10cSrcweir 
8*cdf0e10cSrcweir class AccessibleCellHandler extends NodeHandler
9*cdf0e10cSrcweir {
10*cdf0e10cSrcweir     public NodeHandler createHandler (XAccessibleContext xContext)
11*cdf0e10cSrcweir     {
12*cdf0e10cSrcweir         AccessibleCellHandler aCellHandler = null;
13*cdf0e10cSrcweir         if (xContext != null)
14*cdf0e10cSrcweir         {
15*cdf0e10cSrcweir             XAccessible xParent = xContext.getAccessibleParent();
16*cdf0e10cSrcweir             if (xParent != null)
17*cdf0e10cSrcweir             {
18*cdf0e10cSrcweir                 XAccessibleTable xTable =
19*cdf0e10cSrcweir                     (XAccessibleTable) UnoRuntime.queryInterface (
20*cdf0e10cSrcweir                         XAccessibleTable.class, xParent.getAccessibleContext());
21*cdf0e10cSrcweir                 if (xTable != null)
22*cdf0e10cSrcweir                     aCellHandler = new AccessibleCellHandler (xTable);
23*cdf0e10cSrcweir             }
24*cdf0e10cSrcweir         }
25*cdf0e10cSrcweir         return aCellHandler;
26*cdf0e10cSrcweir 
27*cdf0e10cSrcweir     }
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir     public AccessibleCellHandler ()
30*cdf0e10cSrcweir     {
31*cdf0e10cSrcweir     }
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir     public AccessibleCellHandler (XAccessibleTable xTable)
34*cdf0e10cSrcweir     {
35*cdf0e10cSrcweir         if (xTable != null)
36*cdf0e10cSrcweir             maChildList.setSize (8);
37*cdf0e10cSrcweir     }
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir     protected static XAccessibleTable getTable(Object aObject)
40*cdf0e10cSrcweir     {
41*cdf0e10cSrcweir         return (XAccessibleTable) UnoRuntime.queryInterface (
42*cdf0e10cSrcweir             XAccessibleTable.class, aObject);
43*cdf0e10cSrcweir     }
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir     public AccessibleTreeNode createChild (AccessibleTreeNode aParent, int nIndex)
46*cdf0e10cSrcweir     {
47*cdf0e10cSrcweir         AccessibleTreeNode aChild = null;
48*cdf0e10cSrcweir         XAccessibleTable xTable = null;
49*cdf0e10cSrcweir         XAccessibleContext xContext = null;
50*cdf0e10cSrcweir 		AccessibleTreeNode aGrandParent = aParent.getParent();
51*cdf0e10cSrcweir         if (aGrandParent instanceof AccTreeNode)
52*cdf0e10cSrcweir 		{
53*cdf0e10cSrcweir             xTable = ((AccTreeNode)aGrandParent).getTable();
54*cdf0e10cSrcweir 			xContext = ((AccTreeNode)aGrandParent).getContext();
55*cdf0e10cSrcweir 		}
56*cdf0e10cSrcweir         if (aParent instanceof AccTreeNode)
57*cdf0e10cSrcweir 		{
58*cdf0e10cSrcweir 			xContext = ((AccTreeNode)aParent).getContext();
59*cdf0e10cSrcweir 		}
60*cdf0e10cSrcweir         try
61*cdf0e10cSrcweir         {
62*cdf0e10cSrcweir             if( xTable != null && xContext != null )
63*cdf0e10cSrcweir             {
64*cdf0e10cSrcweir                 switch( nIndex )
65*cdf0e10cSrcweir                 {
66*cdf0e10cSrcweir                     case 0:
67*cdf0e10cSrcweir 						{
68*cdf0e10cSrcweir 							int nChild = xContext.getAccessibleIndexInParent();
69*cdf0e10cSrcweir 							int nRow = xTable.getAccessibleRow( nChild );
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir 							aChild = new StringNode ("# table row: " + nRow, aParent);
72*cdf0e10cSrcweir 						}
73*cdf0e10cSrcweir                         break;
74*cdf0e10cSrcweir                     case 1:
75*cdf0e10cSrcweir 						{
76*cdf0e10cSrcweir 							int nChild = xContext.getAccessibleIndexInParent();
77*cdf0e10cSrcweir 							int nCol = xTable.getAccessibleColumn( nChild );
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 							aChild = new StringNode ("# table column: " + nCol, aParent);
80*cdf0e10cSrcweir 						}
81*cdf0e10cSrcweir                         break;
82*cdf0e10cSrcweir                     case 2:
83*cdf0e10cSrcweir 						{
84*cdf0e10cSrcweir 							int nChild = xContext.getAccessibleIndexInParent();
85*cdf0e10cSrcweir 							int nRow = xTable.getAccessibleRow( nChild );
86*cdf0e10cSrcweir 							int nCol = xTable.getAccessibleColumn( nChild );
87*cdf0e10cSrcweir 							int nExt = xTable.getAccessibleRowExtentAt( nRow, nCol );
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 							aChild = new StringNode ("# table row extend: " + nExt, aParent);
90*cdf0e10cSrcweir 						}
91*cdf0e10cSrcweir 						break;
92*cdf0e10cSrcweir                      case 3:
93*cdf0e10cSrcweir 						{
94*cdf0e10cSrcweir 							int nChild = xContext.getAccessibleIndexInParent();
95*cdf0e10cSrcweir 							int nRow = xTable.getAccessibleRow( nChild );
96*cdf0e10cSrcweir 							int nCol = xTable.getAccessibleColumn( nChild );
97*cdf0e10cSrcweir 							int nExt = xTable.getAccessibleColumnExtentAt( nRow, nCol );
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir 							aChild = new StringNode ("# table column extend: " + nExt, aParent);
100*cdf0e10cSrcweir 						}
101*cdf0e10cSrcweir                         break;
102*cdf0e10cSrcweir                      case 4:
103*cdf0e10cSrcweir 						{
104*cdf0e10cSrcweir 							int nChild = xContext.getAccessibleIndexInParent();
105*cdf0e10cSrcweir 							int nRow = xTable.getAccessibleRow( nChild );
106*cdf0e10cSrcweir 							int nCol = xTable.getAccessibleColumn( nChild );
107*cdf0e10cSrcweir 							XAccessible xChild =
108*cdf0e10cSrcweir 								xTable.getAccessibleCellAt( nRow, nCol );
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 							aChild = new StringNode ("# cell name retrieved from table: " + xChild.getAccessibleContext().getAccessibleName(), aParent);
111*cdf0e10cSrcweir 						}
112*cdf0e10cSrcweir                         break;
113*cdf0e10cSrcweir                      case 5:
114*cdf0e10cSrcweir 						{
115*cdf0e10cSrcweir 							int nChild = xContext.getAccessibleIndexInParent();
116*cdf0e10cSrcweir 							int nRow = xTable.getAccessibleRow( nChild );
117*cdf0e10cSrcweir 							int nCol = xTable.getAccessibleColumn( nChild );
118*cdf0e10cSrcweir 							boolean bSelected =
119*cdf0e10cSrcweir 								xTable.isAccessibleSelected( nRow, nCol );
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir 							aChild = new StringNode ("cell is selected: " + bSelected, aParent);
122*cdf0e10cSrcweir 						}
123*cdf0e10cSrcweir                         break;
124*cdf0e10cSrcweir                      case 6:
125*cdf0e10cSrcweir 						{
126*cdf0e10cSrcweir 							int nChild = xContext.getAccessibleIndexInParent();
127*cdf0e10cSrcweir 							int nRow = xTable.getAccessibleRow( nChild );
128*cdf0e10cSrcweir 							boolean bSelected =
129*cdf0e10cSrcweir 								xTable.isAccessibleRowSelected( nRow );
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 							aChild = new StringNode ("table row is selected: " + bSelected, aParent);
132*cdf0e10cSrcweir 						}
133*cdf0e10cSrcweir                         break;
134*cdf0e10cSrcweir                      case 7:
135*cdf0e10cSrcweir 						{
136*cdf0e10cSrcweir 							int nChild = xContext.getAccessibleIndexInParent();
137*cdf0e10cSrcweir 							int nCol = xTable.getAccessibleColumn( nChild );
138*cdf0e10cSrcweir 							boolean bSelected =
139*cdf0e10cSrcweir 								xTable.isAccessibleColumnSelected( nCol );
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 							aChild = new StringNode ("table column is selected: " + bSelected, aParent);
142*cdf0e10cSrcweir 						}
143*cdf0e10cSrcweir                         break;
144*cdf0e10cSrcweir                     default:
145*cdf0e10cSrcweir                         aChild = new StringNode ("unknown child index " + nIndex, aParent);
146*cdf0e10cSrcweir                 }
147*cdf0e10cSrcweir             }
148*cdf0e10cSrcweir         }
149*cdf0e10cSrcweir         catch (Exception e)
150*cdf0e10cSrcweir         {
151*cdf0e10cSrcweir             // Return empty child.
152*cdf0e10cSrcweir         }
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir         return aChild;
155*cdf0e10cSrcweir     }
156*cdf0e10cSrcweir }
157