GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svtools / source / contnr / svtabbx.cxx
blob7a091e699eced69925976564e0fefd4d28d241ae
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/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;
34 #define MYTABMASK \
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();
42 if( nTabCount )
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!
57 if( !pViewParent )
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);
80 sal_Int32 nIndex = 0;
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 )
95 pTabList = 0;
96 nTabCount = 0;
97 pViewParent = 0;
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 )
114 pTabList = 0;
115 nTabCount = 0;
116 pViewParent = 0;
117 SvTabListBox::Resize();
118 SetHighlightRange();
121 SvTabListBox::~SvTabListBox()
123 // delete array
124 delete [] pTabList;
125 #ifdef DBG_UTIL
126 pTabList = 0;
127 nTabCount = 0;
128 #endif
131 void SvTabListBox::SetTabs( long* pTabs, MapUnit eMapUnit )
133 DBG_ASSERT(pTabs,"SetTabs:NULL-Ptr");
134 if( !pTabs )
135 return;
137 delete [] pTabList;
138 sal_uInt16 nCount = (sal_uInt16)(*pTabs);
139 pTabList = new SvLBoxTab[ nCount ];
140 nTabCount = nCount;
142 MapMode aMMSource( eMapUnit );
143 MapMode aMMDest( MAP_PIXEL );
145 pTabs++;
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;
155 if( IsUpdateMode() )
156 Invalidate();
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;
172 if( IsUpdateMode() )
173 Invalidate();
177 SvTreeListEntry* SvTabListBox::InsertEntry( const OUString& rText, SvTreeListEntry* pParent,
178 sal_Bool /*bChildrenOnDemand*/,
179 sal_uLong nPos, void* pUserData,
180 SvLBoxButtonKind )
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,
191 SvLBoxButtonKind )
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,
198 void* pUser )
200 OUString aStr;
201 if( nCol != 0xffff )
203 while( nCol )
205 aStr += "\t";
206 nCol--;
209 aStr += rStr;
210 OUString aFirstStr( aStr );
211 sal_Int32 nEnd = aFirstStr.indexOf( '\t' );
212 if( nEnd != -1 )
214 aFirstStr = aFirstStr.copy(0, nEnd);
215 aCurEntry = aStr.copy(++nEnd);
217 else
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 )
226 OUString aStr;
227 if( nCol != 0xffff )
229 while( nCol )
231 aStr += "\t";
232 nCol--;
235 aStr += rStr;
236 OUString aFirstStr( aStr );
237 sal_Int32 nEnd = aFirstStr.indexOf('\t');
238 if (nEnd != -1)
240 aFirstStr = aFirstStr.copy(0, nEnd);
241 aCurEntry = aStr.copy(++nEnd);
243 else
244 aCurEntry = OUString();
246 return SvTreeListBox::InsertEntry(
247 aFirstStr,
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");
266 OUString aResult;
267 if( pEntry )
269 sal_uInt16 nCount = pEntry->ItemCount();
270 sal_uInt16 nCur = 0;
271 while( nCur < nCount )
273 const SvLBoxItem* pStr = pEntry->GetItem( nCur );
274 if (pStr->GetType() == SV_ITEM_ID_LBOXSTRING)
276 if( nCol == 0xffff )
278 if (!aResult.isEmpty())
279 aResult += "\t";
280 aResult += static_cast<const SvLBoxString*>(pStr)->GetText();
282 else
284 if( nCol == 0 )
285 return static_cast<const SvLBoxString*>(pStr)->GetText();
286 nCol--;
289 nCur++;
292 return aResult;
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");
310 if( !pEntry )
311 return;
313 OUString sOldText = GetEntryText(pEntry, nCol);
314 if (sOldText == rStr)
315 return;
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)
330 break;
332 else
334 --nCol;
338 GetModel()->InvalidateEntry( pEntry );
340 TabListBoxEventData* pData = new TabListBoxEventData( pEntry, nTextColumn, sOldText );
341 ImplCallEventListeners( VCLEVENT_TABLECELL_NAMECHANGED, pData );
342 delete 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" );
349 OUString aResult;
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();
356 return aResult;
359 sal_uLong SvTabListBox::GetEntryPos( const OUString& rStr, sal_uInt16 nCol )
361 sal_uLong nPos = 0;
362 SvTreeListEntry* pEntry = First();
363 while( pEntry )
365 OUString aStr( GetEntryText( pEntry, nCol ));
366 if( aStr == rStr )
367 return nPos;
368 pEntry = Next( pEntry );
369 nPos++;
371 return 0xffffffff;
374 sal_uLong SvTabListBox::GetEntryPos( const SvTreeListEntry* pEntry ) const
376 sal_uLong nPos = 0;
377 SvTreeListEntry* pTmpEntry = First();
378 while( pTmpEntry )
380 if ( pTmpEntry == pEntry )
381 return nPos;
382 pTmpEntry = Next( pTmpEntry );
383 ++nPos;
385 return 0xffffffff;
388 void SvTabListBox::Resize()
390 SvTreeListBox::Resize();
393 // static
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 " );
403 OUString aResult;
404 if ( pEntry )
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())
416 aResult += "\t";
417 aResult += static_cast<const SvLBoxString*>(pStr)->GetText();
419 else
421 if ( nCol == 0 )
423 OUString sRet = static_cast<const SvLBoxString*>(pStr)->GetText();
424 if ( sRet.isEmpty() )
425 sRet = SVT_RESSTR( STR_SVT_ACC_EMPTY_FIELD );
426 return sRet;
428 --nCol;
431 ++nCur;
434 return aResult;
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 )
446 pEntry = pParent;
447 break;
449 else
451 nPos++;
452 pEntry = GetChildOnPos( pParent, _nEntryPos, nPos );
453 if ( pEntry )
454 break;
458 return pEntry;
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 )
468 return pParent;
469 else
471 _rPos++;
472 SvTreeListEntry* pEntry = GetChildOnPos( pParent, _nEntryPos, _rPos );
473 if ( pEntry )
474 return pEntry;
478 return NULL;
481 void SvTabListBox::SetTabJustify( sal_uInt16 nTab, SvTabJustify eJustify)
483 if( nTab >= nTabCount )
484 return;
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;
491 if( IsUpdateMode() )
492 Invalidate();
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 ------------------------------------------
506 namespace svt
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()
545 delete m_pImpl;
548 // -----------------------------------------------------------------------
550 void SvHeaderTabListBox::Paint( const Rectangle& rRect )
552 if ( m_bFirstPaint )
554 m_bFirstPaint = sal_False;
555 RepaintScrollBars();
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();
594 return pEntry;
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();
604 return pEntry;
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();
616 return pEntry;
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();
626 return n;
629 // -----------------------------------------------------------------------
631 sal_uLong SvHeaderTabListBox::Insert( SvTreeListEntry* pEntry, sal_uLong nRootPos )
633 sal_uLong nPos = SvTabListBox::Insert( pEntry, nRootPos );
634 RecalculateAccessibleChildren();
635 return nPos;
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() );
659 return 0;
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" );
668 if ( pParent )
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 );
678 return 0;
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 );
690 else
692 DBG_ASSERT( m_aAccessibleChildren.size() == nCount, "wrong children count" );
697 // -----------------------------------------------------------------------
699 sal_Bool SvHeaderTabListBox::IsCellCheckBox( long _nRow, sal_uInt16 _nColumn, TriState& _rState )
701 bool bRet = false;
702 SvTreeListEntry* pEntry = GetEntry( _nRow );
703 if ( pEntry )
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)
711 bRet = true;
712 _rState = ( ( pItem->GetButtonFlags() & SV_ITEMSTATE_UNCHECKED ) == 0 )
713 ? STATE_CHECK : STATE_NOCHECK;
716 else
718 SAL_WARN( "svtools.contnr", "SvHeaderTabListBox::IsCellCheckBox(): column out of range" );
721 return bRet;
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
737 sal_Int32 nRet = -1;
738 SvTreeListEntry* pEntry = GetCurEntry();
739 if ( pEntry )
741 sal_uLong nCount = GetEntryCount();
742 for ( sal_uLong i = 0; i < nCount; ++i )
744 if ( pEntry == GetEntry(i) )
746 nRet = i;
747 break;
752 return nRet;
754 // -----------------------------------------------------------------------
755 sal_uInt16 SvHeaderTabListBox::GetCurrColumn() const
757 sal_uInt16 nPos = GetCurrentTabPos() - 1;
758 return nPos;
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
773 return sal_False;
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 );
784 if ( bRet )
786 // first set cursor to _nRow
787 SetCursor( GetEntry( _nRow ), sal_True );
788 // then set the focus into _nColumn
789 bRet = ( SetCurrentTabPos( _nColumn ) == true );
791 return bRet;
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
827 return 0;
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
838 return sal_False;
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
851 return sal_True;
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 )
861 Rectangle aRect;
862 if ( _bIsColumnBar )
864 Window* pParent = NULL;
865 if ( !_bOnScreen )
866 pParent = m_pImpl->m_pHeaderBar->GetAccessibleParentWindow();
868 aRect = m_pImpl->m_pHeaderBar->GetWindowExtentsRelative( pParent );
870 return aRect;
872 // -----------------------------------------------------------------------
873 Rectangle SvHeaderTabListBox::calcTableRect( sal_Bool _bOnScreen )
875 Window* pParent = NULL;
876 if ( !_bOnScreen )
877 pParent = GetAccessibleParentWindow();
879 Rectangle aRect( GetWindowExtentsRelative( pParent ) );
880 return aRect;
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" );
886 Rectangle aRect;
887 SvTreeListEntry* pEntry = GetEntry( _nRow );
888 if ( pEntry )
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;
898 if ( !_bOnScreen )
899 pParent = GetAccessibleParentWindow();
900 aTopLeft = aRect.TopLeft();
901 aTopLeft += GetWindowExtentsRelative( pParent ).TopLeft();
902 aRect = Rectangle( aTopLeft, aRect.GetSize() );
905 return aRect;
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 ];
930 if ( !xChild.is() )
932 TriState eState = STATE_DONTKNOW;
933 sal_Bool bIsCheckBox = IsCellCheckBox( _nRow, _nColumnPos, eState );
934 if ( bIsCheckBox )
935 xChild = m_pImpl->m_aFactoryAccess.getFactory().createAccessibleCheckBoxCell(
936 m_pAccessible->getAccessibleChild( 0 ), *this, NULL, _nRow, _nColumnPos, eState, sal_False );
937 else
938 xChild = m_pImpl->m_aFactoryAccess.getFactory().createAccessibleBrowseBoxTableCell(
939 m_pAccessible->getAccessibleChild( 0 ), *this, NULL, _nRow, _nColumnPos, OFFSET_NONE );
941 // insert into list
942 if ( !AreChildrenTransient() )
943 m_aAccessibleChildren[ nIndex ] = xChild;
946 return xChild;
948 // -----------------------------------------------------------------------
949 Reference< XAccessible > SvHeaderTabListBox::CreateAccessibleRowHeader( sal_Int32 )
951 Reference< XAccessible > xHeader;
952 return 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 >() );
966 // get header
967 Reference< XAccessible > xChild = m_aAccessibleChildren[ _nColumn ];
968 // already exists?
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
977 // insert into list
978 m_aAccessibleChildren[ _nColumn ] = xChild;
981 return xChild;
983 // -----------------------------------------------------------------------
984 sal_Int32 SvHeaderTabListBox::GetAccessibleControlCount() const
986 return -1;
988 // -----------------------------------------------------------------------
989 Reference< XAccessible > SvHeaderTabListBox::CreateAccessibleControl( sal_Int32 )
991 Reference< XAccessible > xControl;
992 return xControl;
994 // -----------------------------------------------------------------------
995 sal_Bool SvHeaderTabListBox::ConvertPointToControlIndex( sal_Int32&, const Point& )
997 return sal_False;
999 // -----------------------------------------------------------------------
1000 sal_Bool SvHeaderTabListBox::ConvertPointToCellAddress( sal_Int32&, sal_uInt16&, const Point& )
1002 return sal_False;
1004 // -----------------------------------------------------------------------
1005 sal_Bool SvHeaderTabListBox::ConvertPointToRowHeader( sal_Int32&, const Point& )
1007 return sal_False;
1009 // -----------------------------------------------------------------------
1010 sal_Bool SvHeaderTabListBox::ConvertPointToColumnHeader( sal_uInt16&, const Point& )
1012 return sal_False;
1014 // -----------------------------------------------------------------------
1015 OUString SvHeaderTabListBox::GetAccessibleObjectName( ::svt::AccessibleBrowseBoxObjType _eType, sal_Int32 _nPos ) const
1017 OUString aRetText;
1018 switch( _eType )
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();
1025 break;
1027 case ::svt::BBTYPE_TABLECELL:
1029 // here we need a valid pos, we can not handle -1
1030 if ( _nPos >= 0 )
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 );
1040 break;
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 ) );
1049 break;
1052 case ::svt::BBTYPE_ROWHEADERBAR:
1053 case ::svt::BBTYPE_ROWHEADERCELL:
1054 aRetText = "error";
1055 break;
1057 default:
1058 OSL_FAIL("BrowseBox::GetAccessibleName: invalid enum!");
1060 return aRetText;
1062 // -----------------------------------------------------------------------
1063 OUString SvHeaderTabListBox::GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType _eType, sal_Int32 _nPos ) const
1065 OUString aRetText;
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 );
1084 aRetText = aText;
1088 return aRetText;
1090 // -----------------------------------------------------------------------
1091 void SvHeaderTabListBox::FillAccessibleStateSet( ::utl::AccessibleStateSetHelper& _rStateSet, ::svt::AccessibleBrowseBoxObjType _eType ) const
1093 switch( _eType )
1095 case ::svt::BBTYPE_BROWSEBOX:
1096 case ::svt::BBTYPE_TABLE:
1098 _rStateSet.AddState( AccessibleStateType::FOCUSABLE );
1099 if ( HasFocus() )
1100 _rStateSet.AddState( AccessibleStateType::FOCUSED );
1101 if ( IsActive() )
1102 _rStateSet.AddState( AccessibleStateType::ACTIVE );
1103 if ( IsEnabled() )
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 );
1117 break;
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 );
1127 break;
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 );
1136 break;
1138 default:
1139 break;
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()
1164 GrabFocus();
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()
1194 return this;
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();
1215 return xAccessible;
1217 // -----------------------------------------------------------------------------
1218 Rectangle SvHeaderTabListBox::GetFieldCharacterBounds(sal_Int32,sal_Int32,sal_Int32)
1220 Rectangle aRect;
1221 return aRect;
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();
1237 return -1;
1239 // -----------------------------------------------------------------------------
1242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */