1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #define _SVX_CHARMAP_CXX_
28 #include <unotools/accessiblestatesethelper.hxx>
29 #include <vcl/svapp.hxx>
30 #include <stdio.h>
31 #include <svx/charmap.hxx>
32 #include "charmapacc.hxx"
33 #include <com/sun/star/accessibility/AccessibleRole.hpp>
34 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
35 #include <toolkit/helper/externallock.hxx>
36 #include <toolkit/helper/convert.hxx>
37 #include <osl/interlck.h>
38 #include <svx/dialmgr.hxx>
39 #include "accessibility.hrc"
40 #include <comphelper/types.hxx>
41 
42 namespace svx
43 {
44 	using namespace comphelper;
45 	using namespace ::com::sun::star;
46 	using namespace ::com::sun::star::uno;
47 	using namespace ::com::sun::star::lang;
48 	using namespace ::com::sun::star::accessibility;
49 
50 // ----------------
51 // - SvxShowCharSetVirtualAcc -
52 // ----------------
53 SvxShowCharSetVirtualAcc::SvxShowCharSetVirtualAcc( SvxShowCharSet* pParent ) : OAccessibleComponentHelper(new VCLExternalSolarLock())
54 ,mpParent( pParent )
55 ,m_pTable(NULL)
56 {
57 	osl_incrementInterlockedCount(&m_refCount);
58 	{ // #b6211265 #
59 		lateInit(this);
60 	}
61 	osl_decrementInterlockedCount(&m_refCount);
62 }
63 
64 // -----------------------------------------------------------------------------
65 
66 SvxShowCharSetVirtualAcc::~SvxShowCharSetVirtualAcc()
67 {
68 	ensureDisposed();
69 	delete getExternalLock();
70 }
71 // -----------------------------------------------------------------------------
72 IMPLEMENT_FORWARD_XINTERFACE2( SvxShowCharSetVirtualAcc, OAccessibleComponentHelper, OAccessibleHelper_Base_2 )
73 IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvxShowCharSetVirtualAcc, OAccessibleComponentHelper, OAccessibleHelper_Base_2 )
74 
75 void SAL_CALL SvxShowCharSetVirtualAcc::fireEvent(
76 					const sal_Int16 _nEventId,
77 					const ::com::sun::star::uno::Any& _rOldValue,
78 					const ::com::sun::star::uno::Any& _rNewValue
79 				)
80 {
81 	if ( m_pTable )
82 		m_pTable->fireEvent(_nEventId,_rOldValue,_rNewValue);
83 }
84 // -----------------------------------------------------------------------------
85 sal_Int32 SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleChildCount(  ) throw (RuntimeException)
86 {
87 	OExternalLockGuard aGuard( this );
88 	ensureAlive();
89 	return ( mpParent->getScrollBar()->IsVisible() ) ? 2 : 1;
90 }
91 // -----------------------------------------------------------------------------
92 uno::Reference< accessibility::XAccessible > SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleAtPoint( const awt::Point& aPoint )
93     throw (uno::RuntimeException)
94 {
95     OExternalLockGuard aGuard( this );
96 	ensureAlive();
97 
98 	uno::Reference< accessibility::XAccessible >    xRet;
99 	const sal_uInt16 nItemId = sal::static_int_cast<sal_uInt16>(mpParent->PixelToMapIndex( Point( aPoint.X, aPoint.Y ) ));
100 
101 	if( sal_uInt16(-1) != nItemId )
102 	{
103 		if ( !m_pTable )
104 			m_pTable = new SvxShowCharSetAcc(this);
105 		xRet = m_pTable;
106 	}
107 	else if ( mpParent->getScrollBar()->IsVisible() )
108 	{
109 		const Point aOutPos( mpParent->getScrollBar()->GetPosPixel() );
110 		const Size  aScrollBar = mpParent->getScrollBar()->GetOutputSizePixel();
111 		Rectangle aRect(aOutPos,aScrollBar);
112 
113 		if ( aRect.IsInside(VCLPoint(aPoint)) )
114 			xRet = mpParent->getScrollBar()->GetAccessible();
115 	}
116     return xRet;
117 }
118 // -----------------------------------------------------------------------------
119 uno::Any SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleKeyBinding()
120     throw (uno::RuntimeException)
121 {
122     return uno::Any();
123 }
124 // -----------------------------------------------------------------------------
125 void SAL_CALL SvxShowCharSetVirtualAcc::grabFocus()
126     throw (uno::RuntimeException)
127 {
128     OExternalLockGuard aGuard( this );
129 	ensureAlive();
130     mpParent->GrabFocus();
131 }
132 
133 
134 // -----------------------------------------------------------------------------
135 Reference< XAccessible > SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException)
136 {
137 	OExternalLockGuard aGuard( this );
138 	ensureAlive();
139 	if ( mpParent->getScrollBar()->IsVisible() && i == 0 )
140 		return mpParent->getScrollBar()->GetAccessible();
141 	else if ( i == 1 )
142 	{
143 		if ( !m_xAcc.is() )
144 		{
145 			m_pTable = new SvxShowCharSetAcc(this);
146 			m_xAcc = m_pTable;
147 		}
148 	}
149 	else
150 		throw IndexOutOfBoundsException();
151 	return m_xAcc;
152 }
153 // -----------------------------------------------------------------------------
154 Reference< XAccessible > SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleParent(  ) throw (RuntimeException)
155 {
156 	OExternalLockGuard aGuard( this );
157 	ensureAlive();
158     Window*                                         pParent = mpParent->GetParent();
159     uno::Reference< accessibility::XAccessible >    xRet;
160 
161     if ( pParent )
162         xRet = pParent->GetAccessible();
163 
164     return xRet;
165 }
166 // -----------------------------------------------------------------------------
167 ::com::sun::star::awt::Rectangle SAL_CALL SvxShowCharSetVirtualAcc::implGetBounds(  ) throw (RuntimeException)
168 {
169 	::com::sun::star::awt::Rectangle aBounds ( 0, 0, 0, 0 );
170 	Window* pWindow = mpParent;
171 	if ( pWindow )
172 	{
173 		Rectangle aRect = pWindow->GetWindowExtentsRelative( NULL );
174 		aBounds = AWTRectangle( aRect );
175 		Window* pParent = pWindow->GetAccessibleParentWindow();
176 		if ( pParent )
177 		{
178 			Rectangle aParentRect = pParent->GetWindowExtentsRelative( NULL );
179 			::com::sun::star::awt::Point aParentScreenLoc = AWTPoint( aParentRect.TopLeft() );
180 			aBounds.X -= aParentScreenLoc.X;
181 			aBounds.Y -= aParentScreenLoc.Y;
182 		}
183 	}
184 	return aBounds;
185 }
186 // -----------------------------------------------------------------------------
187 sal_Int16 SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleRole(  ) throw (RuntimeException)
188 {
189 	return accessibility::AccessibleRole::SCROLL_PANE;
190 }
191 // -----------------------------------------------------------------------------
192 ::rtl::OUString SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleDescription(  ) throw (RuntimeException)
193 {
194 	OExternalLockGuard aGuard( this );
195     return SVX_RESSTR( RID_SVXSTR_CHARACTER_SELECTION);
196 }
197 // -----------------------------------------------------------------------------
198 ::rtl::OUString SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleName(  ) throw (RuntimeException)
199 {
200 	OExternalLockGuard aGuard( this );
201     return SVX_RESSTR( RID_SVXSTR_CHAR_SEL_DESC);
202 }
203 // -----------------------------------------------------------------------------
204 Reference< XAccessibleRelationSet > SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleRelationSet(  ) throw (RuntimeException)
205 {
206 	return Reference< XAccessibleRelationSet >();
207 }
208 // -----------------------------------------------------------------------------
209 Reference< XAccessibleStateSet > SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleStateSet(  ) throw (RuntimeException)
210 {
211 	OExternalLockGuard aGuard( this );
212 
213     ::utl::AccessibleStateSetHelper*    pStateSet = new ::utl::AccessibleStateSetHelper;
214 
215     if( mpParent )
216     {
217 	    // SELECTABLE
218 	    pStateSet->AddState( AccessibleStateType::FOCUSABLE );
219 		if ( mpParent->HasFocus() )
220 			pStateSet->AddState( AccessibleStateType::FOCUSED );
221 		if ( mpParent->IsActive() )
222 			pStateSet->AddState( AccessibleStateType::ACTIVE );
223 		if ( mpParent->IsEnabled() )
224         {
225 			pStateSet->AddState( AccessibleStateType::ENABLED );
226             pStateSet->AddState( AccessibleStateType::SENSITIVE );
227         }
228 		if ( mpParent->IsReallyVisible() )
229 			pStateSet->AddState( AccessibleStateType::VISIBLE );
230     }
231 
232     return pStateSet;
233 }
234 // -----------------------------------------------------------------------------
235 void SAL_CALL SvxShowCharSetVirtualAcc::disposing()
236 {
237 	OAccessibleContextHelper::disposing();
238 	if ( m_pTable )
239 		m_pTable->dispose();
240 	m_pTable = NULL;
241 }
242 // -----------------------------------------------------------------------------
243 // ----------------
244 // - SvxShowCharSetItem -
245 // ----------------
246 
247 SvxShowCharSetItem::SvxShowCharSetItem( SvxShowCharSet& rParent,SvxShowCharSetAcc*	_pParent,sal_uInt16 _nPos ) :
248     mrParent( rParent )
249     ,mnId( _nPos )
250     ,m_pItem(NULL)
251 	,m_pParent(_pParent)
252 {
253 }
254 // -----------------------------------------------------------------------
255 
256 SvxShowCharSetItem::~SvxShowCharSetItem()
257 {
258     if ( m_xAcc.is() )
259     {
260         m_pItem->ParentDestroyed();
261         ClearAccessible();
262     }
263 }
264 
265 // -----------------------------------------------------------------------
266 
267 uno::Reference< accessibility::XAccessible > SvxShowCharSetItem::GetAccessible()
268 {
269     if( !m_xAcc.is() )
270 	{
271 		m_pItem = new SvxShowCharSetItemAcc( this );
272         m_xAcc = m_pItem;
273 	}
274 
275     return m_xAcc;
276 }
277 
278 // -----------------------------------------------------------------------
279 
280 void SvxShowCharSetItem::ClearAccessible()
281 {
282     if ( m_xAcc.is() )
283 	{
284 		m_pItem = NULL;
285 		m_xAcc  = NULL;
286 	}
287 }
288 
289 
290 // ---------------
291 // - SvxShowCharSetAcc -
292 // ---------------
293 
294 SvxShowCharSetAcc::SvxShowCharSetAcc( SvxShowCharSetVirtualAcc* _pParent ) : OAccessibleSelectionHelper(new VCLExternalSolarLock())
295   ,m_pParent( _pParent )
296 {
297 	osl_incrementInterlockedCount(&m_refCount);
298 	{ // #b6211265 #
299 		lateInit(this);
300 	}
301 	osl_decrementInterlockedCount(&m_refCount);
302 }
303 
304 // -----------------------------------------------------------------------------
305 
306 SvxShowCharSetAcc::~SvxShowCharSetAcc()
307 {
308 	ensureDisposed();
309 	delete getExternalLock();
310 }
311 // -----------------------------------------------------------------------------
312 void SAL_CALL SvxShowCharSetAcc::disposing()
313 {
314 	OAccessibleSelectionHelper::disposing();
315 	::std::vector< Reference< XAccessible > >::iterator aIter = m_aChildren.begin();
316 	::std::vector< Reference< XAccessible > >::iterator aEnd  = m_aChildren.end();
317 	for (;aIter != aEnd ; ++aIter)
318 		::comphelper::disposeComponent(*aIter);
319 
320 	m_aChildren.clear();
321 	m_pParent = NULL;
322 }
323 
324 // -----------------------------------------------------------------------------
325 IMPLEMENT_FORWARD_XINTERFACE2( SvxShowCharSetAcc, OAccessibleSelectionHelper, OAccessibleHelper_Base )
326 IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvxShowCharSetAcc, OAccessibleSelectionHelper, OAccessibleHelper_Base )
327 // -----------------------------------------------------------------------
328 sal_Bool SvxShowCharSetAcc::implIsSelected( sal_Int32 nAccessibleChildIndex ) throw (RuntimeException)
329 {
330 	return m_pParent && m_pParent->getCharSetControl()->IsSelected(
331         sal::static_int_cast<sal_uInt16>(nAccessibleChildIndex));
332 }
333 // -----------------------------------------------------------------------------
334 	    // select the specified child => watch for special ChildIndexes (ACCESSIBLE_SELECTION_CHILD_xxx)
335 void SvxShowCharSetAcc::implSelect( sal_Int32 nAccessibleChildIndex, sal_Bool bSelect ) throw (IndexOutOfBoundsException, RuntimeException)
336 {
337 	if ( m_pParent )
338 	{
339 		if ( bSelect )
340 			m_pParent->getCharSetControl()->SelectIndex(nAccessibleChildIndex,sal_True);
341 		else
342 			m_pParent->getCharSetControl()->DeSelect();
343 	}
344 }
345 // -----------------------------------------------------------------------------
346 ::com::sun::star::awt::Rectangle SAL_CALL SvxShowCharSetAcc::implGetBounds(  ) throw (RuntimeException)
347 {
348 	const Point   aOutPos;//( m_pParent->getCharSetControl()->GetPosPixel() );
349     Size          aOutSize( m_pParent->getCharSetControl()->GetOutputSizePixel());
350 	if ( m_pParent->getCharSetControl()->getScrollBar()->IsVisible() )
351 	{
352 		const Size aScrollBar = m_pParent->getCharSetControl()->getScrollBar()->GetOutputSizePixel();
353 		aOutSize.Width() -= aScrollBar.Width();
354 		//aOutSize.Height() -= aScrollBar.Height();
355 	}
356 
357     awt::Rectangle aRet;
358 
359     aRet.X = aOutPos.X();
360     aRet.Y = aOutPos.Y();
361     aRet.Width = aOutSize.Width();
362     aRet.Height = aOutSize.Height();
363 
364     return aRet;
365 }
366 // -----------------------------------------------------------------------------
367 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleChildCount()
368     throw (uno::RuntimeException)
369 {
370     OExternalLockGuard aGuard( this );
371 	ensureAlive();
372     return m_pParent->getCharSetControl()->getMaxCharCount();
373 }
374 
375 // -----------------------------------------------------------------------------
376 
377 uno::Reference< accessibility::XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleChild( sal_Int32 i )
378     throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
379 {
380     OExternalLockGuard aGuard( this );
381 	ensureAlive();
382     uno::Reference< accessibility::XAccessible >    xRet;
383 	SvxShowCharSetItem* pItem = m_pParent->getCharSetControl()->ImplGetItem( static_cast< sal_uInt16 >( i ) );
384 
385 	if( pItem )
386 	{
387 		pItem->m_pParent = this;
388 		xRet = pItem->GetAccessible();
389 		m_aChildren.push_back(xRet);
390 	}
391 	else
392 		throw lang::IndexOutOfBoundsException();
393 
394     return xRet;
395 }
396 
397 // -----------------------------------------------------------------------------
398 
399 uno::Reference< accessibility::XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleParent()
400     throw (uno::RuntimeException)
401 {
402     OExternalLockGuard aGuard( this );
403 	ensureAlive();
404     return m_pParent;
405 }
406 
407 // -----------------------------------------------------------------------------
408 
409 sal_Int16 SAL_CALL SvxShowCharSetAcc::getAccessibleRole()
410     throw (uno::RuntimeException)
411 {
412     return accessibility::AccessibleRole::TABLE;
413 }
414 
415 // -----------------------------------------------------------------------------
416 
417 ::rtl::OUString SAL_CALL SvxShowCharSetAcc::getAccessibleDescription()
418     throw (uno::RuntimeException)
419 {
420 	OExternalLockGuard aGuard( this );
421     return SVX_RESSTR( RID_SVXSTR_CHARACTER_SELECTION );
422 }
423 
424 // -----------------------------------------------------------------------------
425 
426 ::rtl::OUString SAL_CALL SvxShowCharSetAcc::getAccessibleName()
427     throw (uno::RuntimeException)
428 {
429     OExternalLockGuard aGuard( this );
430 	ensureAlive();
431     return SVX_RESSTR( RID_SVXSTR_CHAR_SEL_DESC );
432 }
433 
434 // -----------------------------------------------------------------------------
435 
436 uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL SvxShowCharSetAcc::getAccessibleRelationSet()
437     throw (uno::RuntimeException)
438 {
439     return uno::Reference< accessibility::XAccessibleRelationSet >();
440 }
441 
442 // -----------------------------------------------------------------------------
443 
444 uno::Reference< accessibility::XAccessibleStateSet > SAL_CALL SvxShowCharSetAcc::getAccessibleStateSet()
445     throw (uno::RuntimeException)
446 {
447     OExternalLockGuard aGuard( this );
448 
449     ::utl::AccessibleStateSetHelper*    pStateSet = new ::utl::AccessibleStateSetHelper;
450 
451     if( m_pParent->getCharSetControl() )
452     {
453 	    // SELECTABLE
454 	    pStateSet->AddState( AccessibleStateType::FOCUSABLE );
455 		if ( m_pParent->getCharSetControl()->HasFocus() )
456 			pStateSet->AddState( AccessibleStateType::FOCUSED );
457 		if ( m_pParent->getCharSetControl()->IsActive() )
458 			pStateSet->AddState( AccessibleStateType::ACTIVE );
459 		if ( m_pParent->getCharSetControl()->IsEnabled() )
460         {
461             pStateSet->AddState( AccessibleStateType::ENABLED );
462             pStateSet->AddState( AccessibleStateType::SENSITIVE );
463         }
464 		if ( m_pParent->getCharSetControl()->IsReallyVisible() )
465 			pStateSet->AddState( AccessibleStateType::VISIBLE );
466 
467 		pStateSet->AddState( AccessibleStateType::MANAGES_DESCENDANTS );
468     }
469 
470     return pStateSet;
471 }
472 // -----------------------------------------------------------------------------
473 
474 uno::Reference< accessibility::XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleAtPoint( const awt::Point& aPoint )
475     throw (uno::RuntimeException)
476 {
477     OExternalLockGuard aGuard( this );
478 	ensureAlive();
479 
480 	uno::Reference< accessibility::XAccessible >    xRet;
481 	const sal_uInt16 nItemId = sal::static_int_cast<sal_uInt16>(
482         m_pParent->getCharSetControl()->PixelToMapIndex( Point( aPoint.X, aPoint.Y ) ));
483 
484 	if( sal_uInt16(-1) != nItemId )
485 	{
486 		SvxShowCharSetItem* pItem = m_pParent->getCharSetControl()->ImplGetItem( nItemId );
487 		xRet = pItem->GetAccessible();
488 	}
489     return xRet;
490 }
491 
492 // -----------------------------------------------------------------------------
493 // -----------------------------------------------------------------------------
494 
495 void SAL_CALL SvxShowCharSetAcc::grabFocus()
496     throw (uno::RuntimeException)
497 {
498     OExternalLockGuard aGuard( this );
499 	ensureAlive();
500     m_pParent->getCharSetControl()->GrabFocus();
501 }
502 
503 // -----------------------------------------------------------------------------
504 
505 uno::Any SAL_CALL SvxShowCharSetAcc::getAccessibleKeyBinding()
506     throw (uno::RuntimeException)
507 {
508     return uno::Any();
509 }
510 // -----------------------------------------------------------------------------
511 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleRowCount(  ) throw (RuntimeException)
512 {
513 	return ((getAccessibleChildCount()-1) / COLUMN_COUNT) + 1;
514 }
515 // -----------------------------------------------------------------------------
516 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleColumnCount(  ) throw (RuntimeException)
517 {
518 	return COLUMN_COUNT;
519 }
520 // -----------------------------------------------------------------------------
521 ::rtl::OUString SAL_CALL SvxShowCharSetAcc::getAccessibleRowDescription( sal_Int32 /*nRow*/ ) throw (IndexOutOfBoundsException, RuntimeException)
522 {
523 	return ::rtl::OUString();
524 }
525 // -----------------------------------------------------------------------------
526 ::rtl::OUString SAL_CALL SvxShowCharSetAcc::getAccessibleColumnDescription( sal_Int32 /*nColumn*/ ) throw (IndexOutOfBoundsException, RuntimeException)
527 {
528 	return ::rtl::OUString();
529 }
530 // -----------------------------------------------------------------------------
531 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleRowExtentAt( sal_Int32 /*nRow*/, sal_Int32 /*nColumn*/ ) throw (IndexOutOfBoundsException, RuntimeException)
532 {
533 	return 1;
534 }
535 // -----------------------------------------------------------------------------
536 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleColumnExtentAt( sal_Int32 /*nRow*/, sal_Int32 /*nColumn*/ ) throw (IndexOutOfBoundsException, RuntimeException)
537 {
538 	return 1;
539 }
540 // -----------------------------------------------------------------------------
541 Reference< XAccessibleTable > SAL_CALL SvxShowCharSetAcc::getAccessibleRowHeaders(  ) throw (RuntimeException)
542 {
543 	return Reference< XAccessibleTable >();
544 }
545 // -----------------------------------------------------------------------------
546 Reference< XAccessibleTable > SAL_CALL SvxShowCharSetAcc::getAccessibleColumnHeaders(  ) throw (RuntimeException)
547 {
548 	return Reference< XAccessibleTable >();
549 }
550 // -----------------------------------------------------------------------------
551 Sequence< sal_Int32 > SAL_CALL SvxShowCharSetAcc::getSelectedAccessibleRows(  ) throw (RuntimeException)
552 {
553 	OExternalLockGuard aGuard( this );
554 	ensureAlive();
555 	Sequence< sal_Int32 > aSel(1);
556 	aSel[0] = m_pParent->getCharSetControl()->GetRowPos(m_pParent->getCharSetControl()->GetSelectIndexId());
557 	return aSel;
558 }
559 // -----------------------------------------------------------------------------
560 Sequence< sal_Int32 > SAL_CALL SvxShowCharSetAcc::getSelectedAccessibleColumns(  ) throw (RuntimeException)
561 {
562 	OExternalLockGuard aGuard( this );
563 	ensureAlive();
564 	Sequence< sal_Int32 > aSel(1);
565 	aSel[0] = m_pParent->getCharSetControl()->GetColumnPos(m_pParent->getCharSetControl()->GetSelectIndexId());
566 	return aSel;
567 }
568 // -----------------------------------------------------------------------------
569 sal_Bool SAL_CALL SvxShowCharSetAcc::isAccessibleRowSelected( sal_Int32 nRow ) throw (IndexOutOfBoundsException, RuntimeException)
570 {
571 	OExternalLockGuard aGuard( this );
572 	ensureAlive();
573 	return m_pParent->getCharSetControl()->GetRowPos(m_pParent->getCharSetControl()->GetSelectIndexId()) == nRow;
574 }
575 // -----------------------------------------------------------------------------
576 sal_Bool SAL_CALL SvxShowCharSetAcc::isAccessibleColumnSelected( sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException)
577 {
578 	OExternalLockGuard aGuard( this );
579 	ensureAlive();
580 	return m_pParent->getCharSetControl()->GetColumnPos(m_pParent->getCharSetControl()->GetSelectIndexId()) == nColumn;
581 }
582 // -----------------------------------------------------------------------------
583 Reference< XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleCellAt( sal_Int32 nRow, sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException)
584 {
585 	OExternalLockGuard aGuard( this );
586 	ensureAlive();
587 	::svx::SvxShowCharSetItem* pItem = m_pParent->getCharSetControl()->ImplGetItem(
588         sal::static_int_cast<sal_uInt16>(getAccessibleIndex(nRow,nColumn) ));
589 	if ( !pItem  )
590 		throw IndexOutOfBoundsException();
591 	return pItem->GetAccessible();
592 }
593 // -----------------------------------------------------------------------------
594 Reference< XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleCaption(  ) throw (RuntimeException)
595 {
596 	return Reference< XAccessible >();
597 }
598 // -----------------------------------------------------------------------------
599 Reference< XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleSummary(  ) throw (RuntimeException)
600 {
601 	return Reference< XAccessible >();
602 }
603 // -----------------------------------------------------------------------------
604 sal_Bool SAL_CALL SvxShowCharSetAcc::isAccessibleSelected( sal_Int32 nRow, sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException)
605 {
606 	OExternalLockGuard aGuard( this );
607 	ensureAlive();
608 	return m_pParent->getCharSetControl()->GetSelectIndexId() == getAccessibleIndex(nRow,nColumn);
609 }
610 // -----------------------------------------------------------------------------
611 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleIndex( sal_Int32 nRow, sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException)
612 {
613 	return (nRow*COLUMN_COUNT) + nColumn;
614 }
615 // -----------------------------------------------------------------------------
616 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleRow( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
617 {
618 	OExternalLockGuard aGuard( this );
619 	ensureAlive();
620 	return m_pParent->getCharSetControl()->GetRowPos(sal::static_int_cast<sal_uInt16>(nChildIndex));
621 }
622 // -----------------------------------------------------------------------------
623 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleColumn( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
624 {
625 	OExternalLockGuard aGuard( this );
626 	ensureAlive();
627 	return m_pParent->getCharSetControl()->GetColumnPos(sal::static_int_cast<sal_uInt16>(nChildIndex));
628 }
629 // -----------------------------------------------------------------------------
630 
631 // -----------------------------------------------------------------------------
632 // ----------------
633 // - SvxShowCharSetItemAcc -
634 // ----------------
635 
636 SvxShowCharSetItemAcc::SvxShowCharSetItemAcc( SvxShowCharSetItem* pParent ) : OAccessibleComponentHelper(new VCLExternalSolarLock())
637 ,mpParent( pParent )
638 {
639 	OSL_ENSURE(pParent,"NO parent supplied!");
640 	osl_incrementInterlockedCount(&m_refCount);
641 	{ // #b6211265 #
642 		lateInit(this);
643 	}
644 	osl_decrementInterlockedCount(&m_refCount);
645 }
646 
647 // -----------------------------------------------------------------------------
648 
649 SvxShowCharSetItemAcc::~SvxShowCharSetItemAcc()
650 {
651 	ensureDisposed();
652 	delete getExternalLock();
653 }
654 // -----------------------------------------------------------------------------
655 IMPLEMENT_FORWARD_XINTERFACE2( SvxShowCharSetItemAcc, OAccessibleComponentHelper, OAccessibleHelper_Base_2 )
656 IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvxShowCharSetItemAcc, OAccessibleComponentHelper, OAccessibleHelper_Base_2 )
657 // -----------------------------------------------------------------------------
658 
659 void SvxShowCharSetItemAcc::ParentDestroyed()
660 {
661     const ::osl::MutexGuard aGuard( GetMutex() );
662     mpParent = NULL;
663 }
664 
665 // -----------------------------------------------------------------------------
666 
667 sal_Int32 SAL_CALL SvxShowCharSetItemAcc::getAccessibleChildCount()
668     throw (uno::RuntimeException)
669 {
670     return 0;
671 }
672 
673 // -----------------------------------------------------------------------------
674 
675 uno::Reference< accessibility::XAccessible > SAL_CALL SvxShowCharSetItemAcc::getAccessibleChild( sal_Int32 /*i*/ )
676     throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
677 {
678     throw lang::IndexOutOfBoundsException();
679 }
680 
681 // -----------------------------------------------------------------------------
682 
683 uno::Reference< accessibility::XAccessible > SAL_CALL SvxShowCharSetItemAcc::getAccessibleParent()
684     throw (uno::RuntimeException)
685 {
686     OExternalLockGuard aGuard( this );
687 	ensureAlive();
688     return mpParent->m_pParent;
689 }
690 
691 // -----------------------------------------------------------------------------
692 
693 sal_Int16 SAL_CALL SvxShowCharSetItemAcc::getAccessibleRole()
694     throw (uno::RuntimeException)
695 {
696     return accessibility::AccessibleRole::TABLE_CELL;
697 }
698 
699 // -----------------------------------------------------------------------------
700 
701 ::rtl::OUString SAL_CALL SvxShowCharSetItemAcc::getAccessibleDescription()
702     throw (uno::RuntimeException)
703 {
704     OExternalLockGuard aGuard( this );
705 	ensureAlive();
706 	String sDescription = SVX_RESSTR( RID_SVXSTR_CHARACTER_CODE );
707 
708 	sal_Unicode c = mpParent->maText.GetChar(0);
709 	char buf[16] = "0x0000";
710     sal_Unicode c_Shifted = c;
711 	int tmp_len = 4;
712 	if(c_Shifted>0xFFFF) tmp_len = 8;
713     for( int i = 0; i < tmp_len; ++i )
714     {
715         char h = c_Shifted & 0x0F;
716 		buf[tmp_len+1-i] = (h > 9) ? (h - 10 + 'A') : (h + '0');
717         c_Shifted >>= 4;
718     }
719     if( c < 256 )
720         snprintf( buf+6, 10, " (%d)", c );
721 	sDescription.AppendAscii(" ");
722 	sDescription.AppendAscii(buf);
723 
724     return sDescription;
725 }
726 
727 // -----------------------------------------------------------------------------
728 
729 ::rtl::OUString SAL_CALL SvxShowCharSetItemAcc::getAccessibleName()
730     throw (uno::RuntimeException)
731 {
732     OExternalLockGuard aGuard( this );
733 	ensureAlive();
734     String aRet;
735 
736     if( mpParent )
737     {
738         aRet = mpParent->maText;
739 
740         if( !aRet.Len() )
741 			aRet = getAccessibleDescription();
742     }
743 
744     return aRet;
745 }
746 
747 // -----------------------------------------------------------------------------
748 
749 uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL SvxShowCharSetItemAcc::getAccessibleRelationSet()
750     throw (uno::RuntimeException)
751 {
752     return uno::Reference< accessibility::XAccessibleRelationSet >();
753 }
754 
755 // -----------------------------------------------------------------------------
756 
757 uno::Reference< accessibility::XAccessibleStateSet > SAL_CALL SvxShowCharSetItemAcc::getAccessibleStateSet()
758     throw (uno::RuntimeException)
759 {
760     OExternalLockGuard aGuard( this );
761 	ensureAlive();
762 
763     ::utl::AccessibleStateSetHelper*    pStateSet = new ::utl::AccessibleStateSetHelper;
764 
765     if( mpParent )
766     {
767 		if(mpParent->mrParent.IsEnabled())
768 		{
769 			pStateSet->AddState( accessibility::AccessibleStateType::ENABLED );
770 			// SELECTABLE
771 			pStateSet->AddState( accessibility::AccessibleStateType::SELECTABLE );
772 			pStateSet->AddState( accessibility::AccessibleStateType::FOCUSABLE );
773 		}
774 
775 	    // SELECTED
776         if( mpParent->mrParent.GetSelectIndexId() == mpParent->mnId )
777         {
778             pStateSet->AddState( accessibility::AccessibleStateType::SELECTED );
779        	    pStateSet->AddState( accessibility::AccessibleStateType::FOCUSED );
780         }
781 		if ( mpParent->mnId >= mpParent->mrParent.FirstInView() && mpParent->mnId <= mpParent->mrParent.LastInView() )
782 		{
783 			pStateSet->AddState( AccessibleStateType::VISIBLE );
784 			pStateSet->AddState( AccessibleStateType::SHOWING );
785 		}
786 		pStateSet->AddState( AccessibleStateType::TRANSIENT );
787     }
788 
789     return pStateSet;
790 }
791 
792 // -----------------------------------------------------------------------------
793 void SAL_CALL SvxShowCharSetItemAcc::grabFocus()
794     throw (uno::RuntimeException)
795 {
796     // nothing to do
797 }
798 
799 // -----------------------------------------------------------------------------
800 
801 uno::Any SAL_CALL SvxShowCharSetItemAcc::getAccessibleKeyBinding()
802     throw (uno::RuntimeException)
803 {
804     return uno::Any();
805 }
806 // -----------------------------------------------------------------------------
807 awt::Rectangle SAL_CALL SvxShowCharSetItemAcc::implGetBounds(  ) throw (RuntimeException)
808 {
809 	awt::Rectangle      aRet;
810 
811     if( mpParent )
812     {
813         Rectangle   aRect( mpParent->maRect );
814         Point       aOrigin;
815         Rectangle   aParentRect( aOrigin, mpParent->mrParent.GetOutputSizePixel() );
816 
817         aRect.Intersection( aParentRect );
818 
819         aRet.X = aRect.Left();
820         aRet.Y = aRect.Top();
821         aRet.Width = aRect.GetWidth();
822         aRet.Height = aRect.GetHeight();
823     }
824 
825     return aRet;
826 }
827 // -----------------------------------------------------------------------------
828 uno::Reference< accessibility::XAccessible > SAL_CALL SvxShowCharSetItemAcc::getAccessibleAtPoint( const awt::Point& /*aPoint*/ )
829     throw (uno::RuntimeException)
830 {
831     return uno::Reference< accessibility::XAccessible >();
832 }
833 // -----------------------------------------------------------------------------
834 sal_Int32 SAL_CALL SvxShowCharSetVirtualAcc::getForeground(  ) throw (RuntimeException)
835 {
836 	OExternalLockGuard aGuard( this );
837 
838 	sal_Int32 nColor = 0;
839 	if ( mpParent )
840 	{
841 		if ( mpParent->IsControlForeground() )
842 			nColor = mpParent->GetControlForeground().GetColor();
843 		else
844 		{
845 			Font aFont;
846 			if ( mpParent->IsControlFont() )
847 				aFont = mpParent->GetControlFont();
848 			else
849 				aFont = mpParent->GetFont();
850 			nColor = aFont.GetColor().GetColor();
851 		}
852 	}
853 
854 	return nColor;
855 }
856 // -----------------------------------------------------------------------------
857 sal_Int32 SAL_CALL SvxShowCharSetVirtualAcc::getBackground(  ) throw (RuntimeException)
858 {
859 	OExternalLockGuard aGuard( this  );
860 	sal_Int32 nColor = 0;
861 	if ( mpParent )
862 	{
863 		if ( mpParent->IsControlBackground() )
864 			nColor = mpParent->GetControlBackground().GetColor();
865 		else
866 			nColor = mpParent->GetBackground().GetColor().GetColor();
867 	}
868 
869 	return nColor;
870 }
871 // -----------------------------------------------------------------------------
872 sal_Int32 SAL_CALL SvxShowCharSetAcc::getForeground(  ) throw (RuntimeException)
873 {
874 	OExternalLockGuard aGuard( this );
875 
876 	sal_Int32 nColor = 0;
877 	if ( m_pParent )
878 		nColor = m_pParent->getForeground();
879 	return nColor;
880 }
881 // -----------------------------------------------------------------------------
882 sal_Int32 SAL_CALL SvxShowCharSetAcc::getBackground(  ) throw (RuntimeException)
883 {
884 	OExternalLockGuard aGuard( this  );
885 	sal_Int32 nColor = 0;
886 	if ( m_pParent )
887 		nColor = m_pParent->getBackground();
888 	return nColor;
889 }
890 // -----------------------------------------------------------------------------
891 
892 // -----------------------------------------------------------------------------
893 } // namespace svx
894 // -----------------------------------------------------------------------------
895 
896 
897