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
10b3f79822SAndrew Rist  *
11b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12b3f79822SAndrew Rist  *
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.
19b3f79822SAndrew Rist  *
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>
47*0deba7fbSSteve Yin #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
48*0deba7fbSSteve Yin #include <com/sun/star/sheet/XSpreadsheet.hpp>
49cdf0e10cSrcweir #include <editeng/editview.hxx>
50cdf0e10cSrcweir #include <editeng/editeng.hxx>
51cdf0e10cSrcweir #include <svx/svdmodel.hxx>
52*0deba7fbSSteve Yin #include <sfx2/objsh.hxx>
53*0deba7fbSSteve Yin 
54*0deba7fbSSteve Yin #include "unonames.hxx"
55*0deba7fbSSteve Yin #include "document.hxx"
56*0deba7fbSSteve Yin #include "AccessibleDocument.hxx"
57*0deba7fbSSteve Yin #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
58*0deba7fbSSteve Yin #include <unotools/accessiblerelationsethelper.hxx>
59*0deba7fbSSteve Yin #include <com/sun/star/accessibility/XAccessibleText.hpp>
60*0deba7fbSSteve Yin using ::com::sun::star::lang::IndexOutOfBoundsException;
61*0deba7fbSSteve 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);
82*0deba7fbSSteve Yin 	if( meObjectType == CellInEditMode)
83*0deba7fbSSteve Yin 	{
84*0deba7fbSSteve Yin 		const ScAccessibleDocument *pAccDoc = const_cast<ScAccessibleDocument*>(static_cast<ScAccessibleDocument*>(rxParent.get())) ;
85*0deba7fbSSteve Yin 		if (pAccDoc)
86*0deba7fbSSteve Yin 		{
87*0deba7fbSSteve Yin 			m_pScDoc = pAccDoc->GetDocument();
88*0deba7fbSSteve Yin 			m_curCellAddress =pAccDoc->GetCurCellAddress();
89*0deba7fbSSteve Yin 		}
90*0deba7fbSSteve Yin 		else
91*0deba7fbSSteve Yin 		{
92*0deba7fbSSteve Yin 			m_pScDoc=NULL;
93*0deba7fbSSteve Yin 		}
94*0deba7fbSSteve Yin 	}
95*0deba7fbSSteve Yin 	else
96*0deba7fbSSteve 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 );
105cdf0e10cSrcweir 		// call dispose to inform object wich 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 
135*0deba7fbSSteve Yin //=====  XInterface  ==========================================================
136*0deba7fbSSteve Yin 
137*0deba7fbSSteve Yin com::sun::star::uno::Any SAL_CALL
queryInterface(const com::sun::star::uno::Type & rType)138*0deba7fbSSteve Yin     ScAccessibleEditObject::queryInterface (const com::sun::star::uno::Type & rType)
139*0deba7fbSSteve Yin     throw (::com::sun::star::uno::RuntimeException)
140*0deba7fbSSteve Yin {
141*0deba7fbSSteve Yin     ::com::sun::star::uno::Any aReturn = ScAccessibleContextBase::queryInterface (rType);
142*0deba7fbSSteve Yin     if ( ! aReturn.hasValue())
143*0deba7fbSSteve Yin         aReturn = ::cppu::queryInterface (rType,
144*0deba7fbSSteve Yin             static_cast< ::com::sun::star::accessibility::XAccessibleSelection* >(this)
145*0deba7fbSSteve Yin             );
146*0deba7fbSSteve Yin     return aReturn;
147*0deba7fbSSteve Yin }
148*0deba7fbSSteve Yin void SAL_CALL
acquire(void)149*0deba7fbSSteve Yin     ScAccessibleEditObject::acquire (void)
150*0deba7fbSSteve Yin     throw ()
151*0deba7fbSSteve Yin {
152*0deba7fbSSteve Yin     ScAccessibleContextBase::acquire ();
153*0deba7fbSSteve Yin }
154*0deba7fbSSteve Yin void SAL_CALL
release(void)155*0deba7fbSSteve Yin     ScAccessibleEditObject::release (void)
156*0deba7fbSSteve Yin     throw ()
157*0deba7fbSSteve Yin {
158*0deba7fbSSteve Yin     ScAccessibleContextBase::release ();
159*0deba7fbSSteve 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()405*0deba7fbSSteve Yin sal_Int32 SAL_CALL ScAccessibleEditObject::getForeground(  )
406*0deba7fbSSteve Yin         throw (::com::sun::star::uno::RuntimeException)
407*0deba7fbSSteve Yin {
408*0deba7fbSSteve Yin 	return GetFgBgColor(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CCOLOR)));
409*0deba7fbSSteve Yin }
410*0deba7fbSSteve Yin 
getBackground()411*0deba7fbSSteve Yin sal_Int32 SAL_CALL ScAccessibleEditObject::getBackground(  )
412*0deba7fbSSteve Yin         throw (::com::sun::star::uno::RuntimeException)
413*0deba7fbSSteve Yin {
414*0deba7fbSSteve Yin 	return GetFgBgColor(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CELLBACK)));
415*0deba7fbSSteve Yin }
GetFgBgColor(const rtl::OUString & strPropColor)416*0deba7fbSSteve Yin sal_Int32 ScAccessibleEditObject::GetFgBgColor( const rtl::OUString &strPropColor)
417*0deba7fbSSteve Yin {
418*0deba7fbSSteve Yin     ScUnoGuard aGuard;
419*0deba7fbSSteve Yin     sal_Int32 nColor(0);
420*0deba7fbSSteve Yin     if (m_pScDoc)
421*0deba7fbSSteve Yin     {
422*0deba7fbSSteve Yin         SfxObjectShell* pObjSh = m_pScDoc->GetDocumentShell();
423*0deba7fbSSteve Yin         if ( pObjSh )
424*0deba7fbSSteve Yin         {
425*0deba7fbSSteve Yin             uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( pObjSh->GetModel(), uno::UNO_QUERY );
426*0deba7fbSSteve Yin             if ( xSpreadDoc.is() )
427*0deba7fbSSteve Yin             {
428*0deba7fbSSteve Yin                 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
429*0deba7fbSSteve Yin                 uno::Reference<container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY );
430*0deba7fbSSteve Yin                 if ( xIndex.is() )
431*0deba7fbSSteve Yin                 {
432*0deba7fbSSteve Yin                     uno::Any aTable = xIndex->getByIndex(m_curCellAddress.Tab());
433*0deba7fbSSteve Yin                     uno::Reference<sheet::XSpreadsheet> xTable;
434*0deba7fbSSteve Yin                     if (aTable>>=xTable)
435*0deba7fbSSteve Yin                     {
436*0deba7fbSSteve Yin                         uno::Reference<table::XCell> xCell = xTable->getCellByPosition(m_curCellAddress.Col(), m_curCellAddress.Row());
437*0deba7fbSSteve Yin                         if (xCell.is())
438*0deba7fbSSteve Yin                         {
439*0deba7fbSSteve Yin                             uno::Reference<beans::XPropertySet> xCellProps(xCell, uno::UNO_QUERY);
440*0deba7fbSSteve Yin                             if (xCellProps.is())
441*0deba7fbSSteve Yin                             {
442*0deba7fbSSteve Yin                                 uno::Any aAny = xCellProps->getPropertyValue(strPropColor);
443*0deba7fbSSteve Yin                                 aAny >>= nColor;
444*0deba7fbSSteve Yin                             }
445*0deba7fbSSteve Yin                         }
446*0deba7fbSSteve Yin                     }
447*0deba7fbSSteve Yin                 }
448*0deba7fbSSteve Yin             }
449*0deba7fbSSteve Yin         }
450*0deba7fbSSteve Yin     }
451*0deba7fbSSteve Yin     return nColor;
452*0deba7fbSSteve Yin }
453*0deba7fbSSteve Yin //=====  XAccessibleSelection  ============================================
454*0deba7fbSSteve Yin //--------------------------------------------------------------------------------
selectAccessibleChild(sal_Int32)455*0deba7fbSSteve Yin void SAL_CALL ScAccessibleEditObject::selectAccessibleChild( sal_Int32 )
456*0deba7fbSSteve Yin throw ( IndexOutOfBoundsException, RuntimeException )
457*0deba7fbSSteve Yin {
458*0deba7fbSSteve Yin }
459*0deba7fbSSteve Yin //----------------------------------------------------------------------------------
isAccessibleChildSelected(sal_Int32 nChildIndex)460*0deba7fbSSteve Yin sal_Bool SAL_CALL ScAccessibleEditObject::isAccessibleChildSelected( sal_Int32 nChildIndex )
461*0deba7fbSSteve Yin throw ( IndexOutOfBoundsException,
462*0deba7fbSSteve Yin 	   RuntimeException )
463*0deba7fbSSteve Yin {
464*0deba7fbSSteve Yin 	uno::Reference<XAccessible> xAcc = getAccessibleChild( nChildIndex );
465*0deba7fbSSteve Yin 	uno::Reference<XAccessibleContext> xContext;
466*0deba7fbSSteve Yin 	if( xAcc.is() )
467*0deba7fbSSteve Yin 		xContext = xAcc->getAccessibleContext();
468*0deba7fbSSteve Yin 	if( xContext.is() )
469*0deba7fbSSteve Yin 	{
470*0deba7fbSSteve Yin 		if( xContext->getAccessibleRole() == AccessibleRole::PARAGRAPH )
471*0deba7fbSSteve Yin 		{
472*0deba7fbSSteve Yin 			uno::Reference< ::com::sun::star::accessibility::XAccessibleText >
473*0deba7fbSSteve Yin 				xText(xAcc, uno::UNO_QUERY);
474*0deba7fbSSteve Yin 			if( xText.is() )
475*0deba7fbSSteve Yin 			{
476*0deba7fbSSteve Yin 				if( xText->getSelectionStart() >= 0 ) return sal_True;
477*0deba7fbSSteve Yin 			}
478*0deba7fbSSteve Yin 		}
479*0deba7fbSSteve Yin 	}
480*0deba7fbSSteve Yin 	return sal_False;
481*0deba7fbSSteve Yin }
482*0deba7fbSSteve Yin //---------------------------------------------------------------------
clearAccessibleSelection()483*0deba7fbSSteve Yin void SAL_CALL ScAccessibleEditObject::clearAccessibleSelection(  )
484*0deba7fbSSteve Yin throw ( RuntimeException )
485*0deba7fbSSteve Yin {
486*0deba7fbSSteve Yin }
487*0deba7fbSSteve Yin //-------------------------------------------------------------------------
selectAllAccessibleChildren()488*0deba7fbSSteve Yin void SAL_CALL ScAccessibleEditObject::selectAllAccessibleChildren(  )
489*0deba7fbSSteve Yin throw ( RuntimeException )
490*0deba7fbSSteve Yin {
491*0deba7fbSSteve Yin }
492*0deba7fbSSteve Yin //----------------------------------------------------------------------------
getSelectedAccessibleChildCount()493*0deba7fbSSteve Yin sal_Int32 SAL_CALL ScAccessibleEditObject::getSelectedAccessibleChildCount()
494*0deba7fbSSteve Yin throw ( RuntimeException )
495*0deba7fbSSteve Yin {
496*0deba7fbSSteve Yin 	sal_Int32 nCount = 0;
497*0deba7fbSSteve Yin 	sal_Int32 TotalCount = getAccessibleChildCount();
498*0deba7fbSSteve Yin 	for( sal_Int32 i = 0; i < TotalCount; i++ )
499*0deba7fbSSteve Yin 		if( isAccessibleChildSelected(i) ) nCount++;
500*0deba7fbSSteve Yin 	return nCount;
501*0deba7fbSSteve Yin }
502*0deba7fbSSteve Yin //--------------------------------------------------------------------------------------
getSelectedAccessibleChild(sal_Int32 nSelectedChildIndex)503*0deba7fbSSteve Yin uno::Reference<XAccessible> SAL_CALL ScAccessibleEditObject::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
504*0deba7fbSSteve Yin throw ( IndexOutOfBoundsException, RuntimeException)
505*0deba7fbSSteve Yin {
506*0deba7fbSSteve Yin 	if ( nSelectedChildIndex > getSelectedAccessibleChildCount() )
507*0deba7fbSSteve Yin 		throw IndexOutOfBoundsException();
508*0deba7fbSSteve Yin 	sal_Int32 i1, i2;
509*0deba7fbSSteve Yin 	for( i1 = 0, i2 = 0; i1 < getAccessibleChildCount(); i1++ )
510*0deba7fbSSteve Yin 		if( isAccessibleChildSelected(i1) )
511*0deba7fbSSteve Yin 		{
512*0deba7fbSSteve Yin 			if( i2 == nSelectedChildIndex )
513*0deba7fbSSteve Yin 				return getAccessibleChild( i1 );
514*0deba7fbSSteve Yin 			i2++;
515*0deba7fbSSteve Yin 		}
516*0deba7fbSSteve Yin 	return uno::Reference<XAccessible>();
517*0deba7fbSSteve Yin }
518*0deba7fbSSteve Yin //----------------------------------------------------------------------------------
deselectAccessibleChild(sal_Int32)519*0deba7fbSSteve Yin void SAL_CALL ScAccessibleEditObject::deselectAccessibleChild(
520*0deba7fbSSteve Yin 															sal_Int32 )
521*0deba7fbSSteve Yin 															throw ( IndexOutOfBoundsException,
522*0deba7fbSSteve Yin 															RuntimeException )
523*0deba7fbSSteve Yin {
524*0deba7fbSSteve Yin }
getAccessibleRelationSet()525*0deba7fbSSteve Yin uno::Reference< XAccessibleRelationSet > ScAccessibleEditObject::getAccessibleRelationSet(  )
526*0deba7fbSSteve Yin     throw (uno::RuntimeException)
527*0deba7fbSSteve Yin {
528*0deba7fbSSteve Yin        ScUnoGuard aGuard;
529*0deba7fbSSteve Yin 	Window* pWindow = mpWindow;
530*0deba7fbSSteve Yin 	utl::AccessibleRelationSetHelper* rRelationSet = new utl::AccessibleRelationSetHelper;
531*0deba7fbSSteve Yin 	uno::Reference< XAccessibleRelationSet > rSet = rRelationSet;
532*0deba7fbSSteve Yin 	if ( pWindow )
533*0deba7fbSSteve Yin 	{
534*0deba7fbSSteve Yin 		Window *pLabeledBy = pWindow->GetAccessibleRelationLabeledBy();
535*0deba7fbSSteve Yin 		if ( pLabeledBy && pLabeledBy != pWindow )
536*0deba7fbSSteve Yin 		{
537*0deba7fbSSteve Yin 			uno::Sequence< uno::Reference< uno::XInterface > > aSequence(1);
538*0deba7fbSSteve Yin 			aSequence[0] = pLabeledBy->GetAccessible();
539*0deba7fbSSteve Yin 			rRelationSet->AddRelation( AccessibleRelation( AccessibleRelationType::LABELED_BY, aSequence ) );
540*0deba7fbSSteve Yin 		}
541*0deba7fbSSteve Yin 		Window* pMemberOf = pWindow->GetAccessibleRelationMemberOf();
542*0deba7fbSSteve Yin 		if ( pMemberOf && pMemberOf != pWindow )
543*0deba7fbSSteve Yin 		{
544*0deba7fbSSteve Yin 			uno::Sequence< uno::Reference< uno::XInterface > > aSequence(1);
545*0deba7fbSSteve Yin 			aSequence[0] = pMemberOf->GetAccessible();
546*0deba7fbSSteve Yin 			rRelationSet->AddRelation( AccessibleRelation( AccessibleRelationType::MEMBER_OF, aSequence ) );
547*0deba7fbSSteve Yin 		}
548*0deba7fbSSteve Yin 		return rSet;
549*0deba7fbSSteve Yin 	}
550*0deba7fbSSteve Yin 	return uno::Reference< XAccessibleRelationSet >();
551*0deba7fbSSteve Yin }
552cdf0e10cSrcweir 
553