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
30 public NodeHandler
createHandler( XAccessibleContext xContext
)
32 XAccessibleSelection xSelection
=
33 UnoRuntime
.queryInterface(
34 XAccessibleSelection
.class, xContext
);
35 return (xSelection
== null) ?
null :
36 new AccessibleSelectionHandler(xSelection
);
39 public AccessibleSelectionHandler()
43 public AccessibleSelectionHandler( XAccessibleSelection xSelection
)
45 if (xSelection
!= null)
46 maChildList
.setSize( 2 );
49 public AccessibleTreeNode
createChild( AccessibleTreeNode aParent
,
52 AccessibleTreeNode aChild
= null;
54 if( aParent
instanceof AccTreeNode
)
56 XAccessibleSelection xSelection
=
57 ((AccTreeNode
)aParent
).getSelection();
58 if( xSelection
!= null )
63 aChild
= new StringNode(
64 "getSelectedAccessibleChildCount: " +
65 xSelection
.getSelectedAccessibleChildCount(),
71 new VectorNode( "Selected Children", aParent
);
73 int nCount
= ((AccTreeNode
)aParent
).getContext().
74 getAccessibleChildCount();
77 for( int i
= 0; i
< nCount
; i
++ )
81 if( xSelection
.isAccessibleChildSelected( i
) )
83 XAccessible xSelChild
= xSelection
.
84 getSelectedAccessibleChild(nSelected
);
86 ((AccTreeNode
)aParent
).
87 getContext().getAccessibleChild( i
);
88 aVNode
.addChild( new StringNode(
90 xNChild
.getAccessibleContext().
91 getAccessibleDescription() + " (" +
92 (xSelChild
.equals(xNChild
) ?
"OK" : "XXX") +
96 catch (com
.sun
.star
.lang
.DisposedException e
)
98 aVNode
.addChild( new StringNode(
99 i
+ ": caught DisposedException while creating",
105 catch( IndexOutOfBoundsException e
)
107 aChild
= new StringNode( "IndexOutOfBounds",
113 aChild
= new StringNode( "ERROR", aParent
);
123 public String
[] getActions (AccessibleTreeNode aNode
)
125 if( aNode
instanceof AccTreeNode
)
127 XAccessibleSelection xSelection
=
128 ((AccTreeNode
)aNode
).getSelection();
129 if( xSelection
!= null )
131 return new String
[] { "Select..." };
134 return new String
[0];
137 public void performAction (AccessibleTreeNode aNode
, int nIndex
)
139 new SelectionDialog( (AccTreeNode
)aNode
).show();