merge the formfield patch from ooo-build
[ooovba.git] / vcl / unx / gtk / a11y / atktable.cxx
blob8089c15ca372935d56a42d960eb21f4a7ceb817c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: atktable.cxx,v $
10 * $Revision: 1.4 $
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>
38 #ifdef ENABLE_TRACING
39 #include <stdio.h>
40 #endif
42 using namespace ::com::sun::star;
44 static inline AtkObject *
45 atk_object_wrapper_conditional_ref( const uno::Reference< accessibility::XAccessible >& rxAccessible )
47 #ifdef ENABLE_TRACING
48 fprintf( stderr, ": %p\n", rxAccessible.get() );
49 #endif
51 if( rxAccessible.is() )
52 return atk_object_wrapper_ref( rxAccessible );
54 return NULL;
57 /*****************************************************************************/
59 // FIXME
60 static G_CONST_RETURN gchar *
61 getAsConst( rtl::OUString rString )
63 static const int nMax = 10;
64 static rtl::OString aUgly[nMax];
65 static int nIdx = 0;
66 nIdx = (nIdx + 1) % nMax;
67 aUgly[nIdx] = rtl::OUStringToOString( rString, RTL_TEXTENCODING_UTF8 );
68 return aUgly[ nIdx ];
71 /*****************************************************************************/
73 static accessibility::XAccessibleTable*
74 getTable( AtkTable *pTable ) throw (uno::RuntimeException)
76 AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER( pTable );
77 if( pWrap )
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;
89 return NULL;
92 /*****************************************************************************/
94 extern "C" {
96 static AtkObject*
97 table_wrapper_ref_at (AtkTable *table,
98 gint row,
99 gint column)
101 try {
102 accessibility::XAccessibleTable* pTable = getTable( table );
104 #ifdef ENABLE_TRACING
105 if( pTable )
106 fprintf(stderr, "getAccessibleCellAt( %u, %u ) returns", row, column );
108 if( column >= 255 )
109 fprintf(stderr, "getAccessibleCellAt( %u, %u ) returns", row, column );
111 #endif
113 if( pTable )
114 return atk_object_wrapper_conditional_ref( pTable->getAccessibleCellAt( row, column ) );
117 catch(const uno::Exception& e) {
118 g_warning( "Exception in getAccessibleCellAt()" );
121 return NULL;
124 /*****************************************************************************/
126 static gint
127 table_wrapper_get_index_at (AtkTable *table,
128 gint row,
129 gint column)
131 try {
132 accessibility::XAccessibleTable* pTable = getTable( table );
134 #ifdef ENABLE_TRACING
135 if( pTable )
136 fprintf(stderr, "getAccessibleIndex( %u, %u ) returns %u\n",
137 row, column, pTable->getAccessibleIndex( row, column ) );
138 #endif
140 if( pTable )
141 return pTable->getAccessibleIndex( row, column );
143 catch(const uno::Exception& e) {
144 g_warning( "Exception in getAccessibleIndex()" );
147 return -1;
150 /*****************************************************************************/
152 static gint
153 table_wrapper_get_column_at_index (AtkTable *table,
154 gint nIndex)
156 try {
157 accessibility::XAccessibleTable* pTable = getTable( table );
159 #ifdef ENABLE_TRACING
160 if( pTable )
161 fprintf(stderr, "getAccessibleColumn( %u ) returns %u\n",
162 nIndex, pTable->getAccessibleColumn( nIndex ) );
163 #endif
165 if( pTable )
166 return pTable->getAccessibleColumn( nIndex );
168 catch(const uno::Exception& e) {
169 g_warning( "Exception in getAccessibleColumn()" );
172 return -1;
175 /*****************************************************************************/
177 static gint
178 table_wrapper_get_row_at_index( AtkTable *table,
179 gint nIndex )
181 try {
182 accessibility::XAccessibleTable* pTable = getTable( table );
184 #ifdef ENABLE_TRACING
185 if( pTable )
186 fprintf(stderr, "getAccessibleRow( %u ) returns %u\n",
187 nIndex, pTable->getAccessibleRow( nIndex ) );
188 #endif
190 if( pTable )
191 return pTable->getAccessibleRow( nIndex );
193 catch(const uno::Exception& e) {
194 g_warning( "Exception in getAccessibleRow()" );
197 return -1;
200 /*****************************************************************************/
202 static gint
203 table_wrapper_get_n_columns( AtkTable *table )
205 try {
206 accessibility::XAccessibleTable* pTable = getTable( table );
208 #ifdef ENABLE_TRACING
209 if( pTable )
210 fprintf(stderr, "XAccessibleTable::getAccessibleColumnCount returns %u\n",
211 pTable->getAccessibleColumnCount() );
212 #endif
214 if( pTable )
215 return pTable->getAccessibleColumnCount();
217 catch(const uno::Exception& e) {
218 g_warning( "Exception in getAccessibleColumnCount()" );
221 return -1;
224 /*****************************************************************************/
226 static gint
227 table_wrapper_get_n_rows( AtkTable *table )
229 try {
230 accessibility::XAccessibleTable* pTable = getTable( table );
232 #ifdef ENABLE_TRACING
233 if( pTable )
234 fprintf(stderr, "getAccessibleRowCount() returns %u\n",
235 pTable->getAccessibleRowCount() );
236 #endif
238 if( pTable )
239 return pTable->getAccessibleRowCount();
241 catch(const uno::Exception& e) {
242 g_warning( "Exception in getAccessibleRowCount()" );
245 return -1;
248 /*****************************************************************************/
250 static gint
251 table_wrapper_get_column_extent_at( AtkTable *table,
252 gint row,
253 gint column )
255 try {
256 accessibility::XAccessibleTable* pTable = getTable( table );
258 #ifdef ENABLE_TRACING
259 if( pTable )
260 fprintf(stderr, "getAccessibleColumnExtentAt( %u, %u ) returns %u\n",
261 row, column, pTable->getAccessibleColumnExtentAt( row, column ) );
262 #endif
264 if( pTable )
265 return pTable->getAccessibleColumnExtentAt( row, column );
267 catch(const uno::Exception& e) {
268 g_warning( "Exception in getAccessibleColumnExtentAt()" );
271 return -1;
274 /*****************************************************************************/
276 static gint
277 table_wrapper_get_row_extent_at( AtkTable *table,
278 gint row,
279 gint column )
281 try {
282 accessibility::XAccessibleTable* pTable = getTable( table );
284 #ifdef ENABLE_TRACING
285 if( pTable )
286 fprintf(stderr, "getAccessibleRowExtentAt( %u, %u ) returns %u\n",
287 row, column, pTable->getAccessibleRowExtentAt( row, column ) );
288 #endif
290 if( pTable )
291 return pTable->getAccessibleRowExtentAt( row, column );
293 catch(const uno::Exception& e) {
294 g_warning( "Exception in getAccessibleRowExtentAt()" );
297 return -1;
300 /*****************************************************************************/
302 static AtkObject *
303 table_wrapper_get_caption( AtkTable *table )
305 try {
306 accessibility::XAccessibleTable* pTable = getTable( table );
308 #ifdef ENABLE_TRACING
309 if( pTable )
310 fprintf(stderr, "getAccessibleCaption() returns" );
311 #endif
313 if( pTable )
314 return atk_object_wrapper_conditional_ref( pTable->getAccessibleCaption() );
317 catch(const uno::Exception& e) {
318 g_warning( "Exception in getAccessibleCaption()" );
321 return NULL;
324 /*****************************************************************************/
326 static G_CONST_RETURN gchar *
327 table_wrapper_get_row_description( AtkTable *table,
328 gint row )
330 try {
331 accessibility::XAccessibleTable* pTable = getTable( table );
333 #ifdef ENABLE_TRACING
334 if( pTable )
335 fprintf(stderr, "getAccessibleRowDescription( %u ) returns %s\n",
336 row, getAsConst( pTable->getAccessibleRowDescription( row ) ) );
337 #endif
339 if( pTable )
340 return getAsConst( pTable->getAccessibleRowDescription( row ) );
342 catch(const uno::Exception& e) {
343 g_warning( "Exception in getAccessibleRowDescription()" );
346 return NULL;
349 /*****************************************************************************/
351 static G_CONST_RETURN gchar *
352 table_wrapper_get_column_description( AtkTable *table,
353 gint column )
355 try {
356 accessibility::XAccessibleTable* pTable = getTable( table );
358 #ifdef ENABLE_TRACING
359 if( pTable )
360 fprintf(stderr, "getAccessibleColumnDescription( %u ) returns %s\n",
361 column, getAsConst( pTable->getAccessibleColumnDescription( column ) ) );
362 #endif
364 if( pTable )
365 return getAsConst( pTable->getAccessibleColumnDescription( column ) );
367 catch(const uno::Exception& e) {
368 g_warning( "Exception in getAccessibleColumnDescription()" );
371 return NULL;
374 /*****************************************************************************/
376 static AtkObject *
377 table_wrapper_get_row_header( AtkTable *table,
378 gint row )
380 try {
381 accessibility::XAccessibleTable* pTable = getTable( table );
382 if( pTable )
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",
389 row, row );
390 else
391 fprintf(stderr, "getAccessibleRowHeader( %u ) returns %p\n", row, xRowHeaders.get() );
392 #endif
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()" );
402 return NULL;
405 /*****************************************************************************/
407 static AtkObject *
408 table_wrapper_get_column_header( AtkTable *table,
409 gint column )
411 try {
412 accessibility::XAccessibleTable* pTable = getTable( table );
414 if( pTable )
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",
421 column, column );
422 else
423 fprintf(stderr, "getAccessibleColumnHeader( %u ) returns %p\n", column, xColumnHeaders.get() );
424 #endif
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()" );
434 return NULL;
437 /*****************************************************************************/
439 static AtkObject *
440 table_wrapper_get_summary( AtkTable *table )
442 try {
443 accessibility::XAccessibleTable* pTable = getTable( table );
445 #ifdef ENABLE_TRACING
446 if( pTable )
447 fprintf(stderr, "getAccessibleSummary() returns" );
448 #endif
450 if( pTable )
452 // FIXME: Summary ??
453 // AtkObject* summary;
454 return atk_object_wrapper_conditional_ref( pTable->getAccessibleSummary() );
457 catch(const uno::Exception& e) {
458 g_warning( "Exception in getAccessibleSummary()" );
461 return NULL;
464 /*****************************************************************************/
466 static gint
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 /*****************************************************************************/
482 static gint
483 table_wrapper_get_selected_columns( AtkTable *table,
484 gint **pSelected )
486 *pSelected = NULL;
487 try {
488 accessibility::XAccessibleTable* pTable = getTable( table );
490 #ifdef ENABLE_TRACING
491 if( pTable )
492 fprintf(stderr, "getSelectedAccessibleColumns() \n" );
493 #endif
495 if( pTable )
496 return convertToGIntArray( pTable->getSelectedAccessibleColumns(), pSelected );
498 catch(const uno::Exception& e) {
499 g_warning( "Exception in getSelectedAccessibleColumns()" );
502 return 0;
505 /*****************************************************************************/
507 static gint
508 table_wrapper_get_selected_rows( AtkTable *table,
509 gint **pSelected )
511 *pSelected = NULL;
512 try {
513 accessibility::XAccessibleTable* pTable = getTable( table );
515 #ifdef ENABLE_TRACING
516 if( pTable )
517 fprintf(stderr, "getSelectedAccessibleRows() \n" );
518 #endif
520 if( pTable )
521 return convertToGIntArray( pTable->getSelectedAccessibleRows(), pSelected );
523 catch(const uno::Exception& e) {
524 g_warning( "Exception in getSelectedAccessibleRows()" );
527 return 0;
530 /*****************************************************************************/
532 static gboolean
533 table_wrapper_is_column_selected( AtkTable *table,
534 gint column )
536 try {
537 accessibility::XAccessibleTable* pTable = getTable( table );
539 #ifdef ENABLE_TRACING
540 if( pTable )
541 fprintf(stderr, "isAccessibleColumnSelected( %u ) returns %s\n",
542 column, pTable->isAccessibleColumnSelected( column ) ? "true" : "false" );
543 #endif
545 if( pTable )
546 return pTable->isAccessibleColumnSelected( column );
548 catch(const uno::Exception& e) {
549 g_warning( "Exception in isAccessibleColumnSelected()" );
552 return 0;
555 /*****************************************************************************/
557 static gboolean
558 table_wrapper_is_row_selected( AtkTable *table,
559 gint row )
561 try {
562 accessibility::XAccessibleTable* pTable = getTable( table );
564 #ifdef ENABLE_TRACING
565 if( pTable )
566 fprintf(stderr, "isAccessibleRowSelected( %u ) returns %s\n",
567 row, pTable->isAccessibleRowSelected( row ) ? "true" : "false" );
568 #endif
570 if( pTable )
571 return pTable->isAccessibleRowSelected( row );
573 catch(const uno::Exception& e) {
574 g_warning( "Exception in isAccessibleRowSelected()" );
577 return FALSE;
580 /*****************************************************************************/
582 static gboolean
583 table_wrapper_is_selected( AtkTable *table,
584 gint row,
585 gint column )
587 try {
588 accessibility::XAccessibleTable* pTable = getTable( table );
590 #ifdef ENABLE_TRACING
591 if( pTable )
592 fprintf(stderr, "isAccessibleSelected( %u, %u ) returns %s\n",
593 row, column, pTable->isAccessibleSelected( row , column ) ? "true" : "false" );
594 #endif
596 if( pTable )
597 return pTable->isAccessibleSelected( row, column );
599 catch(const uno::Exception& e) {
600 g_warning( "Exception in isAccessibleSelected()" );
603 return FALSE;
606 /*****************************************************************************/
608 static gboolean
609 table_wrapper_add_row_selection( AtkTable *, gint )
611 g_warning( "FIXME: no simple analogue for add_row_selection" );
612 return 0;
615 /*****************************************************************************/
617 static gboolean
618 table_wrapper_remove_row_selection( AtkTable *, gint )
620 g_warning( "FIXME: no simple analogue for remove_row_selection" );
621 return 0;
624 /*****************************************************************************/
626 static gboolean
627 table_wrapper_add_column_selection( AtkTable *, gint )
629 g_warning( "FIXME: no simple analogue for add_column_selection" );
630 return 0;
633 /*****************************************************************************/
635 static gboolean
636 table_wrapper_remove_column_selection( AtkTable *, gint )
638 g_warning( "FIXME: no simple analogue for remove_column_selection" );
639 return 0;
642 /*****************************************************************************/
644 static void
645 table_wrapper_set_caption( AtkTable *, AtkObject * )
646 { // meaningless helper
649 /*****************************************************************************/
651 static void
652 table_wrapper_set_column_description( AtkTable *, gint, const gchar * )
653 { // meaningless helper
657 /*****************************************************************************/
659 static void
660 table_wrapper_set_column_header( AtkTable *, gint, AtkObject * )
661 { // meaningless helper
665 /*****************************************************************************/
667 static void
668 table_wrapper_set_row_description( AtkTable *, gint, const gchar * )
669 { // meaningless helper
672 /*****************************************************************************/
674 static void
675 table_wrapper_set_row_header( AtkTable *, gint, AtkObject * )
676 { // meaningless helper
679 /*****************************************************************************/
681 static void
682 table_wrapper_set_summary( AtkTable *, AtkObject * )
683 { // meaningless helper
686 /*****************************************************************************/
688 } // extern "C"
690 void
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;