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