Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/accessibility/vclxaccessiblescrollbar.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/vclxaccessiblescrollbar.hxx>
21
22
#include <svdata.hxx>
23
#include <strings.hrc>
24
25
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
26
#include <com/sun/star/accessibility/AccessibleEventId.hpp>
27
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
28
#include <comphelper/accessiblecontexthelper.hxx>
29
#include <vcl/accessibility/strings.hxx>
30
#include <vcl/vclevent.hxx>
31
32
using namespace ::com::sun::star;
33
using namespace ::com::sun::star::uno;
34
using namespace ::com::sun::star::awt;
35
using namespace ::com::sun::star::lang;
36
using namespace ::com::sun::star::accessibility;
37
using namespace ::comphelper;
38
39
40
// VCLXAccessibleScrollBar
41
42
43
void VCLXAccessibleScrollBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
44
0
{
45
0
    switch ( rVclWindowEvent.GetId() )
46
0
    {
47
0
        case VclEventId::ScrollbarScroll:
48
0
        {
49
0
            NotifyAccessibleEvent( AccessibleEventId::VALUE_CHANGED, Any(), Any() );
50
0
        }
51
0
        break;
52
0
        default:
53
0
            VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
54
0
   }
55
0
}
56
57
58
void VCLXAccessibleScrollBar::FillAccessibleStateSet( sal_Int64& rStateSet )
59
0
{
60
0
    VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet );
61
62
    // IA2 CWS: scroll bar should not have FOCUSABLE state.
63
    // rStateSet.AddState( AccessibleStateType::FOCUSABLE );
64
0
    rStateSet |= GetOrientationState();
65
0
}
66
67
68
// XServiceInfo
69
70
71
OUString VCLXAccessibleScrollBar::getImplementationName()
72
0
{
73
0
    return u"com.sun.star.comp.toolkit.AccessibleScrollBar"_ustr;
74
0
}
75
76
77
Sequence< OUString > VCLXAccessibleScrollBar::getSupportedServiceNames()
78
0
{
79
0
    return { u"com.sun.star.awt.AccessibleScrollBar"_ustr };
80
0
}
81
82
// XAccessibleAction
83
84
constexpr sal_Int32 ACCESSIBLE_ACTION_COUNT=4;
85
86
sal_Int32 VCLXAccessibleScrollBar::getAccessibleActionCount( )
87
0
{
88
0
    OExternalLockGuard aGuard( this );
89
90
0
    return ACCESSIBLE_ACTION_COUNT;
91
0
}
92
93
94
sal_Bool VCLXAccessibleScrollBar::doAccessibleAction ( sal_Int32 nIndex )
95
0
{
96
0
    OExternalLockGuard aGuard( this );
97
98
0
    if ( nIndex < 0 || nIndex >= ACCESSIBLE_ACTION_COUNT )
99
0
        throw IndexOutOfBoundsException();
100
101
0
    bool bReturn = false;
102
0
    VclPtr< ScrollBar > pScrollBar = GetAs< ScrollBar >();
103
0
    if ( pScrollBar )
104
0
    {
105
0
        ScrollType eScrollType;
106
0
        switch ( nIndex )
107
0
        {
108
0
            case 0:     eScrollType = ScrollType::LineUp;    break;
109
0
            case 1:     eScrollType = ScrollType::LineDown;  break;
110
0
            case 2:     eScrollType = ScrollType::PageUp;    break;
111
0
            case 3:     eScrollType = ScrollType::PageDown;  break;
112
0
            default:    eScrollType = ScrollType::DontKnow;  break;
113
0
        }
114
0
        if ( pScrollBar->DoScrollAction( eScrollType ) )
115
0
            bReturn = true;
116
0
    }
117
118
0
    return bReturn;
119
0
}
120
121
122
OUString VCLXAccessibleScrollBar::getAccessibleActionDescription ( sal_Int32 nIndex )
123
0
{
124
0
    OExternalLockGuard aGuard( this );
125
126
0
    if ( nIndex < 0 || nIndex >= ACCESSIBLE_ACTION_COUNT )
127
0
        throw IndexOutOfBoundsException();
128
129
0
    OUString sDescription;
130
131
0
    switch ( nIndex )
132
0
    {
133
0
        case 0:     sDescription = RID_STR_ACC_ACTION_DECLINE;      break;
134
0
        case 1:     sDescription = RID_STR_ACC_ACTION_INCLINE;      break;
135
0
        case 2:     sDescription = RID_STR_ACC_ACTION_DECBLOCK;     break;
136
0
        case 3:     sDescription = RID_STR_ACC_ACTION_INCBLOCK;     break;
137
0
        default:                                                              break;
138
0
    }
139
140
0
    return sDescription;
141
0
}
142
143
144
Reference< XAccessibleKeyBinding > VCLXAccessibleScrollBar::getAccessibleActionKeyBinding( sal_Int32 nIndex )
145
0
{
146
0
    OExternalLockGuard aGuard( this );
147
148
0
    if ( nIndex < 0 || nIndex >= ACCESSIBLE_ACTION_COUNT )
149
0
        throw IndexOutOfBoundsException();
150
151
0
    return Reference< XAccessibleKeyBinding >();
152
0
}
153
154
155
// XAccessibleValue
156
157
158
Any VCLXAccessibleScrollBar::getCurrentValue(  )
159
0
{
160
0
    OExternalLockGuard aGuard( this );
161
162
0
    Any aValue;
163
164
0
    VclPtr<ScrollBar> pScrollBar = GetAs<ScrollBar>();
165
0
    if (pScrollBar)
166
0
        aValue <<= sal_Int32(pScrollBar->GetThumbPos());
167
168
0
    return aValue;
169
0
}
170
171
172
sal_Bool VCLXAccessibleScrollBar::setCurrentValue( const Any& aNumber )
173
0
{
174
0
    OExternalLockGuard aGuard( this );
175
176
0
    bool bReturn = false;
177
178
0
    VclPtr<ScrollBar> pScrollBar = GetAs<ScrollBar>();
179
0
    if (pScrollBar)
180
0
    {
181
0
        sal_Int32 nValue = 0;
182
0
        OSL_VERIFY( aNumber >>= nValue );
183
0
        sal_Int32 nValueMax = pScrollBar->GetRangeMax();
184
185
0
        if (nValue < 0)
186
0
            nValue = 0;
187
0
        else if ( nValue > nValueMax )
188
0
            nValue = nValueMax;
189
190
0
        pScrollBar->DoScroll(nValue);
191
0
        bReturn = true;
192
0
    }
193
194
0
    return bReturn;
195
0
}
196
197
198
Any VCLXAccessibleScrollBar::getMaximumValue(  )
199
0
{
200
0
    OExternalLockGuard aGuard( this );
201
202
0
    Any aValue;
203
204
0
    VclPtr<ScrollBar> pScrollBar = GetAs<ScrollBar>();
205
0
    if (pScrollBar)
206
0
        aValue <<= sal_Int32(pScrollBar->GetRangeMax());
207
208
0
    return aValue;
209
0
}
210
211
212
Any VCLXAccessibleScrollBar::getMinimumValue(  )
213
0
{
214
0
    OExternalLockGuard aGuard( this );
215
216
0
    Any aValue;
217
0
    aValue <<= sal_Int32(0);
218
219
0
    return aValue;
220
0
}
221
222
Any VCLXAccessibleScrollBar::getMinimumIncrement(  )
223
0
{
224
0
    OExternalLockGuard aGuard( this );
225
226
0
    return Any();
227
0
}
228
229
230
OUString VCLXAccessibleScrollBar::getAccessibleName(  )
231
0
{
232
0
    OExternalLockGuard aGuard( this );
233
234
0
    if (VCLXAccessibleScrollBar::GetOrientationState() == AccessibleStateType::HORIZONTAL)
235
0
        return VclResId(RID_STR_ACC_SCROLLBAR_NAME_HORIZONTAL);
236
237
0
    return VclResId(RID_STR_ACC_SCROLLBAR_NAME_VERTICAL);
238
0
}
239
240
sal_Int64 VCLXAccessibleScrollBar::GetOrientationState() const
241
0
{
242
0
    VclPtr<ScrollBar> pScrollBar = GetAs<ScrollBar>();
243
0
    if (!pScrollBar || pScrollBar->GetStyle() & WB_HORZ)
244
0
        return AccessibleStateType::HORIZONTAL;
245
246
0
    return AccessibleStateType::VERTICAL;
247
0
}
248
249
250
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */