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  * AccTable.cpp : Implementation of CAccTable.
24  */
25 #include "stdafx.h"
26 #include "UAccCOM2.h"
27 #include "AccTable.h"
28 #include <com/sun/star/accessibility/XAccessible.hpp>
29 #include "MAccessible.h"
30 
31 
32 #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLETABLEEXTENT_HPP_
33 #include <com/sun/star/accessibility/XAccessibleTableSelection.hpp>
34 #endif
35 
36 using namespace com::sun::star::accessibility;
37 using namespace com::sun::star::uno;
38 /**
39   * Gets accessible table cell.
40   *
41   * @param    row        the row of the specified cell.
42   * @param    column     the column of the specified cell.
43   * @param    accessible the accessible object of the cell.
44   */
45 
46 STDMETHODIMP CAccTable::get_accessibleAt(long row, long column, IUnknown * * accessible)
47 {
48 
49 	CHECK_ENABLE_INF
50 
51     ENTER_PROTECTED_BLOCK
52 
53     // #CHECK#
54     if(accessible == NULL)
55         return E_INVALIDARG;
56     // #CHECK XInterface#
57     if(!pRXTable.is())
58         return E_FAIL;
59 
60     Reference<XAccessible> pRAcc = GetXInterface()->getAccessibleCellAt(row,column);
61 
62     if(!pRAcc.is())
63     {
64         *accessible = NULL;
65         return E_FAIL;
66     }
67 
68     IAccessible* pRet = NULL;
69 
70     BOOL isTRUE = CMAccessible::get_IAccessibleFromXAccessible((long)pRAcc.get(),&pRet);
71     if(isTRUE)
72     {
73         *accessible = (IAccessible2 *)pRet;
74         pRet->AddRef();
75         return S_OK;
76     }
77     else if(pRAcc.is())
78     {
79         Reference<XAccessible> pxTable(GetXInterface(),UNO_QUERY);
80 
81         CMAccessible::g_pAgent->InsertAccObj(pRAcc.get(),pxTable.get());
82         isTRUE = CMAccessible::get_IAccessibleFromXAccessible((long)pRAcc.get(),&pRet);
83 
84         if(isTRUE)
85         {
86             *accessible = (IAccessible2 *)pRet;
87             pRet->AddRef();
88             return S_OK;
89         }
90     }
91     return E_FAIL;
92 
93     LEAVE_PROTECTED_BLOCK
94 }
95 
96 /**
97   * Gets accessible table caption.
98   *
99   * @param    accessible    the accessible object of table cpation.
100   */
101 STDMETHODIMP CAccTable::get_caption(IUnknown * *)
102 {
103 
104 
105     ENTER_PROTECTED_BLOCK
106 
107     return E_NOTIMPL;
108 
109     LEAVE_PROTECTED_BLOCK
110 }
111 
112 /**
113   * Gets accessible column description (as string).
114   *
115   * @param    column        the column index.
116   * @param    description   the description of the specified column.
117   */
118 STDMETHODIMP CAccTable::get_columnDescription(long column, BSTR * description)
119 {
120 
121 	CHECK_ENABLE_INF
122 
123     ENTER_PROTECTED_BLOCK
124 
125     // #CHECK#
126     if(description == NULL)
127         return E_INVALIDARG;
128 
129     // #CHECK XInterface#
130     if(!pRXTable.is())
131         return E_FAIL;
132 
133     const ::rtl::OUString& ouStr = GetXInterface()->getAccessibleColumnDescription(column);
134     // #CHECK#
135 
136     SAFE_SYSFREESTRING(*description);//??
137     *description = SysAllocString((OLECHAR*)ouStr.getStr());
138     if(description==NULL)
139         return E_FAIL;
140     return S_OK;
141 
142     LEAVE_PROTECTED_BLOCK
143 }
144 
145 /**
146   * Gets number of columns spanned by table cell.
147   *
148   * @param    row            the row of the specified cell.
149   * @param    column         the column of the specified cell.
150   * @param    spanColumns    the column span of the specified cell.
151   */
152 STDMETHODIMP CAccTable::get_columnExtentAt(long row, long column, long * nColumnsSpanned)
153 {
154 
155 	CHECK_ENABLE_INF
156 
157     ENTER_PROTECTED_BLOCK
158 
159     XAccessibleTable	*pXAccTable = GetXInterface();
160 
161     // Check pointer.
162     if(nColumnsSpanned == NULL)
163         return E_INVALIDARG;
164 
165     // Get Extent.
166     if(pXAccTable)
167     {
168         long lExt = pXAccTable->getAccessibleColumnExtentAt(row,column);
169 
170         // Fill Extent struct.
171         *nColumnsSpanned = lExt;
172         return S_OK;
173     }
174 
175     return E_FAIL;
176 
177     LEAVE_PROTECTED_BLOCK
178 }
179 
180 /**
181   * Gets accessible column header.
182   *
183   * @param    column        the column index.
184   * @param    accessible    the accessible object of the specified column.
185   */
186 STDMETHODIMP CAccTable::get_columnHeader(IAccessibleTable __RPC_FAR *__RPC_FAR *accessibleTable, long *startingRowIndex)
187 {
188 
189 	CHECK_ENABLE_INF
190 
191     ENTER_PROTECTED_BLOCK
192 
193     // #CHECK#
194     if(accessibleTable == NULL || startingRowIndex == NULL)
195         return E_INVALIDARG;
196 
197     // #CHECK XInterface#
198     if(!pRXTable.is())
199         return E_FAIL;
200 
201     Reference<XAccessibleTable> pRColumnHeaderTable = GetXInterface()->getAccessibleColumnHeaders();
202     if(!pRColumnHeaderTable.is())
203     {
204         *accessibleTable = NULL;
205         return E_FAIL;
206     }
207 
208     Reference<XAccessible> pRXColumnHeader(pRColumnHeaderTable,UNO_QUERY);
209 
210     if(!pRXColumnHeader.is())
211     {
212         *accessibleTable = NULL;
213         return E_FAIL;
214     }
215     *startingRowIndex = 0 ;
216 
217     IAccessible* m_pIMacc = NULL;
218 	HRESULT hr = CoCreateInstance( CLSID_MAccessible, NULL, CLSCTX_ALL ,
219                                     IID_IMAccessible,
220                                     (void **)&m_pIMacc
221                                   );
222     ((CMAccessible*)m_pIMacc)->SetXAccessible((long)pRXColumnHeader.get());
223     m_pIMacc->QueryInterface(IID_IAccessibleTable,(void **)accessibleTable);
224     if( SUCCEEDED(hr) )
225     {
226         return S_OK;
227     }
228 
229     return E_FAIL;
230 
231     LEAVE_PROTECTED_BLOCK
232 }
233 
234 /**
235   * Gets total number of columns in table.
236   *
237   * @param    columnCount    the number of columns in table.
238   */
239 STDMETHODIMP CAccTable::get_nColumns(long * columnCount)
240 {
241 
242 	CHECK_ENABLE_INF
243 
244     ENTER_PROTECTED_BLOCK
245 
246     // #CHECK#
247     if(columnCount == NULL)
248         return E_INVALIDARG;
249 
250     // #CHECK XInterface#
251     if(!pRXTable.is())
252         return E_FAIL;
253 
254     *columnCount = GetXInterface()->getAccessibleColumnCount();
255     return S_OK;
256 
257     LEAVE_PROTECTED_BLOCK
258 }
259 
260 /**
261   * Gets total number of rows in table.
262   *
263   * @param    rowCount    the number of rows in table.
264   */
265 STDMETHODIMP CAccTable::get_nRows(long * rowCount)
266 {
267 
268 	CHECK_ENABLE_INF
269 
270     ENTER_PROTECTED_BLOCK
271 
272     // #CHECK#
273     if(rowCount == NULL)
274         return E_INVALIDARG;
275 
276     // #CHECK XInterface#
277     if(!pRXTable.is())
278         return E_FAIL;
279 
280     *rowCount = GetXInterface()->getAccessibleRowCount();
281     return S_OK;
282 
283     LEAVE_PROTECTED_BLOCK
284 }
285 
286 /**
287   * Gets total number of selected columns.
288   *
289   * @param    columnCount    the number of selected columns.
290   */
291 STDMETHODIMP CAccTable::get_nSelectedColumns(long * columnCount)
292 {
293 
294 	CHECK_ENABLE_INF
295 
296     ENTER_PROTECTED_BLOCK
297 
298     // #CHECK#
299     if(columnCount == NULL)
300         return E_INVALIDARG;
301 
302     // #CHECK XInterface#
303     if(!pRXTable.is())
304         return E_FAIL;
305 
306     Sequence<long> pSelected = GetXInterface()->getSelectedAccessibleColumns();
307     *columnCount = pSelected.getLength();
308     return S_OK;
309 
310     LEAVE_PROTECTED_BLOCK
311 }
312 
313 /**
314   * Gets total number of selected rows.
315   *
316   * @param    rowCount    the number of selected rows.
317   */
318 STDMETHODIMP CAccTable::get_nSelectedRows(long * rowCount)
319 {
320 
321 	CHECK_ENABLE_INF
322 
323     ENTER_PROTECTED_BLOCK
324 
325     // #CHECK#
326     if(rowCount == NULL)
327         return E_INVALIDARG;
328 
329     // #CHECK XInterface#
330     if(!pRXTable.is())
331         return E_FAIL;
332 
333     Sequence<long> pSelected = GetXInterface()->getSelectedAccessibleRows();
334     *rowCount = pSelected.getLength();
335     return S_OK;
336 
337     LEAVE_PROTECTED_BLOCK
338 }
339 
340 /**
341   * Gets accessible row description (as string).
342   *
343   * @param    row            the row index.
344   * @param    description    the description of the specified row.
345   */
346 STDMETHODIMP CAccTable::get_rowDescription(long row, BSTR * description)
347 {
348 
349 	CHECK_ENABLE_INF
350 
351     ENTER_PROTECTED_BLOCK
352 
353     // #CHECK#
354     if(description == NULL)
355         return E_INVALIDARG;
356 
357     // #CHECK XInterface#
358     if(!pRXTable.is())
359         return E_FAIL;
360 
361     const ::rtl::OUString& ouStr = GetXInterface()->getAccessibleRowDescription(row);
362     // #CHECK#
363 
364     SAFE_SYSFREESTRING(*description);
365     *description = SysAllocString((OLECHAR*)ouStr.getStr());
366     if(description==NULL)
367         return E_FAIL;
368 
369     return S_OK;
370 
371     LEAVE_PROTECTED_BLOCK
372 }
373 
374 /**
375   * Gets number of rows spanned by a table cell.
376   *
377   * @param    row            the row of the specified cell.
378   * @param    column         the column of the specified cell.
379   * @param    spanRows       the row span of the specified cell.
380   */
381 STDMETHODIMP CAccTable::get_rowExtentAt(long row, long column, long * nRowsSpanned)
382 {
383 
384 	CHECK_ENABLE_INF
385 
386     ENTER_PROTECTED_BLOCK
387 
388     XAccessibleTable	*pXAccTable = GetXInterface();
389 
390     // Check pointer.
391     if(nRowsSpanned == NULL)
392         return E_INVALIDARG;
393 
394     // Get Extent.
395     if(pXAccTable)
396     {
397         long lExt = GetXInterface()->getAccessibleRowExtentAt(row,column);
398 
399         // Fill Extent struct.
400         *nRowsSpanned= lExt;
401 
402         return S_OK;
403     }
404 
405     return E_FAIL;
406 
407     LEAVE_PROTECTED_BLOCK
408 }
409 
410 /**
411   * Gets accessible row header.
412   *
413   * @param    row        the row index.
414   * @param    accessible the accessible object of the row header.
415   */
416 STDMETHODIMP CAccTable::get_rowHeader(IAccessibleTable __RPC_FAR *__RPC_FAR *accessibleTable, long *startingColumnIndex)
417 {
418 
419 	CHECK_ENABLE_INF
420 
421     ENTER_PROTECTED_BLOCK
422 
423     // #CHECK#
424     if(accessibleTable == NULL || startingColumnIndex == NULL)
425         return E_INVALIDARG;
426 
427     // #CHECK XInterface#
428     if(!pRXTable.is())
429         return E_FAIL;
430 
431     Reference<XAccessibleTable> pRRowHeaderTable = GetXInterface()->getAccessibleRowHeaders();
432     if(!pRRowHeaderTable.is())
433     {
434         *accessibleTable = NULL;
435         return E_FAIL;
436     }
437 
438     Reference<XAccessible> pRXRowHeader(pRRowHeaderTable,UNO_QUERY);
439 
440     if(!pRXRowHeader.is())
441     {
442         *accessibleTable = NULL;
443         return E_FAIL;
444     }
445     *startingColumnIndex = 0 ;
446 
447     IAccessible* m_pIMacc = NULL;
448 	HRESULT hr = CoCreateInstance( CLSID_MAccessible, NULL, CLSCTX_ALL ,
449                                     IID_IMAccessible,
450                                     (void **)&m_pIMacc
451                                   );
452     ((CMAccessible*)m_pIMacc)->SetXAccessible((long)pRXRowHeader.get());
453     m_pIMacc->QueryInterface(IID_IAccessibleTable,(void **)accessibleTable);
454     if( SUCCEEDED(hr) )
455     {
456         return S_OK;
457     }
458 
459     return E_FAIL;
460 
461     LEAVE_PROTECTED_BLOCK
462 }
463 
464 /**
465   * Gets list of row indexes currently selected (0-based).
466   *
467   * @param    maxRows        the max number of the rows.
468   * @param    accessible     the accessible object array of the selected rows.
469   * @param    nRows          the actual size of the accessible object array.
470   */
471 STDMETHODIMP CAccTable::get_selectedRows(long, long ** rows, long * nRows)
472 {
473 
474 	CHECK_ENABLE_INF
475 
476     ENTER_PROTECTED_BLOCK
477 
478     // #CHECK#
479     if(rows == NULL || nRows == NULL)
480         return E_INVALIDARG;
481 
482     // #CHECK XInterface#
483     if(!pRXTable.is())
484         return E_FAIL;
485 
486     Sequence<long> pSelected = GetXInterface()->getSelectedAccessibleRows();
487     long count = pSelected.getLength() ;
488     *nRows = count;
489 
490     *rows = reinterpret_cast<long*>(CoTaskMemAlloc((count) * sizeof(long)));
491 	// #CHECK Memory Allocation#
492 	if(*rows == NULL)
493 	{
494 		return E_FAIL;
495 	}
496     for(int i=0; i<count; i++)
497         (*rows)[i] = pSelected[i];
498 
499     return S_OK;
500 
501     LEAVE_PROTECTED_BLOCK
502 }
503 
504 /**
505   * Gets list of column indexes currently selected (0-based).
506   *
507   * @param    maxColumns    the max number of the columns.
508   * @param    accessible    the accessible object array of the selected columns.
509   * @param    numColumns    the actual size of accessible object array.
510   */
511 STDMETHODIMP CAccTable::get_selectedColumns(long, long ** columns, long * numColumns)
512 {
513 
514 	CHECK_ENABLE_INF
515 
516     ENTER_PROTECTED_BLOCK
517 
518     // #CHECK#
519     if(columns == NULL || numColumns == NULL)
520         return E_INVALIDARG;
521 
522     // #CHECK XInterface#
523     if(!pRXTable.is())
524         return E_FAIL;
525 
526     Sequence<long> pSelected = GetXInterface()->getSelectedAccessibleColumns();
527     long count = pSelected.getLength() ;
528     *numColumns = count;
529 
530     *columns = reinterpret_cast<long*>(CoTaskMemAlloc((count) * sizeof(long)));
531 	// #CHECK Memory Allocation#
532 	if(*columns == NULL)
533 	{
534 		return E_FAIL;
535 	}
536     for(int i=0; i<count; i++)
537         (*columns)[i] = pSelected[i];
538 
539     return S_OK;
540 
541     LEAVE_PROTECTED_BLOCK
542 }
543 
544 /**
545   * Gets accessible table summary.
546   *
547   * @param    accessible   the accessible object of the summary.
548   */
549 STDMETHODIMP CAccTable::get_summary(IUnknown * * accessible)
550 {
551 
552 	CHECK_ENABLE_INF
553 
554     ENTER_PROTECTED_BLOCK
555 
556     // #CHECK#
557     if(accessible == NULL)
558         return E_INVALIDARG;
559 
560     // #CHECK XInterface#
561     if(!pRXTable.is())
562     {
563         return E_FAIL;
564     }
565     Reference<XAccessible> pRAcc = GetXInterface()->getAccessibleSummary();
566 
567     IAccessible* pRet = NULL;
568     BOOL isTRUE = CMAccessible::get_IAccessibleFromXAccessible((long)pRAcc.get(),&pRet);
569 
570     if(pRet)
571     {
572         *accessible = (IAccessible2 *)pRet;
573         pRet->AddRef();
574         return S_OK;
575     }
576 
577     return E_FAIL;
578 
579     LEAVE_PROTECTED_BLOCK
580 }
581 
582 /**
583   * Determines if table column is selected.
584   *
585   * @param    column        the column index.
586   * @param    isSelected    the result.
587   */
588 STDMETHODIMP CAccTable::get_isColumnSelected(long column, unsigned char * isSelected)
589 {
590 
591 	CHECK_ENABLE_INF
592 
593     ENTER_PROTECTED_BLOCK
594 
595     // #CHECK#
596     if(isSelected == NULL)
597         return E_INVALIDARG;
598 
599     // #CHECK XInterface#
600     if(!pRXTable.is())
601         return E_FAIL;
602 
603     *isSelected = GetXInterface()->isAccessibleColumnSelected(column);
604     return S_OK;
605 
606     LEAVE_PROTECTED_BLOCK
607 }
608 
609 /**
610   * Determines if table row is selected.
611   *
612   * @param    row           the row index.
613   * @param    isSelected    the result.
614   */
615 STDMETHODIMP CAccTable::get_isRowSelected(long row, unsigned char * isSelected)
616 {
617 
618 	CHECK_ENABLE_INF
619 
620     ENTER_PROTECTED_BLOCK
621 
622     // #CHECK#
623     if(isSelected == NULL)
624         return E_INVALIDARG;
625 
626     // #CHECK XInterface#
627     if(!pRXTable.is())
628     {
629         return E_FAIL;
630     }
631     *isSelected = GetXInterface()->isAccessibleRowSelected(row);
632     return S_OK;
633 
634     LEAVE_PROTECTED_BLOCK
635 }
636 
637 /**
638   * Determines if table cell is selected.
639   *
640   * @param    row            the row index.
641   * @param    column         the column index.
642   * @param    isSelected     the result.
643   */
644 STDMETHODIMP CAccTable::get_isSelected(long row, long column, unsigned char * isSelected)
645 {
646 
647 	CHECK_ENABLE_INF
648 
649     ENTER_PROTECTED_BLOCK
650 
651     // #CHECK#
652     if(isSelected == NULL)
653         return E_INVALIDARG;
654 
655     // #CHECK XInterface#
656     if(!pRXTable.is())
657         return E_FAIL;
658 
659     *isSelected = GetXInterface()->isAccessibleSelected(row,column);
660     return S_OK;
661 
662     LEAVE_PROTECTED_BLOCK
663 }
664 
665 /**
666   * Selects a row and unselect all previously selected rows.
667   *
668   * @param    row        the row index.
669   * @param    success    the result.
670   */
671 STDMETHODIMP CAccTable::selectRow(long row)
672 {
673 
674 	CHECK_ENABLE_INF
675 
676     ENTER_PROTECTED_BLOCK
677 
678     // Check XAccessibleTable reference.
679     if(!pRXTable.is())
680         return E_FAIL;
681 
682     Reference<XAccessibleTableSelection>		pRTableExtent(pRXTable, UNO_QUERY);
683     if(pRTableExtent.is())
684     {
685         pRTableExtent.get()->selectRow(row);
686         return S_OK;
687     }
688     else
689     {
690         // Get XAccessibleSelection.
691         Reference<XAccessibleSelection>		pRSelection(GetXInterface(), UNO_QUERY);
692         if(!pRSelection.is())
693             return E_FAIL;
694 
695         // Select row.
696         long			lCol, lColumnCount, lChildIndex;
697         lColumnCount = GetXInterface()->getAccessibleColumnCount();
698         for(lCol = 0; lCol < lColumnCount; lCol ++)
699         {
700             lChildIndex = GetXInterface()->getAccessibleIndex(row, lCol);
701             pRSelection.get()->selectAccessibleChild(lChildIndex);
702         }
703 
704         return S_OK;
705     }
706     return S_OK;
707 
708     LEAVE_PROTECTED_BLOCK
709 }
710 
711 /**
712   * Selects a column and unselect all previously selected columns.
713   *
714   * @param    column    the column index.
715   * @param    success   the result.
716   */
717 STDMETHODIMP CAccTable::selectColumn(long column)
718 {
719 
720 	CHECK_ENABLE_INF
721 
722     ENTER_PROTECTED_BLOCK
723 
724     // Check XAccessibleTable reference.
725     if(!pRXTable.is())
726         return E_FAIL;
727 
728     Reference<XAccessibleTableSelection>		pRTableExtent(GetXInterface(), UNO_QUERY);
729     if(pRTableExtent.is())
730     {
731         pRTableExtent.get()->selectColumn(column);
732         return S_OK;
733     }
734     else
735     {
736         // Get XAccessibleSelection.
737         Reference<XAccessibleSelection>		pRSelection(pRXTable, UNO_QUERY);
738         if(!pRSelection.is())
739             return E_FAIL;
740 
741         // Select column.
742         long			lRow, lRowCount, lChildIndex;
743         lRowCount = GetXInterface()->getAccessibleRowCount();
744         for(lRow = 0; lRow < lRowCount; lRow ++)
745         {
746             lChildIndex = GetXInterface()->getAccessibleIndex(lRow, column);
747             pRSelection.get()->selectAccessibleChild(lChildIndex);
748         }
749 
750         return S_OK;
751     }
752     return S_OK;
753     // End of added.
754 
755     LEAVE_PROTECTED_BLOCK
756 }
757 
758 /**
759   * Unselects one row, leaving other selected rows selected (if any).
760   *
761   * @param    row        the row index.
762   * @param    success    the result.
763   */
764 STDMETHODIMP CAccTable::unselectRow(long row)
765 {
766 
767 	CHECK_ENABLE_INF
768 
769     ENTER_PROTECTED_BLOCK
770 
771     // Check XAccessibleTable reference.
772     if(!pRXTable.is())
773         return E_FAIL;
774 
775     Reference<XAccessibleTableSelection>		pRTableExtent(GetXInterface(), UNO_QUERY);
776     if(pRTableExtent.is())
777     {
778         if(pRTableExtent.get()->unselectRow(row))
779             return S_OK;
780         else
781             return E_FAIL;
782     }
783     else
784     {
785         // Get XAccessibleSelection.
786         Reference<XAccessibleSelection>		pRSelection(pRXTable, UNO_QUERY);
787         if(!pRSelection.is())
788             return E_FAIL;
789 
790         // Select column.
791         long			lColumn, lColumnCount, lChildIndex;
792         lColumnCount = GetXInterface()->getAccessibleColumnCount();
793         for(lColumn = 0; lColumn < lColumnCount; lColumn ++)
794         {
795             lChildIndex = GetXInterface()->getAccessibleIndex(row,lColumn);
796             pRSelection.get()->deselectAccessibleChild(lChildIndex);
797         }
798 
799         return S_OK;
800     }
801     return S_OK;
802     // End of added.
803 
804     LEAVE_PROTECTED_BLOCK
805 }
806 
807 /**
808   * Unselects one column, leaving other selected columns selected (if any).
809   *
810   * @param    column    the column index.
811   * @param    success   the result.
812   */
813 STDMETHODIMP CAccTable::unselectColumn(long column)
814 {
815 
816 	CHECK_ENABLE_INF
817 
818     ENTER_PROTECTED_BLOCK
819 
820     // Check XAccessibleTable reference.
821     if(!pRXTable.is())
822         return E_FAIL;
823 
824     Reference<XAccessibleTableSelection>		pRTableExtent(GetXInterface(), UNO_QUERY);
825     if(pRTableExtent.is())
826     {
827         if(pRTableExtent.get()->unselectColumn(column))
828             return S_OK;
829         else
830             return E_FAIL;
831     }
832     else
833     {
834         // Get XAccessibleSelection.
835         Reference<XAccessibleSelection>		pRSelection(pRXTable, UNO_QUERY);
836         if(!pRSelection.is())
837             return E_FAIL;
838 
839         // Unselect columns.
840         long			lRow, lRowCount, lChildIndex;
841         lRowCount = GetXInterface()->getAccessibleRowCount();
842 
843         for(lRow = 0; lRow < lRowCount; lRow ++)
844         {
845             lChildIndex = GetXInterface()->getAccessibleIndex(lRow, column);
846             pRSelection.get()->deselectAccessibleChild(lChildIndex);
847         }
848         return S_OK;
849     }
850 
851     return S_OK;
852 
853     LEAVE_PROTECTED_BLOCK
854 }
855 
856 /**
857  * Overide of IUNOXWrapper.
858  *
859  * @param    pXInterface    the pointer of UNO interface.
860  */
861 STDMETHODIMP CAccTable::put_XInterface(long pXInterface)
862 {
863 
864 	CHECK_ENABLE_INF
865 
866     ENTER_PROTECTED_BLOCK
867 
868     CUNOXWrapper::put_XInterface(pXInterface);
869     //special query.
870     if(pUNOInterface == NULL)
871         return E_INVALIDARG;
872 
873     Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext();
874     if( !pRContext.is() )
875         return E_FAIL;
876 
877     Reference<XAccessibleTable> pRXI(pRContext,UNO_QUERY);
878     if( !pRXI.is() )
879         pRXTable = NULL;
880     else
881         pRXTable = pRXI.get();
882     return S_OK;
883 
884     LEAVE_PROTECTED_BLOCK
885 }
886 
887 /**
888   * Gets columnIndex of childIndex.
889   *
890   * @param    childIndex    childIndex
891   */
892 STDMETHODIMP CAccTable::get_columnIndex(long childIndex, long * columnIndex)
893 {
894 
895 	CHECK_ENABLE_INF
896 
897     ENTER_PROTECTED_BLOCK
898 
899     // #CHECK#
900     if(columnIndex == NULL)
901         return E_INVALIDARG;
902 
903     // #CHECK XInterface#
904     if(!pRXTable.is())
905         return E_FAIL;
906 
907     *columnIndex = GetXInterface()->getAccessibleColumn(childIndex);
908     return S_OK;
909 
910     LEAVE_PROTECTED_BLOCK
911 }
912 /**
913   * Gets rowIndex of childIndex.
914   *
915   * @param    childIndex    childIndex
916   */
917 STDMETHODIMP CAccTable::get_rowIndex(long childIndex, long * rowIndex)
918 {
919 
920 	CHECK_ENABLE_INF
921 
922     ENTER_PROTECTED_BLOCK
923 
924     // #CHECK#
925     if(rowIndex == NULL)
926         return E_INVALIDARG;
927 
928     // #CHECK XInterface#
929     if(!pRXTable.is())
930         return E_FAIL;
931 
932     *rowIndex = GetXInterface()->getAccessibleRow(childIndex);
933     return S_OK;
934 
935     LEAVE_PROTECTED_BLOCK
936 }
937 /**
938   * Gets childIndex of childIndex.
939   *
940   * @param    childIndex    childIndex
941   */
942 STDMETHODIMP CAccTable::get_childIndex(long RowIndex , long columnIndex, long * childIndex )
943 {
944 
945 	CHECK_ENABLE_INF
946 
947     ENTER_PROTECTED_BLOCK
948 
949     // #CHECK#
950     if(childIndex == NULL)
951         return E_INVALIDARG;
952 
953     // #CHECK XInterface#
954     if(!pRXTable.is())
955         return E_FAIL;
956 
957     *childIndex = GetXInterface()->getAccessibleIndex(RowIndex, columnIndex);
958     return S_OK;
959 
960     LEAVE_PROTECTED_BLOCK
961 }
962 
963 STDMETHODIMP CAccTable::get_rowColumnExtentsAtIndex(long,
964         long  *,
965         long  *,
966         long  *,
967         long  *,
968         boolean  *)
969 {
970 
971 	CHECK_ENABLE_INF
972 
973     ENTER_PROTECTED_BLOCK
974 
975     return E_NOTIMPL;
976 
977     LEAVE_PROTECTED_BLOCK
978 }
979 
980 STDMETHODIMP CAccTable::get_modelChange(IA2TableModelChange  *)
981 {
982 
983     return E_NOTIMPL;
984 }
985 
986 // @brief Returns the total number of selected children
987 //   @param [out] childCount
988 //    Number of children currently selected
989 STDMETHODIMP CAccTable::get_nSelectedChildren(long *childCount)
990 {
991 
992 	CHECK_ENABLE_INF
993 
994     ENTER_PROTECTED_BLOCK
995 
996     // #CHECK#
997     if(childCount == NULL)
998         return E_INVALIDARG;
999 
1000     // #CHECK XInterface#
1001     if(!pRXTable.is())
1002         return E_FAIL;
1003 
1004     Reference<XAccessibleSelection>		pRSelection(GetXInterface(), UNO_QUERY);
1005     if(!pRSelection.is())
1006         return E_FAIL;
1007 
1008     *childCount = pRSelection->getSelectedAccessibleChildCount();
1009     return S_OK;
1010 
1011     LEAVE_PROTECTED_BLOCK
1012 }
1013 
1014 // @brief Returns a list of child indexes currently selected (0-based).
1015 //   @param [in] maxChildren
1016 //    Max children requested (possibly from IAccessibleTable::nSelectedChildren)
1017 //   @param [out] children
1018 //    array of indexes of selected children (each index is 0-based)
1019 //   @param [out] nChildren
1020 //    Length of array (not more than maxChildren)
1021 STDMETHODIMP CAccTable::get_selectedChildren(long, long **children, long *nChildren)
1022 {
1023 
1024 	CHECK_ENABLE_INF
1025 
1026     ENTER_PROTECTED_BLOCK
1027 
1028     // #CHECK#
1029     if(children == NULL || nChildren == NULL)
1030         return E_INVALIDARG;
1031 
1032     // #CHECK XInterface#
1033     if(!pRXTable.is())
1034         return E_FAIL;
1035 
1036     Reference<XAccessibleSelection>		pRSelection(GetXInterface(), UNO_QUERY);
1037     if(!pRSelection.is())
1038         return E_FAIL;
1039 
1040     long childCount = pRSelection->getSelectedAccessibleChildCount() ;
1041 
1042     *nChildren = childCount;
1043 
1044     *children = reinterpret_cast<long*>(CoTaskMemAlloc((childCount) * sizeof(long)));
1045 
1046     for( long i = 0; i< childCount; i++)
1047     {
1048         Reference<XAccessible> pRAcc = pRSelection->getSelectedAccessibleChild(i);
1049         if(pRAcc.is())
1050         {
1051             Reference<XAccessibleContext> pRContext(pRAcc, UNO_QUERY);
1052             if( !pRContext.is() )
1053                 return E_FAIL;
1054 
1055             long childIndex = pRContext->getAccessibleIndexInParent();
1056             (*children)[i] = childIndex;
1057         }
1058     }
1059 
1060     return S_OK;
1061 
1062     LEAVE_PROTECTED_BLOCK
1063 
1064 }
1065