xref: /trunk/main/editeng/source/accessibility/AccessibleEditableTextPara.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1190118d0SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3190118d0SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4190118d0SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5190118d0SAndrew Rist  * distributed with this work for additional information
6190118d0SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7190118d0SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8190118d0SAndrew Rist  * "License"); you may not use this file except in compliance
9190118d0SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11190118d0SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13190118d0SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14190118d0SAndrew Rist  * software distributed under the License is distributed on an
15190118d0SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16190118d0SAndrew Rist  * KIND, either express or implied.  See the License for the
17190118d0SAndrew Rist  * specific language governing permissions and limitations
18190118d0SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20190118d0SAndrew Rist  *************************************************************/
21190118d0SAndrew Rist 
22190118d0SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_editeng.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir //------------------------------------------------------------------------
28cdf0e10cSrcweir //
29cdf0e10cSrcweir // Global header
30cdf0e10cSrcweir //
31cdf0e10cSrcweir //------------------------------------------------------------------------
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <limits.h>
34cdf0e10cSrcweir #include <vector>
35cdf0e10cSrcweir #include <algorithm>
36cdf0e10cSrcweir #include <vos/mutex.hxx>
37cdf0e10cSrcweir #include <vcl/window.hxx>
38cdf0e10cSrcweir #include <vcl/svapp.hxx>
39cdf0e10cSrcweir #include <editeng/flditem.hxx>
40cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
41cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx>
42cdf0e10cSrcweir #include <com/sun/star/awt/Point.hpp>
43cdf0e10cSrcweir #include <com/sun/star/awt/Rectangle.hpp>
44cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
45cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp>
46cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleTextType.hpp>
47cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
48cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
49cdf0e10cSrcweir #include <comphelper/accessibleeventnotifier.hxx>
50cdf0e10cSrcweir #include <comphelper/sequenceashashmap.hxx>
51cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx>
52cdf0e10cSrcweir #include <unotools/accessiblerelationsethelper.hxx>
53cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
54cdf0e10cSrcweir #include <vcl/unohelp.hxx>
55cdf0e10cSrcweir #include <editeng/editeng.hxx>
56cdf0e10cSrcweir #include <editeng/unoprnms.hxx>
57cdf0e10cSrcweir #include <editeng/unoipset.hxx>
58cdf0e10cSrcweir #include <editeng/outliner.hxx>
599b8096d0SSteve Yin #include <svl/intitem.hxx>
60cdf0e10cSrcweir 
61cdf0e10cSrcweir //------------------------------------------------------------------------
62cdf0e10cSrcweir //
63cdf0e10cSrcweir // Project-local header
64cdf0e10cSrcweir //
65cdf0e10cSrcweir //------------------------------------------------------------------------
66cdf0e10cSrcweir 
67cdf0e10cSrcweir #include <com/sun/star/beans/PropertyState.hpp>
68cdf0e10cSrcweir 
69cdf0e10cSrcweir //!!!#include <svx/unoshape.hxx>
70cdf0e10cSrcweir //!!!#include <svx/dialmgr.hxx>
71cdf0e10cSrcweir //!!!#include "accessibility.hrc"
72cdf0e10cSrcweir 
73cdf0e10cSrcweir #include <editeng/unolingu.hxx>
74cdf0e10cSrcweir #include <editeng/unopracc.hxx>
75cdf0e10cSrcweir #include "editeng/AccessibleEditableTextPara.hxx"
76cdf0e10cSrcweir #include "AccessibleHyperlink.hxx"
77cdf0e10cSrcweir 
78cdf0e10cSrcweir #include <svtools/colorcfg.hxx>
799b8096d0SSteve Yin #include <algorithm>
809b8096d0SSteve Yin using namespace std;
810deba7fbSSteve Yin #include "editeng.hrc"
820deba7fbSSteve Yin #include <editeng/eerdll.hxx>
839b8096d0SSteve Yin #include <editeng/numitem.hxx>
84cdf0e10cSrcweir 
85cdf0e10cSrcweir using namespace ::com::sun::star;
86cdf0e10cSrcweir using namespace ::com::sun::star::beans;
87cdf0e10cSrcweir using namespace ::com::sun::star::accessibility;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 
90cdf0e10cSrcweir //------------------------------------------------------------------------
91cdf0e10cSrcweir //
92cdf0e10cSrcweir // AccessibleEditableTextPara implementation
93cdf0e10cSrcweir //
94cdf0e10cSrcweir //------------------------------------------------------------------------
95cdf0e10cSrcweir 
96cdf0e10cSrcweir namespace accessibility
97cdf0e10cSrcweir {
98cdf0e10cSrcweir 
ImplGetSvxCharAndParaPropertiesSet()99cdf0e10cSrcweir     const SvxItemPropertySet* ImplGetSvxCharAndParaPropertiesSet()
100cdf0e10cSrcweir     {
101cdf0e10cSrcweir         // PropertyMap for character and paragraph properties
102cdf0e10cSrcweir         static const SfxItemPropertyMapEntry aPropMap[] =
103cdf0e10cSrcweir         {
1049b8096d0SSteve Yin             SVX_UNOEDIT_OUTLINER_PROPERTIES,
105cdf0e10cSrcweir             SVX_UNOEDIT_CHAR_PROPERTIES,
106cdf0e10cSrcweir             SVX_UNOEDIT_PARA_PROPERTIES,
107cdf0e10cSrcweir             SVX_UNOEDIT_NUMBERING_PROPERTIE,
108cdf0e10cSrcweir             {MAP_CHAR_LEN("TextUserDefinedAttributes"),     EE_CHAR_XMLATTRIBS,     &::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0)  ,        0,     0},
109cdf0e10cSrcweir             {MAP_CHAR_LEN("ParaUserDefinedAttributes"),     EE_PARA_XMLATTRIBS,     &::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0)  ,        0,     0},
110cdf0e10cSrcweir             {0,0,0,0,0,0}
111cdf0e10cSrcweir         };
112cdf0e10cSrcweir         static SvxItemPropertySet aPropSet( aPropMap, EditEngine::GetGlobalItemPool() );
113cdf0e10cSrcweir         return &aPropSet;
114cdf0e10cSrcweir     }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 
DBG_NAME(AccessibleEditableTextPara)117cdf0e10cSrcweir     DBG_NAME( AccessibleEditableTextPara )
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     // --> OD 2006-01-11 #i27138# - add parameter <_pParaManager>
120cdf0e10cSrcweir     AccessibleEditableTextPara::AccessibleEditableTextPara(
121cdf0e10cSrcweir                                 const uno::Reference< XAccessible >& rParent,
122cdf0e10cSrcweir                                 const AccessibleParaManager* _pParaManager )
123cdf0e10cSrcweir         : AccessibleTextParaInterfaceBase( m_aMutex ),
124cdf0e10cSrcweir           mnParagraphIndex( 0 ),
125cdf0e10cSrcweir           mnIndexInParent( 0 ),
126cdf0e10cSrcweir           mpEditSource( NULL ),
127cdf0e10cSrcweir           maEEOffset( 0, 0 ),
128cdf0e10cSrcweir           mxParent( rParent ),
129cdf0e10cSrcweir           // well, that's strictly (UNO) exception safe, though not
130cdf0e10cSrcweir           // really robust. We rely on the fact that this member is
131cdf0e10cSrcweir           // constructed last, and that the constructor body catches
132cdf0e10cSrcweir           // exceptions, thus no chance for exceptions once the Id is
133cdf0e10cSrcweir           // fetched. Nevertheless, normally should employ RAII here...
134cdf0e10cSrcweir           mnNotifierClientId(::comphelper::AccessibleEventNotifier::registerClient()),
135cdf0e10cSrcweir           // --> OD 2006-01-11 #i27138#
136cdf0e10cSrcweir           mpParaManager( _pParaManager )
137cdf0e10cSrcweir           // <--
138cdf0e10cSrcweir     {
139cdf0e10cSrcweir #ifdef DBG_UTIL
140cdf0e10cSrcweir         DBG_CTOR( AccessibleEditableTextPara, NULL );
141cdf0e10cSrcweir         OSL_TRACE( "AccessibleEditableTextPara received ID: %d\n", mnNotifierClientId );
142cdf0e10cSrcweir #endif
143cdf0e10cSrcweir 
144cdf0e10cSrcweir         try
145cdf0e10cSrcweir         {
146cdf0e10cSrcweir             // Create the state set.
147cdf0e10cSrcweir             ::utl::AccessibleStateSetHelper* pStateSet  = new ::utl::AccessibleStateSetHelper ();
148cdf0e10cSrcweir             mxStateSet = pStateSet;
149cdf0e10cSrcweir 
150cdf0e10cSrcweir             // these are always on
151cdf0e10cSrcweir             pStateSet->AddState( AccessibleStateType::MULTI_LINE );
152cdf0e10cSrcweir             pStateSet->AddState( AccessibleStateType::FOCUSABLE );
153cdf0e10cSrcweir             pStateSet->AddState( AccessibleStateType::VISIBLE );
154cdf0e10cSrcweir             pStateSet->AddState( AccessibleStateType::SHOWING );
155cdf0e10cSrcweir             pStateSet->AddState( AccessibleStateType::ENABLED );
156cdf0e10cSrcweir             pStateSet->AddState( AccessibleStateType::SENSITIVE );
157cdf0e10cSrcweir         }
158cdf0e10cSrcweir         catch( const uno::Exception& ) {}
159cdf0e10cSrcweir     }
160cdf0e10cSrcweir 
~AccessibleEditableTextPara()161cdf0e10cSrcweir     AccessibleEditableTextPara::~AccessibleEditableTextPara()
162cdf0e10cSrcweir     {
163cdf0e10cSrcweir         DBG_DTOR( AccessibleEditableTextPara, NULL );
164cdf0e10cSrcweir 
165cdf0e10cSrcweir         // sign off from event notifier
166cdf0e10cSrcweir         if( getNotifierClientId() != -1 )
167cdf0e10cSrcweir         {
168cdf0e10cSrcweir             try
169cdf0e10cSrcweir             {
170cdf0e10cSrcweir                 ::comphelper::AccessibleEventNotifier::revokeClient( getNotifierClientId() );
171cdf0e10cSrcweir #ifdef DBG_UTIL
172cdf0e10cSrcweir                 OSL_TRACE( "AccessibleEditableTextPara revoked ID: %d\n", mnNotifierClientId );
173cdf0e10cSrcweir #endif
174cdf0e10cSrcweir             }
175cdf0e10cSrcweir             catch( const uno::Exception& ) {}
176cdf0e10cSrcweir         }
177cdf0e10cSrcweir     }
178cdf0e10cSrcweir 
implGetText()179cdf0e10cSrcweir     ::rtl::OUString AccessibleEditableTextPara::implGetText()
180cdf0e10cSrcweir     {
181cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
182cdf0e10cSrcweir 
183cdf0e10cSrcweir         return GetTextRange( 0, GetTextLen() );
184cdf0e10cSrcweir     }
185cdf0e10cSrcweir 
implGetLocale()186cdf0e10cSrcweir     ::com::sun::star::lang::Locale AccessibleEditableTextPara::implGetLocale()
187cdf0e10cSrcweir     {
188cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
189cdf0e10cSrcweir 
190cdf0e10cSrcweir         lang::Locale        aLocale;
191cdf0e10cSrcweir 
192cdf0e10cSrcweir         DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
193cdf0e10cSrcweir                    "AccessibleEditableTextPara::getLocale: paragraph index value overflow");
194cdf0e10cSrcweir 
195cdf0e10cSrcweir         // return locale of first character in the paragraph
1967481e1dfSDamjan Jovanovic         return SvxLanguageToLocale(aLocale, GetTextForwarder().GetLanguage( GetParagraphIndex(), 0 ));
197cdf0e10cSrcweir     }
198cdf0e10cSrcweir 
implGetSelection(sal_Int32 & nStartIndex,sal_Int32 & nEndIndex)199cdf0e10cSrcweir     void AccessibleEditableTextPara::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
200cdf0e10cSrcweir     {
201cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
202cdf0e10cSrcweir 
203cdf0e10cSrcweir         sal_uInt16 nStart, nEnd;
204cdf0e10cSrcweir 
205cdf0e10cSrcweir         if( GetSelection( nStart, nEnd ) )
206cdf0e10cSrcweir         {
207cdf0e10cSrcweir             nStartIndex = nStart;
208cdf0e10cSrcweir             nEndIndex = nEnd;
209cdf0e10cSrcweir         }
210cdf0e10cSrcweir         else
211cdf0e10cSrcweir         {
212cdf0e10cSrcweir             // #102234# No exception, just set to 'invalid'
213cdf0e10cSrcweir             nStartIndex = -1;
214cdf0e10cSrcweir             nEndIndex = -1;
215cdf0e10cSrcweir         }
216cdf0e10cSrcweir     }
217cdf0e10cSrcweir 
implGetParagraphBoundary(::com::sun::star::i18n::Boundary & rBoundary,sal_Int32)218cdf0e10cSrcweir     void AccessibleEditableTextPara::implGetParagraphBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 /*nIndex*/ )
219cdf0e10cSrcweir     {
220cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
221cdf0e10cSrcweir         DBG_WARNING( "AccessibleEditableTextPara::implGetParagraphBoundary: only a base implementation, ignoring the index" );
222cdf0e10cSrcweir 
223cdf0e10cSrcweir         rBoundary.startPos = 0;
2249b8096d0SSteve Yin         //rBoundary.endPos = GetTextLen();
2259b8096d0SSteve Yin         ::rtl::OUString sText( implGetText() );
2269b8096d0SSteve Yin         sal_Int32 nLength = sText.getLength();
2279b8096d0SSteve Yin         rBoundary.endPos = nLength;
228cdf0e10cSrcweir     }
229cdf0e10cSrcweir 
implGetLineBoundary(::com::sun::star::i18n::Boundary & rBoundary,sal_Int32 nIndex)230cdf0e10cSrcweir     void AccessibleEditableTextPara::implGetLineBoundary( ::com::sun::star::i18n::Boundary& rBoundary, sal_Int32 nIndex )
231cdf0e10cSrcweir     {
232cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
233cdf0e10cSrcweir 
234cdf0e10cSrcweir         SvxTextForwarder&   rCacheTF = GetTextForwarder();
235cdf0e10cSrcweir         const sal_Int32     nParaIndex = GetParagraphIndex();
236cdf0e10cSrcweir 
237cdf0e10cSrcweir         DBG_ASSERT(nParaIndex >= 0 && nParaIndex <= USHRT_MAX,
238cdf0e10cSrcweir                    "AccessibleEditableTextPara::implGetLineBoundary: paragraph index value overflow");
239cdf0e10cSrcweir 
2408ee1071cSDamjan Jovanovic         const sal_Int32 nTextLen = rCacheTF.GetTextLen( nParaIndex );
241cdf0e10cSrcweir 
242cdf0e10cSrcweir         CheckPosition(nIndex);
243cdf0e10cSrcweir 
244cdf0e10cSrcweir         rBoundary.startPos = rBoundary.endPos = -1;
245cdf0e10cSrcweir 
246abee0e4cSDamjan Jovanovic         const sal_uInt16 nLineCount=rCacheTF.GetLineCount( nParaIndex );
247cdf0e10cSrcweir 
248cdf0e10cSrcweir         if( nIndex == nTextLen )
249cdf0e10cSrcweir         {
250cdf0e10cSrcweir             // #i17014# Special-casing one-behind-the-end character
251cdf0e10cSrcweir             if( nLineCount <= 1 )
252cdf0e10cSrcweir                 rBoundary.startPos = 0;
253cdf0e10cSrcweir             else
254f94052d8SDamjan Jovanovic                 rBoundary.startPos = nTextLen - rCacheTF.GetLineLen( nParaIndex,
255cdf0e10cSrcweir                                                                      nLineCount-1 );
256cdf0e10cSrcweir 
257cdf0e10cSrcweir             rBoundary.endPos = nTextLen;
258cdf0e10cSrcweir         }
259cdf0e10cSrcweir         else
260cdf0e10cSrcweir         {
261cdf0e10cSrcweir             // normal line search
262cdf0e10cSrcweir             sal_uInt16 nLine;
263cdf0e10cSrcweir             sal_Int32 nCurIndex;
264cdf0e10cSrcweir             for( nLine=0, nCurIndex=0; nLine<nLineCount; ++nLine )
265cdf0e10cSrcweir             {
266f94052d8SDamjan Jovanovic                 nCurIndex += rCacheTF.GetLineLen(nParaIndex, nLine);
267cdf0e10cSrcweir 
268cdf0e10cSrcweir                 if( nCurIndex > nIndex )
269cdf0e10cSrcweir                 {
270f94052d8SDamjan Jovanovic                     rBoundary.startPos = nCurIndex - rCacheTF.GetLineLen(nParaIndex, nLine);
271cdf0e10cSrcweir                     rBoundary.endPos = nCurIndex;
272cdf0e10cSrcweir                     break;
273cdf0e10cSrcweir                 }
274cdf0e10cSrcweir             }
275cdf0e10cSrcweir         }
276cdf0e10cSrcweir     }
277cdf0e10cSrcweir 
getNotifierClientId() const278cdf0e10cSrcweir     int AccessibleEditableTextPara::getNotifierClientId() const
279cdf0e10cSrcweir     {
280cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
281cdf0e10cSrcweir 
282cdf0e10cSrcweir         return mnNotifierClientId;
283cdf0e10cSrcweir     }
284cdf0e10cSrcweir 
SetIndexInParent(sal_Int32 nIndex)285cdf0e10cSrcweir     void AccessibleEditableTextPara::SetIndexInParent( sal_Int32 nIndex )
286cdf0e10cSrcweir     {
287cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
288cdf0e10cSrcweir 
289cdf0e10cSrcweir         mnIndexInParent = nIndex;
290cdf0e10cSrcweir     }
291cdf0e10cSrcweir 
GetIndexInParent() const292cdf0e10cSrcweir     sal_Int32 AccessibleEditableTextPara::GetIndexInParent() const
293cdf0e10cSrcweir     {
294cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
295cdf0e10cSrcweir 
296cdf0e10cSrcweir         return mnIndexInParent;
297cdf0e10cSrcweir     }
298cdf0e10cSrcweir 
SetParagraphIndex(sal_Int32 nIndex)299cdf0e10cSrcweir     void AccessibleEditableTextPara::SetParagraphIndex( sal_Int32 nIndex )
300cdf0e10cSrcweir     {
301cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
302cdf0e10cSrcweir 
303cdf0e10cSrcweir         sal_Int32 nOldIndex = mnParagraphIndex;
304cdf0e10cSrcweir 
305cdf0e10cSrcweir         mnParagraphIndex = nIndex;
306cdf0e10cSrcweir 
307cdf0e10cSrcweir         WeakBullet::HardRefType aChild( maImageBullet.get() );
308cdf0e10cSrcweir         if( aChild.is() )
309cdf0e10cSrcweir             aChild->SetParagraphIndex(mnParagraphIndex);
310cdf0e10cSrcweir 
311cdf0e10cSrcweir         try
312cdf0e10cSrcweir         {
313cdf0e10cSrcweir             if( nOldIndex != nIndex )
314cdf0e10cSrcweir             {
315cdf0e10cSrcweir                 uno::Any aOldDesc;
316cdf0e10cSrcweir                 uno::Any aOldName;
317cdf0e10cSrcweir 
318cdf0e10cSrcweir                 try
319cdf0e10cSrcweir                 {
320cdf0e10cSrcweir                     aOldDesc <<= getAccessibleDescription();
321cdf0e10cSrcweir                     aOldName <<= getAccessibleName();
322cdf0e10cSrcweir                 }
323cdf0e10cSrcweir                 catch( const uno::Exception& ) {} // optional behaviour
324cdf0e10cSrcweir                 // index and therefore description changed
325cdf0e10cSrcweir                 FireEvent( AccessibleEventId::DESCRIPTION_CHANGED, uno::makeAny( getAccessibleDescription() ), aOldDesc );
326cdf0e10cSrcweir                 FireEvent( AccessibleEventId::NAME_CHANGED, uno::makeAny( getAccessibleName() ), aOldName );
327cdf0e10cSrcweir             }
328cdf0e10cSrcweir         }
329cdf0e10cSrcweir         catch( const uno::Exception& ) {} // optional behaviour
330cdf0e10cSrcweir     }
331cdf0e10cSrcweir 
GetParagraphIndex() const332cdf0e10cSrcweir     sal_Int32 AccessibleEditableTextPara::GetParagraphIndex() const SAL_THROW((uno::RuntimeException))
333cdf0e10cSrcweir     {
334cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
335cdf0e10cSrcweir 
336cdf0e10cSrcweir         return mnParagraphIndex;
337cdf0e10cSrcweir     }
338cdf0e10cSrcweir 
Dispose()339cdf0e10cSrcweir     void AccessibleEditableTextPara::Dispose()
340cdf0e10cSrcweir     {
341cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
342cdf0e10cSrcweir 
343cdf0e10cSrcweir         int nClientId( getNotifierClientId() );
344cdf0e10cSrcweir 
345cdf0e10cSrcweir         // #108212# drop all references before notifying dispose
346cdf0e10cSrcweir         mxParent = NULL;
347cdf0e10cSrcweir         mnNotifierClientId = -1;
348cdf0e10cSrcweir         mpEditSource = NULL;
349cdf0e10cSrcweir 
350cdf0e10cSrcweir         // notify listeners
351cdf0e10cSrcweir         if( nClientId != -1 )
352cdf0e10cSrcweir         {
353cdf0e10cSrcweir             try
354cdf0e10cSrcweir             {
355cdf0e10cSrcweir                 uno::Reference < XAccessibleContext > xThis = getAccessibleContext();
356cdf0e10cSrcweir 
357cdf0e10cSrcweir                 // #106234# Delegate to EventNotifier
358cdf0e10cSrcweir                 ::comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( nClientId, xThis );
359cdf0e10cSrcweir #ifdef DBG_UTIL
360cdf0e10cSrcweir                 OSL_TRACE( "Disposed ID: %d\n", nClientId );
361cdf0e10cSrcweir #endif
362cdf0e10cSrcweir             }
363cdf0e10cSrcweir             catch( const uno::Exception& ) {}
364cdf0e10cSrcweir         }
365cdf0e10cSrcweir     }
366cdf0e10cSrcweir 
SetEditSource(SvxEditSourceAdapter * pEditSource)367cdf0e10cSrcweir     void AccessibleEditableTextPara::SetEditSource( SvxEditSourceAdapter* pEditSource )
368cdf0e10cSrcweir     {
369cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
370cdf0e10cSrcweir 
371cdf0e10cSrcweir         WeakBullet::HardRefType aChild( maImageBullet.get() );
372cdf0e10cSrcweir         if( aChild.is() )
373cdf0e10cSrcweir             aChild->SetEditSource(pEditSource);
374cdf0e10cSrcweir 
3759b8096d0SSteve Yin         if( !pEditSource )
376cdf0e10cSrcweir         {
377cdf0e10cSrcweir             // going defunc
378cdf0e10cSrcweir             UnSetState( AccessibleStateType::SHOWING );
379cdf0e10cSrcweir             UnSetState( AccessibleStateType::VISIBLE );
380cdf0e10cSrcweir             SetState( AccessibleStateType::INVALID );
381cdf0e10cSrcweir             SetState( AccessibleStateType::DEFUNC );
382cdf0e10cSrcweir 
383cdf0e10cSrcweir             Dispose();
384cdf0e10cSrcweir         }
3859b8096d0SSteve Yin         mpEditSource = pEditSource;
386cdf0e10cSrcweir         // #108900# Init last text content
387cdf0e10cSrcweir         try
388cdf0e10cSrcweir         {
389cdf0e10cSrcweir             TextChanged();
390cdf0e10cSrcweir         }
391cdf0e10cSrcweir         catch( const uno::RuntimeException& ) {}
392cdf0e10cSrcweir     }
393cdf0e10cSrcweir 
MakeSelection(sal_Int32 nStartEEIndex,sal_Int32 nEndEEIndex)394cdf0e10cSrcweir     ESelection AccessibleEditableTextPara::MakeSelection( sal_Int32 nStartEEIndex, sal_Int32 nEndEEIndex )
395cdf0e10cSrcweir     {
396cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
397cdf0e10cSrcweir 
398cdf0e10cSrcweir         // check overflow
399cdf0e10cSrcweir         DBG_ASSERT(nStartEEIndex >= 0 && nStartEEIndex <= USHRT_MAX &&
400cdf0e10cSrcweir                    nEndEEIndex >= 0 && nEndEEIndex <= USHRT_MAX &&
401cdf0e10cSrcweir                    GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
402cdf0e10cSrcweir                    "AccessibleEditableTextPara::MakeSelection: index value overflow");
403cdf0e10cSrcweir 
4043361926eSDamjan Jovanovic         sal_uInt32 nParaIndex = GetParagraphIndex();
405cdf0e10cSrcweir         return ESelection( nParaIndex, static_cast< sal_uInt16 >( nStartEEIndex ),
406cdf0e10cSrcweir                            nParaIndex, static_cast< sal_uInt16 >( nEndEEIndex ) );
407cdf0e10cSrcweir     }
408cdf0e10cSrcweir 
MakeSelection(sal_Int32 nEEIndex)409cdf0e10cSrcweir     ESelection AccessibleEditableTextPara::MakeSelection( sal_Int32 nEEIndex )
410cdf0e10cSrcweir     {
411cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
412cdf0e10cSrcweir 
413cdf0e10cSrcweir         return MakeSelection( nEEIndex, nEEIndex+1 );
414cdf0e10cSrcweir     }
415cdf0e10cSrcweir 
MakeCursor(sal_Int32 nEEIndex)416cdf0e10cSrcweir     ESelection AccessibleEditableTextPara::MakeCursor( sal_Int32 nEEIndex )
417cdf0e10cSrcweir     {
418cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
419cdf0e10cSrcweir 
420cdf0e10cSrcweir         return MakeSelection( nEEIndex, nEEIndex );
421cdf0e10cSrcweir     }
422cdf0e10cSrcweir 
CheckIndex(sal_Int32 nIndex)423cdf0e10cSrcweir     void AccessibleEditableTextPara::CheckIndex( sal_Int32 nIndex ) SAL_THROW((lang::IndexOutOfBoundsException, uno::RuntimeException))
424cdf0e10cSrcweir     {
425cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
426cdf0e10cSrcweir 
427cdf0e10cSrcweir         if( nIndex < 0 || nIndex >= getCharacterCount() )
428cdf0e10cSrcweir             throw lang::IndexOutOfBoundsException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AccessibleEditableTextPara: character index out of bounds")),
429cdf0e10cSrcweir                                                   uno::Reference< uno::XInterface >
430cdf0e10cSrcweir                                                   ( static_cast< ::cppu::OWeakObject* > (this) ) ); // disambiguate hierarchy
431cdf0e10cSrcweir     }
432cdf0e10cSrcweir 
CheckPosition(sal_Int32 nIndex)433cdf0e10cSrcweir     void AccessibleEditableTextPara::CheckPosition( sal_Int32 nIndex ) SAL_THROW((lang::IndexOutOfBoundsException, uno::RuntimeException))
434cdf0e10cSrcweir     {
435cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
436cdf0e10cSrcweir 
437cdf0e10cSrcweir         if( nIndex < 0 || nIndex > getCharacterCount() )
438cdf0e10cSrcweir             throw lang::IndexOutOfBoundsException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AccessibleEditableTextPara: character position out of bounds")),
439cdf0e10cSrcweir                                                   uno::Reference< uno::XInterface >
440cdf0e10cSrcweir                                                   ( static_cast< ::cppu::OWeakObject* > (this) ) ); // disambiguate hierarchy
441cdf0e10cSrcweir     }
442cdf0e10cSrcweir 
CheckRange(sal_Int32 nStart,sal_Int32 nEnd)443cdf0e10cSrcweir     void AccessibleEditableTextPara::CheckRange( sal_Int32 nStart, sal_Int32 nEnd ) SAL_THROW((lang::IndexOutOfBoundsException, uno::RuntimeException))
444cdf0e10cSrcweir     {
445cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
446cdf0e10cSrcweir 
447cdf0e10cSrcweir         CheckPosition( nStart );
448cdf0e10cSrcweir         CheckPosition( nEnd );
449cdf0e10cSrcweir     }
450cdf0e10cSrcweir 
GetSelection(sal_uInt16 & nStartPos,sal_uInt16 & nEndPos)451cdf0e10cSrcweir     sal_Bool AccessibleEditableTextPara::GetSelection( sal_uInt16& nStartPos, sal_uInt16& nEndPos ) SAL_THROW((uno::RuntimeException))
452cdf0e10cSrcweir     {
453cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
454cdf0e10cSrcweir 
455cdf0e10cSrcweir         ESelection aSelection;
4563361926eSDamjan Jovanovic         sal_uInt32 nPara = GetParagraphIndex();
457cdf0e10cSrcweir         if( !GetEditViewForwarder().GetSelection( aSelection ) )
458cdf0e10cSrcweir             return sal_False;
459cdf0e10cSrcweir 
460cdf0e10cSrcweir         if( aSelection.nStartPara < aSelection.nEndPara )
461cdf0e10cSrcweir         {
462cdf0e10cSrcweir             if( aSelection.nStartPara > nPara ||
463cdf0e10cSrcweir                 aSelection.nEndPara < nPara )
464cdf0e10cSrcweir                 return sal_False;
465cdf0e10cSrcweir 
466cdf0e10cSrcweir             if( nPara == aSelection.nStartPara )
467cdf0e10cSrcweir                 nStartPos = aSelection.nStartPos;
468cdf0e10cSrcweir             else
469cdf0e10cSrcweir                 nStartPos = 0;
470cdf0e10cSrcweir 
471cdf0e10cSrcweir             if( nPara == aSelection.nEndPara )
472cdf0e10cSrcweir                 nEndPos = aSelection.nEndPos;
473cdf0e10cSrcweir             else
474cdf0e10cSrcweir                 nEndPos = GetTextLen();
475cdf0e10cSrcweir         }
476cdf0e10cSrcweir         else
477cdf0e10cSrcweir         {
478cdf0e10cSrcweir             if( aSelection.nStartPara < nPara ||
479cdf0e10cSrcweir                 aSelection.nEndPara > nPara )
480cdf0e10cSrcweir                 return sal_False;
481cdf0e10cSrcweir 
482cdf0e10cSrcweir             if( nPara == aSelection.nStartPara )
483cdf0e10cSrcweir                 nStartPos = aSelection.nStartPos;
484cdf0e10cSrcweir             else
485cdf0e10cSrcweir                 nStartPos = GetTextLen();
486cdf0e10cSrcweir 
487cdf0e10cSrcweir             if( nPara == aSelection.nEndPara )
488cdf0e10cSrcweir                 nEndPos = aSelection.nEndPos;
489cdf0e10cSrcweir             else
490cdf0e10cSrcweir                 nEndPos = 0;
491cdf0e10cSrcweir         }
492cdf0e10cSrcweir 
493cdf0e10cSrcweir         return sal_True;
494cdf0e10cSrcweir     }
495cdf0e10cSrcweir 
GetText(sal_Int32 nIndex)496cdf0e10cSrcweir     String AccessibleEditableTextPara::GetText( sal_Int32 nIndex ) SAL_THROW((uno::RuntimeException))
497cdf0e10cSrcweir     {
498cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
499cdf0e10cSrcweir 
500cdf0e10cSrcweir         return GetTextForwarder().GetText( MakeSelection(nIndex) );
501cdf0e10cSrcweir     }
502cdf0e10cSrcweir 
GetTextRange(sal_Int32 nStartIndex,sal_Int32 nEndIndex)503cdf0e10cSrcweir     String AccessibleEditableTextPara::GetTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) SAL_THROW((uno::RuntimeException))
504cdf0e10cSrcweir     {
505cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
506cdf0e10cSrcweir 
507cdf0e10cSrcweir         return GetTextForwarder().GetText( MakeSelection(nStartIndex, nEndIndex) );
508cdf0e10cSrcweir     }
509cdf0e10cSrcweir 
GetTextLen() const510cdf0e10cSrcweir     sal_uInt16 AccessibleEditableTextPara::GetTextLen() const SAL_THROW((uno::RuntimeException))
511cdf0e10cSrcweir     {
512cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
513cdf0e10cSrcweir 
5148ee1071cSDamjan Jovanovic         return GetTextForwarder().GetTextLen( GetParagraphIndex() );
515cdf0e10cSrcweir     }
516cdf0e10cSrcweir 
IsVisible() const517cdf0e10cSrcweir     sal_Bool AccessibleEditableTextPara::IsVisible() const
518cdf0e10cSrcweir     {
519cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
520cdf0e10cSrcweir 
521cdf0e10cSrcweir         return mpEditSource ? sal_True : sal_False ;
522cdf0e10cSrcweir     }
523cdf0e10cSrcweir 
GetParaInterface(sal_Int32 nIndex)524cdf0e10cSrcweir     uno::Reference< XAccessibleText > AccessibleEditableTextPara::GetParaInterface( sal_Int32 nIndex )
525cdf0e10cSrcweir     {
526cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
527cdf0e10cSrcweir 
528cdf0e10cSrcweir         uno::Reference< XAccessible > xParent = getAccessibleParent();
529cdf0e10cSrcweir         if( xParent.is() )
530cdf0e10cSrcweir         {
531cdf0e10cSrcweir             uno::Reference< XAccessibleContext > xParentContext = xParent->getAccessibleContext();
532cdf0e10cSrcweir             if( xParentContext.is() )
533cdf0e10cSrcweir             {
534cdf0e10cSrcweir                 uno::Reference< XAccessible > xPara = xParentContext->getAccessibleChild( nIndex );
535cdf0e10cSrcweir                 if( xPara.is() )
536cdf0e10cSrcweir                 {
537cdf0e10cSrcweir                     return uno::Reference< XAccessibleText > ( xPara, uno::UNO_QUERY );
538cdf0e10cSrcweir                 }
539cdf0e10cSrcweir             }
540cdf0e10cSrcweir         }
541cdf0e10cSrcweir 
542cdf0e10cSrcweir         return uno::Reference< XAccessibleText >();
543cdf0e10cSrcweir     }
544cdf0e10cSrcweir 
GetEditSource() const545cdf0e10cSrcweir     SvxEditSourceAdapter& AccessibleEditableTextPara::GetEditSource() const SAL_THROW((uno::RuntimeException))
546cdf0e10cSrcweir     {
547cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
548cdf0e10cSrcweir 
549cdf0e10cSrcweir         if( mpEditSource )
550cdf0e10cSrcweir             return *mpEditSource;
551cdf0e10cSrcweir         else
552cdf0e10cSrcweir             throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("No edit source, object is defunct")),
553cdf0e10cSrcweir                                         uno::Reference< uno::XInterface >
554cdf0e10cSrcweir                                         ( static_cast< ::cppu::OWeakObject* >
555cdf0e10cSrcweir                                           ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy
556cdf0e10cSrcweir     }
557cdf0e10cSrcweir 
GetTextForwarder() const558cdf0e10cSrcweir     SvxAccessibleTextAdapter& AccessibleEditableTextPara::GetTextForwarder() const SAL_THROW((uno::RuntimeException))
559cdf0e10cSrcweir     {
560cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
561cdf0e10cSrcweir 
562cdf0e10cSrcweir         SvxEditSourceAdapter& rEditSource = GetEditSource();
563cdf0e10cSrcweir         SvxAccessibleTextAdapter* pTextForwarder = rEditSource.GetTextForwarderAdapter();
564cdf0e10cSrcweir 
565cdf0e10cSrcweir         if( !pTextForwarder )
566cdf0e10cSrcweir             throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Unable to fetch text forwarder, object is defunct")),
567cdf0e10cSrcweir                                         uno::Reference< uno::XInterface >
568cdf0e10cSrcweir                                         ( static_cast< ::cppu::OWeakObject* >
569cdf0e10cSrcweir                                           ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy
570cdf0e10cSrcweir 
571cdf0e10cSrcweir         if( pTextForwarder->IsValid() )
572cdf0e10cSrcweir             return *pTextForwarder;
573cdf0e10cSrcweir         else
574cdf0e10cSrcweir             throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Text forwarder is invalid, object is defunct")),
575cdf0e10cSrcweir                                         uno::Reference< uno::XInterface >
576cdf0e10cSrcweir                                         ( static_cast< ::cppu::OWeakObject* >
577cdf0e10cSrcweir                                           ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy
578cdf0e10cSrcweir     }
579cdf0e10cSrcweir 
GetViewForwarder() const580cdf0e10cSrcweir     SvxViewForwarder& AccessibleEditableTextPara::GetViewForwarder() const SAL_THROW((uno::RuntimeException))
581cdf0e10cSrcweir     {
582cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
583cdf0e10cSrcweir 
584cdf0e10cSrcweir         SvxEditSource& rEditSource = GetEditSource();
585cdf0e10cSrcweir         SvxViewForwarder* pViewForwarder = rEditSource.GetViewForwarder();
586cdf0e10cSrcweir 
587cdf0e10cSrcweir         if( !pViewForwarder )
588cdf0e10cSrcweir         {
589cdf0e10cSrcweir             throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Unable to fetch view forwarder, object is defunct")),
590cdf0e10cSrcweir                                         uno::Reference< uno::XInterface >
591cdf0e10cSrcweir                                         ( static_cast< ::cppu::OWeakObject* >
592cdf0e10cSrcweir                                           ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy
593cdf0e10cSrcweir         }
594cdf0e10cSrcweir 
595cdf0e10cSrcweir         if( pViewForwarder->IsValid() )
596cdf0e10cSrcweir             return *pViewForwarder;
597cdf0e10cSrcweir         else
598cdf0e10cSrcweir             throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("View forwarder is invalid, object is defunct")),
599cdf0e10cSrcweir                                         uno::Reference< uno::XInterface >
600cdf0e10cSrcweir                                         ( static_cast< ::cppu::OWeakObject* >
601cdf0e10cSrcweir                                           ( const_cast< AccessibleEditableTextPara* > (this) )  ) );    // disambiguate hierarchy
602cdf0e10cSrcweir     }
603cdf0e10cSrcweir 
GetEditViewForwarder(sal_Bool bCreate) const604cdf0e10cSrcweir     SvxAccessibleTextEditViewAdapter& AccessibleEditableTextPara::GetEditViewForwarder( sal_Bool bCreate ) const SAL_THROW((uno::RuntimeException))
605cdf0e10cSrcweir     {
606cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
607cdf0e10cSrcweir 
608cdf0e10cSrcweir         SvxEditSourceAdapter& rEditSource = GetEditSource();
609cdf0e10cSrcweir         SvxAccessibleTextEditViewAdapter* pTextEditViewForwarder = rEditSource.GetEditViewForwarderAdapter( bCreate );
610cdf0e10cSrcweir 
611cdf0e10cSrcweir         if( !pTextEditViewForwarder )
612cdf0e10cSrcweir         {
613cdf0e10cSrcweir             if( bCreate )
614cdf0e10cSrcweir                 throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Unable to fetch view forwarder, object is defunct")),
615cdf0e10cSrcweir                                             uno::Reference< uno::XInterface >
616cdf0e10cSrcweir                                             ( static_cast< ::cppu::OWeakObject* >
617cdf0e10cSrcweir                                               ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy
618cdf0e10cSrcweir             else
619cdf0e10cSrcweir                 throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("No view forwarder, object not in edit mode")),
620cdf0e10cSrcweir                                             uno::Reference< uno::XInterface >
621cdf0e10cSrcweir                                             ( static_cast< ::cppu::OWeakObject* >
622cdf0e10cSrcweir                                               ( const_cast< AccessibleEditableTextPara* > (this) ) ) ); // disambiguate hierarchy
623cdf0e10cSrcweir         }
624cdf0e10cSrcweir 
625cdf0e10cSrcweir         if( pTextEditViewForwarder->IsValid() )
626cdf0e10cSrcweir             return *pTextEditViewForwarder;
627cdf0e10cSrcweir         else
628cdf0e10cSrcweir         {
629cdf0e10cSrcweir             if( bCreate )
630cdf0e10cSrcweir                 throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("View forwarder is invalid, object is defunct")),
631cdf0e10cSrcweir                                             uno::Reference< uno::XInterface >
632cdf0e10cSrcweir                                             ( static_cast< ::cppu::OWeakObject* >
633cdf0e10cSrcweir                                               ( const_cast< AccessibleEditableTextPara* > (this) )  ) );    // disambiguate hierarchy
634cdf0e10cSrcweir             else
635cdf0e10cSrcweir                 throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("View forwarder is invalid, object not in edit mode")),
636cdf0e10cSrcweir                                             uno::Reference< uno::XInterface >
637cdf0e10cSrcweir                                             ( static_cast< ::cppu::OWeakObject* >
638cdf0e10cSrcweir                                               ( const_cast< AccessibleEditableTextPara* > (this) )  ) );    // disambiguate hierarchy
639cdf0e10cSrcweir         }
640cdf0e10cSrcweir     }
641cdf0e10cSrcweir 
HaveEditView() const642cdf0e10cSrcweir     sal_Bool AccessibleEditableTextPara::HaveEditView() const
643cdf0e10cSrcweir     {
644cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
645cdf0e10cSrcweir 
646cdf0e10cSrcweir         SvxEditSource& rEditSource = GetEditSource();
647cdf0e10cSrcweir         SvxEditViewForwarder* pViewForwarder = rEditSource.GetEditViewForwarder();
648cdf0e10cSrcweir 
649cdf0e10cSrcweir         if( !pViewForwarder )
650cdf0e10cSrcweir             return sal_False;
651cdf0e10cSrcweir 
652cdf0e10cSrcweir         if( !pViewForwarder->IsValid() )
653cdf0e10cSrcweir             return sal_False;
654cdf0e10cSrcweir 
655cdf0e10cSrcweir         return sal_True;
656cdf0e10cSrcweir     }
657cdf0e10cSrcweir 
HaveChildren()658cdf0e10cSrcweir     sal_Bool AccessibleEditableTextPara::HaveChildren()
659cdf0e10cSrcweir     {
660cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
661cdf0e10cSrcweir 
662cdf0e10cSrcweir         DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
663cdf0e10cSrcweir                    "AccessibleEditableTextPara::HaveChildren: paragraph index value overflow");
664cdf0e10cSrcweir 
6651ba24eaeSDamjan Jovanovic         return GetTextForwarder().HaveImageBullet( GetParagraphIndex() );
666cdf0e10cSrcweir     }
667cdf0e10cSrcweir 
IsActive() const668cdf0e10cSrcweir     sal_Bool AccessibleEditableTextPara::IsActive() const SAL_THROW((uno::RuntimeException))
669cdf0e10cSrcweir     {
670cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
671cdf0e10cSrcweir 
672cdf0e10cSrcweir         SvxEditSource& rEditSource = GetEditSource();
673cdf0e10cSrcweir         SvxEditViewForwarder* pViewForwarder = rEditSource.GetEditViewForwarder();
674cdf0e10cSrcweir 
675cdf0e10cSrcweir         if( !pViewForwarder )
676cdf0e10cSrcweir             return sal_False;
677cdf0e10cSrcweir 
678cdf0e10cSrcweir         if( pViewForwarder->IsValid() )
679cdf0e10cSrcweir             return sal_False;
680cdf0e10cSrcweir         else
681cdf0e10cSrcweir             return sal_True;
682cdf0e10cSrcweir     }
683cdf0e10cSrcweir 
LogicToPixel(const Rectangle & rRect,const MapMode & rMapMode,SvxViewForwarder & rForwarder)684cdf0e10cSrcweir     Rectangle AccessibleEditableTextPara::LogicToPixel( const Rectangle& rRect, const MapMode& rMapMode, SvxViewForwarder& rForwarder )
685cdf0e10cSrcweir     {
686cdf0e10cSrcweir         // convert to screen coordinates
687cdf0e10cSrcweir         return Rectangle( rForwarder.LogicToPixel( rRect.TopLeft(), rMapMode ),
688cdf0e10cSrcweir                           rForwarder.LogicToPixel( rRect.BottomRight(), rMapMode ) );
689cdf0e10cSrcweir     }
690cdf0e10cSrcweir 
GetEEOffset() const691cdf0e10cSrcweir     const Point& AccessibleEditableTextPara::GetEEOffset() const
692cdf0e10cSrcweir     {
693cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
694cdf0e10cSrcweir 
695cdf0e10cSrcweir         return maEEOffset;
696cdf0e10cSrcweir     }
697cdf0e10cSrcweir 
SetEEOffset(const Point & rOffset)698cdf0e10cSrcweir     void AccessibleEditableTextPara::SetEEOffset( const Point& rOffset )
699cdf0e10cSrcweir     {
700cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
701cdf0e10cSrcweir 
702cdf0e10cSrcweir         WeakBullet::HardRefType aChild( maImageBullet.get() );
703cdf0e10cSrcweir         if( aChild.is() )
704cdf0e10cSrcweir             aChild->SetEEOffset(rOffset);
705cdf0e10cSrcweir 
706cdf0e10cSrcweir         maEEOffset = rOffset;
707cdf0e10cSrcweir     }
708cdf0e10cSrcweir 
FireEvent(const sal_Int16 nEventId,const uno::Any & rNewValue,const uno::Any & rOldValue) const709cdf0e10cSrcweir     void AccessibleEditableTextPara::FireEvent(const sal_Int16 nEventId, const uno::Any& rNewValue, const uno::Any& rOldValue) const
710cdf0e10cSrcweir     {
711cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
712cdf0e10cSrcweir 
713cdf0e10cSrcweir         uno::Reference < XAccessibleContext > xThis( const_cast< AccessibleEditableTextPara* > (this)->getAccessibleContext() );
714cdf0e10cSrcweir 
715cdf0e10cSrcweir         AccessibleEventObject aEvent(xThis, nEventId, rNewValue, rOldValue);
716cdf0e10cSrcweir 
717cdf0e10cSrcweir         // #102261# Call global queue for focus events
718cdf0e10cSrcweir         if( nEventId == AccessibleEventId::STATE_CHANGED )
719cdf0e10cSrcweir             vcl::unohelper::NotifyAccessibleStateEventGlobally( aEvent );
720cdf0e10cSrcweir 
721cdf0e10cSrcweir         // #106234# Delegate to EventNotifier
722cdf0e10cSrcweir         if( getNotifierClientId() != -1 )
723cdf0e10cSrcweir             ::comphelper::AccessibleEventNotifier::addEvent( getNotifierClientId(),
724cdf0e10cSrcweir                                                              aEvent );
725cdf0e10cSrcweir     }
726cdf0e10cSrcweir 
GotPropertyEvent(const uno::Any & rNewValue,const sal_Int16 nEventId) const727cdf0e10cSrcweir     void AccessibleEditableTextPara::GotPropertyEvent( const uno::Any& rNewValue, const sal_Int16 nEventId ) const
728cdf0e10cSrcweir     {
729cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
730cdf0e10cSrcweir 
731cdf0e10cSrcweir         FireEvent( nEventId, rNewValue );
732cdf0e10cSrcweir     }
733cdf0e10cSrcweir 
LostPropertyEvent(const uno::Any & rOldValue,const sal_Int16 nEventId) const734cdf0e10cSrcweir     void AccessibleEditableTextPara::LostPropertyEvent( const uno::Any& rOldValue, const sal_Int16 nEventId ) const
735cdf0e10cSrcweir     {
736cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
737cdf0e10cSrcweir 
738cdf0e10cSrcweir         FireEvent( nEventId, uno::Any(), rOldValue );
739cdf0e10cSrcweir     }
740cdf0e10cSrcweir 
HasState(const sal_Int16 nStateId)741cdf0e10cSrcweir     bool AccessibleEditableTextPara::HasState( const sal_Int16 nStateId )
742cdf0e10cSrcweir     {
743cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
744cdf0e10cSrcweir 
745cdf0e10cSrcweir         ::utl::AccessibleStateSetHelper* pStateSet = static_cast< ::utl::AccessibleStateSetHelper*>(mxStateSet.get());
746cdf0e10cSrcweir         if( pStateSet != NULL )
747cdf0e10cSrcweir             return pStateSet->contains(nStateId) ? true : false;
748cdf0e10cSrcweir 
749cdf0e10cSrcweir         return false;
750cdf0e10cSrcweir     }
751cdf0e10cSrcweir 
SetState(const sal_Int16 nStateId)752cdf0e10cSrcweir     void AccessibleEditableTextPara::SetState( const sal_Int16 nStateId )
753cdf0e10cSrcweir     {
754cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
755cdf0e10cSrcweir 
756cdf0e10cSrcweir         ::utl::AccessibleStateSetHelper* pStateSet = static_cast< ::utl::AccessibleStateSetHelper*>(mxStateSet.get());
757cdf0e10cSrcweir         if( pStateSet != NULL &&
758cdf0e10cSrcweir             !pStateSet->contains(nStateId) )
759cdf0e10cSrcweir         {
760cdf0e10cSrcweir             pStateSet->AddState( nStateId );
76174cbd1f1SMatthias Seidel         // MT: Removed method IsShapeParaFocusable which was introduced with IA2 - basically it was only about figuring out whether or not the window has the focus, should be solved differently
7629b8096d0SSteve Yin         // if(IsShapeParaFocusable())
763cdf0e10cSrcweir             GotPropertyEvent( uno::makeAny( nStateId ), AccessibleEventId::STATE_CHANGED );
764cdf0e10cSrcweir         }
765cdf0e10cSrcweir     }
766cdf0e10cSrcweir 
UnSetState(const sal_Int16 nStateId)767cdf0e10cSrcweir     void AccessibleEditableTextPara::UnSetState( const sal_Int16 nStateId )
768cdf0e10cSrcweir     {
769cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
770cdf0e10cSrcweir 
771cdf0e10cSrcweir         ::utl::AccessibleStateSetHelper* pStateSet = static_cast< ::utl::AccessibleStateSetHelper*>(mxStateSet.get());
772cdf0e10cSrcweir         if( pStateSet != NULL &&
773cdf0e10cSrcweir             pStateSet->contains(nStateId) )
774cdf0e10cSrcweir         {
775cdf0e10cSrcweir             pStateSet->RemoveState( nStateId );
776cdf0e10cSrcweir             LostPropertyEvent( uno::makeAny( nStateId ), AccessibleEventId::STATE_CHANGED );
777cdf0e10cSrcweir         }
778cdf0e10cSrcweir     }
779cdf0e10cSrcweir 
TextChanged()780cdf0e10cSrcweir     void AccessibleEditableTextPara::TextChanged()
781cdf0e10cSrcweir     {
782cdf0e10cSrcweir         ::rtl::OUString aCurrentString( OCommonAccessibleText::getText() );
783cdf0e10cSrcweir         uno::Any aDeleted;
784cdf0e10cSrcweir         uno::Any aInserted;
785cdf0e10cSrcweir         if( OCommonAccessibleText::implInitTextChangedEvent( maLastTextString, aCurrentString,
786cdf0e10cSrcweir                                                              aDeleted, aInserted) )
787cdf0e10cSrcweir         {
788cdf0e10cSrcweir             FireEvent( AccessibleEventId::TEXT_CHANGED, aInserted, aDeleted );
789cdf0e10cSrcweir             maLastTextString = aCurrentString;
790cdf0e10cSrcweir         }
791cdf0e10cSrcweir     }
792cdf0e10cSrcweir 
GetAttributeRun(sal_uInt16 & nStartIndex,sal_uInt16 & nEndIndex,sal_Int32 nIndex)793cdf0e10cSrcweir     sal_Bool AccessibleEditableTextPara::GetAttributeRun( sal_uInt16& nStartIndex, sal_uInt16& nEndIndex, sal_Int32 nIndex )
794cdf0e10cSrcweir     {
795cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
796cdf0e10cSrcweir 
797cdf0e10cSrcweir         DBG_ASSERT(nIndex >= 0 && nIndex <= USHRT_MAX,
798cdf0e10cSrcweir                    "AccessibleEditableTextPara::GetAttributeRun: index value overflow");
799cdf0e10cSrcweir 
8007a9d3b93SDamjan Jovanovic         DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= EE_PARA_MAX,
801cdf0e10cSrcweir                    "AccessibleEditableTextPara::getLocale: paragraph index value overflow");
802cdf0e10cSrcweir 
803cdf0e10cSrcweir         return GetTextForwarder().GetAttributeRun( nStartIndex,
804cdf0e10cSrcweir                                                    nEndIndex,
8059d9bf804SDamjan Jovanovic                                                    GetParagraphIndex(),
806cdf0e10cSrcweir                                                    static_cast< sal_uInt16 >(nIndex) );
807cdf0e10cSrcweir     }
808cdf0e10cSrcweir 
queryInterface(const uno::Type & rType)809cdf0e10cSrcweir     uno::Any SAL_CALL AccessibleEditableTextPara::queryInterface (const uno::Type & rType) throw (uno::RuntimeException)
810cdf0e10cSrcweir     {
811cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
812cdf0e10cSrcweir 
813cdf0e10cSrcweir         uno::Any aRet;
814cdf0e10cSrcweir 
815cdf0e10cSrcweir         // must provide XAccesibleText by hand, since it comes publicly inherited by XAccessibleEditableText
816cdf0e10cSrcweir         if ( rType == ::getCppuType((uno::Reference< XAccessibleText > *)0) )
817cdf0e10cSrcweir         {
818cdf0e10cSrcweir             uno::Reference< XAccessibleText > aAccText = static_cast< XAccessibleEditableText * >(this);
819cdf0e10cSrcweir             aRet <<= aAccText;
820cdf0e10cSrcweir         }
821cdf0e10cSrcweir         else if ( rType == ::getCppuType((uno::Reference< XAccessibleEditableText > *)0) )
822cdf0e10cSrcweir         {
823cdf0e10cSrcweir             uno::Reference< XAccessibleEditableText > aAccEditText = this;
824cdf0e10cSrcweir             aRet <<= aAccEditText;
825cdf0e10cSrcweir         }
826cdf0e10cSrcweir     else if ( rType == ::getCppuType((uno::Reference< XAccessibleHypertext > *)0) )
827cdf0e10cSrcweir         {
828cdf0e10cSrcweir             uno::Reference< XAccessibleHypertext > aAccHyperText = this;
829cdf0e10cSrcweir             aRet <<= aAccHyperText;
830cdf0e10cSrcweir         }
831cdf0e10cSrcweir         else
832cdf0e10cSrcweir         {
833cdf0e10cSrcweir             aRet = AccessibleTextParaInterfaceBase::queryInterface(rType);
834cdf0e10cSrcweir         }
835cdf0e10cSrcweir 
836cdf0e10cSrcweir         return aRet;
837cdf0e10cSrcweir     }
838cdf0e10cSrcweir 
839cdf0e10cSrcweir     // XAccessible
getAccessibleContext()840cdf0e10cSrcweir     uno::Reference< XAccessibleContext > SAL_CALL AccessibleEditableTextPara::getAccessibleContext() throw (uno::RuntimeException)
841cdf0e10cSrcweir     {
842cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
843cdf0e10cSrcweir 
844cdf0e10cSrcweir         // We implement the XAccessibleContext interface in the same object
845cdf0e10cSrcweir         return uno::Reference< XAccessibleContext > ( this );
846cdf0e10cSrcweir     }
847cdf0e10cSrcweir 
848cdf0e10cSrcweir     // XAccessibleContext
getAccessibleChildCount()849cdf0e10cSrcweir     sal_Int32 SAL_CALL AccessibleEditableTextPara::getAccessibleChildCount() throw (uno::RuntimeException)
850cdf0e10cSrcweir     {
851cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
852cdf0e10cSrcweir 
853cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
854cdf0e10cSrcweir 
855cdf0e10cSrcweir         return HaveChildren() ? 1 : 0;
856cdf0e10cSrcweir     }
857cdf0e10cSrcweir 
getAccessibleChild(sal_Int32 i)858cdf0e10cSrcweir     uno::Reference< XAccessible > SAL_CALL AccessibleEditableTextPara::getAccessibleChild( sal_Int32 i ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
859cdf0e10cSrcweir     {
860cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
861cdf0e10cSrcweir 
862cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
863cdf0e10cSrcweir 
864cdf0e10cSrcweir         if( !HaveChildren() )
865cdf0e10cSrcweir             throw lang::IndexOutOfBoundsException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("No childs available")),
866cdf0e10cSrcweir                                                   uno::Reference< uno::XInterface >
867cdf0e10cSrcweir                                                   ( static_cast< ::cppu::OWeakObject* > (this) ) ); // static_cast: disambiguate hierarchy
868cdf0e10cSrcweir 
869cdf0e10cSrcweir         if( i != 0 )
870cdf0e10cSrcweir             throw lang::IndexOutOfBoundsException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Invalid child index")),
871cdf0e10cSrcweir                                                   uno::Reference< uno::XInterface >
872cdf0e10cSrcweir                                                   ( static_cast< ::cppu::OWeakObject* > (this) ) ); // static_cast: disambiguate hierarchy
873cdf0e10cSrcweir 
874cdf0e10cSrcweir         WeakBullet::HardRefType aChild( maImageBullet.get() );
875cdf0e10cSrcweir 
876cdf0e10cSrcweir         if( !aChild.is() )
877cdf0e10cSrcweir         {
878cdf0e10cSrcweir             // there is no hard reference available, create object then
879cdf0e10cSrcweir             AccessibleImageBullet* pChild = new AccessibleImageBullet( uno::Reference< XAccessible >( this ) );
880cdf0e10cSrcweir             uno::Reference< XAccessible > xChild( static_cast< ::cppu::OWeakObject* > (pChild), uno::UNO_QUERY );
881cdf0e10cSrcweir 
882cdf0e10cSrcweir             if( !xChild.is() )
883cdf0e10cSrcweir                 throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Child creation failed")),
884cdf0e10cSrcweir                                             uno::Reference< uno::XInterface >
885cdf0e10cSrcweir                                             ( static_cast< ::cppu::OWeakObject* > (this) ) );
886cdf0e10cSrcweir 
887cdf0e10cSrcweir             aChild = WeakBullet::HardRefType( xChild, pChild );
888cdf0e10cSrcweir 
889cdf0e10cSrcweir             aChild->SetEditSource( &GetEditSource() );
890cdf0e10cSrcweir             aChild->SetParagraphIndex( GetParagraphIndex() );
891cdf0e10cSrcweir             aChild->SetIndexInParent( i );
892cdf0e10cSrcweir 
893cdf0e10cSrcweir             maImageBullet = aChild;
894cdf0e10cSrcweir         }
895cdf0e10cSrcweir 
896cdf0e10cSrcweir         return aChild.getRef();
897cdf0e10cSrcweir     }
898cdf0e10cSrcweir 
getAccessibleParent()899cdf0e10cSrcweir     uno::Reference< XAccessible > SAL_CALL AccessibleEditableTextPara::getAccessibleParent() throw (uno::RuntimeException)
900cdf0e10cSrcweir     {
901cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
902cdf0e10cSrcweir 
903cdf0e10cSrcweir #ifdef DBG_UTIL
904cdf0e10cSrcweir         if( !mxParent.is() )
905cdf0e10cSrcweir             DBG_TRACE( "AccessibleEditableTextPara::getAccessibleParent: no frontend set, did somebody forgot to call AccessibleTextHelper::SetEventSource()?");
906cdf0e10cSrcweir #endif
907cdf0e10cSrcweir 
908cdf0e10cSrcweir         return mxParent;
909cdf0e10cSrcweir     }
910cdf0e10cSrcweir 
getAccessibleIndexInParent()911cdf0e10cSrcweir     sal_Int32 SAL_CALL AccessibleEditableTextPara::getAccessibleIndexInParent() throw (uno::RuntimeException)
912cdf0e10cSrcweir     {
913cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
914cdf0e10cSrcweir 
915cdf0e10cSrcweir         return mnIndexInParent;
916cdf0e10cSrcweir     }
917cdf0e10cSrcweir 
getAccessibleRole()918cdf0e10cSrcweir     sal_Int16 SAL_CALL AccessibleEditableTextPara::getAccessibleRole() throw (uno::RuntimeException)
919cdf0e10cSrcweir     {
920cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
921cdf0e10cSrcweir 
922cdf0e10cSrcweir         return AccessibleRole::PARAGRAPH;
923cdf0e10cSrcweir     }
924cdf0e10cSrcweir 
getAccessibleDescription()925cdf0e10cSrcweir     ::rtl::OUString SAL_CALL AccessibleEditableTextPara::getAccessibleDescription() throw (uno::RuntimeException)
926cdf0e10cSrcweir     {
927cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
9280deba7fbSSteve Yin         ::vos::OGuard aGuard( Application::GetSolarMutex() );
929cdf0e10cSrcweir 
9300deba7fbSSteve Yin         // append first 40 characters from text, or first line, if shorter
9310deba7fbSSteve Yin         // (writer takes first sentence here, but that's not supported
9320deba7fbSSteve Yin         // from EditEngine)
9330deba7fbSSteve Yin         // throws if defunc
9340deba7fbSSteve Yin         ::rtl::OUString aLine;
935cdf0e10cSrcweir 
9360deba7fbSSteve Yin         if( getCharacterCount() )
9370deba7fbSSteve Yin             aLine = getTextAtIndex(0, AccessibleTextType::LINE).SegmentText;
9380deba7fbSSteve Yin 
9390deba7fbSSteve Yin         // Get the string from the resource for the specified id.
9400deba7fbSSteve Yin         String sStr = ::rtl::OUString( String( EditResId (RID_SVXSTR_A11Y_PARAGRAPH_DESCRIPTION ) ) );
9410deba7fbSSteve Yin         String sParaIndex = ::rtl::OUString::valueOf( GetParagraphIndex() );
9420deba7fbSSteve Yin         sStr.SearchAndReplace( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "$(ARG)" )),
9430deba7fbSSteve Yin                                sParaIndex );
9440deba7fbSSteve Yin 
9450deba7fbSSteve Yin         if( aLine.getLength() > MaxDescriptionLen )
9460deba7fbSSteve Yin         {
9470deba7fbSSteve Yin             ::rtl::OUString aCurrWord;
9480deba7fbSSteve Yin             sal_Int32 i;
9490deba7fbSSteve Yin 
9500deba7fbSSteve Yin             // search backward from MaxDescriptionLen for previous word start
9510deba7fbSSteve Yin             for( aCurrWord=getTextAtIndex(MaxDescriptionLen, AccessibleTextType::WORD).SegmentText,
9520deba7fbSSteve Yin                      i=MaxDescriptionLen,
9530deba7fbSSteve Yin                      aLine=::rtl::OUString();
9540deba7fbSSteve Yin                  i>=0;
9550deba7fbSSteve Yin                  --i )
9560deba7fbSSteve Yin             {
9570deba7fbSSteve Yin                 if( getTextAtIndex(i, AccessibleTextType::WORD).SegmentText != aCurrWord )
9580deba7fbSSteve Yin                 {
9590deba7fbSSteve Yin                     if( i == 0 )
9600deba7fbSSteve Yin                         // prevent completely empty string
9610deba7fbSSteve Yin                         aLine = getTextAtIndex(0, AccessibleTextType::WORD).SegmentText;
9620deba7fbSSteve Yin                     else
9630deba7fbSSteve Yin                         aLine = getTextRange(0, i);
9640deba7fbSSteve Yin                 }
9650deba7fbSSteve Yin             }
9660deba7fbSSteve Yin         }
9670deba7fbSSteve Yin 
9680deba7fbSSteve Yin         return ::rtl::OUString( sStr ) + aLine;
969cdf0e10cSrcweir     }
970cdf0e10cSrcweir 
getAccessibleName()971cdf0e10cSrcweir     ::rtl::OUString SAL_CALL AccessibleEditableTextPara::getAccessibleName() throw (uno::RuntimeException)
972cdf0e10cSrcweir     {
973cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
974cdf0e10cSrcweir 
9750deba7fbSSteve Yin         ::vos::OGuard aGuard( Application::GetSolarMutex() );
976cdf0e10cSrcweir 
9770deba7fbSSteve Yin         // throws if defunc
9780deba7fbSSteve Yin         sal_Int32 nPara( GetParagraphIndex() );
9790deba7fbSSteve Yin 
9800deba7fbSSteve Yin         // Get the string from the resource for the specified id.
9810deba7fbSSteve Yin         String sStr = ::rtl::OUString( String( EditResId (RID_SVXSTR_A11Y_PARAGRAPH_NAME) ) );
9820deba7fbSSteve Yin         String sParaIndex = ::rtl::OUString::valueOf( nPara );
9830deba7fbSSteve Yin         sStr.SearchAndReplace( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "$(ARG)" )),
9840deba7fbSSteve Yin                                sParaIndex );
9850deba7fbSSteve Yin 
9860deba7fbSSteve Yin         return ::rtl::OUString( sStr );
987cdf0e10cSrcweir     }
988cdf0e10cSrcweir 
getAccessibleRelationSet()989cdf0e10cSrcweir     uno::Reference< XAccessibleRelationSet > SAL_CALL AccessibleEditableTextPara::getAccessibleRelationSet() throw (uno::RuntimeException)
990cdf0e10cSrcweir     {
991cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
992cdf0e10cSrcweir 
993cdf0e10cSrcweir         // --> OD 2006-01-11 #i27138# - provide relations CONTENT_FLOWS_FROM
994cdf0e10cSrcweir         // and CONTENT_FLOWS_TO
995cdf0e10cSrcweir         if ( mpParaManager )
996cdf0e10cSrcweir         {
997cdf0e10cSrcweir             utl::AccessibleRelationSetHelper* pAccRelSetHelper =
998cdf0e10cSrcweir                                         new utl::AccessibleRelationSetHelper();
999cdf0e10cSrcweir             sal_Int32 nMyParaIndex( GetParagraphIndex() );
1000cdf0e10cSrcweir             // relation CONTENT_FLOWS_FROM
1001cdf0e10cSrcweir             if ( nMyParaIndex > 0 &&
1002cdf0e10cSrcweir                  mpParaManager->IsReferencable( nMyParaIndex - 1 ) )
1003cdf0e10cSrcweir             {
1004cdf0e10cSrcweir                 uno::Sequence<uno::Reference<XInterface> > aSequence(1);
1005cdf0e10cSrcweir                 aSequence[0] =
1006cdf0e10cSrcweir                     mpParaManager->GetChild( nMyParaIndex - 1 ).first.get().getRef();
1007cdf0e10cSrcweir                 AccessibleRelation aAccRel( AccessibleRelationType::CONTENT_FLOWS_FROM,
1008cdf0e10cSrcweir                                             aSequence );
1009cdf0e10cSrcweir                 pAccRelSetHelper->AddRelation( aAccRel );
1010cdf0e10cSrcweir             }
1011cdf0e10cSrcweir 
1012cdf0e10cSrcweir             // relation CONTENT_FLOWS_TO
1013cdf0e10cSrcweir             if ( (nMyParaIndex + 1) < (sal_Int32)mpParaManager->GetNum() &&
1014cdf0e10cSrcweir                  mpParaManager->IsReferencable( nMyParaIndex + 1 ) )
1015cdf0e10cSrcweir             {
1016cdf0e10cSrcweir                 uno::Sequence<uno::Reference<XInterface> > aSequence(1);
1017cdf0e10cSrcweir                 aSequence[0] =
1018cdf0e10cSrcweir                     mpParaManager->GetChild( nMyParaIndex + 1 ).first.get().getRef();
1019cdf0e10cSrcweir                 AccessibleRelation aAccRel( AccessibleRelationType::CONTENT_FLOWS_TO,
1020cdf0e10cSrcweir                                             aSequence );
1021cdf0e10cSrcweir                 pAccRelSetHelper->AddRelation( aAccRel );
1022cdf0e10cSrcweir             }
1023cdf0e10cSrcweir 
1024cdf0e10cSrcweir             return pAccRelSetHelper;
1025cdf0e10cSrcweir         }
1026cdf0e10cSrcweir         else
1027cdf0e10cSrcweir         {
1028cdf0e10cSrcweir             // no relations, therefore empty
1029cdf0e10cSrcweir             return uno::Reference< XAccessibleRelationSet >();
1030cdf0e10cSrcweir         }
1031cdf0e10cSrcweir         // <--
1032cdf0e10cSrcweir     }
1033cdf0e10cSrcweir 
getAccessibleStateSet()1034cdf0e10cSrcweir     uno::Reference< XAccessibleStateSet > SAL_CALL AccessibleEditableTextPara::getAccessibleStateSet() throw (uno::RuntimeException)
1035cdf0e10cSrcweir     {
1036cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1037cdf0e10cSrcweir 
1038cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
1039cdf0e10cSrcweir 
1040cdf0e10cSrcweir         // Create a copy of the state set and return it.
1041cdf0e10cSrcweir         ::utl::AccessibleStateSetHelper* pStateSet = static_cast< ::utl::AccessibleStateSetHelper*>(mxStateSet.get());
1042cdf0e10cSrcweir 
1043cdf0e10cSrcweir         if( !pStateSet )
1044cdf0e10cSrcweir             return uno::Reference<XAccessibleStateSet>();
10459b8096d0SSteve Yin         uno::Reference<XAccessibleStateSet> xParentStates;
10469b8096d0SSteve Yin         if (getAccessibleParent().is())
10479b8096d0SSteve Yin         {
10489b8096d0SSteve Yin             uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
10499b8096d0SSteve Yin             xParentStates = xParentContext->getAccessibleStateSet();
10509b8096d0SSteve Yin         }
10519b8096d0SSteve Yin         if (xParentStates.is() && xParentStates->contains(AccessibleStateType::EDITABLE) )
10529b8096d0SSteve Yin         {
10539b8096d0SSteve Yin             pStateSet->AddState(AccessibleStateType::EDITABLE);
10549b8096d0SSteve Yin         }
1055cdf0e10cSrcweir         return uno::Reference<XAccessibleStateSet>( new ::utl::AccessibleStateSetHelper (*pStateSet) );
1056cdf0e10cSrcweir     }
1057cdf0e10cSrcweir 
getLocale()1058cdf0e10cSrcweir     lang::Locale SAL_CALL AccessibleEditableTextPara::getLocale() throw (IllegalAccessibleComponentStateException, uno::RuntimeException)
1059cdf0e10cSrcweir     {
1060cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1061cdf0e10cSrcweir 
1062cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
1063cdf0e10cSrcweir 
1064cdf0e10cSrcweir         return implGetLocale();
1065cdf0e10cSrcweir     }
1066cdf0e10cSrcweir 
addEventListener(const uno::Reference<XAccessibleEventListener> & xListener)1067cdf0e10cSrcweir     void SAL_CALL AccessibleEditableTextPara::addEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) throw (uno::RuntimeException)
1068cdf0e10cSrcweir     {
1069cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1070cdf0e10cSrcweir 
1071cdf0e10cSrcweir         if( getNotifierClientId() != -1 )
1072cdf0e10cSrcweir             ::comphelper::AccessibleEventNotifier::addEventListener( getNotifierClientId(), xListener );
1073cdf0e10cSrcweir     }
1074cdf0e10cSrcweir 
removeEventListener(const uno::Reference<XAccessibleEventListener> & xListener)1075cdf0e10cSrcweir     void SAL_CALL AccessibleEditableTextPara::removeEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) throw (uno::RuntimeException)
1076cdf0e10cSrcweir     {
1077cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1078cdf0e10cSrcweir 
1079cdf0e10cSrcweir         if( getNotifierClientId() != -1 )
1080cdf0e10cSrcweir             ::comphelper::AccessibleEventNotifier::removeEventListener( getNotifierClientId(), xListener );
1081cdf0e10cSrcweir     }
1082cdf0e10cSrcweir 
1083cdf0e10cSrcweir     // XAccessibleComponent
containsPoint(const awt::Point & aTmpPoint)1084cdf0e10cSrcweir     sal_Bool SAL_CALL AccessibleEditableTextPara::containsPoint( const awt::Point& aTmpPoint ) throw (uno::RuntimeException)
1085cdf0e10cSrcweir     {
1086cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1087cdf0e10cSrcweir 
1088cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
1089cdf0e10cSrcweir 
1090cdf0e10cSrcweir         DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1091cdf0e10cSrcweir                    "AccessibleEditableTextPara::contains: index value overflow");
1092cdf0e10cSrcweir 
1093cdf0e10cSrcweir         awt::Rectangle aTmpRect = getBounds();
1094cdf0e10cSrcweir         Rectangle aRect( Point(aTmpRect.X, aTmpRect.Y), Size(aTmpRect.Width, aTmpRect.Height) );
1095cdf0e10cSrcweir         Point aPoint( aTmpPoint.X, aTmpPoint.Y );
1096cdf0e10cSrcweir 
1097cdf0e10cSrcweir         return aRect.IsInside( aPoint );
1098cdf0e10cSrcweir     }
1099cdf0e10cSrcweir 
getAccessibleAtPoint(const awt::Point & _aPoint)1100cdf0e10cSrcweir     uno::Reference< XAccessible > SAL_CALL AccessibleEditableTextPara::getAccessibleAtPoint( const awt::Point& _aPoint ) throw (uno::RuntimeException)
1101cdf0e10cSrcweir     {
1102cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1103cdf0e10cSrcweir 
1104cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
1105cdf0e10cSrcweir 
1106cdf0e10cSrcweir         if( HaveChildren() )
1107cdf0e10cSrcweir         {
1108cdf0e10cSrcweir             // #103862# No longer need to make given position relative
1109cdf0e10cSrcweir             Point aPoint( _aPoint.X, _aPoint.Y );
1110cdf0e10cSrcweir 
1111cdf0e10cSrcweir             // respect EditEngine offset to surrounding shape/cell
1112cdf0e10cSrcweir             aPoint -= GetEEOffset();
1113cdf0e10cSrcweir 
1114cdf0e10cSrcweir             // convert to EditEngine coordinate system
1115cdf0e10cSrcweir             SvxTextForwarder& rCacheTF = GetTextForwarder();
1116cdf0e10cSrcweir             Point aLogPoint( GetViewForwarder().PixelToLogic( aPoint, rCacheTF.GetMapMode() ) );
1117cdf0e10cSrcweir 
1118a6ca19dcSDamjan Jovanovic             EBulletInfo aBulletInfo = rCacheTF.GetBulletInfo( GetParagraphIndex() );
1119cdf0e10cSrcweir 
1120cdf0e10cSrcweir             if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND &&
1121cdf0e10cSrcweir                 aBulletInfo.bVisible &&
1122cdf0e10cSrcweir                 aBulletInfo.nType == SVX_NUM_BITMAP )
1123cdf0e10cSrcweir             {
1124cdf0e10cSrcweir                 Rectangle aRect = aBulletInfo.aBounds;
1125cdf0e10cSrcweir 
1126cdf0e10cSrcweir                 if( aRect.IsInside( aLogPoint ) )
1127cdf0e10cSrcweir                     return getAccessibleChild(0);
1128cdf0e10cSrcweir             }
1129cdf0e10cSrcweir         }
1130cdf0e10cSrcweir 
1131cdf0e10cSrcweir         // no children at all, or none at given position
1132cdf0e10cSrcweir         return uno::Reference< XAccessible >();
1133cdf0e10cSrcweir     }
1134cdf0e10cSrcweir 
getBounds()1135cdf0e10cSrcweir     awt::Rectangle SAL_CALL AccessibleEditableTextPara::getBounds() throw (uno::RuntimeException)
1136cdf0e10cSrcweir     {
1137cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1138cdf0e10cSrcweir 
1139cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
1140cdf0e10cSrcweir 
1141cdf0e10cSrcweir         DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1142cdf0e10cSrcweir                    "AccessibleEditableTextPara::getBounds: index value overflow");
1143cdf0e10cSrcweir 
1144cdf0e10cSrcweir         SvxTextForwarder& rCacheTF = GetTextForwarder();
1145f6b418d9SDamjan Jovanovic         Rectangle aRect = rCacheTF.GetParaBounds( GetParagraphIndex() );
1146cdf0e10cSrcweir 
1147cdf0e10cSrcweir         // convert to screen coordinates
1148cdf0e10cSrcweir         Rectangle aScreenRect = AccessibleEditableTextPara::LogicToPixel( aRect,
1149cdf0e10cSrcweir                                                                           rCacheTF.GetMapMode(),
1150cdf0e10cSrcweir                                                                           GetViewForwarder() );
1151cdf0e10cSrcweir 
1152cdf0e10cSrcweir         // offset from shape/cell
1153cdf0e10cSrcweir         Point aOffset = GetEEOffset();
1154cdf0e10cSrcweir 
1155cdf0e10cSrcweir         return awt::Rectangle( aScreenRect.Left() + aOffset.X(),
1156cdf0e10cSrcweir                                aScreenRect.Top() + aOffset.Y(),
1157cdf0e10cSrcweir                                aScreenRect.GetSize().Width(),
1158cdf0e10cSrcweir                                aScreenRect.GetSize().Height() );
1159cdf0e10cSrcweir     }
1160cdf0e10cSrcweir 
getLocation()1161cdf0e10cSrcweir     awt::Point SAL_CALL AccessibleEditableTextPara::getLocation(  ) throw (uno::RuntimeException)
1162cdf0e10cSrcweir     {
1163cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1164cdf0e10cSrcweir 
1165cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
1166cdf0e10cSrcweir 
1167cdf0e10cSrcweir         awt::Rectangle aRect = getBounds();
1168cdf0e10cSrcweir 
1169cdf0e10cSrcweir         return awt::Point( aRect.X, aRect.Y );
1170cdf0e10cSrcweir     }
1171cdf0e10cSrcweir 
getLocationOnScreen()1172cdf0e10cSrcweir     awt::Point SAL_CALL AccessibleEditableTextPara::getLocationOnScreen(  ) throw (uno::RuntimeException)
1173cdf0e10cSrcweir     {
1174cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1175cdf0e10cSrcweir 
1176cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
1177cdf0e10cSrcweir 
1178cdf0e10cSrcweir         // relate us to parent
1179cdf0e10cSrcweir         uno::Reference< XAccessible > xParent = getAccessibleParent();
1180cdf0e10cSrcweir         if( xParent.is() )
1181cdf0e10cSrcweir         {
1182cdf0e10cSrcweir             uno::Reference< XAccessibleComponent > xParentComponent( xParent, uno::UNO_QUERY );
1183cdf0e10cSrcweir             if( xParentComponent.is() )
1184cdf0e10cSrcweir             {
1185cdf0e10cSrcweir                 awt::Point aRefPoint = xParentComponent->getLocationOnScreen();
1186cdf0e10cSrcweir                 awt::Point aPoint = getLocation();
1187cdf0e10cSrcweir                 aPoint.X += aRefPoint.X;
1188cdf0e10cSrcweir                 aPoint.Y += aRefPoint.Y;
1189cdf0e10cSrcweir 
1190cdf0e10cSrcweir                 return aPoint;
1191cdf0e10cSrcweir             }
1192cdf0e10cSrcweir             // --> OD 2009-12-16 #i88070#
1193cdf0e10cSrcweir             // fallback to parent's <XAccessibleContext> instance
1194cdf0e10cSrcweir             else
1195cdf0e10cSrcweir             {
1196cdf0e10cSrcweir                 uno::Reference< XAccessibleContext > xParentContext = xParent->getAccessibleContext();
1197cdf0e10cSrcweir                 if ( xParentContext.is() )
1198cdf0e10cSrcweir                 {
1199cdf0e10cSrcweir                     uno::Reference< XAccessibleComponent > xParentContextComponent( xParentContext, uno::UNO_QUERY );
1200cdf0e10cSrcweir                     if( xParentContextComponent.is() )
1201cdf0e10cSrcweir                     {
1202cdf0e10cSrcweir                         awt::Point aRefPoint = xParentContextComponent->getLocationOnScreen();
1203cdf0e10cSrcweir                         awt::Point aPoint = getLocation();
1204cdf0e10cSrcweir                         aPoint.X += aRefPoint.X;
1205cdf0e10cSrcweir                         aPoint.Y += aRefPoint.Y;
1206cdf0e10cSrcweir 
1207cdf0e10cSrcweir                         return aPoint;
1208cdf0e10cSrcweir                     }
1209cdf0e10cSrcweir                 }
1210cdf0e10cSrcweir             }
1211cdf0e10cSrcweir             // <--
1212cdf0e10cSrcweir         }
1213cdf0e10cSrcweir 
1214cdf0e10cSrcweir         throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Cannot access parent")),
1215cdf0e10cSrcweir                                     uno::Reference< uno::XInterface >
1216cdf0e10cSrcweir                                     ( static_cast< XAccessible* > (this) ) );   // disambiguate hierarchy
1217cdf0e10cSrcweir     }
1218cdf0e10cSrcweir 
getSize()1219cdf0e10cSrcweir     awt::Size SAL_CALL AccessibleEditableTextPara::getSize(  ) throw (uno::RuntimeException)
1220cdf0e10cSrcweir     {
1221cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1222cdf0e10cSrcweir 
1223cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
1224cdf0e10cSrcweir 
1225cdf0e10cSrcweir         awt::Rectangle aRect = getBounds();
1226cdf0e10cSrcweir 
1227cdf0e10cSrcweir         return awt::Size( aRect.Width, aRect.Height );
1228cdf0e10cSrcweir     }
1229cdf0e10cSrcweir 
grabFocus()1230cdf0e10cSrcweir     void SAL_CALL AccessibleEditableTextPara::grabFocus(  ) throw (uno::RuntimeException)
1231cdf0e10cSrcweir     {
1232cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1233cdf0e10cSrcweir 
1234cdf0e10cSrcweir         // set cursor to this paragraph
1235cdf0e10cSrcweir         setSelection(0,0);
1236cdf0e10cSrcweir     }
1237cdf0e10cSrcweir 
getForeground()1238cdf0e10cSrcweir     sal_Int32 SAL_CALL AccessibleEditableTextPara::getForeground(  ) throw (::com::sun::star::uno::RuntimeException)
1239cdf0e10cSrcweir     {
1240cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1241cdf0e10cSrcweir 
1242cdf0e10cSrcweir         // #104444# Added to XAccessibleComponent interface
1243cdf0e10cSrcweir         svtools::ColorConfig aColorConfig;
1244cdf0e10cSrcweir         sal_uInt32 nColor = aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor;
1245cdf0e10cSrcweir         return static_cast<sal_Int32>(nColor);
1246cdf0e10cSrcweir     }
1247cdf0e10cSrcweir 
getBackground()1248cdf0e10cSrcweir     sal_Int32 SAL_CALL AccessibleEditableTextPara::getBackground(  ) throw (::com::sun::star::uno::RuntimeException)
1249cdf0e10cSrcweir     {
1250cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1251cdf0e10cSrcweir 
1252cdf0e10cSrcweir         // #104444# Added to XAccessibleComponent interface
1253cdf0e10cSrcweir         Color aColor( Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor() );
1254cdf0e10cSrcweir 
1255cdf0e10cSrcweir         // the background is transparent
1256cdf0e10cSrcweir         aColor.SetTransparency( 0xFF);
1257cdf0e10cSrcweir 
1258cdf0e10cSrcweir         return static_cast<sal_Int32>( aColor.GetColor() );
1259cdf0e10cSrcweir     }
1260cdf0e10cSrcweir 
1261cdf0e10cSrcweir     // XAccessibleText
getCaretPosition()1262cdf0e10cSrcweir     sal_Int32 SAL_CALL AccessibleEditableTextPara::getCaretPosition() throw (uno::RuntimeException)
1263cdf0e10cSrcweir     {
1264cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1265cdf0e10cSrcweir 
1266cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
1267cdf0e10cSrcweir 
1268cdf0e10cSrcweir         if( !HaveEditView() )
1269cdf0e10cSrcweir             return -1;
1270cdf0e10cSrcweir 
1271cdf0e10cSrcweir         ESelection aSelection;
1272cdf0e10cSrcweir         if( GetEditViewForwarder().GetSelection( aSelection ) &&
1273cdf0e10cSrcweir             GetParagraphIndex() == aSelection.nEndPara )
1274cdf0e10cSrcweir         {
1275cdf0e10cSrcweir             // caret is always nEndPara,nEndPos
1276a6ca19dcSDamjan Jovanovic             EBulletInfo aBulletInfo = GetTextForwarder().GetBulletInfo( GetParagraphIndex() );
12779b8096d0SSteve Yin             if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND &&
12789b8096d0SSteve Yin                 aBulletInfo.bVisible &&
12799b8096d0SSteve Yin                 aBulletInfo.nType != SVX_NUM_BITMAP )
12809b8096d0SSteve Yin             {
12819b8096d0SSteve Yin                 sal_Int32 nBulletLen = aBulletInfo.aText.Len();
12829b8096d0SSteve Yin                 if( aSelection.nEndPos - nBulletLen >= 0 )
12839b8096d0SSteve Yin                     return aSelection.nEndPos - nBulletLen;
12849b8096d0SSteve Yin             }
1285cdf0e10cSrcweir             return aSelection.nEndPos;
1286cdf0e10cSrcweir         }
1287cdf0e10cSrcweir 
1288cdf0e10cSrcweir         // not within this paragraph
1289cdf0e10cSrcweir         return -1;
1290cdf0e10cSrcweir     }
1291cdf0e10cSrcweir 
setCaretPosition(sal_Int32 nIndex)1292cdf0e10cSrcweir     sal_Bool SAL_CALL AccessibleEditableTextPara::setCaretPosition( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1293cdf0e10cSrcweir     {
1294cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1295cdf0e10cSrcweir 
1296cdf0e10cSrcweir         return setSelection(nIndex, nIndex);
1297cdf0e10cSrcweir     }
1298cdf0e10cSrcweir 
getCharacter(sal_Int32 nIndex)1299cdf0e10cSrcweir     sal_Unicode SAL_CALL AccessibleEditableTextPara::getCharacter( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1300cdf0e10cSrcweir     {
1301cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1302cdf0e10cSrcweir 
1303cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
1304cdf0e10cSrcweir 
1305cdf0e10cSrcweir         DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1306cdf0e10cSrcweir                    "AccessibleEditableTextPara::getCharacter: index value overflow");
1307cdf0e10cSrcweir 
1308cdf0e10cSrcweir         return OCommonAccessibleText::getCharacter( nIndex );
1309cdf0e10cSrcweir     }
getAttributeNames()13109b8096d0SSteve Yin     static uno::Sequence< ::rtl::OUString > getAttributeNames()
13119b8096d0SSteve Yin     {
13129b8096d0SSteve Yin         static uno::Sequence< ::rtl::OUString >* pNames = NULL;
13139b8096d0SSteve Yin 
13149b8096d0SSteve Yin         if( pNames == NULL )
13159b8096d0SSteve Yin         {
13169b8096d0SSteve Yin             uno::Sequence< ::rtl::OUString >* pSeq = new uno::Sequence< ::rtl::OUString >( 21 );
13179b8096d0SSteve Yin             ::rtl::OUString* pStrings = pSeq->getArray();
13189b8096d0SSteve Yin             sal_Int32 i = 0;
13199b8096d0SSteve Yin     #define STR(x) pStrings[i++] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(x))
13209b8096d0SSteve Yin             //STR("CharBackColor");
13219b8096d0SSteve Yin             STR("CharColor");
13229b8096d0SSteve Yin       STR("CharContoured");
13239b8096d0SSteve Yin       STR("CharEmphasis");
13249b8096d0SSteve Yin             STR("CharEscapement");
13259b8096d0SSteve Yin             STR("CharFontName");
13269b8096d0SSteve Yin             STR("CharHeight");
13279b8096d0SSteve Yin             STR("CharPosture");
13289b8096d0SSteve Yin       STR("CharShadowed");
13299b8096d0SSteve Yin             STR("CharStrikeout");
13309b8096d0SSteve Yin             STR("CharUnderline");
13319b8096d0SSteve Yin             STR("CharUnderlineColor");
13329b8096d0SSteve Yin             STR("CharWeight");
13339b8096d0SSteve Yin                 STR("NumberingLevel");
13349b8096d0SSteve Yin             STR("NumberingRules");
13359b8096d0SSteve Yin             STR("ParaAdjust");
13369b8096d0SSteve Yin             STR("ParaBottomMargin");
13379b8096d0SSteve Yin             STR("ParaFirstLineIndent");
13389b8096d0SSteve Yin             STR("ParaLeftMargin");
13399b8096d0SSteve Yin             STR("ParaLineSpacing");
13409b8096d0SSteve Yin             STR("ParaRightMargin");
13419b8096d0SSteve Yin             STR("ParaTabStops");
13429b8096d0SSteve Yin     #undef STR
13439b8096d0SSteve Yin             DBG_ASSERT( i == pSeq->getLength(), "Please adjust length" );
13449b8096d0SSteve Yin             if( i != pSeq->getLength() )
13459b8096d0SSteve Yin                 pSeq->realloc( i );
13469b8096d0SSteve Yin             pNames = pSeq;
13479b8096d0SSteve Yin         }
13489b8096d0SSteve Yin         return *pNames;
13499b8096d0SSteve Yin     }
13509b8096d0SSteve Yin     struct IndexCompare
13519b8096d0SSteve Yin     {
13529b8096d0SSteve Yin         const PropertyValue* pValues;
IndexCompareaccessibility::IndexCompare13539b8096d0SSteve Yin         IndexCompare( const PropertyValue* pVals ) : pValues(pVals) {}
operator ()accessibility::IndexCompare13549b8096d0SSteve Yin         bool operator() ( const sal_Int32& a, const sal_Int32& b ) const
13559b8096d0SSteve Yin         {
13569b8096d0SSteve Yin             return (pValues[a].Name < pValues[b].Name) ? true : false;
13579b8096d0SSteve Yin         }
13589b8096d0SSteve Yin     };
13599b8096d0SSteve Yin 
GetFieldTypeNameAtIndex(sal_Int32 nIndex)13609b8096d0SSteve Yin     String AccessibleEditableTextPara::GetFieldTypeNameAtIndex(sal_Int32 nIndex)
13619b8096d0SSteve Yin     {
13629b8096d0SSteve Yin         String strFldType;
13639b8096d0SSteve Yin         SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder();
13649b8096d0SSteve Yin         //For field object info
13659b8096d0SSteve Yin         sal_Int32 nParaIndex = GetParagraphIndex();
13669b8096d0SSteve Yin         sal_Int32 nAllFieldLen = 0;
136772cd434aSDamjan Jovanovic         sal_Int32 nField = rCacheTF.GetFieldCount(nParaIndex), nFoundFieldIndex = -1;
13689b8096d0SSteve Yin         EFieldInfo ree;
13699b8096d0SSteve Yin         sal_Int32  reeBegin, reeEnd;
13709b8096d0SSteve Yin         sal_Int32 nFieldType = -1;
13719b8096d0SSteve Yin         for(sal_uInt16 j = 0; j < nField; j++)
13729b8096d0SSteve Yin         {
1373c67fa79cSDamjan Jovanovic             ree = rCacheTF.GetFieldInfo(nParaIndex, j);
13749b8096d0SSteve Yin             reeBegin  = ree.aPosition.nIndex + nAllFieldLen;
13759b8096d0SSteve Yin             reeEnd = reeBegin + ree.aCurrentText.Len();
13769b8096d0SSteve Yin             nAllFieldLen += (ree.aCurrentText.Len() - 1);
13779b8096d0SSteve Yin             if( reeBegin > nIndex )
13789b8096d0SSteve Yin             {
13799b8096d0SSteve Yin                 break;
13809b8096d0SSteve Yin             }
13819b8096d0SSteve Yin             if(  nIndex >= reeBegin && nIndex < reeEnd )
13829b8096d0SSteve Yin             {
13839b8096d0SSteve Yin                 nFoundFieldIndex = j;
13849b8096d0SSteve Yin                 break;
13859b8096d0SSteve Yin             }
13869b8096d0SSteve Yin         }
13879b8096d0SSteve Yin         if( nFoundFieldIndex >= 0  )
13889b8096d0SSteve Yin         {
13899b8096d0SSteve Yin             // So we get a field, check its type now.
13909b8096d0SSteve Yin             nFieldType = ree.pFieldItem->GetField()->GetClassId() ;
13919b8096d0SSteve Yin         }
13929b8096d0SSteve Yin         switch(nFieldType)
13939b8096d0SSteve Yin         {
13949b8096d0SSteve Yin         case SVX_DATEFIELD:
13959b8096d0SSteve Yin             {
13969b8096d0SSteve Yin                 const SvxDateField* pDateField = static_cast< const SvxDateField* >(ree.pFieldItem->GetField());
13979b8096d0SSteve Yin                 if (pDateField)
13989b8096d0SSteve Yin                 {
13999b8096d0SSteve Yin                     if (pDateField->GetType() == SVXDATETYPE_FIX)
14009b8096d0SSteve Yin                         strFldType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("date (fixed)"));
14019b8096d0SSteve Yin                     else if (pDateField->GetType() == SVXDATETYPE_VAR)
14029b8096d0SSteve Yin                         strFldType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("date (variable)"));
14039b8096d0SSteve Yin                 }
14049b8096d0SSteve Yin             }
14059b8096d0SSteve Yin             break;
14069b8096d0SSteve Yin         case SVX_PAGEFIELD:
14079b8096d0SSteve Yin             strFldType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("page-number"));
14089b8096d0SSteve Yin             break;
14090deba7fbSSteve Yin         //support the sheet name & pages fields
14109b8096d0SSteve Yin         case SVX_PAGESFIELD:
14119b8096d0SSteve Yin                 strFldType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("page-count"));
14129b8096d0SSteve Yin             break;
14139b8096d0SSteve Yin         case SVX_TABLEFIELD:
14149b8096d0SSteve Yin                 strFldType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sheet-name"));
14159b8096d0SSteve Yin             break;
14160deba7fbSSteve Yin         //End
14179b8096d0SSteve Yin         case SVX_TIMEFIELD:
14189b8096d0SSteve Yin             strFldType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("time"));
14199b8096d0SSteve Yin             break;
14209b8096d0SSteve Yin         case SVX_EXT_TIMEFIELD:
14219b8096d0SSteve Yin             {
14229b8096d0SSteve Yin                 const SvxExtTimeField* pTimeField = static_cast< const SvxExtTimeField* >(ree.pFieldItem->GetField());
14239b8096d0SSteve Yin                 if (pTimeField)
14249b8096d0SSteve Yin                 {
14259b8096d0SSteve Yin                     if (pTimeField->GetType() == SVXTIMETYPE_FIX)
14269b8096d0SSteve Yin                         strFldType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("time (fixed)"));
14279b8096d0SSteve Yin                     else if (pTimeField->GetType() == SVXTIMETYPE_VAR)
14289b8096d0SSteve Yin                         strFldType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("time (variable)"));
14299b8096d0SSteve Yin                 }
14309b8096d0SSteve Yin             }
14319b8096d0SSteve Yin             break;
14329b8096d0SSteve Yin         case SVX_AUTHORFIELD:
14339b8096d0SSteve Yin             strFldType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("author"));
14349b8096d0SSteve Yin             break;
14359b8096d0SSteve Yin         case SVX_EXT_FILEFIELD:
14369b8096d0SSteve Yin         case SVX_FILEFIELD:
14379b8096d0SSteve Yin             strFldType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file name"));
14389b8096d0SSteve Yin         default:
14399b8096d0SSteve Yin             break;
14409b8096d0SSteve Yin         }
14419b8096d0SSteve Yin         return strFldType;
14429b8096d0SSteve Yin     }
1443cdf0e10cSrcweir 
getCharacterAttributes(sal_Int32 nIndex,const::com::sun::star::uno::Sequence<::rtl::OUString> & rRequestedAttributes)1444cdf0e10cSrcweir     uno::Sequence< beans::PropertyValue > SAL_CALL AccessibleEditableTextPara::getCharacterAttributes( sal_Int32 nIndex, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rRequestedAttributes ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1445cdf0e10cSrcweir     {
1446cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1447cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
1448cdf0e10cSrcweir 
1449283563b9SJohn Bampton         //Skip the bullet range to ignore the bullet text
14509b8096d0SSteve Yin         SvxTextForwarder& rCacheTF = GetTextForwarder();
1451a6ca19dcSDamjan Jovanovic         EBulletInfo aBulletInfo = rCacheTF.GetBulletInfo( GetParagraphIndex() );
14529b8096d0SSteve Yin         if (aBulletInfo.bVisible)
14539b8096d0SSteve Yin             nIndex += aBulletInfo.aText.Len();
14549b8096d0SSteve Yin         if (nIndex != 0 && nIndex >= getCharacterCount())
14559b8096d0SSteve Yin             nIndex = getCharacterCount()-1;
14569b8096d0SSteve Yin         //
14579b8096d0SSteve Yin         if (nIndex != 0)
1458cdf0e10cSrcweir             CheckIndex(nIndex); // may throw IndexOutOfBoundsException
1459cdf0e10cSrcweir 
14609b8096d0SSteve Yin         bool bSupplementalMode = false;
14619b8096d0SSteve Yin         uno::Sequence< ::rtl::OUString > aPropertyNames = rRequestedAttributes;
14629b8096d0SSteve Yin         if (aPropertyNames.getLength() == 0)
14639b8096d0SSteve Yin         {
14649b8096d0SSteve Yin             bSupplementalMode = true;
14659b8096d0SSteve Yin             aPropertyNames = getAttributeNames();
14669b8096d0SSteve Yin         }
146749333635SJohn Bampton         // get default attributes...
14689b8096d0SSteve Yin         ::comphelper::SequenceAsHashMap aPropHashMap( getDefaultAttributes( aPropertyNames ) );
1469cdf0e10cSrcweir 
1470cdf0e10cSrcweir         // ... and override them with the direct attributes from the specific position
14719b8096d0SSteve Yin         uno::Sequence< beans::PropertyValue > aRunAttribs( getRunAttributes( nIndex, aPropertyNames ) );
1472cdf0e10cSrcweir         sal_Int32 nRunAttribs = aRunAttribs.getLength();
1473cdf0e10cSrcweir         const beans::PropertyValue *pRunAttrib = aRunAttribs.getConstArray();
1474cdf0e10cSrcweir         for (sal_Int32 k = 0;  k < nRunAttribs;  ++k)
1475cdf0e10cSrcweir         {
1476cdf0e10cSrcweir             const beans::PropertyValue &rRunAttrib = pRunAttrib[k];
1477cdf0e10cSrcweir             aPropHashMap[ rRunAttrib.Name ] = rRunAttrib.Value; //!! should not only be the value !!
1478cdf0e10cSrcweir         }
1479cdf0e10cSrcweir #ifdef TL_DEBUG
1480cdf0e10cSrcweir         {
1481cdf0e10cSrcweir             uno::Sequence< rtl::OUString > aNames(1);
1482cdf0e10cSrcweir             aNames.getArray()[0] = rtl::OUString::createFromAscii("CharHeight");
1483cdf0e10cSrcweir             const rtl::OUString *pNames = aNames.getConstArray();
1484cdf0e10cSrcweir             const uno::Sequence< beans::PropertyValue > aAttribs( getRunAttributes( nIndex, aNames ) );
1485cdf0e10cSrcweir             const beans::PropertyValue *pAttribs = aAttribs.getConstArray();
1486cdf0e10cSrcweir             double d1 = -1.0;
1487cdf0e10cSrcweir             float  f1 = -1.0;
1488cdf0e10cSrcweir             if (aAttribs.getLength())
1489cdf0e10cSrcweir             {
1490cdf0e10cSrcweir                 uno::Any aAny( pAttribs[0].Value );
1491cdf0e10cSrcweir                 aAny >>= d1;
1492cdf0e10cSrcweir                 aAny >>= f1;
1493cdf0e10cSrcweir             }
1494cdf0e10cSrcweir             int i = 3;
1495cdf0e10cSrcweir         }
1496cdf0e10cSrcweir #endif
1497cdf0e10cSrcweir 
1498cdf0e10cSrcweir         // get resulting sequence
1499cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > aRes;
1500cdf0e10cSrcweir         aPropHashMap >> aRes;
1501cdf0e10cSrcweir 
1502cdf0e10cSrcweir         // since SequenceAsHashMap ignores property handles and property state
1503cdf0e10cSrcweir         // we have to restore the property state here (property handles are
1504cdf0e10cSrcweir         // of no use to the accessibility API).
1505cdf0e10cSrcweir         sal_Int32 nRes = aRes.getLength();
1506cdf0e10cSrcweir         beans::PropertyValue *pRes = aRes.getArray();
1507cdf0e10cSrcweir         for (sal_Int32 i = 0;  i < nRes;  ++i)
1508cdf0e10cSrcweir         {
1509cdf0e10cSrcweir             beans::PropertyValue &rRes = pRes[i];
1510cdf0e10cSrcweir             sal_Bool bIsDirectVal = sal_False;
1511cdf0e10cSrcweir             for (sal_Int32 k = 0;  k < nRunAttribs && !bIsDirectVal;  ++k)
1512cdf0e10cSrcweir             {
1513cdf0e10cSrcweir                 if (rRes.Name == pRunAttrib[k].Name)
1514cdf0e10cSrcweir                     bIsDirectVal = sal_True;
1515cdf0e10cSrcweir             }
1516cdf0e10cSrcweir             rRes.Handle = -1;
1517cdf0e10cSrcweir             rRes.State  = bIsDirectVal ? PropertyState_DIRECT_VALUE : PropertyState_DEFAULT_VALUE;
1518cdf0e10cSrcweir         }
15199b8096d0SSteve Yin         if( bSupplementalMode )
15209b8096d0SSteve Yin         {
15219b8096d0SSteve Yin             _correctValues( nIndex, aRes );
15229b8096d0SSteve Yin             // NumberingPrefix
15239b8096d0SSteve Yin             nRes = aRes.getLength();
15249b8096d0SSteve Yin             aRes.realloc( nRes + 1 );
15259b8096d0SSteve Yin             pRes = aRes.getArray();
15269b8096d0SSteve Yin             beans::PropertyValue &rRes = pRes[nRes];
15279b8096d0SSteve Yin             rRes.Name = rtl::OUString::createFromAscii("NumberingPrefix");
15289b8096d0SSteve Yin             ::rtl::OUString numStr;
15299b8096d0SSteve Yin             if (aBulletInfo.nType != SVX_NUM_CHAR_SPECIAL && aBulletInfo.nType != SVX_NUM_BITMAP)
15309b8096d0SSteve Yin                 numStr = (::rtl::OUString)aBulletInfo.aText;
15319b8096d0SSteve Yin             rRes.Value <<= numStr;
15329b8096d0SSteve Yin             rRes.Handle = -1;
15339b8096d0SSteve Yin             rRes.State = PropertyState_DIRECT_VALUE;
15349b8096d0SSteve Yin             //For field object.
15359b8096d0SSteve Yin             String strFieldType = GetFieldTypeNameAtIndex(nIndex);
15369b8096d0SSteve Yin             if (strFieldType.Len() > 0)
15379b8096d0SSteve Yin             {
15389b8096d0SSteve Yin                 nRes = aRes.getLength();
15399b8096d0SSteve Yin                 aRes.realloc( nRes + 1 );
15409b8096d0SSteve Yin                 pRes = aRes.getArray();
15419b8096d0SSteve Yin                 beans::PropertyValue &rResField = pRes[nRes];
15429b8096d0SSteve Yin                 beans::PropertyValue aFieldType;
15439b8096d0SSteve Yin                 rResField.Name = rtl::OUString::createFromAscii("FieldType");
15449b8096d0SSteve Yin                 rResField.Value <<= rtl::OUString(strFieldType.ToLowerAscii());
15459b8096d0SSteve Yin                 rResField.Handle = -1;
15469b8096d0SSteve Yin                 rResField.State = PropertyState_DIRECT_VALUE;
15479b8096d0SSteve Yin         }
15489b8096d0SSteve Yin         //sort property values
15499b8096d0SSteve Yin         // build sorted index array
15509b8096d0SSteve Yin         sal_Int32 nLength = aRes.getLength();
15519b8096d0SSteve Yin         const beans::PropertyValue* pPairs = aRes.getConstArray();
15529b8096d0SSteve Yin         sal_Int32* pIndices = new sal_Int32[nLength];
15539b8096d0SSteve Yin         sal_Int32 i = 0;
15549b8096d0SSteve Yin         for( i = 0; i < nLength; i++ )
15559b8096d0SSteve Yin             pIndices[i] = i;
15569b8096d0SSteve Yin         sort( &pIndices[0], &pIndices[nLength], IndexCompare(pPairs) );
155707a3d7f1SPedro Giffuni         // create sorted sequences according to index array
15589b8096d0SSteve Yin         uno::Sequence<beans::PropertyValue> aNewValues( nLength );
15599b8096d0SSteve Yin         beans::PropertyValue* pNewValues = aNewValues.getArray();
15609b8096d0SSteve Yin         for( i = 0; i < nLength; i++ )
15619b8096d0SSteve Yin         {
15629b8096d0SSteve Yin             pNewValues[i] = pPairs[pIndices[i]];
15639b8096d0SSteve Yin         }
15649b8096d0SSteve Yin         delete[] pIndices;
15659b8096d0SSteve Yin         //
15669b8096d0SSteve Yin         return aNewValues;
15679b8096d0SSteve Yin         }
1568cdf0e10cSrcweir         return aRes;
1569cdf0e10cSrcweir     }
1570cdf0e10cSrcweir 
getCharacterBounds(sal_Int32 nIndex)1571cdf0e10cSrcweir     awt::Rectangle SAL_CALL AccessibleEditableTextPara::getCharacterBounds( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1572cdf0e10cSrcweir     {
1573cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1574cdf0e10cSrcweir 
1575cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
1576cdf0e10cSrcweir 
1577cdf0e10cSrcweir         DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1578cdf0e10cSrcweir                    "AccessibleEditableTextPara::getCharacterBounds: index value overflow");
1579cdf0e10cSrcweir 
1580cdf0e10cSrcweir         // #108900# Have position semantics now for nIndex, as
1581cdf0e10cSrcweir         // one-past-the-end values are legal, too.
1582cdf0e10cSrcweir         CheckPosition( nIndex );
1583cdf0e10cSrcweir 
1584cdf0e10cSrcweir         SvxTextForwarder& rCacheTF = GetTextForwarder();
1585b5969576SDamjan Jovanovic         Rectangle aRect = rCacheTF.GetCharBounds( GetParagraphIndex(), static_cast< sal_uInt16 >( nIndex ) );
1586cdf0e10cSrcweir 
1587cdf0e10cSrcweir         // convert to screen
1588cdf0e10cSrcweir         Rectangle aScreenRect = AccessibleEditableTextPara::LogicToPixel( aRect,
1589cdf0e10cSrcweir                                                                           rCacheTF.GetMapMode(),
1590cdf0e10cSrcweir                                                                           GetViewForwarder() );
1591cdf0e10cSrcweir         // #109864# offset from parent (paragraph), but in screen
1592cdf0e10cSrcweir         // coordinates. This makes sure the internal text offset in
1593cdf0e10cSrcweir         // the outline view forwarder gets cancelled out here
1594cdf0e10cSrcweir         awt::Rectangle aParaRect( getBounds() );
1595cdf0e10cSrcweir         aScreenRect.Move( -aParaRect.X, -aParaRect.Y );
1596cdf0e10cSrcweir 
1597cdf0e10cSrcweir         // offset from shape/cell
1598cdf0e10cSrcweir         Point aOffset = GetEEOffset();
1599cdf0e10cSrcweir 
1600cdf0e10cSrcweir         return awt::Rectangle( aScreenRect.Left() + aOffset.X(),
1601cdf0e10cSrcweir                                aScreenRect.Top() + aOffset.Y(),
1602cdf0e10cSrcweir                                aScreenRect.GetSize().Width(),
1603cdf0e10cSrcweir                                aScreenRect.GetSize().Height() );
1604cdf0e10cSrcweir     }
1605cdf0e10cSrcweir 
getCharacterCount()1606cdf0e10cSrcweir     sal_Int32 SAL_CALL AccessibleEditableTextPara::getCharacterCount() throw (uno::RuntimeException)
1607cdf0e10cSrcweir     {
1608cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1609cdf0e10cSrcweir 
1610cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
1611cdf0e10cSrcweir 
1612cdf0e10cSrcweir         DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1613cdf0e10cSrcweir                    "AccessibleEditableTextPara::getCharacterCount: index value overflow");
1614cdf0e10cSrcweir 
1615cdf0e10cSrcweir         return OCommonAccessibleText::getCharacterCount();
1616cdf0e10cSrcweir     }
1617cdf0e10cSrcweir 
getIndexAtPoint(const awt::Point & rPoint)1618cdf0e10cSrcweir     sal_Int32 SAL_CALL AccessibleEditableTextPara::getIndexAtPoint( const awt::Point& rPoint ) throw (uno::RuntimeException)
1619cdf0e10cSrcweir     {
1620cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1621cdf0e10cSrcweir 
1622cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
16239b8096d0SSteve Yin     if ((rPoint.X <= 0) && (rPoint.Y <= 0))
16249b8096d0SSteve Yin         return 0;
16256a4e5455SDamjan Jovanovic         sal_uInt32 nPara;
16266a4e5455SDamjan Jovanovic         sal_uInt16 nIndex;
1627cdf0e10cSrcweir 
1628cdf0e10cSrcweir         // offset from surrounding cell/shape
1629cdf0e10cSrcweir         Point aOffset( GetEEOffset() );
1630cdf0e10cSrcweir         Point aPoint( rPoint.X - aOffset.X(), rPoint.Y - aOffset.Y() );
1631cdf0e10cSrcweir 
1632cdf0e10cSrcweir         // convert to logical coordinates
1633cdf0e10cSrcweir         SvxTextForwarder& rCacheTF = GetTextForwarder();
1634cdf0e10cSrcweir         Point aLogPoint( GetViewForwarder().PixelToLogic( aPoint, rCacheTF.GetMapMode() ) );
1635cdf0e10cSrcweir 
1636cdf0e10cSrcweir         // re-offset to parent (paragraph)
1637f6b418d9SDamjan Jovanovic         Rectangle aParaRect = rCacheTF.GetParaBounds( GetParagraphIndex() );
1638cdf0e10cSrcweir         aLogPoint.Move( aParaRect.Left(), aParaRect.Top() );
1639cdf0e10cSrcweir 
1640cdf0e10cSrcweir         if( rCacheTF.GetIndexAtPoint( aLogPoint, nPara, nIndex ) &&
1641cdf0e10cSrcweir             GetParagraphIndex() == nPara )
1642cdf0e10cSrcweir         {
1643cdf0e10cSrcweir             // #102259# Double-check if we're _really_ on the given character
1644cdf0e10cSrcweir             try
1645cdf0e10cSrcweir             {
1646cdf0e10cSrcweir                 awt::Rectangle aRect1( getCharacterBounds(nIndex) );
1647cdf0e10cSrcweir                 Rectangle aRect2( aRect1.X, aRect1.Y,
1648cdf0e10cSrcweir                                   aRect1.Width + aRect1.X, aRect1.Height + aRect1.Y );
1649cdf0e10cSrcweir                 if( aRect2.IsInside( Point( rPoint.X, rPoint.Y ) ) )
1650cdf0e10cSrcweir                     return nIndex;
1651cdf0e10cSrcweir                 else
1652cdf0e10cSrcweir                     return -1;
1653cdf0e10cSrcweir             }
1654cdf0e10cSrcweir             catch( const lang::IndexOutOfBoundsException& )
1655cdf0e10cSrcweir             {
1656cdf0e10cSrcweir                 // #103927# Don't throw for invalid nIndex values
1657cdf0e10cSrcweir                 return -1;
1658cdf0e10cSrcweir             }
1659cdf0e10cSrcweir         }
1660cdf0e10cSrcweir         else
1661cdf0e10cSrcweir         {
1662cdf0e10cSrcweir             // not within our paragraph
1663cdf0e10cSrcweir             return -1;
1664cdf0e10cSrcweir         }
1665cdf0e10cSrcweir     }
1666cdf0e10cSrcweir 
getSelectedText()1667cdf0e10cSrcweir     ::rtl::OUString SAL_CALL AccessibleEditableTextPara::getSelectedText() throw (uno::RuntimeException)
1668cdf0e10cSrcweir     {
1669cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1670cdf0e10cSrcweir 
1671cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
1672cdf0e10cSrcweir 
1673cdf0e10cSrcweir         DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1674cdf0e10cSrcweir                    "AccessibleEditableTextPara::getSelectedText: index value overflow");
1675cdf0e10cSrcweir 
1676cdf0e10cSrcweir         if( !HaveEditView() )
1677cdf0e10cSrcweir             return ::rtl::OUString();
1678cdf0e10cSrcweir 
1679cdf0e10cSrcweir         return OCommonAccessibleText::getSelectedText();
1680cdf0e10cSrcweir     }
1681cdf0e10cSrcweir 
getSelectionStart()1682cdf0e10cSrcweir     sal_Int32 SAL_CALL AccessibleEditableTextPara::getSelectionStart() throw (uno::RuntimeException)
1683cdf0e10cSrcweir     {
1684cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1685cdf0e10cSrcweir 
1686cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
1687cdf0e10cSrcweir 
1688cdf0e10cSrcweir         DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1689cdf0e10cSrcweir                    "AccessibleEditableTextPara::getSelectionStart: index value overflow");
1690cdf0e10cSrcweir 
1691cdf0e10cSrcweir         if( !HaveEditView() )
1692cdf0e10cSrcweir             return -1;
1693cdf0e10cSrcweir 
1694cdf0e10cSrcweir         return OCommonAccessibleText::getSelectionStart();
1695cdf0e10cSrcweir     }
1696cdf0e10cSrcweir 
getSelectionEnd()1697cdf0e10cSrcweir     sal_Int32 SAL_CALL AccessibleEditableTextPara::getSelectionEnd() throw (uno::RuntimeException)
1698cdf0e10cSrcweir     {
1699cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1700cdf0e10cSrcweir 
1701cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
1702cdf0e10cSrcweir 
1703cdf0e10cSrcweir         DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1704cdf0e10cSrcweir                    "AccessibleEditableTextPara::getSelectionEnd: index value overflow");
1705cdf0e10cSrcweir 
1706cdf0e10cSrcweir         if( !HaveEditView() )
1707cdf0e10cSrcweir             return -1;
1708cdf0e10cSrcweir 
1709cdf0e10cSrcweir         return OCommonAccessibleText::getSelectionEnd();
1710cdf0e10cSrcweir     }
1711cdf0e10cSrcweir 
setSelection(sal_Int32 nStartIndex,sal_Int32 nEndIndex)1712cdf0e10cSrcweir     sal_Bool SAL_CALL AccessibleEditableTextPara::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1713cdf0e10cSrcweir     {
1714cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1715cdf0e10cSrcweir 
1716cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
1717cdf0e10cSrcweir 
1718cdf0e10cSrcweir         DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1719cdf0e10cSrcweir                    "AccessibleEditableTextPara::setSelection: paragraph index value overflow");
1720cdf0e10cSrcweir 
1721cdf0e10cSrcweir         CheckRange(nStartIndex, nEndIndex);
1722cdf0e10cSrcweir 
1723cdf0e10cSrcweir         try
1724cdf0e10cSrcweir         {
1725cdf0e10cSrcweir             SvxEditViewForwarder& rCacheVF = GetEditViewForwarder( sal_True );
1726cdf0e10cSrcweir             return rCacheVF.SetSelection( MakeSelection(nStartIndex, nEndIndex) );
1727cdf0e10cSrcweir         }
1728cdf0e10cSrcweir         catch( const uno::RuntimeException& )
1729cdf0e10cSrcweir         {
1730cdf0e10cSrcweir             return sal_False;
1731cdf0e10cSrcweir         }
1732cdf0e10cSrcweir     }
1733cdf0e10cSrcweir 
getText()1734cdf0e10cSrcweir     ::rtl::OUString SAL_CALL AccessibleEditableTextPara::getText() throw (uno::RuntimeException)
1735cdf0e10cSrcweir     {
1736cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1737cdf0e10cSrcweir 
1738cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
1739cdf0e10cSrcweir 
1740cdf0e10cSrcweir         DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1741cdf0e10cSrcweir                    "AccessibleEditableTextPara::getText: paragraph index value overflow");
1742cdf0e10cSrcweir 
1743cdf0e10cSrcweir         return OCommonAccessibleText::getText();
1744cdf0e10cSrcweir     }
1745cdf0e10cSrcweir 
getTextRange(sal_Int32 nStartIndex,sal_Int32 nEndIndex)1746cdf0e10cSrcweir     ::rtl::OUString SAL_CALL AccessibleEditableTextPara::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1747cdf0e10cSrcweir     {
1748cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
1749cdf0e10cSrcweir 
1750cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
1751cdf0e10cSrcweir 
1752cdf0e10cSrcweir         DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
1753cdf0e10cSrcweir                    "AccessibleEditableTextPara::getTextRange: paragraph index value overflow");
1754cdf0e10cSrcweir 
1755cdf0e10cSrcweir         return OCommonAccessibleText::getTextRange(nStartIndex, nEndIndex);
1756cdf0e10cSrcweir     }
_correctValues(const sal_Int32,uno::Sequence<PropertyValue> & rValues)1757a16d9e18SPavel Janík     void AccessibleEditableTextPara::_correctValues( const sal_Int32 /* nIndex */,
17589b8096d0SSteve Yin                                            uno::Sequence< PropertyValue >& rValues)
17599b8096d0SSteve Yin     {
17609b8096d0SSteve Yin         SvxTextForwarder& rCacheTF = GetTextForwarder();
17619b8096d0SSteve Yin         sal_Int32 nRes = rValues.getLength();
17629b8096d0SSteve Yin         beans::PropertyValue *pRes = rValues.getArray();
17639b8096d0SSteve Yin         for (sal_Int32 i = 0;  i < nRes;  ++i)
17649b8096d0SSteve Yin         {
17659b8096d0SSteve Yin             beans::PropertyValue &rRes = pRes[i];
17669b8096d0SSteve Yin             // Char color
17679b8096d0SSteve Yin             if (rRes.Name.compareTo(::rtl::OUString::createFromAscii("CharColor"))==0)
17689b8096d0SSteve Yin             {
17699b8096d0SSteve Yin                 uno::Any &anyChar = rRes.Value;
1770b98ff797SHerbert Dürr                 sal_uInt32 crChar = static_cast<sal_uInt32>( reinterpret_cast<sal_uIntPtr>(anyChar.pReserved));
17719b8096d0SSteve Yin                 if (COL_AUTO == crChar )
17729b8096d0SSteve Yin                 {
17739b8096d0SSteve Yin                     uno::Reference< ::com::sun::star::accessibility::XAccessibleComponent > xComponent;
17749b8096d0SSteve Yin                     if (mxParent.is())
17759b8096d0SSteve Yin                     {
17769b8096d0SSteve Yin                         xComponent.set(mxParent,uno::UNO_QUERY);
17779b8096d0SSteve Yin                     }
17789b8096d0SSteve Yin                     else
17799b8096d0SSteve Yin                     {
17809b8096d0SSteve Yin                         xComponent.set(m_xAccInfo,uno::UNO_QUERY);
17819b8096d0SSteve Yin                     }
17829b8096d0SSteve Yin                     if (xComponent.is())
17839b8096d0SSteve Yin                     {
17849b8096d0SSteve Yin                         uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > xContext(xComponent,uno::UNO_QUERY);
17859b8096d0SSteve Yin                         if (xContext->getAccessibleRole() == AccessibleRole::SHAPE
17869b8096d0SSteve Yin                             || xContext->getAccessibleRole() == AccessibleRole::TABLE_CELL)
17879b8096d0SSteve Yin                         {
17889b8096d0SSteve Yin                             anyChar <<= COL_BLACK;
17899b8096d0SSteve Yin                         }
17909b8096d0SSteve Yin                         else
17919b8096d0SSteve Yin                         {
17929b8096d0SSteve Yin                             Color cr(xComponent->getBackground());
17939b8096d0SSteve Yin                             crChar = cr.IsDark() ? COL_WHITE : COL_BLACK;
17949b8096d0SSteve Yin                             anyChar <<= crChar;
17959b8096d0SSteve Yin                         }
17969b8096d0SSteve Yin                     }
17979b8096d0SSteve Yin                 }
17989b8096d0SSteve Yin                 continue;
17999b8096d0SSteve Yin             }
18009b8096d0SSteve Yin             // Underline
18019b8096d0SSteve Yin             if(rRes.Name.compareTo(::rtl::OUString::createFromAscii("CharUnderline"))==0)
18029b8096d0SSteve Yin             {
18039b8096d0SSteve Yin                 /*
18049b8096d0SSteve Yin                 // MT: Implement XAccessibleTextMarkup, mark with TextMarkupType::SPELLCHECK. This way done in SW.
18059b8096d0SSteve Yin                 if (IsCurrentEditorEnableAutoSpell( mxParent ))
18069b8096d0SSteve Yin                 {
18079b8096d0SSteve Yin                     try
18089b8096d0SSteve Yin                     {
18099b8096d0SSteve Yin                         SvxEditViewForwarder& rCacheVF = GetEditViewForwarder( sal_False );
18109b8096d0SSteve Yin                         sal_Bool bWrong = rCacheVF.IsWrongSpelledWordAtPos( GetParagraphIndex(), nIndex );
18119b8096d0SSteve Yin                         if ( bWrong )
18129b8096d0SSteve Yin                         {
18139b8096d0SSteve Yin                             uno::Any &anyUnderLine = pRes[9].Value;
18149b8096d0SSteve Yin                             // MT IA2: Not needed? sal_uInt16 crUnderLine = (sal_uInt16)(anyUnderLine.pReserved);
18159b8096d0SSteve Yin                             anyUnderLine <<= (sal_uInt16)UNDERLINE_WAVE;
18169b8096d0SSteve Yin                         }
18179b8096d0SSteve Yin                     }
18189b8096d0SSteve Yin                     catch( const uno::RuntimeException& )
18199b8096d0SSteve Yin                     {
18209b8096d0SSteve Yin                     }
18219b8096d0SSteve Yin                 }
18229b8096d0SSteve Yin                 */
18239b8096d0SSteve Yin                 continue;
18249b8096d0SSteve Yin             }
18259b8096d0SSteve Yin             // Underline color && Mis-spell
18269b8096d0SSteve Yin             if(rRes.Name.compareTo(::rtl::OUString::createFromAscii("CharUnderlineColor"))==0)
18279b8096d0SSteve Yin             {
18289b8096d0SSteve Yin                 uno::Any &anyCharUnderLine = rRes.Value;
1829b98ff797SHerbert Dürr                 sal_uInt32 crCharUnderLine = static_cast<sal_uInt32>( reinterpret_cast<sal_uIntPtr>( anyCharUnderLine.pReserved));
18309b8096d0SSteve Yin                 if (COL_AUTO == crCharUnderLine )
18319b8096d0SSteve Yin                 {
18329b8096d0SSteve Yin                     uno::Reference< ::com::sun::star::accessibility::XAccessibleComponent > xComponent;
18339b8096d0SSteve Yin                     if (mxParent.is())
18349b8096d0SSteve Yin                     {
18359b8096d0SSteve Yin                         xComponent.set(mxParent,uno::UNO_QUERY);
18369b8096d0SSteve Yin                     }
18379b8096d0SSteve Yin                     else
18389b8096d0SSteve Yin                     {
18399b8096d0SSteve Yin                         xComponent.set(m_xAccInfo,uno::UNO_QUERY);
18409b8096d0SSteve Yin                     }
18419b8096d0SSteve Yin                     if (xComponent.is())
18429b8096d0SSteve Yin                     {
18439b8096d0SSteve Yin                         uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > xContext(xComponent,uno::UNO_QUERY);
18449b8096d0SSteve Yin                         if (xContext->getAccessibleRole() == AccessibleRole::SHAPE
18459b8096d0SSteve Yin                             || xContext->getAccessibleRole() == AccessibleRole::TABLE_CELL)
18469b8096d0SSteve Yin                         {
18479b8096d0SSteve Yin                             anyCharUnderLine <<= COL_BLACK;
18489b8096d0SSteve Yin                         }
18499b8096d0SSteve Yin                         else
18509b8096d0SSteve Yin                         {
18519b8096d0SSteve Yin                             Color cr(xComponent->getBackground());
18529b8096d0SSteve Yin                             crCharUnderLine = cr.IsDark() ? COL_WHITE : COL_BLACK;
18539b8096d0SSteve Yin                             anyCharUnderLine <<= crCharUnderLine;
18549b8096d0SSteve Yin                         }
18559b8096d0SSteve Yin                     }
18569b8096d0SSteve Yin                 }
18579b8096d0SSteve Yin                 // MT: Implement XAccessibleTextMarkup, mark with TextMarkupType::SPELLCHECK. This way done in SW.
18589b8096d0SSteve Yin                 /*
18599b8096d0SSteve Yin                 if (IsCurrentEditorEnableAutoSpell( mxParent ))
18609b8096d0SSteve Yin                 {
18619b8096d0SSteve Yin                     try
18629b8096d0SSteve Yin                     {
18639b8096d0SSteve Yin                         SvxEditViewForwarder& rCacheVF = GetEditViewForwarder( sal_False );
18649b8096d0SSteve Yin                         sal_Bool bWrong = rCacheVF.IsWrongSpelledWordAtPos( GetParagraphIndex(), nIndex );
18659b8096d0SSteve Yin                         if ( bWrong )
18669b8096d0SSteve Yin                         {
18679b8096d0SSteve Yin                             uno::Any &anyUnderLineColor = rRes.Value;
18689b8096d0SSteve Yin                             // MT IA2: Not needed? sal_uInt16 crUnderLineColor = (sal_uInt16)(anyUnderLineColor.pReserved);
18699b8096d0SSteve Yin                             anyUnderLineColor <<= COL_LIGHTRED;
18709b8096d0SSteve Yin                         }
18719b8096d0SSteve Yin                     }
18729b8096d0SSteve Yin                     catch( const uno::RuntimeException& )
18739b8096d0SSteve Yin                     {
18749b8096d0SSteve Yin                     }
18759b8096d0SSteve Yin                 }
18769b8096d0SSteve Yin                 */
18779b8096d0SSteve Yin                 continue;
18789b8096d0SSteve Yin             }
18799b8096d0SSteve Yin             // NumberingLevel
18809b8096d0SSteve Yin             if(rRes.Name.compareTo(::rtl::OUString::createFromAscii("NumberingLevel"))==0)
18819b8096d0SSteve Yin             {
18829ec87cd3SDamjan Jovanovic                 const SvxNumBulletItem& rNumBullet = ( SvxNumBulletItem& )rCacheTF.GetParaAttribs(GetParagraphIndex()).Get(EE_PARA_NUMBULLET);
18839b8096d0SSteve Yin                 if(rNumBullet.GetNumRule()->GetLevelCount()==0)
18849b8096d0SSteve Yin                 {
18859b8096d0SSteve Yin                     rRes.Value <<= (sal_Int16)-1;
18869b8096d0SSteve Yin                     rRes.Handle = -1;
18879b8096d0SSteve Yin                     rRes.State = PropertyState_DIRECT_VALUE;
18889b8096d0SSteve Yin                 }
18899b8096d0SSteve Yin                 else
18909b8096d0SSteve Yin                 {
18919b8096d0SSteve Yin //                  SvxAccessibleTextPropertySet aPropSet( &GetEditSource(),
18929b8096d0SSteve Yin //                      ImplGetSvxCharAndParaPropertiesMap() );
18939b8096d0SSteve Yin                     // MT IA2 TODO: Check if this is the correct replacement for ImplGetSvxCharAndParaPropertiesMap
18949b8096d0SSteve Yin                     SvxAccessibleTextPropertySet aPropSet( &GetEditSource(), ImplGetSvxTextPortionSvxPropertySet() );
1895cdf0e10cSrcweir 
18969b8096d0SSteve Yin                     aPropSet.SetSelection( MakeSelection( 0, GetTextLen() ) );
18979b8096d0SSteve Yin                     rRes.Value = aPropSet._getPropertyValue( rRes.Name, mnParagraphIndex );
18989b8096d0SSteve Yin                     rRes.State = aPropSet._getPropertyState( rRes.Name, mnParagraphIndex );
18999b8096d0SSteve Yin                     rRes.Handle = -1;
19009b8096d0SSteve Yin                 }
19019b8096d0SSteve Yin                 continue;
19029b8096d0SSteve Yin             }
19039b8096d0SSteve Yin             // NumberingRules
19049b8096d0SSteve Yin             if(rRes.Name.compareTo(::rtl::OUString::createFromAscii("NumberingRules"))==0)
19059b8096d0SSteve Yin             {
19069ec87cd3SDamjan Jovanovic                 SfxItemSet aAttribs = rCacheTF.GetParaAttribs( GetParagraphIndex() );
19079b8096d0SSteve Yin                 sal_Bool bVis = ((const SfxUInt16Item&)aAttribs.Get( EE_PARA_BULLETSTATE )).GetValue() ? sal_True : sal_False;
19089b8096d0SSteve Yin                 if(bVis)
19099b8096d0SSteve Yin                 {
19109b8096d0SSteve Yin                     rRes.Value <<= (sal_Int16)-1;
19119b8096d0SSteve Yin                     rRes.Handle = -1;
19129b8096d0SSteve Yin                     rRes.State = PropertyState_DIRECT_VALUE;
19139b8096d0SSteve Yin                 }
19149b8096d0SSteve Yin                 else
19159b8096d0SSteve Yin                 {
19169b8096d0SSteve Yin                     // MT IA2 TODO: Check if this is the correct replacement for ImplGetSvxCharAndParaPropertiesMap
19179b8096d0SSteve Yin                     SvxAccessibleTextPropertySet aPropSet( &GetEditSource(), ImplGetSvxTextPortionSvxPropertySet() );
19189b8096d0SSteve Yin                     aPropSet.SetSelection( MakeSelection( 0, GetTextLen() ) );
19199b8096d0SSteve Yin                     rRes.Value = aPropSet._getPropertyValue( rRes.Name, mnParagraphIndex );
19209b8096d0SSteve Yin                     rRes.State = aPropSet._getPropertyState( rRes.Name, mnParagraphIndex );
19219b8096d0SSteve Yin                     rRes.Handle = -1;
19229b8096d0SSteve Yin                 }
19239b8096d0SSteve Yin                 continue;
19249b8096d0SSteve Yin             }
19259b8096d0SSteve Yin         }
19269b8096d0SSteve Yin     }
SkipField(sal_Int32 nIndex,sal_Bool bForward)19279b8096d0SSteve Yin     sal_Int32 AccessibleEditableTextPara::SkipField(sal_Int32 nIndex, sal_Bool bForward)
19289b8096d0SSteve Yin     {
19299b8096d0SSteve Yin         sal_Int32 nParaIndex = GetParagraphIndex();
19309b8096d0SSteve Yin         SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder();
19319b8096d0SSteve Yin         sal_Int32 nAllFieldLen = 0;
193272cd434aSDamjan Jovanovic         sal_Int32 nField = rCacheTF.GetFieldCount(nParaIndex), nFoundFieldIndex = -1;
19339b8096d0SSteve Yin         EFieldInfo ree;
19349b8096d0SSteve Yin         sal_Int32  reeBegin=0, reeEnd=0;
19359b8096d0SSteve Yin         for(sal_uInt16 j = 0; j < nField; j++)
19369b8096d0SSteve Yin         {
1937c67fa79cSDamjan Jovanovic             ree = rCacheTF.GetFieldInfo(nParaIndex, j);
19389b8096d0SSteve Yin             reeBegin  = ree.aPosition.nIndex + nAllFieldLen;
19399b8096d0SSteve Yin             reeEnd = reeBegin + ree.aCurrentText.Len();
19409b8096d0SSteve Yin             nAllFieldLen += (ree.aCurrentText.Len() - 1);
19419b8096d0SSteve Yin             if( reeBegin > nIndex )
19429b8096d0SSteve Yin             {
19439b8096d0SSteve Yin                 break;
19449b8096d0SSteve Yin             }
19459b8096d0SSteve Yin             if(  nIndex >= reeBegin && nIndex < reeEnd )
19469b8096d0SSteve Yin             {
19479b8096d0SSteve Yin                 if(ree.pFieldItem->GetField()->GetClassId() != SVX_URLFIELD)
19489b8096d0SSteve Yin                 {
19499b8096d0SSteve Yin                     nFoundFieldIndex = j;
19509b8096d0SSteve Yin                     break;
19519b8096d0SSteve Yin                 }
19529b8096d0SSteve Yin             }
19539b8096d0SSteve Yin         }
19549b8096d0SSteve Yin         if( nFoundFieldIndex >= 0  )
19559b8096d0SSteve Yin         {
19569b8096d0SSteve Yin             if( bForward )
19579b8096d0SSteve Yin                 return reeEnd - 1;
19589b8096d0SSteve Yin             else
19599b8096d0SSteve Yin                 return reeBegin;
19609b8096d0SSteve Yin         }
19619b8096d0SSteve Yin         return nIndex;
19629b8096d0SSteve Yin     }
ExtendByField(::com::sun::star::accessibility::TextSegment & Segment)19639b8096d0SSteve Yin     sal_Bool AccessibleEditableTextPara::ExtendByField( ::com::sun::star::accessibility::TextSegment& Segment )
19649b8096d0SSteve Yin     {
19659b8096d0SSteve Yin         sal_Int32 nParaIndex = GetParagraphIndex();
19669b8096d0SSteve Yin         SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder();
19679b8096d0SSteve Yin         sal_Int32 nAllFieldLen = 0;
196872cd434aSDamjan Jovanovic         sal_Int32 nField = rCacheTF.GetFieldCount(nParaIndex), nFoundFieldIndex = -1;
19699b8096d0SSteve Yin         EFieldInfo ree;
19709b8096d0SSteve Yin         sal_Int32  reeBegin=0, reeEnd=0;
19719b8096d0SSteve Yin         for(sal_uInt16 j = 0; j < nField; j++)
19729b8096d0SSteve Yin         {
1973c67fa79cSDamjan Jovanovic             ree = rCacheTF.GetFieldInfo(nParaIndex, j);
19749b8096d0SSteve Yin             reeBegin  = ree.aPosition.nIndex + nAllFieldLen;
19759b8096d0SSteve Yin             reeEnd = reeBegin + ree.aCurrentText.Len();
19769b8096d0SSteve Yin             nAllFieldLen += (ree.aCurrentText.Len() - 1);
19779b8096d0SSteve Yin             if( reeBegin > Segment.SegmentEnd )
19789b8096d0SSteve Yin             {
19799b8096d0SSteve Yin                 break;
19809b8096d0SSteve Yin             }
19819b8096d0SSteve Yin             if(  (Segment.SegmentEnd > reeBegin && Segment.SegmentEnd <= reeEnd) ||
19829b8096d0SSteve Yin                   (Segment.SegmentStart >= reeBegin && Segment.SegmentStart < reeEnd)  )
19839b8096d0SSteve Yin             {
19849b8096d0SSteve Yin                 if(ree.pFieldItem->GetField()->GetClassId() != SVX_URLFIELD)
19859b8096d0SSteve Yin                 {
19869b8096d0SSteve Yin                     nFoundFieldIndex = j;
19879b8096d0SSteve Yin                     break;
19889b8096d0SSteve Yin                 }
19899b8096d0SSteve Yin             }
19909b8096d0SSteve Yin         }
19919b8096d0SSteve Yin         sal_Bool bExtend = sal_False;
19929b8096d0SSteve Yin         if( nFoundFieldIndex >= 0 )
19939b8096d0SSteve Yin         {
19949b8096d0SSteve Yin             if( Segment.SegmentEnd < reeEnd )
19959b8096d0SSteve Yin             {
19969b8096d0SSteve Yin                 Segment.SegmentEnd  = reeEnd;
19979b8096d0SSteve Yin                 bExtend = sal_True;
19989b8096d0SSteve Yin             }
19999b8096d0SSteve Yin             if( Segment.SegmentStart > reeBegin )
20009b8096d0SSteve Yin             {
20019b8096d0SSteve Yin                 Segment.SegmentStart = reeBegin;
20029b8096d0SSteve Yin                 bExtend = sal_True;
20039b8096d0SSteve Yin             }
20049b8096d0SSteve Yin             if( bExtend )
20059b8096d0SSteve Yin             {
20069b8096d0SSteve Yin                 //If there is a bullet before the field, should add the bullet length into the segment.
2007a6ca19dcSDamjan Jovanovic                 EBulletInfo aBulletInfo = rCacheTF.GetBulletInfo(nParaIndex);
20089b8096d0SSteve Yin                 int nBulletLen = aBulletInfo.aText.Len();
20099b8096d0SSteve Yin                 if (nBulletLen > 0)
20109b8096d0SSteve Yin                 {
20119b8096d0SSteve Yin                     Segment.SegmentEnd += nBulletLen;
20129b8096d0SSteve Yin                     if (nFoundFieldIndex > 0)
20139b8096d0SSteve Yin                         Segment.SegmentStart += nBulletLen;
20149b8096d0SSteve Yin                     Segment.SegmentText = GetTextRange(Segment.SegmentStart, Segment.SegmentEnd);
20159b8096d0SSteve Yin                     //After get the correct field name, should restore the offset value which don't contain the bullet.
20169b8096d0SSteve Yin                     Segment.SegmentEnd -= nBulletLen;
20179b8096d0SSteve Yin                     if (nFoundFieldIndex > 0)
20189b8096d0SSteve Yin                         Segment.SegmentStart -= nBulletLen;
20199b8096d0SSteve Yin                 }
20209b8096d0SSteve Yin                 else
20219b8096d0SSteve Yin                     Segment.SegmentText = GetTextRange(Segment.SegmentStart, Segment.SegmentEnd);
20229b8096d0SSteve Yin             }
20239b8096d0SSteve Yin         }
20249b8096d0SSteve Yin         return bExtend;
20259b8096d0SSteve Yin     }
getTextAtIndex(sal_Int32 nIndex,sal_Int16 aTextType)2026cdf0e10cSrcweir     ::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)
2027cdf0e10cSrcweir     {
2028cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
2029cdf0e10cSrcweir 
2030cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
2031cdf0e10cSrcweir 
2032cdf0e10cSrcweir         DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
2033cdf0e10cSrcweir                    "AccessibleEditableTextPara::getTextAtIndex: paragraph index value overflow");
2034cdf0e10cSrcweir 
2035cdf0e10cSrcweir         ::com::sun::star::accessibility::TextSegment aResult;
2036cdf0e10cSrcweir         aResult.SegmentStart = -1;
2037cdf0e10cSrcweir         aResult.SegmentEnd = -1;
2038cdf0e10cSrcweir 
2039cdf0e10cSrcweir         switch( aTextType )
2040cdf0e10cSrcweir         {
20419b8096d0SSteve Yin         case AccessibleTextType::CHARACTER:
20429b8096d0SSteve Yin         case AccessibleTextType::WORD:
20439b8096d0SSteve Yin         {
20449b8096d0SSteve Yin             aResult = OCommonAccessibleText::getTextAtIndex( nIndex, aTextType );
20459b8096d0SSteve Yin             ExtendByField( aResult );
20469b8096d0SSteve Yin             break;
20479b8096d0SSteve Yin                 }
2048cdf0e10cSrcweir             // Not yet handled by OCommonAccessibleText. Missing
2049cdf0e10cSrcweir             // implGetAttributeRunBoundary() method there
2050cdf0e10cSrcweir             case AccessibleTextType::ATTRIBUTE_RUN:
2051cdf0e10cSrcweir             {
20528ee1071cSDamjan Jovanovic                 const sal_Int32 nTextLen = GetTextForwarder().GetTextLen( GetParagraphIndex() );
2053cdf0e10cSrcweir 
2054cdf0e10cSrcweir                 if( nIndex == nTextLen )
2055cdf0e10cSrcweir                 {
2056cdf0e10cSrcweir                     // #i17014# Special-casing one-behind-the-end character
2057cdf0e10cSrcweir                     aResult.SegmentStart = aResult.SegmentEnd = nTextLen;
2058cdf0e10cSrcweir                 }
2059cdf0e10cSrcweir                 else
2060cdf0e10cSrcweir                 {
2061cdf0e10cSrcweir                     sal_uInt16 nStartIndex, nEndIndex;
2062283563b9SJohn Bampton                     //For the bullet paragraph, the bullet string is ignored for IAText::attributes() function.
20639b8096d0SSteve Yin                     SvxTextForwarder&   rCacheTF = GetTextForwarder();
20649b8096d0SSteve Yin                     // MT IA2: Not used? sal_Int32 nBulletLen = 0;
2065a6ca19dcSDamjan Jovanovic                     EBulletInfo aBulletInfo = rCacheTF.GetBulletInfo( GetParagraphIndex() );
20669b8096d0SSteve Yin                     if (aBulletInfo.bVisible)
20679b8096d0SSteve Yin                         nIndex += aBulletInfo.aText.Len();
20689b8096d0SSteve Yin                     if (nIndex != 0  && nIndex >= getCharacterCount())
20699b8096d0SSteve Yin                         nIndex = getCharacterCount()-1;
20709b8096d0SSteve Yin                     CheckPosition(nIndex);
2071cdf0e10cSrcweir                     if( GetAttributeRun(nStartIndex, nEndIndex, nIndex) )
2072cdf0e10cSrcweir                     {
2073cdf0e10cSrcweir                         aResult.SegmentText = GetTextRange(nStartIndex, nEndIndex);
20749b8096d0SSteve Yin                         if (aBulletInfo.bVisible)
20759b8096d0SSteve Yin                         {
20769b8096d0SSteve Yin                             nStartIndex -= aBulletInfo.aText.Len();
20779b8096d0SSteve Yin                             nEndIndex -= aBulletInfo.aText.Len();
20789b8096d0SSteve Yin                         }
2079cdf0e10cSrcweir                         aResult.SegmentStart = nStartIndex;
2080cdf0e10cSrcweir                         aResult.SegmentEnd = nEndIndex;
2081cdf0e10cSrcweir                     }
2082cdf0e10cSrcweir         }
2083cdf0e10cSrcweir                 break;
2084cdf0e10cSrcweir             }
20859b8096d0SSteve Yin             case AccessibleTextType::LINE:
20869b8096d0SSteve Yin             {
20879b8096d0SSteve Yin                 SvxTextForwarder&   rCacheTF = GetTextForwarder();
20889b8096d0SSteve Yin                 sal_Int32           nParaIndex = GetParagraphIndex();
20898ee1071cSDamjan Jovanovic                 // MT IA2: Not needed? sal_Int32 nTextLen = rCacheTF.GetTextLen( nParaIndex );
20909b8096d0SSteve Yin                 CheckPosition(nIndex);
20919b8096d0SSteve Yin         if (nIndex != 0  && nIndex == getCharacterCount())
20929b8096d0SSteve Yin             --nIndex;
2093abee0e4cSDamjan Jovanovic                 sal_uInt16 nLine, nLineCount=rCacheTF.GetLineCount( nParaIndex );
20949b8096d0SSteve Yin                 sal_Int32 nCurIndex;
20959b8096d0SSteve Yin                 //the problem is that rCacheTF.GetLineLen() will include the bullet length. But for the bullet line,
20969b8096d0SSteve Yin                 //the text value doesn't contain the bullet characters. all of the bullet and numbering info are exposed
20979b8096d0SSteve Yin                 //by the IAText::attributes(). So here must do special support for bullet line.
20989b8096d0SSteve Yin                 sal_Int32 nBulletLen = 0;
20999b8096d0SSteve Yin                 for( nLine=0, nCurIndex=0; nLine<nLineCount; ++nLine )
21009b8096d0SSteve Yin                 {
21019b8096d0SSteve Yin                     if (nLine == 0)
21029b8096d0SSteve Yin                     {
2103a6ca19dcSDamjan Jovanovic                         EBulletInfo aBulletInfo = rCacheTF.GetBulletInfo( nParaIndex );
21049b8096d0SSteve Yin                         if (aBulletInfo.bVisible)
21059b8096d0SSteve Yin                         {
21069b8096d0SSteve Yin                             //in bullet or numbering;
21079b8096d0SSteve Yin                             nBulletLen = aBulletInfo.aText.Len();
21089b8096d0SSteve Yin                         }
21099b8096d0SSteve Yin                     }
2110f94052d8SDamjan Jovanovic                     //nCurIndex += rCacheTF.GetLineLen(nParaIndex, nLine);
2111f94052d8SDamjan Jovanovic                     sal_Int32 nLineLen = rCacheTF.GetLineLen(nParaIndex, nLine);
21129b8096d0SSteve Yin                     if (nLine == 0)
21139b8096d0SSteve Yin                         nCurIndex += nLineLen - nBulletLen;
21149b8096d0SSteve Yin                     else
21159b8096d0SSteve Yin                         nCurIndex += nLineLen;
21169b8096d0SSteve Yin                     if( nCurIndex > nIndex )
21179b8096d0SSteve Yin                     {
21189b8096d0SSteve Yin                         if (nLine ==0)
21199b8096d0SSteve Yin                         {
2120f94052d8SDamjan Jovanovic                             //aResult.SegmentStart = nCurIndex - rCacheTF.GetLineLen(nParaIndex, nLine);
21219b8096d0SSteve Yin                             aResult.SegmentStart = 0;
21229b8096d0SSteve Yin                             aResult.SegmentEnd = nCurIndex;
21239b8096d0SSteve Yin                             //aResult.SegmentText = GetTextRange( aResult.SegmentStart, aResult.SegmentEnd );
21249b8096d0SSteve Yin                             aResult.SegmentText = GetTextRange( aResult.SegmentStart, aResult.SegmentEnd + nBulletLen);
21259b8096d0SSteve Yin                             break;
21269b8096d0SSteve Yin                         }
21279b8096d0SSteve Yin                         else
21289b8096d0SSteve Yin                         {
2129f94052d8SDamjan Jovanovic                             //aResult.SegmentStart = nCurIndex - rCacheTF.GetLineLen(nParaIndex, nLine);
21309b8096d0SSteve Yin                             aResult.SegmentStart = nCurIndex - nLineLen;
21319b8096d0SSteve Yin                             aResult.SegmentEnd = nCurIndex;
21329b8096d0SSteve Yin                             //aResult.SegmentText = GetTextRange( aResult.SegmentStart, aResult.SegmentEnd );
21339b8096d0SSteve Yin                             aResult.SegmentText = GetTextRange( aResult.SegmentStart + nBulletLen, aResult.SegmentEnd + nBulletLen);
21349b8096d0SSteve Yin                             break;
21359b8096d0SSteve Yin                         }
21369b8096d0SSteve Yin                     }
21379b8096d0SSteve Yin                 }
21389b8096d0SSteve Yin                 break;
21399b8096d0SSteve Yin             }
2140cdf0e10cSrcweir             default:
2141cdf0e10cSrcweir                 aResult = OCommonAccessibleText::getTextAtIndex( nIndex, aTextType );
2142cdf0e10cSrcweir                 break;
2143cdf0e10cSrcweir         } /* end of switch( aTextType ) */
2144cdf0e10cSrcweir 
2145cdf0e10cSrcweir         return aResult;
2146cdf0e10cSrcweir     }
2147cdf0e10cSrcweir 
getTextBeforeIndex(sal_Int32 nIndex,sal_Int16 aTextType)2148cdf0e10cSrcweir     ::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)
2149cdf0e10cSrcweir     {
2150cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
2151cdf0e10cSrcweir 
2152cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
2153cdf0e10cSrcweir 
2154cdf0e10cSrcweir         DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
2155cdf0e10cSrcweir                    "AccessibleEditableTextPara::getTextBeforeIndex: paragraph index value overflow");
2156cdf0e10cSrcweir 
2157cdf0e10cSrcweir         ::com::sun::star::accessibility::TextSegment aResult;
2158cdf0e10cSrcweir         aResult.SegmentStart = -1;
2159cdf0e10cSrcweir         aResult.SegmentEnd = -1;
21609b8096d0SSteve Yin         i18n::Boundary aBoundary;
2161cdf0e10cSrcweir         switch( aTextType )
2162cdf0e10cSrcweir         {
2163cdf0e10cSrcweir             // Not yet handled by OCommonAccessibleText. Missing
2164cdf0e10cSrcweir             // implGetAttributeRunBoundary() method there
2165cdf0e10cSrcweir             case AccessibleTextType::ATTRIBUTE_RUN:
2166cdf0e10cSrcweir             {
21678ee1071cSDamjan Jovanovic                 const sal_Int32 nTextLen = GetTextForwarder().GetTextLen( GetParagraphIndex() );
2168cdf0e10cSrcweir                 sal_uInt16 nStartIndex, nEndIndex;
2169cdf0e10cSrcweir 
2170cdf0e10cSrcweir                 if( nIndex == nTextLen )
2171cdf0e10cSrcweir                 {
2172cdf0e10cSrcweir                     // #i17014# Special-casing one-behind-the-end character
2173cdf0e10cSrcweir                     if( nIndex > 0 &&
2174cdf0e10cSrcweir                         GetAttributeRun(nStartIndex, nEndIndex, nIndex-1) )
2175cdf0e10cSrcweir                     {
2176cdf0e10cSrcweir                         aResult.SegmentText = GetTextRange(nStartIndex, nEndIndex);
2177cdf0e10cSrcweir                         aResult.SegmentStart = nStartIndex;
2178cdf0e10cSrcweir                         aResult.SegmentEnd = nEndIndex;
2179cdf0e10cSrcweir                     }
2180cdf0e10cSrcweir                 }
2181cdf0e10cSrcweir                 else
2182cdf0e10cSrcweir                 {
2183cdf0e10cSrcweir                     if( GetAttributeRun(nStartIndex, nEndIndex, nIndex) )
2184cdf0e10cSrcweir                     {
2185cdf0e10cSrcweir                         // already at the left border? If not, query
2186cdf0e10cSrcweir                         // one index further left
2187cdf0e10cSrcweir                         if( nStartIndex > 0 &&
2188cdf0e10cSrcweir                             GetAttributeRun(nStartIndex, nEndIndex, nStartIndex-1) )
2189cdf0e10cSrcweir                         {
2190cdf0e10cSrcweir                             aResult.SegmentText = GetTextRange(nStartIndex, nEndIndex);
2191cdf0e10cSrcweir                             aResult.SegmentStart = nStartIndex;
2192cdf0e10cSrcweir                             aResult.SegmentEnd = nEndIndex;
2193cdf0e10cSrcweir                         }
2194cdf0e10cSrcweir                     }
2195cdf0e10cSrcweir                 }
2196cdf0e10cSrcweir                 break;
2197cdf0e10cSrcweir             }
21989b8096d0SSteve Yin             case AccessibleTextType::LINE:
21999b8096d0SSteve Yin             {
22009b8096d0SSteve Yin                 SvxTextForwarder&   rCacheTF = GetTextForwarder();
22019b8096d0SSteve Yin                 sal_Int32           nParaIndex = GetParagraphIndex();
22028ee1071cSDamjan Jovanovic                 // MT IA2 not needed? sal_Int32 nTextLen = rCacheTF.GetTextLen( nParaIndex );
2203cdf0e10cSrcweir 
22049b8096d0SSteve Yin                 CheckPosition(nIndex);
22059b8096d0SSteve Yin 
2206abee0e4cSDamjan Jovanovic                 sal_uInt16 nLine, nLineCount=rCacheTF.GetLineCount( nParaIndex );
22079b8096d0SSteve Yin                 //the problem is that rCacheTF.GetLineLen() will include the bullet length. But for the bullet line,
22089b8096d0SSteve Yin                 //the text value doesn't contain the bullet characters. all of the bullet and numbering info are exposed
22099b8096d0SSteve Yin                 //by the IAText::attributes(). So here must do special support for bullet line.
22109b8096d0SSteve Yin                 sal_Int32 nCurIndex=0, nLastIndex=0, nCurLineLen=0;
2211*d05a6787Smseidel                 sal_Int32 nLastLineLen = 0, nBulletLen = 0;
22129b8096d0SSteve Yin                 // get the line before the line the index points into
22139b8096d0SSteve Yin                 for( nLine=0, nCurIndex=0, nLastIndex=0; nLine<nLineCount; ++nLine )
22149b8096d0SSteve Yin                 {
22159b8096d0SSteve Yin                     nLastIndex = nCurIndex;
22169b8096d0SSteve Yin                     if (nLine == 0)
22179b8096d0SSteve Yin                     {
2218a6ca19dcSDamjan Jovanovic                         EBulletInfo aBulletInfo = rCacheTF.GetBulletInfo( nParaIndex );
22199b8096d0SSteve Yin                         if (aBulletInfo.bVisible)
22209b8096d0SSteve Yin                         {
22219b8096d0SSteve Yin                             //in bullet or numbering;
22229b8096d0SSteve Yin                             nBulletLen = aBulletInfo.aText.Len();
22239b8096d0SSteve Yin                         }
22249b8096d0SSteve Yin                     }
22259b8096d0SSteve Yin                     if (nLine == 1)
22269b8096d0SSteve Yin                         nLastLineLen = nCurLineLen - nBulletLen;
22279b8096d0SSteve Yin                     else
22289b8096d0SSteve Yin                         nLastLineLen = nCurLineLen;
2229f94052d8SDamjan Jovanovic                     nCurLineLen = rCacheTF.GetLineLen(nParaIndex, nLine);
22309b8096d0SSteve Yin                     //nCurIndex += nCurLineLen;
22319b8096d0SSteve Yin                     if (nLine == 0)
22329b8096d0SSteve Yin                         nCurIndex += nCurLineLen - nBulletLen;
22339b8096d0SSteve Yin                     else
22349b8096d0SSteve Yin                         nCurIndex += nCurLineLen;
22359b8096d0SSteve Yin 
22369b8096d0SSteve Yin                     //if( nCurIndex > nIndex &&
22379b8096d0SSteve Yin                     //nLastIndex > nCurLineLen )
22389b8096d0SSteve Yin                     if (nCurIndex > nIndex)
22399b8096d0SSteve Yin                     {
22409b8096d0SSteve Yin                         if (nLine == 0)
22419b8096d0SSteve Yin                         {
22429b8096d0SSteve Yin                             break;
22439b8096d0SSteve Yin                         }
22449b8096d0SSteve Yin                         else if (nLine == 1)
22459b8096d0SSteve Yin                         {
22469b8096d0SSteve Yin                             aResult.SegmentStart = 0;
22479b8096d0SSteve Yin                             aResult.SegmentEnd = static_cast< sal_uInt16 >( nLastIndex );
22489b8096d0SSteve Yin                             aResult.SegmentText = GetTextRange( aResult.SegmentStart, aResult.SegmentEnd + nBulletLen);
22499b8096d0SSteve Yin                             break;
22509b8096d0SSteve Yin                         }
22519b8096d0SSteve Yin                         else
22529b8096d0SSteve Yin                         {
22539b8096d0SSteve Yin                             //aResult.SegmentStart = nLastIndex - nCurLineLen;
22549b8096d0SSteve Yin                             aResult.SegmentStart = nLastIndex - nLastLineLen;
22559b8096d0SSteve Yin                             aResult.SegmentEnd = static_cast< sal_uInt16 >( nLastIndex );
22569b8096d0SSteve Yin                             aResult.SegmentText = GetTextRange( aResult.SegmentStart + nBulletLen, aResult.SegmentEnd + nBulletLen);
22579b8096d0SSteve Yin                             break;
22589b8096d0SSteve Yin                         }
22599b8096d0SSteve Yin                     }
22609b8096d0SSteve Yin                 }
22619b8096d0SSteve Yin 
22629b8096d0SSteve Yin                 break;
22639b8096d0SSteve Yin             }
22649b8096d0SSteve Yin             case AccessibleTextType::WORD:
22659b8096d0SSteve Yin             {
22669b8096d0SSteve Yin                 nIndex = SkipField( nIndex, sal_False);
22679b8096d0SSteve Yin                 ::rtl::OUString sText( implGetText() );
22689b8096d0SSteve Yin                 sal_Int32 nLength = sText.getLength();
22699b8096d0SSteve Yin 
22709b8096d0SSteve Yin                 // get word at index
22719b8096d0SSteve Yin                 implGetWordBoundary( aBoundary, nIndex );
22729b8096d0SSteve Yin 
22739b8096d0SSteve Yin 
22749b8096d0SSteve Yin                 //sal_Int32 curWordStart = aBoundary.startPos;
22759b8096d0SSteve Yin                 //sal_Int32 preWordStart = curWordStart;
22769b8096d0SSteve Yin                 sal_Int32 curWordStart , preWordStart;
22779b8096d0SSteve Yin                 if( aBoundary.startPos == -1 || aBoundary.startPos > nIndex)
22789b8096d0SSteve Yin                     curWordStart = preWordStart = nIndex;
22799b8096d0SSteve Yin                 else
22809b8096d0SSteve Yin                     curWordStart = preWordStart = aBoundary.startPos;
22819b8096d0SSteve Yin 
22829b8096d0SSteve Yin                 // get previous word
22839b8096d0SSteve Yin 
22849b8096d0SSteve Yin                 sal_Bool bWord = sal_False;
22859b8096d0SSteve Yin 
22869b8096d0SSteve Yin                 //while ( preWordStart > 0 && aBoundary.startPos == curWordStart)
22879b8096d0SSteve Yin                 while ( (preWordStart >= 0 && !bWord ) || ( aBoundary.endPos > curWordStart ) )
22889b8096d0SSteve Yin                     {
22899b8096d0SSteve Yin                     preWordStart--;
22909b8096d0SSteve Yin                     bWord = implGetWordBoundary( aBoundary, preWordStart );
22919b8096d0SSteve Yin                 }
22929b8096d0SSteve Yin                 if ( bWord && implIsValidBoundary( aBoundary, nLength ) )
22939b8096d0SSteve Yin                 {
22949b8096d0SSteve Yin                     aResult.SegmentText = sText.copy( aBoundary.startPos, aBoundary.endPos - aBoundary.startPos );
22959b8096d0SSteve Yin                     aResult.SegmentStart = aBoundary.startPos;
22969b8096d0SSteve Yin                     aResult.SegmentEnd = aBoundary.endPos;
22979b8096d0SSteve Yin                     ExtendByField( aResult );
22989b8096d0SSteve Yin                 }
22999b8096d0SSteve Yin             }
23009b8096d0SSteve Yin             break;
23019b8096d0SSteve Yin             case AccessibleTextType::CHARACTER:
23029b8096d0SSteve Yin             {
23039b8096d0SSteve Yin                 nIndex = SkipField( nIndex, sal_False);
23049b8096d0SSteve Yin                 aResult = OCommonAccessibleText::getTextBeforeIndex( nIndex, aTextType );
23059b8096d0SSteve Yin                 ExtendByField( aResult );
23069b8096d0SSteve Yin                 break;
23079b8096d0SSteve Yin             }
2308cdf0e10cSrcweir             default:
2309cdf0e10cSrcweir                 aResult = OCommonAccessibleText::getTextBeforeIndex( nIndex, aTextType );
2310cdf0e10cSrcweir                 break;
2311cdf0e10cSrcweir         } /* end of switch( aTextType ) */
2312cdf0e10cSrcweir 
2313cdf0e10cSrcweir         return aResult;
2314cdf0e10cSrcweir     }
2315cdf0e10cSrcweir 
getTextBehindIndex(sal_Int32 nIndex,sal_Int16 aTextType)2316cdf0e10cSrcweir     ::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)
2317cdf0e10cSrcweir     {
2318cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
2319cdf0e10cSrcweir 
2320cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
2321cdf0e10cSrcweir 
2322cdf0e10cSrcweir         DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
2323cdf0e10cSrcweir                    "AccessibleEditableTextPara::getTextBehindIndex: paragraph index value overflow");
2324cdf0e10cSrcweir 
2325cdf0e10cSrcweir         ::com::sun::star::accessibility::TextSegment aResult;
2326cdf0e10cSrcweir         aResult.SegmentStart = -1;
2327cdf0e10cSrcweir         aResult.SegmentEnd = -1;
23289b8096d0SSteve Yin         i18n::Boundary aBoundary;
2329cdf0e10cSrcweir         switch( aTextType )
2330cdf0e10cSrcweir         {
2331cdf0e10cSrcweir             case AccessibleTextType::ATTRIBUTE_RUN:
2332cdf0e10cSrcweir             {
2333cdf0e10cSrcweir                 sal_uInt16 nStartIndex, nEndIndex;
2334cdf0e10cSrcweir 
2335cdf0e10cSrcweir                 if( GetAttributeRun(nStartIndex, nEndIndex, nIndex) )
2336cdf0e10cSrcweir                 {
2337cdf0e10cSrcweir                     // already at the right border?
2338cdf0e10cSrcweir                     if( nEndIndex < GetTextLen() )
2339cdf0e10cSrcweir                     {
2340cdf0e10cSrcweir                         if( GetAttributeRun(nStartIndex, nEndIndex, nEndIndex) )
2341cdf0e10cSrcweir                         {
2342cdf0e10cSrcweir                             aResult.SegmentText = GetTextRange(nStartIndex, nEndIndex);
2343cdf0e10cSrcweir                             aResult.SegmentStart = nStartIndex;
2344cdf0e10cSrcweir                             aResult.SegmentEnd = nEndIndex;
2345cdf0e10cSrcweir                         }
2346cdf0e10cSrcweir                     }
2347cdf0e10cSrcweir                 }
2348cdf0e10cSrcweir                 break;
2349cdf0e10cSrcweir             }
2350cdf0e10cSrcweir 
23519b8096d0SSteve Yin             case AccessibleTextType::LINE:
23529b8096d0SSteve Yin             {
23539b8096d0SSteve Yin                 SvxTextForwarder&   rCacheTF = GetTextForwarder();
23549b8096d0SSteve Yin                 sal_Int32           nParaIndex = GetParagraphIndex();
23558ee1071cSDamjan Jovanovic                 // MT IA2 not needed? sal_Int32 nTextLen = rCacheTF.GetTextLen( nParaIndex );
23569b8096d0SSteve Yin 
23579b8096d0SSteve Yin                 CheckPosition(nIndex);
23589b8096d0SSteve Yin 
2359abee0e4cSDamjan Jovanovic                 sal_uInt16 nLine, nLineCount=rCacheTF.GetLineCount( nParaIndex );
23609b8096d0SSteve Yin                 sal_Int32 nCurIndex;
23619b8096d0SSteve Yin                 //the problem is that rCacheTF.GetLineLen() will include the bullet length. But for the bullet line,
23629b8096d0SSteve Yin                 //the text value doesn't contain the bullet characters. all of the bullet and numbering info are exposed
23639b8096d0SSteve Yin                 //by the IAText::attributes(). So here must do special support for bullet line.
23649b8096d0SSteve Yin                 sal_Int32 nBulletLen = 0;
23659b8096d0SSteve Yin                 // get the line after the line the index points into
23669b8096d0SSteve Yin                 for( nLine=0, nCurIndex=0; nLine<nLineCount; ++nLine )
23679b8096d0SSteve Yin                 {
23689b8096d0SSteve Yin                     if (nLine == 0)
23699b8096d0SSteve Yin                     {
2370a6ca19dcSDamjan Jovanovic                         EBulletInfo aBulletInfo = rCacheTF.GetBulletInfo( nParaIndex );
23719b8096d0SSteve Yin                         if (aBulletInfo.bVisible)
23729b8096d0SSteve Yin                         {
23739b8096d0SSteve Yin                             //in bullet or numbering;
23749b8096d0SSteve Yin                             nBulletLen = aBulletInfo.aText.Len();
23759b8096d0SSteve Yin                         }
23769b8096d0SSteve Yin                     }
2377f94052d8SDamjan Jovanovic                     //nCurIndex += rCacheTF.GetLineLen(nParaIndex, nLine);
2378f94052d8SDamjan Jovanovic                     sal_Int32 nLineLen = rCacheTF.GetLineLen(nParaIndex, nLine);
23799b8096d0SSteve Yin 
23809b8096d0SSteve Yin                     if (nLine == 0)
23819b8096d0SSteve Yin                         nCurIndex += nLineLen - nBulletLen;
23829b8096d0SSteve Yin                     else
23839b8096d0SSteve Yin                         nCurIndex += nLineLen;
23849b8096d0SSteve Yin 
23859b8096d0SSteve Yin                     if( nCurIndex > nIndex &&
23869b8096d0SSteve Yin                         nLine < nLineCount-1 )
23879b8096d0SSteve Yin                     {
23889b8096d0SSteve Yin                         aResult.SegmentStart = nCurIndex;
2389f94052d8SDamjan Jovanovic                         aResult.SegmentEnd = nCurIndex + rCacheTF.GetLineLen(nParaIndex, nLine+1);
23909b8096d0SSteve Yin                         aResult.SegmentText = GetTextRange( aResult.SegmentStart + nBulletLen, aResult.SegmentEnd + nBulletLen);
23919b8096d0SSteve Yin                         break;
23929b8096d0SSteve Yin                     }
23939b8096d0SSteve Yin                 }
23949b8096d0SSteve Yin 
23959b8096d0SSteve Yin                 break;
23969b8096d0SSteve Yin             }
23979b8096d0SSteve Yin             case AccessibleTextType::WORD:
23989b8096d0SSteve Yin             {
23999b8096d0SSteve Yin                 nIndex = SkipField( nIndex, sal_True);
24009b8096d0SSteve Yin                 ::rtl::OUString sText( implGetText() );
24019b8096d0SSteve Yin                 sal_Int32 nLength = sText.getLength();
24029b8096d0SSteve Yin 
24039b8096d0SSteve Yin                 // get word at index
24049b8096d0SSteve Yin                 sal_Bool bWord = implGetWordBoundary( aBoundary, nIndex );
24059b8096d0SSteve Yin 
24069b8096d0SSteve Yin                 // real current world
24079b8096d0SSteve Yin                 sal_Int32 nextWord = nIndex;
24089b8096d0SSteve Yin                 //if( nIndex >= aBoundary.startPos && nIndex <= aBoundary.endPos )
24099b8096d0SSteve Yin                 if( nIndex <= aBoundary.endPos )
24109b8096d0SSteve Yin                 {
24119b8096d0SSteve Yin                     nextWord =  aBoundary.endPos;
24129b8096d0SSteve Yin                     if( sText.getStr()[nextWord] == sal_Unicode(' ') ) nextWord++;
24139b8096d0SSteve Yin                     bWord = implGetWordBoundary( aBoundary, nextWord );
24149b8096d0SSteve Yin                 }
24159b8096d0SSteve Yin 
24169b8096d0SSteve Yin                 if ( bWord && implIsValidBoundary( aBoundary, nLength ) )
24179b8096d0SSteve Yin                 {
24189b8096d0SSteve Yin                     aResult.SegmentText = sText.copy( aBoundary.startPos, aBoundary.endPos - aBoundary.startPos );
24199b8096d0SSteve Yin                     aResult.SegmentStart = aBoundary.startPos;
24209b8096d0SSteve Yin                     aResult.SegmentEnd = aBoundary.endPos;
24219b8096d0SSteve Yin 
24229b8096d0SSteve Yin                     // If the end position of aBoundary is inside a field, extend the result to the end of the field
24239b8096d0SSteve Yin 
24249b8096d0SSteve Yin                     ExtendByField( aResult );
24259b8096d0SSteve Yin                 }
24269b8096d0SSteve Yin             }
24279b8096d0SSteve Yin             break;
24289b8096d0SSteve Yin 
24299b8096d0SSteve Yin             case AccessibleTextType::CHARACTER:
24309b8096d0SSteve Yin             {
24319b8096d0SSteve Yin                 nIndex = SkipField( nIndex, sal_True);
24329b8096d0SSteve Yin                 aResult = OCommonAccessibleText::getTextBehindIndex( nIndex, aTextType );
24339b8096d0SSteve Yin                 ExtendByField( aResult );
24349b8096d0SSteve Yin                 break;
24359b8096d0SSteve Yin             }
2436cdf0e10cSrcweir             default:
2437cdf0e10cSrcweir                 aResult = OCommonAccessibleText::getTextBehindIndex( nIndex, aTextType );
2438cdf0e10cSrcweir                 break;
2439cdf0e10cSrcweir         } /* end of switch( aTextType ) */
2440cdf0e10cSrcweir 
2441cdf0e10cSrcweir         return aResult;
2442cdf0e10cSrcweir     }
2443cdf0e10cSrcweir 
copyText(sal_Int32 nStartIndex,sal_Int32 nEndIndex)2444cdf0e10cSrcweir     sal_Bool SAL_CALL AccessibleEditableTextPara::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
2445cdf0e10cSrcweir     {
2446cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
2447cdf0e10cSrcweir 
2448cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
2449cdf0e10cSrcweir 
2450cdf0e10cSrcweir         try
2451cdf0e10cSrcweir         {
2452cdf0e10cSrcweir             SvxEditViewForwarder& rCacheVF = GetEditViewForwarder( sal_True );
2453cdf0e10cSrcweir             #if OSL_DEBUG_LEVEL > 0
2454cdf0e10cSrcweir             SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder();    // MUST be after GetEditViewForwarder(), see method docs
2455cdf0e10cSrcweir             (void)rCacheTF;
2456cdf0e10cSrcweir             #else
2457cdf0e10cSrcweir             GetTextForwarder();                                         // MUST be after GetEditViewForwarder(), see method docs
2458cdf0e10cSrcweir             #endif
2459cdf0e10cSrcweir 
2460cdf0e10cSrcweir             sal_Bool aRetVal;
2461cdf0e10cSrcweir 
2462cdf0e10cSrcweir             DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
2463cdf0e10cSrcweir                        "AccessibleEditableTextPara::copyText: index value overflow");
2464cdf0e10cSrcweir 
2465cdf0e10cSrcweir             CheckRange(nStartIndex, nEndIndex);
2466cdf0e10cSrcweir 
24679b8096d0SSteve Yin             //Because bullet may occupy one or more characters, the TextAdapter will include bullet to calculate the selection. Add offset to handle bullet
24689b8096d0SSteve Yin             sal_Int32 nBulletLen = 0;
2469a6ca19dcSDamjan Jovanovic             EBulletInfo aBulletInfo = GetTextForwarder().GetBulletInfo( GetParagraphIndex() );
24709b8096d0SSteve Yin             if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && aBulletInfo.bVisible )
24719b8096d0SSteve Yin                         nBulletLen = aBulletInfo.aText.Len();
2472cdf0e10cSrcweir             // save current selection
2473cdf0e10cSrcweir             ESelection aOldSelection;
2474cdf0e10cSrcweir 
2475cdf0e10cSrcweir             rCacheVF.GetSelection( aOldSelection );
24769b8096d0SSteve Yin             //rCacheVF.SetSelection( MakeSelection(nStartIndex, nEndIndex) );
24779b8096d0SSteve Yin             rCacheVF.SetSelection( MakeSelection(nStartIndex + nBulletLen, nEndIndex + nBulletLen) );
2478cdf0e10cSrcweir             aRetVal = rCacheVF.Copy();
2479cdf0e10cSrcweir             rCacheVF.SetSelection( aOldSelection ); // restore
2480cdf0e10cSrcweir 
2481cdf0e10cSrcweir             return aRetVal;
2482cdf0e10cSrcweir         }
2483cdf0e10cSrcweir         catch( const uno::RuntimeException& )
2484cdf0e10cSrcweir         {
2485cdf0e10cSrcweir             return sal_False;
2486cdf0e10cSrcweir         }
2487cdf0e10cSrcweir     }
2488cdf0e10cSrcweir 
2489cdf0e10cSrcweir     // XAccessibleEditableText
cutText(sal_Int32 nStartIndex,sal_Int32 nEndIndex)2490cdf0e10cSrcweir     sal_Bool SAL_CALL AccessibleEditableTextPara::cutText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
2491cdf0e10cSrcweir     {
2492cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
2493cdf0e10cSrcweir 
2494cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
2495cdf0e10cSrcweir 
2496cdf0e10cSrcweir         try
2497cdf0e10cSrcweir         {
2498cdf0e10cSrcweir             SvxEditViewForwarder& rCacheVF = GetEditViewForwarder( sal_True );
2499cdf0e10cSrcweir             SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder();    // MUST be after GetEditViewForwarder(), see method docs
2500cdf0e10cSrcweir 
2501cdf0e10cSrcweir             DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
2502cdf0e10cSrcweir                        "AccessibleEditableTextPara::cutText: index value overflow");
2503cdf0e10cSrcweir 
2504cdf0e10cSrcweir             CheckRange(nStartIndex, nEndIndex);
2505cdf0e10cSrcweir 
25069b8096d0SSteve Yin             // Because bullet may occupy one or more characters, the TextAdapter will include bullet to calculate the selection. Add offset to handle bullet
25079b8096d0SSteve Yin             sal_Int32 nBulletLen = 0;
2508a6ca19dcSDamjan Jovanovic             EBulletInfo aBulletInfo = GetTextForwarder().GetBulletInfo( GetParagraphIndex() );
25099b8096d0SSteve Yin             if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && aBulletInfo.bVisible )
25109b8096d0SSteve Yin                         nBulletLen = aBulletInfo.aText.Len();
25119b8096d0SSteve Yin             ESelection aSelection = MakeSelection (nStartIndex + nBulletLen, nEndIndex + nBulletLen);
25129b8096d0SSteve Yin             if( !rCacheTF.IsEditable( aSelection ) )
2513cdf0e10cSrcweir                 return sal_False; // non-editable area selected
2514cdf0e10cSrcweir 
2515cdf0e10cSrcweir             // don't save selection, might become invalid after cut!
25169b8096d0SSteve Yin             //rCacheVF.SetSelection( MakeSelection(nStartIndex, nEndIndex) );
25179b8096d0SSteve Yin             rCacheVF.SetSelection( aSelection );
2518cdf0e10cSrcweir 
2519cdf0e10cSrcweir             return rCacheVF.Cut();
2520cdf0e10cSrcweir         }
2521cdf0e10cSrcweir         catch( const uno::RuntimeException& )
2522cdf0e10cSrcweir         {
2523cdf0e10cSrcweir             return sal_False;
2524cdf0e10cSrcweir         }
2525cdf0e10cSrcweir     }
2526cdf0e10cSrcweir 
pasteText(sal_Int32 nIndex)2527cdf0e10cSrcweir     sal_Bool SAL_CALL AccessibleEditableTextPara::pasteText( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
2528cdf0e10cSrcweir     {
2529cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
2530cdf0e10cSrcweir 
2531cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
2532cdf0e10cSrcweir 
2533cdf0e10cSrcweir         try
2534cdf0e10cSrcweir         {
2535cdf0e10cSrcweir             SvxEditViewForwarder& rCacheVF = GetEditViewForwarder( sal_True );
2536cdf0e10cSrcweir             SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder();    // MUST be after GetEditViewForwarder(), see method docs
2537cdf0e10cSrcweir 
2538cdf0e10cSrcweir             DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
2539cdf0e10cSrcweir                        "AccessibleEditableTextPara::pasteText: index value overflow");
2540cdf0e10cSrcweir 
2541cdf0e10cSrcweir             CheckPosition(nIndex);
2542cdf0e10cSrcweir 
25439b8096d0SSteve Yin             // Because bullet may occupy one or more characters, the TextAdapter will include bullet to calculate the selection. Add offset to handle bullet
25449b8096d0SSteve Yin             sal_Int32 nBulletLen = 0;
2545a6ca19dcSDamjan Jovanovic             EBulletInfo aBulletInfo = GetTextForwarder().GetBulletInfo( GetParagraphIndex() );
25469b8096d0SSteve Yin             if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && aBulletInfo.bVisible )
25479b8096d0SSteve Yin                         nBulletLen = aBulletInfo.aText.Len();
25489b8096d0SSteve Yin             //if( !rCacheTF.IsEditable( MakeSelection(nIndex) ) )
25499b8096d0SSteve Yin             if( !rCacheTF.IsEditable( MakeSelection(nIndex + nBulletLen) ) )
2550cdf0e10cSrcweir                 return sal_False; // non-editable area selected
2551cdf0e10cSrcweir 
2552cdf0e10cSrcweir             // #104400# set empty selection (=> cursor) to given index
25539b8096d0SSteve Yin             //rCacheVF.SetSelection( MakeCursor(nIndex) );
25549b8096d0SSteve Yin             rCacheVF.SetSelection( MakeCursor(nIndex + nBulletLen) );
2555cdf0e10cSrcweir 
2556cdf0e10cSrcweir             return rCacheVF.Paste();
2557cdf0e10cSrcweir         }
2558cdf0e10cSrcweir         catch( const uno::RuntimeException& )
2559cdf0e10cSrcweir         {
2560cdf0e10cSrcweir             return sal_False;
2561cdf0e10cSrcweir         }
2562cdf0e10cSrcweir     }
2563cdf0e10cSrcweir 
deleteText(sal_Int32 nStartIndex,sal_Int32 nEndIndex)2564cdf0e10cSrcweir     sal_Bool SAL_CALL AccessibleEditableTextPara::deleteText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
2565cdf0e10cSrcweir     {
2566cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
2567cdf0e10cSrcweir 
2568cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
2569cdf0e10cSrcweir 
2570cdf0e10cSrcweir         try
2571cdf0e10cSrcweir         {
2572cdf0e10cSrcweir             // #102710# Request edit view when doing changes
2573cdf0e10cSrcweir             // AccessibleEmptyEditSource relies on this behaviour
2574cdf0e10cSrcweir             GetEditViewForwarder( sal_True );
2575cdf0e10cSrcweir             SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder();    // MUST be after GetEditViewForwarder(), see method docs
2576cdf0e10cSrcweir 
2577cdf0e10cSrcweir             DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
2578cdf0e10cSrcweir                        "AccessibleEditableTextPara::deleteText: index value overflow");
2579cdf0e10cSrcweir 
2580cdf0e10cSrcweir             CheckRange(nStartIndex, nEndIndex);
2581cdf0e10cSrcweir 
25829b8096d0SSteve Yin             // Because bullet may occupy one or more characters, the TextAdapter will include bullet to calculate the selection. Add offset to handle bullet
25839b8096d0SSteve Yin             sal_Int32 nBulletLen = 0;
2584a6ca19dcSDamjan Jovanovic             EBulletInfo aBulletInfo = GetTextForwarder().GetBulletInfo( GetParagraphIndex() );
25859b8096d0SSteve Yin             if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && aBulletInfo.bVisible )
25869b8096d0SSteve Yin                         nBulletLen = aBulletInfo.aText.Len();
25879b8096d0SSteve Yin             ESelection aSelection = MakeSelection (nStartIndex + nBulletLen, nEndIndex + nBulletLen);
25889b8096d0SSteve Yin 
25899b8096d0SSteve Yin             //if( !rCacheTF.IsEditable( MakeSelection(nStartIndex, nEndIndex) ) )
25909b8096d0SSteve Yin             if( !rCacheTF.IsEditable( aSelection ) )
2591cdf0e10cSrcweir                 return sal_False; // non-editable area selected
2592cdf0e10cSrcweir 
25939b8096d0SSteve Yin             //sal_Bool bRet = rCacheTF.Delete( MakeSelection(nStartIndex, nEndIndex) );
25949b8096d0SSteve Yin             sal_Bool bRet = rCacheTF.Delete( aSelection );
2595cdf0e10cSrcweir 
2596cdf0e10cSrcweir             GetEditSource().UpdateData();
2597cdf0e10cSrcweir 
2598cdf0e10cSrcweir             return bRet;
2599cdf0e10cSrcweir         }
2600cdf0e10cSrcweir         catch( const uno::RuntimeException& )
2601cdf0e10cSrcweir         {
2602cdf0e10cSrcweir             return sal_False;
2603cdf0e10cSrcweir         }
2604cdf0e10cSrcweir     }
2605cdf0e10cSrcweir 
insertText(const::rtl::OUString & sText,sal_Int32 nIndex)2606cdf0e10cSrcweir     sal_Bool SAL_CALL AccessibleEditableTextPara::insertText( const ::rtl::OUString& sText, sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
2607cdf0e10cSrcweir     {
2608cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
2609cdf0e10cSrcweir 
2610cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
2611cdf0e10cSrcweir 
2612cdf0e10cSrcweir         try
2613cdf0e10cSrcweir         {
2614cdf0e10cSrcweir             // #102710# Request edit view when doing changes
2615cdf0e10cSrcweir             // AccessibleEmptyEditSource relies on this behaviour
2616cdf0e10cSrcweir             GetEditViewForwarder( sal_True );
2617cdf0e10cSrcweir             SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder();    // MUST be after GetEditViewForwarder(), see method docs
2618cdf0e10cSrcweir 
2619cdf0e10cSrcweir             DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
2620cdf0e10cSrcweir                        "AccessibleEditableTextPara::insertText: index value overflow");
2621cdf0e10cSrcweir 
2622cdf0e10cSrcweir             CheckPosition(nIndex);
2623cdf0e10cSrcweir 
26249b8096d0SSteve Yin             // Because bullet may occupy one or more characters, the TextAdapter will include bullet to calculate the selection. Add offset to handle bullet
26259b8096d0SSteve Yin             sal_Int32 nBulletLen = 0;
2626a6ca19dcSDamjan Jovanovic             EBulletInfo aBulletInfo = GetTextForwarder().GetBulletInfo( GetParagraphIndex() );
26279b8096d0SSteve Yin             if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && aBulletInfo.bVisible )
26289b8096d0SSteve Yin                         nBulletLen = aBulletInfo.aText.Len();
26299b8096d0SSteve Yin 
26309b8096d0SSteve Yin             //if( !rCacheTF.IsEditable( MakeSelection(nIndex) ) )
26319b8096d0SSteve Yin             if( !rCacheTF.IsEditable( MakeSelection(nIndex + nBulletLen) ) )
2632cdf0e10cSrcweir                 return sal_False; // non-editable area selected
2633cdf0e10cSrcweir 
2634cdf0e10cSrcweir             // #104400# insert given text at empty selection (=> cursor)
26359b8096d0SSteve Yin             //sal_Bool bRet = rCacheTF.InsertText( sText, MakeCursor(nIndex) );
26369b8096d0SSteve Yin             sal_Bool bRet = rCacheTF.InsertText( sText, MakeCursor(nIndex + nBulletLen) );
2637cdf0e10cSrcweir 
2638cdf0e10cSrcweir             rCacheTF.QuickFormatDoc();
2639cdf0e10cSrcweir             GetEditSource().UpdateData();
2640cdf0e10cSrcweir 
2641cdf0e10cSrcweir             return bRet;
2642cdf0e10cSrcweir         }
2643cdf0e10cSrcweir         catch( const uno::RuntimeException& )
2644cdf0e10cSrcweir         {
2645cdf0e10cSrcweir             return sal_False;
2646cdf0e10cSrcweir         }
2647cdf0e10cSrcweir     }
2648cdf0e10cSrcweir 
replaceText(sal_Int32 nStartIndex,sal_Int32 nEndIndex,const::rtl::OUString & sReplacement)2649cdf0e10cSrcweir     sal_Bool SAL_CALL AccessibleEditableTextPara::replaceText( sal_Int32 nStartIndex, sal_Int32 nEndIndex, const ::rtl::OUString& sReplacement ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
2650cdf0e10cSrcweir     {
2651cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
2652cdf0e10cSrcweir 
2653cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
2654cdf0e10cSrcweir 
2655cdf0e10cSrcweir         try
2656cdf0e10cSrcweir         {
2657cdf0e10cSrcweir             // #102710# Request edit view when doing changes
2658cdf0e10cSrcweir             // AccessibleEmptyEditSource relies on this behaviour
2659cdf0e10cSrcweir             GetEditViewForwarder( sal_True );
2660cdf0e10cSrcweir             SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder();    // MUST be after GetEditViewForwarder(), see method docs
2661cdf0e10cSrcweir 
2662cdf0e10cSrcweir             DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
2663cdf0e10cSrcweir                        "AccessibleEditableTextPara::replaceText: index value overflow");
2664cdf0e10cSrcweir 
2665cdf0e10cSrcweir             CheckRange(nStartIndex, nEndIndex);
2666cdf0e10cSrcweir 
26679b8096d0SSteve Yin             // Because bullet may occupy one or more characters, the TextAdapter will include bullet to calculate the selection. Add offset to handle bullet
26689b8096d0SSteve Yin             sal_Int32 nBulletLen = 0;
2669a6ca19dcSDamjan Jovanovic             EBulletInfo aBulletInfo = GetTextForwarder().GetBulletInfo( GetParagraphIndex() );
26709b8096d0SSteve Yin             if( aBulletInfo.nParagraph != EE_PARA_NOT_FOUND && aBulletInfo.bVisible )
26719b8096d0SSteve Yin                         nBulletLen = aBulletInfo.aText.Len();
26729b8096d0SSteve Yin             ESelection aSelection = MakeSelection (nStartIndex + nBulletLen, nEndIndex + nBulletLen);
26739b8096d0SSteve Yin 
26749b8096d0SSteve Yin             //if( !rCacheTF.IsEditable( MakeSelection(nStartIndex, nEndIndex) ) )
26759b8096d0SSteve Yin             if( !rCacheTF.IsEditable( aSelection ) )
2676cdf0e10cSrcweir                 return sal_False; // non-editable area selected
2677cdf0e10cSrcweir 
2678cdf0e10cSrcweir             // insert given text into given range => replace
26799b8096d0SSteve Yin             //sal_Bool bRet = rCacheTF.InsertText( sReplacement, MakeSelection(nStartIndex, nEndIndex) );
26809b8096d0SSteve Yin             sal_Bool bRet = rCacheTF.InsertText( sReplacement, aSelection );
2681cdf0e10cSrcweir 
2682cdf0e10cSrcweir             rCacheTF.QuickFormatDoc();
2683cdf0e10cSrcweir             GetEditSource().UpdateData();
2684cdf0e10cSrcweir 
2685cdf0e10cSrcweir             return bRet;
2686cdf0e10cSrcweir         }
2687cdf0e10cSrcweir         catch( const uno::RuntimeException& )
2688cdf0e10cSrcweir         {
2689cdf0e10cSrcweir             return sal_False;
2690cdf0e10cSrcweir         }
2691cdf0e10cSrcweir     }
2692cdf0e10cSrcweir 
setAttributes(sal_Int32 nStartIndex,sal_Int32 nEndIndex,const uno::Sequence<beans::PropertyValue> & aAttributeSet)2693cdf0e10cSrcweir     sal_Bool SAL_CALL AccessibleEditableTextPara::setAttributes( sal_Int32 nStartIndex, sal_Int32 nEndIndex, const uno::Sequence< beans::PropertyValue >& aAttributeSet ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
2694cdf0e10cSrcweir     {
2695cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
2696cdf0e10cSrcweir 
2697cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
2698cdf0e10cSrcweir 
2699cdf0e10cSrcweir         try
2700cdf0e10cSrcweir         {
2701cdf0e10cSrcweir             // #102710# Request edit view when doing changes
2702cdf0e10cSrcweir             // AccessibleEmptyEditSource relies on this behaviour
2703cdf0e10cSrcweir             GetEditViewForwarder( sal_True );
2704cdf0e10cSrcweir             SvxAccessibleTextAdapter& rCacheTF = GetTextForwarder();    // MUST be after GetEditViewForwarder(), see method docs
27058ee1071cSDamjan Jovanovic             sal_uInt32 nPara = GetParagraphIndex();
2706cdf0e10cSrcweir 
2707cdf0e10cSrcweir             DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
2708cdf0e10cSrcweir                        "AccessibleEditableTextPara::setAttributes: index value overflow");
2709cdf0e10cSrcweir 
2710cdf0e10cSrcweir             CheckRange(nStartIndex, nEndIndex);
2711cdf0e10cSrcweir 
2712cdf0e10cSrcweir             if( !rCacheTF.IsEditable( MakeSelection(nStartIndex, nEndIndex) ) )
2713cdf0e10cSrcweir                 return sal_False; // non-editable area selected
2714cdf0e10cSrcweir 
2715cdf0e10cSrcweir             // do the indices span the whole paragraph? Then use the outliner map
2716cdf0e10cSrcweir             // TODO: hold it as a member?
2717cdf0e10cSrcweir             SvxAccessibleTextPropertySet aPropSet( &GetEditSource(),
2718cdf0e10cSrcweir                                                    0 == nStartIndex &&
2719cdf0e10cSrcweir                                                    rCacheTF.GetTextLen(nPara) == nEndIndex ?
2720cdf0e10cSrcweir                                                    ImplGetSvxUnoOutlinerTextCursorSvxPropertySet() :
2721cdf0e10cSrcweir                                                    ImplGetSvxTextPortionSvxPropertySet() );
2722cdf0e10cSrcweir 
2723cdf0e10cSrcweir             aPropSet.SetSelection( MakeSelection(nStartIndex, nEndIndex) );
2724cdf0e10cSrcweir 
2725cdf0e10cSrcweir             // convert from PropertyValue to Any
2726cdf0e10cSrcweir             sal_Int32 i, nLength( aAttributeSet.getLength() );
2727cdf0e10cSrcweir             const beans::PropertyValue* pPropArray = aAttributeSet.getConstArray();
2728cdf0e10cSrcweir             for(i=0; i<nLength; ++i)
2729cdf0e10cSrcweir             {
2730cdf0e10cSrcweir                 try
2731cdf0e10cSrcweir                 {
2732cdf0e10cSrcweir                     aPropSet.setPropertyValue(pPropArray->Name, pPropArray->Value);
2733cdf0e10cSrcweir                 }
2734cdf0e10cSrcweir                 catch( const uno::Exception& )
2735cdf0e10cSrcweir                 {
2736cdf0e10cSrcweir                     DBG_ERROR("AccessibleEditableTextPara::setAttributes exception in setPropertyValue");
2737cdf0e10cSrcweir                 }
2738cdf0e10cSrcweir 
2739cdf0e10cSrcweir                 ++pPropArray;
2740cdf0e10cSrcweir             }
2741cdf0e10cSrcweir 
2742cdf0e10cSrcweir             rCacheTF.QuickFormatDoc();
2743cdf0e10cSrcweir             GetEditSource().UpdateData();
2744cdf0e10cSrcweir 
2745cdf0e10cSrcweir             return sal_True;
2746cdf0e10cSrcweir         }
2747cdf0e10cSrcweir         catch( const uno::RuntimeException& )
2748cdf0e10cSrcweir         {
2749cdf0e10cSrcweir             return sal_False;
2750cdf0e10cSrcweir         }
2751cdf0e10cSrcweir     }
2752cdf0e10cSrcweir 
setText(const::rtl::OUString & sText)2753cdf0e10cSrcweir     sal_Bool SAL_CALL AccessibleEditableTextPara::setText( const ::rtl::OUString& sText ) throw (uno::RuntimeException)
2754cdf0e10cSrcweir     {
2755cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
2756cdf0e10cSrcweir 
2757cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
2758cdf0e10cSrcweir 
2759cdf0e10cSrcweir         return replaceText(0, getCharacterCount(), sText);
2760cdf0e10cSrcweir     }
2761cdf0e10cSrcweir 
2762cdf0e10cSrcweir     // XAccessibleTextAttributes
getDefaultAttributes(const uno::Sequence<::rtl::OUString> & rRequestedAttributes)2763cdf0e10cSrcweir     uno::Sequence< beans::PropertyValue > SAL_CALL AccessibleEditableTextPara::getDefaultAttributes(
2764cdf0e10cSrcweir             const uno::Sequence< ::rtl::OUString >& rRequestedAttributes )
2765cdf0e10cSrcweir         throw (uno::RuntimeException)
2766cdf0e10cSrcweir     {
2767cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
2768cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
2769cdf0e10cSrcweir 
2770cdf0e10cSrcweir         #if OSL_DEBUG_LEVEL > 0
2771cdf0e10cSrcweir         SvxAccessibleTextAdapter& rCacheTF =
2772cdf0e10cSrcweir         #endif
2773cdf0e10cSrcweir             GetTextForwarder();
2774cdf0e10cSrcweir 
2775cdf0e10cSrcweir         #if OSL_DEBUG_LEVEL > 0
2776cdf0e10cSrcweir         (void)rCacheTF;
2777cdf0e10cSrcweir         #endif
2778cdf0e10cSrcweir 
2779cdf0e10cSrcweir         DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
2780cdf0e10cSrcweir                    "AccessibleEditableTextPara::getCharacterAttributes: index value overflow");
2781cdf0e10cSrcweir 
2782cdf0e10cSrcweir         // get XPropertySetInfo for paragraph attributes and
2783cdf0e10cSrcweir         // character attributes that span all the paragraphs text.
2784cdf0e10cSrcweir         SvxAccessibleTextPropertySet aPropSet( &GetEditSource(),
2785cdf0e10cSrcweir                 ImplGetSvxCharAndParaPropertiesSet() );
2786cdf0e10cSrcweir         aPropSet.SetSelection( MakeSelection( 0, GetTextLen() ) );
2787cdf0e10cSrcweir         uno::Reference< beans::XPropertySetInfo > xPropSetInfo = aPropSet.getPropertySetInfo();
2788cdf0e10cSrcweir         if (!xPropSetInfo.is())
2789cdf0e10cSrcweir             throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Cannot query XPropertySetInfo")),
2790cdf0e10cSrcweir                         uno::Reference< uno::XInterface >
2791cdf0e10cSrcweir                         ( static_cast< XAccessible* > (this) ) );   // disambiguate hierarchy
2792cdf0e10cSrcweir 
2793cdf0e10cSrcweir         // build sequence of available properties to check
2794cdf0e10cSrcweir         sal_Int32 nLenReqAttr = rRequestedAttributes.getLength();
2795cdf0e10cSrcweir         uno::Sequence< beans::Property > aProperties;
2796cdf0e10cSrcweir         if (nLenReqAttr)
2797cdf0e10cSrcweir         {
2798cdf0e10cSrcweir             const rtl::OUString *pRequestedAttributes = rRequestedAttributes.getConstArray();
2799cdf0e10cSrcweir 
2800cdf0e10cSrcweir             aProperties.realloc( nLenReqAttr );
2801cdf0e10cSrcweir             beans::Property *pProperties = aProperties.getArray();
2802cdf0e10cSrcweir             sal_Int32 nCurLen = 0;
2803cdf0e10cSrcweir             for (sal_Int32 i = 0;  i < nLenReqAttr;  ++i)
2804cdf0e10cSrcweir             {
2805cdf0e10cSrcweir                 beans::Property aProp;
2806cdf0e10cSrcweir                 try
2807cdf0e10cSrcweir                 {
2808cdf0e10cSrcweir                     aProp = xPropSetInfo->getPropertyByName( pRequestedAttributes[i] );
2809cdf0e10cSrcweir                 }
2810cdf0e10cSrcweir                 catch (beans::UnknownPropertyException &)
2811cdf0e10cSrcweir                 {
2812cdf0e10cSrcweir                     continue;
2813cdf0e10cSrcweir                 }
2814cdf0e10cSrcweir                 pProperties[ nCurLen++ ] = aProp;
2815cdf0e10cSrcweir             }
2816cdf0e10cSrcweir             aProperties.realloc( nCurLen );
2817cdf0e10cSrcweir         }
2818cdf0e10cSrcweir         else
2819cdf0e10cSrcweir             aProperties = xPropSetInfo->getProperties();
2820cdf0e10cSrcweir 
2821cdf0e10cSrcweir         sal_Int32 nLength = aProperties.getLength();
2822cdf0e10cSrcweir         const beans::Property *pProperties = aProperties.getConstArray();
2823cdf0e10cSrcweir 
2824cdf0e10cSrcweir         // build resulting sequence
2825cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > aOutSequence( nLength );
2826cdf0e10cSrcweir         beans::PropertyValue* pOutSequence = aOutSequence.getArray();
2827cdf0e10cSrcweir         sal_Int32 nOutLen = 0;
2828cdf0e10cSrcweir         for (sal_Int32 i = 0;  i < nLength;  ++i)
2829cdf0e10cSrcweir         {
2830cdf0e10cSrcweir             // calling implementation functions:
2831cdf0e10cSrcweir             // _getPropertyState and _getPropertyValue (see below) to provide
2832cdf0e10cSrcweir             // the proper paragraph number when retrieving paragraph attributes
2833cdf0e10cSrcweir             PropertyState eState = aPropSet._getPropertyState( pProperties->Name, mnParagraphIndex );
2834cdf0e10cSrcweir             if ( eState == PropertyState_AMBIGUOUS_VALUE )
2835cdf0e10cSrcweir             {
2836cdf0e10cSrcweir                 OSL_ENSURE( false, "ambiguous property value encountered" );
2837cdf0e10cSrcweir             }
2838cdf0e10cSrcweir 
2839cdf0e10cSrcweir             //if (eState == PropertyState_DIRECT_VALUE)
2840cdf0e10cSrcweir             // per definition all paragraph properties and all character
2841cdf0e10cSrcweir             // properties spanning the whole paragraph should be returned
2842cdf0e10cSrcweir             // and declared as default value
2843cdf0e10cSrcweir             {
2844cdf0e10cSrcweir                 pOutSequence->Name      = pProperties->Name;
2845cdf0e10cSrcweir                 pOutSequence->Handle    = pProperties->Handle;
2846cdf0e10cSrcweir                 pOutSequence->Value     = aPropSet._getPropertyValue( pProperties->Name, mnParagraphIndex );
2847cdf0e10cSrcweir                 pOutSequence->State     = PropertyState_DEFAULT_VALUE;
2848cdf0e10cSrcweir 
2849cdf0e10cSrcweir                 ++pOutSequence;
2850cdf0e10cSrcweir                 ++nOutLen;
2851cdf0e10cSrcweir             }
2852cdf0e10cSrcweir             ++pProperties;
2853cdf0e10cSrcweir         }
2854cdf0e10cSrcweir         aOutSequence.realloc( nOutLen );
2855cdf0e10cSrcweir 
2856cdf0e10cSrcweir         return aOutSequence;
2857cdf0e10cSrcweir     }
2858cdf0e10cSrcweir 
2859cdf0e10cSrcweir 
getRunAttributes(sal_Int32 nIndex,const uno::Sequence<::rtl::OUString> & rRequestedAttributes)2860cdf0e10cSrcweir     uno::Sequence< beans::PropertyValue > SAL_CALL AccessibleEditableTextPara::getRunAttributes(
2861cdf0e10cSrcweir             sal_Int32 nIndex,
2862cdf0e10cSrcweir             const uno::Sequence< ::rtl::OUString >& rRequestedAttributes )
2863cdf0e10cSrcweir         throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
2864cdf0e10cSrcweir     {
2865cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
2866cdf0e10cSrcweir 
2867cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
2868cdf0e10cSrcweir 
2869cdf0e10cSrcweir         #if OSL_DEBUG_LEVEL > 0
2870cdf0e10cSrcweir         SvxAccessibleTextAdapter& rCacheTF =
2871cdf0e10cSrcweir         #endif
2872cdf0e10cSrcweir             GetTextForwarder();
2873cdf0e10cSrcweir 
2874cdf0e10cSrcweir         #if OSL_DEBUG_LEVEL > 0
2875cdf0e10cSrcweir         (void)rCacheTF;
2876cdf0e10cSrcweir         #endif
2877cdf0e10cSrcweir 
2878cdf0e10cSrcweir         DBG_ASSERT(GetParagraphIndex() >= 0 && GetParagraphIndex() <= USHRT_MAX,
2879cdf0e10cSrcweir                    "AccessibleEditableTextPara::getCharacterAttributes: index value overflow");
2880cdf0e10cSrcweir 
28819b8096d0SSteve Yin         if( getCharacterCount() > 0 )
2882cdf0e10cSrcweir             CheckIndex(nIndex);
28839b8096d0SSteve Yin         else
28849b8096d0SSteve Yin             CheckPosition(nIndex);
2885cdf0e10cSrcweir 
2886cdf0e10cSrcweir         SvxAccessibleTextPropertySet aPropSet( &GetEditSource(),
2887cdf0e10cSrcweir                                                ImplGetSvxCharAndParaPropertiesSet() );
2888cdf0e10cSrcweir         aPropSet.SetSelection( MakeSelection( nIndex ) );
2889cdf0e10cSrcweir         uno::Reference< beans::XPropertySetInfo > xPropSetInfo = aPropSet.getPropertySetInfo();
2890cdf0e10cSrcweir         if (!xPropSetInfo.is())
2891cdf0e10cSrcweir             throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Cannot query XPropertySetInfo")),
2892cdf0e10cSrcweir                                         uno::Reference< uno::XInterface >
2893cdf0e10cSrcweir                                         ( static_cast< XAccessible* > (this) ) );   // disambiguate hierarchy
2894cdf0e10cSrcweir 
2895cdf0e10cSrcweir         // build sequence of available properties to check
2896cdf0e10cSrcweir         sal_Int32 nLenReqAttr = rRequestedAttributes.getLength();
2897cdf0e10cSrcweir         uno::Sequence< beans::Property > aProperties;
2898cdf0e10cSrcweir         if (nLenReqAttr)
2899cdf0e10cSrcweir         {
2900cdf0e10cSrcweir             const rtl::OUString *pRequestedAttributes = rRequestedAttributes.getConstArray();
2901cdf0e10cSrcweir 
2902cdf0e10cSrcweir             aProperties.realloc( nLenReqAttr );
2903cdf0e10cSrcweir             beans::Property *pProperties = aProperties.getArray();
2904cdf0e10cSrcweir             sal_Int32 nCurLen = 0;
2905cdf0e10cSrcweir             for (sal_Int32 i = 0;  i < nLenReqAttr;  ++i)
2906cdf0e10cSrcweir             {
2907cdf0e10cSrcweir                 beans::Property aProp;
2908cdf0e10cSrcweir                 try
2909cdf0e10cSrcweir                 {
2910cdf0e10cSrcweir                     aProp = xPropSetInfo->getPropertyByName( pRequestedAttributes[i] );
2911cdf0e10cSrcweir                 }
2912cdf0e10cSrcweir                 catch (beans::UnknownPropertyException &)
2913cdf0e10cSrcweir                 {
2914cdf0e10cSrcweir                     continue;
2915cdf0e10cSrcweir                 }
2916cdf0e10cSrcweir                 pProperties[ nCurLen++ ] = aProp;
2917cdf0e10cSrcweir             }
2918cdf0e10cSrcweir             aProperties.realloc( nCurLen );
2919cdf0e10cSrcweir         }
2920cdf0e10cSrcweir         else
2921cdf0e10cSrcweir             aProperties = xPropSetInfo->getProperties();
2922cdf0e10cSrcweir 
2923cdf0e10cSrcweir         sal_Int32 nLength = aProperties.getLength();
2924cdf0e10cSrcweir         const beans::Property *pProperties = aProperties.getConstArray();
2925cdf0e10cSrcweir 
2926cdf0e10cSrcweir         // build resulting sequence
2927cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > aOutSequence( nLength );
2928cdf0e10cSrcweir         beans::PropertyValue* pOutSequence = aOutSequence.getArray();
2929cdf0e10cSrcweir         sal_Int32 nOutLen = 0;
2930cdf0e10cSrcweir         for (sal_Int32 i = 0;  i < nLength;  ++i)
2931cdf0e10cSrcweir         {
2932cdf0e10cSrcweir             // calling 'regular' functions that will operate on the selection
2933cdf0e10cSrcweir             PropertyState eState = aPropSet.getPropertyState( pProperties->Name );
2934cdf0e10cSrcweir             if (eState == PropertyState_DIRECT_VALUE)
2935cdf0e10cSrcweir             {
2936cdf0e10cSrcweir                 pOutSequence->Name      = pProperties->Name;
2937cdf0e10cSrcweir                 pOutSequence->Handle    = pProperties->Handle;
2938cdf0e10cSrcweir                 pOutSequence->Value     = aPropSet.getPropertyValue( pProperties->Name );
2939cdf0e10cSrcweir                 pOutSequence->State     = eState;
2940cdf0e10cSrcweir 
2941cdf0e10cSrcweir                 ++pOutSequence;
2942cdf0e10cSrcweir                 ++nOutLen;
2943cdf0e10cSrcweir             }
2944cdf0e10cSrcweir             ++pProperties;
2945cdf0e10cSrcweir         }
2946cdf0e10cSrcweir         aOutSequence.realloc( nOutLen );
2947cdf0e10cSrcweir 
2948cdf0e10cSrcweir         return aOutSequence;
2949cdf0e10cSrcweir     }
2950cdf0e10cSrcweir 
2951cdf0e10cSrcweir     // XAccessibleHypertext
getHyperLinkCount()2952cdf0e10cSrcweir     ::sal_Int32 SAL_CALL AccessibleEditableTextPara::getHyperLinkCount(  ) throw (::com::sun::star::uno::RuntimeException)
2953cdf0e10cSrcweir     {
2954cdf0e10cSrcweir         SvxAccessibleTextAdapter& rT = GetTextForwarder();
2955cdf0e10cSrcweir         const sal_Int32 nPara = GetParagraphIndex();
2956cdf0e10cSrcweir 
2957cdf0e10cSrcweir         sal_uInt16 nHyperLinks = 0;
2958cdf0e10cSrcweir         sal_uInt16 nFields = rT.GetFieldCount( nPara );
2959cdf0e10cSrcweir         for ( sal_uInt16 n = 0; n < nFields; n++ )
2960cdf0e10cSrcweir         {
2961cdf0e10cSrcweir             EFieldInfo aField = rT.GetFieldInfo( nPara, n );
2962cdf0e10cSrcweir             if ( aField.pFieldItem->GetField()->ISA( SvxURLField ) )
2963cdf0e10cSrcweir                 nHyperLinks++;
2964cdf0e10cSrcweir         }
2965cdf0e10cSrcweir         return nHyperLinks;
2966cdf0e10cSrcweir     }
2967cdf0e10cSrcweir 
getHyperLink(::sal_Int32 nLinkIndex)2968cdf0e10cSrcweir     ::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)
2969cdf0e10cSrcweir     {
2970cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleHyperlink > xRef;
2971cdf0e10cSrcweir 
2972cdf0e10cSrcweir         SvxAccessibleTextAdapter& rT = GetTextForwarder();
2973cdf0e10cSrcweir         const sal_Int32 nPara = GetParagraphIndex();
2974cdf0e10cSrcweir 
2975cdf0e10cSrcweir         sal_uInt16 nHyperLink = 0;
2976cdf0e10cSrcweir         sal_uInt16 nFields = rT.GetFieldCount( nPara );
2977cdf0e10cSrcweir         for ( sal_uInt16 n = 0; n < nFields; n++ )
2978cdf0e10cSrcweir         {
2979cdf0e10cSrcweir             EFieldInfo aField = rT.GetFieldInfo( nPara, n );
2980cdf0e10cSrcweir             if ( aField.pFieldItem->GetField()->ISA( SvxURLField ) )
2981cdf0e10cSrcweir             {
2982cdf0e10cSrcweir                 if ( nHyperLink == nLinkIndex )
2983cdf0e10cSrcweir                 {
2984cdf0e10cSrcweir                     sal_uInt16 nEEStart = aField.aPosition.nIndex;
2985cdf0e10cSrcweir 
2986cdf0e10cSrcweir                     // Translate EE Index to accessible index
2987cdf0e10cSrcweir                     sal_uInt16 nStart = rT.CalcEditEngineIndex( nPara, nEEStart );
2988cdf0e10cSrcweir                     sal_uInt16 nEnd = nStart + aField.aCurrentText.Len();
2989cdf0e10cSrcweir                     xRef = new AccessibleHyperlink( rT, new SvxFieldItem( *aField.pFieldItem ), nPara, nEEStart, nStart, nEnd, aField.aCurrentText );
2990cdf0e10cSrcweir                     break;
2991cdf0e10cSrcweir                 }
2992cdf0e10cSrcweir                 nHyperLink++;
2993cdf0e10cSrcweir             }
2994cdf0e10cSrcweir         }
2995cdf0e10cSrcweir 
2996cdf0e10cSrcweir         return xRef;
2997cdf0e10cSrcweir     }
2998cdf0e10cSrcweir 
getHyperLinkIndex(::sal_Int32 nCharIndex)2999cdf0e10cSrcweir     ::sal_Int32 SAL_CALL AccessibleEditableTextPara::getHyperLinkIndex( ::sal_Int32 nCharIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
3000cdf0e10cSrcweir     {
3001cdf0e10cSrcweir         const sal_Int32 nPara = GetParagraphIndex();
3002cdf0e10cSrcweir         SvxAccessibleTextAdapter& rT = GetTextForwarder();
3003cdf0e10cSrcweir 
3004cdf0e10cSrcweir //        SvxAccessibleTextIndex aIndex;
3005cdf0e10cSrcweir //        aIndex.SetIndex(nPara, nCharIndex, rT);
3006cdf0e10cSrcweir //        const sal_uInt16 nEEIndex = aIndex.GetEEIndex();
3007cdf0e10cSrcweir 
3008cdf0e10cSrcweir         const sal_uInt16 nEEIndex = rT.CalcEditEngineIndex( nPara, nCharIndex );
3009fd080abbSSteve Yin         sal_Int32 nHLIndex = -1; //i123620
3010cdf0e10cSrcweir         sal_uInt16 nHyperLink = 0;
3011cdf0e10cSrcweir         sal_uInt16 nFields = rT.GetFieldCount( nPara );
3012cdf0e10cSrcweir         for ( sal_uInt16 n = 0; n < nFields; n++ )
3013cdf0e10cSrcweir         {
3014cdf0e10cSrcweir             EFieldInfo aField = rT.GetFieldInfo( nPara, n );
3015cdf0e10cSrcweir             if ( aField.pFieldItem->GetField()->ISA( SvxURLField ) )
3016cdf0e10cSrcweir             {
3017cdf0e10cSrcweir                 if ( aField.aPosition.nIndex == nEEIndex )
3018cdf0e10cSrcweir                 {
3019cdf0e10cSrcweir                     nHLIndex = nHyperLink;
3020cdf0e10cSrcweir                     break;
3021cdf0e10cSrcweir                 }
3022cdf0e10cSrcweir                 nHyperLink++;
3023cdf0e10cSrcweir             }
3024cdf0e10cSrcweir         }
3025cdf0e10cSrcweir 
3026cdf0e10cSrcweir         return nHLIndex;
3027cdf0e10cSrcweir     }
3028cdf0e10cSrcweir 
3029cdf0e10cSrcweir     // XAccessibleMultiLineText
getLineNumberAtIndex(sal_Int32 nIndex)3030cdf0e10cSrcweir     sal_Int32 SAL_CALL AccessibleEditableTextPara::getLineNumberAtIndex( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
3031cdf0e10cSrcweir     {
3032cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
3033cdf0e10cSrcweir 
3034cdf0e10cSrcweir         sal_Int32 nRes = -1;
3035cdf0e10cSrcweir         sal_Int32 nPara = GetParagraphIndex();
3036cdf0e10cSrcweir 
3037cdf0e10cSrcweir         SvxTextForwarder &rCacheTF = GetTextForwarder();
3038cdf0e10cSrcweir         const bool bValidPara = 0 <= nPara && nPara < rCacheTF.GetParagraphCount();
3039cdf0e10cSrcweir         DBG_ASSERT( bValidPara, "getLineNumberAtIndex: current paragraph index out of range" );
3040cdf0e10cSrcweir         if (bValidPara)
3041cdf0e10cSrcweir         {
3042cdf0e10cSrcweir             // we explicitly allow for the index to point at the character right behind the text
3043c2eaa082SDamjan Jovanovic             if (0 <= nIndex && nIndex <= rCacheTF.GetTextLen( nPara ))
3044c2eaa082SDamjan Jovanovic                 nRes = rCacheTF.GetLineNumberAtIndex( nPara, static_cast< sal_uInt16 >(nIndex) );
3045cdf0e10cSrcweir             else
3046cdf0e10cSrcweir                 throw lang::IndexOutOfBoundsException();
3047cdf0e10cSrcweir         }
3048cdf0e10cSrcweir         return nRes;
3049cdf0e10cSrcweir     }
3050cdf0e10cSrcweir 
3051cdf0e10cSrcweir     // XAccessibleMultiLineText
getTextAtLineNumber(sal_Int32 nLineNo)3052cdf0e10cSrcweir     ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleEditableTextPara::getTextAtLineNumber( sal_Int32 nLineNo ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
3053cdf0e10cSrcweir     {
3054cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
3055cdf0e10cSrcweir 
3056cdf0e10cSrcweir         ::com::sun::star::accessibility::TextSegment aResult;
3057cdf0e10cSrcweir         sal_Int32 nPara = GetParagraphIndex();
3058cdf0e10cSrcweir         SvxTextForwarder &rCacheTF = GetTextForwarder();
3059cdf0e10cSrcweir         const bool bValidPara = 0 <= nPara && nPara < rCacheTF.GetParagraphCount();
3060cdf0e10cSrcweir         DBG_ASSERT( bValidPara, "getTextAtLineNumber: current paragraph index out of range" );
3061cdf0e10cSrcweir         if (bValidPara)
3062cdf0e10cSrcweir         {
3063c2eaa082SDamjan Jovanovic             if (0 <= nLineNo && nLineNo < rCacheTF.GetLineCount( nPara ))
3064cdf0e10cSrcweir             {
3065cdf0e10cSrcweir                 sal_uInt16 nStart = 0, nEnd = 0;
3066c2eaa082SDamjan Jovanovic                 rCacheTF.GetLineBoundaries( nStart, nEnd, nPara, static_cast< sal_uInt16 >(nLineNo) );
3067cdf0e10cSrcweir                 if (nStart != 0xFFFF && nEnd != 0xFFFF)
3068cdf0e10cSrcweir                 {
3069cdf0e10cSrcweir                     try
3070cdf0e10cSrcweir                     {
3071cdf0e10cSrcweir                         aResult.SegmentText     = getTextRange( nStart, nEnd );
3072cdf0e10cSrcweir                         aResult.SegmentStart    = nStart;
3073cdf0e10cSrcweir                         aResult.SegmentEnd      = nEnd;
3074cdf0e10cSrcweir                     }
3075cdf0e10cSrcweir                     catch (lang::IndexOutOfBoundsException)
3076cdf0e10cSrcweir                     {
3077cdf0e10cSrcweir                         // this is not the exception that should be raised in this function ...
3078cdf0e10cSrcweir                         DBG_ASSERT( 0, "unexpected exception" );
3079cdf0e10cSrcweir                     }
3080cdf0e10cSrcweir                 }
3081cdf0e10cSrcweir             }
3082cdf0e10cSrcweir             else
3083cdf0e10cSrcweir                 throw lang::IndexOutOfBoundsException();
3084cdf0e10cSrcweir         }
3085cdf0e10cSrcweir         return aResult;
3086cdf0e10cSrcweir     }
3087cdf0e10cSrcweir 
3088cdf0e10cSrcweir     // XAccessibleMultiLineText
getTextAtLineWithCaret()3089cdf0e10cSrcweir     ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleEditableTextPara::getTextAtLineWithCaret(  ) throw (uno::RuntimeException)
3090cdf0e10cSrcweir     {
3091cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
3092cdf0e10cSrcweir 
3093cdf0e10cSrcweir         ::com::sun::star::accessibility::TextSegment aResult;
3094cdf0e10cSrcweir         try
3095cdf0e10cSrcweir         {
3096cdf0e10cSrcweir             aResult = getTextAtLineNumber( getNumberOfLineWithCaret() );
3097cdf0e10cSrcweir         }
3098cdf0e10cSrcweir         catch (lang::IndexOutOfBoundsException &)
3099cdf0e10cSrcweir         {
3100cdf0e10cSrcweir             // this one needs to be catched since this interface does not allow for it.
3101cdf0e10cSrcweir         }
3102cdf0e10cSrcweir         return aResult;
3103cdf0e10cSrcweir     }
3104cdf0e10cSrcweir 
3105cdf0e10cSrcweir     // XAccessibleMultiLineText
getNumberOfLineWithCaret()3106cdf0e10cSrcweir     sal_Int32 SAL_CALL AccessibleEditableTextPara::getNumberOfLineWithCaret(  ) throw (uno::RuntimeException)
3107cdf0e10cSrcweir     {
3108cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
3109cdf0e10cSrcweir 
3110cdf0e10cSrcweir         sal_Int32 nRes = -1;
3111cdf0e10cSrcweir         try
3112cdf0e10cSrcweir         {
3113cdf0e10cSrcweir             nRes = getLineNumberAtIndex( getCaretPosition() );
3114cdf0e10cSrcweir         }
3115cdf0e10cSrcweir         catch (lang::IndexOutOfBoundsException &)
3116cdf0e10cSrcweir         {
3117cdf0e10cSrcweir             // this one needs to be catched since this interface does not allow for it.
3118cdf0e10cSrcweir         }
3119cdf0e10cSrcweir         return nRes;
3120cdf0e10cSrcweir     }
3121cdf0e10cSrcweir 
3122cdf0e10cSrcweir 
3123cdf0e10cSrcweir     // XServiceInfo
getImplementationName(void)3124cdf0e10cSrcweir     ::rtl::OUString SAL_CALL AccessibleEditableTextPara::getImplementationName (void) throw (uno::RuntimeException)
3125cdf0e10cSrcweir     {
3126cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
3127cdf0e10cSrcweir 
3128cdf0e10cSrcweir         return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ("AccessibleEditableTextPara"));
3129cdf0e10cSrcweir     }
3130cdf0e10cSrcweir 
supportsService(const::rtl::OUString & sServiceName)3131cdf0e10cSrcweir     sal_Bool SAL_CALL AccessibleEditableTextPara::supportsService (const ::rtl::OUString& sServiceName) throw (uno::RuntimeException)
3132cdf0e10cSrcweir     {
3133cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
3134cdf0e10cSrcweir 
3135cdf0e10cSrcweir         //  Iterate over all supported service names and return true if on of them
3136cdf0e10cSrcweir         //  matches the given name.
3137cdf0e10cSrcweir         uno::Sequence< ::rtl::OUString> aSupportedServices (
3138cdf0e10cSrcweir             getSupportedServiceNames ());
3139cdf0e10cSrcweir         for (int i=0; i<aSupportedServices.getLength(); i++)
3140cdf0e10cSrcweir             if (sServiceName == aSupportedServices[i])
3141cdf0e10cSrcweir                 return sal_True;
3142cdf0e10cSrcweir         return sal_False;
3143cdf0e10cSrcweir     }
3144cdf0e10cSrcweir 
getSupportedServiceNames(void)3145cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString> SAL_CALL AccessibleEditableTextPara::getSupportedServiceNames (void) throw (uno::RuntimeException)
3146cdf0e10cSrcweir     {
3147cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
3148cdf0e10cSrcweir 
3149cdf0e10cSrcweir         const ::rtl::OUString sServiceName( getServiceName() );
3150cdf0e10cSrcweir         return uno::Sequence< ::rtl::OUString > (&sServiceName, 1);
3151cdf0e10cSrcweir     }
3152cdf0e10cSrcweir 
3153cdf0e10cSrcweir     // XServiceName
getServiceName(void)3154cdf0e10cSrcweir     ::rtl::OUString SAL_CALL AccessibleEditableTextPara::getServiceName (void) throw (uno::RuntimeException)
3155cdf0e10cSrcweir     {
3156cdf0e10cSrcweir         DBG_CHKTHIS( AccessibleEditableTextPara, NULL );
3157cdf0e10cSrcweir 
3158cdf0e10cSrcweir         // #105185# Using correct service now
3159cdf0e10cSrcweir         return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.AccessibleParagraphView"));
3160cdf0e10cSrcweir     }
3161cdf0e10cSrcweir 
3162cdf0e10cSrcweir }  // end of namespace accessibility
3163cdf0e10cSrcweir 
3164cdf0e10cSrcweir //------------------------------------------------------------------------
3165