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 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_vcl.hxx" 26 27 #include "atkwrapper.hxx" 28 29 #include <com/sun/star/accessibility/XAccessibleSelection.hpp> 30 31 #include <stdio.h> 32 33 using namespace ::com::sun::star; 34 35 static accessibility::XAccessibleSelection* 36 getSelection( AtkSelection *pSelection ) throw (uno::RuntimeException) 37 { 38 AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER( pSelection ); 39 if( pWrap ) 40 { 41 if( !pWrap->mpSelection && pWrap->mpContext ) 42 { 43 uno::Any any = pWrap->mpContext->queryInterface( accessibility::XAccessibleSelection::static_type(NULL) ); 44 pWrap->mpSelection = reinterpret_cast< accessibility::XAccessibleSelection * > (any.pReserved); 45 pWrap->mpSelection->acquire(); 46 } 47 48 return pWrap->mpSelection; 49 } 50 51 return NULL; 52 } 53 54 extern "C" { 55 56 static gboolean 57 selection_add_selection( AtkSelection *selection, 58 gint i ) 59 { 60 try { 61 accessibility::XAccessibleSelection* pSelection = getSelection( selection ); 62 if( pSelection ) 63 { 64 pSelection->selectAccessibleChild( i ); 65 return TRUE; 66 } 67 } 68 catch(const uno::Exception& e) { 69 g_warning( "Exception in selectAccessibleChild()" ); 70 } 71 72 return FALSE; 73 } 74 75 static gboolean 76 selection_clear_selection( AtkSelection *selection ) 77 { 78 try { 79 accessibility::XAccessibleSelection* pSelection = getSelection( selection ); 80 if( pSelection ) 81 { 82 pSelection->clearAccessibleSelection(); 83 return TRUE; 84 } 85 } 86 catch(const uno::Exception& e) { 87 g_warning( "Exception in selectAccessibleChild()" ); 88 } 89 90 return FALSE; 91 } 92 93 static AtkObject* 94 selection_ref_selection( AtkSelection *selection, 95 gint i ) 96 { 97 try { 98 accessibility::XAccessibleSelection* pSelection = getSelection( selection ); 99 if( pSelection ) 100 return atk_object_wrapper_ref( pSelection->getSelectedAccessibleChild( i ) ); 101 } 102 catch(const uno::Exception& e) { 103 g_warning( "Exception in getSelectedAccessibleChild()" ); 104 } 105 106 return NULL; 107 } 108 109 static gint 110 selection_get_selection_count( AtkSelection *selection) 111 { 112 try { 113 accessibility::XAccessibleSelection* pSelection = getSelection( selection ); 114 if( pSelection ) 115 return pSelection->getSelectedAccessibleChildCount(); 116 } 117 catch(const uno::Exception& e) { 118 g_warning( "Exception in getSelectedAccessibleChildCount()" ); 119 } 120 121 return -1; 122 } 123 124 static gboolean 125 selection_is_child_selected( AtkSelection *selection, 126 gint i) 127 { 128 try { 129 accessibility::XAccessibleSelection* pSelection = getSelection( selection ); 130 if( pSelection ) 131 return pSelection->isAccessibleChildSelected( i ); 132 } 133 catch(const uno::Exception& e) { 134 g_warning( "Exception in getSelectedAccessibleChildCount()" ); 135 } 136 137 return FALSE; 138 } 139 140 static gboolean 141 selection_remove_selection( AtkSelection *selection, 142 gint i ) 143 { 144 try { 145 accessibility::XAccessibleSelection* pSelection = getSelection( selection ); 146 if( pSelection ) 147 { 148 pSelection->deselectAccessibleChild( i ); 149 return TRUE; 150 } 151 } 152 catch(const uno::Exception& e) { 153 g_warning( "Exception in getSelectedAccessibleChildCount()" ); 154 } 155 156 return FALSE; 157 } 158 159 static gboolean 160 selection_select_all_selection( AtkSelection *selection) 161 { 162 try { 163 accessibility::XAccessibleSelection* pSelection = getSelection( selection ); 164 if( pSelection ) 165 { 166 pSelection->selectAllAccessibleChildren(); 167 return TRUE; 168 } 169 } 170 catch(const uno::Exception& e) { 171 g_warning( "Exception in getSelectedAccessibleChildCount()" ); 172 } 173 174 return FALSE; 175 } 176 177 } // extern "C" 178 179 void 180 selectionIfaceInit( AtkSelectionIface *iface) 181 { 182 g_return_if_fail (iface != NULL); 183 184 iface->add_selection = selection_add_selection; 185 iface->clear_selection = selection_clear_selection; 186 iface->ref_selection = selection_ref_selection; 187 iface->get_selection_count = selection_get_selection_count; 188 iface->is_child_selected = selection_is_child_selected; 189 iface->remove_selection = selection_remove_selection; 190 iface->select_all_selection = selection_select_all_selection; 191 } 192