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