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