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 /*	const Point   aOutPos( mpParent->GetPosPixel() );
170     Size          aOutSize( mpParent->GetOutputSizePixel() );
171 	if ( mpParent->getScrollBar()->IsVisible() )
172 	{
173 		const Size aScrollBar = mpParent->getScrollBar()->GetOutputSizePixel();
174 		aOutSize.Width() -= aScrollBar.Width();
175 		aOutSize.Height() -= aScrollBar.Height();
176 	}
177 
178     awt::Rectangle aRet;
179 
180     aRet.X = aOutPos.X();
181     aRet.Y = aOutPos.Y();
182     aRet.Width = aOutSize.Width();
183     aRet.Height = aOutSize.Height();
184 
185     return aRet;
186 */
187 	::com::sun::star::awt::Rectangle aBounds ( 0, 0, 0, 0 );
188 	Window* pWindow = mpParent;
189 	if ( pWindow )
190 	{
191 		Rectangle aRect = pWindow->GetWindowExtentsRelative( NULL );
192 		aBounds = AWTRectangle( aRect );
193 		Window* pParent = pWindow->GetAccessibleParentWindow();
194 		if ( pParent )
195 		{
196 			Rectangle aParentRect = pParent->GetWindowExtentsRelative( NULL );
197 			::com::sun::star::awt::Point aParentScreenLoc = AWTPoint( aParentRect.TopLeft() );
198 			aBounds.X -= aParentScreenLoc.X;
199 			aBounds.Y -= aParentScreenLoc.Y;
200 		}
201 	}
202 	return aBounds;
203 }
204 // -----------------------------------------------------------------------------
205 sal_Int16 SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleRole(  ) throw (RuntimeException)
206 {
207 	return accessibility::AccessibleRole::SCROLL_PANE;
208 }
209 // -----------------------------------------------------------------------------
210 ::rtl::OUString SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleDescription(  ) throw (RuntimeException)
211 {
212 	OExternalLockGuard aGuard( this );
213     return SVX_RESSTR( RID_SVXSTR_CHARACTER_SELECTION);
214 }
215 // -----------------------------------------------------------------------------
216 ::rtl::OUString SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleName(  ) throw (RuntimeException)
217 {
218 	OExternalLockGuard aGuard( this );
219     return SVX_RESSTR( RID_SVXSTR_CHAR_SEL_DESC);
220 }
221 // -----------------------------------------------------------------------------
222 Reference< XAccessibleRelationSet > SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleRelationSet(  ) throw (RuntimeException)
223 {
224 	return Reference< XAccessibleRelationSet >();
225 }
226 // -----------------------------------------------------------------------------
227 Reference< XAccessibleStateSet > SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleStateSet(  ) throw (RuntimeException)
228 {
229 	OExternalLockGuard aGuard( this );
230 
231     ::utl::AccessibleStateSetHelper*    pStateSet = new ::utl::AccessibleStateSetHelper;
232 
233     if( mpParent )
234     {
235 	    // SELECTABLE
236 	    pStateSet->AddState( AccessibleStateType::FOCUSABLE );
237 		if ( mpParent->HasFocus() )
238 			pStateSet->AddState( AccessibleStateType::FOCUSED );
239 		if ( mpParent->IsActive() )
240 			pStateSet->AddState( AccessibleStateType::ACTIVE );
241 		if ( mpParent->IsEnabled() )
242         {
243 			pStateSet->AddState( AccessibleStateType::ENABLED );
244             pStateSet->AddState( AccessibleStateType::SENSITIVE );
245         }
246 		if ( mpParent->IsReallyVisible() )
247 			pStateSet->AddState( AccessibleStateType::VISIBLE );
248     }
249 
250     return pStateSet;
251 }
252 // -----------------------------------------------------------------------------
253 void SAL_CALL SvxShowCharSetVirtualAcc::disposing()
254 {
255 	OAccessibleContextHelper::disposing();
256 	if ( m_pTable )
257 		m_pTable->dispose();
258 	m_pTable = NULL;
259 }
260 // -----------------------------------------------------------------------------
261 // ----------------
262 // - SvxShowCharSetItem -
263 // ----------------
264 
265 SvxShowCharSetItem::SvxShowCharSetItem( SvxShowCharSet& rParent,SvxShowCharSetAcc*	_pParent,sal_uInt16 _nPos ) :
266     mrParent( rParent )
267     ,mnId( _nPos )
268     ,m_pItem(NULL)
269 	,m_pParent(_pParent)
270 {
271 }
272 // -----------------------------------------------------------------------
273 
274 SvxShowCharSetItem::~SvxShowCharSetItem()
275 {
276     if ( m_xAcc.is() )
277     {
278         m_pItem->ParentDestroyed();
279         ClearAccessible();
280     }
281 }
282 
283 // -----------------------------------------------------------------------
284 
285 uno::Reference< accessibility::XAccessible > SvxShowCharSetItem::GetAccessible()
286 {
287     if( !m_xAcc.is() )
288 	{
289 		m_pItem = new SvxShowCharSetItemAcc( this );
290         m_xAcc = m_pItem;
291 	}
292 
293     return m_xAcc;
294 }
295 
296 // -----------------------------------------------------------------------
297 
298 void SvxShowCharSetItem::ClearAccessible()
299 {
300     if ( m_xAcc.is() )
301 	{
302 		m_pItem = NULL;
303 		m_xAcc  = NULL;
304 	}
305 }
306 
307 
308 // ---------------
309 // - SvxShowCharSetAcc -
310 // ---------------
311 
312 SvxShowCharSetAcc::SvxShowCharSetAcc( SvxShowCharSetVirtualAcc* _pParent ) : OAccessibleSelectionHelper(new VCLExternalSolarLock())
313   ,m_pParent( _pParent )
314 {
315 	osl_incrementInterlockedCount(&m_refCount);
316 	{ // #b6211265 #
317 		lateInit(this);
318 	}
319 	osl_decrementInterlockedCount(&m_refCount);
320 }
321 
322 // -----------------------------------------------------------------------------
323 
324 SvxShowCharSetAcc::~SvxShowCharSetAcc()
325 {
326 	ensureDisposed();
327 	delete getExternalLock();
328 }
329 // -----------------------------------------------------------------------------
330 void SAL_CALL SvxShowCharSetAcc::disposing()
331 {
332 	OAccessibleSelectionHelper::disposing();
333 	::std::vector< Reference< XAccessible > >::iterator aIter = m_aChildren.begin();
334 	::std::vector< Reference< XAccessible > >::iterator aEnd  = m_aChildren.end();
335 	for (;aIter != aEnd ; ++aIter)
336 		::comphelper::disposeComponent(*aIter);
337 
338 	m_aChildren.clear();
339 	m_pParent = NULL;
340 }
341 
342 // -----------------------------------------------------------------------------
343 IMPLEMENT_FORWARD_XINTERFACE2( SvxShowCharSetAcc, OAccessibleSelectionHelper, OAccessibleHelper_Base )
344 IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvxShowCharSetAcc, OAccessibleSelectionHelper, OAccessibleHelper_Base )
345 // -----------------------------------------------------------------------
346 sal_Bool SvxShowCharSetAcc::implIsSelected( sal_Int32 nAccessibleChildIndex ) throw (RuntimeException)
347 {
348 	return m_pParent && m_pParent->getCharSetControl()->IsSelected(
349         sal::static_int_cast<sal_uInt16>(nAccessibleChildIndex));
350 }
351 // -----------------------------------------------------------------------------
352 	    // select the specified child => watch for special ChildIndexes (ACCESSIBLE_SELECTION_CHILD_xxx)
353 void SvxShowCharSetAcc::implSelect( sal_Int32 nAccessibleChildIndex, sal_Bool bSelect ) throw (IndexOutOfBoundsException, RuntimeException)
354 {
355 	if ( m_pParent )
356 	{
357 		if ( bSelect )
358 			m_pParent->getCharSetControl()->SelectIndex(nAccessibleChildIndex,sal_True);
359 		else
360 			m_pParent->getCharSetControl()->DeSelect();
361 	}
362 }
363 // -----------------------------------------------------------------------------
364 ::com::sun::star::awt::Rectangle SAL_CALL SvxShowCharSetAcc::implGetBounds(  ) throw (RuntimeException)
365 {
366 	const Point   aOutPos;//( m_pParent->getCharSetControl()->GetPosPixel() );
367     Size          aOutSize( m_pParent->getCharSetControl()->GetOutputSizePixel());
368 	if ( m_pParent->getCharSetControl()->getScrollBar()->IsVisible() )
369 	{
370 		const Size aScrollBar = m_pParent->getCharSetControl()->getScrollBar()->GetOutputSizePixel();
371 		aOutSize.Width() -= aScrollBar.Width();
372 		//aOutSize.Height() -= aScrollBar.Height();
373 	}
374 
375     awt::Rectangle aRet;
376 
377     aRet.X = aOutPos.X();
378     aRet.Y = aOutPos.Y();
379     aRet.Width = aOutSize.Width();
380     aRet.Height = aOutSize.Height();
381 
382     return aRet;
383 }
384 // -----------------------------------------------------------------------------
385 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleChildCount()
386     throw (uno::RuntimeException)
387 {
388     OExternalLockGuard aGuard( this );
389 	ensureAlive();
390     return m_pParent->getCharSetControl()->getMaxCharCount();
391 }
392 
393 // -----------------------------------------------------------------------------
394 
395 uno::Reference< accessibility::XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleChild( sal_Int32 i )
396     throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
397 {
398     OExternalLockGuard aGuard( this );
399 	ensureAlive();
400     uno::Reference< accessibility::XAccessible >    xRet;
401 	SvxShowCharSetItem* pItem = m_pParent->getCharSetControl()->ImplGetItem( static_cast< sal_uInt16 >( i ) );
402 
403 	if( pItem )
404 	{
405 		pItem->m_pParent = this;
406 		xRet = pItem->GetAccessible();
407 		m_aChildren.push_back(xRet);
408 	}
409 	else
410 		throw lang::IndexOutOfBoundsException();
411 
412     return xRet;
413 }
414 
415 // -----------------------------------------------------------------------------
416 
417 uno::Reference< accessibility::XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleParent()
418     throw (uno::RuntimeException)
419 {
420     OExternalLockGuard aGuard( this );
421 	ensureAlive();
422     return m_pParent;
423 }
424 
425 // -----------------------------------------------------------------------------
426 
427 sal_Int16 SAL_CALL SvxShowCharSetAcc::getAccessibleRole()
428     throw (uno::RuntimeException)
429 {
430     return accessibility::AccessibleRole::TABLE;
431 }
432 
433 // -----------------------------------------------------------------------------
434 
435 ::rtl::OUString SAL_CALL SvxShowCharSetAcc::getAccessibleDescription()
436     throw (uno::RuntimeException)
437 {
438 	OExternalLockGuard aGuard( this );
439     return SVX_RESSTR( RID_SVXSTR_CHARACTER_SELECTION );
440 }
441 
442 // -----------------------------------------------------------------------------
443 
444 ::rtl::OUString SAL_CALL SvxShowCharSetAcc::getAccessibleName()
445     throw (uno::RuntimeException)
446 {
447     OExternalLockGuard aGuard( this );
448 	ensureAlive();
449     return SVX_RESSTR( RID_SVXSTR_CHAR_SEL_DESC );
450 }
451 
452 // -----------------------------------------------------------------------------
453 
454 uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL SvxShowCharSetAcc::getAccessibleRelationSet()
455     throw (uno::RuntimeException)
456 {
457     return uno::Reference< accessibility::XAccessibleRelationSet >();
458 }
459 
460 // -----------------------------------------------------------------------------
461 
462 uno::Reference< accessibility::XAccessibleStateSet > SAL_CALL SvxShowCharSetAcc::getAccessibleStateSet()
463     throw (uno::RuntimeException)
464 {
465     OExternalLockGuard aGuard( this );
466 
467     ::utl::AccessibleStateSetHelper*    pStateSet = new ::utl::AccessibleStateSetHelper;
468 
469     if( m_pParent->getCharSetControl() )
470     {
471 	    // SELECTABLE
472 	    pStateSet->AddState( AccessibleStateType::FOCUSABLE );
473 		if ( m_pParent->getCharSetControl()->HasFocus() )
474 			pStateSet->AddState( AccessibleStateType::FOCUSED );
475 		if ( m_pParent->getCharSetControl()->IsActive() )
476 			pStateSet->AddState( AccessibleStateType::ACTIVE );
477 		if ( m_pParent->getCharSetControl()->IsEnabled() )
478         {
479             pStateSet->AddState( AccessibleStateType::ENABLED );
480             pStateSet->AddState( AccessibleStateType::SENSITIVE );
481         }
482 		if ( m_pParent->getCharSetControl()->IsReallyVisible() )
483 			pStateSet->AddState( AccessibleStateType::VISIBLE );
484 
485 		pStateSet->AddState( AccessibleStateType::MANAGES_DESCENDANTS );
486     }
487 
488     return pStateSet;
489 }
490 // -----------------------------------------------------------------------------
491 
492 uno::Reference< accessibility::XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleAtPoint( const awt::Point& aPoint )
493     throw (uno::RuntimeException)
494 {
495     OExternalLockGuard aGuard( this );
496 	ensureAlive();
497 
498 	uno::Reference< accessibility::XAccessible >    xRet;
499 	const sal_uInt16 nItemId = sal::static_int_cast<sal_uInt16>(
500         m_pParent->getCharSetControl()->PixelToMapIndex( Point( aPoint.X, aPoint.Y ) ));
501 
502 	if( sal_uInt16(-1) != nItemId )
503 	{
504 		SvxShowCharSetItem* pItem = m_pParent->getCharSetControl()->ImplGetItem( nItemId );
505 		xRet = pItem->GetAccessible();
506 	}
507     return xRet;
508 }
509 
510 // -----------------------------------------------------------------------------
511 // -----------------------------------------------------------------------------
512 
513 void SAL_CALL SvxShowCharSetAcc::grabFocus()
514     throw (uno::RuntimeException)
515 {
516     OExternalLockGuard aGuard( this );
517 	ensureAlive();
518     m_pParent->getCharSetControl()->GrabFocus();
519 }
520 
521 // -----------------------------------------------------------------------------
522 
523 uno::Any SAL_CALL SvxShowCharSetAcc::getAccessibleKeyBinding()
524     throw (uno::RuntimeException)
525 {
526     return uno::Any();
527 }
528 // -----------------------------------------------------------------------------
529 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleRowCount(  ) throw (RuntimeException)
530 {
531 	return ((getAccessibleChildCount()-1) / COLUMN_COUNT) + 1;
532 }
533 // -----------------------------------------------------------------------------
534 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleColumnCount(  ) throw (RuntimeException)
535 {
536 	return COLUMN_COUNT;
537 }
538 // -----------------------------------------------------------------------------
539 ::rtl::OUString SAL_CALL SvxShowCharSetAcc::getAccessibleRowDescription( sal_Int32 /*nRow*/ ) throw (IndexOutOfBoundsException, RuntimeException)
540 {
541 	return ::rtl::OUString();
542 }
543 // -----------------------------------------------------------------------------
544 ::rtl::OUString SAL_CALL SvxShowCharSetAcc::getAccessibleColumnDescription( sal_Int32 /*nColumn*/ ) throw (IndexOutOfBoundsException, RuntimeException)
545 {
546 	return ::rtl::OUString();
547 }
548 // -----------------------------------------------------------------------------
549 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleRowExtentAt( sal_Int32 /*nRow*/, sal_Int32 /*nColumn*/ ) throw (IndexOutOfBoundsException, RuntimeException)
550 {
551 	return 1;
552 }
553 // -----------------------------------------------------------------------------
554 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleColumnExtentAt( sal_Int32 /*nRow*/, sal_Int32 /*nColumn*/ ) throw (IndexOutOfBoundsException, RuntimeException)
555 {
556 	return 1;
557 }
558 // -----------------------------------------------------------------------------
559 Reference< XAccessibleTable > SAL_CALL SvxShowCharSetAcc::getAccessibleRowHeaders(  ) throw (RuntimeException)
560 {
561 	return Reference< XAccessibleTable >();
562 }
563 // -----------------------------------------------------------------------------
564 Reference< XAccessibleTable > SAL_CALL SvxShowCharSetAcc::getAccessibleColumnHeaders(  ) throw (RuntimeException)
565 {
566 	return Reference< XAccessibleTable >();
567 }
568 // -----------------------------------------------------------------------------
569 Sequence< sal_Int32 > SAL_CALL SvxShowCharSetAcc::getSelectedAccessibleRows(  ) throw (RuntimeException)
570 {
571 	OExternalLockGuard aGuard( this );
572 	ensureAlive();
573 	Sequence< sal_Int32 > aSel(1);
574 	aSel[0] = m_pParent->getCharSetControl()->GetRowPos(m_pParent->getCharSetControl()->GetSelectIndexId());
575 	return aSel;
576 }
577 // -----------------------------------------------------------------------------
578 Sequence< sal_Int32 > SAL_CALL SvxShowCharSetAcc::getSelectedAccessibleColumns(  ) throw (RuntimeException)
579 {
580 	OExternalLockGuard aGuard( this );
581 	ensureAlive();
582 	Sequence< sal_Int32 > aSel(1);
583 	aSel[0] = m_pParent->getCharSetControl()->GetColumnPos(m_pParent->getCharSetControl()->GetSelectIndexId());
584 	return aSel;
585 }
586 // -----------------------------------------------------------------------------
587 sal_Bool SAL_CALL SvxShowCharSetAcc::isAccessibleRowSelected( sal_Int32 nRow ) throw (IndexOutOfBoundsException, RuntimeException)
588 {
589 	OExternalLockGuard aGuard( this );
590 	ensureAlive();
591 	return m_pParent->getCharSetControl()->GetRowPos(m_pParent->getCharSetControl()->GetSelectIndexId()) == nRow;
592 }
593 // -----------------------------------------------------------------------------
594 sal_Bool SAL_CALL SvxShowCharSetAcc::isAccessibleColumnSelected( sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException)
595 {
596 	OExternalLockGuard aGuard( this );
597 	ensureAlive();
598 	return m_pParent->getCharSetControl()->GetColumnPos(m_pParent->getCharSetControl()->GetSelectIndexId()) == nColumn;
599 }
600 // -----------------------------------------------------------------------------
601 Reference< XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleCellAt( sal_Int32 nRow, sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException)
602 {
603 	OExternalLockGuard aGuard( this );
604 	ensureAlive();
605 	::svx::SvxShowCharSetItem* pItem = m_pParent->getCharSetControl()->ImplGetItem(
606         sal::static_int_cast<sal_uInt16>(getAccessibleIndex(nRow,nColumn) ));
607 	if ( !pItem  )
608 		throw IndexOutOfBoundsException();
609 	return pItem->GetAccessible();
610 }
611 // -----------------------------------------------------------------------------
612 Reference< XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleCaption(  ) throw (RuntimeException)
613 {
614 	return Reference< XAccessible >();
615 }
616 // -----------------------------------------------------------------------------
617 Reference< XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleSummary(  ) throw (RuntimeException)
618 {
619 	return Reference< XAccessible >();
620 }
621 // -----------------------------------------------------------------------------
622 sal_Bool SAL_CALL SvxShowCharSetAcc::isAccessibleSelected( sal_Int32 nRow, sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException)
623 {
624 	OExternalLockGuard aGuard( this );
625 	ensureAlive();
626 	return m_pParent->getCharSetControl()->GetSelectIndexId() == getAccessibleIndex(nRow,nColumn);
627 }
628 // -----------------------------------------------------------------------------
629 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleIndex( sal_Int32 nRow, sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException)
630 {
631 	return (nRow*COLUMN_COUNT) + nColumn;
632 }
633 // -----------------------------------------------------------------------------
634 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleRow( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
635 {
636 	OExternalLockGuard aGuard( this );
637 	ensureAlive();
638 	return m_pParent->getCharSetControl()->GetRowPos(sal::static_int_cast<sal_uInt16>(nChildIndex));
639 }
640 // -----------------------------------------------------------------------------
641 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleColumn( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
642 {
643 	OExternalLockGuard aGuard( this );
644 	ensureAlive();
645 	return m_pParent->getCharSetControl()->GetColumnPos(sal::static_int_cast<sal_uInt16>(nChildIndex));
646 }
647 // -----------------------------------------------------------------------------
648 
649 // -----------------------------------------------------------------------------
650 // ----------------
651 // - SvxShowCharSetItemAcc -
652 // ----------------
653 
654 SvxShowCharSetItemAcc::SvxShowCharSetItemAcc( SvxShowCharSetItem* pParent ) : OAccessibleComponentHelper(new VCLExternalSolarLock())
655 ,mpParent( pParent )
656 {
657 	OSL_ENSURE(pParent,"NO parent supplied!");
658 	osl_incrementInterlockedCount(&m_refCount);
659 	{ // #b6211265 #
660 		lateInit(this);
661 	}
662 	osl_decrementInterlockedCount(&m_refCount);
663 }
664 
665 // -----------------------------------------------------------------------------
666 
667 SvxShowCharSetItemAcc::~SvxShowCharSetItemAcc()
668 {
669 	ensureDisposed();
670 	delete getExternalLock();
671 }
672 // -----------------------------------------------------------------------------
673 IMPLEMENT_FORWARD_XINTERFACE2( SvxShowCharSetItemAcc, OAccessibleComponentHelper, OAccessibleHelper_Base_2 )
674 IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvxShowCharSetItemAcc, OAccessibleComponentHelper, OAccessibleHelper_Base_2 )
675 // -----------------------------------------------------------------------------
676 
677 void SvxShowCharSetItemAcc::ParentDestroyed()
678 {
679     const ::osl::MutexGuard aGuard( GetMutex() );
680     mpParent = NULL;
681 }
682 
683 // -----------------------------------------------------------------------------
684 
685 sal_Int32 SAL_CALL SvxShowCharSetItemAcc::getAccessibleChildCount()
686     throw (uno::RuntimeException)
687 {
688     return 0;
689 }
690 
691 // -----------------------------------------------------------------------------
692 
693 uno::Reference< accessibility::XAccessible > SAL_CALL SvxShowCharSetItemAcc::getAccessibleChild( sal_Int32 /*i*/ )
694     throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
695 {
696     throw lang::IndexOutOfBoundsException();
697 }
698 
699 // -----------------------------------------------------------------------------
700 
701 uno::Reference< accessibility::XAccessible > SAL_CALL SvxShowCharSetItemAcc::getAccessibleParent()
702     throw (uno::RuntimeException)
703 {
704     OExternalLockGuard aGuard( this );
705 	ensureAlive();
706     return mpParent->m_pParent;
707 }
708 
709 // -----------------------------------------------------------------------------
710 
711 sal_Int16 SAL_CALL SvxShowCharSetItemAcc::getAccessibleRole()
712     throw (uno::RuntimeException)
713 {
714     //return accessibility::AccessibleRole::LABEL;
715     return accessibility::AccessibleRole::TABLE_CELL;
716 }
717 
718 // -----------------------------------------------------------------------------
719 
720 ::rtl::OUString SAL_CALL SvxShowCharSetItemAcc::getAccessibleDescription()
721     throw (uno::RuntimeException)
722 {
723     OExternalLockGuard aGuard( this );
724 	ensureAlive();
725 	String sDescription = SVX_RESSTR( RID_SVXSTR_CHARACTER_CODE );
726 
727 	sal_Unicode c = mpParent->maText.GetChar(0);
728 	char buf[16] = "0x0000";
729     sal_Unicode c_Shifted = c;
730 /*
731     for( int i = 0; i < 4; ++i )
732     {
733         char h = (char)(c_Shifted & 0x0F);
734         buf[5-i] = (h > 9) ? (h - 10 + 'A') : (h + '0');
735         c_Shifted >>= 4;
736     }
737 */
738 	int tmp_len = 4;
739 	if(c_Shifted>0xFFFF) tmp_len = 8;
740     for( int i = 0; i < tmp_len; ++i )
741     {
742         char h = c_Shifted & 0x0F;
743         //buf[9-i] = (h > 9) ? (h - 10 + 'A') : (h + '0');
744 		buf[tmp_len+1-i] = (h > 9) ? (h - 10 + 'A') : (h + '0');
745         c_Shifted >>= 4;
746     }
747     if( c < 256 )
748         snprintf( buf+6, 10, " (%d)", c );
749 	sDescription.AppendAscii(" ");
750 	sDescription.AppendAscii(buf);
751 
752     return sDescription;
753 }
754 
755 // -----------------------------------------------------------------------------
756 
757 ::rtl::OUString SAL_CALL SvxShowCharSetItemAcc::getAccessibleName()
758     throw (uno::RuntimeException)
759 {
760     OExternalLockGuard aGuard( this );
761 	ensureAlive();
762     String aRet;
763 
764     if( mpParent )
765     {
766         aRet = mpParent->maText;
767 
768         if( !aRet.Len() )
769 			aRet = getAccessibleDescription();
770     }
771 
772     return aRet;
773 }
774 
775 // -----------------------------------------------------------------------------
776 
777 uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL SvxShowCharSetItemAcc::getAccessibleRelationSet()
778     throw (uno::RuntimeException)
779 {
780     return uno::Reference< accessibility::XAccessibleRelationSet >();
781 }
782 
783 // -----------------------------------------------------------------------------
784 
785 uno::Reference< accessibility::XAccessibleStateSet > SAL_CALL SvxShowCharSetItemAcc::getAccessibleStateSet()
786     throw (uno::RuntimeException)
787 {
788     OExternalLockGuard aGuard( this );
789 	ensureAlive();
790 
791     ::utl::AccessibleStateSetHelper*    pStateSet = new ::utl::AccessibleStateSetHelper;
792 
793     if( mpParent )
794     {
795 		if(mpParent->mrParent.IsEnabled())
796 		{
797 			pStateSet->AddState( accessibility::AccessibleStateType::ENABLED );
798 			// SELECTABLE
799 			pStateSet->AddState( accessibility::AccessibleStateType::SELECTABLE );
800 			pStateSet->AddState( accessibility::AccessibleStateType::FOCUSABLE );
801 		}
802 
803 	    // SELECTED
804         if( mpParent->mrParent.GetSelectIndexId() == mpParent->mnId )
805         {
806             pStateSet->AddState( accessibility::AccessibleStateType::SELECTED );
807        	    pStateSet->AddState( accessibility::AccessibleStateType::FOCUSED );
808         }
809 		if ( mpParent->mnId >= mpParent->mrParent.FirstInView() && mpParent->mnId <= mpParent->mrParent.LastInView() )
810 		{
811 			pStateSet->AddState( AccessibleStateType::VISIBLE );
812 			pStateSet->AddState( AccessibleStateType::SHOWING );
813 		}
814 		pStateSet->AddState( AccessibleStateType::TRANSIENT );
815     }
816 
817     return pStateSet;
818 }
819 
820 // -----------------------------------------------------------------------------
821 void SAL_CALL SvxShowCharSetItemAcc::grabFocus()
822     throw (uno::RuntimeException)
823 {
824     // nothing to do
825 }
826 
827 // -----------------------------------------------------------------------------
828 
829 uno::Any SAL_CALL SvxShowCharSetItemAcc::getAccessibleKeyBinding()
830     throw (uno::RuntimeException)
831 {
832     return uno::Any();
833 }
834 // -----------------------------------------------------------------------------
835 awt::Rectangle SAL_CALL SvxShowCharSetItemAcc::implGetBounds(  ) throw (RuntimeException)
836 {
837 	awt::Rectangle      aRet;
838 
839     if( mpParent )
840     {
841         Rectangle   aRect( mpParent->maRect );
842         Point       aOrigin;
843         Rectangle   aParentRect( aOrigin, mpParent->mrParent.GetOutputSizePixel() );
844 
845         aRect.Intersection( aParentRect );
846 
847         aRet.X = aRect.Left();
848         aRet.Y = aRect.Top();
849         aRet.Width = aRect.GetWidth();
850         aRet.Height = aRect.GetHeight();
851     }
852 
853     return aRet;
854 }
855 // -----------------------------------------------------------------------------
856 uno::Reference< accessibility::XAccessible > SAL_CALL SvxShowCharSetItemAcc::getAccessibleAtPoint( const awt::Point& /*aPoint*/ )
857     throw (uno::RuntimeException)
858 {
859     return uno::Reference< accessibility::XAccessible >();
860 }
861 // -----------------------------------------------------------------------------
862 sal_Int32 SAL_CALL SvxShowCharSetVirtualAcc::getForeground(  ) throw (RuntimeException)
863 {
864 	OExternalLockGuard aGuard( this );
865 
866 	sal_Int32 nColor = 0;
867 	if ( mpParent )
868 	{
869 		if ( mpParent->IsControlForeground() )
870 			nColor = mpParent->GetControlForeground().GetColor();
871 		else
872 		{
873 			Font aFont;
874 			if ( mpParent->IsControlFont() )
875 				aFont = mpParent->GetControlFont();
876 			else
877 				aFont = mpParent->GetFont();
878 			nColor = aFont.GetColor().GetColor();
879 		}
880 	}
881 
882 	return nColor;
883 }
884 // -----------------------------------------------------------------------------
885 sal_Int32 SAL_CALL SvxShowCharSetVirtualAcc::getBackground(  ) throw (RuntimeException)
886 {
887 	OExternalLockGuard aGuard( this  );
888 	sal_Int32 nColor = 0;
889 	if ( mpParent )
890 	{
891 		if ( mpParent->IsControlBackground() )
892 			nColor = mpParent->GetControlBackground().GetColor();
893 		else
894 			nColor = mpParent->GetBackground().GetColor().GetColor();
895 	}
896 
897 	return nColor;
898 }
899 // -----------------------------------------------------------------------------
900 sal_Int32 SAL_CALL SvxShowCharSetAcc::getForeground(  ) throw (RuntimeException)
901 {
902 	OExternalLockGuard aGuard( this );
903 
904 	sal_Int32 nColor = 0;
905 	if ( m_pParent )
906 		nColor = m_pParent->getForeground();
907 	return nColor;
908 }
909 // -----------------------------------------------------------------------------
910 sal_Int32 SAL_CALL SvxShowCharSetAcc::getBackground(  ) throw (RuntimeException)
911 {
912 	OExternalLockGuard aGuard( this  );
913 	sal_Int32 nColor = 0;
914 	if ( m_pParent )
915 		nColor = m_pParent->getBackground();
916 	return nColor;
917 }
918 // -----------------------------------------------------------------------------
919 
920 // -----------------------------------------------------------------------------
921 } // namespace svx
922 // -----------------------------------------------------------------------------
923 
924 
925