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