1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b3f79822SAndrew Rist  * distributed with this work for additional information
6*b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b3f79822SAndrew Rist  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist  *
13*b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b3f79822SAndrew Rist  * specific language governing permissions and limitations
18*b3f79822SAndrew Rist  * under the License.
19*b3f79822SAndrew Rist  *
20*b3f79822SAndrew Rist  *************************************************************/
21*b3f79822SAndrew Rist 
22*b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "AccessibleCell.hxx"
29cdf0e10cSrcweir #include "scitems.hxx"
30cdf0e10cSrcweir #include <editeng/eeitem.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include "AccessibleText.hxx"
34cdf0e10cSrcweir #include "AccessibleDocument.hxx"
35cdf0e10cSrcweir #include "tabvwsh.hxx"
36cdf0e10cSrcweir #include "document.hxx"
37cdf0e10cSrcweir #include "attrib.hxx"
38cdf0e10cSrcweir #include "miscuno.hxx"
39cdf0e10cSrcweir #include "unoguard.hxx"
40cdf0e10cSrcweir #include "editsrc.hxx"
41cdf0e10cSrcweir #include "dociter.hxx"
42cdf0e10cSrcweir #include "cell.hxx"
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #ifndef _UTL_ACCESSIBLESTATESETHELPER_HXX
45cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx>
46cdf0e10cSrcweir #endif
47cdf0e10cSrcweir #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLEROLE_HPP_
48cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp>
49cdf0e10cSrcweir #endif
50cdf0e10cSrcweir #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLESTATETYPE_HPP_
51cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
52cdf0e10cSrcweir #endif
53cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
54cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleTable.hpp>
55cdf0e10cSrcweir #include <rtl/uuid.h>
56cdf0e10cSrcweir #include <tools/debug.hxx>
57cdf0e10cSrcweir #include <editeng/brshitem.hxx>
58cdf0e10cSrcweir #include <comphelper/sequence.hxx>
59cdf0e10cSrcweir #include <float.h>
60cdf0e10cSrcweir 
61cdf0e10cSrcweir using namespace	::com::sun::star;
62cdf0e10cSrcweir using namespace	::com::sun::star::accessibility;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir //=====  internal  ============================================================
65cdf0e10cSrcweir 
66cdf0e10cSrcweir ScAccessibleCell::ScAccessibleCell(
67cdf0e10cSrcweir         const uno::Reference<XAccessible>& rxParent,
68cdf0e10cSrcweir 		ScTabViewShell* pViewShell,
69cdf0e10cSrcweir 		ScAddress& rCellAddress,
70cdf0e10cSrcweir 		sal_Int32 nIndex,
71cdf0e10cSrcweir 		ScSplitPos eSplitPos,
72cdf0e10cSrcweir         ScAccessibleDocument* pAccDoc)
73cdf0e10cSrcweir 	:
74cdf0e10cSrcweir 	ScAccessibleCellBase(rxParent, GetDocument(pViewShell), rCellAddress, nIndex),
75cdf0e10cSrcweir         ::accessibility::AccessibleStaticTextBase(CreateEditSource(pViewShell, rCellAddress, eSplitPos)),
76cdf0e10cSrcweir 	mpViewShell(pViewShell),
77cdf0e10cSrcweir     mpAccDoc(pAccDoc),
78cdf0e10cSrcweir 	meSplitPos(eSplitPos)
79cdf0e10cSrcweir {
80cdf0e10cSrcweir 	if (pViewShell)
81cdf0e10cSrcweir 		pViewShell->AddAccessibilityObject(*this);
82cdf0e10cSrcweir }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir ScAccessibleCell::~ScAccessibleCell()
85cdf0e10cSrcweir {
86cdf0e10cSrcweir 	if (!ScAccessibleContextBase::IsDefunc() && !rBHelper.bInDispose)
87cdf0e10cSrcweir 	{
88cdf0e10cSrcweir 		// increment refcount to prevent double call off dtor
89cdf0e10cSrcweir 		osl_incrementInterlockedCount( &m_refCount );
90cdf0e10cSrcweir 		// call dispose to inform object wich have a weak reference to this object
91cdf0e10cSrcweir 		dispose();
92cdf0e10cSrcweir 	}
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir void ScAccessibleCell::Init()
96cdf0e10cSrcweir {
97cdf0e10cSrcweir     ScAccessibleCellBase::Init();
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     SetEventSource(this);
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir void SAL_CALL ScAccessibleCell::disposing()
103cdf0e10cSrcweir {
104cdf0e10cSrcweir     ScUnoGuard aGuard;
105cdf0e10cSrcweir     // #100593# dispose in AccessibleStaticTextBase
106cdf0e10cSrcweir     Dispose();
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 	if (mpViewShell)
109cdf0e10cSrcweir 	{
110cdf0e10cSrcweir 		mpViewShell->RemoveAccessibilityObject(*this);
111cdf0e10cSrcweir 		mpViewShell = NULL;
112cdf0e10cSrcweir 	}
113cdf0e10cSrcweir     mpAccDoc = NULL;
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     ScAccessibleCellBase::disposing();
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 	//=====  XInterface  =====================================================
119cdf0e10cSrcweir 
120cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( ScAccessibleCell, ScAccessibleCellBase, AccessibleStaticTextBase )
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     //=====  XTypeProvider  ===================================================
123cdf0e10cSrcweir 
124cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( ScAccessibleCell, ScAccessibleCellBase, AccessibleStaticTextBase )
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 	//=====  XAccessibleComponent  ============================================
127cdf0e10cSrcweir 
128cdf0e10cSrcweir uno::Reference< XAccessible > SAL_CALL ScAccessibleCell::getAccessibleAtPoint(
129cdf0e10cSrcweir 		const awt::Point& rPoint )
130cdf0e10cSrcweir 		throw (uno::RuntimeException)
131cdf0e10cSrcweir {
132cdf0e10cSrcweir     return AccessibleStaticTextBase::getAccessibleAtPoint(rPoint);
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
135cdf0e10cSrcweir void SAL_CALL ScAccessibleCell::grabFocus(  )
136cdf0e10cSrcweir 		throw (uno::RuntimeException)
137cdf0e10cSrcweir {
138cdf0e10cSrcweir  	ScUnoGuard aGuard;
139cdf0e10cSrcweir     IsObjectValid();
140cdf0e10cSrcweir 	if (getAccessibleParent().is() && mpViewShell)
141cdf0e10cSrcweir 	{
142cdf0e10cSrcweir 		uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
143cdf0e10cSrcweir 		if (xAccessibleComponent.is())
144cdf0e10cSrcweir 		{
145cdf0e10cSrcweir 			xAccessibleComponent->grabFocus();
146cdf0e10cSrcweir 			mpViewShell->SetCursor(maCellAddress.Col(), maCellAddress.Row());
147cdf0e10cSrcweir 		}
148cdf0e10cSrcweir 	}
149cdf0e10cSrcweir }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir Rectangle ScAccessibleCell::GetBoundingBoxOnScreen(void) const
152cdf0e10cSrcweir 		throw (uno::RuntimeException)
153cdf0e10cSrcweir {
154cdf0e10cSrcweir 	Rectangle aCellRect(GetBoundingBox());
155cdf0e10cSrcweir 	if (mpViewShell)
156cdf0e10cSrcweir 	{
157cdf0e10cSrcweir 		Window* pWindow = mpViewShell->GetWindowByPos(meSplitPos);
158cdf0e10cSrcweir 		if (pWindow)
159cdf0e10cSrcweir 		{
160cdf0e10cSrcweir 			Rectangle aRect = pWindow->GetWindowExtentsRelative(NULL);
161cdf0e10cSrcweir 			aCellRect.setX(aCellRect.getX() + aRect.getX());
162cdf0e10cSrcweir 			aCellRect.setY(aCellRect.getY() + aRect.getY());
163cdf0e10cSrcweir 		}
164cdf0e10cSrcweir 	}
165cdf0e10cSrcweir 	return aCellRect;
166cdf0e10cSrcweir }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir Rectangle ScAccessibleCell::GetBoundingBox(void) const
169cdf0e10cSrcweir 		throw (uno::RuntimeException)
170cdf0e10cSrcweir {
171cdf0e10cSrcweir 	Rectangle aCellRect;
172cdf0e10cSrcweir 	if (mpViewShell)
173cdf0e10cSrcweir 	{
174cdf0e10cSrcweir 		long nSizeX, nSizeY;
175cdf0e10cSrcweir 		mpViewShell->GetViewData()->GetMergeSizePixel(
176cdf0e10cSrcweir 			maCellAddress.Col(), maCellAddress.Row(), nSizeX, nSizeY);
177cdf0e10cSrcweir 		aCellRect.SetSize(Size(nSizeX, nSizeY));
178cdf0e10cSrcweir 		aCellRect.SetPos(mpViewShell->GetViewData()->GetScrPos(maCellAddress.Col(), maCellAddress.Row(), meSplitPos, sal_True));
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 		Window* pWindow = mpViewShell->GetWindowByPos(meSplitPos);
181cdf0e10cSrcweir 		if (pWindow)
182cdf0e10cSrcweir 		{
183cdf0e10cSrcweir 			Rectangle aRect(pWindow->GetWindowExtentsRelative(pWindow->GetAccessibleParentWindow()));
184cdf0e10cSrcweir 			aRect.Move(-aRect.Left(), -aRect.Top());
185cdf0e10cSrcweir 			aCellRect = aRect.Intersection(aCellRect);
186cdf0e10cSrcweir 		}
187cdf0e10cSrcweir 
188cdf0e10cSrcweir         /*  #i19430# Gnopernicus reads text partly if it sticks out of the cell
189cdf0e10cSrcweir             boundaries. This leads to wrong results in cases where the cell
190cdf0e10cSrcweir             text is rotated, because rotation is not taken into account when
191cdf0e10cSrcweir             calculating the visible part of the text. In these cases we will
192cdf0e10cSrcweir             simply expand the cell size to the width of the unrotated text. */
193cdf0e10cSrcweir         if (mpDoc)
194cdf0e10cSrcweir         {
195cdf0e10cSrcweir             const SfxInt32Item* pItem = static_cast< const SfxInt32Item* >(
196cdf0e10cSrcweir                 mpDoc->GetAttr( maCellAddress.Col(), maCellAddress.Row(), maCellAddress.Tab(), ATTR_ROTATE_VALUE ) );
197cdf0e10cSrcweir             if( pItem && (pItem->GetValue() != 0) )
198cdf0e10cSrcweir             {
199cdf0e10cSrcweir                 Rectangle aParaRect = GetParagraphBoundingBox();
200cdf0e10cSrcweir                 if( !aParaRect.IsEmpty() && (aCellRect.GetWidth() < aParaRect.GetWidth()) )
201cdf0e10cSrcweir                     aCellRect.SetSize( Size( aParaRect.GetWidth(), aCellRect.GetHeight() ) );
202cdf0e10cSrcweir             }
203cdf0e10cSrcweir         }
204cdf0e10cSrcweir 	}
205cdf0e10cSrcweir     if (aCellRect.IsEmpty())
206cdf0e10cSrcweir         aCellRect.SetPos(Point(-1, -1));
207cdf0e10cSrcweir 	return aCellRect;
208cdf0e10cSrcweir }
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 	//=====  XAccessibleContext  ==============================================
211cdf0e10cSrcweir 
212cdf0e10cSrcweir sal_Int32 SAL_CALL
213cdf0e10cSrcweir 	ScAccessibleCell::getAccessibleChildCount(void)
214cdf0e10cSrcweir     				throw (uno::RuntimeException)
215cdf0e10cSrcweir {
216cdf0e10cSrcweir     return AccessibleStaticTextBase::getAccessibleChildCount();
217cdf0e10cSrcweir }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir uno::Reference< XAccessible > SAL_CALL
220cdf0e10cSrcweir 	ScAccessibleCell::getAccessibleChild(sal_Int32 nIndex)
221cdf0e10cSrcweir         throw (uno::RuntimeException,
222cdf0e10cSrcweir 		lang::IndexOutOfBoundsException)
223cdf0e10cSrcweir {
224cdf0e10cSrcweir     return AccessibleStaticTextBase::getAccessibleChild(nIndex);
225cdf0e10cSrcweir }
226cdf0e10cSrcweir 
227cdf0e10cSrcweir uno::Reference<XAccessibleStateSet> SAL_CALL
228cdf0e10cSrcweir 	ScAccessibleCell::getAccessibleStateSet(void)
229cdf0e10cSrcweir     throw (uno::RuntimeException)
230cdf0e10cSrcweir {
231cdf0e10cSrcweir 	ScUnoGuard aGuard;
232cdf0e10cSrcweir 	uno::Reference<XAccessibleStateSet> xParentStates;
233cdf0e10cSrcweir 	if (getAccessibleParent().is())
234cdf0e10cSrcweir 	{
235cdf0e10cSrcweir 		uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
236cdf0e10cSrcweir 		xParentStates = xParentContext->getAccessibleStateSet();
237cdf0e10cSrcweir 	}
238cdf0e10cSrcweir 	utl::AccessibleStateSetHelper* pStateSet = new utl::AccessibleStateSetHelper();
239cdf0e10cSrcweir 	if (IsDefunc(xParentStates))
240cdf0e10cSrcweir 		pStateSet->AddState(AccessibleStateType::DEFUNC);
241cdf0e10cSrcweir     else
242cdf0e10cSrcweir     {
243cdf0e10cSrcweir 	    if (IsEditable(xParentStates))
244cdf0e10cSrcweir 	    {
245cdf0e10cSrcweir 		    pStateSet->AddState(AccessibleStateType::EDITABLE);
246cdf0e10cSrcweir 		    pStateSet->AddState(AccessibleStateType::RESIZABLE);
247cdf0e10cSrcweir 	    }
248cdf0e10cSrcweir 	    pStateSet->AddState(AccessibleStateType::ENABLED);
249cdf0e10cSrcweir 	    pStateSet->AddState(AccessibleStateType::MULTI_LINE);
250cdf0e10cSrcweir 	    pStateSet->AddState(AccessibleStateType::MULTI_SELECTABLE);
251cdf0e10cSrcweir 	    if (IsOpaque(xParentStates))
252cdf0e10cSrcweir 		    pStateSet->AddState(AccessibleStateType::OPAQUE);
253cdf0e10cSrcweir 	    pStateSet->AddState(AccessibleStateType::SELECTABLE);
254cdf0e10cSrcweir 	    if (IsSelected())
255cdf0e10cSrcweir 		    pStateSet->AddState(AccessibleStateType::SELECTED);
256cdf0e10cSrcweir 	    if (isShowing())
257cdf0e10cSrcweir 		    pStateSet->AddState(AccessibleStateType::SHOWING);
258cdf0e10cSrcweir 	    pStateSet->AddState(AccessibleStateType::TRANSIENT);
259cdf0e10cSrcweir 	    if (isVisible())
260cdf0e10cSrcweir 		    pStateSet->AddState(AccessibleStateType::VISIBLE);
261cdf0e10cSrcweir     }
262cdf0e10cSrcweir 	return pStateSet;
263cdf0e10cSrcweir }
264cdf0e10cSrcweir 
265cdf0e10cSrcweir uno::Reference<XAccessibleRelationSet> SAL_CALL
266cdf0e10cSrcweir    	ScAccessibleCell::getAccessibleRelationSet(void)
267cdf0e10cSrcweir     throw (uno::RuntimeException)
268cdf0e10cSrcweir {
269cdf0e10cSrcweir 	ScUnoGuard aGuard;
270cdf0e10cSrcweir     IsObjectValid();
271cdf0e10cSrcweir     utl::AccessibleRelationSetHelper* pRelationSet = NULL;
272cdf0e10cSrcweir     if (mpAccDoc)
273cdf0e10cSrcweir         pRelationSet = mpAccDoc->GetRelationSet(&maCellAddress);
274cdf0e10cSrcweir     if (!pRelationSet)
275cdf0e10cSrcweir 	    pRelationSet = new utl::AccessibleRelationSetHelper();
276cdf0e10cSrcweir 	FillDependends(pRelationSet);
277cdf0e10cSrcweir 	FillPrecedents(pRelationSet);
278cdf0e10cSrcweir 	return pRelationSet;
279cdf0e10cSrcweir }
280cdf0e10cSrcweir 
281cdf0e10cSrcweir 	//=====  XServiceInfo  ====================================================
282cdf0e10cSrcweir 
283cdf0e10cSrcweir ::rtl::OUString SAL_CALL ScAccessibleCell::getImplementationName(void)
284cdf0e10cSrcweir         throw (uno::RuntimeException)
285cdf0e10cSrcweir {
286cdf0e10cSrcweir 	return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ("ScAccessibleCell"));
287cdf0e10cSrcweir }
288cdf0e10cSrcweir 
289cdf0e10cSrcweir uno::Sequence< ::rtl::OUString> SAL_CALL
290cdf0e10cSrcweir 	ScAccessibleCell::getSupportedServiceNames(void)
291cdf0e10cSrcweir         throw (uno::RuntimeException)
292cdf0e10cSrcweir {
293cdf0e10cSrcweir 	uno::Sequence< ::rtl::OUString > aSequence = ScAccessibleContextBase::getSupportedServiceNames();
294cdf0e10cSrcweir     sal_Int32 nOldSize(aSequence.getLength());
295cdf0e10cSrcweir     aSequence.realloc(nOldSize + 1);
296cdf0e10cSrcweir     ::rtl::OUString* pNames = aSequence.getArray();
297cdf0e10cSrcweir 
298cdf0e10cSrcweir 	pNames[nOldSize] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.AccessibleCell"));
299cdf0e10cSrcweir 
300cdf0e10cSrcweir 	return aSequence;
301cdf0e10cSrcweir }
302cdf0e10cSrcweir 
303cdf0e10cSrcweir 	//====  internal  =========================================================
304cdf0e10cSrcweir 
305cdf0e10cSrcweir sal_Bool ScAccessibleCell::IsDefunc(
306cdf0e10cSrcweir 	const uno::Reference<XAccessibleStateSet>& rxParentStates)
307cdf0e10cSrcweir {
308cdf0e10cSrcweir 	return ScAccessibleContextBase::IsDefunc() || (mpDoc == NULL) || (mpViewShell == NULL) || !getAccessibleParent().is() ||
309cdf0e10cSrcweir 		 (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
310cdf0e10cSrcweir }
311cdf0e10cSrcweir 
312cdf0e10cSrcweir sal_Bool ScAccessibleCell::IsEditable(
313cdf0e10cSrcweir 	const uno::Reference<XAccessibleStateSet>& rxParentStates)
314cdf0e10cSrcweir {
315cdf0e10cSrcweir 	sal_Bool bEditable(sal_True);
316cdf0e10cSrcweir 	if (rxParentStates.is() && !rxParentStates->contains(AccessibleStateType::EDITABLE) &&
317cdf0e10cSrcweir 		mpDoc)
318cdf0e10cSrcweir 	{
319cdf0e10cSrcweir 		// here I have to test whether the protection of the table should influence this cell.
320cdf0e10cSrcweir 		const ScProtectionAttr* pItem = (const ScProtectionAttr*)mpDoc->GetAttr(
321cdf0e10cSrcweir 			maCellAddress.Col(), maCellAddress.Row(),
322cdf0e10cSrcweir 			maCellAddress.Tab(), ATTR_PROTECTION);
323cdf0e10cSrcweir 		if (pItem)
324cdf0e10cSrcweir 			bEditable = !pItem->GetProtection();
325cdf0e10cSrcweir 	}
326cdf0e10cSrcweir 	return bEditable;
327cdf0e10cSrcweir }
328cdf0e10cSrcweir 
329cdf0e10cSrcweir sal_Bool ScAccessibleCell::IsOpaque(
330cdf0e10cSrcweir     const uno::Reference<XAccessibleStateSet>& /* rxParentStates */)
331cdf0e10cSrcweir {
332cdf0e10cSrcweir 	// test whether there is a background color
333cdf0e10cSrcweir 	sal_Bool bOpaque(sal_True);
334cdf0e10cSrcweir 	if (mpDoc)
335cdf0e10cSrcweir 	{
336cdf0e10cSrcweir 		const SvxBrushItem* pItem = (const SvxBrushItem*)mpDoc->GetAttr(
337cdf0e10cSrcweir 			maCellAddress.Col(), maCellAddress.Row(),
338cdf0e10cSrcweir 			maCellAddress.Tab(), ATTR_BACKGROUND);
339cdf0e10cSrcweir 		if (pItem)
340cdf0e10cSrcweir 			bOpaque = pItem->GetColor() != COL_TRANSPARENT;
341cdf0e10cSrcweir 	}
342cdf0e10cSrcweir 	return bOpaque;
343cdf0e10cSrcweir }
344cdf0e10cSrcweir 
345cdf0e10cSrcweir sal_Bool ScAccessibleCell::IsSelected()
346cdf0e10cSrcweir {
347cdf0e10cSrcweir 	sal_Bool bResult(sal_False);
348cdf0e10cSrcweir 	if (mpViewShell && mpViewShell->GetViewData())
349cdf0e10cSrcweir 	{
350cdf0e10cSrcweir 		const ScMarkData& rMarkdata = mpViewShell->GetViewData()->GetMarkData();
351cdf0e10cSrcweir 		bResult = rMarkdata.IsCellMarked(maCellAddress.Col(), maCellAddress.Row());
352cdf0e10cSrcweir 	}
353cdf0e10cSrcweir 	return bResult;
354cdf0e10cSrcweir }
355cdf0e10cSrcweir 
356cdf0e10cSrcweir ScDocument* ScAccessibleCell::GetDocument(ScTabViewShell* pViewShell)
357cdf0e10cSrcweir {
358cdf0e10cSrcweir 	ScDocument* pDoc = NULL;
359cdf0e10cSrcweir 	if (pViewShell && pViewShell->GetViewData())
360cdf0e10cSrcweir 		pDoc = pViewShell->GetViewData()->GetDocument();
361cdf0e10cSrcweir 	return pDoc;
362cdf0e10cSrcweir }
363cdf0e10cSrcweir 
364cdf0e10cSrcweir ::std::auto_ptr< SvxEditSource > ScAccessibleCell::CreateEditSource(ScTabViewShell* pViewShell, ScAddress aCell, ScSplitPos eSplitPos)
365cdf0e10cSrcweir {
366cdf0e10cSrcweir 	::std::auto_ptr < ScAccessibleTextData > pAccessibleCellTextData
367cdf0e10cSrcweir         ( new ScAccessibleCellTextData( pViewShell, aCell, eSplitPos, this ) );
368cdf0e10cSrcweir 	::std::auto_ptr< SvxEditSource > pEditSource (new ScAccessibilityEditSource(pAccessibleCellTextData));
369cdf0e10cSrcweir 
370cdf0e10cSrcweir     return pEditSource;
371cdf0e10cSrcweir }
372cdf0e10cSrcweir 
373cdf0e10cSrcweir void ScAccessibleCell::FillDependends(utl::AccessibleRelationSetHelper* pRelationSet)
374cdf0e10cSrcweir {
375cdf0e10cSrcweir 	if (mpDoc)
376cdf0e10cSrcweir 	{
377cdf0e10cSrcweir 		ScCellIterator aCellIter( mpDoc, 0,0, maCellAddress.Tab(), MAXCOL,MAXROW, maCellAddress.Tab() );
378cdf0e10cSrcweir 		ScBaseCell* pCell = aCellIter.GetFirst();
379cdf0e10cSrcweir 		while (pCell)
380cdf0e10cSrcweir 		{
381cdf0e10cSrcweir 			if (pCell->GetCellType() == CELLTYPE_FORMULA)
382cdf0e10cSrcweir 			{
383cdf0e10cSrcweir 				sal_Bool bFound(sal_False);
384cdf0e10cSrcweir 				ScDetectiveRefIter aIter( (ScFormulaCell*) pCell );
385cdf0e10cSrcweir                 ScRange aRef;
386cdf0e10cSrcweir 				while ( !bFound && aIter.GetNextRef( aRef ) )
387cdf0e10cSrcweir 				{
388cdf0e10cSrcweir 					if (aRef.In(maCellAddress))
389cdf0e10cSrcweir 						bFound = sal_True;
390cdf0e10cSrcweir 				}
391cdf0e10cSrcweir 				if (bFound)
392cdf0e10cSrcweir 					AddRelation(ScAddress(aCellIter.GetCol(), aCellIter.GetRow(), aCellIter.GetTab()), AccessibleRelationType::CONTROLLER_FOR, pRelationSet);
393cdf0e10cSrcweir 			}
394cdf0e10cSrcweir 			pCell = aCellIter.GetNext();
395cdf0e10cSrcweir 		}
396cdf0e10cSrcweir 	}
397cdf0e10cSrcweir }
398cdf0e10cSrcweir 
399cdf0e10cSrcweir void ScAccessibleCell::FillPrecedents(utl::AccessibleRelationSetHelper* pRelationSet)
400cdf0e10cSrcweir {
401cdf0e10cSrcweir 	if (mpDoc)
402cdf0e10cSrcweir 	{
403cdf0e10cSrcweir 		ScBaseCell* pBaseCell = mpDoc->GetCell(maCellAddress);
404cdf0e10cSrcweir 		if (pBaseCell && (pBaseCell->GetCellType() == CELLTYPE_FORMULA))
405cdf0e10cSrcweir 		{
406cdf0e10cSrcweir 			ScFormulaCell* pFCell = (ScFormulaCell*) pBaseCell;
407cdf0e10cSrcweir 
408cdf0e10cSrcweir 			ScDetectiveRefIter aIter( pFCell );
409cdf0e10cSrcweir             ScRange aRef;
410cdf0e10cSrcweir 			while ( aIter.GetNextRef( aRef ) )
411cdf0e10cSrcweir 			{
412cdf0e10cSrcweir 				AddRelation( aRef, AccessibleRelationType::CONTROLLED_BY, pRelationSet);
413cdf0e10cSrcweir 			}
414cdf0e10cSrcweir 		}
415cdf0e10cSrcweir 	}
416cdf0e10cSrcweir }
417cdf0e10cSrcweir 
418cdf0e10cSrcweir void ScAccessibleCell::AddRelation(const ScAddress& rCell,
419cdf0e10cSrcweir 	const sal_uInt16 aRelationType,
420cdf0e10cSrcweir 	utl::AccessibleRelationSetHelper* pRelationSet)
421cdf0e10cSrcweir {
422cdf0e10cSrcweir 	AddRelation(ScRange(rCell, rCell), aRelationType, pRelationSet);
423cdf0e10cSrcweir }
424cdf0e10cSrcweir 
425cdf0e10cSrcweir void ScAccessibleCell::AddRelation(const ScRange& rRange,
426cdf0e10cSrcweir 	const sal_uInt16 aRelationType,
427cdf0e10cSrcweir 	utl::AccessibleRelationSetHelper* pRelationSet)
428cdf0e10cSrcweir {
429cdf0e10cSrcweir 	uno::Reference < XAccessibleTable > xTable ( getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY );
430cdf0e10cSrcweir 	if (xTable.is())
431cdf0e10cSrcweir 	{
432cdf0e10cSrcweir         sal_uInt32 nCount(static_cast<sal_uInt32>(rRange.aEnd.Col() -
433cdf0e10cSrcweir                     rRange.aStart.Col() + 1) * (rRange.aEnd.Row() -
434cdf0e10cSrcweir                     rRange.aStart.Row() + 1));
435cdf0e10cSrcweir 		uno::Sequence < uno::Reference < uno::XInterface > > aTargetSet( nCount );
436cdf0e10cSrcweir 		uno::Reference < uno::XInterface >* pTargetSet = aTargetSet.getArray();
437cdf0e10cSrcweir 		if (pTargetSet)
438cdf0e10cSrcweir 		{
439cdf0e10cSrcweir 			sal_uInt32 nPos(0);
440cdf0e10cSrcweir             for (sal_uInt32 nRow = rRange.aStart.Row(); nRow <= sal::static_int_cast<sal_uInt32>(rRange.aEnd.Row()); ++nRow)
441cdf0e10cSrcweir 			{
442cdf0e10cSrcweir                 for (sal_uInt32 nCol = rRange.aStart.Col(); nCol <= sal::static_int_cast<sal_uInt32>(rRange.aEnd.Col()); ++nCol)
443cdf0e10cSrcweir 				{
444cdf0e10cSrcweir 					pTargetSet[nPos] = xTable->getAccessibleCellAt(nRow, nCol);
445cdf0e10cSrcweir 					++nPos;
446cdf0e10cSrcweir 				}
447cdf0e10cSrcweir 			}
448cdf0e10cSrcweir 			DBG_ASSERT(nCount == nPos, "something wents wrong");
449cdf0e10cSrcweir 		}
450cdf0e10cSrcweir 		AccessibleRelation aRelation;
451cdf0e10cSrcweir 		aRelation.RelationType = aRelationType;
452cdf0e10cSrcweir 		aRelation.TargetSet = aTargetSet;
453cdf0e10cSrcweir 		pRelationSet->AddRelation(aRelation);
454cdf0e10cSrcweir 	}
455cdf0e10cSrcweir }
456