Coverage Report

Created: 2026-10-14 09:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/accessibility/vclxaccessiblestatusbaritem.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/vclxaccessiblestatusbaritem.hxx>
21
22
#include <com/sun/star/accessibility/AccessibleEventId.hpp>
23
#include <com/sun/star/accessibility/AccessibleRole.hpp>
24
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
25
#include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
26
#include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
27
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
28
#include <comphelper/accessiblecontexthelper.hxx>
29
#include <cppuhelper/supportsservice.hxx>
30
#include <unotools/accessiblerelationsethelper.hxx>
31
#include <vcl/accessibility/characterattributeshelper.hxx>
32
#include <vcl/ctrl.hxx>
33
#include <vcl/svapp.hxx>
34
#include <vcl/unohelp.hxx>
35
#include <vcl/unohelp2.hxx>
36
#include <vcl/status.hxx>
37
#include <vcl/settings.hxx>
38
#include <i18nlangtag/languagetag.hxx>
39
40
using namespace ::com::sun::star::accessibility;
41
using namespace ::com::sun::star::uno;
42
using namespace ::com::sun::star::lang;
43
using namespace ::com::sun::star::beans;
44
using namespace ::com::sun::star;
45
using namespace ::comphelper;
46
47
48
49
50
VCLXAccessibleStatusBarItem::VCLXAccessibleStatusBarItem( StatusBar* pStatusBar, sal_uInt16 nItemId )
51
0
    :m_pStatusBar( pStatusBar )
52
0
    ,m_nItemId( nItemId )
53
0
{
54
55
0
    m_sItemName = GetItemName();
56
0
    m_sItemText = GetItemText();
57
0
    m_bShowing  = IsShowing();
58
0
}
59
60
61
bool VCLXAccessibleStatusBarItem::IsShowing()
62
0
{
63
0
    bool bShowing = false;
64
65
0
    if ( m_pStatusBar )
66
0
        bShowing = m_pStatusBar->IsItemVisible( m_nItemId );
67
68
0
    return bShowing;
69
0
}
70
71
72
void VCLXAccessibleStatusBarItem::SetShowing( bool bShowing )
73
0
{
74
0
    if ( m_bShowing != bShowing )
75
0
    {
76
0
        Any aOldValue, aNewValue;
77
0
        if ( m_bShowing )
78
0
            aOldValue <<= AccessibleStateType::SHOWING;
79
0
        else
80
0
            aNewValue <<= AccessibleStateType::SHOWING;
81
0
        m_bShowing = bShowing;
82
0
        NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
83
0
    }
84
0
}
85
86
87
void VCLXAccessibleStatusBarItem::SetItemName( const OUString& sItemName )
88
0
{
89
0
    if ( m_sItemName != sItemName )
90
0
    {
91
0
        Any aOldValue, aNewValue;
92
0
        aOldValue <<= m_sItemName;
93
0
        aNewValue <<= sItemName;
94
0
        m_sItemName = sItemName;
95
0
        NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
96
0
    }
97
0
}
98
99
100
OUString VCLXAccessibleStatusBarItem::GetItemName()
101
0
{
102
0
    OUString sName;
103
0
    if ( m_pStatusBar )
104
0
        sName = m_pStatusBar->GetAccessibleName( m_nItemId );
105
106
0
    return sName;
107
0
}
108
109
110
void VCLXAccessibleStatusBarItem::SetItemText( const OUString& sItemText )
111
0
{
112
0
    Any aOldValue, aNewValue;
113
0
    if ( implInitTextChangedEvent( m_sItemText, sItemText, aOldValue, aNewValue ) )
114
0
    {
115
0
        m_sItemText = sItemText;
116
0
        NotifyAccessibleEvent( AccessibleEventId::TEXT_CHANGED, aOldValue, aNewValue );
117
0
    }
118
0
}
119
120
121
OUString VCLXAccessibleStatusBarItem::GetItemText()
122
0
{
123
0
    OUString sText;
124
0
    if ( m_pStatusBar )
125
0
        sText = m_pStatusBar->GetItemText( m_nItemId );
126
127
0
    return sText;
128
0
}
129
130
131
void VCLXAccessibleStatusBarItem::FillAccessibleStateSet( sal_Int64& rStateSet )
132
0
{
133
0
    rStateSet |= AccessibleStateType::ENABLED;
134
0
    rStateSet |= AccessibleStateType::SENSITIVE;
135
136
0
    rStateSet |= AccessibleStateType::VISIBLE;
137
138
0
    if ( IsShowing() )
139
0
        rStateSet |= AccessibleStateType::SHOWING;
140
0
}
141
142
// OAccessible
143
144
awt::Rectangle VCLXAccessibleStatusBarItem::implGetBounds()
145
0
{
146
0
    awt::Rectangle aBounds( 0, 0, 0, 0 );
147
148
0
    if ( m_pStatusBar )
149
0
        aBounds = vcl::unohelper::ConvertToAWTRect(m_pStatusBar->GetItemRect(m_nItemId));
150
151
0
    return aBounds;
152
0
}
153
154
155
// OCommonAccessibleText
156
157
158
OUString VCLXAccessibleStatusBarItem::implGetText()
159
0
{
160
0
    return GetItemText();
161
0
}
162
163
164
lang::Locale VCLXAccessibleStatusBarItem::implGetLocale()
165
0
{
166
0
    return Application::GetSettings().GetLanguageTag().getLocale();
167
0
}
168
169
170
void VCLXAccessibleStatusBarItem::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
171
0
{
172
0
    nStartIndex = 0;
173
0
    nEndIndex = 0;
174
0
}
175
176
177
// XComponent
178
179
180
void VCLXAccessibleStatusBarItem::disposing()
181
0
{
182
0
    comphelper::OAccessibleTextHelper::disposing();
183
184
0
    m_pStatusBar = nullptr;
185
0
    m_sItemName.clear();
186
0
    m_sItemText.clear();
187
0
}
188
189
// XAccessibleContext
190
191
192
sal_Int64 VCLXAccessibleStatusBarItem::getAccessibleChildCount()
193
0
{
194
0
    OExternalLockGuard aGuard( this );
195
196
0
    return 0;
197
0
}
198
199
200
Reference< XAccessible > VCLXAccessibleStatusBarItem::getAccessibleChild( sal_Int64 )
201
0
{
202
0
    throw IndexOutOfBoundsException();
203
0
}
204
205
206
Reference< XAccessible > VCLXAccessibleStatusBarItem::getAccessibleParent(  )
207
0
{
208
0
    OExternalLockGuard aGuard( this );
209
210
0
    Reference< XAccessible > xParent;
211
0
    if ( m_pStatusBar )
212
0
        xParent = m_pStatusBar->GetAccessible();
213
214
0
    return xParent;
215
0
}
216
217
218
sal_Int64 VCLXAccessibleStatusBarItem::getAccessibleIndexInParent(  )
219
0
{
220
0
    OExternalLockGuard aGuard( this );
221
222
0
    sal_Int64 nIndexInParent = -1;
223
0
    if ( m_pStatusBar )
224
0
        nIndexInParent = m_pStatusBar->GetItemPos( m_nItemId );
225
226
0
    return nIndexInParent;
227
0
}
228
229
230
sal_Int16 VCLXAccessibleStatusBarItem::getAccessibleRole(  )
231
0
{
232
0
    OExternalLockGuard aGuard( this );
233
234
0
    return AccessibleRole::LABEL;
235
0
}
236
237
238
OUString VCLXAccessibleStatusBarItem::getAccessibleDescription(  )
239
0
{
240
0
    OExternalLockGuard aGuard( this );
241
242
0
    OUString sDescription;
243
0
    if ( m_pStatusBar )
244
0
        sDescription = m_pStatusBar->GetHelpText( m_nItemId );
245
246
0
    return sDescription;
247
0
}
248
249
250
OUString VCLXAccessibleStatusBarItem::getAccessibleName(  )
251
0
{
252
0
    OExternalLockGuard aGuard( this );
253
254
0
    return GetItemName();
255
0
}
256
257
258
Reference< XAccessibleRelationSet > VCLXAccessibleStatusBarItem::getAccessibleRelationSet(  )
259
0
{
260
0
    OExternalLockGuard aGuard( this );
261
262
0
    return new utl::AccessibleRelationSetHelper;
263
0
}
264
265
266
sal_Int64 VCLXAccessibleStatusBarItem::getAccessibleStateSet(  )
267
0
{
268
0
    OExternalLockGuard aGuard( this );
269
270
0
    sal_Int64 nStateSet = 0;
271
272
0
    if (isAlive())
273
0
        FillAccessibleStateSet( nStateSet );
274
0
    else
275
0
        nStateSet |= AccessibleStateType::DEFUNC;
276
277
0
    return nStateSet;
278
0
}
279
280
281
Locale VCLXAccessibleStatusBarItem::getLocale(  )
282
0
{
283
0
    OExternalLockGuard aGuard( this );
284
285
0
    return Application::GetSettings().GetLanguageTag().getLocale();
286
0
}
287
288
289
// XAccessibleComponent
290
291
292
Reference< XAccessible > VCLXAccessibleStatusBarItem::getAccessibleAtPoint( const awt::Point& )
293
0
{
294
0
    OExternalLockGuard aGuard( this );
295
296
0
    return Reference< XAccessible >();
297
0
}
298
299
300
void VCLXAccessibleStatusBarItem::grabFocus(  )
301
0
{
302
    // no focus for status bar items
303
0
}
304
305
306
sal_Int32 VCLXAccessibleStatusBarItem::getForeground(   )
307
0
{
308
0
    OExternalLockGuard aGuard( this );
309
310
0
    sal_Int32 nColor = 0;
311
0
    Reference< XAccessible > xParent = getAccessibleParent();
312
0
    if ( xParent.is() )
313
0
    {
314
0
        Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
315
0
        if ( xParentComp.is() )
316
0
            nColor = xParentComp->getForeground();
317
0
    }
318
319
0
    return nColor;
320
0
}
321
322
323
sal_Int32 VCLXAccessibleStatusBarItem::getBackground(  )
324
0
{
325
0
    OExternalLockGuard aGuard( this );
326
327
0
    sal_Int32 nColor = 0;
328
0
    Reference< XAccessible > xParent = getAccessibleParent();
329
0
    if ( xParent.is() )
330
0
    {
331
0
        Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
332
0
        if ( xParentComp.is() )
333
0
            nColor = xParentComp->getBackground();
334
0
    }
335
336
0
    return nColor;
337
0
}
338
339
340
// XAccessibleExtendedComponent
341
342
OUString VCLXAccessibleStatusBarItem::getTitledBorderText(  )
343
0
{
344
0
    OExternalLockGuard aGuard( this );
345
346
0
    return GetItemText();
347
0
}
348
349
// XAccessibleText
350
351
OUString VCLXAccessibleStatusBarItem::getText()
352
0
{
353
0
    OExternalLockGuard aGuard( this );
354
355
0
    return GetItemText();
356
0
}
357
358
OUString VCLXAccessibleStatusBarItem::getTextRange(sal_Int32 nStartIndex, sal_Int32 nEndIndex)
359
0
{
360
0
    OExternalLockGuard aGuard( this );
361
362
0
    return OCommonAccessibleText::implGetTextRange(GetItemText(), nStartIndex, nEndIndex);
363
0
}
364
365
366
sal_Int32 VCLXAccessibleStatusBarItem::getCharacterCount()
367
0
{
368
0
    OExternalLockGuard aGuard( this );
369
370
0
    return GetItemText().getLength();
371
0
}
372
373
sal_Unicode VCLXAccessibleStatusBarItem::getCharacter( sal_Int32 nIndex )
374
0
{
375
0
     OExternalLockGuard aGuard( this );
376
377
0
     return OCommonAccessibleText::implGetCharacter( GetItemText(), nIndex );
378
0
}
379
380
sal_Int32 VCLXAccessibleStatusBarItem::getCaretPosition()
381
0
{
382
0
    OExternalLockGuard aGuard( this );
383
384
0
    return -1;
385
0
}
386
387
388
sal_Bool VCLXAccessibleStatusBarItem::setCaretPosition( sal_Int32 nIndex )
389
0
{
390
0
    OExternalLockGuard aGuard( this );
391
392
0
    if ( !implIsValidRange( nIndex, nIndex, GetItemText().getLength() ) )
393
0
        throw IndexOutOfBoundsException();
394
395
0
    return false;
396
0
}
397
398
399
Sequence< PropertyValue > VCLXAccessibleStatusBarItem::getCharacterAttributes( sal_Int32 nIndex, const Sequence< OUString >& aRequestedAttributes )
400
0
{
401
0
    OExternalLockGuard aGuard( this );
402
403
0
    Sequence< PropertyValue > aValues;
404
0
    OUString sText( implGetText() );
405
406
0
    if ( !implIsValidIndex( nIndex, sText.getLength() ) )
407
0
        throw IndexOutOfBoundsException();
408
409
0
    if ( m_pStatusBar )
410
0
    {
411
0
        vcl::Font aFont = m_pStatusBar->GetFont();
412
0
        sal_Int32 nBackColor = getBackground();
413
0
        sal_Int32 nColor = getForeground();
414
0
        aValues = CharacterAttributesHelper( aFont, nBackColor, nColor )
415
0
            .GetCharacterAttributes( aRequestedAttributes );
416
0
    }
417
418
0
    return aValues;
419
0
}
420
421
422
awt::Rectangle VCLXAccessibleStatusBarItem::getCharacterBounds( sal_Int32 nIndex )
423
0
{
424
0
    OExternalLockGuard aGuard( this );
425
426
0
    if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
427
0
        throw IndexOutOfBoundsException();
428
429
0
    awt::Rectangle aBounds( 0, 0, 0, 0 );
430
0
    if ( m_pStatusBar )
431
0
    {
432
0
        vcl::ControlLayoutData aLayoutData;
433
0
        tools::Rectangle aItemRect = m_pStatusBar->GetItemRect( m_nItemId );
434
0
        m_pStatusBar->RecordLayoutData( &aLayoutData, aItemRect );
435
0
        tools::Rectangle aCharRect = aLayoutData.GetCharacterBounds( nIndex );
436
0
        aCharRect.Move( -aItemRect.Left(), -aItemRect.Top() );
437
0
        aBounds = vcl::unohelper::ConvertToAWTRect(aCharRect);
438
0
    }
439
440
0
    return aBounds;
441
0
}
442
443
444
sal_Int32 VCLXAccessibleStatusBarItem::getIndexAtPoint( const awt::Point& aPoint )
445
0
{
446
0
    OExternalLockGuard aGuard( this );
447
448
0
    sal_Int32 nIndex = -1;
449
0
    if ( m_pStatusBar )
450
0
    {
451
0
        vcl::ControlLayoutData aLayoutData;
452
0
        tools::Rectangle aItemRect = m_pStatusBar->GetItemRect( m_nItemId );
453
0
        m_pStatusBar->RecordLayoutData( &aLayoutData, aItemRect );
454
0
        Point aPnt(vcl::unohelper::ConvertToVCLPoint(aPoint));
455
0
        aPnt += aItemRect.TopLeft();
456
0
        nIndex = aLayoutData.GetIndexForPoint( aPnt );
457
0
    }
458
459
0
    return nIndex;
460
0
}
461
462
463
sal_Bool VCLXAccessibleStatusBarItem::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
464
0
{
465
0
    OExternalLockGuard aGuard( this );
466
467
0
    if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
468
0
        throw IndexOutOfBoundsException();
469
470
0
    return false;
471
0
}
472
473
474
sal_Bool VCLXAccessibleStatusBarItem::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
475
0
{
476
0
    OExternalLockGuard aGuard( this );
477
478
0
    bool bReturn = false;
479
480
0
    if ( m_pStatusBar )
481
0
    {
482
0
        Reference< datatransfer::clipboard::XClipboard > xClipboard = m_pStatusBar->GetClipboard();
483
0
        if ( xClipboard.is() )
484
0
        {
485
0
            OUString sText( implGetTextRange( GetItemText(), nStartIndex, nEndIndex ) );
486
487
0
            rtl::Reference<vcl::unohelper::TextDataObject> pDataObj = new vcl::unohelper::TextDataObject( sText );
488
489
0
            SolarMutexReleaser aReleaser;
490
0
            xClipboard->setContents( pDataObj, nullptr );
491
492
0
            Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
493
0
            if( xFlushableClipboard.is() )
494
0
                xFlushableClipboard->flushClipboard();
495
496
0
            bReturn = true;
497
0
        }
498
0
    }
499
500
0
    return bReturn;
501
0
}
502
503
504
sal_Bool VCLXAccessibleStatusBarItem::scrollSubstringTo( sal_Int32, sal_Int32, AccessibleScrollType )
505
0
{
506
0
    return false;
507
0
}
508
509
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */