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 const sal_Unicode
* pCurToken
= aCurEntry
.GetBuffer();
82 sal_uInt16 nCurTokenLen
;
83 const sal_Unicode
* pNextToken
= GetToken( pCurToken
, nCurTokenLen
);
84 sal_uInt16 nCount
= nTabCount
; nCount
--;
85 for( sal_uInt16 nToken
= 0; nToken
< nCount
; nToken
++ )
87 if( pCurToken
&& nCurTokenLen
)
88 aToken
= OUString(pCurToken
, nCurTokenLen
);
91 SvLBoxString
* pStr
= new SvLBoxString( pEntry
, 0, aToken
);
92 pEntry
->AddItem( pStr
);
93 pCurToken
= pNextToken
;
95 pNextToken
= GetToken( pCurToken
, nCurTokenLen
);
102 SvTabListBox::SvTabListBox( Window
* pParent
, WinBits nBits
)
103 : SvTreeListBox( pParent
, nBits
)
108 SetHighlightRange(); // select full width
111 extern "C" SAL_DLLPUBLIC_EXPORT Window
* SAL_CALL
makeSvTabListBox(Window
*pParent
,
112 VclBuilder::stringmap
&rMap
)
114 WinBits nWinStyle
= WB_TABSTOP
;
115 OString sBorder
= VclBuilder::extractCustomProperty(rMap
);
116 if (!sBorder
.isEmpty())
117 nWinStyle
|= WB_BORDER
;
118 return new SvTabListBox(pParent
, nWinStyle
);
121 SvTabListBox::SvTabListBox( Window
* pParent
, const ResId
& rResId
)
122 : SvTreeListBox( pParent
, rResId
)
127 SvTabListBox::Resize();
131 SvTabListBox::~SvTabListBox()
141 void SvTabListBox::SetTabs( long* pTabs
, MapUnit eMapUnit
)
143 DBG_ASSERT(pTabs
,"SetTabs:NULL-Ptr");
148 sal_uInt16 nCount
= (sal_uInt16
)(*pTabs
);
149 pTabList
= new SvLBoxTab
[ nCount
];
152 MapMode
aMMSource( eMapUnit
);
153 MapMode
aMMDest( MAP_PIXEL
);
156 for( sal_uInt16 nIdx
= 0; nIdx
< nCount
; nIdx
++, pTabs
++ )
158 Size
aSize( *pTabs
, 0 );
159 aSize
= LogicToLogic( aSize
, &aMMSource
, &aMMDest
);
160 long nNewTab
= aSize
.Width();
161 pTabList
[nIdx
].SetPos( nNewTab
);
162 pTabList
[nIdx
].nFlags
=(SV_LBOXTAB_ADJUST_LEFT
| SV_LBOXTAB_INV_ALWAYS
);
164 SvTreeListBox::nTreeFlags
|= TREEFLAG_RECALCTABS
;
169 void SvTabListBox::SetTab( sal_uInt16 nTab
,long nValue
,MapUnit eMapUnit
)
171 DBG_ASSERT(nTab
<nTabCount
,"Invalid Tab-Pos");
172 if( nTab
< nTabCount
)
174 DBG_ASSERT(pTabList
,"TabList?");
175 MapMode
aMMSource( eMapUnit
);
176 MapMode
aMMDest( MAP_PIXEL
);
177 Size
aSize( nValue
, 0 );
178 aSize
= LogicToLogic( aSize
, &aMMSource
, &aMMDest
);
179 nValue
= aSize
.Width();
180 pTabList
[ nTab
].SetPos( nValue
);
181 SvTreeListBox::nTreeFlags
|= TREEFLAG_RECALCTABS
;
187 SvTreeListEntry
* SvTabListBox::InsertEntry( const XubString
& rText
, SvTreeListEntry
* pParent
,
188 sal_Bool
/*bChildrenOnDemand*/,
189 sal_uLong nPos
, void* pUserData
,
192 return InsertEntryToColumn( rText
, pParent
, nPos
, 0xffff, pUserData
);
195 SvTreeListEntry
* SvTabListBox::InsertEntry( const XubString
& rText
,
196 const Image
& rExpandedEntryBmp
,
197 const Image
& rCollapsedEntryBmp
,
198 SvTreeListEntry
* pParent
,
199 sal_Bool
/*bChildrenOnDemand*/,
200 sal_uLong nPos
, void* pUserData
,
203 return InsertEntryToColumn( rText
, rExpandedEntryBmp
, rCollapsedEntryBmp
,
204 pParent
, nPos
, 0xffff, pUserData
);
207 SvTreeListEntry
* SvTabListBox::InsertEntryToColumn(const XubString
& rStr
,SvTreeListEntry
* pParent
,sal_uLong nPos
,sal_uInt16 nCol
,
220 XubString
aFirstStr( aStr
);
221 sal_uInt16 nEnd
= aFirstStr
.Search( '\t' );
222 if( nEnd
!= STRING_NOTFOUND
)
224 aFirstStr
.Erase( nEnd
);
226 aCurEntry
.Erase( 0, ++nEnd
);
230 return SvTreeListBox::InsertEntry( aFirstStr
, pParent
, sal_False
, nPos
, pUser
);
233 SvTreeListEntry
* SvTabListBox::InsertEntryToColumn( const XubString
& rStr
,
234 const Image
& rExpandedEntryBmp
, const Image
& rCollapsedEntryBmp
,
235 SvTreeListEntry
* pParent
,sal_uLong nPos
,sal_uInt16 nCol
, void* pUser
)
247 XubString
aFirstStr( aStr
);
248 sal_uInt16 nEnd
= aFirstStr
.Search( '\t' );
249 if( nEnd
!= STRING_NOTFOUND
)
251 aFirstStr
.Erase( nEnd
);
253 aCurEntry
.Erase( 0, ++nEnd
);
258 return SvTreeListBox::InsertEntry(
260 rExpandedEntryBmp
, rCollapsedEntryBmp
,
261 pParent
, sal_False
, nPos
, pUser
);
264 SvTreeListEntry
* SvTabListBox::InsertEntryToColumn( const XubString
& rStr
, sal_uLong nPos
,
265 sal_uInt16 nCol
, void* pUser
)
267 return InsertEntryToColumn( rStr
,0,nPos
, nCol
, pUser
);
270 String
SvTabListBox::GetEntryText( SvTreeListEntry
* pEntry
) const
272 return GetEntryText( pEntry
, 0xffff );
275 String
SvTabListBox::GetEntryText( SvTreeListEntry
* pEntry
, sal_uInt16 nCol
) const
277 DBG_ASSERT(pEntry
,"GetEntryText:Invalid Entry");
281 sal_uInt16 nCount
= pEntry
->ItemCount();
283 while( nCur
< nCount
)
285 const SvLBoxItem
* pStr
= pEntry
->GetItem( nCur
);
286 if (pStr
->GetType() == SV_ITEM_ID_LBOXSTRING
)
292 aResult
+= static_cast<const SvLBoxString
*>(pStr
)->GetText();
297 return static_cast<const SvLBoxString
*>(pStr
)->GetText();
307 String
SvTabListBox::GetEntryText( sal_uLong nPos
, sal_uInt16 nCol
) const
309 SvTreeListEntry
* pEntry
= GetEntryOnPos( nPos
);
310 return GetEntryText( pEntry
, nCol
);
313 void SvTabListBox::SetEntryText( const XubString
& rStr
, sal_uLong nPos
, sal_uInt16 nCol
)
315 SvTreeListEntry
* pEntry
= SvTreeListBox::GetEntry( nPos
);
316 SetEntryText( rStr
, pEntry
, nCol
);
319 void SvTabListBox::SetEntryText( const XubString
& rStr
, SvTreeListEntry
* pEntry
, sal_uInt16 nCol
)
321 DBG_ASSERT(pEntry
,"SetEntryText:Invalid Entry");
325 String sOldText
= GetEntryText( pEntry
, nCol
);
326 if ( sOldText
== rStr
)
329 sal_uInt16 nTextColumn
= nCol
;
330 const sal_Unicode
* pCurToken
= rStr
.GetBuffer();
331 sal_uInt16 nCurTokenLen
;
332 const sal_Unicode
* pNextToken
= GetToken( pCurToken
, nCurTokenLen
);
335 sal_uInt16 nCount
= pEntry
->ItemCount();
337 while( nCur
< nCount
)
339 SvLBoxItem
* pStr
= pEntry
->GetItem( nCur
);
340 if (pStr
&& pStr
->GetType() == SV_ITEM_ID_LBOXSTRING
)
345 aTemp
= OUString(pCurToken
, nCurTokenLen
);
347 aTemp
.Erase(); // delete all columns without a token
348 ((SvLBoxString
*)pStr
)->SetText( aTemp
);
349 pCurToken
= pNextToken
;
350 pNextToken
= GetToken( pCurToken
, nCurTokenLen
);
356 aTemp
= OUString(pCurToken
, nCurTokenLen
);
357 ((SvLBoxString
*)pStr
)->SetText( aTemp
);
360 pCurToken
= pNextToken
;
361 pNextToken
= GetToken( pCurToken
, nCurTokenLen
);
369 GetModel()->InvalidateEntry( pEntry
);
371 TabListBoxEventData
* pData
= new TabListBoxEventData( pEntry
, nTextColumn
, sOldText
);
372 ImplCallEventListeners( VCLEVENT_TABLECELL_NAMECHANGED
, pData
);
376 String
SvTabListBox::GetCellText( sal_uLong nPos
, sal_uInt16 nCol
) const
378 SvTreeListEntry
* pEntry
= GetEntryOnPos( nPos
);
379 DBG_ASSERT( pEntry
, "SvTabListBox::GetCellText(): Invalid Entry" );
381 if (pEntry
&& pEntry
->ItemCount() > static_cast<size_t>(nCol
+1))
383 const SvLBoxItem
* pStr
= pEntry
->GetItem( nCol
+ 1 );
384 if (pStr
&& pStr
->GetType() == SV_ITEM_ID_LBOXSTRING
)
385 aResult
= static_cast<const SvLBoxString
*>(pStr
)->GetText();
390 sal_uLong
SvTabListBox::GetEntryPos( const XubString
& rStr
, sal_uInt16 nCol
)
393 SvTreeListEntry
* pEntry
= First();
396 XubString
aStr( GetEntryText( pEntry
, nCol
));
399 pEntry
= Next( pEntry
);
405 sal_uLong
SvTabListBox::GetEntryPos( const SvTreeListEntry
* pEntry
) const
408 SvTreeListEntry
* pTmpEntry
= First();
411 if ( pTmpEntry
== pEntry
)
413 pTmpEntry
= Next( pTmpEntry
);
419 void SvTabListBox::Resize()
421 SvTreeListBox::Resize();
425 const sal_Unicode
* SvTabListBox::GetToken( const sal_Unicode
* pPtr
, sal_uInt16
& rLen
)
427 if( !pPtr
|| *pPtr
== 0 )
432 sal_Unicode c
= *pPtr
;
434 while( c
!= '\t' && c
!= 0 )
448 String
SvTabListBox::GetTabEntryText( sal_uLong nPos
, sal_uInt16 nCol
) const
450 SvTreeListEntry
* pEntry
= SvTreeListBox::GetEntry( nPos
);
451 DBG_ASSERT( pEntry
, "GetTabEntryText(): Invalid entry " );
455 sal_uInt16 nCount
= pEntry
->ItemCount();
456 sal_uInt16 nCur
= ( 0 == nCol
&& IsCellFocusEnabled() ) ? GetCurrentTabPos() : 0;
457 while( nCur
< nCount
)
459 const SvLBoxItem
* pStr
= pEntry
->GetItem( nCur
);
460 if (pStr
->GetType() == SV_ITEM_ID_LBOXSTRING
)
462 if ( nCol
== 0xffff )
466 aResult
+= static_cast<const SvLBoxString
*>(pStr
)->GetText();
472 String sRet
= static_cast<const SvLBoxString
*>(pStr
)->GetText();
473 if ( sRet
.Len() == 0 )
474 sRet
= SVT_RESSTR( STR_SVT_ACC_EMPTY_FIELD
);
486 SvTreeListEntry
* SvTabListBox::GetEntryOnPos( sal_uLong _nEntryPos
) const
488 SvTreeListEntry
* pEntry
= NULL
;
489 sal_uLong i
, nPos
= 0, nCount
= GetLevelChildCount( NULL
);
490 for ( i
= 0; i
< nCount
; ++i
)
492 SvTreeListEntry
* pParent
= GetEntry(i
);
493 if ( nPos
== _nEntryPos
)
501 pEntry
= GetChildOnPos( pParent
, _nEntryPos
, nPos
);
510 SvTreeListEntry
* SvTabListBox::GetChildOnPos( SvTreeListEntry
* _pParent
, sal_uLong _nEntryPos
, sal_uLong
& _rPos
) const
512 sal_uLong i
, nCount
= GetLevelChildCount( _pParent
);
513 for ( i
= 0; i
< nCount
; ++i
)
515 SvTreeListEntry
* pParent
= GetEntry( _pParent
, i
);
516 if ( _rPos
== _nEntryPos
)
521 SvTreeListEntry
* pEntry
= GetChildOnPos( pParent
, _nEntryPos
, _rPos
);
530 void SvTabListBox::SetTabJustify( sal_uInt16 nTab
, SvTabJustify eJustify
)
532 if( nTab
>= nTabCount
)
534 SvLBoxTab
* pTab
= &(pTabList
[ nTab
]);
535 sal_uInt16 nFlags
= pTab
->nFlags
;
536 nFlags
&= (~MYTABMASK
);
537 nFlags
|= (sal_uInt16
)eJustify
;
538 pTab
->nFlags
= nFlags
;
539 SvTreeListBox::nTreeFlags
|= TREEFLAG_RECALCTABS
;
544 long SvTabListBox::GetLogicTab( sal_uInt16 nTab
)
546 if( SvTreeListBox::nTreeFlags
& TREEFLAG_RECALCTABS
)
547 ((SvTabListBox
*)this)->SetTabs();
549 DBG_ASSERT(nTab
<nTabCount
,"GetTabPos:Invalid Tab");
550 return aTabs
[ nTab
]->GetPos();
553 // class SvHeaderTabListBoxImpl ------------------------------------------
557 struct SvHeaderTabListBoxImpl
559 HeaderBar
* m_pHeaderBar
;
560 AccessibleFactoryAccess m_aFactoryAccess
;
562 SvHeaderTabListBoxImpl() : m_pHeaderBar( NULL
) { }
566 // class SvHeaderTabListBox ----------------------------------------------
568 SvHeaderTabListBox::SvHeaderTabListBox( Window
* pParent
, WinBits nWinStyle
) :
570 SvTabListBox( pParent
, nWinStyle
),
572 m_bFirstPaint ( sal_True
),
573 m_pImpl ( new ::svt::SvHeaderTabListBoxImpl
),
574 m_pAccessible ( NULL
)
578 // -----------------------------------------------------------------------
580 SvHeaderTabListBox::SvHeaderTabListBox( Window
* pParent
, const ResId
& rResId
) :
582 SvTabListBox( pParent
, rResId
),
584 m_bFirstPaint ( sal_True
),
585 m_pImpl ( new ::svt::SvHeaderTabListBoxImpl
),
586 m_pAccessible ( NULL
)
590 // -----------------------------------------------------------------------
592 SvHeaderTabListBox::~SvHeaderTabListBox()
597 // -----------------------------------------------------------------------
599 void SvHeaderTabListBox::Paint( const Rectangle
& rRect
)
603 m_bFirstPaint
= sal_False
;
606 SvTabListBox::Paint( rRect
);
609 // -----------------------------------------------------------------------
611 void SvHeaderTabListBox::InitHeaderBar( HeaderBar
* pHeaderBar
)
613 DBG_ASSERT( !m_pImpl
->m_pHeaderBar
, "header bar already initialized" );
614 DBG_ASSERT( pHeaderBar
, "invalid header bar initialization" );
615 m_pImpl
->m_pHeaderBar
= pHeaderBar
;
616 SetScrolledHdl( LINK( this, SvHeaderTabListBox
, ScrollHdl_Impl
) );
617 m_pImpl
->m_pHeaderBar
->SetCreateAccessibleHdl( LINK( this, SvHeaderTabListBox
, CreateAccessibleHdl_Impl
) );
620 // -----------------------------------------------------------------------
622 sal_Bool
SvHeaderTabListBox::IsItemChecked( SvTreeListEntry
* pEntry
, sal_uInt16 nCol
) const
624 SvButtonState eState
= SV_BUTTON_UNCHECKED
;
625 SvLBoxButton
* pItem
= (SvLBoxButton
*)( pEntry
->GetItem( nCol
+ 1 ) );
627 if (pItem
&& pItem
->GetType() == SV_ITEM_ID_LBOXBUTTON
)
629 sal_uInt16 nButtonFlags
= pItem
->GetButtonFlags();
630 eState
= pCheckButtonData
->ConvertToButtonState( nButtonFlags
);
633 return ( eState
== SV_BUTTON_CHECKED
);
636 // -----------------------------------------------------------------------
638 SvTreeListEntry
* SvHeaderTabListBox::InsertEntryToColumn(
639 const XubString
& rStr
, sal_uLong nPos
, sal_uInt16 nCol
, void* pUserData
)
641 SvTreeListEntry
* pEntry
= SvTabListBox::InsertEntryToColumn( rStr
, nPos
, nCol
, pUserData
);
642 RecalculateAccessibleChildren();
646 // -----------------------------------------------------------------------
648 SvTreeListEntry
* SvHeaderTabListBox::InsertEntryToColumn(
649 const XubString
& rStr
, SvTreeListEntry
* pParent
, sal_uLong nPos
, sal_uInt16 nCol
, void* pUserData
)
651 SvTreeListEntry
* pEntry
= SvTabListBox::InsertEntryToColumn( rStr
, pParent
, nPos
, nCol
, pUserData
);
652 RecalculateAccessibleChildren();
656 // -----------------------------------------------------------------------
658 SvTreeListEntry
* SvHeaderTabListBox::InsertEntryToColumn(
659 const XubString
& rStr
, const Image
& rExpandedEntryBmp
, const Image
& rCollapsedEntryBmp
,
660 SvTreeListEntry
* pParent
, sal_uLong nPos
, sal_uInt16 nCol
, void* pUserData
)
662 SvTreeListEntry
* pEntry
= SvTabListBox::InsertEntryToColumn(
663 rStr
, rExpandedEntryBmp
, rCollapsedEntryBmp
, pParent
, nPos
, nCol
, pUserData
);
664 RecalculateAccessibleChildren();
668 // -----------------------------------------------------------------------
670 sal_uLong
SvHeaderTabListBox::Insert(
671 SvTreeListEntry
* pEnt
, SvTreeListEntry
* pPar
, sal_uLong nPos
)
673 sal_uLong n
= SvTabListBox::Insert( pEnt
, pPar
, nPos
);
674 RecalculateAccessibleChildren();
678 // -----------------------------------------------------------------------
680 sal_uLong
SvHeaderTabListBox::Insert( SvTreeListEntry
* pEntry
, sal_uLong nRootPos
)
682 sal_uLong nPos
= SvTabListBox::Insert( pEntry
, nRootPos
);
683 RecalculateAccessibleChildren();
687 // -----------------------------------------------------------------------
689 void SvHeaderTabListBox::RemoveEntry( SvTreeListEntry
* _pEntry
)
691 GetModel()->Remove( _pEntry
);
692 m_aAccessibleChildren
.clear();
695 // -----------------------------------------------------------------------
697 void SvHeaderTabListBox::Clear()
699 SvTabListBox::Clear();
700 m_aAccessibleChildren
.clear();
703 // -----------------------------------------------------------------------
705 IMPL_LINK_NOARG(SvHeaderTabListBox
, ScrollHdl_Impl
)
707 m_pImpl
->m_pHeaderBar
->SetOffset( -GetXOffset() );
711 // -----------------------------------------------------------------------
713 IMPL_LINK_NOARG(SvHeaderTabListBox
, CreateAccessibleHdl_Impl
)
715 Window
* pParent
= m_pImpl
->m_pHeaderBar
->GetAccessibleParentWindow();
716 DBG_ASSERT( pParent
, "SvHeaderTabListBox..CreateAccessibleHdl_Impl - accessible parent not found" );
719 ::com::sun::star::uno::Reference
< XAccessible
> xAccParent
= pParent
->GetAccessible();
720 if ( xAccParent
.is() )
722 Reference
< XAccessible
> xAccessible
= m_pImpl
->m_aFactoryAccess
.getFactory().createAccessibleBrowseBoxHeaderBar(
723 xAccParent
, *this, ::svt::BBTYPE_COLUMNHEADERBAR
);
724 m_pImpl
->m_pHeaderBar
->SetAccessible( xAccessible
);
730 // -----------------------------------------------------------------------
732 void SvHeaderTabListBox::RecalculateAccessibleChildren()
734 if ( !m_aAccessibleChildren
.empty() )
736 sal_uInt32 nCount
= ( GetRowCount() + 1 ) * GetColumnCount();
737 if ( m_aAccessibleChildren
.size() < nCount
)
738 m_aAccessibleChildren
.resize( nCount
);
741 DBG_ASSERT( m_aAccessibleChildren
.size() == nCount
, "wrong children count" );
746 // -----------------------------------------------------------------------
748 sal_Bool
SvHeaderTabListBox::IsCellCheckBox( long _nRow
, sal_uInt16 _nColumn
, TriState
& _rState
)
751 SvTreeListEntry
* pEntry
= GetEntry( _nRow
);
754 sal_uInt16 nItemCount
= pEntry
->ItemCount();
755 if ( nItemCount
> ( _nColumn
+ 1 ) )
757 SvLBoxButton
* pItem
= (SvLBoxButton
*)( pEntry
->GetItem( _nColumn
+ 1 ) );
758 if (pItem
&& pItem
->GetType() == SV_ITEM_ID_LBOXBUTTON
)
761 _rState
= ( ( pItem
->GetButtonFlags() & SV_ITEMSTATE_UNCHECKED
) == 0 )
762 ? STATE_CHECK
: STATE_NOCHECK
;
767 SAL_WARN( "svtools.contnr", "SvHeaderTabListBox::IsCellCheckBox(): column out of range" );
773 // -----------------------------------------------------------------------
774 long SvHeaderTabListBox::GetRowCount() const
776 return GetEntryCount();
778 // -----------------------------------------------------------------------
779 sal_uInt16
SvHeaderTabListBox::GetColumnCount() const
781 return m_pImpl
->m_pHeaderBar
->GetItemCount();
783 // -----------------------------------------------------------------------
784 sal_Int32
SvHeaderTabListBox::GetCurrRow() const
787 SvTreeListEntry
* pEntry
= GetCurEntry();
790 sal_uLong nCount
= GetEntryCount();
791 for ( sal_uLong i
= 0; i
< nCount
; ++i
)
793 if ( pEntry
== GetEntry(i
) )
803 // -----------------------------------------------------------------------
804 sal_uInt16
SvHeaderTabListBox::GetCurrColumn() const
806 sal_uInt16 nPos
= GetCurrentTabPos() - 1;
809 // -----------------------------------------------------------------------
810 OUString
SvHeaderTabListBox::GetRowDescription( sal_Int32 _nRow
) const
812 return OUString( GetEntryText( _nRow
) );
814 // -----------------------------------------------------------------------
815 OUString
SvHeaderTabListBox::GetColumnDescription( sal_uInt16 _nColumn
) const
817 return OUString( m_pImpl
->m_pHeaderBar
->GetItemText( m_pImpl
->m_pHeaderBar
->GetItemId( _nColumn
) ) );
819 // -----------------------------------------------------------------------
820 sal_Bool
SvHeaderTabListBox::HasRowHeader() const
824 // -----------------------------------------------------------------------
825 sal_Bool
SvHeaderTabListBox::IsCellFocusable() const
827 return IsCellFocusEnabled();
829 // -----------------------------------------------------------------------
830 sal_Bool
SvHeaderTabListBox::GoToCell( sal_Int32 _nRow
, sal_uInt16 _nColumn
)
832 sal_Bool bRet
= ( IsCellFocusEnabled() == sal_True
);
835 // first set cursor to _nRow
836 SetCursor( GetEntry( _nRow
), sal_True
);
837 // then set the focus into _nColumn
838 bRet
= ( SetCurrentTabPos( _nColumn
) == true );
842 // -----------------------------------------------------------------------
843 void SvHeaderTabListBox::SetNoSelection()
845 SvTreeListBox::SelectAll(false);
847 // -----------------------------------------------------------------------
848 void SvHeaderTabListBox::SelectAll()
850 SvTreeListBox::SelectAll(true);
852 // -----------------------------------------------------------------------
853 void SvHeaderTabListBox::SelectAll( sal_Bool bSelect
, sal_Bool bPaint
)
855 // overwritten just to disambiguate the SelectAll() from the base' class SelectAll( BOOl, sal_Bool )
856 SvTabListBox::SelectAll( bSelect
, bPaint
);
859 // -----------------------------------------------------------------------
860 void SvHeaderTabListBox::SelectRow( long _nRow
, sal_Bool _bSelect
, sal_Bool
)
862 Select( GetEntry( _nRow
), _bSelect
);
864 // -----------------------------------------------------------------------
865 void SvHeaderTabListBox::SelectColumn( sal_uInt16
, sal_Bool
)
868 // -----------------------------------------------------------------------
869 sal_Int32
SvHeaderTabListBox::GetSelectedRowCount() const
871 return GetSelectionCount();
873 // -----------------------------------------------------------------------
874 sal_Int32
SvHeaderTabListBox::GetSelectedColumnCount() const
878 // -----------------------------------------------------------------------
879 bool SvHeaderTabListBox::IsRowSelected( long _nRow
) const
881 SvTreeListEntry
* pEntry
= GetEntry( _nRow
);
882 return ( pEntry
&& IsSelected( pEntry
) );
884 // -----------------------------------------------------------------------
885 sal_Bool
SvHeaderTabListBox::IsColumnSelected( long ) const
889 // -----------------------------------------------------------------------
890 void SvHeaderTabListBox::GetAllSelectedRows( ::com::sun::star::uno::Sequence
< sal_Int32
>& ) const
893 // -----------------------------------------------------------------------
894 void SvHeaderTabListBox::GetAllSelectedColumns( ::com::sun::star::uno::Sequence
< sal_Int32
>& ) const
897 // -----------------------------------------------------------------------
898 sal_Bool
SvHeaderTabListBox::IsCellVisible( sal_Int32
, sal_uInt16
) const
902 // -----------------------------------------------------------------------
903 String
SvHeaderTabListBox::GetAccessibleCellText( long _nRow
, sal_uInt16 _nColumnPos
) const
905 return OUString( GetTabEntryText( _nRow
, _nColumnPos
) );
907 // -----------------------------------------------------------------------
908 Rectangle
SvHeaderTabListBox::calcHeaderRect( sal_Bool _bIsColumnBar
, sal_Bool _bOnScreen
)
913 Window
* pParent
= NULL
;
915 pParent
= m_pImpl
->m_pHeaderBar
->GetAccessibleParentWindow();
917 aRect
= m_pImpl
->m_pHeaderBar
->GetWindowExtentsRelative( pParent
);
921 // -----------------------------------------------------------------------
922 Rectangle
SvHeaderTabListBox::calcTableRect( sal_Bool _bOnScreen
)
924 Window
* pParent
= NULL
;
926 pParent
= GetAccessibleParentWindow();
928 Rectangle
aRect( GetWindowExtentsRelative( pParent
) );
931 // -----------------------------------------------------------------------
932 Rectangle
SvHeaderTabListBox::GetFieldRectPixelAbs( sal_Int32 _nRow
, sal_uInt16 _nColumn
, sal_Bool _bIsHeader
, sal_Bool _bOnScreen
)
934 DBG_ASSERT( !_bIsHeader
|| 0 == _nRow
, "invalid parameters" );
936 SvTreeListEntry
* pEntry
= GetEntry( _nRow
);
939 aRect
= _bIsHeader
? calcHeaderRect( sal_True
, sal_False
) : GetBoundingRect( pEntry
);
940 Point aTopLeft
= aRect
.TopLeft();
941 DBG_ASSERT( m_pImpl
->m_pHeaderBar
->GetItemCount() > _nColumn
, "invalid column" );
942 Rectangle aItemRect
= m_pImpl
->m_pHeaderBar
->GetItemRect( m_pImpl
->m_pHeaderBar
->GetItemId( _nColumn
) );
943 aTopLeft
.X() = aItemRect
.Left();
944 Size aSize
= aItemRect
.GetSize();
945 aRect
= Rectangle( aTopLeft
, aSize
);
946 Window
* pParent
= NULL
;
948 pParent
= GetAccessibleParentWindow();
949 aTopLeft
= aRect
.TopLeft();
950 aTopLeft
+= GetWindowExtentsRelative( pParent
).TopLeft();
951 aRect
= Rectangle( aTopLeft
, aRect
.GetSize() );
956 // -----------------------------------------------------------------------
957 Reference
< XAccessible
> SvHeaderTabListBox::CreateAccessibleCell( sal_Int32 _nRow
, sal_uInt16 _nColumnPos
)
959 OSL_ENSURE( m_pAccessible
, "Invalid call: Accessible is null" );
961 Reference
< XAccessible
> xChild
;
962 sal_Int32 nIndex
= -1;
964 if ( !AreChildrenTransient() )
966 const sal_uInt16 nColumnCount
= GetColumnCount();
968 // first call? -> initial list
969 if ( m_aAccessibleChildren
.empty() )
971 sal_Int32 nCount
= ( GetRowCount() + 1 ) * nColumnCount
;
972 m_aAccessibleChildren
.assign( nCount
, Reference
< XAccessible
>() );
975 nIndex
= ( _nRow
* nColumnCount
) + _nColumnPos
+ nColumnCount
;
976 xChild
= m_aAccessibleChildren
[ nIndex
];
981 TriState eState
= STATE_DONTKNOW
;
982 sal_Bool bIsCheckBox
= IsCellCheckBox( _nRow
, _nColumnPos
, eState
);
984 xChild
= m_pImpl
->m_aFactoryAccess
.getFactory().createAccessibleCheckBoxCell(
985 m_pAccessible
->getAccessibleChild( 0 ), *this, NULL
, _nRow
, _nColumnPos
, eState
, sal_False
);
987 xChild
= m_pImpl
->m_aFactoryAccess
.getFactory().createAccessibleBrowseBoxTableCell(
988 m_pAccessible
->getAccessibleChild( 0 ), *this, NULL
, _nRow
, _nColumnPos
, OFFSET_NONE
);
991 if ( !AreChildrenTransient() )
992 m_aAccessibleChildren
[ nIndex
] = xChild
;
997 // -----------------------------------------------------------------------
998 Reference
< XAccessible
> SvHeaderTabListBox::CreateAccessibleRowHeader( sal_Int32
)
1000 Reference
< XAccessible
> xHeader
;
1003 // -----------------------------------------------------------------------
1004 Reference
< XAccessible
> SvHeaderTabListBox::CreateAccessibleColumnHeader( sal_uInt16 _nColumn
)
1006 // first call? -> initial list
1007 if ( m_aAccessibleChildren
.empty() )
1009 const sal_uInt16 nColumnCount
= GetColumnCount();
1010 sal_Int32 nCount
= AreChildrenTransient() ?
1011 nColumnCount
: ( GetRowCount() + 1 ) * nColumnCount
;
1012 m_aAccessibleChildren
.assign( nCount
, Reference
< XAccessible
>() );
1016 Reference
< XAccessible
> xChild
= m_aAccessibleChildren
[ _nColumn
];
1018 if ( !xChild
.is() && m_pAccessible
)
1020 // no -> create new header cell
1021 xChild
= m_pImpl
->m_aFactoryAccess
.getFactory().createAccessibleBrowseBoxHeaderCell(
1022 _nColumn
, m_pAccessible
->getHeaderBar( ::svt::BBTYPE_COLUMNHEADERBAR
),
1023 *this, NULL
, ::svt::BBTYPE_COLUMNHEADERCELL
1027 m_aAccessibleChildren
[ _nColumn
] = xChild
;
1032 // -----------------------------------------------------------------------
1033 sal_Int32
SvHeaderTabListBox::GetAccessibleControlCount() const
1037 // -----------------------------------------------------------------------
1038 Reference
< XAccessible
> SvHeaderTabListBox::CreateAccessibleControl( sal_Int32
)
1040 Reference
< XAccessible
> xControl
;
1043 // -----------------------------------------------------------------------
1044 sal_Bool
SvHeaderTabListBox::ConvertPointToControlIndex( sal_Int32
&, const Point
& )
1048 // -----------------------------------------------------------------------
1049 sal_Bool
SvHeaderTabListBox::ConvertPointToCellAddress( sal_Int32
&, sal_uInt16
&, const Point
& )
1053 // -----------------------------------------------------------------------
1054 sal_Bool
SvHeaderTabListBox::ConvertPointToRowHeader( sal_Int32
&, const Point
& )
1058 // -----------------------------------------------------------------------
1059 sal_Bool
SvHeaderTabListBox::ConvertPointToColumnHeader( sal_uInt16
&, const Point
& )
1063 // -----------------------------------------------------------------------
1064 OUString
SvHeaderTabListBox::GetAccessibleObjectName( ::svt::AccessibleBrowseBoxObjType _eType
, sal_Int32 _nPos
) const
1069 case ::svt::BBTYPE_BROWSEBOX
:
1070 case ::svt::BBTYPE_TABLE
:
1071 case ::svt::BBTYPE_COLUMNHEADERBAR
:
1072 // should be empty now (see #i63983)
1073 aRetText
= OUString();
1076 case ::svt::BBTYPE_TABLECELL
:
1078 // here we need a valid pos, we can not handle -1
1081 sal_uInt16 nColumnCount
= GetColumnCount();
1082 if (nColumnCount
> 0)
1084 sal_Int32 nRow
= _nPos
/ nColumnCount
;
1085 sal_uInt16 nColumn
= static_cast< sal_uInt16
>( _nPos
% nColumnCount
);
1086 aRetText
= GetCellText( nRow
, nColumn
);
1091 case ::svt::BBTYPE_CHECKBOXCELL
:
1093 break; // checkbox cells have no name
1095 case ::svt::BBTYPE_COLUMNHEADERCELL
:
1097 aRetText
= m_pImpl
->m_pHeaderBar
->GetItemText( m_pImpl
->m_pHeaderBar
->GetItemId( (sal_uInt16
)_nPos
) );
1101 case ::svt::BBTYPE_ROWHEADERBAR
:
1102 case ::svt::BBTYPE_ROWHEADERCELL
:
1103 aRetText
= OUString( "error" );
1107 OSL_FAIL("BrowseBox::GetAccessibleName: invalid enum!");
1111 // -----------------------------------------------------------------------
1112 OUString
SvHeaderTabListBox::GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType _eType
, sal_Int32 _nPos
) const
1116 if( _eType
== ::svt::BBTYPE_TABLECELL
&& _nPos
!= -1 )
1118 const String
sVar1( RTL_CONSTASCII_USTRINGPARAM( "%1" ) );
1119 const String
sVar2( RTL_CONSTASCII_USTRINGPARAM( "%2" ) );
1121 sal_uInt16 nColumnCount
= GetColumnCount();
1122 if (nColumnCount
> 0)
1124 sal_Int32 nRow
= _nPos
/ nColumnCount
;
1125 sal_uInt16 nColumn
= static_cast< sal_uInt16
>( _nPos
% nColumnCount
);
1127 String
aText( SVT_RESSTR(STR_SVT_ACC_DESC_TABLISTBOX
) );
1128 aText
.SearchAndReplace( sVar1
, OUString::number( nRow
) );
1129 String sColHeader
= m_pImpl
->m_pHeaderBar
->GetItemText( m_pImpl
->m_pHeaderBar
->GetItemId( nColumn
) );
1130 if ( sColHeader
.Len() == 0 )
1131 sColHeader
= OUString::number( nColumn
);
1132 aText
.SearchAndReplace( sVar2
, sColHeader
);
1139 // -----------------------------------------------------------------------
1140 void SvHeaderTabListBox::FillAccessibleStateSet( ::utl::AccessibleStateSetHelper
& _rStateSet
, ::svt::AccessibleBrowseBoxObjType _eType
) const
1144 case ::svt::BBTYPE_BROWSEBOX
:
1145 case ::svt::BBTYPE_TABLE
:
1147 _rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
1149 _rStateSet
.AddState( AccessibleStateType::FOCUSED
);
1151 _rStateSet
.AddState( AccessibleStateType::ACTIVE
);
1154 _rStateSet
.AddState( AccessibleStateType::ENABLED
);
1155 _rStateSet
.AddState( AccessibleStateType::SENSITIVE
);
1157 if ( IsReallyVisible() )
1158 _rStateSet
.AddState( AccessibleStateType::VISIBLE
);
1159 if ( _eType
== ::svt::BBTYPE_TABLE
)
1162 if ( AreChildrenTransient() )
1163 _rStateSet
.AddState( AccessibleStateType::MANAGES_DESCENDANTS
);
1164 _rStateSet
.AddState( AccessibleStateType::MULTI_SELECTABLE
);
1169 case ::svt::BBTYPE_COLUMNHEADERBAR
:
1171 sal_Int32 nCurRow
= GetCurrRow();
1172 sal_uInt16 nCurColumn
= GetCurrColumn();
1173 if ( IsCellVisible( nCurRow
, nCurColumn
) )
1174 _rStateSet
.AddState( AccessibleStateType::VISIBLE
);
1175 _rStateSet
.AddState( AccessibleStateType::TRANSIENT
);
1179 case ::svt::BBTYPE_ROWHEADERCELL
:
1180 case ::svt::BBTYPE_COLUMNHEADERCELL
:
1182 _rStateSet
.AddState( AccessibleStateType::VISIBLE
);
1183 _rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
1184 _rStateSet
.AddState( AccessibleStateType::TRANSIENT
);
1191 // -----------------------------------------------------------------------
1192 void SvHeaderTabListBox::FillAccessibleStateSetForCell( ::utl::AccessibleStateSetHelper
& _rStateSet
, sal_Int32 _nRow
, sal_uInt16 _nColumn
) const
1194 _rStateSet
.AddState( AccessibleStateType::SELECTABLE
);
1195 if ( AreChildrenTransient() )
1196 _rStateSet
.AddState( AccessibleStateType::TRANSIENT
);
1198 if ( IsCellVisible( _nRow
, _nColumn
) )
1200 _rStateSet
.AddState( AccessibleStateType::VISIBLE
);
1201 _rStateSet
.AddState( AccessibleStateType::ENABLED
);
1204 if ( IsRowSelected( _nRow
) )
1206 _rStateSet
.AddState( AccessibleStateType::ACTIVE
);
1207 _rStateSet
.AddState( AccessibleStateType::SELECTED
);
1210 // -----------------------------------------------------------------------
1211 void SvHeaderTabListBox::GrabTableFocus()
1215 // -----------------------------------------------------------------------
1216 sal_Bool
SvHeaderTabListBox::GetGlyphBoundRects( const Point
& rOrigin
, const String
& rStr
, int nIndex
, int nLen
, int nBase
, MetricVector
& rVector
)
1218 return Control::GetGlyphBoundRects( rOrigin
, rStr
, nIndex
, nLen
, nBase
, rVector
);
1220 // -----------------------------------------------------------------------
1221 Rectangle
SvHeaderTabListBox::GetWindowExtentsRelative( Window
*pRelativeWindow
) const
1223 return Control::GetWindowExtentsRelative( pRelativeWindow
);
1225 // -----------------------------------------------------------------------
1226 void SvHeaderTabListBox::GrabFocus()
1228 Control::GrabFocus();
1230 // -----------------------------------------------------------------------
1231 Reference
< XAccessible
> SvHeaderTabListBox::GetAccessible( sal_Bool bCreate
)
1233 return Control::GetAccessible( bCreate
);
1235 // -----------------------------------------------------------------------
1236 Window
* SvHeaderTabListBox::GetAccessibleParentWindow() const
1238 return Control::GetAccessibleParentWindow();
1240 // -----------------------------------------------------------------------
1241 Window
* SvHeaderTabListBox::GetWindowInstance()
1245 // -----------------------------------------------------------------------
1246 Reference
< XAccessible
> SvHeaderTabListBox::CreateAccessible()
1248 Window
* pParent
= GetAccessibleParentWindow();
1249 DBG_ASSERT( pParent
, "SvHeaderTabListBox::::CreateAccessible - accessible parent not found" );
1251 Reference
< XAccessible
> xAccessible
;
1252 if ( m_pAccessible
) xAccessible
= m_pAccessible
->getMyself();
1254 if( pParent
&& !m_pAccessible
)
1256 Reference
< XAccessible
> xAccParent
= pParent
->GetAccessible();
1257 if ( xAccParent
.is() )
1259 m_pAccessible
= m_pImpl
->m_aFactoryAccess
.getFactory().createAccessibleTabListBox( xAccParent
, *this );
1260 if ( m_pAccessible
)
1261 xAccessible
= m_pAccessible
->getMyself();
1266 // -----------------------------------------------------------------------------
1267 Rectangle
SvHeaderTabListBox::GetFieldCharacterBounds(sal_Int32
,sal_Int32
,sal_Int32
)
1272 // -----------------------------------------------------------------------------
1273 sal_Int32
SvHeaderTabListBox::GetFieldIndexAtPoint(sal_Int32 _nRow
,sal_Int32 _nColumnPos
,const Point
& _rPoint
)
1275 String sText
= GetAccessibleCellText( _nRow
, static_cast< sal_uInt16
>( _nColumnPos
) );
1276 MetricVector aRects
;
1277 if ( GetGlyphBoundRects(Point(0,0),sText
,0,STRING_LEN
,0,aRects
) )
1279 for (MetricVector::iterator aIter
= aRects
.begin(); aIter
!= aRects
.end(); ++aIter
)
1281 if( aIter
->IsInside(_rPoint
) )
1282 return aIter
- aRects
.begin();
1288 // -----------------------------------------------------------------------------
1291 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */