sw/qa: warning C6011: Dereferencing NULL pointer
[LibreOffice.git] / starmath / source / accessibility.cxx
blobc6abfaed1743d2733873f853b75e7aa92086223c
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 <com/sun/star/accessibility/AccessibleRole.hpp>
21 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
22 #include <com/sun/star/accessibility/AccessibleTextType.hpp>
23 #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
24 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
25 #include <unotools/accessiblerelationsethelper.hxx>
27 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
28 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
29 #include <comphelper/accessibleeventnotifier.hxx>
30 #include <cppuhelper/supportsservice.hxx>
31 #include <osl/diagnose.h>
32 #include <comphelper/diagnose_ex.hxx>
33 #include <vcl/kernarray.hxx>
34 #include <vcl/svapp.hxx>
35 #include <vcl/unohelp2.hxx>
36 #include <vcl/settings.hxx>
38 #include <tools/gen.hxx>
40 #include <editeng/editobj.hxx>
43 #include "accessibility.hxx"
44 #include <document.hxx>
45 #include <view.hxx>
46 #include <strings.hrc>
47 #include <smmod.hxx>
49 using namespace com::sun::star;
50 using namespace com::sun::star::lang;
51 using namespace com::sun::star::uno;
52 using namespace com::sun::star::accessibility;
54 SmGraphicAccessible::SmGraphicAccessible(SmGraphicWidget *pGraphicWin) :
55 aAccName (SmResId(RID_DOCUMENTSTR)),
56 nClientId (0),
57 pWin (pGraphicWin)
59 OSL_ENSURE( pWin, "SmGraphicAccessible: window missing" );
62 SmGraphicAccessible::~SmGraphicAccessible()
66 SmDocShell * SmGraphicAccessible::GetDoc_Impl()
68 SmViewShell *pView = pWin ? &pWin->GetView() : nullptr;
69 return pView ? pView->GetDoc() : nullptr;
72 OUString SmGraphicAccessible::GetAccessibleText_Impl()
74 OUString aTxt;
75 SmDocShell *pDoc = GetDoc_Impl();
76 if (pDoc)
77 aTxt = pDoc->GetAccessibleText();
78 return aTxt;
81 void SmGraphicAccessible::ClearWin()
83 pWin = nullptr; // implicitly results in AccessibleStateType::DEFUNC set
85 if ( nClientId )
87 comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( std::exchange(nClientId, 0), *this );
91 void SmGraphicAccessible::LaunchEvent(
92 const sal_Int16 nAccessibleEventId,
93 const uno::Any &rOldVal,
94 const uno::Any &rNewVal)
96 AccessibleEventObject aEvt;
97 aEvt.Source = static_cast<XAccessible *>(this);
98 aEvt.EventId = nAccessibleEventId;
99 aEvt.OldValue = rOldVal;
100 aEvt.NewValue = rNewVal ;
102 // pass event on to event-listener's
103 if (nClientId)
104 comphelper::AccessibleEventNotifier::addEvent( nClientId, aEvt );
107 uno::Reference< XAccessibleContext > SAL_CALL SmGraphicAccessible::getAccessibleContext()
109 return this;
112 sal_Bool SAL_CALL SmGraphicAccessible::containsPoint( const awt::Point& aPoint )
114 //! the arguments coordinates are relative to the current window !
115 //! Thus the top-left point is (0, 0)
117 SolarMutexGuard aGuard;
118 if (!pWin)
119 throw RuntimeException();
121 Size aSz( pWin->GetOutputSizePixel() );
122 return aPoint.X >= 0 && aPoint.Y >= 0 &&
123 aPoint.X < aSz.Width() && aPoint.Y < aSz.Height();
126 uno::Reference< XAccessible > SAL_CALL SmGraphicAccessible::getAccessibleAtPoint(
127 const awt::Point& aPoint )
129 SolarMutexGuard aGuard;
130 XAccessible *pRes = nullptr;
131 if (containsPoint( aPoint ))
132 pRes = this;
133 return pRes;
136 awt::Rectangle SAL_CALL SmGraphicAccessible::getBounds()
138 SolarMutexGuard aGuard;
139 if (!pWin)
140 throw RuntimeException();
142 const Point aOutPos;
143 const Size aOutSize(pWin->GetOutputSizePixel());
144 css::awt::Rectangle aRet;
146 aRet.X = aOutPos.X();
147 aRet.Y = aOutPos.Y();
148 aRet.Width = aOutSize.Width();
149 aRet.Height = aOutSize.Height();
151 return aRet;
154 awt::Point SAL_CALL SmGraphicAccessible::getLocation()
156 SolarMutexGuard aGuard;
157 if (!pWin)
158 throw RuntimeException();
160 const css::awt::Rectangle aRect(getBounds());
161 css::awt::Point aRet;
163 aRet.X = aRect.X;
164 aRet.Y = aRect.Y;
166 return aRet;
169 awt::Point SAL_CALL SmGraphicAccessible::getLocationOnScreen()
171 SolarMutexGuard aGuard;
172 if (!pWin)
173 throw RuntimeException();
175 css::awt::Point aScreenLoc(0, 0);
177 css::uno::Reference<css::accessibility::XAccessible> xParent(getAccessibleParent());
178 if (xParent)
180 css::uno::Reference<css::accessibility::XAccessibleContext> xParentContext(
181 xParent->getAccessibleContext());
182 css::uno::Reference<css::accessibility::XAccessibleComponent> xParentComponent(
183 xParentContext, css::uno::UNO_QUERY);
184 OSL_ENSURE(xParentComponent.is(),
185 "WeldEditAccessible::getLocationOnScreen: no parent component!");
186 if (xParentComponent.is())
188 css::awt::Point aParentScreenLoc(xParentComponent->getLocationOnScreen());
189 css::awt::Point aOwnRelativeLoc(getLocation());
190 aScreenLoc.X = aParentScreenLoc.X + aOwnRelativeLoc.X;
191 aScreenLoc.Y = aParentScreenLoc.Y + aOwnRelativeLoc.Y;
195 return aScreenLoc;
198 awt::Size SAL_CALL SmGraphicAccessible::getSize()
200 SolarMutexGuard aGuard;
201 if (!pWin)
202 throw RuntimeException();
203 Size aSz(pWin->GetOutputSizePixel());
204 return css::awt::Size(aSz.Width(), aSz.Height());
207 void SAL_CALL SmGraphicAccessible::grabFocus()
209 SolarMutexGuard aGuard;
210 if (!pWin)
211 throw RuntimeException();
213 pWin->GrabFocus();
216 sal_Int32 SAL_CALL SmGraphicAccessible::getForeground()
218 SolarMutexGuard aGuard;
219 if (!pWin)
220 throw RuntimeException();
222 weld::DrawingArea* pDrawingArea = pWin->GetDrawingArea();
223 OutputDevice& rDevice = pDrawingArea->get_ref_device();
225 return static_cast<sal_Int32>(rDevice.GetTextColor());
228 sal_Int32 SAL_CALL SmGraphicAccessible::getBackground()
230 SolarMutexGuard aGuard;
231 if (!pWin)
232 throw RuntimeException();
234 weld::DrawingArea* pDrawingArea = pWin->GetDrawingArea();
235 OutputDevice& rDevice = pDrawingArea->get_ref_device();
237 Wallpaper aWall(rDevice.GetBackground());
238 Color nCol;
239 if (aWall.IsBitmap() || aWall.IsGradient())
240 nCol = Application::GetSettings().GetStyleSettings().GetWindowColor();
241 else
242 nCol = aWall.GetColor();
243 return static_cast<sal_Int32>(nCol);
246 sal_Int64 SAL_CALL SmGraphicAccessible::getAccessibleChildCount()
248 return 0;
251 Reference< XAccessible > SAL_CALL SmGraphicAccessible::getAccessibleChild(
252 sal_Int64 /*i*/ )
254 throw IndexOutOfBoundsException(); // there is no child...
257 Reference< XAccessible > SAL_CALL SmGraphicAccessible::getAccessibleParent()
259 SolarMutexGuard aGuard;
260 if (!pWin)
261 throw RuntimeException();
263 return pWin->GetDrawingArea()->get_accessible_parent();
266 sal_Int64 SAL_CALL SmGraphicAccessible::getAccessibleIndexInParent()
268 SolarMutexGuard aGuard;
270 // -1 for child not found/no parent (according to specification)
271 sal_Int64 nRet = -1;
273 css::uno::Reference<css::accessibility::XAccessible> xParent(getAccessibleParent());
274 if (!xParent)
275 return nRet;
279 css::uno::Reference<css::accessibility::XAccessibleContext> xParentContext(
280 xParent->getAccessibleContext());
282 // iterate over parent's children and search for this object
283 if (xParentContext.is())
285 sal_Int64 nChildCount = xParentContext->getAccessibleChildCount();
286 for (sal_Int64 nChild = 0; (nChild < nChildCount) && (-1 == nRet); ++nChild)
288 css::uno::Reference<css::accessibility::XAccessible> xChild(
289 xParentContext->getAccessibleChild(nChild));
290 if (xChild.get() == this)
291 nRet = nChild;
295 catch (const css::uno::Exception&)
297 TOOLS_WARN_EXCEPTION("svx", "WeldEditAccessible::getAccessibleIndexInParent");
300 return nRet;
303 sal_Int16 SAL_CALL SmGraphicAccessible::getAccessibleRole()
305 return AccessibleRole::DOCUMENT;
308 OUString SAL_CALL SmGraphicAccessible::getAccessibleDescription()
310 SolarMutexGuard aGuard;
311 SmDocShell *pDoc = GetDoc_Impl();
312 return pDoc ? pDoc->GetText() : OUString();
315 OUString SAL_CALL SmGraphicAccessible::getAccessibleName()
317 SolarMutexGuard aGuard;
318 return aAccName;
321 Reference< XAccessibleRelationSet > SAL_CALL SmGraphicAccessible::getAccessibleRelationSet()
323 return new utl::AccessibleRelationSetHelper(); // empty relation set
326 sal_Int64 SAL_CALL SmGraphicAccessible::getAccessibleStateSet()
328 SolarMutexGuard aGuard;
329 sal_Int64 nStateSet = 0;
331 if (!pWin)
332 nStateSet |= AccessibleStateType::DEFUNC;
333 else
335 nStateSet |= AccessibleStateType::ENABLED;
336 nStateSet |= AccessibleStateType::FOCUSABLE;
337 if (pWin->HasFocus())
338 nStateSet |= AccessibleStateType::FOCUSED;
339 if (pWin->IsActive())
340 nStateSet |= AccessibleStateType::ACTIVE;
341 if (pWin->IsVisible())
342 nStateSet |= AccessibleStateType::SHOWING;
343 if (pWin->IsReallyVisible())
344 nStateSet |= AccessibleStateType::VISIBLE;
345 weld::DrawingArea* pDrawingArea = pWin->GetDrawingArea();
346 OutputDevice& rDevice = pDrawingArea->get_ref_device();
347 if (COL_TRANSPARENT != rDevice.GetBackground().GetColor())
348 nStateSet |= AccessibleStateType::OPAQUE;
351 return nStateSet;
354 Locale SAL_CALL SmGraphicAccessible::getLocale()
356 SolarMutexGuard aGuard;
357 // should be the document language...
358 // We use the language of the localized symbol names here.
359 return Application::GetSettings().GetUILanguageTag().getLocale();
363 void SAL_CALL SmGraphicAccessible::addAccessibleEventListener(
364 const Reference< XAccessibleEventListener >& xListener )
366 if (xListener.is())
368 SolarMutexGuard aGuard;
369 if (pWin)
371 if (!nClientId)
372 nClientId = comphelper::AccessibleEventNotifier::registerClient( );
373 comphelper::AccessibleEventNotifier::addEventListener( nClientId, xListener );
378 void SAL_CALL SmGraphicAccessible::removeAccessibleEventListener(
379 const Reference< XAccessibleEventListener >& xListener )
381 if (!(xListener.is() && nClientId))
382 return;
384 SolarMutexGuard aGuard;
385 sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( nClientId, xListener );
386 if ( !nListenerCount )
388 // no listeners anymore
389 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
390 // and at least to us not firing any events anymore, in case somebody calls
391 // NotifyAccessibleEvent, again
392 comphelper::AccessibleEventNotifier::revokeClient( std::exchange(nClientId, 0) );
396 sal_Int32 SAL_CALL SmGraphicAccessible::getCaretPosition()
398 return 0;
401 sal_Bool SAL_CALL SmGraphicAccessible::setCaretPosition( sal_Int32 nIndex )
403 SolarMutexGuard aGuard;
404 OUString aTxt( GetAccessibleText_Impl() );
405 if (nIndex >= aTxt.getLength())
406 throw IndexOutOfBoundsException();
407 return false;
410 sal_Unicode SAL_CALL SmGraphicAccessible::getCharacter( sal_Int32 nIndex )
412 SolarMutexGuard aGuard;
413 OUString aTxt( GetAccessibleText_Impl() );
414 if (nIndex >= aTxt.getLength())
415 throw IndexOutOfBoundsException();
416 return aTxt[nIndex];
419 Sequence< beans::PropertyValue > SAL_CALL SmGraphicAccessible::getCharacterAttributes(
420 sal_Int32 nIndex,
421 const uno::Sequence< OUString > & /*rRequestedAttributes*/ )
423 SolarMutexGuard aGuard;
424 sal_Int32 nLen = GetAccessibleText_Impl().getLength();
425 if (0 > nIndex || nIndex >= nLen)
426 throw IndexOutOfBoundsException();
427 return Sequence< beans::PropertyValue >();
430 awt::Rectangle SAL_CALL SmGraphicAccessible::getCharacterBounds( sal_Int32 nIndex )
432 SolarMutexGuard aGuard;
434 awt::Rectangle aRes;
436 if (!pWin)
437 throw RuntimeException();
439 // get accessible text
440 SmDocShell* pDoc = pWin->GetView().GetDoc();
441 if (!pDoc)
442 throw RuntimeException();
443 OUString aTxt( GetAccessibleText_Impl() );
444 if (0 > nIndex || nIndex > aTxt.getLength()) // aTxt.getLength() is valid
445 throw IndexOutOfBoundsException();
447 // find a reasonable rectangle for position aTxt.getLength().
448 bool bWasBehindText = (nIndex == aTxt.getLength());
449 if (bWasBehindText && nIndex)
450 --nIndex;
452 const SmNode *pTree = pDoc->GetFormulaTree();
453 const SmNode *pNode = pTree->FindNodeWithAccessibleIndex( nIndex );
454 //! pNode may be 0 if the index belongs to a char that was inserted
455 //! only for the accessible text!
456 if (pNode)
458 sal_Int32 nAccIndex = pNode->GetAccessibleIndex();
459 OSL_ENSURE( nAccIndex >= 0, "invalid accessible index" );
460 OSL_ENSURE( nIndex >= nAccIndex, "index out of range" );
462 OUStringBuffer aBuf;
463 pNode->GetAccessibleText(aBuf);
464 OUString aNodeText = aBuf.makeStringAndClear();
465 sal_Int32 nNodeIndex = nIndex - nAccIndex;
466 if (0 <= nNodeIndex && nNodeIndex < aNodeText.getLength())
468 // get appropriate rectangle
469 Point aOffset(pNode->GetTopLeft() - pTree->GetTopLeft());
470 Point aTLPos (pWin->GetFormulaDrawPos() + aOffset);
471 Size aSize (pNode->GetSize());
473 weld::DrawingArea* pDrawingArea = pWin->GetDrawingArea();
474 OutputDevice& rDevice = pDrawingArea->get_ref_device();
476 KernArray aXAry;
477 rDevice.SetFont( pNode->GetFont() );
478 rDevice.GetTextArray( aNodeText, &aXAry, 0, aNodeText.getLength() );
479 aTLPos.AdjustX(nNodeIndex > 0 ? aXAry[nNodeIndex - 1] : 0 );
480 aSize.setWidth( nNodeIndex > 0 ? aXAry[nNodeIndex] - aXAry[nNodeIndex - 1] : aXAry[nNodeIndex] );
482 aTLPos = rDevice.LogicToPixel( aTLPos );
483 aSize = rDevice.LogicToPixel( aSize );
484 aRes.X = aTLPos.X();
485 aRes.Y = aTLPos.Y();
486 aRes.Width = aSize.Width();
487 aRes.Height = aSize.Height();
491 // take rectangle from last character and move it to the right
492 if (bWasBehindText)
493 aRes.X += aRes.Width;
495 return aRes;
498 sal_Int32 SAL_CALL SmGraphicAccessible::getCharacterCount()
500 SolarMutexGuard aGuard;
501 return GetAccessibleText_Impl().getLength();
504 sal_Int32 SAL_CALL SmGraphicAccessible::getIndexAtPoint( const awt::Point& aPoint )
506 SolarMutexGuard aGuard;
508 sal_Int32 nRes = -1;
509 if (pWin)
511 const SmNode *pTree = pWin->GetView().GetDoc()->GetFormulaTree();
512 // can be NULL! e.g. if one clicks within the window already during loading of the
513 // document (before the parser even started)
514 if (!pTree)
515 return nRes;
517 weld::DrawingArea* pDrawingArea = pWin->GetDrawingArea();
518 OutputDevice& rDevice = pDrawingArea->get_ref_device();
520 // get position relative to formula draw position
521 Point aPos( aPoint.X, aPoint.Y );
522 aPos = rDevice.PixelToLogic( aPos );
523 aPos -= pWin->GetFormulaDrawPos();
525 // if it was inside the formula then get the appropriate node
526 const SmNode *pNode = nullptr;
527 if (pTree->OrientedDist(aPos) <= 0)
528 pNode = pTree->FindRectClosestTo(aPos);
530 if (pNode)
532 // get appropriate rectangle
533 Point aOffset( pNode->GetTopLeft() - pTree->GetTopLeft() );
534 Point aTLPos ( aOffset );
535 Size aSize( pNode->GetSize() );
537 tools::Rectangle aRect( aTLPos, aSize );
538 if (aRect.Contains( aPos ))
540 OSL_ENSURE( pNode->IsVisible(), "node is not a leaf" );
541 OUStringBuffer aBuf;
542 pNode->GetAccessibleText(aBuf);
543 OUString aTxt = aBuf.makeStringAndClear();
544 OSL_ENSURE( !aTxt.isEmpty(), "no accessible text available" );
546 tools::Long nNodeX = pNode->GetLeft();
548 KernArray aXAry;
549 rDevice.SetFont( pNode->GetFont() );
550 rDevice.GetTextArray( aTxt, &aXAry, 0, aTxt.getLength() );
551 for (sal_Int32 i = 0; i < aTxt.getLength() && nRes == -1; ++i)
553 if (aXAry[i] + nNodeX > aPos.X())
554 nRes = i;
556 OSL_ENSURE( nRes >= 0 && nRes < aTxt.getLength(), "index out of range" );
557 OSL_ENSURE( pNode->GetAccessibleIndex() >= 0,
558 "invalid accessible index" );
560 nRes = pNode->GetAccessibleIndex() + nRes;
564 return nRes;
567 OUString SAL_CALL SmGraphicAccessible::getSelectedText()
569 return OUString();
572 sal_Int32 SAL_CALL SmGraphicAccessible::getSelectionStart()
574 return -1;
577 sal_Int32 SAL_CALL SmGraphicAccessible::getSelectionEnd()
579 return -1;
582 sal_Bool SAL_CALL SmGraphicAccessible::setSelection(
583 sal_Int32 nStartIndex,
584 sal_Int32 nEndIndex )
586 SolarMutexGuard aGuard;
587 sal_Int32 nLen = GetAccessibleText_Impl().getLength();
588 if (0 > nStartIndex || nStartIndex >= nLen ||
589 0 > nEndIndex || nEndIndex >= nLen)
590 throw IndexOutOfBoundsException();
591 return false;
594 OUString SAL_CALL SmGraphicAccessible::getText()
596 SolarMutexGuard aGuard;
597 return GetAccessibleText_Impl();
600 OUString SAL_CALL SmGraphicAccessible::getTextRange(
601 sal_Int32 nStartIndex,
602 sal_Int32 nEndIndex )
604 //!! nEndIndex may be the string length per definition of the interface !!
605 //!! text should be copied exclusive that end index though. And arguments
606 //!! may be switched.
608 SolarMutexGuard aGuard;
609 OUString aTxt( GetAccessibleText_Impl() );
610 sal_Int32 nStart = std::min(nStartIndex, nEndIndex);
611 sal_Int32 nEnd = std::max(nStartIndex, nEndIndex);
612 if ((nStart > aTxt.getLength()) ||
613 (nEnd > aTxt.getLength()))
614 throw IndexOutOfBoundsException();
615 return aTxt.copy( nStart, nEnd - nStart );
618 css::accessibility::TextSegment SAL_CALL SmGraphicAccessible::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType )
620 SolarMutexGuard aGuard;
621 OUString aTxt( GetAccessibleText_Impl() );
622 //!! nIndex is allowed to be the string length
623 if (nIndex > aTxt.getLength())
624 throw IndexOutOfBoundsException();
626 css::accessibility::TextSegment aResult;
627 aResult.SegmentStart = -1;
628 aResult.SegmentEnd = -1;
629 if ( (AccessibleTextType::CHARACTER == aTextType) && (nIndex < aTxt.getLength()) )
631 auto nIndexEnd = nIndex;
632 aTxt.iterateCodePoints(&nIndexEnd);
634 aResult.SegmentText = aTxt.copy(nIndex, nIndexEnd - nIndex);
635 aResult.SegmentStart = nIndex;
636 aResult.SegmentEnd = nIndexEnd;
638 return aResult;
641 css::accessibility::TextSegment SAL_CALL SmGraphicAccessible::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType )
643 SolarMutexGuard aGuard;
644 OUString aTxt( GetAccessibleText_Impl() );
645 //!! nIndex is allowed to be the string length
646 if (nIndex > aTxt.getLength())
647 throw IndexOutOfBoundsException();
649 css::accessibility::TextSegment aResult;
650 aResult.SegmentStart = -1;
651 aResult.SegmentEnd = -1;
653 if ( (AccessibleTextType::CHARACTER == aTextType) && nIndex > 0 )
655 aTxt.iterateCodePoints(&nIndex, -1);
656 auto nIndexEnd = nIndex;
657 aTxt.iterateCodePoints(&nIndexEnd);
658 aResult.SegmentText = aTxt.copy(nIndex, nIndexEnd - nIndex);
659 aResult.SegmentStart = nIndex;
660 aResult.SegmentEnd = nIndexEnd;
662 return aResult;
665 css::accessibility::TextSegment SAL_CALL SmGraphicAccessible::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType )
667 SolarMutexGuard aGuard;
668 OUString aTxt( GetAccessibleText_Impl() );
669 //!! nIndex is allowed to be the string length
670 if (nIndex > aTxt.getLength())
671 throw IndexOutOfBoundsException();
673 css::accessibility::TextSegment aResult;
674 aResult.SegmentStart = -1;
675 aResult.SegmentEnd = -1;
677 if ( (AccessibleTextType::CHARACTER == aTextType) && (nIndex + 1 < aTxt.getLength()) )
679 aTxt.iterateCodePoints(&nIndex);
680 auto nIndexEnd = nIndex;
681 aTxt.iterateCodePoints(&nIndexEnd);
682 aResult.SegmentText = aTxt.copy(nIndex, nIndexEnd - nIndex);
683 aResult.SegmentStart = nIndex;
684 aResult.SegmentEnd = nIndexEnd;
686 return aResult;
689 sal_Bool SAL_CALL SmGraphicAccessible::copyText(
690 sal_Int32 nStartIndex,
691 sal_Int32 nEndIndex )
693 SolarMutexGuard aGuard;
694 bool bReturn = false;
696 if (!pWin)
697 throw RuntimeException();
699 Reference< datatransfer::clipboard::XClipboard > xClipboard = pWin->GetClipboard();
700 if ( xClipboard.is() )
702 OUString sText( getTextRange(nStartIndex, nEndIndex) );
704 rtl::Reference<vcl::unohelper::TextDataObject> pDataObj = new vcl::unohelper::TextDataObject( sText );
705 SolarMutexReleaser aReleaser;
706 xClipboard->setContents( pDataObj, nullptr );
708 Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
709 if( xFlushableClipboard.is() )
710 xFlushableClipboard->flushClipboard();
712 bReturn = true;
716 return bReturn;
719 sal_Bool SAL_CALL SmGraphicAccessible::scrollSubstringTo( sal_Int32, sal_Int32, AccessibleScrollType )
721 return false;
724 OUString SAL_CALL SmGraphicAccessible::getImplementationName()
726 return u"SmGraphicAccessible"_ustr;
729 sal_Bool SAL_CALL SmGraphicAccessible::supportsService(
730 const OUString& rServiceName )
732 return cppu::supportsService(this, rServiceName);
735 Sequence< OUString > SAL_CALL SmGraphicAccessible::getSupportedServiceNames()
737 return {
738 u"css::accessibility::Accessible"_ustr,
739 u"css::accessibility::AccessibleComponent"_ustr,
740 u"css::accessibility::AccessibleContext"_ustr,
741 u"css::accessibility::AccessibleText"_ustr
745 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */