xref: /AOO41X/main/vcl/unx/gtk/a11y/atktable.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_vcl.hxx"
30 
31 #include "atkwrapper.hxx"
32 
33 #include <com/sun/star/accessibility/XAccessibleTable.hpp>
34 
35 #ifdef ENABLE_TRACING
36 #include <stdio.h>
37 #endif
38 
39 using namespace ::com::sun::star;
40 
41 static inline AtkObject *
42 atk_object_wrapper_conditional_ref( const uno::Reference< accessibility::XAccessible >& rxAccessible )
43 {
44 #ifdef ENABLE_TRACING
45     fprintf( stderr, ": %p\n", rxAccessible.get() );
46 #endif
47 
48     if( rxAccessible.is() )
49         return atk_object_wrapper_ref( rxAccessible );
50 
51     return NULL;
52 }
53 
54 /*****************************************************************************/
55 
56 // FIXME
57 static G_CONST_RETURN gchar *
58 getAsConst( rtl::OUString rString )
59 {
60     static const int nMax = 10;
61     static rtl::OString aUgly[nMax];
62     static int nIdx = 0;
63     nIdx = (nIdx + 1) % nMax;
64     aUgly[nIdx] = rtl::OUStringToOString( rString, RTL_TEXTENCODING_UTF8 );
65     return aUgly[ nIdx ];
66 }
67 
68 /*****************************************************************************/
69 
70 static accessibility::XAccessibleTable*
71     getTable( AtkTable *pTable ) throw (uno::RuntimeException)
72 {
73     AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER( pTable );
74     if( pWrap )
75     {
76         if( !pWrap->mpTable && pWrap->mpContext )
77         {
78             uno::Any any = pWrap->mpContext->queryInterface( accessibility::XAccessibleTable::static_type(NULL) );
79             pWrap->mpTable = reinterpret_cast< accessibility::XAccessibleTable * > (any.pReserved);
80             pWrap->mpTable->acquire();
81         }
82 
83         return pWrap->mpTable;
84     }
85 
86     return NULL;
87 }
88 
89 /*****************************************************************************/
90 
91 extern "C" {
92 
93 static AtkObject*
94 table_wrapper_ref_at (AtkTable *table,
95                       gint      row,
96                       gint      column)
97 {
98     try {
99         accessibility::XAccessibleTable* pTable = getTable( table );
100 
101 #ifdef ENABLE_TRACING
102         if( pTable )
103             fprintf(stderr, "getAccessibleCellAt( %u, %u ) returns", row, column );
104 
105         if( column >= 255 )
106             fprintf(stderr, "getAccessibleCellAt( %u, %u ) returns", row, column );
107 
108 #endif
109 
110         if( pTable )
111             return atk_object_wrapper_conditional_ref( pTable->getAccessibleCellAt( row, column ) );
112     }
113 
114     catch(const uno::Exception& e) {
115         g_warning( "Exception in getAccessibleCellAt()" );
116     }
117 
118     return NULL;
119 }
120 
121 /*****************************************************************************/
122 
123 static gint
124 table_wrapper_get_index_at (AtkTable      *table,
125                             gint          row,
126                             gint          column)
127 {
128     try {
129         accessibility::XAccessibleTable* pTable = getTable( table );
130 
131 #ifdef ENABLE_TRACING
132         if( pTable )
133             fprintf(stderr, "getAccessibleIndex( %u, %u ) returns %u\n",
134                 row, column, pTable->getAccessibleIndex( row, column ) );
135 #endif
136 
137         if( pTable )
138             return pTable->getAccessibleIndex( row, column );
139     }
140     catch(const uno::Exception& e) {
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         accessibility::XAccessibleTable* pTable = getTable( table );
155 
156 #ifdef ENABLE_TRACING
157         if( pTable )
158             fprintf(stderr, "getAccessibleColumn( %u ) returns %u\n",
159                 nIndex, pTable->getAccessibleColumn( nIndex ) );
160 #endif
161 
162         if( pTable )
163             return pTable->getAccessibleColumn( nIndex );
164     }
165     catch(const uno::Exception& e) {
166         g_warning( "Exception in getAccessibleColumn()" );
167     }
168 
169     return -1;
170 }
171 
172 /*****************************************************************************/
173 
174 static gint
175 table_wrapper_get_row_at_index( AtkTable *table,
176                                 gint      nIndex )
177 {
178     try {
179         accessibility::XAccessibleTable* pTable = getTable( table );
180 
181 #ifdef ENABLE_TRACING
182         if( pTable )
183             fprintf(stderr, "getAccessibleRow( %u ) returns %u\n",
184                 nIndex, pTable->getAccessibleRow( nIndex ) );
185 #endif
186 
187         if( pTable )
188             return pTable->getAccessibleRow( nIndex );
189     }
190     catch(const uno::Exception& e) {
191         g_warning( "Exception in getAccessibleRow()" );
192     }
193 
194     return -1;
195 }
196 
197 /*****************************************************************************/
198 
199 static gint
200 table_wrapper_get_n_columns( AtkTable *table )
201 {
202     try {
203         accessibility::XAccessibleTable* pTable = getTable( table );
204 
205 #ifdef ENABLE_TRACING
206         if( pTable )
207             fprintf(stderr, "XAccessibleTable::getAccessibleColumnCount returns %u\n",
208                 pTable->getAccessibleColumnCount() );
209 #endif
210 
211         if( pTable )
212             return pTable->getAccessibleColumnCount();
213     }
214     catch(const uno::Exception& e) {
215         g_warning( "Exception in getAccessibleColumnCount()" );
216     }
217 
218     return -1;
219 }
220 
221 /*****************************************************************************/
222 
223 static gint
224 table_wrapper_get_n_rows( AtkTable *table )
225 {
226     try {
227         accessibility::XAccessibleTable* pTable = getTable( table );
228 
229 #ifdef ENABLE_TRACING
230         if( pTable )
231             fprintf(stderr, "getAccessibleRowCount() returns %u\n",
232                 pTable->getAccessibleRowCount() );
233 #endif
234 
235         if( pTable )
236             return pTable->getAccessibleRowCount();
237     }
238     catch(const uno::Exception& e) {
239         g_warning( "Exception in getAccessibleRowCount()" );
240     }
241 
242     return -1;
243 }
244 
245 /*****************************************************************************/
246 
247 static gint
248 table_wrapper_get_column_extent_at( AtkTable *table,
249                                     gint      row,
250                                     gint      column )
251 {
252     try {
253         accessibility::XAccessibleTable* pTable = getTable( table );
254 
255 #ifdef ENABLE_TRACING
256         if( pTable )
257             fprintf(stderr, "getAccessibleColumnExtentAt( %u, %u ) returns %u\n",
258                 row, column, pTable->getAccessibleColumnExtentAt( row, column ) );
259 #endif
260 
261         if( pTable )
262             return pTable->getAccessibleColumnExtentAt( row, column );
263     }
264     catch(const uno::Exception& e) {
265         g_warning( "Exception in getAccessibleColumnExtentAt()" );
266     }
267 
268     return -1;
269 }
270 
271 /*****************************************************************************/
272 
273 static gint
274 table_wrapper_get_row_extent_at( AtkTable *table,
275                                  gint      row,
276                                  gint      column )
277 {
278     try {
279         accessibility::XAccessibleTable* pTable = getTable( table );
280 
281 #ifdef ENABLE_TRACING
282         if( pTable )
283             fprintf(stderr, "getAccessibleRowExtentAt( %u, %u ) returns %u\n",
284                 row, column, pTable->getAccessibleRowExtentAt( row, column ) );
285 #endif
286 
287         if( pTable )
288             return pTable->getAccessibleRowExtentAt( row, column );
289     }
290     catch(const uno::Exception& e) {
291         g_warning( "Exception in getAccessibleRowExtentAt()" );
292     }
293 
294     return -1;
295 }
296 
297 /*****************************************************************************/
298 
299 static AtkObject *
300 table_wrapper_get_caption( AtkTable *table )
301 {
302     try {
303         accessibility::XAccessibleTable* pTable = getTable( table );
304 
305 #ifdef ENABLE_TRACING
306         if( pTable )
307             fprintf(stderr, "getAccessibleCaption() returns" );
308 #endif
309 
310         if( pTable )
311             return atk_object_wrapper_conditional_ref( pTable->getAccessibleCaption() );
312     }
313 
314     catch(const uno::Exception& e) {
315         g_warning( "Exception in getAccessibleCaption()" );
316     }
317 
318     return NULL;
319 }
320 
321 /*****************************************************************************/
322 
323 static G_CONST_RETURN gchar *
324 table_wrapper_get_row_description( AtkTable *table,
325                                    gint      row )
326 {
327     try {
328         accessibility::XAccessibleTable* pTable = getTable( table );
329 
330 #ifdef ENABLE_TRACING
331         if( pTable )
332             fprintf(stderr, "getAccessibleRowDescription( %u ) returns %s\n",
333                 row, getAsConst( pTable->getAccessibleRowDescription( row ) ) );
334 #endif
335 
336         if( pTable )
337             return getAsConst( pTable->getAccessibleRowDescription( row ) );
338     }
339     catch(const uno::Exception& e) {
340         g_warning( "Exception in getAccessibleRowDescription()" );
341     }
342 
343     return NULL;
344 }
345 
346 /*****************************************************************************/
347 
348 static G_CONST_RETURN gchar *
349 table_wrapper_get_column_description( AtkTable *table,
350                                       gint      column )
351 {
352     try {
353         accessibility::XAccessibleTable* pTable = getTable( table );
354 
355 #ifdef ENABLE_TRACING
356         if( pTable )
357             fprintf(stderr, "getAccessibleColumnDescription( %u ) returns %s\n",
358                 column, getAsConst( pTable->getAccessibleColumnDescription( column ) ) );
359 #endif
360 
361         if( pTable )
362             return getAsConst( pTable->getAccessibleColumnDescription( column ) );
363     }
364     catch(const uno::Exception& e) {
365         g_warning( "Exception in getAccessibleColumnDescription()" );
366     }
367 
368     return NULL;
369 }
370 
371 /*****************************************************************************/
372 
373 static AtkObject *
374 table_wrapper_get_row_header( AtkTable *table,
375                               gint      row )
376 {
377     try {
378         accessibility::XAccessibleTable* pTable = getTable( table );
379         if( pTable )
380         {
381             uno::Reference< accessibility::XAccessibleTable > xRowHeaders( pTable->getAccessibleRowHeaders() );
382 
383 #ifdef ENABLE_TRACING
384             if( xRowHeaders.is() )
385                 fprintf(stderr, "getAccessibleRowHeader( %u )->getAccessibleCellAt( 0, %u ) returns",
386                     row, row );
387             else
388                 fprintf(stderr, "getAccessibleRowHeader( %u ) returns %p\n", row, xRowHeaders.get() );
389 #endif
390 
391             if( xRowHeaders.is() )
392                 return atk_object_wrapper_conditional_ref( xRowHeaders->getAccessibleCellAt( row, 0 ) );
393         }
394     }
395     catch(const uno::Exception& e) {
396         g_warning( "Exception in getAccessibleRowHeaders()" );
397     }
398 
399     return NULL;
400 }
401 
402 /*****************************************************************************/
403 
404 static AtkObject *
405 table_wrapper_get_column_header( AtkTable *table,
406                                  gint      column )
407 {
408     try {
409         accessibility::XAccessibleTable* pTable = getTable( table );
410 
411         if( pTable )
412         {
413             uno::Reference< accessibility::XAccessibleTable > xColumnHeaders( pTable->getAccessibleColumnHeaders() );
414 
415 #ifdef ENABLE_TRACING
416             if( xColumnHeaders.is() )
417                 fprintf(stderr, "getAccessibleColumnHeader( %u )->getAccessibleCellAt( 0, %u ) returns",
418                     column, column );
419             else
420                 fprintf(stderr, "getAccessibleColumnHeader( %u ) returns %p\n", column, xColumnHeaders.get() );
421 #endif
422 
423             if( xColumnHeaders.is() )
424                 return atk_object_wrapper_conditional_ref( xColumnHeaders->getAccessibleCellAt( 0, column ) );
425         }
426     }
427     catch(const uno::Exception& e) {
428         g_warning( "Exception in getAccessibleColumnHeaders()" );
429     }
430 
431     return NULL;
432 }
433 
434 /*****************************************************************************/
435 
436 static AtkObject *
437 table_wrapper_get_summary( AtkTable *table )
438 {
439     try {
440         accessibility::XAccessibleTable* pTable = getTable( table );
441 
442 #ifdef ENABLE_TRACING
443         if( pTable )
444             fprintf(stderr, "getAccessibleSummary() returns" );
445 #endif
446 
447         if( pTable )
448         {
449     // FIXME: Summary ??
450 //            AtkObject* summary;
451             return atk_object_wrapper_conditional_ref( pTable->getAccessibleSummary() );
452         }
453     }
454     catch(const uno::Exception& e) {
455         g_warning( "Exception in getAccessibleSummary()" );
456     }
457 
458     return NULL;
459 }
460 
461 /*****************************************************************************/
462 
463 static gint
464 convertToGIntArray( const uno::Sequence< ::sal_Int32 >& aSequence, gint **pSelected )
465 {
466     if( aSequence.getLength() )
467     {
468         *pSelected = g_new( gint, aSequence.getLength() );
469 
470         for( sal_Int32 i = 0; i < aSequence.getLength(); i++ )
471             (*pSelected) [i] = aSequence[i];
472     }
473 
474     return aSequence.getLength();
475 }
476 
477 /*****************************************************************************/
478 
479 static gint
480 table_wrapper_get_selected_columns( AtkTable      *table,
481                                     gint          **pSelected )
482 {
483     *pSelected = NULL;
484     try {
485         accessibility::XAccessibleTable* pTable = getTable( table );
486 
487 #ifdef ENABLE_TRACING
488         if( pTable )
489             fprintf(stderr, "getSelectedAccessibleColumns() \n" );
490 #endif
491 
492         if( pTable )
493             return convertToGIntArray( pTable->getSelectedAccessibleColumns(), pSelected );
494     }
495     catch(const uno::Exception& e) {
496         g_warning( "Exception in getSelectedAccessibleColumns()" );
497     }
498 
499     return 0;
500 }
501 
502 /*****************************************************************************/
503 
504 static gint
505 table_wrapper_get_selected_rows( AtkTable      *table,
506                                  gint          **pSelected )
507 {
508     *pSelected = NULL;
509     try {
510         accessibility::XAccessibleTable* pTable = getTable( table );
511 
512 #ifdef ENABLE_TRACING
513         if( pTable )
514             fprintf(stderr, "getSelectedAccessibleRows() \n" );
515 #endif
516 
517         if( pTable )
518             return convertToGIntArray( pTable->getSelectedAccessibleRows(), pSelected );
519     }
520     catch(const uno::Exception& e) {
521         g_warning( "Exception in getSelectedAccessibleRows()" );
522     }
523 
524     return 0;
525 }
526 
527 /*****************************************************************************/
528 
529 static gboolean
530 table_wrapper_is_column_selected( AtkTable      *table,
531                                   gint          column )
532 {
533     try {
534         accessibility::XAccessibleTable* pTable = getTable( table );
535 
536 #ifdef ENABLE_TRACING
537         if( pTable )
538             fprintf(stderr, "isAccessibleColumnSelected( %u ) returns %s\n",
539                 column, pTable->isAccessibleColumnSelected( column ) ? "true" : "false" );
540 #endif
541 
542         if( pTable )
543             return pTable->isAccessibleColumnSelected( column );
544     }
545     catch(const uno::Exception& e) {
546         g_warning( "Exception in isAccessibleColumnSelected()" );
547     }
548 
549     return 0;
550 }
551 
552 /*****************************************************************************/
553 
554 static gboolean
555 table_wrapper_is_row_selected( AtkTable      *table,
556                                gint          row )
557 {
558     try {
559         accessibility::XAccessibleTable* pTable = getTable( table );
560 
561 #ifdef ENABLE_TRACING
562         if( pTable )
563             fprintf(stderr, "isAccessibleRowSelected( %u ) returns %s\n",
564                 row, pTable->isAccessibleRowSelected( row ) ? "true" : "false" );
565 #endif
566 
567         if( pTable )
568             return pTable->isAccessibleRowSelected( row );
569     }
570     catch(const uno::Exception& e) {
571         g_warning( "Exception in isAccessibleRowSelected()" );
572     }
573 
574     return FALSE;
575 }
576 
577 /*****************************************************************************/
578 
579 static gboolean
580 table_wrapper_is_selected( AtkTable      *table,
581                            gint          row,
582                            gint          column )
583 {
584     try {
585         accessibility::XAccessibleTable* pTable = getTable( table );
586 
587 #ifdef ENABLE_TRACING
588         if( pTable )
589             fprintf(stderr, "isAccessibleSelected( %u, %u ) returns %s\n",
590                 row, column, pTable->isAccessibleSelected( row , column ) ? "true" : "false" );
591 #endif
592 
593         if( pTable )
594             return pTable->isAccessibleSelected( row, column );
595     }
596     catch(const uno::Exception& e) {
597         g_warning( "Exception in isAccessibleSelected()" );
598     }
599 
600     return FALSE;
601 }
602 
603 /*****************************************************************************/
604 
605 static gboolean
606 table_wrapper_add_row_selection( AtkTable *, gint )
607 {
608     g_warning( "FIXME: no simple analogue for add_row_selection" );
609     return 0;
610 }
611 
612 /*****************************************************************************/
613 
614 static gboolean
615 table_wrapper_remove_row_selection( AtkTable *, gint )
616 {
617     g_warning( "FIXME: no simple analogue for remove_row_selection" );
618     return 0;
619 }
620 
621 /*****************************************************************************/
622 
623 static gboolean
624 table_wrapper_add_column_selection( AtkTable *, gint )
625 {
626     g_warning( "FIXME: no simple analogue for add_column_selection" );
627     return 0;
628 }
629 
630 /*****************************************************************************/
631 
632 static gboolean
633 table_wrapper_remove_column_selection( AtkTable *, gint )
634 {
635     g_warning( "FIXME: no simple analogue for remove_column_selection" );
636     return 0;
637 }
638 
639 /*****************************************************************************/
640 
641 static void
642 table_wrapper_set_caption( AtkTable *, AtkObject * )
643 { // meaningless helper
644 }
645 
646 /*****************************************************************************/
647 
648 static void
649 table_wrapper_set_column_description( AtkTable *, gint, const gchar * )
650 { // meaningless helper
651 }
652 
653 
654 /*****************************************************************************/
655 
656 static void
657 table_wrapper_set_column_header( AtkTable *, gint, AtkObject * )
658 { // meaningless helper
659 }
660 
661 
662 /*****************************************************************************/
663 
664 static void
665 table_wrapper_set_row_description( AtkTable *, gint, const gchar * )
666 { // meaningless helper
667 }
668 
669 /*****************************************************************************/
670 
671 static void
672 table_wrapper_set_row_header( AtkTable *, gint, AtkObject * )
673 { // meaningless helper
674 }
675 
676 /*****************************************************************************/
677 
678 static void
679 table_wrapper_set_summary( AtkTable *, AtkObject * )
680 { // meaningless helper
681 }
682 
683 /*****************************************************************************/
684 
685 } // extern "C"
686 
687 void
688 tableIfaceInit (AtkTableIface *iface)
689 {
690   g_return_if_fail (iface != NULL);
691 
692   iface->ref_at = table_wrapper_ref_at;
693   iface->get_n_rows = table_wrapper_get_n_rows;
694   iface->get_n_columns = table_wrapper_get_n_columns;
695   iface->get_index_at = table_wrapper_get_index_at;
696   iface->get_column_at_index = table_wrapper_get_column_at_index;
697   iface->get_row_at_index = table_wrapper_get_row_at_index;
698   iface->is_row_selected = table_wrapper_is_row_selected;
699   iface->is_selected = table_wrapper_is_selected;
700   iface->get_selected_rows = table_wrapper_get_selected_rows;
701   iface->add_row_selection = table_wrapper_add_row_selection;
702   iface->remove_row_selection = table_wrapper_remove_row_selection;
703   iface->add_column_selection = table_wrapper_add_column_selection;
704   iface->remove_column_selection = table_wrapper_remove_column_selection;
705   iface->get_selected_columns = table_wrapper_get_selected_columns;
706   iface->is_column_selected = table_wrapper_is_column_selected;
707   iface->get_column_extent_at = table_wrapper_get_column_extent_at;
708   iface->get_row_extent_at = table_wrapper_get_row_extent_at;
709   iface->get_row_header = table_wrapper_get_row_header;
710   iface->set_row_header = table_wrapper_set_row_header;
711   iface->get_column_header = table_wrapper_get_column_header;
712   iface->set_column_header = table_wrapper_set_column_header;
713   iface->get_caption = table_wrapper_get_caption;
714   iface->set_caption = table_wrapper_set_caption;
715   iface->get_summary = table_wrapper_get_summary;
716   iface->set_summary = table_wrapper_set_summary;
717   iface->get_row_description = table_wrapper_get_row_description;
718   iface->set_row_description = table_wrapper_set_row_description;
719   iface->get_column_description = table_wrapper_get_column_description;
720   iface->set_column_description = table_wrapper_set_column_description;
721 }
722