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