xref: /AOO41X/main/toolkit/test/accessibility/AccessibleContextHandler.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessible;
2*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleContext;
3*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleStateSet;
4*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
5*cdf0e10cSrcweir import com.sun.star.container.XIndexAccess;
6*cdf0e10cSrcweir import java.util.HashMap;
7*cdf0e10cSrcweir 
8*cdf0e10cSrcweir import tools.NameProvider;
9*cdf0e10cSrcweir 
10*cdf0e10cSrcweir class AccessibleContextHandler
11*cdf0e10cSrcweir     extends NodeHandler
12*cdf0e10cSrcweir {
13*cdf0e10cSrcweir     protected int nChildrenCount;
14*cdf0e10cSrcweir 
15*cdf0e10cSrcweir     public NodeHandler createHandler (XAccessibleContext xContext)
16*cdf0e10cSrcweir     {
17*cdf0e10cSrcweir         if (xContext != null)
18*cdf0e10cSrcweir             return new AccessibleContextHandler (xContext);
19*cdf0e10cSrcweir         else
20*cdf0e10cSrcweir             return null;
21*cdf0e10cSrcweir     }
22*cdf0e10cSrcweir 
23*cdf0e10cSrcweir     public AccessibleContextHandler ()
24*cdf0e10cSrcweir     {
25*cdf0e10cSrcweir         super ();
26*cdf0e10cSrcweir     }
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir     public AccessibleContextHandler (XAccessibleContext xContext)
29*cdf0e10cSrcweir     {
30*cdf0e10cSrcweir         super();
31*cdf0e10cSrcweir         if (xContext != null)
32*cdf0e10cSrcweir             maChildList.setSize (4);
33*cdf0e10cSrcweir     }
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir     public AccessibleTreeNode createChild (AccessibleTreeNode aParent, int nIndex)
36*cdf0e10cSrcweir     {
37*cdf0e10cSrcweir         XAccessibleContext xContext = null;
38*cdf0e10cSrcweir         if (aParent instanceof AccTreeNode)
39*cdf0e10cSrcweir             xContext = ((AccTreeNode)aParent).getContext();
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir         String sChild = new String();
42*cdf0e10cSrcweir         if (xContext != null)
43*cdf0e10cSrcweir         {
44*cdf0e10cSrcweir             switch( nIndex )
45*cdf0e10cSrcweir             {
46*cdf0e10cSrcweir                 case 0:
47*cdf0e10cSrcweir                     sChild = "Description: " +
48*cdf0e10cSrcweir                         xContext.getAccessibleDescription();
49*cdf0e10cSrcweir                     break;
50*cdf0e10cSrcweir                 case 1:
51*cdf0e10cSrcweir                     int nRole = xContext.getAccessibleRole();
52*cdf0e10cSrcweir                     sChild = "Role: " + nRole + " (" + NameProvider.getRoleName(nRole) + ")";
53*cdf0e10cSrcweir                     break;
54*cdf0e10cSrcweir                 case 2:
55*cdf0e10cSrcweir                     XAccessible xParent = xContext.getAccessibleParent();
56*cdf0e10cSrcweir                     sChild = "Has parent: " + (xParent!=null ? "yes" : "no");
57*cdf0e10cSrcweir                     /*                    if (xParent != ((AccTreeNode)aParent).getAccessible())
58*cdf0e10cSrcweir                     {
59*cdf0e10cSrcweir                         sChild += " but that is inconsistent"
60*cdf0e10cSrcweir                             + "#" + xParent + " # " + ((AccTreeNode)aParent).getAccessible();
61*cdf0e10cSrcweir                     }
62*cdf0e10cSrcweir                     */
63*cdf0e10cSrcweir                     break;
64*cdf0e10cSrcweir                 case 3:
65*cdf0e10cSrcweir                     sChild = "";
66*cdf0e10cSrcweir                     XAccessibleStateSet xStateSet =
67*cdf0e10cSrcweir                         xContext.getAccessibleStateSet();
68*cdf0e10cSrcweir                     if (xStateSet != null)
69*cdf0e10cSrcweir                     {
70*cdf0e10cSrcweir                         for (short i=0; i<=30; i++)
71*cdf0e10cSrcweir                         {
72*cdf0e10cSrcweir                             if (xStateSet.contains (i))
73*cdf0e10cSrcweir                             {
74*cdf0e10cSrcweir                                 if (sChild.compareTo ("") != 0)
75*cdf0e10cSrcweir                                     sChild += ", ";
76*cdf0e10cSrcweir                                 sChild += NameProvider.getStateName(i);
77*cdf0e10cSrcweir                             }
78*cdf0e10cSrcweir                         }
79*cdf0e10cSrcweir                     }
80*cdf0e10cSrcweir                     else
81*cdf0e10cSrcweir                         sChild += "no state set";
82*cdf0e10cSrcweir                     sChild = "State set: " + sChild;
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir                     /*                case 3:
85*cdf0e10cSrcweir                     sChild = "Child count: " + xContext.getAccessibleChildCount();
86*cdf0e10cSrcweir                     break;*/
87*cdf0e10cSrcweir             }
88*cdf0e10cSrcweir         }
89*cdf0e10cSrcweir         return new StringNode (sChild, aParent);
90*cdf0e10cSrcweir     }
91*cdf0e10cSrcweir }
92