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