Get the style color and number just once
[LibreOffice.git] / svtools / source / brwbox / brwbox3.cxx
blob649da48cfc1df781127c06362818201ed1c40c92
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 <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;
36 namespace svt
38 static Reference< XAccessible > getHeaderCell(BrowseBox::THeaderCellMap& _raHeaderCells,
39 sal_Int32 _nPos,
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(
51 _nPos,
52 _rParent,
53 _rBrowseBox,
54 _eType
56 aFind = _raHeaderCells.emplace( _nPos, xAccessible ).first;
58 if ( aFind != _raHeaderCells.end() )
59 xRet = aFind->second;
60 return xRet;
64 Reference<XAccessible> BrowseBox::getAccessibleHeaderBar(AccessibleBrowseBoxObjType _eObjType)
66 if (m_pAccessible && m_pAccessible->isAlive())
67 return m_pAccessible->getHeaderBar(_eObjType);
68 return nullptr;
71 Reference<XAccessible> BrowseBox::getAccessibleTable()
73 if (m_pAccessible && m_pAccessible->isAlive())
74 return m_pAccessible->getTable();
75 return nullptr;
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();
86 if( xAccParent.is() )
88 m_pAccessible = getAccessibleFactory().createAccessibleBrowseBox(
89 xAccParent, *this
94 return m_pAccessible;
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(),
107 *this,
108 _nRow,
109 _nColumnPos,
110 OFFSET_DEFAULT
115 Reference< XAccessible > BrowseBox::CreateAccessibleRowHeader( sal_Int32 _nRow )
117 return svt::getHeaderCell(
118 m_aRowHeaderCellMap,
119 _nRow,
120 AccessibleBrowseBoxObjType::RowHeaderCell,
121 getAccessibleHeaderBar(AccessibleBrowseBoxObjType::RowHeaderBar),
122 *this,
123 m_aFactoryAccess.getFactory()
128 Reference< XAccessible > BrowseBox::CreateAccessibleColumnHeader( sal_uInt16 _nColumnPos )
130 return svt::getHeaderCell(
131 m_aColHeaderCellMap,
132 _nColumnPos,
133 AccessibleBrowseBoxObjType::ColumnHeaderCell,
134 getAccessibleHeaderBar(AccessibleBrowseBoxObjType::ColumnHeaderBar),
135 *this,
136 m_aFactoryAccess.getFactory()
141 sal_Int32 BrowseBox::GetAccessibleControlCount() const
143 return 0;
147 Reference< XAccessible > BrowseBox::CreateAccessibleControl( sal_Int32 )
149 SAL_WARN( "svtools", "BrowseBox::CreateAccessibleControl: to be overwritten!" );
150 return nullptr;
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
184 sal_Int32 nRow = 0;
185 sal_uInt16 nColumn = 0;
186 bool bRet = ConvertPointToCellAddress(nRow,nColumn,_rPoint);
187 if ( bRet )
188 _rnIndex = nRow * ColCount() + nColumn;
190 return bRet;
194 // Object data and state ------------------------------------------------------
196 OUString BrowseBox::GetAccessibleObjectName( AccessibleBrowseBoxObjType eObjType,sal_Int32 _nPosition) const
198 OUString aRetText;
199 switch( eObjType )
201 case AccessibleBrowseBoxObjType::BrowseBox:
202 aRetText = "BrowseBox";
203 break;
204 case AccessibleBrowseBoxObjType::Table:
205 aRetText = "Table";
206 break;
207 case AccessibleBrowseBoxObjType::RowHeaderBar:
208 aRetText = "RowHeaderBar";
209 break;
210 case AccessibleBrowseBoxObjType::ColumnHeaderBar:
211 aRetText = "ColumnHeaderBar";
212 break;
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);
222 else
223 aRetText = "TableCell";
224 #if OSL_DEBUG_LEVEL > 0
225 aRetText += " ["
226 + OUString::number(GetCurRow())
227 + ","
228 + OUString::number(sal_Int32(GetCurColumnId()))
229 + "]";
230 #endif
231 break;
232 case AccessibleBrowseBoxObjType::RowHeaderCell:
234 sal_Int32 rowId = _nPosition + 1;
235 aRetText = OUString::number( rowId );
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 AccessibleBrowseBoxObjType::ColumnHeaderCell:
246 aRetText = GetColumnDescription( sal_Int16( _nPosition ) );
247 #if OSL_DEBUG_LEVEL > 0
248 aRetText += " ["
249 + OUString::number(GetCurRow())
250 + ","
251 + OUString::number(sal_Int32(GetCurColumnId()))
252 + "]";
253 #endif
254 break;
255 default:
256 OSL_FAIL("BrowseBox::GetAccessibleName: invalid enum!");
258 return aRetText;
262 OUString BrowseBox::GetAccessibleObjectDescription( AccessibleBrowseBoxObjType eObjType,sal_Int32 ) const
264 OUString aRetText;
265 switch( eObjType )
267 case AccessibleBrowseBoxObjType::BrowseBox:
268 aRetText = "BrowseBox description";
269 break;
270 case AccessibleBrowseBoxObjType::Table:
271 // aRetText = "TABLE description";
272 break;
273 case AccessibleBrowseBoxObjType::RowHeaderBar:
274 // aRetText = "ROWHEADERBAR description";
275 break;
276 case AccessibleBrowseBoxObjType::ColumnHeaderBar:
277 // aRetText = "COLUMNHEADERBAR description";
278 break;
279 case AccessibleBrowseBoxObjType::TableCell:
280 // aRetText = "TABLECELL description";
281 break;
282 case AccessibleBrowseBoxObjType::RowHeaderCell:
283 // aRetText = "ROWHEADERCELL description";
284 break;
285 case AccessibleBrowseBoxObjType::ColumnHeaderCell:
286 // aRetText = "COLUMNHEADERCELL description";
287 break;
288 case AccessibleBrowseBoxObjType::CheckBoxCell:
289 break;
291 return aRetText;
295 OUString BrowseBox::GetRowDescription( sal_Int32 ) const
297 return OUString();
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
311 switch( eObjType )
313 case AccessibleBrowseBoxObjType::BrowseBox:
314 case AccessibleBrowseBoxObjType::Table:
316 rStateSet |= AccessibleStateType::FOCUSABLE;
317 if ( HasFocus() )
318 rStateSet |= AccessibleStateType::FOCUSED;
319 if ( IsActive() )
320 rStateSet |= AccessibleStateType::ACTIVE;
321 if ( GetUpdateMode() )
322 rStateSet |= AccessibleStateType::EDITABLE;
323 if ( IsEnabled() )
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;
333 break;
334 case AccessibleBrowseBoxObjType::RowHeaderBar:
335 rStateSet |= AccessibleStateType::FOCUSABLE;
336 rStateSet |= AccessibleStateType::VISIBLE;
337 if ( GetSelectRowCount() )
338 rStateSet |= AccessibleStateType::FOCUSED;
339 rStateSet |= AccessibleStateType::MANAGES_DESCENDANTS;
340 break;
341 case AccessibleBrowseBoxObjType::ColumnHeaderBar:
342 rStateSet |= AccessibleStateType::FOCUSABLE;
343 rStateSet |= AccessibleStateType::VISIBLE;
344 if ( GetSelectColumnCount() )
345 rStateSet |= AccessibleStateType::FOCUSED;
346 rStateSet |= AccessibleStateType::MANAGES_DESCENDANTS;
347 break;
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;
358 break;
359 case AccessibleBrowseBoxObjType::RowHeaderCell:
360 case AccessibleBrowseBoxObjType::ColumnHeaderCell:
361 case AccessibleBrowseBoxObjType::CheckBoxCell:
362 OSL_FAIL("Illegal call here!");
363 break;
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()
382 GrabFocus();
385 OUString BrowseBox::GetCellText(sal_Int32, sal_uInt16 ) const
387 SAL_WARN("svtools", "This method has to be implemented by the derived classes! BUG!!");
388 return OUString();
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
426 return GetCurRow();
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();
469 if( nCount )
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) )
486 return;
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;
502 ++nIndex;
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()
550 return this;
553 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */