Debian Codegraph @

vcl/unx/gtk3/a11y/atktable.cxx

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include <sal/config.h>
21
22 #include <string_view>
23
24 #include "atkwrapper.hxx"
25
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>
30
31 using namespace ::com::sun::star;
32
33 static AtkObject *
34 atk_object_wrapper_conditional_ref( const uno::Reference< accessibility::XAccessible >& rxAccessible )
35 {
36 if( rxAccessible.is() )
37 return atk_object_wrapper_ref( rxAccessible );
38
39 return nullptr;
40 }
41
42 /*****************************************************************************/
43
44 // FIXME
45 static const gchar *
46 getAsConst( std::u16string_view rString )
47 {
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();
54 }
55
56 /*****************************************************************************/
57
58 /// @throws uno::RuntimeException
59 static css::uno::Reference<css::accessibility::XAccessibleTable>
60 getTable( AtkTable *pTable )
61 {
62 AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER( pTable );
63 if( pWrap )
64 {
65 if( !pWrap->mpTable.is() )
66 {
67 pWrap->mpTable.set(pWrap->mpContext, css::uno::UNO_QUERY);
68 }
69
70 return pWrap->mpTable;
71 }
72
73 return css::uno::Reference<css::accessibility::XAccessibleTable>();
74 }
75
76 static css::uno::Reference<css::accessibility::XAccessibleTableSelection>
77 getTableSelection(AtkTable *pTable)
78 {
79 AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER(pTable);
80 if (pWrap)
81 {
82 if (!pWrap->mpTableSelection.is())
83 {
84 pWrap->mpTableSelection.set(pWrap->mpContext, css::uno::UNO_QUERY);
85 }
86
87 return pWrap->mpTableSelection;
88 }
89
90 return css::uno::Reference<css::accessibility::XAccessibleTableSelection>();
91 }
92
93 /*****************************************************************************/
94
95 extern "C" {
96
97 static AtkObject*
98 table_wrapper_ref_at (AtkTable *table,
99 gint row,
100 gint column)
101 {
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 ) );
106 }
107
108 catch(const uno::Exception&) {
109 g_warning( "Exception in getAccessibleCellAt()" );
110 }
111
112 return nullptr;
113 }
114
115 /*****************************************************************************/
116
117 static gint
118 table_wrapper_get_index_at (AtkTable *table,
119 gint row,
120 gint column)
121 {
122 try {
123 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
124 = getTable( table );
125 if( pTable.is() )
126 {
127 sal_Int64 nIndex = pTable->getAccessibleIndex( row, column );
128 if (nIndex > std::numeric_limits<gint>::max())
129 {
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;
136 }
137 return nIndex;
138 }
139 }
140 catch(const uno::Exception&) {
141 g_warning( "Exception in getAccessibleIndex()" );
142 }
143
144 return -1;
145 }
146
147 /*****************************************************************************/
148
149 static gint
150 table_wrapper_get_column_at_index (AtkTable *table,
151 gint nIndex)
152 {
153 try {
154 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
155 = getTable( table );
156 if( pTable.is() )
157 return pTable->getAccessibleColumn( nIndex );
158 }
159 catch(const uno::Exception&) {
160 g_warning( "Exception in getAccessibleColumn()" );
161 }
162
163 return -1;
164 }
165
166 /*****************************************************************************/
167
168 static gint
169 table_wrapper_get_row_at_index( AtkTable *table,
170 gint nIndex )
171 {
172 try {
173 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
174 = getTable( table );
175 if( pTable.is() )
176 return pTable->getAccessibleRow( nIndex );
177 }
178 catch(const uno::Exception&) {
179 g_warning( "Exception in getAccessibleRow()" );
180 }
181
182 return -1;
183 }
184
185 /*****************************************************************************/
186
187 static gint
188 table_wrapper_get_n_columns( AtkTable *table )
189 {
190 try {
191 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
192 = getTable( table );
193 if( pTable.is() )
194 return pTable->getAccessibleColumnCount();
195 }
196 catch(const uno::Exception&) {
197 g_warning( "Exception in getAccessibleColumnCount()" );
198 }
199
200 return -1;
201 }
202
203 /*****************************************************************************/
204
205 static gint
206 table_wrapper_get_n_rows( AtkTable *table )
207 {
208 try {
209 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
210 = getTable( table );
211 if( pTable.is() )
212 return pTable->getAccessibleRowCount();
213 }
214 catch(const uno::Exception&) {
215 g_warning( "Exception in getAccessibleRowCount()" );
216 }
217
218 return -1;
219 }
220
221 /*****************************************************************************/
222
223 static gint
224 table_wrapper_get_column_extent_at( AtkTable *table,
225 gint row,
226 gint column )
227 {
228 try {
229 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
230 = getTable( table );
231 if( pTable.is() )
232 return pTable->getAccessibleColumnExtentAt( row, column );
233 }
234 catch(const uno::Exception&) {
235 g_warning( "Exception in getAccessibleColumnExtentAt()" );
236 }
237
238 return -1;
239 }
240
241 /*****************************************************************************/
242
243 static gint
244 table_wrapper_get_row_extent_at( AtkTable *table,
245 gint row,
246 gint column )
247 {
248 try {
249 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
250 = getTable( table );
251 if( pTable.is() )
252 return pTable->getAccessibleRowExtentAt( row, column );
253 }
254 catch(const uno::Exception&) {
255 g_warning( "Exception in getAccessibleRowExtentAt()" );
256 }
257
258 return -1;
259 }
260
261 /*****************************************************************************/
262
263 static AtkObject *
264 table_wrapper_get_caption( AtkTable *table )
265 {
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() );
271 }
272
273 catch(const uno::Exception&) {
274 g_warning( "Exception in getAccessibleCaption()" );
275 }
276
277 return nullptr;
278 }
279
280 /*****************************************************************************/
281
282 static const gchar *
283 table_wrapper_get_row_description( AtkTable *table,
284 gint row )
285 {
286 try {
287 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
288 = getTable( table );
289 if( pTable.is() )
290 return getAsConst( pTable->getAccessibleRowDescription( row ) );
291 }
292 catch(const uno::Exception&) {
293 g_warning( "Exception in getAccessibleRowDescription()" );
294 }
295
296 return nullptr;
297 }
298
299 /*****************************************************************************/
300
301 static const gchar *
302 table_wrapper_get_column_description( AtkTable *table,
303 gint column )
304 {
305 try {
306 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
307 = getTable( table );
308 if( pTable.is() )
309 return getAsConst( pTable->getAccessibleColumnDescription( column ) );
310 }
311 catch(const uno::Exception&) {
312 g_warning( "Exception in getAccessibleColumnDescription()" );
313 }
314
315 return nullptr;
316 }
317
318 /*****************************************************************************/
319
320 static AtkObject *
321 table_wrapper_get_row_header( AtkTable *table,
322 gint row )
323 {
324 try {
325 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
326 = getTable( table );
327 if( pTable.is() )
328 {
329 uno::Reference< accessibility::XAccessibleTable > xRowHeaders( pTable->getAccessibleRowHeaders() );
330 if( xRowHeaders.is() )
331 return atk_object_wrapper_conditional_ref( xRowHeaders->getAccessibleCellAt( row, 0 ) );
332 }
333 }
334 catch(const uno::Exception&) {
335 g_warning( "Exception in getAccessibleRowHeaders()" );
336 }
337
338 return nullptr;
339 }
340
341 /*****************************************************************************/
342
343 static AtkObject *
344 table_wrapper_get_column_header( AtkTable *table,
345 gint column )
346 {
347 try {
348 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
349 = getTable( table );
350 if( pTable.is() )
351 {
352 uno::Reference< accessibility::XAccessibleTable > xColumnHeaders( pTable->getAccessibleColumnHeaders() );
353 if( xColumnHeaders.is() )
354 return atk_object_wrapper_conditional_ref( xColumnHeaders->getAccessibleCellAt( 0, column ) );
355 }
356 }
357 catch(const uno::Exception&) {
358 g_warning( "Exception in getAccessibleColumnHeaders()" );
359 }
360
361 return nullptr;
362 }
363
364 /*****************************************************************************/
365
366 static AtkObject *
367 table_wrapper_get_summary( AtkTable *table )
368 {
369 try {
370 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
371 = getTable( table );
372 if( pTable.is() )
373 {
374 return atk_object_wrapper_conditional_ref( pTable->getAccessibleSummary() );
375 }
376 }
377 catch(const uno::Exception&) {
378 g_warning( "Exception in getAccessibleSummary()" );
379 }
380
381 return nullptr;
382 }
383
384 /*****************************************************************************/
385
386 static gint
387 convertToGIntArray( const uno::Sequence< ::sal_Int32 >& aSequence, gint **pSelected )
388 {
389 if( aSequence.hasElements() )
390 {
391 *pSelected = g_new( gint, aSequence.getLength() );
392
393 *pSelected = comphelper::sequenceToArray(*pSelected, aSequence);
394 }
395
396 return aSequence.getLength();
397 }
398
399 /*****************************************************************************/
400
401 static gint
402 table_wrapper_get_selected_columns( AtkTable *table,
403 gint **pSelected )
404 {
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 );
411 }
412 catch(const uno::Exception&) {
413 g_warning( "Exception in getSelectedAccessibleColumns()" );
414 }
415
416 return 0;
417 }
418
419 /*****************************************************************************/
420
421 static gint
422 table_wrapper_get_selected_rows( AtkTable *table,
423 gint **pSelected )
424 {
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 );
431 }
432 catch(const uno::Exception&) {
433 g_warning( "Exception in getSelectedAccessibleRows()" );
434 }
435
436 return 0;
437 }
438
439 /*****************************************************************************/
440
441 static gboolean
442 table_wrapper_is_column_selected( AtkTable *table,
443 gint column )
444 {
445 try {
446 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
447 = getTable( table );
448 if( pTable.is() )
449 return pTable->isAccessibleColumnSelected( column );
450 }
451 catch(const uno::Exception&) {
452 g_warning( "Exception in isAccessibleColumnSelected()" );
453 }
454
455 return 0;
456 }
457
458 /*****************************************************************************/
459
460 static gboolean
461 table_wrapper_is_row_selected( AtkTable *table,
462 gint row )
463 {
464 try {
465 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
466 = getTable( table );
467 if( pTable.is() )
468 return pTable->isAccessibleRowSelected( row );
469 }
470 catch(const uno::Exception&) {
471 g_warning( "Exception in isAccessibleRowSelected()" );
472 }
473
474 return FALSE;
475 }
476
477 /*****************************************************************************/
478
479 static gboolean
480 table_wrapper_is_selected( AtkTable *table,
481 gint row,
482 gint column )
483 {
484 try {
485 css::uno::Reference<css::accessibility::XAccessibleTable> pTable
486 = getTable( table );
487 if( pTable.is() )
488 return pTable->isAccessibleSelected( row, column );
489 }
490 catch(const uno::Exception&) {
491 g_warning( "Exception in isAccessibleSelected()" );
492 }
493
494 return FALSE;
495 }
496
497 /*****************************************************************************/
498
499 static gboolean
500 table_wrapper_add_row_selection(AtkTable *pTable, gint row)
501 {
502 try {
503 css::uno::Reference<css::accessibility::XAccessibleTableSelection> xTableSelection = getTableSelection(pTable);
504 if (xTableSelection.is())
505 return xTableSelection->selectRow(row);
506 }
507 catch(const uno::Exception&) {
508 g_warning( "Exception in selectRow()" );
509 }
510
511 return false;
512 }
513
514 /*****************************************************************************/
515
516 static gboolean
517 table_wrapper_remove_row_selection(AtkTable *pTable, gint row)
518 {
519 try {
520 css::uno::Reference<css::accessibility::XAccessibleTableSelection> xTableSelection = getTableSelection(pTable);
521 if (xTableSelection.is())
522 return xTableSelection->unselectRow(row);
523 }
524 catch(const uno::Exception&) {
525 g_warning( "Exception in unselectRow()" );
526 }
527
528 return false;
529 }
530
531 /*****************************************************************************/
532
533 static gboolean
534 table_wrapper_add_column_selection(AtkTable *pTable, gint column)
535 {
536 try {
537 css::uno::Reference<css::accessibility::XAccessibleTableSelection> xTableSelection = getTableSelection(pTable);
538 if (xTableSelection.is())
539 return xTableSelection->selectColumn(column);
540 }
541 catch(const uno::Exception&) {
542 g_warning( "Exception in selectColumn()" );
543 }
544
545 return false;
546 }
547
548 /*****************************************************************************/
549
550 static gboolean
551 table_wrapper_remove_column_selection(AtkTable *pTable, gint column)
552 {
553 try {
554 css::uno::Reference<css::accessibility::XAccessibleTableSelection> xTableSelection = getTableSelection(pTable);
555 if (xTableSelection.is())
556 return xTableSelection->unselectColumn(column);
557 }
558 catch(const uno::Exception&) {
559 g_warning( "Exception in unselectColumn()" );
560 }
561
562 return false;
563 }
564
565 /*****************************************************************************/
566
567 static void
568 table_wrapper_set_caption( AtkTable *, AtkObject * )
569 { // meaningless helper
570 }
571
572 /*****************************************************************************/
573
574 static void
575 table_wrapper_set_column_description( AtkTable *, gint, const gchar * )
576 { // meaningless helper
577 }
578
579 /*****************************************************************************/
580
581 static void
582 table_wrapper_set_column_header( AtkTable *, gint, AtkObject * )
583 { // meaningless helper
584 }
585
586 /*****************************************************************************/
587
588 static void
589 table_wrapper_set_row_description( AtkTable *, gint, const gchar * )
590 { // meaningless helper
591 }
592
593 /*****************************************************************************/
594
595 static void
596 table_wrapper_set_row_header( AtkTable *, gint, AtkObject * )
597 { // meaningless helper
598 }
599
600 /*****************************************************************************/
601
602 static void
603 table_wrapper_set_summary( AtkTable *, AtkObject * )
604 { // meaningless helper
605 }
606
607 /*****************************************************************************/
608
609 } // extern "C"
610
611 void
612 tableIfaceInit (gpointer iface_, gpointer)
613 {
614 auto const iface = static_cast<AtkTableIface *>(iface_);
615 g_return_if_fail (iface != nullptr);
616
617 iface->ref_at = table_wrapper_ref_at;
618 iface->get_n_rows = table_wrapper_get_n_rows;
619 iface->get_n_columns = table_wrapper_get_n_columns;
620 iface->get_index_at = table_wrapper_get_index_at;
621 iface->get_column_at_index = table_wrapper_get_column_at_index;
622 iface->get_row_at_index = table_wrapper_get_row_at_index;
623 iface->is_row_selected = table_wrapper_is_row_selected;
624 iface->is_selected = table_wrapper_is_selected;
625 iface->get_selected_rows = table_wrapper_get_selected_rows;
626 iface->add_row_selection = table_wrapper_add_row_selection;
627 iface->remove_row_selection = table_wrapper_remove_row_selection;
628 iface->add_column_selection = table_wrapper_add_column_selection;
629 iface->remove_column_selection = table_wrapper_remove_column_selection;
630 iface->get_selected_columns = table_wrapper_get_selected_columns;
631 iface->is_column_selected = table_wrapper_is_column_selected;
632 iface->get_column_extent_at = table_wrapper_get_column_extent_at;
633 iface->get_row_extent_at = table_wrapper_get_row_extent_at;
634 iface->get_row_header = table_wrapper_get_row_header;
635 iface->set_row_header = table_wrapper_set_row_header;
636 iface->get_column_header = table_wrapper_get_column_header;
637 iface->set_column_header = table_wrapper_set_column_header;
638 iface->get_caption = table_wrapper_get_caption;
639 iface->set_caption = table_wrapper_set_caption;
640 iface->get_summary = table_wrapper_get_summary;
641 iface->set_summary = table_wrapper_set_summary;
642 iface->get_row_description = table_wrapper_get_row_description;
643 iface->set_row_description = table_wrapper_set_row_description;
644 iface->get_column_description = table_wrapper_get_column_description;
645 iface->set_column_description = table_wrapper_set_column_description;
646 }
647
648 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */