Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/accessibility/vclxaccessibleradiobutton.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/vclxaccessibleradiobutton.hxx>
21
22
#include <unotools/accessiblerelationsethelper.hxx>
23
#include <comphelper/accessiblecontexthelper.hxx>
24
#include <comphelper/accessiblekeybindinghelper.hxx>
25
#include <comphelper/sequence.hxx>
26
#include <com/sun/star/awt/KeyModifier.hpp>
27
#include <com/sun/star/accessibility/AccessibleRelationType.hpp>
28
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
29
#include <com/sun/star/accessibility/AccessibleEventId.hpp>
30
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
31
#include <vcl/accessibility/strings.hxx>
32
#include <vcl/window.hxx>
33
#include <vcl/event.hxx>
34
#include <vcl/vclevent.hxx>
35
36
using namespace ::com::sun::star;
37
using namespace ::com::sun::star::uno;
38
using namespace ::com::sun::star::lang;
39
using namespace ::com::sun::star::accessibility;
40
using namespace ::comphelper;
41
42
43
// VCLXAccessibleRadioButton
44
45
46
void VCLXAccessibleRadioButton::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
47
0
{
48
0
    switch ( rVclWindowEvent.GetId() )
49
0
    {
50
0
        case VclEventId::RadiobuttonToggle:
51
0
        {
52
0
            Any aOldValue;
53
0
            Any aNewValue;
54
55
0
            VclPtr<RadioButton> pRadioButton = GetAs<RadioButton>();
56
0
            if (pRadioButton && pRadioButton->IsChecked())
57
0
                aNewValue <<= AccessibleStateType::CHECKED;
58
0
            else
59
0
                aOldValue <<= AccessibleStateType::CHECKED;
60
61
0
            NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
62
0
        }
63
0
        break;
64
0
        default:
65
0
            VCLXAccessibleTextComponent::ProcessWindowEvent( rVclWindowEvent );
66
0
   }
67
0
}
68
69
70
void VCLXAccessibleRadioButton::FillAccessibleRelationSet( utl::AccessibleRelationSetHelper& rRelationSet )
71
0
{
72
0
    VCLXAccessibleTextComponent::FillAccessibleRelationSet( rRelationSet );
73
74
0
    VclPtr<RadioButton> pRadioButton = GetAs<RadioButton>();
75
0
    if ( !pRadioButton )
76
0
        return;
77
78
0
    std::vector< VclPtr<RadioButton> > aGroup(pRadioButton->GetRadioButtonGroup());
79
0
    if (!aGroup.empty())
80
0
    {
81
0
        std::vector<Reference<css::accessibility::XAccessible>> aVec;
82
0
        aVec.reserve(aGroup.size());
83
0
        std::transform(aGroup.begin(), aGroup.end(), std::back_inserter(aVec),
84
0
            [](const VclPtr<RadioButton>& rxItem) { return rxItem->GetAccessible(); });
85
0
        rRelationSet.AddRelation(AccessibleRelation(AccessibleRelationType_MEMBER_OF,
86
0
                                                    comphelper::containerToSequence(aVec)));
87
0
    }
88
0
}
89
90
91
void VCLXAccessibleRadioButton::FillAccessibleStateSet( sal_Int64& rStateSet )
92
0
{
93
0
    VCLXAccessibleTextComponent::FillAccessibleStateSet( rStateSet );
94
95
0
    VclPtr<RadioButton> pRadioButton = GetAs<RadioButton>();
96
0
    if (pRadioButton)
97
0
    {
98
0
        rStateSet |= AccessibleStateType::CHECKABLE;
99
0
        rStateSet |= AccessibleStateType::FOCUSABLE;
100
0
        if (pRadioButton->IsChecked())
101
0
            rStateSet |= AccessibleStateType::CHECKED;
102
0
    }
103
0
}
104
105
// XAccessibleAction
106
107
108
sal_Int32 VCLXAccessibleRadioButton::getAccessibleActionCount( )
109
0
{
110
0
    OExternalLockGuard aGuard( this );
111
112
0
    return 1;
113
0
}
114
115
116
sal_Bool VCLXAccessibleRadioButton::doAccessibleAction ( sal_Int32 nIndex )
117
0
{
118
0
    OExternalLockGuard aGuard( this );
119
120
0
    if ( nIndex != 0 )
121
0
        throw IndexOutOfBoundsException();
122
123
0
    VclPtr<RadioButton> pRadioButton = GetAs<RadioButton>();
124
0
    if (pRadioButton && !pRadioButton->IsChecked())
125
0
        pRadioButton->Check(true);
126
127
0
    return true;
128
0
}
129
130
OUString VCLXAccessibleRadioButton::getAccessibleActionDescription ( sal_Int32 nIndex )
131
0
{
132
0
    OExternalLockGuard aGuard( this );
133
134
0
    if ( nIndex != 0 )
135
0
        throw IndexOutOfBoundsException();
136
137
0
    return RID_STR_ACC_ACTION_SELECT;
138
0
}
139
140
Reference< XAccessibleKeyBinding > VCLXAccessibleRadioButton::getAccessibleActionKeyBinding( sal_Int32 nIndex )
141
0
{
142
0
    OExternalLockGuard aGuard( this );
143
144
0
    if ( nIndex != 0 )
145
0
        throw IndexOutOfBoundsException();
146
147
0
    rtl::Reference<OAccessibleKeyBindingHelper> pKeyBindingHelper = new OAccessibleKeyBindingHelper();
148
149
0
    VclPtr<vcl::Window> pWindow = GetWindow();
150
0
    if ( pWindow )
151
0
    {
152
0
        KeyEvent aKeyEvent = pWindow->GetActivationKey();
153
0
        vcl::KeyCode aKeyCode = aKeyEvent.GetKeyCode();
154
0
        if ( aKeyCode.GetCode() != 0 )
155
0
        {
156
0
            awt::KeyStroke aKeyStroke;
157
0
            aKeyStroke.Modifiers = 0;
158
0
            if ( aKeyCode.IsShift() )
159
0
                aKeyStroke.Modifiers |= awt::KeyModifier::SHIFT;
160
0
            if ( aKeyCode.IsMod1() )
161
0
                aKeyStroke.Modifiers |= awt::KeyModifier::MOD1;
162
0
            if ( aKeyCode.IsMod2() )
163
0
                aKeyStroke.Modifiers |= awt::KeyModifier::MOD2;
164
0
            if ( aKeyCode.IsMod3() )
165
0
                aKeyStroke.Modifiers |= awt::KeyModifier::MOD3;
166
0
            aKeyStroke.KeyCode = aKeyCode.GetCode();
167
0
            aKeyStroke.KeyChar = aKeyEvent.GetCharCode();
168
0
            aKeyStroke.KeyFunc = static_cast< sal_Int16 >( aKeyCode.GetFunction() );
169
0
            pKeyBindingHelper->AddKeyBinding( aKeyStroke );
170
0
        }
171
0
    }
172
173
0
    return pKeyBindingHelper;
174
0
}
175
176
177
// XAccessibleValue
178
179
180
Any VCLXAccessibleRadioButton::getCurrentValue(  )
181
0
{
182
0
    OExternalLockGuard aGuard( this );
183
184
0
    Any aValue;
185
186
0
    VclPtr<RadioButton> pRadioButton = GetAs<RadioButton>();
187
0
    if (pRadioButton)
188
0
        aValue <<= static_cast<sal_Int32>(pRadioButton->IsChecked() ? 1 : 0);
189
190
0
    return aValue;
191
0
}
192
193
194
sal_Bool VCLXAccessibleRadioButton::setCurrentValue( const Any& aNumber )
195
0
{
196
0
    OExternalLockGuard aGuard( this );
197
198
0
    bool bReturn = false;
199
200
0
    VclPtr<RadioButton> pRadioButton = GetAs<RadioButton>();
201
0
    if (pRadioButton)
202
0
    {
203
0
        sal_Int32 nValue = 0;
204
0
        OSL_VERIFY( aNumber >>= nValue );
205
206
0
        if ( nValue < 0 )
207
0
            nValue = 0;
208
0
        else if ( nValue > 1 )
209
0
            nValue = 1;
210
211
0
        pRadioButton->Check(nValue == 1);
212
0
        bReturn = true;
213
0
    }
214
215
0
    return bReturn;
216
0
}
217
218
219
Any VCLXAccessibleRadioButton::getMaximumValue(  )
220
0
{
221
0
    OExternalLockGuard aGuard( this );
222
223
0
    Any aValue;
224
0
    aValue <<= sal_Int32(1);
225
226
0
    return aValue;
227
0
}
228
229
230
Any VCLXAccessibleRadioButton::getMinimumValue(  )
231
0
{
232
0
    OExternalLockGuard aGuard( this );
233
234
0
    Any aValue;
235
0
    aValue <<= sal_Int32(0);
236
237
0
    return aValue;
238
0
}
239
240
Any VCLXAccessibleRadioButton::getMinimumIncrement(  )
241
0
{
242
0
    OExternalLockGuard aGuard( this );
243
244
0
    Any aValue;
245
0
    aValue <<= sal_Int32(1);
246
247
0
    return aValue;
248
0
}
249
250
251
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */