bump product version to 6.3.0.0.beta1
[LibreOffice.git] / svtools / source / brwbox / brwbox3.cxx
blobcc5b535767e2b5af45bd8a504c8fa97bf5656337
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 "datwin.hxx"
28 #include "brwimpl.hxx"
29 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
30 #include <com/sun/star/accessibility/AccessibleRole.hpp>
32 // Accessibility ==============================================================
34 using namespace ::com::sun::star::uno;
35 using ::com::sun::star::accessibility::XAccessible;
36 using namespace ::com::sun::star::accessibility;
39 namespace svt
41 using namespace ::com::sun::star::lang;
42 using namespace utl;
44 static Reference< XAccessible > getHeaderCell( BrowseBoxImpl::THeaderCellMap& _raHeaderCells,
45 sal_Int32 _nPos,
46 vcl::AccessibleBrowseBoxObjType _eType,
47 const Reference< XAccessible >& _rParent,
48 BrowseBox& _rBrowseBox,
49 vcl::IAccessibleFactory const & rFactory
52 Reference< XAccessible > xRet;
53 BrowseBoxImpl::THeaderCellMap::iterator aFind = _raHeaderCells.find( _nPos );
54 if ( aFind == _raHeaderCells.end() )
56 Reference< XAccessible > xAccessible = rFactory.createAccessibleBrowseBoxHeaderCell(
57 _nPos,
58 _rParent,
59 _rBrowseBox,
60 nullptr,
61 _eType
63 aFind = _raHeaderCells.emplace( _nPos, xAccessible ).first;
65 if ( aFind != _raHeaderCells.end() )
66 xRet = aFind->second;
67 return xRet;
71 Reference< XAccessible > BrowseBoxImpl::getAccessibleHeaderBar( vcl::AccessibleBrowseBoxObjType _eObjType )
73 if ( m_pAccessible && m_pAccessible->isAlive() )
74 return m_pAccessible->getHeaderBar( _eObjType );
75 return nullptr;
79 Reference< XAccessible > BrowseBoxImpl::getAccessibleTable( )
81 if ( m_pAccessible && m_pAccessible->isAlive() )
82 return m_pAccessible->getTable( );
83 return nullptr;
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();
96 if( xAccParent.is() )
98 m_pImpl->m_pAccessible = getAccessibleFactory().createAccessibleBrowseBox(
99 xAccParent, *this
104 Reference< XAccessible > xAccessible;
105 if ( m_pImpl->m_pAccessible )
106 xAccessible = m_pImpl->m_pAccessible->getMyself();
108 return xAccessible;
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(),
121 *this,
122 nullptr,
123 _nRow,
124 _nColumnPos,
125 OFFSET_DEFAULT
130 Reference< XAccessible > BrowseBox::CreateAccessibleRowHeader( sal_Int32 _nRow )
132 return svt::getHeaderCell(
133 m_pImpl->m_aRowHeaderCellMap,
134 _nRow,
135 vcl::BBTYPE_ROWHEADERCELL,
136 m_pImpl->getAccessibleHeaderBar(vcl::BBTYPE_ROWHEADERBAR),
137 *this,
138 m_pImpl->m_aFactoryAccess.getFactory()
143 Reference< XAccessible > BrowseBox::CreateAccessibleColumnHeader( sal_uInt16 _nColumnPos )
145 return svt::getHeaderCell(
146 m_pImpl->m_aColHeaderCellMap,
147 _nColumnPos,
148 vcl::BBTYPE_COLUMNHEADERCELL,
149 m_pImpl->getAccessibleHeaderBar(vcl::BBTYPE_COLUMNHEADERBAR),
150 *this,
151 m_pImpl->m_aFactoryAccess.getFactory()
156 sal_Int32 BrowseBox::GetAccessibleControlCount() const
158 return 0;
162 Reference< XAccessible > BrowseBox::CreateAccessibleControl( sal_Int32 )
164 SAL_WARN( "svtools", "BrowseBox::CreateAccessibleControl: to be overwritten!" );
165 return nullptr;
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
199 sal_Int32 nRow = 0;
200 sal_uInt16 nColumn = 0;
201 bool bRet = ConvertPointToCellAddress(nRow,nColumn,_rPoint);
202 if ( bRet )
203 _rnIndex = nRow * ColCount() + nColumn;
205 return bRet;
209 // Object data and state ------------------------------------------------------
211 OUString BrowseBox::GetAccessibleObjectName( ::vcl::AccessibleBrowseBoxObjType eObjType,sal_Int32 _nPosition) const
213 OUString aRetText;
214 switch( eObjType )
216 case ::vcl::BBTYPE_BROWSEBOX:
217 aRetText = "BrowseBox";
218 break;
219 case ::vcl::BBTYPE_TABLE:
220 aRetText = "Table";
221 break;
222 case ::vcl::BBTYPE_ROWHEADERBAR:
223 aRetText = "RowHeaderBar";
224 break;
225 case ::vcl::BBTYPE_COLUMNHEADERBAR:
226 aRetText = "ColumnHeaderBar";
227 break;
228 case ::vcl::BBTYPE_TABLECELL:
229 if( ColCount() !=0 && GetRowCount()!=0)
232 sal_Int32 columnId = _nPosition % ColCount() +1;
233 aRetText = GetColumnDescription( sal_Int16( columnId ) );
234 sal_Int32 rowId = _nPosition / GetRowCount() + 1;
235 aRetText += OUString::number(rowId);
237 else
238 aRetText = "TableCell";
239 #if OSL_DEBUG_LEVEL > 0
240 aRetText += " ["
241 + OUString::number(sal_Int32(GetCurRow()))
242 + ","
243 + OUString::number(sal_Int32(GetCurColumnId()))
244 + "]";
245 #endif
246 break;
247 case ::vcl::BBTYPE_ROWHEADERCELL:
249 sal_Int32 rowId = _nPosition + 1;
250 aRetText = OUString::number( rowId );
252 #if OSL_DEBUG_LEVEL > 0
253 aRetText += " ["
254 + OUString::number(sal_Int32(GetCurRow()))
255 + ","
256 + OUString::number(sal_Int32(GetCurColumnId()))
257 + "]";
258 #endif
259 break;
260 case ::vcl::BBTYPE_COLUMNHEADERCELL:
261 aRetText = GetColumnDescription( sal_Int16( _nPosition ) );
262 #if OSL_DEBUG_LEVEL > 0
263 aRetText += " ["
264 + OUString::number(sal_Int32(GetCurRow()))
265 + ","
266 + OUString::number(sal_Int32(GetCurColumnId()))
267 + "]";
268 #endif
269 break;
270 default:
271 OSL_FAIL("BrowseBox::GetAccessibleName: invalid enum!");
273 return aRetText;
277 OUString BrowseBox::GetAccessibleObjectDescription( ::vcl::AccessibleBrowseBoxObjType eObjType,sal_Int32 ) const
279 OUString aRetText;
280 switch( eObjType )
282 case ::vcl::BBTYPE_BROWSEBOX:
283 aRetText = "BrowseBox description";
284 break;
285 case ::vcl::BBTYPE_TABLE:
286 // aRetText = "TABLE description";
287 break;
288 case ::vcl::BBTYPE_ROWHEADERBAR:
289 // aRetText = "ROWHEADERBAR description";
290 break;
291 case ::vcl::BBTYPE_COLUMNHEADERBAR:
292 // aRetText = "COLUMNHEADERBAR description";
293 break;
294 case ::vcl::BBTYPE_TABLECELL:
295 // aRetText = "TABLECELL description";
296 break;
297 case ::vcl::BBTYPE_ROWHEADERCELL:
298 // aRetText = "ROWHEADERCELL description";
299 break;
300 case ::vcl::BBTYPE_COLUMNHEADERCELL:
301 // aRetText = "COLUMNHEADERCELL description";
302 break;
303 case ::vcl::BBTYPE_CHECKBOXCELL:
304 break;
306 return aRetText;
310 OUString BrowseBox::GetRowDescription( sal_Int32 ) const
312 return OUString();
316 OUString BrowseBox::GetColumnDescription( sal_uInt16 _nColumn ) const
318 return GetColumnTitle( GetColumnId( _nColumn ) );
322 void BrowseBox::FillAccessibleStateSet(
323 ::utl::AccessibleStateSetHelper& rStateSet,
324 ::vcl::AccessibleBrowseBoxObjType eObjType ) const
326 switch( eObjType )
328 case ::vcl::BBTYPE_BROWSEBOX:
329 case ::vcl::BBTYPE_TABLE:
331 rStateSet.AddState( AccessibleStateType::FOCUSABLE );
332 if ( HasFocus() )
333 rStateSet.AddState( AccessibleStateType::FOCUSED );
334 if ( IsActive() )
335 rStateSet.AddState( AccessibleStateType::ACTIVE );
336 if ( GetUpdateMode() )
337 rStateSet.AddState( AccessibleStateType::EDITABLE );
338 if ( IsEnabled() )
340 rStateSet.AddState( AccessibleStateType::ENABLED );
341 rStateSet.AddState( AccessibleStateType::SENSITIVE );
343 if ( IsReallyVisible() )
344 rStateSet.AddState( AccessibleStateType::VISIBLE );
345 if ( eObjType == ::vcl::BBTYPE_TABLE )
346 rStateSet.AddState( AccessibleStateType::MANAGES_DESCENDANTS );
348 break;
349 case ::vcl::BBTYPE_ROWHEADERBAR:
350 rStateSet.AddState( AccessibleStateType::FOCUSABLE );
351 rStateSet.AddState( AccessibleStateType::VISIBLE );
352 if ( GetSelectRowCount() )
353 rStateSet.AddState( AccessibleStateType::FOCUSED );
354 rStateSet.AddState( AccessibleStateType::MANAGES_DESCENDANTS );
355 break;
356 case ::vcl::BBTYPE_COLUMNHEADERBAR:
357 rStateSet.AddState( AccessibleStateType::FOCUSABLE );
358 rStateSet.AddState( AccessibleStateType::VISIBLE );
359 if ( GetSelectColumnCount() )
360 rStateSet.AddState( AccessibleStateType::FOCUSED );
361 rStateSet.AddState( AccessibleStateType::MANAGES_DESCENDANTS );
362 break;
363 case ::vcl::BBTYPE_TABLECELL:
365 sal_Int32 nRow = GetCurRow();
366 sal_uInt16 nColumn = GetCurColumnId();
367 if ( IsFieldVisible(nRow,nColumn) )
368 rStateSet.AddState( AccessibleStateType::VISIBLE );
369 if ( !IsFrozen( nColumn ) )
370 rStateSet.AddState( AccessibleStateType::FOCUSABLE );
371 rStateSet.AddState( AccessibleStateType::TRANSIENT );
373 break;
374 case ::vcl::BBTYPE_ROWHEADERCELL:
375 case ::vcl::BBTYPE_COLUMNHEADERCELL:
376 case ::vcl::BBTYPE_CHECKBOXCELL:
377 OSL_FAIL("Illegal call here!");
378 break;
382 void BrowseBox::FillAccessibleStateSetForCell( ::utl::AccessibleStateSetHelper& _rStateSet,
383 sal_Int32 _nRow, sal_uInt16 _nColumnPos ) const
385 //! TODO check if the state is valid for table cells
386 if ( IsCellVisible( _nRow, _nColumnPos ) )
387 _rStateSet.AddState( AccessibleStateType::VISIBLE );
388 if ( GetCurrRow() == _nRow && GetCurrColumn() == _nColumnPos )
389 _rStateSet.AddState( AccessibleStateType::FOCUSED );
390 else // only transient when column is not focused
391 _rStateSet.AddState( AccessibleStateType::TRANSIENT );
395 void BrowseBox::GrabTableFocus()
397 GrabFocus();
400 OUString BrowseBox::GetCellText(long, sal_uInt16 ) const
402 SAL_WARN("svtools", "This method has to be implemented by the derived classes! BUG!!");
403 return OUString();
407 void BrowseBox::commitHeaderBarEvent(sal_Int16 nEventId,
408 const Any& rNewValue, const Any& rOldValue, bool _bColumnHeaderBar )
410 if ( isAccessibleAlive() )
411 m_pImpl->m_pAccessible->commitHeaderBarEvent( nEventId,
412 rNewValue, rOldValue, _bColumnHeaderBar );
415 void BrowseBox::commitTableEvent( sal_Int16 _nEventId, const Any& _rNewValue, const Any& _rOldValue )
417 if ( isAccessibleAlive() )
418 m_pImpl->m_pAccessible->commitTableEvent( _nEventId, _rNewValue, _rOldValue );
421 void BrowseBox::commitBrowseBoxEvent( sal_Int16 _nEventId, const Any& _rNewValue, const Any& _rOldValue )
423 if ( isAccessibleAlive() )
424 m_pImpl->m_pAccessible->commitEvent( _nEventId, _rNewValue, _rOldValue);
427 ::vcl::IAccessibleFactory& BrowseBox::getAccessibleFactory()
429 return m_pImpl->m_aFactoryAccess.getFactory();
432 bool BrowseBox::isAccessibleAlive( ) const
434 return ( nullptr != m_pImpl->m_pAccessible ) && m_pImpl->m_pAccessible->isAlive();
437 // IAccessibleTableProvider
439 sal_Int32 BrowseBox::GetCurrRow() const
441 return GetCurRow();
444 sal_uInt16 BrowseBox::GetCurrColumn() const
446 return GetColumnPos( GetCurColumnId() );
449 bool BrowseBox::HasRowHeader() const
451 return ( GetColumnId( 0 ) == HandleColumnId ); // HandleColumn == RowHeader
454 bool BrowseBox::GoToCell( sal_Int32 _nRow, sal_uInt16 _nColumn )
456 return GoToRowColumnId( _nRow, GetColumnId( _nColumn ) );
459 void BrowseBox::SelectColumn( sal_uInt16 _nColumn, bool _bSelect )
461 SelectColumnPos( _nColumn, _bSelect );
464 bool BrowseBox::IsColumnSelected( long _nColumn ) const
466 return ( pColSel && (0 <= _nColumn) && (_nColumn <= 0xFFF) ) &&
467 pColSel->IsSelected( static_cast< sal_uInt16 >( _nColumn ) );
470 sal_Int32 BrowseBox::GetSelectedRowCount() const
472 return GetSelectRowCount();
475 sal_Int32 BrowseBox::GetSelectedColumnCount() const
477 const MultiSelection* pColumnSel = GetColumnSelection();
478 return pColumnSel ? pColumnSel->GetSelectCount() : 0;
481 void BrowseBox::GetAllSelectedRows( css::uno::Sequence< sal_Int32 >& _rRows ) const
483 sal_Int32 nCount = GetSelectRowCount();
484 if( nCount )
486 _rRows.realloc( nCount );
487 _rRows[ 0 ] = const_cast< BrowseBox* >( this )->FirstSelectedRow();
488 for( sal_Int32 nIndex = 1; nIndex < nCount; ++nIndex )
489 _rRows[ nIndex ] = const_cast< BrowseBox* >( this )->NextSelectedRow();
490 DBG_ASSERT( const_cast< BrowseBox* >( this )->NextSelectedRow() == BROWSER_ENDOFSELECTION,
491 "BrowseBox::GetAllSelectedRows - too many selected rows found" );
495 void BrowseBox::GetAllSelectedColumns( css::uno::Sequence< sal_Int32 >& _rColumns ) const
497 const MultiSelection* pColumnSel = GetColumnSelection();
498 sal_Int32 nCount = GetSelectedColumnCount();
499 if( !(pColumnSel && nCount) )
500 return;
502 _rColumns.realloc( nCount );
504 sal_Int32 nIndex = 0;
505 const size_t nRangeCount = pColumnSel->GetRangeCount();
506 for( size_t nRange = 0; nRange < nRangeCount; ++nRange )
508 const Range& rRange = pColumnSel->GetRange( nRange );
509 // loop has to include aRange.Max()
510 for( sal_Int32 nCol = rRange.Min(); nCol <= static_cast<sal_Int32>(rRange.Max()); ++nCol )
512 DBG_ASSERT( nIndex < nCount,
513 "GetAllSelectedColumns - range overflow" );
514 _rColumns[ nIndex ] = nCol;
515 ++nIndex;
520 bool BrowseBox::IsCellVisible( sal_Int32 _nRow, sal_uInt16 _nColumnPos ) const
522 return IsFieldVisible( _nRow, GetColumnId( _nColumnPos ) );
525 OUString BrowseBox::GetAccessibleCellText(long _nRow, sal_uInt16 _nColPos) const
527 return GetCellText( _nRow, GetColumnId( _nColPos ) );
531 bool BrowseBox::GetGlyphBoundRects( const Point& rOrigin, const OUString& rStr, int nIndex, int nLen, MetricVector& rVector )
533 return Control::GetGlyphBoundRects( rOrigin, rStr, nIndex, nLen, rVector );
536 tools::Rectangle BrowseBox::GetWindowExtentsRelative( vcl::Window *pRelativeWindow ) const
538 return Control::GetWindowExtentsRelative( pRelativeWindow );
541 void BrowseBox::GrabFocus()
543 Control::GrabFocus();
546 Reference< XAccessible > BrowseBox::GetAccessible()
548 return Control::GetAccessible();
551 vcl::Window* BrowseBox::GetAccessibleParentWindow() const
553 return Control::GetAccessibleParentWindow();
556 vcl::Window* BrowseBox::GetWindowInstance()
558 return this;
561 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */