xref: /trunk/main/sc/source/ui/Accessibility/AccessibleEditObject.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b3f79822SAndrew Rist  * distributed with this work for additional information
6b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17b3f79822SAndrew Rist  * specific language governing permissions and limitations
18b3f79822SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20b3f79822SAndrew Rist  *************************************************************/
21b3f79822SAndrew Rist 
22b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir #include "AccessibleEditObject.hxx"
27cdf0e10cSrcweir #include "scitems.hxx"
28cdf0e10cSrcweir #include <editeng/eeitem.hxx>
29cdf0e10cSrcweir #include "unoguard.hxx"
30cdf0e10cSrcweir #include "AccessibleText.hxx"
31cdf0e10cSrcweir #include "editsrc.hxx"
32cdf0e10cSrcweir #include "scmod.hxx"
33cdf0e10cSrcweir #include "inputhdl.hxx"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #ifndef _UTL_ACCESSIBLESTATESETHELPER_HXX
36cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx>
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLEROLE_HPP_
39cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp>
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLESTATETYPE_HPP_
42cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
43cdf0e10cSrcweir #endif
44cdf0e10cSrcweir #include <rtl/uuid.h>
45cdf0e10cSrcweir #include <tools/debug.hxx>
46cdf0e10cSrcweir #include <svx/AccessibleTextHelper.hxx>
470deba7fbSSteve Yin #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
480deba7fbSSteve Yin #include <com/sun/star/sheet/XSpreadsheet.hpp>
49cdf0e10cSrcweir #include <editeng/editview.hxx>
50cdf0e10cSrcweir #include <editeng/editeng.hxx>
51cdf0e10cSrcweir #include <svx/svdmodel.hxx>
520deba7fbSSteve Yin #include <sfx2/objsh.hxx>
53cdf0e10cSrcweir 
540deba7fbSSteve Yin #include "unonames.hxx"
550deba7fbSSteve Yin #include "document.hxx"
560deba7fbSSteve Yin #include "AccessibleDocument.hxx"
570deba7fbSSteve Yin #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
580deba7fbSSteve Yin #include <unotools/accessiblerelationsethelper.hxx>
590deba7fbSSteve Yin #include <com/sun/star/accessibility/XAccessibleText.hpp>
600deba7fbSSteve Yin using ::com::sun::star::lang::IndexOutOfBoundsException;
610deba7fbSSteve Yin using ::com::sun::star::uno::RuntimeException;
62cdf0e10cSrcweir using namespace ::com::sun::star;
63cdf0e10cSrcweir using namespace ::com::sun::star::accessibility;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir //=====  internal  ============================================================
66cdf0e10cSrcweir 
ScAccessibleEditObject(const uno::Reference<XAccessible> & rxParent,EditView * pEditView,Window * pWin,const rtl::OUString & rName,const rtl::OUString & rDescription,EditObjectType eObjectType)67cdf0e10cSrcweir ScAccessibleEditObject::ScAccessibleEditObject(
68cdf0e10cSrcweir         const uno::Reference<XAccessible>& rxParent,
69cdf0e10cSrcweir         EditView* pEditView, Window* pWin, const rtl::OUString& rName,
70cdf0e10cSrcweir         const rtl::OUString& rDescription, EditObjectType eObjectType)
71cdf0e10cSrcweir     :
72cdf0e10cSrcweir     ScAccessibleContextBase(rxParent, AccessibleRole::TEXT_FRAME),
73cdf0e10cSrcweir     mpTextHelper(NULL),
74cdf0e10cSrcweir     mpEditView(pEditView),
75cdf0e10cSrcweir     mpWindow(pWin),
76cdf0e10cSrcweir     meObjectType(eObjectType),
77cdf0e10cSrcweir     mbHasFocus(sal_False)
78cdf0e10cSrcweir {
79cdf0e10cSrcweir     CreateTextHelper();
80cdf0e10cSrcweir     SetName(rName);
81cdf0e10cSrcweir     SetDescription(rDescription);
820deba7fbSSteve Yin     if( meObjectType == CellInEditMode)
830deba7fbSSteve Yin     {
840deba7fbSSteve Yin         const ScAccessibleDocument *pAccDoc = const_cast<ScAccessibleDocument*>(static_cast<ScAccessibleDocument*>(rxParent.get())) ;
850deba7fbSSteve Yin         if (pAccDoc)
860deba7fbSSteve Yin         {
870deba7fbSSteve Yin             m_pScDoc = pAccDoc->GetDocument();
880deba7fbSSteve Yin             m_curCellAddress =pAccDoc->GetCurCellAddress();
890deba7fbSSteve Yin         }
900deba7fbSSteve Yin         else
910deba7fbSSteve Yin         {
920deba7fbSSteve Yin             m_pScDoc=NULL;
930deba7fbSSteve Yin         }
940deba7fbSSteve Yin     }
950deba7fbSSteve Yin     else
960deba7fbSSteve Yin         m_pScDoc=NULL;
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
~ScAccessibleEditObject()99cdf0e10cSrcweir ScAccessibleEditObject::~ScAccessibleEditObject()
100cdf0e10cSrcweir {
101cdf0e10cSrcweir     if (!ScAccessibleContextBase::IsDefunc() && !rBHelper.bInDispose)
102cdf0e10cSrcweir     {
103cdf0e10cSrcweir         // increment refcount to prevent double call off dtor
104cdf0e10cSrcweir         osl_incrementInterlockedCount( &m_refCount );
105*86e1cf34SPedro Giffuni         // call dispose to inform object which have a weak reference to this object
106cdf0e10cSrcweir         dispose();
107cdf0e10cSrcweir     }
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
disposing()110cdf0e10cSrcweir void SAL_CALL ScAccessibleEditObject::disposing()
111cdf0e10cSrcweir {
112cdf0e10cSrcweir     ScUnoGuard aGuard;
113cdf0e10cSrcweir     if (mpTextHelper)
114cdf0e10cSrcweir         DELETEZ(mpTextHelper);
115cdf0e10cSrcweir 
116cdf0e10cSrcweir     ScAccessibleContextBase::disposing();
117cdf0e10cSrcweir }
118cdf0e10cSrcweir 
LostFocus()119cdf0e10cSrcweir void ScAccessibleEditObject::LostFocus()
120cdf0e10cSrcweir {
121cdf0e10cSrcweir     mbHasFocus = sal_False;
122cdf0e10cSrcweir     if (mpTextHelper)
123cdf0e10cSrcweir         mpTextHelper->SetFocus(sal_False);
124cdf0e10cSrcweir     CommitFocusLost();
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
GotFocus()127cdf0e10cSrcweir void ScAccessibleEditObject::GotFocus()
128cdf0e10cSrcweir {
129cdf0e10cSrcweir     mbHasFocus = sal_True;
130cdf0e10cSrcweir     CommitFocusGained();
131cdf0e10cSrcweir     if (mpTextHelper)
132cdf0e10cSrcweir         mpTextHelper->SetFocus(sal_True);
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
1350deba7fbSSteve Yin //=====  XInterface  ==========================================================
1360deba7fbSSteve Yin 
1370deba7fbSSteve Yin com::sun::star::uno::Any SAL_CALL
queryInterface(const com::sun::star::uno::Type & rType)1380deba7fbSSteve Yin     ScAccessibleEditObject::queryInterface (const com::sun::star::uno::Type & rType)
1390deba7fbSSteve Yin     throw (::com::sun::star::uno::RuntimeException)
1400deba7fbSSteve Yin {
1410deba7fbSSteve Yin     ::com::sun::star::uno::Any aReturn = ScAccessibleContextBase::queryInterface (rType);
1420deba7fbSSteve Yin     if ( ! aReturn.hasValue())
1430deba7fbSSteve Yin         aReturn = ::cppu::queryInterface (rType,
1440deba7fbSSteve Yin             static_cast< ::com::sun::star::accessibility::XAccessibleSelection* >(this)
1450deba7fbSSteve Yin             );
1460deba7fbSSteve Yin     return aReturn;
1470deba7fbSSteve Yin }
1480deba7fbSSteve Yin void SAL_CALL
acquire(void)1490deba7fbSSteve Yin     ScAccessibleEditObject::acquire (void)
1500deba7fbSSteve Yin     throw ()
1510deba7fbSSteve Yin {
1520deba7fbSSteve Yin     ScAccessibleContextBase::acquire ();
1530deba7fbSSteve Yin }
1540deba7fbSSteve Yin void SAL_CALL
release(void)1550deba7fbSSteve Yin     ScAccessibleEditObject::release (void)
1560deba7fbSSteve Yin     throw ()
1570deba7fbSSteve Yin {
1580deba7fbSSteve Yin     ScAccessibleContextBase::release ();
1590deba7fbSSteve Yin }
160cdf0e10cSrcweir     //=====  XAccessibleComponent  ============================================
161cdf0e10cSrcweir 
getAccessibleAtPoint(const awt::Point & rPoint)162cdf0e10cSrcweir uno::Reference< XAccessible > SAL_CALL ScAccessibleEditObject::getAccessibleAtPoint(
163cdf0e10cSrcweir         const awt::Point& rPoint )
164cdf0e10cSrcweir         throw (uno::RuntimeException)
165cdf0e10cSrcweir {
166cdf0e10cSrcweir     uno::Reference<XAccessible> xRet;
167cdf0e10cSrcweir     if (containsPoint(rPoint))
168cdf0e10cSrcweir     {
169cdf0e10cSrcweir         ScUnoGuard aGuard;
170cdf0e10cSrcweir         IsObjectValid();
171cdf0e10cSrcweir 
172cdf0e10cSrcweir         if(!mpTextHelper)
173cdf0e10cSrcweir             CreateTextHelper();
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         xRet = mpTextHelper->GetAt(rPoint);
176cdf0e10cSrcweir     }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     return xRet;
179cdf0e10cSrcweir }
180cdf0e10cSrcweir 
GetBoundingBoxOnScreen(void) const181cdf0e10cSrcweir Rectangle ScAccessibleEditObject::GetBoundingBoxOnScreen(void) const
182cdf0e10cSrcweir         throw (uno::RuntimeException)
183cdf0e10cSrcweir {
184cdf0e10cSrcweir     Rectangle aScreenBounds;
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     if ( mpWindow )
187cdf0e10cSrcweir     {
188cdf0e10cSrcweir         if ( meObjectType == CellInEditMode )
189cdf0e10cSrcweir         {
190cdf0e10cSrcweir             if ( mpEditView && mpEditView->GetEditEngine() )
191cdf0e10cSrcweir             {
192cdf0e10cSrcweir                 MapMode aMapMode( mpEditView->GetEditEngine()->GetRefMapMode() );
193cdf0e10cSrcweir                 aScreenBounds = mpWindow->LogicToPixel( mpEditView->GetOutputArea(), aMapMode );
194cdf0e10cSrcweir                 Point aCellLoc = aScreenBounds.TopLeft();
195cdf0e10cSrcweir                 Rectangle aWindowRect = mpWindow->GetWindowExtentsRelative( NULL );
196cdf0e10cSrcweir                 Point aWindowLoc = aWindowRect.TopLeft();
197cdf0e10cSrcweir                 Point aPos( aCellLoc.getX() + aWindowLoc.getX(), aCellLoc.getY() + aWindowLoc.getY() );
198cdf0e10cSrcweir                 aScreenBounds.SetPos( aPos );
199cdf0e10cSrcweir             }
200cdf0e10cSrcweir         }
201cdf0e10cSrcweir         else
202cdf0e10cSrcweir         {
203cdf0e10cSrcweir             aScreenBounds = mpWindow->GetWindowExtentsRelative( NULL );
204cdf0e10cSrcweir         }
205cdf0e10cSrcweir     }
206cdf0e10cSrcweir 
207cdf0e10cSrcweir     return aScreenBounds;
208cdf0e10cSrcweir }
209cdf0e10cSrcweir 
GetBoundingBox(void) const210cdf0e10cSrcweir Rectangle ScAccessibleEditObject::GetBoundingBox(void) const
211cdf0e10cSrcweir         throw (uno::RuntimeException)
212cdf0e10cSrcweir {
213cdf0e10cSrcweir     Rectangle aBounds( GetBoundingBoxOnScreen() );
214cdf0e10cSrcweir 
215cdf0e10cSrcweir     if ( mpWindow )
216cdf0e10cSrcweir     {
217cdf0e10cSrcweir         uno::Reference< XAccessible > xThis( mpWindow->GetAccessible() );
218cdf0e10cSrcweir         if ( xThis.is() )
219cdf0e10cSrcweir         {
220cdf0e10cSrcweir             uno::Reference< XAccessibleContext > xContext( xThis->getAccessibleContext() );
221cdf0e10cSrcweir             if ( xContext.is() )
222cdf0e10cSrcweir             {
223cdf0e10cSrcweir                 uno::Reference< XAccessible > xParent( xContext->getAccessibleParent() );
224cdf0e10cSrcweir                 if ( xParent.is() )
225cdf0e10cSrcweir                 {
226cdf0e10cSrcweir                     uno::Reference< XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), uno::UNO_QUERY );
227cdf0e10cSrcweir                     if ( xParentComponent.is() )
228cdf0e10cSrcweir                     {
229cdf0e10cSrcweir                         Point aScreenLoc = aBounds.TopLeft();
230cdf0e10cSrcweir                         awt::Point aParentScreenLoc = xParentComponent->getLocationOnScreen();
231cdf0e10cSrcweir                         Point aPos( aScreenLoc.getX() - aParentScreenLoc.X, aScreenLoc.getY() - aParentScreenLoc.Y );
232cdf0e10cSrcweir                         aBounds.SetPos( aPos );
233cdf0e10cSrcweir                     }
234cdf0e10cSrcweir                 }
235cdf0e10cSrcweir             }
236cdf0e10cSrcweir         }
237cdf0e10cSrcweir     }
238cdf0e10cSrcweir 
239cdf0e10cSrcweir     return aBounds;
240cdf0e10cSrcweir }
241cdf0e10cSrcweir 
242cdf0e10cSrcweir     //=====  XAccessibleContext  ==============================================
243cdf0e10cSrcweir 
244cdf0e10cSrcweir sal_Int32 SAL_CALL
getAccessibleChildCount(void)245cdf0e10cSrcweir     ScAccessibleEditObject::getAccessibleChildCount(void)
246cdf0e10cSrcweir                     throw (uno::RuntimeException)
247cdf0e10cSrcweir {
248cdf0e10cSrcweir     ScUnoGuard aGuard;
249cdf0e10cSrcweir     IsObjectValid();
250cdf0e10cSrcweir     if (!mpTextHelper)
251cdf0e10cSrcweir         CreateTextHelper();
252cdf0e10cSrcweir     return mpTextHelper->GetChildCount();
253cdf0e10cSrcweir }
254cdf0e10cSrcweir 
255cdf0e10cSrcweir uno::Reference< XAccessible > SAL_CALL
getAccessibleChild(sal_Int32 nIndex)256cdf0e10cSrcweir     ScAccessibleEditObject::getAccessibleChild(sal_Int32 nIndex)
257cdf0e10cSrcweir         throw (uno::RuntimeException,
258cdf0e10cSrcweir         lang::IndexOutOfBoundsException)
259cdf0e10cSrcweir {
260cdf0e10cSrcweir     ScUnoGuard aGuard;
261cdf0e10cSrcweir     IsObjectValid();
262cdf0e10cSrcweir     if (!mpTextHelper)
263cdf0e10cSrcweir         CreateTextHelper();
264cdf0e10cSrcweir     return mpTextHelper->GetChild(nIndex);
265cdf0e10cSrcweir }
266cdf0e10cSrcweir 
267cdf0e10cSrcweir uno::Reference<XAccessibleStateSet> SAL_CALL
getAccessibleStateSet(void)268cdf0e10cSrcweir     ScAccessibleEditObject::getAccessibleStateSet(void)
269cdf0e10cSrcweir     throw (uno::RuntimeException)
270cdf0e10cSrcweir {
271cdf0e10cSrcweir     ScUnoGuard aGuard;
272cdf0e10cSrcweir     uno::Reference<XAccessibleStateSet> xParentStates;
273cdf0e10cSrcweir     if (getAccessibleParent().is())
274cdf0e10cSrcweir     {
275cdf0e10cSrcweir         uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
276cdf0e10cSrcweir         xParentStates = xParentContext->getAccessibleStateSet();
277cdf0e10cSrcweir     }
278cdf0e10cSrcweir     utl::AccessibleStateSetHelper* pStateSet = new utl::AccessibleStateSetHelper();
279cdf0e10cSrcweir     if (IsDefunc(xParentStates))
280cdf0e10cSrcweir         pStateSet->AddState(AccessibleStateType::DEFUNC);
281cdf0e10cSrcweir     else
282cdf0e10cSrcweir     {
283cdf0e10cSrcweir         // all states are const, because this object exists only in one state
284cdf0e10cSrcweir         pStateSet->AddState(AccessibleStateType::EDITABLE);
285cdf0e10cSrcweir         pStateSet->AddState(AccessibleStateType::ENABLED);
286cdf0e10cSrcweir         pStateSet->AddState(AccessibleStateType::SENSITIVE);
287cdf0e10cSrcweir         pStateSet->AddState(AccessibleStateType::MULTI_LINE);
288cdf0e10cSrcweir         pStateSet->AddState(AccessibleStateType::MULTI_SELECTABLE);
289cdf0e10cSrcweir         pStateSet->AddState(AccessibleStateType::SHOWING);
290cdf0e10cSrcweir         pStateSet->AddState(AccessibleStateType::VISIBLE);
291cdf0e10cSrcweir     }
292cdf0e10cSrcweir     return pStateSet;
293cdf0e10cSrcweir }
294cdf0e10cSrcweir 
295cdf0e10cSrcweir ::rtl::OUString SAL_CALL
createAccessibleDescription(void)296cdf0e10cSrcweir     ScAccessibleEditObject::createAccessibleDescription(void)
297cdf0e10cSrcweir     throw (uno::RuntimeException)
298cdf0e10cSrcweir {
299cdf0e10cSrcweir //    DBG_ERRORFILE("Should never be called, because is set in the constructor.")
300cdf0e10cSrcweir     return rtl::OUString();
301cdf0e10cSrcweir }
302cdf0e10cSrcweir 
303cdf0e10cSrcweir ::rtl::OUString SAL_CALL
createAccessibleName(void)304cdf0e10cSrcweir     ScAccessibleEditObject::createAccessibleName(void)
305cdf0e10cSrcweir     throw (uno::RuntimeException)
306cdf0e10cSrcweir {
307cdf0e10cSrcweir     DBG_ERRORFILE("Should never be called, because is set in the constructor.");
308cdf0e10cSrcweir     return rtl::OUString();
309cdf0e10cSrcweir }
310cdf0e10cSrcweir 
311cdf0e10cSrcweir     ///=====  XAccessibleEventBroadcaster  =====================================
312cdf0e10cSrcweir 
313cdf0e10cSrcweir void SAL_CALL
addEventListener(const uno::Reference<XAccessibleEventListener> & xListener)314cdf0e10cSrcweir     ScAccessibleEditObject::addEventListener(const uno::Reference<XAccessibleEventListener>& xListener)
315cdf0e10cSrcweir         throw (uno::RuntimeException)
316cdf0e10cSrcweir {
317cdf0e10cSrcweir     if (!mpTextHelper)
318cdf0e10cSrcweir         CreateTextHelper();
319cdf0e10cSrcweir 
320cdf0e10cSrcweir     mpTextHelper->AddEventListener(xListener);
321cdf0e10cSrcweir 
322cdf0e10cSrcweir     ScAccessibleContextBase::addEventListener(xListener);
323cdf0e10cSrcweir }
324cdf0e10cSrcweir 
325cdf0e10cSrcweir void SAL_CALL
removeEventListener(const uno::Reference<XAccessibleEventListener> & xListener)326cdf0e10cSrcweir     ScAccessibleEditObject::removeEventListener(const uno::Reference<XAccessibleEventListener>& xListener)
327cdf0e10cSrcweir         throw (uno::RuntimeException)
328cdf0e10cSrcweir {
329cdf0e10cSrcweir     if (!mpTextHelper)
330cdf0e10cSrcweir         CreateTextHelper();
331cdf0e10cSrcweir 
332cdf0e10cSrcweir     mpTextHelper->RemoveEventListener(xListener);
333cdf0e10cSrcweir 
334cdf0e10cSrcweir     ScAccessibleContextBase::removeEventListener(xListener);
335cdf0e10cSrcweir }
336cdf0e10cSrcweir 
337cdf0e10cSrcweir     //=====  XServiceInfo  ====================================================
338cdf0e10cSrcweir 
getImplementationName(void)339cdf0e10cSrcweir ::rtl::OUString SAL_CALL ScAccessibleEditObject::getImplementationName(void)
340cdf0e10cSrcweir         throw (uno::RuntimeException)
341cdf0e10cSrcweir {
342cdf0e10cSrcweir     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ("ScAccessibleEditObject"));
343cdf0e10cSrcweir }
344cdf0e10cSrcweir 
345cdf0e10cSrcweir //=====  XTypeProvider  =======================================================
346cdf0e10cSrcweir 
347cdf0e10cSrcweir uno::Sequence<sal_Int8> SAL_CALL
getImplementationId(void)348cdf0e10cSrcweir     ScAccessibleEditObject::getImplementationId(void)
349cdf0e10cSrcweir     throw (uno::RuntimeException)
350cdf0e10cSrcweir {
351cdf0e10cSrcweir     ScUnoGuard aGuard;
352cdf0e10cSrcweir     IsObjectValid();
353cdf0e10cSrcweir     static uno::Sequence<sal_Int8> aId;
354cdf0e10cSrcweir     if (aId.getLength() == 0)
355cdf0e10cSrcweir     {
356cdf0e10cSrcweir         aId.realloc (16);
357cdf0e10cSrcweir         rtl_createUuid (reinterpret_cast<sal_uInt8 *>(aId.getArray()), 0, sal_True);
358cdf0e10cSrcweir     }
359cdf0e10cSrcweir     return aId;
360cdf0e10cSrcweir }
361cdf0e10cSrcweir 
362cdf0e10cSrcweir     //====  internal  =========================================================
363cdf0e10cSrcweir 
IsDefunc(const uno::Reference<XAccessibleStateSet> & rxParentStates)364cdf0e10cSrcweir sal_Bool ScAccessibleEditObject::IsDefunc(
365cdf0e10cSrcweir     const uno::Reference<XAccessibleStateSet>& rxParentStates)
366cdf0e10cSrcweir {
367cdf0e10cSrcweir     return ScAccessibleContextBase::IsDefunc() || !getAccessibleParent().is() ||
368cdf0e10cSrcweir          (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
369cdf0e10cSrcweir }
370cdf0e10cSrcweir 
CreateTextHelper()371cdf0e10cSrcweir void ScAccessibleEditObject::CreateTextHelper()
372cdf0e10cSrcweir {
373cdf0e10cSrcweir     if (!mpTextHelper)
374cdf0e10cSrcweir     {
375cdf0e10cSrcweir         ::std::auto_ptr < ScAccessibleTextData > pAccessibleTextData;
376cdf0e10cSrcweir         if (meObjectType == CellInEditMode || meObjectType == EditControl)
377cdf0e10cSrcweir         {
378cdf0e10cSrcweir             pAccessibleTextData.reset
379cdf0e10cSrcweir                 (new ScAccessibleEditObjectTextData(mpEditView, mpWindow));
380cdf0e10cSrcweir         }
381cdf0e10cSrcweir         else
382cdf0e10cSrcweir         {
383cdf0e10cSrcweir             pAccessibleTextData.reset
384cdf0e10cSrcweir                 (new ScAccessibleEditLineTextData(NULL, mpWindow));
385cdf0e10cSrcweir         }
386cdf0e10cSrcweir 
387cdf0e10cSrcweir         ::std::auto_ptr< SvxEditSource > pEditSource (new ScAccessibilityEditSource(pAccessibleTextData));
388cdf0e10cSrcweir         mpTextHelper = new ::accessibility::AccessibleTextHelper(pEditSource );
389cdf0e10cSrcweir         mpTextHelper->SetEventSource(this);
390cdf0e10cSrcweir         mpTextHelper->SetFocus(mbHasFocus);
391cdf0e10cSrcweir 
392cdf0e10cSrcweir         // #i54814# activate cell in edit mode
393cdf0e10cSrcweir         if( meObjectType == CellInEditMode )
394cdf0e10cSrcweir         {
395cdf0e10cSrcweir             // do not activate cell object, if top edit line is active
396cdf0e10cSrcweir             const ScInputHandler* pInputHdl = SC_MOD()->GetInputHdl();
397cdf0e10cSrcweir             if( pInputHdl && !pInputHdl->IsTopMode() )
398cdf0e10cSrcweir             {
399cdf0e10cSrcweir                 SdrHint aHint( HINT_BEGEDIT );
400cdf0e10cSrcweir                 mpTextHelper->GetEditSource().GetBroadcaster().Broadcast( aHint );
401cdf0e10cSrcweir             }
402cdf0e10cSrcweir         }
403cdf0e10cSrcweir     }
404cdf0e10cSrcweir }
getForeground()4050deba7fbSSteve Yin sal_Int32 SAL_CALL ScAccessibleEditObject::getForeground(  )
4060deba7fbSSteve Yin         throw (::com::sun::star::uno::RuntimeException)
4070deba7fbSSteve Yin {
4080deba7fbSSteve Yin     return GetFgBgColor(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CCOLOR)));
4090deba7fbSSteve Yin }
4100deba7fbSSteve Yin 
getBackground()4110deba7fbSSteve Yin sal_Int32 SAL_CALL ScAccessibleEditObject::getBackground(  )
4120deba7fbSSteve Yin         throw (::com::sun::star::uno::RuntimeException)
4130deba7fbSSteve Yin {
4140deba7fbSSteve Yin     return GetFgBgColor(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CELLBACK)));
4150deba7fbSSteve Yin }
GetFgBgColor(const rtl::OUString & strPropColor)4160deba7fbSSteve Yin sal_Int32 ScAccessibleEditObject::GetFgBgColor( const rtl::OUString &strPropColor)
4170deba7fbSSteve Yin {
4180deba7fbSSteve Yin     ScUnoGuard aGuard;
4190deba7fbSSteve Yin     sal_Int32 nColor(0);
4200deba7fbSSteve Yin     if (m_pScDoc)
4210deba7fbSSteve Yin     {
4220deba7fbSSteve Yin         SfxObjectShell* pObjSh = m_pScDoc->GetDocumentShell();
4230deba7fbSSteve Yin         if ( pObjSh )
4240deba7fbSSteve Yin         {
4250deba7fbSSteve Yin             uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( pObjSh->GetModel(), uno::UNO_QUERY );
4260deba7fbSSteve Yin             if ( xSpreadDoc.is() )
4270deba7fbSSteve Yin             {
4280deba7fbSSteve Yin                 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
4290deba7fbSSteve Yin                 uno::Reference<container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY );
4300deba7fbSSteve Yin                 if ( xIndex.is() )
4310deba7fbSSteve Yin                 {
4320deba7fbSSteve Yin                     uno::Any aTable = xIndex->getByIndex(m_curCellAddress.Tab());
4330deba7fbSSteve Yin                     uno::Reference<sheet::XSpreadsheet> xTable;
4340deba7fbSSteve Yin                     if (aTable>>=xTable)
4350deba7fbSSteve Yin                     {
4360deba7fbSSteve Yin                         uno::Reference<table::XCell> xCell = xTable->getCellByPosition(m_curCellAddress.Col(), m_curCellAddress.Row());
4370deba7fbSSteve Yin                         if (xCell.is())
4380deba7fbSSteve Yin                         {
4390deba7fbSSteve Yin                             uno::Reference<beans::XPropertySet> xCellProps(xCell, uno::UNO_QUERY);
4400deba7fbSSteve Yin                             if (xCellProps.is())
4410deba7fbSSteve Yin                             {
4420deba7fbSSteve Yin                                 uno::Any aAny = xCellProps->getPropertyValue(strPropColor);
4430deba7fbSSteve Yin                                 aAny >>= nColor;
4440deba7fbSSteve Yin                             }
4450deba7fbSSteve Yin                         }
4460deba7fbSSteve Yin                     }
4470deba7fbSSteve Yin                 }
4480deba7fbSSteve Yin             }
4490deba7fbSSteve Yin         }
4500deba7fbSSteve Yin     }
4510deba7fbSSteve Yin     return nColor;
4520deba7fbSSteve Yin }
4530deba7fbSSteve Yin //=====  XAccessibleSelection  ============================================
4540deba7fbSSteve Yin //--------------------------------------------------------------------------------
selectAccessibleChild(sal_Int32)4550deba7fbSSteve Yin void SAL_CALL ScAccessibleEditObject::selectAccessibleChild( sal_Int32 )
4560deba7fbSSteve Yin throw ( IndexOutOfBoundsException, RuntimeException )
4570deba7fbSSteve Yin {
4580deba7fbSSteve Yin }
4590deba7fbSSteve Yin //----------------------------------------------------------------------------------
isAccessibleChildSelected(sal_Int32 nChildIndex)4600deba7fbSSteve Yin sal_Bool SAL_CALL ScAccessibleEditObject::isAccessibleChildSelected( sal_Int32 nChildIndex )
4610deba7fbSSteve Yin throw ( IndexOutOfBoundsException,
4620deba7fbSSteve Yin        RuntimeException )
4630deba7fbSSteve Yin {
4640deba7fbSSteve Yin     uno::Reference<XAccessible> xAcc = getAccessibleChild( nChildIndex );
4650deba7fbSSteve Yin     uno::Reference<XAccessibleContext> xContext;
4660deba7fbSSteve Yin     if( xAcc.is() )
4670deba7fbSSteve Yin         xContext = xAcc->getAccessibleContext();
4680deba7fbSSteve Yin     if( xContext.is() )
4690deba7fbSSteve Yin     {
4700deba7fbSSteve Yin         if( xContext->getAccessibleRole() == AccessibleRole::PARAGRAPH )
4710deba7fbSSteve Yin         {
4720deba7fbSSteve Yin             uno::Reference< ::com::sun::star::accessibility::XAccessibleText >
4730deba7fbSSteve Yin                 xText(xAcc, uno::UNO_QUERY);
4740deba7fbSSteve Yin             if( xText.is() )
4750deba7fbSSteve Yin             {
4760deba7fbSSteve Yin                 if( xText->getSelectionStart() >= 0 ) return sal_True;
4770deba7fbSSteve Yin             }
4780deba7fbSSteve Yin         }
4790deba7fbSSteve Yin     }
4800deba7fbSSteve Yin     return sal_False;
4810deba7fbSSteve Yin }
4820deba7fbSSteve Yin //---------------------------------------------------------------------
clearAccessibleSelection()4830deba7fbSSteve Yin void SAL_CALL ScAccessibleEditObject::clearAccessibleSelection(  )
4840deba7fbSSteve Yin throw ( RuntimeException )
4850deba7fbSSteve Yin {
4860deba7fbSSteve Yin }
4870deba7fbSSteve Yin //-------------------------------------------------------------------------
selectAllAccessibleChildren()4880deba7fbSSteve Yin void SAL_CALL ScAccessibleEditObject::selectAllAccessibleChildren(  )
4890deba7fbSSteve Yin throw ( RuntimeException )
4900deba7fbSSteve Yin {
4910deba7fbSSteve Yin }
4920deba7fbSSteve Yin //----------------------------------------------------------------------------
getSelectedAccessibleChildCount()4930deba7fbSSteve Yin sal_Int32 SAL_CALL ScAccessibleEditObject::getSelectedAccessibleChildCount()
4940deba7fbSSteve Yin throw ( RuntimeException )
4950deba7fbSSteve Yin {
4960deba7fbSSteve Yin     sal_Int32 nCount = 0;
4970deba7fbSSteve Yin     sal_Int32 TotalCount = getAccessibleChildCount();
4980deba7fbSSteve Yin     for( sal_Int32 i = 0; i < TotalCount; i++ )
4990deba7fbSSteve Yin         if( isAccessibleChildSelected(i) ) nCount++;
5000deba7fbSSteve Yin     return nCount;
5010deba7fbSSteve Yin }
5020deba7fbSSteve Yin //--------------------------------------------------------------------------------------
getSelectedAccessibleChild(sal_Int32 nSelectedChildIndex)5030deba7fbSSteve Yin uno::Reference<XAccessible> SAL_CALL ScAccessibleEditObject::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
5040deba7fbSSteve Yin throw ( IndexOutOfBoundsException, RuntimeException)
5050deba7fbSSteve Yin {
5060deba7fbSSteve Yin     if ( nSelectedChildIndex > getSelectedAccessibleChildCount() )
5070deba7fbSSteve Yin         throw IndexOutOfBoundsException();
5080deba7fbSSteve Yin     sal_Int32 i1, i2;
5090deba7fbSSteve Yin     for( i1 = 0, i2 = 0; i1 < getAccessibleChildCount(); i1++ )
5100deba7fbSSteve Yin         if( isAccessibleChildSelected(i1) )
5110deba7fbSSteve Yin         {
5120deba7fbSSteve Yin             if( i2 == nSelectedChildIndex )
5130deba7fbSSteve Yin                 return getAccessibleChild( i1 );
5140deba7fbSSteve Yin             i2++;
5150deba7fbSSteve Yin         }
5160deba7fbSSteve Yin     return uno::Reference<XAccessible>();
5170deba7fbSSteve Yin }
5180deba7fbSSteve Yin //----------------------------------------------------------------------------------
deselectAccessibleChild(sal_Int32)5190deba7fbSSteve Yin void SAL_CALL ScAccessibleEditObject::deselectAccessibleChild(
5200deba7fbSSteve Yin                                                             sal_Int32 )
5210deba7fbSSteve Yin                                                             throw ( IndexOutOfBoundsException,
5220deba7fbSSteve Yin                                                             RuntimeException )
5230deba7fbSSteve Yin {
5240deba7fbSSteve Yin }
getAccessibleRelationSet()5250deba7fbSSteve Yin uno::Reference< XAccessibleRelationSet > ScAccessibleEditObject::getAccessibleRelationSet(  )
5260deba7fbSSteve Yin     throw (uno::RuntimeException)
5270deba7fbSSteve Yin {
5280deba7fbSSteve Yin        ScUnoGuard aGuard;
5290deba7fbSSteve Yin     Window* pWindow = mpWindow;
5300deba7fbSSteve Yin     utl::AccessibleRelationSetHelper* rRelationSet = new utl::AccessibleRelationSetHelper;
5310deba7fbSSteve Yin     uno::Reference< XAccessibleRelationSet > rSet = rRelationSet;
5320deba7fbSSteve Yin     if ( pWindow )
5330deba7fbSSteve Yin     {
5340deba7fbSSteve Yin         Window *pLabeledBy = pWindow->GetAccessibleRelationLabeledBy();
5350deba7fbSSteve Yin         if ( pLabeledBy && pLabeledBy != pWindow )
5360deba7fbSSteve Yin         {
5370deba7fbSSteve Yin             uno::Sequence< uno::Reference< uno::XInterface > > aSequence(1);
5380deba7fbSSteve Yin             aSequence[0] = pLabeledBy->GetAccessible();
5390deba7fbSSteve Yin             rRelationSet->AddRelation( AccessibleRelation( AccessibleRelationType::LABELED_BY, aSequence ) );
5400deba7fbSSteve Yin         }
5410deba7fbSSteve Yin         Window* pMemberOf = pWindow->GetAccessibleRelationMemberOf();
5420deba7fbSSteve Yin         if ( pMemberOf && pMemberOf != pWindow )
5430deba7fbSSteve Yin         {
5440deba7fbSSteve Yin             uno::Sequence< uno::Reference< uno::XInterface > > aSequence(1);
5450deba7fbSSteve Yin             aSequence[0] = pMemberOf->GetAccessible();
5460deba7fbSSteve Yin             rRelationSet->AddRelation( AccessibleRelation( AccessibleRelationType::MEMBER_OF, aSequence ) );
5470deba7fbSSteve Yin         }
5480deba7fbSSteve Yin         return rSet;
5490deba7fbSSteve Yin     }
5500deba7fbSSteve Yin     return uno::Reference< XAccessibleRelationSet >();
5510deba7fbSSteve Yin }
552