LibreOffice Module accessibility (master) 1
vclxaccessibletabpage.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/mnemonic.hxx>
34#include <vcl/svapp.hxx>
35#include <vcl/unohelp2.hxx>
36#include <vcl/tabctrl.hxx>
37#include <vcl/tabpage.hxx>
38#include <vcl/settings.hxx>
40
41using namespace ::com::sun::star::accessibility;
42using namespace ::com::sun::star::uno;
43using namespace ::com::sun::star::lang;
44using namespace ::com::sun::star::beans;
45using namespace ::com::sun::star;
46using namespace ::comphelper;
47
48
49
50
52 :m_pTabControl( pTabControl )
53 ,m_nPageId( nPageId )
54{
58}
59
60
62{
63}
64
65
67{
68 bool bFocused = false;
69
70 if ( m_pTabControl && m_pTabControl->HasFocus() && m_pTabControl->GetCurPageId() == m_nPageId )
71 bFocused = true;
72
73 return bFocused;
74}
75
76
78{
79 bool bSelected = false;
80
81 if ( m_pTabControl && m_pTabControl->GetCurPageId() == m_nPageId )
82 bSelected = true;
83
84 return bSelected;
85}
86
87
89{
90 if ( m_bFocused != bFocused )
91 {
92 Any aOldValue, aNewValue;
93 if ( m_bFocused )
94 aOldValue <<= AccessibleStateType::FOCUSED;
95 else
96 aNewValue <<= AccessibleStateType::FOCUSED;
97 m_bFocused = bFocused;
98 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
99 }
100}
101
102
104{
105 if ( m_bSelected != bSelected )
106 {
107 Any aOldValue, aNewValue;
108 if ( m_bSelected )
109 aOldValue <<= AccessibleStateType::SELECTED;
110 else
111 aNewValue <<= AccessibleStateType::SELECTED;
112 m_bSelected = bSelected;
113 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
114 }
115}
116
117
118void VCLXAccessibleTabPage::SetPageText( const OUString& sPageText )
119{
120 Any aOldValue, aNewValue;
121 if ( OCommonAccessibleText::implInitTextChangedEvent( m_sPageText, sPageText, aOldValue, aNewValue ) )
122 {
123 Any aOldName, aNewName;
124 aOldName <<= m_sPageText;
125 aNewName <<= sPageText;
126 m_sPageText = sPageText;
127 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, aOldName, aNewName );
128 NotifyAccessibleEvent( AccessibleEventId::TEXT_CHANGED, aOldValue, aNewValue );
129 }
130}
131
132
134{
135 OUString sText;
136 if ( m_pTabControl )
137 sText = removeMnemonicFromString( m_pTabControl->GetPageText( m_nPageId ) );
138
139 return sText;
140}
141
142
144{
145 if ( !m_pTabControl )
146 return;
147
148 TabPage* pTabPage = m_pTabControl->GetTabPage( m_nPageId );
149 if ( !pTabPage )
150 return;
151
152 Reference< XAccessible > xChild( pTabPage->GetAccessible( bNew ) );
153 if ( xChild.is() )
154 {
155 Any aOldValue, aNewValue;
156 if ( bNew )
157 aNewValue <<= xChild;
158 else
159 aOldValue <<= xChild;
160 NotifyAccessibleEvent( AccessibleEventId::CHILD, aOldValue, aNewValue );
161 }
162}
163
164
166{
167 rStateSet |= AccessibleStateType::ENABLED;
168 rStateSet |= AccessibleStateType::SENSITIVE;
169
170 rStateSet |= AccessibleStateType::FOCUSABLE;
171
172 if ( IsFocused() )
173 rStateSet |= AccessibleStateType::FOCUSED;
174
175 rStateSet |= AccessibleStateType::VISIBLE;
176
177 rStateSet |= AccessibleStateType::SHOWING;
178
179 rStateSet |= AccessibleStateType::SELECTABLE;
180
181 if ( IsSelected() )
182 rStateSet |= AccessibleStateType::SELECTED;
183}
184
185
186// OCommonAccessibleComponent
187
188
190{
191 awt::Rectangle aBounds( 0, 0, 0, 0 );
192
193 if ( m_pTabControl )
194 aBounds = AWTRectangle( m_pTabControl->GetTabBounds( m_nPageId ) );
195
196 return aBounds;
197}
198
199
200// OCommonAccessibleText
201
202
204{
205 return GetPageText();
206}
207
208
210{
212}
213
214
215void VCLXAccessibleTabPage::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
216{
217 nStartIndex = 0;
218 nEndIndex = 0;
219}
220
221
222// XComponent
223
224
226{
227 AccessibleTextHelper_BASE::disposing();
228
229 m_pTabControl = nullptr;
230 m_sPageText.clear();
231}
232
233
234// XServiceInfo
235
236
238{
239 return "com.sun.star.comp.toolkit.AccessibleTabPage";
240}
241
242
244{
245 return cppu::supportsService(this, rServiceName);
246}
247
248
250{
251 return { "com.sun.star.awt.AccessibleTabPage" };
252}
253
254
255// XAccessible
256
257
258Reference< XAccessibleContext > VCLXAccessibleTabPage::getAccessibleContext( )
259{
260 OExternalLockGuard aGuard( this );
261
262 return this;
263}
264
265
266// XAccessibleContext
267
268
270{
271 OExternalLockGuard aGuard( this );
273}
274
276{
277 sal_Int64 nCount = 0;
278 if ( m_pTabControl )
279 {
280 TabPage* pTabPage = m_pTabControl->GetTabPage( m_nPageId );
281 if ( pTabPage && pTabPage->IsVisible() )
282 nCount = 1;
283 }
284
285 return nCount;
286}
287
288
290{
291 OExternalLockGuard aGuard( this );
292
293 if ( i < 0 || i >= implGetAccessibleChildCount() )
294 throw IndexOutOfBoundsException();
295
297 if ( m_pTabControl )
298 {
299 TabPage* pTabPage = m_pTabControl->GetTabPage( m_nPageId );
300 if ( pTabPage && pTabPage->IsVisible() )
301 xChild = pTabPage->GetAccessible();
302 }
303
304 return xChild;
305}
306
307
309{
310 OExternalLockGuard aGuard( this );
311
313 if ( m_pTabControl )
314 xParent = m_pTabControl->GetAccessible();
315
316 return xParent;
317}
318
319
321{
322 OExternalLockGuard aGuard( this );
323
324 sal_Int64 nIndexInParent = -1;
325 if ( m_pTabControl )
326 nIndexInParent = m_pTabControl->GetPagePos( m_nPageId );
327
328 return nIndexInParent;
329}
330
332{
333 OExternalLockGuard aGuard( this );
334
335 return AccessibleRole::PAGE_TAB;
336}
337
339{
340 OExternalLockGuard aGuard( this );
341
342 OUString sDescription;
343 if ( m_pTabControl )
344 sDescription = m_pTabControl->GetAccessibleDescription( m_nPageId );
345
346 return sDescription;
347}
348
350{
351 OExternalLockGuard aGuard( this );
352
353 OUString sName;
354 if ( m_pTabControl )
355 sName = m_pTabControl->GetAccessibleName( m_nPageId );
356
357 return sName;
358}
359
360Reference< XAccessibleRelationSet > VCLXAccessibleTabPage::getAccessibleRelationSet( )
361{
362 OExternalLockGuard aGuard( this );
363
365}
366
367
369{
370 OExternalLockGuard aGuard( this );
371
372 sal_Int64 nStateSet = 0;
373
374 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
375 {
376 FillAccessibleStateSet( nStateSet );
377 }
378 else
379 {
380 nStateSet |= AccessibleStateType::DEFUNC;
381 }
382
383 return nStateSet;
384}
385
386
388{
389 OExternalLockGuard aGuard( this );
390
392}
393
394
395// XAccessibleComponent
396
397
399{
400 OExternalLockGuard aGuard( this );
401
403 for ( sal_Int64 i = 0, nCount = getAccessibleChildCount(); i < nCount; ++i )
404 {
406 if ( xAcc.is() )
407 {
408 Reference< XAccessibleComponent > xComp( xAcc->getAccessibleContext(), UNO_QUERY );
409 if ( xComp.is() )
410 {
411 tools::Rectangle aRect = VCLRectangle( xComp->getBounds() );
412 Point aPos = VCLPoint( rPoint );
413 if ( aRect.Contains( aPos ) )
414 {
415 xChild = xAcc;
416 break;
417 }
418 }
419 }
420 }
421
422 return xChild;
423}
424
425
427{
428 OExternalLockGuard aGuard( this );
429
430 if ( m_pTabControl )
431 {
432 m_pTabControl->SelectTabPage( m_nPageId );
433 m_pTabControl->GrabFocus();
434 }
435}
436
437
439{
440 OExternalLockGuard aGuard( this );
441
442 sal_Int32 nColor = 0;
444 if ( xParent.is() )
445 {
446 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
447 if ( xParentComp.is() )
448 nColor = xParentComp->getForeground();
449 }
450
451 return nColor;
452}
453
454
456{
457 OExternalLockGuard aGuard( this );
458
459 sal_Int32 nColor = 0;
461 if ( xParent.is() )
462 {
463 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
464 if ( xParentComp.is() )
465 nColor = xParentComp->getBackground();
466 }
467
468 return nColor;
469}
470
471
472// XAccessibleExtendedComponent
473
474
475Reference< awt::XFont > VCLXAccessibleTabPage::getFont( )
476{
477 OExternalLockGuard aGuard( this );
478
479 Reference< awt::XFont > xFont;
481 if ( xParent.is() )
482 {
483 Reference< XAccessibleExtendedComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
484 if ( xParentComp.is() )
485 xFont = xParentComp->getFont();
486 }
487
488 return xFont;
489}
490
491
493{
494 OExternalLockGuard aGuard( this );
495
496 return OUString();
497}
498
499
501{
502 OExternalLockGuard aGuard( this );
503
504 return OUString();
505}
506
507
508// XAccessibleText
509
511{
512 OExternalLockGuard aGuard( this );
513
514 return GetPageText();
515}
516
517OUString VCLXAccessibleTabPage::getTextRange(sal_Int32 nStartIndex, sal_Int32 nEndIndex)
518{
519 OExternalLockGuard aGuard( this );
520
521 return OCommonAccessibleText::implGetTextRange(GetPageText(), nStartIndex, nEndIndex);
522}
523
525{
526 OExternalLockGuard aGuard( this );
527
528 return OCommonAccessibleText::implGetCharacter( GetPageText(), nIndex );
529}
530
532{
533 return GetPageText().getLength();
534}
535
537{
538 OExternalLockGuard aGuard( this );
539
540 return -1;
541}
542
543
545{
546 OExternalLockGuard aGuard( this );
547
548 if ( !implIsValidRange( nIndex, nIndex, GetPageText().getLength() ) )
549 throw IndexOutOfBoundsException();
550
551 return false;
552}
553
554
555Sequence< PropertyValue > VCLXAccessibleTabPage::getCharacterAttributes( sal_Int32 nIndex, const Sequence< OUString >& aRequestedAttributes )
556{
557 OExternalLockGuard aGuard( this );
558
559 Sequence< PropertyValue > aValues;
560 OUString sText( GetPageText() );
561
562 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
563 throw IndexOutOfBoundsException();
564
565 if ( m_pTabControl )
566 {
567 vcl::Font aFont = m_pTabControl->GetFont();
568 sal_Int32 nBackColor = getBackground();
569 sal_Int32 nColor = getForeground();
570 aValues = CharacterAttributesHelper( aFont, nBackColor, nColor )
571 .GetCharacterAttributes( aRequestedAttributes );
572 }
573
574 return aValues;
575}
576
577
578awt::Rectangle VCLXAccessibleTabPage::getCharacterBounds( sal_Int32 nIndex )
579{
580 OExternalLockGuard aGuard( this );
581
582 if ( !implIsValidIndex( nIndex, GetPageText().getLength() ) )
583 throw IndexOutOfBoundsException();
584
585 awt::Rectangle aBounds( 0, 0, 0, 0 );
586 if ( m_pTabControl )
587 {
588 tools::Rectangle aPageRect = m_pTabControl->GetTabBounds( m_nPageId );
589 tools::Rectangle aCharRect; // m_pTabControl->GetCharacterBounds( m_nPageId, nIndex );
590 aCharRect.Move( -aPageRect.Left(), -aPageRect.Top() );
591 aBounds = AWTRectangle( aCharRect );
592 }
593
594 return aBounds;
595}
596
597
598sal_Int32 VCLXAccessibleTabPage::getIndexAtPoint( const awt::Point& /*aPoint*/ )
599{
600 OExternalLockGuard aGuard( this );
601
602 sal_Int32 nIndex = -1;
603// if ( m_pTabControl )
604// {
605// sal_uInt16 nPageId = 0;
606// tools::Rectangle aPageRect = m_pTabControl->GetTabBounds( m_nPageId );
607// Point aPnt( VCLPoint( aPoint ) );
608// aPnt += aPageRect.TopLeft();
609// sal_Int32 nI = m_pTabControl->GetIndexForPoint( aPnt, nPageId );
610// if ( nI != -1 && m_nPageId == nPageId )
611// nIndex = nI;
612// }
613
614 return nIndex;
615}
616
617
618sal_Bool VCLXAccessibleTabPage::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
619{
620 OExternalLockGuard aGuard( this );
621
622 if ( !implIsValidRange( nStartIndex, nEndIndex, GetPageText().getLength() ) )
623 throw IndexOutOfBoundsException();
624
625 return false;
626}
627
628
629sal_Bool VCLXAccessibleTabPage::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
630{
631 OExternalLockGuard aGuard( this );
632
633 bool bReturn = false;
634
635 if ( m_pTabControl )
636 {
637 Reference< datatransfer::clipboard::XClipboard > xClipboard = m_pTabControl->GetClipboard();
638 if ( xClipboard.is() )
639 {
640 OUString sText( implGetTextRange( GetPageText(), nStartIndex, nEndIndex ) );
641
643
644 SolarMutexReleaser aReleaser;
645 xClipboard->setContents( pDataObj, nullptr );
646
647 Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
648 if( xFlushableClipboard.is() )
649 xFlushableClipboard->flushClipboard();
650
651 bReturn = true;
652 }
653 }
654
655 return bReturn;
656}
657
658sal_Bool VCLXAccessibleTabPage::scrollSubstringTo( sal_Int32, sal_Int32, AccessibleScrollType )
659{
660 return false;
661}
662
663
664/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 nPageId
const LanguageTag & GetLanguageTag() const
static const AllSettings & GetSettings()
std::vector< css::beans::PropertyValue > GetCharacterAttributes()
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Bool SAL_CALL copyText(sal_Int32 nStartIndex, sal_Int32 nEndIndex) override
VclPtr< TabControl > m_pTabControl
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
virtual ~VCLXAccessibleTabPage() override
virtual sal_Int32 SAL_CALL getBackground() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override
virtual OUString SAL_CALL getTitledBorderText() override
void FillAccessibleStateSet(sal_Int64 &rStateSet)
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point &aPoint) override
virtual void implGetSelection(sal_Int32 &nStartIndex, sal_Int32 &nEndIndex) override
virtual sal_Int32 SAL_CALL getCaretPosition() override
virtual sal_Unicode SAL_CALL getCharacter(sal_Int32 nIndex) override
void SetFocused(bool bFocused)
virtual void SAL_CALL grabFocus() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int64 i) override
virtual sal_Bool SAL_CALL scrollSubstringTo(sal_Int32 nStartIndex, sal_Int32 nEndIndex, css::accessibility::AccessibleScrollType aScrollType) override
virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getCharacterAttributes(sal_Int32 nIndex, const css::uno::Sequence< OUString > &aRequestedAttributes) override
VCLXAccessibleTabPage(TabControl *pTabControl, sal_uInt16 nPageId)
virtual OUString SAL_CALL getImplementationName() override
virtual sal_Int16 SAL_CALL getAccessibleRole() override
virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext() override
virtual sal_Int32 SAL_CALL getCharacterCount() override
void SetPageText(const OUString &sPageText)
virtual OUString SAL_CALL getTextRange(sal_Int32 nStartIndex, sal_Int32 nEndIndex) override
virtual sal_Int32 SAL_CALL getForeground() override
virtual css::uno::Reference< css::awt::XFont > SAL_CALL getFont() override
virtual OUString SAL_CALL getAccessibleDescription() override
virtual css::awt::Rectangle SAL_CALL getCharacterBounds(sal_Int32 nIndex) override
virtual sal_Int64 SAL_CALL getAccessibleChildCount() override
virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override
void SetSelected(bool bSelected)
virtual OUString SAL_CALL getText() override
virtual css::lang::Locale implGetLocale() override
virtual sal_Int64 SAL_CALL getAccessibleIndexInParent() override
virtual sal_Int32 SAL_CALL getIndexAtPoint(const css::awt::Point &aPoint) override
virtual void SAL_CALL disposing() override
virtual css::lang::Locale SAL_CALL getLocale() override
virtual css::awt::Rectangle implGetBounds() override
virtual OUString SAL_CALL getAccessibleName() override
virtual sal_Bool SAL_CALL setCaretPosition(sal_Int32 nIndex) override
virtual sal_Bool SAL_CALL setSelection(sal_Int32 nStartIndex, sal_Int32 nEndIndex) override
virtual OUString SAL_CALL getToolTipText() override
virtual sal_Int64 SAL_CALL getAccessibleStateSet() override
virtual OUString implGetText() override
bool Contains(const Point &rPOINT) const
constexpr tools::Long Top() const
void Move(tools::Long nHorzMoveDelta, tools::Long nVertMoveDelta)
constexpr tools::Long Left() const
css::uno::Reference< css::accessibility::XAccessible > GetAccessible(bool bCreate=true)
bool IsVisible() const
css::awt::Rectangle AWTRectangle(const ::tools::Rectangle &rVCLRect)
inline ::tools::Rectangle VCLRectangle(const css::awt::Rectangle &rAWTRect)
inline ::Point VCLPoint(const css::awt::Point &rAWTPoint)
int nCount
OUString sName
sal_Int32 nIndex
VCL_DLLPUBLIC OUString removeMnemonicFromString(OUString const &rStr, sal_Int32 &rMnemonicPos)
double getLength(const B2DPolygon &rCandidate)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
unsigned char sal_Bool
sal_uInt16 sal_Unicode