1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: atktable.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
34 #include "atkwrapper.hxx"
36 #include <com/sun/star/accessibility/XAccessibleTable.hpp>
42 using namespace ::com::sun::star
;
44 static inline AtkObject
*
45 atk_object_wrapper_conditional_ref( const uno::Reference
< accessibility::XAccessible
>& rxAccessible
)
48 fprintf( stderr
, ": %p\n", rxAccessible
.get() );
51 if( rxAccessible
.is() )
52 return atk_object_wrapper_ref( rxAccessible
);
57 /*****************************************************************************/
60 static G_CONST_RETURN gchar
*
61 getAsConst( rtl::OUString rString
)
63 static const int nMax
= 10;
64 static rtl::OString aUgly
[nMax
];
66 nIdx
= (nIdx
+ 1) % nMax
;
67 aUgly
[nIdx
] = rtl::OUStringToOString( rString
, RTL_TEXTENCODING_UTF8
);
71 /*****************************************************************************/
73 static accessibility::XAccessibleTable
*
74 getTable( AtkTable
*pTable
) throw (uno::RuntimeException
)
76 AtkObjectWrapper
*pWrap
= ATK_OBJECT_WRAPPER( pTable
);
79 if( !pWrap
->mpTable
&& pWrap
->mpContext
)
81 uno::Any any
= pWrap
->mpContext
->queryInterface( accessibility::XAccessibleTable::static_type(NULL
) );
82 pWrap
->mpTable
= reinterpret_cast< accessibility::XAccessibleTable
* > (any
.pReserved
);
83 pWrap
->mpTable
->acquire();
86 return pWrap
->mpTable
;
92 /*****************************************************************************/
97 table_wrapper_ref_at (AtkTable
*table
,
102 accessibility::XAccessibleTable
* pTable
= getTable( table
);
104 #ifdef ENABLE_TRACING
106 fprintf(stderr
, "getAccessibleCellAt( %u, %u ) returns", row
, column
);
109 fprintf(stderr
, "getAccessibleCellAt( %u, %u ) returns", row
, column
);
114 return atk_object_wrapper_conditional_ref( pTable
->getAccessibleCellAt( row
, column
) );
117 catch(const uno::Exception
& e
) {
118 g_warning( "Exception in getAccessibleCellAt()" );
124 /*****************************************************************************/
127 table_wrapper_get_index_at (AtkTable
*table
,
132 accessibility::XAccessibleTable
* pTable
= getTable( table
);
134 #ifdef ENABLE_TRACING
136 fprintf(stderr
, "getAccessibleIndex( %u, %u ) returns %u\n",
137 row
, column
, pTable
->getAccessibleIndex( row
, column
) );
141 return pTable
->getAccessibleIndex( row
, column
);
143 catch(const uno::Exception
& e
) {
144 g_warning( "Exception in getAccessibleIndex()" );
150 /*****************************************************************************/
153 table_wrapper_get_column_at_index (AtkTable
*table
,
157 accessibility::XAccessibleTable
* pTable
= getTable( table
);
159 #ifdef ENABLE_TRACING
161 fprintf(stderr
, "getAccessibleColumn( %u ) returns %u\n",
162 nIndex
, pTable
->getAccessibleColumn( nIndex
) );
166 return pTable
->getAccessibleColumn( nIndex
);
168 catch(const uno::Exception
& e
) {
169 g_warning( "Exception in getAccessibleColumn()" );
175 /*****************************************************************************/
178 table_wrapper_get_row_at_index( AtkTable
*table
,
182 accessibility::XAccessibleTable
* pTable
= getTable( table
);
184 #ifdef ENABLE_TRACING
186 fprintf(stderr
, "getAccessibleRow( %u ) returns %u\n",
187 nIndex
, pTable
->getAccessibleRow( nIndex
) );
191 return pTable
->getAccessibleRow( nIndex
);
193 catch(const uno::Exception
& e
) {
194 g_warning( "Exception in getAccessibleRow()" );
200 /*****************************************************************************/
203 table_wrapper_get_n_columns( AtkTable
*table
)
206 accessibility::XAccessibleTable
* pTable
= getTable( table
);
208 #ifdef ENABLE_TRACING
210 fprintf(stderr
, "XAccessibleTable::getAccessibleColumnCount returns %u\n",
211 pTable
->getAccessibleColumnCount() );
215 return pTable
->getAccessibleColumnCount();
217 catch(const uno::Exception
& e
) {
218 g_warning( "Exception in getAccessibleColumnCount()" );
224 /*****************************************************************************/
227 table_wrapper_get_n_rows( AtkTable
*table
)
230 accessibility::XAccessibleTable
* pTable
= getTable( table
);
232 #ifdef ENABLE_TRACING
234 fprintf(stderr
, "getAccessibleRowCount() returns %u\n",
235 pTable
->getAccessibleRowCount() );
239 return pTable
->getAccessibleRowCount();
241 catch(const uno::Exception
& e
) {
242 g_warning( "Exception in getAccessibleRowCount()" );
248 /*****************************************************************************/
251 table_wrapper_get_column_extent_at( AtkTable
*table
,
256 accessibility::XAccessibleTable
* pTable
= getTable( table
);
258 #ifdef ENABLE_TRACING
260 fprintf(stderr
, "getAccessibleColumnExtentAt( %u, %u ) returns %u\n",
261 row
, column
, pTable
->getAccessibleColumnExtentAt( row
, column
) );
265 return pTable
->getAccessibleColumnExtentAt( row
, column
);
267 catch(const uno::Exception
& e
) {
268 g_warning( "Exception in getAccessibleColumnExtentAt()" );
274 /*****************************************************************************/
277 table_wrapper_get_row_extent_at( AtkTable
*table
,
282 accessibility::XAccessibleTable
* pTable
= getTable( table
);
284 #ifdef ENABLE_TRACING
286 fprintf(stderr
, "getAccessibleRowExtentAt( %u, %u ) returns %u\n",
287 row
, column
, pTable
->getAccessibleRowExtentAt( row
, column
) );
291 return pTable
->getAccessibleRowExtentAt( row
, column
);
293 catch(const uno::Exception
& e
) {
294 g_warning( "Exception in getAccessibleRowExtentAt()" );
300 /*****************************************************************************/
303 table_wrapper_get_caption( AtkTable
*table
)
306 accessibility::XAccessibleTable
* pTable
= getTable( table
);
308 #ifdef ENABLE_TRACING
310 fprintf(stderr
, "getAccessibleCaption() returns" );
314 return atk_object_wrapper_conditional_ref( pTable
->getAccessibleCaption() );
317 catch(const uno::Exception
& e
) {
318 g_warning( "Exception in getAccessibleCaption()" );
324 /*****************************************************************************/
326 static G_CONST_RETURN gchar
*
327 table_wrapper_get_row_description( AtkTable
*table
,
331 accessibility::XAccessibleTable
* pTable
= getTable( table
);
333 #ifdef ENABLE_TRACING
335 fprintf(stderr
, "getAccessibleRowDescription( %u ) returns %s\n",
336 row
, getAsConst( pTable
->getAccessibleRowDescription( row
) ) );
340 return getAsConst( pTable
->getAccessibleRowDescription( row
) );
342 catch(const uno::Exception
& e
) {
343 g_warning( "Exception in getAccessibleRowDescription()" );
349 /*****************************************************************************/
351 static G_CONST_RETURN gchar
*
352 table_wrapper_get_column_description( AtkTable
*table
,
356 accessibility::XAccessibleTable
* pTable
= getTable( table
);
358 #ifdef ENABLE_TRACING
360 fprintf(stderr
, "getAccessibleColumnDescription( %u ) returns %s\n",
361 column
, getAsConst( pTable
->getAccessibleColumnDescription( column
) ) );
365 return getAsConst( pTable
->getAccessibleColumnDescription( column
) );
367 catch(const uno::Exception
& e
) {
368 g_warning( "Exception in getAccessibleColumnDescription()" );
374 /*****************************************************************************/
377 table_wrapper_get_row_header( AtkTable
*table
,
381 accessibility::XAccessibleTable
* pTable
= getTable( table
);
384 uno::Reference
< accessibility::XAccessibleTable
> xRowHeaders( pTable
->getAccessibleRowHeaders() );
386 #ifdef ENABLE_TRACING
387 if( xRowHeaders
.is() )
388 fprintf(stderr
, "getAccessibleRowHeader( %u )->getAccessibleCellAt( 0, %u ) returns",
391 fprintf(stderr
, "getAccessibleRowHeader( %u ) returns %p\n", row
, xRowHeaders
.get() );
394 if( xRowHeaders
.is() )
395 return atk_object_wrapper_conditional_ref( xRowHeaders
->getAccessibleCellAt( row
, 0 ) );
398 catch(const uno::Exception
& e
) {
399 g_warning( "Exception in getAccessibleRowHeaders()" );
405 /*****************************************************************************/
408 table_wrapper_get_column_header( AtkTable
*table
,
412 accessibility::XAccessibleTable
* pTable
= getTable( table
);
416 uno::Reference
< accessibility::XAccessibleTable
> xColumnHeaders( pTable
->getAccessibleColumnHeaders() );
418 #ifdef ENABLE_TRACING
419 if( xColumnHeaders
.is() )
420 fprintf(stderr
, "getAccessibleColumnHeader( %u )->getAccessibleCellAt( 0, %u ) returns",
423 fprintf(stderr
, "getAccessibleColumnHeader( %u ) returns %p\n", column
, xColumnHeaders
.get() );
426 if( xColumnHeaders
.is() )
427 return atk_object_wrapper_conditional_ref( xColumnHeaders
->getAccessibleCellAt( 0, column
) );
430 catch(const uno::Exception
& e
) {
431 g_warning( "Exception in getAccessibleColumnHeaders()" );
437 /*****************************************************************************/
440 table_wrapper_get_summary( AtkTable
*table
)
443 accessibility::XAccessibleTable
* pTable
= getTable( table
);
445 #ifdef ENABLE_TRACING
447 fprintf(stderr
, "getAccessibleSummary() returns" );
453 // AtkObject* summary;
454 return atk_object_wrapper_conditional_ref( pTable
->getAccessibleSummary() );
457 catch(const uno::Exception
& e
) {
458 g_warning( "Exception in getAccessibleSummary()" );
464 /*****************************************************************************/
467 convertToGIntArray( const uno::Sequence
< ::sal_Int32
>& aSequence
, gint
**pSelected
)
469 if( aSequence
.getLength() )
471 *pSelected
= g_new( gint
, aSequence
.getLength() );
473 for( sal_Int32 i
= 0; i
< aSequence
.getLength(); i
++ )
474 (*pSelected
) [i
] = aSequence
[i
];
477 return aSequence
.getLength();
480 /*****************************************************************************/
483 table_wrapper_get_selected_columns( AtkTable
*table
,
488 accessibility::XAccessibleTable
* pTable
= getTable( table
);
490 #ifdef ENABLE_TRACING
492 fprintf(stderr
, "getSelectedAccessibleColumns() \n" );
496 return convertToGIntArray( pTable
->getSelectedAccessibleColumns(), pSelected
);
498 catch(const uno::Exception
& e
) {
499 g_warning( "Exception in getSelectedAccessibleColumns()" );
505 /*****************************************************************************/
508 table_wrapper_get_selected_rows( AtkTable
*table
,
513 accessibility::XAccessibleTable
* pTable
= getTable( table
);
515 #ifdef ENABLE_TRACING
517 fprintf(stderr
, "getSelectedAccessibleRows() \n" );
521 return convertToGIntArray( pTable
->getSelectedAccessibleRows(), pSelected
);
523 catch(const uno::Exception
& e
) {
524 g_warning( "Exception in getSelectedAccessibleRows()" );
530 /*****************************************************************************/
533 table_wrapper_is_column_selected( AtkTable
*table
,
537 accessibility::XAccessibleTable
* pTable
= getTable( table
);
539 #ifdef ENABLE_TRACING
541 fprintf(stderr
, "isAccessibleColumnSelected( %u ) returns %s\n",
542 column
, pTable
->isAccessibleColumnSelected( column
) ? "true" : "false" );
546 return pTable
->isAccessibleColumnSelected( column
);
548 catch(const uno::Exception
& e
) {
549 g_warning( "Exception in isAccessibleColumnSelected()" );
555 /*****************************************************************************/
558 table_wrapper_is_row_selected( AtkTable
*table
,
562 accessibility::XAccessibleTable
* pTable
= getTable( table
);
564 #ifdef ENABLE_TRACING
566 fprintf(stderr
, "isAccessibleRowSelected( %u ) returns %s\n",
567 row
, pTable
->isAccessibleRowSelected( row
) ? "true" : "false" );
571 return pTable
->isAccessibleRowSelected( row
);
573 catch(const uno::Exception
& e
) {
574 g_warning( "Exception in isAccessibleRowSelected()" );
580 /*****************************************************************************/
583 table_wrapper_is_selected( AtkTable
*table
,
588 accessibility::XAccessibleTable
* pTable
= getTable( table
);
590 #ifdef ENABLE_TRACING
592 fprintf(stderr
, "isAccessibleSelected( %u, %u ) returns %s\n",
593 row
, column
, pTable
->isAccessibleSelected( row
, column
) ? "true" : "false" );
597 return pTable
->isAccessibleSelected( row
, column
);
599 catch(const uno::Exception
& e
) {
600 g_warning( "Exception in isAccessibleSelected()" );
606 /*****************************************************************************/
609 table_wrapper_add_row_selection( AtkTable
*, gint
)
611 g_warning( "FIXME: no simple analogue for add_row_selection" );
615 /*****************************************************************************/
618 table_wrapper_remove_row_selection( AtkTable
*, gint
)
620 g_warning( "FIXME: no simple analogue for remove_row_selection" );
624 /*****************************************************************************/
627 table_wrapper_add_column_selection( AtkTable
*, gint
)
629 g_warning( "FIXME: no simple analogue for add_column_selection" );
633 /*****************************************************************************/
636 table_wrapper_remove_column_selection( AtkTable
*, gint
)
638 g_warning( "FIXME: no simple analogue for remove_column_selection" );
642 /*****************************************************************************/
645 table_wrapper_set_caption( AtkTable
*, AtkObject
* )
646 { // meaningless helper
649 /*****************************************************************************/
652 table_wrapper_set_column_description( AtkTable
*, gint
, const gchar
* )
653 { // meaningless helper
657 /*****************************************************************************/
660 table_wrapper_set_column_header( AtkTable
*, gint
, AtkObject
* )
661 { // meaningless helper
665 /*****************************************************************************/
668 table_wrapper_set_row_description( AtkTable
*, gint
, const gchar
* )
669 { // meaningless helper
672 /*****************************************************************************/
675 table_wrapper_set_row_header( AtkTable
*, gint
, AtkObject
* )
676 { // meaningless helper
679 /*****************************************************************************/
682 table_wrapper_set_summary( AtkTable
*, AtkObject
* )
683 { // meaningless helper
686 /*****************************************************************************/
691 tableIfaceInit (AtkTableIface
*iface
)
693 g_return_if_fail (iface
!= NULL
);
695 iface
->ref_at
= table_wrapper_ref_at
;
696 iface
->get_n_rows
= table_wrapper_get_n_rows
;
697 iface
->get_n_columns
= table_wrapper_get_n_columns
;
698 iface
->get_index_at
= table_wrapper_get_index_at
;
699 iface
->get_column_at_index
= table_wrapper_get_column_at_index
;
700 iface
->get_row_at_index
= table_wrapper_get_row_at_index
;
701 iface
->is_row_selected
= table_wrapper_is_row_selected
;
702 iface
->is_selected
= table_wrapper_is_selected
;
703 iface
->get_selected_rows
= table_wrapper_get_selected_rows
;
704 iface
->add_row_selection
= table_wrapper_add_row_selection
;
705 iface
->remove_row_selection
= table_wrapper_remove_row_selection
;
706 iface
->add_column_selection
= table_wrapper_add_column_selection
;
707 iface
->remove_column_selection
= table_wrapper_remove_column_selection
;
708 iface
->get_selected_columns
= table_wrapper_get_selected_columns
;
709 iface
->is_column_selected
= table_wrapper_is_column_selected
;
710 iface
->get_column_extent_at
= table_wrapper_get_column_extent_at
;
711 iface
->get_row_extent_at
= table_wrapper_get_row_extent_at
;
712 iface
->get_row_header
= table_wrapper_get_row_header
;
713 iface
->set_row_header
= table_wrapper_set_row_header
;
714 iface
->get_column_header
= table_wrapper_get_column_header
;
715 iface
->set_column_header
= table_wrapper_set_column_header
;
716 iface
->get_caption
= table_wrapper_get_caption
;
717 iface
->set_caption
= table_wrapper_set_caption
;
718 iface
->get_summary
= table_wrapper_get_summary
;
719 iface
->set_summary
= table_wrapper_set_summary
;
720 iface
->get_row_description
= table_wrapper_get_row_description
;
721 iface
->set_row_description
= table_wrapper_set_row_description
;
722 iface
->get_column_description
= table_wrapper_get_column_description
;
723 iface
->set_column_description
= table_wrapper_set_column_description
;