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_accessibility.hxx"
30 
31 
32 #include "accessibility/extended/AccessibleBrowseBoxTable.hxx"
33 #include <svtools/accessibletableprovider.hxx>
34 
35 // ============================================================================
36 
37 using ::rtl::OUString;
38 
39 using ::com::sun::star::uno::Reference;
40 using ::com::sun::star::uno::Sequence;
41 using ::com::sun::star::uno::Any;
42 
43 using namespace ::com::sun::star;
44 using namespace ::com::sun::star::accessibility;
45 using namespace ::svt;
46 
47 // ============================================================================
48 
49 namespace accessibility {
50 
51 // ============================================================================
52 
53 // Ctor/Dtor/disposing --------------------------------------------------------
54 
55 DBG_NAME( AccessibleBrowseBoxTable )
56 
57 AccessibleBrowseBoxTable::AccessibleBrowseBoxTable(
58         const Reference< XAccessible >& rxParent,
59         IAccessibleTableProvider&                      rBrowseBox ) :
60     AccessibleBrowseBoxTableBase( rxParent, rBrowseBox, BBTYPE_TABLE )
61 {
62     DBG_CTOR( AccessibleBrowseBoxTable, NULL );
63 }
64 
65 AccessibleBrowseBoxTable::~AccessibleBrowseBoxTable()
66 {
67     DBG_DTOR( AccessibleBrowseBoxTable, NULL );
68 }
69 
70 // XAccessibleContext ---------------------------------------------------------
71 
72 Reference< XAccessible > SAL_CALL
73 AccessibleBrowseBoxTable::getAccessibleChild( sal_Int32 nChildIndex )
74     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
75 {
76     BBSolarGuard aSolarGuard;
77     ::osl::MutexGuard aGuard( getOslMutex() );
78     ensureIsAlive();
79     ensureIsValidIndex( nChildIndex );
80     return mpBrowseBox->CreateAccessibleCell(
81         implGetRow( nChildIndex ), (sal_Int16)implGetColumn( nChildIndex ) );
82 }
83 
84 sal_Int32 SAL_CALL AccessibleBrowseBoxTable::getAccessibleIndexInParent()
85     throw ( uno::RuntimeException )
86 {
87     ensureIsAlive();
88     return BBINDEX_TABLE;
89 }
90 
91 // XAccessibleComponent -------------------------------------------------------
92 
93 Reference< XAccessible > SAL_CALL
94 AccessibleBrowseBoxTable::getAccessibleAtPoint( const awt::Point& rPoint )
95     throw ( uno::RuntimeException )
96 {
97     BBSolarGuard aSolarGuard;
98     ::osl::MutexGuard aGuard( getOslMutex() );
99     ensureIsAlive();
100 
101     Reference< XAccessible > xChild;
102     sal_Int32 nRow = 0;
103     sal_uInt16 nColumnPos = 0;
104     if( mpBrowseBox->ConvertPointToCellAddress( nRow, nColumnPos, VCLPoint( rPoint ) ) )
105         xChild = mpBrowseBox->CreateAccessibleCell( nRow, nColumnPos );
106 
107     return xChild;
108 }
109 
110 void SAL_CALL AccessibleBrowseBoxTable::grabFocus()
111     throw ( uno::RuntimeException )
112 {
113     BBSolarGuard aSolarGuard;
114     ::osl::MutexGuard aGuard( getOslMutex() );
115     ensureIsAlive();
116     mpBrowseBox->GrabTableFocus();
117 }
118 
119 Any SAL_CALL AccessibleBrowseBoxTable::getAccessibleKeyBinding()
120     throw ( uno::RuntimeException )
121 {
122     ensureIsAlive();
123     return Any();   // no special key bindings for data table
124 }
125 
126 // XAccessibleTable -----------------------------------------------------------
127 
128 OUString SAL_CALL AccessibleBrowseBoxTable::getAccessibleRowDescription( sal_Int32 nRow )
129     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
130 {
131     BBSolarGuard aSolarGuard;
132     ::osl::MutexGuard aGuard( getOslMutex() );
133     ensureIsAlive();
134     ensureIsValidRow( nRow );
135     return mpBrowseBox->GetRowDescription( nRow );
136 }
137 
138 OUString SAL_CALL AccessibleBrowseBoxTable::getAccessibleColumnDescription( sal_Int32 nColumn )
139     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
140 {
141     BBSolarGuard aSolarGuard;
142     ::osl::MutexGuard aGuard( getOslMutex() );
143     ensureIsAlive();
144     ensureIsValidColumn( nColumn );
145     return mpBrowseBox->GetColumnDescription( (sal_uInt16)nColumn );
146 }
147 
148 Reference< XAccessibleTable > SAL_CALL AccessibleBrowseBoxTable::getAccessibleRowHeaders()
149     throw ( uno::RuntimeException )
150 {
151     ::osl::MutexGuard aGuard( getOslMutex() );
152     ensureIsAlive();
153     return implGetHeaderBar( BBINDEX_ROWHEADERBAR );
154 }
155 
156 Reference< XAccessibleTable > SAL_CALL AccessibleBrowseBoxTable::getAccessibleColumnHeaders()
157     throw ( uno::RuntimeException )
158 {
159     ::osl::MutexGuard aGuard( getOslMutex() );
160     ensureIsAlive();
161     return implGetHeaderBar( BBINDEX_COLUMNHEADERBAR );
162 }
163 
164 Sequence< sal_Int32 > SAL_CALL AccessibleBrowseBoxTable::getSelectedAccessibleRows()
165     throw ( uno::RuntimeException )
166 {
167     BBSolarGuard aSolarGuard;
168     ::osl::MutexGuard aGuard( getOslMutex() );
169     ensureIsAlive();
170 
171     Sequence< sal_Int32 > aSelSeq;
172     implGetSelectedRows( aSelSeq );
173     return aSelSeq;
174 }
175 
176 Sequence< sal_Int32 > SAL_CALL AccessibleBrowseBoxTable::getSelectedAccessibleColumns()
177     throw ( uno::RuntimeException )
178 {
179     BBSolarGuard aSolarGuard;
180     ::osl::MutexGuard aGuard( getOslMutex() );
181     ensureIsAlive();
182 
183     Sequence< sal_Int32 > aSelSeq;
184     implGetSelectedColumns( aSelSeq );
185     return aSelSeq;
186 }
187 
188 sal_Bool SAL_CALL AccessibleBrowseBoxTable::isAccessibleRowSelected( sal_Int32 nRow )
189     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
190 {
191     BBSolarGuard aSolarGuard;
192     ::osl::MutexGuard aGuard( getOslMutex() );
193     ensureIsAlive();
194     ensureIsValidRow( nRow );
195     return implIsRowSelected( nRow );
196 }
197 
198 sal_Bool SAL_CALL AccessibleBrowseBoxTable::isAccessibleColumnSelected( sal_Int32 nColumn )
199     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
200 {
201     BBSolarGuard aSolarGuard;
202     ::osl::MutexGuard aGuard( getOslMutex() );
203     ensureIsAlive();
204     ensureIsValidColumn( nColumn );
205     return implIsColumnSelected( nColumn );
206 }
207 
208 Reference< XAccessible > SAL_CALL AccessibleBrowseBoxTable::getAccessibleCellAt(
209         sal_Int32 nRow, sal_Int32 nColumn )
210     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
211 {
212     BBSolarGuard aSolarGuard;
213     ::osl::MutexGuard aGuard( getOslMutex() );
214     ensureIsAlive();
215     ensureIsValidAddress( nRow, nColumn );
216     return mpBrowseBox->CreateAccessibleCell( nRow, (sal_Int16)nColumn );
217 }
218 
219 sal_Bool SAL_CALL AccessibleBrowseBoxTable::isAccessibleSelected(
220         sal_Int32 nRow, sal_Int32 nColumn )
221     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
222 {
223     BBSolarGuard aSolarGuard;
224     ::osl::MutexGuard aGuard( getOslMutex() );
225     ensureIsAlive();
226     ensureIsValidAddress( nRow, nColumn );
227     return implIsRowSelected( nRow ) || implIsColumnSelected( nColumn );
228 }
229 
230 // XServiceInfo ---------------------------------------------------------------
231 
232 OUString SAL_CALL AccessibleBrowseBoxTable::getImplementationName()
233     throw ( uno::RuntimeException )
234 {
235     return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svtools.AccessibleBrowseBoxTable" ) );
236 }
237 
238 // internal virtual methods ---------------------------------------------------
239 
240 Rectangle AccessibleBrowseBoxTable::implGetBoundingBox()
241 {
242 	return mpBrowseBox->calcTableRect(sal_False);
243 }
244 
245 Rectangle AccessibleBrowseBoxTable::implGetBoundingBoxOnScreen()
246 {
247     return mpBrowseBox->calcTableRect();
248 }
249 
250 // internal helper methods ----------------------------------------------------
251 
252 Reference< XAccessibleTable > AccessibleBrowseBoxTable::implGetHeaderBar(
253         sal_Int32 nChildIndex )
254     throw ( uno::RuntimeException )
255 {
256     Reference< XAccessible > xRet;
257     Reference< XAccessibleContext > xContext( mxParent, uno::UNO_QUERY );
258     if( xContext.is() )
259     {
260         try
261         {
262             xRet = xContext->getAccessibleChild( nChildIndex );
263         }
264         catch( lang::IndexOutOfBoundsException& )
265         {
266             DBG_ERROR( "implGetHeaderBar - wrong child index" );
267         }
268         // RuntimeException goes to caller
269     }
270     return Reference< XAccessibleTable >( xRet, uno::UNO_QUERY );
271 }
272 
273 // ============================================================================
274 
275 } // namespace accessibility
276 
277 // ============================================================================
278 
279