Bump version to 5.0-14
[LibreOffice.git] / svtools / source / brwbox / brwbox3.cxx
blobd2a44ffe8464c07673d89dab70f494d3a769f380
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 <svtools/AccessibleBrowseBoxObjType.hxx>
22 #include <tools/debug.hxx>
23 #include <tools/multisel.hxx>
24 #include "datwin.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;
37 namespace svt
39 using namespace ::com::sun::star::lang;
40 using namespace utl;
42 Reference< XAccessible > getHeaderCell( BrowseBoxImpl::THeaderCellMap& _raHeaderCells,
43 sal_Int32 _nPos,
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(
55 _nPos,
56 _rParent,
57 _rBrowseBox,
58 NULL,
59 _eType
61 aFind = _raHeaderCells.insert( BrowseBoxImpl::THeaderCellMap::value_type( _nPos, xAccessible ) ).first;
63 if ( aFind != _raHeaderCells.end() )
64 xRet = aFind->second;
65 return xRet;
70 Reference< XAccessible > BrowseBoxImpl::getAccessibleHeaderBar( AccessibleBrowseBoxObjType _eObjType )
72 if ( m_pAccessible && m_pAccessible->isAlive() )
73 return m_pAccessible->getHeaderBar( _eObjType );
74 return NULL;
78 Reference< XAccessible > BrowseBoxImpl::getAccessibleTable( )
80 if ( m_pAccessible && m_pAccessible->isAlive() )
81 return m_pAccessible->getTable( );
82 return NULL;
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 NULL,
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 svt::BBTYPE_ROWHEADERCELL,
136 m_pImpl->getAccessibleHeaderBar(svt::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 svt::BBTYPE_COLUMNHEADERCELL,
149 m_pImpl->getAccessibleHeaderBar(svt::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 DBG_ASSERT( false, "BrowseBox::CreateAccessibleControl: to be overwritten!" );
165 return NULL;
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( ::svt::AccessibleBrowseBoxObjType eObjType,sal_Int32 _nPosition) const
213 OUString aRetText;
214 switch( eObjType )
216 case ::svt::BBTYPE_BROWSEBOX:
217 aRetText = "BrowseBox";
218 break;
219 case ::svt::BBTYPE_TABLE:
220 aRetText = "Table";
221 break;
222 case ::svt::BBTYPE_ROWHEADERBAR:
223 aRetText = "RowHeaderBar";
224 break;
225 case ::svt::BBTYPE_COLUMNHEADERBAR:
226 aRetText = "ColumnHeaderBar";
227 break;
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);
237 else
238 aRetText = "TableCell";
239 #if OSL_DEBUG_LEVEL > 1
240 aRetText += " [";
241 aRetText += OUString::number(sal_Int32(GetCurRow()));
242 aRetText += ",";
243 aRetText += OUString::number(sal_Int32(GetCurColumnId()));
244 aRetText += "]";
245 #endif
246 break;
247 case ::svt::BBTYPE_ROWHEADERCELL:
249 sal_Int32 rowId = _nPosition + 1;
250 aRetText = OUString::number( rowId );
252 #if OSL_DEBUG_LEVEL > 1
253 aRetText += " [";
254 aRetText += OUString::number(sal_Int32(GetCurRow()));
255 aRetText += ",";
256 aRetText += OUString::number(sal_Int32(GetCurColumnId()));
257 aRetText += "]";
258 #endif
259 break;
260 case ::svt::BBTYPE_COLUMNHEADERCELL:
261 aRetText = OUString( GetColumnDescription( sal_Int16( _nPosition ) ) );
262 #if OSL_DEBUG_LEVEL > 1
263 aRetText += " [";
264 aRetText += OUString::number(sal_Int32(GetCurRow()));
265 aRetText += ",";
266 aRetText += OUString::number(sal_Int32(GetCurColumnId()));
267 aRetText += "]";
268 #endif
269 break;
270 default:
271 OSL_FAIL("BrowseBox::GetAccessibleName: invalid enum!");
273 return aRetText;
277 OUString BrowseBox::GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType eObjType,sal_Int32 ) const
279 OUString aRetText;
280 switch( eObjType )
282 case ::svt::BBTYPE_BROWSEBOX:
283 aRetText = "BrowseBox description";
284 break;
285 case ::svt::BBTYPE_TABLE:
286 // aRetText = "TABLE description";
287 break;
288 case ::svt::BBTYPE_ROWHEADERBAR:
289 // aRetText = "ROWHEADERBAR description";
290 break;
291 case ::svt::BBTYPE_COLUMNHEADERBAR:
292 // aRetText = "COLUMNHEADERBAR description";
293 break;
294 case ::svt::BBTYPE_TABLECELL:
295 // aRetText = "TABLECELL description";
296 break;
297 case ::svt::BBTYPE_ROWHEADERCELL:
298 // aRetText = "ROWHEADERCELL description";
299 break;
300 case ::svt::BBTYPE_COLUMNHEADERCELL:
301 // aRetText = "COLUMNHEADERCELL description";
302 break;
303 case ::svt::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 OUString( GetColumnTitle( GetColumnId( _nColumn ) ) );
323 void BrowseBox::FillAccessibleStateSet(
324 ::utl::AccessibleStateSetHelper& rStateSet,
325 ::svt::AccessibleBrowseBoxObjType eObjType ) const
327 switch( eObjType )
329 case ::svt::BBTYPE_BROWSEBOX:
330 case ::svt::BBTYPE_TABLE:
332 rStateSet.AddState( AccessibleStateType::FOCUSABLE );
333 if ( HasFocus() )
334 rStateSet.AddState( AccessibleStateType::FOCUSED );
335 if ( IsActive() )
336 rStateSet.AddState( AccessibleStateType::ACTIVE );
337 if ( GetUpdateMode() )
338 rStateSet.AddState( AccessibleStateType::EDITABLE );
339 if ( IsEnabled() )
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 );
349 break;
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 );
356 break;
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 );
363 break;
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 );
374 break;
375 case ::svt::BBTYPE_ROWHEADERCELL:
376 case ::svt::BBTYPE_COLUMNHEADERCELL:
377 case ::svt::BBTYPE_CHECKBOXCELL:
378 OSL_FAIL("Illegal call here!");
379 break;
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()
398 GrabFocus();
401 OUString BrowseBox::GetCellText(long, sal_uInt16 ) const
403 DBG_ASSERT(false,"This method has to be implemented by the derived classes! BUG!!");
404 return OUString();
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
445 return GetCurRow();
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
460 return true;
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();
493 if( nCount )
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;
523 ++nIndex;
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()
567 return this;
570 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */