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