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
;
36 // ============================================================================
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() )
68 // ============================================================================
69 // ----------------------------------------------------------------------------
70 Reference
< XAccessible
> BrowseBoxImpl::getAccessibleHeaderBar( AccessibleBrowseBoxObjType _eObjType
)
72 if ( m_pAccessible
&& m_pAccessible
->isAlive() )
73 return m_pAccessible
->getHeaderBar( _eObjType
);
77 // ----------------------------------------------------------------------------
78 Reference
< XAccessible
> BrowseBoxImpl::getAccessibleTable( )
80 if ( m_pAccessible
&& m_pAccessible
->isAlive() )
81 return m_pAccessible
->getTable( );
86 // ============================================================================
88 Reference
< XAccessible
> BrowseBox::CreateAccessible()
90 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();
110 // -----------------------------------------------------------------------------
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(),
128 // -----------------------------------------------------------------------------
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()
141 // -----------------------------------------------------------------------------
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()
154 // -----------------------------------------------------------------------------
156 sal_Int32
BrowseBox::GetAccessibleControlCount() const
160 // -----------------------------------------------------------------------------
162 Reference
< XAccessible
> BrowseBox::CreateAccessibleControl( sal_Int32
)
164 DBG_ASSERT( sal_False
, "BrowseBox::CreateAccessibleControl: to be overwritten!" );
167 // -----------------------------------------------------------------------------
169 // Conversions ----------------------------------------------------------------
171 sal_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
;
179 // -----------------------------------------------------------------------------
181 sal_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;
187 // -----------------------------------------------------------------------------
189 sal_Bool
BrowseBox::ConvertPointToColumnHeader( sal_uInt16
& _rnColumnPos
, const Point
& _rPoint
)
191 _rnColumnPos
= GetColumnAtXPosPixel(_rPoint
.X());
192 return _rnColumnPos
!= BROWSER_INVALIDID
;
194 // -----------------------------------------------------------------------------
196 sal_Bool
BrowseBox::ConvertPointToControlIndex( sal_Int32
& _rnIndex
, const Point
& _rPoint
)
198 //! TODO has to be checked
200 sal_uInt16 nColumn
= 0;
201 sal_Bool bRet
= ConvertPointToCellAddress(nRow
,nColumn
,_rPoint
);
203 _rnIndex
= nRow
* ColCount() + nColumn
;
207 // -----------------------------------------------------------------------------
209 // Object data and state ------------------------------------------------------
211 OUString
BrowseBox::GetAccessibleObjectName( ::svt::AccessibleBrowseBoxObjType eObjType
,sal_Int32
) const
216 case ::svt::BBTYPE_BROWSEBOX
:
217 aRetText
= OUString( "BrowseBox" );
219 case ::svt::BBTYPE_TABLE
:
220 aRetText
= OUString( "Table" );
222 case ::svt::BBTYPE_ROWHEADERBAR
:
223 aRetText
= OUString( "RowHeaderBar" );
225 case ::svt::BBTYPE_COLUMNHEADERBAR
:
226 aRetText
= OUString( "ColumnHeaderBar" );
228 case ::svt::BBTYPE_TABLECELL
:
229 aRetText
= OUString( "TableCell" );
230 #if OSL_DEBUG_LEVEL > 1
232 aRetText
+= OUString::valueOf(sal_Int32(GetCurRow()));
234 aRetText
+= OUString::valueOf(sal_Int32(GetCurColumnId()));
238 case ::svt::BBTYPE_ROWHEADERCELL
:
239 aRetText
= OUString( "RowHeaderCell" );
240 #if OSL_DEBUG_LEVEL > 1
242 aRetText
+= OUString::valueOf(sal_Int32(GetCurRow()));
244 aRetText
+= OUString::valueOf(sal_Int32(GetCurColumnId()));
248 case ::svt::BBTYPE_COLUMNHEADERCELL
:
249 aRetText
= OUString( "ColumnHeaderCell" );
250 #if OSL_DEBUG_LEVEL > 1
252 aRetText
+= OUString::valueOf(sal_Int32(GetCurRow()));
254 aRetText
+= OUString::valueOf(sal_Int32(GetCurColumnId()));
259 OSL_FAIL("BrowseBox::GetAccessibleName: invalid enum!");
263 // -----------------------------------------------------------------------------
265 OUString
BrowseBox::GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType eObjType
,sal_Int32
) const
270 case ::svt::BBTYPE_BROWSEBOX
:
271 aRetText
= OUString( "BrowseBox description" );
273 case ::svt::BBTYPE_TABLE
:
274 // aRetText = OUString( "TABLE description" );
276 case ::svt::BBTYPE_ROWHEADERBAR
:
277 // aRetText = OUString( "ROWHEADERBAR description" );
279 case ::svt::BBTYPE_COLUMNHEADERBAR
:
280 // aRetText = OUString( "COLUMNHEADERBAR description" );
282 case ::svt::BBTYPE_TABLECELL
:
283 // aRetText = OUString( "TABLECELL description" );
285 case ::svt::BBTYPE_ROWHEADERCELL
:
286 // aRetText = OUString( "ROWHEADERCELL description" );
288 case ::svt::BBTYPE_COLUMNHEADERCELL
:
289 // aRetText = OUString( "COLUMNHEADERCELL description" );
291 case ::svt::BBTYPE_CHECKBOXCELL
:
296 // -----------------------------------------------------------------------------
298 OUString
BrowseBox::GetRowDescription( sal_Int32
) const
302 // -----------------------------------------------------------------------------
304 OUString
BrowseBox::GetColumnDescription( sal_uInt16 _nColumn
) const
306 return OUString( GetColumnTitle( GetColumnId( _nColumn
) ) );
309 // -----------------------------------------------------------------------------
311 void BrowseBox::FillAccessibleStateSet(
312 ::utl::AccessibleStateSetHelper
& rStateSet
,
313 ::svt::AccessibleBrowseBoxObjType eObjType
) const
317 case ::svt::BBTYPE_BROWSEBOX
:
318 case ::svt::BBTYPE_TABLE
:
320 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
322 rStateSet
.AddState( AccessibleStateType::FOCUSED
);
324 rStateSet
.AddState( AccessibleStateType::ACTIVE
);
325 if ( GetUpdateMode() )
326 rStateSet
.AddState( AccessibleStateType::EDITABLE
);
329 rStateSet
.AddState( AccessibleStateType::ENABLED
);
330 rStateSet
.AddState( AccessibleStateType::SENSITIVE
);
332 if ( IsReallyVisible() )
333 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
334 if ( eObjType
== ::svt::BBTYPE_TABLE
)
335 rStateSet
.AddState( AccessibleStateType::MANAGES_DESCENDANTS
);
338 case ::svt::BBTYPE_ROWHEADERBAR
:
339 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
340 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
341 if ( GetSelectRowCount() )
342 rStateSet
.AddState( AccessibleStateType::FOCUSED
);
343 rStateSet
.AddState( AccessibleStateType::MANAGES_DESCENDANTS
);
345 case ::svt::BBTYPE_COLUMNHEADERBAR
:
346 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
347 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
348 if ( GetSelectColumnCount() )
349 rStateSet
.AddState( AccessibleStateType::FOCUSED
);
350 rStateSet
.AddState( AccessibleStateType::MANAGES_DESCENDANTS
);
352 case ::svt::BBTYPE_TABLECELL
:
354 sal_Int32 nRow
= GetCurRow();
355 sal_uInt16 nColumn
= GetCurColumnId();
356 if ( IsFieldVisible(nRow
,nColumn
) )
357 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
358 if ( !IsFrozen( nColumn
) )
359 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
360 rStateSet
.AddState( AccessibleStateType::TRANSIENT
);
363 case ::svt::BBTYPE_ROWHEADERCELL
:
364 case ::svt::BBTYPE_COLUMNHEADERCELL
:
365 case ::svt::BBTYPE_CHECKBOXCELL
:
366 OSL_FAIL("Illegal call here!");
370 // -----------------------------------------------------------------------
371 void BrowseBox::FillAccessibleStateSetForCell( ::utl::AccessibleStateSetHelper
& _rStateSet
,
372 sal_Int32 _nRow
, sal_uInt16 _nColumnPos
) const
374 //! TODO check if the state is valid for table cells
375 if ( IsCellVisible( _nRow
, _nColumnPos
) )
376 _rStateSet
.AddState( AccessibleStateType::VISIBLE
);
377 if ( GetCurrRow() == _nRow
&& GetCurrColumn() == _nColumnPos
)
378 _rStateSet
.AddState( AccessibleStateType::FOCUSED
);
379 else // only transient when column is not focused
380 _rStateSet
.AddState( AccessibleStateType::TRANSIENT
);
382 // -----------------------------------------------------------------------------
384 void BrowseBox::GrabTableFocus()
388 // -----------------------------------------------------------------------------
389 String
BrowseBox::GetCellText(long, sal_uInt16
) const
391 DBG_ASSERT(0,"This method has to be implemented by the derived classes! BUG!!");
395 // -----------------------------------------------------------------------------
396 void BrowseBox::commitHeaderBarEvent(sal_Int16 nEventId
,
397 const Any
& rNewValue
, const Any
& rOldValue
, sal_Bool _bColumnHeaderBar
)
399 if ( isAccessibleAlive() )
400 m_pImpl
->m_pAccessible
->commitHeaderBarEvent( nEventId
,
401 rNewValue
, rOldValue
, _bColumnHeaderBar
);
404 // -----------------------------------------------------------------------------
405 void BrowseBox::commitTableEvent( sal_Int16 _nEventId
, const Any
& _rNewValue
, const Any
& _rOldValue
)
407 if ( isAccessibleAlive() )
408 m_pImpl
->m_pAccessible
->commitTableEvent( _nEventId
, _rNewValue
, _rOldValue
);
410 // -----------------------------------------------------------------------------
411 void BrowseBox::commitBrowseBoxEvent( sal_Int16 _nEventId
, const Any
& _rNewValue
, const Any
& _rOldValue
)
413 if ( isAccessibleAlive() )
414 m_pImpl
->m_pAccessible
->commitEvent( _nEventId
, _rNewValue
, _rOldValue
);
417 // -----------------------------------------------------------------------------
418 ::svt::IAccessibleFactory
& BrowseBox::getAccessibleFactory()
420 return m_pImpl
->m_aFactoryAccess
.getFactory();
423 // -----------------------------------------------------------------------------
424 sal_Bool
BrowseBox::isAccessibleAlive( ) const
426 return ( NULL
!= m_pImpl
->m_pAccessible
) && m_pImpl
->m_pAccessible
->isAlive();
428 // -----------------------------------------------------------------------------
429 // IAccessibleTableProvider
430 // -----------------------------------------------------------------------------
431 sal_Int32
BrowseBox::GetCurrRow() const
435 // -----------------------------------------------------------------------------
436 sal_uInt16
BrowseBox::GetCurrColumn() const
438 return GetColumnPos( GetCurColumnId() );
440 // -----------------------------------------------------------------------------
441 sal_Bool
BrowseBox::HasRowHeader() const
443 return ( GetColumnId( 0 ) == HandleColumnId
); // HandleColumn == RowHeader
445 // -----------------------------------------------------------------------------
446 sal_Bool
BrowseBox::IsCellFocusable() const
450 // -----------------------------------------------------------------------------
451 sal_Bool
BrowseBox::GoToCell( sal_Int32 _nRow
, sal_uInt16 _nColumn
)
453 return GoToRowColumnId( _nRow
, GetColumnId( _nColumn
) );
455 // -----------------------------------------------------------------------------
456 void BrowseBox::SelectColumn( sal_uInt16 _nColumn
, sal_Bool _bSelect
)
458 SelectColumnPos( _nColumn
, _bSelect
);
460 // -----------------------------------------------------------------------------
461 sal_Bool
BrowseBox::IsColumnSelected( long _nColumn
) const
463 return ( pColSel
&& (0 <= _nColumn
) && (_nColumn
<= 0xFFF) ) ?
464 pColSel
->IsSelected( static_cast< sal_uInt16
>( _nColumn
) ) :
467 // -----------------------------------------------------------------------------
468 sal_Int32
BrowseBox::GetSelectedRowCount() const
470 return GetSelectRowCount();
472 // -----------------------------------------------------------------------------
473 sal_Int32
BrowseBox::GetSelectedColumnCount() const
475 const MultiSelection
* pColumnSel
= GetColumnSelection();
476 return pColumnSel
? pColumnSel
->GetSelectCount() : 0;
478 // -----------------------------------------------------------------------------
479 void BrowseBox::GetAllSelectedRows( ::com::sun::star::uno::Sequence
< sal_Int32
>& _rRows
) const
481 sal_Int32 nCount
= GetSelectRowCount();
484 _rRows
.realloc( nCount
);
485 _rRows
[ 0 ] = const_cast< BrowseBox
* >( this )->FirstSelectedRow();
486 for( sal_Int32 nIndex
= 1; nIndex
< nCount
; ++nIndex
)
487 _rRows
[ nIndex
] = const_cast< BrowseBox
* >( this )->NextSelectedRow();
488 DBG_ASSERT( const_cast< BrowseBox
* >( this )->NextSelectedRow() == BROWSER_ENDOFSELECTION
,
489 "BrowseBox::GetAllSelectedRows - too many selected rows found" );
492 // -----------------------------------------------------------------------------
493 void BrowseBox::GetAllSelectedColumns( ::com::sun::star::uno::Sequence
< sal_Int32
>& _rColumns
) const
495 const MultiSelection
* pColumnSel
= GetColumnSelection();
496 sal_Int32 nCount
= GetSelectedColumnCount();
497 if( pColumnSel
&& nCount
)
499 _rColumns
.realloc( nCount
);
501 sal_Int32 nIndex
= 0;
502 sal_uInt32 nRangeCount
= pColumnSel
->GetRangeCount();
503 for( sal_uInt32 nRange
= 0; nRange
< nRangeCount
; ++nRange
)
505 const Range
& rRange
= pColumnSel
->GetRange( nRange
);
506 // loop has to include aRange.Max()
507 for( sal_Int32 nCol
= rRange
.Min(); nCol
<= rRange
.Max(); ++nCol
)
509 DBG_ASSERT( nIndex
< nCount
,
510 "GetAllSelectedColumns - range overflow" );
511 _rColumns
[ nIndex
] = nCol
;
517 // -----------------------------------------------------------------------------
518 sal_Bool
BrowseBox::IsCellVisible( sal_Int32 _nRow
, sal_uInt16 _nColumnPos
) const
520 return IsFieldVisible( _nRow
, GetColumnId( _nColumnPos
) );
522 // -----------------------------------------------------------------------------
523 String
BrowseBox::GetAccessibleCellText(long _nRow
, sal_uInt16 _nColPos
) const
525 return GetCellText( _nRow
, GetColumnId( _nColPos
) );
528 // -----------------------------------------------------------------------------
529 sal_Bool
BrowseBox::GetGlyphBoundRects( const Point
& rOrigin
, const String
& rStr
, int nIndex
, int nLen
, int nBase
, MetricVector
& rVector
)
531 return Control::GetGlyphBoundRects( rOrigin
, rStr
, nIndex
, nLen
, nBase
, rVector
);
533 // -----------------------------------------------------------------------------
534 Rectangle
BrowseBox::GetWindowExtentsRelative( Window
*pRelativeWindow
) const
536 return Control::GetWindowExtentsRelative( pRelativeWindow
);
538 // -----------------------------------------------------------------------------
539 void BrowseBox::GrabFocus()
541 Control::GrabFocus();
543 // -----------------------------------------------------------------------------
544 Reference
< XAccessible
> BrowseBox::GetAccessible( sal_Bool bCreate
)
546 return Control::GetAccessible( bCreate
);
548 // -----------------------------------------------------------------------------
549 Window
* BrowseBox::GetAccessibleParentWindow() const
551 return Control::GetAccessibleParentWindow();
553 // -----------------------------------------------------------------------------
554 Window
* BrowseBox::GetWindowInstance()
559 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */