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_accessibility.hxx"
26 
27 
28 #include "accessibility/extended/AccessibleGridControlHeader.hxx"
29 #include "accessibility/extended/AccessibleGridControlHeaderCell.hxx"
30 #include "accessibility/extended/AccessibleGridControlTableCell.hxx"
31 #include <svtools/accessibletable.hxx>
32 
33 
34 // ============================================================================
35 
36 using ::rtl::OUString;
37 
38 using ::com::sun::star::uno::Reference;
39 using ::com::sun::star::uno::Sequence;
40 using ::com::sun::star::uno::Any;
41 
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star;
44 using namespace ::com::sun::star::lang;
45 using namespace ::com::sun::star::accessibility;
46 using namespace ::svt;
47 using namespace ::svt::table;
48 
49 // ============================================================================
50 
51 namespace accessibility {
52 
53 // ============================================================================
54 
DBG_NAME(AccessibleGridControlHeader)55 DBG_NAME( AccessibleGridControlHeader )
56 
57 AccessibleGridControlHeader::AccessibleGridControlHeader(
58         const Reference< XAccessible >& rxParent,
59         ::svt::table::IAccessibleTable&                      rTable,
60 		::svt::table::AccessibleTableControlObjType      eObjType):
61 		AccessibleGridControlTableBase( rxParent, rTable, eObjType )
62 {
63     DBG_ASSERT( isRowBar() || isColumnBar(),
64         "accessibility/extended/AccessibleGridControlHeaderBar - invalid object type" );
65 }
66 
~AccessibleGridControlHeader()67 AccessibleGridControlHeader::~AccessibleGridControlHeader()
68 {
69 }
70 
71 // XAccessibleContext ---------------------------------------------------------
72 
73 Reference< XAccessible > SAL_CALL
getAccessibleChild(sal_Int32 nChildIndex)74 AccessibleGridControlHeader::getAccessibleChild( sal_Int32 nChildIndex )
75     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
76 {
77     TCSolarGuard aSolarGuard;
78     ::osl::MutexGuard aGuard( getOslMutex() );
79 
80     if (nChildIndex<0 || nChildIndex>=getAccessibleChildCount())
81 	throw IndexOutOfBoundsException();
82     ensureIsAlive();
83     Reference< XAccessible > xChild;
84     if(m_eObjType == svt::table::TCTYPE_COLUMNHEADERBAR)
85     {
86 	    AccessibleGridControlHeaderCell* pColHeaderCell = new AccessibleGridControlHeaderCell(nChildIndex, this, m_aTable, svt::table::TCTYPE_COLUMNHEADERCELL);
87 	    xChild = pColHeaderCell;
88     }
89     else if(m_eObjType == svt::table::TCTYPE_ROWHEADERBAR)
90     {
91 	    AccessibleGridControlHeaderCell* pRowHeaderCell = new AccessibleGridControlHeaderCell(nChildIndex, this, m_aTable, svt::table::TCTYPE_ROWHEADERCELL);
92 	    xChild = pRowHeaderCell;
93     }
94     return xChild;
95 }
96 
getAccessibleIndexInParent()97 sal_Int32 SAL_CALL AccessibleGridControlHeader::getAccessibleIndexInParent()
98     throw ( uno::RuntimeException )
99 {
100      ensureIsAlive();
101      if(m_eObjType == svt::table::TCTYPE_ROWHEADERBAR && m_aTable.HasColHeader())
102 	     return 1;
103      else
104 	     return 0;
105 }
106 
107 // XAccessibleComponent -------------------------------------------------------
108 
109 Reference< XAccessible > SAL_CALL
getAccessibleAtPoint(const awt::Point & rPoint)110 AccessibleGridControlHeader::getAccessibleAtPoint( const awt::Point& rPoint )
111     throw ( uno::RuntimeException )
112 {
113     TCSolarGuard aSolarGuard;
114     ::osl::MutexGuard aGuard( getOslMutex() );
115     ensureIsAlive();
116 
117     sal_Int32 nRow = 0;
118     sal_Int32 nColumnPos = 0;
119     sal_Bool bConverted = isRowBar() ?
120     m_aTable.ConvertPointToCellAddress( nRow, nColumnPos, VCLPoint( rPoint ) ) :
121     m_aTable.ConvertPointToCellAddress( nRow, nColumnPos, VCLPoint( rPoint ) );
122 
123     return bConverted ? implGetChild( nRow, nColumnPos ) : Reference< XAccessible >();
124 }
125 
grabFocus()126 void SAL_CALL AccessibleGridControlHeader::grabFocus()
127     throw ( uno::RuntimeException )
128 {
129     ensureIsAlive();
130     // focus on header not supported
131 }
132 
getAccessibleKeyBinding()133 Any SAL_CALL AccessibleGridControlHeader::getAccessibleKeyBinding()
134     throw ( uno::RuntimeException )
135 {
136     ensureIsAlive();
137     return Any();   // no special key bindings for header
138 }
139 
140 // XAccessibleTable -----------------------------------------------------------
141 
getAccessibleRowDescription(sal_Int32 nRow)142 OUString SAL_CALL AccessibleGridControlHeader::getAccessibleRowDescription( sal_Int32 nRow )
143     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
144 {
145     TCSolarGuard aSolarGuard;
146     ::osl::MutexGuard aGuard( getOslMutex() );
147     ensureIsAlive();
148     ensureIsValidRow( nRow );
149     return OUString();  // no headers in headers
150 }
151 
getAccessibleColumnDescription(sal_Int32 nColumn)152 OUString SAL_CALL AccessibleGridControlHeader::getAccessibleColumnDescription( sal_Int32 nColumn )
153     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
154 {
155     TCSolarGuard aSolarGuard;
156     ::osl::MutexGuard aGuard( getOslMutex() );
157     ensureIsAlive();
158     ensureIsValidColumn( nColumn );
159     return OUString();  // no headers in headers
160 }
161 
getAccessibleRowHeaders()162 Reference< XAccessibleTable > SAL_CALL AccessibleGridControlHeader::getAccessibleRowHeaders()
163     throw ( uno::RuntimeException )
164 {
165     ensureIsAlive();
166     return NULL;        // no headers in headers
167 }
168 
getAccessibleColumnHeaders()169 Reference< XAccessibleTable > SAL_CALL AccessibleGridControlHeader::getAccessibleColumnHeaders()
170     throw ( uno::RuntimeException )
171 {
172     ensureIsAlive();
173     return NULL;        // no headers in headers
174 }
175 //not selectable
getSelectedAccessibleRows()176 Sequence< sal_Int32 > SAL_CALL AccessibleGridControlHeader::getSelectedAccessibleRows()
177     throw ( uno::RuntimeException )
178 {
179     Sequence< sal_Int32 > aSelSeq(0);
180     return aSelSeq;
181 }
182 //columns aren't selectable
getSelectedAccessibleColumns()183 Sequence< sal_Int32 > SAL_CALL AccessibleGridControlHeader::getSelectedAccessibleColumns()
184     throw ( uno::RuntimeException )
185 {
186     Sequence< sal_Int32 > aSelSeq(0);
187     return aSelSeq;
188 }
189 //row headers not selectable
isAccessibleRowSelected(sal_Int32)190 sal_Bool SAL_CALL AccessibleGridControlHeader::isAccessibleRowSelected( sal_Int32 /*nRow*/ )
191     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
192 {
193     return sal_False;
194 }
195 //columns aren't selectable
isAccessibleColumnSelected(sal_Int32 nColumn)196 sal_Bool SAL_CALL AccessibleGridControlHeader::isAccessibleColumnSelected( sal_Int32 nColumn )
197     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
198 {
199     (void)nColumn;
200     return sal_False;
201 }
202 //not implemented
getAccessibleCellAt(sal_Int32,sal_Int32)203 Reference< XAccessible > SAL_CALL AccessibleGridControlHeader::getAccessibleCellAt(
204         sal_Int32 /*nRow*/, sal_Int32 /*nColumn*/ )
205     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
206 {
207     return NULL;
208 }
209 // not selectable
isAccessibleSelected(sal_Int32,sal_Int32)210 sal_Bool SAL_CALL AccessibleGridControlHeader::isAccessibleSelected(
211         sal_Int32 /*nRow*/, sal_Int32 /*nColumn */)
212     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
213 {
214     return sal_False;
215 }
216 
217 // XServiceInfo ---------------------------------------------------------------
218 
getImplementationName()219 OUString SAL_CALL AccessibleGridControlHeader::getImplementationName()
220     throw ( uno::RuntimeException )
221 {
222     return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.accessibility.AccessibleGridControlHeader" ) );
223 }
224 
getImplementationId()225 Sequence< sal_Int8 > SAL_CALL AccessibleGridControlHeader::getImplementationId()
226     throw ( uno::RuntimeException )
227 {
228     ::osl::MutexGuard aGuard( getOslGlobalMutex() );
229     static Sequence< sal_Int8 > aId;
230     implCreateUuid( aId );
231     return aId;
232 }
233 
234 // internal virtual methods ---------------------------------------------------
235 
implGetBoundingBox()236 Rectangle AccessibleGridControlHeader::implGetBoundingBox()
237 {
238     Window* pParent = m_aTable.GetAccessibleParentWindow();
239 	Rectangle aGridRect( m_aTable.GetWindowExtentsRelative( pParent ) );
240 	Rectangle aHeaderRect (m_aTable.calcHeaderRect(isColumnBar()));
241 	if(isColumnBar())
242 		return Rectangle(aGridRect.TopLeft(), Size(aGridRect.getWidth(),aHeaderRect.getHeight()));
243 	else
244 		return Rectangle(aGridRect.TopLeft(), Size(aHeaderRect.getWidth(),aGridRect.getHeight()));
245 
246 }
247 
implGetBoundingBoxOnScreen()248 Rectangle AccessibleGridControlHeader::implGetBoundingBoxOnScreen()
249 {
250     Rectangle aGridRect( m_aTable.GetWindowExtentsRelative( NULL ) );
251 	Rectangle aHeaderRect (m_aTable.calcHeaderRect(isColumnBar()));
252 	if(isColumnBar())
253 		return Rectangle(aGridRect.TopLeft(), Size(aGridRect.getWidth(),aHeaderRect.getHeight()));
254 	else
255 		return Rectangle(aGridRect.TopLeft(), Size(aHeaderRect.getWidth(),aGridRect.getHeight()));
256 }
257 
implGetRowCount() const258 sal_Int32 AccessibleGridControlHeader::implGetRowCount() const
259 {
260     return 1;
261 }
262 
implGetColumnCount() const263 sal_Int32 AccessibleGridControlHeader::implGetColumnCount() const
264 {
265     return 1;
266 }
267 
268 // internal helper methods ----------------------------------------------------
269 
implGetChild(sal_Int32 nRow,sal_uInt32 nColumnPos)270 Reference< XAccessible > AccessibleGridControlHeader::implGetChild(
271         sal_Int32 nRow, sal_uInt32 nColumnPos )
272 {
273     Reference< XAccessible > xChild;
274     if(m_eObjType == svt::table::TCTYPE_COLUMNHEADERBAR)
275     {
276 	    AccessibleGridControlHeaderCell* pColHeaderCell = new AccessibleGridControlHeaderCell(nColumnPos, this, m_aTable, svt::table::TCTYPE_COLUMNHEADERCELL);
277 	    xChild = pColHeaderCell;
278     }
279     else if(m_eObjType == svt::table::TCTYPE_ROWHEADERBAR)
280     {
281 	    AccessibleGridControlHeaderCell* pRowHeaderCell = new AccessibleGridControlHeaderCell(nRow, this, m_aTable, svt::table::TCTYPE_ROWHEADERCELL);
282 	    xChild = pRowHeaderCell;
283     }
284     return xChild;
285 }
286 
287 // ============================================================================
288 
289 } // namespace accessibility
290 
291 // ============================================================================
292 
293