xref: /aoo41x/main/editeng/source/uno/unoedprx.cxx (revision cdf0e10c)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_editeng.hxx"
30 
31 //------------------------------------------------------------------------
32 //
33 // Global header
34 //
35 //------------------------------------------------------------------------
36 
37 #include <limits.h>
38 #include <vector>
39 #include <algorithm>
40 #include <vos/mutex.hxx>
41 #include <vcl/window.hxx>
42 #include <vcl/svapp.hxx>
43 #include <com/sun/star/uno/Any.hxx>
44 #include <com/sun/star/uno/Reference.hxx>
45 
46 //------------------------------------------------------------------------
47 //
48 // Project-local header
49 //
50 //------------------------------------------------------------------------
51 #include "editeng/unoedprx.hxx"
52 #include <editeng/unotext.hxx>
53 #include <editeng/unoedhlp.hxx>
54 #include <editeng/editdata.hxx>
55 #include <editeng/editeng.hxx>
56 #include <editeng/editview.hxx>
57 #include <editeng/AccessibleStringWrap.hxx>
58 #include <editeng/outliner.hxx>
59 
60 using namespace ::com::sun::star;
61 
62 
63 class SvxAccessibleTextIndex
64 {
65 public:
66     SvxAccessibleTextIndex() :
67         mnPara(0),
68         mnIndex(0),
69         mnEEIndex(0),
70         mnFieldOffset(0),
71         mnFieldLen(0),
72         mbInField(sal_False),
73         mnBulletOffset(0),
74         mnBulletLen(0),
75         mbInBullet(sal_False) {};
76     ~SvxAccessibleTextIndex() {};
77 
78     // Get/Set current paragraph
79     void SetParagraph( sal_uInt16 nPara )
80     {
81         mnPara = nPara;
82     }
83     sal_uInt16 GetParagraph() const { return mnPara; }
84 
85     /** Set the index in the UAA semantic
86 
87         @param nIndex
88      	The index from the UA API (fields and bullets are expanded)
89 
90         @param rTF
91         The text forwarder to use in the calculations
92      */
93     void SetIndex( sal_Int32 nIndex, const SvxTextForwarder& rTF );
94     void SetIndex( sal_uInt16 nPara, sal_Int32 nIndex, const SvxTextForwarder& rTF ) { SetParagraph(nPara); SetIndex(nIndex, rTF); }
95     sal_Int32 GetIndex() const { return mnIndex; }
96 
97     /** Set the index in the edit engine semantic
98 
99     	Update the object state to reflect the given index position in
100     	EditEngine/Outliner index values
101 
102         @param nEEIndex
103      	The index from the edit engine (fields span exactly one index increment)
104 
105         @param rTF
106         The text forwarder to use in the calculations
107      */
108     void SetEEIndex( sal_uInt16 nEEIndex, const SvxTextForwarder& rTF );
109     void SetEEIndex( sal_uInt16 nPara, sal_uInt16 nEEIndex, const SvxTextForwarder& rTF ) { SetParagraph(nPara); SetEEIndex(nEEIndex, rTF); }
110     sal_uInt16 GetEEIndex() const;
111 
112     void SetFieldOffset( sal_Int32 nOffset, sal_Int32 nLen ) { mnFieldOffset = nOffset; mnFieldLen = nLen; }
113     sal_Int32 GetFieldOffset() const { return mnFieldOffset; }
114     sal_Int32 GetFieldLen() const { return mnFieldLen; }
115     void AreInField( sal_Bool bInField = sal_True ) { mbInField = bInField; }
116     sal_Bool InField() const { return mbInField; }
117 
118     void SetBulletOffset( sal_Int32 nOffset, sal_Int32 nLen ) { mnBulletOffset = nOffset; mnBulletLen = nLen; }
119     sal_Int32 GetBulletOffset() const { return mnBulletOffset; }
120     sal_Int32 GetBulletLen() const { return mnBulletLen; }
121     void AreInBullet( sal_Bool bInBullet = sal_True ) { mbInBullet = bInBullet; }
122     sal_Bool InBullet() const { return mbInBullet; }
123 
124     /// returns false if the current index contains non-editable text (e.g. bullets)
125     sal_Bool IsEditable() const;
126 
127     /// returns false if the given range is non-editable (e.g. contains bullets or _parts_ of fields)
128     sal_Bool IsEditableRange( const SvxAccessibleTextIndex& rEnd ) const;
129 
130 private:
131     sal_uInt16 	  mnPara;
132     sal_Int32 mnIndex;
133     sal_Int32 mnEEIndex;
134     sal_Int32 mnFieldOffset;
135     sal_Int32 mnFieldLen;
136     sal_Bool  mbInField;
137     sal_Int32 mnBulletOffset;
138     sal_Int32 mnBulletLen;
139     sal_Bool  mbInBullet;
140 };
141 
142 ESelection MakeEESelection( const SvxAccessibleTextIndex& rStart, const SvxAccessibleTextIndex& rEnd )
143 {
144     // deal with field special case: to really get a field contained
145     // within a selection, the start index must be before or on the
146     // field, the end index after it.
147 
148     // The SvxAccessibleTextIndex.GetEEIndex method gives the index on
149     // the field, as long the input index is on the field. Thus,
150     // correction necessary for the end index
151 
152     // Therefore, for _ranges_, if part of the field is touched, all
153     // of the field must be selected
154     if( rStart.GetParagraph() <= rEnd.GetParagraph() ||
155         (rStart.GetParagraph() == rEnd.GetParagraph() &&
156          rStart.GetEEIndex() <= rEnd.GetEEIndex()) )
157     {
158         if( rEnd.InField() && rEnd.GetFieldOffset() )
159             return ESelection( rStart.GetParagraph(), rStart.GetEEIndex(),
160                                rEnd.GetParagraph(), rEnd.GetEEIndex()+1 );
161     }
162     else if( rStart.GetParagraph() > rEnd.GetParagraph() ||
163              (rStart.GetParagraph() == rEnd.GetParagraph() &&
164               rStart.GetEEIndex() > rEnd.GetEEIndex()) )
165     {
166         if( rStart.InField() && rStart.GetFieldOffset()  )
167             return ESelection( rStart.GetParagraph(), rStart.GetEEIndex()+1,
168                                rEnd.GetParagraph(), rEnd.GetEEIndex() );
169     }
170 
171     return ESelection( rStart.GetParagraph(), rStart.GetEEIndex(),
172                        rEnd.GetParagraph(), rEnd.GetEEIndex() );
173 }
174 
175 ESelection MakeEESelection( const SvxAccessibleTextIndex& rIndex )
176 {
177     return ESelection( rIndex.GetParagraph(), rIndex.GetEEIndex(),
178                        rIndex.GetParagraph(), rIndex.GetEEIndex() + 1 );
179 }
180 
181 sal_uInt16 SvxAccessibleTextIndex::GetEEIndex() const
182 {
183     DBG_ASSERT(mnEEIndex >= 0 && mnEEIndex <= USHRT_MAX,
184                "SvxAccessibleTextIndex::GetEEIndex: index value overflow");
185 
186     return static_cast< sal_uInt16 > (mnEEIndex);
187 }
188 
189 void SvxAccessibleTextIndex::SetEEIndex( sal_uInt16 nEEIndex, const SvxTextForwarder& rTF )
190 {
191     // reset
192     mnFieldOffset = 0;
193     mbInField = sal_False;
194     mnFieldLen = 0;
195     mnBulletOffset = 0;
196     mbInBullet = sal_False;
197     mnBulletLen = 0;
198 
199     // set known values
200     mnEEIndex = nEEIndex;
201 
202     // calculate unknowns
203     sal_uInt16					nCurrField, nFieldCount = rTF.GetFieldCount( GetParagraph() );
204 
205     mnIndex = nEEIndex;
206 
207     EBulletInfo aBulletInfo = rTF.GetBulletInfo( GetParagraph() );
208 
209     // any text bullets?
210     if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND &&
211         aBulletInfo.bVisible &&
212         aBulletInfo.nType != SVX_NUM_BITMAP )
213     {
214         mnIndex += aBulletInfo.aText.Len();
215     }
216 
217     for( nCurrField=0; nCurrField < nFieldCount; ++nCurrField )
218     {
219         EFieldInfo aFieldInfo( rTF.GetFieldInfo( GetParagraph(), nCurrField ) );
220 
221         if( aFieldInfo.aPosition.nIndex > nEEIndex )
222             break;
223 
224         if( aFieldInfo.aPosition.nIndex == nEEIndex )
225         {
226             AreInField();
227             break;
228         }
229 
230         // #106010#
231         mnIndex += ::std::max(aFieldInfo.aCurrentText.Len()-1, 0);
232     }
233 }
234 
235 void SvxAccessibleTextIndex::SetIndex( sal_Int32 nIndex, const SvxTextForwarder& rTF )
236 {
237     // reset
238     mnFieldOffset = 0;
239     mbInField = sal_False;
240     mnFieldLen = 0;
241     mnBulletOffset = 0;
242     mbInBullet = sal_False;
243     mnBulletLen = 0;
244 
245     // set known values
246     mnIndex = nIndex;
247 
248     // calculate unknowns
249     sal_uInt16					nCurrField, nFieldCount = rTF.GetFieldCount( GetParagraph() );
250 
251     DBG_ASSERT(nIndex >= 0 && nIndex <= USHRT_MAX,
252                "SvxAccessibleTextIndex::SetIndex: index value overflow");
253 
254     mnEEIndex = nIndex;
255 
256     EBulletInfo aBulletInfo = rTF.GetBulletInfo( GetParagraph() );
257 
258     // any text bullets?
259     if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND &&
260         aBulletInfo.bVisible &&
261         aBulletInfo.nType != SVX_NUM_BITMAP )
262     {
263         sal_Int32 nBulletLen = aBulletInfo.aText.Len();
264 
265         if( nIndex < nBulletLen )
266         {
267             AreInBullet();
268             SetBulletOffset( nIndex, nBulletLen );
269             mnEEIndex = 0;
270             return;
271         }
272 
273         mnEEIndex = mnEEIndex - nBulletLen;
274     }
275 
276     for( nCurrField=0; nCurrField < nFieldCount; ++nCurrField )
277     {
278         EFieldInfo aFieldInfo( rTF.GetFieldInfo( GetParagraph(), nCurrField ) );
279 
280         // we're before a field
281         if( aFieldInfo.aPosition.nIndex > mnEEIndex )
282             break;
283 
284         // #106010#
285         mnEEIndex -= ::std::max(aFieldInfo.aCurrentText.Len()-1, 0);
286 
287         // we're within a field
288         if( aFieldInfo.aPosition.nIndex >= mnEEIndex )
289         {
290             AreInField();
291             SetFieldOffset( ::std::max(aFieldInfo.aCurrentText.Len()-1, 0) - (aFieldInfo.aPosition.nIndex - mnEEIndex),
292                             aFieldInfo.aCurrentText.Len() );
293             mnEEIndex = aFieldInfo.aPosition.nIndex ;
294             break;
295         }
296     }
297 }
298 
299 sal_Bool SvxAccessibleTextIndex::IsEditable() const
300 {
301     if( InBullet() || InField() )
302         return sal_False;
303 
304     return sal_True;
305 }
306 
307 sal_Bool SvxAccessibleTextIndex::IsEditableRange( const SvxAccessibleTextIndex& rEnd ) const
308 {
309     if( GetIndex() > rEnd.GetIndex() )
310         return rEnd.IsEditableRange( *this );
311 
312     if( InBullet() || rEnd.InBullet() )
313         return sal_False;
314 
315     if( InField() && GetFieldOffset() )
316         return sal_False; // within field
317 
318     if( rEnd.InField() && rEnd.GetFieldOffset() >= rEnd.GetFieldLen() - 1 )
319         return sal_False; // within field
320 
321     return sal_True;
322 }
323 
324 //---------------------------------------------------------------------------------
325 
326 SvxEditSourceAdapter::SvxEditSourceAdapter() : mbEditSourceValid( sal_False )
327 {
328 }
329 
330 SvxEditSourceAdapter::~SvxEditSourceAdapter()
331 {
332 }
333 
334 SvxEditSource* SvxEditSourceAdapter::Clone() const
335 {
336     if( mbEditSourceValid && mpAdaptee.get() )
337     {
338         ::std::auto_ptr< SvxEditSource > pClonedAdaptee( mpAdaptee->Clone() );
339 
340         if( pClonedAdaptee.get() )
341         {
342             SvxEditSourceAdapter* pClone = new SvxEditSourceAdapter();
343 
344             if( pClone )
345             {
346                 pClone->SetEditSource( pClonedAdaptee );
347                 return pClone;
348             }
349         }
350     }
351 
352     return NULL;
353 }
354 
355 SvxAccessibleTextAdapter* SvxEditSourceAdapter::GetTextForwarderAdapter()
356 {
357     if( mbEditSourceValid && mpAdaptee.get() )
358     {
359         SvxTextForwarder* pTextForwarder = mpAdaptee->GetTextForwarder();
360 
361         if( pTextForwarder )
362         {
363             maTextAdapter.SetForwarder(*pTextForwarder);
364 
365             return &maTextAdapter;
366         }
367     }
368 
369     return NULL;
370 }
371 
372 SvxTextForwarder* SvxEditSourceAdapter::GetTextForwarder()
373 {
374     return GetTextForwarderAdapter();
375 }
376 
377 SvxViewForwarder* SvxEditSourceAdapter::GetViewForwarder()
378 {
379     if( mbEditSourceValid && mpAdaptee.get() )
380         return mpAdaptee->GetViewForwarder();
381 
382     return NULL;
383 }
384 
385 SvxAccessibleTextEditViewAdapter* SvxEditSourceAdapter::GetEditViewForwarderAdapter( sal_Bool bCreate )
386 {
387     if( mbEditSourceValid && mpAdaptee.get() )
388     {
389         SvxEditViewForwarder* pEditViewForwarder = mpAdaptee->GetEditViewForwarder(bCreate);
390 
391         if( pEditViewForwarder )
392         {
393             SvxAccessibleTextAdapter* pTextAdapter = GetTextForwarderAdapter();
394 
395             if( pTextAdapter )
396             {
397                 maEditViewAdapter.SetForwarder(*pEditViewForwarder, *pTextAdapter);
398 
399                 return &maEditViewAdapter;
400             }
401         }
402     }
403 
404     return NULL;
405 }
406 
407 SvxEditViewForwarder* SvxEditSourceAdapter::GetEditViewForwarder( sal_Bool bCreate )
408 {
409     return GetEditViewForwarderAdapter( bCreate );
410 }
411 
412 void SvxEditSourceAdapter::UpdateData()
413 {
414     if( mbEditSourceValid && mpAdaptee.get() )
415         mpAdaptee->UpdateData();
416 }
417 
418 SfxBroadcaster& SvxEditSourceAdapter::GetBroadcaster() const
419 {
420     if( mbEditSourceValid && mpAdaptee.get() )
421         return mpAdaptee->GetBroadcaster();
422 
423     return maDummyBroadcaster;
424 }
425 
426 void SvxEditSourceAdapter::SetEditSource( ::std::auto_ptr< SvxEditSource > pAdaptee )
427 {
428     if( pAdaptee.get() )
429     {
430         mpAdaptee = pAdaptee;
431         mbEditSourceValid = sal_True;
432     }
433     else
434     {
435         // do a lazy delete (prevents us from deleting the broadcaster
436         // from within a broadcast in
437         // AccessibleTextHelper_Impl::Notify)
438         mbEditSourceValid = sal_False;
439     }
440 }
441 
442 sal_Bool SvxEditSourceAdapter::IsValid() const
443 {
444     return mbEditSourceValid;
445 }
446 
447 
448 //--------------------------------------------------------------------------------------
449 
450 SvxAccessibleTextAdapter::SvxAccessibleTextAdapter() : mrTextForwarder( NULL )
451 {
452 }
453 
454 SvxAccessibleTextAdapter::~SvxAccessibleTextAdapter()
455 {
456 }
457 
458 sal_uInt16 SvxAccessibleTextAdapter::GetParagraphCount() const
459 {
460     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
461 
462     return mrTextForwarder->GetParagraphCount();
463 }
464 
465 sal_uInt16 SvxAccessibleTextAdapter::GetTextLen( sal_uInt16 nParagraph ) const
466 {
467     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
468 
469     SvxAccessibleTextIndex aIndex;
470     aIndex.SetEEIndex( nParagraph, mrTextForwarder->GetTextLen( nParagraph ), *this );
471 
472     return static_cast< sal_uInt16 >(aIndex.GetIndex());
473 }
474 
475 String SvxAccessibleTextAdapter::GetText( const ESelection& rSel ) const
476 {
477     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
478 
479     SvxAccessibleTextIndex aStartIndex;
480     SvxAccessibleTextIndex aEndIndex;
481 
482     aStartIndex.SetIndex( rSel.nStartPara, rSel.nStartPos, *this );
483     aEndIndex.SetIndex( rSel.nEndPara, rSel.nEndPos, *this );
484 
485     // normalize selection
486     if( rSel.nStartPara > rSel.nEndPara ||
487         (rSel.nStartPara == rSel.nEndPara && rSel.nStartPos > rSel.nEndPos) )
488     {
489         ::std::swap( aStartIndex, aEndIndex );
490     }
491 
492     String sStr = mrTextForwarder->GetText( MakeEESelection(aStartIndex, aEndIndex) );
493 
494     // trim field text, if necessary
495     if( aStartIndex.InField() )
496     {
497         DBG_ASSERT(aStartIndex.GetFieldOffset() >= 0 &&
498                    aStartIndex.GetFieldOffset() <= USHRT_MAX,
499                    "SvxAccessibleTextIndex::GetText: index value overflow");
500 
501         sStr.Erase(0, static_cast< sal_uInt16 > (aStartIndex.GetFieldOffset()) );
502     }
503     if( aEndIndex.InField() && aEndIndex.GetFieldOffset() )
504     {
505         DBG_ASSERT(sStr.Len() - (aEndIndex.GetFieldLen() - aEndIndex.GetFieldOffset()) >= 0 &&
506                    sStr.Len() - (aEndIndex.GetFieldLen() - aEndIndex.GetFieldOffset()) <= USHRT_MAX,
507                    "SvxAccessibleTextIndex::GetText: index value overflow");
508 
509         sStr = sStr.Copy(0, static_cast< sal_uInt16 > (sStr.Len() - (aEndIndex.GetFieldLen() - aEndIndex.GetFieldOffset())) );
510     }
511 
512     EBulletInfo aBulletInfo1 = GetBulletInfo( static_cast< sal_uInt16 >(aStartIndex.GetParagraph()) );
513     EBulletInfo aBulletInfo2 = GetBulletInfo( static_cast< sal_uInt16 >(aEndIndex.GetParagraph()) );
514 
515     if( aStartIndex.InBullet() )
516     {
517         // prepend leading bullet
518         String sBullet = aBulletInfo1.aText;
519 
520         DBG_ASSERT(aStartIndex.GetBulletOffset() >= 0 &&
521                    aStartIndex.GetBulletOffset() <= USHRT_MAX,
522                    "SvxAccessibleTextIndex::GetText: index value overflow");
523 
524         sBullet.Erase(0, static_cast< sal_uInt16 > (aStartIndex.GetBulletOffset()) );
525 
526         sBullet += sStr;
527         sStr = sBullet;
528     }
529 
530     if( aEndIndex.InBullet() )
531     {
532         // append trailing bullet
533         sStr += aBulletInfo2.aText;;
534 
535         DBG_ASSERT(sStr.Len() - (aEndIndex.GetBulletLen() - aEndIndex.GetBulletOffset()) >= 0 &&
536                    sStr.Len() - (aEndIndex.GetBulletLen() - aEndIndex.GetBulletOffset()) <= USHRT_MAX,
537                    "SvxAccessibleTextIndex::GetText: index value overflow");
538 
539         sStr = sStr.Copy(0, static_cast< sal_uInt16 > (sStr.Len() - (aEndIndex.GetBulletLen() - aEndIndex.GetBulletOffset())) );
540     }
541     else if( aStartIndex.GetParagraph() != aEndIndex.GetParagraph() &&
542              HaveTextBullet( aEndIndex.GetParagraph() ) )
543     {
544         String sBullet = aBulletInfo2.aText;
545 
546         DBG_ASSERT(sBullet.Len() - (aEndIndex.GetBulletLen() - aEndIndex.GetBulletOffset()) >= 0 &&
547                    sBullet.Len() - (aEndIndex.GetBulletLen() - aEndIndex.GetBulletOffset()) <= USHRT_MAX,
548                    "SvxAccessibleTextIndex::GetText: index value overflow");
549 
550         sBullet = sBullet.Copy(0, static_cast< sal_uInt16 > (sBullet.Len() - (aEndIndex.GetBulletLen() - aEndIndex.GetBulletOffset())) );
551 
552         // insert bullet
553         sStr.Insert( sBullet,
554                      static_cast< sal_uInt16 > (GetTextLen(aStartIndex.GetParagraph()) - aStartIndex.GetIndex()) );
555     }
556 
557     return sStr;
558 }
559 
560 SfxItemSet SvxAccessibleTextAdapter::GetAttribs( const ESelection& rSel, sal_Bool bOnlyHardAttrib ) const
561 {
562     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
563 
564     SvxAccessibleTextIndex aStartIndex;
565     SvxAccessibleTextIndex aEndIndex;
566 
567     aStartIndex.SetIndex( rSel.nStartPara, rSel.nStartPos, *this );
568     aEndIndex.SetIndex( rSel.nEndPara, rSel.nEndPos, *this );
569 
570     return mrTextForwarder->GetAttribs( MakeEESelection(aStartIndex, aEndIndex),
571                                         bOnlyHardAttrib );
572 }
573 
574 SfxItemSet SvxAccessibleTextAdapter::GetParaAttribs( sal_uInt16 nPara ) const
575 {
576     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
577 
578     return mrTextForwarder->GetParaAttribs( nPara );
579 }
580 
581 void SvxAccessibleTextAdapter::SetParaAttribs( sal_uInt16 nPara, const SfxItemSet& rSet )
582 {
583     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
584 
585     mrTextForwarder->SetParaAttribs( nPara, rSet );
586 }
587 
588 void SvxAccessibleTextAdapter::RemoveAttribs( const ESelection& , sal_Bool , sal_uInt16 )
589 {
590     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
591 }
592 
593 void SvxAccessibleTextAdapter::GetPortions( sal_uInt16 nPara, SvUShorts& rList ) const
594 {
595     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
596 
597     mrTextForwarder->GetPortions( nPara, rList );
598 }
599 
600 sal_uInt16 SvxAccessibleTextAdapter::GetItemState( const ESelection& rSel, sal_uInt16 nWhich ) const
601 {
602     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
603 
604     SvxAccessibleTextIndex aStartIndex;
605     SvxAccessibleTextIndex aEndIndex;
606 
607     aStartIndex.SetIndex( rSel.nStartPara, rSel.nStartPos, *this );
608     aEndIndex.SetIndex( rSel.nEndPara, rSel.nEndPos, *this );
609 
610     return mrTextForwarder->GetItemState( MakeEESelection(aStartIndex, aEndIndex),
611                                           nWhich );
612 }
613 
614 sal_uInt16 SvxAccessibleTextAdapter::GetItemState( sal_uInt16 nPara, sal_uInt16 nWhich ) const
615 {
616     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
617 
618     return mrTextForwarder->GetItemState( nPara, nWhich );
619 }
620 
621 void SvxAccessibleTextAdapter::QuickInsertText( const String& rText, const ESelection& rSel )
622 {
623     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
624 
625     SvxAccessibleTextIndex aStartIndex;
626     SvxAccessibleTextIndex aEndIndex;
627 
628     aStartIndex.SetIndex( rSel.nStartPara, rSel.nStartPos, *this );
629     aEndIndex.SetIndex( rSel.nEndPara, rSel.nEndPos, *this );
630 
631     mrTextForwarder->QuickInsertText( rText,
632                                       MakeEESelection(aStartIndex, aEndIndex) );
633 }
634 
635 void SvxAccessibleTextAdapter::QuickInsertField( const SvxFieldItem& rFld, const ESelection& rSel )
636 {
637     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
638 
639     SvxAccessibleTextIndex aStartIndex;
640     SvxAccessibleTextIndex aEndIndex;
641 
642     aStartIndex.SetIndex( rSel.nStartPara, rSel.nStartPos, *this );
643     aEndIndex.SetIndex( rSel.nEndPara, rSel.nEndPos, *this );
644 
645     mrTextForwarder->QuickInsertField( rFld,
646                                        MakeEESelection(aStartIndex, aEndIndex) );
647 }
648 
649 void SvxAccessibleTextAdapter::QuickSetAttribs( const SfxItemSet& rSet, const ESelection& rSel )
650 {
651     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
652 
653     SvxAccessibleTextIndex aStartIndex;
654     SvxAccessibleTextIndex aEndIndex;
655 
656     aStartIndex.SetIndex( rSel.nStartPara, rSel.nStartPos, *this );
657     aEndIndex.SetIndex( rSel.nEndPara, rSel.nEndPos, *this );
658 
659     mrTextForwarder->QuickSetAttribs( rSet,
660                                       MakeEESelection(aStartIndex, aEndIndex) );
661 }
662 
663 void SvxAccessibleTextAdapter::QuickInsertLineBreak( const ESelection& rSel )
664 {
665     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
666 
667     SvxAccessibleTextIndex aStartIndex;
668     SvxAccessibleTextIndex aEndIndex;
669 
670     aStartIndex.SetIndex( rSel.nStartPara, rSel.nStartPos, *this );
671     aEndIndex.SetIndex( rSel.nEndPara, rSel.nEndPos, *this );
672 
673     mrTextForwarder->QuickInsertLineBreak( MakeEESelection(aStartIndex, aEndIndex) );
674 }
675 
676 SfxItemPool* SvxAccessibleTextAdapter::GetPool() const
677 {
678     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
679 
680     return mrTextForwarder->GetPool();
681 }
682 
683 XubString SvxAccessibleTextAdapter::CalcFieldValue( const SvxFieldItem& rField, sal_uInt16 nPara, sal_uInt16 nPos, Color*& rpTxtColor, Color*& rpFldColor )
684 {
685     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
686 
687     return mrTextForwarder->CalcFieldValue( rField, nPara, nPos, rpTxtColor, rpFldColor );
688 }
689 
690 void SvxAccessibleTextAdapter::FieldClicked( const SvxFieldItem& rField, sal_uInt16 nPara, xub_StrLen nPos )
691 {
692     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
693 
694     mrTextForwarder->FieldClicked( rField, nPara, nPos );
695 }
696 
697 sal_Int32 SvxAccessibleTextAdapter::CalcLogicalIndex( sal_uInt16 nPara, sal_uInt16 nEEIndex )
698 {
699     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
700 
701     SvxAccessibleTextIndex aIndex;
702     aIndex.SetEEIndex(nPara, nEEIndex, *mrTextForwarder);
703     return aIndex.GetIndex();
704 }
705 
706 sal_uInt16 SvxAccessibleTextAdapter::CalcEditEngineIndex( sal_uInt16 nPara, sal_Int32 nLogicalIndex )
707 {
708     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
709 
710     SvxAccessibleTextIndex aIndex;
711     aIndex.SetIndex(nPara, nLogicalIndex, *mrTextForwarder);
712     return aIndex.GetEEIndex();
713 }
714 
715 
716 
717 sal_Bool SvxAccessibleTextAdapter::IsValid() const
718 {
719     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
720 
721     if( mrTextForwarder )
722         return mrTextForwarder->IsValid();
723     else
724         return sal_False;
725 }
726 
727 LanguageType SvxAccessibleTextAdapter::GetLanguage( sal_uInt16 nPara, sal_uInt16 nPos ) const
728 {
729     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
730 
731     SvxAccessibleTextIndex aIndex;
732 
733     aIndex.SetIndex( nPara, nPos, *this );
734 
735     return mrTextForwarder->GetLanguage( nPara, aIndex.GetEEIndex() );
736 }
737 
738 sal_uInt16 SvxAccessibleTextAdapter::GetFieldCount( sal_uInt16 nPara ) const
739 {
740     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
741 
742     return mrTextForwarder->GetFieldCount( nPara );
743 }
744 
745 EFieldInfo SvxAccessibleTextAdapter::GetFieldInfo( sal_uInt16 nPara, sal_uInt16 nField ) const
746 {
747     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
748 
749     return mrTextForwarder->GetFieldInfo( nPara, nField );
750 }
751 
752 EBulletInfo SvxAccessibleTextAdapter::GetBulletInfo( sal_uInt16 nPara ) const
753 {
754     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
755 
756     return mrTextForwarder->GetBulletInfo( nPara );
757 }
758 
759 Rectangle SvxAccessibleTextAdapter::GetCharBounds( sal_uInt16 nPara, sal_uInt16 nIndex ) const
760 {
761     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
762 
763     SvxAccessibleTextIndex aIndex;
764     aIndex.SetIndex( nPara, nIndex, *this );
765 
766     // preset if anything goes wrong below
767     // n-th char in GetParagraphIndex's paragraph
768     Rectangle aRect = mrTextForwarder->GetCharBounds( nPara, static_cast< sal_uInt16 >( aIndex.GetEEIndex() ) );
769 
770     if( aIndex.InBullet() )
771     {
772         EBulletInfo aBulletInfo = GetBulletInfo( nPara );
773 
774         OutputDevice* pOutDev = GetRefDevice();
775 
776         DBG_ASSERT(pOutDev!=NULL, "SvxAccessibleTextAdapter::GetCharBounds: No ref device");
777 
778         // preset if anything goes wrong below
779         aRect = aBulletInfo.aBounds; // better than nothing
780         if( pOutDev )
781         {
782             AccessibleStringWrap aStringWrap( *pOutDev, aBulletInfo.aFont, aBulletInfo.aText );
783 
784             if( aStringWrap.GetCharacterBounds( aIndex.GetBulletOffset(), aRect ) )
785                 aRect.Move( aBulletInfo.aBounds.Left(), aBulletInfo.aBounds.Top() );
786         }
787     }
788     else
789     {
790         // handle field content manually
791         if( aIndex.InField() )
792         {
793             OutputDevice* pOutDev = GetRefDevice();
794 
795             DBG_ASSERT(pOutDev!=NULL, "SvxAccessibleTextAdapter::GetCharBounds: No ref device");
796 
797             if( pOutDev )
798             {
799                 ESelection aSel = MakeEESelection( aIndex );
800 
801                 SvxFont aFont = EditEngine::CreateSvxFontFromItemSet( mrTextForwarder->GetAttribs( aSel ) );
802                 AccessibleStringWrap aStringWrap( *pOutDev,
803                                                   aFont,
804                                                   mrTextForwarder->GetText( aSel ) );
805 
806                 Rectangle aStartRect = mrTextForwarder->GetCharBounds( nPara, static_cast< sal_uInt16 >( aIndex.GetEEIndex() ) );
807 
808                 if( !aStringWrap.GetCharacterBounds( aIndex.GetFieldOffset(), aRect ) )
809                     aRect = aStartRect;
810                 else
811                     aRect.Move( aStartRect.Left(), aStartRect.Top() );
812             }
813         }
814     }
815 
816     return aRect;
817 }
818 
819 Rectangle SvxAccessibleTextAdapter::GetParaBounds( sal_uInt16 nPara ) const
820 {
821     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
822 
823     EBulletInfo aBulletInfo = GetBulletInfo( nPara );
824 
825     if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND &&
826         aBulletInfo.bVisible &&
827         aBulletInfo.nType != SVX_NUM_BITMAP )
828     {
829         // include bullet in para bounding box
830         Rectangle aRect( mrTextForwarder->GetParaBounds( nPara ) );
831 
832         aRect.Union( aBulletInfo.aBounds );
833 
834         return aRect;
835     }
836 
837     return mrTextForwarder->GetParaBounds( nPara );
838 }
839 
840 MapMode SvxAccessibleTextAdapter::GetMapMode() const
841 {
842     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
843 
844     return mrTextForwarder->GetMapMode();
845 }
846 
847 OutputDevice* SvxAccessibleTextAdapter::GetRefDevice() const
848 {
849     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
850 
851     return mrTextForwarder->GetRefDevice();
852 }
853 
854 sal_Bool SvxAccessibleTextAdapter::GetIndexAtPoint( const Point& rPoint, sal_uInt16& nPara, sal_uInt16& nIndex ) const
855 {
856     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
857 
858     if( !mrTextForwarder->GetIndexAtPoint( rPoint, nPara, nIndex ) )
859         return sal_False;
860 
861     SvxAccessibleTextIndex aIndex;
862     aIndex.SetEEIndex(nPara, nIndex, *this);
863 
864     DBG_ASSERT(aIndex.GetIndex() >= 0 && aIndex.GetIndex() <= USHRT_MAX,
865                "SvxAccessibleTextIndex::SetIndex: index value overflow");
866 
867     nIndex = static_cast< sal_uInt16 > (aIndex.GetIndex());
868 
869     EBulletInfo aBulletInfo = GetBulletInfo( nPara );
870 
871     // any text bullets?
872     if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND &&
873         aBulletInfo.bVisible &&
874         aBulletInfo.nType != SVX_NUM_BITMAP )
875     {
876         if( aBulletInfo.aBounds.IsInside( rPoint) )
877         {
878             OutputDevice* pOutDev = GetRefDevice();
879 
880             DBG_ASSERT(pOutDev!=NULL, "SvxAccessibleTextAdapter::GetIndexAtPoint: No ref device");
881 
882             if( !pOutDev )
883                 return sal_False;
884 
885             AccessibleStringWrap aStringWrap( *pOutDev, aBulletInfo.aFont, aBulletInfo.aText );
886 
887             Point aPoint = rPoint;
888             aPoint.Move( -aBulletInfo.aBounds.Left(), -aBulletInfo.aBounds.Top() );
889 
890             DBG_ASSERT(aStringWrap.GetIndexAtPoint( aPoint ) >= 0 &&
891                        aStringWrap.GetIndexAtPoint( aPoint ) <= USHRT_MAX,
892                        "SvxAccessibleTextIndex::SetIndex: index value overflow");
893 
894             nIndex = static_cast< sal_uInt16 > (aStringWrap.GetIndexAtPoint( aPoint ));
895             return sal_True;
896         }
897     }
898 
899     if( aIndex.InField() )
900     {
901         OutputDevice* pOutDev = GetRefDevice();
902 
903         DBG_ASSERT(pOutDev!=NULL, "SvxAccessibleTextAdapter::GetIndexAtPoint: No ref device");
904 
905         if( !pOutDev )
906             return sal_False;
907 
908         ESelection aSelection = MakeEESelection( aIndex );
909         SvxFont aFont = EditEngine::CreateSvxFontFromItemSet( mrTextForwarder->GetAttribs( aSelection ) );
910         AccessibleStringWrap aStringWrap( *pOutDev,
911                                           aFont,
912                                           mrTextForwarder->GetText( aSelection ) );
913 
914         Rectangle aRect = mrTextForwarder->GetCharBounds( nPara, aIndex.GetEEIndex() );
915         Point aPoint = rPoint;
916         aPoint.Move( -aRect.Left(), -aRect.Top() );
917 
918         DBG_ASSERT(aIndex.GetIndex() + aStringWrap.GetIndexAtPoint( rPoint ) >= 0 &&
919                    aIndex.GetIndex() + aStringWrap.GetIndexAtPoint( rPoint ) <= USHRT_MAX,
920                    "SvxAccessibleTextIndex::SetIndex: index value overflow");
921 
922         nIndex = static_cast< sal_uInt16 >(aIndex.GetIndex() + aStringWrap.GetIndexAtPoint( aPoint ));
923         return sal_True;
924     }
925 
926     return sal_True;
927 }
928 
929 sal_Bool SvxAccessibleTextAdapter::GetWordIndices( sal_uInt16 nPara, sal_uInt16 nIndex, sal_uInt16& nStart, sal_uInt16& nEnd ) const
930 {
931     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
932 
933     SvxAccessibleTextIndex aIndex;
934     aIndex.SetIndex(nPara, nIndex, *this);
935     nIndex = aIndex.GetEEIndex();
936 
937     if( aIndex.InBullet() )
938     {
939         DBG_ASSERT(aIndex.GetBulletLen() >= 0 &&
940                    aIndex.GetBulletLen() <= USHRT_MAX,
941                    "SvxAccessibleTextIndex::SetIndex: index value overflow");
942 
943         // always treat bullet as separate word
944         nStart = 0;
945         nEnd = static_cast< sal_uInt16 > (aIndex.GetBulletLen());
946 
947         return sal_True;
948     }
949 
950     if( aIndex.InField() )
951     {
952         DBG_ASSERT(aIndex.GetIndex() - aIndex.GetFieldOffset() >= 0 &&
953                    aIndex.GetIndex() - aIndex.GetFieldOffset() <= USHRT_MAX &&
954                    nStart + aIndex.GetFieldLen() >= 0 &&
955                    nStart + aIndex.GetFieldLen() <= USHRT_MAX,
956                    "SvxAccessibleTextIndex::SetIndex: index value overflow");
957 
958         // always treat field as separate word
959         // TODO: to circumvent this, _we_ would have to do the break iterator stuff!
960         nStart = static_cast< sal_uInt16 > (aIndex.GetIndex() - aIndex.GetFieldOffset());
961         nEnd = static_cast< sal_uInt16 > (nStart + aIndex.GetFieldLen());
962 
963         return sal_True;
964     }
965 
966     if( !mrTextForwarder->GetWordIndices( nPara, nIndex, nStart, nEnd ) )
967         return sal_False;
968 
969     aIndex.SetEEIndex( nPara, nStart, *this );
970     DBG_ASSERT(aIndex.GetIndex() >= 0 &&
971                aIndex.GetIndex() <= USHRT_MAX,
972                "SvxAccessibleTextIndex::SetIndex: index value overflow");
973     nStart = static_cast< sal_uInt16 > (aIndex.GetIndex());
974 
975     aIndex.SetEEIndex( nPara, nEnd, *this );
976     DBG_ASSERT(aIndex.GetIndex() >= 0 &&
977                aIndex.GetIndex() <= USHRT_MAX,
978                "SvxAccessibleTextIndex::SetIndex: index value overflow");
979     nEnd = static_cast< sal_uInt16 > (aIndex.GetIndex());
980 
981     return sal_True;
982 }
983 
984 sal_Bool SvxAccessibleTextAdapter::GetAttributeRun( sal_uInt16& nStartIndex, sal_uInt16& nEndIndex, sal_uInt16 nPara, sal_uInt16 nIndex ) const
985 {
986     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
987 
988     SvxAccessibleTextIndex aIndex;
989     aIndex.SetIndex(nPara, nIndex, *this);
990     nIndex = aIndex.GetEEIndex();
991 
992     if( aIndex.InBullet() )
993     {
994         DBG_ASSERT(aIndex.GetBulletLen() >= 0 &&
995                    aIndex.GetBulletLen() <= USHRT_MAX,
996                    "SvxAccessibleTextIndex::SetIndex: index value overflow");
997 
998         // always treat bullet as distinct attribute
999         nStartIndex = 0;
1000         nEndIndex = static_cast< sal_uInt16 > (aIndex.GetBulletLen());
1001 
1002         return sal_True;
1003     }
1004 
1005     if( aIndex.InField() )
1006     {
1007         DBG_ASSERT(aIndex.GetIndex() - aIndex.GetFieldOffset() >= 0 &&
1008                    aIndex.GetIndex() - aIndex.GetFieldOffset() <= USHRT_MAX,
1009                    "SvxAccessibleTextIndex::SetIndex: index value overflow");
1010 
1011         // always treat field as distinct attribute
1012         nStartIndex = static_cast< sal_uInt16 > (aIndex.GetIndex() - aIndex.GetFieldOffset());
1013         nEndIndex = static_cast< sal_uInt16 > (nStartIndex + aIndex.GetFieldLen());
1014 
1015         return sal_True;
1016     }
1017 
1018     if( !mrTextForwarder->GetAttributeRun( nStartIndex, nEndIndex, nPara, nIndex ) )
1019         return sal_False;
1020 
1021     aIndex.SetEEIndex( nPara, nStartIndex, *this );
1022     DBG_ASSERT(aIndex.GetIndex() >= 0 &&
1023                aIndex.GetIndex() <= USHRT_MAX,
1024                "SvxAccessibleTextIndex::SetIndex: index value overflow");
1025     nStartIndex = static_cast< sal_uInt16 > (aIndex.GetIndex());
1026 
1027     aIndex.SetEEIndex( nPara, nEndIndex, *this );
1028     DBG_ASSERT(aIndex.GetIndex() >= 0 &&
1029                aIndex.GetIndex() <= USHRT_MAX,
1030                "SvxAccessibleTextIndex::SetIndex: index value overflow");
1031     nEndIndex = static_cast< sal_uInt16 > (aIndex.GetIndex());
1032 
1033     return sal_True;
1034 }
1035 
1036 sal_uInt16 SvxAccessibleTextAdapter::GetLineCount( sal_uInt16 nPara ) const
1037 {
1038     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
1039 
1040     return mrTextForwarder->GetLineCount( nPara );
1041 }
1042 
1043 sal_uInt16 SvxAccessibleTextAdapter::GetLineLen( sal_uInt16 nPara, sal_uInt16 nLine ) const
1044 {
1045     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
1046 
1047     SvxAccessibleTextIndex aStartIndex;
1048     SvxAccessibleTextIndex aEndIndex;
1049     sal_uInt16 nCurrLine;
1050     sal_uInt16 nCurrIndex, nLastIndex;
1051     for( nCurrLine=0, nCurrIndex=0, nLastIndex=0; nCurrLine<=nLine; ++nCurrLine )
1052     {
1053         nLastIndex = nCurrIndex;
1054         nCurrIndex =
1055             nCurrIndex + mrTextForwarder->GetLineLen( nPara, nCurrLine );
1056     }
1057 
1058     aEndIndex.SetEEIndex( nPara, nCurrIndex, *this );
1059     if( nLine > 0 )
1060     {
1061         aStartIndex.SetEEIndex( nPara, nLastIndex, *this );
1062 
1063         return static_cast< sal_uInt16 >(aEndIndex.GetIndex() - aStartIndex.GetIndex());
1064     }
1065     else
1066         return static_cast< sal_uInt16 >(aEndIndex.GetIndex());
1067 }
1068 
1069 void SvxAccessibleTextAdapter::GetLineBoundaries( /*out*/sal_uInt16 &rStart, /*out*/sal_uInt16 &rEnd, sal_uInt16 nParagraph, sal_uInt16 nLine ) const
1070 {
1071     mrTextForwarder->GetLineBoundaries( rStart, rEnd, nParagraph, nLine );
1072 }
1073 
1074 sal_uInt16 SvxAccessibleTextAdapter::GetLineNumberAtIndex( sal_uInt16 nPara, sal_uInt16 nIndex ) const
1075 {
1076     return mrTextForwarder->GetLineNumberAtIndex( nPara, nIndex );
1077 }
1078 
1079 sal_Bool SvxAccessibleTextAdapter::Delete( const ESelection& rSel )
1080 {
1081     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
1082 
1083     SvxAccessibleTextIndex aStartIndex;
1084     SvxAccessibleTextIndex aEndIndex;
1085 
1086     aStartIndex.SetIndex( rSel.nStartPara, rSel.nStartPos, *this );
1087     aEndIndex.SetIndex( rSel.nEndPara, rSel.nEndPos, *this );
1088 
1089     return mrTextForwarder->Delete( MakeEESelection(aStartIndex, aEndIndex ) );
1090 }
1091 
1092 sal_Bool SvxAccessibleTextAdapter::InsertText( const String& rStr, const ESelection& rSel )
1093 {
1094     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
1095 
1096     SvxAccessibleTextIndex aStartIndex;
1097     SvxAccessibleTextIndex aEndIndex;
1098 
1099     aStartIndex.SetIndex( rSel.nStartPara, rSel.nStartPos, *this );
1100     aEndIndex.SetIndex( rSel.nEndPara, rSel.nEndPos, *this );
1101 
1102     return mrTextForwarder->InsertText( rStr, MakeEESelection(aStartIndex, aEndIndex) );
1103 }
1104 
1105 sal_Bool SvxAccessibleTextAdapter::QuickFormatDoc( sal_Bool bFull )
1106 {
1107     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
1108 
1109     return mrTextForwarder->QuickFormatDoc( bFull );
1110 }
1111 
1112 sal_Int16 SvxAccessibleTextAdapter::GetDepth( sal_uInt16 nPara ) const
1113 {
1114     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
1115 
1116     return mrTextForwarder->GetDepth( nPara );
1117 }
1118 
1119 sal_Bool SvxAccessibleTextAdapter::SetDepth( sal_uInt16 nPara, sal_Int16 nNewDepth )
1120 {
1121     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
1122 
1123     return mrTextForwarder->SetDepth( nPara, nNewDepth );
1124 }
1125 
1126 void SvxAccessibleTextAdapter::SetForwarder( SvxTextForwarder& rForwarder )
1127 {
1128     mrTextForwarder = &rForwarder;
1129 }
1130 
1131 sal_Bool SvxAccessibleTextAdapter::HaveImageBullet( sal_uInt16 nPara ) const
1132 {
1133     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
1134 
1135     EBulletInfo aBulletInfo = GetBulletInfo( nPara );
1136 
1137     if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND &&
1138         aBulletInfo.bVisible &&
1139         aBulletInfo.nType == SVX_NUM_BITMAP )
1140     {
1141         return sal_True;
1142     }
1143     else
1144     {
1145         return sal_False;
1146     }
1147 }
1148 
1149 sal_Bool SvxAccessibleTextAdapter::HaveTextBullet( sal_uInt16 nPara ) const
1150 {
1151     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
1152 
1153     EBulletInfo aBulletInfo = GetBulletInfo( nPara );
1154 
1155     if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND &&
1156         aBulletInfo.bVisible &&
1157         aBulletInfo.nType != SVX_NUM_BITMAP )
1158     {
1159         return sal_True;
1160     }
1161     else
1162     {
1163         return sal_False;
1164     }
1165 }
1166 
1167 sal_Bool SvxAccessibleTextAdapter::IsEditable( const ESelection& rSel )
1168 {
1169     DBG_ASSERT(mrTextForwarder, "SvxAccessibleTextAdapter: no forwarder");
1170 
1171     SvxAccessibleTextIndex aStartIndex;
1172     SvxAccessibleTextIndex aEndIndex;
1173 
1174     aStartIndex.SetIndex( rSel.nStartPara, rSel.nStartPos, *this );
1175     aEndIndex.SetIndex( rSel.nEndPara, rSel.nEndPos, *this );
1176 
1177     // normalize selection
1178     if( rSel.nStartPara > rSel.nEndPara ||
1179         (rSel.nStartPara == rSel.nEndPara && rSel.nStartPos > rSel.nEndPos) )
1180     {
1181         ::std::swap( aStartIndex, aEndIndex );
1182     }
1183 
1184     return aStartIndex.IsEditableRange( aEndIndex );
1185 }
1186 
1187 const SfxItemSet * SvxAccessibleTextAdapter::GetEmptyItemSetPtr()
1188 {
1189     DBG_ERROR( "not implemented" );
1190     return 0;
1191 }
1192 
1193 void SvxAccessibleTextAdapter::AppendParagraph()
1194 {
1195     DBG_ERROR( "not implemented" );
1196 }
1197 
1198 xub_StrLen SvxAccessibleTextAdapter::AppendTextPortion( sal_uInt16, const String &, const SfxItemSet & )
1199 {
1200     DBG_ERROR( "not implemented" );
1201     return 0;
1202 }
1203 void        SvxAccessibleTextAdapter::CopyText(const SvxTextForwarder&)
1204 {
1205     DBG_ERROR( "not implemented" );
1206 }
1207 
1208 
1209 
1210 //---------------------------------------------------------------------------------------
1211 
1212 SvxAccessibleTextEditViewAdapter::SvxAccessibleTextEditViewAdapter()
1213 {
1214 }
1215 
1216 SvxAccessibleTextEditViewAdapter::~SvxAccessibleTextEditViewAdapter()
1217 {
1218 }
1219 
1220 sal_Bool SvxAccessibleTextEditViewAdapter::IsValid() const
1221 {
1222     DBG_ASSERT(mrViewForwarder, "SvxAccessibleTextEditViewAdapter: no forwarder");
1223 
1224     if( mrViewForwarder )
1225         return mrViewForwarder->IsValid();
1226     else
1227         return sal_False;
1228 }
1229 
1230 Rectangle SvxAccessibleTextEditViewAdapter::GetVisArea() const
1231 {
1232     DBG_ASSERT(mrViewForwarder, "SvxAccessibleTextEditViewAdapter: no forwarder");
1233 
1234     return mrViewForwarder->GetVisArea();
1235 }
1236 
1237 Point SvxAccessibleTextEditViewAdapter::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
1238 {
1239     DBG_ASSERT(mrViewForwarder, "SvxAccessibleTextEditViewAdapter: no forwarder");
1240 
1241     return mrViewForwarder->LogicToPixel(rPoint, rMapMode);
1242 }
1243 
1244 Point SvxAccessibleTextEditViewAdapter::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
1245 {
1246     DBG_ASSERT(mrViewForwarder, "SvxAccessibleTextEditViewAdapter: no forwarder");
1247 
1248     return mrViewForwarder->PixelToLogic(rPoint, rMapMode);
1249 }
1250 
1251 sal_Bool SvxAccessibleTextEditViewAdapter::GetSelection( ESelection& rSel ) const
1252 {
1253     DBG_ASSERT(mrViewForwarder, "SvxAccessibleTextEditViewAdapter: no forwarder");
1254 
1255     ESelection aSelection;
1256 
1257     if( !mrViewForwarder->GetSelection( aSelection ) )
1258         return sal_False;
1259 
1260     SvxAccessibleTextIndex aStartIndex;
1261     SvxAccessibleTextIndex aEndIndex;
1262 
1263     aStartIndex.SetEEIndex( aSelection.nStartPara, aSelection.nStartPos, *mrTextForwarder );
1264     aEndIndex.SetEEIndex( aSelection.nEndPara, aSelection.nEndPos, *mrTextForwarder );
1265 
1266     DBG_ASSERT(aStartIndex.GetIndex() >= 0 && aStartIndex.GetIndex() <= USHRT_MAX &&
1267                aEndIndex.GetIndex() >= 0 && aEndIndex.GetIndex() <= USHRT_MAX,
1268                "SvxAccessibleTextEditViewAdapter::GetSelection: index value overflow");
1269 
1270     rSel = ESelection( aStartIndex.GetParagraph(), static_cast< sal_uInt16 > (aStartIndex.GetIndex()),
1271                        aEndIndex.GetParagraph(), static_cast< sal_uInt16 > (aEndIndex.GetIndex()) );
1272 
1273     return sal_True;
1274 }
1275 
1276 sal_Bool SvxAccessibleTextEditViewAdapter::SetSelection( const ESelection& rSel )
1277 {
1278     DBG_ASSERT(mrViewForwarder, "SvxAccessibleTextEditViewAdapter: no forwarder");
1279 
1280     SvxAccessibleTextIndex aStartIndex;
1281     SvxAccessibleTextIndex aEndIndex;
1282 
1283     aStartIndex.SetIndex( rSel.nStartPara, rSel.nStartPos, *mrTextForwarder );
1284     aEndIndex.SetIndex( rSel.nEndPara, rSel.nEndPos, *mrTextForwarder );
1285 
1286     return mrViewForwarder->SetSelection( MakeEESelection(aStartIndex, aEndIndex) );
1287 }
1288 
1289 sal_Bool SvxAccessibleTextEditViewAdapter::Copy()
1290 {
1291     DBG_ASSERT(mrViewForwarder, "SvxAccessibleTextEditViewAdapter: no forwarder");
1292 
1293     return mrViewForwarder->Copy();
1294 }
1295 
1296 sal_Bool SvxAccessibleTextEditViewAdapter::Cut()
1297 {
1298     DBG_ASSERT(mrViewForwarder, "SvxAccessibleTextEditViewAdapter: no forwarder");
1299 
1300     return mrViewForwarder->Cut();
1301 }
1302 
1303 sal_Bool SvxAccessibleTextEditViewAdapter::Paste()
1304 {
1305     DBG_ASSERT(mrViewForwarder, "SvxAccessibleTextEditViewAdapter: no forwarder");
1306 
1307     return mrViewForwarder->Paste();
1308 }
1309 
1310 void SvxAccessibleTextEditViewAdapter::SetForwarder( SvxEditViewForwarder& 		rForwarder,
1311                                                      SvxAccessibleTextAdapter&	rTextForwarder )
1312 {
1313     mrViewForwarder = &rForwarder;
1314     mrTextForwarder = &rTextForwarder;
1315 }
1316 
1317