LibreOffice Module accessibility (master) 1
vclxaccessiblestatusbaritem.cxx
Go to the documentation of this file.
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
23
24#include <com/sun/star/accessibility/AccessibleEventId.hpp>
25#include <com/sun/star/accessibility/AccessibleRole.hpp>
26#include <com/sun/star/accessibility/AccessibleStateType.hpp>
27#include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
28#include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
29#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
33#include <vcl/ctrl.hxx>
34#include <vcl/svapp.hxx>
35#include <vcl/unohelp2.hxx>
36#include <vcl/status.hxx>
37#include <vcl/settings.hxx>
39
40using namespace ::com::sun::star::accessibility;
41using namespace ::com::sun::star::uno;
42using namespace ::com::sun::star::lang;
43using namespace ::com::sun::star::beans;
44using namespace ::com::sun::star;
45using namespace ::comphelper;
46
47
48
49
51 :m_pStatusBar( pStatusBar )
52 ,m_nItemId( nItemId )
53{
54
58}
59
60
62{
63 bool bShowing = false;
64
65 if ( m_pStatusBar )
66 bShowing = m_pStatusBar->IsItemVisible( m_nItemId );
67
68 return bShowing;
69}
70
71
73{
74 if ( m_bShowing != bShowing )
75 {
76 Any aOldValue, aNewValue;
77 if ( m_bShowing )
78 aOldValue <<= AccessibleStateType::SHOWING;
79 else
80 aNewValue <<= AccessibleStateType::SHOWING;
81 m_bShowing = bShowing;
82 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
83 }
84}
85
86
87void VCLXAccessibleStatusBarItem::SetItemName( const OUString& sItemName )
88{
89 if ( m_sItemName != sItemName )
90 {
91 Any aOldValue, aNewValue;
92 aOldValue <<= m_sItemName;
93 aNewValue <<= sItemName;
94 m_sItemName = sItemName;
95 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
96 }
97}
98
99
101{
102 OUString sName;
103 if ( m_pStatusBar )
104 sName = m_pStatusBar->GetAccessibleName( m_nItemId );
105
106 return sName;
107}
108
109
110void VCLXAccessibleStatusBarItem::SetItemText( const OUString& sItemText )
111{
112 Any aOldValue, aNewValue;
113 if ( implInitTextChangedEvent( m_sItemText, sItemText, aOldValue, aNewValue ) )
114 {
115 m_sItemText = sItemText;
116 NotifyAccessibleEvent( AccessibleEventId::TEXT_CHANGED, aOldValue, aNewValue );
117 }
118}
119
120
122{
123 OUString sText;
124 if ( m_pStatusBar )
125 sText = m_pStatusBar->GetItemText( m_nItemId );
126
127 return sText;
128}
129
130
132{
133 rStateSet |= AccessibleStateType::ENABLED;
134 rStateSet |= AccessibleStateType::SENSITIVE;
135
136 rStateSet |= AccessibleStateType::VISIBLE;
137
138 if ( IsShowing() )
139 rStateSet |= AccessibleStateType::SHOWING;
140}
141
142
143// OCommonAccessibleComponent
144
145
147{
148 awt::Rectangle aBounds( 0, 0, 0, 0 );
149
150 if ( m_pStatusBar )
151 aBounds = AWTRectangle( m_pStatusBar->GetItemRect( m_nItemId ) );
152
153 return aBounds;
154}
155
156
157// OCommonAccessibleText
158
159
161{
162 return GetItemText();
163}
164
165
167{
169}
170
171
172void VCLXAccessibleStatusBarItem::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
173{
174 nStartIndex = 0;
175 nEndIndex = 0;
176}
177
178
179// XComponent
180
181
183{
184 AccessibleTextHelper_BASE::disposing();
185
186 m_pStatusBar = nullptr;
187 m_sItemName.clear();
188 m_sItemText.clear();
189}
190
191
192// XServiceInfo
193
194
196{
197 return "com.sun.star.comp.toolkit.AccessibleStatusBarItem";
198}
199
200
202{
203 return cppu::supportsService(this, rServiceName);
204}
205
206
208{
209 return { "com.sun.star.awt.AccessibleStatusBarItem" };
210}
211
212
213// XAccessible
214
215
217{
218 OExternalLockGuard aGuard( this );
219
220 return this;
221}
222
223
224// XAccessibleContext
225
226
228{
229 OExternalLockGuard aGuard( this );
230
231 return 0;
232}
233
234
236{
237 throw IndexOutOfBoundsException();
238}
239
240
242{
243 OExternalLockGuard aGuard( this );
244
246 if ( m_pStatusBar )
247 xParent = m_pStatusBar->GetAccessible();
248
249 return xParent;
250}
251
252
254{
255 OExternalLockGuard aGuard( this );
256
257 sal_Int64 nIndexInParent = -1;
258 if ( m_pStatusBar )
259 nIndexInParent = m_pStatusBar->GetItemPos( m_nItemId );
260
261 return nIndexInParent;
262}
263
264
266{
267 OExternalLockGuard aGuard( this );
268
269 return AccessibleRole::LABEL;
270}
271
272
274{
275 OExternalLockGuard aGuard( this );
276
277 OUString sDescription;
278 if ( m_pStatusBar )
279 sDescription = m_pStatusBar->GetHelpText( m_nItemId );
280
281 return sDescription;
282}
283
284
286{
287 OExternalLockGuard aGuard( this );
288
289 return GetItemName();
290}
291
292
293Reference< XAccessibleRelationSet > VCLXAccessibleStatusBarItem::getAccessibleRelationSet( )
294{
295 OExternalLockGuard aGuard( this );
296
298}
299
300
302{
303 OExternalLockGuard aGuard( this );
304
305 sal_Int64 nStateSet = 0;
306
307 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
308 {
309 FillAccessibleStateSet( nStateSet );
310 }
311 else
312 {
313 nStateSet |= AccessibleStateType::DEFUNC;
314 }
315
316 return nStateSet;
317}
318
319
321{
322 OExternalLockGuard aGuard( this );
323
325}
326
327
328// XAccessibleComponent
329
330
332{
333 OExternalLockGuard aGuard( this );
334
336}
337
338
340{
341 // no focus for status bar items
342}
343
344
346{
347 OExternalLockGuard aGuard( this );
348
349 sal_Int32 nColor = 0;
351 if ( xParent.is() )
352 {
353 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
354 if ( xParentComp.is() )
355 nColor = xParentComp->getForeground();
356 }
357
358 return nColor;
359}
360
361
363{
364 OExternalLockGuard aGuard( this );
365
366 sal_Int32 nColor = 0;
368 if ( xParent.is() )
369 {
370 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
371 if ( xParentComp.is() )
372 nColor = xParentComp->getBackground();
373 }
374
375 return nColor;
376}
377
378
379// XAccessibleExtendedComponent
380
381
382Reference< awt::XFont > VCLXAccessibleStatusBarItem::getFont( )
383{
384 OExternalLockGuard aGuard( this );
385
386 Reference< awt::XFont > xFont;
388 if ( xParent.is() )
389 {
390 Reference< XAccessibleExtendedComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
391 if ( xParentComp.is() )
392 xFont = xParentComp->getFont();
393 }
394
395 return xFont;
396}
397
398
400{
401 OExternalLockGuard aGuard( this );
402
403 return GetItemText();
404}
405
406
408{
409 OExternalLockGuard aGuard( this );
410
411 return OUString();
412}
413
414
415// XAccessibleText
416
418{
419 OExternalLockGuard aGuard( this );
420
421 return GetItemText();
422}
423
424OUString VCLXAccessibleStatusBarItem::getTextRange(sal_Int32 nStartIndex, sal_Int32 nEndIndex)
425{
426 OExternalLockGuard aGuard( this );
427
428 return OCommonAccessibleText::implGetTextRange(GetItemText(), nStartIndex, nEndIndex);
429}
430
431
433{
434 OExternalLockGuard aGuard( this );
435
436 return GetItemText().getLength();
437}
438
440{
441 OExternalLockGuard aGuard( this );
442
443 return OCommonAccessibleText::implGetCharacter( GetItemText(), nIndex );
444}
445
447{
448 OExternalLockGuard aGuard( this );
449
450 return -1;
451}
452
453
455{
456 OExternalLockGuard aGuard( this );
457
458 if ( !implIsValidRange( nIndex, nIndex, GetItemText().getLength() ) )
459 throw IndexOutOfBoundsException();
460
461 return false;
462}
463
464
465Sequence< PropertyValue > VCLXAccessibleStatusBarItem::getCharacterAttributes( sal_Int32 nIndex, const Sequence< OUString >& aRequestedAttributes )
466{
467 OExternalLockGuard aGuard( this );
468
469 Sequence< PropertyValue > aValues;
470 OUString sText( implGetText() );
471
472 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
473 throw IndexOutOfBoundsException();
474
475 if ( m_pStatusBar )
476 {
477 vcl::Font aFont = m_pStatusBar->GetFont();
478 sal_Int32 nBackColor = getBackground();
479 sal_Int32 nColor = getForeground();
480 aValues = CharacterAttributesHelper( aFont, nBackColor, nColor )
481 .GetCharacterAttributes( aRequestedAttributes );
482 }
483
484 return aValues;
485}
486
487
488awt::Rectangle VCLXAccessibleStatusBarItem::getCharacterBounds( sal_Int32 nIndex )
489{
490 OExternalLockGuard aGuard( this );
491
492 if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
493 throw IndexOutOfBoundsException();
494
495 awt::Rectangle aBounds( 0, 0, 0, 0 );
496 if ( m_pStatusBar )
497 {
498 vcl::ControlLayoutData aLayoutData;
499 tools::Rectangle aItemRect = m_pStatusBar->GetItemRect( m_nItemId );
500 m_pStatusBar->RecordLayoutData( &aLayoutData, aItemRect );
501 tools::Rectangle aCharRect = aLayoutData.GetCharacterBounds( nIndex );
502 aCharRect.Move( -aItemRect.Left(), -aItemRect.Top() );
503 aBounds = AWTRectangle( aCharRect );
504 }
505
506 return aBounds;
507}
508
509
510sal_Int32 VCLXAccessibleStatusBarItem::getIndexAtPoint( const awt::Point& aPoint )
511{
512 OExternalLockGuard aGuard( this );
513
514 sal_Int32 nIndex = -1;
515 if ( m_pStatusBar )
516 {
517 vcl::ControlLayoutData aLayoutData;
518 tools::Rectangle aItemRect = m_pStatusBar->GetItemRect( m_nItemId );
519 m_pStatusBar->RecordLayoutData( &aLayoutData, aItemRect );
520 Point aPnt( VCLPoint( aPoint ) );
521 aPnt += aItemRect.TopLeft();
522 nIndex = aLayoutData.GetIndexForPoint( aPnt );
523 }
524
525 return nIndex;
526}
527
528
529sal_Bool VCLXAccessibleStatusBarItem::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
530{
531 OExternalLockGuard aGuard( this );
532
533 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
534 throw IndexOutOfBoundsException();
535
536 return false;
537}
538
539
540sal_Bool VCLXAccessibleStatusBarItem::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
541{
542 OExternalLockGuard aGuard( this );
543
544 bool bReturn = false;
545
546 if ( m_pStatusBar )
547 {
548 Reference< datatransfer::clipboard::XClipboard > xClipboard = m_pStatusBar->GetClipboard();
549 if ( xClipboard.is() )
550 {
551 OUString sText( implGetTextRange( GetItemText(), nStartIndex, nEndIndex ) );
552
554
555 SolarMutexReleaser aReleaser;
556 xClipboard->setContents( pDataObj, nullptr );
557
558 Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
559 if( xFlushableClipboard.is() )
560 xFlushableClipboard->flushClipboard();
561
562 bReturn = true;
563 }
564 }
565
566 return bReturn;
567}
568
569
570sal_Bool VCLXAccessibleStatusBarItem::scrollSubstringTo( sal_Int32, sal_Int32, AccessibleScrollType )
571{
572 return false;
573}
574
575/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const LanguageTag & GetLanguageTag() const
static const AllSettings & GetSettings()
std::vector< css::beans::PropertyValue > GetCharacterAttributes()
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
void FillAccessibleStateSet(sal_Int64 &rStateSet)
virtual css::uno::Reference< css::awt::XFont > SAL_CALL getFont() override
virtual css::awt::Rectangle SAL_CALL getCharacterBounds(sal_Int32 nIndex) override
void SetItemText(const OUString &sItemText)
virtual OUString SAL_CALL getText() override
virtual sal_Bool SAL_CALL scrollSubstringTo(sal_Int32 nStartIndex, sal_Int32 nEndIndex, css::accessibility::AccessibleScrollType aScrollType) override
virtual OUString SAL_CALL getTitledBorderText() override
virtual sal_Int64 SAL_CALL getAccessibleIndexInParent() override
virtual css::awt::Rectangle implGetBounds() override
virtual css::lang::Locale implGetLocale() override
virtual sal_Bool SAL_CALL setSelection(sal_Int32 nStartIndex, sal_Int32 nEndIndex) override
virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override
virtual sal_Unicode SAL_CALL getCharacter(sal_Int32 nIndex) override
virtual OUString SAL_CALL getToolTipText() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int64) override
virtual void SAL_CALL disposing() override
virtual sal_Int32 SAL_CALL getCharacterCount() override
virtual sal_Int32 SAL_CALL getForeground() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getCharacterAttributes(sal_Int32 nIndex, const css::uno::Sequence< OUString > &aRequestedAttributes) override
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point &aPoint) override
virtual OUString SAL_CALL getAccessibleName() override
virtual sal_Int32 SAL_CALL getBackground() override
virtual sal_Int64 SAL_CALL getAccessibleStateSet() override
void SetItemName(const OUString &sItemName)
virtual sal_Int16 SAL_CALL getAccessibleRole() override
virtual void implGetSelection(sal_Int32 &nStartIndex, sal_Int32 &nEndIndex) override
virtual void SAL_CALL grabFocus() override
VCLXAccessibleStatusBarItem(StatusBar *pStatusBar, sal_uInt16 nItemId)
virtual OUString implGetText() override
virtual sal_Int32 SAL_CALL getCaretPosition() override
virtual sal_Bool SAL_CALL setCaretPosition(sal_Int32 nIndex) override
virtual sal_Bool SAL_CALL copyText(sal_Int32 nStartIndex, sal_Int32 nEndIndex) override
virtual sal_Int32 SAL_CALL getIndexAtPoint(const css::awt::Point &aPoint) override
virtual sal_Int64 SAL_CALL getAccessibleChildCount() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override
virtual OUString SAL_CALL getAccessibleDescription() override
virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext() override
virtual css::lang::Locale SAL_CALL getLocale() override
virtual OUString SAL_CALL getTextRange(sal_Int32 nStartIndex, sal_Int32 nEndIndex) override
constexpr tools::Long Top() const
constexpr Point TopLeft() const
void Move(tools::Long nHorzMoveDelta, tools::Long nVertMoveDelta)
constexpr tools::Long Left() const
css::awt::Rectangle AWTRectangle(const ::tools::Rectangle &rVCLRect)
inline ::Point VCLPoint(const css::awt::Point &rAWTPoint)
OUString sName
sal_Int32 nIndex
double getLength(const B2DPolygon &rCandidate)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
tools::Long GetIndexForPoint(const Point &rPoint) const
tools::Rectangle GetCharacterBounds(tools::Long nIndex) const
unsigned char sal_Bool
sal_uInt16 sal_Unicode