Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / accessibility / charmapacc.cxx
blob80198498273b62baf0c94bf6e40b9f620317d4a7
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 <unotools/accessiblestatesethelper.hxx>
21 #include <vcl/svapp.hxx>
22 #include <stdio.h>
23 #include <svx/charmap.hxx>
24 #include "charmapacc.hxx"
25 #include <com/sun/star/accessibility/AccessibleRole.hpp>
26 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
27 #include <toolkit/helper/externallock.hxx>
28 #include <toolkit/helper/convert.hxx>
29 #include <osl/interlck.h>
30 #include <svx/dialmgr.hxx>
31 #include "accessibility.hrc"
32 #include <comphelper/types.hxx>
34 namespace svx
36 using namespace comphelper;
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::lang;
40 using namespace ::com::sun::star::accessibility;
43 // - SvxShowCharSetVirtualAcc -
45 SvxShowCharSetVirtualAcc::SvxShowCharSetVirtualAcc( SvxShowCharSet* pParent ) : OAccessibleComponentHelper(new VCLExternalSolarLock())
46 ,mpParent( pParent )
47 ,m_pTable(NULL)
49 osl_atomic_increment(&m_refCount);
51 lateInit(this);
53 osl_atomic_decrement(&m_refCount);
58 SvxShowCharSetVirtualAcc::~SvxShowCharSetVirtualAcc()
60 ensureDisposed();
61 delete getExternalLock();
64 IMPLEMENT_FORWARD_XINTERFACE2( SvxShowCharSetVirtualAcc, OAccessibleComponentHelper, OAccessibleHelper_Base_2 )
65 IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvxShowCharSetVirtualAcc, OAccessibleComponentHelper, OAccessibleHelper_Base_2 )
67 void SAL_CALL SvxShowCharSetVirtualAcc::fireEvent(
68 const sal_Int16 _nEventId,
69 const ::com::sun::star::uno::Any& _rOldValue,
70 const ::com::sun::star::uno::Any& _rNewValue
73 if ( m_pTable )
74 m_pTable->fireEvent(_nEventId,_rOldValue,_rNewValue);
77 sal_Int32 SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleChildCount( ) throw (RuntimeException, std::exception)
79 OExternalLockGuard aGuard( this );
80 ensureAlive();
81 return ( mpParent->getScrollBar()->IsVisible() ) ? 2 : 1;
84 uno::Reference< css::accessibility::XAccessible > SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleAtPoint( const awt::Point& aPoint )
85 throw (uno::RuntimeException, std::exception)
87 OExternalLockGuard aGuard( this );
88 ensureAlive();
90 uno::Reference< css::accessibility::XAccessible > xRet;
91 const sal_uInt16 nItemId = sal::static_int_cast<sal_uInt16>(mpParent->PixelToMapIndex( Point( aPoint.X, aPoint.Y ) ));
93 if( sal_uInt16(-1) != nItemId )
95 if ( !m_pTable )
96 m_pTable = new SvxShowCharSetAcc(this);
97 xRet = m_pTable;
99 else if ( mpParent->getScrollBar()->IsVisible() )
101 const Point aOutPos( mpParent->getScrollBar()->GetPosPixel() );
102 const Size aScrollBar = mpParent->getScrollBar()->GetOutputSizePixel();
103 Rectangle aRect(aOutPos,aScrollBar);
105 if ( aRect.IsInside(VCLPoint(aPoint)) )
106 xRet = mpParent->getScrollBar()->GetAccessible();
108 return xRet;
111 uno::Any SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleKeyBinding()
112 throw (uno::RuntimeException)
114 return uno::Any();
117 void SAL_CALL SvxShowCharSetVirtualAcc::grabFocus()
118 throw (uno::RuntimeException, std::exception)
120 OExternalLockGuard aGuard( this );
121 ensureAlive();
122 mpParent->GrabFocus();
127 Reference< XAccessible > SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
129 OExternalLockGuard aGuard( this );
130 ensureAlive();
131 if ( mpParent->getScrollBar()->IsVisible() && i == 0 )
132 return mpParent->getScrollBar()->GetAccessible();
133 else if ( i == 1 )
135 if ( !m_xAcc.is() )
137 m_pTable = new SvxShowCharSetAcc(this);
138 m_xAcc = m_pTable;
141 else
142 throw IndexOutOfBoundsException();
143 return m_xAcc;
146 Reference< XAccessible > SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleParent( ) throw (RuntimeException, std::exception)
148 OExternalLockGuard aGuard( this );
149 ensureAlive();
150 Window* pParent = mpParent->GetParent();
151 uno::Reference< css::accessibility::XAccessible > xRet;
153 if ( pParent )
154 xRet = pParent->GetAccessible();
156 return xRet;
159 ::com::sun::star::awt::Rectangle SvxShowCharSetVirtualAcc::implGetBounds( ) throw (RuntimeException)
161 ::com::sun::star::awt::Rectangle aBounds ( 0, 0, 0, 0 );
162 Window* pWindow = mpParent;
163 if ( pWindow )
165 Rectangle aRect = pWindow->GetWindowExtentsRelative( NULL );
166 aBounds = AWTRectangle( aRect );
167 Window* pParent = pWindow->GetAccessibleParentWindow();
168 if ( pParent )
170 Rectangle aParentRect = pParent->GetWindowExtentsRelative( NULL );
171 ::com::sun::star::awt::Point aParentScreenLoc = AWTPoint( aParentRect.TopLeft() );
172 aBounds.X -= aParentScreenLoc.X;
173 aBounds.Y -= aParentScreenLoc.Y;
176 return aBounds;
179 sal_Int16 SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleRole( ) throw (RuntimeException, std::exception)
181 return css::accessibility::AccessibleRole::SCROLL_PANE;
184 OUString SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleDescription( ) throw (RuntimeException, std::exception)
186 OExternalLockGuard aGuard( this );
187 return SVX_RESSTR( RID_SVXSTR_CHARACTER_SELECTION);
190 OUString SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleName( ) throw (RuntimeException, std::exception)
192 OExternalLockGuard aGuard( this );
193 return SVX_RESSTR( RID_SVXSTR_CHAR_SEL_DESC);
196 Reference< XAccessibleRelationSet > SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleRelationSet( ) throw (RuntimeException, std::exception)
198 return Reference< XAccessibleRelationSet >();
201 Reference< XAccessibleStateSet > SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleStateSet( ) throw (RuntimeException, std::exception)
203 OExternalLockGuard aGuard( this );
205 ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper;
207 if( mpParent )
209 // SELECTABLE
210 pStateSet->AddState( AccessibleStateType::FOCUSABLE );
211 if ( mpParent->HasFocus() )
212 pStateSet->AddState( AccessibleStateType::FOCUSED );
213 if ( mpParent->IsActive() )
214 pStateSet->AddState( AccessibleStateType::ACTIVE );
215 if ( mpParent->IsEnabled() )
217 pStateSet->AddState( AccessibleStateType::ENABLED );
218 pStateSet->AddState( AccessibleStateType::SENSITIVE );
220 if ( mpParent->IsReallyVisible() )
221 pStateSet->AddState( AccessibleStateType::VISIBLE );
224 return pStateSet;
227 void SAL_CALL SvxShowCharSetVirtualAcc::disposing()
229 OAccessibleContextHelper::disposing();
230 if ( m_pTable )
231 m_pTable->dispose();
232 m_pTable = NULL;
236 // - SvxShowCharSetItem -
239 SvxShowCharSetItem::SvxShowCharSetItem( SvxShowCharSet& rParent,SvxShowCharSetAcc* _pParent,sal_uInt16 _nPos ) :
240 mrParent( rParent )
241 ,mnId( _nPos )
242 ,m_pItem(NULL)
243 ,m_pParent(_pParent)
248 SvxShowCharSetItem::~SvxShowCharSetItem()
250 if ( m_xAcc.is() )
252 m_pItem->ParentDestroyed();
253 ClearAccessible();
259 uno::Reference< css::accessibility::XAccessible > SvxShowCharSetItem::GetAccessible()
261 if( !m_xAcc.is() )
263 m_pItem = new SvxShowCharSetItemAcc( this );
264 m_xAcc = m_pItem;
267 return m_xAcc;
272 void SvxShowCharSetItem::ClearAccessible()
274 if ( m_xAcc.is() )
276 m_pItem = NULL;
277 m_xAcc = NULL;
283 // - SvxShowCharSetAcc -
286 SvxShowCharSetAcc::SvxShowCharSetAcc( SvxShowCharSetVirtualAcc* _pParent ) : OAccessibleSelectionHelper(new VCLExternalSolarLock())
287 ,m_pParent( _pParent )
289 osl_atomic_increment(&m_refCount);
291 lateInit(this);
293 osl_atomic_decrement(&m_refCount);
298 SvxShowCharSetAcc::~SvxShowCharSetAcc()
300 ensureDisposed();
301 delete getExternalLock();
304 void SAL_CALL SvxShowCharSetAcc::disposing()
306 OAccessibleSelectionHelper::disposing();
307 ::std::vector< Reference< XAccessible > >::iterator aIter = m_aChildren.begin();
308 ::std::vector< Reference< XAccessible > >::iterator aEnd = m_aChildren.end();
309 for (;aIter != aEnd ; ++aIter)
310 ::comphelper::disposeComponent(*aIter);
312 m_aChildren.clear();
313 m_pParent = NULL;
317 IMPLEMENT_FORWARD_XINTERFACE2( SvxShowCharSetAcc, OAccessibleSelectionHelper, OAccessibleHelper_Base )
318 IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvxShowCharSetAcc, OAccessibleSelectionHelper, OAccessibleHelper_Base )
320 bool SvxShowCharSetAcc::implIsSelected( sal_Int32 nAccessibleChildIndex ) throw (RuntimeException)
322 return m_pParent && m_pParent->getCharSetControl()->IsSelected(
323 sal::static_int_cast<sal_uInt16>(nAccessibleChildIndex));
326 // select the specified child => watch for special ChildIndexes (ACCESSIBLE_SELECTION_CHILD_xxx)
327 void SvxShowCharSetAcc::implSelect( sal_Int32 nAccessibleChildIndex, sal_Bool bSelect ) throw (IndexOutOfBoundsException, RuntimeException)
329 if ( m_pParent )
331 if ( bSelect )
332 m_pParent->getCharSetControl()->SelectIndex(nAccessibleChildIndex, true);
333 else
334 m_pParent->getCharSetControl()->DeSelect();
338 ::com::sun::star::awt::Rectangle SvxShowCharSetAcc::implGetBounds( ) throw (RuntimeException)
340 const Point aOutPos;//( m_pParent->getCharSetControl()->GetPosPixel() );
341 Size aOutSize( m_pParent->getCharSetControl()->GetOutputSizePixel());
342 if ( m_pParent->getCharSetControl()->getScrollBar()->IsVisible() )
344 const Size aScrollBar = m_pParent->getCharSetControl()->getScrollBar()->GetOutputSizePixel();
345 aOutSize.Width() -= aScrollBar.Width();
348 awt::Rectangle aRet;
350 aRet.X = aOutPos.X();
351 aRet.Y = aOutPos.Y();
352 aRet.Width = aOutSize.Width();
353 aRet.Height = aOutSize.Height();
355 return aRet;
358 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleChildCount()
359 throw (uno::RuntimeException, std::exception)
361 OExternalLockGuard aGuard( this );
362 ensureAlive();
363 return m_pParent->getCharSetControl()->getMaxCharCount();
368 uno::Reference< css::accessibility::XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleChild( sal_Int32 i )
369 throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
371 OExternalLockGuard aGuard( this );
372 ensureAlive();
373 uno::Reference< css::accessibility::XAccessible > xRet;
374 SvxShowCharSetItem* pItem = m_pParent->getCharSetControl()->ImplGetItem( static_cast< sal_uInt16 >( i ) );
376 if( pItem )
378 pItem->m_pParent = this;
379 xRet = pItem->GetAccessible();
380 m_aChildren.push_back(xRet);
382 else
383 throw lang::IndexOutOfBoundsException();
385 return xRet;
390 uno::Reference< css::accessibility::XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleParent()
391 throw (uno::RuntimeException, std::exception)
393 OExternalLockGuard aGuard( this );
394 ensureAlive();
395 return m_pParent;
400 sal_Int16 SAL_CALL SvxShowCharSetAcc::getAccessibleRole()
401 throw (uno::RuntimeException, std::exception)
403 return css::accessibility::AccessibleRole::TABLE;
408 OUString SAL_CALL SvxShowCharSetAcc::getAccessibleDescription()
409 throw (uno::RuntimeException, std::exception)
411 OExternalLockGuard aGuard( this );
412 return SVX_RESSTR( RID_SVXSTR_CHARACTER_SELECTION );
417 OUString SAL_CALL SvxShowCharSetAcc::getAccessibleName()
418 throw (uno::RuntimeException, std::exception)
420 OExternalLockGuard aGuard( this );
421 ensureAlive();
422 return SVX_RESSTR( RID_SVXSTR_CHAR_SEL_DESC );
427 uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL SvxShowCharSetAcc::getAccessibleRelationSet()
428 throw (uno::RuntimeException, std::exception)
430 return uno::Reference< css::accessibility::XAccessibleRelationSet >();
435 uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL SvxShowCharSetAcc::getAccessibleStateSet()
436 throw (uno::RuntimeException, std::exception)
438 OExternalLockGuard aGuard( this );
440 ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper;
442 if( m_pParent->getCharSetControl() )
444 // SELECTABLE
445 pStateSet->AddState( AccessibleStateType::FOCUSABLE );
446 if ( m_pParent->getCharSetControl()->HasFocus() )
447 pStateSet->AddState( AccessibleStateType::FOCUSED );
448 if ( m_pParent->getCharSetControl()->IsActive() )
449 pStateSet->AddState( AccessibleStateType::ACTIVE );
450 if ( m_pParent->getCharSetControl()->IsEnabled() )
452 pStateSet->AddState( AccessibleStateType::ENABLED );
453 pStateSet->AddState( AccessibleStateType::SENSITIVE );
455 if ( m_pParent->getCharSetControl()->IsReallyVisible() )
456 pStateSet->AddState( AccessibleStateType::VISIBLE );
458 pStateSet->AddState( AccessibleStateType::MANAGES_DESCENDANTS );
461 return pStateSet;
465 uno::Reference< css::accessibility::XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleAtPoint( const awt::Point& aPoint )
466 throw (uno::RuntimeException, std::exception)
468 OExternalLockGuard aGuard( this );
469 ensureAlive();
471 uno::Reference< css::accessibility::XAccessible > xRet;
472 const sal_uInt16 nItemId = sal::static_int_cast<sal_uInt16>(
473 m_pParent->getCharSetControl()->PixelToMapIndex( Point( aPoint.X, aPoint.Y ) ));
475 if( sal_uInt16(-1) != nItemId )
477 SvxShowCharSetItem* pItem = m_pParent->getCharSetControl()->ImplGetItem( nItemId );
478 xRet = pItem->GetAccessible();
480 return xRet;
486 void SAL_CALL SvxShowCharSetAcc::grabFocus()
487 throw (uno::RuntimeException, std::exception)
489 OExternalLockGuard aGuard( this );
490 ensureAlive();
491 m_pParent->getCharSetControl()->GrabFocus();
496 uno::Any SAL_CALL SvxShowCharSetAcc::getAccessibleKeyBinding()
497 throw (uno::RuntimeException)
499 return uno::Any();
502 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleRowCount( ) throw (RuntimeException, std::exception)
504 return ((getAccessibleChildCount()-1) / COLUMN_COUNT) + 1;
507 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleColumnCount( ) throw (RuntimeException, std::exception)
509 return COLUMN_COUNT;
512 OUString SAL_CALL SvxShowCharSetAcc::getAccessibleRowDescription( sal_Int32 /*nRow*/ ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
514 return OUString();
517 OUString SAL_CALL SvxShowCharSetAcc::getAccessibleColumnDescription( sal_Int32 /*nColumn*/ ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
519 return OUString();
522 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleRowExtentAt( sal_Int32 /*nRow*/, sal_Int32 /*nColumn*/ ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
524 return 1;
527 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleColumnExtentAt( sal_Int32 /*nRow*/, sal_Int32 /*nColumn*/ ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
529 return 1;
532 Reference< XAccessibleTable > SAL_CALL SvxShowCharSetAcc::getAccessibleRowHeaders( ) throw (RuntimeException, std::exception)
534 return Reference< XAccessibleTable >();
537 Reference< XAccessibleTable > SAL_CALL SvxShowCharSetAcc::getAccessibleColumnHeaders( ) throw (RuntimeException, std::exception)
539 return Reference< XAccessibleTable >();
542 Sequence< sal_Int32 > SAL_CALL SvxShowCharSetAcc::getSelectedAccessibleRows( ) throw (RuntimeException, std::exception)
544 OExternalLockGuard aGuard( this );
545 ensureAlive();
546 Sequence< sal_Int32 > aSel(1);
547 aSel[0] = m_pParent->getCharSetControl()->GetRowPos(m_pParent->getCharSetControl()->GetSelectIndexId());
548 return aSel;
551 Sequence< sal_Int32 > SAL_CALL SvxShowCharSetAcc::getSelectedAccessibleColumns( ) throw (RuntimeException, std::exception)
553 OExternalLockGuard aGuard( this );
554 ensureAlive();
555 Sequence< sal_Int32 > aSel(1);
556 aSel[0] = m_pParent->getCharSetControl()->GetColumnPos(m_pParent->getCharSetControl()->GetSelectIndexId());
557 return aSel;
560 sal_Bool SAL_CALL SvxShowCharSetAcc::isAccessibleRowSelected( sal_Int32 nRow ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
562 OExternalLockGuard aGuard( this );
563 ensureAlive();
564 return m_pParent->getCharSetControl()->GetRowPos(m_pParent->getCharSetControl()->GetSelectIndexId()) == nRow;
567 sal_Bool SAL_CALL SvxShowCharSetAcc::isAccessibleColumnSelected( sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
569 OExternalLockGuard aGuard( this );
570 ensureAlive();
571 return m_pParent->getCharSetControl()->GetColumnPos(m_pParent->getCharSetControl()->GetSelectIndexId()) == nColumn;
574 Reference< XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleCellAt( sal_Int32 nRow, sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
576 OExternalLockGuard aGuard( this );
577 ensureAlive();
578 ::svx::SvxShowCharSetItem* pItem = m_pParent->getCharSetControl()->ImplGetItem(
579 sal::static_int_cast<sal_uInt16>(getAccessibleIndex(nRow,nColumn) ));
580 if ( !pItem )
581 throw IndexOutOfBoundsException();
582 return pItem->GetAccessible();
585 Reference< XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleCaption( ) throw (RuntimeException, std::exception)
587 return Reference< XAccessible >();
590 Reference< XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleSummary( ) throw (RuntimeException, std::exception)
592 return Reference< XAccessible >();
595 sal_Bool SAL_CALL SvxShowCharSetAcc::isAccessibleSelected( sal_Int32 nRow, sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
597 OExternalLockGuard aGuard( this );
598 ensureAlive();
599 return m_pParent->getCharSetControl()->GetSelectIndexId() == getAccessibleIndex(nRow,nColumn);
602 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleIndex( sal_Int32 nRow, sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
604 return (nRow*COLUMN_COUNT) + nColumn;
607 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleRow( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
609 OExternalLockGuard aGuard( this );
610 ensureAlive();
611 return m_pParent->getCharSetControl()->GetRowPos(sal::static_int_cast<sal_uInt16>(nChildIndex));
614 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleColumn( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
616 OExternalLockGuard aGuard( this );
617 ensureAlive();
618 return m_pParent->getCharSetControl()->GetColumnPos(sal::static_int_cast<sal_uInt16>(nChildIndex));
624 // - SvxShowCharSetItemAcc -
627 SvxShowCharSetItemAcc::SvxShowCharSetItemAcc( SvxShowCharSetItem* pParent ) : OAccessibleComponentHelper(new VCLExternalSolarLock())
628 ,mpParent( pParent )
630 OSL_ENSURE(pParent,"NO parent supplied!");
631 osl_atomic_increment(&m_refCount);
632 { // #b6211265 #
633 lateInit(this);
635 osl_atomic_decrement(&m_refCount);
640 SvxShowCharSetItemAcc::~SvxShowCharSetItemAcc()
642 ensureDisposed();
643 delete getExternalLock();
646 IMPLEMENT_FORWARD_XINTERFACE2( SvxShowCharSetItemAcc, OAccessibleComponentHelper, OAccessibleHelper_Base_2 )
647 IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvxShowCharSetItemAcc, OAccessibleComponentHelper, OAccessibleHelper_Base_2 )
650 void SvxShowCharSetItemAcc::ParentDestroyed()
652 const ::osl::MutexGuard aGuard( GetMutex() );
653 mpParent = NULL;
658 sal_Int32 SAL_CALL SvxShowCharSetItemAcc::getAccessibleChildCount()
659 throw (uno::RuntimeException, std::exception)
661 return 0;
666 uno::Reference< css::accessibility::XAccessible > SAL_CALL SvxShowCharSetItemAcc::getAccessibleChild( sal_Int32 /*i*/ )
667 throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
669 throw lang::IndexOutOfBoundsException();
674 uno::Reference< css::accessibility::XAccessible > SAL_CALL SvxShowCharSetItemAcc::getAccessibleParent()
675 throw (uno::RuntimeException, std::exception)
677 OExternalLockGuard aGuard( this );
678 ensureAlive();
679 return mpParent->m_pParent;
684 sal_Int16 SAL_CALL SvxShowCharSetItemAcc::getAccessibleRole()
685 throw (uno::RuntimeException, std::exception)
687 return css::accessibility::AccessibleRole::TABLE_CELL;
692 OUString SAL_CALL SvxShowCharSetItemAcc::getAccessibleDescription()
693 throw (uno::RuntimeException, std::exception)
695 OExternalLockGuard aGuard( this );
696 ensureAlive();
697 OUString sDescription = SVX_RESSTR( RID_SVXSTR_CHARACTER_CODE );
699 const OUString aCharStr( mpParent->maText);
700 sal_Int32 nStrIndex = 0;
701 const sal_UCS4 c = aCharStr.iterateCodePoints( &nStrIndex );
702 const int tmp_len = (c < 0x10000) ? 4 : 6;
703 char buf[16] = "0x0000";
704 sal_UCS4 c_Shifted = c;
705 for( int i = 0; i < tmp_len; ++i )
707 char h = (char)(c_Shifted & 0x0F);
708 buf[tmp_len+1-i] = (h > 9) ? (h - 10 + 'A') : (h + '0');
709 c_Shifted >>= 4;
711 if( c < 256 )
712 snprintf( buf+6, 10, " (%" SAL_PRIuUINT32 ")", c );
713 sDescription += " " + OUString(buf, strlen(buf), RTL_TEXTENCODING_ASCII_US);
715 return sDescription;
720 OUString SAL_CALL SvxShowCharSetItemAcc::getAccessibleName()
721 throw (uno::RuntimeException, std::exception)
723 OExternalLockGuard aGuard( this );
724 ensureAlive();
725 OUString aRet;
727 if( mpParent )
729 aRet = mpParent->maText;
731 if (aRet.isEmpty())
732 aRet = getAccessibleDescription();
735 return aRet;
740 uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL SvxShowCharSetItemAcc::getAccessibleRelationSet()
741 throw (uno::RuntimeException, std::exception)
743 return uno::Reference< css::accessibility::XAccessibleRelationSet >();
748 uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL SvxShowCharSetItemAcc::getAccessibleStateSet()
749 throw (uno::RuntimeException, std::exception)
751 OExternalLockGuard aGuard( this );
752 ensureAlive();
754 ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper;
756 if( mpParent )
758 if (mpParent->mrParent.IsEnabled())
760 pStateSet->AddState( css::accessibility::AccessibleStateType::ENABLED );
761 // SELECTABLE
762 pStateSet->AddState( css::accessibility::AccessibleStateType::SELECTABLE );
763 pStateSet->AddState( css::accessibility::AccessibleStateType::FOCUSABLE );
766 // SELECTED
767 if( mpParent->mrParent.GetSelectIndexId() == mpParent->mnId )
769 pStateSet->AddState( css::accessibility::AccessibleStateType::SELECTED );
770 pStateSet->AddState( css::accessibility::AccessibleStateType::FOCUSED );
772 if ( mpParent->mnId >= mpParent->mrParent.FirstInView() && mpParent->mnId <= mpParent->mrParent.LastInView() )
774 pStateSet->AddState( AccessibleStateType::VISIBLE );
775 pStateSet->AddState( AccessibleStateType::SHOWING );
777 pStateSet->AddState( AccessibleStateType::TRANSIENT );
780 return pStateSet;
784 void SAL_CALL SvxShowCharSetItemAcc::grabFocus()
785 throw (uno::RuntimeException, std::exception)
787 // nothing to do
792 uno::Any SAL_CALL SvxShowCharSetItemAcc::getAccessibleKeyBinding()
793 throw (uno::RuntimeException)
795 return uno::Any();
798 awt::Rectangle SvxShowCharSetItemAcc::implGetBounds( ) throw (RuntimeException)
800 awt::Rectangle aRet;
802 if( mpParent )
804 Rectangle aRect( mpParent->maRect );
805 Point aOrigin;
806 Rectangle aParentRect( aOrigin, mpParent->mrParent.GetOutputSizePixel() );
808 aRect.Intersection( aParentRect );
810 aRet.X = aRect.Left();
811 aRet.Y = aRect.Top();
812 aRet.Width = aRect.GetWidth();
813 aRet.Height = aRect.GetHeight();
816 return aRet;
819 uno::Reference< css::accessibility::XAccessible > SAL_CALL SvxShowCharSetItemAcc::getAccessibleAtPoint( const awt::Point& /*aPoint*/ )
820 throw (uno::RuntimeException, std::exception)
822 return uno::Reference< css::accessibility::XAccessible >();
825 sal_Int32 SAL_CALL SvxShowCharSetVirtualAcc::getForeground( ) throw (RuntimeException, std::exception)
827 OExternalLockGuard aGuard( this );
829 sal_Int32 nColor = 0;
830 if ( mpParent )
832 if ( mpParent->IsControlForeground() )
833 nColor = mpParent->GetControlForeground().GetColor();
834 else
836 Font aFont;
837 if ( mpParent->IsControlFont() )
838 aFont = mpParent->GetControlFont();
839 else
840 aFont = mpParent->GetFont();
841 nColor = aFont.GetColor().GetColor();
845 return nColor;
848 sal_Int32 SAL_CALL SvxShowCharSetVirtualAcc::getBackground( ) throw (RuntimeException, std::exception)
850 OExternalLockGuard aGuard( this );
851 sal_Int32 nColor = 0;
852 if ( mpParent )
854 if ( mpParent->IsControlBackground() )
855 nColor = mpParent->GetControlBackground().GetColor();
856 else
857 nColor = mpParent->GetBackground().GetColor().GetColor();
860 return nColor;
863 sal_Int32 SAL_CALL SvxShowCharSetAcc::getForeground( ) throw (RuntimeException, std::exception)
865 OExternalLockGuard aGuard( this );
867 sal_Int32 nColor = 0;
868 if ( m_pParent )
869 nColor = m_pParent->getForeground();
870 return nColor;
873 sal_Int32 SAL_CALL SvxShowCharSetAcc::getBackground( ) throw (RuntimeException, std::exception)
875 OExternalLockGuard aGuard( this );
876 sal_Int32 nColor = 0;
877 if ( m_pParent )
878 nColor = m_pParent->getBackground();
879 return nColor;
884 } // namespace svx
888 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */