1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <osl/diagnose.h>
21 #include <svtools/brwbox.hxx>
22 #include <vcl/AccessibleBrowseBoxObjType.hxx>
23 #include <vcl/accessiblefactory.hxx>
24 #include <sal/log.hxx>
25 #include <tools/debug.hxx>
26 #include <tools/multisel.hxx>
27 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
29 // Accessibility ==============================================================
31 using namespace ::com::sun::star::uno
;
32 using ::com::sun::star::accessibility::XAccessible
;
33 using namespace ::com::sun::star::accessibility
;
38 static Reference
< XAccessible
> getHeaderCell(BrowseBox::THeaderCellMap
& _raHeaderCells
,
40 AccessibleBrowseBoxObjType _eType
,
41 const Reference
< XAccessible
>& _rParent
,
42 BrowseBox
& _rBrowseBox
,
43 vcl::IAccessibleFactory
const & rFactory
46 Reference
< XAccessible
> xRet
;
47 BrowseBox::THeaderCellMap::iterator aFind
= _raHeaderCells
.find(_nPos
);
48 if ( aFind
== _raHeaderCells
.end() )
50 Reference
< XAccessible
> xAccessible
= rFactory
.createAccessibleBrowseBoxHeaderCell(
56 aFind
= _raHeaderCells
.emplace( _nPos
, xAccessible
).first
;
58 if ( aFind
!= _raHeaderCells
.end() )
64 Reference
<XAccessible
> BrowseBox::getAccessibleHeaderBar(AccessibleBrowseBoxObjType _eObjType
)
66 if (m_pAccessible
&& m_pAccessible
->isAlive())
67 return m_pAccessible
->getHeaderBar(_eObjType
);
71 Reference
<XAccessible
> BrowseBox::getAccessibleTable()
73 if (m_pAccessible
&& m_pAccessible
->isAlive())
74 return m_pAccessible
->getTable();
78 Reference
< XAccessible
> BrowseBox::CreateAccessible()
80 vcl::Window
* pParent
= GetAccessibleParentWindow();
81 DBG_ASSERT( pParent
, "BrowseBox::CreateAccessible - parent not found" );
83 if (pParent
&& !m_pAccessible
)
85 Reference
< XAccessible
> xAccParent
= pParent
->GetAccessible();
88 m_pAccessible
= getAccessibleFactory().createAccessibleBrowseBox(
98 // Children -------------------------------------------------------------------
100 Reference
< XAccessible
> BrowseBox::CreateAccessibleCell( sal_Int32 _nRow
, sal_uInt16 _nColumnPos
)
102 // BBINDEX_TABLE must be the table
103 OSL_ENSURE(m_pAccessible
,"Invalid call: Accessible is null");
105 return m_aFactoryAccess
.getFactory().createAccessibleBrowseBoxTableCell(
106 getAccessibleTable(),
115 Reference
< XAccessible
> BrowseBox::CreateAccessibleRowHeader( sal_Int32 _nRow
)
117 return svt::getHeaderCell(
120 AccessibleBrowseBoxObjType::RowHeaderCell
,
121 getAccessibleHeaderBar(AccessibleBrowseBoxObjType::RowHeaderBar
),
123 m_aFactoryAccess
.getFactory()
128 Reference
< XAccessible
> BrowseBox::CreateAccessibleColumnHeader( sal_uInt16 _nColumnPos
)
130 return svt::getHeaderCell(
133 AccessibleBrowseBoxObjType::ColumnHeaderCell
,
134 getAccessibleHeaderBar(AccessibleBrowseBoxObjType::ColumnHeaderBar
),
136 m_aFactoryAccess
.getFactory()
141 sal_Int32
BrowseBox::GetAccessibleControlCount() const
147 Reference
< XAccessible
> BrowseBox::CreateAccessibleControl( sal_Int32
)
149 SAL_WARN( "svtools", "BrowseBox::CreateAccessibleControl: to be overwritten!" );
154 // Conversions ----------------------------------------------------------------
156 bool BrowseBox::ConvertPointToCellAddress(
157 sal_Int32
& rnRow
, sal_uInt16
& rnColumnPos
, const Point
& rPoint
)
159 //! TODO has to be checked
160 rnRow
= GetRowAtYPosPixel(rPoint
.Y());
161 rnColumnPos
= GetColumnAtXPosPixel(rPoint
.X());
162 return rnRow
!= BROWSER_INVALIDID
&& rnColumnPos
!= BROWSER_INVALIDID
;
166 bool BrowseBox::ConvertPointToRowHeader( sal_Int32
& rnRow
, const Point
& rPoint
)
168 rnRow
= GetRowAtYPosPixel(rPoint
.Y());
169 // sal_uInt16 nColumnId = GetColumnAtXPosPixel(rPoint.X());
170 return rnRow
!= BROWSER_INVALIDID
;// && nColumnId == 0;
174 bool BrowseBox::ConvertPointToColumnHeader( sal_uInt16
& _rnColumnPos
, const Point
& _rPoint
)
176 _rnColumnPos
= GetColumnAtXPosPixel(_rPoint
.X());
177 return _rnColumnPos
!= BROWSER_INVALIDID
;
181 bool BrowseBox::ConvertPointToControlIndex( sal_Int32
& _rnIndex
, const Point
& _rPoint
)
183 //! TODO has to be checked
185 sal_uInt16 nColumn
= 0;
186 bool bRet
= ConvertPointToCellAddress(nRow
,nColumn
,_rPoint
);
188 _rnIndex
= nRow
* ColCount() + nColumn
;
194 // Object data and state ------------------------------------------------------
196 OUString
BrowseBox::GetAccessibleObjectName( AccessibleBrowseBoxObjType eObjType
,sal_Int32 _nPosition
) const
201 case AccessibleBrowseBoxObjType::BrowseBox
:
202 aRetText
= "BrowseBox";
204 case AccessibleBrowseBoxObjType::Table
:
207 case AccessibleBrowseBoxObjType::RowHeaderBar
:
208 aRetText
= "RowHeaderBar";
210 case AccessibleBrowseBoxObjType::ColumnHeaderBar
:
211 aRetText
= "ColumnHeaderBar";
213 case AccessibleBrowseBoxObjType::TableCell
:
214 if( ColCount() !=0 && GetRowCount()!=0)
217 sal_Int32 columnId
= _nPosition
% ColCount() +1;
218 aRetText
= GetColumnDescription( sal_Int16( columnId
) );
219 sal_Int32 rowId
= _nPosition
/ GetRowCount() + 1;
220 aRetText
+= OUString::number(rowId
);
223 aRetText
= "TableCell";
224 #if OSL_DEBUG_LEVEL > 0
226 + OUString::number(GetCurRow())
228 + OUString::number(sal_Int32(GetCurColumnId()))
232 case AccessibleBrowseBoxObjType::RowHeaderCell
:
234 sal_Int32 rowId
= _nPosition
+ 1;
235 aRetText
= OUString::number( rowId
);
237 #if OSL_DEBUG_LEVEL > 0
239 + OUString::number(GetCurRow())
241 + OUString::number(sal_Int32(GetCurColumnId()))
245 case AccessibleBrowseBoxObjType::ColumnHeaderCell
:
246 aRetText
= GetColumnDescription( sal_Int16( _nPosition
) );
247 #if OSL_DEBUG_LEVEL > 0
249 + OUString::number(GetCurRow())
251 + OUString::number(sal_Int32(GetCurColumnId()))
256 OSL_FAIL("BrowseBox::GetAccessibleName: invalid enum!");
262 OUString
BrowseBox::GetAccessibleObjectDescription( AccessibleBrowseBoxObjType eObjType
,sal_Int32
) const
267 case AccessibleBrowseBoxObjType::BrowseBox
:
268 aRetText
= "BrowseBox description";
270 case AccessibleBrowseBoxObjType::Table
:
271 // aRetText = "TABLE description";
273 case AccessibleBrowseBoxObjType::RowHeaderBar
:
274 // aRetText = "ROWHEADERBAR description";
276 case AccessibleBrowseBoxObjType::ColumnHeaderBar
:
277 // aRetText = "COLUMNHEADERBAR description";
279 case AccessibleBrowseBoxObjType::TableCell
:
280 // aRetText = "TABLECELL description";
282 case AccessibleBrowseBoxObjType::RowHeaderCell
:
283 // aRetText = "ROWHEADERCELL description";
285 case AccessibleBrowseBoxObjType::ColumnHeaderCell
:
286 // aRetText = "COLUMNHEADERCELL description";
288 case AccessibleBrowseBoxObjType::CheckBoxCell
:
295 OUString
BrowseBox::GetRowDescription( sal_Int32
) const
301 OUString
BrowseBox::GetColumnDescription( sal_uInt16 _nColumn
) const
303 return GetColumnTitle( GetColumnId( _nColumn
) );
307 void BrowseBox::FillAccessibleStateSet(
308 sal_Int64
& rStateSet
,
309 AccessibleBrowseBoxObjType eObjType
) const
313 case AccessibleBrowseBoxObjType::BrowseBox
:
314 case AccessibleBrowseBoxObjType::Table
:
316 rStateSet
|= AccessibleStateType::FOCUSABLE
;
318 rStateSet
|= AccessibleStateType::FOCUSED
;
320 rStateSet
|= AccessibleStateType::ACTIVE
;
321 if ( GetUpdateMode() )
322 rStateSet
|= AccessibleStateType::EDITABLE
;
325 rStateSet
|= AccessibleStateType::ENABLED
;
326 rStateSet
|= AccessibleStateType::SENSITIVE
;
328 if ( IsReallyVisible() )
329 rStateSet
|= AccessibleStateType::VISIBLE
;
330 if ( eObjType
== AccessibleBrowseBoxObjType::Table
)
331 rStateSet
|= AccessibleStateType::MANAGES_DESCENDANTS
;
334 case AccessibleBrowseBoxObjType::RowHeaderBar
:
335 rStateSet
|= AccessibleStateType::FOCUSABLE
;
336 rStateSet
|= AccessibleStateType::VISIBLE
;
337 if ( GetSelectRowCount() )
338 rStateSet
|= AccessibleStateType::FOCUSED
;
339 rStateSet
|= AccessibleStateType::MANAGES_DESCENDANTS
;
341 case AccessibleBrowseBoxObjType::ColumnHeaderBar
:
342 rStateSet
|= AccessibleStateType::FOCUSABLE
;
343 rStateSet
|= AccessibleStateType::VISIBLE
;
344 if ( GetSelectColumnCount() )
345 rStateSet
|= AccessibleStateType::FOCUSED
;
346 rStateSet
|= AccessibleStateType::MANAGES_DESCENDANTS
;
348 case AccessibleBrowseBoxObjType::TableCell
:
350 sal_Int32 nRow
= GetCurRow();
351 sal_uInt16 nColumn
= GetCurColumnId();
352 if ( IsFieldVisible(nRow
,nColumn
) )
353 rStateSet
|= AccessibleStateType::VISIBLE
;
354 if ( !IsFrozen( nColumn
) )
355 rStateSet
|= AccessibleStateType::FOCUSABLE
;
356 rStateSet
|= AccessibleStateType::TRANSIENT
;
359 case AccessibleBrowseBoxObjType::RowHeaderCell
:
360 case AccessibleBrowseBoxObjType::ColumnHeaderCell
:
361 case AccessibleBrowseBoxObjType::CheckBoxCell
:
362 OSL_FAIL("Illegal call here!");
367 void BrowseBox::FillAccessibleStateSetForCell( sal_Int64
& _rStateSet
,
368 sal_Int32 _nRow
, sal_uInt16 _nColumnPos
) const
370 //! TODO check if the state is valid for table cells
371 if ( IsCellVisible( _nRow
, _nColumnPos
) )
372 _rStateSet
|= AccessibleStateType::VISIBLE
;
373 if ( GetCurrRow() == _nRow
&& GetCurrColumn() == _nColumnPos
)
374 _rStateSet
|= AccessibleStateType::FOCUSED
;
375 else // only transient when column is not focused
376 _rStateSet
|= AccessibleStateType::TRANSIENT
;
380 void BrowseBox::GrabTableFocus()
385 OUString
BrowseBox::GetCellText(sal_Int32
, sal_uInt16
) const
387 SAL_WARN("svtools", "This method has to be implemented by the derived classes! BUG!!");
392 void BrowseBox::commitHeaderBarEvent(sal_Int16 nEventId
,
393 const Any
& rNewValue
, const Any
& rOldValue
, bool _bColumnHeaderBar
)
395 if ( isAccessibleAlive() )
396 m_pAccessible
->commitHeaderBarEvent( nEventId
,
397 rNewValue
, rOldValue
, _bColumnHeaderBar
);
400 void BrowseBox::commitTableEvent( sal_Int16 _nEventId
, const Any
& _rNewValue
, const Any
& _rOldValue
)
402 if ( isAccessibleAlive() )
403 m_pAccessible
->commitTableEvent(_nEventId
, _rNewValue
, _rOldValue
);
406 void BrowseBox::commitBrowseBoxEvent( sal_Int16 _nEventId
, const Any
& _rNewValue
, const Any
& _rOldValue
)
408 if ( isAccessibleAlive() )
409 m_pAccessible
->commitEvent( _nEventId
, _rNewValue
, _rOldValue
);
412 ::vcl::IAccessibleFactory
& BrowseBox::getAccessibleFactory()
414 return m_aFactoryAccess
.getFactory();
417 bool BrowseBox::isAccessibleAlive( ) const
419 return m_pAccessible
&& m_pAccessible
->isAlive();
422 // IAccessibleTableProvider
424 sal_Int32
BrowseBox::GetCurrRow() const
429 sal_uInt16
BrowseBox::GetCurrColumn() const
431 return GetColumnPos( GetCurColumnId() );
434 bool BrowseBox::HasRowHeader() const
436 return ( GetColumnId( 0 ) == HandleColumnId
); // HandleColumn == RowHeader
439 bool BrowseBox::GoToCell( sal_Int32 _nRow
, sal_uInt16 _nColumn
)
441 return GoToRowColumnId( _nRow
, GetColumnId( _nColumn
) );
444 void BrowseBox::SelectColumn( sal_uInt16 _nColumn
, bool _bSelect
)
446 SelectColumnPos( _nColumn
, _bSelect
);
449 bool BrowseBox::IsColumnSelected( sal_Int32 _nColumn
) const
451 return ( pColSel
&& (0 <= _nColumn
) && (_nColumn
<= 0xFFF) ) &&
452 pColSel
->IsSelected( static_cast< sal_uInt16
>( _nColumn
) );
455 sal_Int32
BrowseBox::GetSelectedRowCount() const
457 return GetSelectRowCount();
460 sal_Int32
BrowseBox::GetSelectedColumnCount() const
462 const MultiSelection
* pColumnSel
= GetColumnSelection();
463 return pColumnSel
? pColumnSel
->GetSelectCount() : 0;
466 void BrowseBox::GetAllSelectedRows( css::uno::Sequence
< sal_Int32
>& _rRows
) const
468 sal_Int32 nCount
= GetSelectRowCount();
471 _rRows
.realloc( nCount
);
472 auto pRows
= _rRows
.getArray();
473 pRows
[ 0 ] = const_cast< BrowseBox
* >( this )->FirstSelectedRow();
474 for( sal_Int32 nIndex
= 1; nIndex
< nCount
; ++nIndex
)
475 pRows
[ nIndex
] = const_cast< BrowseBox
* >( this )->NextSelectedRow();
476 DBG_ASSERT( const_cast< BrowseBox
* >( this )->NextSelectedRow() == BROWSER_ENDOFSELECTION
,
477 "BrowseBox::GetAllSelectedRows - too many selected rows found" );
481 void BrowseBox::GetAllSelectedColumns( css::uno::Sequence
< sal_Int32
>& _rColumns
) const
483 const MultiSelection
* pColumnSel
= GetColumnSelection();
484 sal_Int32 nCount
= GetSelectedColumnCount();
485 if( !(pColumnSel
&& nCount
) )
488 _rColumns
.realloc( nCount
);
489 auto pColumns
= _rColumns
.getArray();
491 sal_Int32 nIndex
= 0;
492 const size_t nRangeCount
= pColumnSel
->GetRangeCount();
493 for( size_t nRange
= 0; nRange
< nRangeCount
; ++nRange
)
495 const Range
& rRange
= pColumnSel
->GetRange( nRange
);
496 // loop has to include aRange.Max()
497 for( sal_Int32 nCol
= rRange
.Min(); nCol
<= static_cast<sal_Int32
>(rRange
.Max()); ++nCol
)
499 DBG_ASSERT( nIndex
< nCount
,
500 "GetAllSelectedColumns - range overflow" );
501 pColumns
[ nIndex
] = nCol
;
507 bool BrowseBox::IsCellVisible( sal_Int32 _nRow
, sal_uInt16 _nColumnPos
) const
509 return IsFieldVisible( _nRow
, GetColumnId( _nColumnPos
) );
512 OUString
BrowseBox::GetAccessibleCellText(sal_Int32 _nRow
, sal_uInt16 _nColPos
) const
514 return GetCellText( _nRow
, GetColumnId( _nColPos
) );
518 bool BrowseBox::GetGlyphBoundRects( const Point
& rOrigin
, const OUString
& rStr
, int nIndex
, int nLen
, std::vector
< tools::Rectangle
>& rVector
)
520 return GetOutDev()->GetGlyphBoundRects( rOrigin
, rStr
, nIndex
, nLen
, rVector
);
523 AbsoluteScreenPixelRectangle
BrowseBox::GetWindowExtentsAbsolute() const
525 return Control::GetWindowExtentsAbsolute();
528 tools::Rectangle
BrowseBox::GetWindowExtentsRelative(const vcl::Window
& rRelativeWindow
) const
530 return Control::GetWindowExtentsRelative( rRelativeWindow
);
533 void BrowseBox::GrabFocus()
535 Control::GrabFocus();
538 Reference
< XAccessible
> BrowseBox::GetAccessible()
540 return Control::GetAccessible();
543 vcl::Window
* BrowseBox::GetAccessibleParentWindow() const
545 return Control::GetAccessibleParentWindow();
548 vcl::Window
* BrowseBox::GetWindowInstance()
553 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */