1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/svtabbx.hxx>
21 #include <svtools/headbar.hxx>
22 #include <svtools/svtresid.hxx>
23 #include <svtools/svlbitm.hxx>
24 #include <svtools/svtools.hrc>
25 #include <svtools/treelistentry.hxx>
26 #include <vcl/builder.hxx>
27 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
28 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
29 #include "svtaccessiblefactory.hxx"
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::accessibility
;
35 ( SV_LBOXTAB_ADJUST_RIGHT | SV_LBOXTAB_ADJUST_LEFT | SV_LBOXTAB_ADJUST_CENTER | SV_LBOXTAB_ADJUST_NUMERIC )
37 // SvTreeListBox callback
39 void SvTabListBox::SetTabs()
41 SvTreeListBox::SetTabs();
44 DBG_ASSERT(pTabList
,"TabList ?");
46 // The tree listbox has now inserted its tabs into the list. Now we
47 // fluff up the list with additional tabs and adjust the rightmost tab
48 // of the tree listbox.
50 // Picking the rightmost tab.
51 // HACK for the explorer! If ViewParent != 0, the first tab of the tree
52 // listbox is calculated by the tre listbox itself! This behavior is
53 // necessary for ButtonsOnRoot, as the explorer does not know in this
54 // case, which additional offset it need to add to the tabs in this mode
55 // -- the tree listbox knows that, though!
59 SvLBoxTab* pFirstTab = (SvLBoxTab*)aTabs.GetObject( aTabs.Count()-1 );
60 pFirstTab->SetPos( pTabList[0].GetPos() );
61 pFirstTab->nFlags &= ~MYTABMASK;
62 pFirstTab->nFlags |= pTabList[0].nFlags;
66 // append all other tabs to the list
67 for( sal_uInt16 nCurTab
= 1; nCurTab
< nTabCount
; nCurTab
++ )
69 SvLBoxTab
* pTab
= pTabList
+nCurTab
;
70 AddTab( pTab
->GetPos(), pTab
->nFlags
);
75 void SvTabListBox::InitEntry(SvTreeListEntry
* pEntry
, const OUString
& rStr
,
76 const Image
& rColl
, const Image
& rExp
, SvLBoxButtonKind eButtonKind
)
78 SvTreeListBox::InitEntry(pEntry
, rStr
, rColl
, rExp
, eButtonKind
);
81 // TODO: verify if nTabCount is always >0 here!
82 const sal_uInt16 nCount
= nTabCount
- 1;
83 for( sal_uInt16 nToken
= 0; nToken
< nCount
; nToken
++ )
85 const OUString aToken
= GetToken(aCurEntry
, nIndex
);
86 SvLBoxString
* pStr
= new SvLBoxString( pEntry
, 0, aToken
);
87 pEntry
->AddItem( pStr
);
92 SvTabListBox::SvTabListBox( Window
* pParent
, WinBits nBits
)
93 : SvTreeListBox( pParent
, nBits
)
98 SetHighlightRange(); // select full width
101 extern "C" SAL_DLLPUBLIC_EXPORT Window
* SAL_CALL
makeSvTabListBox(Window
*pParent
,
102 VclBuilder::stringmap
&rMap
)
104 WinBits nWinStyle
= WB_TABSTOP
;
105 OString sBorder
= VclBuilder::extractCustomProperty(rMap
);
106 if (!sBorder
.isEmpty())
107 nWinStyle
|= WB_BORDER
;
108 return new SvTabListBox(pParent
, nWinStyle
);
111 SvTabListBox::SvTabListBox( Window
* pParent
, const ResId
& rResId
)
112 : SvTreeListBox( pParent
, rResId
)
117 SvTabListBox::Resize();
121 SvTabListBox::~SvTabListBox()
131 void SvTabListBox::SetTabs( long* pTabs
, MapUnit eMapUnit
)
133 DBG_ASSERT(pTabs
,"SetTabs:NULL-Ptr");
138 sal_uInt16 nCount
= (sal_uInt16
)(*pTabs
);
139 pTabList
= new SvLBoxTab
[ nCount
];
142 MapMode
aMMSource( eMapUnit
);
143 MapMode
aMMDest( MAP_PIXEL
);
146 for( sal_uInt16 nIdx
= 0; nIdx
< nCount
; nIdx
++, pTabs
++ )
148 Size
aSize( *pTabs
, 0 );
149 aSize
= LogicToLogic( aSize
, &aMMSource
, &aMMDest
);
150 long nNewTab
= aSize
.Width();
151 pTabList
[nIdx
].SetPos( nNewTab
);
152 pTabList
[nIdx
].nFlags
=(SV_LBOXTAB_ADJUST_LEFT
| SV_LBOXTAB_INV_ALWAYS
);
154 SvTreeListBox::nTreeFlags
|= TREEFLAG_RECALCTABS
;
159 void SvTabListBox::SetTab( sal_uInt16 nTab
,long nValue
,MapUnit eMapUnit
)
161 DBG_ASSERT(nTab
<nTabCount
,"Invalid Tab-Pos");
162 if( nTab
< nTabCount
)
164 DBG_ASSERT(pTabList
,"TabList?");
165 MapMode
aMMSource( eMapUnit
);
166 MapMode
aMMDest( MAP_PIXEL
);
167 Size
aSize( nValue
, 0 );
168 aSize
= LogicToLogic( aSize
, &aMMSource
, &aMMDest
);
169 nValue
= aSize
.Width();
170 pTabList
[ nTab
].SetPos( nValue
);
171 SvTreeListBox::nTreeFlags
|= TREEFLAG_RECALCTABS
;
177 SvTreeListEntry
* SvTabListBox::InsertEntry( const OUString
& rText
, SvTreeListEntry
* pParent
,
178 sal_Bool
/*bChildrenOnDemand*/,
179 sal_uLong nPos
, void* pUserData
,
182 return InsertEntryToColumn( rText
, pParent
, nPos
, 0xffff, pUserData
);
185 SvTreeListEntry
* SvTabListBox::InsertEntry( const OUString
& rText
,
186 const Image
& rExpandedEntryBmp
,
187 const Image
& rCollapsedEntryBmp
,
188 SvTreeListEntry
* pParent
,
189 sal_Bool
/*bChildrenOnDemand*/,
190 sal_uLong nPos
, void* pUserData
,
193 return InsertEntryToColumn( rText
, rExpandedEntryBmp
, rCollapsedEntryBmp
,
194 pParent
, nPos
, 0xffff, pUserData
);
197 SvTreeListEntry
* SvTabListBox::InsertEntryToColumn(const OUString
& rStr
,SvTreeListEntry
* pParent
,sal_uLong nPos
,sal_uInt16 nCol
,
210 OUString
aFirstStr( aStr
);
211 sal_Int32 nEnd
= aFirstStr
.indexOf( '\t' );
214 aFirstStr
= aFirstStr
.copy(0, nEnd
);
215 aCurEntry
= aStr
.copy(++nEnd
);
218 aCurEntry
= OUString();
219 return SvTreeListBox::InsertEntry( aFirstStr
, pParent
, sal_False
, nPos
, pUser
);
222 SvTreeListEntry
* SvTabListBox::InsertEntryToColumn( const OUString
& rStr
,
223 const Image
& rExpandedEntryBmp
, const Image
& rCollapsedEntryBmp
,
224 SvTreeListEntry
* pParent
,sal_uLong nPos
,sal_uInt16 nCol
, void* pUser
)
236 OUString
aFirstStr( aStr
);
237 sal_Int32 nEnd
= aFirstStr
.indexOf('\t');
240 aFirstStr
= aFirstStr
.copy(0, nEnd
);
241 aCurEntry
= aStr
.copy(++nEnd
);
244 aCurEntry
= OUString();
246 return SvTreeListBox::InsertEntry(
248 rExpandedEntryBmp
, rCollapsedEntryBmp
,
249 pParent
, sal_False
, nPos
, pUser
);
252 SvTreeListEntry
* SvTabListBox::InsertEntryToColumn( const OUString
& rStr
, sal_uLong nPos
,
253 sal_uInt16 nCol
, void* pUser
)
255 return InsertEntryToColumn( rStr
,0,nPos
, nCol
, pUser
);
258 OUString
SvTabListBox::GetEntryText( SvTreeListEntry
* pEntry
) const
260 return GetEntryText( pEntry
, 0xffff );
263 OUString
SvTabListBox::GetEntryText( SvTreeListEntry
* pEntry
, sal_uInt16 nCol
) const
265 DBG_ASSERT(pEntry
,"GetEntryText:Invalid Entry");
269 sal_uInt16 nCount
= pEntry
->ItemCount();
271 while( nCur
< nCount
)
273 const SvLBoxItem
* pStr
= pEntry
->GetItem( nCur
);
274 if (pStr
->GetType() == SV_ITEM_ID_LBOXSTRING
)
278 if (!aResult
.isEmpty())
280 aResult
+= static_cast<const SvLBoxString
*>(pStr
)->GetText();
285 return static_cast<const SvLBoxString
*>(pStr
)->GetText();
295 OUString
SvTabListBox::GetEntryText( sal_uLong nPos
, sal_uInt16 nCol
) const
297 SvTreeListEntry
* pEntry
= GetEntryOnPos( nPos
);
298 return GetEntryText( pEntry
, nCol
);
301 void SvTabListBox::SetEntryText(const OUString
& rStr
, sal_uLong nPos
, sal_uInt16 nCol
)
303 SvTreeListEntry
* pEntry
= SvTreeListBox::GetEntry( nPos
);
304 SetEntryText( rStr
, pEntry
, nCol
);
307 void SvTabListBox::SetEntryText(const OUString
& rStr
, SvTreeListEntry
* pEntry
, sal_uInt16 nCol
)
309 DBG_ASSERT(pEntry
,"SetEntryText:Invalid Entry");
313 OUString sOldText
= GetEntryText(pEntry
, nCol
);
314 if (sOldText
== rStr
)
317 sal_Int32 nIndex
= 0;
318 const sal_uInt16 nTextColumn
= nCol
;
319 const sal_uInt16 nCount
= pEntry
->ItemCount();
320 for (sal_uInt16 nCur
= 0; nCur
< nCount
; ++nCur
)
322 SvLBoxItem
* pStr
= pEntry
->GetItem( nCur
);
323 if (pStr
&& pStr
->GetType() == SV_ITEM_ID_LBOXSTRING
)
325 if (!nCol
|| nCol
==0xFFFF)
327 const OUString
aTemp(GetToken(rStr
, nIndex
));
328 ((SvLBoxString
*)pStr
)->SetText( aTemp
);
329 if (!nCol
&& nIndex
<0)
338 GetModel()->InvalidateEntry( pEntry
);
340 TabListBoxEventData
* pData
= new TabListBoxEventData( pEntry
, nTextColumn
, sOldText
);
341 ImplCallEventListeners( VCLEVENT_TABLECELL_NAMECHANGED
, pData
);
345 OUString
SvTabListBox::GetCellText( sal_uLong nPos
, sal_uInt16 nCol
) const
347 SvTreeListEntry
* pEntry
= GetEntryOnPos( nPos
);
348 DBG_ASSERT( pEntry
, "SvTabListBox::GetCellText(): Invalid Entry" );
350 if (pEntry
&& pEntry
->ItemCount() > static_cast<size_t>(nCol
+1))
352 const SvLBoxItem
* pStr
= pEntry
->GetItem( nCol
+ 1 );
353 if (pStr
&& pStr
->GetType() == SV_ITEM_ID_LBOXSTRING
)
354 aResult
= static_cast<const SvLBoxString
*>(pStr
)->GetText();
359 sal_uLong
SvTabListBox::GetEntryPos( const OUString
& rStr
, sal_uInt16 nCol
)
362 SvTreeListEntry
* pEntry
= First();
365 OUString
aStr( GetEntryText( pEntry
, nCol
));
368 pEntry
= Next( pEntry
);
374 sal_uLong
SvTabListBox::GetEntryPos( const SvTreeListEntry
* pEntry
) const
377 SvTreeListEntry
* pTmpEntry
= First();
380 if ( pTmpEntry
== pEntry
)
382 pTmpEntry
= Next( pTmpEntry
);
388 void SvTabListBox::Resize()
390 SvTreeListBox::Resize();
394 OUString
SvTabListBox::GetToken( const OUString
&sStr
, sal_Int32
& nIndex
)
396 return sStr
.getToken(0, '\t', nIndex
);
399 OUString
SvTabListBox::GetTabEntryText( sal_uLong nPos
, sal_uInt16 nCol
) const
401 SvTreeListEntry
* pEntry
= SvTreeListBox::GetEntry( nPos
);
402 DBG_ASSERT( pEntry
, "GetTabEntryText(): Invalid entry " );
406 sal_uInt16 nCount
= pEntry
->ItemCount();
407 sal_uInt16 nCur
= ( 0 == nCol
&& IsCellFocusEnabled() ) ? GetCurrentTabPos() : 0;
408 while( nCur
< nCount
)
410 const SvLBoxItem
* pStr
= pEntry
->GetItem( nCur
);
411 if (pStr
->GetType() == SV_ITEM_ID_LBOXSTRING
)
413 if ( nCol
== 0xffff )
415 if (!aResult
.isEmpty())
417 aResult
+= static_cast<const SvLBoxString
*>(pStr
)->GetText();
423 OUString sRet
= static_cast<const SvLBoxString
*>(pStr
)->GetText();
424 if ( sRet
.isEmpty() )
425 sRet
= SVT_RESSTR( STR_SVT_ACC_EMPTY_FIELD
);
437 SvTreeListEntry
* SvTabListBox::GetEntryOnPos( sal_uLong _nEntryPos
) const
439 SvTreeListEntry
* pEntry
= NULL
;
440 sal_uLong i
, nPos
= 0, nCount
= GetLevelChildCount( NULL
);
441 for ( i
= 0; i
< nCount
; ++i
)
443 SvTreeListEntry
* pParent
= GetEntry(i
);
444 if ( nPos
== _nEntryPos
)
452 pEntry
= GetChildOnPos( pParent
, _nEntryPos
, nPos
);
461 SvTreeListEntry
* SvTabListBox::GetChildOnPos( SvTreeListEntry
* _pParent
, sal_uLong _nEntryPos
, sal_uLong
& _rPos
) const
463 sal_uLong i
, nCount
= GetLevelChildCount( _pParent
);
464 for ( i
= 0; i
< nCount
; ++i
)
466 SvTreeListEntry
* pParent
= GetEntry( _pParent
, i
);
467 if ( _rPos
== _nEntryPos
)
472 SvTreeListEntry
* pEntry
= GetChildOnPos( pParent
, _nEntryPos
, _rPos
);
481 void SvTabListBox::SetTabJustify( sal_uInt16 nTab
, SvTabJustify eJustify
)
483 if( nTab
>= nTabCount
)
485 SvLBoxTab
* pTab
= &(pTabList
[ nTab
]);
486 sal_uInt16 nFlags
= pTab
->nFlags
;
487 nFlags
&= (~MYTABMASK
);
488 nFlags
|= (sal_uInt16
)eJustify
;
489 pTab
->nFlags
= nFlags
;
490 SvTreeListBox::nTreeFlags
|= TREEFLAG_RECALCTABS
;
495 long SvTabListBox::GetLogicTab( sal_uInt16 nTab
)
497 if( SvTreeListBox::nTreeFlags
& TREEFLAG_RECALCTABS
)
498 ((SvTabListBox
*)this)->SetTabs();
500 DBG_ASSERT(nTab
<nTabCount
,"GetTabPos:Invalid Tab");
501 return aTabs
[ nTab
]->GetPos();
504 // class SvHeaderTabListBoxImpl ------------------------------------------
508 struct SvHeaderTabListBoxImpl
510 HeaderBar
* m_pHeaderBar
;
511 AccessibleFactoryAccess m_aFactoryAccess
;
513 SvHeaderTabListBoxImpl() : m_pHeaderBar( NULL
) { }
517 // class SvHeaderTabListBox ----------------------------------------------
519 SvHeaderTabListBox::SvHeaderTabListBox( Window
* pParent
, WinBits nWinStyle
) :
521 SvTabListBox( pParent
, nWinStyle
),
523 m_bFirstPaint ( sal_True
),
524 m_pImpl ( new ::svt::SvHeaderTabListBoxImpl
),
525 m_pAccessible ( NULL
)
529 // -----------------------------------------------------------------------
531 SvHeaderTabListBox::SvHeaderTabListBox( Window
* pParent
, const ResId
& rResId
) :
533 SvTabListBox( pParent
, rResId
),
535 m_bFirstPaint ( sal_True
),
536 m_pImpl ( new ::svt::SvHeaderTabListBoxImpl
),
537 m_pAccessible ( NULL
)
541 // -----------------------------------------------------------------------
543 SvHeaderTabListBox::~SvHeaderTabListBox()
548 // -----------------------------------------------------------------------
550 void SvHeaderTabListBox::Paint( const Rectangle
& rRect
)
554 m_bFirstPaint
= sal_False
;
557 SvTabListBox::Paint( rRect
);
560 // -----------------------------------------------------------------------
562 void SvHeaderTabListBox::InitHeaderBar( HeaderBar
* pHeaderBar
)
564 DBG_ASSERT( !m_pImpl
->m_pHeaderBar
, "header bar already initialized" );
565 DBG_ASSERT( pHeaderBar
, "invalid header bar initialization" );
566 m_pImpl
->m_pHeaderBar
= pHeaderBar
;
567 SetScrolledHdl( LINK( this, SvHeaderTabListBox
, ScrollHdl_Impl
) );
568 m_pImpl
->m_pHeaderBar
->SetCreateAccessibleHdl( LINK( this, SvHeaderTabListBox
, CreateAccessibleHdl_Impl
) );
571 // -----------------------------------------------------------------------
573 sal_Bool
SvHeaderTabListBox::IsItemChecked( SvTreeListEntry
* pEntry
, sal_uInt16 nCol
) const
575 SvButtonState eState
= SV_BUTTON_UNCHECKED
;
576 SvLBoxButton
* pItem
= (SvLBoxButton
*)( pEntry
->GetItem( nCol
+ 1 ) );
578 if (pItem
&& pItem
->GetType() == SV_ITEM_ID_LBOXBUTTON
)
580 sal_uInt16 nButtonFlags
= pItem
->GetButtonFlags();
581 eState
= pCheckButtonData
->ConvertToButtonState( nButtonFlags
);
584 return ( eState
== SV_BUTTON_CHECKED
);
587 // -----------------------------------------------------------------------
589 SvTreeListEntry
* SvHeaderTabListBox::InsertEntryToColumn(
590 const OUString
& rStr
, sal_uLong nPos
, sal_uInt16 nCol
, void* pUserData
)
592 SvTreeListEntry
* pEntry
= SvTabListBox::InsertEntryToColumn( rStr
, nPos
, nCol
, pUserData
);
593 RecalculateAccessibleChildren();
597 // -----------------------------------------------------------------------
599 SvTreeListEntry
* SvHeaderTabListBox::InsertEntryToColumn(
600 const OUString
& rStr
, SvTreeListEntry
* pParent
, sal_uLong nPos
, sal_uInt16 nCol
, void* pUserData
)
602 SvTreeListEntry
* pEntry
= SvTabListBox::InsertEntryToColumn( rStr
, pParent
, nPos
, nCol
, pUserData
);
603 RecalculateAccessibleChildren();
607 // -----------------------------------------------------------------------
609 SvTreeListEntry
* SvHeaderTabListBox::InsertEntryToColumn(
610 const OUString
& rStr
, const Image
& rExpandedEntryBmp
, const Image
& rCollapsedEntryBmp
,
611 SvTreeListEntry
* pParent
, sal_uLong nPos
, sal_uInt16 nCol
, void* pUserData
)
613 SvTreeListEntry
* pEntry
= SvTabListBox::InsertEntryToColumn(
614 rStr
, rExpandedEntryBmp
, rCollapsedEntryBmp
, pParent
, nPos
, nCol
, pUserData
);
615 RecalculateAccessibleChildren();
619 // -----------------------------------------------------------------------
621 sal_uLong
SvHeaderTabListBox::Insert(
622 SvTreeListEntry
* pEnt
, SvTreeListEntry
* pPar
, sal_uLong nPos
)
624 sal_uLong n
= SvTabListBox::Insert( pEnt
, pPar
, nPos
);
625 RecalculateAccessibleChildren();
629 // -----------------------------------------------------------------------
631 sal_uLong
SvHeaderTabListBox::Insert( SvTreeListEntry
* pEntry
, sal_uLong nRootPos
)
633 sal_uLong nPos
= SvTabListBox::Insert( pEntry
, nRootPos
);
634 RecalculateAccessibleChildren();
638 // -----------------------------------------------------------------------
640 void SvHeaderTabListBox::RemoveEntry( SvTreeListEntry
* _pEntry
)
642 GetModel()->Remove( _pEntry
);
643 m_aAccessibleChildren
.clear();
646 // -----------------------------------------------------------------------
648 void SvHeaderTabListBox::Clear()
650 SvTabListBox::Clear();
651 m_aAccessibleChildren
.clear();
654 // -----------------------------------------------------------------------
656 IMPL_LINK_NOARG(SvHeaderTabListBox
, ScrollHdl_Impl
)
658 m_pImpl
->m_pHeaderBar
->SetOffset( -GetXOffset() );
662 // -----------------------------------------------------------------------
664 IMPL_LINK_NOARG(SvHeaderTabListBox
, CreateAccessibleHdl_Impl
)
666 Window
* pParent
= m_pImpl
->m_pHeaderBar
->GetAccessibleParentWindow();
667 DBG_ASSERT( pParent
, "SvHeaderTabListBox..CreateAccessibleHdl_Impl - accessible parent not found" );
670 ::com::sun::star::uno::Reference
< XAccessible
> xAccParent
= pParent
->GetAccessible();
671 if ( xAccParent
.is() )
673 Reference
< XAccessible
> xAccessible
= m_pImpl
->m_aFactoryAccess
.getFactory().createAccessibleBrowseBoxHeaderBar(
674 xAccParent
, *this, ::svt::BBTYPE_COLUMNHEADERBAR
);
675 m_pImpl
->m_pHeaderBar
->SetAccessible( xAccessible
);
681 // -----------------------------------------------------------------------
683 void SvHeaderTabListBox::RecalculateAccessibleChildren()
685 if ( !m_aAccessibleChildren
.empty() )
687 sal_uInt32 nCount
= ( GetRowCount() + 1 ) * GetColumnCount();
688 if ( m_aAccessibleChildren
.size() < nCount
)
689 m_aAccessibleChildren
.resize( nCount
);
692 DBG_ASSERT( m_aAccessibleChildren
.size() == nCount
, "wrong children count" );
697 // -----------------------------------------------------------------------
699 sal_Bool
SvHeaderTabListBox::IsCellCheckBox( long _nRow
, sal_uInt16 _nColumn
, TriState
& _rState
)
702 SvTreeListEntry
* pEntry
= GetEntry( _nRow
);
705 sal_uInt16 nItemCount
= pEntry
->ItemCount();
706 if ( nItemCount
> ( _nColumn
+ 1 ) )
708 SvLBoxButton
* pItem
= (SvLBoxButton
*)( pEntry
->GetItem( _nColumn
+ 1 ) );
709 if (pItem
&& pItem
->GetType() == SV_ITEM_ID_LBOXBUTTON
)
712 _rState
= ( ( pItem
->GetButtonFlags() & SV_ITEMSTATE_UNCHECKED
) == 0 )
713 ? STATE_CHECK
: STATE_NOCHECK
;
718 SAL_WARN( "svtools.contnr", "SvHeaderTabListBox::IsCellCheckBox(): column out of range" );
724 // -----------------------------------------------------------------------
725 long SvHeaderTabListBox::GetRowCount() const
727 return GetEntryCount();
729 // -----------------------------------------------------------------------
730 sal_uInt16
SvHeaderTabListBox::GetColumnCount() const
732 return m_pImpl
->m_pHeaderBar
->GetItemCount();
734 // -----------------------------------------------------------------------
735 sal_Int32
SvHeaderTabListBox::GetCurrRow() const
738 SvTreeListEntry
* pEntry
= GetCurEntry();
741 sal_uLong nCount
= GetEntryCount();
742 for ( sal_uLong i
= 0; i
< nCount
; ++i
)
744 if ( pEntry
== GetEntry(i
) )
754 // -----------------------------------------------------------------------
755 sal_uInt16
SvHeaderTabListBox::GetCurrColumn() const
757 sal_uInt16 nPos
= GetCurrentTabPos() - 1;
760 // -----------------------------------------------------------------------
761 OUString
SvHeaderTabListBox::GetRowDescription( sal_Int32 _nRow
) const
763 return OUString( GetEntryText( _nRow
) );
765 // -----------------------------------------------------------------------
766 OUString
SvHeaderTabListBox::GetColumnDescription( sal_uInt16 _nColumn
) const
768 return OUString( m_pImpl
->m_pHeaderBar
->GetItemText( m_pImpl
->m_pHeaderBar
->GetItemId( _nColumn
) ) );
770 // -----------------------------------------------------------------------
771 sal_Bool
SvHeaderTabListBox::HasRowHeader() const
775 // -----------------------------------------------------------------------
776 sal_Bool
SvHeaderTabListBox::IsCellFocusable() const
778 return IsCellFocusEnabled();
780 // -----------------------------------------------------------------------
781 sal_Bool
SvHeaderTabListBox::GoToCell( sal_Int32 _nRow
, sal_uInt16 _nColumn
)
783 sal_Bool bRet
= ( IsCellFocusEnabled() == sal_True
);
786 // first set cursor to _nRow
787 SetCursor( GetEntry( _nRow
), sal_True
);
788 // then set the focus into _nColumn
789 bRet
= ( SetCurrentTabPos( _nColumn
) == true );
793 // -----------------------------------------------------------------------
794 void SvHeaderTabListBox::SetNoSelection()
796 SvTreeListBox::SelectAll(false);
798 // -----------------------------------------------------------------------
799 void SvHeaderTabListBox::SelectAll()
801 SvTreeListBox::SelectAll(true);
803 // -----------------------------------------------------------------------
804 void SvHeaderTabListBox::SelectAll( sal_Bool bSelect
, sal_Bool bPaint
)
806 // overwritten just to disambiguate the SelectAll() from the base' class SelectAll( BOOl, sal_Bool )
807 SvTabListBox::SelectAll( bSelect
, bPaint
);
810 // -----------------------------------------------------------------------
811 void SvHeaderTabListBox::SelectRow( long _nRow
, sal_Bool _bSelect
, sal_Bool
)
813 Select( GetEntry( _nRow
), _bSelect
);
815 // -----------------------------------------------------------------------
816 void SvHeaderTabListBox::SelectColumn( sal_uInt16
, sal_Bool
)
819 // -----------------------------------------------------------------------
820 sal_Int32
SvHeaderTabListBox::GetSelectedRowCount() const
822 return GetSelectionCount();
824 // -----------------------------------------------------------------------
825 sal_Int32
SvHeaderTabListBox::GetSelectedColumnCount() const
829 // -----------------------------------------------------------------------
830 bool SvHeaderTabListBox::IsRowSelected( long _nRow
) const
832 SvTreeListEntry
* pEntry
= GetEntry( _nRow
);
833 return ( pEntry
&& IsSelected( pEntry
) );
835 // -----------------------------------------------------------------------
836 sal_Bool
SvHeaderTabListBox::IsColumnSelected( long ) const
840 // -----------------------------------------------------------------------
841 void SvHeaderTabListBox::GetAllSelectedRows( ::com::sun::star::uno::Sequence
< sal_Int32
>& ) const
844 // -----------------------------------------------------------------------
845 void SvHeaderTabListBox::GetAllSelectedColumns( ::com::sun::star::uno::Sequence
< sal_Int32
>& ) const
848 // -----------------------------------------------------------------------
849 sal_Bool
SvHeaderTabListBox::IsCellVisible( sal_Int32
, sal_uInt16
) const
853 // -----------------------------------------------------------------------
854 OUString
SvHeaderTabListBox::GetAccessibleCellText( long _nRow
, sal_uInt16 _nColumnPos
) const
856 return GetTabEntryText(_nRow
, _nColumnPos
);
858 // -----------------------------------------------------------------------
859 Rectangle
SvHeaderTabListBox::calcHeaderRect( sal_Bool _bIsColumnBar
, sal_Bool _bOnScreen
)
864 Window
* pParent
= NULL
;
866 pParent
= m_pImpl
->m_pHeaderBar
->GetAccessibleParentWindow();
868 aRect
= m_pImpl
->m_pHeaderBar
->GetWindowExtentsRelative( pParent
);
872 // -----------------------------------------------------------------------
873 Rectangle
SvHeaderTabListBox::calcTableRect( sal_Bool _bOnScreen
)
875 Window
* pParent
= NULL
;
877 pParent
= GetAccessibleParentWindow();
879 Rectangle
aRect( GetWindowExtentsRelative( pParent
) );
882 // -----------------------------------------------------------------------
883 Rectangle
SvHeaderTabListBox::GetFieldRectPixelAbs( sal_Int32 _nRow
, sal_uInt16 _nColumn
, sal_Bool _bIsHeader
, sal_Bool _bOnScreen
)
885 DBG_ASSERT( !_bIsHeader
|| 0 == _nRow
, "invalid parameters" );
887 SvTreeListEntry
* pEntry
= GetEntry( _nRow
);
890 aRect
= _bIsHeader
? calcHeaderRect( sal_True
, sal_False
) : GetBoundingRect( pEntry
);
891 Point aTopLeft
= aRect
.TopLeft();
892 DBG_ASSERT( m_pImpl
->m_pHeaderBar
->GetItemCount() > _nColumn
, "invalid column" );
893 Rectangle aItemRect
= m_pImpl
->m_pHeaderBar
->GetItemRect( m_pImpl
->m_pHeaderBar
->GetItemId( _nColumn
) );
894 aTopLeft
.X() = aItemRect
.Left();
895 Size aSize
= aItemRect
.GetSize();
896 aRect
= Rectangle( aTopLeft
, aSize
);
897 Window
* pParent
= NULL
;
899 pParent
= GetAccessibleParentWindow();
900 aTopLeft
= aRect
.TopLeft();
901 aTopLeft
+= GetWindowExtentsRelative( pParent
).TopLeft();
902 aRect
= Rectangle( aTopLeft
, aRect
.GetSize() );
907 // -----------------------------------------------------------------------
908 Reference
< XAccessible
> SvHeaderTabListBox::CreateAccessibleCell( sal_Int32 _nRow
, sal_uInt16 _nColumnPos
)
910 OSL_ENSURE( m_pAccessible
, "Invalid call: Accessible is null" );
912 Reference
< XAccessible
> xChild
;
913 sal_Int32 nIndex
= -1;
915 if ( !AreChildrenTransient() )
917 const sal_uInt16 nColumnCount
= GetColumnCount();
919 // first call? -> initial list
920 if ( m_aAccessibleChildren
.empty() )
922 sal_Int32 nCount
= ( GetRowCount() + 1 ) * nColumnCount
;
923 m_aAccessibleChildren
.assign( nCount
, Reference
< XAccessible
>() );
926 nIndex
= ( _nRow
* nColumnCount
) + _nColumnPos
+ nColumnCount
;
927 xChild
= m_aAccessibleChildren
[ nIndex
];
932 TriState eState
= STATE_DONTKNOW
;
933 sal_Bool bIsCheckBox
= IsCellCheckBox( _nRow
, _nColumnPos
, eState
);
935 xChild
= m_pImpl
->m_aFactoryAccess
.getFactory().createAccessibleCheckBoxCell(
936 m_pAccessible
->getAccessibleChild( 0 ), *this, NULL
, _nRow
, _nColumnPos
, eState
, sal_False
);
938 xChild
= m_pImpl
->m_aFactoryAccess
.getFactory().createAccessibleBrowseBoxTableCell(
939 m_pAccessible
->getAccessibleChild( 0 ), *this, NULL
, _nRow
, _nColumnPos
, OFFSET_NONE
);
942 if ( !AreChildrenTransient() )
943 m_aAccessibleChildren
[ nIndex
] = xChild
;
948 // -----------------------------------------------------------------------
949 Reference
< XAccessible
> SvHeaderTabListBox::CreateAccessibleRowHeader( sal_Int32
)
951 Reference
< XAccessible
> xHeader
;
954 // -----------------------------------------------------------------------
955 Reference
< XAccessible
> SvHeaderTabListBox::CreateAccessibleColumnHeader( sal_uInt16 _nColumn
)
957 // first call? -> initial list
958 if ( m_aAccessibleChildren
.empty() )
960 const sal_uInt16 nColumnCount
= GetColumnCount();
961 sal_Int32 nCount
= AreChildrenTransient() ?
962 nColumnCount
: ( GetRowCount() + 1 ) * nColumnCount
;
963 m_aAccessibleChildren
.assign( nCount
, Reference
< XAccessible
>() );
967 Reference
< XAccessible
> xChild
= m_aAccessibleChildren
[ _nColumn
];
969 if ( !xChild
.is() && m_pAccessible
)
971 // no -> create new header cell
972 xChild
= m_pImpl
->m_aFactoryAccess
.getFactory().createAccessibleBrowseBoxHeaderCell(
973 _nColumn
, m_pAccessible
->getHeaderBar( ::svt::BBTYPE_COLUMNHEADERBAR
),
974 *this, NULL
, ::svt::BBTYPE_COLUMNHEADERCELL
978 m_aAccessibleChildren
[ _nColumn
] = xChild
;
983 // -----------------------------------------------------------------------
984 sal_Int32
SvHeaderTabListBox::GetAccessibleControlCount() const
988 // -----------------------------------------------------------------------
989 Reference
< XAccessible
> SvHeaderTabListBox::CreateAccessibleControl( sal_Int32
)
991 Reference
< XAccessible
> xControl
;
994 // -----------------------------------------------------------------------
995 sal_Bool
SvHeaderTabListBox::ConvertPointToControlIndex( sal_Int32
&, const Point
& )
999 // -----------------------------------------------------------------------
1000 sal_Bool
SvHeaderTabListBox::ConvertPointToCellAddress( sal_Int32
&, sal_uInt16
&, const Point
& )
1004 // -----------------------------------------------------------------------
1005 sal_Bool
SvHeaderTabListBox::ConvertPointToRowHeader( sal_Int32
&, const Point
& )
1009 // -----------------------------------------------------------------------
1010 sal_Bool
SvHeaderTabListBox::ConvertPointToColumnHeader( sal_uInt16
&, const Point
& )
1014 // -----------------------------------------------------------------------
1015 OUString
SvHeaderTabListBox::GetAccessibleObjectName( ::svt::AccessibleBrowseBoxObjType _eType
, sal_Int32 _nPos
) const
1020 case ::svt::BBTYPE_BROWSEBOX
:
1021 case ::svt::BBTYPE_TABLE
:
1022 case ::svt::BBTYPE_COLUMNHEADERBAR
:
1023 // should be empty now (see #i63983)
1024 aRetText
= OUString();
1027 case ::svt::BBTYPE_TABLECELL
:
1029 // here we need a valid pos, we can not handle -1
1032 sal_uInt16 nColumnCount
= GetColumnCount();
1033 if (nColumnCount
> 0)
1035 sal_Int32 nRow
= _nPos
/ nColumnCount
;
1036 sal_uInt16 nColumn
= static_cast< sal_uInt16
>( _nPos
% nColumnCount
);
1037 aRetText
= GetCellText( nRow
, nColumn
);
1042 case ::svt::BBTYPE_CHECKBOXCELL
:
1044 break; // checkbox cells have no name
1046 case ::svt::BBTYPE_COLUMNHEADERCELL
:
1048 aRetText
= m_pImpl
->m_pHeaderBar
->GetItemText( m_pImpl
->m_pHeaderBar
->GetItemId( (sal_uInt16
)_nPos
) );
1052 case ::svt::BBTYPE_ROWHEADERBAR
:
1053 case ::svt::BBTYPE_ROWHEADERCELL
:
1058 OSL_FAIL("BrowseBox::GetAccessibleName: invalid enum!");
1062 // -----------------------------------------------------------------------
1063 OUString
SvHeaderTabListBox::GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType _eType
, sal_Int32 _nPos
) const
1067 if( _eType
== ::svt::BBTYPE_TABLECELL
&& _nPos
!= -1 )
1069 const OUString
sVar1( "%1" );
1070 const OUString
sVar2( "%2" );
1072 sal_uInt16 nColumnCount
= GetColumnCount();
1073 if (nColumnCount
> 0)
1075 sal_Int32 nRow
= _nPos
/ nColumnCount
;
1076 sal_uInt16 nColumn
= static_cast< sal_uInt16
>( _nPos
% nColumnCount
);
1078 OUString
aText( SVT_RESSTR(STR_SVT_ACC_DESC_TABLISTBOX
) );
1079 aText
= aText
.replaceFirst( sVar1
, OUString::number( nRow
) );
1080 OUString sColHeader
= m_pImpl
->m_pHeaderBar
->GetItemText( m_pImpl
->m_pHeaderBar
->GetItemId( nColumn
) );
1081 if ( sColHeader
.isEmpty() )
1082 sColHeader
= OUString::number( nColumn
);
1083 aText
= aText
.replaceFirst( sVar2
, sColHeader
);
1090 // -----------------------------------------------------------------------
1091 void SvHeaderTabListBox::FillAccessibleStateSet( ::utl::AccessibleStateSetHelper
& _rStateSet
, ::svt::AccessibleBrowseBoxObjType _eType
) const
1095 case ::svt::BBTYPE_BROWSEBOX
:
1096 case ::svt::BBTYPE_TABLE
:
1098 _rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
1100 _rStateSet
.AddState( AccessibleStateType::FOCUSED
);
1102 _rStateSet
.AddState( AccessibleStateType::ACTIVE
);
1105 _rStateSet
.AddState( AccessibleStateType::ENABLED
);
1106 _rStateSet
.AddState( AccessibleStateType::SENSITIVE
);
1108 if ( IsReallyVisible() )
1109 _rStateSet
.AddState( AccessibleStateType::VISIBLE
);
1110 if ( _eType
== ::svt::BBTYPE_TABLE
)
1113 if ( AreChildrenTransient() )
1114 _rStateSet
.AddState( AccessibleStateType::MANAGES_DESCENDANTS
);
1115 _rStateSet
.AddState( AccessibleStateType::MULTI_SELECTABLE
);
1120 case ::svt::BBTYPE_COLUMNHEADERBAR
:
1122 sal_Int32 nCurRow
= GetCurrRow();
1123 sal_uInt16 nCurColumn
= GetCurrColumn();
1124 if ( IsCellVisible( nCurRow
, nCurColumn
) )
1125 _rStateSet
.AddState( AccessibleStateType::VISIBLE
);
1126 _rStateSet
.AddState( AccessibleStateType::TRANSIENT
);
1130 case ::svt::BBTYPE_ROWHEADERCELL
:
1131 case ::svt::BBTYPE_COLUMNHEADERCELL
:
1133 _rStateSet
.AddState( AccessibleStateType::VISIBLE
);
1134 _rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
1135 _rStateSet
.AddState( AccessibleStateType::TRANSIENT
);
1142 // -----------------------------------------------------------------------
1143 void SvHeaderTabListBox::FillAccessibleStateSetForCell( ::utl::AccessibleStateSetHelper
& _rStateSet
, sal_Int32 _nRow
, sal_uInt16 _nColumn
) const
1145 _rStateSet
.AddState( AccessibleStateType::SELECTABLE
);
1146 if ( AreChildrenTransient() )
1147 _rStateSet
.AddState( AccessibleStateType::TRANSIENT
);
1149 if ( IsCellVisible( _nRow
, _nColumn
) )
1151 _rStateSet
.AddState( AccessibleStateType::VISIBLE
);
1152 _rStateSet
.AddState( AccessibleStateType::ENABLED
);
1155 if ( IsRowSelected( _nRow
) )
1157 _rStateSet
.AddState( AccessibleStateType::ACTIVE
);
1158 _rStateSet
.AddState( AccessibleStateType::SELECTED
);
1161 // -----------------------------------------------------------------------
1162 void SvHeaderTabListBox::GrabTableFocus()
1166 // -----------------------------------------------------------------------
1167 sal_Bool
SvHeaderTabListBox::GetGlyphBoundRects( const Point
& rOrigin
, const OUString
& rStr
, int nIndex
, int nLen
, int nBase
, MetricVector
& rVector
)
1169 return Control::GetGlyphBoundRects( rOrigin
, rStr
, nIndex
, nLen
, nBase
, rVector
);
1171 // -----------------------------------------------------------------------
1172 Rectangle
SvHeaderTabListBox::GetWindowExtentsRelative( Window
*pRelativeWindow
) const
1174 return Control::GetWindowExtentsRelative( pRelativeWindow
);
1176 // -----------------------------------------------------------------------
1177 void SvHeaderTabListBox::GrabFocus()
1179 Control::GrabFocus();
1181 // -----------------------------------------------------------------------
1182 Reference
< XAccessible
> SvHeaderTabListBox::GetAccessible( sal_Bool bCreate
)
1184 return Control::GetAccessible( bCreate
);
1186 // -----------------------------------------------------------------------
1187 Window
* SvHeaderTabListBox::GetAccessibleParentWindow() const
1189 return Control::GetAccessibleParentWindow();
1191 // -----------------------------------------------------------------------
1192 Window
* SvHeaderTabListBox::GetWindowInstance()
1196 // -----------------------------------------------------------------------
1197 Reference
< XAccessible
> SvHeaderTabListBox::CreateAccessible()
1199 Window
* pParent
= GetAccessibleParentWindow();
1200 DBG_ASSERT( pParent
, "SvHeaderTabListBox::::CreateAccessible - accessible parent not found" );
1202 Reference
< XAccessible
> xAccessible
;
1203 if ( m_pAccessible
) xAccessible
= m_pAccessible
->getMyself();
1205 if( pParent
&& !m_pAccessible
)
1207 Reference
< XAccessible
> xAccParent
= pParent
->GetAccessible();
1208 if ( xAccParent
.is() )
1210 m_pAccessible
= m_pImpl
->m_aFactoryAccess
.getFactory().createAccessibleTabListBox( xAccParent
, *this );
1211 if ( m_pAccessible
)
1212 xAccessible
= m_pAccessible
->getMyself();
1217 // -----------------------------------------------------------------------------
1218 Rectangle
SvHeaderTabListBox::GetFieldCharacterBounds(sal_Int32
,sal_Int32
,sal_Int32
)
1223 // -----------------------------------------------------------------------------
1224 sal_Int32
SvHeaderTabListBox::GetFieldIndexAtPoint(sal_Int32 _nRow
,sal_Int32 _nColumnPos
,const Point
& _rPoint
)
1226 OUString sText
= GetAccessibleCellText( _nRow
, static_cast< sal_uInt16
>( _nColumnPos
) );
1227 MetricVector aRects
;
1228 if ( GetGlyphBoundRects(Point(0,0),sText
,0,STRING_LEN
,0,aRects
) )
1230 for (MetricVector::iterator aIter
= aRects
.begin(); aIter
!= aRects
.end(); ++aIter
)
1232 if( aIter
->IsInside(_rPoint
) )
1233 return aIter
- aRects
.begin();
1239 // -----------------------------------------------------------------------------
1242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */