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