1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "extended/AccessibleGridControl.hxx"
#include "extended/AccessibleGridControlTable.hxx"
#include "extended/AccessibleGridControlHeader.hxx"
#include <com/sun/star/accessibility/AccessibleEventId.hpp>
#include <com/sun/star/accessibility/AccessibleTableModelChange.hpp>
#include <com/sun/star/accessibility/AccessibleTableModelChangeType.hpp>
#include <svtools/accessibletable.hxx>
#include <comphelper/types.hxx>
#include <toolkit/helper/vclunohelper.hxx>
namespace accessibility
{
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::accessibility;
using namespace ::svt;
using namespace ::svt::table;
class AccessibleGridControl_Impl
{
public:
/// the css::accessibility::XAccessible which created the AccessibleGridControl
css::uno::WeakReference< css::accessibility::XAccessible > m_aCreator;
/** The data table child. */
css::uno::Reference< css::accessibility::XAccessible > m_xTable;
AccessibleGridControlTable* m_pTable;
/** The header bar for rows. */
css::uno::Reference< css::accessibility::XAccessible > m_xRowHeaderBar;
AccessibleGridControlHeader* m_pRowHeaderBar;
/** The header bar for columns (first row of the table). */
css::uno::Reference< css::accessibility::XAccessible > m_xColumnHeaderBar;
AccessibleGridControlHeader* m_pColumnHeaderBar;
/** The table cell child. */
css::uno::Reference< css::accessibility::XAccessible > m_xCell;
AccessibleGridControlTableCell* m_pCell;
};
AccessibleGridControl::AccessibleGridControl(
const css::uno::Reference< css::accessibility::XAccessible >& _rxParent, const css::uno::Reference< css::accessibility::XAccessible >& _rxCreator,
::svt::table::IAccessibleTable& _rTable )
: AccessibleGridControlBase( _rxParent, _rTable, TCTYPE_GRIDCONTROL )
{
m_xImpl.reset( new AccessibleGridControl_Impl() );
m_xImpl->m_aCreator = _rxCreator;
}
AccessibleGridControl::~AccessibleGridControl()
{
}
void SAL_CALL AccessibleGridControl::disposing()
{
SolarMutexGuard g;
m_xImpl->m_pTable = nullptr;
m_xImpl->m_pColumnHeaderBar = nullptr;
m_xImpl->m_pRowHeaderBar = nullptr;
m_xImpl->m_pCell = nullptr;
m_xImpl->m_aCreator.clear();
css::uno::Reference< css::accessibility::XAccessible > xTable = m_xImpl->m_xTable;
css::uno::Reference< XComponent > xComp( m_xImpl->m_xTable, UNO_QUERY );
if ( xComp.is() )
{
xComp->dispose();
}
css::uno::Reference< css::accessibility::XAccessible > xCell = m_xImpl->m_xCell;
css::uno::Reference< XComponent > xCellComp( m_xImpl->m_xCell, UNO_QUERY );
if ( xCellComp.is() )
{
xCellComp->dispose();
}
::comphelper::disposeComponent(m_xImpl->m_xRowHeaderBar);
::comphelper::disposeComponent(m_xImpl->m_xColumnHeaderBar);
AccessibleGridControlBase::disposing();
}
// css::accessibility::XAccessibleContext ---------------------------------------------------------
sal_Int32 SAL_CALL AccessibleGridControl::getAccessibleChildCount()
throw ( uno::RuntimeException, std::exception )
{
SolarMutexGuard aSolarGuard;
ensureIsAlive();
return m_aTable.GetAccessibleControlCount();
}
css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
AccessibleGridControl::getAccessibleChild( sal_Int32 nChildIndex )
throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
{
SolarMutexGuard aSolarGuard;
if (nChildIndex<0 || nChildIndex>=getAccessibleChildCount())
throw IndexOutOfBoundsException();
css::uno::Reference< css::accessibility::XAccessible > xChild;
if (isAlive())
{
if(nChildIndex == 0 && m_aTable.HasColHeader())
{
if(!m_xImpl->m_xColumnHeaderBar.is())
{
AccessibleGridControlHeader* pColHeaderBar = new AccessibleGridControlHeader(m_xImpl->m_aCreator, m_aTable, svt::table::TCTYPE_COLUMNHEADERBAR);
m_xImpl->m_xColumnHeaderBar = pColHeaderBar;
}
xChild = m_xImpl->m_xColumnHeaderBar;
}
else if(m_aTable.HasRowHeader() && (nChildIndex == 1 || nChildIndex == 0))
{
if(!m_xImpl->m_xRowHeaderBar.is())
{
AccessibleGridControlHeader* pRowHeaderBar = new AccessibleGridControlHeader(m_xImpl->m_aCreator, m_aTable, svt::table::TCTYPE_ROWHEADERBAR);
m_xImpl->m_xRowHeaderBar = pRowHeaderBar;
}
xChild = m_xImpl->m_xRowHeaderBar;
}
else
{
if(!m_xImpl->m_xTable.is())
{
AccessibleGridControlTable* pTable = new AccessibleGridControlTable(m_xImpl->m_aCreator, m_aTable, svt::table::TCTYPE_TABLE);
m_xImpl->m_xTable = pTable;
m_xImpl->m_pTable = pTable;
}
xChild = m_xImpl->m_xTable;
}
}
return xChild;
}
sal_Int16 SAL_CALL AccessibleGridControl::getAccessibleRole()
throw ( uno::RuntimeException, std::exception )
{
SolarMutexGuard g;
ensureIsAlive();
return AccessibleRole::PANEL;
}
// css::accessibility::XAccessibleComponent -------------------------------------------------------
css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
AccessibleGridControl::getAccessibleAtPoint( const awt::Point& rPoint )
throw ( uno::RuntimeException, std::exception )
{
SolarMutexGuard aSolarGuard;
ensureIsAlive();
css::uno::Reference< css::accessibility::XAccessible > xChild;
sal_Int32 nIndex = 0;
if( m_aTable.ConvertPointToControlIndex( nIndex, VCLPoint( rPoint ) ) )
xChild = m_aTable.CreateAccessibleControl( nIndex );
else
{
// try whether point is in one of the fixed children
// (table, header bars, corner control)
Point aPoint( VCLPoint( rPoint ) );
for( nIndex = 0; (nIndex < 3) && !xChild.is(); ++nIndex )
{
css::uno::Reference< css::accessibility::XAccessible > xCurrChild( implGetFixedChild( nIndex ) );
css::uno::Reference< css::accessibility::XAccessibleComponent >
xCurrChildComp( xCurrChild, uno::UNO_QUERY );
if( xCurrChildComp.is() &&
VCLRectangle( xCurrChildComp->getBounds() ).IsInside( aPoint ) )
xChild = xCurrChild;
}
}
return xChild;
}
void SAL_CALL AccessibleGridControl::grabFocus()
throw ( uno::RuntimeException, std::exception )
{
SolarMutexGuard aSolarGuard;
ensureIsAlive();
m_aTable.GrabFocus();
}
// XServiceInfo ---------------------------------------------------------------
OUString SAL_CALL AccessibleGridControl::getImplementationName()
throw ( uno::RuntimeException, std::exception )
{
return OUString( "com.sun.star.accessibility.AccessibleGridControl" );
}
// internal virtual methods ---------------------------------------------------
Rectangle AccessibleGridControl::implGetBoundingBox()
{
vcl::Window* pParent = m_aTable.GetAccessibleParentWindow();
OSL_ENSURE( pParent, "implGetBoundingBox - missing parent window" );
return m_aTable.GetWindowExtentsRelative( pParent );
}
Rectangle AccessibleGridControl::implGetBoundingBoxOnScreen()
{
return m_aTable.GetWindowExtentsRelative( nullptr );
}
// internal helper methods ----------------------------------------------------
css::uno::Reference< css::accessibility::XAccessible > AccessibleGridControl::implGetTable()
{
if( !m_xImpl->m_xTable.is() )
{
m_xImpl->m_pTable = createAccessibleTable();
m_xImpl->m_xTable = m_xImpl->m_pTable;
}
return m_xImpl->m_xTable;
}
css::uno::Reference< css::accessibility::XAccessible >
AccessibleGridControl::implGetHeaderBar( AccessibleTableControlObjType eObjType )
{
css::uno::Reference< css::accessibility::XAccessible > xRet;
css::uno::Reference< css::accessibility::XAccessible >* pxMember = nullptr;
if( eObjType == TCTYPE_ROWHEADERBAR )
pxMember = &m_xImpl->m_xRowHeaderBar;
else if( eObjType == TCTYPE_COLUMNHEADERBAR )
pxMember = &m_xImpl->m_xColumnHeaderBar;
if( pxMember )
{
if( !pxMember->is() )
{
AccessibleGridControlHeader* pHeaderBar = new AccessibleGridControlHeader(
m_xImpl->m_aCreator, m_aTable, eObjType );
if ( TCTYPE_COLUMNHEADERBAR == eObjType)
m_xImpl->m_pColumnHeaderBar = pHeaderBar;
else
m_xImpl->m_pRowHeaderBar = pHeaderBar;
*pxMember = pHeaderBar;
}
xRet = *pxMember;
}
return xRet;
}
css::uno::Reference< css::accessibility::XAccessible >
AccessibleGridControl::implGetFixedChild( sal_Int32 nChildIndex )
{
css::uno::Reference< css::accessibility::XAccessible > xRet;
switch( nChildIndex )
{
case TCINDEX_COLUMNHEADERBAR:
xRet = implGetHeaderBar( TCTYPE_COLUMNHEADERBAR );
break;
case TCINDEX_ROWHEADERBAR:
xRet = implGetHeaderBar( TCTYPE_ROWHEADERBAR );
break;
case TCINDEX_TABLE:
xRet = implGetTable();
break;
}
return xRet;
}
AccessibleGridControlTable* AccessibleGridControl::createAccessibleTable()
{
css::uno::Reference< css::accessibility::XAccessible > xCreator(m_xImpl->m_aCreator);
OSL_ENSURE( xCreator.is(), "extended/AccessibleGridControl::createAccessibleTable: my creator died - how this?" );
return new AccessibleGridControlTable( xCreator, m_aTable, TCTYPE_TABLE );
}
void AccessibleGridControl::commitCellEvent(sal_Int16 _nEventId,const Any& _rNewValue,const Any& _rOldValue)
{
sal_Int32 nChildCount = getAccessibleChildCount();
if(nChildCount != 0)
{
for(sal_Int32 i=0;i<nChildCount;i++)
{
css::uno::Reference< css::accessibility::XAccessible > xAccessible = getAccessibleChild(i);
css::uno::Reference< css::accessibility::XAccessibleContext > xAccessibleChild = xAccessible->getAccessibleContext();
if(m_xImpl->m_xTable == xAccessible)
{
std::vector< AccessibleGridControlTableCell* >& rCells =
m_xImpl->m_pTable->getCellVector();
size_t nIndex = m_aTable.GetCurrentRow() * m_aTable.GetColumnCount()
+ m_aTable.GetCurrentColumn();
if (nIndex < rCells.size() && rCells[nIndex])
{
m_xImpl->m_pCell = rCells[nIndex];
m_xImpl->m_pCell->commitEvent( _nEventId, _rNewValue, _rOldValue );
}
}
}
}
else
{
if ( m_xImpl->m_xTable.is() )
m_xImpl->m_pTable->commitEvent(_nEventId,_rNewValue,_rOldValue);
}
}
void AccessibleGridControl::commitTableEvent(sal_Int16 _nEventId,const Any& _rNewValue,const Any& _rOldValue)
{
if ( m_xImpl->m_xTable.is() )
{
if(_nEventId == AccessibleEventId::ACTIVE_DESCENDANT_CHANGED)
{
const sal_Int32 nCurrentRow = m_aTable.GetCurrentRow();
const sal_Int32 nCurrentCol = m_aTable.GetCurrentColumn();
css::uno::Reference< css::accessibility::XAccessible > xChild;
if (nCurrentRow > -1 && nCurrentCol > -1)
{
sal_Int32 nColumnCount = m_aTable.GetColumnCount();
xChild = m_xImpl->m_pTable->getAccessibleChild(nCurrentRow * nCurrentCol + nColumnCount);
}
m_xImpl->m_pTable->commitEvent(_nEventId, makeAny(xChild),_rOldValue);
}
else if(_nEventId == AccessibleEventId::TABLE_MODEL_CHANGED)
{
AccessibleTableModelChange aChange;
if(_rNewValue >>= aChange)
{
if(aChange.Type == AccessibleTableModelChangeType::DELETE)
{
std::vector< AccessibleGridControlTableCell* >& rCells =
m_xImpl->m_pTable->getCellVector();
std::vector< css::uno::Reference< css::accessibility::XAccessible > >& rAccCells =
m_xImpl->m_pTable->getAccessibleCellVector();
int nColCount = m_aTable.GetColumnCount();
// check valid index - entries are inserted lazily
size_t const nStart = nColCount * aChange.FirstRow;
size_t const nEnd = nColCount * aChange.LastRow;
if (nStart < rCells.size())
{
m_xImpl->m_pTable->getCellVector().erase(
rCells.begin() + nStart,
rCells.begin() + std::min(rCells.size(), nEnd));
}
if (nStart < rAccCells.size())
{
m_xImpl->m_pTable->getAccessibleCellVector().erase(
rAccCells.begin() + nStart,
rAccCells.begin() + std::min(rAccCells.size(), nEnd));
}
m_xImpl->m_pTable->commitEvent(_nEventId,_rNewValue,_rOldValue);
}
else
m_xImpl->m_pTable->commitEvent(_nEventId,_rNewValue,_rOldValue);
}
}
else
m_xImpl->m_pTable->commitEvent(_nEventId,_rNewValue,_rOldValue);
}
}
// = AccessibleGridControlAccess
AccessibleGridControlAccess::AccessibleGridControlAccess(
const css::uno::Reference< css::accessibility::XAccessible >& rxParent, ::svt::table::IAccessibleTable& rTable )
: m_xParent( rxParent )
, m_pTable( & rTable )
, m_pContext( nullptr )
{
}
AccessibleGridControlAccess::~AccessibleGridControlAccess()
{
}
void AccessibleGridControlAccess::DisposeAccessImpl()
{
SolarMutexGuard g;
m_pTable = nullptr;
m_pContext = nullptr;
::comphelper::disposeComponent( m_xContext );
}
css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL AccessibleGridControlAccess::getAccessibleContext() throw ( RuntimeException, std::exception )
{
SolarMutexGuard g;
OSL_ENSURE( ( m_pContext && m_xContext.is() ) || ( !m_pContext && !m_xContext.is() ),
"extended/AccessibleGridControlAccess::getAccessibleContext: inconsistency!" );
// if the context died meanwhile (we're no listener, so it won't tell us explicitily when this happens),
// then reset an re-create.
if ( m_pContext && !m_pContext->isAlive() )
m_xContext = m_pContext = nullptr;
if (!m_xContext.is() && m_pTable)
m_xContext = m_pContext =
new AccessibleGridControl(m_xParent, this, *m_pTable);
return m_xContext;
}
bool AccessibleGridControlAccess::isContextAlive() const
{
return ( nullptr != m_pContext ) && m_pContext->isAlive();
}
} // namespace accessibility
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|