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 // ----------------
SvxShowCharSetVirtualAcc(SvxShowCharSet * pParent)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 
~SvxShowCharSetVirtualAcc()66 SvxShowCharSetVirtualAcc::~SvxShowCharSetVirtualAcc()
67 {
68 	ensureDisposed();
69 	delete getExternalLock();
70 }
71 // -----------------------------------------------------------------------------
IMPLEMENT_FORWARD_XINTERFACE2(SvxShowCharSetVirtualAcc,OAccessibleComponentHelper,OAccessibleHelper_Base_2)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 // -----------------------------------------------------------------------------
getAccessibleChildCount()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 // -----------------------------------------------------------------------------
getAccessibleAtPoint(const awt::Point & aPoint)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 // -----------------------------------------------------------------------------
getAccessibleKeyBinding()119 uno::Any SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleKeyBinding()
120     throw (uno::RuntimeException)
121 {
122     return uno::Any();
123 }
124 // -----------------------------------------------------------------------------
grabFocus()125 void SAL_CALL SvxShowCharSetVirtualAcc::grabFocus()
126     throw (uno::RuntimeException)
127 {
128     OExternalLockGuard aGuard( this );
129 	ensureAlive();
130     mpParent->GrabFocus();
131 }
132 
133 
134 // -----------------------------------------------------------------------------
getAccessibleChild(sal_Int32 i)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 // -----------------------------------------------------------------------------
getAccessibleParent()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 // -----------------------------------------------------------------------------
implGetBounds()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 // -----------------------------------------------------------------------------
getAccessibleRole()187 sal_Int16 SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleRole(  ) throw (RuntimeException)
188 {
189 	return accessibility::AccessibleRole::SCROLL_PANE;
190 }
191 // -----------------------------------------------------------------------------
getAccessibleDescription()192 ::rtl::OUString SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleDescription(  ) throw (RuntimeException)
193 {
194 	OExternalLockGuard aGuard( this );
195     return SVX_RESSTR( RID_SVXSTR_CHARACTER_SELECTION);
196 }
197 // -----------------------------------------------------------------------------
getAccessibleName()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 // -----------------------------------------------------------------------------
getAccessibleRelationSet()204 Reference< XAccessibleRelationSet > SAL_CALL SvxShowCharSetVirtualAcc::getAccessibleRelationSet(  ) throw (RuntimeException)
205 {
206 	return Reference< XAccessibleRelationSet >();
207 }
208 // -----------------------------------------------------------------------------
getAccessibleStateSet()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 // -----------------------------------------------------------------------------
disposing()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 
SvxShowCharSetItem(SvxShowCharSet & rParent,SvxShowCharSetAcc * _pParent,sal_uInt16 _nPos)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 
~SvxShowCharSetItem()256 SvxShowCharSetItem::~SvxShowCharSetItem()
257 {
258     if ( m_xAcc.is() )
259     {
260         m_pItem->ParentDestroyed();
261         ClearAccessible();
262     }
263 }
264 
265 // -----------------------------------------------------------------------
266 
GetAccessible()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 
ClearAccessible()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 
SvxShowCharSetAcc(SvxShowCharSetVirtualAcc * _pParent)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 
~SvxShowCharSetAcc()306 SvxShowCharSetAcc::~SvxShowCharSetAcc()
307 {
308 	ensureDisposed();
309 	delete getExternalLock();
310 }
311 // -----------------------------------------------------------------------------
disposing()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 // -----------------------------------------------------------------------------
IMPLEMENT_FORWARD_XINTERFACE2(SvxShowCharSetAcc,OAccessibleSelectionHelper,OAccessibleHelper_Base)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)
implSelect(sal_Int32 nAccessibleChildIndex,sal_Bool bSelect)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 // -----------------------------------------------------------------------------
implGetBounds()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 // -----------------------------------------------------------------------------
getAccessibleChildCount()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 
getAccessibleChild(sal_Int32 i)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 
getAccessibleParent()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 
getAccessibleRole()409 sal_Int16 SAL_CALL SvxShowCharSetAcc::getAccessibleRole()
410     throw (uno::RuntimeException)
411 {
412     return accessibility::AccessibleRole::TABLE;
413 }
414 
415 // -----------------------------------------------------------------------------
416 
getAccessibleDescription()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 
getAccessibleName()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 
getAccessibleRelationSet()436 uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL SvxShowCharSetAcc::getAccessibleRelationSet()
437     throw (uno::RuntimeException)
438 {
439     return uno::Reference< accessibility::XAccessibleRelationSet >();
440 }
441 
442 // -----------------------------------------------------------------------------
443 
getAccessibleStateSet()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 
getAccessibleAtPoint(const awt::Point & aPoint)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 
grabFocus()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 
getAccessibleKeyBinding()505 uno::Any SAL_CALL SvxShowCharSetAcc::getAccessibleKeyBinding()
506     throw (uno::RuntimeException)
507 {
508     return uno::Any();
509 }
510 // -----------------------------------------------------------------------------
getAccessibleRowCount()511 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleRowCount(  ) throw (RuntimeException)
512 {
513 	return ((getAccessibleChildCount()-1) / COLUMN_COUNT) + 1;
514 }
515 // -----------------------------------------------------------------------------
getAccessibleColumnCount()516 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleColumnCount(  ) throw (RuntimeException)
517 {
518 	return COLUMN_COUNT;
519 }
520 // -----------------------------------------------------------------------------
getAccessibleRowDescription(sal_Int32)521 ::rtl::OUString SAL_CALL SvxShowCharSetAcc::getAccessibleRowDescription( sal_Int32 /*nRow*/ ) throw (IndexOutOfBoundsException, RuntimeException)
522 {
523 	return ::rtl::OUString();
524 }
525 // -----------------------------------------------------------------------------
getAccessibleColumnDescription(sal_Int32)526 ::rtl::OUString SAL_CALL SvxShowCharSetAcc::getAccessibleColumnDescription( sal_Int32 /*nColumn*/ ) throw (IndexOutOfBoundsException, RuntimeException)
527 {
528 	return ::rtl::OUString();
529 }
530 // -----------------------------------------------------------------------------
getAccessibleRowExtentAt(sal_Int32,sal_Int32)531 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleRowExtentAt( sal_Int32 /*nRow*/, sal_Int32 /*nColumn*/ ) throw (IndexOutOfBoundsException, RuntimeException)
532 {
533 	return 1;
534 }
535 // -----------------------------------------------------------------------------
getAccessibleColumnExtentAt(sal_Int32,sal_Int32)536 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleColumnExtentAt( sal_Int32 /*nRow*/, sal_Int32 /*nColumn*/ ) throw (IndexOutOfBoundsException, RuntimeException)
537 {
538 	return 1;
539 }
540 // -----------------------------------------------------------------------------
getAccessibleRowHeaders()541 Reference< XAccessibleTable > SAL_CALL SvxShowCharSetAcc::getAccessibleRowHeaders(  ) throw (RuntimeException)
542 {
543 	return Reference< XAccessibleTable >();
544 }
545 // -----------------------------------------------------------------------------
getAccessibleColumnHeaders()546 Reference< XAccessibleTable > SAL_CALL SvxShowCharSetAcc::getAccessibleColumnHeaders(  ) throw (RuntimeException)
547 {
548 	return Reference< XAccessibleTable >();
549 }
550 // -----------------------------------------------------------------------------
getSelectedAccessibleRows()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 // -----------------------------------------------------------------------------
getSelectedAccessibleColumns()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 // -----------------------------------------------------------------------------
isAccessibleRowSelected(sal_Int32 nRow)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 // -----------------------------------------------------------------------------
isAccessibleColumnSelected(sal_Int32 nColumn)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 // -----------------------------------------------------------------------------
getAccessibleCellAt(sal_Int32 nRow,sal_Int32 nColumn)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 // -----------------------------------------------------------------------------
getAccessibleCaption()594 Reference< XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleCaption(  ) throw (RuntimeException)
595 {
596 	return Reference< XAccessible >();
597 }
598 // -----------------------------------------------------------------------------
getAccessibleSummary()599 Reference< XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleSummary(  ) throw (RuntimeException)
600 {
601 	return Reference< XAccessible >();
602 }
603 // -----------------------------------------------------------------------------
isAccessibleSelected(sal_Int32 nRow,sal_Int32 nColumn)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 // -----------------------------------------------------------------------------
getAccessibleIndex(sal_Int32 nRow,sal_Int32 nColumn)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 // -----------------------------------------------------------------------------
getAccessibleRow(sal_Int32 nChildIndex)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 // -----------------------------------------------------------------------------
getAccessibleColumn(sal_Int32 nChildIndex)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 
SvxShowCharSetItemAcc(SvxShowCharSetItem * pParent)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 
~SvxShowCharSetItemAcc()649 SvxShowCharSetItemAcc::~SvxShowCharSetItemAcc()
650 {
651 	ensureDisposed();
652 	delete getExternalLock();
653 }
654 // -----------------------------------------------------------------------------
IMPLEMENT_FORWARD_XINTERFACE2(SvxShowCharSetItemAcc,OAccessibleComponentHelper,OAccessibleHelper_Base_2)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 
getAccessibleChildCount()667 sal_Int32 SAL_CALL SvxShowCharSetItemAcc::getAccessibleChildCount()
668     throw (uno::RuntimeException)
669 {
670     return 0;
671 }
672 
673 // -----------------------------------------------------------------------------
674 
getAccessibleChild(sal_Int32)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 
getAccessibleParent()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 
getAccessibleRole()693 sal_Int16 SAL_CALL SvxShowCharSetItemAcc::getAccessibleRole()
694     throw (uno::RuntimeException)
695 {
696     return accessibility::AccessibleRole::TABLE_CELL;
697 }
698 
699 // -----------------------------------------------------------------------------
700 
getAccessibleDescription()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 	const rtl::OUString aCharStr( mpParent->maText);
709 	sal_Int32 nStrIndex = 0;
710 	const sal_UCS4 c = aCharStr.iterateCodePoints( &nStrIndex );
711 	const int tmp_len = (c < 0x10000) ? 4 : 6;
712 	char buf[16] = "0x0000";
713 	sal_UCS4 c_Shifted = c;
714     for( int i = 0; i < tmp_len; ++i )
715     {
716         char h = c_Shifted & 0x0F;
717 		buf[tmp_len+1-i] = (h > 9) ? (h - 10 + 'A') : (h + '0');
718         c_Shifted >>= 4;
719     }
720     if( c < 256 )
721         snprintf( buf+6, 10, " (%d)", c );
722 	sDescription.AppendAscii(" ");
723 	sDescription.AppendAscii(buf);
724 
725     return sDescription;
726 }
727 
728 // -----------------------------------------------------------------------------
729 
getAccessibleName()730 ::rtl::OUString SAL_CALL SvxShowCharSetItemAcc::getAccessibleName()
731     throw (uno::RuntimeException)
732 {
733     OExternalLockGuard aGuard( this );
734 	ensureAlive();
735     String aRet;
736 
737     if( mpParent )
738     {
739         aRet = mpParent->maText;
740 
741         if( !aRet.Len() )
742 			aRet = getAccessibleDescription();
743     }
744 
745     return aRet;
746 }
747 
748 // -----------------------------------------------------------------------------
749 
getAccessibleRelationSet()750 uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL SvxShowCharSetItemAcc::getAccessibleRelationSet()
751     throw (uno::RuntimeException)
752 {
753     return uno::Reference< accessibility::XAccessibleRelationSet >();
754 }
755 
756 // -----------------------------------------------------------------------------
757 
getAccessibleStateSet()758 uno::Reference< accessibility::XAccessibleStateSet > SAL_CALL SvxShowCharSetItemAcc::getAccessibleStateSet()
759     throw (uno::RuntimeException)
760 {
761     OExternalLockGuard aGuard( this );
762 	ensureAlive();
763 
764     ::utl::AccessibleStateSetHelper*    pStateSet = new ::utl::AccessibleStateSetHelper;
765 
766     if( mpParent )
767     {
768 		if(mpParent->mrParent.IsEnabled())
769 		{
770 			pStateSet->AddState( accessibility::AccessibleStateType::ENABLED );
771 			// SELECTABLE
772 			pStateSet->AddState( accessibility::AccessibleStateType::SELECTABLE );
773 			pStateSet->AddState( accessibility::AccessibleStateType::FOCUSABLE );
774 		}
775 
776 	    // SELECTED
777         if( mpParent->mrParent.GetSelectIndexId() == mpParent->mnId )
778         {
779             pStateSet->AddState( accessibility::AccessibleStateType::SELECTED );
780        	    pStateSet->AddState( accessibility::AccessibleStateType::FOCUSED );
781         }
782 		if ( mpParent->mnId >= mpParent->mrParent.FirstInView() && mpParent->mnId <= mpParent->mrParent.LastInView() )
783 		{
784 			pStateSet->AddState( AccessibleStateType::VISIBLE );
785 			pStateSet->AddState( AccessibleStateType::SHOWING );
786 		}
787 		pStateSet->AddState( AccessibleStateType::TRANSIENT );
788     }
789 
790     return pStateSet;
791 }
792 
793 // -----------------------------------------------------------------------------
grabFocus()794 void SAL_CALL SvxShowCharSetItemAcc::grabFocus()
795     throw (uno::RuntimeException)
796 {
797     // nothing to do
798 }
799 
800 // -----------------------------------------------------------------------------
801 
getAccessibleKeyBinding()802 uno::Any SAL_CALL SvxShowCharSetItemAcc::getAccessibleKeyBinding()
803     throw (uno::RuntimeException)
804 {
805     return uno::Any();
806 }
807 // -----------------------------------------------------------------------------
implGetBounds()808 awt::Rectangle SAL_CALL SvxShowCharSetItemAcc::implGetBounds(  ) throw (RuntimeException)
809 {
810 	awt::Rectangle      aRet;
811 
812     if( mpParent )
813     {
814         Rectangle   aRect( mpParent->maRect );
815         Point       aOrigin;
816         Rectangle   aParentRect( aOrigin, mpParent->mrParent.GetOutputSizePixel() );
817 
818         aRect.Intersection( aParentRect );
819 
820         aRet.X = aRect.Left();
821         aRet.Y = aRect.Top();
822         aRet.Width = aRect.GetWidth();
823         aRet.Height = aRect.GetHeight();
824     }
825 
826     return aRet;
827 }
828 // -----------------------------------------------------------------------------
getAccessibleAtPoint(const awt::Point &)829 uno::Reference< accessibility::XAccessible > SAL_CALL SvxShowCharSetItemAcc::getAccessibleAtPoint( const awt::Point& /*aPoint*/ )
830     throw (uno::RuntimeException)
831 {
832     return uno::Reference< accessibility::XAccessible >();
833 }
834 // -----------------------------------------------------------------------------
getForeground()835 sal_Int32 SAL_CALL SvxShowCharSetVirtualAcc::getForeground(  ) throw (RuntimeException)
836 {
837 	OExternalLockGuard aGuard( this );
838 
839 	sal_Int32 nColor = 0;
840 	if ( mpParent )
841 	{
842 		if ( mpParent->IsControlForeground() )
843 			nColor = mpParent->GetControlForeground().GetColor();
844 		else
845 		{
846 			Font aFont;
847 			if ( mpParent->IsControlFont() )
848 				aFont = mpParent->GetControlFont();
849 			else
850 				aFont = mpParent->GetFont();
851 			nColor = aFont.GetColor().GetColor();
852 		}
853 	}
854 
855 	return nColor;
856 }
857 // -----------------------------------------------------------------------------
getBackground()858 sal_Int32 SAL_CALL SvxShowCharSetVirtualAcc::getBackground(  ) throw (RuntimeException)
859 {
860 	OExternalLockGuard aGuard( this  );
861 	sal_Int32 nColor = 0;
862 	if ( mpParent )
863 	{
864 		if ( mpParent->IsControlBackground() )
865 			nColor = mpParent->GetControlBackground().GetColor();
866 		else
867 			nColor = mpParent->GetBackground().GetColor().GetColor();
868 	}
869 
870 	return nColor;
871 }
872 // -----------------------------------------------------------------------------
getForeground()873 sal_Int32 SAL_CALL SvxShowCharSetAcc::getForeground(  ) throw (RuntimeException)
874 {
875 	OExternalLockGuard aGuard( this );
876 
877 	sal_Int32 nColor = 0;
878 	if ( m_pParent )
879 		nColor = m_pParent->getForeground();
880 	return nColor;
881 }
882 // -----------------------------------------------------------------------------
getBackground()883 sal_Int32 SAL_CALL SvxShowCharSetAcc::getBackground(  ) throw (RuntimeException)
884 {
885 	OExternalLockGuard aGuard( this  );
886 	sal_Int32 nColor = 0;
887 	if ( m_pParent )
888 		nColor = m_pParent->getBackground();
889 	return nColor;
890 }
891 // -----------------------------------------------------------------------------
892 
893 // -----------------------------------------------------------------------------
894 } // namespace svx
895 // -----------------------------------------------------------------------------
896 
897 
898