fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svtools / source / contnr / svtabbx.cxx
blob3c8111f89e7c2be4d6bc3adba5d72a75eaf9d32f
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);
79 XubString aToken;
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);
89 else
90 aToken.Erase();
91 SvLBoxString* pStr = new SvLBoxString( pEntry, 0, aToken );
92 pEntry->AddItem( pStr );
93 pCurToken = pNextToken;
94 if( pCurToken )
95 pNextToken = GetToken( pCurToken, nCurTokenLen );
96 else
97 nCurTokenLen = 0;
102 SvTabListBox::SvTabListBox( Window* pParent, WinBits nBits )
103 : SvTreeListBox( pParent, nBits )
105 pTabList = 0;
106 nTabCount = 0;
107 pViewParent = 0;
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 )
124 pTabList = 0;
125 nTabCount = 0;
126 pViewParent = 0;
127 SvTabListBox::Resize();
128 SetHighlightRange();
131 SvTabListBox::~SvTabListBox()
133 // delete array
134 delete [] pTabList;
135 #ifdef DBG_UTIL
136 pTabList = 0;
137 nTabCount = 0;
138 #endif
141 void SvTabListBox::SetTabs( long* pTabs, MapUnit eMapUnit )
143 DBG_ASSERT(pTabs,"SetTabs:NULL-Ptr");
144 if( !pTabs )
145 return;
147 delete [] pTabList;
148 sal_uInt16 nCount = (sal_uInt16)(*pTabs);
149 pTabList = new SvLBoxTab[ nCount ];
150 nTabCount = nCount;
152 MapMode aMMSource( eMapUnit );
153 MapMode aMMDest( MAP_PIXEL );
155 pTabs++;
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;
165 if( IsUpdateMode() )
166 Invalidate();
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;
182 if( IsUpdateMode() )
183 Invalidate();
187 SvTreeListEntry* SvTabListBox::InsertEntry( const XubString& rText, SvTreeListEntry* pParent,
188 sal_Bool /*bChildrenOnDemand*/,
189 sal_uLong nPos, void* pUserData,
190 SvLBoxButtonKind )
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,
201 SvLBoxButtonKind )
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,
208 void* pUser )
210 XubString aStr;
211 if( nCol != 0xffff )
213 while( nCol )
215 aStr += '\t';
216 nCol--;
219 aStr += rStr;
220 XubString aFirstStr( aStr );
221 sal_uInt16 nEnd = aFirstStr.Search( '\t' );
222 if( nEnd != STRING_NOTFOUND )
224 aFirstStr.Erase( nEnd );
225 aCurEntry = aStr;
226 aCurEntry.Erase( 0, ++nEnd );
228 else
229 aCurEntry.Erase();
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 )
237 XubString aStr;
238 if( nCol != 0xffff )
240 while( nCol )
242 aStr += '\t';
243 nCol--;
246 aStr += rStr;
247 XubString aFirstStr( aStr );
248 sal_uInt16 nEnd = aFirstStr.Search( '\t' );
249 if( nEnd != STRING_NOTFOUND )
251 aFirstStr.Erase( nEnd );
252 aCurEntry = aStr;
253 aCurEntry.Erase( 0, ++nEnd );
255 else
256 aCurEntry.Erase();
258 return SvTreeListBox::InsertEntry(
259 aFirstStr,
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");
278 XubString aResult;
279 if( pEntry )
281 sal_uInt16 nCount = pEntry->ItemCount();
282 sal_uInt16 nCur = 0;
283 while( nCur < nCount )
285 const SvLBoxItem* pStr = pEntry->GetItem( nCur );
286 if (pStr->GetType() == SV_ITEM_ID_LBOXSTRING)
288 if( nCol == 0xffff )
290 if( aResult.Len() )
291 aResult += '\t';
292 aResult += static_cast<const SvLBoxString*>(pStr)->GetText();
294 else
296 if( nCol == 0 )
297 return static_cast<const SvLBoxString*>(pStr)->GetText();
298 nCol--;
301 nCur++;
304 return aResult;
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");
322 if( !pEntry )
323 return;
325 String sOldText = GetEntryText( pEntry, nCol );
326 if ( sOldText == rStr )
327 return;
329 sal_uInt16 nTextColumn = nCol;
330 const sal_Unicode* pCurToken = rStr.GetBuffer();
331 sal_uInt16 nCurTokenLen;
332 const sal_Unicode* pNextToken = GetToken( pCurToken, nCurTokenLen );
334 XubString aTemp;
335 sal_uInt16 nCount = pEntry->ItemCount();
336 sal_uInt16 nCur = 0;
337 while( nCur < nCount )
339 SvLBoxItem* pStr = pEntry->GetItem( nCur );
340 if (pStr && pStr->GetType() == SV_ITEM_ID_LBOXSTRING)
342 if( nCol == 0xffff )
344 if( pCurToken )
345 aTemp = OUString(pCurToken, nCurTokenLen);
346 else
347 aTemp.Erase(); // delete all columns without a token
348 ((SvLBoxString*)pStr)->SetText( aTemp );
349 pCurToken = pNextToken;
350 pNextToken = GetToken( pCurToken, nCurTokenLen );
352 else
354 if( !nCol )
356 aTemp = OUString(pCurToken, nCurTokenLen);
357 ((SvLBoxString*)pStr)->SetText( aTemp );
358 if( !pNextToken )
359 break;
360 pCurToken = pNextToken;
361 pNextToken = GetToken( pCurToken, nCurTokenLen );
363 else
364 nCol--;
367 nCur++;
369 GetModel()->InvalidateEntry( pEntry );
371 TabListBoxEventData* pData = new TabListBoxEventData( pEntry, nTextColumn, sOldText );
372 ImplCallEventListeners( VCLEVENT_TABLECELL_NAMECHANGED, pData );
373 delete 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" );
380 XubString aResult;
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();
387 return aResult;
390 sal_uLong SvTabListBox::GetEntryPos( const XubString& rStr, sal_uInt16 nCol )
392 sal_uLong nPos = 0;
393 SvTreeListEntry* pEntry = First();
394 while( pEntry )
396 XubString aStr( GetEntryText( pEntry, nCol ));
397 if( aStr == rStr )
398 return nPos;
399 pEntry = Next( pEntry );
400 nPos++;
402 return 0xffffffff;
405 sal_uLong SvTabListBox::GetEntryPos( const SvTreeListEntry* pEntry ) const
407 sal_uLong nPos = 0;
408 SvTreeListEntry* pTmpEntry = First();
409 while( pTmpEntry )
411 if ( pTmpEntry == pEntry )
412 return nPos;
413 pTmpEntry = Next( pTmpEntry );
414 ++nPos;
416 return 0xffffffff;
419 void SvTabListBox::Resize()
421 SvTreeListBox::Resize();
424 // static
425 const sal_Unicode* SvTabListBox::GetToken( const sal_Unicode* pPtr, sal_uInt16& rLen )
427 if( !pPtr || *pPtr == 0 )
429 rLen = 0;
430 return 0;
432 sal_Unicode c = *pPtr;
433 sal_uInt16 nLen = 0;
434 while( c != '\t' && c != 0 )
436 pPtr++;
437 nLen++;
438 c = *pPtr;
440 if( c )
441 pPtr++; // skip tab
442 else
443 pPtr = 0;
444 rLen = nLen;
445 return pPtr;
448 String SvTabListBox::GetTabEntryText( sal_uLong nPos, sal_uInt16 nCol ) const
450 SvTreeListEntry* pEntry = SvTreeListBox::GetEntry( nPos );
451 DBG_ASSERT( pEntry, "GetTabEntryText(): Invalid entry " );
452 XubString aResult;
453 if ( pEntry )
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 )
464 if ( aResult.Len() )
465 aResult += '\t';
466 aResult += static_cast<const SvLBoxString*>(pStr)->GetText();
468 else
470 if ( nCol == 0 )
472 String sRet = static_cast<const SvLBoxString*>(pStr)->GetText();
473 if ( sRet.Len() == 0 )
474 sRet = SVT_RESSTR( STR_SVT_ACC_EMPTY_FIELD );
475 return sRet;
477 --nCol;
480 ++nCur;
483 return aResult;
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 )
495 pEntry = pParent;
496 break;
498 else
500 nPos++;
501 pEntry = GetChildOnPos( pParent, _nEntryPos, nPos );
502 if ( pEntry )
503 break;
507 return pEntry;
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 )
517 return pParent;
518 else
520 _rPos++;
521 SvTreeListEntry* pEntry = GetChildOnPos( pParent, _nEntryPos, _rPos );
522 if ( pEntry )
523 return pEntry;
527 return NULL;
530 void SvTabListBox::SetTabJustify( sal_uInt16 nTab, SvTabJustify eJustify)
532 if( nTab >= nTabCount )
533 return;
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;
540 if( IsUpdateMode() )
541 Invalidate();
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 ------------------------------------------
555 namespace svt
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()
594 delete m_pImpl;
597 // -----------------------------------------------------------------------
599 void SvHeaderTabListBox::Paint( const Rectangle& rRect )
601 if ( m_bFirstPaint )
603 m_bFirstPaint = sal_False;
604 RepaintScrollBars();
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();
643 return pEntry;
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();
653 return pEntry;
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();
665 return pEntry;
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();
675 return n;
678 // -----------------------------------------------------------------------
680 sal_uLong SvHeaderTabListBox::Insert( SvTreeListEntry* pEntry, sal_uLong nRootPos )
682 sal_uLong nPos = SvTabListBox::Insert( pEntry, nRootPos );
683 RecalculateAccessibleChildren();
684 return nPos;
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() );
708 return 0;
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" );
717 if ( pParent )
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 );
727 return 0;
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 );
739 else
741 DBG_ASSERT( m_aAccessibleChildren.size() == nCount, "wrong children count" );
746 // -----------------------------------------------------------------------
748 sal_Bool SvHeaderTabListBox::IsCellCheckBox( long _nRow, sal_uInt16 _nColumn, TriState& _rState )
750 bool bRet = false;
751 SvTreeListEntry* pEntry = GetEntry( _nRow );
752 if ( pEntry )
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)
760 bRet = true;
761 _rState = ( ( pItem->GetButtonFlags() & SV_ITEMSTATE_UNCHECKED ) == 0 )
762 ? STATE_CHECK : STATE_NOCHECK;
765 else
767 SAL_WARN( "svtools.contnr", "SvHeaderTabListBox::IsCellCheckBox(): column out of range" );
770 return bRet;
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
786 sal_Int32 nRet = -1;
787 SvTreeListEntry* pEntry = GetCurEntry();
788 if ( pEntry )
790 sal_uLong nCount = GetEntryCount();
791 for ( sal_uLong i = 0; i < nCount; ++i )
793 if ( pEntry == GetEntry(i) )
795 nRet = i;
796 break;
801 return nRet;
803 // -----------------------------------------------------------------------
804 sal_uInt16 SvHeaderTabListBox::GetCurrColumn() const
806 sal_uInt16 nPos = GetCurrentTabPos() - 1;
807 return nPos;
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
822 return sal_False;
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 );
833 if ( bRet )
835 // first set cursor to _nRow
836 SetCursor( GetEntry( _nRow ), sal_True );
837 // then set the focus into _nColumn
838 bRet = ( SetCurrentTabPos( _nColumn ) == true );
840 return bRet;
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
876 return 0;
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
887 return sal_False;
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
900 return sal_True;
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 )
910 Rectangle aRect;
911 if ( _bIsColumnBar )
913 Window* pParent = NULL;
914 if ( !_bOnScreen )
915 pParent = m_pImpl->m_pHeaderBar->GetAccessibleParentWindow();
917 aRect = m_pImpl->m_pHeaderBar->GetWindowExtentsRelative( pParent );
919 return aRect;
921 // -----------------------------------------------------------------------
922 Rectangle SvHeaderTabListBox::calcTableRect( sal_Bool _bOnScreen )
924 Window* pParent = NULL;
925 if ( !_bOnScreen )
926 pParent = GetAccessibleParentWindow();
928 Rectangle aRect( GetWindowExtentsRelative( pParent ) );
929 return aRect;
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" );
935 Rectangle aRect;
936 SvTreeListEntry* pEntry = GetEntry( _nRow );
937 if ( pEntry )
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;
947 if ( !_bOnScreen )
948 pParent = GetAccessibleParentWindow();
949 aTopLeft = aRect.TopLeft();
950 aTopLeft += GetWindowExtentsRelative( pParent ).TopLeft();
951 aRect = Rectangle( aTopLeft, aRect.GetSize() );
954 return aRect;
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 ];
979 if ( !xChild.is() )
981 TriState eState = STATE_DONTKNOW;
982 sal_Bool bIsCheckBox = IsCellCheckBox( _nRow, _nColumnPos, eState );
983 if ( bIsCheckBox )
984 xChild = m_pImpl->m_aFactoryAccess.getFactory().createAccessibleCheckBoxCell(
985 m_pAccessible->getAccessibleChild( 0 ), *this, NULL, _nRow, _nColumnPos, eState, sal_False );
986 else
987 xChild = m_pImpl->m_aFactoryAccess.getFactory().createAccessibleBrowseBoxTableCell(
988 m_pAccessible->getAccessibleChild( 0 ), *this, NULL, _nRow, _nColumnPos, OFFSET_NONE );
990 // insert into list
991 if ( !AreChildrenTransient() )
992 m_aAccessibleChildren[ nIndex ] = xChild;
995 return xChild;
997 // -----------------------------------------------------------------------
998 Reference< XAccessible > SvHeaderTabListBox::CreateAccessibleRowHeader( sal_Int32 )
1000 Reference< XAccessible > xHeader;
1001 return 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 >() );
1015 // get header
1016 Reference< XAccessible > xChild = m_aAccessibleChildren[ _nColumn ];
1017 // already exists?
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
1026 // insert into list
1027 m_aAccessibleChildren[ _nColumn ] = xChild;
1030 return xChild;
1032 // -----------------------------------------------------------------------
1033 sal_Int32 SvHeaderTabListBox::GetAccessibleControlCount() const
1035 return -1;
1037 // -----------------------------------------------------------------------
1038 Reference< XAccessible > SvHeaderTabListBox::CreateAccessibleControl( sal_Int32 )
1040 Reference< XAccessible > xControl;
1041 return xControl;
1043 // -----------------------------------------------------------------------
1044 sal_Bool SvHeaderTabListBox::ConvertPointToControlIndex( sal_Int32&, const Point& )
1046 return sal_False;
1048 // -----------------------------------------------------------------------
1049 sal_Bool SvHeaderTabListBox::ConvertPointToCellAddress( sal_Int32&, sal_uInt16&, const Point& )
1051 return sal_False;
1053 // -----------------------------------------------------------------------
1054 sal_Bool SvHeaderTabListBox::ConvertPointToRowHeader( sal_Int32&, const Point& )
1056 return sal_False;
1058 // -----------------------------------------------------------------------
1059 sal_Bool SvHeaderTabListBox::ConvertPointToColumnHeader( sal_uInt16&, const Point& )
1061 return sal_False;
1063 // -----------------------------------------------------------------------
1064 OUString SvHeaderTabListBox::GetAccessibleObjectName( ::svt::AccessibleBrowseBoxObjType _eType, sal_Int32 _nPos ) const
1066 OUString aRetText;
1067 switch( _eType )
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();
1074 break;
1076 case ::svt::BBTYPE_TABLECELL:
1078 // here we need a valid pos, we can not handle -1
1079 if ( _nPos >= 0 )
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 );
1089 break;
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 ) );
1098 break;
1101 case ::svt::BBTYPE_ROWHEADERBAR:
1102 case ::svt::BBTYPE_ROWHEADERCELL:
1103 aRetText = OUString( "error" );
1104 break;
1106 default:
1107 OSL_FAIL("BrowseBox::GetAccessibleName: invalid enum!");
1109 return aRetText;
1111 // -----------------------------------------------------------------------
1112 OUString SvHeaderTabListBox::GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType _eType, sal_Int32 _nPos ) const
1114 OUString aRetText;
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 );
1133 aRetText = aText;
1137 return aRetText;
1139 // -----------------------------------------------------------------------
1140 void SvHeaderTabListBox::FillAccessibleStateSet( ::utl::AccessibleStateSetHelper& _rStateSet, ::svt::AccessibleBrowseBoxObjType _eType ) const
1142 switch( _eType )
1144 case ::svt::BBTYPE_BROWSEBOX:
1145 case ::svt::BBTYPE_TABLE:
1147 _rStateSet.AddState( AccessibleStateType::FOCUSABLE );
1148 if ( HasFocus() )
1149 _rStateSet.AddState( AccessibleStateType::FOCUSED );
1150 if ( IsActive() )
1151 _rStateSet.AddState( AccessibleStateType::ACTIVE );
1152 if ( IsEnabled() )
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 );
1166 break;
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 );
1176 break;
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 );
1185 break;
1187 default:
1188 break;
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()
1213 GrabFocus();
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()
1243 return this;
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();
1264 return xAccessible;
1266 // -----------------------------------------------------------------------------
1267 Rectangle SvHeaderTabListBox::GetFieldCharacterBounds(sal_Int32,sal_Int32,sal_Int32)
1269 Rectangle aRect;
1270 return aRect;
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();
1286 return -1;
1288 // -----------------------------------------------------------------------------
1291 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */