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