bump product version to 7.6.3.2-android
[LibreOffice.git] / vcl / unx / gtk3 / a11y / atktable.cxx
blob021f3c19c42cc75802c64440e2dae311432ab7c2
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 <sal/config.h>
22 #include <string_view>
24 #include "atkwrapper.hxx"
26 #include <com/sun/star/accessibility/XAccessibleTable.hpp>
27 #include <com/sun/star/accessibility/XAccessibleTableSelection.hpp>
28 #include <comphelper/sequence.hxx>
29 #include <sal/log.hxx>
31 using namespace ::com::sun::star;
33 static AtkObject *
34 atk_object_wrapper_conditional_ref( const uno::Reference< accessibility::XAccessible >& rxAccessible )
36 if( rxAccessible.is() )
37 return atk_object_wrapper_ref( rxAccessible );
39 return nullptr;
42 /*****************************************************************************/
44 // FIXME
45 static const gchar *
46 getAsConst( std::u16string_view rString )
48 static const int nMax = 10;
49 static OString aUgly[nMax];
50 static int nIdx = 0;
51 nIdx = (nIdx + 1) % nMax;
52 aUgly[nIdx] = OUStringToOString( rString, RTL_TEXTENCODING_UTF8 );
53 return aUgly[ nIdx ].getStr();
56 /*****************************************************************************/
58 /// @throws uno::RuntimeException
59 static css::uno::Reference<css::accessibility::XAccessibleTable>
60 getTable( AtkTable *pTable )
62 AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER( pTable );
63 if( pWrap )
65 if( !pWrap->mpTable.is() )
67 pWrap->mpTable.set(pWrap->mpContext, css::uno::UNO_QUERY);
70 return pWrap->mpTable;
73 return css::uno::Reference<css::accessibility::XAccessibleTable>();
76 static css::uno::Reference<css::accessibility::XAccessibleTableSelection>
77 getTableSelection(AtkTable *pTable)
79 AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER(pTable);
80 if (pWrap)
82 if (!pWrap->mpTableSelection.is())
84 pWrap->mpTableSelection.set(pWrap->mpContext, css::uno::UNO_QUERY);
87 return pWrap->mpTableSelection;
90 return css::uno::Reference<css::accessibility::XAccessibleTableSelection>();
93 /*****************************************************************************/
95 extern "C" {
97 static AtkObject*
98 table_wrapper_ref_at (AtkTable *table,
99 gint row,
100 gint column)
102 try {
103 css::uno::Reference<css::accessibility::XAccessibleTable> pTable = getTable( table );
104 if( pTable.is() )
105 return atk_object_wrapper_conditional_ref( pTable->getAccessibleCellAt( row, column ) );
108 catch(const uno::Exception&) {
109 g_warning( "Exception in getAccessibleCellAt()" );
112 return nullptr;
115 /*****************************************************************************/
117 static gint
118 table_wrapper_get_index_at (AtkTable *table,
119 gint row,
120 gint column)
122 try {
123 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
124 = getTable( table );
125 if( pTable.is() )
127 sal_Int64 nIndex = pTable->getAccessibleIndex( row, column );
128 if (nIndex > std::numeric_limits<gint>::max())
130 // use -2 when the child index is too large to fit into 32 bit to neither use the
131 // valid index of another cell nor -1, which might easily be interpreted as the cell
132 // not/no longer being valid
133 SAL_WARN("vcl.gtk", "table_wrapper_get_index_at: Child index exceeds maximum gint value, "
134 "returning -2.");
135 nIndex = -2;
137 return nIndex;
140 catch(const uno::Exception&) {
141 g_warning( "Exception in getAccessibleIndex()" );
144 return -1;
147 /*****************************************************************************/
149 static gint
150 table_wrapper_get_column_at_index (AtkTable *table,
151 gint nIndex)
153 try {
154 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
155 = getTable( table );
156 if( pTable.is() )
157 return pTable->getAccessibleColumn( nIndex );
159 catch(const uno::Exception&) {
160 g_warning( "Exception in getAccessibleColumn()" );
163 return -1;
166 /*****************************************************************************/
168 static gint
169 table_wrapper_get_row_at_index( AtkTable *table,
170 gint nIndex )
172 try {
173 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
174 = getTable( table );
175 if( pTable.is() )
176 return pTable->getAccessibleRow( nIndex );
178 catch(const uno::Exception&) {
179 g_warning( "Exception in getAccessibleRow()" );
182 return -1;
185 /*****************************************************************************/
187 static gint
188 table_wrapper_get_n_columns( AtkTable *table )
190 try {
191 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
192 = getTable( table );
193 if( pTable.is() )
194 return pTable->getAccessibleColumnCount();
196 catch(const uno::Exception&) {
197 g_warning( "Exception in getAccessibleColumnCount()" );
200 return -1;
203 /*****************************************************************************/
205 static gint
206 table_wrapper_get_n_rows( AtkTable *table )
208 try {
209 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
210 = getTable( table );
211 if( pTable.is() )
212 return pTable->getAccessibleRowCount();
214 catch(const uno::Exception&) {
215 g_warning( "Exception in getAccessibleRowCount()" );
218 return -1;
221 /*****************************************************************************/
223 static gint
224 table_wrapper_get_column_extent_at( AtkTable *table,
225 gint row,
226 gint column )
228 try {
229 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
230 = getTable( table );
231 if( pTable.is() )
232 return pTable->getAccessibleColumnExtentAt( row, column );
234 catch(const uno::Exception&) {
235 g_warning( "Exception in getAccessibleColumnExtentAt()" );
238 return -1;
241 /*****************************************************************************/
243 static gint
244 table_wrapper_get_row_extent_at( AtkTable *table,
245 gint row,
246 gint column )
248 try {
249 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
250 = getTable( table );
251 if( pTable.is() )
252 return pTable->getAccessibleRowExtentAt( row, column );
254 catch(const uno::Exception&) {
255 g_warning( "Exception in getAccessibleRowExtentAt()" );
258 return -1;
261 /*****************************************************************************/
263 static AtkObject *
264 table_wrapper_get_caption( AtkTable *table )
266 try {
267 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
268 = getTable( table );
269 if( pTable.is() )
270 return atk_object_wrapper_conditional_ref( pTable->getAccessibleCaption() );
273 catch(const uno::Exception&) {
274 g_warning( "Exception in getAccessibleCaption()" );
277 return nullptr;
280 /*****************************************************************************/
282 static const gchar *
283 table_wrapper_get_row_description( AtkTable *table,
284 gint row )
286 try {
287 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
288 = getTable( table );
289 if( pTable.is() )
290 return getAsConst( pTable->getAccessibleRowDescription( row ) );
292 catch(const uno::Exception&) {
293 g_warning( "Exception in getAccessibleRowDescription()" );
296 return nullptr;
299 /*****************************************************************************/
301 static const gchar *
302 table_wrapper_get_column_description( AtkTable *table,
303 gint column )
305 try {
306 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
307 = getTable( table );
308 if( pTable.is() )
309 return getAsConst( pTable->getAccessibleColumnDescription( column ) );
311 catch(const uno::Exception&) {
312 g_warning( "Exception in getAccessibleColumnDescription()" );
315 return nullptr;
318 /*****************************************************************************/
320 static AtkObject *
321 table_wrapper_get_row_header( AtkTable *table,
322 gint row )
324 try {
325 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
326 = getTable( table );
327 if( pTable.is() )
329 uno::Reference< accessibility::XAccessibleTable > xRowHeaders( pTable->getAccessibleRowHeaders() );
330 if( xRowHeaders.is() )
331 return atk_object_wrapper_conditional_ref( xRowHeaders->getAccessibleCellAt( row, 0 ) );
334 catch(const uno::Exception&) {
335 g_warning( "Exception in getAccessibleRowHeaders()" );
338 return nullptr;
341 /*****************************************************************************/
343 static AtkObject *
344 table_wrapper_get_column_header( AtkTable *table,
345 gint column )
347 try {
348 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
349 = getTable( table );
350 if( pTable.is() )
352 uno::Reference< accessibility::XAccessibleTable > xColumnHeaders( pTable->getAccessibleColumnHeaders() );
353 if( xColumnHeaders.is() )
354 return atk_object_wrapper_conditional_ref( xColumnHeaders->getAccessibleCellAt( 0, column ) );
357 catch(const uno::Exception&) {
358 g_warning( "Exception in getAccessibleColumnHeaders()" );
361 return nullptr;
364 /*****************************************************************************/
366 static AtkObject *
367 table_wrapper_get_summary( AtkTable *table )
369 try {
370 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
371 = getTable( table );
372 if( pTable.is() )
374 return atk_object_wrapper_conditional_ref( pTable->getAccessibleSummary() );
377 catch(const uno::Exception&) {
378 g_warning( "Exception in getAccessibleSummary()" );
381 return nullptr;
384 /*****************************************************************************/
386 static gint
387 convertToGIntArray( const uno::Sequence< ::sal_Int32 >& aSequence, gint **pSelected )
389 if( aSequence.hasElements() )
391 *pSelected = g_new( gint, aSequence.getLength() );
393 *pSelected = comphelper::sequenceToArray(*pSelected, aSequence);
396 return aSequence.getLength();
399 /*****************************************************************************/
401 static gint
402 table_wrapper_get_selected_columns( AtkTable *table,
403 gint **pSelected )
405 *pSelected = nullptr;
406 try {
407 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
408 = getTable( table );
409 if( pTable.is() )
410 return convertToGIntArray( pTable->getSelectedAccessibleColumns(), pSelected );
412 catch(const uno::Exception&) {
413 g_warning( "Exception in getSelectedAccessibleColumns()" );
416 return 0;
419 /*****************************************************************************/
421 static gint
422 table_wrapper_get_selected_rows( AtkTable *table,
423 gint **pSelected )
425 *pSelected = nullptr;
426 try {
427 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
428 = getTable( table );
429 if( pTable.is() )
430 return convertToGIntArray( pTable->getSelectedAccessibleRows(), pSelected );
432 catch(const uno::Exception&) {
433 g_warning( "Exception in getSelectedAccessibleRows()" );
436 return 0;
439 /*****************************************************************************/
441 static gboolean
442 table_wrapper_is_column_selected( AtkTable *table,
443 gint column )
445 try {
446 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
447 = getTable( table );
448 if( pTable.is() )
449 return pTable->isAccessibleColumnSelected( column );
451 catch(const uno::Exception&) {
452 g_warning( "Exception in isAccessibleColumnSelected()" );
455 return 0;
458 /*****************************************************************************/
460 static gboolean
461 table_wrapper_is_row_selected( AtkTable *table,
462 gint row )
464 try {
465 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
466 = getTable( table );
467 if( pTable.is() )
468 return pTable->isAccessibleRowSelected( row );
470 catch(const uno::Exception&) {
471 g_warning( "Exception in isAccessibleRowSelected()" );
474 return FALSE;
477 /*****************************************************************************/
479 static gboolean
480 table_wrapper_is_selected( AtkTable *table,
481 gint row,
482 gint column )
484 try {
485 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
486 = getTable( table );
487 if( pTable.is() )
488 return pTable->isAccessibleSelected( row, column );
490 catch(const uno::Exception&) {
491 g_warning( "Exception in isAccessibleSelected()" );
494 return FALSE;
497 /*****************************************************************************/
499 static gboolean
500 table_wrapper_add_row_selection(AtkTable *pTable, gint row)
502 try {
503 css::uno::Reference<css::accessibility::XAccessibleTableSelection> xTableSelection = getTableSelection(pTable);
504 if (xTableSelection.is())
505 return xTableSelection->selectRow(row);
507 catch(const uno::Exception&) {
508 g_warning( "Exception in selectRow()" );
511 return false;
514 /*****************************************************************************/
516 static gboolean
517 table_wrapper_remove_row_selection(AtkTable *pTable, gint row)
519 try {
520 css::uno::Reference<css::accessibility::XAccessibleTableSelection> xTableSelection = getTableSelection(pTable);
521 if (xTableSelection.is())
522 return xTableSelection->unselectRow(row);
524 catch(const uno::Exception&) {
525 g_warning( "Exception in unselectRow()" );
528 return false;
531 /*****************************************************************************/
533 static gboolean
534 table_wrapper_add_column_selection(AtkTable *pTable, gint column)
536 try {
537 css::uno::Reference<css::accessibility::XAccessibleTableSelection> xTableSelection = getTableSelection(pTable);
538 if (xTableSelection.is())
539 return xTableSelection->selectColumn(column);
541 catch(const uno::Exception&) {
542 g_warning( "Exception in selectColumn()" );
545 return false;
548 /*****************************************************************************/
550 static gboolean
551 table_wrapper_remove_column_selection(AtkTable *pTable, gint column)
553 try {
554 css::uno::Reference<css::accessibility::XAccessibleTableSelection> xTableSelection = getTableSelection(pTable);
555 if (xTableSelection.is())
556 return xTableSelection->unselectColumn(column);
558 catch(const uno::Exception&) {
559 g_warning( "Exception in unselectColumn()" );
562 return false;
565 /*****************************************************************************/
567 static void
568 table_wrapper_set_caption( AtkTable *, AtkObject * )
569 { // meaningless helper
572 /*****************************************************************************/
574 static void
575 table_wrapper_set_column_description( AtkTable *, gint, const gchar * )
576 { // meaningless helper
579 /*****************************************************************************/
581 static void
582 table_wrapper_set_column_header( AtkTable *, gint, AtkObject * )
583 { // meaningless helper
586 /*****************************************************************************/
588 static void
589 table_wrapper_set_row_description( AtkTable *, gint, const gchar * )
590 { // meaningless helper
593 /*****************************************************************************/
595 static void
596 table_wrapper_set_row_header( AtkTable *, gint, AtkObject * )
597 { // meaningless helper
600 /*****************************************************************************/
602 static void
603 table_wrapper_set_summary( AtkTable *, AtkObject * )
604 { // meaningless helper
607 /*****************************************************************************/
609 } // extern "C"
611 void
612 tableIfaceInit (AtkTableIface *iface)
614 g_return_if_fail (iface != nullptr);
616 iface->ref_at = table_wrapper_ref_at;
617 iface->get_n_rows = table_wrapper_get_n_rows;
618 iface->get_n_columns = table_wrapper_get_n_columns;
619 iface->get_index_at = table_wrapper_get_index_at;
620 iface->get_column_at_index = table_wrapper_get_column_at_index;
621 iface->get_row_at_index = table_wrapper_get_row_at_index;
622 iface->is_row_selected = table_wrapper_is_row_selected;
623 iface->is_selected = table_wrapper_is_selected;
624 iface->get_selected_rows = table_wrapper_get_selected_rows;
625 iface->add_row_selection = table_wrapper_add_row_selection;
626 iface->remove_row_selection = table_wrapper_remove_row_selection;
627 iface->add_column_selection = table_wrapper_add_column_selection;
628 iface->remove_column_selection = table_wrapper_remove_column_selection;
629 iface->get_selected_columns = table_wrapper_get_selected_columns;
630 iface->is_column_selected = table_wrapper_is_column_selected;
631 iface->get_column_extent_at = table_wrapper_get_column_extent_at;
632 iface->get_row_extent_at = table_wrapper_get_row_extent_at;
633 iface->get_row_header = table_wrapper_get_row_header;
634 iface->set_row_header = table_wrapper_set_row_header;
635 iface->get_column_header = table_wrapper_get_column_header;
636 iface->set_column_header = table_wrapper_set_column_header;
637 iface->get_caption = table_wrapper_get_caption;
638 iface->set_caption = table_wrapper_set_caption;
639 iface->get_summary = table_wrapper_get_summary;
640 iface->set_summary = table_wrapper_set_summary;
641 iface->get_row_description = table_wrapper_get_row_description;
642 iface->set_row_description = table_wrapper_set_row_description;
643 iface->get_column_description = table_wrapper_get_column_description;
644 iface->set_column_description = table_wrapper_set_column_description;
647 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */