bump product version to 5.0.4.1
[LibreOffice.git] / winaccessibility / source / UAccCOM / AccTextBase.cxx
blob156ef30c21ebca1ddd86f0e8886b2f49db5908fb
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"
24 #include <string>
26 #include "AccTextBase.h"
28 #include <vcl/svapp.hxx>
30 #include <com/sun/star/accessibility/AccessibleTextType.hpp>
31 #include <com/sun/star/accessibility/XAccessible.hpp>
32 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
33 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
34 #include <com/sun/star/accessibility/XAccessibleTextSelection.hpp>
35 #include "MAccessible.h"
37 using namespace com::sun::star::accessibility;
38 using namespace com::sun::star::uno;
41 // Construction/Destruction
44 static OUString ReplaceFourChar(OUString oldOUString);
46 CAccTextBase::CAccTextBase()
49 CAccTextBase::~CAccTextBase()
53 /**
54 * Get special selection.
55 * @param startOffset Start selection offset.
56 * @param endOffset End selection offset.
57 * @param success Variant to accept the result of if the method call is successful.
58 * @return Result.
60 STDMETHODIMP CAccTextBase::get_addSelection(long startOffset, long endOffset)
62 SolarMutexGuard g;
64 ENTER_PROTECTED_BLOCK
66 // #CHECK XInterface#
67 if(pUNOInterface == NULL)
68 return E_FAIL;
70 Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext();
72 Reference< XAccessibleTextSelection > pRExtension(pRContext,UNO_QUERY);
74 if( pRExtension.is() )
76 pRExtension->addSelection(0, startOffset, endOffset);
77 return S_OK;
79 else
81 GetXInterface()->setSelection(startOffset, endOffset);
82 return S_OK;
85 LEAVE_PROTECTED_BLOCK
88 /**
89 * Get special attributes.
90 * @param offset Offset.
91 * @param startOffset Variant to accept start offset.
92 * @param endOffset Variant to accept end offset.
93 * @param textAttributes Variant to accept attributes.
94 * @return Result.
96 STDMETHODIMP CAccTextBase::get_attributes(long offset, long * startOffset, long * endOffset, BSTR * textAttributes)
98 SolarMutexGuard g;
100 ENTER_PROTECTED_BLOCK
102 if (startOffset == NULL || endOffset == NULL || textAttributes == NULL)
103 return E_INVALIDARG;
104 // #CHECK XInterface#
105 if(!pRXText.is())
107 return E_FAIL;
110 if( offset < 0 || offset > GetXInterface()->getCharacterCount() )
111 return E_FAIL;
113 std::wstring strAttrs;
115 strAttrs += L"Version:1;";
117 Sequence< ::com::sun::star::beans::PropertyValue > pValues = GetXInterface()->getCharacterAttributes(offset, Sequence< rtl::OUString >());
118 int nCount = pValues.getLength();
120 short numberingLevel = 0;
121 OUString numberingPrefix;
122 Any anyNumRule;
123 bool bHaveNumberingPrefixAttr = false;
124 bool bHaveNumberingLevel = false;
125 bool bHaveNumberingRules = false;
126 for(int i =0; i<nCount; i++)
129 ::com::sun::star::beans::PropertyValue &pValue = pValues[i];
130 if(pValue.Name == "NumberingLevel")
132 if (pValue.Value != Any())
133 pValue.Value >>= numberingLevel;
134 else
135 numberingLevel = -1;
136 bHaveNumberingLevel = true;
137 continue;
139 if(pValue.Name == "NumberingPrefix")
141 pValue.Value >>=numberingPrefix;
142 bHaveNumberingPrefixAttr = true;
143 continue;
145 if(pValue.Name == "NumberingRules")
147 bHaveNumberingRules = true;
148 anyNumRule = pValue.Value;
149 continue;
151 if (bHaveNumberingLevel && bHaveNumberingRules && bHaveNumberingPrefixAttr)
153 OLECHAR numProps[512] = {0};
154 strAttrs+=L";";
155 numberingPrefix = ReplaceFourChar(numberingPrefix);
156 CMAccessible::get_OLECHAR4Numbering(anyNumRule,numberingLevel,numberingPrefix,numProps);
157 strAttrs += numProps;
158 bHaveNumberingLevel = 0;
159 bHaveNumberingRules = 0;
161 if( (bHaveNumberingPrefixAttr && i > 1 ) ||
162 (!bHaveNumberingPrefixAttr && i > 0 ) ) //element 0 is NumberingPrefix, not write alone
164 strAttrs+=L";";
166 strAttrs += pValue.Name.getStr();
167 strAttrs += L":";
169 OLECHAR pTemp[2048] = {0};
171 if (pValue.Name == "CharBackColor" ||
172 pValue.Name == "CharColor" ||
173 pValue.Name == "CharUnderlineColor" )
175 unsigned long nColor;
176 pValue.Value >>= nColor;
177 OLECHAR pBuf[64];
178 swprintf( pBuf, L"%08X", nColor );
179 pTemp[0]=L'#';
180 wcscat( pTemp, pBuf );
183 else
185 CMAccessible::get_OLECHARFromAny(pValue.Value,pTemp);
188 strAttrs +=pTemp;
190 strAttrs +=L";";
191 // #CHECK#
192 if(*textAttributes)
193 SysFreeString(*textAttributes);
194 *textAttributes = SysAllocString(strAttrs.c_str());
196 if( offset < GetXInterface()->getCharacterCount() )
198 TextSegment textSeg = GetXInterface()->getTextAtIndex(offset, AccessibleTextType::ATTRIBUTE_RUN);
199 *startOffset = textSeg.SegmentStart;
200 *endOffset = textSeg.SegmentEnd;
202 else
204 *startOffset = offset;
205 *endOffset = offset;
208 return S_OK;
210 LEAVE_PROTECTED_BLOCK
214 * Get caret position.
215 * @param offset Variant to accept caret offset.
216 * @return Result.
218 STDMETHODIMP CAccTextBase::get_caretOffset(long * offset)
220 SolarMutexGuard g;
222 ENTER_PROTECTED_BLOCK
224 if (offset == NULL)
225 return E_INVALIDARG;
226 // #CHECK XInterface#
227 if(!pRXText.is())
229 *offset = 0;
230 return S_OK;
233 *offset = GetXInterface()->getCaretPosition();
234 return S_OK;
236 LEAVE_PROTECTED_BLOCK
240 * Get character count.
241 * @param nCharacters Variant to accept character count.
242 * @return Result.
244 STDMETHODIMP CAccTextBase::get_characterCount(long * nCharacters)
246 SolarMutexGuard g;
248 ENTER_PROTECTED_BLOCK
250 if (nCharacters == NULL)
251 return E_INVALIDARG;
252 // #CHECK XInterface#
253 if(!pRXText.is())
255 *nCharacters = 0;
256 return S_OK;
259 *nCharacters = GetXInterface()->getCharacterCount();
260 return S_OK;
262 LEAVE_PROTECTED_BLOCK
266 * Get character extents.
267 * @param offset Offset.
268 * @param x Variant to accept x position.
269 * @param y Variant to accept y position.
270 * @param width Variant to accept width.
271 * @param Height Variant to accept height.
272 * @return Result.
274 STDMETHODIMP CAccTextBase::get_characterExtents(long offset, IA2CoordinateType coordType, long * x, long * y, long * width, long * height)
276 SolarMutexGuard g;
278 ENTER_PROTECTED_BLOCK
280 if (x == NULL || height == NULL || y == NULL || width == NULL)
281 return E_INVALIDARG;
282 // #CHECK XInterface#
283 if(!pRXText.is())
284 return E_FAIL;
286 if(offset < 0 || offset > GetXInterface()->getCharacterCount() )
287 return E_FAIL;
289 com::sun::star::awt::Rectangle rectangle;
290 rectangle = GetXInterface()->getCharacterBounds(offset);
292 //IA2Point aPoint;
293 com::sun::star::awt::Point aPoint;
295 Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext();
296 if( !pRContext.is() )
298 return E_FAIL;
300 Reference<XAccessibleComponent> pRComp(pRContext,UNO_QUERY);
301 if( pRComp.is() )
303 if(coordType == IA2_COORDTYPE_SCREEN_RELATIVE)
305 ::com::sun::star::awt::Point pt = pRComp->getLocationOnScreen();
306 aPoint.X = pt.X;
307 aPoint.Y = pt.Y;
309 else if(coordType == IA2_COORDTYPE_PARENT_RELATIVE)
311 ::com::sun::star::awt::Point pt = pRComp->getLocation();
312 aPoint.X = pt.X;
313 aPoint.Y = pt.Y;
316 rectangle.X = rectangle.X + aPoint.X;
317 rectangle.Y = rectangle.Y + aPoint.Y;
319 *x = rectangle.X;
320 *y = rectangle.Y;
322 // GetXInterface()->getCharacterBounds() have different implement in different acc component
323 // But we need return the width/height == 1 for every component when offset == text length.
324 // So we ignore the return result of GetXInterface()->getCharacterBounds() when offset == text length.
325 if( offset == GetXInterface()->getCharacterCount() )
327 *width = 1;
328 *height = 1;
330 else
332 *width = rectangle.Width;
333 *height = rectangle.Height;
336 return S_OK;
338 LEAVE_PROTECTED_BLOCK
342 * Get selections count.
343 * @param nSelections Variant to accept selections count.
344 * @return Result.
346 STDMETHODIMP CAccTextBase::get_nSelections(long * nSelections)
348 SolarMutexGuard g;
350 ENTER_PROTECTED_BLOCK
352 if (nSelections == NULL)
353 return E_INVALIDARG;
354 // #CHECK XInterface#
355 if(pUNOInterface == NULL)
357 *nSelections = 0;
358 return S_OK;
361 Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext();
363 Reference< XAccessibleTextSelection > pRExtension(pRContext,UNO_QUERY);
365 if( pRExtension.is() )
367 *nSelections = pRExtension->getSelectedPortionCount();
368 return S_OK;
371 long iLength = GetXInterface()->getSelectedText().getLength();
372 if( iLength> 0)
374 *nSelections = 1;
375 return S_OK;
378 *nSelections = 0;
379 return S_OK;
381 LEAVE_PROTECTED_BLOCK
385 * Get offset of some special point.
386 * @param x X position of one point.
387 * @param x Y position of one point.
388 * @param coordType Type.
389 * @param offset Variant to accept offset.
390 * @return Result.
392 STDMETHODIMP CAccTextBase::get_offsetAtPoint(long x, long y, IA2CoordinateType, long * offset)
394 SolarMutexGuard g;
396 ENTER_PROTECTED_BLOCK
398 if (offset == NULL)
399 return E_INVALIDARG;
400 // #CHECK XInterface#
401 if(!pRXText.is())
402 return E_FAIL;
404 com::sun::star::awt::Point point;
405 point.X = x;
406 point.Y = y;
407 *offset = GetXInterface()->getIndexAtPoint(point);
408 return S_OK;
410 LEAVE_PROTECTED_BLOCK
414 * Get selection range.
415 * @param selection selection count.
416 * @param startOffset Variant to accept the start offset of special selection.
417 * @param endOffset Variant to accept the end offset of special selection.
418 * @return Result.
421 STDMETHODIMP CAccTextBase::get_selection(long selectionIndex, long * startOffset, long * endOffset)
423 SolarMutexGuard g;
425 ENTER_PROTECTED_BLOCK
427 if (startOffset == NULL || endOffset == NULL )
428 return E_INVALIDARG;
429 // #CHECK XInterface#
430 if(pUNOInterface == NULL )
431 return E_FAIL;
433 long nSelection = 0;
434 get_nSelections(&nSelection);
436 if(selectionIndex >= nSelection || selectionIndex < 0 )
437 return E_FAIL;
439 Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext();
441 Reference< XAccessibleTextSelection > pRExtension(pRContext,UNO_QUERY);
443 if( pRExtension.is() )
445 *startOffset = pRExtension->getSeletedPositionStart(selectionIndex);
446 *endOffset = pRExtension->getSeletedPositionEnd(selectionIndex);
447 return S_OK;
449 else if(GetXInterface()->getSelectionEnd() > -1)
451 *startOffset = GetXInterface()->getSelectionStart();
452 *endOffset = GetXInterface()->getSelectionEnd();
453 return S_OK;
456 *startOffset = 0;
457 *endOffset = 0;
458 return E_FAIL;
460 LEAVE_PROTECTED_BLOCK
464 * Get special text.
465 * @param startOffset Start position of special range.
466 * @param endOffset End position of special range.
467 * @param text Variant to accept the text of special range.
468 * @return Result.
470 STDMETHODIMP CAccTextBase::get_text(long startOffset, long endOffset, BSTR * text)
472 SolarMutexGuard g;
474 ENTER_PROTECTED_BLOCK
476 if (text == NULL)
477 return E_INVALIDARG;
478 // #CHECK XInterface#
479 if(!pRXText.is())
480 return E_FAIL;
482 if (endOffset < -1 || endOffset < startOffset )
484 return E_FAIL;
487 ::rtl::OUString ouStr;
488 if (endOffset == -1 )
490 long nLen=0;
491 if(SUCCEEDED(get_characterCount(&nLen)))
493 ouStr = GetXInterface()->getTextRange( 0, nLen );
496 else
498 ouStr = GetXInterface()->getTextRange( startOffset, endOffset );
501 SysFreeString(*text);
502 *text = SysAllocString((OLECHAR*)ouStr.getStr());
503 return S_OK;
505 LEAVE_PROTECTED_BLOCK
509 * Get special text before some position.
510 * @param offset Special position.
511 * @param boundaryType Boundary type.
512 * @param startOffset Variant to accept the start offset.
513 * @param endOffset Variant to accept the end offset.
514 * @param text Variant to accept the special text.
515 * @return Result.
517 STDMETHODIMP CAccTextBase::get_textBeforeOffset(long offset, IA2TextBoundaryType boundaryType, long * startOffset, long * endOffset, BSTR * text)
519 SolarMutexGuard g;
521 ENTER_PROTECTED_BLOCK
523 // #CHECK#
524 if (startOffset == NULL || endOffset == NULL || text == NULL)
525 return E_INVALIDARG;
526 // #CHECK XInterface#
527 if(!pRXText.is())
528 return E_FAIL;
530 // In New UNO IAccessibleText.idl these constant values are defined as follows:
532 // const long TEXT_BOUNDARY_CHAR = -1;
533 // const long TEXT_BOUNDARY_TO_CURSOR_POS = -2;
534 // const long TEXT_BOUNDARY_START_OF_WORD = -3;
535 // const long TEXT_BOUNDARY_END_OF_WORD = -4;
536 // const long TEXT_BOUNDARY_START_OF_SENTENCE = -5;
537 // const long TEXT_BOUNDARY_END_OF_SENTENCE = -6;
538 // const long TEXT_BOUNDARY_START_OF_LINE = -7;
539 // const long TEXT_BOUNDARY_END_OF_LINE = -8;
541 // In UNO, the corresponding values are as follows:
543 // const short CHARACTER = 1;
544 // const short WORD = 2;
545 // const short SENTENCE = 3;
546 // const short PARAGRAPH = 4;
547 // const short LINE = 5;
548 // const short GLYPH = 6;
549 // const short ATTRIBUTE_RUN = 7;
552 long lUnoBoundaryType;
554 switch(boundaryType)
556 case IA2_TEXT_BOUNDARY_CHAR:
557 lUnoBoundaryType = 1; // CHARACTER;
558 break;
559 case IA2_TEXT_BOUNDARY_WORD:
560 lUnoBoundaryType = 2; // WORD;
561 break;
562 case IA2_TEXT_BOUNDARY_SENTENCE:
563 lUnoBoundaryType = 3; // SENTENCE;
564 break;
565 case IA2_TEXT_BOUNDARY_LINE:
566 lUnoBoundaryType = 5; // LINE;
567 break;
568 case IA2_TEXT_BOUNDARY_PARAGRAPH:
569 lUnoBoundaryType = 4;
570 break;
571 case IA2_TEXT_BOUNDARY_ALL:
573 long nChar;
574 get_nCharacters( &nChar );
575 *startOffset = 0;
576 *endOffset = nChar;
577 return get_text(0, nChar, text);
579 break;
580 default:
581 return E_FAIL;
584 TextSegment segment = GetXInterface()->getTextBeforeIndex( offset, sal_Int16(lUnoBoundaryType));
585 ::rtl::OUString ouStr = segment.SegmentText;
586 SysFreeString(*text);
587 *text = SysAllocString((OLECHAR*)ouStr.getStr());
588 *startOffset = segment.SegmentStart;
589 *endOffset = segment.SegmentEnd;
591 return S_OK;
593 LEAVE_PROTECTED_BLOCK
597 * Get special text after some position.
598 * @param offset Special position.
599 * @param boundaryType Boundary type.
600 * @param startOffset Variant to accept the start offset.
601 * @param endOffset Variant to accept the end offset.
602 * @param text Variant to accept the special text.
603 * @return Result.
605 STDMETHODIMP CAccTextBase::get_textAfterOffset(long offset, IA2TextBoundaryType boundaryType, long * startOffset, long * endOffset, BSTR * text)
607 SolarMutexGuard g;
609 ENTER_PROTECTED_BLOCK
611 if (startOffset == NULL || endOffset == NULL || text == NULL)
612 return E_INVALIDARG;
613 // #CHECK XInterface#
614 if(!pRXText.is())
615 return E_FAIL;
617 // In New UNO IAccessibleText.idl these constant values are defined as follows:
619 // const long TEXT_BOUNDARY_CHAR = -1;
620 // const long TEXT_BOUNDARY_TO_CURSOR_POS = -2;
621 // const long TEXT_BOUNDARY_START_OF_WORD = -3;
622 // const long TEXT_BOUNDARY_END_OF_WORD = -4;
623 // const long TEXT_BOUNDARY_START_OF_SENTENCE = -5;
624 // const long TEXT_BOUNDARY_END_OF_SENTENCE = -6;
625 // const long TEXT_BOUNDARY_START_OF_LINE = -7;
626 // const long TEXT_BOUNDARY_END_OF_LINE = -8;
628 // In UNO, the corresponding values are as follows:
630 // const short CHARACTER = 1;
631 // const short WORD = 2;
632 // const short SENTENCE = 3;
633 // const short PARAGRAPH = 4;
634 // const short LINE = 5;
635 // const short GLYPH = 6;
636 // const short ATTRIBUTE_RUN = 7;
639 long lUnoBoundaryType;
640 switch(boundaryType)
642 case IA2_TEXT_BOUNDARY_CHAR:
643 lUnoBoundaryType = 1; // CHARACTER;
644 break;
645 case IA2_TEXT_BOUNDARY_WORD:
646 lUnoBoundaryType = 2; // WORD;
647 break;
648 case IA2_TEXT_BOUNDARY_SENTENCE:
649 lUnoBoundaryType = 3; // SENTENCE;
650 break;
651 case IA2_TEXT_BOUNDARY_LINE:
652 lUnoBoundaryType = 5; // LINE;
653 break;
654 case IA2_TEXT_BOUNDARY_PARAGRAPH:
655 lUnoBoundaryType = 4;
656 break;
657 case IA2_TEXT_BOUNDARY_ALL:
659 long nChar;
660 get_nCharacters( &nChar );
661 *startOffset = 0;
662 *endOffset = nChar;
663 return get_text(0, nChar, text);
665 break;
666 default:
667 return E_FAIL;
670 TextSegment segment = GetXInterface()->getTextBehindIndex( offset, sal_Int16(lUnoBoundaryType));
671 ::rtl::OUString ouStr = segment.SegmentText;
672 SysFreeString(*text);
673 *text = SysAllocString((OLECHAR*)ouStr.getStr());
674 *startOffset = segment.SegmentStart;
675 *endOffset = segment.SegmentEnd;
677 return S_OK;
679 LEAVE_PROTECTED_BLOCK
683 * Get special text at some position.
684 * @param offset Special position.
685 * @param boundaryType Boundary type.
686 * @param startOffset Variant to accept the start offset.
687 * @param endOffset Variant to accept the end offset.
688 * @param text Variant to accept the special text.
689 * @return Result.
691 STDMETHODIMP CAccTextBase::get_textAtOffset(long offset, IA2TextBoundaryType boundaryType, long * startOffset, long * endOffset, BSTR * text)
693 SolarMutexGuard g;
695 ENTER_PROTECTED_BLOCK
697 if (startOffset == NULL || text == NULL ||endOffset == NULL)
698 return E_INVALIDARG;
699 // #CHECK XInterface#
700 if(!pRXText.is())
701 return E_FAIL;
703 // In New UNO IAccessibleText.idl these constant values are defined as follows:
705 // const long TEXT_BOUNDARY_CHAR = -1;
706 // const long TEXT_BOUNDARY_TO_CURSOR_POS = -2;
707 // const long TEXT_BOUNDARY_START_OF_WORD = -3;
708 // const long TEXT_BOUNDARY_END_OF_WORD = -4;
709 // const long TEXT_BOUNDARY_START_OF_SENTENCE = -5;
710 // const long TEXT_BOUNDARY_END_OF_SENTENCE = -6;
711 // const long TEXT_BOUNDARY_START_OF_LINE = -7;
712 // const long TEXT_BOUNDARY_END_OF_LINE = -8;
714 // In UNO, the corresponding values are as follows:
716 // const short CHARACTER = 1;
717 // const short WORD = 2;
718 // const short SENTENCE = 3;
719 // const short PARAGRAPH = 4;
720 // const short LINE = 5;
721 // const short GLYPH = 6;
722 // const short ATTRIBUTE_RUN = 7;
725 long lUnoBoundaryType;
727 switch(boundaryType)
729 case IA2_TEXT_BOUNDARY_CHAR:
730 lUnoBoundaryType = 1; // CHARACTER;
731 break;
732 case IA2_TEXT_BOUNDARY_WORD:
733 lUnoBoundaryType = 2; // WORD;
734 break;
735 case IA2_TEXT_BOUNDARY_SENTENCE:
736 lUnoBoundaryType = 3; // SENTENCE;
737 break;
738 case IA2_TEXT_BOUNDARY_LINE:
739 lUnoBoundaryType = 5; // LINE;
740 break;
741 case IA2_TEXT_BOUNDARY_PARAGRAPH:
742 lUnoBoundaryType = 4;
743 break;
744 case IA2_TEXT_BOUNDARY_ALL:
746 long nChar;
747 get_nCharacters( &nChar );
748 *startOffset = 0;
749 *endOffset = nChar;
750 return get_text(0, nChar, text);
752 break;
753 default:
754 return E_FAIL;
757 TextSegment segment = GetXInterface()->getTextAtIndex( offset, sal_Int16(lUnoBoundaryType));
758 ::rtl::OUString ouStr = segment.SegmentText;
759 SysFreeString(*text);
760 *text = SysAllocString((OLECHAR*)ouStr.getStr());
761 *startOffset = segment.SegmentStart;
762 *endOffset = segment.SegmentEnd;
764 return S_OK;
766 LEAVE_PROTECTED_BLOCK
770 * Remove selection.
771 * @param selectionIndex Special selection index
772 * @param success Variant to accept the memthod called result.
773 * @return Result.
775 STDMETHODIMP CAccTextBase::removeSelection(long selectionIndex)
777 SolarMutexGuard g;
779 ENTER_PROTECTED_BLOCK
781 // #CHECK XInterface#
782 if(pUNOInterface == NULL)
784 return E_FAIL;
787 Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext();
789 Reference< XAccessibleTextSelection > pRExtension(pRContext,UNO_QUERY);
791 if( pRExtension.is() )
793 pRExtension->removeSelection(selectionIndex);
794 return S_OK;
796 else
798 GetXInterface()->setSelection(0, 0);
799 return S_OK;
802 LEAVE_PROTECTED_BLOCK
806 * Set caret position.
807 * @param offset Special position.
808 * @param success Variant to accept the memthod called result.
809 * @return Result.
811 STDMETHODIMP CAccTextBase::setCaretOffset(long offset)
813 SolarMutexGuard g;
815 ENTER_PROTECTED_BLOCK
817 // #CHECK XInterface#
818 if(!pRXText.is())
819 return E_FAIL;
821 GetXInterface()->setCaretPosition( offset);
823 return S_OK;
825 LEAVE_PROTECTED_BLOCK
829 * Set special selection.
830 * @param selectionIndex Special selection index.
831 * @param startOffset start position.
832 * @param endOffset end position.
833 * @param success Variant to accept the memthod called result.
834 * @return Result.
836 STDMETHODIMP CAccTextBase::setSelection(long, long startOffset, long endOffset)
838 SolarMutexGuard g;
840 ENTER_PROTECTED_BLOCK
842 // #CHECK XInterface#
843 if(!pRXText.is())
845 return E_FAIL;
848 GetXInterface()->setSelection( startOffset, endOffset );
850 return S_OK;
852 LEAVE_PROTECTED_BLOCK
856 * Get characters count.
857 * @param nCharacters Variant to accept the characters count.
858 * @return Result.
860 STDMETHODIMP CAccTextBase::get_nCharacters(long * nCharacters)
862 SolarMutexGuard g;
864 ENTER_PROTECTED_BLOCK
866 if (nCharacters == NULL)
867 return E_INVALIDARG;
868 // #CHECK XInterface#
869 if(!pRXText.is())
871 *nCharacters = 0;
872 return S_OK;
875 *nCharacters = GetXInterface()->getCharacterCount();
877 return S_OK;
879 LEAVE_PROTECTED_BLOCK
882 // added by qiuhd, 2006/07/03, for direver 07/11
883 STDMETHODIMP CAccTextBase::get_newText( IA2TextSegment *)
885 return E_NOTIMPL;
888 STDMETHODIMP CAccTextBase::get_oldText( IA2TextSegment *)
890 return E_NOTIMPL;
894 * Scroll to special sub-string .
895 * @param startIndex Start index of sub string.
896 * @param endIndex End index of sub string.
897 * @return Result.
899 STDMETHODIMP CAccTextBase::scrollSubstringToPoint(long, long, IA2CoordinateType, long, long )
901 return E_NOTIMPL;
904 STDMETHODIMP CAccTextBase::scrollSubstringTo(long, long, IA2ScrollType)
906 return E_NOTIMPL;
910 * Put UNO interface.
911 * @param pXInterface UNO interface.
912 * @return Result.
914 STDMETHODIMP CAccTextBase::put_XInterface(hyper pXInterface)
916 // internal IUNOXWrapper - no mutex meeded
918 ENTER_PROTECTED_BLOCK
920 CUNOXWrapper::put_XInterface(pXInterface);
921 //special query.
922 if(pUNOInterface == NULL)
923 return E_FAIL;
924 Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext();
925 if( !pRContext.is() )
927 return E_FAIL;
929 Reference<XAccessibleText> pRXI(pRContext,UNO_QUERY);
930 if( !pRXI.is() )
931 pRXText = NULL;
932 else
933 pRXText = pRXI;
934 return S_OK;
936 LEAVE_PROTECTED_BLOCK
939 static OUString ReplaceOneChar(OUString oldOUString, OUString replacedChar, OUString replaceStr)
941 int iReplace = -1;
942 iReplace = oldOUString.lastIndexOf(replacedChar);
943 if (iReplace > -1)
945 for(;iReplace>-1;)
947 oldOUString = oldOUString.replaceAt(iReplace,1, replaceStr);
948 iReplace=oldOUString.lastIndexOf(replacedChar,iReplace);
951 return oldOUString;
954 static OUString ReplaceFourChar(OUString oldOUString)
956 oldOUString = ReplaceOneChar(oldOUString, OUString("\\"), OUString("\\\\"));
957 oldOUString = ReplaceOneChar(oldOUString, OUString(";"), OUString("\\;"));
958 oldOUString = ReplaceOneChar(oldOUString, OUString("="), OUString("\\="));
959 oldOUString = ReplaceOneChar(oldOUString, OUString(","), OUString("\\,"));
960 oldOUString = ReplaceOneChar(oldOUString, OUString(":"), OUString("\\:"));
961 return oldOUString;
964 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */