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 <svtools/brwbox.hxx>
21 #include <svtools/AccessibleBrowseBoxObjType.hxx>
22 #include <tools/debug.hxx>
23 #include <tools/multisel.hxx>
25 #include "brwimpl.hxx"
26 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
27 #include <com/sun/star/accessibility/AccessibleRole.hpp>
28 #include <toolkit/helper/vclunohelper.hxx>
30 // Accessibility ==============================================================
32 using namespace ::com::sun::star::uno
;
33 using ::com::sun::star::accessibility::XAccessible
;
34 using namespace ::com::sun::star::accessibility
;
39 using namespace ::com::sun::star::lang
;
42 Reference
< XAccessible
> getHeaderCell( BrowseBoxImpl::THeaderCellMap
& _raHeaderCells
,
44 AccessibleBrowseBoxObjType _eType
,
45 const Reference
< XAccessible
>& _rParent
,
46 BrowseBox
& _rBrowseBox
,
47 IAccessibleFactory
& rFactory
50 Reference
< XAccessible
> xRet
;
51 BrowseBoxImpl::THeaderCellMap::iterator aFind
= _raHeaderCells
.find( _nPos
);
52 if ( aFind
== _raHeaderCells
.end() )
54 Reference
< XAccessible
> xAccessible
= rFactory
.createAccessibleBrowseBoxHeaderCell(
61 aFind
= _raHeaderCells
.insert( BrowseBoxImpl::THeaderCellMap::value_type( _nPos
, xAccessible
) ).first
;
63 if ( aFind
!= _raHeaderCells
.end() )
70 Reference
< XAccessible
> BrowseBoxImpl::getAccessibleHeaderBar( AccessibleBrowseBoxObjType _eObjType
)
72 if ( m_pAccessible
&& m_pAccessible
->isAlive() )
73 return m_pAccessible
->getHeaderBar( _eObjType
);
78 Reference
< XAccessible
> BrowseBoxImpl::getAccessibleTable( )
80 if ( m_pAccessible
&& m_pAccessible
->isAlive() )
81 return m_pAccessible
->getTable( );
88 Reference
< XAccessible
> BrowseBox::CreateAccessible()
90 vcl::Window
* pParent
= GetAccessibleParentWindow();
91 DBG_ASSERT( pParent
, "BrowseBox::CreateAccessible - parent not found" );
93 if( pParent
&& !m_pImpl
->m_pAccessible
)
95 Reference
< XAccessible
> xAccParent
= pParent
->GetAccessible();
98 m_pImpl
->m_pAccessible
= getAccessibleFactory().createAccessibleBrowseBox(
104 Reference
< XAccessible
> xAccessible
;
105 if ( m_pImpl
->m_pAccessible
)
106 xAccessible
= m_pImpl
->m_pAccessible
->getMyself();
112 // Children -------------------------------------------------------------------
114 Reference
< XAccessible
> BrowseBox::CreateAccessibleCell( sal_Int32 _nRow
, sal_uInt16 _nColumnPos
)
116 // BBINDEX_TABLE must be the table
117 OSL_ENSURE(m_pImpl
->m_pAccessible
,"Invalid call: Accessible is null");
119 return m_pImpl
->m_aFactoryAccess
.getFactory().createAccessibleBrowseBoxTableCell(
120 m_pImpl
->getAccessibleTable(),
130 Reference
< XAccessible
> BrowseBox::CreateAccessibleRowHeader( sal_Int32 _nRow
)
132 return svt::getHeaderCell(
133 m_pImpl
->m_aRowHeaderCellMap
,
135 svt::BBTYPE_ROWHEADERCELL
,
136 m_pImpl
->getAccessibleHeaderBar(svt::BBTYPE_ROWHEADERBAR
),
138 m_pImpl
->m_aFactoryAccess
.getFactory()
143 Reference
< XAccessible
> BrowseBox::CreateAccessibleColumnHeader( sal_uInt16 _nColumnPos
)
145 return svt::getHeaderCell(
146 m_pImpl
->m_aColHeaderCellMap
,
148 svt::BBTYPE_COLUMNHEADERCELL
,
149 m_pImpl
->getAccessibleHeaderBar(svt::BBTYPE_COLUMNHEADERBAR
),
151 m_pImpl
->m_aFactoryAccess
.getFactory()
156 sal_Int32
BrowseBox::GetAccessibleControlCount() const
162 Reference
< XAccessible
> BrowseBox::CreateAccessibleControl( sal_Int32
)
164 DBG_ASSERT( false, "BrowseBox::CreateAccessibleControl: to be overwritten!" );
169 // Conversions ----------------------------------------------------------------
171 bool BrowseBox::ConvertPointToCellAddress(
172 sal_Int32
& rnRow
, sal_uInt16
& rnColumnPos
, const Point
& rPoint
)
174 //! TODO has to be checked
175 rnRow
= GetRowAtYPosPixel(rPoint
.Y());
176 rnColumnPos
= GetColumnAtXPosPixel(rPoint
.X());
177 return rnRow
!= BROWSER_INVALIDID
&& rnColumnPos
!= BROWSER_INVALIDID
;
181 bool BrowseBox::ConvertPointToRowHeader( sal_Int32
& rnRow
, const Point
& rPoint
)
183 rnRow
= GetRowAtYPosPixel(rPoint
.Y());
184 // sal_uInt16 nColumnId = GetColumnAtXPosPixel(rPoint.X());
185 return rnRow
!= BROWSER_INVALIDID
;// && nColumnId == 0;
189 bool BrowseBox::ConvertPointToColumnHeader( sal_uInt16
& _rnColumnPos
, const Point
& _rPoint
)
191 _rnColumnPos
= GetColumnAtXPosPixel(_rPoint
.X());
192 return _rnColumnPos
!= BROWSER_INVALIDID
;
196 bool BrowseBox::ConvertPointToControlIndex( sal_Int32
& _rnIndex
, const Point
& _rPoint
)
198 //! TODO has to be checked
200 sal_uInt16 nColumn
= 0;
201 bool bRet
= ConvertPointToCellAddress(nRow
,nColumn
,_rPoint
);
203 _rnIndex
= nRow
* ColCount() + nColumn
;
209 // Object data and state ------------------------------------------------------
211 OUString
BrowseBox::GetAccessibleObjectName( ::svt::AccessibleBrowseBoxObjType eObjType
,sal_Int32 _nPosition
) const
216 case ::svt::BBTYPE_BROWSEBOX
:
217 aRetText
= "BrowseBox";
219 case ::svt::BBTYPE_TABLE
:
222 case ::svt::BBTYPE_ROWHEADERBAR
:
223 aRetText
= "RowHeaderBar";
225 case ::svt::BBTYPE_COLUMNHEADERBAR
:
226 aRetText
= "ColumnHeaderBar";
228 case ::svt::BBTYPE_TABLECELL
:
229 if( ColCount() !=0 && GetRowCount()!=0)
232 sal_Int32 columnId
= _nPosition
% ColCount() +1;
233 aRetText
= OUString( GetColumnDescription( sal_Int16( columnId
) ) );
234 sal_Int32 rowId
= _nPosition
/ GetRowCount() + 1;
235 aRetText
+= OUString::number(rowId
);
238 aRetText
= "TableCell";
239 #if OSL_DEBUG_LEVEL > 1
241 aRetText
+= OUString::number(sal_Int32(GetCurRow()));
243 aRetText
+= OUString::number(sal_Int32(GetCurColumnId()));
247 case ::svt::BBTYPE_ROWHEADERCELL
:
249 sal_Int32 rowId
= _nPosition
+ 1;
250 aRetText
= OUString::number( rowId
);
252 #if OSL_DEBUG_LEVEL > 1
254 aRetText
+= OUString::number(sal_Int32(GetCurRow()));
256 aRetText
+= OUString::number(sal_Int32(GetCurColumnId()));
260 case ::svt::BBTYPE_COLUMNHEADERCELL
:
261 aRetText
= OUString( GetColumnDescription( sal_Int16( _nPosition
) ) );
262 #if OSL_DEBUG_LEVEL > 1
264 aRetText
+= OUString::number(sal_Int32(GetCurRow()));
266 aRetText
+= OUString::number(sal_Int32(GetCurColumnId()));
271 OSL_FAIL("BrowseBox::GetAccessibleName: invalid enum!");
277 OUString
BrowseBox::GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType eObjType
,sal_Int32
) const
282 case ::svt::BBTYPE_BROWSEBOX
:
283 aRetText
= "BrowseBox description";
285 case ::svt::BBTYPE_TABLE
:
286 // aRetText = "TABLE description";
288 case ::svt::BBTYPE_ROWHEADERBAR
:
289 // aRetText = "ROWHEADERBAR description";
291 case ::svt::BBTYPE_COLUMNHEADERBAR
:
292 // aRetText = "COLUMNHEADERBAR description";
294 case ::svt::BBTYPE_TABLECELL
:
295 // aRetText = "TABLECELL description";
297 case ::svt::BBTYPE_ROWHEADERCELL
:
298 // aRetText = "ROWHEADERCELL description";
300 case ::svt::BBTYPE_COLUMNHEADERCELL
:
301 // aRetText = "COLUMNHEADERCELL description";
303 case ::svt::BBTYPE_CHECKBOXCELL
:
310 OUString
BrowseBox::GetRowDescription( sal_Int32
) const
316 OUString
BrowseBox::GetColumnDescription( sal_uInt16 _nColumn
) const
318 return OUString( GetColumnTitle( GetColumnId( _nColumn
) ) );
323 void BrowseBox::FillAccessibleStateSet(
324 ::utl::AccessibleStateSetHelper
& rStateSet
,
325 ::svt::AccessibleBrowseBoxObjType eObjType
) const
329 case ::svt::BBTYPE_BROWSEBOX
:
330 case ::svt::BBTYPE_TABLE
:
332 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
334 rStateSet
.AddState( AccessibleStateType::FOCUSED
);
336 rStateSet
.AddState( AccessibleStateType::ACTIVE
);
337 if ( GetUpdateMode() )
338 rStateSet
.AddState( AccessibleStateType::EDITABLE
);
341 rStateSet
.AddState( AccessibleStateType::ENABLED
);
342 rStateSet
.AddState( AccessibleStateType::SENSITIVE
);
344 if ( IsReallyVisible() )
345 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
346 if ( eObjType
== ::svt::BBTYPE_TABLE
)
347 rStateSet
.AddState( AccessibleStateType::MANAGES_DESCENDANTS
);
350 case ::svt::BBTYPE_ROWHEADERBAR
:
351 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
352 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
353 if ( GetSelectRowCount() )
354 rStateSet
.AddState( AccessibleStateType::FOCUSED
);
355 rStateSet
.AddState( AccessibleStateType::MANAGES_DESCENDANTS
);
357 case ::svt::BBTYPE_COLUMNHEADERBAR
:
358 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
359 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
360 if ( GetSelectColumnCount() )
361 rStateSet
.AddState( AccessibleStateType::FOCUSED
);
362 rStateSet
.AddState( AccessibleStateType::MANAGES_DESCENDANTS
);
364 case ::svt::BBTYPE_TABLECELL
:
366 sal_Int32 nRow
= GetCurRow();
367 sal_uInt16 nColumn
= GetCurColumnId();
368 if ( IsFieldVisible(nRow
,nColumn
) )
369 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
370 if ( !IsFrozen( nColumn
) )
371 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
372 rStateSet
.AddState( AccessibleStateType::TRANSIENT
);
375 case ::svt::BBTYPE_ROWHEADERCELL
:
376 case ::svt::BBTYPE_COLUMNHEADERCELL
:
377 case ::svt::BBTYPE_CHECKBOXCELL
:
378 OSL_FAIL("Illegal call here!");
383 void BrowseBox::FillAccessibleStateSetForCell( ::utl::AccessibleStateSetHelper
& _rStateSet
,
384 sal_Int32 _nRow
, sal_uInt16 _nColumnPos
) const
386 //! TODO check if the state is valid for table cells
387 if ( IsCellVisible( _nRow
, _nColumnPos
) )
388 _rStateSet
.AddState( AccessibleStateType::VISIBLE
);
389 if ( GetCurrRow() == _nRow
&& GetCurrColumn() == _nColumnPos
)
390 _rStateSet
.AddState( AccessibleStateType::FOCUSED
);
391 else // only transient when column is not focused
392 _rStateSet
.AddState( AccessibleStateType::TRANSIENT
);
396 void BrowseBox::GrabTableFocus()
401 OUString
BrowseBox::GetCellText(long, sal_uInt16
) const
403 DBG_ASSERT(false,"This method has to be implemented by the derived classes! BUG!!");
408 void BrowseBox::commitHeaderBarEvent(sal_Int16 nEventId
,
409 const Any
& rNewValue
, const Any
& rOldValue
, bool _bColumnHeaderBar
)
411 if ( isAccessibleAlive() )
412 m_pImpl
->m_pAccessible
->commitHeaderBarEvent( nEventId
,
413 rNewValue
, rOldValue
, _bColumnHeaderBar
);
417 void BrowseBox::commitTableEvent( sal_Int16 _nEventId
, const Any
& _rNewValue
, const Any
& _rOldValue
)
419 if ( isAccessibleAlive() )
420 m_pImpl
->m_pAccessible
->commitTableEvent( _nEventId
, _rNewValue
, _rOldValue
);
423 void BrowseBox::commitBrowseBoxEvent( sal_Int16 _nEventId
, const Any
& _rNewValue
, const Any
& _rOldValue
)
425 if ( isAccessibleAlive() )
426 m_pImpl
->m_pAccessible
->commitEvent( _nEventId
, _rNewValue
, _rOldValue
);
430 ::svt::IAccessibleFactory
& BrowseBox::getAccessibleFactory()
432 return m_pImpl
->m_aFactoryAccess
.getFactory();
436 bool BrowseBox::isAccessibleAlive( ) const
438 return ( NULL
!= m_pImpl
->m_pAccessible
) && m_pImpl
->m_pAccessible
->isAlive();
441 // IAccessibleTableProvider
443 sal_Int32
BrowseBox::GetCurrRow() const
448 sal_uInt16
BrowseBox::GetCurrColumn() const
450 return GetColumnPos( GetCurColumnId() );
453 bool BrowseBox::HasRowHeader() const
455 return ( GetColumnId( 0 ) == HandleColumnId
); // HandleColumn == RowHeader
458 bool BrowseBox::IsCellFocusable() const
463 bool BrowseBox::GoToCell( sal_Int32 _nRow
, sal_uInt16 _nColumn
)
465 return GoToRowColumnId( _nRow
, GetColumnId( _nColumn
) );
468 void BrowseBox::SelectColumn( sal_uInt16 _nColumn
, bool _bSelect
)
470 SelectColumnPos( _nColumn
, _bSelect
);
473 bool BrowseBox::IsColumnSelected( long _nColumn
) const
475 return ( pColSel
&& (0 <= _nColumn
) && (_nColumn
<= 0xFFF) ) &&
476 pColSel
->IsSelected( static_cast< sal_uInt16
>( _nColumn
) );
479 sal_Int32
BrowseBox::GetSelectedRowCount() const
481 return GetSelectRowCount();
484 sal_Int32
BrowseBox::GetSelectedColumnCount() const
486 const MultiSelection
* pColumnSel
= GetColumnSelection();
487 return pColumnSel
? pColumnSel
->GetSelectCount() : 0;
490 void BrowseBox::GetAllSelectedRows( ::com::sun::star::uno::Sequence
< sal_Int32
>& _rRows
) const
492 sal_Int32 nCount
= GetSelectRowCount();
495 _rRows
.realloc( nCount
);
496 _rRows
[ 0 ] = const_cast< BrowseBox
* >( this )->FirstSelectedRow();
497 for( sal_Int32 nIndex
= 1; nIndex
< nCount
; ++nIndex
)
498 _rRows
[ nIndex
] = const_cast< BrowseBox
* >( this )->NextSelectedRow();
499 DBG_ASSERT( const_cast< BrowseBox
* >( this )->NextSelectedRow() == BROWSER_ENDOFSELECTION
,
500 "BrowseBox::GetAllSelectedRows - too many selected rows found" );
504 void BrowseBox::GetAllSelectedColumns( ::com::sun::star::uno::Sequence
< sal_Int32
>& _rColumns
) const
506 const MultiSelection
* pColumnSel
= GetColumnSelection();
507 sal_Int32 nCount
= GetSelectedColumnCount();
508 if( pColumnSel
&& nCount
)
510 _rColumns
.realloc( nCount
);
512 sal_Int32 nIndex
= 0;
513 const size_t nRangeCount
= pColumnSel
->GetRangeCount();
514 for( size_t nRange
= 0; nRange
< nRangeCount
; ++nRange
)
516 const Range
& rRange
= pColumnSel
->GetRange( nRange
);
517 // loop has to include aRange.Max()
518 for( sal_Int32 nCol
= rRange
.Min(); nCol
<= rRange
.Max(); ++nCol
)
520 DBG_ASSERT( nIndex
< nCount
,
521 "GetAllSelectedColumns - range overflow" );
522 _rColumns
[ nIndex
] = nCol
;
529 bool BrowseBox::IsCellVisible( sal_Int32 _nRow
, sal_uInt16 _nColumnPos
) const
531 return IsFieldVisible( _nRow
, GetColumnId( _nColumnPos
) );
534 OUString
BrowseBox::GetAccessibleCellText(long _nRow
, sal_uInt16 _nColPos
) const
536 return GetCellText( _nRow
, GetColumnId( _nColPos
) );
540 bool BrowseBox::GetGlyphBoundRects( const Point
& rOrigin
, const OUString
& rStr
, int nIndex
, int nLen
, int nBase
, MetricVector
& rVector
)
542 return Control::GetGlyphBoundRects( rOrigin
, rStr
, nIndex
, nLen
, nBase
, rVector
);
545 Rectangle
BrowseBox::GetWindowExtentsRelative( vcl::Window
*pRelativeWindow
) const
547 return Control::GetWindowExtentsRelative( pRelativeWindow
);
550 void BrowseBox::GrabFocus()
552 Control::GrabFocus();
555 Reference
< XAccessible
> BrowseBox::GetAccessible( bool bCreate
)
557 return Control::GetAccessible( bCreate
);
560 vcl::Window
* BrowseBox::GetAccessibleParentWindow() const
562 return Control::GetAccessibleParentWindow();
565 vcl::Window
* BrowseBox::GetWindowInstance()
570 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */