tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / toolkit / test / accessibility / AccessibleSelectionHandler.java
blob41eae0d980fa07342f7ad9b8f1bc09bd5178f986
1 /*
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
28 extends NodeHandler
30 @Override
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 );
50 @Override
51 public AccessibleTreeNode createChild( AccessibleTreeNode aParent,
52 int nIndex )
54 if( !(aParent instanceof AccTreeNode) )
55 return null;
57 XAccessibleSelection xSelection = ((AccTreeNode)aParent).getSelection();
58 if( xSelection == null )
59 return null;
61 AccessibleTreeNode aChild = null;
63 switch( nIndex )
65 case 0:
66 aChild = new StringNode(
67 "getSelectedAccessibleChildCount: " +
68 xSelection.getSelectedAccessibleChildCount(),
69 aParent );
70 break;
71 case 1:
73 VectorNode aVNode =
74 new VectorNode( "Selected Children", aParent);
75 long nSelected = 0;
76 long nCount = ((AccTreeNode)aParent).getContext().
77 getAccessibleChildCount();
78 try
80 for( long i = 0; i < nCount; i++ )
82 try
84 if( xSelection.isAccessibleChildSelected( i ) )
86 XAccessible xSelChild = xSelection.
87 getSelectedAccessibleChild(nSelected);
88 XAccessible xNChild =
89 ((AccTreeNode)aParent).
90 getContext().getAccessibleChild( i );
91 aVNode.addChild( new StringNode(
92 i + ": " +
93 xNChild.getAccessibleContext().
94 getAccessibleDescription() + " (" +
95 (xSelChild.equals(xNChild) ? "OK" : "XXX") +
96 ")", aParent ) );
99 catch (com.sun.star.lang.DisposedException e)
101 aVNode.addChild( new StringNode(
102 i + ": caught DisposedException while creating",
103 aParent ));
106 aChild = aVNode;
108 catch( IndexOutOfBoundsException e )
110 aChild = new StringNode( "IndexOutOfBounds",
111 aParent );
114 break;
115 default:
116 aChild = new StringNode( "ERROR", aParent );
117 break;
120 return aChild;
124 @Override
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];
139 @Override
140 public void performAction (AccessibleTreeNode aNode, int nIndex)
142 SelectionDialog selectionDialog = new SelectionDialog( (AccTreeNode)aNode );
143 selectionDialog.setVisible(true);