2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 import com
.sun
.star
.uno
.UnoRuntime
;
20 import com
.sun
.star
.accessibility
.XAccessible
;
21 import com
.sun
.star
.accessibility
.XAccessibleContext
;
22 import com
.sun
.star
.accessibility
.XAccessibleSelection
;
23 import com
.sun
.star
.lang
.IndexOutOfBoundsException
;
27 class AccessibleSelectionHandler
31 public NodeHandler
createHandler( XAccessibleContext xContext
)
33 XAccessibleSelection xSelection
=
34 UnoRuntime
.queryInterface(
35 XAccessibleSelection
.class, xContext
);
36 return (xSelection
== null) ?
null :
37 new AccessibleSelectionHandler(xSelection
);
40 public AccessibleSelectionHandler()
44 private AccessibleSelectionHandler( XAccessibleSelection xSelection
)
46 if (xSelection
!= null)
47 maChildList
.setSize( 2 );
51 public AccessibleTreeNode
createChild( AccessibleTreeNode aParent
,
54 if( !(aParent
instanceof AccTreeNode
) )
57 XAccessibleSelection xSelection
= ((AccTreeNode
)aParent
).getSelection();
58 if( xSelection
== null )
61 AccessibleTreeNode aChild
= null;
66 aChild
= new StringNode(
67 "getSelectedAccessibleChildCount: " +
68 xSelection
.getSelectedAccessibleChildCount(),
74 new VectorNode( "Selected Children", aParent
);
76 long nCount
= ((AccTreeNode
)aParent
).getContext().
77 getAccessibleChildCount();
80 for( long i
= 0; i
< nCount
; i
++ )
84 if( xSelection
.isAccessibleChildSelected( i
) )
86 XAccessible xSelChild
= xSelection
.
87 getSelectedAccessibleChild(nSelected
);
89 ((AccTreeNode
)aParent
).
90 getContext().getAccessibleChild( i
);
91 aVNode
.addChild( new StringNode(
93 xNChild
.getAccessibleContext().
94 getAccessibleDescription() + " (" +
95 (xSelChild
.equals(xNChild
) ?
"OK" : "XXX") +
99 catch (com
.sun
.star
.lang
.DisposedException e
)
101 aVNode
.addChild( new StringNode(
102 i
+ ": caught DisposedException while creating",
108 catch( IndexOutOfBoundsException e
)
110 aChild
= new StringNode( "IndexOutOfBounds",
116 aChild
= new StringNode( "ERROR", aParent
);
125 public String
[] getActions (AccessibleTreeNode aNode
)
127 if( aNode
instanceof AccTreeNode
)
129 XAccessibleSelection xSelection
=
130 ((AccTreeNode
)aNode
).getSelection();
131 if( xSelection
!= null )
133 return new String
[] { "Select..." };
136 return new String
[0];
140 public void performAction (AccessibleTreeNode aNode
, int nIndex
)
142 SelectionDialog selectionDialog
= new SelectionDialog( (AccTreeNode
)aNode
);
143 selectionDialog
.setVisible(true);