Coverage Report

Created: 2026-06-30 11:14

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
190
// XServiceInfo
191
192
193
OUString VCLXAccessibleStatusBarItem::getImplementationName()
194
0
{
195
0
    return u"com.sun.star.comp.toolkit.AccessibleStatusBarItem"_ustr;
196
0
}
197
198
199
sal_Bool VCLXAccessibleStatusBarItem::supportsService( const OUString& rServiceName )
200
0
{
201
0
    return cppu::supportsService(this, rServiceName);
202
0
}
203
204
205
Sequence< OUString > VCLXAccessibleStatusBarItem::getSupportedServiceNames()
206
0
{
207
0
    return { u"com.sun.star.awt.AccessibleStatusBarItem"_ustr };
208
0
}
209
210
// XAccessibleContext
211
212
213
sal_Int64 VCLXAccessibleStatusBarItem::getAccessibleChildCount()
214
0
{
215
0
    OExternalLockGuard aGuard( this );
216
217
0
    return 0;
218
0
}
219
220
221
Reference< XAccessible > VCLXAccessibleStatusBarItem::getAccessibleChild( sal_Int64 )
222
0
{
223
0
    throw IndexOutOfBoundsException();
224
0
}
225
226
227
Reference< XAccessible > VCLXAccessibleStatusBarItem::getAccessibleParent(  )
228
0
{
229
0
    OExternalLockGuard aGuard( this );
230
231
0
    Reference< XAccessible > xParent;
232
0
    if ( m_pStatusBar )
233
0
        xParent = m_pStatusBar->GetAccessible();
234
235
0
    return xParent;
236
0
}
237
238
239
sal_Int64 VCLXAccessibleStatusBarItem::getAccessibleIndexInParent(  )
240
0
{
241
0
    OExternalLockGuard aGuard( this );
242
243
0
    sal_Int64 nIndexInParent = -1;
244
0
    if ( m_pStatusBar )
245
0
        nIndexInParent = m_pStatusBar->GetItemPos( m_nItemId );
246
247
0
    return nIndexInParent;
248
0
}
249
250
251
sal_Int16 VCLXAccessibleStatusBarItem::getAccessibleRole(  )
252
0
{
253
0
    OExternalLockGuard aGuard( this );
254
255
0
    return AccessibleRole::LABEL;
256
0
}
257
258
259
OUString VCLXAccessibleStatusBarItem::getAccessibleDescription(  )
260
0
{
261
0
    OExternalLockGuard aGuard( this );
262
263
0
    OUString sDescription;
264
0
    if ( m_pStatusBar )
265
0
        sDescription = m_pStatusBar->GetHelpText( m_nItemId );
266
267
0
    return sDescription;
268
0
}
269
270
271
OUString VCLXAccessibleStatusBarItem::getAccessibleName(  )
272
0
{
273
0
    OExternalLockGuard aGuard( this );
274
275
0
    return GetItemName();
276
0
}
277
278
279
Reference< XAccessibleRelationSet > VCLXAccessibleStatusBarItem::getAccessibleRelationSet(  )
280
0
{
281
0
    OExternalLockGuard aGuard( this );
282
283
0
    return new utl::AccessibleRelationSetHelper;
284
0
}
285
286
287
sal_Int64 VCLXAccessibleStatusBarItem::getAccessibleStateSet(  )
288
0
{
289
0
    OExternalLockGuard aGuard( this );
290
291
0
    sal_Int64 nStateSet = 0;
292
293
0
    if (isAlive())
294
0
        FillAccessibleStateSet( nStateSet );
295
0
    else
296
0
        nStateSet |= AccessibleStateType::DEFUNC;
297
298
0
    return nStateSet;
299
0
}
300
301
302
Locale VCLXAccessibleStatusBarItem::getLocale(  )
303
0
{
304
0
    OExternalLockGuard aGuard( this );
305
306
0
    return Application::GetSettings().GetLanguageTag().getLocale();
307
0
}
308
309
310
// XAccessibleComponent
311
312
313
Reference< XAccessible > VCLXAccessibleStatusBarItem::getAccessibleAtPoint( const awt::Point& )
314
0
{
315
0
    OExternalLockGuard aGuard( this );
316
317
0
    return Reference< XAccessible >();
318
0
}
319
320
321
void VCLXAccessibleStatusBarItem::grabFocus(  )
322
0
{
323
    // no focus for status bar items
324
0
}
325
326
327
sal_Int32 VCLXAccessibleStatusBarItem::getForeground(   )
328
0
{
329
0
    OExternalLockGuard aGuard( this );
330
331
0
    sal_Int32 nColor = 0;
332
0
    Reference< XAccessible > xParent = getAccessibleParent();
333
0
    if ( xParent.is() )
334
0
    {
335
0
        Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
336
0
        if ( xParentComp.is() )
337
0
            nColor = xParentComp->getForeground();
338
0
    }
339
340
0
    return nColor;
341
0
}
342
343
344
sal_Int32 VCLXAccessibleStatusBarItem::getBackground(  )
345
0
{
346
0
    OExternalLockGuard aGuard( this );
347
348
0
    sal_Int32 nColor = 0;
349
0
    Reference< XAccessible > xParent = getAccessibleParent();
350
0
    if ( xParent.is() )
351
0
    {
352
0
        Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
353
0
        if ( xParentComp.is() )
354
0
            nColor = xParentComp->getBackground();
355
0
    }
356
357
0
    return nColor;
358
0
}
359
360
361
// XAccessibleExtendedComponent
362
363
OUString VCLXAccessibleStatusBarItem::getTitledBorderText(  )
364
0
{
365
0
    OExternalLockGuard aGuard( this );
366
367
0
    return GetItemText();
368
0
}
369
370
// XAccessibleText
371
372
OUString VCLXAccessibleStatusBarItem::getText()
373
0
{
374
0
    OExternalLockGuard aGuard( this );
375
376
0
    return GetItemText();
377
0
}
378
379
OUString VCLXAccessibleStatusBarItem::getTextRange(sal_Int32 nStartIndex, sal_Int32 nEndIndex)
380
0
{
381
0
    OExternalLockGuard aGuard( this );
382
383
0
    return OCommonAccessibleText::implGetTextRange(GetItemText(), nStartIndex, nEndIndex);
384
0
}
385
386
387
sal_Int32 VCLXAccessibleStatusBarItem::getCharacterCount()
388
0
{
389
0
    OExternalLockGuard aGuard( this );
390
391
0
    return GetItemText().getLength();
392
0
}
393
394
sal_Unicode VCLXAccessibleStatusBarItem::getCharacter( sal_Int32 nIndex )
395
0
{
396
0
     OExternalLockGuard aGuard( this );
397
398
0
     return OCommonAccessibleText::implGetCharacter( GetItemText(), nIndex );
399
0
}
400
401
sal_Int32 VCLXAccessibleStatusBarItem::getCaretPosition()
402
0
{
403
0
    OExternalLockGuard aGuard( this );
404
405
0
    return -1;
406
0
}
407
408
409
sal_Bool VCLXAccessibleStatusBarItem::setCaretPosition( sal_Int32 nIndex )
410
0
{
411
0
    OExternalLockGuard aGuard( this );
412
413
0
    if ( !implIsValidRange( nIndex, nIndex, GetItemText().getLength() ) )
414
0
        throw IndexOutOfBoundsException();
415
416
0
    return false;
417
0
}
418
419
420
Sequence< PropertyValue > VCLXAccessibleStatusBarItem::getCharacterAttributes( sal_Int32 nIndex, const Sequence< OUString >& aRequestedAttributes )
421
0
{
422
0
    OExternalLockGuard aGuard( this );
423
424
0
    Sequence< PropertyValue > aValues;
425
0
    OUString sText( implGetText() );
426
427
0
    if ( !implIsValidIndex( nIndex, sText.getLength() ) )
428
0
        throw IndexOutOfBoundsException();
429
430
0
    if ( m_pStatusBar )
431
0
    {
432
0
        vcl::Font aFont = m_pStatusBar->GetFont();
433
0
        sal_Int32 nBackColor = getBackground();
434
0
        sal_Int32 nColor = getForeground();
435
0
        aValues = CharacterAttributesHelper( aFont, nBackColor, nColor )
436
0
            .GetCharacterAttributes( aRequestedAttributes );
437
0
    }
438
439
0
    return aValues;
440
0
}
441
442
443
awt::Rectangle VCLXAccessibleStatusBarItem::getCharacterBounds( sal_Int32 nIndex )
444
0
{
445
0
    OExternalLockGuard aGuard( this );
446
447
0
    if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
448
0
        throw IndexOutOfBoundsException();
449
450
0
    awt::Rectangle aBounds( 0, 0, 0, 0 );
451
0
    if ( m_pStatusBar )
452
0
    {
453
0
        vcl::ControlLayoutData aLayoutData;
454
0
        tools::Rectangle aItemRect = m_pStatusBar->GetItemRect( m_nItemId );
455
0
        m_pStatusBar->RecordLayoutData( &aLayoutData, aItemRect );
456
0
        tools::Rectangle aCharRect = aLayoutData.GetCharacterBounds( nIndex );
457
0
        aCharRect.Move( -aItemRect.Left(), -aItemRect.Top() );
458
0
        aBounds = vcl::unohelper::ConvertToAWTRect(aCharRect);
459
0
    }
460
461
0
    return aBounds;
462
0
}
463
464
465
sal_Int32 VCLXAccessibleStatusBarItem::getIndexAtPoint( const awt::Point& aPoint )
466
0
{
467
0
    OExternalLockGuard aGuard( this );
468
469
0
    sal_Int32 nIndex = -1;
470
0
    if ( m_pStatusBar )
471
0
    {
472
0
        vcl::ControlLayoutData aLayoutData;
473
0
        tools::Rectangle aItemRect = m_pStatusBar->GetItemRect( m_nItemId );
474
0
        m_pStatusBar->RecordLayoutData( &aLayoutData, aItemRect );
475
0
        Point aPnt(vcl::unohelper::ConvertToVCLPoint(aPoint));
476
0
        aPnt += aItemRect.TopLeft();
477
0
        nIndex = aLayoutData.GetIndexForPoint( aPnt );
478
0
    }
479
480
0
    return nIndex;
481
0
}
482
483
484
sal_Bool VCLXAccessibleStatusBarItem::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
485
0
{
486
0
    OExternalLockGuard aGuard( this );
487
488
0
    if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
489
0
        throw IndexOutOfBoundsException();
490
491
0
    return false;
492
0
}
493
494
495
sal_Bool VCLXAccessibleStatusBarItem::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
496
0
{
497
0
    OExternalLockGuard aGuard( this );
498
499
0
    bool bReturn = false;
500
501
0
    if ( m_pStatusBar )
502
0
    {
503
0
        Reference< datatransfer::clipboard::XClipboard > xClipboard = m_pStatusBar->GetClipboard();
504
0
        if ( xClipboard.is() )
505
0
        {
506
0
            OUString sText( implGetTextRange( GetItemText(), nStartIndex, nEndIndex ) );
507
508
0
            rtl::Reference<vcl::unohelper::TextDataObject> pDataObj = new vcl::unohelper::TextDataObject( sText );
509
510
0
            SolarMutexReleaser aReleaser;
511
0
            xClipboard->setContents( pDataObj, nullptr );
512
513
0
            Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
514
0
            if( xFlushableClipboard.is() )
515
0
                xFlushableClipboard->flushClipboard();
516
517
0
            bReturn = true;
518
0
        }
519
0
    }
520
521
0
    return bReturn;
522
0
}
523
524
525
sal_Bool VCLXAccessibleStatusBarItem::scrollSubstringTo( sal_Int32, sal_Int32, AccessibleScrollType )
526
0
{
527
0
    return false;
528
0
}
529
530
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */