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 
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"
430deba7fbSSteve Yin #include "validat.hxx"
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 
610deba7fbSSteve Yin #include "AccessibleSpreadsheet.hxx"
62cdf0e10cSrcweir using namespace	::com::sun::star;
63cdf0e10cSrcweir using namespace	::com::sun::star::accessibility;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir //=====  internal  ============================================================
66cdf0e10cSrcweir 
ScAccessibleCell(const uno::Reference<XAccessible> & rxParent,ScTabViewShell * pViewShell,ScAddress & rCellAddress,sal_Int32 nIndex,ScSplitPos eSplitPos,ScAccessibleDocument * pAccDoc)67cdf0e10cSrcweir ScAccessibleCell::ScAccessibleCell(
68cdf0e10cSrcweir         const uno::Reference<XAccessible>& rxParent,
69cdf0e10cSrcweir 		ScTabViewShell* pViewShell,
70cdf0e10cSrcweir 		ScAddress& rCellAddress,
71cdf0e10cSrcweir 		sal_Int32 nIndex,
72cdf0e10cSrcweir 		ScSplitPos eSplitPos,
73cdf0e10cSrcweir         ScAccessibleDocument* pAccDoc)
74cdf0e10cSrcweir 	:
75cdf0e10cSrcweir 	ScAccessibleCellBase(rxParent, GetDocument(pViewShell), rCellAddress, nIndex),
76cdf0e10cSrcweir         ::accessibility::AccessibleStaticTextBase(CreateEditSource(pViewShell, rCellAddress, eSplitPos)),
77cdf0e10cSrcweir 	mpViewShell(pViewShell),
78cdf0e10cSrcweir     mpAccDoc(pAccDoc),
79cdf0e10cSrcweir 	meSplitPos(eSplitPos)
80cdf0e10cSrcweir {
81cdf0e10cSrcweir 	if (pViewShell)
82cdf0e10cSrcweir 		pViewShell->AddAccessibilityObject(*this);
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
~ScAccessibleCell()85cdf0e10cSrcweir ScAccessibleCell::~ScAccessibleCell()
86cdf0e10cSrcweir {
87cdf0e10cSrcweir 	if (!ScAccessibleContextBase::IsDefunc() && !rBHelper.bInDispose)
88cdf0e10cSrcweir 	{
89cdf0e10cSrcweir 		// increment refcount to prevent double call off dtor
90cdf0e10cSrcweir 		osl_incrementInterlockedCount( &m_refCount );
91cdf0e10cSrcweir 		// call dispose to inform object wich have a weak reference to this object
92cdf0e10cSrcweir 		dispose();
93cdf0e10cSrcweir 	}
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
Init()96cdf0e10cSrcweir void ScAccessibleCell::Init()
97cdf0e10cSrcweir {
98cdf0e10cSrcweir     ScAccessibleCellBase::Init();
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     SetEventSource(this);
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
disposing()103cdf0e10cSrcweir void SAL_CALL ScAccessibleCell::disposing()
104cdf0e10cSrcweir {
105cdf0e10cSrcweir     ScUnoGuard aGuard;
106cdf0e10cSrcweir     // #100593# dispose in AccessibleStaticTextBase
107cdf0e10cSrcweir     Dispose();
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	if (mpViewShell)
110cdf0e10cSrcweir 	{
111cdf0e10cSrcweir 		mpViewShell->RemoveAccessibilityObject(*this);
112cdf0e10cSrcweir 		mpViewShell = NULL;
113cdf0e10cSrcweir 	}
114cdf0e10cSrcweir     mpAccDoc = NULL;
115cdf0e10cSrcweir 
116cdf0e10cSrcweir     ScAccessibleCellBase::disposing();
117cdf0e10cSrcweir }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 	//=====  XInterface  =====================================================
120cdf0e10cSrcweir 
IMPLEMENT_FORWARD_XINTERFACE3(ScAccessibleCell,ScAccessibleCellBase,AccessibleStaticTextBase,ScAccessibleCellAttributeImpl)1210deba7fbSSteve Yin IMPLEMENT_FORWARD_XINTERFACE3( ScAccessibleCell, ScAccessibleCellBase, AccessibleStaticTextBase, ScAccessibleCellAttributeImpl )
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     //=====  XTypeProvider  ===================================================
124cdf0e10cSrcweir 
1250deba7fbSSteve Yin IMPLEMENT_FORWARD_XTYPEPROVIDER3( ScAccessibleCell, ScAccessibleCellBase, AccessibleStaticTextBase, ScAccessibleCellAttributeImpl )
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	//=====  XAccessibleComponent  ============================================
128cdf0e10cSrcweir 
129cdf0e10cSrcweir uno::Reference< XAccessible > SAL_CALL ScAccessibleCell::getAccessibleAtPoint(
130cdf0e10cSrcweir 		const awt::Point& rPoint )
131cdf0e10cSrcweir 		throw (uno::RuntimeException)
132cdf0e10cSrcweir {
133cdf0e10cSrcweir     return AccessibleStaticTextBase::getAccessibleAtPoint(rPoint);
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
grabFocus()136cdf0e10cSrcweir void SAL_CALL ScAccessibleCell::grabFocus(  )
137cdf0e10cSrcweir 		throw (uno::RuntimeException)
138cdf0e10cSrcweir {
139cdf0e10cSrcweir  	ScUnoGuard aGuard;
140cdf0e10cSrcweir     IsObjectValid();
141cdf0e10cSrcweir 	if (getAccessibleParent().is() && mpViewShell)
142cdf0e10cSrcweir 	{
143cdf0e10cSrcweir 		uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
144cdf0e10cSrcweir 		if (xAccessibleComponent.is())
145cdf0e10cSrcweir 		{
146cdf0e10cSrcweir 			xAccessibleComponent->grabFocus();
147cdf0e10cSrcweir 			mpViewShell->SetCursor(maCellAddress.Col(), maCellAddress.Row());
148cdf0e10cSrcweir 		}
149cdf0e10cSrcweir 	}
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
GetBoundingBoxOnScreen(void) const152cdf0e10cSrcweir Rectangle ScAccessibleCell::GetBoundingBoxOnScreen(void) const
153cdf0e10cSrcweir 		throw (uno::RuntimeException)
154cdf0e10cSrcweir {
155cdf0e10cSrcweir 	Rectangle aCellRect(GetBoundingBox());
156cdf0e10cSrcweir 	if (mpViewShell)
157cdf0e10cSrcweir 	{
158cdf0e10cSrcweir 		Window* pWindow = mpViewShell->GetWindowByPos(meSplitPos);
159cdf0e10cSrcweir 		if (pWindow)
160cdf0e10cSrcweir 		{
161cdf0e10cSrcweir 			Rectangle aRect = pWindow->GetWindowExtentsRelative(NULL);
162cdf0e10cSrcweir 			aCellRect.setX(aCellRect.getX() + aRect.getX());
163cdf0e10cSrcweir 			aCellRect.setY(aCellRect.getY() + aRect.getY());
164cdf0e10cSrcweir 		}
165cdf0e10cSrcweir 	}
166cdf0e10cSrcweir 	return aCellRect;
167cdf0e10cSrcweir }
168cdf0e10cSrcweir 
GetBoundingBox(void) const169cdf0e10cSrcweir Rectangle ScAccessibleCell::GetBoundingBox(void) const
170cdf0e10cSrcweir 		throw (uno::RuntimeException)
171cdf0e10cSrcweir {
172cdf0e10cSrcweir 	Rectangle aCellRect;
173cdf0e10cSrcweir 	if (mpViewShell)
174cdf0e10cSrcweir 	{
175cdf0e10cSrcweir 		long nSizeX, nSizeY;
176cdf0e10cSrcweir 		mpViewShell->GetViewData()->GetMergeSizePixel(
177cdf0e10cSrcweir 			maCellAddress.Col(), maCellAddress.Row(), nSizeX, nSizeY);
178cdf0e10cSrcweir 		aCellRect.SetSize(Size(nSizeX, nSizeY));
179cdf0e10cSrcweir 		aCellRect.SetPos(mpViewShell->GetViewData()->GetScrPos(maCellAddress.Col(), maCellAddress.Row(), meSplitPos, sal_True));
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 		Window* pWindow = mpViewShell->GetWindowByPos(meSplitPos);
182cdf0e10cSrcweir 		if (pWindow)
183cdf0e10cSrcweir 		{
184cdf0e10cSrcweir 			Rectangle aRect(pWindow->GetWindowExtentsRelative(pWindow->GetAccessibleParentWindow()));
185cdf0e10cSrcweir 			aRect.Move(-aRect.Left(), -aRect.Top());
186cdf0e10cSrcweir 			aCellRect = aRect.Intersection(aCellRect);
187cdf0e10cSrcweir 		}
188cdf0e10cSrcweir 
189cdf0e10cSrcweir         /*  #i19430# Gnopernicus reads text partly if it sticks out of the cell
190cdf0e10cSrcweir             boundaries. This leads to wrong results in cases where the cell
191cdf0e10cSrcweir             text is rotated, because rotation is not taken into account when
192cdf0e10cSrcweir             calculating the visible part of the text. In these cases we will
193cdf0e10cSrcweir             simply expand the cell size to the width of the unrotated text. */
194cdf0e10cSrcweir         if (mpDoc)
195cdf0e10cSrcweir         {
196cdf0e10cSrcweir             const SfxInt32Item* pItem = static_cast< const SfxInt32Item* >(
197cdf0e10cSrcweir                 mpDoc->GetAttr( maCellAddress.Col(), maCellAddress.Row(), maCellAddress.Tab(), ATTR_ROTATE_VALUE ) );
198cdf0e10cSrcweir             if( pItem && (pItem->GetValue() != 0) )
199cdf0e10cSrcweir             {
200cdf0e10cSrcweir                 Rectangle aParaRect = GetParagraphBoundingBox();
201cdf0e10cSrcweir                 if( !aParaRect.IsEmpty() && (aCellRect.GetWidth() < aParaRect.GetWidth()) )
202cdf0e10cSrcweir                     aCellRect.SetSize( Size( aParaRect.GetWidth(), aCellRect.GetHeight() ) );
203cdf0e10cSrcweir             }
204cdf0e10cSrcweir         }
205cdf0e10cSrcweir 	}
206cdf0e10cSrcweir     if (aCellRect.IsEmpty())
207cdf0e10cSrcweir         aCellRect.SetPos(Point(-1, -1));
208cdf0e10cSrcweir 	return aCellRect;
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 	//=====  XAccessibleContext  ==============================================
212cdf0e10cSrcweir 
213cdf0e10cSrcweir sal_Int32 SAL_CALL
getAccessibleChildCount(void)214cdf0e10cSrcweir 	ScAccessibleCell::getAccessibleChildCount(void)
215cdf0e10cSrcweir     				throw (uno::RuntimeException)
216cdf0e10cSrcweir {
217cdf0e10cSrcweir     return AccessibleStaticTextBase::getAccessibleChildCount();
218cdf0e10cSrcweir }
219cdf0e10cSrcweir 
220cdf0e10cSrcweir uno::Reference< XAccessible > SAL_CALL
getAccessibleChild(sal_Int32 nIndex)221cdf0e10cSrcweir 	ScAccessibleCell::getAccessibleChild(sal_Int32 nIndex)
222cdf0e10cSrcweir         throw (uno::RuntimeException,
223cdf0e10cSrcweir 		lang::IndexOutOfBoundsException)
224cdf0e10cSrcweir {
225cdf0e10cSrcweir     return AccessibleStaticTextBase::getAccessibleChild(nIndex);
226cdf0e10cSrcweir }
227cdf0e10cSrcweir 
228cdf0e10cSrcweir uno::Reference<XAccessibleStateSet> SAL_CALL
getAccessibleStateSet(void)229cdf0e10cSrcweir 	ScAccessibleCell::getAccessibleStateSet(void)
230cdf0e10cSrcweir     throw (uno::RuntimeException)
231cdf0e10cSrcweir {
232cdf0e10cSrcweir 	ScUnoGuard aGuard;
233cdf0e10cSrcweir 	uno::Reference<XAccessibleStateSet> xParentStates;
234cdf0e10cSrcweir 	if (getAccessibleParent().is())
235cdf0e10cSrcweir 	{
236cdf0e10cSrcweir 		uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
237cdf0e10cSrcweir 		xParentStates = xParentContext->getAccessibleStateSet();
238cdf0e10cSrcweir 	}
239cdf0e10cSrcweir 	utl::AccessibleStateSetHelper* pStateSet = new utl::AccessibleStateSetHelper();
240cdf0e10cSrcweir 	if (IsDefunc(xParentStates))
241cdf0e10cSrcweir 		pStateSet->AddState(AccessibleStateType::DEFUNC);
242cdf0e10cSrcweir     else
243cdf0e10cSrcweir     {
2440deba7fbSSteve Yin 		if (IsFormulaMode())
2450deba7fbSSteve Yin 		{
2460deba7fbSSteve Yin 			pStateSet->AddState(AccessibleStateType::ENABLED);
2470deba7fbSSteve Yin 		    pStateSet->AddState(AccessibleStateType::MULTI_LINE);
2480deba7fbSSteve Yin 			pStateSet->AddState(AccessibleStateType::MULTI_SELECTABLE);
2490deba7fbSSteve Yin 			if (IsOpaque(xParentStates))
2500deba7fbSSteve Yin 				pStateSet->AddState(AccessibleStateType::OPAQUE);
2510deba7fbSSteve Yin 			pStateSet->AddState(AccessibleStateType::SELECTABLE);
2520deba7fbSSteve Yin 			if (IsSelected())
2530deba7fbSSteve Yin 				pStateSet->AddState(AccessibleStateType::SELECTED);
2540deba7fbSSteve Yin 			if (isShowing())
2550deba7fbSSteve Yin 				pStateSet->AddState(AccessibleStateType::SHOWING);
2560deba7fbSSteve Yin 			pStateSet->AddState(AccessibleStateType::TRANSIENT);
2570deba7fbSSteve Yin 			if (isVisible())
2580deba7fbSSteve Yin 				pStateSet->AddState(AccessibleStateType::VISIBLE);
2590deba7fbSSteve Yin 			return pStateSet;
2600deba7fbSSteve Yin 		}
261cdf0e10cSrcweir 	    if (IsEditable(xParentStates))
262cdf0e10cSrcweir 	    {
263cdf0e10cSrcweir 		    pStateSet->AddState(AccessibleStateType::EDITABLE);
264cdf0e10cSrcweir 		    pStateSet->AddState(AccessibleStateType::RESIZABLE);
265cdf0e10cSrcweir 	    }
266cdf0e10cSrcweir 	    pStateSet->AddState(AccessibleStateType::ENABLED);
267cdf0e10cSrcweir 	    pStateSet->AddState(AccessibleStateType::MULTI_LINE);
268cdf0e10cSrcweir 	    pStateSet->AddState(AccessibleStateType::MULTI_SELECTABLE);
2690deba7fbSSteve Yin 	    pStateSet->AddState(AccessibleStateType::FOCUSABLE);
270cdf0e10cSrcweir 	    if (IsOpaque(xParentStates))
271cdf0e10cSrcweir 		    pStateSet->AddState(AccessibleStateType::OPAQUE);
272cdf0e10cSrcweir 	    pStateSet->AddState(AccessibleStateType::SELECTABLE);
273cdf0e10cSrcweir 	    if (IsSelected())
274cdf0e10cSrcweir 		    pStateSet->AddState(AccessibleStateType::SELECTED);
275cdf0e10cSrcweir 	    if (isShowing())
276cdf0e10cSrcweir 		    pStateSet->AddState(AccessibleStateType::SHOWING);
277cdf0e10cSrcweir 	    pStateSet->AddState(AccessibleStateType::TRANSIENT);
278cdf0e10cSrcweir 	    if (isVisible())
279cdf0e10cSrcweir 		    pStateSet->AddState(AccessibleStateType::VISIBLE);
280cdf0e10cSrcweir     }
281cdf0e10cSrcweir 	return pStateSet;
282cdf0e10cSrcweir }
283cdf0e10cSrcweir 
284cdf0e10cSrcweir uno::Reference<XAccessibleRelationSet> SAL_CALL
getAccessibleRelationSet(void)285cdf0e10cSrcweir    	ScAccessibleCell::getAccessibleRelationSet(void)
286cdf0e10cSrcweir     throw (uno::RuntimeException)
287cdf0e10cSrcweir {
288cdf0e10cSrcweir 	ScUnoGuard aGuard;
289cdf0e10cSrcweir     IsObjectValid();
290cdf0e10cSrcweir     utl::AccessibleRelationSetHelper* pRelationSet = NULL;
291cdf0e10cSrcweir     if (mpAccDoc)
292cdf0e10cSrcweir         pRelationSet = mpAccDoc->GetRelationSet(&maCellAddress);
293cdf0e10cSrcweir     if (!pRelationSet)
294cdf0e10cSrcweir 	    pRelationSet = new utl::AccessibleRelationSetHelper();
295cdf0e10cSrcweir 	FillDependends(pRelationSet);
296cdf0e10cSrcweir 	FillPrecedents(pRelationSet);
297cdf0e10cSrcweir 	return pRelationSet;
298cdf0e10cSrcweir }
299cdf0e10cSrcweir 
300cdf0e10cSrcweir 	//=====  XServiceInfo  ====================================================
301cdf0e10cSrcweir 
getImplementationName(void)302cdf0e10cSrcweir ::rtl::OUString SAL_CALL ScAccessibleCell::getImplementationName(void)
303cdf0e10cSrcweir         throw (uno::RuntimeException)
304cdf0e10cSrcweir {
305cdf0e10cSrcweir 	return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ("ScAccessibleCell"));
306cdf0e10cSrcweir }
307cdf0e10cSrcweir 
308cdf0e10cSrcweir uno::Sequence< ::rtl::OUString> SAL_CALL
getSupportedServiceNames(void)309cdf0e10cSrcweir 	ScAccessibleCell::getSupportedServiceNames(void)
310cdf0e10cSrcweir         throw (uno::RuntimeException)
311cdf0e10cSrcweir {
312cdf0e10cSrcweir 	uno::Sequence< ::rtl::OUString > aSequence = ScAccessibleContextBase::getSupportedServiceNames();
313cdf0e10cSrcweir     sal_Int32 nOldSize(aSequence.getLength());
314cdf0e10cSrcweir     aSequence.realloc(nOldSize + 1);
315cdf0e10cSrcweir     ::rtl::OUString* pNames = aSequence.getArray();
316cdf0e10cSrcweir 
317cdf0e10cSrcweir 	pNames[nOldSize] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.AccessibleCell"));
318cdf0e10cSrcweir 
319cdf0e10cSrcweir 	return aSequence;
320cdf0e10cSrcweir }
321cdf0e10cSrcweir 
322cdf0e10cSrcweir 	//====  internal  =========================================================
323cdf0e10cSrcweir 
IsDefunc(const uno::Reference<XAccessibleStateSet> & rxParentStates)324cdf0e10cSrcweir sal_Bool ScAccessibleCell::IsDefunc(
325cdf0e10cSrcweir 	const uno::Reference<XAccessibleStateSet>& rxParentStates)
326cdf0e10cSrcweir {
327cdf0e10cSrcweir 	return ScAccessibleContextBase::IsDefunc() || (mpDoc == NULL) || (mpViewShell == NULL) || !getAccessibleParent().is() ||
328cdf0e10cSrcweir 		 (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
329cdf0e10cSrcweir }
330cdf0e10cSrcweir 
IsEditable(const uno::Reference<XAccessibleStateSet> & rxParentStates)331cdf0e10cSrcweir sal_Bool ScAccessibleCell::IsEditable(
332cdf0e10cSrcweir 	const uno::Reference<XAccessibleStateSet>& rxParentStates)
333cdf0e10cSrcweir {
334cdf0e10cSrcweir 	sal_Bool bEditable(sal_True);
335cdf0e10cSrcweir 	if (rxParentStates.is() && !rxParentStates->contains(AccessibleStateType::EDITABLE) &&
336cdf0e10cSrcweir 		mpDoc)
337cdf0e10cSrcweir 	{
338cdf0e10cSrcweir 		// here I have to test whether the protection of the table should influence this cell.
339cdf0e10cSrcweir 		const ScProtectionAttr* pItem = (const ScProtectionAttr*)mpDoc->GetAttr(
340cdf0e10cSrcweir 			maCellAddress.Col(), maCellAddress.Row(),
341cdf0e10cSrcweir 			maCellAddress.Tab(), ATTR_PROTECTION);
342cdf0e10cSrcweir 		if (pItem)
343cdf0e10cSrcweir 			bEditable = !pItem->GetProtection();
344cdf0e10cSrcweir 	}
345cdf0e10cSrcweir 	return bEditable;
346cdf0e10cSrcweir }
347cdf0e10cSrcweir 
IsOpaque(const uno::Reference<XAccessibleStateSet> &)348cdf0e10cSrcweir sal_Bool ScAccessibleCell::IsOpaque(
349cdf0e10cSrcweir     const uno::Reference<XAccessibleStateSet>& /* rxParentStates */)
350cdf0e10cSrcweir {
351cdf0e10cSrcweir 	// test whether there is a background color
352cdf0e10cSrcweir 	sal_Bool bOpaque(sal_True);
353cdf0e10cSrcweir 	if (mpDoc)
354cdf0e10cSrcweir 	{
355cdf0e10cSrcweir 		const SvxBrushItem* pItem = (const SvxBrushItem*)mpDoc->GetAttr(
356cdf0e10cSrcweir 			maCellAddress.Col(), maCellAddress.Row(),
357cdf0e10cSrcweir 			maCellAddress.Tab(), ATTR_BACKGROUND);
358cdf0e10cSrcweir 		if (pItem)
359cdf0e10cSrcweir 			bOpaque = pItem->GetColor() != COL_TRANSPARENT;
360cdf0e10cSrcweir 	}
361cdf0e10cSrcweir 	return bOpaque;
362cdf0e10cSrcweir }
363cdf0e10cSrcweir 
IsSelected()364cdf0e10cSrcweir sal_Bool ScAccessibleCell::IsSelected()
365cdf0e10cSrcweir {
3660deba7fbSSteve Yin 	if (IsFormulaMode())
3670deba7fbSSteve Yin 	{
3680deba7fbSSteve Yin 		const ScAccessibleSpreadsheet *pSheet =static_cast<const ScAccessibleSpreadsheet*>(mxParent.get());
3690deba7fbSSteve Yin 		if (pSheet)
3700deba7fbSSteve Yin 		{
3710deba7fbSSteve Yin 			return pSheet->IsScAddrFormulaSel(maCellAddress);
3720deba7fbSSteve Yin 		}
3730deba7fbSSteve Yin 		return sal_False;
3740deba7fbSSteve Yin 	}
375cdf0e10cSrcweir 	sal_Bool bResult(sal_False);
376cdf0e10cSrcweir 	if (mpViewShell && mpViewShell->GetViewData())
377cdf0e10cSrcweir 	{
378cdf0e10cSrcweir 		const ScMarkData& rMarkdata = mpViewShell->GetViewData()->GetMarkData();
379cdf0e10cSrcweir 		bResult = rMarkdata.IsCellMarked(maCellAddress.Col(), maCellAddress.Row());
380cdf0e10cSrcweir 	}
381cdf0e10cSrcweir 	return bResult;
382cdf0e10cSrcweir }
383cdf0e10cSrcweir 
GetDocument(ScTabViewShell * pViewShell)384cdf0e10cSrcweir ScDocument* ScAccessibleCell::GetDocument(ScTabViewShell* pViewShell)
385cdf0e10cSrcweir {
386cdf0e10cSrcweir 	ScDocument* pDoc = NULL;
387cdf0e10cSrcweir 	if (pViewShell && pViewShell->GetViewData())
388cdf0e10cSrcweir 		pDoc = pViewShell->GetViewData()->GetDocument();
389cdf0e10cSrcweir 	return pDoc;
390cdf0e10cSrcweir }
391cdf0e10cSrcweir 
CreateEditSource(ScTabViewShell * pViewShell,ScAddress aCell,ScSplitPos eSplitPos)392cdf0e10cSrcweir ::std::auto_ptr< SvxEditSource > ScAccessibleCell::CreateEditSource(ScTabViewShell* pViewShell, ScAddress aCell, ScSplitPos eSplitPos)
393cdf0e10cSrcweir {
3940deba7fbSSteve Yin 	if (IsFormulaMode())
3950deba7fbSSteve Yin 	{
3960deba7fbSSteve Yin 		return ::std::auto_ptr< SvxEditSource >();
3970deba7fbSSteve Yin 	}
398cdf0e10cSrcweir 	::std::auto_ptr < ScAccessibleTextData > pAccessibleCellTextData
399cdf0e10cSrcweir         ( new ScAccessibleCellTextData( pViewShell, aCell, eSplitPos, this ) );
400cdf0e10cSrcweir 	::std::auto_ptr< SvxEditSource > pEditSource (new ScAccessibilityEditSource(pAccessibleCellTextData));
401cdf0e10cSrcweir 
402cdf0e10cSrcweir     return pEditSource;
403cdf0e10cSrcweir }
404cdf0e10cSrcweir 
FillDependends(utl::AccessibleRelationSetHelper * pRelationSet)405cdf0e10cSrcweir void ScAccessibleCell::FillDependends(utl::AccessibleRelationSetHelper* pRelationSet)
406cdf0e10cSrcweir {
407cdf0e10cSrcweir 	if (mpDoc)
408cdf0e10cSrcweir 	{
409cdf0e10cSrcweir 		ScCellIterator aCellIter( mpDoc, 0,0, maCellAddress.Tab(), MAXCOL,MAXROW, maCellAddress.Tab() );
410cdf0e10cSrcweir 		ScBaseCell* pCell = aCellIter.GetFirst();
411cdf0e10cSrcweir 		while (pCell)
412cdf0e10cSrcweir 		{
413cdf0e10cSrcweir 			if (pCell->GetCellType() == CELLTYPE_FORMULA)
414cdf0e10cSrcweir 			{
415cdf0e10cSrcweir 				sal_Bool bFound(sal_False);
416cdf0e10cSrcweir 				ScDetectiveRefIter aIter( (ScFormulaCell*) pCell );
417cdf0e10cSrcweir                 ScRange aRef;
418cdf0e10cSrcweir 				while ( !bFound && aIter.GetNextRef( aRef ) )
419cdf0e10cSrcweir 				{
420cdf0e10cSrcweir 					if (aRef.In(maCellAddress))
421cdf0e10cSrcweir 						bFound = sal_True;
422cdf0e10cSrcweir 				}
423cdf0e10cSrcweir 				if (bFound)
424cdf0e10cSrcweir 					AddRelation(ScAddress(aCellIter.GetCol(), aCellIter.GetRow(), aCellIter.GetTab()), AccessibleRelationType::CONTROLLER_FOR, pRelationSet);
425cdf0e10cSrcweir 			}
426cdf0e10cSrcweir 			pCell = aCellIter.GetNext();
427cdf0e10cSrcweir 		}
428cdf0e10cSrcweir 	}
429cdf0e10cSrcweir }
430cdf0e10cSrcweir 
FillPrecedents(utl::AccessibleRelationSetHelper * pRelationSet)431cdf0e10cSrcweir void ScAccessibleCell::FillPrecedents(utl::AccessibleRelationSetHelper* pRelationSet)
432cdf0e10cSrcweir {
433cdf0e10cSrcweir 	if (mpDoc)
434cdf0e10cSrcweir 	{
435cdf0e10cSrcweir 		ScBaseCell* pBaseCell = mpDoc->GetCell(maCellAddress);
436cdf0e10cSrcweir 		if (pBaseCell && (pBaseCell->GetCellType() == CELLTYPE_FORMULA))
437cdf0e10cSrcweir 		{
438cdf0e10cSrcweir 			ScFormulaCell* pFCell = (ScFormulaCell*) pBaseCell;
439cdf0e10cSrcweir 
440cdf0e10cSrcweir 			ScDetectiveRefIter aIter( pFCell );
441cdf0e10cSrcweir             ScRange aRef;
442cdf0e10cSrcweir 			while ( aIter.GetNextRef( aRef ) )
443cdf0e10cSrcweir 			{
444cdf0e10cSrcweir 				AddRelation( aRef, AccessibleRelationType::CONTROLLED_BY, pRelationSet);
445cdf0e10cSrcweir 			}
446cdf0e10cSrcweir 		}
447cdf0e10cSrcweir 	}
448cdf0e10cSrcweir }
449cdf0e10cSrcweir 
AddRelation(const ScAddress & rCell,const sal_uInt16 aRelationType,utl::AccessibleRelationSetHelper * pRelationSet)450cdf0e10cSrcweir void ScAccessibleCell::AddRelation(const ScAddress& rCell,
451cdf0e10cSrcweir 	const sal_uInt16 aRelationType,
452cdf0e10cSrcweir 	utl::AccessibleRelationSetHelper* pRelationSet)
453cdf0e10cSrcweir {
454cdf0e10cSrcweir 	AddRelation(ScRange(rCell, rCell), aRelationType, pRelationSet);
455cdf0e10cSrcweir }
456cdf0e10cSrcweir 
AddRelation(const ScRange & rRange,const sal_uInt16 aRelationType,utl::AccessibleRelationSetHelper * pRelationSet)457cdf0e10cSrcweir void ScAccessibleCell::AddRelation(const ScRange& rRange,
458cdf0e10cSrcweir 	const sal_uInt16 aRelationType,
459cdf0e10cSrcweir 	utl::AccessibleRelationSetHelper* pRelationSet)
460cdf0e10cSrcweir {
461cdf0e10cSrcweir 	uno::Reference < XAccessibleTable > xTable ( getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY );
462cdf0e10cSrcweir 	if (xTable.is())
463cdf0e10cSrcweir 	{
464cdf0e10cSrcweir         sal_uInt32 nCount(static_cast<sal_uInt32>(rRange.aEnd.Col() -
465cdf0e10cSrcweir                     rRange.aStart.Col() + 1) * (rRange.aEnd.Row() -
466cdf0e10cSrcweir                     rRange.aStart.Row() + 1));
467cdf0e10cSrcweir 		uno::Sequence < uno::Reference < uno::XInterface > > aTargetSet( nCount );
468cdf0e10cSrcweir 		uno::Reference < uno::XInterface >* pTargetSet = aTargetSet.getArray();
469cdf0e10cSrcweir 		if (pTargetSet)
470cdf0e10cSrcweir 		{
471cdf0e10cSrcweir 			sal_uInt32 nPos(0);
472cdf0e10cSrcweir             for (sal_uInt32 nRow = rRange.aStart.Row(); nRow <= sal::static_int_cast<sal_uInt32>(rRange.aEnd.Row()); ++nRow)
473cdf0e10cSrcweir 			{
474cdf0e10cSrcweir                 for (sal_uInt32 nCol = rRange.aStart.Col(); nCol <= sal::static_int_cast<sal_uInt32>(rRange.aEnd.Col()); ++nCol)
475cdf0e10cSrcweir 				{
476cdf0e10cSrcweir 					pTargetSet[nPos] = xTable->getAccessibleCellAt(nRow, nCol);
477cdf0e10cSrcweir 					++nPos;
478cdf0e10cSrcweir 				}
479cdf0e10cSrcweir 			}
480cdf0e10cSrcweir 			DBG_ASSERT(nCount == nPos, "something wents wrong");
481cdf0e10cSrcweir 		}
482cdf0e10cSrcweir 		AccessibleRelation aRelation;
483cdf0e10cSrcweir 		aRelation.RelationType = aRelationType;
484cdf0e10cSrcweir 		aRelation.TargetSet = aTargetSet;
485cdf0e10cSrcweir 		pRelationSet->AddRelation(aRelation);
486cdf0e10cSrcweir 	}
487cdf0e10cSrcweir }
ReplaceOneChar(::rtl::OUString oldOUString,::rtl::OUString replacedChar,::rtl::OUString replaceStr)4880deba7fbSSteve Yin ::rtl::OUString ReplaceOneChar(::rtl::OUString oldOUString, ::rtl::OUString replacedChar, ::rtl::OUString replaceStr)
4890deba7fbSSteve Yin {
4900deba7fbSSteve Yin 	int iReplace = -1;
4910deba7fbSSteve Yin 	iReplace = oldOUString.lastIndexOf(replacedChar);
4920deba7fbSSteve Yin 	if (iReplace > -1)
4930deba7fbSSteve Yin 	{
4940deba7fbSSteve Yin 		for(;iReplace>-1;)
4950deba7fbSSteve Yin 		{
4960deba7fbSSteve Yin 			oldOUString = oldOUString.replaceAt(iReplace,1, replaceStr);
4970deba7fbSSteve Yin 			iReplace=oldOUString.lastIndexOf(replacedChar,iReplace);
4980deba7fbSSteve Yin 		}
4990deba7fbSSteve Yin 	}
5000deba7fbSSteve Yin 	return oldOUString;
5010deba7fbSSteve Yin }
ReplaceFourChar(::rtl::OUString oldOUString)5020deba7fbSSteve Yin ::rtl::OUString ReplaceFourChar(::rtl::OUString oldOUString)
5030deba7fbSSteve Yin {
5040deba7fbSSteve Yin 	oldOUString = ReplaceOneChar(oldOUString,::rtl::OUString::createFromAscii("\\"),::rtl::OUString::createFromAscii("\\\\"));
5050deba7fbSSteve Yin 	oldOUString = ReplaceOneChar(oldOUString,::rtl::OUString::createFromAscii(";"),::rtl::OUString::createFromAscii("\\;"));
5060deba7fbSSteve Yin 	oldOUString = ReplaceOneChar(oldOUString,::rtl::OUString::createFromAscii("="),::rtl::OUString::createFromAscii("\\="));
5070deba7fbSSteve Yin 	oldOUString = ReplaceOneChar(oldOUString,::rtl::OUString::createFromAscii(","),::rtl::OUString::createFromAscii("\\,"));
5080deba7fbSSteve Yin 	oldOUString = ReplaceOneChar(oldOUString,::rtl::OUString::createFromAscii(":"),::rtl::OUString::createFromAscii("\\:"));
5090deba7fbSSteve Yin 	return oldOUString;
5100deba7fbSSteve Yin }
5110deba7fbSSteve Yin 
getExtendedAttributes()5120deba7fbSSteve Yin uno::Any SAL_CALL ScAccessibleCell::getExtendedAttributes()
513*4937ceefSSteve Yin 		throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
5140deba7fbSSteve Yin {
5150deba7fbSSteve Yin 	uno::Any strRet;
5160deba7fbSSteve Yin 	if (mpViewShell)
5170deba7fbSSteve Yin 	{
5180deba7fbSSteve Yin 		const ::rtl::OUString strAttr(::rtl::OUString::createFromAscii(":"));
5190deba7fbSSteve Yin 		const ::rtl::OUString strSplit(::rtl::OUString::createFromAscii(";"));
5200deba7fbSSteve Yin 		::rtl::OUString strFor = mpViewShell->GetFormula(maCellAddress) ;
5210deba7fbSSteve Yin 		strFor = strFor.replaceAt(0,1,::rtl::OUString::createFromAscii(""));
5220deba7fbSSteve Yin 		strFor = ReplaceFourChar(strFor);
5230deba7fbSSteve Yin 		strFor =::rtl::OUString::createFromAscii("Formula:") + strFor;
5240deba7fbSSteve Yin 		strFor +=strSplit;
5250deba7fbSSteve Yin 		strFor +=::rtl::OUString::createFromAscii("Note:");
5260deba7fbSSteve Yin 		strFor +=ReplaceFourChar(GetAllDisplayNote());
5270deba7fbSSteve Yin 		strFor +=strSplit;
5280deba7fbSSteve Yin 		strFor += getShadowAttrs();//the string returned contains the spliter ";"
5290deba7fbSSteve Yin 		strFor += getBorderAttrs();//the string returned contains the spliter ";"
5300deba7fbSSteve Yin 		//end of cell attributes
5310deba7fbSSteve Yin 		if( mpDoc )
5320deba7fbSSteve Yin 		{
5330deba7fbSSteve Yin 			strFor += ::rtl::OUString::createFromAscii("isdropdown:");
5340deba7fbSSteve Yin 			if( IsDropdown() )
5350deba7fbSSteve Yin 				strFor+= ::rtl::OUString::createFromAscii("true");
5360deba7fbSSteve Yin 			else
5370deba7fbSSteve Yin 				strFor+= ::rtl::OUString::createFromAscii("false");
5380deba7fbSSteve Yin 			strFor += ::rtl::OUString::createFromAscii(";");
5390deba7fbSSteve Yin 		}
5400deba7fbSSteve Yin 		strRet <<= strFor ;
5410deba7fbSSteve Yin 	}
5420deba7fbSSteve Yin 	return strRet;
5430deba7fbSSteve Yin }
5440deba7fbSSteve Yin 
5450deba7fbSSteve Yin // cell has its own ParaIndent property, so when calling character attributes on cell, the ParaIndent should replace the ParaLeftMargin if its value is not zero.
getCharacterAttributes(sal_Int32 nIndex,const::com::sun::star::uno::Sequence<::rtl::OUString> & aRequestedAttributes)5460deba7fbSSteve Yin uno::Sequence< beans::PropertyValue > SAL_CALL ScAccessibleCell::getCharacterAttributes( sal_Int32 nIndex, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aRequestedAttributes ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
5470deba7fbSSteve Yin {
5480deba7fbSSteve Yin 	uno::Sequence< beans::PropertyValue > aAttribs = AccessibleStaticTextBase::getCharacterAttributes( nIndex, aRequestedAttributes );
5490deba7fbSSteve Yin 	beans::PropertyValue *pAttribs = aAttribs.getArray();
5500deba7fbSSteve Yin 
5510deba7fbSSteve Yin 	sal_uInt16 nParaIndent = static_cast< const SfxUInt16Item* >( mpDoc->GetAttr( maCellAddress.Col(), maCellAddress.Row(), maCellAddress.Tab(), ATTR_INDENT ) )->GetValue();
5520deba7fbSSteve Yin 	if (nParaIndent > 0)
5530deba7fbSSteve Yin 	{
5540deba7fbSSteve Yin 		::rtl::OUString sLeftMarginName (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaLeftMargin")));
5550deba7fbSSteve Yin 		for (int i = 0; i < aAttribs.getLength(); ++i)
5560deba7fbSSteve Yin 		{
5570deba7fbSSteve Yin 			if (sLeftMarginName == pAttribs[i].Name)
5580deba7fbSSteve Yin 			{
5590deba7fbSSteve Yin 				pAttribs[i].Value = uno::makeAny( nParaIndent );
5600deba7fbSSteve Yin 				break;
5610deba7fbSSteve Yin 			}
5620deba7fbSSteve Yin 		}
5630deba7fbSSteve Yin 	}
5640deba7fbSSteve Yin 	return aAttribs;
5650deba7fbSSteve Yin }
5660deba7fbSSteve Yin 
IsFormulaMode()5670deba7fbSSteve Yin sal_Bool ScAccessibleCell::IsFormulaMode()
5680deba7fbSSteve Yin {
5690deba7fbSSteve Yin 	ScAccessibleSpreadsheet* pSheet =static_cast<ScAccessibleSpreadsheet*>(mxParent.get());
5700deba7fbSSteve Yin 	if (pSheet)
5710deba7fbSSteve Yin 	{
5720deba7fbSSteve Yin 		return pSheet->IsFormulaMode();
5730deba7fbSSteve Yin 	}
5740deba7fbSSteve Yin 	return sal_False;
5750deba7fbSSteve Yin }
IsDropdown()5760deba7fbSSteve Yin sal_Bool ScAccessibleCell::IsDropdown()
5770deba7fbSSteve Yin {
5780deba7fbSSteve Yin 	sal_uInt16 nPosX = maCellAddress.Col();
5790deba7fbSSteve Yin 	sal_uInt16 nPosY = sal_uInt16(maCellAddress.Row());
5800deba7fbSSteve Yin 	sal_uInt16 nTab = maCellAddress.Tab();
5810deba7fbSSteve Yin 	sal_uInt32 nValidation = static_cast< const SfxUInt32Item* >( mpDoc->GetAttr( nPosX, nPosY, nTab, ATTR_VALIDDATA ) )->GetValue();
5820deba7fbSSteve Yin     if( nValidation )
5830deba7fbSSteve Yin     {
5840deba7fbSSteve Yin         const ScValidationData* pData = mpDoc->GetValidationEntry( nValidation );
5850deba7fbSSteve Yin         if( pData && pData->HasSelectionList() )
5860deba7fbSSteve Yin             return sal_True;
5870deba7fbSSteve Yin     }
5880deba7fbSSteve Yin 	ScMergeFlagAttr* pAttr;
5890deba7fbSSteve Yin 	pAttr = (ScMergeFlagAttr*)mpDoc->GetAttr( nPosX, nPosY, nTab, ATTR_MERGE_FLAG );
5900deba7fbSSteve Yin 	if( pAttr->HasAutoFilter() )
5910deba7fbSSteve Yin 	{
5920deba7fbSSteve Yin 		return sal_True;
5930deba7fbSSteve Yin 	}
5940deba7fbSSteve Yin 	else
5950deba7fbSSteve Yin 	{
5960deba7fbSSteve Yin 		sal_uInt16 nTabCount = mpDoc->GetTableCount();
5970deba7fbSSteve Yin 		if ( nTab+1<nTabCount && mpDoc->IsScenario(nTab+1) && !mpDoc->IsScenario(nTab) )
5980deba7fbSSteve Yin 		{
5990deba7fbSSteve Yin 			sal_uInt16 i;
6000deba7fbSSteve Yin 			ScMarkData aMarks;
6010deba7fbSSteve Yin 			for (i=nTab+1; i<nTabCount && mpDoc->IsScenario(i); i++)
6020deba7fbSSteve Yin 				mpDoc->MarkScenario( i, nTab, aMarks, sal_False, SC_SCENARIO_SHOWFRAME );
6030deba7fbSSteve Yin 			ScRangeList aRanges;
6040deba7fbSSteve Yin 			aMarks.FillRangeListWithMarks( &aRanges, sal_False );
6050deba7fbSSteve Yin 			sal_Bool bHasScenario;
6060deba7fbSSteve Yin 			sal_uInt16 nRangeCount = (sal_uInt16)aRanges.Count();
6070deba7fbSSteve Yin 			for (i=0; i<nRangeCount; i++)
6080deba7fbSSteve Yin 			{
6090deba7fbSSteve Yin 				ScRange aRange = *aRanges.GetObject(i);
6100deba7fbSSteve Yin 				mpDoc->ExtendTotalMerge( aRange );
6110deba7fbSSteve Yin 				sal_Bool bTextBelow = ( aRange.aStart.Row() == 0 );
6120deba7fbSSteve Yin 				// MT IA2: Not used: sal_Bool bIsInScen = sal_False;
6130deba7fbSSteve Yin 				if ( bTextBelow )
6140deba7fbSSteve Yin 				{
6150deba7fbSSteve Yin 					bHasScenario = (aRange.aStart.Col() == nPosX && aRange.aEnd.Row() == nPosY-1);
6160deba7fbSSteve Yin 				}
6170deba7fbSSteve Yin 				else
6180deba7fbSSteve Yin 				{
6190deba7fbSSteve Yin 					bHasScenario = (aRange.aStart.Col() == nPosX && aRange.aStart.Row() == nPosY+1);
6200deba7fbSSteve Yin 				}
6210deba7fbSSteve Yin 				if( bHasScenario ) return sal_True;
6220deba7fbSSteve Yin 			}
6230deba7fbSSteve Yin 		}
6240deba7fbSSteve Yin 	}
6250deba7fbSSteve Yin 	return sal_False;
6260deba7fbSSteve Yin }
627