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