1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: brwbox3.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 #include <svtools/brwbox.hxx>
34 #include <svtools/AccessibleBrowseBoxObjType.hxx>
35 #include <tools/debug.hxx>
36 #include <tools/multisel.hxx>
38 #include "brwimpl.hxx"
39 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
40 #include <com/sun/star/accessibility/AccessibleRole.hpp>
41 #include <toolkit/helper/vclunohelper.hxx>
43 // Accessibility ==============================================================
45 using ::rtl::OUString
;
46 using namespace ::com::sun::star::uno
;
47 using ::com::sun::star::accessibility::XAccessible
;
48 using namespace ::com::sun::star::accessibility
;
50 // ============================================================================
53 using namespace ::com::sun::star::lang
;
56 Reference
< XAccessible
> getHeaderCell( BrowseBoxImpl::THeaderCellMap
& _raHeaderCells
,
58 AccessibleBrowseBoxObjType _eType
,
59 const Reference
< XAccessible
>& _rParent
,
60 BrowseBox
& _rBrowseBox
,
61 IAccessibleFactory
& rFactory
64 Reference
< XAccessible
> xRet
;
65 BrowseBoxImpl::THeaderCellMap::iterator aFind
= _raHeaderCells
.find( _nPos
);
66 if ( aFind
== _raHeaderCells
.end() )
68 Reference
< XAccessible
> xAccessible
= rFactory
.createAccessibleBrowseBoxHeaderCell(
75 aFind
= _raHeaderCells
.insert( BrowseBoxImpl::THeaderCellMap::value_type( _nPos
, xAccessible
) ).first
;
77 if ( aFind
!= _raHeaderCells
.end() )
82 // ============================================================================
83 // ----------------------------------------------------------------------------
84 Reference
< XAccessible
> BrowseBoxImpl::getAccessibleHeaderBar( AccessibleBrowseBoxObjType _eObjType
)
86 if ( m_pAccessible
&& m_pAccessible
->isAlive() )
87 return m_pAccessible
->getHeaderBar( _eObjType
);
91 // ----------------------------------------------------------------------------
92 Reference
< XAccessible
> BrowseBoxImpl::getAccessibleTable( )
94 if ( m_pAccessible
&& m_pAccessible
->isAlive() )
95 return m_pAccessible
->getTable( );
100 // ============================================================================
102 Reference
< XAccessible
> BrowseBox::CreateAccessible()
104 Window
* pParent
= GetAccessibleParentWindow();
105 DBG_ASSERT( pParent
, "BrowseBox::CreateAccessible - parent not found" );
107 if( pParent
&& !m_pImpl
->m_pAccessible
)
109 Reference
< XAccessible
> xAccParent
= pParent
->GetAccessible();
110 if( xAccParent
.is() )
112 m_pImpl
->m_pAccessible
= getAccessibleFactory().createAccessibleBrowseBox(
118 Reference
< XAccessible
> xAccessible
;
119 if ( m_pImpl
->m_pAccessible
)
120 xAccessible
= m_pImpl
->m_pAccessible
->getMyself();
124 // -----------------------------------------------------------------------------
126 // Children -------------------------------------------------------------------
128 Reference
< XAccessible
> BrowseBox::CreateAccessibleCell( sal_Int32 _nRow
, sal_uInt16 _nColumnPos
)
130 // BBINDEX_TABLE must be the table
131 OSL_ENSURE(m_pImpl
->m_pAccessible
,"Invalid call: Accessible is null");
133 return m_pImpl
->m_aFactoryAccess
.getFactory().createAccessibleBrowseBoxTableCell(
134 m_pImpl
->getAccessibleTable(),
142 // -----------------------------------------------------------------------------
144 Reference
< XAccessible
> BrowseBox::CreateAccessibleRowHeader( sal_Int32 _nRow
)
146 return svt::getHeaderCell(
147 m_pImpl
->m_aRowHeaderCellMap
,
149 svt::BBTYPE_ROWHEADERCELL
,
150 m_pImpl
->getAccessibleHeaderBar(svt::BBTYPE_ROWHEADERBAR
),
152 m_pImpl
->m_aFactoryAccess
.getFactory()
155 // -----------------------------------------------------------------------------
157 Reference
< XAccessible
> BrowseBox::CreateAccessibleColumnHeader( sal_uInt16 _nColumnPos
)
159 return svt::getHeaderCell(
160 m_pImpl
->m_aColHeaderCellMap
,
162 svt::BBTYPE_COLUMNHEADERCELL
,
163 m_pImpl
->getAccessibleHeaderBar(svt::BBTYPE_COLUMNHEADERBAR
),
165 m_pImpl
->m_aFactoryAccess
.getFactory()
168 // -----------------------------------------------------------------------------
170 sal_Int32
BrowseBox::GetAccessibleControlCount() const
174 // -----------------------------------------------------------------------------
176 Reference
< XAccessible
> BrowseBox::CreateAccessibleControl( sal_Int32
)
178 DBG_ASSERT( FALSE
, "BrowseBox::CreateAccessibleControl: to be overwritten!" );
181 // -----------------------------------------------------------------------------
183 // Conversions ----------------------------------------------------------------
185 sal_Bool
BrowseBox::ConvertPointToCellAddress(
186 sal_Int32
& rnRow
, sal_uInt16
& rnColumnPos
, const Point
& rPoint
)
188 //! TODO has to be checked
189 rnRow
= GetRowAtYPosPixel(rPoint
.Y());
190 rnColumnPos
= GetColumnAtXPosPixel(rPoint
.X());
191 return rnRow
!= BROWSER_INVALIDID
&& rnColumnPos
!= BROWSER_INVALIDID
;
193 // -----------------------------------------------------------------------------
195 sal_Bool
BrowseBox::ConvertPointToRowHeader( sal_Int32
& rnRow
, const Point
& rPoint
)
197 rnRow
= GetRowAtYPosPixel(rPoint
.Y());
198 // USHORT nColumnId = GetColumnAtXPosPixel(rPoint.X());
199 return rnRow
!= BROWSER_INVALIDID
;// && nColumnId == 0;
201 // -----------------------------------------------------------------------------
203 sal_Bool
BrowseBox::ConvertPointToColumnHeader( sal_uInt16
& _rnColumnPos
, const Point
& _rPoint
)
205 _rnColumnPos
= GetColumnAtXPosPixel(_rPoint
.X());
206 return _rnColumnPos
!= BROWSER_INVALIDID
;
208 // -----------------------------------------------------------------------------
210 sal_Bool
BrowseBox::ConvertPointToControlIndex( sal_Int32
& _rnIndex
, const Point
& _rPoint
)
212 //! TODO has to be checked
214 sal_uInt16 nColumn
= 0;
215 sal_Bool bRet
= ConvertPointToCellAddress(nRow
,nColumn
,_rPoint
);
217 _rnIndex
= nRow
* ColCount() + nColumn
;
221 // -----------------------------------------------------------------------------
223 // Object data and state ------------------------------------------------------
225 OUString
BrowseBox::GetAccessibleObjectName( ::svt::AccessibleBrowseBoxObjType eObjType
,sal_Int32
) const
230 case ::svt::BBTYPE_BROWSEBOX
:
231 aRetText
= OUString( RTL_CONSTASCII_USTRINGPARAM( "BrowseBox" ) );
233 case ::svt::BBTYPE_TABLE
:
234 aRetText
= OUString( RTL_CONSTASCII_USTRINGPARAM( "Table" ) );
236 case ::svt::BBTYPE_ROWHEADERBAR
:
237 aRetText
= OUString( RTL_CONSTASCII_USTRINGPARAM( "RowHeaderBar" ) );
239 case ::svt::BBTYPE_COLUMNHEADERBAR
:
240 aRetText
= OUString( RTL_CONSTASCII_USTRINGPARAM( "ColumnHeaderBar" ) );
242 case ::svt::BBTYPE_TABLECELL
:
243 aRetText
= OUString( RTL_CONSTASCII_USTRINGPARAM( "TableCell" ) );
244 #if OSL_DEBUG_LEVEL > 1
245 aRetText
+= OUString( RTL_CONSTASCII_USTRINGPARAM( " [" ) );
246 aRetText
+= OUString::valueOf(sal_Int32(GetCurRow()));
247 aRetText
+= OUString( RTL_CONSTASCII_USTRINGPARAM( "," ) );
248 aRetText
+= OUString::valueOf(sal_Int32(GetCurColumnId()));
249 aRetText
+= OUString( RTL_CONSTASCII_USTRINGPARAM( "]" ) );
252 case ::svt::BBTYPE_ROWHEADERCELL
:
253 aRetText
= OUString( RTL_CONSTASCII_USTRINGPARAM( "RowHeaderCell" ) );
254 #if OSL_DEBUG_LEVEL > 1
255 aRetText
+= OUString( RTL_CONSTASCII_USTRINGPARAM( " [" ) );
256 aRetText
+= OUString::valueOf(sal_Int32(GetCurRow()));
257 aRetText
+= OUString( RTL_CONSTASCII_USTRINGPARAM( "," ) );
258 aRetText
+= OUString::valueOf(sal_Int32(GetCurColumnId()));
259 aRetText
+= OUString( RTL_CONSTASCII_USTRINGPARAM( "]" ) );
262 case ::svt::BBTYPE_COLUMNHEADERCELL
:
263 aRetText
= OUString( RTL_CONSTASCII_USTRINGPARAM( "ColumnHeaderCell" ) );
264 #if OSL_DEBUG_LEVEL > 1
265 aRetText
+= OUString( RTL_CONSTASCII_USTRINGPARAM( " [" ) );
266 aRetText
+= OUString::valueOf(sal_Int32(GetCurRow()));
267 aRetText
+= OUString( RTL_CONSTASCII_USTRINGPARAM( "," ) );
268 aRetText
+= OUString::valueOf(sal_Int32(GetCurColumnId()));
269 aRetText
+= OUString( RTL_CONSTASCII_USTRINGPARAM( "]" ) );
273 OSL_ENSURE(0,"BrowseBox::GetAccessibleName: invalid enum!");
277 // -----------------------------------------------------------------------------
279 OUString
BrowseBox::GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType eObjType
,sal_Int32
) const
284 case ::svt::BBTYPE_BROWSEBOX
:
285 aRetText
= OUString( RTL_CONSTASCII_USTRINGPARAM( "BrowseBox description" ) );
287 case ::svt::BBTYPE_TABLE
:
288 // aRetText = OUString( RTL_CONSTASCII_USTRINGPARAM( "TABLE description" ) );
290 case ::svt::BBTYPE_ROWHEADERBAR
:
291 // aRetText = OUString( RTL_CONSTASCII_USTRINGPARAM( "ROWHEADERBAR description" ) );
293 case ::svt::BBTYPE_COLUMNHEADERBAR
:
294 // aRetText = OUString( RTL_CONSTASCII_USTRINGPARAM( "COLUMNHEADERBAR description" ) );
296 case ::svt::BBTYPE_TABLECELL
:
297 // aRetText = OUString( RTL_CONSTASCII_USTRINGPARAM( "TABLECELL description" ) );
299 case ::svt::BBTYPE_ROWHEADERCELL
:
300 // aRetText = OUString( RTL_CONSTASCII_USTRINGPARAM( "ROWHEADERCELL description" ) );
302 case ::svt::BBTYPE_COLUMNHEADERCELL
:
303 // aRetText = OUString( RTL_CONSTASCII_USTRINGPARAM( "COLUMNHEADERCELL description" ) );
305 case ::svt::BBTYPE_CHECKBOXCELL
:
310 // -----------------------------------------------------------------------------
312 OUString
BrowseBox::GetRowDescription( sal_Int32
) const
316 // -----------------------------------------------------------------------------
318 OUString
BrowseBox::GetColumnDescription( sal_uInt16 _nColumn
) const
320 return OUString( GetColumnTitle( GetColumnId( _nColumn
) ) );
323 // -----------------------------------------------------------------------------
325 void BrowseBox::FillAccessibleStateSet(
326 ::utl::AccessibleStateSetHelper
& rStateSet
,
327 ::svt::AccessibleBrowseBoxObjType eObjType
) const
331 case ::svt::BBTYPE_BROWSEBOX
:
332 case ::svt::BBTYPE_TABLE
:
334 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
336 rStateSet
.AddState( AccessibleStateType::FOCUSED
);
338 rStateSet
.AddState( AccessibleStateType::ACTIVE
);
339 if ( GetUpdateMode() )
340 rStateSet
.AddState( AccessibleStateType::EDITABLE
);
343 rStateSet
.AddState( AccessibleStateType::ENABLED
);
344 rStateSet
.AddState( AccessibleStateType::SENSITIVE
);
346 if ( IsReallyVisible() )
347 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
348 if ( eObjType
== ::svt::BBTYPE_TABLE
)
349 rStateSet
.AddState( AccessibleStateType::MANAGES_DESCENDANTS
);
352 case ::svt::BBTYPE_ROWHEADERBAR
:
353 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
354 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
355 if ( GetSelectRowCount() )
356 rStateSet
.AddState( AccessibleStateType::FOCUSED
);
357 rStateSet
.AddState( AccessibleStateType::MANAGES_DESCENDANTS
);
359 case ::svt::BBTYPE_COLUMNHEADERBAR
:
360 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
361 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
362 if ( GetSelectColumnCount() )
363 rStateSet
.AddState( AccessibleStateType::FOCUSED
);
364 rStateSet
.AddState( AccessibleStateType::MANAGES_DESCENDANTS
);
366 case ::svt::BBTYPE_TABLECELL
:
368 sal_Int32 nRow
= GetCurRow();
369 sal_uInt16 nColumn
= GetCurColumnId();
370 if ( IsFieldVisible(nRow
,nColumn
) )
371 rStateSet
.AddState( AccessibleStateType::VISIBLE
);
372 if ( !IsFrozen( nColumn
) )
373 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
374 rStateSet
.AddState( AccessibleStateType::TRANSIENT
);
377 case ::svt::BBTYPE_ROWHEADERCELL
:
378 case ::svt::BBTYPE_COLUMNHEADERCELL
:
379 case ::svt::BBTYPE_CHECKBOXCELL
:
380 OSL_ENSURE(0,"Illegal call here!");
384 // -----------------------------------------------------------------------
385 void BrowseBox::FillAccessibleStateSetForCell( ::utl::AccessibleStateSetHelper
& _rStateSet
,
386 sal_Int32 _nRow
, sal_uInt16 _nColumnPos
) const
388 //! TODO check if the state is valid for table cells
389 if ( IsCellVisible( _nRow
, _nColumnPos
) )
390 _rStateSet
.AddState( AccessibleStateType::VISIBLE
);
391 if ( GetCurrRow() == _nRow
&& GetCurrColumn() == _nColumnPos
)
392 _rStateSet
.AddState( AccessibleStateType::FOCUSED
);
393 else // only transient when column is not focused
394 _rStateSet
.AddState( AccessibleStateType::TRANSIENT
);
396 // -----------------------------------------------------------------------------
398 void BrowseBox::GrabTableFocus()
402 // -----------------------------------------------------------------------------
403 String
BrowseBox::GetCellText(long, USHORT
) const
405 DBG_ASSERT(0,"This method has to be implemented by the derived classes! BUG!!");
409 // -----------------------------------------------------------------------------
410 void BrowseBox::commitHeaderBarEvent(sal_Int16 nEventId
,
411 const Any
& rNewValue
, const Any
& rOldValue
, sal_Bool _bColumnHeaderBar
)
413 if ( isAccessibleAlive() )
414 m_pImpl
->m_pAccessible
->commitHeaderBarEvent( nEventId
,
415 rNewValue
, rOldValue
, _bColumnHeaderBar
);
418 // -----------------------------------------------------------------------------
419 void BrowseBox::commitTableEvent( sal_Int16 _nEventId
, const Any
& _rNewValue
, const Any
& _rOldValue
)
421 if ( isAccessibleAlive() )
422 m_pImpl
->m_pAccessible
->commitTableEvent( _nEventId
, _rNewValue
, _rOldValue
);
424 // -----------------------------------------------------------------------------
425 void BrowseBox::commitBrowseBoxEvent( sal_Int16 _nEventId
, const Any
& _rNewValue
, const Any
& _rOldValue
)
427 if ( isAccessibleAlive() )
428 m_pImpl
->m_pAccessible
->commitEvent( _nEventId
, _rNewValue
, _rOldValue
);
431 // -----------------------------------------------------------------------------
432 ::svt::IAccessibleFactory
& BrowseBox::getAccessibleFactory()
434 return m_pImpl
->m_aFactoryAccess
.getFactory();
437 // -----------------------------------------------------------------------------
438 sal_Bool
BrowseBox::isAccessibleAlive( ) const
440 return ( NULL
!= m_pImpl
->m_pAccessible
) && m_pImpl
->m_pAccessible
->isAlive();
442 // -----------------------------------------------------------------------------
443 // IAccessibleTableProvider
444 // -----------------------------------------------------------------------------
445 sal_Int32
BrowseBox::GetCurrRow() const
449 // -----------------------------------------------------------------------------
450 sal_uInt16
BrowseBox::GetCurrColumn() const
452 return GetColumnPos( GetCurColumnId() );
454 // -----------------------------------------------------------------------------
455 sal_Bool
BrowseBox::HasRowHeader() const
457 return ( GetColumnId( 0 ) == 0 ); // HandleColumn == RowHeader
459 // -----------------------------------------------------------------------------
460 sal_Bool
BrowseBox::IsCellFocusable() const
464 // -----------------------------------------------------------------------------
465 sal_Bool
BrowseBox::GoToCell( sal_Int32 _nRow
, sal_uInt16 _nColumn
)
467 return GoToRowColumnId( _nRow
, GetColumnId( _nColumn
) );
469 // -----------------------------------------------------------------------------
470 void BrowseBox::SelectColumn( sal_uInt16 _nColumn
, sal_Bool _bSelect
)
472 SelectColumnPos( _nColumn
, _bSelect
);
474 // -----------------------------------------------------------------------------
475 sal_Bool
BrowseBox::IsColumnSelected( long _nColumn
) const
477 return ( pColSel
&& (0 <= _nColumn
) && (_nColumn
<= 0xFFF) ) ?
478 pColSel
->IsSelected( static_cast< sal_uInt16
>( _nColumn
) ) :
481 // -----------------------------------------------------------------------------
482 sal_Int32
BrowseBox::GetSelectedRowCount() const
484 return GetSelectRowCount();
486 // -----------------------------------------------------------------------------
487 sal_Int32
BrowseBox::GetSelectedColumnCount() const
489 const MultiSelection
* pColumnSel
= GetColumnSelection();
490 return pColumnSel
? pColumnSel
->GetSelectCount() : 0;
492 // -----------------------------------------------------------------------------
493 void BrowseBox::GetAllSelectedRows( ::com::sun::star::uno::Sequence
< sal_Int32
>& _rRows
) const
495 sal_Int32 nCount
= GetSelectRowCount();
498 _rRows
.realloc( nCount
);
499 _rRows
[ 0 ] = const_cast< BrowseBox
* >( this )->FirstSelectedRow();
500 for( sal_Int32 nIndex
= 1; nIndex
< nCount
; ++nIndex
)
501 _rRows
[ nIndex
] = const_cast< BrowseBox
* >( this )->NextSelectedRow();
502 DBG_ASSERT( const_cast< BrowseBox
* >( this )->NextSelectedRow() == BROWSER_ENDOFSELECTION
,
503 "BrowseBox::GetAllSelectedRows - too many selected rows found" );
506 // -----------------------------------------------------------------------------
507 void BrowseBox::GetAllSelectedColumns( ::com::sun::star::uno::Sequence
< sal_Int32
>& _rColumns
) const
509 const MultiSelection
* pColumnSel
= GetColumnSelection();
510 sal_Int32 nCount
= GetSelectedColumnCount();
511 if( pColumnSel
&& nCount
)
513 _rColumns
.realloc( nCount
);
515 sal_Int32 nIndex
= 0;
516 sal_uInt32 nRangeCount
= pColumnSel
->GetRangeCount();
517 for( sal_uInt32 nRange
= 0; nRange
< nRangeCount
; ++nRange
)
519 const Range
& rRange
= pColumnSel
->GetRange( nRange
);
520 // loop has to include aRange.Max()
521 for( sal_Int32 nCol
= rRange
.Min(); nCol
<= rRange
.Max(); ++nCol
)
523 DBG_ASSERT( nIndex
< nCount
,
524 "GetAllSelectedColumns - range overflow" );
525 _rColumns
[ nIndex
] = nCol
;
531 // -----------------------------------------------------------------------------
532 sal_Bool
BrowseBox::IsCellVisible( sal_Int32 _nRow
, sal_uInt16 _nColumnPos
) const
534 return IsFieldVisible( _nRow
, GetColumnId( _nColumnPos
) );
536 // -----------------------------------------------------------------------------
537 String
BrowseBox::GetAccessibleCellText(long _nRow
, USHORT _nColPos
) const
539 return GetCellText( _nRow
, GetColumnId( _nColPos
) );
542 // -----------------------------------------------------------------------------
543 BOOL
BrowseBox::GetGlyphBoundRects( const Point
& rOrigin
, const String
& rStr
, int nIndex
, int nLen
, int nBase
, MetricVector
& rVector
)
545 return Control::GetGlyphBoundRects( rOrigin
, rStr
, nIndex
, nLen
, nBase
, rVector
);
547 // -----------------------------------------------------------------------------
548 Rectangle
BrowseBox::GetWindowExtentsRelative( Window
*pRelativeWindow
)
550 return Control::GetWindowExtentsRelative( pRelativeWindow
);
552 // -----------------------------------------------------------------------------
553 void BrowseBox::GrabFocus()
555 Control::GrabFocus();
557 // -----------------------------------------------------------------------------
558 Reference
< XAccessible
> BrowseBox::GetAccessible( BOOL bCreate
)
560 return Control::GetAccessible( bCreate
);
562 // -----------------------------------------------------------------------------
563 Window
* BrowseBox::GetAccessibleParentWindow() const
565 return Control::GetAccessibleParentWindow();
567 // -----------------------------------------------------------------------------
568 Window
* BrowseBox::GetWindowInstance()