Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / winaccessibility / source / UAccCOM / AccTextBase.cxx
blob6717ce6fed7f7af4c733093c9d26ce00045fcfb5
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 .
21 // AccTextBase.cpp: implementation of the CAccTextBase class.
23 #include "stdafx.h"
25 #include "AccTextBase.h"
27 #include <rtl/ustrbuf.hxx>
28 #include <vcl/svapp.hxx>
29 #include <o3tl/char16_t2wchar_t.hxx>
31 #include <com/sun/star/accessibility/AccessibleTextType.hpp>
32 #include <com/sun/star/accessibility/XAccessible.hpp>
33 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
34 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
35 #include <com/sun/star/accessibility/XAccessibleTextSelection.hpp>
36 #include "MAccessible.h"
38 using namespace css::accessibility;
39 using namespace css::uno;
42 // Construction/Destruction
45 static OUString ReplaceFourChar(OUString const & oldOUString);
47 CAccTextBase::CAccTextBase()
50 CAccTextBase::~CAccTextBase()
54 /**
55 * Get special selection.
56 * @param startOffset Start selection offset.
57 * @param endOffset End selection offset.
58 * @param success Variant to accept the result of if the method call is successful.
59 * @return Result.
61 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_addSelection(long startOffset, long endOffset)
63 SolarMutexGuard g;
65 ENTER_PROTECTED_BLOCK
67 // #CHECK XInterface#
68 if(pUNOInterface == nullptr)
69 return E_FAIL;
71 Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext();
73 Reference< XAccessibleTextSelection > pRExtension(pRContext,UNO_QUERY);
75 if( pRExtension.is() )
77 pRExtension->addSelection(0, startOffset, endOffset);
78 return S_OK;
80 else
82 GetXInterface()->setSelection(startOffset, endOffset);
83 return S_OK;
86 LEAVE_PROTECTED_BLOCK
89 /**
90 * Get special attributes.
91 * @param offset Offset.
92 * @param startOffset Variant to accept start offset.
93 * @param endOffset Variant to accept end offset.
94 * @param textAttributes Variant to accept attributes.
95 * @return Result.
97 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_attributes(long offset, long * startOffset, long * endOffset, BSTR * textAttributes)
99 SolarMutexGuard g;
101 ENTER_PROTECTED_BLOCK
103 if (startOffset == nullptr || endOffset == nullptr || textAttributes == nullptr)
104 return E_INVALIDARG;
105 // #CHECK XInterface#
106 if(!pRXText.is())
108 return E_FAIL;
111 if( offset < 0 || offset > GetXInterface()->getCharacterCount() )
112 return E_FAIL;
114 OUStringBuffer strAttrs("Version:1;");
116 Sequence< css::beans::PropertyValue > pValues = GetXInterface()->getCharacterAttributes(offset, Sequence< OUString >());
117 int nCount = pValues.getLength();
119 sal_Int16 numberingLevel = 0;
120 OUString numberingPrefix;
121 Any anyNumRule;
122 bool bHaveNumberingPrefixAttr = false;
123 bool bHaveNumberingLevel = false;
124 bool bHaveNumberingRules = false;
125 for(int i =0; i<nCount; i++)
128 css::beans::PropertyValue &pValue = pValues[i];
129 if(pValue.Name == "NumberingLevel")
131 if (pValue.Value != Any())
132 pValue.Value >>= numberingLevel;
133 else
134 numberingLevel = -1;
135 bHaveNumberingLevel = true;
136 continue;
138 if(pValue.Name == "NumberingPrefix")
140 pValue.Value >>=numberingPrefix;
141 bHaveNumberingPrefixAttr = true;
142 continue;
144 if(pValue.Name == "NumberingRules")
146 bHaveNumberingRules = true;
147 anyNumRule = pValue.Value;
148 continue;
150 if (bHaveNumberingLevel && bHaveNumberingRules && bHaveNumberingPrefixAttr)
152 strAttrs.append(';');
153 numberingPrefix = ReplaceFourChar(numberingPrefix);
154 strAttrs.append(CMAccessible::get_String4Numbering(anyNumRule,numberingLevel,numberingPrefix));
155 bHaveNumberingLevel = false;
156 bHaveNumberingRules = false;
158 if( (bHaveNumberingPrefixAttr && i > 1 ) ||
159 (!bHaveNumberingPrefixAttr && i > 0 ) ) //element 0 is NumberingPrefix, not write alone
161 strAttrs.append(';');
163 strAttrs.append(pValue.Name);
164 strAttrs.append(':');
166 if (pValue.Name == "CharBackColor" ||
167 pValue.Name == "CharColor" ||
168 pValue.Name == "CharUnderlineColor" )
170 unsigned long nColor;
171 pValue.Value >>= nColor;
172 strAttrs.append('#');
173 OUString const hex = OUString::number(nColor, 16).toAsciiUpperCase();
174 for (sal_Int32 j = hex.getLength(); j < 8; ++j) {
175 strAttrs.append('0');
177 strAttrs.append(hex);
179 else
181 strAttrs.append(CMAccessible::get_StringFromAny(pValue.Value));
184 strAttrs.append(';');
185 // #CHECK#
186 if(*textAttributes)
187 SysFreeString(*textAttributes);
188 *textAttributes = SysAllocString(o3tl::toW(strAttrs.makeStringAndClear().getStr()));
190 if( offset < GetXInterface()->getCharacterCount() )
192 TextSegment textSeg = GetXInterface()->getTextAtIndex(offset, AccessibleTextType::ATTRIBUTE_RUN);
193 *startOffset = textSeg.SegmentStart;
194 *endOffset = textSeg.SegmentEnd;
196 else
198 *startOffset = offset;
199 *endOffset = offset;
202 return S_OK;
204 LEAVE_PROTECTED_BLOCK
208 * Get caret position.
209 * @param offset Variant to accept caret offset.
210 * @return Result.
212 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_caretOffset(long * offset)
214 SolarMutexGuard g;
216 ENTER_PROTECTED_BLOCK
218 if (offset == nullptr)
219 return E_INVALIDARG;
220 // #CHECK XInterface#
221 if(!pRXText.is())
223 *offset = 0;
224 return S_OK;
227 *offset = GetXInterface()->getCaretPosition();
228 return S_OK;
230 LEAVE_PROTECTED_BLOCK
234 * Get character count.
235 * @param nCharacters Variant to accept character count.
236 * @return Result.
238 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_characterCount(long * nCharacters)
240 SolarMutexGuard g;
242 ENTER_PROTECTED_BLOCK
244 if (nCharacters == nullptr)
245 return E_INVALIDARG;
246 // #CHECK XInterface#
247 if(!pRXText.is())
249 *nCharacters = 0;
250 return S_OK;
253 *nCharacters = GetXInterface()->getCharacterCount();
254 return S_OK;
256 LEAVE_PROTECTED_BLOCK
260 * Get character extents.
261 * @param offset Offset.
262 * @param x Variant to accept x position.
263 * @param y Variant to accept y position.
264 * @param width Variant to accept width.
265 * @param Height Variant to accept height.
266 * @return Result.
268 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_characterExtents(long offset, IA2CoordinateType coordType, long * x, long * y, long * width, long * height)
270 SolarMutexGuard g;
272 ENTER_PROTECTED_BLOCK
274 if (x == nullptr || height == nullptr || y == nullptr || width == nullptr)
275 return E_INVALIDARG;
276 // #CHECK XInterface#
277 if(!pRXText.is())
278 return E_FAIL;
280 if(offset < 0 || offset > GetXInterface()->getCharacterCount() )
281 return E_FAIL;
283 css::awt::Rectangle rectangle;
284 rectangle = GetXInterface()->getCharacterBounds(offset);
286 //IA2Point aPoint;
287 css::awt::Point aPoint;
289 Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext();
290 if( !pRContext.is() )
292 return E_FAIL;
294 Reference<XAccessibleComponent> pRComp(pRContext,UNO_QUERY);
295 if( pRComp.is() )
297 if(coordType == IA2_COORDTYPE_SCREEN_RELATIVE)
299 css::awt::Point pt = pRComp->getLocationOnScreen();
300 aPoint.X = pt.X;
301 aPoint.Y = pt.Y;
303 else if(coordType == IA2_COORDTYPE_PARENT_RELATIVE)
305 css::awt::Point pt = pRComp->getLocation();
306 aPoint.X = pt.X;
307 aPoint.Y = pt.Y;
310 rectangle.X = rectangle.X + aPoint.X;
311 rectangle.Y = rectangle.Y + aPoint.Y;
313 *x = rectangle.X;
314 *y = rectangle.Y;
316 // GetXInterface()->getCharacterBounds() have different implement in different acc component
317 // But we need return the width/height == 1 for every component when offset == text length.
318 // So we ignore the return result of GetXInterface()->getCharacterBounds() when offset == text length.
319 if( offset == GetXInterface()->getCharacterCount() )
321 *width = 1;
322 *height = 1;
324 else
326 *width = rectangle.Width;
327 *height = rectangle.Height;
330 return S_OK;
332 LEAVE_PROTECTED_BLOCK
336 * Get selections count.
337 * @param nSelections Variant to accept selections count.
338 * @return Result.
340 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_nSelections(long * nSelections)
342 SolarMutexGuard g;
344 ENTER_PROTECTED_BLOCK
346 if (nSelections == nullptr)
347 return E_INVALIDARG;
348 // #CHECK XInterface#
349 if(pUNOInterface == nullptr)
351 *nSelections = 0;
352 return S_OK;
355 Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext();
357 Reference< XAccessibleTextSelection > pRExtension(pRContext,UNO_QUERY);
359 if( pRExtension.is() )
361 *nSelections = pRExtension->getSelectedPortionCount();
362 return S_OK;
365 long iLength = GetXInterface()->getSelectedText().getLength();
366 if( iLength> 0)
368 *nSelections = 1;
369 return S_OK;
372 *nSelections = 0;
373 return S_OK;
375 LEAVE_PROTECTED_BLOCK
379 * Get offset of some special point.
380 * @param x X position of one point.
381 * @param x Y position of one point.
382 * @param coordType Type.
383 * @param offset Variant to accept offset.
384 * @return Result.
386 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_offsetAtPoint(long x, long y, IA2CoordinateType, long * offset)
388 SolarMutexGuard g;
390 ENTER_PROTECTED_BLOCK
392 if (offset == nullptr)
393 return E_INVALIDARG;
394 // #CHECK XInterface#
395 if(!pRXText.is())
396 return E_FAIL;
398 css::awt::Point point;
399 point.X = x;
400 point.Y = y;
401 *offset = GetXInterface()->getIndexAtPoint(point);
402 return S_OK;
404 LEAVE_PROTECTED_BLOCK
408 * Get selection range.
409 * @param selection selection count.
410 * @param startOffset Variant to accept the start offset of special selection.
411 * @param endOffset Variant to accept the end offset of special selection.
412 * @return Result.
415 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_selection(long selectionIndex, long * startOffset, long * endOffset)
417 SolarMutexGuard g;
419 ENTER_PROTECTED_BLOCK
421 if (startOffset == nullptr || endOffset == nullptr )
422 return E_INVALIDARG;
423 // #CHECK XInterface#
424 if(pUNOInterface == nullptr )
425 return E_FAIL;
427 long nSelection = 0;
428 get_nSelections(&nSelection);
430 if(selectionIndex >= nSelection || selectionIndex < 0 )
431 return E_FAIL;
433 Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext();
435 Reference< XAccessibleTextSelection > pRExtension(pRContext,UNO_QUERY);
437 if( pRExtension.is() )
439 *startOffset = pRExtension->getSeletedPositionStart(selectionIndex);
440 *endOffset = pRExtension->getSeletedPositionEnd(selectionIndex);
441 return S_OK;
443 else if(GetXInterface()->getSelectionEnd() > -1)
445 *startOffset = GetXInterface()->getSelectionStart();
446 *endOffset = GetXInterface()->getSelectionEnd();
447 return S_OK;
450 *startOffset = 0;
451 *endOffset = 0;
452 return E_FAIL;
454 LEAVE_PROTECTED_BLOCK
458 * Get special text.
459 * @param startOffset Start position of special range.
460 * @param endOffset End position of special range.
461 * @param text Variant to accept the text of special range.
462 * @return Result.
464 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_text(long startOffset, long endOffset, BSTR * text)
466 SolarMutexGuard g;
468 ENTER_PROTECTED_BLOCK
470 if (text == nullptr)
471 return E_INVALIDARG;
472 // #CHECK XInterface#
473 if(!pRXText.is())
474 return E_FAIL;
476 if (endOffset < -1 || endOffset < startOffset )
478 return E_FAIL;
481 OUString ouStr;
482 if (endOffset == -1 )
484 long nLen=0;
485 if(SUCCEEDED(get_characterCount(&nLen)))
487 ouStr = GetXInterface()->getTextRange( 0, nLen );
490 else
492 ouStr = GetXInterface()->getTextRange( startOffset, endOffset );
495 SysFreeString(*text);
496 *text = SysAllocString(o3tl::toW(ouStr.getStr()));
497 return S_OK;
499 LEAVE_PROTECTED_BLOCK
503 * Get special text before some position.
504 * @param offset Special position.
505 * @param boundaryType Boundary type.
506 * @param startOffset Variant to accept the start offset.
507 * @param endOffset Variant to accept the end offset.
508 * @param text Variant to accept the special text.
509 * @return Result.
511 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_textBeforeOffset(long offset, IA2TextBoundaryType boundaryType, long * startOffset, long * endOffset, BSTR * text)
513 SolarMutexGuard g;
515 ENTER_PROTECTED_BLOCK
517 // #CHECK#
518 if (startOffset == nullptr || endOffset == nullptr || text == nullptr)
519 return E_INVALIDARG;
520 // #CHECK XInterface#
521 if(!pRXText.is())
522 return E_FAIL;
524 // In New UNO IAccessibleText.idl these constant values are defined as follows:
526 // const long TEXT_BOUNDARY_CHAR = -1;
527 // const long TEXT_BOUNDARY_TO_CURSOR_POS = -2;
528 // const long TEXT_BOUNDARY_START_OF_WORD = -3;
529 // const long TEXT_BOUNDARY_END_OF_WORD = -4;
530 // const long TEXT_BOUNDARY_START_OF_SENTENCE = -5;
531 // const long TEXT_BOUNDARY_END_OF_SENTENCE = -6;
532 // const long TEXT_BOUNDARY_START_OF_LINE = -7;
533 // const long TEXT_BOUNDARY_END_OF_LINE = -8;
535 // In UNO, the corresponding values are as follows:
537 // const short CHARACTER = 1;
538 // const short WORD = 2;
539 // const short SENTENCE = 3;
540 // const short PARAGRAPH = 4;
541 // const short LINE = 5;
542 // const short GLYPH = 6;
543 // const short ATTRIBUTE_RUN = 7;
546 long lUnoBoundaryType;
548 switch(boundaryType)
550 case IA2_TEXT_BOUNDARY_CHAR:
551 lUnoBoundaryType = 1; // CHARACTER;
552 break;
553 case IA2_TEXT_BOUNDARY_WORD:
554 lUnoBoundaryType = 2; // WORD;
555 break;
556 case IA2_TEXT_BOUNDARY_SENTENCE:
557 lUnoBoundaryType = 3; // SENTENCE;
558 break;
559 case IA2_TEXT_BOUNDARY_LINE:
560 lUnoBoundaryType = 5; // LINE;
561 break;
562 case IA2_TEXT_BOUNDARY_PARAGRAPH:
563 lUnoBoundaryType = 4;
564 break;
565 case IA2_TEXT_BOUNDARY_ALL:
567 long nChar;
568 get_nCharacters( &nChar );
569 *startOffset = 0;
570 *endOffset = nChar;
571 return get_text(0, nChar, text);
573 break;
574 default:
575 return E_FAIL;
578 TextSegment segment = GetXInterface()->getTextBeforeIndex( offset, sal_Int16(lUnoBoundaryType));
579 OUString ouStr = segment.SegmentText;
580 SysFreeString(*text);
581 *text = SysAllocString(o3tl::toW(ouStr.getStr()));
582 *startOffset = segment.SegmentStart;
583 *endOffset = segment.SegmentEnd;
585 return S_OK;
587 LEAVE_PROTECTED_BLOCK
591 * Get special text after some position.
592 * @param offset Special position.
593 * @param boundaryType Boundary type.
594 * @param startOffset Variant to accept the start offset.
595 * @param endOffset Variant to accept the end offset.
596 * @param text Variant to accept the special text.
597 * @return Result.
599 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_textAfterOffset(long offset, IA2TextBoundaryType boundaryType, long * startOffset, long * endOffset, BSTR * text)
601 SolarMutexGuard g;
603 ENTER_PROTECTED_BLOCK
605 if (startOffset == nullptr || endOffset == nullptr || text == nullptr)
606 return E_INVALIDARG;
607 // #CHECK XInterface#
608 if(!pRXText.is())
609 return E_FAIL;
611 // In New UNO IAccessibleText.idl these constant values are defined as follows:
613 // const long TEXT_BOUNDARY_CHAR = -1;
614 // const long TEXT_BOUNDARY_TO_CURSOR_POS = -2;
615 // const long TEXT_BOUNDARY_START_OF_WORD = -3;
616 // const long TEXT_BOUNDARY_END_OF_WORD = -4;
617 // const long TEXT_BOUNDARY_START_OF_SENTENCE = -5;
618 // const long TEXT_BOUNDARY_END_OF_SENTENCE = -6;
619 // const long TEXT_BOUNDARY_START_OF_LINE = -7;
620 // const long TEXT_BOUNDARY_END_OF_LINE = -8;
622 // In UNO, the corresponding values are as follows:
624 // const short CHARACTER = 1;
625 // const short WORD = 2;
626 // const short SENTENCE = 3;
627 // const short PARAGRAPH = 4;
628 // const short LINE = 5;
629 // const short GLYPH = 6;
630 // const short ATTRIBUTE_RUN = 7;
633 long lUnoBoundaryType;
634 switch(boundaryType)
636 case IA2_TEXT_BOUNDARY_CHAR:
637 lUnoBoundaryType = 1; // CHARACTER;
638 break;
639 case IA2_TEXT_BOUNDARY_WORD:
640 lUnoBoundaryType = 2; // WORD;
641 break;
642 case IA2_TEXT_BOUNDARY_SENTENCE:
643 lUnoBoundaryType = 3; // SENTENCE;
644 break;
645 case IA2_TEXT_BOUNDARY_LINE:
646 lUnoBoundaryType = 5; // LINE;
647 break;
648 case IA2_TEXT_BOUNDARY_PARAGRAPH:
649 lUnoBoundaryType = 4;
650 break;
651 case IA2_TEXT_BOUNDARY_ALL:
653 long nChar;
654 get_nCharacters( &nChar );
655 *startOffset = 0;
656 *endOffset = nChar;
657 return get_text(0, nChar, text);
659 break;
660 default:
661 return E_FAIL;
664 TextSegment segment = GetXInterface()->getTextBehindIndex( offset, sal_Int16(lUnoBoundaryType));
665 OUString ouStr = segment.SegmentText;
666 SysFreeString(*text);
667 *text = SysAllocString(o3tl::toW(ouStr.getStr()));
668 *startOffset = segment.SegmentStart;
669 *endOffset = segment.SegmentEnd;
671 return S_OK;
673 LEAVE_PROTECTED_BLOCK
677 * Get special text at some position.
678 * @param offset Special position.
679 * @param boundaryType Boundary type.
680 * @param startOffset Variant to accept the start offset.
681 * @param endOffset Variant to accept the end offset.
682 * @param text Variant to accept the special text.
683 * @return Result.
685 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_textAtOffset(long offset, IA2TextBoundaryType boundaryType, long * startOffset, long * endOffset, BSTR * text)
687 SolarMutexGuard g;
689 ENTER_PROTECTED_BLOCK
691 if (startOffset == nullptr || text == nullptr ||endOffset == nullptr)
692 return E_INVALIDARG;
693 // #CHECK XInterface#
694 if(!pRXText.is())
695 return E_FAIL;
697 // In New UNO IAccessibleText.idl these constant values are defined as follows:
699 // const long TEXT_BOUNDARY_CHAR = -1;
700 // const long TEXT_BOUNDARY_TO_CURSOR_POS = -2;
701 // const long TEXT_BOUNDARY_START_OF_WORD = -3;
702 // const long TEXT_BOUNDARY_END_OF_WORD = -4;
703 // const long TEXT_BOUNDARY_START_OF_SENTENCE = -5;
704 // const long TEXT_BOUNDARY_END_OF_SENTENCE = -6;
705 // const long TEXT_BOUNDARY_START_OF_LINE = -7;
706 // const long TEXT_BOUNDARY_END_OF_LINE = -8;
708 // In UNO, the corresponding values are as follows:
710 // const short CHARACTER = 1;
711 // const short WORD = 2;
712 // const short SENTENCE = 3;
713 // const short PARAGRAPH = 4;
714 // const short LINE = 5;
715 // const short GLYPH = 6;
716 // const short ATTRIBUTE_RUN = 7;
719 long lUnoBoundaryType;
721 switch(boundaryType)
723 case IA2_TEXT_BOUNDARY_CHAR:
724 lUnoBoundaryType = 1; // CHARACTER;
725 break;
726 case IA2_TEXT_BOUNDARY_WORD:
727 lUnoBoundaryType = 2; // WORD;
728 break;
729 case IA2_TEXT_BOUNDARY_SENTENCE:
730 lUnoBoundaryType = 3; // SENTENCE;
731 break;
732 case IA2_TEXT_BOUNDARY_LINE:
733 lUnoBoundaryType = 5; // LINE;
734 break;
735 case IA2_TEXT_BOUNDARY_PARAGRAPH:
736 lUnoBoundaryType = 4;
737 break;
738 case IA2_TEXT_BOUNDARY_ALL:
740 long nChar;
741 get_nCharacters( &nChar );
742 *startOffset = 0;
743 *endOffset = nChar;
744 return get_text(0, nChar, text);
746 break;
747 default:
748 return E_FAIL;
751 TextSegment segment = GetXInterface()->getTextAtIndex( offset, sal_Int16(lUnoBoundaryType));
752 OUString ouStr = segment.SegmentText;
753 SysFreeString(*text);
754 *text = SysAllocString(o3tl::toW(ouStr.getStr()));
755 *startOffset = segment.SegmentStart;
756 *endOffset = segment.SegmentEnd;
758 return S_OK;
760 LEAVE_PROTECTED_BLOCK
764 * Remove selection.
765 * @param selectionIndex Special selection index
766 * @param success Variant to accept the memthod called result.
767 * @return Result.
769 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::removeSelection(long selectionIndex)
771 SolarMutexGuard g;
773 ENTER_PROTECTED_BLOCK
775 // #CHECK XInterface#
776 if(pUNOInterface == nullptr)
778 return E_FAIL;
781 Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext();
783 Reference< XAccessibleTextSelection > pRExtension(pRContext,UNO_QUERY);
785 if( pRExtension.is() )
787 pRExtension->removeSelection(selectionIndex);
788 return S_OK;
790 else
792 GetXInterface()->setSelection(0, 0);
793 return S_OK;
796 LEAVE_PROTECTED_BLOCK
800 * Set caret position.
801 * @param offset Special position.
802 * @param success Variant to accept the memthod called result.
803 * @return Result.
805 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::setCaretOffset(long offset)
807 SolarMutexGuard g;
809 ENTER_PROTECTED_BLOCK
811 // #CHECK XInterface#
812 if(!pRXText.is())
813 return E_FAIL;
815 GetXInterface()->setCaretPosition( offset);
817 return S_OK;
819 LEAVE_PROTECTED_BLOCK
823 * Set special selection.
824 * @param selectionIndex Special selection index.
825 * @param startOffset start position.
826 * @param endOffset end position.
827 * @param success Variant to accept the memthod called result.
828 * @return Result.
830 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::setSelection(long, long startOffset, long endOffset)
832 SolarMutexGuard g;
834 ENTER_PROTECTED_BLOCK
836 // #CHECK XInterface#
837 if(!pRXText.is())
839 return E_FAIL;
842 GetXInterface()->setSelection( startOffset, endOffset );
844 return S_OK;
846 LEAVE_PROTECTED_BLOCK
850 * Get characters count.
851 * @param nCharacters Variant to accept the characters count.
852 * @return Result.
854 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_nCharacters(long * nCharacters)
856 SolarMutexGuard g;
858 ENTER_PROTECTED_BLOCK
860 if (nCharacters == nullptr)
861 return E_INVALIDARG;
862 // #CHECK XInterface#
863 if(!pRXText.is())
865 *nCharacters = 0;
866 return S_OK;
869 *nCharacters = GetXInterface()->getCharacterCount();
871 return S_OK;
873 LEAVE_PROTECTED_BLOCK
876 // added by qiuhd, 2006/07/03, for direver 07/11
877 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_newText( IA2TextSegment *)
879 return E_NOTIMPL;
882 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_oldText( IA2TextSegment *)
884 return E_NOTIMPL;
888 * Scroll to special sub-string .
889 * @param startIndex Start index of sub string.
890 * @param endIndex End index of sub string.
891 * @return Result.
893 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::scrollSubstringToPoint(long, long, IA2CoordinateType, long, long )
895 return E_NOTIMPL;
898 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::scrollSubstringTo(long, long, IA2ScrollType)
900 return E_NOTIMPL;
904 * Put UNO interface.
905 * @param pXInterface UNO interface.
906 * @return Result.
908 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::put_XInterface(hyper pXInterface)
910 // internal IUNOXWrapper - no mutex meeded
912 ENTER_PROTECTED_BLOCK
914 CUNOXWrapper::put_XInterface(pXInterface);
915 //special query.
916 if(pUNOInterface == nullptr)
917 return E_FAIL;
918 Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext();
919 if( !pRContext.is() )
921 return E_FAIL;
923 Reference<XAccessibleText> pRXI(pRContext,UNO_QUERY);
924 if( !pRXI.is() )
925 pRXText = nullptr;
926 else
927 pRXText = pRXI;
928 return S_OK;
930 LEAVE_PROTECTED_BLOCK
933 static OUString ReplaceOneChar(OUString const & oldOUString, OUString const & replacedChar, OUString const & replaceStr)
935 auto s = oldOUString;
936 int iReplace = s.lastIndexOf(replacedChar);
937 if (iReplace > -1)
939 for(;iReplace>-1;)
941 s = s.replaceAt(iReplace,1, replaceStr);
942 iReplace=s.lastIndexOf(replacedChar,iReplace);
945 return s;
948 static OUString ReplaceFourChar(OUString const & oldOUString)
950 auto s = oldOUString;
951 s = ReplaceOneChar(s, "\\", "\\\\");
952 s = ReplaceOneChar(s, ";", "\\;");
953 s = ReplaceOneChar(s, "=", "\\=");
954 s = ReplaceOneChar(s, ",", "\\,");
955 s = ReplaceOneChar(s, ":", "\\:");
956 return s;
959 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */