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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
|
/* -*- 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 <brwbox.hxx>
#include <AccessibleBrowseBoxObjType.hxx>
#include <tools/debug.hxx>
#include <tools/multisel.hxx>
#include "datwin.hxx"
#include "brwimpl.hxx"
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
#include <com/sun/star/accessibility/AccessibleRole.hpp>
#include <toolkit/helper/vclunohelper.hxx>
// Accessibility ==============================================================
using namespace ::com::sun::star::uno;
using ::com::sun::star::accessibility::XAccessible;
using namespace ::com::sun::star::accessibility;
// ============================================================================
namespace svt
{
using namespace ::com::sun::star::lang;
using namespace utl;
Reference< XAccessible > getHeaderCell( BrowseBoxImpl::THeaderCellMap& _raHeaderCells,
sal_Int32 _nPos,
AccessibleBrowseBoxObjType _eType,
const Reference< XAccessible >& _rParent,
BrowseBox& _rBrowseBox,
IAccessibleFactory& rFactory
)
{
Reference< XAccessible > xRet;
BrowseBoxImpl::THeaderCellMap::iterator aFind = _raHeaderCells.find( _nPos );
if ( aFind == _raHeaderCells.end() )
{
Reference< XAccessible > xAccessible = rFactory.createAccessibleBrowseBoxHeaderCell(
_nPos,
_rParent,
_rBrowseBox,
NULL,
_eType
);
aFind = _raHeaderCells.insert( BrowseBoxImpl::THeaderCellMap::value_type( _nPos, xAccessible ) ).first;
}
if ( aFind != _raHeaderCells.end() )
xRet = aFind->second;
return xRet;
}
// ============================================================================
// ----------------------------------------------------------------------------
Reference< XAccessible > BrowseBoxImpl::getAccessibleHeaderBar( AccessibleBrowseBoxObjType _eObjType )
{
if ( m_pAccessible && m_pAccessible->isAlive() )
return m_pAccessible->getHeaderBar( _eObjType );
return NULL;
}
// ----------------------------------------------------------------------------
Reference< XAccessible > BrowseBoxImpl::getAccessibleTable( )
{
if ( m_pAccessible && m_pAccessible->isAlive() )
return m_pAccessible->getTable( );
return NULL;
}
}
// ============================================================================
Reference< XAccessible > BrowseBox::CreateAccessible()
{
Window* pParent = GetAccessibleParentWindow();
DBG_ASSERT( pParent, "BrowseBox::CreateAccessible - parent not found" );
if( pParent && !m_pImpl->m_pAccessible)
{
Reference< XAccessible > xAccParent = pParent->GetAccessible();
if( xAccParent.is() )
{
m_pImpl->m_pAccessible = getAccessibleFactory().createAccessibleBrowseBox(
xAccParent, *this
);
}
}
Reference< XAccessible > xAccessible;
if ( m_pImpl->m_pAccessible )
xAccessible = m_pImpl->m_pAccessible->getMyself();
return xAccessible;
}
// -----------------------------------------------------------------------------
// Children -------------------------------------------------------------------
Reference< XAccessible > BrowseBox::CreateAccessibleCell( sal_Int32 _nRow, sal_uInt16 _nColumnPos )
{
// BBINDEX_TABLE must be the table
OSL_ENSURE(m_pImpl->m_pAccessible,"Invalid call: Accessible is null");
return m_pImpl->m_aFactoryAccess.getFactory().createAccessibleBrowseBoxTableCell(
m_pImpl->getAccessibleTable(),
*this,
NULL,
_nRow,
_nColumnPos,
OFFSET_DEFAULT
);
}
// -----------------------------------------------------------------------------
Reference< XAccessible > BrowseBox::CreateAccessibleRowHeader( sal_Int32 _nRow )
{
return svt::getHeaderCell(
m_pImpl->m_aRowHeaderCellMap,
_nRow,
svt::BBTYPE_ROWHEADERCELL,
m_pImpl->getAccessibleHeaderBar(svt::BBTYPE_ROWHEADERBAR),
*this,
m_pImpl->m_aFactoryAccess.getFactory()
);
}
// -----------------------------------------------------------------------------
Reference< XAccessible > BrowseBox::CreateAccessibleColumnHeader( sal_uInt16 _nColumnPos )
{
return svt::getHeaderCell(
m_pImpl->m_aColHeaderCellMap,
_nColumnPos,
svt::BBTYPE_COLUMNHEADERCELL,
m_pImpl->getAccessibleHeaderBar(svt::BBTYPE_COLUMNHEADERBAR),
*this,
m_pImpl->m_aFactoryAccess.getFactory()
);
}
// -----------------------------------------------------------------------------
sal_Int32 BrowseBox::GetAccessibleControlCount() const
{
return 0;
}
// -----------------------------------------------------------------------------
Reference< XAccessible > BrowseBox::CreateAccessibleControl( sal_Int32 )
{
DBG_ASSERT( sal_False, "BrowseBox::CreateAccessibleControl: to be overwritten!" );
return NULL;
}
// -----------------------------------------------------------------------------
// Conversions ----------------------------------------------------------------
sal_Bool BrowseBox::ConvertPointToCellAddress(
sal_Int32& rnRow, sal_uInt16& rnColumnPos, const Point& rPoint )
{
//! TODO has to be checked
rnRow = GetRowAtYPosPixel(rPoint.Y());
rnColumnPos = GetColumnAtXPosPixel(rPoint.X());
return rnRow != BROWSER_INVALIDID && rnColumnPos != BROWSER_INVALIDID;
}
// -----------------------------------------------------------------------------
sal_Bool BrowseBox::ConvertPointToRowHeader( sal_Int32& rnRow, const Point& rPoint )
{
rnRow = GetRowAtYPosPixel(rPoint.Y());
// sal_uInt16 nColumnId = GetColumnAtXPosPixel(rPoint.X());
return rnRow != BROWSER_INVALIDID;// && nColumnId == 0;
}
// -----------------------------------------------------------------------------
sal_Bool BrowseBox::ConvertPointToColumnHeader( sal_uInt16& _rnColumnPos, const Point& _rPoint )
{
_rnColumnPos = GetColumnAtXPosPixel(_rPoint.X());
return _rnColumnPos != BROWSER_INVALIDID;
}
// -----------------------------------------------------------------------------
sal_Bool BrowseBox::ConvertPointToControlIndex( sal_Int32& _rnIndex, const Point& _rPoint )
{
//! TODO has to be checked
sal_Int32 nRow = 0;
sal_uInt16 nColumn = 0;
sal_Bool bRet = ConvertPointToCellAddress(nRow,nColumn,_rPoint);
if ( bRet )
_rnIndex = nRow * ColCount() + nColumn;
return bRet;
}
// -----------------------------------------------------------------------------
// Object data and state ------------------------------------------------------
OUString BrowseBox::GetAccessibleObjectName( ::svt::AccessibleBrowseBoxObjType eObjType,sal_Int32 ) const
{
OUString aRetText;
switch( eObjType )
{
case ::svt::BBTYPE_BROWSEBOX:
aRetText = OUString( "BrowseBox" );
break;
case ::svt::BBTYPE_TABLE:
aRetText = OUString( "Table" );
break;
case ::svt::BBTYPE_ROWHEADERBAR:
aRetText = OUString( "RowHeaderBar" );
break;
case ::svt::BBTYPE_COLUMNHEADERBAR:
aRetText = OUString( "ColumnHeaderBar" );
break;
case ::svt::BBTYPE_TABLECELL:
aRetText = OUString( "TableCell" );
#if OSL_DEBUG_LEVEL > 1
aRetText += " [";
aRetText += OUString::valueOf(sal_Int32(GetCurRow()));
aRetText += ",";
aRetText += OUString::valueOf(sal_Int32(GetCurColumnId()));
aRetText += "]";
#endif
break;
case ::svt::BBTYPE_ROWHEADERCELL:
aRetText = OUString( "RowHeaderCell" );
#if OSL_DEBUG_LEVEL > 1
aRetText += " [";
aRetText += OUString::valueOf(sal_Int32(GetCurRow()));
aRetText += ",";
aRetText += OUString::valueOf(sal_Int32(GetCurColumnId()));
aRetText += "]";
#endif
break;
case ::svt::BBTYPE_COLUMNHEADERCELL:
aRetText = OUString( "ColumnHeaderCell" );
#if OSL_DEBUG_LEVEL > 1
aRetText += " [";
aRetText += OUString::valueOf(sal_Int32(GetCurRow()));
aRetText += ",";
aRetText += OUString::valueOf(sal_Int32(GetCurColumnId()));
aRetText += "]";
#endif
break;
default:
OSL_FAIL("BrowseBox::GetAccessibleName: invalid enum!");
}
return aRetText;
}
// -----------------------------------------------------------------------------
OUString BrowseBox::GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType eObjType,sal_Int32 ) const
{
OUString aRetText;
switch( eObjType )
{
case ::svt::BBTYPE_BROWSEBOX:
aRetText = OUString( "BrowseBox description" );
break;
case ::svt::BBTYPE_TABLE:
// aRetText = OUString( "TABLE description" );
break;
case ::svt::BBTYPE_ROWHEADERBAR:
// aRetText = OUString( "ROWHEADERBAR description" );
break;
case ::svt::BBTYPE_COLUMNHEADERBAR:
// aRetText = OUString( "COLUMNHEADERBAR description" );
break;
case ::svt::BBTYPE_TABLECELL:
// aRetText = OUString( "TABLECELL description" );
break;
case ::svt::BBTYPE_ROWHEADERCELL:
// aRetText = OUString( "ROWHEADERCELL description" );
break;
case ::svt::BBTYPE_COLUMNHEADERCELL:
// aRetText = OUString( "COLUMNHEADERCELL description" );
break;
case ::svt::BBTYPE_CHECKBOXCELL:
break;
}
return aRetText;
}
// -----------------------------------------------------------------------------
OUString BrowseBox::GetRowDescription( sal_Int32 ) const
{
return OUString();
}
// -----------------------------------------------------------------------------
OUString BrowseBox::GetColumnDescription( sal_uInt16 _nColumn ) const
{
return OUString( GetColumnTitle( GetColumnId( _nColumn ) ) );
}
// -----------------------------------------------------------------------------
void BrowseBox::FillAccessibleStateSet(
::utl::AccessibleStateSetHelper& rStateSet,
::svt::AccessibleBrowseBoxObjType eObjType ) const
{
switch( eObjType )
{
case ::svt::BBTYPE_BROWSEBOX:
case ::svt::BBTYPE_TABLE:
rStateSet.AddState( AccessibleStateType::FOCUSABLE );
if ( HasFocus() )
rStateSet.AddState( AccessibleStateType::FOCUSED );
if ( IsActive() )
rStateSet.AddState( AccessibleStateType::ACTIVE );
if ( GetUpdateMode() )
rStateSet.AddState( AccessibleStateType::EDITABLE );
if ( IsEnabled() )
{
rStateSet.AddState( AccessibleStateType::ENABLED );
rStateSet.AddState( AccessibleStateType::SENSITIVE );
}
if ( IsReallyVisible() )
rStateSet.AddState( AccessibleStateType::VISIBLE );
if ( eObjType == ::svt::BBTYPE_TABLE )
rStateSet.AddState( AccessibleStateType::MANAGES_DESCENDANTS );
break;
case ::svt::BBTYPE_ROWHEADERBAR:
rStateSet.AddState( AccessibleStateType::FOCUSABLE );
rStateSet.AddState( AccessibleStateType::VISIBLE );
if ( GetSelectRowCount() )
rStateSet.AddState( AccessibleStateType::FOCUSED );
rStateSet.AddState( AccessibleStateType::MANAGES_DESCENDANTS );
break;
case ::svt::BBTYPE_COLUMNHEADERBAR:
rStateSet.AddState( AccessibleStateType::FOCUSABLE );
rStateSet.AddState( AccessibleStateType::VISIBLE );
if ( GetSelectColumnCount() )
rStateSet.AddState( AccessibleStateType::FOCUSED );
rStateSet.AddState( AccessibleStateType::MANAGES_DESCENDANTS );
break;
case ::svt::BBTYPE_TABLECELL:
{
sal_Int32 nRow = GetCurRow();
sal_uInt16 nColumn = GetCurColumnId();
if ( IsFieldVisible(nRow,nColumn) )
rStateSet.AddState( AccessibleStateType::VISIBLE );
if ( !IsFrozen( nColumn ) )
rStateSet.AddState( AccessibleStateType::FOCUSABLE );
rStateSet.AddState( AccessibleStateType::TRANSIENT );
}
break;
case ::svt::BBTYPE_ROWHEADERCELL:
case ::svt::BBTYPE_COLUMNHEADERCELL:
case ::svt::BBTYPE_CHECKBOXCELL:
OSL_FAIL("Illegal call here!");
break;
}
}
// -----------------------------------------------------------------------
void BrowseBox::FillAccessibleStateSetForCell( ::utl::AccessibleStateSetHelper& _rStateSet,
sal_Int32 _nRow, sal_uInt16 _nColumnPos ) const
{
//! TODO check if the state is valid for table cells
if ( IsCellVisible( _nRow, _nColumnPos ) )
_rStateSet.AddState( AccessibleStateType::VISIBLE );
if ( GetCurrRow() == _nRow && GetCurrColumn() == _nColumnPos )
_rStateSet.AddState( AccessibleStateType::FOCUSED );
else // only transient when column is not focused
_rStateSet.AddState( AccessibleStateType::TRANSIENT );
}
// -----------------------------------------------------------------------------
void BrowseBox::GrabTableFocus()
{
GrabFocus();
}
// -----------------------------------------------------------------------------
OUString BrowseBox::GetCellText(long, sal_uInt16 ) const
{
DBG_ASSERT(0,"This method has to be implemented by the derived classes! BUG!!");
return OUString();
}
// -----------------------------------------------------------------------------
void BrowseBox::commitHeaderBarEvent(sal_Int16 nEventId,
const Any& rNewValue, const Any& rOldValue, sal_Bool _bColumnHeaderBar )
{
if ( isAccessibleAlive() )
m_pImpl->m_pAccessible->commitHeaderBarEvent( nEventId,
rNewValue, rOldValue, _bColumnHeaderBar );
}
// -----------------------------------------------------------------------------
void BrowseBox::commitTableEvent( sal_Int16 _nEventId, const Any& _rNewValue, const Any& _rOldValue )
{
if ( isAccessibleAlive() )
m_pImpl->m_pAccessible->commitTableEvent( _nEventId, _rNewValue, _rOldValue );
}
// -----------------------------------------------------------------------------
void BrowseBox::commitBrowseBoxEvent( sal_Int16 _nEventId, const Any& _rNewValue, const Any& _rOldValue )
{
if ( isAccessibleAlive() )
m_pImpl->m_pAccessible->commitEvent( _nEventId, _rNewValue, _rOldValue);
}
// -----------------------------------------------------------------------------
::svt::IAccessibleFactory& BrowseBox::getAccessibleFactory()
{
return m_pImpl->m_aFactoryAccess.getFactory();
}
// -----------------------------------------------------------------------------
sal_Bool BrowseBox::isAccessibleAlive( ) const
{
return ( NULL != m_pImpl->m_pAccessible ) && m_pImpl->m_pAccessible->isAlive();
}
// -----------------------------------------------------------------------------
// IAccessibleTableProvider
// -----------------------------------------------------------------------------
sal_Int32 BrowseBox::GetCurrRow() const
{
return GetCurRow();
}
// -----------------------------------------------------------------------------
sal_uInt16 BrowseBox::GetCurrColumn() const
{
return GetColumnPos( GetCurColumnId() );
}
// -----------------------------------------------------------------------------
sal_Bool BrowseBox::HasRowHeader() const
{
return ( GetColumnId( 0 ) == HandleColumnId ); // HandleColumn == RowHeader
}
// -----------------------------------------------------------------------------
sal_Bool BrowseBox::IsCellFocusable() const
{
return sal_True;
}
// -----------------------------------------------------------------------------
sal_Bool BrowseBox::GoToCell( sal_Int32 _nRow, sal_uInt16 _nColumn )
{
return GoToRowColumnId( _nRow, GetColumnId( _nColumn ) );
}
// -----------------------------------------------------------------------------
void BrowseBox::SelectColumn( sal_uInt16 _nColumn, sal_Bool _bSelect )
{
SelectColumnPos( _nColumn, _bSelect );
}
// -----------------------------------------------------------------------------
sal_Bool BrowseBox::IsColumnSelected( long _nColumn ) const
{
return ( pColSel && (0 <= _nColumn) && (_nColumn <= 0xFFF) ) ?
pColSel->IsSelected( static_cast< sal_uInt16 >( _nColumn ) ) :
sal_False;
}
// -----------------------------------------------------------------------------
sal_Int32 BrowseBox::GetSelectedRowCount() const
{
return GetSelectRowCount();
}
// -----------------------------------------------------------------------------
sal_Int32 BrowseBox::GetSelectedColumnCount() const
{
const MultiSelection* pColumnSel = GetColumnSelection();
return pColumnSel ? pColumnSel->GetSelectCount() : 0;
}
// -----------------------------------------------------------------------------
void BrowseBox::GetAllSelectedRows( ::com::sun::star::uno::Sequence< sal_Int32 >& _rRows ) const
{
sal_Int32 nCount = GetSelectRowCount();
if( nCount )
{
_rRows.realloc( nCount );
_rRows[ 0 ] = const_cast< BrowseBox* >( this )->FirstSelectedRow();
for( sal_Int32 nIndex = 1; nIndex < nCount; ++nIndex )
_rRows[ nIndex ] = const_cast< BrowseBox* >( this )->NextSelectedRow();
DBG_ASSERT( const_cast< BrowseBox* >( this )->NextSelectedRow() == BROWSER_ENDOFSELECTION,
"BrowseBox::GetAllSelectedRows - too many selected rows found" );
}
}
// -----------------------------------------------------------------------------
void BrowseBox::GetAllSelectedColumns( ::com::sun::star::uno::Sequence< sal_Int32 >& _rColumns ) const
{
const MultiSelection* pColumnSel = GetColumnSelection();
sal_Int32 nCount = GetSelectedColumnCount();
if( pColumnSel && nCount )
{
_rColumns.realloc( nCount );
sal_Int32 nIndex = 0;
sal_uInt32 nRangeCount = pColumnSel->GetRangeCount();
for( sal_uInt32 nRange = 0; nRange < nRangeCount; ++nRange )
{
const Range& rRange = pColumnSel->GetRange( nRange );
// loop has to include aRange.Max()
for( sal_Int32 nCol = rRange.Min(); nCol <= rRange.Max(); ++nCol )
{
DBG_ASSERT( nIndex < nCount,
"GetAllSelectedColumns - range overflow" );
_rColumns[ nIndex ] = nCol;
++nIndex;
}
}
}
}
// -----------------------------------------------------------------------------
sal_Bool BrowseBox::IsCellVisible( sal_Int32 _nRow, sal_uInt16 _nColumnPos ) const
{
return IsFieldVisible( _nRow, GetColumnId( _nColumnPos ) );
}
// -----------------------------------------------------------------------------
OUString BrowseBox::GetAccessibleCellText(long _nRow, sal_uInt16 _nColPos) const
{
return GetCellText( _nRow, GetColumnId( _nColPos ) );
}
// -----------------------------------------------------------------------------
sal_Bool BrowseBox::GetGlyphBoundRects( const Point& rOrigin, const String& rStr, int nIndex, int nLen, int nBase, MetricVector& rVector )
{
return Control::GetGlyphBoundRects( rOrigin, rStr, nIndex, nLen, nBase, rVector );
}
// -----------------------------------------------------------------------------
Rectangle BrowseBox::GetWindowExtentsRelative( Window *pRelativeWindow ) const
{
return Control::GetWindowExtentsRelative( pRelativeWindow );
}
// -----------------------------------------------------------------------------
void BrowseBox::GrabFocus()
{
Control::GrabFocus();
}
// -----------------------------------------------------------------------------
Reference< XAccessible > BrowseBox::GetAccessible( sal_Bool bCreate )
{
return Control::GetAccessible( bCreate );
}
// -----------------------------------------------------------------------------
Window* BrowseBox::GetAccessibleParentWindow() const
{
return Control::GetAccessibleParentWindow();
}
// -----------------------------------------------------------------------------
Window* BrowseBox::GetWindowInstance()
{
return this;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|