1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef INCLUDED_COMPHELPER_ACCESSIBLETEXTHELPER_HXX
21 #define INCLUDED_COMPHELPER_ACCESSIBLETEXTHELPER_HXX
23 #include <com/sun/star/accessibility/XAccessibleText.hpp>
24 #include <com/sun/star/accessibility/TextSegment.hpp>
25 #include <com/sun/star/i18n/XBreakIterator.hpp>
26 #include <com/sun/star/i18n/XCharacterClassification.hpp>
27 #include <comphelper/accessiblecomponenthelper.hxx>
28 #include <cppuhelper/implbase1.hxx>
29 #include <comphelper/comphelperdllapi.h>
36 // OCommonAccessibleText
38 /** base class encapsulating common functionality for the helper classes implementing
41 class COMPHELPER_DLLPUBLIC OCommonAccessibleText
44 css::uno::Reference
< css::i18n::XBreakIterator
> m_xBreakIter
;
45 css::uno::Reference
< css::i18n::XCharacterClassification
> m_xCharClass
;
48 OCommonAccessibleText();
49 virtual ~OCommonAccessibleText();
51 css::uno::Reference
< css::i18n::XBreakIterator
> const & implGetBreakIterator();
52 css::uno::Reference
< css::i18n::XCharacterClassification
> const & implGetCharacterClassification();
53 static bool implIsValidBoundary( css::i18n::Boundary
& rBoundary
, sal_Int32 nLength
);
54 static bool implIsValidIndex( sal_Int32 nIndex
, sal_Int32 nLength
);
55 static bool implIsValidRange( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
, sal_Int32 nLength
);
56 virtual OUString
implGetText() = 0;
57 virtual css::lang::Locale
implGetLocale() = 0;
58 virtual void implGetSelection( sal_Int32
& nStartIndex
, sal_Int32
& nEndIndex
) = 0;
59 void implGetGlyphBoundary( css::i18n::Boundary
& rBoundary
, sal_Int32 nIndex
);
60 bool implGetWordBoundary( css::i18n::Boundary
& rBoundary
, sal_Int32 nIndex
);
61 void implGetSentenceBoundary( css::i18n::Boundary
& rBoundary
, sal_Int32 nIndex
);
62 virtual void implGetParagraphBoundary( css::i18n::Boundary
& rBoundary
, sal_Int32 nIndex
);
63 virtual void implGetLineBoundary( css::i18n::Boundary
& rBoundary
, sal_Int32 nIndex
);
65 /** non-virtual versions of the methods
67 sal_Unicode SAL_CALL
getCharacter( sal_Int32 nIndex
) throw (css::lang::IndexOutOfBoundsException
, css::uno::RuntimeException
);
68 sal_Int32 SAL_CALL
getCharacterCount() throw (css::uno::RuntimeException
);
69 OUString SAL_CALL
getSelectedText() throw (css::uno::RuntimeException
);
70 sal_Int32 SAL_CALL
getSelectionStart() throw (css::uno::RuntimeException
);
71 sal_Int32 SAL_CALL
getSelectionEnd() throw (css::uno::RuntimeException
);
72 OUString SAL_CALL
getText() throw (css::uno::RuntimeException
);
73 OUString SAL_CALL
getTextRange( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) throw (css::lang::IndexOutOfBoundsException
, css::uno::RuntimeException
);
74 css::accessibility::TextSegment SAL_CALL
getTextAtIndex( sal_Int32 nIndex
, sal_Int16 aTextType
) throw (css::lang::IndexOutOfBoundsException
, css::lang::IllegalArgumentException
, css::uno::RuntimeException
);
75 css::accessibility::TextSegment SAL_CALL
getTextBeforeIndex( sal_Int32 nIndex
, sal_Int16 aTextType
) throw (css::lang::IndexOutOfBoundsException
, css::lang::IllegalArgumentException
, css::uno::RuntimeException
);
76 css::accessibility::TextSegment SAL_CALL
getTextBehindIndex( sal_Int32 nIndex
, sal_Int16 aTextType
) throw (css::lang::IndexOutOfBoundsException
, css::lang::IllegalArgumentException
, css::uno::RuntimeException
);
80 /** Helper method, that detects the difference between
81 two strings and returns the deleted selection and
82 the inserted selection if available.
84 @returns true if there are differences between the
85 two strings and false if both are equal
87 @see css::accessibility::AccessibleEventId
88 css::accessibility::TextSegment
90 static bool implInitTextChangedEvent(
91 const OUString
& rOldString
,
92 const OUString
& rNewString
,
93 /*out*/ css::uno::Any
& rDeleted
,
94 /*out*/ css::uno::Any
& rInserted
); // throw()
98 // OAccessibleTextHelper
101 typedef ::cppu::ImplHelper1
< css::accessibility::XAccessibleText
102 > OAccessibleTextHelper_Base
;
104 /** a helper class for implementing an AccessibleExtendedComponent which at the same time
105 supports an XAccessibleText interface
107 class COMPHELPER_DLLPUBLIC OAccessibleTextHelper
: public OAccessibleExtendedComponentHelper
,
108 public OCommonAccessibleText
,
109 public OAccessibleTextHelper_Base
112 // see the respective base class ctor for an extensive comment on this, please
113 OAccessibleTextHelper( IMutex
* _pExternalLock
);
117 DECLARE_XINTERFACE( )
120 DECLARE_XTYPEPROVIDER( )
123 virtual sal_Unicode SAL_CALL
getCharacter( sal_Int32 nIndex
) throw (css::lang::IndexOutOfBoundsException
, css::uno::RuntimeException
, std::exception
) override
;
124 virtual sal_Int32 SAL_CALL
getCharacterCount() throw (css::uno::RuntimeException
, std::exception
) override
;
125 virtual OUString SAL_CALL
getSelectedText() throw (css::uno::RuntimeException
, std::exception
) override
;
126 virtual sal_Int32 SAL_CALL
getSelectionStart() throw (css::uno::RuntimeException
, std::exception
) override
;
127 virtual sal_Int32 SAL_CALL
getSelectionEnd() throw (css::uno::RuntimeException
, std::exception
) override
;
128 virtual OUString SAL_CALL
getText() throw (css::uno::RuntimeException
, std::exception
) override
;
129 virtual OUString SAL_CALL
getTextRange( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) throw (css::lang::IndexOutOfBoundsException
, css::uno::RuntimeException
, std::exception
) override
;
130 virtual css::accessibility::TextSegment SAL_CALL
getTextAtIndex( sal_Int32 nIndex
, sal_Int16 aTextType
) throw (css::lang::IndexOutOfBoundsException
, css::lang::IllegalArgumentException
, css::uno::RuntimeException
, std::exception
) override
;
131 virtual css::accessibility::TextSegment SAL_CALL
getTextBeforeIndex( sal_Int32 nIndex
, sal_Int16 aTextType
) throw (css::lang::IndexOutOfBoundsException
, css::lang::IllegalArgumentException
, css::uno::RuntimeException
, std::exception
) override
;
132 virtual css::accessibility::TextSegment SAL_CALL
getTextBehindIndex( sal_Int32 nIndex
, sal_Int16 aTextType
) throw (css::lang::IndexOutOfBoundsException
, css::lang::IllegalArgumentException
, css::uno::RuntimeException
, std::exception
) override
;
136 } // namespace comphelper
139 #endif // INCLUDED_COMPHELPER_ACCESSIBLETEXTHELPER_HXX
142 // OAccessibleTextHelper is a helper class for implementing the
143 // XAccessibleText interface.
145 // The following methods have a default implementation:
155 // getTextBeforeIndex
156 // getTextBehindIndex
158 // The following methods must be overridden by derived classes:
165 // getCharacterAttributes
166 // getCharacterBounds
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */