1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #if !defined INCLUDED_ACCESSIBILITY_TEXTWINDOWACCESSIBILITY_HXX
29 #define INCLUDED_ACCESSIBILITY_TEXTWINDOWACCESSIBILITY_HXX
30 
31 #include <toolkit/awt/vclxaccessiblecomponent.hxx>
32 #include <svl/lstner.hxx>
33 #include <svtools/textdata.hxx>
34 #include <svtools/texteng.hxx>
35 #include <svtools/textview.hxx>
36 #include <svtools/txtattr.hxx>
37 #include <com/sun/star/awt/FontWeight.hpp>
38 #include <com/sun/star/lang/EventObject.hpp>
39 #include <com/sun/star/uno/Reference.hxx>
40 #include <com/sun/star/util/Color.hpp>
41 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
42 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
43 #include <com/sun/star/accessibility/AccessibleRole.hpp>
44 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
45 #include <com/sun/star/accessibility/AccessibleTextType.hpp>
46 #include <com/sun/star/accessibility/XAccessible.hpp>
47 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
48 #include <com/sun/star/accessibility/XAccessibleEditableText.hpp>
49 #include <com/sun/star/accessibility/XAccessibleMultiLineText.hpp>
50 #include <com/sun/star/accessibility/XAccessibleTextAttributes.hpp>
51 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
52 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
53 #include <toolkit/awt/vclxwindow.hxx>
54 #include <cppuhelper/compbase7.hxx>
55 #include <comphelper/accessiblecontexthelper.hxx>
56 #include <comphelper/accessibletexthelper.hxx>
57 #include <rtl/ref.hxx>
58 
59 #include <memory>
60 #include <queue>
61 #include <hash_map>
62 
63 class TextEngine;
64 class TextView;
65 
66 namespace css = ::com::sun::star;
67 
68 namespace accessibility
69 {
70 
71 class Paragraph;
72 class Document;
73 
74 class SfxListenerGuard
75 {
76 public:
77     inline SfxListenerGuard(::SfxListener & rListener):
78         m_rListener(rListener), m_pNotifier(0) {}
79 
80     inline ~SfxListenerGuard() { endListening(); }
81 
82     // Not thread safe:
83     void startListening(::SfxBroadcaster & rNotifier);
84 
85     // Not thread safe:
86     void endListening();
87 
88 private:
89     ::SfxListener & m_rListener;
90     ::SfxBroadcaster * m_pNotifier;
91 };
92 
93 class WindowListenerGuard
94 {
95 public:
96     inline WindowListenerGuard(::Link const & rListener):
97         m_aListener(rListener), m_pNotifier(0) {}
98 
99     inline ~WindowListenerGuard() { endListening(); }
100 
101     // Not thread safe:
102     void startListening(::Window & rNotifier);
103 
104     // Not thread safe:
105     void endListening();
106 
107 private:
108     ::Link m_aListener;
109     ::Window * m_pNotifier;
110 };
111 
112 class ParagraphInfo
113 {
114 public:
115     inline ParagraphInfo(::sal_Int32 nHeight): m_nHeight(nHeight) {}
116 
117     inline
118     ::css::uno::WeakReference< ::css::accessibility::XAccessible > const &
119     getParagraph() const { return m_xParagraph; }
120 
121     inline ::sal_Int32 getHeight() const { return m_nHeight; }
122 
123     inline void setParagraph(
124         ::css::uno::Reference< ::css::accessibility::XAccessible > const &
125         rParagraph) { m_xParagraph = rParagraph; }
126 
127     inline void changeHeight(::sal_Int32 nHeight) { m_nHeight = nHeight; }
128 
129 private:
130     ::css::uno::WeakReference< ::css::accessibility::XAccessible >
131     m_xParagraph;
132     ::sal_Int32 m_nHeight;
133 };
134 
135 typedef ::std::vector< ParagraphInfo > Paragraphs;
136 
137 typedef ::cppu::WeakAggComponentImplHelper7<
138     ::css::accessibility::XAccessible,
139     ::css::accessibility::XAccessibleContext,
140     ::css::accessibility::XAccessibleComponent,
141     ::css::accessibility::XAccessibleEditableText,
142     ::css::accessibility::XAccessibleMultiLineText,
143     ::css::accessibility::XAccessibleTextAttributes,
144     ::css::accessibility::XAccessibleEventBroadcaster > ParagraphBase;
145 
146 // The Paragraph's number is the absolute position within the text engine (from
147 // 0 to N - 1), whereas the Paragraph's index is the position within the text
148 // view/accessible parent (from 0 to M - 1).  Paragraphs outside the currently
149 // visible range have an index of -1.
150 class ParagraphImpl:
151     public ParagraphBase, private ::comphelper::OCommonAccessibleText
152 {
153 public:
154     ParagraphImpl(::rtl::Reference< Document > const & rDocument,
155                   Paragraphs::size_type nNumber, ::osl::Mutex & rMutex);
156 
157     // Not thread-safe.
158     inline Paragraphs::size_type getNumber() const { return m_nNumber; }
159 
160     // Not thread-safe.
161     void numberChanged(bool bIncremented);
162 
163     // Not thread-safe.
164     void textChanged();
165 
166     // Thread-safe.
167     void notifyEvent(::sal_Int16 nEventId, ::css::uno::Any const & rOldValue,
168                      ::css::uno::Any const & rNewValue);
169 
170 protected:
171     // OCommonAccessibleText
172     virtual void implGetParagraphBoundary( ::css::i18n::Boundary& rBoundary,
173                                            ::sal_Int32 nIndex );
174     virtual void implGetLineBoundary( ::css::i18n::Boundary& rBoundary,
175                                       ::sal_Int32 nIndex );
176 
177 private:
178     virtual ::css::uno::Reference< ::css::accessibility::XAccessibleContext >
179     SAL_CALL getAccessibleContext() throw (::css::uno::RuntimeException);
180 
181     virtual ::sal_Int32 SAL_CALL getAccessibleChildCount()
182         throw (::css::uno::RuntimeException);
183 
184     virtual ::css::uno::Reference< ::css::accessibility::XAccessible > SAL_CALL
185     getAccessibleChild(::sal_Int32 i)
186         throw (::css::lang::IndexOutOfBoundsException,
187                ::css::uno::RuntimeException);
188 
189     virtual ::css::uno::Reference< ::css::accessibility::XAccessible > SAL_CALL
190     getAccessibleParent() throw (::css::uno::RuntimeException);
191 
192     virtual ::sal_Int32 SAL_CALL getAccessibleIndexInParent()
193         throw (::css::uno::RuntimeException);
194 
195     virtual ::sal_Int16 SAL_CALL getAccessibleRole()
196         throw (::css::uno::RuntimeException);
197 
198     virtual ::rtl::OUString SAL_CALL getAccessibleDescription()
199         throw (::css::uno::RuntimeException);
200 
201     virtual ::rtl::OUString SAL_CALL getAccessibleName()
202         throw (::css::uno::RuntimeException);
203 
204     virtual
205     ::css::uno::Reference< ::css::accessibility::XAccessibleRelationSet >
206     SAL_CALL getAccessibleRelationSet() throw (::css::uno::RuntimeException);
207 
208     virtual
209     ::css::uno::Reference< ::css::accessibility::XAccessibleStateSet > SAL_CALL
210     getAccessibleStateSet() throw (::css::uno::RuntimeException);
211 
212     virtual ::css::lang::Locale SAL_CALL getLocale()
213         throw (::css::accessibility::IllegalAccessibleComponentStateException,
214                ::css::uno::RuntimeException);
215 
216     virtual ::sal_Bool SAL_CALL containsPoint(::css::awt::Point const & rPoint)
217         throw (::css::uno::RuntimeException);
218 
219     virtual ::css::uno::Reference< ::css::accessibility::XAccessible > SAL_CALL
220     getAccessibleAtPoint(::css::awt::Point const & rPoint)
221         throw (::css::uno::RuntimeException);
222 
223     virtual ::css::awt::Rectangle SAL_CALL getBounds()
224         throw (::css::uno::RuntimeException);
225 
226     virtual ::css::awt::Point SAL_CALL getLocation()
227         throw (::css::uno::RuntimeException);
228 
229     virtual ::css::awt::Point SAL_CALL getLocationOnScreen()
230         throw (::css::uno::RuntimeException);
231 
232     virtual ::css::awt::Size SAL_CALL getSize()
233         throw (::css::uno::RuntimeException);
234 
235     virtual void SAL_CALL grabFocus() throw (::css::uno::RuntimeException);
236 
237     virtual ::css::uno::Any SAL_CALL getAccessibleKeyBinding()
238         throw (::css::uno::RuntimeException);
239 
240     virtual ::css::util::Color SAL_CALL getForeground()
241         throw (::css::uno::RuntimeException);
242 
243     virtual ::css::util::Color SAL_CALL getBackground()
244         throw (::css::uno::RuntimeException);
245 
246     virtual ::sal_Int32 SAL_CALL getCaretPosition()
247         throw (::css::uno::RuntimeException);
248 
249     virtual ::sal_Bool SAL_CALL setCaretPosition(::sal_Int32 nIndex)
250         throw (::css::lang::IndexOutOfBoundsException,
251                ::css::uno::RuntimeException);
252 
253     virtual ::sal_Unicode SAL_CALL getCharacter(::sal_Int32 nIndex)
254         throw (::css::lang::IndexOutOfBoundsException,
255                ::css::uno::RuntimeException);
256 
257     virtual ::css::uno::Sequence< ::css::beans::PropertyValue > SAL_CALL
258     getCharacterAttributes(::sal_Int32 nIndex, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aRequestedAttributes )
259         throw (::css::lang::IndexOutOfBoundsException,
260                ::css::uno::RuntimeException);
261 
262     virtual ::css::awt::Rectangle SAL_CALL
263     getCharacterBounds(::sal_Int32 nIndex)
264         throw (::css::lang::IndexOutOfBoundsException,
265                ::css::uno::RuntimeException);
266 
267     virtual ::sal_Int32 SAL_CALL getCharacterCount()
268         throw (::css::uno::RuntimeException);
269 
270     virtual ::sal_Int32 SAL_CALL
271     getIndexAtPoint(::css::awt::Point const & rPoint)
272         throw (::css::uno::RuntimeException);
273 
274     virtual ::rtl::OUString SAL_CALL getSelectedText()
275         throw (::css::uno::RuntimeException);
276 
277     virtual ::sal_Int32 SAL_CALL getSelectionStart()
278         throw (::css::uno::RuntimeException);
279 
280     virtual ::sal_Int32 SAL_CALL getSelectionEnd()
281         throw (::css::uno::RuntimeException);
282 
283     virtual ::sal_Bool SAL_CALL setSelection(::sal_Int32 nStartIndex,
284                                              ::sal_Int32 nEndIndex)
285         throw (::css::lang::IndexOutOfBoundsException,
286                ::css::uno::RuntimeException);
287 
288     virtual ::rtl::OUString SAL_CALL getText()
289         throw (::css::uno::RuntimeException);
290 
291     virtual ::rtl::OUString SAL_CALL getTextRange(::sal_Int32 nStartIndex,
292                                                   ::sal_Int32 nEndIndex)
293         throw (::css::lang::IndexOutOfBoundsException,
294                ::css::uno::RuntimeException);
295 
296     virtual ::com::sun::star::accessibility::TextSegment SAL_CALL getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
297     virtual ::com::sun::star::accessibility::TextSegment SAL_CALL getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
298     virtual ::com::sun::star::accessibility::TextSegment SAL_CALL getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
299 
300     virtual ::sal_Bool SAL_CALL copyText(::sal_Int32 nStartIndex,
301                                          ::sal_Int32 nEndIndex)
302         throw (::css::lang::IndexOutOfBoundsException,
303                ::css::uno::RuntimeException);
304 
305     virtual ::sal_Bool SAL_CALL cutText(::sal_Int32 nStartIndex,
306                                         ::sal_Int32 nEndIndex)
307         throw (::css::lang::IndexOutOfBoundsException,
308                ::css::uno::RuntimeException);
309 
310     virtual ::sal_Bool SAL_CALL pasteText(::sal_Int32 nIndex)
311         throw (::css::lang::IndexOutOfBoundsException,
312                ::css::uno::RuntimeException);
313 
314     virtual ::sal_Bool SAL_CALL deleteText(::sal_Int32 nStartIndex,
315                                            ::sal_Int32 nEndIndex)
316         throw (::css::lang::IndexOutOfBoundsException,
317                ::css::uno::RuntimeException);
318 
319     virtual ::sal_Bool SAL_CALL insertText(::rtl::OUString const & rText,
320                                            ::sal_Int32 nIndex)
321         throw (::css::lang::IndexOutOfBoundsException,
322                ::css::uno::RuntimeException);
323 
324     virtual ::sal_Bool SAL_CALL replaceText(
325         ::sal_Int32 nStartIndex, ::sal_Int32 nEndIndex,
326         ::rtl::OUString const & rReplacement)
327         throw (::css::lang::IndexOutOfBoundsException,
328                ::css::uno::RuntimeException);
329 
330     virtual ::sal_Bool SAL_CALL setAttributes(
331         ::sal_Int32 nStartIndex, ::sal_Int32 nEndIndex,
332         ::css::uno::Sequence< ::css::beans::PropertyValue > const &
333         rAttributeSet)
334         throw (::css::lang::IndexOutOfBoundsException,
335                ::css::uno::RuntimeException);
336 
337     virtual ::sal_Bool SAL_CALL setText(::rtl::OUString const & rText)
338         throw (::css::uno::RuntimeException);
339 
340     virtual ::css::uno::Sequence< ::css::beans::PropertyValue > SAL_CALL
341     getDefaultAttributes(const ::css::uno::Sequence< ::rtl::OUString >& RequestedAttributes)
342         throw (::css::uno::RuntimeException);
343 
344     virtual ::css::uno::Sequence< ::css::beans::PropertyValue > SAL_CALL
345     getRunAttributes(::sal_Int32 Index, const ::css::uno::Sequence< ::rtl::OUString >& RequestedAttributes)
346         throw (::css::lang::IndexOutOfBoundsException,
347                ::css::uno::RuntimeException);
348 
349     virtual ::sal_Int32 SAL_CALL getLineNumberAtIndex( ::sal_Int32 nIndex )
350         throw (::com::sun::star::lang::IndexOutOfBoundsException,
351                ::com::sun::star::uno::RuntimeException);
352 
353     virtual ::com::sun::star::accessibility::TextSegment SAL_CALL getTextAtLineNumber( ::sal_Int32 nLineNo )
354         throw (::com::sun::star::lang::IndexOutOfBoundsException,
355                ::com::sun::star::uno::RuntimeException);
356 
357     virtual ::com::sun::star::accessibility::TextSegment SAL_CALL getTextAtLineWithCaret(  )
358         throw (::com::sun::star::uno::RuntimeException);
359 
360     virtual ::sal_Int32 SAL_CALL getNumberOfLineWithCaret(  )
361         throw (::com::sun::star::uno::RuntimeException);
362 
363     using cppu::WeakAggComponentImplHelperBase::addEventListener;
364     virtual void SAL_CALL addEventListener(
365         ::css::uno::Reference<
366         ::css::accessibility::XAccessibleEventListener > const & rListener)
367         throw (::css::uno::RuntimeException);
368 
369     using cppu::WeakAggComponentImplHelperBase::removeEventListener;
370     virtual void SAL_CALL removeEventListener(
371         ::css::uno::Reference<
372         ::css::accessibility::XAccessibleEventListener > const & rListener)
373         throw (::css::uno::RuntimeException);
374 
375     virtual void SAL_CALL disposing();
376 
377     virtual ::rtl::OUString implGetText();
378 
379     virtual ::css::lang::Locale implGetLocale();
380 
381     virtual void implGetSelection(::sal_Int32 & rStartIndex,
382                                   ::sal_Int32 & rEndIndex);
383 
384     // Throws ::css::lang::DisposedException:
385     void checkDisposed();
386 
387     ::rtl::Reference< Document > m_xDocument;
388     Paragraphs::size_type m_nNumber;
389 
390 //    ::cppu::OInterfaceContainerHelper m_aListeners;
391     /// client id in the AccessibleEventNotifier queue
392     sal_uInt32 m_nClientId;
393 
394     ::rtl::OUString m_aParagraphText;
395 };
396 
397 
398 typedef ::std::hash_map< ::rtl::OUString,
399                          ::css::beans::PropertyValue,
400                          ::rtl::OUStringHash,
401                          ::std::equal_to< ::rtl::OUString > > tPropValMap;
402 
403 class Document: public ::VCLXAccessibleComponent, public ::SfxListener
404 {
405 public:
406     Document(::VCLXWindow * pVclXWindow, ::TextEngine & rEngine,
407              ::TextView & rView, bool bCompoundControlChild);
408 
409     inline ::css::uno::Reference< ::css::accessibility::XAccessible >
410     getAccessible() { return m_xAccessible; }
411 
412     // Must be called only after init has been called.
413     ::css::lang::Locale retrieveLocale();
414 
415     // Must be called only after init has been called.
416     // To make it possible for this method to be (indirectly) called from
417     // within Paragraph's constructor (i.e., when the Paragraph's ref count is
418     // still zero), pass a "ParagraphImpl const *" instead of a
419     // "::rtl::Reference< ParagraphImpl > const &".
420     ::sal_Int32 retrieveParagraphIndex(ParagraphImpl const * pParagraph);
421 
422     // Must be called only after init has been called.
423     // To make it possible for this method to be (indirectly) called from
424     // within Paragraph's constructor (i.e., when the Paragraph's ref count is
425     // still zero), pass a "ParagraphImpl const *" instead of a
426     // "::rtl::Reference< ParagraphImpl > const &".
427     ::sal_Int64 retrieveParagraphState(ParagraphImpl const * pParagraph);
428 
429     // Must be called only after init has been called.
430     // To make it possible for this method to be (indirectly) called from
431     // within Paragraph's constructor (i.e., when the Paragraph's ref count is
432     // still zero), pass a "ParagraphImpl const &" instead of a
433     // "::rtl::Reference< ParagraphImpl > const &".
434     ::css::awt::Rectangle
435     retrieveParagraphBounds(ParagraphImpl const * pParagraph, bool bAbsolute);
436 
437     // Must be called only after init has been called.
438     // To make it possible for this method to be (indirectly) called from
439     // within Paragraph's constructor (i.e., when the Paragraph's ref count is
440     // still zero), pass a "ParagraphImpl const &" instead of a
441     // "::rtl::Reference< ParagraphImpl > const &".
442     ::rtl::OUString retrieveParagraphText(ParagraphImpl const * pParagraph);
443 
444     // Must be called only after init has been called.
445     // To make it possible for this method to be (indirectly) called from
446     // within Paragraph's constructor (i.e., when the Paragraph's ref count is
447     // still zero), pass a "ParagraphImpl const &" instead of a
448     // "::rtl::Reference< ParagraphImpl > const &".
449     void retrieveParagraphSelection(ParagraphImpl const * pParagraph,
450                                     ::sal_Int32 * pBegin, ::sal_Int32 * pEnd);
451 
452     // Must be called only after init has been called.
453     // To make it possible for this method to be (indirectly) called from
454     // within Paragraph's constructor (i.e., when the Paragraph's ref count is
455     // still zero), pass a "ParagraphImpl const *" instead of a
456     // "::rtl::Reference< ParagraphImpl > const &".
457     ::sal_Int32 retrieveParagraphCaretPosition(ParagraphImpl const * pParagraph);
458 
459     // Must be called only after init has been called.
460     // To make it possible for this method to be (indirectly) called from
461     // within Paragraph's constructor (i.e., when the Paragraph's ref count is
462     // still zero), pass a "ParagraphImpl const &" instead of a
463     // "::rtl::Reference< ParagraphImpl > const &".
464     // Throws ::css::lang::IndexOutOfBoundsException.
465     ::css::awt::Rectangle
466     retrieveCharacterBounds(ParagraphImpl const * pParagraph,
467                             ::sal_Int32 nIndex);
468 
469     // Must be called only after init has been called.
470     // To make it possible for this method to be (indirectly) called from
471     // within Paragraph's constructor (i.e., when the Paragraph's ref count is
472     // still zero), pass a "ParagraphImpl const &" instead of a
473     // "::rtl::Reference< ParagraphImpl > const &".
474     ::sal_Int32 retrieveCharacterIndex(ParagraphImpl const * pParagraph,
475                                        ::css::awt::Point const & rPoint);
476 
477     // Must be called only after init has been called.
478     // To make it possible for this method to be (indirectly) called from
479     // within Paragraph's constructor (i.e., when the Paragraph's ref count is
480     // still zero), pass a "ParagraphImpl const &" instead of a
481     // "::rtl::Reference< ParagraphImpl > const &".
482     // Throws ::css::lang::IndexOutOfBoundsException.
483     ::css::uno::Sequence< ::css::beans::PropertyValue > retrieveCharacterAttributes(
484         ParagraphImpl const * pParagraph, ::sal_Int32 nIndex,
485         const ::css::uno::Sequence< ::rtl::OUString >& aRequestedAttributes);
486 
487     // Must be called only after init has been called.
488     // To make it possible for this method to be (indirectly) called from
489     // within Paragraph's constructor (i.e., when the Paragraph's ref count is
490     // still zero), pass a "ParagraphImpl const &" instead of a
491     // "::rtl::Reference< ParagraphImpl > const &".
492     ::css::uno::Sequence< ::css::beans::PropertyValue > retrieveDefaultAttributes(
493         ParagraphImpl const * pParagraph,
494         const ::css::uno::Sequence< ::rtl::OUString >& RequestedAttributes);
495 
496     // Must be called only after init has been called.
497     // To make it possible for this method to be (indirectly) called from
498     // within Paragraph's constructor (i.e., when the Paragraph's ref count is
499     // still zero), pass a "ParagraphImpl const &" instead of a
500     // "::rtl::Reference< ParagraphImpl > const &".
501     // Throws ::css::lang::IndexOutOfBoundsException.
502     ::css::uno::Sequence< ::css::beans::PropertyValue > retrieveRunAttributes(
503         ParagraphImpl const * pParagraph, ::sal_Int32 Index,
504         const ::css::uno::Sequence< ::rtl::OUString >& RequestedAttributes);
505 
506     // Must be called only after init has been called.
507     // To make it possible for this method to be (indirectly) called from
508     // within Paragraph's constructor (i.e., when the Paragraph's ref count is
509     // still zero), pass a "ParagraphImpl const &" instead of a
510     // "::rtl::Reference< ParagraphImpl > const &".
511     void changeParagraphText(ParagraphImpl * pParagraph,
512                              ::rtl::OUString const & rText);
513 
514     // Must be called only after init has been called.
515     // To make it possible for this method to be (indirectly) called from
516     // within Paragraph's constructor (i.e., when the Paragraph's ref count is
517     // still zero), pass a "ParagraphImpl const &" instead of a
518     // "::rtl::Reference< ParagraphImpl > const &".
519     // Throws ::css::lang::IndexOutOfBoundsException.
520     void changeParagraphText(ParagraphImpl * pParagraph, ::sal_Int32 nBegin,
521                              ::sal_Int32 nEnd, bool bCut, bool bPaste,
522                              ::rtl::OUString const & rText);
523 
524     // Must be called only after init has been called.
525     // To make it possible for this method to be (indirectly) called from
526     // within Paragraph's constructor (i.e., when the Paragraph's ref count is
527     // still zero), pass a "ParagraphImpl const &" instead of a
528     // "::rtl::Reference< ParagraphImpl > const &".
529     // Throws ::css::lang::IndexOutOfBoundsException.
530     void copyParagraphText(ParagraphImpl const * pParagraph,
531                            ::sal_Int32 nBegin, ::sal_Int32 nEnd);
532 
533     // Must be called only after init has been called.
534     // To make it possible for this method to be (indirectly) called from
535     // within Paragraph's constructor (i.e., when the Paragraph's ref count is
536     // still zero), pass a "ParagraphImpl const &" instead of a
537     // "::rtl::Reference< ParagraphImpl > const &".
538     // Throws ::css::lang::IndexOutOfBoundsException.
539     void changeParagraphAttributes(
540         ParagraphImpl * pParagraph, ::sal_Int32 nBegin, ::sal_Int32 nEnd,
541         ::css::uno::Sequence< ::css::beans::PropertyValue > const &
542         rAttributeSet);
543 
544     // Must be called only after init has been called.
545     // To make it possible for this method to be (indirectly) called from
546     // within Paragraph's constructor (i.e., when the Paragraph's ref count is
547     // still zero), pass a "ParagraphImpl const &" instead of a
548     // "::rtl::Reference< ParagraphImpl > const &".
549     // Throws ::css::lang::IndexOutOfBoundsException.
550     void changeParagraphSelection(ParagraphImpl * pParagraph,
551                                   ::sal_Int32 nBegin, ::sal_Int32 nEnd);
552 
553     ::css::i18n::Boundary
554     retrieveParagraphLineBoundary( ParagraphImpl const * pParagraph,
555                                    ::sal_Int32 nIndex, ::sal_Int32 *pLineNo = NULL);
556 
557     ::css::i18n::Boundary
558     retrieveParagraphBoundaryOfLine( ParagraphImpl const * pParagraph,
559                                      ::sal_Int32 nIndex );
560 
561     sal_Int32 retrieveParagraphLineWithCursor( ParagraphImpl const * pParagraph );
562 
563     ::css::uno::Reference< ::css::accessibility::XAccessibleRelationSet >
564     retrieveParagraphRelationSet( ParagraphImpl const * pParagraph );
565 
566 protected:
567 	// window event listener from base class
568 	virtual void ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent );
569 
570 private:
571     virtual ::sal_Int32 SAL_CALL getAccessibleChildCount()
572         throw (::css::uno::RuntimeException);
573 
574     virtual ::css::uno::Reference< ::css::accessibility::XAccessible >
575     SAL_CALL getAccessibleChild(::sal_Int32 i)
576         throw (::css::lang::IndexOutOfBoundsException,
577                ::css::uno::RuntimeException);
578 
579     virtual ::sal_Int16 SAL_CALL getAccessibleRole()
580         throw (::css::uno::RuntimeException);
581 
582     virtual ::css::uno::Reference< ::css::accessibility::XAccessible >
583     SAL_CALL getAccessibleAtPoint(::css::awt::Point const & rPoint)
584         throw (::css::uno::RuntimeException);
585 
586     // ??? Will be called with both the external (Solar) and internal mutex
587     // locked:
588     virtual void SAL_CALL disposing();
589 
590     // ??? Will be called with the external (Solar) mutex locked.
591     // init will already have been called.
592     virtual void Notify(::SfxBroadcaster & rBC, ::SfxHint const & rHint);
593 
594     // Assuming that this will only be called with the external (Solar) mutex
595     // locked.
596     // init will already have been called.
597     DECL_LINK(WindowEventHandler, VclSimpleEvent *);
598 
599     // Must be called with both the external (Solar) and internal mutex
600     // locked.
601     void init();
602 
603     // Must be called with both the external (Solar) and internal mutex
604     // locked, and after init has been called:
605     ::rtl::Reference< ParagraphImpl >
606     getParagraph(Paragraphs::iterator const & rIt);
607 
608     // Must be called with both the external (Solar) and internal mutex
609     // locked, and after init has been called.
610     // Throws ::css::uno::RuntimeException.
611     ::css::uno::Reference< ::css::accessibility::XAccessible >
612     getAccessibleChild(Paragraphs::iterator const & rIt);
613 
614     // Must be called with both the external (Solar) and internal mutex
615     // locked, and after init has been called:
616     void determineVisibleRange();
617 
618     // Must be called with both the external (Solar) and internal mutex
619     // locked, and after init has been called:
620     void notifyVisibleRangeChanges(
621         Paragraphs::iterator const & rOldVisibleBegin,
622         Paragraphs::iterator const & rOldVisibleEnd,
623         Paragraphs::iterator const & rInserted);
624 
625     // Must be called with both the external (Solar) and internal mutex
626     // locked, and after init has been called:
627     void changeParagraphText(::sal_uLong nNumber, ::sal_uInt16 nBegin, ::sal_uInt16 nEnd,
628                              bool bCut, bool bPaste,
629                              ::rtl::OUString const & rText);
630 
631     void
632     handleParagraphNotifications();
633 
634     void handleSelectionChangeNotification();
635 
636     void notifySelectionChange( sal_Int32 nFirst, sal_Int32 nLast );
637 
638     void justifySelection( TextPaM& rTextStart, TextPaM& rTextEnd );
639 
640     void disposeParagraphs();
641 
642     static ::css::uno::Any mapFontColor(::Color const & rColor);
643 
644     static ::Color mapFontColor(::css::uno::Any const & rColor);
645 
646     static ::css::uno::Any mapFontWeight(::FontWeight nWeight);
647 
648     static ::FontWeight mapFontWeight(::css::uno::Any const & rWeight);
649 
650     void retrieveDefaultAttributesImpl(
651         ParagraphImpl const * pParagraph,
652         const ::css::uno::Sequence< ::rtl::OUString >& RequestedAttributes,
653         tPropValMap& rDefAttrSeq);
654 
655     void retrieveRunAttributesImpl(
656         ParagraphImpl const * pParagraph, ::sal_Int32 Index,
657         const ::css::uno::Sequence< ::rtl::OUString >& RequestedAttributes,
658         tPropValMap& rRunAttrSeq);
659 
660     static ::css::uno::Sequence< ::css::beans::PropertyValue >
661     convertHashMapToSequence(tPropValMap& rAttrSeq);
662 
663     ::css::uno::Reference< ::css::accessibility::XAccessible > m_xAccessible;
664     ::TextEngine & m_rEngine;
665     ::TextView & m_rView;
666 
667     SfxListenerGuard m_aEngineListener;
668     WindowListenerGuard m_aViewListener;
669 
670     // All the following members have valid values only after calling init:
671 
672     ::std::auto_ptr< Paragraphs > m_xParagraphs;
673 
674     // m_nViewOffset is from the start of the document (0) to the start of the
675     // current view, and m_nViewHeight is the height of the view:
676     ::sal_Int32 m_nViewOffset;
677     ::sal_Int32 m_nViewHeight;
678 
679     // m_aVisibleBegin points to the first Paragraph that is (partially)
680     // contained in the view, and m_aVisibleEnd points past the last Paragraph
681     // that is (partially) contained.  If no Paragraphs are (partially) in the
682     // view, both m_aVisibleBegin and m_aVisibleEnd are set to
683     // m_xParagraphs->end().  These values are only changed by
684     // determineVisibleRange.
685     Paragraphs::iterator m_aVisibleBegin;
686     Paragraphs::iterator m_aVisibleEnd;
687 
688     // m_nVisibleBeginOffset is from m_nViewOffset back to the start of the
689     // Paragraph pointed to by m_aVisibleBegin (and always has a non-negative
690     // value).  If m_aVisibleBegin == m_xParagraphs->end(),
691     // m_nVisibleBeginOffset is set to 0.  These values are only changed by
692     // determineVisibleRange.
693     ::sal_Int32 m_nVisibleBeginOffset;
694 
695     // If no selection has yet been set, all the following four variables are
696     // set to -1.  m_nSelectionLastPara/Pos is also the cursor position.
697     ::sal_Int32 m_nSelectionFirstPara;
698     ::sal_Int32 m_nSelectionFirstPos;
699     ::sal_Int32 m_nSelectionLastPara;
700     ::sal_Int32 m_nSelectionLastPos;
701 
702     Paragraphs::iterator m_aFocused;
703 
704     ::std::queue< ::TextHint > m_aParagraphNotifications;
705     bool m_bSelectionChangedNotification;
706 	bool m_bCompoundControlChild;
707 };
708 
709 }
710 
711 #endif // INCLUDED_ACCESSIBILITY_TEXTWINDOWACCESSIBILITY_HXX
712