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 <standard/vclxaccessibletoolboxitem.hxx>
21 #include <toolkit/helper/convert.hxx>
22 #include <helper/accresmgr.hxx>
23 #include <strings.hrc>
24 #include <com/sun/star/awt/Rectangle.hpp>
25 
26 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
27 #include <com/sun/star/accessibility/AccessibleRole.hpp>
28 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
29 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
30 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
31 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
32 #include <cppuhelper/supportsservice.hxx>
33 #include <vcl/svapp.hxx>
34 #include <vcl/toolbox.hxx>
35 #include <vcl/unohelp2.hxx>
36 #include <vcl/help.hxx>
37 #include <vcl/settings.hxx>
38 #include <unotools/accessiblestatesethelper.hxx>
39 #include <unotools/accessiblerelationsethelper.hxx>
40 #include <strings.hxx>
41 #include <sal/log.hxx>
42 #include <i18nlangtag/languagetag.hxx>
43 
44 #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
45 
46 #include <array>
47 
48 // class VCLXAccessibleToolBoxItem ------------------------------------------
49 
50 using namespace ::com::sun::star::accessibility;
51 using namespace ::com::sun::star::uno;
52 using namespace ::com::sun::star::beans;
53 using namespace ::com::sun::star::lang;
54 using namespace ::com::sun::star;
55 using namespace ::comphelper;
56 
57 
58 // Ctor() and Dtor()
59 
VCLXAccessibleToolBoxItem(ToolBox * _pToolBox,sal_Int32 _nPos)60 VCLXAccessibleToolBoxItem::VCLXAccessibleToolBoxItem( ToolBox* _pToolBox, sal_Int32 _nPos ) :
61     m_pToolBox      ( _pToolBox ),
62     m_nIndexInParent( _nPos ),
63     m_nRole         ( AccessibleRole::PUSH_BUTTON ),
64     m_nItemId       ( 0 ),
65     m_bHasFocus     ( false ),
66     m_bIsChecked    ( false ),
67     m_bIndeterminate( false )
68 
69 {
70     OSL_ENSURE( m_pToolBox, "invalid toolbox" );
71     m_nItemId = m_pToolBox->GetItemId( m_nIndexInParent );
72     m_sOldName = GetText();
73     m_bIsChecked = m_pToolBox->IsItemChecked( m_nItemId );
74     m_bIndeterminate = ( m_pToolBox->GetItemState( m_nItemId ) == TRISTATE_INDET );
75     ToolBoxItemType eType = m_pToolBox->GetItemType( m_nIndexInParent );
76     switch ( eType )
77     {
78         case ToolBoxItemType::BUTTON :
79         {
80             ToolBoxItemBits nBits = m_pToolBox->GetItemBits( m_nItemId );
81             if (
82                  (( nBits & ToolBoxItemBits::DROPDOWN ) == ToolBoxItemBits::DROPDOWN) ||
83                  (( nBits & ToolBoxItemBits::DROPDOWNONLY ) == ToolBoxItemBits::DROPDOWNONLY)
84                )
85                 m_nRole = AccessibleRole::BUTTON_DROPDOWN;
86             else if (
87                 ( ( nBits & ToolBoxItemBits::CHECKABLE ) == ToolBoxItemBits::CHECKABLE ) ||
88                 ( ( nBits & ToolBoxItemBits::RADIOCHECK ) == ToolBoxItemBits::RADIOCHECK ) ||
89                 ( ( nBits & ToolBoxItemBits::AUTOCHECK ) == ToolBoxItemBits::AUTOCHECK )
90                )
91                 m_nRole = AccessibleRole::TOGGLE_BUTTON;
92             else if ( m_pToolBox->GetItemWindow( m_nItemId ) )
93                 m_nRole = AccessibleRole::PANEL;
94             break;
95         }
96 
97         case ToolBoxItemType::SPACE :
98             m_nRole = AccessibleRole::FILLER;
99             break;
100 
101         case ToolBoxItemType::SEPARATOR :
102         case ToolBoxItemType::BREAK :
103             m_nRole = AccessibleRole::SEPARATOR;
104             break;
105 
106         default:
107         {
108             SAL_WARN( "accessibility", "unsupported toolbox itemtype" );
109         }
110     }
111 }
112 
~VCLXAccessibleToolBoxItem()113 VCLXAccessibleToolBoxItem::~VCLXAccessibleToolBoxItem()
114 {
115 }
116 
GetText() const117 OUString VCLXAccessibleToolBoxItem::GetText() const
118 {
119     OUString sRet;
120     // no text for separators and spaces
121     if ( m_pToolBox && m_nItemId > ToolBoxItemId(0) )
122     {
123         sRet = m_pToolBox->GetItemText( m_nItemId );
124         if (sRet.isEmpty())
125         {
126             sRet = m_pToolBox->GetQuickHelpText( m_nItemId );
127             if (sRet.isEmpty())
128             {
129                 vcl::Window* pItemWindow = m_pToolBox->GetItemWindow( m_nItemId );
130                 if ( m_nRole == AccessibleRole::PANEL && pItemWindow && pItemWindow->GetAccessible().is() &&
131                      pItemWindow->GetAccessible()->getAccessibleContext().is() )
132                 {
133                     OUString sWinText = pItemWindow->GetAccessible()->getAccessibleContext()->getAccessibleName();
134                     if (!sWinText.isEmpty())
135                         sRet = sWinText;
136                 }
137             }
138         }
139 
140     }
141     return sRet;
142 }
143 
SetFocus(bool _bFocus)144 void VCLXAccessibleToolBoxItem::SetFocus( bool _bFocus )
145 {
146     if ( m_bHasFocus != _bFocus )
147     {
148         Any aOldValue;
149         Any aNewValue;
150         if ( m_bHasFocus )
151             aOldValue <<= AccessibleStateType::FOCUSED;
152         else
153             aNewValue <<= AccessibleStateType::FOCUSED;
154         m_bHasFocus = _bFocus;
155         NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
156     }
157 }
158 
SetChecked(bool _bCheck)159 void VCLXAccessibleToolBoxItem::SetChecked( bool _bCheck )
160 {
161     if( m_nRole == AccessibleRole::PANEL)
162         return;
163     if ( m_bIsChecked != _bCheck )
164     {
165         Any aOldValue;
166         Any aNewValue;
167         if ( m_bIsChecked )
168             aOldValue <<= AccessibleStateType::CHECKED;
169         else
170             aNewValue <<= AccessibleStateType::CHECKED;
171         m_bIsChecked = _bCheck;
172         NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
173     }
174 }
175 
SetIndeterminate(bool _bIndeterminate)176 void VCLXAccessibleToolBoxItem::SetIndeterminate( bool _bIndeterminate )
177 {
178     if ( m_bIndeterminate != _bIndeterminate )
179     {
180         Any aOldValue, aNewValue;
181         if ( m_bIndeterminate )
182             aOldValue <<= AccessibleStateType::INDETERMINATE;
183         else
184             aNewValue <<= AccessibleStateType::INDETERMINATE;
185         m_bIndeterminate = _bIndeterminate;
186         NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
187     }
188 }
189 
NameChanged()190 void VCLXAccessibleToolBoxItem::NameChanged()
191 {
192     OUString sNewName = implGetText();
193     if ( sNewName != m_sOldName )
194     {
195         Any aOldValue, aNewValue;
196         aOldValue <<= m_sOldName;
197         // save new name as old name for next change
198         m_sOldName = sNewName;
199         aNewValue <<= m_sOldName;
200         NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
201     }
202 }
203 
SetChild(const Reference<XAccessible> & _xChild)204 void VCLXAccessibleToolBoxItem::SetChild( const Reference< XAccessible >& _xChild )
205 {
206     m_xChild = _xChild;
207 }
208 
NotifyChildEvent(const Reference<XAccessible> & _xChild,bool _bShow)209 void VCLXAccessibleToolBoxItem::NotifyChildEvent( const Reference< XAccessible >& _xChild, bool _bShow )
210 {
211     Any aOld = _bShow ? Any() : Any( _xChild );
212     Any aNew = _bShow ? Any( _xChild ) : Any();
213     NotifyAccessibleEvent( AccessibleEventId::CHILD, aOld, aNew );
214 }
215 
ToggleEnableState()216 void VCLXAccessibleToolBoxItem::ToggleEnableState()
217 {
218     std::array<Any, 2> aOldValue, aNewValue;
219     if ( m_pToolBox->IsItemEnabled( m_nItemId ) )
220     {
221         aNewValue[0] <<= AccessibleStateType::SENSITIVE;
222         aNewValue[1] <<= AccessibleStateType::ENABLED;
223     }
224     else
225     {
226         aOldValue[0] <<= AccessibleStateType::ENABLED;
227         aOldValue[1] <<= AccessibleStateType::SENSITIVE;
228     }
229 
230     NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue[0], aNewValue[0] );
231     NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue[1], aNewValue[1] );
232 }
233 
implGetBounds()234 awt::Rectangle VCLXAccessibleToolBoxItem::implGetBounds(  )
235 {
236     awt::Rectangle aRect;
237     if ( m_pToolBox )
238         aRect = AWTRectangle( m_pToolBox->GetItemPosRect( m_nIndexInParent ) );
239 
240     return aRect;
241 }
242 
implGetText()243 OUString VCLXAccessibleToolBoxItem::implGetText()
244 {
245     return GetText();
246 }
247 
implGetLocale()248 Locale VCLXAccessibleToolBoxItem::implGetLocale()
249 {
250     return Application::GetSettings().GetUILanguageTag().getLocale();
251 }
252 
implGetSelection(sal_Int32 & nStartIndex,sal_Int32 & nEndIndex)253 void VCLXAccessibleToolBoxItem::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
254 {
255     nStartIndex = 0;
256     nEndIndex = 0;
257 }
258 
259 // XInterface
260 
IMPLEMENT_FORWARD_REFCOUNT(VCLXAccessibleToolBoxItem,AccessibleTextHelper_BASE)261 IMPLEMENT_FORWARD_REFCOUNT( VCLXAccessibleToolBoxItem, AccessibleTextHelper_BASE )
262 Any SAL_CALL VCLXAccessibleToolBoxItem::queryInterface( const Type& _rType )
263 {
264     // #i33611# - toolbox buttons without text don't support XAccessibleText
265     if ( _rType == cppu::UnoType<XAccessibleText>::get()
266         && ( !m_pToolBox || m_pToolBox->GetButtonType() == ButtonType::SYMBOLONLY ) )
267         return Any();
268 
269     css::uno::Any aReturn = AccessibleTextHelper_BASE::queryInterface( _rType );
270     if ( !aReturn.hasValue() )
271         aReturn = VCLXAccessibleToolBoxItem_BASE::queryInterface( _rType );
272     return aReturn;
273 }
274 
275 // XTypeProvider
276 
IMPLEMENT_FORWARD_XTYPEPROVIDER2(VCLXAccessibleToolBoxItem,AccessibleTextHelper_BASE,VCLXAccessibleToolBoxItem_BASE)277 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleToolBoxItem, AccessibleTextHelper_BASE, VCLXAccessibleToolBoxItem_BASE )
278 
279 // XComponent
280 
281 void SAL_CALL VCLXAccessibleToolBoxItem::disposing()
282 {
283     AccessibleTextHelper_BASE::disposing();
284     m_pToolBox = nullptr;
285 }
286 
287 // XServiceInfo
288 
getImplementationName()289 OUString VCLXAccessibleToolBoxItem::getImplementationName()
290 {
291     return "com.sun.star.comp.toolkit.AccessibleToolBoxItem";
292 }
293 
supportsService(const OUString & rServiceName)294 sal_Bool VCLXAccessibleToolBoxItem::supportsService( const OUString& rServiceName )
295 {
296     return cppu::supportsService(this, rServiceName);
297 }
298 
getSupportedServiceNames()299 Sequence< OUString > VCLXAccessibleToolBoxItem::getSupportedServiceNames()
300 {
301     return {"com.sun.star.accessibility.AccessibleContext",
302             "com.sun.star.accessibility.AccessibleComponent",
303             "com.sun.star.accessibility.AccessibleExtendedComponent",
304             "com.sun.star.accessibility.AccessibleToolBoxItem"};
305 }
306 
307 // XAccessible
308 
getAccessibleContext()309 Reference< XAccessibleContext > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleContext(  )
310 {
311     return this;
312 }
313 
314 // XAccessibleContext
315 
getAccessibleChildCount()316 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleChildCount(  )
317 {
318     OContextEntryGuard aGuard( this );
319 
320     return m_xChild.is() ? 1 : 0;
321 }
322 
getAccessibleChild(sal_Int32 i)323 Reference< XAccessible > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleChild( sal_Int32 i )
324 {
325     OContextEntryGuard aGuard( this );
326 
327     // no child -> so index is out of bounds
328     if ( !m_xChild.is() || i != 0 )
329         throw IndexOutOfBoundsException();
330 
331     return m_xChild;
332 }
333 
getAccessibleParent()334 Reference< XAccessible > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleParent(  )
335 {
336     OContextEntryGuard aGuard( this );
337 
338     return m_pToolBox->GetAccessible();
339 }
340 
getAccessibleIndexInParent()341 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleIndexInParent(  )
342 {
343     OContextEntryGuard aGuard( this );
344 
345     return m_nIndexInParent;
346 }
347 
getAccessibleRole()348 sal_Int16 SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleRole(  )
349 {
350     OContextEntryGuard aGuard( this );
351 
352     return m_nRole;
353 }
354 
getAccessibleDescription()355 OUString SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleDescription(  )
356 {
357     OExternalLockGuard aGuard( this );
358 
359     if (m_nRole == AccessibleRole::PANEL && m_xChild.is())
360     {
361         return AccResId( RID_STR_ACC_PANEL_DESCRIPTION );
362     }
363     else
364     {
365         OUString sDescription;
366         if ( m_pToolBox )
367             sDescription = m_pToolBox->GetHelpText( m_nItemId );
368         return sDescription;
369     }
370 }
371 
getAccessibleName()372 OUString SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleName(  )
373 {
374     OExternalLockGuard aGuard( this );
375 
376     // entry text == accessible name
377     return GetText();
378 }
379 
getAccessibleRelationSet()380 Reference< XAccessibleRelationSet > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleRelationSet(  )
381 {
382     OContextEntryGuard aGuard( this );
383 
384     return new utl::AccessibleRelationSetHelper;
385 }
386 
getAccessibleStateSet()387 Reference< XAccessibleStateSet > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleStateSet(  )
388 {
389     OExternalLockGuard aGuard( this );
390 
391     rtl::Reference<utl::AccessibleStateSetHelper> pStateSetHelper = new utl::AccessibleStateSetHelper;
392 
393     if ( m_pToolBox && !rBHelper.bDisposed && !rBHelper.bInDispose )
394     {
395         pStateSetHelper->AddState( AccessibleStateType::FOCUSABLE );
396         if ( m_bIsChecked && m_nRole != AccessibleRole::PANEL )
397             pStateSetHelper->AddState( AccessibleStateType::CHECKED );
398         if ( m_bIndeterminate )
399             pStateSetHelper->AddState( AccessibleStateType::INDETERMINATE );
400         if ( m_pToolBox->IsEnabled() && m_pToolBox->IsItemEnabled( m_nItemId ) )
401         {
402             pStateSetHelper->AddState( AccessibleStateType::ENABLED );
403             pStateSetHelper->AddState( AccessibleStateType::SENSITIVE );
404         }
405         if ( m_pToolBox->IsItemVisible( m_nItemId ) )
406             pStateSetHelper->AddState( AccessibleStateType::VISIBLE );
407         if ( m_pToolBox->IsItemReallyVisible( m_nItemId ) )
408             pStateSetHelper->AddState( AccessibleStateType::SHOWING );
409         if ( m_bHasFocus )
410             pStateSetHelper->AddState( AccessibleStateType::FOCUSED );
411     }
412     else
413         pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
414 
415     return pStateSetHelper;
416 }
417 
418 // XAccessibleText
419 
getText()420 OUString VCLXAccessibleToolBoxItem::getText()
421 {
422     OExternalLockGuard aGuard( this );
423 
424     return GetText();
425 }
426 
getCharacterCount()427 sal_Int32 VCLXAccessibleToolBoxItem::getCharacterCount()
428 {
429     return GetText().getLength();
430 }
431 
getCharacter(sal_Int32 nIndex)432 sal_Unicode VCLXAccessibleToolBoxItem::getCharacter( sal_Int32 nIndex )
433 {
434      OExternalLockGuard aGuard( this );
435 
436      return OCommonAccessibleText::implGetCharacter( GetText(), nIndex );
437 }
438 
getTextRange(sal_Int32 nStartIndex,sal_Int32 nEndIndex)439 OUString VCLXAccessibleToolBoxItem::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
440 {
441      OExternalLockGuard aGuard( this );
442 
443      return OCommonAccessibleText::implGetTextRange( GetText(), nStartIndex, nEndIndex );
444 }
445 
getCaretPosition()446 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getCaretPosition()
447 {
448     return -1;
449 }
450 
setCaretPosition(sal_Int32 nIndex)451 sal_Bool SAL_CALL VCLXAccessibleToolBoxItem::setCaretPosition( sal_Int32 nIndex )
452 {
453     OExternalLockGuard aGuard( this );
454 
455     if ( !implIsValidRange( nIndex, nIndex, GetText().getLength() ) )
456         throw IndexOutOfBoundsException();
457 
458     return false;
459 }
460 
getCharacterAttributes(sal_Int32 nIndex,const Sequence<OUString> &)461 Sequence< PropertyValue > SAL_CALL VCLXAccessibleToolBoxItem::getCharacterAttributes( sal_Int32 nIndex, const Sequence< OUString >& )
462 {
463     OExternalLockGuard aGuard( this );
464 
465     OUString sText( implGetText() );
466 
467     if ( !implIsValidIndex( nIndex, sText.getLength() ) )
468         throw IndexOutOfBoundsException();
469 
470     return Sequence< PropertyValue >();
471 }
472 
getCharacterBounds(sal_Int32 nIndex)473 awt::Rectangle SAL_CALL VCLXAccessibleToolBoxItem::getCharacterBounds( sal_Int32 nIndex )
474 {
475     OExternalLockGuard aGuard( this );
476 
477     OUString sText( implGetText() );
478 
479     if ( !implIsValidIndex( nIndex, sText.getLength() ) )
480         throw IndexOutOfBoundsException();
481 
482     awt::Rectangle aBounds( 0, 0, 0, 0 );
483     if ( m_pToolBox && m_pToolBox->GetButtonType() != ButtonType::SYMBOLONLY ) // symbol buttons have no character bounds
484     {
485         tools::Rectangle aCharRect = m_pToolBox->GetCharacterBounds( m_nItemId, nIndex );
486         tools::Rectangle aItemRect = m_pToolBox->GetItemRect( m_nItemId );
487         aCharRect.Move( -aItemRect.Left(), -aItemRect.Top() );
488         aBounds = AWTRectangle( aCharRect );
489     }
490 
491     return aBounds;
492 }
493 
getIndexAtPoint(const awt::Point & aPoint)494 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getIndexAtPoint( const awt::Point& aPoint )
495 {
496     OExternalLockGuard aGuard( this );
497 
498     sal_Int32 nIndex = -1;
499     if ( m_pToolBox && m_pToolBox->GetButtonType() != ButtonType::SYMBOLONLY ) // symbol buttons have no character bounds
500     {
501         ToolBoxItemId nItemId;
502         tools::Rectangle aItemRect = m_pToolBox->GetItemRect( m_nItemId );
503         Point aPnt( VCLPoint( aPoint ) );
504         aPnt += aItemRect.TopLeft();
505         sal_Int32 nIdx = m_pToolBox->GetIndexForPoint( aPnt, nItemId );
506         if ( nIdx != -1 && nItemId == m_nItemId )
507             nIndex = nIdx;
508     }
509 
510     return nIndex;
511 }
512 
setSelection(sal_Int32 nStartIndex,sal_Int32 nEndIndex)513 sal_Bool SAL_CALL VCLXAccessibleToolBoxItem::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
514 {
515     OExternalLockGuard aGuard( this );
516 
517     if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
518         throw IndexOutOfBoundsException();
519 
520     return false;
521 }
522 
copyText(sal_Int32 nStartIndex,sal_Int32 nEndIndex)523 sal_Bool SAL_CALL VCLXAccessibleToolBoxItem::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
524 {
525     OExternalLockGuard aGuard( this );
526 
527     if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
528         throw IndexOutOfBoundsException();
529 
530     bool bReturn = false;
531 
532     if ( m_pToolBox )
533     {
534         Reference< datatransfer::clipboard::XClipboard > xClipboard = m_pToolBox->GetClipboard();
535         if ( xClipboard.is() )
536         {
537             OUString sText( OCommonAccessibleText::implGetTextRange( implGetText(), nStartIndex, nEndIndex ) );
538 
539             rtl::Reference<vcl::unohelper::TextDataObject> pDataObj = new vcl::unohelper::TextDataObject( sText );
540 
541             SolarMutexReleaser aReleaser;
542             xClipboard->setContents( pDataObj, nullptr );
543 
544             Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
545             if( xFlushableClipboard.is() )
546                 xFlushableClipboard->flushClipboard();
547 
548             bReturn = true;
549         }
550     }
551 
552     return bReturn;
553 }
554 
scrollSubstringTo(sal_Int32,sal_Int32,AccessibleScrollType)555 sal_Bool VCLXAccessibleToolBoxItem::scrollSubstringTo( sal_Int32, sal_Int32, AccessibleScrollType )
556 {
557     return false;
558 }
559 
560 // XAccessibleComponent
561 
getAccessibleAtPoint(const awt::Point &)562 Reference< XAccessible > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleAtPoint( const awt::Point& )
563 {
564     return Reference< XAccessible >();
565 }
566 
grabFocus()567 void SAL_CALL VCLXAccessibleToolBoxItem::grabFocus(  )
568 {
569     Reference< XAccessible > xParent(getAccessibleParent());
570 
571     if( xParent.is() )
572     {
573         Reference< XAccessibleSelection > rxAccessibleSelection(xParent->getAccessibleContext(), UNO_QUERY);
574 
575         if ( rxAccessibleSelection.is() )
576         {
577             rxAccessibleSelection -> selectAccessibleChild ( getAccessibleIndexInParent() );
578         }
579     }
580 }
581 
getForeground()582 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getForeground(  )
583 {
584     OExternalLockGuard aGuard( this );
585 
586     Color nColor;
587     if ( m_pToolBox )
588        nColor = m_pToolBox->GetControlForeground();
589 
590     return sal_Int32(nColor);
591 }
592 
getBackground()593 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getBackground(  )
594 {
595     OExternalLockGuard aGuard( this );
596 
597     Color nColor;
598     if ( m_pToolBox )
599        nColor = m_pToolBox->GetControlBackground();
600 
601     return sal_Int32(nColor);
602 }
603 
604 // XAccessibleExtendedComponent
getFont()605 Reference< awt::XFont > SAL_CALL VCLXAccessibleToolBoxItem::getFont(    )
606 {
607     return uno::Reference< awt::XFont >();
608 }
609 
getTitledBorderText()610 OUString SAL_CALL VCLXAccessibleToolBoxItem::getTitledBorderText(  )
611 {
612     OExternalLockGuard aGuard( this );
613 
614     OUString sRet;
615     if ( m_pToolBox )
616         sRet = m_pToolBox->GetItemText( m_nItemId );
617 
618     return sRet;
619 }
620 
getToolTipText()621 OUString SAL_CALL VCLXAccessibleToolBoxItem::getToolTipText(  )
622 {
623     OExternalLockGuard aGuard( this );
624 
625     OUString sRet;
626     if ( m_pToolBox )
627     {
628         if ( Help::IsExtHelpEnabled() )
629             sRet = m_pToolBox->GetHelpText( m_nItemId );
630         else
631             sRet = m_pToolBox->GetQuickHelpText( m_nItemId );
632         if ( sRet.isEmpty() )
633             // no help text set, so use item text
634             sRet = m_pToolBox->GetItemText( m_nItemId );
635     }
636     return sRet;
637 }
638 
639 // XAccessibleAction
640 
getAccessibleActionCount()641 sal_Int32 VCLXAccessibleToolBoxItem::getAccessibleActionCount( )
642 {
643     // only one action -> "Click"
644     return 1;
645 }
646 
doAccessibleAction(sal_Int32 nIndex)647 sal_Bool VCLXAccessibleToolBoxItem::doAccessibleAction ( sal_Int32 nIndex )
648 {
649     OExternalLockGuard aGuard( this );
650 
651     if ( nIndex != 0 )
652         throw IndexOutOfBoundsException();
653 
654     if ( m_pToolBox )
655         m_pToolBox->TriggerItem( m_nItemId );
656 
657     return true;
658 }
659 
getAccessibleActionDescription(sal_Int32 nIndex)660 OUString VCLXAccessibleToolBoxItem::getAccessibleActionDescription ( sal_Int32 nIndex )
661 {
662     OExternalLockGuard aGuard( this );
663 
664     if ( nIndex != 0 )
665         throw IndexOutOfBoundsException();
666 
667     return RID_STR_ACC_ACTION_CLICK;
668 }
669 
getAccessibleActionKeyBinding(sal_Int32 nIndex)670 Reference< XAccessibleKeyBinding > VCLXAccessibleToolBoxItem::getAccessibleActionKeyBinding( sal_Int32 nIndex )
671 {
672     OContextEntryGuard aGuard( this );
673 
674     if ( nIndex != 0 )
675         throw IndexOutOfBoundsException();
676 
677     return Reference< XAccessibleKeyBinding >();
678 }
679 
680 // XAccessibleValue
681 
getCurrentValue()682 Any VCLXAccessibleToolBoxItem::getCurrentValue(  )
683 {
684     OExternalLockGuard aGuard( this );
685 
686     Any aValue;
687     if ( m_pToolBox )
688         aValue <<= static_cast<sal_Int32>(m_pToolBox->IsItemChecked( m_nItemId ));
689 
690     if( m_nRole == AccessibleRole::PANEL )
691         aValue <<= sal_Int32(0);
692     return aValue;
693 }
694 
setCurrentValue(const Any & aNumber)695 sal_Bool VCLXAccessibleToolBoxItem::setCurrentValue( const Any& aNumber )
696 {
697     OExternalLockGuard aGuard( this );
698 
699     bool bReturn = false;
700 
701     if ( m_pToolBox )
702     {
703         sal_Int32 nValue = 0;
704         OSL_VERIFY( aNumber >>= nValue );
705 
706         if ( nValue < 0 )
707             nValue = 0;
708         else if ( nValue > 1 )
709             nValue = 1;
710 
711         m_pToolBox->CheckItem( m_nItemId, nValue == 1 );
712         bReturn = true;
713     }
714 
715     return bReturn;
716 }
717 
getMaximumValue()718 Any VCLXAccessibleToolBoxItem::getMaximumValue(  )
719 {
720     return Any(sal_Int32(1));
721 }
722 
getMinimumValue()723 Any VCLXAccessibleToolBoxItem::getMinimumValue(  )
724 {
725     return Any(sal_Int32(0));
726 }
727 
728 
729 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
730