1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
;
34 atk_object_wrapper_conditional_ref( const uno::Reference
< accessibility::XAccessible
>& rxAccessible
)
36 if( rxAccessible
.is() )
37 return atk_object_wrapper_ref( rxAccessible
);
42 /*****************************************************************************/
46 getAsConst( std::u16string_view rString
)
48 static const int nMax
= 10;
49 static OString aUgly
[nMax
];
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
);
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
);
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 /*****************************************************************************/
98 table_wrapper_ref_at (AtkTable
*table
,
103 css::uno::Reference
<css::accessibility::XAccessibleTable
> pTable
= getTable( table
);
105 return atk_object_wrapper_conditional_ref( pTable
->getAccessibleCellAt( row
, column
) );
108 catch(const uno::Exception
&) {
109 g_warning( "Exception in getAccessibleCellAt()" );
115 /*****************************************************************************/
118 table_wrapper_get_index_at (AtkTable
*table
,
123 css::uno::Reference
<css::accessibility::XAccessibleTable
> pTable
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, "
140 catch(const uno::Exception
&) {
141 g_warning( "Exception in getAccessibleIndex()" );
147 /*****************************************************************************/
150 table_wrapper_get_column_at_index (AtkTable
*table
,
154 css::uno::Reference
<css::accessibility::XAccessibleTable
> pTable
157 return pTable
->getAccessibleColumn( nIndex
);
159 catch(const uno::Exception
&) {
160 g_warning( "Exception in getAccessibleColumn()" );
166 /*****************************************************************************/
169 table_wrapper_get_row_at_index( AtkTable
*table
,
173 css::uno::Reference
<css::accessibility::XAccessibleTable
> pTable
176 return pTable
->getAccessibleRow( nIndex
);
178 catch(const uno::Exception
&) {
179 g_warning( "Exception in getAccessibleRow()" );
185 /*****************************************************************************/
188 table_wrapper_get_n_columns( AtkTable
*table
)
191 css::uno::Reference
<css::accessibility::XAccessibleTable
> pTable
194 return pTable
->getAccessibleColumnCount();
196 catch(const uno::Exception
&) {
197 g_warning( "Exception in getAccessibleColumnCount()" );
203 /*****************************************************************************/
206 table_wrapper_get_n_rows( AtkTable
*table
)
209 css::uno::Reference
<css::accessibility::XAccessibleTable
> pTable
212 return pTable
->getAccessibleRowCount();
214 catch(const uno::Exception
&) {
215 g_warning( "Exception in getAccessibleRowCount()" );
221 /*****************************************************************************/
224 table_wrapper_get_column_extent_at( AtkTable
*table
,
229 css::uno::Reference
<css::accessibility::XAccessibleTable
> pTable
232 return pTable
->getAccessibleColumnExtentAt( row
, column
);
234 catch(const uno::Exception
&) {
235 g_warning( "Exception in getAccessibleColumnExtentAt()" );
241 /*****************************************************************************/
244 table_wrapper_get_row_extent_at( AtkTable
*table
,
249 css::uno::Reference
<css::accessibility::XAccessibleTable
> pTable
252 return pTable
->getAccessibleRowExtentAt( row
, column
);
254 catch(const uno::Exception
&) {
255 g_warning( "Exception in getAccessibleRowExtentAt()" );
261 /*****************************************************************************/
264 table_wrapper_get_caption( AtkTable
*table
)
267 css::uno::Reference
<css::accessibility::XAccessibleTable
> pTable
270 return atk_object_wrapper_conditional_ref( pTable
->getAccessibleCaption() );
273 catch(const uno::Exception
&) {
274 g_warning( "Exception in getAccessibleCaption()" );
280 /*****************************************************************************/
283 table_wrapper_get_row_description( AtkTable
*table
,
287 css::uno::Reference
<css::accessibility::XAccessibleTable
> pTable
290 return getAsConst( pTable
->getAccessibleRowDescription( row
) );
292 catch(const uno::Exception
&) {
293 g_warning( "Exception in getAccessibleRowDescription()" );
299 /*****************************************************************************/
302 table_wrapper_get_column_description( AtkTable
*table
,
306 css::uno::Reference
<css::accessibility::XAccessibleTable
> pTable
309 return getAsConst( pTable
->getAccessibleColumnDescription( column
) );
311 catch(const uno::Exception
&) {
312 g_warning( "Exception in getAccessibleColumnDescription()" );
318 /*****************************************************************************/
321 table_wrapper_get_row_header( AtkTable
*table
,
325 css::uno::Reference
<css::accessibility::XAccessibleTable
> pTable
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()" );
341 /*****************************************************************************/
344 table_wrapper_get_column_header( AtkTable
*table
,
348 css::uno::Reference
<css::accessibility::XAccessibleTable
> pTable
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()" );
364 /*****************************************************************************/
367 table_wrapper_get_summary( AtkTable
*table
)
370 css::uno::Reference
<css::accessibility::XAccessibleTable
> pTable
374 return atk_object_wrapper_conditional_ref( pTable
->getAccessibleSummary() );
377 catch(const uno::Exception
&) {
378 g_warning( "Exception in getAccessibleSummary()" );
384 /*****************************************************************************/
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 /*****************************************************************************/
402 table_wrapper_get_selected_columns( AtkTable
*table
,
405 *pSelected
= nullptr;
407 css::uno::Reference
<css::accessibility::XAccessibleTable
> pTable
410 return convertToGIntArray( pTable
->getSelectedAccessibleColumns(), pSelected
);
412 catch(const uno::Exception
&) {
413 g_warning( "Exception in getSelectedAccessibleColumns()" );
419 /*****************************************************************************/
422 table_wrapper_get_selected_rows( AtkTable
*table
,
425 *pSelected
= nullptr;
427 css::uno::Reference
<css::accessibility::XAccessibleTable
> pTable
430 return convertToGIntArray( pTable
->getSelectedAccessibleRows(), pSelected
);
432 catch(const uno::Exception
&) {
433 g_warning( "Exception in getSelectedAccessibleRows()" );
439 /*****************************************************************************/
442 table_wrapper_is_column_selected( AtkTable
*table
,
446 css::uno::Reference
<css::accessibility::XAccessibleTable
> pTable
449 return pTable
->isAccessibleColumnSelected( column
);
451 catch(const uno::Exception
&) {
452 g_warning( "Exception in isAccessibleColumnSelected()" );
458 /*****************************************************************************/
461 table_wrapper_is_row_selected( AtkTable
*table
,
465 css::uno::Reference
<css::accessibility::XAccessibleTable
> pTable
468 return pTable
->isAccessibleRowSelected( row
);
470 catch(const uno::Exception
&) {
471 g_warning( "Exception in isAccessibleRowSelected()" );
477 /*****************************************************************************/
480 table_wrapper_is_selected( AtkTable
*table
,
485 css::uno::Reference
<css::accessibility::XAccessibleTable
> pTable
488 return pTable
->isAccessibleSelected( row
, column
);
490 catch(const uno::Exception
&) {
491 g_warning( "Exception in isAccessibleSelected()" );
497 /*****************************************************************************/
500 table_wrapper_add_row_selection(AtkTable
*pTable
, gint row
)
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()" );
514 /*****************************************************************************/
517 table_wrapper_remove_row_selection(AtkTable
*pTable
, gint row
)
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()" );
531 /*****************************************************************************/
534 table_wrapper_add_column_selection(AtkTable
*pTable
, gint column
)
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()" );
548 /*****************************************************************************/
551 table_wrapper_remove_column_selection(AtkTable
*pTable
, gint column
)
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()" );
565 /*****************************************************************************/
568 table_wrapper_set_caption( AtkTable
*, AtkObject
* )
569 { // meaningless helper
572 /*****************************************************************************/
575 table_wrapper_set_column_description( AtkTable
*, gint
, const gchar
* )
576 { // meaningless helper
579 /*****************************************************************************/
582 table_wrapper_set_column_header( AtkTable
*, gint
, AtkObject
* )
583 { // meaningless helper
586 /*****************************************************************************/
589 table_wrapper_set_row_description( AtkTable
*, gint
, const gchar
* )
590 { // meaningless helper
593 /*****************************************************************************/
596 table_wrapper_set_row_header( AtkTable
*, gint
, AtkObject
* )
597 { // meaningless helper
600 /*****************************************************************************/
603 table_wrapper_set_summary( AtkTable
*, AtkObject
* )
604 { // meaningless helper
607 /*****************************************************************************/
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: */