nss: upgrade to release 3.73
[LibreOffice.git] / svtools / source / brwbox / brwbox3.cxx
blob46f2d4f8d97c6782dd32282239a31c3d821e23df
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <vcl/AccessibleBrowseBoxObjType.hxx>
22 #include <vcl/accessiblefactory.hxx>
23 #include <unotools/accessiblestatesethelper.hxx>
24 #include <sal/log.hxx>
25 #include <tools/debug.hxx>
26 #include <tools/multisel.hxx>
27 #include "brwimpl.hxx"
28 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
30 // Accessibility ==============================================================
32 using namespace ::com::sun::star::uno;
33 using ::com::sun::star::accessibility::XAccessible;
34 using namespace ::com::sun::star::accessibility;
37 namespace svt
39 using namespace ::com::sun::star::lang;
40 using namespace utl;
42 static Reference< XAccessible > getHeaderCell( BrowseBoxImpl::THeaderCellMap& _raHeaderCells,
43 sal_Int32 _nPos,
44 vcl::AccessibleBrowseBoxObjType _eType,
45 const Reference< XAccessible >& _rParent,
46 BrowseBox& _rBrowseBox,
47 vcl::IAccessibleFactory const & rFactory
50 Reference< XAccessible > xRet;
51 BrowseBoxImpl::THeaderCellMap::iterator aFind = _raHeaderCells.find( _nPos );
52 if ( aFind == _raHeaderCells.end() )
54 Reference< XAccessible > xAccessible = rFactory.createAccessibleBrowseBoxHeaderCell(
55 _nPos,
56 _rParent,
57 _rBrowseBox,
58 nullptr,
59 _eType
61 aFind = _raHeaderCells.emplace( _nPos, xAccessible ).first;
63 if ( aFind != _raHeaderCells.end() )
64 xRet = aFind->second;
65 return xRet;
69 Reference< XAccessible > BrowseBoxImpl::getAccessibleHeaderBar( vcl::AccessibleBrowseBoxObjType _eObjType )
71 if ( m_pAccessible && m_pAccessible->isAlive() )
72 return m_pAccessible->getHeaderBar( _eObjType );
73 return nullptr;
77 Reference< XAccessible > BrowseBoxImpl::getAccessibleTable( )
79 if ( m_pAccessible && m_pAccessible->isAlive() )
80 return m_pAccessible->getTable( );
81 return nullptr;
86 Reference< XAccessible > BrowseBox::CreateAccessible()
88 vcl::Window* pParent = GetAccessibleParentWindow();
89 DBG_ASSERT( pParent, "BrowseBox::CreateAccessible - parent not found" );
91 if( pParent && !m_pImpl->m_pAccessible)
93 Reference< XAccessible > xAccParent = pParent->GetAccessible();
94 if( xAccParent.is() )
96 m_pImpl->m_pAccessible = getAccessibleFactory().createAccessibleBrowseBox(
97 xAccParent, *this
102 Reference< XAccessible > xAccessible;
103 if ( m_pImpl->m_pAccessible )
104 xAccessible = m_pImpl->m_pAccessible->getMyself();
106 return xAccessible;
110 // Children -------------------------------------------------------------------
112 Reference< XAccessible > BrowseBox::CreateAccessibleCell( sal_Int32 _nRow, sal_uInt16 _nColumnPos )
114 // BBINDEX_TABLE must be the table
115 OSL_ENSURE(m_pImpl->m_pAccessible,"Invalid call: Accessible is null");
117 return m_pImpl->m_aFactoryAccess.getFactory().createAccessibleBrowseBoxTableCell(
118 m_pImpl->getAccessibleTable(),
119 *this,
120 nullptr,
121 _nRow,
122 _nColumnPos,
123 OFFSET_DEFAULT
128 Reference< XAccessible > BrowseBox::CreateAccessibleRowHeader( sal_Int32 _nRow )
130 return svt::getHeaderCell(
131 m_pImpl->m_aRowHeaderCellMap,
132 _nRow,
133 vcl::BBTYPE_ROWHEADERCELL,
134 m_pImpl->getAccessibleHeaderBar(vcl::BBTYPE_ROWHEADERBAR),
135 *this,
136 m_pImpl->m_aFactoryAccess.getFactory()
141 Reference< XAccessible > BrowseBox::CreateAccessibleColumnHeader( sal_uInt16 _nColumnPos )
143 return svt::getHeaderCell(
144 m_pImpl->m_aColHeaderCellMap,
145 _nColumnPos,
146 vcl::BBTYPE_COLUMNHEADERCELL,
147 m_pImpl->getAccessibleHeaderBar(vcl::BBTYPE_COLUMNHEADERBAR),
148 *this,
149 m_pImpl->m_aFactoryAccess.getFactory()
154 sal_Int32 BrowseBox::GetAccessibleControlCount() const
156 return 0;
160 Reference< XAccessible > BrowseBox::CreateAccessibleControl( sal_Int32 )
162 SAL_WARN( "svtools", "BrowseBox::CreateAccessibleControl: to be overwritten!" );
163 return nullptr;
167 // Conversions ----------------------------------------------------------------
169 bool BrowseBox::ConvertPointToCellAddress(
170 sal_Int32& rnRow, sal_uInt16& rnColumnPos, const Point& rPoint )
172 //! TODO has to be checked
173 rnRow = GetRowAtYPosPixel(rPoint.Y());
174 rnColumnPos = GetColumnAtXPosPixel(rPoint.X());
175 return rnRow != BROWSER_INVALIDID && rnColumnPos != BROWSER_INVALIDID;
179 bool BrowseBox::ConvertPointToRowHeader( sal_Int32& rnRow, const Point& rPoint )
181 rnRow = GetRowAtYPosPixel(rPoint.Y());
182 // sal_uInt16 nColumnId = GetColumnAtXPosPixel(rPoint.X());
183 return rnRow != BROWSER_INVALIDID;// && nColumnId == 0;
187 bool BrowseBox::ConvertPointToColumnHeader( sal_uInt16& _rnColumnPos, const Point& _rPoint )
189 _rnColumnPos = GetColumnAtXPosPixel(_rPoint.X());
190 return _rnColumnPos != BROWSER_INVALIDID;
194 bool BrowseBox::ConvertPointToControlIndex( sal_Int32& _rnIndex, const Point& _rPoint )
196 //! TODO has to be checked
197 sal_Int32 nRow = 0;
198 sal_uInt16 nColumn = 0;
199 bool bRet = ConvertPointToCellAddress(nRow,nColumn,_rPoint);
200 if ( bRet )
201 _rnIndex = nRow * ColCount() + nColumn;
203 return bRet;
207 // Object data and state ------------------------------------------------------
209 OUString BrowseBox::GetAccessibleObjectName( ::vcl::AccessibleBrowseBoxObjType eObjType,sal_Int32 _nPosition) const
211 OUString aRetText;
212 switch( eObjType )
214 case ::vcl::BBTYPE_BROWSEBOX:
215 aRetText = "BrowseBox";
216 break;
217 case ::vcl::BBTYPE_TABLE:
218 aRetText = "Table";
219 break;
220 case ::vcl::BBTYPE_ROWHEADERBAR:
221 aRetText = "RowHeaderBar";
222 break;
223 case ::vcl::BBTYPE_COLUMNHEADERBAR:
224 aRetText = "ColumnHeaderBar";
225 break;
226 case ::vcl::BBTYPE_TABLECELL:
227 if( ColCount() !=0 && GetRowCount()!=0)
230 sal_Int32 columnId = _nPosition % ColCount() +1;
231 aRetText = GetColumnDescription( sal_Int16( columnId ) );
232 sal_Int32 rowId = _nPosition / GetRowCount() + 1;
233 aRetText += OUString::number(rowId);
235 else
236 aRetText = "TableCell";
237 #if OSL_DEBUG_LEVEL > 0
238 aRetText += " ["
239 + OUString::number(GetCurRow())
240 + ","
241 + OUString::number(sal_Int32(GetCurColumnId()))
242 + "]";
243 #endif
244 break;
245 case ::vcl::BBTYPE_ROWHEADERCELL:
247 sal_Int32 rowId = _nPosition + 1;
248 aRetText = OUString::number( rowId );
250 #if OSL_DEBUG_LEVEL > 0
251 aRetText += " ["
252 + OUString::number(GetCurRow())
253 + ","
254 + OUString::number(sal_Int32(GetCurColumnId()))
255 + "]";
256 #endif
257 break;
258 case ::vcl::BBTYPE_COLUMNHEADERCELL:
259 aRetText = GetColumnDescription( sal_Int16( _nPosition ) );
260 #if OSL_DEBUG_LEVEL > 0
261 aRetText += " ["
262 + OUString::number(GetCurRow())
263 + ","
264 + OUString::number(sal_Int32(GetCurColumnId()))
265 + "]";
266 #endif
267 break;
268 default:
269 OSL_FAIL("BrowseBox::GetAccessibleName: invalid enum!");
271 return aRetText;
275 OUString BrowseBox::GetAccessibleObjectDescription( ::vcl::AccessibleBrowseBoxObjType eObjType,sal_Int32 ) const
277 OUString aRetText;
278 switch( eObjType )
280 case ::vcl::BBTYPE_BROWSEBOX:
281 aRetText = "BrowseBox description";
282 break;
283 case ::vcl::BBTYPE_TABLE:
284 // aRetText = "TABLE description";
285 break;
286 case ::vcl::BBTYPE_ROWHEADERBAR:
287 // aRetText = "ROWHEADERBAR description";
288 break;
289 case ::vcl::BBTYPE_COLUMNHEADERBAR:
290 // aRetText = "COLUMNHEADERBAR description";
291 break;
292 case ::vcl::BBTYPE_TABLECELL:
293 // aRetText = "TABLECELL description";
294 break;
295 case ::vcl::BBTYPE_ROWHEADERCELL:
296 // aRetText = "ROWHEADERCELL description";
297 break;
298 case ::vcl::BBTYPE_COLUMNHEADERCELL:
299 // aRetText = "COLUMNHEADERCELL description";
300 break;
301 case ::vcl::BBTYPE_CHECKBOXCELL:
302 break;
304 return aRetText;
308 OUString BrowseBox::GetRowDescription( sal_Int32 ) const
310 return OUString();
314 OUString BrowseBox::GetColumnDescription( sal_uInt16 _nColumn ) const
316 return GetColumnTitle( GetColumnId( _nColumn ) );
320 void BrowseBox::FillAccessibleStateSet(
321 ::utl::AccessibleStateSetHelper& rStateSet,
322 ::vcl::AccessibleBrowseBoxObjType eObjType ) const
324 switch( eObjType )
326 case ::vcl::BBTYPE_BROWSEBOX:
327 case ::vcl::BBTYPE_TABLE:
329 rStateSet.AddState( AccessibleStateType::FOCUSABLE );
330 if ( HasFocus() )
331 rStateSet.AddState( AccessibleStateType::FOCUSED );
332 if ( IsActive() )
333 rStateSet.AddState( AccessibleStateType::ACTIVE );
334 if ( GetUpdateMode() )
335 rStateSet.AddState( AccessibleStateType::EDITABLE );
336 if ( IsEnabled() )
338 rStateSet.AddState( AccessibleStateType::ENABLED );
339 rStateSet.AddState( AccessibleStateType::SENSITIVE );
341 if ( IsReallyVisible() )
342 rStateSet.AddState( AccessibleStateType::VISIBLE );
343 if ( eObjType == ::vcl::BBTYPE_TABLE )
344 rStateSet.AddState( AccessibleStateType::MANAGES_DESCENDANTS );
346 break;
347 case ::vcl::BBTYPE_ROWHEADERBAR:
348 rStateSet.AddState( AccessibleStateType::FOCUSABLE );
349 rStateSet.AddState( AccessibleStateType::VISIBLE );
350 if ( GetSelectRowCount() )
351 rStateSet.AddState( AccessibleStateType::FOCUSED );
352 rStateSet.AddState( AccessibleStateType::MANAGES_DESCENDANTS );
353 break;
354 case ::vcl::BBTYPE_COLUMNHEADERBAR:
355 rStateSet.AddState( AccessibleStateType::FOCUSABLE );
356 rStateSet.AddState( AccessibleStateType::VISIBLE );
357 if ( GetSelectColumnCount() )
358 rStateSet.AddState( AccessibleStateType::FOCUSED );
359 rStateSet.AddState( AccessibleStateType::MANAGES_DESCENDANTS );
360 break;
361 case ::vcl::BBTYPE_TABLECELL:
363 sal_Int32 nRow = GetCurRow();
364 sal_uInt16 nColumn = GetCurColumnId();
365 if ( IsFieldVisible(nRow,nColumn) )
366 rStateSet.AddState( AccessibleStateType::VISIBLE );
367 if ( !IsFrozen( nColumn ) )
368 rStateSet.AddState( AccessibleStateType::FOCUSABLE );
369 rStateSet.AddState( AccessibleStateType::TRANSIENT );
371 break;
372 case ::vcl::BBTYPE_ROWHEADERCELL:
373 case ::vcl::BBTYPE_COLUMNHEADERCELL:
374 case ::vcl::BBTYPE_CHECKBOXCELL:
375 OSL_FAIL("Illegal call here!");
376 break;
380 void BrowseBox::FillAccessibleStateSetForCell( ::utl::AccessibleStateSetHelper& _rStateSet,
381 sal_Int32 _nRow, sal_uInt16 _nColumnPos ) const
383 //! TODO check if the state is valid for table cells
384 if ( IsCellVisible( _nRow, _nColumnPos ) )
385 _rStateSet.AddState( AccessibleStateType::VISIBLE );
386 if ( GetCurrRow() == _nRow && GetCurrColumn() == _nColumnPos )
387 _rStateSet.AddState( AccessibleStateType::FOCUSED );
388 else // only transient when column is not focused
389 _rStateSet.AddState( AccessibleStateType::TRANSIENT );
393 void BrowseBox::GrabTableFocus()
395 GrabFocus();
398 OUString BrowseBox::GetCellText(sal_Int32, sal_uInt16 ) const
400 SAL_WARN("svtools", "This method has to be implemented by the derived classes! BUG!!");
401 return OUString();
405 void BrowseBox::commitHeaderBarEvent(sal_Int16 nEventId,
406 const Any& rNewValue, const Any& rOldValue, bool _bColumnHeaderBar )
408 if ( isAccessibleAlive() )
409 m_pImpl->m_pAccessible->commitHeaderBarEvent( nEventId,
410 rNewValue, rOldValue, _bColumnHeaderBar );
413 void BrowseBox::commitTableEvent( sal_Int16 _nEventId, const Any& _rNewValue, const Any& _rOldValue )
415 if ( isAccessibleAlive() )
416 m_pImpl->m_pAccessible->commitTableEvent( _nEventId, _rNewValue, _rOldValue );
419 void BrowseBox::commitBrowseBoxEvent( sal_Int16 _nEventId, const Any& _rNewValue, const Any& _rOldValue )
421 if ( isAccessibleAlive() )
422 m_pImpl->m_pAccessible->commitEvent( _nEventId, _rNewValue, _rOldValue);
425 ::vcl::IAccessibleFactory& BrowseBox::getAccessibleFactory()
427 return m_pImpl->m_aFactoryAccess.getFactory();
430 bool BrowseBox::isAccessibleAlive( ) const
432 return ( nullptr != m_pImpl->m_pAccessible ) && m_pImpl->m_pAccessible->isAlive();
435 // IAccessibleTableProvider
437 sal_Int32 BrowseBox::GetCurrRow() const
439 return GetCurRow();
442 sal_uInt16 BrowseBox::GetCurrColumn() const
444 return GetColumnPos( GetCurColumnId() );
447 bool BrowseBox::HasRowHeader() const
449 return ( GetColumnId( 0 ) == HandleColumnId ); // HandleColumn == RowHeader
452 bool BrowseBox::GoToCell( sal_Int32 _nRow, sal_uInt16 _nColumn )
454 return GoToRowColumnId( _nRow, GetColumnId( _nColumn ) );
457 void BrowseBox::SelectColumn( sal_uInt16 _nColumn, bool _bSelect )
459 SelectColumnPos( _nColumn, _bSelect );
462 bool BrowseBox::IsColumnSelected( sal_Int32 _nColumn ) const
464 return ( pColSel && (0 <= _nColumn) && (_nColumn <= 0xFFF) ) &&
465 pColSel->IsSelected( static_cast< sal_uInt16 >( _nColumn ) );
468 sal_Int32 BrowseBox::GetSelectedRowCount() const
470 return GetSelectRowCount();
473 sal_Int32 BrowseBox::GetSelectedColumnCount() const
475 const MultiSelection* pColumnSel = GetColumnSelection();
476 return pColumnSel ? pColumnSel->GetSelectCount() : 0;
479 void BrowseBox::GetAllSelectedRows( css::uno::Sequence< sal_Int32 >& _rRows ) const
481 sal_Int32 nCount = GetSelectRowCount();
482 if( nCount )
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" );
493 void BrowseBox::GetAllSelectedColumns( css::uno::Sequence< sal_Int32 >& _rColumns ) const
495 const MultiSelection* pColumnSel = GetColumnSelection();
496 sal_Int32 nCount = GetSelectedColumnCount();
497 if( !(pColumnSel && nCount) )
498 return;
500 _rColumns.realloc( nCount );
502 sal_Int32 nIndex = 0;
503 const size_t nRangeCount = pColumnSel->GetRangeCount();
504 for( size_t nRange = 0; nRange < nRangeCount; ++nRange )
506 const Range& rRange = pColumnSel->GetRange( nRange );
507 // loop has to include aRange.Max()
508 for( sal_Int32 nCol = rRange.Min(); nCol <= static_cast<sal_Int32>(rRange.Max()); ++nCol )
510 DBG_ASSERT( nIndex < nCount,
511 "GetAllSelectedColumns - range overflow" );
512 _rColumns[ nIndex ] = nCol;
513 ++nIndex;
518 bool BrowseBox::IsCellVisible( sal_Int32 _nRow, sal_uInt16 _nColumnPos ) const
520 return IsFieldVisible( _nRow, GetColumnId( _nColumnPos ) );
523 OUString BrowseBox::GetAccessibleCellText(sal_Int32 _nRow, sal_uInt16 _nColPos) const
525 return GetCellText( _nRow, GetColumnId( _nColPos ) );
529 bool BrowseBox::GetGlyphBoundRects( const Point& rOrigin, const OUString& rStr, int nIndex, int nLen, MetricVector& rVector )
531 return Control::GetGlyphBoundRects( rOrigin, rStr, nIndex, nLen, rVector );
534 tools::Rectangle BrowseBox::GetWindowExtentsRelative(const vcl::Window *pRelativeWindow) const
536 return Control::GetWindowExtentsRelative( pRelativeWindow );
539 void BrowseBox::GrabFocus()
541 Control::GrabFocus();
544 Reference< XAccessible > BrowseBox::GetAccessible()
546 return Control::GetAccessible();
549 vcl::Window* BrowseBox::GetAccessibleParentWindow() const
551 return Control::GetAccessibleParentWindow();
554 vcl::Window* BrowseBox::GetWindowInstance()
556 return this;
559 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */