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.XAccessibleComponent;
26 
27 
28 class AccessibleComponentHandler
29     extends NodeHandler
30 {
31 
createHandler(XAccessibleContext xContext)32     public NodeHandler createHandler (XAccessibleContext xContext)
33     {
34         XAccessibleComponent xComponent =
35             (XAccessibleComponent) UnoRuntime.queryInterface (
36                 XAccessibleComponent.class, xContext);
37         if (xComponent != null)
38             return new AccessibleComponentHandler (xComponent);
39         else
40             return null;
41 
42     }
43 
AccessibleComponentHandler()44     public AccessibleComponentHandler ()
45     {
46     }
47 
AccessibleComponentHandler(XAccessibleComponent xComponent)48     public AccessibleComponentHandler (XAccessibleComponent xComponent)
49     {
50         if (xComponent != null)
51             maChildList.setSize (6);
52     }
53 
createChild(AccessibleTreeNode aParent, int nIndex)54     public AccessibleTreeNode createChild (AccessibleTreeNode aParent, int nIndex)
55     {
56         AccessibleTreeNode aChild = null;
57         if (aParent instanceof AccTreeNode)
58         {
59             XAccessibleComponent xComponent =
60                 ((AccTreeNode)aParent).getComponent();
61 
62             if (xComponent != null)
63             {
64                 int nColor;
65                 switch (nIndex)
66                 {
67                     case 0:
68                         com.sun.star.awt.Point aLocation = xComponent.getLocation();
69                         aChild = new StringNode (
70                             "Location: " + aLocation.X + ", " + aLocation.Y,
71                             aParent);
72                         break;
73                     case 1:
74                         com.sun.star.awt.Point aScreenLocation = xComponent.getLocationOnScreen();
75                         aChild = new StringNode (
76                             "Location on Screen: " + aScreenLocation.X + ", " + aScreenLocation.Y,
77                             aParent);
78                         break;
79                     case 2:
80                         com.sun.star.awt.Size aSize = xComponent.getSize();
81                         aChild = new StringNode (
82                             "Size: "+ aSize.Width + ", " + aSize.Height,
83                             aParent);
84                         break;
85                     case 3:
86                         com.sun.star.awt.Rectangle aBBox = xComponent.getBounds();
87                         aChild = new StringNode (
88                             "Bounding Box: "+ aBBox.X + ", " + aBBox.Y + ","
89                             + aBBox.Width + ", " + aBBox.Height,
90                             aParent);
91                         break;
92                     case 4:
93                         nColor = xComponent.getForeground();
94                         aChild = new StringNode ("Foreground color: R"
95                             +       (nColor>>16&0xff)
96                             + "G" + (nColor>>8&0xff)
97                             + "B" + (nColor>>0&0xff)
98                             + "A" + (nColor>>24&0xff),
99                             aParent);
100                         break;
101                     case 5:
102                         nColor = xComponent.getBackground();
103                         aChild = new StringNode ("Background color: R"
104                             +       (nColor>>16&0xff)
105                             + "G" + (nColor>>8&0xff)
106                             + "B" + (nColor>>0&0xff)
107                             + "A" + (nColor>>24&0xff),
108                             aParent);
109                         break;
110                 }
111             }
112         }
113         return aChild;
114     }
115 
update(AccessibleTreeNode aNode)116     public void update (AccessibleTreeNode aNode)
117     {
118         maChildList.clear();
119         if (aNode instanceof AccTreeNode)
120             if (((AccTreeNode)aNode).getComponent() != null)
121                 maChildList.setSize (4);
122     }
123 }
124