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 <editeng/flditem.hxx>
34 : #include <com/sun/star/uno/Any.hxx>
35 : #include <com/sun/star/uno/Reference.hxx>
36 : #include <com/sun/star/awt/Point.hpp>
37 : #include <com/sun/star/awt/Rectangle.hpp>
38 : #include <com/sun/star/lang/DisposedException.hpp>
39 : #include <com/sun/star/accessibility/AccessibleRole.hpp>
40 : #include <com/sun/star/accessibility/AccessibleTextType.hpp>
41 : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
42 : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
43 : #include <comphelper/accessibleeventnotifier.hxx>
44 : #include <comphelper/sequenceashashmap.hxx>
45 : #include <cppuhelper/supportsservice.hxx>
46 : #include <unotools/accessiblestatesethelper.hxx>
47 : #include <unotools/accessiblerelationsethelper.hxx>
48 : #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
49 : #include <vcl/unohelp.hxx>
50 : #include <vcl/settings.hxx>
51 :
52 : #include <editeng/editeng.hxx>
53 : #include <editeng/unoprnms.hxx>
54 : #include <editeng/unoipset.hxx>
55 : #include <editeng/outliner.hxx>
56 : #include <svl/intitem.hxx>
57 :
58 :
59 :
60 : // Project-local header
61 :
62 :
63 :
64 : #include <com/sun/star/beans/PropertyState.hpp>
65 :
66 : #include <editeng/unolingu.hxx>
67 : #include <editeng/unopracc.hxx>
68 : #include "editeng/AccessibleEditableTextPara.hxx"
69 : #include "AccessibleHyperlink.hxx"
70 :
71 : #include <svtools/colorcfg.hxx>
72 : using namespace std;
73 : #include "editeng.hrc"
74 : #include <editeng/eerdll.hxx>
75 : #include <editeng/numitem.hxx>
76 : #include <boost/scoped_array.hpp>
77 :
78 : using namespace ::com::sun::star;
79 : using namespace ::com::sun::star::beans;
80 : using namespace ::com::sun::star::accessibility;
81 :
82 :
83 :
84 : // AccessibleEditableTextPara implementation
85 :
86 :
87 :
88 : namespace accessibility
89 : {
90 4 : const SvxItemPropertySet* ImplGetSvxCharAndParaPropertiesSet()
91 : {
92 : // PropertyMap for character and paragraph properties
93 : static const SfxItemPropertyMapEntry aPropMap[] =
94 : {
95 10 : SVX_UNOEDIT_OUTLINER_PROPERTIES,
96 98 : SVX_UNOEDIT_CHAR_PROPERTIES,
97 28 : SVX_UNOEDIT_PARA_PROPERTIES,
98 4 : SVX_UNOEDIT_NUMBERING_PROPERTIE,
99 2 : {OUString("TextUserDefinedAttributes"), EE_CHAR_XMLATTRIBS, cppu::UnoType<com::sun::star::container::XNameContainer>::get(), 0, 0},
100 2 : {OUString("ParaUserDefinedAttributes"), EE_PARA_XMLATTRIBS, cppu::UnoType<com::sun::star::container::XNameContainer>::get(), 0, 0},
101 : { OUString(), 0, css::uno::Type(), 0, 0 }
102 150 : };
103 4 : static SvxItemPropertySet aPropSet( aPropMap, EditEngine::GetGlobalItemPool() );
104 4 : return &aPropSet;
105 : }
106 :
107 : // #i27138# - add parameter <_pParaManager>
108 62 : AccessibleEditableTextPara::AccessibleEditableTextPara(
109 : const uno::Reference< XAccessible >& rParent,
110 : const AccessibleParaManager* _pParaManager )
111 : : AccessibleTextParaInterfaceBase( m_aMutex ),
112 : mnParagraphIndex( 0 ),
113 : mnIndexInParent( 0 ),
114 : mpEditSource( NULL ),
115 : maEEOffset( 0, 0 ),
116 : mxParent( rParent ),
117 : // well, that's strictly (UNO) exception safe, though not
118 : // really robust. We rely on the fact that this member is
119 : // constructed last, and that the constructor body catches
120 : // exceptions, thus no chance for exceptions once the Id is
121 : // fetched. Nevertheless, normally should employ RAII here...
122 62 : mnNotifierClientId(::comphelper::AccessibleEventNotifier::registerClient()),
123 : // #i27138#
124 124 : mpParaManager( _pParaManager )
125 : {
126 : #ifdef DBG_UTIL
127 : OSL_TRACE( "AccessibleEditableTextPara received ID: %d", mnNotifierClientId );
128 : #endif
129 :
130 : try
131 : {
132 : // Create the state set.
133 62 : ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper ();
134 62 : mxStateSet = pStateSet;
135 :
136 : // these are always on
137 62 : pStateSet->AddState( AccessibleStateType::MULTI_LINE );
138 62 : pStateSet->AddState( AccessibleStateType::FOCUSABLE );
139 62 : pStateSet->AddState( AccessibleStateType::VISIBLE );
140 62 : pStateSet->AddState( AccessibleStateType::SHOWING );
141 62 : pStateSet->AddState( AccessibleStateType::ENABLED );
142 62 : pStateSet->AddState( AccessibleStateType::SENSITIVE );
143 : }
144 0 : catch (const uno::Exception&)
145 : {
146 : }
147 62 : }
148 :
149 186 : AccessibleEditableTextPara::~AccessibleEditableTextPara()
150 : {
151 : // sign off from event notifier
152 62 : if( getNotifierClientId() != -1 )
153 : {
154 : try
155 : {
156 17 : ::comphelper::AccessibleEventNotifier::revokeClient( getNotifierClientId() );
157 : #ifdef DBG_UTIL
158 : OSL_TRACE( "AccessibleEditableTextPara revoked ID: %d", mnNotifierClientId );
159 : #endif
160 : }
161 0 : catch (const uno::Exception&)
162 : {
163 : }
164 : }
165 124 : }
166 :
167 260 : OUString AccessibleEditableTextPara::implGetText()
168 : {
169 260 : return GetTextRange( 0, GetTextLen() );
170 : }
171 :
172 6 : ::com::sun::star::lang::Locale AccessibleEditableTextPara::implGetLocale()
173 : {
174 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= SAL_MAX_INT32,
175 : "AccessibleEditableTextPara::getLocale: paragraph index value overflow");
176 :
177 : // return locale of first character in the paragraph
178 6 : return LanguageTag(GetTextForwarder().GetLanguage( GetParagraphIndex(), 0 )).getLocale();
179 : }
180 :
181 0 : void AccessibleEditableTextPara::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
182 : {
183 : sal_Int32 nStart, nEnd;
184 :
185 0 : if( GetSelection( nStart, nEnd ) )
186 : {
187 0 : nStartIndex = nStart;
188 0 : nEndIndex = nEnd;
189 : }
190 : else
191 : {
192 : // #102234# No exception, just set to 'invalid'
193 0 : nStartIndex = -1;
194 0 : nEndIndex = -1;
195 : }
196 0 : }
197 :
198 8 : void AccessibleEditableTextPara::implGetParagraphBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 /*nIndex*/ )
199 : {
200 : DBG_WARNING( "AccessibleEditableTextPara::implGetParagraphBoundary: only a base implementation, ignoring the index" );
201 :
202 8 : rBoundary.startPos = 0;
203 : //rBoundary.endPos = GetTextLen();
204 8 : OUString sText( implGetText() );
205 8 : sal_Int32 nLength = sText.getLength();
206 8 : rBoundary.endPos = nLength;
207 8 : }
208 :
209 0 : void AccessibleEditableTextPara::implGetLineBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 nIndex )
210 : {
211 0 : SvxTextForwarder& rCacheTF = GetTextForwarder();
212 0 : const sal_Int32 nParaIndex = GetParagraphIndex();
213 :
214 : DBG_ASSERT(nParaIndex >= 0 && nParaIndex <= SAL_MAX_INT32,
215 : "AccessibleEditableTextPara::implGetLineBoundary: paragraph index value overflow");
216 :
217 0 : const sal_Int32 nTextLen = rCacheTF.GetTextLen( nParaIndex );
218 :
219 0 : CheckPosition(nIndex);
220 :
221 0 : rBoundary.startPos = rBoundary.endPos = -1;
222 :
223 0 : const sal_Int32 nLineCount=rCacheTF.GetLineCount( nParaIndex );
224 :
225 0 : if( nIndex == nTextLen )
226 : {
227 : // #i17014# Special-casing one-behind-the-end character
228 0 : if( nLineCount <= 1 )
229 0 : rBoundary.startPos = 0;
230 : else
231 0 : rBoundary.startPos = nTextLen - rCacheTF.GetLineLen( nParaIndex,
232 0 : nLineCount-1 );
233 :
234 0 : rBoundary.endPos = nTextLen;
235 : }
236 : else
237 : {
238 : // normal line search
239 : sal_Int32 nLine;
240 : sal_Int32 nCurIndex;
241 0 : for( nLine=0, nCurIndex=0; nLine<nLineCount; ++nLine )
242 : {
243 0 : nCurIndex += rCacheTF.GetLineLen( nParaIndex, nLine);
244 :
245 0 : if( nCurIndex > nIndex )
246 : {
247 0 : rBoundary.startPos = nCurIndex - rCacheTF.GetLineLen( nParaIndex, nLine);
248 0 : rBoundary.endPos = nCurIndex;
249 0 : break;
250 : }
251 : }
252 : }
253 0 : }
254 :
255 :
256 52 : void AccessibleEditableTextPara::SetIndexInParent( sal_Int32 nIndex )
257 : {
258 52 : mnIndexInParent = nIndex;
259 52 : }
260 :
261 :
262 52 : void AccessibleEditableTextPara::SetParagraphIndex( sal_Int32 nIndex )
263 : {
264 52 : sal_Int32 nOldIndex = mnParagraphIndex;
265 :
266 52 : mnParagraphIndex = nIndex;
267 :
268 52 : WeakBullet::HardRefType aChild( maImageBullet.get() );
269 52 : if( aChild.is() )
270 0 : aChild->SetParagraphIndex(mnParagraphIndex);
271 :
272 : try
273 : {
274 52 : if( nOldIndex != nIndex )
275 : {
276 0 : uno::Any aOldDesc;
277 0 : uno::Any aOldName;
278 :
279 : try
280 : {
281 0 : aOldDesc <<= getAccessibleDescription();
282 0 : aOldName <<= getAccessibleName();
283 : }
284 0 : catch (const uno::Exception&) // optional behaviour
285 : {
286 : }
287 : // index and therefore description changed
288 0 : FireEvent( AccessibleEventId::DESCRIPTION_CHANGED, uno::makeAny( getAccessibleDescription() ), aOldDesc );
289 0 : FireEvent( AccessibleEventId::NAME_CHANGED, uno::makeAny( getAccessibleName() ), aOldName );
290 : }
291 : }
292 0 : catch (const uno::Exception&) // optional behaviour
293 : {
294 52 : }
295 52 : }
296 :
297 :
298 51 : void AccessibleEditableTextPara::Dispose()
299 : {
300 51 : int nClientId( getNotifierClientId() );
301 :
302 : // #108212# drop all references before notifying dispose
303 51 : mxParent = NULL;
304 51 : mnNotifierClientId = -1;
305 51 : mpEditSource = NULL;
306 :
307 : // notify listeners
308 51 : if( nClientId != -1 )
309 : {
310 : try
311 : {
312 45 : uno::Reference < XAccessibleContext > xThis = getAccessibleContext();
313 :
314 : // #106234# Delegate to EventNotifier
315 45 : ::comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( nClientId, xThis );
316 : #ifdef DBG_UTIL
317 : OSL_TRACE( "Disposed ID: %d", nClientId );
318 : #endif
319 : }
320 0 : catch (const uno::Exception&)
321 : {
322 : }
323 : }
324 51 : }
325 :
326 66 : void AccessibleEditableTextPara::SetEditSource( SvxEditSourceAdapter* pEditSource )
327 : {
328 66 : WeakBullet::HardRefType aChild( maImageBullet.get() );
329 66 : if( aChild.is() )
330 0 : aChild->SetEditSource(pEditSource);
331 :
332 66 : if( !pEditSource )
333 : {
334 : // going defunc
335 4 : UnSetState( AccessibleStateType::SHOWING );
336 4 : UnSetState( AccessibleStateType::VISIBLE );
337 4 : SetState( AccessibleStateType::INVALID );
338 4 : SetState( AccessibleStateType::DEFUNC );
339 :
340 4 : Dispose();
341 : }
342 66 : mpEditSource = pEditSource;
343 : // #108900# Init last text content
344 : try
345 : {
346 66 : TextChanged();
347 : }
348 4 : catch (const uno::RuntimeException&)
349 : {
350 66 : }
351 66 : }
352 :
353 268 : ESelection AccessibleEditableTextPara::MakeSelection( sal_Int32 nStartEEIndex, sal_Int32 nEndEEIndex )
354 : {
355 : // check overflow
356 : DBG_ASSERT(nStartEEIndex >= 0 && nStartEEIndex <= USHRT_MAX &&
357 : nEndEEIndex >= 0 && nEndEEIndex <= USHRT_MAX &&
358 : GetParagraphIndex() >= 0 && GetParagraphIndex() <= SAL_MAX_INT32,
359 : "AccessibleEditableTextPara::MakeSelection: index value overflow");
360 :
361 268 : sal_Int32 nParaIndex = GetParagraphIndex();
362 268 : return ESelection(nParaIndex, nStartEEIndex, nParaIndex, nEndEEIndex);
363 : }
364 :
365 2 : ESelection AccessibleEditableTextPara::MakeSelection( sal_Int32 nEEIndex )
366 : {
367 2 : return MakeSelection( nEEIndex, nEEIndex+1 );
368 : }
369 :
370 0 : ESelection AccessibleEditableTextPara::MakeCursor( sal_Int32 nEEIndex )
371 : {
372 0 : return MakeSelection( nEEIndex, nEEIndex );
373 : }
374 :
375 8 : void AccessibleEditableTextPara::CheckIndex( sal_Int32 nIndex )
376 : {
377 8 : if( nIndex < 0 || nIndex >= getCharacterCount() )
378 : throw lang::IndexOutOfBoundsException("AccessibleEditableTextPara: character index out of bounds",
379 : uno::Reference< uno::XInterface >
380 4 : ( static_cast< ::cppu::OWeakObject* > (this) ) ); // disambiguate hierarchy
381 4 : }
382 :
383 62 : void AccessibleEditableTextPara::CheckPosition( sal_Int32 nIndex )
384 : {
385 62 : if( nIndex < 0 || nIndex > getCharacterCount() )
386 : throw lang::IndexOutOfBoundsException("AccessibleEditableTextPara: character position out of bounds",
387 : uno::Reference< uno::XInterface >
388 8 : ( static_cast< ::cppu::OWeakObject* > (this) ) ); // disambiguate hierarchy
389 54 : }
390 :
391 6 : void AccessibleEditableTextPara::CheckRange( sal_Int32 nStart, sal_Int32 nEnd )
392 : {
393 6 : CheckPosition( nStart );
394 2 : CheckPosition( nEnd );
395 2 : }
396 :
397 0 : bool AccessibleEditableTextPara::GetSelection(sal_Int32 &nStartPos, sal_Int32 &nEndPos)
398 : {
399 0 : ESelection aSelection;
400 0 : sal_Int32 nPara = GetParagraphIndex();
401 0 : if( !GetEditViewForwarder().GetSelection( aSelection ) )
402 0 : return false;
403 :
404 0 : if( aSelection.nStartPara < aSelection.nEndPara )
405 : {
406 0 : if( aSelection.nStartPara > nPara ||
407 0 : aSelection.nEndPara < nPara )
408 0 : return false;
409 :
410 0 : if( nPara == aSelection.nStartPara )
411 0 : nStartPos = aSelection.nStartPos;
412 : else
413 0 : nStartPos = 0;
414 :
415 0 : if( nPara == aSelection.nEndPara )
416 0 : nEndPos = aSelection.nEndPos;
417 : else
418 0 : nEndPos = GetTextLen();
419 : }
420 : else
421 : {
422 0 : if( aSelection.nStartPara < nPara ||
423 0 : aSelection.nEndPara > nPara )
424 0 : return false;
425 :
426 0 : if( nPara == aSelection.nStartPara )
427 0 : nStartPos = aSelection.nStartPos;
428 : else
429 0 : nStartPos = GetTextLen();
430 :
431 0 : if( nPara == aSelection.nEndPara )
432 0 : nEndPos = aSelection.nEndPos;
433 : else
434 0 : nEndPos = 0;
435 : }
436 :
437 0 : return true;
438 : }
439 :
440 264 : OUString AccessibleEditableTextPara::GetTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
441 : {
442 264 : return GetTextForwarder().GetText( MakeSelection(nStartIndex, nEndIndex) );
443 : }
444 :
445 262 : sal_Int32 AccessibleEditableTextPara::GetTextLen() const
446 : {
447 262 : return GetTextForwarder().GetTextLen(GetParagraphIndex());
448 : }
449 :
450 1114 : SvxEditSourceAdapter& AccessibleEditableTextPara::GetEditSource() const
451 : {
452 1114 : if( mpEditSource )
453 2220 : return *mpEditSource;
454 : else
455 : throw uno::RuntimeException("No edit source, object is defunct",
456 : uno::Reference< uno::XInterface >
457 : ( static_cast< ::cppu::OWeakObject* >
458 4 : ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy
459 : }
460 :
461 898 : SvxAccessibleTextAdapter& AccessibleEditableTextPara::GetTextForwarder() const
462 : {
463 898 : SvxEditSourceAdapter& rEditSource = GetEditSource();
464 894 : SvxAccessibleTextAdapter* pTextForwarder = rEditSource.GetTextForwarderAdapter();
465 :
466 894 : if( !pTextForwarder )
467 : throw uno::RuntimeException("Unable to fetch text forwarder, object is defunct",
468 : uno::Reference< uno::XInterface >
469 : ( static_cast< ::cppu::OWeakObject* >
470 0 : ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy
471 :
472 894 : if( pTextForwarder->IsValid() )
473 1788 : return *pTextForwarder;
474 : else
475 : throw uno::RuntimeException("Text forwarder is invalid, object is defunct",
476 : uno::Reference< uno::XInterface >
477 : ( static_cast< ::cppu::OWeakObject* >
478 0 : ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy
479 : }
480 :
481 210 : SvxViewForwarder& AccessibleEditableTextPara::GetViewForwarder() const
482 : {
483 210 : SvxEditSource& rEditSource = GetEditSource();
484 210 : SvxViewForwarder* pViewForwarder = rEditSource.GetViewForwarder();
485 :
486 210 : if( !pViewForwarder )
487 : {
488 : throw uno::RuntimeException("Unable to fetch view forwarder, object is defunct",
489 : uno::Reference< uno::XInterface >
490 : ( static_cast< ::cppu::OWeakObject* >
491 0 : ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy
492 : }
493 :
494 210 : if( pViewForwarder->IsValid() )
495 420 : return *pViewForwarder;
496 : else
497 : throw uno::RuntimeException("View forwarder is invalid, object is defunct",
498 : uno::Reference< uno::XInterface >
499 : ( static_cast< ::cppu::OWeakObject* >
500 0 : ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy
501 : }
502 :
503 2 : SvxAccessibleTextEditViewAdapter& AccessibleEditableTextPara::GetEditViewForwarder( bool bCreate ) const
504 : {
505 2 : SvxEditSourceAdapter& rEditSource = GetEditSource();
506 2 : SvxAccessibleTextEditViewAdapter* pTextEditViewForwarder = rEditSource.GetEditViewForwarderAdapter( bCreate );
507 :
508 2 : if( !pTextEditViewForwarder )
509 : {
510 2 : if( bCreate )
511 : throw uno::RuntimeException("Unable to fetch view forwarder, object is defunct",
512 : uno::Reference< uno::XInterface >
513 : ( static_cast< ::cppu::OWeakObject* >
514 2 : ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy
515 : else
516 : throw uno::RuntimeException("No view forwarder, object not in edit mode",
517 : uno::Reference< uno::XInterface >
518 : ( static_cast< ::cppu::OWeakObject* >
519 0 : ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy
520 : }
521 :
522 0 : if( pTextEditViewForwarder->IsValid() )
523 0 : return *pTextEditViewForwarder;
524 : else
525 : {
526 0 : if( bCreate )
527 : throw uno::RuntimeException("View forwarder is invalid, object is defunct",
528 : uno::Reference< uno::XInterface >
529 : ( static_cast< ::cppu::OWeakObject* >
530 0 : ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy
531 : else
532 : throw uno::RuntimeException("View forwarder is invalid, object not in edit mode",
533 : uno::Reference< uno::XInterface >
534 : ( static_cast< ::cppu::OWeakObject* >
535 0 : ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy
536 : }
537 : }
538 :
539 0 : bool AccessibleEditableTextPara::HaveEditView() const
540 : {
541 0 : SvxEditSource& rEditSource = GetEditSource();
542 0 : SvxEditViewForwarder* pViewForwarder = rEditSource.GetEditViewForwarder();
543 :
544 0 : if( !pViewForwarder )
545 0 : return false;
546 :
547 0 : if( !pViewForwarder->IsValid() )
548 0 : return false;
549 :
550 0 : return true;
551 : }
552 :
553 106 : bool AccessibleEditableTextPara::HaveChildren()
554 : {
555 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= SAL_MAX_INT32,
556 : "AccessibleEditableTextPara::HaveChildren: paragraph index value overflow");
557 :
558 106 : return GetTextForwarder().HaveImageBullet( GetParagraphIndex() );
559 : }
560 :
561 292 : Rectangle AccessibleEditableTextPara::LogicToPixel( const Rectangle& rRect, const MapMode& rMapMode, SvxViewForwarder& rForwarder )
562 : {
563 : // convert to screen coordinates
564 584 : return Rectangle( rForwarder.LogicToPixel( rRect.TopLeft(), rMapMode ),
565 876 : rForwarder.LogicToPixel( rRect.BottomRight(), rMapMode ) );
566 : }
567 :
568 :
569 72 : void AccessibleEditableTextPara::SetEEOffset( const Point& rOffset )
570 : {
571 72 : WeakBullet::HardRefType aChild( maImageBullet.get() );
572 72 : if( aChild.is() )
573 0 : aChild->SetEEOffset(rOffset);
574 :
575 72 : maEEOffset = rOffset;
576 72 : }
577 :
578 82 : void AccessibleEditableTextPara::FireEvent(const sal_Int16 nEventId, const uno::Any& rNewValue, const uno::Any& rOldValue) const
579 : {
580 82 : uno::Reference < XAccessibleContext > xThis( const_cast< AccessibleEditableTextPara* > (this)->getAccessibleContext() );
581 :
582 164 : AccessibleEventObject aEvent(xThis, nEventId, rNewValue, rOldValue);
583 :
584 : // #102261# Call global queue for focus events
585 82 : if( nEventId == AccessibleEventId::STATE_CHANGED )
586 28 : vcl::unohelper::NotifyAccessibleStateEventGlobally( aEvent );
587 :
588 : // #106234# Delegate to EventNotifier
589 82 : if( getNotifierClientId() != -1 )
590 66 : ::comphelper::AccessibleEventNotifier::addEvent( getNotifierClientId(),
591 148 : aEvent );
592 82 : }
593 :
594 20 : void AccessibleEditableTextPara::GotPropertyEvent( const uno::Any& rNewValue, const sal_Int16 nEventId ) const
595 : {
596 20 : FireEvent( nEventId, rNewValue );
597 20 : }
598 :
599 8 : void AccessibleEditableTextPara::LostPropertyEvent( const uno::Any& rOldValue, const sal_Int16 nEventId ) const
600 : {
601 8 : FireEvent( nEventId, uno::Any(), rOldValue );
602 8 : }
603 :
604 20 : void AccessibleEditableTextPara::SetState( const sal_Int16 nStateId )
605 : {
606 20 : ::utl::AccessibleStateSetHelper* pStateSet = static_cast< ::utl::AccessibleStateSetHelper*>(mxStateSet.get());
607 40 : if( pStateSet != NULL &&
608 20 : !pStateSet->contains(nStateId) )
609 : {
610 20 : pStateSet->AddState( nStateId );
611 20 : GotPropertyEvent( uno::makeAny( nStateId ), AccessibleEventId::STATE_CHANGED );
612 : }
613 20 : }
614 :
615 8 : void AccessibleEditableTextPara::UnSetState( const sal_Int16 nStateId )
616 : {
617 8 : ::utl::AccessibleStateSetHelper* pStateSet = static_cast< ::utl::AccessibleStateSetHelper*>(mxStateSet.get());
618 16 : if( pStateSet != NULL &&
619 8 : pStateSet->contains(nStateId) )
620 : {
621 8 : pStateSet->RemoveState( nStateId );
622 8 : LostPropertyEvent( uno::makeAny( nStateId ), AccessibleEventId::STATE_CHANGED );
623 : }
624 8 : }
625 :
626 66 : void AccessibleEditableTextPara::TextChanged()
627 : {
628 66 : OUString aCurrentString( OCommonAccessibleText::getText() );
629 124 : uno::Any aDeleted;
630 124 : uno::Any aInserted;
631 62 : if( OCommonAccessibleText::implInitTextChangedEvent( maLastTextString, aCurrentString,
632 62 : aDeleted, aInserted) )
633 : {
634 42 : FireEvent( AccessibleEventId::TEXT_CHANGED, aInserted, aDeleted );
635 42 : maLastTextString = aCurrentString;
636 62 : }
637 62 : }
638 :
639 0 : bool AccessibleEditableTextPara::GetAttributeRun( sal_Int32& nStartIndex, sal_Int32& nEndIndex, sal_Int32 nIndex )
640 : {
641 : DBG_ASSERT(nIndex >= 0 && nIndex <= SAL_MAX_INT32,
642 : "AccessibleEditableTextPara::GetAttributeRun: index value overflow");
643 :
644 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= SAL_MAX_INT32,
645 : "AccessibleEditableTextPara::getLocale: paragraph index value overflow");
646 :
647 0 : return GetTextForwarder().GetAttributeRun( nStartIndex,
648 : nEndIndex,
649 : GetParagraphIndex(),
650 0 : nIndex );
651 : }
652 :
653 767 : uno::Any SAL_CALL AccessibleEditableTextPara::queryInterface (const uno::Type & rType) throw (uno::RuntimeException, std::exception)
654 : {
655 767 : uno::Any aRet;
656 :
657 : // must provide XAccesibleText by hand, since it comes publicly inherited by XAccessibleEditableText
658 767 : if ( rType == cppu::UnoType<XAccessibleText>::get())
659 : {
660 2 : uno::Reference< XAccessibleText > aAccText = static_cast< XAccessibleEditableText * >(this);
661 2 : aRet <<= aAccText;
662 : }
663 765 : else if ( rType == cppu::UnoType<XAccessibleEditableText>::get())
664 : {
665 0 : uno::Reference< XAccessibleEditableText > aAccEditText = this;
666 0 : aRet <<= aAccEditText;
667 : }
668 765 : else if ( rType == cppu::UnoType<XAccessibleHypertext>::get())
669 : {
670 0 : uno::Reference< XAccessibleHypertext > aAccHyperText = this;
671 0 : aRet <<= aAccHyperText;
672 : }
673 : else
674 : {
675 765 : aRet = AccessibleTextParaInterfaceBase::queryInterface(rType);
676 : }
677 :
678 767 : return aRet;
679 : }
680 :
681 : // XAccessible
682 225 : uno::Reference< XAccessibleContext > SAL_CALL AccessibleEditableTextPara::getAccessibleContext() throw (uno::RuntimeException, std::exception)
683 : {
684 : // We implement the XAccessibleContext interface in the same object
685 225 : return uno::Reference< XAccessibleContext > ( this );
686 : }
687 :
688 : // XAccessibleContext
689 106 : sal_Int32 SAL_CALL AccessibleEditableTextPara::getAccessibleChildCount() throw (uno::RuntimeException, std::exception)
690 : {
691 106 : SolarMutexGuard aGuard;
692 :
693 106 : return HaveChildren() ? 1 : 0;
694 : }
695 :
696 0 : uno::Reference< XAccessible > SAL_CALL AccessibleEditableTextPara::getAccessibleChild( sal_Int32 i ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
697 : {
698 0 : SolarMutexGuard aGuard;
699 :
700 0 : if( !HaveChildren() )
701 : throw lang::IndexOutOfBoundsException("No children available",
702 : uno::Reference< uno::XInterface >
703 0 : ( static_cast< ::cppu::OWeakObject* > (this) ) ); // static_cast: disambiguate hierarchy
704 :
705 0 : if( i != 0 )
706 : throw lang::IndexOutOfBoundsException("Invalid child index",
707 : uno::Reference< uno::XInterface >
708 0 : ( static_cast< ::cppu::OWeakObject* > (this) ) ); // static_cast: disambiguate hierarchy
709 :
710 0 : WeakBullet::HardRefType aChild( maImageBullet.get() );
711 :
712 0 : if( !aChild.is() )
713 : {
714 : // there is no hard reference available, create object then
715 0 : AccessibleImageBullet* pChild = new AccessibleImageBullet( uno::Reference< XAccessible >( this ) );
716 0 : uno::Reference< XAccessible > xChild( static_cast< ::cppu::OWeakObject* > (pChild), uno::UNO_QUERY );
717 :
718 0 : if( !xChild.is() )
719 : throw uno::RuntimeException("Child creation failed",
720 : uno::Reference< uno::XInterface >
721 0 : ( static_cast< ::cppu::OWeakObject* > (this) ) );
722 :
723 0 : aChild = WeakBullet::HardRefType( xChild, pChild );
724 :
725 0 : aChild->SetEditSource( &GetEditSource() );
726 0 : aChild->SetParagraphIndex( GetParagraphIndex() );
727 0 : aChild->SetIndexInParent( i );
728 :
729 0 : maImageBullet = aChild;
730 : }
731 :
732 0 : return aChild.getRef();
733 : }
734 :
735 124 : uno::Reference< XAccessible > SAL_CALL AccessibleEditableTextPara::getAccessibleParent() throw (uno::RuntimeException, std::exception)
736 : {
737 :
738 : #ifdef DBG_UTIL
739 : if( !mxParent.is() )
740 : OSL_TRACE( "AccessibleEditableTextPara::getAccessibleParent: no frontend set, did somebody forgot to call AccessibleTextHelper::SetEventSource()?");
741 : #endif
742 :
743 124 : return mxParent;
744 : }
745 :
746 16 : sal_Int32 SAL_CALL AccessibleEditableTextPara::getAccessibleIndexInParent() throw (uno::RuntimeException, std::exception)
747 : {
748 16 : return mnIndexInParent;
749 : }
750 :
751 80 : sal_Int16 SAL_CALL AccessibleEditableTextPara::getAccessibleRole() throw (uno::RuntimeException, std::exception)
752 : {
753 80 : return AccessibleRole::PARAGRAPH;
754 : }
755 :
756 38 : OUString SAL_CALL AccessibleEditableTextPara::getAccessibleDescription() throw (uno::RuntimeException, std::exception)
757 : {
758 38 : SolarMutexGuard aGuard;
759 :
760 : // append first 40 characters from text, or first line, if shorter
761 : // (writer takes first sentence here, but that's not supported
762 : // from EditEngine)
763 : // throws if defunc
764 76 : OUString aLine;
765 :
766 38 : if( getCharacterCount() )
767 8 : aLine = getTextAtIndex(0, AccessibleTextType::LINE).SegmentText;
768 :
769 : // Get the string from the resource for the specified id.
770 76 : OUString sStr(EditResId(RID_SVXSTR_A11Y_PARAGRAPH_DESCRIPTION));
771 76 : OUString sParaIndex = OUString::number(GetParagraphIndex());
772 38 : sStr = sStr.replaceFirst("$(ARG)", sParaIndex);
773 :
774 38 : if( aLine.getLength() > MaxDescriptionLen )
775 : {
776 0 : OUString aCurrWord;
777 : sal_Int32 i;
778 :
779 : // search backward from MaxDescriptionLen for previous word start
780 0 : for( aCurrWord=getTextAtIndex(MaxDescriptionLen, AccessibleTextType::WORD).SegmentText,
781 : i=MaxDescriptionLen,
782 0 : aLine=OUString();
783 : i>=0;
784 : --i )
785 : {
786 0 : if( getTextAtIndex(i, AccessibleTextType::WORD).SegmentText != aCurrWord )
787 : {
788 0 : if( i == 0 )
789 : // prevent completely empty string
790 0 : aLine = getTextAtIndex(0, AccessibleTextType::WORD).SegmentText;
791 : else
792 0 : aLine = getTextRange(0, i);
793 : }
794 0 : }
795 : }
796 :
797 76 : return OUString( sStr ) + aLine;
798 : }
799 :
800 42 : OUString SAL_CALL AccessibleEditableTextPara::getAccessibleName() throw (uno::RuntimeException, std::exception)
801 : {
802 42 : SolarMutexGuard aGuard;
803 :
804 : // throws if defunc
805 42 : sal_Int32 nPara( GetParagraphIndex() );
806 :
807 : // Get the string from the resource for the specified id.
808 84 : OUString sStr(EditResId(RID_SVXSTR_A11Y_PARAGRAPH_NAME));
809 84 : OUString sParaIndex = OUString::number(nPara);
810 84 : return sStr.replaceFirst("$(ARG)", sParaIndex);
811 : }
812 :
813 2 : uno::Reference< XAccessibleRelationSet > SAL_CALL AccessibleEditableTextPara::getAccessibleRelationSet() throw (uno::RuntimeException, std::exception)
814 : {
815 : // #i27138# - provide relations CONTENT_FLOWS_FROM
816 : // and CONTENT_FLOWS_TO
817 2 : if ( mpParaManager )
818 : {
819 : utl::AccessibleRelationSetHelper* pAccRelSetHelper =
820 2 : new utl::AccessibleRelationSetHelper();
821 2 : sal_Int32 nMyParaIndex( GetParagraphIndex() );
822 : // relation CONTENT_FLOWS_FROM
823 2 : if ( nMyParaIndex > 0 &&
824 0 : mpParaManager->IsReferencable( nMyParaIndex - 1 ) )
825 : {
826 0 : uno::Sequence<uno::Reference<XInterface> > aSequence(1);
827 0 : aSequence[0] =
828 0 : mpParaManager->GetChild( nMyParaIndex - 1 ).first.get().getRef();
829 : AccessibleRelation aAccRel( AccessibleRelationType::CONTENT_FLOWS_FROM,
830 0 : aSequence );
831 0 : pAccRelSetHelper->AddRelation( aAccRel );
832 : }
833 :
834 : // relation CONTENT_FLOWS_TO
835 2 : if ( (nMyParaIndex + 1) < (sal_Int32)mpParaManager->GetNum() &&
836 0 : mpParaManager->IsReferencable( nMyParaIndex + 1 ) )
837 : {
838 0 : uno::Sequence<uno::Reference<XInterface> > aSequence(1);
839 0 : aSequence[0] =
840 0 : mpParaManager->GetChild( nMyParaIndex + 1 ).first.get().getRef();
841 : AccessibleRelation aAccRel( AccessibleRelationType::CONTENT_FLOWS_TO,
842 0 : aSequence );
843 0 : pAccRelSetHelper->AddRelation( aAccRel );
844 : }
845 :
846 2 : return pAccRelSetHelper;
847 : }
848 : else
849 : {
850 : // no relations, therefore empty
851 0 : return uno::Reference< XAccessibleRelationSet >();
852 : }
853 : }
854 :
855 0 : static uno::Sequence< OUString > getAttributeNames()
856 : {
857 : static uno::Sequence< OUString >* pNames = NULL;
858 :
859 0 : if( pNames == NULL )
860 : {
861 0 : uno::Sequence< OUString >* pSeq = new uno::Sequence< OUString >( 21 );
862 0 : OUString* pStrings = pSeq->getArray();
863 0 : sal_Int32 i = 0;
864 : #define STR(x) pStrings[i++] = OUString(x)
865 0 : STR("CharColor");
866 0 : STR("CharContoured");
867 0 : STR("CharEmphasis");
868 0 : STR("CharEscapement");
869 0 : STR("CharFontName");
870 0 : STR("CharHeight");
871 0 : STR("CharPosture");
872 0 : STR("CharShadowed");
873 0 : STR("CharStrikeout");
874 0 : STR("CharCaseMap");
875 0 : STR("CharUnderline");
876 0 : STR("CharUnderlineColor");
877 0 : STR("CharWeight");
878 0 : STR("NumberingLevel");
879 0 : STR("NumberingRules");
880 0 : STR("ParaAdjust");
881 0 : STR("ParaBottomMargin");
882 0 : STR("ParaFirstLineIndent");
883 0 : STR("ParaLeftMargin");
884 0 : STR("ParaLineSpacing");
885 0 : STR("ParaRightMargin");
886 0 : STR("ParaTabStops");
887 : #undef STR
888 : DBG_ASSERT( i == pSeq->getLength(), "Please adjust length" );
889 0 : if( i != pSeq->getLength() )
890 0 : pSeq->realloc( i );
891 0 : pNames = pSeq;
892 : }
893 0 : return *pNames;
894 : }
895 :
896 : struct IndexCompare
897 : {
898 : const PropertyValue* pValues;
899 0 : IndexCompare( const PropertyValue* pVals ) : pValues(pVals) {}
900 0 : bool operator() ( const sal_Int32& a, const sal_Int32& b ) const
901 : {
902 0 : return pValues[a].Name < pValues[b].Name;
903 : }
904 : };
905 :
906 0 : OUString AccessibleEditableTextPara::GetFieldTypeNameAtIndex(sal_Int32 nIndex)
907 : {
908 0 : OUString strFldType;
909 0 : SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder();
910 : //For field object info
911 0 : sal_Int32 nParaIndex = GetParagraphIndex();
912 0 : sal_Int32 nAllFieldLen = 0;
913 0 : sal_Int32 nField = rCacheTF.GetFieldCount(nParaIndex), nFoundFieldIndex = -1;
914 0 : EFieldInfo ree;
915 : sal_Int32 reeBegin, reeEnd;
916 0 : sal_Int32 nFieldType = -1;
917 0 : for(sal_Int32 j = 0; j < nField; j++)
918 : {
919 0 : ree = rCacheTF.GetFieldInfo(nParaIndex, j);
920 0 : reeBegin = ree.aPosition.nIndex + nAllFieldLen;
921 0 : reeEnd = reeBegin + ree.aCurrentText.getLength();
922 0 : nAllFieldLen += (ree.aCurrentText.getLength() - 1);
923 0 : if( reeBegin > nIndex )
924 : {
925 0 : break;
926 : }
927 0 : if( nIndex >= reeBegin && nIndex < reeEnd )
928 : {
929 0 : nFoundFieldIndex = j;
930 0 : break;
931 : }
932 : }
933 0 : if( nFoundFieldIndex >= 0 )
934 : {
935 : // So we get a field, check its type now.
936 0 : nFieldType = ree.pFieldItem->GetField()->GetClassId() ;
937 : }
938 0 : switch(nFieldType)
939 : {
940 : case text::textfield::Type::DATE:
941 : {
942 0 : const SvxDateField* pDateField = static_cast< const SvxDateField* >(ree.pFieldItem->GetField());
943 0 : if (pDateField)
944 : {
945 0 : if (pDateField->GetType() == SVXDATETYPE_FIX)
946 0 : strFldType = "date (fixed)";
947 0 : else if (pDateField->GetType() == SVXDATETYPE_VAR)
948 0 : strFldType = "date (variable)";
949 : }
950 : }
951 0 : break;
952 : case text::textfield::Type::PAGE:
953 0 : strFldType = "page-number";
954 0 : break;
955 : //support the sheet name & pages fields
956 : case text::textfield::Type::PAGES:
957 0 : strFldType = "page-count";
958 0 : break;
959 : case text::textfield::Type::TABLE:
960 0 : strFldType = "sheet-name";
961 0 : break;
962 : //End
963 : case text::textfield::Type::TIME:
964 0 : strFldType = "time";
965 0 : break;
966 : case text::textfield::Type::EXTENDED_TIME:
967 : {
968 0 : const SvxExtTimeField* pTimeField = static_cast< const SvxExtTimeField* >(ree.pFieldItem->GetField());
969 0 : if (pTimeField)
970 : {
971 0 : if (pTimeField->GetType() == SVXTIMETYPE_FIX)
972 0 : strFldType = "time (fixed)";
973 0 : else if (pTimeField->GetType() == SVXTIMETYPE_VAR)
974 0 : strFldType = "time (variable)";
975 : }
976 : }
977 0 : break;
978 : case text::textfield::Type::AUTHOR:
979 0 : strFldType = "author";
980 0 : break;
981 : case text::textfield::Type::EXTENDED_FILE:
982 : case text::textfield::Type::DOCINFO_TITLE:
983 0 : strFldType = "file name";
984 : default:
985 0 : break;
986 : }
987 0 : return strFldType;
988 : }
989 :
990 46 : uno::Reference< XAccessibleStateSet > SAL_CALL AccessibleEditableTextPara::getAccessibleStateSet() throw (uno::RuntimeException, std::exception)
991 : {
992 46 : SolarMutexGuard aGuard;
993 :
994 : // Create a copy of the state set and return it.
995 46 : ::utl::AccessibleStateSetHelper* pStateSet = static_cast< ::utl::AccessibleStateSetHelper*>(mxStateSet.get());
996 :
997 46 : if( !pStateSet )
998 0 : return uno::Reference<XAccessibleStateSet>();
999 92 : uno::Reference<XAccessibleStateSet> xParentStates;
1000 46 : if (getAccessibleParent().is())
1001 : {
1002 46 : uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
1003 46 : xParentStates = xParentContext->getAccessibleStateSet();
1004 : }
1005 46 : if (xParentStates.is() && xParentStates->contains(AccessibleStateType::EDITABLE) )
1006 : {
1007 2 : pStateSet->AddState(AccessibleStateType::EDITABLE);
1008 : }
1009 92 : return uno::Reference<XAccessibleStateSet>( new ::utl::AccessibleStateSetHelper (*pStateSet) );
1010 : }
1011 :
1012 2 : lang::Locale SAL_CALL AccessibleEditableTextPara::getLocale() throw (IllegalAccessibleComponentStateException, uno::RuntimeException, std::exception)
1013 : {
1014 2 : SolarMutexGuard aGuard;
1015 :
1016 2 : return implGetLocale();
1017 : }
1018 :
1019 2 : void SAL_CALL AccessibleEditableTextPara::addAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) throw (uno::RuntimeException, std::exception)
1020 : {
1021 2 : if( getNotifierClientId() != -1 )
1022 2 : ::comphelper::AccessibleEventNotifier::addEventListener( getNotifierClientId(), xListener );
1023 2 : }
1024 :
1025 4 : void SAL_CALL AccessibleEditableTextPara::removeAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) throw (uno::RuntimeException, std::exception)
1026 : {
1027 4 : if( getNotifierClientId() != -1 )
1028 0 : ::comphelper::AccessibleEventNotifier::removeEventListener( getNotifierClientId(), xListener );
1029 4 : }
1030 :
1031 : // XAccessibleComponent
1032 6 : sal_Bool SAL_CALL AccessibleEditableTextPara::containsPoint( const awt::Point& aTmpPoint ) throw (uno::RuntimeException, std::exception)
1033 : {
1034 6 : SolarMutexGuard aGuard;
1035 :
1036 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= SAL_MAX_INT32,
1037 : "AccessibleEditableTextPara::contains: index value overflow");
1038 :
1039 6 : awt::Rectangle aTmpRect = getBounds();
1040 6 : Rectangle aRect( Point(aTmpRect.X, aTmpRect.Y), Size(aTmpRect.Width, aTmpRect.Height) );
1041 6 : Point aPoint( aTmpPoint.X, aTmpPoint.Y );
1042 :
1043 6 : return aRect.IsInside( aPoint );
1044 : }
1045 :
1046 0 : uno::Reference< XAccessible > SAL_CALL AccessibleEditableTextPara::getAccessibleAtPoint( const awt::Point& _aPoint ) throw (uno::RuntimeException, std::exception)
1047 : {
1048 0 : SolarMutexGuard aGuard;
1049 :
1050 0 : if( HaveChildren() )
1051 : {
1052 : // #103862# No longer need to make given position relative
1053 0 : Point aPoint( _aPoint.X, _aPoint.Y );
1054 :
1055 : // respect EditEngine offset to surrounding shape/cell
1056 0 : aPoint -= GetEEOffset();
1057 :
1058 : // convert to EditEngine coordinate system
1059 0 : SvxTextForwarder& rCacheTF = GetTextForwarder();
1060 0 : Point aLogPoint( GetViewForwarder().PixelToLogic( aPoint, rCacheTF.GetMapMode() ) );
1061 :
1062 0 : EBulletInfo aBulletInfo = rCacheTF.GetBulletInfo(GetParagraphIndex());
1063 :
1064 0 : if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND &&
1065 0 : aBulletInfo.bVisible &&
1066 0 : aBulletInfo.nType == SVX_NUM_BITMAP )
1067 : {
1068 0 : Rectangle aRect = aBulletInfo.aBounds;
1069 :
1070 0 : if( aRect.IsInside( aLogPoint ) )
1071 0 : return getAccessibleChild(0);
1072 0 : }
1073 : }
1074 :
1075 : // no children at all, or none at given position
1076 0 : return uno::Reference< XAccessible >();
1077 : }
1078 :
1079 146 : awt::Rectangle SAL_CALL AccessibleEditableTextPara::getBounds() throw (uno::RuntimeException, std::exception)
1080 : {
1081 146 : SolarMutexGuard aGuard;
1082 :
1083 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= SAL_MAX_INT32,
1084 : "AccessibleEditableTextPara::getBounds: index value overflow");
1085 :
1086 146 : SvxTextForwarder& rCacheTF = GetTextForwarder();
1087 146 : Rectangle aRect = rCacheTF.GetParaBounds( GetParagraphIndex() );
1088 :
1089 : // convert to screen coordinates
1090 : Rectangle aScreenRect = AccessibleEditableTextPara::LogicToPixel( aRect,
1091 146 : rCacheTF.GetMapMode(),
1092 292 : GetViewForwarder() );
1093 :
1094 : // offset from shape/cell
1095 146 : Point aOffset = GetEEOffset();
1096 :
1097 292 : return awt::Rectangle( aScreenRect.Left() + aOffset.X(),
1098 292 : aScreenRect.Top() + aOffset.Y(),
1099 292 : aScreenRect.GetSize().Width(),
1100 1022 : aScreenRect.GetSize().Height() );
1101 : }
1102 :
1103 0 : awt::Point SAL_CALL AccessibleEditableTextPara::getLocation( ) throw (uno::RuntimeException, std::exception)
1104 : {
1105 0 : SolarMutexGuard aGuard;
1106 :
1107 0 : awt::Rectangle aRect = getBounds();
1108 :
1109 0 : return awt::Point( aRect.X, aRect.Y );
1110 : }
1111 :
1112 0 : awt::Point SAL_CALL AccessibleEditableTextPara::getLocationOnScreen( ) throw (uno::RuntimeException, std::exception)
1113 : {
1114 0 : SolarMutexGuard aGuard;
1115 :
1116 : // relate us to parent
1117 0 : uno::Reference< XAccessible > xParent = getAccessibleParent();
1118 0 : if( xParent.is() )
1119 : {
1120 0 : uno::Reference< XAccessibleComponent > xParentComponent( xParent, uno::UNO_QUERY );
1121 0 : if( xParentComponent.is() )
1122 : {
1123 0 : awt::Point aRefPoint = xParentComponent->getLocationOnScreen();
1124 0 : awt::Point aPoint = getLocation();
1125 0 : aPoint.X += aRefPoint.X;
1126 0 : aPoint.Y += aRefPoint.Y;
1127 :
1128 0 : return aPoint;
1129 : }
1130 : // #i88070#
1131 : // fallback to parent's <XAccessibleContext> instance
1132 : else
1133 : {
1134 0 : uno::Reference< XAccessibleContext > xParentContext = xParent->getAccessibleContext();
1135 0 : if ( xParentContext.is() )
1136 : {
1137 0 : uno::Reference< XAccessibleComponent > xParentContextComponent( xParentContext, uno::UNO_QUERY );
1138 0 : if( xParentContextComponent.is() )
1139 : {
1140 0 : awt::Point aRefPoint = xParentContextComponent->getLocationOnScreen();
1141 0 : awt::Point aPoint = getLocation();
1142 0 : aPoint.X += aRefPoint.X;
1143 0 : aPoint.Y += aRefPoint.Y;
1144 :
1145 0 : return aPoint;
1146 0 : }
1147 0 : }
1148 0 : }
1149 : }
1150 :
1151 : throw uno::RuntimeException("Cannot access parent",
1152 : uno::Reference< uno::XInterface >
1153 0 : ( static_cast< XAccessible* > (this) ) ); // disambiguate hierarchy
1154 : }
1155 :
1156 0 : awt::Size SAL_CALL AccessibleEditableTextPara::getSize( ) throw (uno::RuntimeException, std::exception)
1157 : {
1158 0 : SolarMutexGuard aGuard;
1159 :
1160 0 : awt::Rectangle aRect = getBounds();
1161 :
1162 0 : return awt::Size( aRect.Width, aRect.Height );
1163 : }
1164 :
1165 0 : void SAL_CALL AccessibleEditableTextPara::grabFocus( ) throw (uno::RuntimeException, std::exception)
1166 : {
1167 : // set cursor to this paragraph
1168 0 : setSelection(0,0);
1169 0 : }
1170 :
1171 0 : sal_Int32 SAL_CALL AccessibleEditableTextPara::getForeground( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
1172 : {
1173 : // #104444# Added to XAccessibleComponent interface
1174 0 : svtools::ColorConfig aColorConfig;
1175 0 : sal_uInt32 nColor = aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor;
1176 0 : return static_cast<sal_Int32>(nColor);
1177 : }
1178 :
1179 0 : sal_Int32 SAL_CALL AccessibleEditableTextPara::getBackground( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
1180 : {
1181 : // #104444# Added to XAccessibleComponent interface
1182 0 : Color aColor( Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor() );
1183 :
1184 : // the background is transparent
1185 0 : aColor.SetTransparency( 0xFF);
1186 :
1187 0 : return static_cast<sal_Int32>( aColor.GetColor() );
1188 : }
1189 :
1190 : // XAccessibleText
1191 0 : sal_Int32 SAL_CALL AccessibleEditableTextPara::getCaretPosition() throw (uno::RuntimeException, std::exception)
1192 : {
1193 0 : SolarMutexGuard aGuard;
1194 :
1195 0 : if( !HaveEditView() )
1196 0 : return -1;
1197 :
1198 0 : ESelection aSelection;
1199 0 : if( GetEditViewForwarder().GetSelection( aSelection ) &&
1200 0 : GetParagraphIndex() == aSelection.nEndPara )
1201 : {
1202 : // caret is always nEndPara,nEndPos
1203 0 : EBulletInfo aBulletInfo = GetTextForwarder().GetBulletInfo(GetParagraphIndex());
1204 0 : if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND &&
1205 0 : aBulletInfo.bVisible &&
1206 0 : aBulletInfo.nType != SVX_NUM_BITMAP )
1207 : {
1208 0 : sal_Int32 nBulletLen = aBulletInfo.aText.getLength();
1209 0 : if( aSelection.nEndPos - nBulletLen >= 0 )
1210 0 : return aSelection.nEndPos - nBulletLen;
1211 : }
1212 0 : return aSelection.nEndPos;
1213 : }
1214 :
1215 : // not within this paragraph
1216 0 : return -1;
1217 : }
1218 :
1219 6 : sal_Bool SAL_CALL AccessibleEditableTextPara::setCaretPosition( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
1220 : {
1221 6 : return setSelection(nIndex, nIndex);
1222 : }
1223 :
1224 14 : sal_Unicode SAL_CALL AccessibleEditableTextPara::getCharacter( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
1225 : {
1226 14 : SolarMutexGuard aGuard;
1227 :
1228 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1229 : "AccessibleEditableTextPara::getCharacter: index value overflow");
1230 :
1231 14 : return OCommonAccessibleText::getCharacter( nIndex );
1232 : }
1233 :
1234 6 : uno::Sequence< beans::PropertyValue > SAL_CALL AccessibleEditableTextPara::getCharacterAttributes( sal_Int32 nIndex, const ::com::sun::star::uno::Sequence< OUString >& rRequestedAttributes ) throw (lang::IndexOutOfBoundsException, beans::UnknownPropertyException, uno::RuntimeException, std::exception)
1235 : {
1236 6 : SolarMutexGuard aGuard;
1237 :
1238 : //Skip the bullet range to ingnore the bullet text
1239 6 : SvxTextForwarder& rCacheTF = GetTextForwarder();
1240 12 : EBulletInfo aBulletInfo = rCacheTF.GetBulletInfo(GetParagraphIndex());
1241 6 : if (aBulletInfo.bVisible)
1242 0 : nIndex += aBulletInfo.aText.getLength();
1243 6 : CheckIndex(nIndex); // may throw IndexOutOfBoundsException
1244 :
1245 2 : bool bSupplementalMode = false;
1246 4 : uno::Sequence< OUString > aPropertyNames = rRequestedAttributes;
1247 2 : if (aPropertyNames.getLength() == 0)
1248 : {
1249 0 : bSupplementalMode = true;
1250 0 : aPropertyNames = getAttributeNames();
1251 : }
1252 :
1253 : // get default attribues...
1254 4 : ::comphelper::SequenceAsHashMap aPropHashMap( getDefaultAttributes( aPropertyNames ) );
1255 :
1256 : // ... and override them with the direct attributes from the specific position
1257 4 : uno::Sequence< beans::PropertyValue > aRunAttribs( getRunAttributes( nIndex, aPropertyNames ) );
1258 2 : sal_Int32 nRunAttribs = aRunAttribs.getLength();
1259 2 : const beans::PropertyValue *pRunAttrib = aRunAttribs.getConstArray();
1260 2 : for (sal_Int32 k = 0; k < nRunAttribs; ++k)
1261 : {
1262 0 : const beans::PropertyValue &rRunAttrib = pRunAttrib[k];
1263 0 : aPropHashMap[ rRunAttrib.Name ] = rRunAttrib.Value; //!! should not only be the value !!
1264 : }
1265 :
1266 : // get resulting sequence
1267 4 : uno::Sequence< beans::PropertyValue > aRes;
1268 2 : aPropHashMap >> aRes;
1269 :
1270 : // since SequenceAsHashMap ignores property handles and property state
1271 : // we have to restore the property state here (property handles are
1272 : // of no use to the accessibility API).
1273 2 : sal_Int32 nRes = aRes.getLength();
1274 2 : beans::PropertyValue *pRes = aRes.getArray();
1275 2 : for (sal_Int32 i = 0; i < nRes; ++i)
1276 : {
1277 0 : beans::PropertyValue &rRes = pRes[i];
1278 0 : bool bIsDirectVal = false;
1279 0 : for (sal_Int32 k = 0; k < nRunAttribs && !bIsDirectVal; ++k)
1280 : {
1281 0 : if (rRes.Name == pRunAttrib[k].Name)
1282 0 : bIsDirectVal = true;
1283 : }
1284 0 : rRes.Handle = -1;
1285 0 : rRes.State = bIsDirectVal ? PropertyState_DIRECT_VALUE : PropertyState_DEFAULT_VALUE;
1286 : }
1287 2 : if( bSupplementalMode )
1288 : {
1289 0 : _correctValues( nIndex, aRes );
1290 : // NumberingPrefix
1291 0 : nRes = aRes.getLength();
1292 0 : aRes.realloc( nRes + 1 );
1293 0 : pRes = aRes.getArray();
1294 0 : beans::PropertyValue &rRes = pRes[nRes];
1295 0 : rRes.Name = "NumberingPrefix";
1296 0 : OUString numStr;
1297 0 : if (aBulletInfo.nType != SVX_NUM_CHAR_SPECIAL && aBulletInfo.nType != SVX_NUM_BITMAP)
1298 0 : numStr = aBulletInfo.aText;
1299 0 : rRes.Value <<= numStr;
1300 0 : rRes.Handle = -1;
1301 0 : rRes.State = PropertyState_DIRECT_VALUE;
1302 : //For field object.
1303 0 : OUString strFieldType = GetFieldTypeNameAtIndex(nIndex);
1304 0 : if (!strFieldType.isEmpty())
1305 : {
1306 0 : nRes = aRes.getLength();
1307 0 : aRes.realloc( nRes + 1 );
1308 0 : pRes = aRes.getArray();
1309 0 : beans::PropertyValue &rResField = pRes[nRes];
1310 0 : beans::PropertyValue aFieldType;
1311 0 : rResField.Name = "FieldType";
1312 0 : rResField.Value <<= strFieldType.toAsciiLowerCase();
1313 0 : rResField.Handle = -1;
1314 0 : rResField.State = PropertyState_DIRECT_VALUE;
1315 : }
1316 : //sort property values
1317 : // build sorted index array
1318 0 : sal_Int32 nLength = aRes.getLength();
1319 0 : const beans::PropertyValue* pPairs = aRes.getConstArray();
1320 0 : boost::scoped_array<sal_Int32> pIndices(new sal_Int32[nLength]);
1321 0 : sal_Int32 i = 0;
1322 0 : for( i = 0; i < nLength; i++ )
1323 0 : pIndices[i] = i;
1324 0 : sort( &pIndices[0], &pIndices[nLength], IndexCompare(pPairs) );
1325 : // create sorted sequences according to index array
1326 0 : uno::Sequence<beans::PropertyValue> aNewValues( nLength );
1327 0 : beans::PropertyValue* pNewValues = aNewValues.getArray();
1328 0 : for( i = 0; i < nLength; i++ )
1329 : {
1330 0 : pNewValues[i] = pPairs[pIndices[i]];
1331 : }
1332 :
1333 0 : return aNewValues;
1334 : }
1335 8 : return aRes;
1336 : }
1337 :
1338 46 : awt::Rectangle SAL_CALL AccessibleEditableTextPara::getCharacterBounds( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
1339 : {
1340 46 : SolarMutexGuard aGuard;
1341 :
1342 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1343 : "AccessibleEditableTextPara::getCharacterBounds: index value overflow");
1344 :
1345 : // #108900# Have position semantics now for nIndex, as
1346 : // one-past-the-end values are legal, too.
1347 46 : CheckPosition( nIndex );
1348 :
1349 42 : SvxTextForwarder& rCacheTF = GetTextForwarder();
1350 42 : Rectangle aRect = rCacheTF.GetCharBounds(GetParagraphIndex(), nIndex);
1351 :
1352 : // convert to screen
1353 : Rectangle aScreenRect = AccessibleEditableTextPara::LogicToPixel( aRect,
1354 42 : rCacheTF.GetMapMode(),
1355 84 : GetViewForwarder() );
1356 : // #109864# offset from parent (paragraph), but in screen
1357 : // coordinates. This makes sure the internal text offset in
1358 : // the outline view forwarder gets cancelled out here
1359 42 : awt::Rectangle aParaRect( getBounds() );
1360 42 : aScreenRect.Move( -aParaRect.X, -aParaRect.Y );
1361 :
1362 : // offset from shape/cell
1363 42 : Point aOffset = GetEEOffset();
1364 :
1365 84 : return awt::Rectangle( aScreenRect.Left() + aOffset.X(),
1366 84 : aScreenRect.Top() + aOffset.Y(),
1367 84 : aScreenRect.GetSize().Width(),
1368 298 : aScreenRect.GetSize().Height() );
1369 : }
1370 :
1371 106 : sal_Int32 SAL_CALL AccessibleEditableTextPara::getCharacterCount() throw (uno::RuntimeException, std::exception)
1372 : {
1373 106 : SolarMutexGuard aGuard;
1374 :
1375 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1376 : "AccessibleEditableTextPara::getCharacterCount: index value overflow");
1377 :
1378 106 : return OCommonAccessibleText::getCharacterCount();
1379 : }
1380 :
1381 22 : sal_Int32 SAL_CALL AccessibleEditableTextPara::getIndexAtPoint( const awt::Point& rPoint ) throw (uno::RuntimeException, std::exception)
1382 : {
1383 22 : SolarMutexGuard aGuard;
1384 :
1385 : sal_Int32 nPara;
1386 : sal_Int32 nIndex;
1387 :
1388 : // offset from surrounding cell/shape
1389 22 : Point aOffset( GetEEOffset() );
1390 22 : Point aPoint( rPoint.X - aOffset.X(), rPoint.Y - aOffset.Y() );
1391 :
1392 : // convert to logical coordinates
1393 22 : SvxTextForwarder& rCacheTF = GetTextForwarder();
1394 22 : Point aLogPoint( GetViewForwarder().PixelToLogic( aPoint, rCacheTF.GetMapMode() ) );
1395 :
1396 : // re-offset to parent (paragraph)
1397 22 : Rectangle aParaRect = rCacheTF.GetParaBounds( GetParagraphIndex() );
1398 22 : aLogPoint.Move( aParaRect.Left(), aParaRect.Top() );
1399 :
1400 44 : if( rCacheTF.GetIndexAtPoint( aLogPoint, nPara, nIndex ) &&
1401 22 : GetParagraphIndex() == nPara )
1402 : {
1403 : // #102259# Double-check if we're _really_ on the given character
1404 : try
1405 : {
1406 22 : awt::Rectangle aRect1( getCharacterBounds(nIndex) );
1407 : Rectangle aRect2( aRect1.X, aRect1.Y,
1408 22 : aRect1.Width + aRect1.X, aRect1.Height + aRect1.Y );
1409 22 : if( aRect2.IsInside( Point( rPoint.X, rPoint.Y ) ) )
1410 20 : return nIndex;
1411 : else
1412 2 : return -1;
1413 : }
1414 0 : catch (const lang::IndexOutOfBoundsException&)
1415 : {
1416 : // #103927# Don't throw for invalid nIndex values
1417 0 : return -1;
1418 : }
1419 : }
1420 : else
1421 : {
1422 : // not within our paragraph
1423 0 : return -1;
1424 22 : }
1425 : }
1426 :
1427 0 : OUString SAL_CALL AccessibleEditableTextPara::getSelectedText() throw (uno::RuntimeException, std::exception)
1428 : {
1429 0 : SolarMutexGuard aGuard;
1430 :
1431 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1432 : "AccessibleEditableTextPara::getSelectedText: index value overflow");
1433 :
1434 0 : if( !HaveEditView() )
1435 0 : return OUString();
1436 :
1437 0 : return OCommonAccessibleText::getSelectedText();
1438 : }
1439 :
1440 0 : sal_Int32 SAL_CALL AccessibleEditableTextPara::getSelectionStart() throw (uno::RuntimeException, std::exception)
1441 : {
1442 0 : SolarMutexGuard aGuard;
1443 :
1444 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1445 : "AccessibleEditableTextPara::getSelectionStart: index value overflow");
1446 :
1447 0 : if( !HaveEditView() )
1448 0 : return -1;
1449 :
1450 0 : return OCommonAccessibleText::getSelectionStart();
1451 : }
1452 :
1453 0 : sal_Int32 SAL_CALL AccessibleEditableTextPara::getSelectionEnd() throw (uno::RuntimeException, std::exception)
1454 : {
1455 0 : SolarMutexGuard aGuard;
1456 :
1457 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1458 : "AccessibleEditableTextPara::getSelectionEnd: index value overflow");
1459 :
1460 0 : if( !HaveEditView() )
1461 0 : return -1;
1462 :
1463 0 : return OCommonAccessibleText::getSelectionEnd();
1464 : }
1465 :
1466 6 : sal_Bool SAL_CALL AccessibleEditableTextPara::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
1467 : {
1468 6 : SolarMutexGuard aGuard;
1469 :
1470 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1471 : "AccessibleEditableTextPara::setSelection: paragraph index value overflow");
1472 :
1473 6 : CheckRange(nStartIndex, nEndIndex);
1474 :
1475 : try
1476 : {
1477 2 : SvxEditViewForwarder& rCacheVF = GetEditViewForwarder( true );
1478 0 : return rCacheVF.SetSelection( MakeSelection(nStartIndex, nEndIndex) );
1479 : }
1480 4 : catch (const uno::RuntimeException&)
1481 : {
1482 2 : return sal_False;
1483 6 : }
1484 : }
1485 :
1486 4 : OUString SAL_CALL AccessibleEditableTextPara::getText() throw (uno::RuntimeException, std::exception)
1487 : {
1488 4 : SolarMutexGuard aGuard;
1489 :
1490 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1491 : "AccessibleEditableTextPara::getText: paragraph index value overflow");
1492 :
1493 4 : return OCommonAccessibleText::getText();
1494 : }
1495 :
1496 14 : OUString SAL_CALL AccessibleEditableTextPara::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
1497 : {
1498 14 : SolarMutexGuard aGuard;
1499 :
1500 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1501 : "AccessibleEditableTextPara::getTextRange: paragraph index value overflow");
1502 :
1503 14 : return OCommonAccessibleText::getTextRange(nStartIndex, nEndIndex);
1504 : }
1505 :
1506 0 : void AccessibleEditableTextPara::_correctValues( const sal_Int32 /* nIndex */,
1507 : uno::Sequence< PropertyValue >& rValues)
1508 : {
1509 0 : SvxTextForwarder& rCacheTF = GetTextForwarder();
1510 0 : sal_Int32 nRes = rValues.getLength();
1511 0 : beans::PropertyValue *pRes = rValues.getArray();
1512 0 : for (sal_Int32 i = 0; i < nRes; ++i)
1513 : {
1514 0 : beans::PropertyValue &rRes = pRes[i];
1515 : // Char color
1516 0 : if (rRes.Name == "CharColor")
1517 : {
1518 0 : uno::Any &anyChar = rRes.Value;
1519 0 : sal_uInt32 crChar = static_cast<sal_uInt32>( reinterpret_cast<sal_uIntPtr>(anyChar.pReserved));
1520 0 : if (COL_AUTO == crChar )
1521 : {
1522 0 : uno::Reference< ::com::sun::star::accessibility::XAccessibleComponent > xComponent;
1523 0 : if (mxParent.is())
1524 : {
1525 0 : xComponent.set(mxParent,uno::UNO_QUERY);
1526 : }
1527 : else
1528 : {
1529 0 : xComponent.set(m_xAccInfo,uno::UNO_QUERY);
1530 : }
1531 0 : if (xComponent.is())
1532 : {
1533 0 : uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > xContext(xComponent,uno::UNO_QUERY);
1534 0 : if (xContext->getAccessibleRole() == AccessibleRole::SHAPE
1535 0 : || xContext->getAccessibleRole() == AccessibleRole::TABLE_CELL)
1536 : {
1537 0 : anyChar <<= COL_BLACK;
1538 : }
1539 : else
1540 : {
1541 0 : Color cr(xComponent->getBackground());
1542 0 : crChar = cr.IsDark() ? COL_WHITE : COL_BLACK;
1543 0 : anyChar <<= crChar;
1544 0 : }
1545 0 : }
1546 : }
1547 0 : continue;
1548 : }
1549 : // Underline
1550 0 : if (rRes.Name == "CharUnderline")
1551 : {
1552 0 : continue;
1553 : }
1554 : // Underline color && Mis-spell
1555 0 : if (rRes.Name == "CharUnderlineColor")
1556 : {
1557 0 : uno::Any &anyCharUnderLine = rRes.Value;
1558 0 : sal_uInt32 crCharUnderLine = static_cast<sal_uInt32>( reinterpret_cast<sal_uIntPtr>( anyCharUnderLine.pReserved));
1559 0 : if (COL_AUTO == crCharUnderLine )
1560 : {
1561 0 : uno::Reference< ::com::sun::star::accessibility::XAccessibleComponent > xComponent;
1562 0 : if (mxParent.is())
1563 : {
1564 0 : xComponent.set(mxParent,uno::UNO_QUERY);
1565 : }
1566 : else
1567 : {
1568 0 : xComponent.set(m_xAccInfo,uno::UNO_QUERY);
1569 : }
1570 0 : if (xComponent.is())
1571 : {
1572 0 : uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > xContext(xComponent,uno::UNO_QUERY);
1573 0 : if (xContext->getAccessibleRole() == AccessibleRole::SHAPE
1574 0 : || xContext->getAccessibleRole() == AccessibleRole::TABLE_CELL)
1575 : {
1576 0 : anyCharUnderLine <<= COL_BLACK;
1577 : }
1578 : else
1579 : {
1580 0 : Color cr(xComponent->getBackground());
1581 0 : crCharUnderLine = cr.IsDark() ? COL_WHITE : COL_BLACK;
1582 0 : anyCharUnderLine <<= crCharUnderLine;
1583 0 : }
1584 0 : }
1585 : }
1586 0 : continue;
1587 : }
1588 : // NumberingLevel
1589 0 : if (rRes.Name == "NumberingLevel")
1590 : {
1591 0 : const SvxNumBulletItem& rNumBullet = static_cast<const SvxNumBulletItem&>(rCacheTF.GetParaAttribs(GetParagraphIndex()).Get(EE_PARA_NUMBULLET));
1592 0 : if(rNumBullet.GetNumRule()->GetLevelCount()==0)
1593 : {
1594 0 : rRes.Value <<= (sal_Int16)-1;
1595 0 : rRes.Handle = -1;
1596 0 : rRes.State = PropertyState_DIRECT_VALUE;
1597 : }
1598 : else
1599 : {
1600 : // SvxAccessibleTextPropertySet aPropSet( &GetEditSource(),
1601 : // ImplGetSvxCharAndParaPropertiesMap() );
1602 : // MT IA2 TODO: Check if this is the correct replacement for ImplGetSvxCharAndParaPropertiesMap
1603 0 : SvxAccessibleTextPropertySet aPropSet( &GetEditSource(), ImplGetSvxTextPortionSvxPropertySet() );
1604 :
1605 0 : aPropSet.SetSelection( MakeSelection( 0, GetTextLen() ) );
1606 0 : rRes.Value = aPropSet._getPropertyValue( rRes.Name, mnParagraphIndex );
1607 0 : rRes.State = aPropSet._getPropertyState( rRes.Name, mnParagraphIndex );
1608 0 : rRes.Handle = -1;
1609 : }
1610 0 : continue;
1611 : }
1612 : // NumberingRules
1613 0 : if (rRes.Name == "NumberingRules")
1614 : {
1615 0 : SfxItemSet aAttribs = rCacheTF.GetParaAttribs(GetParagraphIndex());
1616 0 : bool bVis = static_cast<const SfxUInt16Item&>(aAttribs.Get( EE_PARA_BULLETSTATE )).GetValue() ? true : false;
1617 0 : if(bVis)
1618 : {
1619 0 : rRes.Value <<= (sal_Int16)-1;
1620 0 : rRes.Handle = -1;
1621 0 : rRes.State = PropertyState_DIRECT_VALUE;
1622 : }
1623 : else
1624 : {
1625 : // MT IA2 TODO: Check if this is the correct replacement for ImplGetSvxCharAndParaPropertiesMap
1626 0 : SvxAccessibleTextPropertySet aPropSet( &GetEditSource(), ImplGetSvxTextPortionSvxPropertySet() );
1627 0 : aPropSet.SetSelection( MakeSelection( 0, GetTextLen() ) );
1628 0 : rRes.Value = aPropSet._getPropertyValue( rRes.Name, mnParagraphIndex );
1629 0 : rRes.State = aPropSet._getPropertyState( rRes.Name, mnParagraphIndex );
1630 0 : rRes.Handle = -1;
1631 : }
1632 0 : continue;
1633 : }
1634 : }
1635 0 : }
1636 10 : sal_Int32 AccessibleEditableTextPara::SkipField(sal_Int32 nIndex, bool bForward)
1637 : {
1638 10 : sal_Int32 nParaIndex = GetParagraphIndex();
1639 10 : SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder();
1640 10 : sal_Int32 nAllFieldLen = 0;
1641 10 : sal_Int32 nField = rCacheTF.GetFieldCount(nParaIndex), nFoundFieldIndex = -1;
1642 10 : EFieldInfo ree;
1643 10 : sal_Int32 reeBegin=0, reeEnd=0;
1644 10 : for (sal_Int32 j = 0; j < nField; j++)
1645 : {
1646 0 : ree = rCacheTF.GetFieldInfo(nParaIndex, j);
1647 0 : reeBegin = ree.aPosition.nIndex + nAllFieldLen;
1648 0 : reeEnd = reeBegin + ree.aCurrentText.getLength();
1649 0 : nAllFieldLen += (ree.aCurrentText.getLength() - 1);
1650 0 : if( reeBegin > nIndex )
1651 : {
1652 0 : break;
1653 : }
1654 0 : if( nIndex >= reeBegin && nIndex < reeEnd )
1655 : {
1656 0 : if(ree.pFieldItem->GetField()->GetClassId() != text::textfield::Type::URL)
1657 : {
1658 0 : nFoundFieldIndex = j;
1659 0 : break;
1660 : }
1661 : }
1662 : }
1663 10 : if( nFoundFieldIndex >= 0 )
1664 : {
1665 0 : if( bForward )
1666 0 : return reeEnd - 1;
1667 : else
1668 0 : return reeBegin;
1669 : }
1670 10 : return nIndex;
1671 : }
1672 22 : bool AccessibleEditableTextPara::ExtendByField( ::com::sun::star::accessibility::TextSegment& Segment )
1673 : {
1674 22 : sal_Int32 nParaIndex = GetParagraphIndex();
1675 22 : SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder();
1676 22 : sal_Int32 nAllFieldLen = 0;
1677 22 : sal_Int32 nField = rCacheTF.GetFieldCount(nParaIndex), nFoundFieldIndex = -1;
1678 22 : EFieldInfo ree;
1679 22 : sal_Int32 reeBegin=0, reeEnd=0;
1680 22 : for (sal_Int32 j = 0; j < nField; j++)
1681 : {
1682 0 : ree = rCacheTF.GetFieldInfo(nParaIndex, j);
1683 0 : reeBegin = ree.aPosition.nIndex + nAllFieldLen;
1684 0 : reeEnd = reeBegin + ree.aCurrentText.getLength();
1685 0 : nAllFieldLen += (ree.aCurrentText.getLength() - 1);
1686 0 : if( reeBegin > Segment.SegmentEnd )
1687 : {
1688 0 : break;
1689 : }
1690 0 : if( (Segment.SegmentEnd > reeBegin && Segment.SegmentEnd <= reeEnd) ||
1691 0 : (Segment.SegmentStart >= reeBegin && Segment.SegmentStart < reeEnd) )
1692 : {
1693 0 : if(ree.pFieldItem->GetField()->GetClassId() != text::textfield::Type::URL)
1694 : {
1695 0 : nFoundFieldIndex = j;
1696 0 : break;
1697 : }
1698 : }
1699 : }
1700 22 : bool bExtend = false;
1701 22 : if( nFoundFieldIndex >= 0 )
1702 : {
1703 0 : if( Segment.SegmentEnd < reeEnd )
1704 : {
1705 0 : Segment.SegmentEnd = reeEnd;
1706 0 : bExtend = true;
1707 : }
1708 0 : if( Segment.SegmentStart > reeBegin )
1709 : {
1710 0 : Segment.SegmentStart = reeBegin;
1711 0 : bExtend = true;
1712 : }
1713 0 : if( bExtend )
1714 : {
1715 : //If there is a bullet before the field, should add the bullet length into the segment.
1716 0 : EBulletInfo aBulletInfo = rCacheTF.GetBulletInfo(nParaIndex);
1717 0 : sal_Int32 nBulletLen = aBulletInfo.aText.getLength();
1718 0 : if (nBulletLen > 0)
1719 : {
1720 0 : Segment.SegmentEnd += nBulletLen;
1721 0 : if (nFoundFieldIndex > 0)
1722 0 : Segment.SegmentStart += nBulletLen;
1723 0 : Segment.SegmentText = GetTextRange(Segment.SegmentStart, Segment.SegmentEnd);
1724 : //After get the correct field name, should restore the offset value which don't contain the bullet.
1725 0 : Segment.SegmentEnd -= nBulletLen;
1726 0 : if (nFoundFieldIndex > 0)
1727 0 : Segment.SegmentStart -= nBulletLen;
1728 : }
1729 : else
1730 0 : Segment.SegmentText = GetTextRange(Segment.SegmentStart, Segment.SegmentEnd);
1731 : }
1732 : }
1733 22 : return bExtend;
1734 : }
1735 :
1736 26 : ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleEditableTextPara::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
1737 : {
1738 26 : SolarMutexGuard aGuard;
1739 :
1740 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1741 : "AccessibleEditableTextPara::getTextAtIndex: paragraph index value overflow");
1742 :
1743 26 : ::com::sun::star::accessibility::TextSegment aResult;
1744 26 : aResult.SegmentStart = -1;
1745 26 : aResult.SegmentEnd = -1;
1746 :
1747 26 : switch( aTextType )
1748 : {
1749 : case AccessibleTextType::CHARACTER:
1750 : case AccessibleTextType::WORD:
1751 : {
1752 12 : aResult = OCommonAccessibleText::getTextAtIndex( nIndex, aTextType );
1753 12 : ExtendByField( aResult );
1754 12 : break;
1755 : }
1756 : // Not yet handled by OCommonAccessibleText. Missing
1757 : // implGetAttributeRunBoundary() method there
1758 : case AccessibleTextType::ATTRIBUTE_RUN:
1759 : {
1760 0 : const sal_Int32 nTextLen = GetTextForwarder().GetTextLen( GetParagraphIndex() );
1761 :
1762 0 : if( nIndex == nTextLen )
1763 : {
1764 : // #i17014# Special-casing one-behind-the-end character
1765 0 : aResult.SegmentStart = aResult.SegmentEnd = nTextLen;
1766 : }
1767 : else
1768 : {
1769 : sal_Int32 nStartIndex, nEndIndex;
1770 : //For the bullet paragraph, the bullet string is ingnored for IAText::attributes() function.
1771 0 : SvxTextForwarder& rCacheTF = GetTextForwarder();
1772 : // MT IA2: Not used? sal_Int32 nBulletLen = 0;
1773 0 : EBulletInfo aBulletInfo = rCacheTF.GetBulletInfo(GetParagraphIndex());
1774 0 : if (aBulletInfo.bVisible)
1775 0 : nIndex += aBulletInfo.aText.getLength();
1776 0 : if (nIndex != 0 && nIndex >= getCharacterCount())
1777 0 : nIndex = getCharacterCount()-1;
1778 0 : CheckPosition(nIndex);
1779 0 : if( GetAttributeRun(nStartIndex, nEndIndex, nIndex) )
1780 : {
1781 0 : aResult.SegmentText = GetTextRange(nStartIndex, nEndIndex);
1782 0 : if (aBulletInfo.bVisible)
1783 : {
1784 0 : nStartIndex -= aBulletInfo.aText.getLength();
1785 0 : nEndIndex -= aBulletInfo.aText.getLength();
1786 : }
1787 0 : aResult.SegmentStart = nStartIndex;
1788 0 : aResult.SegmentEnd = nEndIndex;
1789 0 : }
1790 : }
1791 0 : break;
1792 : }
1793 : case AccessibleTextType::LINE:
1794 : {
1795 8 : SvxTextForwarder& rCacheTF = GetTextForwarder();
1796 8 : sal_Int32 nParaIndex = GetParagraphIndex();
1797 8 : CheckPosition(nIndex);
1798 8 : if (nIndex != 0 && nIndex == getCharacterCount())
1799 0 : --nIndex;
1800 8 : sal_Int32 nLine, nLineCount=rCacheTF.GetLineCount( nParaIndex );
1801 : sal_Int32 nCurIndex;
1802 : //the problem is that rCacheTF.GetLineLen() will include the bullet length. But for the bullet line,
1803 : //the text value doesn't contain the bullet characters. all of the bullet and numbering info are exposed
1804 : //by the IAText::attributes(). So here must do special support for bullet line.
1805 8 : sal_Int32 nBulletLen = 0;
1806 8 : for( nLine=0, nCurIndex=0; nLine<nLineCount; ++nLine )
1807 : {
1808 8 : if (nLine == 0)
1809 : {
1810 8 : EBulletInfo aBulletInfo = rCacheTF.GetBulletInfo( nParaIndex );
1811 8 : if (aBulletInfo.bVisible)
1812 : {
1813 : //in bullet or numbering;
1814 0 : nBulletLen = aBulletInfo.aText.getLength();
1815 8 : }
1816 : }
1817 8 : sal_Int32 nLineLen = rCacheTF.GetLineLen(nParaIndex, nLine);
1818 8 : if (nLine == 0)
1819 8 : nCurIndex += nLineLen - nBulletLen;
1820 : else
1821 0 : nCurIndex += nLineLen;
1822 8 : if( nCurIndex > nIndex )
1823 : {
1824 8 : if (nLine ==0)
1825 : {
1826 8 : aResult.SegmentStart = 0;
1827 8 : aResult.SegmentEnd = nCurIndex;
1828 8 : aResult.SegmentText = GetTextRange( aResult.SegmentStart, aResult.SegmentEnd + nBulletLen);
1829 8 : break;
1830 : }
1831 : else
1832 : {
1833 0 : aResult.SegmentStart = nCurIndex - nLineLen;
1834 0 : aResult.SegmentEnd = nCurIndex;
1835 : //aResult.SegmentText = GetTextRange( aResult.SegmentStart, aResult.SegmentEnd );
1836 0 : aResult.SegmentText = GetTextRange( aResult.SegmentStart + nBulletLen, aResult.SegmentEnd + nBulletLen);
1837 0 : break;
1838 : }
1839 : }
1840 : }
1841 8 : break;
1842 : }
1843 : default:
1844 6 : aResult = OCommonAccessibleText::getTextAtIndex( nIndex, aTextType );
1845 2 : break;
1846 : } /* end of switch( aTextType ) */
1847 :
1848 26 : return aResult;
1849 : }
1850 :
1851 12 : ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleEditableTextPara::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
1852 : {
1853 12 : SolarMutexGuard aGuard;
1854 :
1855 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1856 : "AccessibleEditableTextPara::getTextBeforeIndex: paragraph index value overflow");
1857 :
1858 12 : ::com::sun::star::accessibility::TextSegment aResult;
1859 12 : aResult.SegmentStart = -1;
1860 12 : aResult.SegmentEnd = -1;
1861 12 : i18n::Boundary aBoundary;
1862 12 : switch( aTextType )
1863 : {
1864 : // Not yet handled by OCommonAccessibleText. Missing
1865 : // implGetAttributeRunBoundary() method there
1866 : case AccessibleTextType::ATTRIBUTE_RUN:
1867 : {
1868 0 : const sal_Int32 nTextLen = GetTextForwarder().GetTextLen( GetParagraphIndex() );
1869 : sal_Int32 nStartIndex, nEndIndex;
1870 :
1871 0 : if( nIndex == nTextLen )
1872 : {
1873 : // #i17014# Special-casing one-behind-the-end character
1874 0 : if( nIndex > 0 &&
1875 0 : GetAttributeRun(nStartIndex, nEndIndex, nIndex-1) )
1876 : {
1877 0 : aResult.SegmentText = GetTextRange(nStartIndex, nEndIndex);
1878 0 : aResult.SegmentStart = nStartIndex;
1879 0 : aResult.SegmentEnd = nEndIndex;
1880 : }
1881 : }
1882 : else
1883 : {
1884 0 : if( GetAttributeRun(nStartIndex, nEndIndex, nIndex) )
1885 : {
1886 : // already at the left border? If not, query
1887 : // one index further left
1888 0 : if( nStartIndex > 0 &&
1889 0 : GetAttributeRun(nStartIndex, nEndIndex, nStartIndex-1) )
1890 : {
1891 0 : aResult.SegmentText = GetTextRange(nStartIndex, nEndIndex);
1892 0 : aResult.SegmentStart = nStartIndex;
1893 0 : aResult.SegmentEnd = nEndIndex;
1894 : }
1895 : }
1896 : }
1897 0 : break;
1898 : }
1899 : case AccessibleTextType::LINE:
1900 : {
1901 0 : SvxTextForwarder& rCacheTF = GetTextForwarder();
1902 0 : sal_Int32 nParaIndex = GetParagraphIndex();
1903 :
1904 0 : CheckPosition(nIndex);
1905 :
1906 0 : sal_Int32 nLine, nLineCount=rCacheTF.GetLineCount( nParaIndex );
1907 : //the problem is that rCacheTF.GetLineLen() will include the bullet length. But for the bullet line,
1908 : //the text value doesn't contain the bullet characters. all of the bullet and numbering info are exposed
1909 : //by the IAText::attributes(). So here must do special support for bullet line.
1910 0 : sal_Int32 nCurIndex=0, nLastIndex=0, nCurLineLen=0;
1911 0 : sal_Int32 nLastLineLen = 0, nBulletLen = 0;;
1912 : // get the line before the line the index points into
1913 0 : for( nLine=0, nCurIndex=0, nLastIndex=0; nLine<nLineCount; ++nLine )
1914 : {
1915 0 : nLastIndex = nCurIndex;
1916 0 : if (nLine == 0)
1917 : {
1918 0 : EBulletInfo aBulletInfo = rCacheTF.GetBulletInfo(nParaIndex);
1919 0 : if (aBulletInfo.bVisible)
1920 : {
1921 : //in bullet or numbering;
1922 0 : nBulletLen = aBulletInfo.aText.getLength();
1923 0 : }
1924 : }
1925 0 : if (nLine == 1)
1926 0 : nLastLineLen = nCurLineLen - nBulletLen;
1927 : else
1928 0 : nLastLineLen = nCurLineLen;
1929 0 : nCurLineLen = rCacheTF.GetLineLen( nParaIndex, nLine);
1930 : //nCurIndex += nCurLineLen;
1931 0 : if (nLine == 0)
1932 0 : nCurIndex += nCurLineLen - nBulletLen;
1933 : else
1934 0 : nCurIndex += nCurLineLen;
1935 :
1936 : //if( nCurIndex > nIndex &&
1937 : //nLastIndex > nCurLineLen )
1938 0 : if (nCurIndex > nIndex)
1939 : {
1940 0 : if (nLine == 0)
1941 : {
1942 0 : break;
1943 : }
1944 0 : else if (nLine == 1)
1945 : {
1946 0 : aResult.SegmentStart = 0;
1947 0 : aResult.SegmentEnd = nLastIndex;
1948 0 : aResult.SegmentText = GetTextRange( aResult.SegmentStart, aResult.SegmentEnd + nBulletLen);
1949 0 : break;
1950 : }
1951 : else
1952 : {
1953 : //aResult.SegmentStart = nLastIndex - nCurLineLen;
1954 0 : aResult.SegmentStart = nLastIndex - nLastLineLen;
1955 0 : aResult.SegmentEnd = nLastIndex;
1956 0 : aResult.SegmentText = GetTextRange( aResult.SegmentStart + nBulletLen, aResult.SegmentEnd + nBulletLen);
1957 0 : break;
1958 : }
1959 : }
1960 : }
1961 :
1962 0 : break;
1963 : }
1964 : case AccessibleTextType::WORD:
1965 : {
1966 2 : nIndex = SkipField( nIndex, false);
1967 2 : OUString sText( implGetText() );
1968 2 : sal_Int32 nLength = sText.getLength();
1969 :
1970 : // get word at index
1971 2 : implGetWordBoundary( aBoundary, nIndex );
1972 :
1973 :
1974 : //sal_Int32 curWordStart = aBoundary.startPos;
1975 : //sal_Int32 preWordStart = curWordStart;
1976 : sal_Int32 curWordStart , preWordStart;
1977 2 : if( aBoundary.startPos == -1 || aBoundary.startPos > nIndex)
1978 0 : curWordStart = preWordStart = nIndex;
1979 : else
1980 2 : curWordStart = preWordStart = aBoundary.startPos;
1981 :
1982 : // get previous word
1983 :
1984 2 : bool bWord = false;
1985 :
1986 : //while ( preWordStart > 0 && aBoundary.startPos == curWordStart)
1987 6 : while ( (preWordStart >= 0 && !bWord ) || ( aBoundary.endPos > curWordStart ) )
1988 : {
1989 2 : preWordStart--;
1990 2 : bWord = implGetWordBoundary( aBoundary, preWordStart );
1991 : }
1992 2 : if ( bWord && implIsValidBoundary( aBoundary, nLength ) )
1993 : {
1994 2 : aResult.SegmentText = sText.copy( aBoundary.startPos, aBoundary.endPos - aBoundary.startPos );
1995 2 : aResult.SegmentStart = aBoundary.startPos;
1996 2 : aResult.SegmentEnd = aBoundary.endPos;
1997 2 : ExtendByField( aResult );
1998 2 : }
1999 : }
2000 2 : break;
2001 : case AccessibleTextType::CHARACTER:
2002 : {
2003 4 : nIndex = SkipField( nIndex, false);
2004 4 : aResult = OCommonAccessibleText::getTextBeforeIndex( nIndex, aTextType );
2005 4 : ExtendByField( aResult );
2006 4 : break;
2007 : }
2008 : default:
2009 6 : aResult = OCommonAccessibleText::getTextBeforeIndex( nIndex, aTextType );
2010 2 : break;
2011 : } /* end of switch( aTextType ) */
2012 :
2013 12 : return aResult;
2014 : }
2015 :
2016 12 : ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleEditableTextPara::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
2017 : {
2018 12 : SolarMutexGuard aGuard;
2019 :
2020 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
2021 : "AccessibleEditableTextPara::getTextBehindIndex: paragraph index value overflow");
2022 :
2023 12 : ::com::sun::star::accessibility::TextSegment aResult;
2024 12 : aResult.SegmentStart = -1;
2025 12 : aResult.SegmentEnd = -1;
2026 12 : i18n::Boundary aBoundary;
2027 12 : switch( aTextType )
2028 : {
2029 : case AccessibleTextType::ATTRIBUTE_RUN:
2030 : {
2031 : sal_Int32 nStartIndex, nEndIndex;
2032 :
2033 0 : if( GetAttributeRun(nStartIndex, nEndIndex, nIndex) )
2034 : {
2035 : // already at the right border?
2036 0 : if( nEndIndex < GetTextLen() )
2037 : {
2038 0 : if( GetAttributeRun(nStartIndex, nEndIndex, nEndIndex) )
2039 : {
2040 0 : aResult.SegmentText = GetTextRange(nStartIndex, nEndIndex);
2041 0 : aResult.SegmentStart = nStartIndex;
2042 0 : aResult.SegmentEnd = nEndIndex;
2043 : }
2044 : }
2045 : }
2046 0 : break;
2047 : }
2048 :
2049 : case AccessibleTextType::LINE:
2050 : {
2051 0 : SvxTextForwarder& rCacheTF = GetTextForwarder();
2052 0 : sal_Int32 nParaIndex = GetParagraphIndex();
2053 :
2054 0 : CheckPosition(nIndex);
2055 :
2056 0 : sal_Int32 nLine, nLineCount = rCacheTF.GetLineCount( nParaIndex );
2057 : sal_Int32 nCurIndex;
2058 : //the problem is that rCacheTF.GetLineLen() will include the bullet length. But for the bullet line,
2059 : //the text value doesn't contain the bullet characters. all of the bullet and numbering info are exposed
2060 : //by the IAText::attributes(). So here must do special support for bullet line.
2061 0 : sal_Int32 nBulletLen = 0;
2062 : // get the line after the line the index points into
2063 0 : for( nLine=0, nCurIndex=0; nLine<nLineCount; ++nLine )
2064 : {
2065 0 : if (nLine == 0)
2066 : {
2067 0 : EBulletInfo aBulletInfo = rCacheTF.GetBulletInfo(nParaIndex);
2068 0 : if (aBulletInfo.bVisible)
2069 : {
2070 : //in bullet or numbering;
2071 0 : nBulletLen = aBulletInfo.aText.getLength();
2072 0 : }
2073 : }
2074 0 : sal_Int32 nLineLen = rCacheTF.GetLineLen( nParaIndex, nLine);
2075 :
2076 0 : if (nLine == 0)
2077 0 : nCurIndex += nLineLen - nBulletLen;
2078 : else
2079 0 : nCurIndex += nLineLen;
2080 :
2081 0 : if( nCurIndex > nIndex &&
2082 0 : nLine < nLineCount-1 )
2083 : {
2084 0 : aResult.SegmentStart = nCurIndex;
2085 0 : aResult.SegmentEnd = nCurIndex + rCacheTF.GetLineLen( nParaIndex, nLine+1);
2086 0 : aResult.SegmentText = GetTextRange( aResult.SegmentStart + nBulletLen, aResult.SegmentEnd + nBulletLen);
2087 0 : break;
2088 : }
2089 : }
2090 :
2091 0 : break;
2092 : }
2093 : case AccessibleTextType::WORD:
2094 : {
2095 0 : nIndex = SkipField( nIndex, true);
2096 0 : OUString sText( implGetText() );
2097 0 : sal_Int32 nLength = sText.getLength();
2098 :
2099 : // get word at index
2100 0 : bool bWord = implGetWordBoundary( aBoundary, nIndex );
2101 :
2102 : // real current world
2103 0 : sal_Int32 nextWord = nIndex;
2104 : //if( nIndex >= aBoundary.startPos && nIndex <= aBoundary.endPos )
2105 0 : if( nIndex <= aBoundary.endPos )
2106 : {
2107 0 : nextWord = aBoundary.endPos;
2108 0 : if( sText.getStr()[nextWord] == sal_Unicode(' ') ) nextWord++;
2109 0 : bWord = implGetWordBoundary( aBoundary, nextWord );
2110 : }
2111 :
2112 0 : if ( bWord && implIsValidBoundary( aBoundary, nLength ) )
2113 : {
2114 0 : aResult.SegmentText = sText.copy( aBoundary.startPos, aBoundary.endPos - aBoundary.startPos );
2115 0 : aResult.SegmentStart = aBoundary.startPos;
2116 0 : aResult.SegmentEnd = aBoundary.endPos;
2117 :
2118 : // If the end position of aBoundary is inside a field, extend the result to the end of the field
2119 :
2120 0 : ExtendByField( aResult );
2121 0 : }
2122 : }
2123 0 : break;
2124 :
2125 : case AccessibleTextType::CHARACTER:
2126 : {
2127 4 : nIndex = SkipField( nIndex, true);
2128 4 : aResult = OCommonAccessibleText::getTextBehindIndex( nIndex, aTextType );
2129 4 : ExtendByField( aResult );
2130 4 : break;
2131 : }
2132 : default:
2133 8 : aResult = OCommonAccessibleText::getTextBehindIndex( nIndex, aTextType );
2134 4 : break;
2135 : } /* end of switch( aTextType ) */
2136 :
2137 12 : return aResult;
2138 : }
2139 :
2140 0 : sal_Bool SAL_CALL AccessibleEditableTextPara::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
2141 : {
2142 0 : SolarMutexGuard aGuard;
2143 :
2144 : try
2145 : {
2146 0 : SvxEditViewForwarder& rCacheVF = GetEditViewForwarder( true );
2147 : #if OSL_DEBUG_LEVEL > 0
2148 : SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder(); // MUST be after GetEditViewForwarder(), see method docs
2149 : (void)rCacheTF;
2150 : #else
2151 0 : GetTextForwarder(); // MUST be after GetEditViewForwarder(), see method docs
2152 : #endif
2153 :
2154 : bool aRetVal;
2155 :
2156 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
2157 : "AccessibleEditableTextPara::copyText: index value overflow");
2158 :
2159 0 : CheckRange(nStartIndex, nEndIndex);
2160 :
2161 : //Because bullet may occupy one or more characters, the TextAdapter will include bullet to calculate the selection. Add offset to handle bullet
2162 0 : sal_Int32 nBulletLen = 0;
2163 0 : EBulletInfo aBulletInfo = GetTextForwarder().GetBulletInfo(GetParagraphIndex());
2164 0 : if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && aBulletInfo.bVisible )
2165 0 : nBulletLen = aBulletInfo.aText.getLength();
2166 : // save current selection
2167 0 : ESelection aOldSelection;
2168 :
2169 0 : rCacheVF.GetSelection( aOldSelection );
2170 : //rCacheVF.SetSelection( MakeSelection(nStartIndex, nEndIndex) );
2171 0 : rCacheVF.SetSelection( MakeSelection(nStartIndex + nBulletLen, nEndIndex + nBulletLen) );
2172 0 : aRetVal = rCacheVF.Copy();
2173 0 : rCacheVF.SetSelection( aOldSelection ); // restore
2174 :
2175 0 : return aRetVal;
2176 : }
2177 0 : catch (const uno::RuntimeException&)
2178 : {
2179 0 : return sal_False;
2180 0 : }
2181 : }
2182 :
2183 : // XAccessibleEditableText
2184 0 : sal_Bool SAL_CALL AccessibleEditableTextPara::cutText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
2185 : {
2186 :
2187 0 : SolarMutexGuard aGuard;
2188 :
2189 : try
2190 : {
2191 0 : SvxEditViewForwarder& rCacheVF = GetEditViewForwarder( true );
2192 0 : SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder(); // MUST be after GetEditViewForwarder(), see method docs
2193 :
2194 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
2195 : "AccessibleEditableTextPara::cutText: index value overflow");
2196 :
2197 0 : CheckRange(nStartIndex, nEndIndex);
2198 :
2199 : // Because bullet may occupy one or more characters, the TextAdapter will include bullet to calculate the selection. Add offset to handle bullet
2200 0 : sal_Int32 nBulletLen = 0;
2201 0 : EBulletInfo aBulletInfo = GetTextForwarder().GetBulletInfo(GetParagraphIndex());
2202 0 : if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && aBulletInfo.bVisible )
2203 0 : nBulletLen = aBulletInfo.aText.getLength();
2204 0 : ESelection aSelection = MakeSelection (nStartIndex + nBulletLen, nEndIndex + nBulletLen);
2205 : //if( !rCacheTF.IsEditable( MakeSelection(nStartIndex, nEndIndex) ) )
2206 0 : if( !rCacheTF.IsEditable( aSelection ) )
2207 0 : return sal_False; // non-editable area selected
2208 :
2209 : // don't save selection, might become invalid after cut!
2210 : //rCacheVF.SetSelection( MakeSelection(nStartIndex, nEndIndex) );
2211 0 : rCacheVF.SetSelection( aSelection );
2212 :
2213 0 : return rCacheVF.Cut();
2214 : }
2215 0 : catch (const uno::RuntimeException&)
2216 : {
2217 0 : return sal_False;
2218 0 : }
2219 : }
2220 :
2221 0 : sal_Bool SAL_CALL AccessibleEditableTextPara::pasteText( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
2222 : {
2223 :
2224 0 : SolarMutexGuard aGuard;
2225 :
2226 : try
2227 : {
2228 0 : SvxEditViewForwarder& rCacheVF = GetEditViewForwarder( true );
2229 0 : SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder(); // MUST be after GetEditViewForwarder(), see method docs
2230 :
2231 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
2232 : "AccessibleEditableTextPara::pasteText: index value overflow");
2233 :
2234 0 : CheckPosition(nIndex);
2235 :
2236 : // Because bullet may occupy one or more characters, the TextAdapter will include bullet to calculate the selection. Add offset to handle bullet
2237 0 : sal_Int32 nBulletLen = 0;
2238 0 : EBulletInfo aBulletInfo = GetTextForwarder().GetBulletInfo(GetParagraphIndex());
2239 0 : if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && aBulletInfo.bVisible )
2240 0 : nBulletLen = aBulletInfo.aText.getLength();
2241 0 : if( !rCacheTF.IsEditable( MakeSelection(nIndex + nBulletLen) ) )
2242 0 : return sal_False; // non-editable area selected
2243 :
2244 : // #104400# set empty selection (=> cursor) to given index
2245 : //rCacheVF.SetSelection( MakeCursor(nIndex) );
2246 0 : rCacheVF.SetSelection( MakeCursor(nIndex + nBulletLen) );
2247 :
2248 0 : return rCacheVF.Paste();
2249 : }
2250 0 : catch (const uno::RuntimeException&)
2251 : {
2252 0 : return sal_False;
2253 0 : }
2254 : }
2255 :
2256 0 : sal_Bool SAL_CALL AccessibleEditableTextPara::deleteText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
2257 : {
2258 :
2259 0 : SolarMutexGuard aGuard;
2260 :
2261 : try
2262 : {
2263 : // #102710# Request edit view when doing changes
2264 : // AccessibleEmptyEditSource relies on this behaviour
2265 0 : GetEditViewForwarder( true );
2266 0 : SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder(); // MUST be after GetEditViewForwarder(), see method docs
2267 :
2268 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
2269 : "AccessibleEditableTextPara::deleteText: index value overflow");
2270 :
2271 0 : CheckRange(nStartIndex, nEndIndex);
2272 :
2273 : // Because bullet may occupy one or more characters, the TextAdapter will include bullet to calculate the selection. Add offset to handle bullet
2274 0 : sal_Int32 nBulletLen = 0;
2275 0 : EBulletInfo aBulletInfo = GetTextForwarder().GetBulletInfo(GetParagraphIndex());
2276 0 : if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && aBulletInfo.bVisible )
2277 0 : nBulletLen = aBulletInfo.aText.getLength();
2278 0 : ESelection aSelection = MakeSelection (nStartIndex + nBulletLen, nEndIndex + nBulletLen);
2279 :
2280 : //if( !rCacheTF.IsEditable( MakeSelection(nStartIndex, nEndIndex) ) )
2281 0 : if( !rCacheTF.IsEditable( aSelection ) )
2282 0 : return sal_False; // non-editable area selected
2283 :
2284 : //sal_Bool bRet = rCacheTF.Delete( MakeSelection(nStartIndex, nEndIndex) );
2285 0 : bool bRet = rCacheTF.Delete( aSelection );
2286 :
2287 0 : GetEditSource().UpdateData();
2288 :
2289 0 : return bRet;
2290 : }
2291 0 : catch (const uno::RuntimeException&)
2292 : {
2293 0 : return sal_False;
2294 0 : }
2295 : }
2296 :
2297 0 : sal_Bool SAL_CALL AccessibleEditableTextPara::insertText( const OUString& sText, sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
2298 : {
2299 :
2300 0 : SolarMutexGuard aGuard;
2301 :
2302 : try
2303 : {
2304 : // #102710# Request edit view when doing changes
2305 : // AccessibleEmptyEditSource relies on this behaviour
2306 0 : GetEditViewForwarder( true );
2307 0 : SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder(); // MUST be after GetEditViewForwarder(), see method docs
2308 :
2309 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
2310 : "AccessibleEditableTextPara::insertText: index value overflow");
2311 :
2312 0 : CheckPosition(nIndex);
2313 :
2314 : // Because bullet may occupy one or more characters, the TextAdapter will include bullet to calculate the selection. Add offset to handle bullet
2315 0 : sal_Int32 nBulletLen = 0;
2316 0 : EBulletInfo aBulletInfo = GetTextForwarder().GetBulletInfo(GetParagraphIndex());
2317 0 : if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && aBulletInfo.bVisible )
2318 0 : nBulletLen = aBulletInfo.aText.getLength();
2319 :
2320 0 : if( !rCacheTF.IsEditable( MakeSelection(nIndex + nBulletLen) ) )
2321 0 : return sal_False; // non-editable area selected
2322 :
2323 : // #104400# insert given text at empty selection (=> cursor)
2324 0 : bool bRet = rCacheTF.InsertText( sText, MakeCursor(nIndex + nBulletLen) );
2325 :
2326 0 : rCacheTF.QuickFormatDoc();
2327 0 : GetEditSource().UpdateData();
2328 :
2329 0 : return bRet;
2330 : }
2331 0 : catch (const uno::RuntimeException&)
2332 : {
2333 0 : return sal_False;
2334 0 : }
2335 : }
2336 :
2337 0 : sal_Bool SAL_CALL AccessibleEditableTextPara::replaceText( sal_Int32 nStartIndex, sal_Int32 nEndIndex, const OUString& sReplacement ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
2338 : {
2339 :
2340 0 : SolarMutexGuard aGuard;
2341 :
2342 : try
2343 : {
2344 : // #102710# Request edit view when doing changes
2345 : // AccessibleEmptyEditSource relies on this behaviour
2346 0 : GetEditViewForwarder( true );
2347 0 : SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder(); // MUST be after GetEditViewForwarder(), see method docs
2348 :
2349 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
2350 : "AccessibleEditableTextPara::replaceText: index value overflow");
2351 :
2352 0 : CheckRange(nStartIndex, nEndIndex);
2353 :
2354 : // Because bullet may occupy one or more characters, the TextAdapter will include bullet to calculate the selection. Add offset to handle bullet
2355 0 : sal_Int32 nBulletLen = 0;
2356 0 : EBulletInfo aBulletInfo = GetTextForwarder().GetBulletInfo(GetParagraphIndex());
2357 0 : if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && aBulletInfo.bVisible )
2358 0 : nBulletLen = aBulletInfo.aText.getLength();
2359 0 : ESelection aSelection = MakeSelection (nStartIndex + nBulletLen, nEndIndex + nBulletLen);
2360 :
2361 : //if( !rCacheTF.IsEditable( MakeSelection(nStartIndex, nEndIndex) ) )
2362 0 : if( !rCacheTF.IsEditable( aSelection ) )
2363 0 : return sal_False; // non-editable area selected
2364 :
2365 : // insert given text into given range => replace
2366 : //sal_Bool bRet = rCacheTF.InsertText( sReplacement, MakeSelection(nStartIndex, nEndIndex) );
2367 0 : bool bRet = rCacheTF.InsertText( sReplacement, aSelection );
2368 :
2369 0 : rCacheTF.QuickFormatDoc();
2370 0 : GetEditSource().UpdateData();
2371 :
2372 0 : return bRet;
2373 : }
2374 0 : catch (const uno::RuntimeException&)
2375 : {
2376 0 : return sal_False;
2377 0 : }
2378 : }
2379 :
2380 0 : sal_Bool SAL_CALL AccessibleEditableTextPara::setAttributes( sal_Int32 nStartIndex, sal_Int32 nEndIndex, const uno::Sequence< beans::PropertyValue >& aAttributeSet ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
2381 : {
2382 :
2383 0 : SolarMutexGuard aGuard;
2384 :
2385 : try
2386 : {
2387 : // #102710# Request edit view when doing changes
2388 : // AccessibleEmptyEditSource relies on this behaviour
2389 0 : GetEditViewForwarder( true );
2390 0 : SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder(); // MUST be after GetEditViewForwarder(), see method docs
2391 0 : sal_Int32 nPara = GetParagraphIndex();
2392 :
2393 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
2394 : "AccessibleEditableTextPara::setAttributes: index value overflow");
2395 :
2396 0 : CheckRange(nStartIndex, nEndIndex);
2397 :
2398 0 : if( !rCacheTF.IsEditable( MakeSelection(nStartIndex, nEndIndex) ) )
2399 0 : return sal_False; // non-editable area selected
2400 :
2401 : // do the indices span the whole paragraph? Then use the outliner map
2402 : // TODO: hold it as a member?
2403 0 : SvxAccessibleTextPropertySet aPropSet( &GetEditSource(),
2404 0 : 0 == nStartIndex &&
2405 0 : rCacheTF.GetTextLen(nPara) == nEndIndex ?
2406 : ImplGetSvxUnoOutlinerTextCursorSvxPropertySet() :
2407 0 : ImplGetSvxTextPortionSvxPropertySet() );
2408 :
2409 0 : aPropSet.SetSelection( MakeSelection(nStartIndex, nEndIndex) );
2410 :
2411 : // convert from PropertyValue to Any
2412 0 : sal_Int32 i, nLength( aAttributeSet.getLength() );
2413 0 : const beans::PropertyValue* pPropArray = aAttributeSet.getConstArray();
2414 0 : for(i=0; i<nLength; ++i)
2415 : {
2416 : try
2417 : {
2418 0 : aPropSet.setPropertyValue(pPropArray->Name, pPropArray->Value);
2419 : }
2420 0 : catch (const uno::Exception&)
2421 : {
2422 : OSL_FAIL("AccessibleEditableTextPara::setAttributes exception in setPropertyValue");
2423 : }
2424 :
2425 0 : ++pPropArray;
2426 : }
2427 :
2428 0 : rCacheTF.QuickFormatDoc();
2429 0 : GetEditSource().UpdateData();
2430 :
2431 0 : return sal_True;
2432 : }
2433 0 : catch (const uno::RuntimeException&)
2434 : {
2435 0 : return sal_False;
2436 0 : }
2437 : }
2438 :
2439 0 : sal_Bool SAL_CALL AccessibleEditableTextPara::setText( const OUString& sText ) throw (uno::RuntimeException, std::exception)
2440 : {
2441 :
2442 0 : SolarMutexGuard aGuard;
2443 :
2444 0 : return replaceText(0, getCharacterCount(), sText);
2445 : }
2446 :
2447 : // XAccessibleTextAttributes
2448 2 : uno::Sequence< beans::PropertyValue > SAL_CALL AccessibleEditableTextPara::getDefaultAttributes(
2449 : const uno::Sequence< OUString >& rRequestedAttributes )
2450 : throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
2451 : {
2452 2 : SolarMutexGuard aGuard;
2453 :
2454 : #if OSL_DEBUG_LEVEL > 0
2455 : SvxAccessibleTextAdapter& rCacheTF =
2456 : #endif
2457 2 : GetTextForwarder();
2458 :
2459 : #if OSL_DEBUG_LEVEL > 0
2460 : (void)rCacheTF;
2461 : #endif
2462 :
2463 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
2464 : "AccessibleEditableTextPara::getCharacterAttributes: index value overflow");
2465 :
2466 : // get XPropertySetInfo for paragraph attributes and
2467 : // character attributes that span all the paragraphs text.
2468 2 : SvxAccessibleTextPropertySet aPropSet( &GetEditSource(),
2469 6 : ImplGetSvxCharAndParaPropertiesSet() );
2470 2 : aPropSet.SetSelection( MakeSelection( 0, GetTextLen() ) );
2471 4 : uno::Reference< beans::XPropertySetInfo > xPropSetInfo = aPropSet.getPropertySetInfo();
2472 2 : if (!xPropSetInfo.is())
2473 : throw uno::RuntimeException("Cannot query XPropertySetInfo",
2474 : uno::Reference< uno::XInterface >
2475 0 : ( static_cast< XAccessible* > (this) ) ); // disambiguate hierarchy
2476 :
2477 : // build sequence of available properties to check
2478 2 : sal_Int32 nLenReqAttr = rRequestedAttributes.getLength();
2479 4 : uno::Sequence< beans::Property > aProperties;
2480 2 : if (nLenReqAttr)
2481 : {
2482 2 : const OUString *pRequestedAttributes = rRequestedAttributes.getConstArray();
2483 :
2484 2 : aProperties.realloc( nLenReqAttr );
2485 2 : beans::Property *pProperties = aProperties.getArray();
2486 2 : sal_Int32 nCurLen = 0;
2487 4 : for (sal_Int32 i = 0; i < nLenReqAttr; ++i)
2488 : {
2489 2 : beans::Property aProp;
2490 : try
2491 : {
2492 2 : aProp = xPropSetInfo->getPropertyByName( pRequestedAttributes[i] );
2493 : }
2494 4 : catch (const beans::UnknownPropertyException&)
2495 : {
2496 2 : continue;
2497 : }
2498 0 : pProperties[ nCurLen++ ] = aProp;
2499 0 : }
2500 2 : aProperties.realloc( nCurLen );
2501 : }
2502 : else
2503 0 : aProperties = xPropSetInfo->getProperties();
2504 :
2505 2 : sal_Int32 nLength = aProperties.getLength();
2506 2 : const beans::Property *pProperties = aProperties.getConstArray();
2507 :
2508 : // build resulting sequence
2509 2 : uno::Sequence< beans::PropertyValue > aOutSequence( nLength );
2510 2 : beans::PropertyValue* pOutSequence = aOutSequence.getArray();
2511 2 : sal_Int32 nOutLen = 0;
2512 2 : for (sal_Int32 i = 0; i < nLength; ++i)
2513 : {
2514 : // calling implementation functions:
2515 : // _getPropertyState and _getPropertyValue (see below) to provide
2516 : // the proper paragraph number when retrieving paragraph attributes
2517 0 : PropertyState eState = aPropSet._getPropertyState( pProperties->Name, mnParagraphIndex );
2518 : if ( eState == PropertyState_AMBIGUOUS_VALUE )
2519 : {
2520 : OSL_FAIL( "ambiguous property value encountered" );
2521 : }
2522 :
2523 : //if (eState == PropertyState_DIRECT_VALUE)
2524 : // per definition all paragraph properties and all character
2525 : // properties spanning the whole paragraph should be returned
2526 : // and declared as default value
2527 : {
2528 0 : pOutSequence->Name = pProperties->Name;
2529 0 : pOutSequence->Handle = pProperties->Handle;
2530 0 : pOutSequence->Value = aPropSet._getPropertyValue( pProperties->Name, mnParagraphIndex );
2531 0 : pOutSequence->State = PropertyState_DEFAULT_VALUE;
2532 :
2533 0 : ++pOutSequence;
2534 0 : ++nOutLen;
2535 : }
2536 0 : ++pProperties;
2537 : }
2538 2 : aOutSequence.realloc( nOutLen );
2539 :
2540 4 : return aOutSequence;
2541 : }
2542 :
2543 :
2544 2 : uno::Sequence< beans::PropertyValue > SAL_CALL AccessibleEditableTextPara::getRunAttributes(
2545 : sal_Int32 nIndex,
2546 : const uno::Sequence< OUString >& rRequestedAttributes )
2547 : throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
2548 : {
2549 :
2550 2 : SolarMutexGuard aGuard;
2551 :
2552 : #if OSL_DEBUG_LEVEL > 0
2553 : SvxAccessibleTextAdapter& rCacheTF =
2554 : #endif
2555 2 : GetTextForwarder();
2556 :
2557 : #if OSL_DEBUG_LEVEL > 0
2558 : (void)rCacheTF;
2559 : #endif
2560 :
2561 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
2562 : "AccessibleEditableTextPara::getCharacterAttributes: index value overflow");
2563 :
2564 2 : if( getCharacterCount() > 0 )
2565 2 : CheckIndex(nIndex);
2566 : else
2567 0 : CheckPosition(nIndex);
2568 :
2569 2 : SvxAccessibleTextPropertySet aPropSet( &GetEditSource(),
2570 6 : ImplGetSvxCharAndParaPropertiesSet() );
2571 2 : aPropSet.SetSelection( MakeSelection( nIndex ) );
2572 4 : uno::Reference< beans::XPropertySetInfo > xPropSetInfo = aPropSet.getPropertySetInfo();
2573 2 : if (!xPropSetInfo.is())
2574 : throw uno::RuntimeException("Cannot query XPropertySetInfo",
2575 : uno::Reference< uno::XInterface >
2576 0 : ( static_cast< XAccessible* > (this) ) ); // disambiguate hierarchy
2577 :
2578 : // build sequence of available properties to check
2579 2 : sal_Int32 nLenReqAttr = rRequestedAttributes.getLength();
2580 4 : uno::Sequence< beans::Property > aProperties;
2581 2 : if (nLenReqAttr)
2582 : {
2583 2 : const OUString *pRequestedAttributes = rRequestedAttributes.getConstArray();
2584 :
2585 2 : aProperties.realloc( nLenReqAttr );
2586 2 : beans::Property *pProperties = aProperties.getArray();
2587 2 : sal_Int32 nCurLen = 0;
2588 4 : for (sal_Int32 i = 0; i < nLenReqAttr; ++i)
2589 : {
2590 2 : beans::Property aProp;
2591 : try
2592 : {
2593 2 : aProp = xPropSetInfo->getPropertyByName( pRequestedAttributes[i] );
2594 : }
2595 4 : catch (const beans::UnknownPropertyException&)
2596 : {
2597 2 : continue;
2598 : }
2599 0 : pProperties[ nCurLen++ ] = aProp;
2600 0 : }
2601 2 : aProperties.realloc( nCurLen );
2602 : }
2603 : else
2604 0 : aProperties = xPropSetInfo->getProperties();
2605 :
2606 2 : sal_Int32 nLength = aProperties.getLength();
2607 2 : const beans::Property *pProperties = aProperties.getConstArray();
2608 :
2609 : // build resulting sequence
2610 2 : uno::Sequence< beans::PropertyValue > aOutSequence( nLength );
2611 2 : beans::PropertyValue* pOutSequence = aOutSequence.getArray();
2612 2 : sal_Int32 nOutLen = 0;
2613 2 : for (sal_Int32 i = 0; i < nLength; ++i)
2614 : {
2615 : // calling 'regular' functions that will operate on the selection
2616 0 : PropertyState eState = aPropSet.getPropertyState( pProperties->Name );
2617 0 : if (eState == PropertyState_DIRECT_VALUE)
2618 : {
2619 0 : pOutSequence->Name = pProperties->Name;
2620 0 : pOutSequence->Handle = pProperties->Handle;
2621 0 : pOutSequence->Value = aPropSet.getPropertyValue( pProperties->Name );
2622 0 : pOutSequence->State = eState;
2623 :
2624 0 : ++pOutSequence;
2625 0 : ++nOutLen;
2626 : }
2627 0 : ++pProperties;
2628 : }
2629 2 : aOutSequence.realloc( nOutLen );
2630 :
2631 4 : return aOutSequence;
2632 : }
2633 :
2634 : // XAccessibleHypertext
2635 0 : ::sal_Int32 SAL_CALL AccessibleEditableTextPara::getHyperLinkCount( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
2636 : {
2637 0 : SvxAccessibleTextAdapter& rT = GetTextForwarder();
2638 0 : const sal_Int32 nPara = GetParagraphIndex();
2639 :
2640 0 : sal_Int32 nHyperLinks = 0;
2641 0 : sal_Int32 nFields = rT.GetFieldCount( nPara );
2642 0 : for (sal_Int32 n = 0; n < nFields; ++n)
2643 : {
2644 0 : EFieldInfo aField = rT.GetFieldInfo( nPara, n );
2645 0 : if ( aField.pFieldItem->GetField()->ISA( SvxURLField ) )
2646 0 : nHyperLinks++;
2647 0 : }
2648 0 : return nHyperLinks;
2649 : }
2650 :
2651 0 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleHyperlink > SAL_CALL AccessibleEditableTextPara::getHyperLink( ::sal_Int32 nLinkIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
2652 : {
2653 0 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleHyperlink > xRef;
2654 :
2655 0 : SvxAccessibleTextAdapter& rT = GetTextForwarder();
2656 0 : const sal_Int32 nPara = GetParagraphIndex();
2657 :
2658 0 : sal_Int32 nHyperLink = 0;
2659 0 : sal_Int32 nFields = rT.GetFieldCount( nPara );
2660 0 : for (sal_Int32 n = 0; n < nFields; ++n)
2661 : {
2662 0 : EFieldInfo aField = rT.GetFieldInfo( nPara, n );
2663 0 : if ( aField.pFieldItem->GetField()->ISA( SvxURLField ) )
2664 : {
2665 0 : if ( nHyperLink == nLinkIndex )
2666 : {
2667 0 : sal_Int32 nEEStart = aField.aPosition.nIndex;
2668 :
2669 : // Translate EE Index to accessible index
2670 0 : sal_Int32 nStart = rT.CalcEditEngineIndex( nPara, nEEStart );
2671 0 : sal_Int32 nEnd = nStart + aField.aCurrentText.getLength();
2672 0 : xRef = new AccessibleHyperlink( rT, new SvxFieldItem( *aField.pFieldItem ), nPara, nEEStart, nStart, nEnd, aField.aCurrentText );
2673 0 : break;
2674 : }
2675 0 : nHyperLink++;
2676 : }
2677 0 : }
2678 :
2679 0 : return xRef;
2680 : }
2681 :
2682 0 : ::sal_Int32 SAL_CALL AccessibleEditableTextPara::getHyperLinkIndex( ::sal_Int32 nCharIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
2683 : {
2684 0 : const sal_Int32 nPara = GetParagraphIndex();
2685 0 : SvxAccessibleTextAdapter& rT = GetTextForwarder();
2686 :
2687 0 : const sal_Int32 nEEIndex = rT.CalcEditEngineIndex( nPara, nCharIndex );
2688 0 : sal_Int32 nHLIndex = -1; //i123620
2689 0 : sal_Int32 nHyperLink = 0;
2690 0 : sal_Int32 nFields = rT.GetFieldCount( nPara );
2691 0 : for (sal_Int32 n = 0; n < nFields; ++n)
2692 : {
2693 0 : EFieldInfo aField = rT.GetFieldInfo( nPara, n );
2694 0 : if ( aField.pFieldItem->GetField()->ISA( SvxURLField ) )
2695 : {
2696 0 : if ( aField.aPosition.nIndex == nEEIndex )
2697 : {
2698 0 : nHLIndex = nHyperLink;
2699 0 : break;
2700 : }
2701 0 : nHyperLink++;
2702 : }
2703 0 : }
2704 :
2705 0 : return nHLIndex;
2706 : }
2707 :
2708 : // XAccessibleMultiLineText
2709 0 : sal_Int32 SAL_CALL AccessibleEditableTextPara::getLineNumberAtIndex( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
2710 : {
2711 :
2712 0 : sal_Int32 nRes = -1;
2713 0 : sal_Int32 nPara = GetParagraphIndex();
2714 :
2715 0 : SvxTextForwarder &rCacheTF = GetTextForwarder();
2716 0 : const bool bValidPara = 0 <= nPara && nPara < rCacheTF.GetParagraphCount();
2717 : DBG_ASSERT( bValidPara, "getLineNumberAtIndex: current paragraph index out of range" );
2718 0 : if (bValidPara)
2719 : {
2720 : // we explicitly allow for the index to point at the character right behind the text
2721 0 : if (0 <= nIndex && nIndex <= rCacheTF.GetTextLen( nPara ))
2722 0 : nRes = rCacheTF.GetLineNumberAtIndex( nPara, nIndex );
2723 : else
2724 0 : throw lang::IndexOutOfBoundsException();
2725 : }
2726 0 : return nRes;
2727 : }
2728 :
2729 : // XAccessibleMultiLineText
2730 0 : ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleEditableTextPara::getTextAtLineNumber( sal_Int32 nLineNo ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
2731 : {
2732 :
2733 0 : ::com::sun::star::accessibility::TextSegment aResult;
2734 0 : sal_Int32 nPara = GetParagraphIndex();
2735 0 : SvxTextForwarder &rCacheTF = GetTextForwarder();
2736 0 : const bool bValidPara = 0 <= nPara && nPara < rCacheTF.GetParagraphCount();
2737 : DBG_ASSERT( bValidPara, "getTextAtLineNumber: current paragraph index out of range" );
2738 0 : if (bValidPara)
2739 : {
2740 0 : if (0 <= nLineNo && nLineNo < rCacheTF.GetLineCount( nPara ))
2741 : {
2742 0 : sal_Int32 nStart = 0, nEnd = 0;
2743 0 : rCacheTF.GetLineBoundaries( nStart, nEnd, nPara, nLineNo );
2744 0 : if (nStart >= 0 && nEnd >= 0)
2745 : {
2746 : try
2747 : {
2748 0 : aResult.SegmentText = getTextRange( nStart, nEnd );
2749 0 : aResult.SegmentStart = nStart;
2750 0 : aResult.SegmentEnd = nEnd;
2751 : }
2752 0 : catch (const lang::IndexOutOfBoundsException&)
2753 : {
2754 : // this is not the exception that should be raised in this function ...
2755 : DBG_ASSERT( false, "unexpected exception" );
2756 : }
2757 : }
2758 : }
2759 : else
2760 0 : throw lang::IndexOutOfBoundsException();
2761 : }
2762 0 : return aResult;
2763 : }
2764 :
2765 : // XAccessibleMultiLineText
2766 0 : ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleEditableTextPara::getTextAtLineWithCaret( ) throw (uno::RuntimeException, std::exception)
2767 : {
2768 :
2769 0 : ::com::sun::star::accessibility::TextSegment aResult;
2770 : try
2771 : {
2772 0 : aResult = getTextAtLineNumber( getNumberOfLineWithCaret() );
2773 : }
2774 0 : catch (const lang::IndexOutOfBoundsException&)
2775 : {
2776 : // this one needs to be catched since this interface does not allow for it.
2777 : }
2778 0 : return aResult;
2779 : }
2780 :
2781 : // XAccessibleMultiLineText
2782 0 : sal_Int32 SAL_CALL AccessibleEditableTextPara::getNumberOfLineWithCaret( ) throw (uno::RuntimeException, std::exception)
2783 : {
2784 :
2785 0 : sal_Int32 nRes = -1;
2786 : try
2787 : {
2788 0 : nRes = getLineNumberAtIndex( getCaretPosition() );
2789 : }
2790 0 : catch (const lang::IndexOutOfBoundsException&)
2791 : {
2792 : // this one needs to be catched since this interface does not allow for it.
2793 : }
2794 0 : return nRes;
2795 : }
2796 :
2797 :
2798 : // XServiceInfo
2799 12 : OUString SAL_CALL AccessibleEditableTextPara::getImplementationName (void) throw (uno::RuntimeException, std::exception)
2800 : {
2801 :
2802 12 : return OUString("AccessibleEditableTextPara");
2803 : }
2804 :
2805 0 : sal_Bool SAL_CALL AccessibleEditableTextPara::supportsService (const OUString& sServiceName) throw (uno::RuntimeException, std::exception)
2806 : {
2807 :
2808 0 : return cppu::supportsService(this, sServiceName);
2809 : }
2810 :
2811 0 : uno::Sequence< OUString> SAL_CALL AccessibleEditableTextPara::getSupportedServiceNames (void) throw (uno::RuntimeException, std::exception)
2812 : {
2813 :
2814 0 : const OUString sServiceName( getServiceName() );
2815 0 : return uno::Sequence< OUString > (&sServiceName, 1);
2816 : }
2817 :
2818 : // XServiceName
2819 0 : OUString SAL_CALL AccessibleEditableTextPara::getServiceName (void) throw (uno::RuntimeException)
2820 : {
2821 :
2822 : // #105185# Using correct service now
2823 0 : return OUString("com.sun.star.text.AccessibleParagraphView");
2824 : }
2825 :
2826 669 : } // end of namespace accessibility
2827 :
2828 :
2829 :
2830 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|