nss: upgrade to release 3.73
[LibreOffice.git] / vcl / unx / gtk3 / a11y / gtk3atktable.cxx
blob221e55d2b287a2527282d93d75ed61fd56de5838
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "atkwrapper.hxx"
22 #include <com/sun/star/accessibility/XAccessibleTable.hpp>
23 #include <comphelper/sequence.hxx>
25 using namespace ::com::sun::star;
27 static AtkObject *
28 atk_object_wrapper_conditional_ref( const uno::Reference< accessibility::XAccessible >& rxAccessible )
30 if( rxAccessible.is() )
31 return atk_object_wrapper_ref( rxAccessible );
33 return nullptr;
36 /*****************************************************************************/
38 // FIXME
39 static const gchar *
40 getAsConst( const OUString& rString )
42 static const int nMax = 10;
43 static OString aUgly[nMax];
44 static int nIdx = 0;
45 nIdx = (nIdx + 1) % nMax;
46 aUgly[nIdx] = OUStringToOString( rString, RTL_TEXTENCODING_UTF8 );
47 return aUgly[ nIdx ].getStr();
50 /*****************************************************************************/
52 /// @throws uno::RuntimeException
53 static css::uno::Reference<css::accessibility::XAccessibleTable>
54 getTable( AtkTable *pTable )
56 AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER( pTable );
57 if( pWrap )
59 if( !pWrap->mpTable.is() )
61 pWrap->mpTable.set(pWrap->mpContext, css::uno::UNO_QUERY);
64 return pWrap->mpTable;
67 return css::uno::Reference<css::accessibility::XAccessibleTable>();
70 /*****************************************************************************/
72 extern "C" {
74 static AtkObject*
75 table_wrapper_ref_at (AtkTable *table,
76 gint row,
77 gint column)
79 try {
80 css::uno::Reference<css::accessibility::XAccessibleTable> pTable = getTable( table );
81 if( pTable.is() )
82 return atk_object_wrapper_conditional_ref( pTable->getAccessibleCellAt( row, column ) );
85 catch(const uno::Exception&) {
86 g_warning( "Exception in getAccessibleCellAt()" );
89 return nullptr;
92 /*****************************************************************************/
94 static gint
95 table_wrapper_get_index_at (AtkTable *table,
96 gint row,
97 gint column)
99 try {
100 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
101 = getTable( table );
102 if( pTable.is() )
103 return pTable->getAccessibleIndex( row, column );
105 catch(const uno::Exception&) {
106 g_warning( "Exception in getAccessibleIndex()" );
109 return -1;
112 /*****************************************************************************/
114 static gint
115 table_wrapper_get_column_at_index (AtkTable *table,
116 gint nIndex)
118 try {
119 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
120 = getTable( table );
121 if( pTable.is() )
122 return pTable->getAccessibleColumn( nIndex );
124 catch(const uno::Exception&) {
125 g_warning( "Exception in getAccessibleColumn()" );
128 return -1;
131 /*****************************************************************************/
133 static gint
134 table_wrapper_get_row_at_index( AtkTable *table,
135 gint nIndex )
137 try {
138 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
139 = getTable( table );
140 if( pTable.is() )
141 return pTable->getAccessibleRow( nIndex );
143 catch(const uno::Exception&) {
144 g_warning( "Exception in getAccessibleRow()" );
147 return -1;
150 /*****************************************************************************/
152 static gint
153 table_wrapper_get_n_columns( AtkTable *table )
155 try {
156 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
157 = getTable( table );
158 if( pTable.is() )
159 return pTable->getAccessibleColumnCount();
161 catch(const uno::Exception&) {
162 g_warning( "Exception in getAccessibleColumnCount()" );
165 return -1;
168 /*****************************************************************************/
170 static gint
171 table_wrapper_get_n_rows( AtkTable *table )
173 try {
174 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
175 = getTable( table );
176 if( pTable.is() )
177 return pTable->getAccessibleRowCount();
179 catch(const uno::Exception&) {
180 g_warning( "Exception in getAccessibleRowCount()" );
183 return -1;
186 /*****************************************************************************/
188 static gint
189 table_wrapper_get_column_extent_at( AtkTable *table,
190 gint row,
191 gint column )
193 try {
194 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
195 = getTable( table );
196 if( pTable.is() )
197 return pTable->getAccessibleColumnExtentAt( row, column );
199 catch(const uno::Exception&) {
200 g_warning( "Exception in getAccessibleColumnExtentAt()" );
203 return -1;
206 /*****************************************************************************/
208 static gint
209 table_wrapper_get_row_extent_at( AtkTable *table,
210 gint row,
211 gint column )
213 try {
214 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
215 = getTable( table );
216 if( pTable.is() )
217 return pTable->getAccessibleRowExtentAt( row, column );
219 catch(const uno::Exception&) {
220 g_warning( "Exception in getAccessibleRowExtentAt()" );
223 return -1;
226 /*****************************************************************************/
228 static AtkObject *
229 table_wrapper_get_caption( AtkTable *table )
231 try {
232 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
233 = getTable( table );
234 if( pTable.is() )
235 return atk_object_wrapper_conditional_ref( pTable->getAccessibleCaption() );
238 catch(const uno::Exception&) {
239 g_warning( "Exception in getAccessibleCaption()" );
242 return nullptr;
245 /*****************************************************************************/
247 static const gchar *
248 table_wrapper_get_row_description( AtkTable *table,
249 gint row )
251 try {
252 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
253 = getTable( table );
254 if( pTable.is() )
255 return getAsConst( pTable->getAccessibleRowDescription( row ) );
257 catch(const uno::Exception&) {
258 g_warning( "Exception in getAccessibleRowDescription()" );
261 return nullptr;
264 /*****************************************************************************/
266 static const gchar *
267 table_wrapper_get_column_description( AtkTable *table,
268 gint column )
270 try {
271 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
272 = getTable( table );
273 if( pTable.is() )
274 return getAsConst( pTable->getAccessibleColumnDescription( column ) );
276 catch(const uno::Exception&) {
277 g_warning( "Exception in getAccessibleColumnDescription()" );
280 return nullptr;
283 /*****************************************************************************/
285 static AtkObject *
286 table_wrapper_get_row_header( AtkTable *table,
287 gint row )
289 try {
290 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
291 = getTable( table );
292 if( pTable.is() )
294 uno::Reference< accessibility::XAccessibleTable > xRowHeaders( pTable->getAccessibleRowHeaders() );
295 if( xRowHeaders.is() )
296 return atk_object_wrapper_conditional_ref( xRowHeaders->getAccessibleCellAt( row, 0 ) );
299 catch(const uno::Exception&) {
300 g_warning( "Exception in getAccessibleRowHeaders()" );
303 return nullptr;
306 /*****************************************************************************/
308 static AtkObject *
309 table_wrapper_get_column_header( AtkTable *table,
310 gint column )
312 try {
313 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
314 = getTable( table );
315 if( pTable.is() )
317 uno::Reference< accessibility::XAccessibleTable > xColumnHeaders( pTable->getAccessibleColumnHeaders() );
318 if( xColumnHeaders.is() )
319 return atk_object_wrapper_conditional_ref( xColumnHeaders->getAccessibleCellAt( 0, column ) );
322 catch(const uno::Exception&) {
323 g_warning( "Exception in getAccessibleColumnHeaders()" );
326 return nullptr;
329 /*****************************************************************************/
331 static AtkObject *
332 table_wrapper_get_summary( AtkTable *table )
334 try {
335 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
336 = getTable( table );
337 if( pTable.is() )
339 return atk_object_wrapper_conditional_ref( pTable->getAccessibleSummary() );
342 catch(const uno::Exception&) {
343 g_warning( "Exception in getAccessibleSummary()" );
346 return nullptr;
349 /*****************************************************************************/
351 static gint
352 convertToGIntArray( const uno::Sequence< ::sal_Int32 >& aSequence, gint **pSelected )
354 if( aSequence.hasElements() )
356 *pSelected = g_new( gint, aSequence.getLength() );
358 *pSelected = comphelper::sequenceToArray(*pSelected, aSequence);
361 return aSequence.getLength();
364 /*****************************************************************************/
366 static gint
367 table_wrapper_get_selected_columns( AtkTable *table,
368 gint **pSelected )
370 *pSelected = nullptr;
371 try {
372 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
373 = getTable( table );
374 if( pTable.is() )
375 return convertToGIntArray( pTable->getSelectedAccessibleColumns(), pSelected );
377 catch(const uno::Exception&) {
378 g_warning( "Exception in getSelectedAccessibleColumns()" );
381 return 0;
384 /*****************************************************************************/
386 static gint
387 table_wrapper_get_selected_rows( AtkTable *table,
388 gint **pSelected )
390 *pSelected = nullptr;
391 try {
392 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
393 = getTable( table );
394 if( pTable.is() )
395 return convertToGIntArray( pTable->getSelectedAccessibleRows(), pSelected );
397 catch(const uno::Exception&) {
398 g_warning( "Exception in getSelectedAccessibleRows()" );
401 return 0;
404 /*****************************************************************************/
406 static gboolean
407 table_wrapper_is_column_selected( AtkTable *table,
408 gint column )
410 try {
411 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
412 = getTable( table );
413 if( pTable.is() )
414 return pTable->isAccessibleColumnSelected( column );
416 catch(const uno::Exception&) {
417 g_warning( "Exception in isAccessibleColumnSelected()" );
420 return 0;
423 /*****************************************************************************/
425 static gboolean
426 table_wrapper_is_row_selected( AtkTable *table,
427 gint row )
429 try {
430 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
431 = getTable( table );
432 if( pTable.is() )
433 return pTable->isAccessibleRowSelected( row );
435 catch(const uno::Exception&) {
436 g_warning( "Exception in isAccessibleRowSelected()" );
439 return FALSE;
442 /*****************************************************************************/
444 static gboolean
445 table_wrapper_is_selected( AtkTable *table,
446 gint row,
447 gint column )
449 try {
450 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
451 = getTable( table );
452 if( pTable.is() )
453 return pTable->isAccessibleSelected( row, column );
455 catch(const uno::Exception&) {
456 g_warning( "Exception in isAccessibleSelected()" );
459 return FALSE;
462 /*****************************************************************************/
464 static gboolean
465 table_wrapper_add_row_selection( AtkTable *, gint )
467 g_warning( "FIXME: no simple analogue for add_row_selection" );
468 return 0;
471 /*****************************************************************************/
473 static gboolean
474 table_wrapper_remove_row_selection( AtkTable *, gint )
476 g_warning( "FIXME: no simple analogue for remove_row_selection" );
477 return 0;
480 /*****************************************************************************/
482 static gboolean
483 table_wrapper_add_column_selection( AtkTable *, gint )
485 g_warning( "FIXME: no simple analogue for add_column_selection" );
486 return 0;
489 /*****************************************************************************/
491 static gboolean
492 table_wrapper_remove_column_selection( AtkTable *, gint )
494 g_warning( "FIXME: no simple analogue for remove_column_selection" );
495 return 0;
498 /*****************************************************************************/
500 static void
501 table_wrapper_set_caption( AtkTable *, AtkObject * )
502 { // meaningless helper
505 /*****************************************************************************/
507 static void
508 table_wrapper_set_column_description( AtkTable *, gint, const gchar * )
509 { // meaningless helper
512 /*****************************************************************************/
514 static void
515 table_wrapper_set_column_header( AtkTable *, gint, AtkObject * )
516 { // meaningless helper
519 /*****************************************************************************/
521 static void
522 table_wrapper_set_row_description( AtkTable *, gint, const gchar * )
523 { // meaningless helper
526 /*****************************************************************************/
528 static void
529 table_wrapper_set_row_header( AtkTable *, gint, AtkObject * )
530 { // meaningless helper
533 /*****************************************************************************/
535 static void
536 table_wrapper_set_summary( AtkTable *, AtkObject * )
537 { // meaningless helper
540 /*****************************************************************************/
542 } // extern "C"
544 void
545 tableIfaceInit (AtkTableIface *iface)
547 g_return_if_fail (iface != nullptr);
549 iface->ref_at = table_wrapper_ref_at;
550 iface->get_n_rows = table_wrapper_get_n_rows;
551 iface->get_n_columns = table_wrapper_get_n_columns;
552 iface->get_index_at = table_wrapper_get_index_at;
553 iface->get_column_at_index = table_wrapper_get_column_at_index;
554 iface->get_row_at_index = table_wrapper_get_row_at_index;
555 iface->is_row_selected = table_wrapper_is_row_selected;
556 iface->is_selected = table_wrapper_is_selected;
557 iface->get_selected_rows = table_wrapper_get_selected_rows;
558 iface->add_row_selection = table_wrapper_add_row_selection;
559 iface->remove_row_selection = table_wrapper_remove_row_selection;
560 iface->add_column_selection = table_wrapper_add_column_selection;
561 iface->remove_column_selection = table_wrapper_remove_column_selection;
562 iface->get_selected_columns = table_wrapper_get_selected_columns;
563 iface->is_column_selected = table_wrapper_is_column_selected;
564 iface->get_column_extent_at = table_wrapper_get_column_extent_at;
565 iface->get_row_extent_at = table_wrapper_get_row_extent_at;
566 iface->get_row_header = table_wrapper_get_row_header;
567 iface->set_row_header = table_wrapper_set_row_header;
568 iface->get_column_header = table_wrapper_get_column_header;
569 iface->set_column_header = table_wrapper_set_column_header;
570 iface->get_caption = table_wrapper_get_caption;
571 iface->set_caption = table_wrapper_set_caption;
572 iface->get_summary = table_wrapper_get_summary;
573 iface->set_summary = table_wrapper_set_summary;
574 iface->get_row_description = table_wrapper_get_row_description;
575 iface->set_row_description = table_wrapper_set_row_description;
576 iface->get_column_description = table_wrapper_get_column_description;
577 iface->set_column_description = table_wrapper_set_column_description;
580 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */