Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / accessibility / source / standard / vclxaccessiblestatusbaritem.cxx
blob4c4bf62347419a0dc858f6f2d6194834fc2b845f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <standard/vclxaccessiblestatusbaritem.hxx>
21 #include <toolkit/helper/convert.hxx>
22 #include <helper/characterattributeshelper.hxx>
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>
30 #include <comphelper/accessiblecontexthelper.hxx>
31 #include <cppuhelper/supportsservice.hxx>
32 #include <unotools/accessiblerelationsethelper.hxx>
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>
38 #include <i18nlangtag/languagetag.hxx>
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;
50 VCLXAccessibleStatusBarItem::VCLXAccessibleStatusBarItem( StatusBar* pStatusBar, sal_uInt16 nItemId )
51 :m_pStatusBar( pStatusBar )
52 ,m_nItemId( nItemId )
55 m_sItemName = GetItemName();
56 m_sItemText = GetItemText();
57 m_bShowing = IsShowing();
61 bool VCLXAccessibleStatusBarItem::IsShowing()
63 bool bShowing = false;
65 if ( m_pStatusBar )
66 bShowing = m_pStatusBar->IsItemVisible( m_nItemId );
68 return bShowing;
72 void VCLXAccessibleStatusBarItem::SetShowing( bool bShowing )
74 if ( m_bShowing != bShowing )
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 );
87 void VCLXAccessibleStatusBarItem::SetItemName( const OUString& sItemName )
89 if ( m_sItemName != sItemName )
91 Any aOldValue, aNewValue;
92 aOldValue <<= m_sItemName;
93 aNewValue <<= sItemName;
94 m_sItemName = sItemName;
95 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
100 OUString VCLXAccessibleStatusBarItem::GetItemName()
102 OUString sName;
103 if ( m_pStatusBar )
104 sName = m_pStatusBar->GetAccessibleName( m_nItemId );
106 return sName;
110 void VCLXAccessibleStatusBarItem::SetItemText( const OUString& sItemText )
112 Any aOldValue, aNewValue;
113 if ( implInitTextChangedEvent( m_sItemText, sItemText, aOldValue, aNewValue ) )
115 m_sItemText = sItemText;
116 NotifyAccessibleEvent( AccessibleEventId::TEXT_CHANGED, aOldValue, aNewValue );
121 OUString VCLXAccessibleStatusBarItem::GetItemText()
123 OUString sText;
124 if ( m_pStatusBar )
125 sText = m_pStatusBar->GetItemText( m_nItemId );
127 return sText;
131 void VCLXAccessibleStatusBarItem::FillAccessibleStateSet( sal_Int64& rStateSet )
133 rStateSet |= AccessibleStateType::ENABLED;
134 rStateSet |= AccessibleStateType::SENSITIVE;
136 rStateSet |= AccessibleStateType::VISIBLE;
138 if ( IsShowing() )
139 rStateSet |= AccessibleStateType::SHOWING;
143 // OCommonAccessibleComponent
146 awt::Rectangle VCLXAccessibleStatusBarItem::implGetBounds()
148 awt::Rectangle aBounds( 0, 0, 0, 0 );
150 if ( m_pStatusBar )
151 aBounds = AWTRectangle( m_pStatusBar->GetItemRect( m_nItemId ) );
153 return aBounds;
157 // OCommonAccessibleText
160 OUString VCLXAccessibleStatusBarItem::implGetText()
162 return GetItemText();
166 lang::Locale VCLXAccessibleStatusBarItem::implGetLocale()
168 return Application::GetSettings().GetLanguageTag().getLocale();
172 void VCLXAccessibleStatusBarItem::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
174 nStartIndex = 0;
175 nEndIndex = 0;
179 // XComponent
182 void VCLXAccessibleStatusBarItem::disposing()
184 AccessibleTextHelper_BASE::disposing();
186 m_pStatusBar = nullptr;
187 m_sItemName.clear();
188 m_sItemText.clear();
192 // XServiceInfo
195 OUString VCLXAccessibleStatusBarItem::getImplementationName()
197 return "com.sun.star.comp.toolkit.AccessibleStatusBarItem";
201 sal_Bool VCLXAccessibleStatusBarItem::supportsService( const OUString& rServiceName )
203 return cppu::supportsService(this, rServiceName);
207 Sequence< OUString > VCLXAccessibleStatusBarItem::getSupportedServiceNames()
209 return { "com.sun.star.awt.AccessibleStatusBarItem" };
213 // XAccessible
216 Reference< XAccessibleContext > VCLXAccessibleStatusBarItem::getAccessibleContext( )
218 OExternalLockGuard aGuard( this );
220 return this;
224 // XAccessibleContext
227 sal_Int64 VCLXAccessibleStatusBarItem::getAccessibleChildCount()
229 OExternalLockGuard aGuard( this );
231 return 0;
235 Reference< XAccessible > VCLXAccessibleStatusBarItem::getAccessibleChild( sal_Int64 )
237 throw IndexOutOfBoundsException();
241 Reference< XAccessible > VCLXAccessibleStatusBarItem::getAccessibleParent( )
243 OExternalLockGuard aGuard( this );
245 Reference< XAccessible > xParent;
246 if ( m_pStatusBar )
247 xParent = m_pStatusBar->GetAccessible();
249 return xParent;
253 sal_Int64 VCLXAccessibleStatusBarItem::getAccessibleIndexInParent( )
255 OExternalLockGuard aGuard( this );
257 sal_Int64 nIndexInParent = -1;
258 if ( m_pStatusBar )
259 nIndexInParent = m_pStatusBar->GetItemPos( m_nItemId );
261 return nIndexInParent;
265 sal_Int16 VCLXAccessibleStatusBarItem::getAccessibleRole( )
267 OExternalLockGuard aGuard( this );
269 return AccessibleRole::LABEL;
273 OUString VCLXAccessibleStatusBarItem::getAccessibleDescription( )
275 OExternalLockGuard aGuard( this );
277 OUString sDescription;
278 if ( m_pStatusBar )
279 sDescription = m_pStatusBar->GetHelpText( m_nItemId );
281 return sDescription;
285 OUString VCLXAccessibleStatusBarItem::getAccessibleName( )
287 OExternalLockGuard aGuard( this );
289 return GetItemName();
293 Reference< XAccessibleRelationSet > VCLXAccessibleStatusBarItem::getAccessibleRelationSet( )
295 OExternalLockGuard aGuard( this );
297 return new utl::AccessibleRelationSetHelper;
301 sal_Int64 VCLXAccessibleStatusBarItem::getAccessibleStateSet( )
303 OExternalLockGuard aGuard( this );
305 sal_Int64 nStateSet = 0;
307 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
309 FillAccessibleStateSet( nStateSet );
311 else
313 nStateSet |= AccessibleStateType::DEFUNC;
316 return nStateSet;
320 Locale VCLXAccessibleStatusBarItem::getLocale( )
322 OExternalLockGuard aGuard( this );
324 return Application::GetSettings().GetLanguageTag().getLocale();
328 // XAccessibleComponent
331 Reference< XAccessible > VCLXAccessibleStatusBarItem::getAccessibleAtPoint( const awt::Point& )
333 OExternalLockGuard aGuard( this );
335 return Reference< XAccessible >();
339 void VCLXAccessibleStatusBarItem::grabFocus( )
341 // no focus for status bar items
345 sal_Int32 VCLXAccessibleStatusBarItem::getForeground( )
347 OExternalLockGuard aGuard( this );
349 sal_Int32 nColor = 0;
350 Reference< XAccessible > xParent = getAccessibleParent();
351 if ( xParent.is() )
353 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
354 if ( xParentComp.is() )
355 nColor = xParentComp->getForeground();
358 return nColor;
362 sal_Int32 VCLXAccessibleStatusBarItem::getBackground( )
364 OExternalLockGuard aGuard( this );
366 sal_Int32 nColor = 0;
367 Reference< XAccessible > xParent = getAccessibleParent();
368 if ( xParent.is() )
370 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
371 if ( xParentComp.is() )
372 nColor = xParentComp->getBackground();
375 return nColor;
379 // XAccessibleExtendedComponent
382 Reference< awt::XFont > VCLXAccessibleStatusBarItem::getFont( )
384 OExternalLockGuard aGuard( this );
386 Reference< awt::XFont > xFont;
387 Reference< XAccessible > xParent = getAccessibleParent();
388 if ( xParent.is() )
390 Reference< XAccessibleExtendedComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
391 if ( xParentComp.is() )
392 xFont = xParentComp->getFont();
395 return xFont;
399 OUString VCLXAccessibleStatusBarItem::getTitledBorderText( )
401 OExternalLockGuard aGuard( this );
403 return GetItemText();
407 OUString VCLXAccessibleStatusBarItem::getToolTipText( )
409 OExternalLockGuard aGuard( this );
411 return OUString();
415 // XAccessibleText
417 OUString VCLXAccessibleStatusBarItem::getText()
419 OExternalLockGuard aGuard( this );
421 return GetItemText();
424 OUString VCLXAccessibleStatusBarItem::getTextRange(sal_Int32 nStartIndex, sal_Int32 nEndIndex)
426 OExternalLockGuard aGuard( this );
428 return OCommonAccessibleText::implGetTextRange(GetItemText(), nStartIndex, nEndIndex);
432 sal_Int32 VCLXAccessibleStatusBarItem::getCharacterCount()
434 OExternalLockGuard aGuard( this );
436 return GetItemText().getLength();
439 sal_Unicode VCLXAccessibleStatusBarItem::getCharacter( sal_Int32 nIndex )
441 OExternalLockGuard aGuard( this );
443 return OCommonAccessibleText::implGetCharacter( GetItemText(), nIndex );
446 sal_Int32 VCLXAccessibleStatusBarItem::getCaretPosition()
448 OExternalLockGuard aGuard( this );
450 return -1;
454 sal_Bool VCLXAccessibleStatusBarItem::setCaretPosition( sal_Int32 nIndex )
456 OExternalLockGuard aGuard( this );
458 if ( !implIsValidRange( nIndex, nIndex, GetItemText().getLength() ) )
459 throw IndexOutOfBoundsException();
461 return false;
465 Sequence< PropertyValue > VCLXAccessibleStatusBarItem::getCharacterAttributes( sal_Int32 nIndex, const Sequence< OUString >& aRequestedAttributes )
467 OExternalLockGuard aGuard( this );
469 Sequence< PropertyValue > aValues;
470 OUString sText( implGetText() );
472 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
473 throw IndexOutOfBoundsException();
475 if ( m_pStatusBar )
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 );
484 return aValues;
488 awt::Rectangle VCLXAccessibleStatusBarItem::getCharacterBounds( sal_Int32 nIndex )
490 OExternalLockGuard aGuard( this );
492 if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
493 throw IndexOutOfBoundsException();
495 awt::Rectangle aBounds( 0, 0, 0, 0 );
496 if ( m_pStatusBar )
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 );
506 return aBounds;
510 sal_Int32 VCLXAccessibleStatusBarItem::getIndexAtPoint( const awt::Point& aPoint )
512 OExternalLockGuard aGuard( this );
514 sal_Int32 nIndex = -1;
515 if ( m_pStatusBar )
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 );
525 return nIndex;
529 sal_Bool VCLXAccessibleStatusBarItem::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
531 OExternalLockGuard aGuard( this );
533 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
534 throw IndexOutOfBoundsException();
536 return false;
540 sal_Bool VCLXAccessibleStatusBarItem::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
542 OExternalLockGuard aGuard( this );
544 bool bReturn = false;
546 if ( m_pStatusBar )
548 Reference< datatransfer::clipboard::XClipboard > xClipboard = m_pStatusBar->GetClipboard();
549 if ( xClipboard.is() )
551 OUString sText( implGetTextRange( GetItemText(), nStartIndex, nEndIndex ) );
553 rtl::Reference<vcl::unohelper::TextDataObject> pDataObj = new vcl::unohelper::TextDataObject( sText );
555 SolarMutexReleaser aReleaser;
556 xClipboard->setContents( pDataObj, nullptr );
558 Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
559 if( xFlushableClipboard.is() )
560 xFlushableClipboard->flushClipboard();
562 bReturn = true;
566 return bReturn;
570 sal_Bool VCLXAccessibleStatusBarItem::scrollSubstringTo( sal_Int32, sal_Int32, AccessibleScrollType )
572 return false;
575 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */