1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <vcl/settings.hxx>
21 #include <vcl/svapp.hxx>
23 #include <svx/charmap.hxx>
24 #include <charmapacc.hxx>
25 #include <com/sun/star/accessibility/AccessibleRole.hpp>
26 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
27 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
28 #include <o3tl/temporary.hxx>
29 #include <osl/interlck.h>
30 #include <svx/dialmgr.hxx>
31 #include <svx/strings.hrc>
32 #include <comphelper/accessiblecontexthelper.hxx>
33 #include <comphelper/types.hxx>
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
;
43 SvxShowCharSetItem::SvxShowCharSetItem( SvxShowCharSet
& rParent
,SvxShowCharSetAcc
* _pParent
,sal_uInt16 _nPos
) :
50 SvxShowCharSetItem::~SvxShowCharSetItem()
54 m_xItem
->ParentDestroyed();
59 uno::Reference
< css::accessibility::XAccessible
> SvxShowCharSetItem::GetAccessible()
63 m_xItem
= new SvxShowCharSetItemAcc( this );
69 SvxShowCharSetAcc::SvxShowCharSetAcc(SvxShowCharSet
* pParent
)
72 osl_atomic_increment(&m_refCount
);
76 osl_atomic_decrement(&m_refCount
);
79 SvxShowCharSetAcc::~SvxShowCharSetAcc()
84 void SAL_CALL
SvxShowCharSetAcc::disposing()
86 OAccessibleSelectionHelper::disposing();
87 for (auto& rChild
: m_aChildren
)
88 ::comphelper::disposeComponent(rChild
);
94 bool SvxShowCharSetAcc::implIsSelected( sal_Int64 nAccessibleChildIndex
)
99 if (nAccessibleChildIndex
< 0 || nAccessibleChildIndex
>= getAccessibleChildCount())
100 throw IndexOutOfBoundsException();
102 return m_pParent
->IsSelected(sal::static_int_cast
<sal_uInt16
>(nAccessibleChildIndex
));
105 // select the specified child => watch for special ChildIndexes (ACCESSIBLE_SELECTION_CHILD_xxx)
106 void SvxShowCharSetAcc::implSelect(sal_Int64 nAccessibleChildIndex
, bool bSelect
)
111 if (nAccessibleChildIndex
< 0 || nAccessibleChildIndex
>= getAccessibleChildCount())
112 throw IndexOutOfBoundsException();
115 m_pParent
->SelectIndex(nAccessibleChildIndex
, true);
117 m_pParent
->DeSelect();
120 css::awt::Rectangle
SvxShowCharSetAcc::implGetBounds()
126 const Point aOutPos
;//( m_pParent->GetPosPixel() );
127 Size
aOutSize( m_pParent
->GetOutputSizePixel());
129 aRet
.X
= aOutPos
.X();
130 aRet
.Y
= aOutPos
.Y();
131 aRet
.Width
= aOutSize
.Width();
132 aRet
.Height
= aOutSize
.Height();
138 sal_Int64 SAL_CALL
SvxShowCharSetAcc::getAccessibleChildCount()
140 OExternalLockGuard
aGuard( this );
142 return m_pParent
->getMaxCharCount();
145 uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
SvxShowCharSetAcc::getAccessibleChild( sal_Int64 i
)
147 OExternalLockGuard
aGuard( this );
149 uno::Reference
< css::accessibility::XAccessible
> xRet
;
150 SvxShowCharSetItem
* pItem
= m_pParent
->ImplGetItem( static_cast< sal_uInt16
>( i
) );
153 throw lang::IndexOutOfBoundsException();
155 pItem
->m_pParent
= this;
156 xRet
= pItem
->GetAccessible();
157 m_aChildren
.push_back(xRet
);
162 uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
SvxShowCharSetAcc::getAccessibleParent()
164 OExternalLockGuard
aGuard( this );
167 return m_pParent
->getAccessibleParent();
168 return uno::Reference
<css::accessibility::XAccessible
>();
171 sal_Int16 SAL_CALL
SvxShowCharSetAcc::getAccessibleRole()
173 return css::accessibility::AccessibleRole::TABLE
;
176 OUString SAL_CALL
SvxShowCharSetAcc::getAccessibleDescription()
178 OExternalLockGuard
aGuard( this );
179 return SvxResId( RID_SVXSTR_CHARACTER_SELECTION
);
183 OUString SAL_CALL
SvxShowCharSetAcc::getAccessibleName()
185 OExternalLockGuard
aGuard( this );
187 return SvxResId( RID_SVXSTR_CHAR_SEL_DESC
);
191 uno::Reference
< css::accessibility::XAccessibleRelationSet
> SAL_CALL
SvxShowCharSetAcc::getAccessibleRelationSet()
193 return uno::Reference
< css::accessibility::XAccessibleRelationSet
>();
197 sal_Int64 SAL_CALL
SvxShowCharSetAcc::getAccessibleStateSet()
199 OExternalLockGuard
aGuard( this );
201 sal_Int64 nStateSet
= 0;
206 nStateSet
|= AccessibleStateType::FOCUSABLE
;
207 if (m_pParent
->HasFocus())
209 nStateSet
|= AccessibleStateType::FOCUSED
;
210 nStateSet
|= AccessibleStateType::ACTIVE
;
212 if (m_pParent
->IsEnabled())
214 nStateSet
|= AccessibleStateType::ENABLED
;
215 nStateSet
|= AccessibleStateType::SENSITIVE
;
217 if (m_pParent
->IsVisible())
218 nStateSet
|= AccessibleStateType::VISIBLE
;
220 nStateSet
|= AccessibleStateType::MANAGES_DESCENDANTS
;
227 uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
SvxShowCharSetAcc::getAccessibleAtPoint( const awt::Point
& aPoint
)
229 OExternalLockGuard
aGuard( this );
231 uno::Reference
< css::accessibility::XAccessible
> xRet
;
232 const sal_uInt16 nItemId
= sal::static_int_cast
<sal_uInt16
>(
233 m_pParent
->PixelToMapIndex( Point( aPoint
.X
, aPoint
.Y
) ));
235 if( sal_uInt16(-1) != nItemId
)
237 SvxShowCharSetItem
* pItem
= m_pParent
->ImplGetItem( nItemId
);
238 xRet
= pItem
->GetAccessible();
243 void SAL_CALL
SvxShowCharSetAcc::grabFocus()
245 OExternalLockGuard
aGuard( this );
247 m_pParent
->GrabFocus();
250 sal_Int32 SAL_CALL
SvxShowCharSetAcc::getAccessibleRowCount( )
252 return ((getAccessibleChildCount()-1) / COLUMN_COUNT
) + 1;
255 sal_Int32 SAL_CALL
SvxShowCharSetAcc::getAccessibleColumnCount( )
260 OUString SAL_CALL
SvxShowCharSetAcc::getAccessibleRowDescription( sal_Int32
/*nRow*/ )
265 OUString SAL_CALL
SvxShowCharSetAcc::getAccessibleColumnDescription( sal_Int32
/*nColumn*/ )
270 sal_Int32 SAL_CALL
SvxShowCharSetAcc::getAccessibleRowExtentAt( sal_Int32
/*nRow*/, sal_Int32
/*nColumn*/ )
275 sal_Int32 SAL_CALL
SvxShowCharSetAcc::getAccessibleColumnExtentAt( sal_Int32
/*nRow*/, sal_Int32
/*nColumn*/ )
280 Reference
< XAccessibleTable
> SAL_CALL
SvxShowCharSetAcc::getAccessibleRowHeaders( )
282 return Reference
< XAccessibleTable
>();
285 Reference
< XAccessibleTable
> SAL_CALL
SvxShowCharSetAcc::getAccessibleColumnHeaders( )
287 return Reference
< XAccessibleTable
>();
290 Sequence
< sal_Int32
> SAL_CALL
SvxShowCharSetAcc::getSelectedAccessibleRows( )
292 OExternalLockGuard
aGuard( this );
294 return { SvxShowCharSet::GetRowPos(m_pParent
->GetSelectIndexId()) };
297 Sequence
< sal_Int32
> SAL_CALL
SvxShowCharSetAcc::getSelectedAccessibleColumns( )
299 OExternalLockGuard
aGuard( this );
301 return { SvxShowCharSet::GetColumnPos(m_pParent
->GetSelectIndexId()) };
304 sal_Bool SAL_CALL
SvxShowCharSetAcc::isAccessibleRowSelected( sal_Int32 nRow
)
306 OExternalLockGuard
aGuard( this );
308 return SvxShowCharSet::GetRowPos(m_pParent
->GetSelectIndexId()) == nRow
;
311 sal_Bool SAL_CALL
SvxShowCharSetAcc::isAccessibleColumnSelected( sal_Int32 nColumn
)
313 OExternalLockGuard
aGuard( this );
315 return SvxShowCharSet::GetColumnPos(m_pParent
->GetSelectIndexId()) == nColumn
;
318 Reference
< XAccessible
> SAL_CALL
SvxShowCharSetAcc::getAccessibleCellAt( sal_Int32 nRow
, sal_Int32 nColumn
)
320 OExternalLockGuard
aGuard( this );
322 svx::SvxShowCharSetItem
* pItem
= m_pParent
->ImplGetItem(
323 sal::static_int_cast
<sal_uInt16
>(getAccessibleIndex(nRow
,nColumn
) ));
325 throw IndexOutOfBoundsException();
326 return pItem
->GetAccessible();
329 Reference
< XAccessible
> SAL_CALL
SvxShowCharSetAcc::getAccessibleCaption( )
331 return Reference
< XAccessible
>();
334 Reference
< XAccessible
> SAL_CALL
SvxShowCharSetAcc::getAccessibleSummary( )
336 return Reference
< XAccessible
>();
339 sal_Bool SAL_CALL
SvxShowCharSetAcc::isAccessibleSelected( sal_Int32 nRow
, sal_Int32 nColumn
)
341 OExternalLockGuard
aGuard( this );
343 return m_pParent
->GetSelectIndexId() == getAccessibleIndex(nRow
,nColumn
);
346 sal_Int64 SAL_CALL
SvxShowCharSetAcc::getAccessibleIndex( sal_Int32 nRow
, sal_Int32 nColumn
)
348 return (static_cast<sal_Int64
>(nRow
) * COLUMN_COUNT
) + nColumn
;
351 sal_Int32 SAL_CALL
SvxShowCharSetAcc::getAccessibleRow( sal_Int64 nChildIndex
)
353 OExternalLockGuard
aGuard( this );
355 return SvxShowCharSet::GetRowPos(sal::static_int_cast
<sal_uInt16
>(nChildIndex
));
358 sal_Int32 SAL_CALL
SvxShowCharSetAcc::getAccessibleColumn( sal_Int64 nChildIndex
)
360 OExternalLockGuard
aGuard( this );
362 return SvxShowCharSet::GetColumnPos(sal::static_int_cast
<sal_uInt16
>(nChildIndex
));
366 SvxShowCharSetItemAcc::SvxShowCharSetItemAcc( SvxShowCharSetItem
* pParent
) : mpParent( pParent
)
368 OSL_ENSURE(pParent
,"NO parent supplied!");
369 osl_atomic_increment(&m_refCount
);
373 osl_atomic_decrement(&m_refCount
);
377 SvxShowCharSetItemAcc::~SvxShowCharSetItemAcc()
382 void SvxShowCharSetItemAcc::ParentDestroyed()
384 const ::osl::MutexGuard
aGuard( GetMutex() );
388 sal_Int64 SAL_CALL
SvxShowCharSetItemAcc::getAccessibleChildCount()
394 uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
SvxShowCharSetItemAcc::getAccessibleChild( sal_Int64
/*i*/ )
396 throw lang::IndexOutOfBoundsException();
400 uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
SvxShowCharSetItemAcc::getAccessibleParent()
402 OExternalLockGuard
aGuard( this );
404 return mpParent
->m_pParent
;
408 sal_Int16 SAL_CALL
SvxShowCharSetItemAcc::getAccessibleRole()
410 return css::accessibility::AccessibleRole::TABLE_CELL
;
414 OUString SAL_CALL
SvxShowCharSetItemAcc::getAccessibleDescription()
416 OExternalLockGuard
aGuard( this );
418 OUString sDescription
;
420 const OUString
aCharStr( mpParent
->maText
);
421 const sal_UCS4 c
= aCharStr
.iterateCodePoints( &o3tl::temporary(sal_Int32(0)) );
422 const int tmp_len
= (c
< 0x10000) ? 4 : 6;
423 char buf
[16] = "0x0000";
424 sal_UCS4 c_Shifted
= c
;
425 for( int i
= 0; i
< tmp_len
; ++i
)
427 char h
= static_cast<char>(c_Shifted
& 0x0F);
428 buf
[tmp_len
+1-i
] = (h
> 9) ? (h
- 10 + 'A') : (h
+ '0');
432 snprintf( buf
+6, 10, " (%" SAL_PRIuUINT32
")", c
);
434 sDescription
= SvxResId( RID_SVXSTR_CHARACTER_CODE
)
436 + OUString(buf
, strlen(buf
), RTL_TEXTENCODING_ASCII_US
);
442 OUString SAL_CALL
SvxShowCharSetItemAcc::getAccessibleName()
444 OExternalLockGuard
aGuard( this );
450 aRet
= mpParent
->maText
;
453 aRet
= getAccessibleDescription();
460 uno::Reference
< css::accessibility::XAccessibleRelationSet
> SAL_CALL
SvxShowCharSetItemAcc::getAccessibleRelationSet()
462 return uno::Reference
< css::accessibility::XAccessibleRelationSet
>();
466 sal_Int64 SAL_CALL
SvxShowCharSetItemAcc::getAccessibleStateSet()
468 OExternalLockGuard
aGuard( this );
470 sal_Int64 nStateSet
= 0;
474 if (mpParent
->mrParent
.IsEnabled())
476 nStateSet
|= css::accessibility::AccessibleStateType::ENABLED
;
478 nStateSet
|= css::accessibility::AccessibleStateType::SELECTABLE
;
479 nStateSet
|= css::accessibility::AccessibleStateType::FOCUSABLE
;
483 if( mpParent
->mrParent
.GetSelectIndexId() == mpParent
->mnId
)
485 nStateSet
|= css::accessibility::AccessibleStateType::SELECTED
;
486 if (mpParent
->mrParent
.HasChildFocus())
487 nStateSet
|= css::accessibility::AccessibleStateType::FOCUSED
;
489 if ( mpParent
->mnId
>= mpParent
->mrParent
.FirstInView() && mpParent
->mnId
<= mpParent
->mrParent
.LastInView() )
491 nStateSet
|= AccessibleStateType::VISIBLE
;
492 nStateSet
|= AccessibleStateType::SHOWING
;
494 nStateSet
|= AccessibleStateType::TRANSIENT
;
501 sal_Int32
SvxShowCharSetItemAcc::getAccessibleActionCount()
507 sal_Bool
SvxShowCharSetItemAcc::doAccessibleAction ( sal_Int32 nIndex
)
509 OExternalLockGuard
aGuard( this );
513 mpParent
->mrParent
.OutputIndex( mpParent
->mnId
);
516 throw IndexOutOfBoundsException();
520 OUString
SvxShowCharSetItemAcc::getAccessibleActionDescription ( sal_Int32 nIndex
)
524 throw IndexOutOfBoundsException();
528 Reference
< css::accessibility::XAccessibleKeyBinding
> SvxShowCharSetItemAcc::getAccessibleActionKeyBinding( sal_Int32 nIndex
)
531 return Reference
< css::accessibility::XAccessibleKeyBinding
>();
532 throw IndexOutOfBoundsException();
536 void SAL_CALL
SvxShowCharSetItemAcc::grabFocus()
541 awt::Rectangle
SvxShowCharSetItemAcc::implGetBounds( )
547 tools::Rectangle
aRect( mpParent
->maRect
);
548 tools::Rectangle
aParentRect(Point(), mpParent
->mrParent
.GetOutputSizePixel());
550 aRect
.Intersection( aParentRect
);
552 aRet
.X
= aRect
.Left();
553 aRet
.Y
= aRect
.Top();
554 aRet
.Width
= aRect
.GetWidth();
555 aRet
.Height
= aRect
.GetHeight();
561 uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
SvxShowCharSetItemAcc::getAccessibleAtPoint( const awt::Point
& /*aPoint*/ )
563 return uno::Reference
< css::accessibility::XAccessible
>();
566 sal_Int32 SAL_CALL
SvxShowCharSetAcc::getForeground( )
568 OExternalLockGuard
aGuard( this );
570 //see SvxShowCharSet::InitSettings
571 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
572 return static_cast<sal_Int32
>(rStyleSettings
.GetDialogTextColor());
575 sal_Int32 SAL_CALL
SvxShowCharSetAcc::getBackground( )
577 OExternalLockGuard
aGuard( this );
579 //see SvxShowCharSet::InitSettings
580 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
581 return static_cast<sal_Int32
>(rStyleSettings
.GetWindowColor());
586 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */