1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20 #include <unotools/accessiblestatesethelper.hxx>
21 #include <vcl/settings.hxx>
22 #include <vcl/svapp.hxx>
23 #include <stdio.h>
24 #include <svx/charmap.hxx>
25 #include <charmapacc.hxx>
26 #include <com/sun/star/accessibility/AccessibleRole.hpp>
27 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
28 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
29 #include <o3tl/temporary.hxx>
30 #include <osl/interlck.h>
31 #include <svx/dialmgr.hxx>
32 #include <svx/strings.hrc>
33 #include <comphelper/types.hxx>
34
35 namespace svx
36 {
37 using namespace comphelper;
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::lang;
41 using namespace ::com::sun::star::accessibility;
42
SvxShowCharSetItem(SvxShowCharSet & rParent,SvxShowCharSetAcc * _pParent,sal_uInt16 _nPos)43 SvxShowCharSetItem::SvxShowCharSetItem( SvxShowCharSet& rParent,SvxShowCharSetAcc* _pParent,sal_uInt16 _nPos ) :
44 mrParent( rParent )
45 ,mnId( _nPos )
46 ,m_pParent(_pParent)
47 {
48 }
49
~SvxShowCharSetItem()50 SvxShowCharSetItem::~SvxShowCharSetItem()
51 {
52 if ( m_xItem.is() )
53 {
54 m_xItem->ParentDestroyed();
55 m_xItem.clear();
56 }
57 }
58
GetAccessible()59 uno::Reference< css::accessibility::XAccessible > SvxShowCharSetItem::GetAccessible()
60 {
61 if( !m_xItem.is() )
62 {
63 m_xItem = new SvxShowCharSetItemAcc( this );
64 }
65
66 return m_xItem;
67 }
68
SvxShowCharSetAcc(SvxShowCharSet * pParent)69 SvxShowCharSetAcc::SvxShowCharSetAcc(SvxShowCharSet* pParent)
70 : m_pParent(pParent)
71 {
72 osl_atomic_increment(&m_refCount);
73 {
74 lateInit(this);
75 }
76 osl_atomic_decrement(&m_refCount);
77 }
78
~SvxShowCharSetAcc()79 SvxShowCharSetAcc::~SvxShowCharSetAcc()
80 {
81 ensureDisposed();
82 }
83
disposing()84 void SAL_CALL SvxShowCharSetAcc::disposing()
85 {
86 OAccessibleSelectionHelper::disposing();
87 for (auto& rChild : m_aChildren)
88 ::comphelper::disposeComponent(rChild);
89
90 m_aChildren.clear();
91 m_pParent = nullptr;
92 }
93
94
IMPLEMENT_FORWARD_XINTERFACE2(SvxShowCharSetAcc,OAccessibleSelectionHelper,OAccessibleHelper_Base)95 IMPLEMENT_FORWARD_XINTERFACE2( SvxShowCharSetAcc, OAccessibleSelectionHelper, OAccessibleHelper_Base )
96 IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvxShowCharSetAcc, OAccessibleSelectionHelper, OAccessibleHelper_Base )
97
98 bool SvxShowCharSetAcc::implIsSelected( sal_Int32 nAccessibleChildIndex )
99 {
100 return m_pParent && m_pParent->IsSelected(
101 sal::static_int_cast<sal_uInt16>(nAccessibleChildIndex));
102 }
103
104 // select the specified child => watch for special ChildIndexes (ACCESSIBLE_SELECTION_CHILD_xxx)
implSelect(sal_Int32 nAccessibleChildIndex,bool bSelect)105 void SvxShowCharSetAcc::implSelect(sal_Int32 nAccessibleChildIndex, bool bSelect)
106 {
107 if ( m_pParent )
108 {
109 if ( bSelect )
110 m_pParent->SelectIndex(nAccessibleChildIndex, true);
111 else
112 m_pParent->DeSelect();
113 }
114 }
115
implGetBounds()116 css::awt::Rectangle SvxShowCharSetAcc::implGetBounds()
117 {
118 awt::Rectangle aRet;
119
120 if (m_pParent)
121 {
122 const Point aOutPos;//( m_pParent->GetPosPixel() );
123 Size aOutSize( m_pParent->GetOutputSizePixel());
124
125 aRet.X = aOutPos.X();
126 aRet.Y = aOutPos.Y();
127 aRet.Width = aOutSize.Width();
128 aRet.Height = aOutSize.Height();
129 }
130
131 return aRet;
132 }
133
getAccessibleChildCount()134 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleChildCount()
135 {
136 OExternalLockGuard aGuard( this );
137
138 return m_pParent->getMaxCharCount();
139 }
140
getAccessibleChild(sal_Int32 i)141 uno::Reference< css::accessibility::XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleChild( sal_Int32 i )
142 {
143 OExternalLockGuard aGuard( this );
144
145 uno::Reference< css::accessibility::XAccessible > xRet;
146 SvxShowCharSetItem* pItem = m_pParent->ImplGetItem( static_cast< sal_uInt16 >( i ) );
147
148 if( !pItem )
149 throw lang::IndexOutOfBoundsException();
150
151 pItem->m_pParent = this;
152 xRet = pItem->GetAccessible();
153 m_aChildren.push_back(xRet);
154
155 return xRet;
156 }
157
getAccessibleParent()158 uno::Reference< css::accessibility::XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleParent()
159 {
160 OExternalLockGuard aGuard( this );
161
162 if (m_pParent)
163 return m_pParent->getAccessibleParent();
164 return uno::Reference<css::accessibility::XAccessible>();
165 }
166
getAccessibleRole()167 sal_Int16 SAL_CALL SvxShowCharSetAcc::getAccessibleRole()
168 {
169 return css::accessibility::AccessibleRole::TABLE;
170 }
171
getAccessibleDescription()172 OUString SAL_CALL SvxShowCharSetAcc::getAccessibleDescription()
173 {
174 OExternalLockGuard aGuard( this );
175 return SvxResId( RID_SVXSTR_CHARACTER_SELECTION );
176 }
177
178
getAccessibleName()179 OUString SAL_CALL SvxShowCharSetAcc::getAccessibleName()
180 {
181 OExternalLockGuard aGuard( this );
182
183 return SvxResId( RID_SVXSTR_CHAR_SEL_DESC );
184 }
185
186
getAccessibleRelationSet()187 uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL SvxShowCharSetAcc::getAccessibleRelationSet()
188 {
189 return uno::Reference< css::accessibility::XAccessibleRelationSet >();
190 }
191
192
getAccessibleStateSet()193 uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL SvxShowCharSetAcc::getAccessibleStateSet()
194 {
195 OExternalLockGuard aGuard( this );
196
197 rtl::Reference<::utl::AccessibleStateSetHelper> pStateSet = new ::utl::AccessibleStateSetHelper;
198
199 if (m_pParent)
200 {
201 // SELECTABLE
202 pStateSet->AddState( AccessibleStateType::FOCUSABLE );
203 if (m_pParent->HasFocus())
204 {
205 pStateSet->AddState( AccessibleStateType::FOCUSED );
206 pStateSet->AddState( AccessibleStateType::ACTIVE );
207 }
208 if (m_pParent->IsEnabled())
209 {
210 pStateSet->AddState( AccessibleStateType::ENABLED );
211 pStateSet->AddState( AccessibleStateType::SENSITIVE );
212 }
213 if (m_pParent->IsVisible())
214 pStateSet->AddState( AccessibleStateType::VISIBLE );
215
216 pStateSet->AddState( AccessibleStateType::MANAGES_DESCENDANTS );
217 }
218
219 return pStateSet;
220 }
221
222
getAccessibleAtPoint(const awt::Point & aPoint)223 uno::Reference< css::accessibility::XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleAtPoint( const awt::Point& aPoint )
224 {
225 OExternalLockGuard aGuard( this );
226
227 uno::Reference< css::accessibility::XAccessible > xRet;
228 const sal_uInt16 nItemId = sal::static_int_cast<sal_uInt16>(
229 m_pParent->PixelToMapIndex( Point( aPoint.X, aPoint.Y ) ));
230
231 if( sal_uInt16(-1) != nItemId )
232 {
233 SvxShowCharSetItem* pItem = m_pParent->ImplGetItem( nItemId );
234 xRet = pItem->GetAccessible();
235 }
236 return xRet;
237 }
238
grabFocus()239 void SAL_CALL SvxShowCharSetAcc::grabFocus()
240 {
241 OExternalLockGuard aGuard( this );
242
243 m_pParent->GrabFocus();
244 }
245
getAccessibleRowCount()246 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleRowCount( )
247 {
248 return ((getAccessibleChildCount()-1) / COLUMN_COUNT) + 1;
249 }
250
getAccessibleColumnCount()251 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleColumnCount( )
252 {
253 return COLUMN_COUNT;
254 }
255
getAccessibleRowDescription(sal_Int32)256 OUString SAL_CALL SvxShowCharSetAcc::getAccessibleRowDescription( sal_Int32 /*nRow*/ )
257 {
258 return OUString();
259 }
260
getAccessibleColumnDescription(sal_Int32)261 OUString SAL_CALL SvxShowCharSetAcc::getAccessibleColumnDescription( sal_Int32 /*nColumn*/ )
262 {
263 return OUString();
264 }
265
getAccessibleRowExtentAt(sal_Int32,sal_Int32)266 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleRowExtentAt( sal_Int32 /*nRow*/, sal_Int32 /*nColumn*/ )
267 {
268 return 1;
269 }
270
getAccessibleColumnExtentAt(sal_Int32,sal_Int32)271 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleColumnExtentAt( sal_Int32 /*nRow*/, sal_Int32 /*nColumn*/ )
272 {
273 return 1;
274 }
275
getAccessibleRowHeaders()276 Reference< XAccessibleTable > SAL_CALL SvxShowCharSetAcc::getAccessibleRowHeaders( )
277 {
278 return Reference< XAccessibleTable >();
279 }
280
getAccessibleColumnHeaders()281 Reference< XAccessibleTable > SAL_CALL SvxShowCharSetAcc::getAccessibleColumnHeaders( )
282 {
283 return Reference< XAccessibleTable >();
284 }
285
getSelectedAccessibleRows()286 Sequence< sal_Int32 > SAL_CALL SvxShowCharSetAcc::getSelectedAccessibleRows( )
287 {
288 OExternalLockGuard aGuard( this );
289
290 return { SvxShowCharSet::GetRowPos(m_pParent->GetSelectIndexId()) };
291 }
292
getSelectedAccessibleColumns()293 Sequence< sal_Int32 > SAL_CALL SvxShowCharSetAcc::getSelectedAccessibleColumns( )
294 {
295 OExternalLockGuard aGuard( this );
296
297 return { SvxShowCharSet::GetColumnPos(m_pParent->GetSelectIndexId()) };
298 }
299
isAccessibleRowSelected(sal_Int32 nRow)300 sal_Bool SAL_CALL SvxShowCharSetAcc::isAccessibleRowSelected( sal_Int32 nRow )
301 {
302 OExternalLockGuard aGuard( this );
303
304 return SvxShowCharSet::GetRowPos(m_pParent->GetSelectIndexId()) == nRow;
305 }
306
isAccessibleColumnSelected(sal_Int32 nColumn)307 sal_Bool SAL_CALL SvxShowCharSetAcc::isAccessibleColumnSelected( sal_Int32 nColumn )
308 {
309 OExternalLockGuard aGuard( this );
310 ensureAlive();
311 return SvxShowCharSet::GetColumnPos(m_pParent->GetSelectIndexId()) == nColumn;
312 }
313
getAccessibleCellAt(sal_Int32 nRow,sal_Int32 nColumn)314 Reference< XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleCellAt( sal_Int32 nRow, sal_Int32 nColumn )
315 {
316 OExternalLockGuard aGuard( this );
317
318 svx::SvxShowCharSetItem* pItem = m_pParent->ImplGetItem(
319 sal::static_int_cast<sal_uInt16>(getAccessibleIndex(nRow,nColumn) ));
320 if ( !pItem )
321 throw IndexOutOfBoundsException();
322 return pItem->GetAccessible();
323 }
324
getAccessibleCaption()325 Reference< XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleCaption( )
326 {
327 return Reference< XAccessible >();
328 }
329
getAccessibleSummary()330 Reference< XAccessible > SAL_CALL SvxShowCharSetAcc::getAccessibleSummary( )
331 {
332 return Reference< XAccessible >();
333 }
334
isAccessibleSelected(sal_Int32 nRow,sal_Int32 nColumn)335 sal_Bool SAL_CALL SvxShowCharSetAcc::isAccessibleSelected( sal_Int32 nRow, sal_Int32 nColumn )
336 {
337 OExternalLockGuard aGuard( this );
338
339 return m_pParent->GetSelectIndexId() == getAccessibleIndex(nRow,nColumn);
340 }
341
getAccessibleIndex(sal_Int32 nRow,sal_Int32 nColumn)342 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleIndex( sal_Int32 nRow, sal_Int32 nColumn )
343 {
344 return (nRow*COLUMN_COUNT) + nColumn;
345 }
346
getAccessibleRow(sal_Int32 nChildIndex)347 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleRow( sal_Int32 nChildIndex )
348 {
349 OExternalLockGuard aGuard( this );
350
351 return SvxShowCharSet::GetRowPos(sal::static_int_cast<sal_uInt16>(nChildIndex));
352 }
353
getAccessibleColumn(sal_Int32 nChildIndex)354 sal_Int32 SAL_CALL SvxShowCharSetAcc::getAccessibleColumn( sal_Int32 nChildIndex )
355 {
356 OExternalLockGuard aGuard( this );
357
358 return SvxShowCharSet::GetColumnPos(sal::static_int_cast<sal_uInt16>(nChildIndex));
359 }
360
361
SvxShowCharSetItemAcc(SvxShowCharSetItem * pParent)362 SvxShowCharSetItemAcc::SvxShowCharSetItemAcc( SvxShowCharSetItem* pParent ) : mpParent( pParent )
363 {
364 OSL_ENSURE(pParent,"NO parent supplied!");
365 osl_atomic_increment(&m_refCount);
366 { // #b6211265 #
367 lateInit(this);
368 }
369 osl_atomic_decrement(&m_refCount);
370 }
371
372
~SvxShowCharSetItemAcc()373 SvxShowCharSetItemAcc::~SvxShowCharSetItemAcc()
374 {
375 ensureDisposed();
376 }
377
IMPLEMENT_FORWARD_XINTERFACE2(SvxShowCharSetItemAcc,OAccessibleComponentHelper,OAccessibleHelper_Base_3)378 IMPLEMENT_FORWARD_XINTERFACE2( SvxShowCharSetItemAcc, OAccessibleComponentHelper, OAccessibleHelper_Base_3 )
379 IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvxShowCharSetItemAcc, OAccessibleComponentHelper, OAccessibleHelper_Base_3 )
380
381 void SvxShowCharSetItemAcc::ParentDestroyed()
382 {
383 const ::osl::MutexGuard aGuard( GetMutex() );
384 mpParent = nullptr;
385 }
386
getAccessibleChildCount()387 sal_Int32 SAL_CALL SvxShowCharSetItemAcc::getAccessibleChildCount()
388 {
389 return 0;
390 }
391
392
getAccessibleChild(sal_Int32)393 uno::Reference< css::accessibility::XAccessible > SAL_CALL SvxShowCharSetItemAcc::getAccessibleChild( sal_Int32 /*i*/ )
394 {
395 throw lang::IndexOutOfBoundsException();
396 }
397
398
getAccessibleParent()399 uno::Reference< css::accessibility::XAccessible > SAL_CALL SvxShowCharSetItemAcc::getAccessibleParent()
400 {
401 OExternalLockGuard aGuard( this );
402
403 return mpParent->m_pParent;
404 }
405
406
getAccessibleRole()407 sal_Int16 SAL_CALL SvxShowCharSetItemAcc::getAccessibleRole()
408 {
409 return css::accessibility::AccessibleRole::TABLE_CELL;
410 }
411
412
getAccessibleDescription()413 OUString SAL_CALL SvxShowCharSetItemAcc::getAccessibleDescription()
414 {
415 OExternalLockGuard aGuard( this );
416
417 OUString sDescription;
418
419 const OUString aCharStr( mpParent->maText);
420 const sal_UCS4 c = aCharStr.iterateCodePoints( &o3tl::temporary(sal_Int32(0)) );
421 const int tmp_len = (c < 0x10000) ? 4 : 6;
422 char buf[16] = "0x0000";
423 sal_UCS4 c_Shifted = c;
424 for( int i = 0; i < tmp_len; ++i )
425 {
426 char h = static_cast<char>(c_Shifted & 0x0F);
427 buf[tmp_len+1-i] = (h > 9) ? (h - 10 + 'A') : (h + '0');
428 c_Shifted >>= 4;
429 }
430 if( c < 256 )
431 snprintf( buf+6, 10, " (%" SAL_PRIuUINT32 ")", c );
432
433 sDescription = SvxResId( RID_SVXSTR_CHARACTER_CODE )
434 + " "
435 + OUString(buf, strlen(buf), RTL_TEXTENCODING_ASCII_US);
436
437 return sDescription;
438 }
439
440
getAccessibleName()441 OUString SAL_CALL SvxShowCharSetItemAcc::getAccessibleName()
442 {
443 OExternalLockGuard aGuard( this );
444
445 OUString aRet;
446
447 if( mpParent )
448 {
449 aRet = mpParent->maText;
450
451 if (aRet.isEmpty())
452 aRet = getAccessibleDescription();
453 }
454
455 return aRet;
456 }
457
458
getAccessibleRelationSet()459 uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL SvxShowCharSetItemAcc::getAccessibleRelationSet()
460 {
461 return uno::Reference< css::accessibility::XAccessibleRelationSet >();
462 }
463
464
getAccessibleStateSet()465 uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL SvxShowCharSetItemAcc::getAccessibleStateSet()
466 {
467 OExternalLockGuard aGuard( this );
468
469 rtl::Reference<::utl::AccessibleStateSetHelper> pStateSet = new ::utl::AccessibleStateSetHelper;
470
471 if( mpParent )
472 {
473 if (mpParent->mrParent.IsEnabled())
474 {
475 pStateSet->AddState( css::accessibility::AccessibleStateType::ENABLED );
476 // SELECTABLE
477 pStateSet->AddState( css::accessibility::AccessibleStateType::SELECTABLE );
478 pStateSet->AddState( css::accessibility::AccessibleStateType::FOCUSABLE );
479 }
480
481 // SELECTED
482 if( mpParent->mrParent.GetSelectIndexId() == mpParent->mnId )
483 {
484 pStateSet->AddState( css::accessibility::AccessibleStateType::SELECTED );
485 pStateSet->AddState( css::accessibility::AccessibleStateType::FOCUSED );
486 }
487 if ( mpParent->mnId >= mpParent->mrParent.FirstInView() && mpParent->mnId <= mpParent->mrParent.LastInView() )
488 {
489 pStateSet->AddState( AccessibleStateType::VISIBLE );
490 pStateSet->AddState( AccessibleStateType::SHOWING );
491 }
492 pStateSet->AddState( AccessibleStateType::TRANSIENT );
493 }
494
495 return pStateSet;
496 }
497
498
getAccessibleActionCount()499 sal_Int32 SvxShowCharSetItemAcc::getAccessibleActionCount()
500 {
501 return 1;
502 }
503
504
doAccessibleAction(sal_Int32 nIndex)505 sal_Bool SvxShowCharSetItemAcc::doAccessibleAction ( sal_Int32 nIndex )
506 {
507 OExternalLockGuard aGuard( this );
508
509 if( nIndex == 0 )
510 {
511 mpParent->mrParent.OutputIndex( mpParent->mnId );
512 return true;
513 }
514 throw IndexOutOfBoundsException();
515 }
516
517
getAccessibleActionDescription(sal_Int32 nIndex)518 OUString SvxShowCharSetItemAcc::getAccessibleActionDescription ( sal_Int32 nIndex )
519 {
520 if( nIndex == 0 )
521 return "press";
522 throw IndexOutOfBoundsException();
523 }
524
525
getAccessibleActionKeyBinding(sal_Int32 nIndex)526 Reference< css::accessibility::XAccessibleKeyBinding > SvxShowCharSetItemAcc::getAccessibleActionKeyBinding( sal_Int32 nIndex )
527 {
528 if( nIndex == 0 )
529 return Reference< css::accessibility::XAccessibleKeyBinding >();
530 throw IndexOutOfBoundsException();
531 }
532
533
grabFocus()534 void SAL_CALL SvxShowCharSetItemAcc::grabFocus()
535 {
536 // nothing to do
537 }
538
implGetBounds()539 awt::Rectangle SvxShowCharSetItemAcc::implGetBounds( )
540 {
541 awt::Rectangle aRet;
542
543 if( mpParent )
544 {
545 tools::Rectangle aRect( mpParent->maRect );
546 tools::Rectangle aParentRect(Point(), mpParent->mrParent.GetOutputSizePixel());
547
548 aRect.Intersection( aParentRect );
549
550 aRet.X = aRect.Left();
551 aRet.Y = aRect.Top();
552 aRet.Width = aRect.GetWidth();
553 aRet.Height = aRect.GetHeight();
554 }
555
556 return aRet;
557 }
558
getAccessibleAtPoint(const awt::Point &)559 uno::Reference< css::accessibility::XAccessible > SAL_CALL SvxShowCharSetItemAcc::getAccessibleAtPoint( const awt::Point& /*aPoint*/ )
560 {
561 return uno::Reference< css::accessibility::XAccessible >();
562 }
563
getForeground()564 sal_Int32 SAL_CALL SvxShowCharSetAcc::getForeground( )
565 {
566 OExternalLockGuard aGuard( this );
567
568 //see SvxShowCharSet::InitSettings
569 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
570 return static_cast<sal_Int32>(rStyleSettings.GetDialogTextColor());
571 }
572
getBackground()573 sal_Int32 SAL_CALL SvxShowCharSetAcc::getBackground( )
574 {
575 OExternalLockGuard aGuard( this );
576
577 //see SvxShowCharSet::InitSettings
578 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
579 return static_cast<sal_Int32>(rStyleSettings.GetWindowColor());
580 }
581
582 }
583
584 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
585