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 <unotools/accessiblestatesethelper.hxx>
46 : #include <unotools/accessiblerelationsethelper.hxx>
47 : #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
48 : #include <vcl/unohelp.hxx>
49 : #include <editeng/editeng.hxx>
50 : #include <editeng/unoprnms.hxx>
51 : #include <editeng/unoipset.hxx>
52 : #include <editeng/outliner.hxx>
53 :
54 : //------------------------------------------------------------------------
55 : //
56 : // Project-local header
57 : //
58 : //------------------------------------------------------------------------
59 :
60 : #include <com/sun/star/beans/PropertyState.hpp>
61 :
62 : //!!!#include <svx/unoshape.hxx>
63 : //!!!#include <svx/dialmgr.hxx>
64 : //!!!#include "accessibility.hrc"
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 :
73 :
74 : using namespace ::com::sun::star;
75 : using namespace ::com::sun::star::beans;
76 : using namespace ::com::sun::star::accessibility;
77 :
78 :
79 : //------------------------------------------------------------------------
80 : //
81 : // AccessibleEditableTextPara implementation
82 : //
83 : //------------------------------------------------------------------------
84 :
85 : namespace accessibility
86 : {
87 :
88 2 : const SvxItemPropertySet* ImplGetSvxCharAndParaPropertiesSet()
89 : {
90 : // PropertyMap for character and paragraph properties
91 : static const SfxItemPropertyMapEntry aPropMap[] =
92 : {
93 46 : SVX_UNOEDIT_CHAR_PROPERTIES,
94 14 : SVX_UNOEDIT_PARA_PROPERTIES,
95 2 : SVX_UNOEDIT_NUMBERING_PROPERTIE,
96 1 : {MAP_CHAR_LEN("TextUserDefinedAttributes"), EE_CHAR_XMLATTRIBS, &::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0) , 0, 0},
97 1 : {MAP_CHAR_LEN("ParaUserDefinedAttributes"), EE_PARA_XMLATTRIBS, &::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0) , 0, 0},
98 : {0,0,0,0,0,0}
99 66 : };
100 2 : static SvxItemPropertySet aPropSet( aPropMap, EditEngine::GetGlobalItemPool() );
101 2 : return &aPropSet;
102 : }
103 :
104 :
105 : DBG_NAME( AccessibleEditableTextPara )
106 :
107 : // #i27138# - add parameter <_pParaManager>
108 30 : 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 30 : mnNotifierClientId(::comphelper::AccessibleEventNotifier::registerClient()),
123 : // #i27138#
124 60 : mpParaManager( _pParaManager )
125 : {
126 : #ifdef DBG_UTIL
127 : DBG_CTOR( AccessibleEditableTextPara, NULL );
128 : OSL_TRACE( "AccessibleEditableTextPara received ID: %d", mnNotifierClientId );
129 : #endif
130 :
131 : try
132 : {
133 : // Create the state set.
134 30 : ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper ();
135 30 : mxStateSet = pStateSet;
136 :
137 : // these are always on
138 30 : pStateSet->AddState( AccessibleStateType::MULTI_LINE );
139 30 : pStateSet->AddState( AccessibleStateType::FOCUSABLE );
140 30 : pStateSet->AddState( AccessibleStateType::VISIBLE );
141 30 : pStateSet->AddState( AccessibleStateType::SHOWING );
142 30 : pStateSet->AddState( AccessibleStateType::ENABLED );
143 30 : pStateSet->AddState( AccessibleStateType::SENSITIVE );
144 : }
145 0 : catch (const uno::Exception&)
146 : {
147 : }
148 30 : }
149 :
150 90 : AccessibleEditableTextPara::~AccessibleEditableTextPara()
151 : {
152 : DBG_DTOR( AccessibleEditableTextPara, NULL );
153 :
154 : // sign off from event notifier
155 30 : if( getNotifierClientId() != -1 )
156 : {
157 : try
158 : {
159 7 : ::comphelper::AccessibleEventNotifier::revokeClient( getNotifierClientId() );
160 : #ifdef DBG_UTIL
161 : OSL_TRACE( "AccessibleEditableTextPara revoked ID: %d", mnNotifierClientId );
162 : #endif
163 : }
164 0 : catch (const uno::Exception&)
165 : {
166 : }
167 : }
168 60 : }
169 :
170 102 : OUString AccessibleEditableTextPara::implGetText()
171 : {
172 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
173 :
174 102 : return GetTextRange( 0, GetTextLen() );
175 : }
176 :
177 3 : ::com::sun::star::lang::Locale AccessibleEditableTextPara::implGetLocale()
178 : {
179 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
180 :
181 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= SAL_MAX_INT32,
182 : "AccessibleEditableTextPara::getLocale: paragraph index value overflow");
183 :
184 : // return locale of first character in the paragraph
185 3 : return LanguageTag(GetTextForwarder().GetLanguage( GetParagraphIndex(), 0 )).getLocale();
186 : }
187 :
188 0 : void AccessibleEditableTextPara::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
189 : {
190 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
191 :
192 : sal_uInt16 nStart, nEnd;
193 :
194 0 : if( GetSelection( nStart, nEnd ) )
195 : {
196 0 : nStartIndex = nStart;
197 0 : nEndIndex = nEnd;
198 : }
199 : else
200 : {
201 : // #102234# No exception, just set to 'invalid'
202 0 : nStartIndex = -1;
203 0 : nEndIndex = -1;
204 : }
205 0 : }
206 :
207 4 : void AccessibleEditableTextPara::implGetParagraphBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 /*nIndex*/ )
208 : {
209 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
210 : DBG_WARNING( "AccessibleEditableTextPara::implGetParagraphBoundary: only a base implementation, ignoring the index" );
211 :
212 4 : rBoundary.startPos = 0;
213 4 : rBoundary.endPos = GetTextLen();
214 4 : }
215 :
216 0 : void AccessibleEditableTextPara::implGetLineBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 nIndex )
217 : {
218 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
219 :
220 0 : SvxTextForwarder& rCacheTF = GetTextForwarder();
221 0 : const sal_Int32 nParaIndex = GetParagraphIndex();
222 :
223 : DBG_ASSERT(nParaIndex >= 0 && nParaIndex <= SAL_MAX_INT32,
224 : "AccessibleEditableTextPara::implGetLineBoundary: paragraph index value overflow");
225 :
226 0 : const sal_Int32 nTextLen = rCacheTF.GetTextLen( nParaIndex );
227 :
228 0 : CheckPosition(nIndex);
229 :
230 0 : rBoundary.startPos = rBoundary.endPos = -1;
231 :
232 0 : const sal_uInt16 nLineCount=rCacheTF.GetLineCount( nParaIndex );
233 :
234 0 : if( nIndex == nTextLen )
235 : {
236 : // #i17014# Special-casing one-behind-the-end character
237 0 : if( nLineCount <= 1 )
238 0 : rBoundary.startPos = 0;
239 : else
240 0 : rBoundary.startPos = nTextLen - rCacheTF.GetLineLen( nParaIndex,
241 0 : nLineCount-1 );
242 :
243 0 : rBoundary.endPos = nTextLen;
244 : }
245 : else
246 : {
247 : // normal line search
248 : sal_uInt16 nLine;
249 : sal_Int32 nCurIndex;
250 0 : for( nLine=0, nCurIndex=0; nLine<nLineCount; ++nLine )
251 : {
252 0 : nCurIndex += rCacheTF.GetLineLen( nParaIndex, nLine);
253 :
254 0 : if( nCurIndex > nIndex )
255 : {
256 0 : rBoundary.startPos = nCurIndex - rCacheTF.GetLineLen( nParaIndex, nLine);
257 0 : rBoundary.endPos = nCurIndex;
258 0 : break;
259 : }
260 : }
261 : }
262 0 : }
263 :
264 146 : int AccessibleEditableTextPara::getNotifierClientId() const
265 : {
266 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
267 :
268 146 : return mnNotifierClientId;
269 : }
270 :
271 25 : void AccessibleEditableTextPara::SetIndexInParent( sal_Int32 nIndex )
272 : {
273 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
274 :
275 25 : mnIndexInParent = nIndex;
276 25 : }
277 :
278 0 : sal_Int32 AccessibleEditableTextPara::GetIndexInParent() const
279 : {
280 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
281 :
282 0 : return mnIndexInParent;
283 : }
284 :
285 25 : void AccessibleEditableTextPara::SetParagraphIndex( sal_Int32 nIndex )
286 : {
287 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
288 :
289 25 : sal_Int32 nOldIndex = mnParagraphIndex;
290 :
291 25 : mnParagraphIndex = nIndex;
292 :
293 25 : WeakBullet::HardRefType aChild( maImageBullet.get() );
294 25 : if( aChild.is() )
295 0 : aChild->SetParagraphIndex(mnParagraphIndex);
296 :
297 : try
298 : {
299 25 : if( nOldIndex != nIndex )
300 : {
301 0 : uno::Any aOldDesc;
302 0 : uno::Any aOldName;
303 :
304 : try
305 : {
306 0 : aOldDesc <<= getAccessibleDescription();
307 0 : aOldName <<= getAccessibleName();
308 : }
309 0 : catch (const uno::Exception&) // optional behaviour
310 : {
311 : }
312 : // index and therefore description changed
313 0 : FireEvent( AccessibleEventId::DESCRIPTION_CHANGED, uno::makeAny( getAccessibleDescription() ), aOldDesc );
314 0 : FireEvent( AccessibleEventId::NAME_CHANGED, uno::makeAny( getAccessibleName() ), aOldName );
315 : }
316 : }
317 0 : catch (const uno::Exception&) // optional behaviour
318 : {
319 25 : }
320 25 : }
321 :
322 364 : sal_Int32 AccessibleEditableTextPara::GetParagraphIndex() const SAL_THROW((uno::RuntimeException))
323 : {
324 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
325 :
326 364 : return mnParagraphIndex;
327 : }
328 :
329 25 : void AccessibleEditableTextPara::Dispose()
330 : {
331 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
332 :
333 25 : int nClientId( getNotifierClientId() );
334 :
335 : // #108212# drop all references before notifying dispose
336 25 : mxParent = NULL;
337 25 : mnNotifierClientId = -1;
338 25 : mpEditSource = NULL;
339 :
340 : // notify listeners
341 25 : if( nClientId != -1 )
342 : {
343 : try
344 : {
345 23 : uno::Reference < XAccessibleContext > xThis = getAccessibleContext();
346 :
347 : // #106234# Delegate to EventNotifier
348 23 : ::comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( nClientId, xThis );
349 : #ifdef DBG_UTIL
350 : OSL_TRACE( "Disposed ID: %d", nClientId );
351 : #endif
352 : }
353 0 : catch (const uno::Exception&)
354 : {
355 : }
356 : }
357 25 : }
358 :
359 33 : void AccessibleEditableTextPara::SetEditSource( SvxEditSourceAdapter* pEditSource )
360 : {
361 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
362 :
363 33 : mpEditSource = pEditSource;
364 :
365 33 : WeakBullet::HardRefType aChild( maImageBullet.get() );
366 33 : if( aChild.is() )
367 0 : aChild->SetEditSource(pEditSource);
368 :
369 33 : if( !mpEditSource )
370 : {
371 : // going defunc
372 3 : UnSetState( AccessibleStateType::SHOWING );
373 3 : UnSetState( AccessibleStateType::VISIBLE );
374 3 : SetState( AccessibleStateType::INVALID );
375 3 : SetState( AccessibleStateType::DEFUNC );
376 :
377 3 : Dispose();
378 : }
379 :
380 : // #108900# Init last text content
381 : try
382 : {
383 33 : TextChanged();
384 : }
385 3 : catch (const uno::RuntimeException&)
386 : {
387 33 : }
388 33 : }
389 :
390 101 : ESelection AccessibleEditableTextPara::MakeSelection( sal_Int32 nStartEEIndex, sal_Int32 nEndEEIndex )
391 : {
392 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
393 :
394 : // check overflow
395 : DBG_ASSERT(nStartEEIndex >= 0 && nStartEEIndex <= USHRT_MAX &&
396 : nEndEEIndex >= 0 && nEndEEIndex <= USHRT_MAX &&
397 : GetParagraphIndex() >= 0 && GetParagraphIndex() <= SAL_MAX_INT32,
398 : "AccessibleEditableTextPara::MakeSelection: index value overflow");
399 :
400 101 : sal_Int32 nParaIndex = GetParagraphIndex();
401 : return ESelection( nParaIndex, static_cast< sal_uInt16 >( nStartEEIndex ),
402 101 : nParaIndex, static_cast< sal_uInt16 >( nEndEEIndex ) );
403 : }
404 :
405 1 : ESelection AccessibleEditableTextPara::MakeSelection( sal_Int32 nEEIndex )
406 : {
407 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
408 :
409 1 : return MakeSelection( nEEIndex, nEEIndex+1 );
410 : }
411 :
412 0 : ESelection AccessibleEditableTextPara::MakeCursor( sal_Int32 nEEIndex )
413 : {
414 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
415 :
416 0 : return MakeSelection( nEEIndex, nEEIndex );
417 : }
418 :
419 4 : void AccessibleEditableTextPara::CheckIndex( sal_Int32 nIndex ) SAL_THROW((lang::IndexOutOfBoundsException, uno::RuntimeException))
420 : {
421 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
422 :
423 4 : if( nIndex < 0 || nIndex >= getCharacterCount() )
424 : throw lang::IndexOutOfBoundsException("AccessibleEditableTextPara: character index out of bounds",
425 : uno::Reference< uno::XInterface >
426 2 : ( static_cast< ::cppu::OWeakObject* > (this) ) ); // disambiguate hierarchy
427 2 : }
428 :
429 27 : void AccessibleEditableTextPara::CheckPosition( sal_Int32 nIndex ) SAL_THROW((lang::IndexOutOfBoundsException, uno::RuntimeException))
430 : {
431 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
432 :
433 27 : if( nIndex < 0 || nIndex > getCharacterCount() )
434 : throw lang::IndexOutOfBoundsException("AccessibleEditableTextPara: character position out of bounds",
435 : uno::Reference< uno::XInterface >
436 4 : ( static_cast< ::cppu::OWeakObject* > (this) ) ); // disambiguate hierarchy
437 23 : }
438 :
439 3 : void AccessibleEditableTextPara::CheckRange( sal_Int32 nStart, sal_Int32 nEnd ) SAL_THROW((lang::IndexOutOfBoundsException, uno::RuntimeException))
440 : {
441 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
442 :
443 3 : CheckPosition( nStart );
444 1 : CheckPosition( nEnd );
445 1 : }
446 :
447 0 : sal_Bool AccessibleEditableTextPara::GetSelection( sal_uInt16& nStartPos, sal_uInt16& nEndPos ) SAL_THROW((uno::RuntimeException))
448 : {
449 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
450 :
451 0 : ESelection aSelection;
452 0 : sal_Int32 nPara = GetParagraphIndex();
453 0 : if( !GetEditViewForwarder().GetSelection( aSelection ) )
454 0 : return sal_False;
455 :
456 0 : if( aSelection.nStartPara < aSelection.nEndPara )
457 : {
458 0 : if( aSelection.nStartPara > nPara ||
459 0 : aSelection.nEndPara < nPara )
460 0 : return sal_False;
461 :
462 0 : if( nPara == aSelection.nStartPara )
463 0 : nStartPos = aSelection.nStartPos;
464 : else
465 0 : nStartPos = 0;
466 :
467 0 : if( nPara == aSelection.nEndPara )
468 0 : nEndPos = aSelection.nEndPos;
469 : else
470 0 : nEndPos = GetTextLen();
471 : }
472 : else
473 : {
474 0 : if( aSelection.nStartPara < nPara ||
475 0 : aSelection.nEndPara > nPara )
476 0 : return sal_False;
477 :
478 0 : if( nPara == aSelection.nStartPara )
479 0 : nStartPos = aSelection.nStartPos;
480 : else
481 0 : nStartPos = GetTextLen();
482 :
483 0 : if( nPara == aSelection.nEndPara )
484 0 : nEndPos = aSelection.nEndPos;
485 : else
486 0 : nEndPos = 0;
487 : }
488 :
489 0 : return sal_True;
490 : }
491 :
492 99 : String AccessibleEditableTextPara::GetTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) SAL_THROW((uno::RuntimeException))
493 : {
494 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
495 :
496 99 : return GetTextForwarder().GetText( MakeSelection(nStartIndex, nEndIndex) );
497 : }
498 :
499 107 : sal_uInt16 AccessibleEditableTextPara::GetTextLen() const SAL_THROW((uno::RuntimeException))
500 : {
501 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
502 :
503 107 : return GetTextForwarder().GetTextLen( static_cast< sal_uInt16 >( GetParagraphIndex() ) );
504 : }
505 :
506 451 : SvxEditSourceAdapter& AccessibleEditableTextPara::GetEditSource() const SAL_THROW((uno::RuntimeException))
507 : {
508 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
509 :
510 451 : if( mpEditSource )
511 896 : return *mpEditSource;
512 : else
513 : throw uno::RuntimeException("No edit source, object is defunct",
514 : uno::Reference< uno::XInterface >
515 : ( static_cast< ::cppu::OWeakObject* >
516 3 : ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy
517 : }
518 :
519 355 : SvxAccessibleTextAdapter& AccessibleEditableTextPara::GetTextForwarder() const SAL_THROW((uno::RuntimeException))
520 : {
521 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
522 :
523 355 : SvxEditSourceAdapter& rEditSource = GetEditSource();
524 352 : SvxAccessibleTextAdapter* pTextForwarder = rEditSource.GetTextForwarderAdapter();
525 :
526 352 : if( !pTextForwarder )
527 : throw uno::RuntimeException("Unable to fetch text forwarder, object is defunct",
528 : uno::Reference< uno::XInterface >
529 : ( static_cast< ::cppu::OWeakObject* >
530 0 : ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy
531 :
532 352 : if( pTextForwarder->IsValid() )
533 704 : return *pTextForwarder;
534 : else
535 : throw uno::RuntimeException("Text forwarder is invalid, object is defunct",
536 : uno::Reference< uno::XInterface >
537 : ( static_cast< ::cppu::OWeakObject* >
538 0 : ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy
539 : }
540 :
541 93 : SvxViewForwarder& AccessibleEditableTextPara::GetViewForwarder() const SAL_THROW((uno::RuntimeException))
542 : {
543 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
544 :
545 93 : SvxEditSource& rEditSource = GetEditSource();
546 93 : SvxViewForwarder* pViewForwarder = rEditSource.GetViewForwarder();
547 :
548 93 : if( !pViewForwarder )
549 : {
550 : throw uno::RuntimeException("Unable to fetch view forwarder, object is defunct",
551 : uno::Reference< uno::XInterface >
552 : ( static_cast< ::cppu::OWeakObject* >
553 0 : ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy
554 : }
555 :
556 93 : if( pViewForwarder->IsValid() )
557 186 : return *pViewForwarder;
558 : else
559 : throw uno::RuntimeException("View forwarder is invalid, object is defunct",
560 : uno::Reference< uno::XInterface >
561 : ( static_cast< ::cppu::OWeakObject* >
562 0 : ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy
563 : }
564 :
565 1 : SvxAccessibleTextEditViewAdapter& AccessibleEditableTextPara::GetEditViewForwarder( sal_Bool bCreate ) const SAL_THROW((uno::RuntimeException))
566 : {
567 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
568 :
569 1 : SvxEditSourceAdapter& rEditSource = GetEditSource();
570 1 : SvxAccessibleTextEditViewAdapter* pTextEditViewForwarder = rEditSource.GetEditViewForwarderAdapter( bCreate );
571 :
572 1 : if( !pTextEditViewForwarder )
573 : {
574 1 : if( bCreate )
575 : throw uno::RuntimeException("Unable to fetch view forwarder, object is defunct",
576 : uno::Reference< uno::XInterface >
577 : ( static_cast< ::cppu::OWeakObject* >
578 1 : ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy
579 : else
580 : throw uno::RuntimeException("No view forwarder, object not in edit mode",
581 : uno::Reference< uno::XInterface >
582 : ( static_cast< ::cppu::OWeakObject* >
583 0 : ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy
584 : }
585 :
586 0 : if( pTextEditViewForwarder->IsValid() )
587 0 : return *pTextEditViewForwarder;
588 : else
589 : {
590 0 : if( bCreate )
591 : throw uno::RuntimeException("View forwarder is invalid, object is defunct",
592 : uno::Reference< uno::XInterface >
593 : ( static_cast< ::cppu::OWeakObject* >
594 0 : ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy
595 : else
596 : throw uno::RuntimeException("View forwarder is invalid, object not in edit mode",
597 : uno::Reference< uno::XInterface >
598 : ( static_cast< ::cppu::OWeakObject* >
599 0 : ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy
600 : }
601 : }
602 :
603 0 : sal_Bool AccessibleEditableTextPara::HaveEditView() const
604 : {
605 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
606 :
607 0 : SvxEditSource& rEditSource = GetEditSource();
608 0 : SvxEditViewForwarder* pViewForwarder = rEditSource.GetEditViewForwarder();
609 :
610 0 : if( !pViewForwarder )
611 0 : return sal_False;
612 :
613 0 : if( !pViewForwarder->IsValid() )
614 0 : return sal_False;
615 :
616 0 : return sal_True;
617 : }
618 :
619 51 : sal_Bool AccessibleEditableTextPara::HaveChildren()
620 : {
621 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
622 :
623 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= SAL_MAX_INT32,
624 : "AccessibleEditableTextPara::HaveChildren: paragraph index value overflow");
625 :
626 51 : return GetTextForwarder().HaveImageBullet( GetParagraphIndex() );
627 : }
628 :
629 132 : Rectangle AccessibleEditableTextPara::LogicToPixel( const Rectangle& rRect, const MapMode& rMapMode, SvxViewForwarder& rForwarder )
630 : {
631 : // convert to screen coordinates
632 264 : return Rectangle( rForwarder.LogicToPixel( rRect.TopLeft(), rMapMode ),
633 396 : rForwarder.LogicToPixel( rRect.BottomRight(), rMapMode ) );
634 : }
635 :
636 93 : const Point& AccessibleEditableTextPara::GetEEOffset() const
637 : {
638 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
639 :
640 93 : return maEEOffset;
641 : }
642 :
643 35 : void AccessibleEditableTextPara::SetEEOffset( const Point& rOffset )
644 : {
645 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
646 :
647 35 : WeakBullet::HardRefType aChild( maImageBullet.get() );
648 35 : if( aChild.is() )
649 0 : aChild->SetEEOffset(rOffset);
650 :
651 35 : maEEOffset = rOffset;
652 35 : }
653 :
654 44 : void AccessibleEditableTextPara::FireEvent(const sal_Int16 nEventId, const uno::Any& rNewValue, const uno::Any& rOldValue) const
655 : {
656 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
657 :
658 44 : uno::Reference < XAccessibleContext > xThis( const_cast< AccessibleEditableTextPara* > (this)->getAccessibleContext() );
659 :
660 88 : AccessibleEventObject aEvent(xThis, nEventId, rNewValue, rOldValue);
661 :
662 : // #102261# Call global queue for focus events
663 44 : if( nEventId == AccessibleEventId::STATE_CHANGED )
664 18 : vcl::unohelper::NotifyAccessibleStateEventGlobally( aEvent );
665 :
666 : // #106234# Delegate to EventNotifier
667 44 : if( getNotifierClientId() != -1 )
668 36 : ::comphelper::AccessibleEventNotifier::addEvent( getNotifierClientId(),
669 80 : aEvent );
670 44 : }
671 :
672 12 : void AccessibleEditableTextPara::GotPropertyEvent( const uno::Any& rNewValue, const sal_Int16 nEventId ) const
673 : {
674 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
675 :
676 12 : FireEvent( nEventId, rNewValue );
677 12 : }
678 :
679 6 : void AccessibleEditableTextPara::LostPropertyEvent( const uno::Any& rOldValue, const sal_Int16 nEventId ) const
680 : {
681 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
682 :
683 6 : FireEvent( nEventId, uno::Any(), rOldValue );
684 6 : }
685 :
686 12 : void AccessibleEditableTextPara::SetState( const sal_Int16 nStateId )
687 : {
688 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
689 :
690 12 : ::utl::AccessibleStateSetHelper* pStateSet = static_cast< ::utl::AccessibleStateSetHelper*>(mxStateSet.get());
691 24 : if( pStateSet != NULL &&
692 12 : !pStateSet->contains(nStateId) )
693 : {
694 12 : pStateSet->AddState( nStateId );
695 12 : GotPropertyEvent( uno::makeAny( nStateId ), AccessibleEventId::STATE_CHANGED );
696 : }
697 12 : }
698 :
699 6 : void AccessibleEditableTextPara::UnSetState( const sal_Int16 nStateId )
700 : {
701 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
702 :
703 6 : ::utl::AccessibleStateSetHelper* pStateSet = static_cast< ::utl::AccessibleStateSetHelper*>(mxStateSet.get());
704 12 : if( pStateSet != NULL &&
705 6 : pStateSet->contains(nStateId) )
706 : {
707 6 : pStateSet->RemoveState( nStateId );
708 6 : LostPropertyEvent( uno::makeAny( nStateId ), AccessibleEventId::STATE_CHANGED );
709 : }
710 6 : }
711 :
712 33 : void AccessibleEditableTextPara::TextChanged()
713 : {
714 33 : OUString aCurrentString( OCommonAccessibleText::getText() );
715 60 : uno::Any aDeleted;
716 60 : uno::Any aInserted;
717 30 : if( OCommonAccessibleText::implInitTextChangedEvent( maLastTextString, aCurrentString,
718 30 : aDeleted, aInserted) )
719 : {
720 22 : FireEvent( AccessibleEventId::TEXT_CHANGED, aInserted, aDeleted );
721 22 : maLastTextString = aCurrentString;
722 30 : }
723 30 : }
724 :
725 0 : sal_Bool AccessibleEditableTextPara::GetAttributeRun( sal_uInt16& nStartIndex, sal_uInt16& nEndIndex, sal_Int32 nIndex )
726 : {
727 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
728 :
729 : DBG_ASSERT(nIndex >= 0 && nIndex <= USHRT_MAX,
730 : "AccessibleEditableTextPara::GetAttributeRun: index value overflow");
731 :
732 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= SAL_MAX_INT32,
733 : "AccessibleEditableTextPara::getLocale: paragraph index value overflow");
734 :
735 0 : return GetTextForwarder().GetAttributeRun( nStartIndex,
736 : nEndIndex,
737 : GetParagraphIndex(),
738 0 : static_cast< sal_uInt16 >(nIndex) );
739 : }
740 :
741 332 : uno::Any SAL_CALL AccessibleEditableTextPara::queryInterface (const uno::Type & rType) throw (uno::RuntimeException)
742 : {
743 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
744 :
745 332 : uno::Any aRet;
746 :
747 : // must provide XAccesibleText by hand, since it comes publicly inherited by XAccessibleEditableText
748 332 : if ( rType == ::getCppuType((uno::Reference< XAccessibleText > *)0) )
749 : {
750 1 : uno::Reference< XAccessibleText > aAccText = static_cast< XAccessibleEditableText * >(this);
751 1 : aRet <<= aAccText;
752 : }
753 331 : else if ( rType == ::getCppuType((uno::Reference< XAccessibleEditableText > *)0) )
754 : {
755 0 : uno::Reference< XAccessibleEditableText > aAccEditText = this;
756 0 : aRet <<= aAccEditText;
757 : }
758 331 : else if ( rType == ::getCppuType((uno::Reference< XAccessibleHypertext > *)0) )
759 : {
760 0 : uno::Reference< XAccessibleHypertext > aAccHyperText = this;
761 0 : aRet <<= aAccHyperText;
762 : }
763 : else
764 : {
765 331 : aRet = AccessibleTextParaInterfaceBase::queryInterface(rType);
766 : }
767 :
768 332 : return aRet;
769 : }
770 :
771 : // XAccessible
772 107 : uno::Reference< XAccessibleContext > SAL_CALL AccessibleEditableTextPara::getAccessibleContext() throw (uno::RuntimeException)
773 : {
774 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
775 :
776 : // We implement the XAccessibleContext interface in the same object
777 107 : return uno::Reference< XAccessibleContext > ( this );
778 : }
779 :
780 : // XAccessibleContext
781 51 : sal_Int32 SAL_CALL AccessibleEditableTextPara::getAccessibleChildCount() throw (uno::RuntimeException)
782 : {
783 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
784 :
785 51 : SolarMutexGuard aGuard;
786 :
787 51 : return HaveChildren() ? 1 : 0;
788 : }
789 :
790 0 : uno::Reference< XAccessible > SAL_CALL AccessibleEditableTextPara::getAccessibleChild( sal_Int32 i ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
791 : {
792 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
793 :
794 0 : SolarMutexGuard aGuard;
795 :
796 0 : if( !HaveChildren() )
797 : throw lang::IndexOutOfBoundsException("No children available",
798 : uno::Reference< uno::XInterface >
799 0 : ( static_cast< ::cppu::OWeakObject* > (this) ) ); // static_cast: disambiguate hierarchy
800 :
801 0 : if( i != 0 )
802 : throw lang::IndexOutOfBoundsException("Invalid child index",
803 : uno::Reference< uno::XInterface >
804 0 : ( static_cast< ::cppu::OWeakObject* > (this) ) ); // static_cast: disambiguate hierarchy
805 :
806 0 : WeakBullet::HardRefType aChild( maImageBullet.get() );
807 :
808 0 : if( !aChild.is() )
809 : {
810 : // there is no hard reference available, create object then
811 0 : AccessibleImageBullet* pChild = new AccessibleImageBullet( uno::Reference< XAccessible >( this ) );
812 0 : uno::Reference< XAccessible > xChild( static_cast< ::cppu::OWeakObject* > (pChild), uno::UNO_QUERY );
813 :
814 0 : if( !xChild.is() )
815 : throw uno::RuntimeException("Child creation failed",
816 : uno::Reference< uno::XInterface >
817 0 : ( static_cast< ::cppu::OWeakObject* > (this) ) );
818 :
819 0 : aChild = WeakBullet::HardRefType( xChild, pChild );
820 :
821 0 : aChild->SetEditSource( &GetEditSource() );
822 0 : aChild->SetParagraphIndex( GetParagraphIndex() );
823 0 : aChild->SetIndexInParent( i );
824 :
825 0 : maImageBullet = aChild;
826 : }
827 :
828 0 : return aChild.getRef();
829 : }
830 :
831 13 : uno::Reference< XAccessible > SAL_CALL AccessibleEditableTextPara::getAccessibleParent() throw (uno::RuntimeException)
832 : {
833 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
834 :
835 : #ifdef DBG_UTIL
836 : if( !mxParent.is() )
837 : OSL_TRACE( "AccessibleEditableTextPara::getAccessibleParent: no frontend set, did somebody forgot to call AccessibleTextHelper::SetEventSource()?");
838 : #endif
839 :
840 13 : return mxParent;
841 : }
842 :
843 6 : sal_Int32 SAL_CALL AccessibleEditableTextPara::getAccessibleIndexInParent() throw (uno::RuntimeException)
844 : {
845 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
846 :
847 6 : return mnIndexInParent;
848 : }
849 :
850 36 : sal_Int16 SAL_CALL AccessibleEditableTextPara::getAccessibleRole() throw (uno::RuntimeException)
851 : {
852 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
853 :
854 36 : return AccessibleRole::PARAGRAPH;
855 : }
856 :
857 14 : OUString SAL_CALL AccessibleEditableTextPara::getAccessibleDescription() throw (uno::RuntimeException)
858 : {
859 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
860 :
861 : // SolarMutexGuard aGuard;
862 :
863 14 : return OUString();
864 : }
865 :
866 16 : OUString SAL_CALL AccessibleEditableTextPara::getAccessibleName() throw (uno::RuntimeException)
867 : {
868 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
869 :
870 : // SolarMutexGuard aGuard;
871 :
872 16 : return OUString();
873 : }
874 :
875 1 : uno::Reference< XAccessibleRelationSet > SAL_CALL AccessibleEditableTextPara::getAccessibleRelationSet() throw (uno::RuntimeException)
876 : {
877 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
878 :
879 : // #i27138# - provide relations CONTENT_FLOWS_FROM
880 : // and CONTENT_FLOWS_TO
881 1 : if ( mpParaManager )
882 : {
883 : utl::AccessibleRelationSetHelper* pAccRelSetHelper =
884 1 : new utl::AccessibleRelationSetHelper();
885 1 : sal_Int32 nMyParaIndex( GetParagraphIndex() );
886 : // relation CONTENT_FLOWS_FROM
887 1 : if ( nMyParaIndex > 0 &&
888 0 : mpParaManager->IsReferencable( nMyParaIndex - 1 ) )
889 : {
890 0 : uno::Sequence<uno::Reference<XInterface> > aSequence(1);
891 0 : aSequence[0] =
892 0 : mpParaManager->GetChild( nMyParaIndex - 1 ).first.get().getRef();
893 : AccessibleRelation aAccRel( AccessibleRelationType::CONTENT_FLOWS_FROM,
894 0 : aSequence );
895 0 : pAccRelSetHelper->AddRelation( aAccRel );
896 : }
897 :
898 : // relation CONTENT_FLOWS_TO
899 1 : if ( (nMyParaIndex + 1) < (sal_Int32)mpParaManager->GetNum() &&
900 0 : mpParaManager->IsReferencable( nMyParaIndex + 1 ) )
901 : {
902 0 : uno::Sequence<uno::Reference<XInterface> > aSequence(1);
903 0 : aSequence[0] =
904 0 : mpParaManager->GetChild( nMyParaIndex + 1 ).first.get().getRef();
905 : AccessibleRelation aAccRel( AccessibleRelationType::CONTENT_FLOWS_TO,
906 0 : aSequence );
907 0 : pAccRelSetHelper->AddRelation( aAccRel );
908 : }
909 :
910 1 : return pAccRelSetHelper;
911 : }
912 : else
913 : {
914 : // no relations, therefore empty
915 0 : return uno::Reference< XAccessibleRelationSet >();
916 : }
917 : }
918 :
919 22 : uno::Reference< XAccessibleStateSet > SAL_CALL AccessibleEditableTextPara::getAccessibleStateSet() throw (uno::RuntimeException)
920 : {
921 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
922 :
923 22 : SolarMutexGuard aGuard;
924 :
925 : // Create a copy of the state set and return it.
926 22 : ::utl::AccessibleStateSetHelper* pStateSet = static_cast< ::utl::AccessibleStateSetHelper*>(mxStateSet.get());
927 :
928 22 : if( !pStateSet )
929 0 : return uno::Reference<XAccessibleStateSet>();
930 :
931 22 : return uno::Reference<XAccessibleStateSet>( new ::utl::AccessibleStateSetHelper (*pStateSet) );
932 : }
933 :
934 1 : lang::Locale SAL_CALL AccessibleEditableTextPara::getLocale() throw (IllegalAccessibleComponentStateException, uno::RuntimeException)
935 : {
936 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
937 :
938 1 : SolarMutexGuard aGuard;
939 :
940 1 : return implGetLocale();
941 : }
942 :
943 1 : void SAL_CALL AccessibleEditableTextPara::addAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) throw (uno::RuntimeException)
944 : {
945 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
946 :
947 1 : if( getNotifierClientId() != -1 )
948 1 : ::comphelper::AccessibleEventNotifier::addEventListener( getNotifierClientId(), xListener );
949 1 : }
950 :
951 2 : void SAL_CALL AccessibleEditableTextPara::removeAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) throw (uno::RuntimeException)
952 : {
953 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
954 :
955 2 : if( getNotifierClientId() != -1 )
956 0 : ::comphelper::AccessibleEventNotifier::removeEventListener( getNotifierClientId(), xListener );
957 2 : }
958 :
959 : // XAccessibleComponent
960 2 : sal_Bool SAL_CALL AccessibleEditableTextPara::containsPoint( const awt::Point& aTmpPoint ) throw (uno::RuntimeException)
961 : {
962 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
963 :
964 2 : SolarMutexGuard aGuard;
965 :
966 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= SAL_MAX_INT32,
967 : "AccessibleEditableTextPara::contains: index value overflow");
968 :
969 2 : awt::Rectangle aTmpRect = getBounds();
970 2 : Rectangle aRect( Point(aTmpRect.X, aTmpRect.Y), Size(aTmpRect.Width, aTmpRect.Height) );
971 2 : Point aPoint( aTmpPoint.X, aTmpPoint.Y );
972 :
973 2 : return aRect.IsInside( aPoint );
974 : }
975 :
976 0 : uno::Reference< XAccessible > SAL_CALL AccessibleEditableTextPara::getAccessibleAtPoint( const awt::Point& _aPoint ) throw (uno::RuntimeException)
977 : {
978 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
979 :
980 0 : SolarMutexGuard aGuard;
981 :
982 0 : if( HaveChildren() )
983 : {
984 : // #103862# No longer need to make given position relative
985 0 : Point aPoint( _aPoint.X, _aPoint.Y );
986 :
987 : // respect EditEngine offset to surrounding shape/cell
988 0 : aPoint -= GetEEOffset();
989 :
990 : // convert to EditEngine coordinate system
991 0 : SvxTextForwarder& rCacheTF = GetTextForwarder();
992 0 : Point aLogPoint( GetViewForwarder().PixelToLogic( aPoint, rCacheTF.GetMapMode() ) );
993 :
994 0 : EBulletInfo aBulletInfo = rCacheTF.GetBulletInfo( static_cast< sal_uInt16 > (GetParagraphIndex()) );
995 :
996 0 : if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND &&
997 0 : aBulletInfo.bVisible &&
998 0 : aBulletInfo.nType == SVX_NUM_BITMAP )
999 : {
1000 0 : Rectangle aRect = aBulletInfo.aBounds;
1001 :
1002 0 : if( aRect.IsInside( aLogPoint ) )
1003 0 : return getAccessibleChild(0);
1004 0 : }
1005 : }
1006 :
1007 : // no children at all, or none at given position
1008 0 : return uno::Reference< XAccessible >();
1009 : }
1010 :
1011 61 : awt::Rectangle SAL_CALL AccessibleEditableTextPara::getBounds() throw (uno::RuntimeException)
1012 : {
1013 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1014 :
1015 61 : SolarMutexGuard aGuard;
1016 :
1017 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= SAL_MAX_INT32,
1018 : "AccessibleEditableTextPara::getBounds: index value overflow");
1019 :
1020 61 : SvxTextForwarder& rCacheTF = GetTextForwarder();
1021 61 : Rectangle aRect = rCacheTF.GetParaBounds( GetParagraphIndex() );
1022 :
1023 : // convert to screen coordinates
1024 : Rectangle aScreenRect = AccessibleEditableTextPara::LogicToPixel( aRect,
1025 61 : rCacheTF.GetMapMode(),
1026 122 : GetViewForwarder() );
1027 :
1028 : // offset from shape/cell
1029 61 : Point aOffset = GetEEOffset();
1030 :
1031 61 : return awt::Rectangle( aScreenRect.Left() + aOffset.X(),
1032 61 : aScreenRect.Top() + aOffset.Y(),
1033 122 : aScreenRect.GetSize().Width(),
1034 244 : aScreenRect.GetSize().Height() );
1035 : }
1036 :
1037 0 : awt::Point SAL_CALL AccessibleEditableTextPara::getLocation( ) throw (uno::RuntimeException)
1038 : {
1039 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1040 :
1041 0 : SolarMutexGuard aGuard;
1042 :
1043 0 : awt::Rectangle aRect = getBounds();
1044 :
1045 0 : return awt::Point( aRect.X, aRect.Y );
1046 : }
1047 :
1048 0 : awt::Point SAL_CALL AccessibleEditableTextPara::getLocationOnScreen( ) throw (uno::RuntimeException)
1049 : {
1050 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1051 :
1052 0 : SolarMutexGuard aGuard;
1053 :
1054 : // relate us to parent
1055 0 : uno::Reference< XAccessible > xParent = getAccessibleParent();
1056 0 : if( xParent.is() )
1057 : {
1058 0 : uno::Reference< XAccessibleComponent > xParentComponent( xParent, uno::UNO_QUERY );
1059 0 : if( xParentComponent.is() )
1060 : {
1061 0 : awt::Point aRefPoint = xParentComponent->getLocationOnScreen();
1062 0 : awt::Point aPoint = getLocation();
1063 0 : aPoint.X += aRefPoint.X;
1064 0 : aPoint.Y += aRefPoint.Y;
1065 :
1066 0 : return aPoint;
1067 : }
1068 : // #i88070#
1069 : // fallback to parent's <XAccessibleContext> instance
1070 : else
1071 : {
1072 0 : uno::Reference< XAccessibleContext > xParentContext = xParent->getAccessibleContext();
1073 0 : if ( xParentContext.is() )
1074 : {
1075 0 : uno::Reference< XAccessibleComponent > xParentContextComponent( xParentContext, uno::UNO_QUERY );
1076 0 : if( xParentContextComponent.is() )
1077 : {
1078 0 : awt::Point aRefPoint = xParentContextComponent->getLocationOnScreen();
1079 0 : awt::Point aPoint = getLocation();
1080 0 : aPoint.X += aRefPoint.X;
1081 0 : aPoint.Y += aRefPoint.Y;
1082 :
1083 0 : return aPoint;
1084 0 : }
1085 0 : }
1086 0 : }
1087 : }
1088 :
1089 : throw uno::RuntimeException("Cannot access parent",
1090 : uno::Reference< uno::XInterface >
1091 0 : ( static_cast< XAccessible* > (this) ) ); // disambiguate hierarchy
1092 : }
1093 :
1094 0 : awt::Size SAL_CALL AccessibleEditableTextPara::getSize( ) throw (uno::RuntimeException)
1095 : {
1096 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1097 :
1098 0 : SolarMutexGuard aGuard;
1099 :
1100 0 : awt::Rectangle aRect = getBounds();
1101 :
1102 0 : return awt::Size( aRect.Width, aRect.Height );
1103 : }
1104 :
1105 0 : void SAL_CALL AccessibleEditableTextPara::grabFocus( ) throw (uno::RuntimeException)
1106 : {
1107 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1108 :
1109 : // set cursor to this paragraph
1110 0 : setSelection(0,0);
1111 0 : }
1112 :
1113 0 : sal_Int32 SAL_CALL AccessibleEditableTextPara::getForeground( ) throw (::com::sun::star::uno::RuntimeException)
1114 : {
1115 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1116 :
1117 : // #104444# Added to XAccessibleComponent interface
1118 0 : svtools::ColorConfig aColorConfig;
1119 0 : sal_uInt32 nColor = aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor;
1120 0 : return static_cast<sal_Int32>(nColor);
1121 : }
1122 :
1123 0 : sal_Int32 SAL_CALL AccessibleEditableTextPara::getBackground( ) throw (::com::sun::star::uno::RuntimeException)
1124 : {
1125 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1126 :
1127 : // #104444# Added to XAccessibleComponent interface
1128 0 : Color aColor( Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor() );
1129 :
1130 : // the background is transparent
1131 0 : aColor.SetTransparency( 0xFF);
1132 :
1133 0 : return static_cast<sal_Int32>( aColor.GetColor() );
1134 : }
1135 :
1136 : // XAccessibleText
1137 0 : sal_Int32 SAL_CALL AccessibleEditableTextPara::getCaretPosition() throw (uno::RuntimeException)
1138 : {
1139 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1140 :
1141 0 : SolarMutexGuard aGuard;
1142 :
1143 0 : if( !HaveEditView() )
1144 0 : return -1;
1145 :
1146 0 : ESelection aSelection;
1147 0 : if( GetEditViewForwarder().GetSelection( aSelection ) &&
1148 0 : GetParagraphIndex() == aSelection.nEndPara )
1149 : {
1150 : // caret is always nEndPara,nEndPos
1151 0 : return aSelection.nEndPos;
1152 : }
1153 :
1154 : // not within this paragraph
1155 0 : return -1;
1156 : }
1157 :
1158 3 : sal_Bool SAL_CALL AccessibleEditableTextPara::setCaretPosition( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1159 : {
1160 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1161 :
1162 3 : return setSelection(nIndex, nIndex);
1163 : }
1164 :
1165 7 : sal_Unicode SAL_CALL AccessibleEditableTextPara::getCharacter( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1166 : {
1167 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1168 :
1169 7 : SolarMutexGuard aGuard;
1170 :
1171 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1172 : "AccessibleEditableTextPara::getCharacter: index value overflow");
1173 :
1174 7 : return OCommonAccessibleText::getCharacter( nIndex );
1175 : }
1176 :
1177 3 : uno::Sequence< beans::PropertyValue > SAL_CALL AccessibleEditableTextPara::getCharacterAttributes( sal_Int32 nIndex, const ::com::sun::star::uno::Sequence< OUString >& rRequestedAttributes ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1178 : {
1179 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1180 3 : SolarMutexGuard aGuard;
1181 :
1182 3 : CheckIndex(nIndex); // may throw IndexOutOfBoundsException
1183 :
1184 : // get default attribues...
1185 2 : ::comphelper::SequenceAsHashMap aPropHashMap( getDefaultAttributes( rRequestedAttributes ) );
1186 :
1187 : // ... and override them with the direct attributes from the specific position
1188 2 : uno::Sequence< beans::PropertyValue > aRunAttribs( getRunAttributes( nIndex, rRequestedAttributes ) );
1189 1 : sal_Int32 nRunAttribs = aRunAttribs.getLength();
1190 1 : const beans::PropertyValue *pRunAttrib = aRunAttribs.getConstArray();
1191 1 : for (sal_Int32 k = 0; k < nRunAttribs; ++k)
1192 : {
1193 0 : const beans::PropertyValue &rRunAttrib = pRunAttrib[k];
1194 0 : aPropHashMap[ rRunAttrib.Name ] = rRunAttrib.Value; //!! should not only be the value !!
1195 : }
1196 :
1197 : // get resulting sequence
1198 1 : uno::Sequence< beans::PropertyValue > aRes;
1199 1 : aPropHashMap >> aRes;
1200 :
1201 : // since SequenceAsHashMap ignores property handles and property state
1202 : // we have to restore the property state here (property handles are
1203 : // of no use to the accessibility API).
1204 1 : sal_Int32 nRes = aRes.getLength();
1205 1 : beans::PropertyValue *pRes = aRes.getArray();
1206 1 : for (sal_Int32 i = 0; i < nRes; ++i)
1207 : {
1208 0 : beans::PropertyValue &rRes = pRes[i];
1209 0 : sal_Bool bIsDirectVal = sal_False;
1210 0 : for (sal_Int32 k = 0; k < nRunAttribs && !bIsDirectVal; ++k)
1211 : {
1212 0 : if (rRes.Name == pRunAttrib[k].Name)
1213 0 : bIsDirectVal = sal_True;
1214 : }
1215 0 : rRes.Handle = -1;
1216 0 : rRes.State = bIsDirectVal ? PropertyState_DIRECT_VALUE : PropertyState_DEFAULT_VALUE;
1217 : }
1218 :
1219 4 : return aRes;
1220 : }
1221 :
1222 23 : awt::Rectangle SAL_CALL AccessibleEditableTextPara::getCharacterBounds( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1223 : {
1224 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1225 :
1226 23 : SolarMutexGuard aGuard;
1227 :
1228 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1229 : "AccessibleEditableTextPara::getCharacterBounds: index value overflow");
1230 :
1231 : // #108900# Have position semantics now for nIndex, as
1232 : // one-past-the-end values are legal, too.
1233 23 : CheckPosition( nIndex );
1234 :
1235 21 : SvxTextForwarder& rCacheTF = GetTextForwarder();
1236 21 : Rectangle aRect = rCacheTF.GetCharBounds( static_cast< sal_uInt16 >( GetParagraphIndex() ), static_cast< sal_uInt16 >( nIndex ) );
1237 :
1238 : // convert to screen
1239 : Rectangle aScreenRect = AccessibleEditableTextPara::LogicToPixel( aRect,
1240 21 : rCacheTF.GetMapMode(),
1241 42 : GetViewForwarder() );
1242 : // #109864# offset from parent (paragraph), but in screen
1243 : // coordinates. This makes sure the internal text offset in
1244 : // the outline view forwarder gets cancelled out here
1245 21 : awt::Rectangle aParaRect( getBounds() );
1246 21 : aScreenRect.Move( -aParaRect.X, -aParaRect.Y );
1247 :
1248 : // offset from shape/cell
1249 21 : Point aOffset = GetEEOffset();
1250 :
1251 21 : return awt::Rectangle( aScreenRect.Left() + aOffset.X(),
1252 21 : aScreenRect.Top() + aOffset.Y(),
1253 42 : aScreenRect.GetSize().Width(),
1254 86 : aScreenRect.GetSize().Height() );
1255 : }
1256 :
1257 29 : sal_Int32 SAL_CALL AccessibleEditableTextPara::getCharacterCount() throw (uno::RuntimeException)
1258 : {
1259 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1260 :
1261 29 : SolarMutexGuard aGuard;
1262 :
1263 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1264 : "AccessibleEditableTextPara::getCharacterCount: index value overflow");
1265 :
1266 29 : return OCommonAccessibleText::getCharacterCount();
1267 : }
1268 :
1269 11 : sal_Int32 SAL_CALL AccessibleEditableTextPara::getIndexAtPoint( const awt::Point& rPoint ) throw (uno::RuntimeException)
1270 : {
1271 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1272 :
1273 11 : SolarMutexGuard aGuard;
1274 :
1275 : sal_Int32 nPara;
1276 : sal_uInt16 nIndex;
1277 :
1278 : // offset from surrounding cell/shape
1279 11 : Point aOffset( GetEEOffset() );
1280 11 : Point aPoint( rPoint.X - aOffset.X(), rPoint.Y - aOffset.Y() );
1281 :
1282 : // convert to logical coordinates
1283 11 : SvxTextForwarder& rCacheTF = GetTextForwarder();
1284 11 : Point aLogPoint( GetViewForwarder().PixelToLogic( aPoint, rCacheTF.GetMapMode() ) );
1285 :
1286 : // re-offset to parent (paragraph)
1287 11 : Rectangle aParaRect = rCacheTF.GetParaBounds( GetParagraphIndex() );
1288 11 : aLogPoint.Move( aParaRect.Left(), aParaRect.Top() );
1289 :
1290 22 : if( rCacheTF.GetIndexAtPoint( aLogPoint, nPara, nIndex ) &&
1291 11 : GetParagraphIndex() == nPara )
1292 : {
1293 : // #102259# Double-check if we're _really_ on the given character
1294 : try
1295 : {
1296 11 : awt::Rectangle aRect1( getCharacterBounds(nIndex) );
1297 : Rectangle aRect2( aRect1.X, aRect1.Y,
1298 11 : aRect1.Width + aRect1.X, aRect1.Height + aRect1.Y );
1299 11 : if( aRect2.IsInside( Point( rPoint.X, rPoint.Y ) ) )
1300 10 : return nIndex;
1301 : else
1302 1 : return -1;
1303 : }
1304 0 : catch (const lang::IndexOutOfBoundsException&)
1305 : {
1306 : // #103927# Don't throw for invalid nIndex values
1307 0 : return -1;
1308 : }
1309 : }
1310 : else
1311 : {
1312 : // not within our paragraph
1313 0 : return -1;
1314 11 : }
1315 : }
1316 :
1317 0 : OUString SAL_CALL AccessibleEditableTextPara::getSelectedText() throw (uno::RuntimeException)
1318 : {
1319 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1320 :
1321 0 : SolarMutexGuard aGuard;
1322 :
1323 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1324 : "AccessibleEditableTextPara::getSelectedText: index value overflow");
1325 :
1326 0 : if( !HaveEditView() )
1327 0 : return OUString();
1328 :
1329 0 : return OCommonAccessibleText::getSelectedText();
1330 : }
1331 :
1332 0 : sal_Int32 SAL_CALL AccessibleEditableTextPara::getSelectionStart() throw (uno::RuntimeException)
1333 : {
1334 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1335 :
1336 0 : SolarMutexGuard aGuard;
1337 :
1338 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1339 : "AccessibleEditableTextPara::getSelectionStart: index value overflow");
1340 :
1341 0 : if( !HaveEditView() )
1342 0 : return -1;
1343 :
1344 0 : return OCommonAccessibleText::getSelectionStart();
1345 : }
1346 :
1347 0 : sal_Int32 SAL_CALL AccessibleEditableTextPara::getSelectionEnd() throw (uno::RuntimeException)
1348 : {
1349 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1350 :
1351 0 : SolarMutexGuard aGuard;
1352 :
1353 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1354 : "AccessibleEditableTextPara::getSelectionEnd: index value overflow");
1355 :
1356 0 : if( !HaveEditView() )
1357 0 : return -1;
1358 :
1359 0 : return OCommonAccessibleText::getSelectionEnd();
1360 : }
1361 :
1362 3 : sal_Bool SAL_CALL AccessibleEditableTextPara::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1363 : {
1364 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1365 :
1366 3 : SolarMutexGuard aGuard;
1367 :
1368 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1369 : "AccessibleEditableTextPara::setSelection: paragraph index value overflow");
1370 :
1371 3 : CheckRange(nStartIndex, nEndIndex);
1372 :
1373 : try
1374 : {
1375 1 : SvxEditViewForwarder& rCacheVF = GetEditViewForwarder( sal_True );
1376 0 : return rCacheVF.SetSelection( MakeSelection(nStartIndex, nEndIndex) );
1377 : }
1378 2 : catch (const uno::RuntimeException&)
1379 : {
1380 1 : return sal_False;
1381 3 : }
1382 : }
1383 :
1384 2 : OUString SAL_CALL AccessibleEditableTextPara::getText() throw (uno::RuntimeException)
1385 : {
1386 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1387 :
1388 2 : SolarMutexGuard aGuard;
1389 :
1390 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1391 : "AccessibleEditableTextPara::getText: paragraph index value overflow");
1392 :
1393 2 : return OCommonAccessibleText::getText();
1394 : }
1395 :
1396 7 : OUString SAL_CALL AccessibleEditableTextPara::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1397 : {
1398 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1399 :
1400 7 : SolarMutexGuard aGuard;
1401 :
1402 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1403 : "AccessibleEditableTextPara::getTextRange: paragraph index value overflow");
1404 :
1405 7 : return OCommonAccessibleText::getTextRange(nStartIndex, nEndIndex);
1406 : }
1407 :
1408 9 : ::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)
1409 : {
1410 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1411 :
1412 9 : SolarMutexGuard aGuard;
1413 :
1414 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1415 : "AccessibleEditableTextPara::getTextAtIndex: paragraph index value overflow");
1416 :
1417 9 : ::com::sun::star::accessibility::TextSegment aResult;
1418 9 : aResult.SegmentStart = -1;
1419 9 : aResult.SegmentEnd = -1;
1420 :
1421 9 : switch( aTextType )
1422 : {
1423 : // Not yet handled by OCommonAccessibleText. Missing
1424 : // implGetAttributeRunBoundary() method there
1425 : case AccessibleTextType::ATTRIBUTE_RUN:
1426 : {
1427 0 : const sal_Int32 nTextLen = GetTextForwarder().GetTextLen( GetParagraphIndex() );
1428 :
1429 0 : if( nIndex == nTextLen )
1430 : {
1431 : // #i17014# Special-casing one-behind-the-end character
1432 0 : aResult.SegmentStart = aResult.SegmentEnd = nTextLen;
1433 : }
1434 : else
1435 : {
1436 : sal_uInt16 nStartIndex, nEndIndex;
1437 :
1438 0 : if( GetAttributeRun(nStartIndex, nEndIndex, nIndex) )
1439 : {
1440 0 : aResult.SegmentText = GetTextRange(nStartIndex, nEndIndex);
1441 0 : aResult.SegmentStart = nStartIndex;
1442 0 : aResult.SegmentEnd = nEndIndex;
1443 : }
1444 : }
1445 0 : break;
1446 : }
1447 :
1448 : default:
1449 9 : aResult = OCommonAccessibleText::getTextAtIndex( nIndex, aTextType );
1450 7 : break;
1451 : } /* end of switch( aTextType ) */
1452 :
1453 9 : return aResult;
1454 : }
1455 :
1456 6 : ::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)
1457 : {
1458 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1459 :
1460 6 : SolarMutexGuard aGuard;
1461 :
1462 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1463 : "AccessibleEditableTextPara::getTextBeforeIndex: paragraph index value overflow");
1464 :
1465 6 : ::com::sun::star::accessibility::TextSegment aResult;
1466 6 : aResult.SegmentStart = -1;
1467 6 : aResult.SegmentEnd = -1;
1468 :
1469 6 : switch( aTextType )
1470 : {
1471 : // Not yet handled by OCommonAccessibleText. Missing
1472 : // implGetAttributeRunBoundary() method there
1473 : case AccessibleTextType::ATTRIBUTE_RUN:
1474 : {
1475 0 : const sal_Int32 nTextLen = GetTextForwarder().GetTextLen( GetParagraphIndex() );
1476 : sal_uInt16 nStartIndex, nEndIndex;
1477 :
1478 0 : if( nIndex == nTextLen )
1479 : {
1480 : // #i17014# Special-casing one-behind-the-end character
1481 0 : if( nIndex > 0 &&
1482 0 : GetAttributeRun(nStartIndex, nEndIndex, nIndex-1) )
1483 : {
1484 0 : aResult.SegmentText = GetTextRange(nStartIndex, nEndIndex);
1485 0 : aResult.SegmentStart = nStartIndex;
1486 0 : aResult.SegmentEnd = nEndIndex;
1487 : }
1488 : }
1489 : else
1490 : {
1491 0 : if( GetAttributeRun(nStartIndex, nEndIndex, nIndex) )
1492 : {
1493 : // already at the left border? If not, query
1494 : // one index further left
1495 0 : if( nStartIndex > 0 &&
1496 0 : GetAttributeRun(nStartIndex, nEndIndex, nStartIndex-1) )
1497 : {
1498 0 : aResult.SegmentText = GetTextRange(nStartIndex, nEndIndex);
1499 0 : aResult.SegmentStart = nStartIndex;
1500 0 : aResult.SegmentEnd = nEndIndex;
1501 : }
1502 : }
1503 : }
1504 0 : break;
1505 : }
1506 :
1507 : default:
1508 6 : aResult = OCommonAccessibleText::getTextBeforeIndex( nIndex, aTextType );
1509 4 : break;
1510 : } /* end of switch( aTextType ) */
1511 :
1512 6 : return aResult;
1513 : }
1514 :
1515 6 : ::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)
1516 : {
1517 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1518 :
1519 6 : SolarMutexGuard aGuard;
1520 :
1521 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1522 : "AccessibleEditableTextPara::getTextBehindIndex: paragraph index value overflow");
1523 :
1524 6 : ::com::sun::star::accessibility::TextSegment aResult;
1525 6 : aResult.SegmentStart = -1;
1526 6 : aResult.SegmentEnd = -1;
1527 :
1528 6 : switch( aTextType )
1529 : {
1530 : case AccessibleTextType::ATTRIBUTE_RUN:
1531 : {
1532 : sal_uInt16 nStartIndex, nEndIndex;
1533 :
1534 0 : if( GetAttributeRun(nStartIndex, nEndIndex, nIndex) )
1535 : {
1536 : // already at the right border?
1537 0 : if( nEndIndex < GetTextLen() )
1538 : {
1539 0 : if( GetAttributeRun(nStartIndex, nEndIndex, nEndIndex) )
1540 : {
1541 0 : aResult.SegmentText = GetTextRange(nStartIndex, nEndIndex);
1542 0 : aResult.SegmentStart = nStartIndex;
1543 0 : aResult.SegmentEnd = nEndIndex;
1544 : }
1545 : }
1546 : }
1547 0 : break;
1548 : }
1549 :
1550 : default:
1551 6 : aResult = OCommonAccessibleText::getTextBehindIndex( nIndex, aTextType );
1552 4 : break;
1553 : } /* end of switch( aTextType ) */
1554 :
1555 6 : return aResult;
1556 : }
1557 :
1558 0 : sal_Bool SAL_CALL AccessibleEditableTextPara::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1559 : {
1560 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1561 :
1562 0 : SolarMutexGuard aGuard;
1563 :
1564 : try
1565 : {
1566 0 : SvxEditViewForwarder& rCacheVF = GetEditViewForwarder( sal_True );
1567 : #if OSL_DEBUG_LEVEL > 0
1568 : SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder(); // MUST be after GetEditViewForwarder(), see method docs
1569 : (void)rCacheTF;
1570 : #else
1571 0 : GetTextForwarder(); // MUST be after GetEditViewForwarder(), see method docs
1572 : #endif
1573 :
1574 : sal_Bool aRetVal;
1575 :
1576 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1577 : "AccessibleEditableTextPara::copyText: index value overflow");
1578 :
1579 0 : CheckRange(nStartIndex, nEndIndex);
1580 :
1581 : // save current selection
1582 0 : ESelection aOldSelection;
1583 :
1584 0 : rCacheVF.GetSelection( aOldSelection );
1585 0 : rCacheVF.SetSelection( MakeSelection(nStartIndex, nEndIndex) );
1586 0 : aRetVal = rCacheVF.Copy();
1587 0 : rCacheVF.SetSelection( aOldSelection ); // restore
1588 :
1589 0 : return aRetVal;
1590 : }
1591 0 : catch (const uno::RuntimeException&)
1592 : {
1593 0 : return sal_False;
1594 0 : }
1595 : }
1596 :
1597 : // XAccessibleEditableText
1598 0 : sal_Bool SAL_CALL AccessibleEditableTextPara::cutText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1599 : {
1600 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1601 :
1602 0 : SolarMutexGuard aGuard;
1603 :
1604 : try
1605 : {
1606 0 : SvxEditViewForwarder& rCacheVF = GetEditViewForwarder( sal_True );
1607 0 : SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder(); // MUST be after GetEditViewForwarder(), see method docs
1608 :
1609 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1610 : "AccessibleEditableTextPara::cutText: index value overflow");
1611 :
1612 0 : CheckRange(nStartIndex, nEndIndex);
1613 :
1614 0 : if( !rCacheTF.IsEditable( MakeSelection(nStartIndex, nEndIndex) ) )
1615 0 : return sal_False; // non-editable area selected
1616 :
1617 : // don't save selection, might become invalid after cut!
1618 0 : rCacheVF.SetSelection( MakeSelection(nStartIndex, nEndIndex) );
1619 :
1620 0 : return rCacheVF.Cut();
1621 : }
1622 0 : catch (const uno::RuntimeException&)
1623 : {
1624 0 : return sal_False;
1625 0 : }
1626 : }
1627 :
1628 0 : sal_Bool SAL_CALL AccessibleEditableTextPara::pasteText( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1629 : {
1630 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1631 :
1632 0 : SolarMutexGuard aGuard;
1633 :
1634 : try
1635 : {
1636 0 : SvxEditViewForwarder& rCacheVF = GetEditViewForwarder( sal_True );
1637 0 : SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder(); // MUST be after GetEditViewForwarder(), see method docs
1638 :
1639 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1640 : "AccessibleEditableTextPara::pasteText: index value overflow");
1641 :
1642 0 : CheckPosition(nIndex);
1643 :
1644 0 : if( !rCacheTF.IsEditable( MakeSelection(nIndex) ) )
1645 0 : return sal_False; // non-editable area selected
1646 :
1647 : // #104400# set empty selection (=> cursor) to given index
1648 0 : rCacheVF.SetSelection( MakeCursor(nIndex) );
1649 :
1650 0 : return rCacheVF.Paste();
1651 : }
1652 0 : catch (const uno::RuntimeException&)
1653 : {
1654 0 : return sal_False;
1655 0 : }
1656 : }
1657 :
1658 0 : sal_Bool SAL_CALL AccessibleEditableTextPara::deleteText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1659 : {
1660 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1661 :
1662 0 : SolarMutexGuard aGuard;
1663 :
1664 : try
1665 : {
1666 : // #102710# Request edit view when doing changes
1667 : // AccessibleEmptyEditSource relies on this behaviour
1668 0 : GetEditViewForwarder( sal_True );
1669 0 : SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder(); // MUST be after GetEditViewForwarder(), see method docs
1670 :
1671 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1672 : "AccessibleEditableTextPara::deleteText: index value overflow");
1673 :
1674 0 : CheckRange(nStartIndex, nEndIndex);
1675 :
1676 0 : if( !rCacheTF.IsEditable( MakeSelection(nStartIndex, nEndIndex) ) )
1677 0 : return sal_False; // non-editable area selected
1678 :
1679 0 : sal_Bool bRet = rCacheTF.Delete( MakeSelection(nStartIndex, nEndIndex) );
1680 :
1681 0 : GetEditSource().UpdateData();
1682 :
1683 0 : return bRet;
1684 : }
1685 0 : catch (const uno::RuntimeException&)
1686 : {
1687 0 : return sal_False;
1688 0 : }
1689 : }
1690 :
1691 0 : sal_Bool SAL_CALL AccessibleEditableTextPara::insertText( const OUString& sText, sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1692 : {
1693 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1694 :
1695 0 : SolarMutexGuard aGuard;
1696 :
1697 : try
1698 : {
1699 : // #102710# Request edit view when doing changes
1700 : // AccessibleEmptyEditSource relies on this behaviour
1701 0 : GetEditViewForwarder( sal_True );
1702 0 : SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder(); // MUST be after GetEditViewForwarder(), see method docs
1703 :
1704 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1705 : "AccessibleEditableTextPara::insertText: index value overflow");
1706 :
1707 0 : CheckPosition(nIndex);
1708 :
1709 0 : if( !rCacheTF.IsEditable( MakeSelection(nIndex) ) )
1710 0 : return sal_False; // non-editable area selected
1711 :
1712 : // #104400# insert given text at empty selection (=> cursor)
1713 0 : sal_Bool bRet = rCacheTF.InsertText( sText, MakeCursor(nIndex) );
1714 :
1715 0 : rCacheTF.QuickFormatDoc();
1716 0 : GetEditSource().UpdateData();
1717 :
1718 0 : return bRet;
1719 : }
1720 0 : catch (const uno::RuntimeException&)
1721 : {
1722 0 : return sal_False;
1723 0 : }
1724 : }
1725 :
1726 0 : sal_Bool SAL_CALL AccessibleEditableTextPara::replaceText( sal_Int32 nStartIndex, sal_Int32 nEndIndex, const OUString& sReplacement ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1727 : {
1728 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1729 :
1730 0 : SolarMutexGuard aGuard;
1731 :
1732 : try
1733 : {
1734 : // #102710# Request edit view when doing changes
1735 : // AccessibleEmptyEditSource relies on this behaviour
1736 0 : GetEditViewForwarder( sal_True );
1737 0 : SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder(); // MUST be after GetEditViewForwarder(), see method docs
1738 :
1739 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1740 : "AccessibleEditableTextPara::replaceText: index value overflow");
1741 :
1742 0 : CheckRange(nStartIndex, nEndIndex);
1743 :
1744 0 : if( !rCacheTF.IsEditable( MakeSelection(nStartIndex, nEndIndex) ) )
1745 0 : return sal_False; // non-editable area selected
1746 :
1747 : // insert given text into given range => replace
1748 0 : sal_Bool bRet = rCacheTF.InsertText( sReplacement, MakeSelection(nStartIndex, nEndIndex) );
1749 :
1750 0 : rCacheTF.QuickFormatDoc();
1751 0 : GetEditSource().UpdateData();
1752 :
1753 0 : return bRet;
1754 : }
1755 0 : catch (const uno::RuntimeException&)
1756 : {
1757 0 : return sal_False;
1758 0 : }
1759 : }
1760 :
1761 0 : sal_Bool SAL_CALL AccessibleEditableTextPara::setAttributes( sal_Int32 nStartIndex, sal_Int32 nEndIndex, const uno::Sequence< beans::PropertyValue >& aAttributeSet ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1762 : {
1763 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1764 :
1765 0 : SolarMutexGuard aGuard;
1766 :
1767 : try
1768 : {
1769 : // #102710# Request edit view when doing changes
1770 : // AccessibleEmptyEditSource relies on this behaviour
1771 0 : GetEditViewForwarder( sal_True );
1772 0 : SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder(); // MUST be after GetEditViewForwarder(), see method docs
1773 0 : sal_uInt16 nPara = static_cast< sal_uInt16 >( GetParagraphIndex() );
1774 :
1775 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1776 : "AccessibleEditableTextPara::setAttributes: index value overflow");
1777 :
1778 0 : CheckRange(nStartIndex, nEndIndex);
1779 :
1780 0 : if( !rCacheTF.IsEditable( MakeSelection(nStartIndex, nEndIndex) ) )
1781 0 : return sal_False; // non-editable area selected
1782 :
1783 : // do the indices span the whole paragraph? Then use the outliner map
1784 : // TODO: hold it as a member?
1785 0 : SvxAccessibleTextPropertySet aPropSet( &GetEditSource(),
1786 0 : 0 == nStartIndex &&
1787 0 : rCacheTF.GetTextLen(nPara) == nEndIndex ?
1788 : ImplGetSvxUnoOutlinerTextCursorSvxPropertySet() :
1789 0 : ImplGetSvxTextPortionSvxPropertySet() );
1790 :
1791 0 : aPropSet.SetSelection( MakeSelection(nStartIndex, nEndIndex) );
1792 :
1793 : // convert from PropertyValue to Any
1794 0 : sal_Int32 i, nLength( aAttributeSet.getLength() );
1795 0 : const beans::PropertyValue* pPropArray = aAttributeSet.getConstArray();
1796 0 : for(i=0; i<nLength; ++i)
1797 : {
1798 : try
1799 : {
1800 0 : aPropSet.setPropertyValue(pPropArray->Name, pPropArray->Value);
1801 : }
1802 0 : catch (const uno::Exception&)
1803 : {
1804 : OSL_FAIL("AccessibleEditableTextPara::setAttributes exception in setPropertyValue");
1805 : }
1806 :
1807 0 : ++pPropArray;
1808 : }
1809 :
1810 0 : rCacheTF.QuickFormatDoc();
1811 0 : GetEditSource().UpdateData();
1812 :
1813 0 : return sal_True;
1814 : }
1815 0 : catch (const uno::RuntimeException&)
1816 : {
1817 0 : return sal_False;
1818 0 : }
1819 : }
1820 :
1821 0 : sal_Bool SAL_CALL AccessibleEditableTextPara::setText( const OUString& sText ) throw (uno::RuntimeException)
1822 : {
1823 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1824 :
1825 0 : SolarMutexGuard aGuard;
1826 :
1827 0 : return replaceText(0, getCharacterCount(), sText);
1828 : }
1829 :
1830 : // XAccessibleTextAttributes
1831 1 : uno::Sequence< beans::PropertyValue > SAL_CALL AccessibleEditableTextPara::getDefaultAttributes(
1832 : const uno::Sequence< OUString >& rRequestedAttributes )
1833 : throw (uno::RuntimeException)
1834 : {
1835 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1836 1 : SolarMutexGuard aGuard;
1837 :
1838 : #if OSL_DEBUG_LEVEL > 0
1839 : SvxAccessibleTextAdapter& rCacheTF =
1840 : #endif
1841 1 : GetTextForwarder();
1842 :
1843 : #if OSL_DEBUG_LEVEL > 0
1844 : (void)rCacheTF;
1845 : #endif
1846 :
1847 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1848 : "AccessibleEditableTextPara::getCharacterAttributes: index value overflow");
1849 :
1850 : // get XPropertySetInfo for paragraph attributes and
1851 : // character attributes that span all the paragraphs text.
1852 1 : SvxAccessibleTextPropertySet aPropSet( &GetEditSource(),
1853 3 : ImplGetSvxCharAndParaPropertiesSet() );
1854 1 : aPropSet.SetSelection( MakeSelection( 0, GetTextLen() ) );
1855 2 : uno::Reference< beans::XPropertySetInfo > xPropSetInfo = aPropSet.getPropertySetInfo();
1856 1 : if (!xPropSetInfo.is())
1857 : throw uno::RuntimeException("Cannot query XPropertySetInfo",
1858 : uno::Reference< uno::XInterface >
1859 0 : ( static_cast< XAccessible* > (this) ) ); // disambiguate hierarchy
1860 :
1861 : // build sequence of available properties to check
1862 1 : sal_Int32 nLenReqAttr = rRequestedAttributes.getLength();
1863 2 : uno::Sequence< beans::Property > aProperties;
1864 1 : if (nLenReqAttr)
1865 : {
1866 1 : const OUString *pRequestedAttributes = rRequestedAttributes.getConstArray();
1867 :
1868 1 : aProperties.realloc( nLenReqAttr );
1869 1 : beans::Property *pProperties = aProperties.getArray();
1870 1 : sal_Int32 nCurLen = 0;
1871 2 : for (sal_Int32 i = 0; i < nLenReqAttr; ++i)
1872 : {
1873 1 : beans::Property aProp;
1874 : try
1875 : {
1876 1 : aProp = xPropSetInfo->getPropertyByName( pRequestedAttributes[i] );
1877 : }
1878 2 : catch (const beans::UnknownPropertyException&)
1879 : {
1880 1 : continue;
1881 : }
1882 0 : pProperties[ nCurLen++ ] = aProp;
1883 0 : }
1884 1 : aProperties.realloc( nCurLen );
1885 : }
1886 : else
1887 0 : aProperties = xPropSetInfo->getProperties();
1888 :
1889 1 : sal_Int32 nLength = aProperties.getLength();
1890 1 : const beans::Property *pProperties = aProperties.getConstArray();
1891 :
1892 : // build resulting sequence
1893 1 : uno::Sequence< beans::PropertyValue > aOutSequence( nLength );
1894 1 : beans::PropertyValue* pOutSequence = aOutSequence.getArray();
1895 1 : sal_Int32 nOutLen = 0;
1896 1 : for (sal_Int32 i = 0; i < nLength; ++i)
1897 : {
1898 : // calling implementation functions:
1899 : // _getPropertyState and _getPropertyValue (see below) to provide
1900 : // the proper paragraph number when retrieving paragraph attributes
1901 0 : PropertyState eState = aPropSet._getPropertyState( pProperties->Name, mnParagraphIndex );
1902 : if ( eState == PropertyState_AMBIGUOUS_VALUE )
1903 : {
1904 : OSL_FAIL( "ambiguous property value encountered" );
1905 : }
1906 :
1907 : //if (eState == PropertyState_DIRECT_VALUE)
1908 : // per definition all paragraph properties and all character
1909 : // properties spanning the whole paragraph should be returned
1910 : // and declared as default value
1911 : {
1912 0 : pOutSequence->Name = pProperties->Name;
1913 0 : pOutSequence->Handle = pProperties->Handle;
1914 0 : pOutSequence->Value = aPropSet._getPropertyValue( pProperties->Name, mnParagraphIndex );
1915 0 : pOutSequence->State = PropertyState_DEFAULT_VALUE;
1916 :
1917 0 : ++pOutSequence;
1918 0 : ++nOutLen;
1919 : }
1920 0 : ++pProperties;
1921 : }
1922 1 : aOutSequence.realloc( nOutLen );
1923 :
1924 2 : return aOutSequence;
1925 : }
1926 :
1927 :
1928 1 : uno::Sequence< beans::PropertyValue > SAL_CALL AccessibleEditableTextPara::getRunAttributes(
1929 : sal_Int32 nIndex,
1930 : const uno::Sequence< OUString >& rRequestedAttributes )
1931 : throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1932 : {
1933 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1934 :
1935 1 : SolarMutexGuard aGuard;
1936 :
1937 : #if OSL_DEBUG_LEVEL > 0
1938 : SvxAccessibleTextAdapter& rCacheTF =
1939 : #endif
1940 1 : GetTextForwarder();
1941 :
1942 : #if OSL_DEBUG_LEVEL > 0
1943 : (void)rCacheTF;
1944 : #endif
1945 :
1946 : DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1947 : "AccessibleEditableTextPara::getCharacterAttributes: index value overflow");
1948 :
1949 1 : CheckIndex(nIndex);
1950 :
1951 1 : SvxAccessibleTextPropertySet aPropSet( &GetEditSource(),
1952 3 : ImplGetSvxCharAndParaPropertiesSet() );
1953 1 : aPropSet.SetSelection( MakeSelection( nIndex ) );
1954 2 : uno::Reference< beans::XPropertySetInfo > xPropSetInfo = aPropSet.getPropertySetInfo();
1955 1 : if (!xPropSetInfo.is())
1956 : throw uno::RuntimeException("Cannot query XPropertySetInfo",
1957 : uno::Reference< uno::XInterface >
1958 0 : ( static_cast< XAccessible* > (this) ) ); // disambiguate hierarchy
1959 :
1960 : // build sequence of available properties to check
1961 1 : sal_Int32 nLenReqAttr = rRequestedAttributes.getLength();
1962 2 : uno::Sequence< beans::Property > aProperties;
1963 1 : if (nLenReqAttr)
1964 : {
1965 1 : const OUString *pRequestedAttributes = rRequestedAttributes.getConstArray();
1966 :
1967 1 : aProperties.realloc( nLenReqAttr );
1968 1 : beans::Property *pProperties = aProperties.getArray();
1969 1 : sal_Int32 nCurLen = 0;
1970 2 : for (sal_Int32 i = 0; i < nLenReqAttr; ++i)
1971 : {
1972 1 : beans::Property aProp;
1973 : try
1974 : {
1975 1 : aProp = xPropSetInfo->getPropertyByName( pRequestedAttributes[i] );
1976 : }
1977 2 : catch (const beans::UnknownPropertyException&)
1978 : {
1979 1 : continue;
1980 : }
1981 0 : pProperties[ nCurLen++ ] = aProp;
1982 0 : }
1983 1 : aProperties.realloc( nCurLen );
1984 : }
1985 : else
1986 0 : aProperties = xPropSetInfo->getProperties();
1987 :
1988 1 : sal_Int32 nLength = aProperties.getLength();
1989 1 : const beans::Property *pProperties = aProperties.getConstArray();
1990 :
1991 : // build resulting sequence
1992 1 : uno::Sequence< beans::PropertyValue > aOutSequence( nLength );
1993 1 : beans::PropertyValue* pOutSequence = aOutSequence.getArray();
1994 1 : sal_Int32 nOutLen = 0;
1995 1 : for (sal_Int32 i = 0; i < nLength; ++i)
1996 : {
1997 : // calling 'regular' functions that will operate on the selection
1998 0 : PropertyState eState = aPropSet.getPropertyState( pProperties->Name );
1999 0 : if (eState == PropertyState_DIRECT_VALUE)
2000 : {
2001 0 : pOutSequence->Name = pProperties->Name;
2002 0 : pOutSequence->Handle = pProperties->Handle;
2003 0 : pOutSequence->Value = aPropSet.getPropertyValue( pProperties->Name );
2004 0 : pOutSequence->State = eState;
2005 :
2006 0 : ++pOutSequence;
2007 0 : ++nOutLen;
2008 : }
2009 0 : ++pProperties;
2010 : }
2011 1 : aOutSequence.realloc( nOutLen );
2012 :
2013 2 : return aOutSequence;
2014 : }
2015 :
2016 : // XAccessibleHypertext
2017 0 : ::sal_Int32 SAL_CALL AccessibleEditableTextPara::getHyperLinkCount( ) throw (::com::sun::star::uno::RuntimeException)
2018 : {
2019 0 : SvxAccessibleTextAdapter& rT = GetTextForwarder();
2020 0 : const sal_Int32 nPara = GetParagraphIndex();
2021 :
2022 0 : sal_uInt16 nHyperLinks = 0;
2023 0 : sal_uInt16 nFields = rT.GetFieldCount( nPara );
2024 0 : for ( sal_uInt16 n = 0; n < nFields; n++ )
2025 : {
2026 0 : EFieldInfo aField = rT.GetFieldInfo( nPara, n );
2027 0 : if ( aField.pFieldItem->GetField()->ISA( SvxURLField ) )
2028 0 : nHyperLinks++;
2029 0 : }
2030 0 : return nHyperLinks;
2031 : }
2032 :
2033 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)
2034 : {
2035 0 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleHyperlink > xRef;
2036 :
2037 0 : SvxAccessibleTextAdapter& rT = GetTextForwarder();
2038 0 : const sal_Int32 nPara = GetParagraphIndex();
2039 :
2040 0 : sal_uInt16 nHyperLink = 0;
2041 0 : sal_uInt16 nFields = rT.GetFieldCount( nPara );
2042 0 : for ( sal_uInt16 n = 0; n < nFields; n++ )
2043 : {
2044 0 : EFieldInfo aField = rT.GetFieldInfo( nPara, n );
2045 0 : if ( aField.pFieldItem->GetField()->ISA( SvxURLField ) )
2046 : {
2047 0 : if ( nHyperLink == nLinkIndex )
2048 : {
2049 0 : sal_uInt16 nEEStart = aField.aPosition.nIndex;
2050 :
2051 : // Translate EE Index to accessible index
2052 0 : sal_uInt16 nStart = rT.CalcEditEngineIndex( nPara, nEEStart );
2053 0 : sal_uInt16 nEnd = nStart + aField.aCurrentText.Len();
2054 0 : xRef = new AccessibleHyperlink( rT, new SvxFieldItem( *aField.pFieldItem ), nPara, nEEStart, nStart, nEnd, aField.aCurrentText );
2055 0 : break;
2056 : }
2057 0 : nHyperLink++;
2058 : }
2059 0 : }
2060 :
2061 0 : return xRef;
2062 : }
2063 :
2064 0 : ::sal_Int32 SAL_CALL AccessibleEditableTextPara::getHyperLinkIndex( ::sal_Int32 nCharIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
2065 : {
2066 0 : const sal_Int32 nPara = GetParagraphIndex();
2067 0 : SvxAccessibleTextAdapter& rT = GetTextForwarder();
2068 :
2069 : // SvxAccessibleTextIndex aIndex;
2070 : // aIndex.SetIndex(nPara, nCharIndex, rT);
2071 : // const sal_uInt16 nEEIndex = aIndex.GetEEIndex();
2072 :
2073 0 : const sal_uInt16 nEEIndex = rT.CalcEditEngineIndex( nPara, nCharIndex );
2074 0 : sal_Int32 nHLIndex = 0;
2075 0 : sal_uInt16 nHyperLink = 0;
2076 0 : sal_uInt16 nFields = rT.GetFieldCount( nPara );
2077 0 : for ( sal_uInt16 n = 0; n < nFields; n++ )
2078 : {
2079 0 : EFieldInfo aField = rT.GetFieldInfo( nPara, n );
2080 0 : if ( aField.pFieldItem->GetField()->ISA( SvxURLField ) )
2081 : {
2082 0 : if ( aField.aPosition.nIndex == nEEIndex )
2083 : {
2084 0 : nHLIndex = nHyperLink;
2085 0 : break;
2086 : }
2087 0 : nHyperLink++;
2088 : }
2089 0 : }
2090 :
2091 0 : return nHLIndex;
2092 : }
2093 :
2094 : // XAccessibleMultiLineText
2095 0 : sal_Int32 SAL_CALL AccessibleEditableTextPara::getLineNumberAtIndex( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
2096 : {
2097 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
2098 :
2099 0 : sal_Int32 nRes = -1;
2100 0 : sal_Int32 nPara = GetParagraphIndex();
2101 :
2102 0 : SvxTextForwarder &rCacheTF = GetTextForwarder();
2103 0 : const bool bValidPara = 0 <= nPara && nPara < rCacheTF.GetParagraphCount();
2104 : DBG_ASSERT( bValidPara, "getLineNumberAtIndex: current paragraph index out of range" );
2105 0 : if (bValidPara)
2106 : {
2107 : // we explicitly allow for the index to point at the character right behind the text
2108 0 : if (0 <= nIndex && nIndex <= rCacheTF.GetTextLen( nPara ))
2109 0 : nRes = rCacheTF.GetLineNumberAtIndex( nPara, static_cast< sal_uInt16 >(nIndex) );
2110 : else
2111 0 : throw lang::IndexOutOfBoundsException();
2112 : }
2113 0 : return nRes;
2114 : }
2115 :
2116 : // XAccessibleMultiLineText
2117 0 : ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleEditableTextPara::getTextAtLineNumber( sal_Int32 nLineNo ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
2118 : {
2119 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
2120 :
2121 0 : ::com::sun::star::accessibility::TextSegment aResult;
2122 0 : sal_Int32 nPara = GetParagraphIndex();
2123 0 : SvxTextForwarder &rCacheTF = GetTextForwarder();
2124 0 : const bool bValidPara = 0 <= nPara && nPara < rCacheTF.GetParagraphCount();
2125 : DBG_ASSERT( bValidPara, "getTextAtLineNumber: current paragraph index out of range" );
2126 0 : if (bValidPara)
2127 : {
2128 0 : if (0 <= nLineNo && nLineNo < rCacheTF.GetLineCount( nPara ))
2129 : {
2130 0 : sal_uInt16 nStart = 0, nEnd = 0;
2131 0 : rCacheTF.GetLineBoundaries( nStart, nEnd, nPara, static_cast< sal_uInt16 >(nLineNo) );
2132 0 : if (nStart != 0xFFFF && nEnd != 0xFFFF)
2133 : {
2134 : try
2135 : {
2136 0 : aResult.SegmentText = getTextRange( nStart, nEnd );
2137 0 : aResult.SegmentStart = nStart;
2138 0 : aResult.SegmentEnd = nEnd;
2139 : }
2140 0 : catch (const lang::IndexOutOfBoundsException&)
2141 : {
2142 : // this is not the exception that should be raised in this function ...
2143 : DBG_ASSERT( 0, "unexpected exception" );
2144 : }
2145 : }
2146 : }
2147 : else
2148 0 : throw lang::IndexOutOfBoundsException();
2149 : }
2150 0 : return aResult;
2151 : }
2152 :
2153 : // XAccessibleMultiLineText
2154 0 : ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleEditableTextPara::getTextAtLineWithCaret( ) throw (uno::RuntimeException)
2155 : {
2156 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
2157 :
2158 0 : ::com::sun::star::accessibility::TextSegment aResult;
2159 : try
2160 : {
2161 0 : aResult = getTextAtLineNumber( getNumberOfLineWithCaret() );
2162 : }
2163 0 : catch (const lang::IndexOutOfBoundsException&)
2164 : {
2165 : // this one needs to be catched since this interface does not allow for it.
2166 : }
2167 0 : return aResult;
2168 : }
2169 :
2170 : // XAccessibleMultiLineText
2171 0 : sal_Int32 SAL_CALL AccessibleEditableTextPara::getNumberOfLineWithCaret( ) throw (uno::RuntimeException)
2172 : {
2173 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
2174 :
2175 0 : sal_Int32 nRes = -1;
2176 : try
2177 : {
2178 0 : nRes = getLineNumberAtIndex( getCaretPosition() );
2179 : }
2180 0 : catch (const lang::IndexOutOfBoundsException&)
2181 : {
2182 : // this one needs to be catched since this interface does not allow for it.
2183 : }
2184 0 : return nRes;
2185 : }
2186 :
2187 :
2188 : // XServiceInfo
2189 5 : OUString SAL_CALL AccessibleEditableTextPara::getImplementationName (void) throw (uno::RuntimeException)
2190 : {
2191 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
2192 :
2193 5 : return OUString("AccessibleEditableTextPara");
2194 : }
2195 :
2196 0 : sal_Bool SAL_CALL AccessibleEditableTextPara::supportsService (const OUString& sServiceName) throw (uno::RuntimeException)
2197 : {
2198 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
2199 :
2200 : // Iterate over all supported service names and return true if on of them
2201 : // matches the given name.
2202 : uno::Sequence< OUString> aSupportedServices (
2203 0 : getSupportedServiceNames ());
2204 0 : for (int i=0; i<aSupportedServices.getLength(); i++)
2205 0 : if (sServiceName == aSupportedServices[i])
2206 0 : return sal_True;
2207 0 : return sal_False;
2208 : }
2209 :
2210 0 : uno::Sequence< OUString> SAL_CALL AccessibleEditableTextPara::getSupportedServiceNames (void) throw (uno::RuntimeException)
2211 : {
2212 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
2213 :
2214 0 : const OUString sServiceName( getServiceName() );
2215 0 : return uno::Sequence< OUString > (&sServiceName, 1);
2216 : }
2217 :
2218 : // XServiceName
2219 0 : OUString SAL_CALL AccessibleEditableTextPara::getServiceName (void) throw (uno::RuntimeException)
2220 : {
2221 : DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
2222 :
2223 : // #105185# Using correct service now
2224 0 : return OUString("com.sun.star.text.AccessibleParagraphView");
2225 : }
2226 :
2227 267 : } // end of namespace accessibility
2228 :
2229 : //------------------------------------------------------------------------
2230 :
2231 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|