Coverage Report

Created: 2026-03-31 11:00

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