1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10f6e50924SAndrew Rist  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12f6e50924SAndrew Rist  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19f6e50924SAndrew Rist  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <accessiblecell.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "svx/DescriptionGenerator.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp>
32cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <vcl/svapp.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <editeng/outlobj.hxx>
39cdf0e10cSrcweir #include <svx/unoshtxt.hxx>
40cdf0e10cSrcweir #include <svx/svdotext.hxx>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir using ::rtl::OUString;
43cdf0e10cSrcweir using namespace ::sdr::table;
44cdf0e10cSrcweir using namespace ::com::sun::star;
45cdf0e10cSrcweir using namespace ::com::sun::star::uno;
46cdf0e10cSrcweir using namespace	::com::sun::star::accessibility;
47cdf0e10cSrcweir using namespace ::com::sun::star::lang;
48cdf0e10cSrcweir using namespace ::com::sun::star::container;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir namespace accessibility {
51cdf0e10cSrcweir 
52cdf0e10cSrcweir // --------------------------------------------------------------------
53cdf0e10cSrcweir // AccessibleCell
54cdf0e10cSrcweir // --------------------------------------------------------------------
55cdf0e10cSrcweir 
56cdf0e10cSrcweir AccessibleCell::AccessibleCell( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible>& rxParent, const sdr::table::CellRef& rCell, sal_Int32 nIndex, const AccessibleShapeTreeInfo& rShapeTreeInfo )
57cdf0e10cSrcweir : AccessibleCellBase( rxParent, AccessibleRole::TABLE_CELL )
58cdf0e10cSrcweir , maShapeTreeInfo( rShapeTreeInfo )
59cdf0e10cSrcweir , mnIndexInParent( nIndex )
60cdf0e10cSrcweir , mpText( NULL )
61cdf0e10cSrcweir , mxCell( rCell )
62cdf0e10cSrcweir {
63*9b8096d0SSteve Yin 	//Init the pAccTable var
64*9b8096d0SSteve Yin 	pAccTable = dynamic_cast <AccessibleTableShape *> (rxParent.get());
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir // --------------------------------------------------------------------
68cdf0e10cSrcweir 
69cdf0e10cSrcweir AccessibleCell::~AccessibleCell (void)
70cdf0e10cSrcweir {
71cdf0e10cSrcweir 	DBG_ASSERT( mpText == 0, "svx::AccessibleCell::~AccessibleCell(), not disposed!?" );
72cdf0e10cSrcweir }
73cdf0e10cSrcweir 
74cdf0e10cSrcweir // --------------------------------------------------------------------
75cdf0e10cSrcweir 
76cdf0e10cSrcweir void AccessibleCell::Init (void)
77cdf0e10cSrcweir {
78cdf0e10cSrcweir 	SdrView* pView = maShapeTreeInfo.GetSdrView();
79cdf0e10cSrcweir 	const Window* pWindow = maShapeTreeInfo.GetWindow ();
80cdf0e10cSrcweir 	if( (pView != NULL) && (pWindow != NULL) && mxCell.is())
81cdf0e10cSrcweir 	{
82cdf0e10cSrcweir         OutlinerParaObject* pOutlinerParaObject = mxCell->GetEditOutlinerParaObject(); // Get the OutlinerParaObject if text edit is active
83cdf0e10cSrcweir 
84cdf0e10cSrcweir         bool bOwnParaObject = pOutlinerParaObject != 0;
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 		if( !pOutlinerParaObject )
87cdf0e10cSrcweir 			pOutlinerParaObject = mxCell->GetOutlinerParaObject();
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 		// create AccessibleTextHelper to handle this shape's text
90cdf0e10cSrcweir         if( pOutlinerParaObject )
91cdf0e10cSrcweir         {
92cdf0e10cSrcweir             // non-empty text -> use full-fledged edit source right away
93cdf0e10cSrcweir             ::std::auto_ptr<SvxEditSource> pEditSource( new SvxTextEditSource( mxCell->GetObject(), mxCell.get(), *pView, *pWindow) );
94cdf0e10cSrcweir             mpText = new AccessibleTextHelper( pEditSource );
95cdf0e10cSrcweir 			mpText->SetEventSource(this);
96cdf0e10cSrcweir         }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir         if( bOwnParaObject)
99cdf0e10cSrcweir             delete pOutlinerParaObject;
100cdf0e10cSrcweir     }
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir // --------------------------------------------------------------------
104cdf0e10cSrcweir 
105cdf0e10cSrcweir sal_Bool AccessibleCell::SetState (sal_Int16 aState)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir     sal_Bool bStateHasChanged = sal_False;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     if (aState == AccessibleStateType::FOCUSED && mpText != NULL)
110cdf0e10cSrcweir     {
111cdf0e10cSrcweir         // Offer FOCUSED state to edit engine and detect whether the state
112cdf0e10cSrcweir         // changes.
113cdf0e10cSrcweir         sal_Bool bIsFocused = mpText->HaveFocus ();
114cdf0e10cSrcweir         mpText->SetFocus (sal_True);
115cdf0e10cSrcweir         bStateHasChanged = (bIsFocused != mpText->HaveFocus ());
116cdf0e10cSrcweir     }
117cdf0e10cSrcweir     else
118cdf0e10cSrcweir         bStateHasChanged = AccessibleContextBase::SetState (aState);
119cdf0e10cSrcweir 
120cdf0e10cSrcweir     return bStateHasChanged;
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir // --------------------------------------------------------------------
124cdf0e10cSrcweir 
125cdf0e10cSrcweir sal_Bool AccessibleCell::ResetState (sal_Int16 aState)
126cdf0e10cSrcweir {
127cdf0e10cSrcweir     sal_Bool bStateHasChanged = sal_False;
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     if (aState == AccessibleStateType::FOCUSED && mpText != NULL)
130cdf0e10cSrcweir     {
131cdf0e10cSrcweir         // Try to remove FOCUSED state from the edit engine and detect
132cdf0e10cSrcweir         // whether the state changes.
133cdf0e10cSrcweir         sal_Bool bIsFocused = mpText->HaveFocus ();
134cdf0e10cSrcweir         mpText->SetFocus (sal_False);
135cdf0e10cSrcweir         bStateHasChanged = (bIsFocused != mpText->HaveFocus ());
136cdf0e10cSrcweir     }
137cdf0e10cSrcweir     else
138cdf0e10cSrcweir         bStateHasChanged = AccessibleContextBase::ResetState (aState);
139cdf0e10cSrcweir 
140cdf0e10cSrcweir     return bStateHasChanged;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir 
143cdf0e10cSrcweir // --------------------------------------------------------------------
144cdf0e10cSrcweir 
145cdf0e10cSrcweir sal_Bool AccessibleCell::GetState (sal_Int16 aState)
146cdf0e10cSrcweir {
147cdf0e10cSrcweir     if (aState == AccessibleStateType::FOCUSED && mpText != NULL)
148cdf0e10cSrcweir     {
149cdf0e10cSrcweir         // Just delegate the call to the edit engine.  The state is not
150cdf0e10cSrcweir         // merged into the state set.
151cdf0e10cSrcweir         return mpText->HaveFocus();
152cdf0e10cSrcweir     }
153cdf0e10cSrcweir     else
154cdf0e10cSrcweir         return AccessibleContextBase::GetState (aState);
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir //-----------------------------------------------------------------------------
158cdf0e10cSrcweir 
159cdf0e10cSrcweir bool AccessibleCell::operator== (const AccessibleCell& rAccessibleCell)
160cdf0e10cSrcweir {
161cdf0e10cSrcweir 	return this == &rAccessibleCell;
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir //-----------------------------------------------------------------------------
165cdf0e10cSrcweir // XInterface
166cdf0e10cSrcweir //-----------------------------------------------------------------------------
167cdf0e10cSrcweir 
168cdf0e10cSrcweir Any SAL_CALL AccessibleCell::queryInterface( const Type& aType ) throw (RuntimeException)
169cdf0e10cSrcweir {
170cdf0e10cSrcweir 	return AccessibleCellBase::queryInterface( aType );
171cdf0e10cSrcweir }
172cdf0e10cSrcweir 
173cdf0e10cSrcweir //-----------------------------------------------------------------------------
174cdf0e10cSrcweir 
175cdf0e10cSrcweir void SAL_CALL AccessibleCell::acquire(  ) throw ()
176cdf0e10cSrcweir {
177cdf0e10cSrcweir 	AccessibleCellBase::acquire();
178cdf0e10cSrcweir }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir //-----------------------------------------------------------------------------
181cdf0e10cSrcweir 
182cdf0e10cSrcweir void SAL_CALL AccessibleCell::release(  ) throw ()
183cdf0e10cSrcweir {
184cdf0e10cSrcweir 	AccessibleCellBase::release();
185cdf0e10cSrcweir }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir // --------------------------------------------------------------------
188cdf0e10cSrcweir // XAccessibleContext
189cdf0e10cSrcweir // --------------------------------------------------------------------
190cdf0e10cSrcweir 
191cdf0e10cSrcweir /** The children of this cell come from the paragraphs of text.
192cdf0e10cSrcweir */
193cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleCell::getAccessibleChildCount() throw (::com::sun::star::uno::RuntimeException)
194cdf0e10cSrcweir {
195cdf0e10cSrcweir     ::vos::OGuard aSolarGuard (::Application::GetSolarMutex());
196cdf0e10cSrcweir     ThrowIfDisposed ();
197cdf0e10cSrcweir 	return mpText != NULL ? mpText->GetChildCount () : 0;
198cdf0e10cSrcweir }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir // --------------------------------------------------------------------
201cdf0e10cSrcweir 
202cdf0e10cSrcweir /** Forward the request to the shape.  Return the requested shape or throw
203cdf0e10cSrcweir     an exception for a wrong index.
204cdf0e10cSrcweir */
205cdf0e10cSrcweir Reference<XAccessible> SAL_CALL AccessibleCell::getAccessibleChild (sal_Int32 nIndex) throw (IndexOutOfBoundsException, RuntimeException)
206cdf0e10cSrcweir {
207cdf0e10cSrcweir     ::vos::OGuard aSolarGuard (::Application::GetSolarMutex());
208cdf0e10cSrcweir     ThrowIfDisposed ();
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 	// todo: does GetChild throw IndexOutOfBoundsException?
211cdf0e10cSrcweir 	return mpText->GetChild (nIndex);
212cdf0e10cSrcweir }
213cdf0e10cSrcweir 
214cdf0e10cSrcweir // --------------------------------------------------------------------
215cdf0e10cSrcweir 
216cdf0e10cSrcweir /**	Return a copy of the state set.
217cdf0e10cSrcweir     Possible states are:
218cdf0e10cSrcweir 		ENABLED
219cdf0e10cSrcweir 		SHOWING
220cdf0e10cSrcweir 		VISIBLE
221cdf0e10cSrcweir */
222cdf0e10cSrcweir Reference<XAccessibleStateSet> SAL_CALL AccessibleCell::getAccessibleStateSet (void) throw (RuntimeException)
223cdf0e10cSrcweir {
224cdf0e10cSrcweir     ::vos::OGuard aSolarGuard (::Application::GetSolarMutex());
225cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
226cdf0e10cSrcweir     Reference<XAccessibleStateSet> xStateSet;
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 	if (rBHelper.bDisposed || mpText == NULL)
229cdf0e10cSrcweir 	{
230cdf0e10cSrcweir         // Return a minimal state set that only contains the DEFUNC state.
231cdf0e10cSrcweir         xStateSet = AccessibleContextBase::getAccessibleStateSet ();
232cdf0e10cSrcweir 	}
233cdf0e10cSrcweir     else
234cdf0e10cSrcweir     {
235cdf0e10cSrcweir         ::utl::AccessibleStateSetHelper* pStateSet = static_cast< ::utl::AccessibleStateSetHelper*>(mxStateSet.get());
236cdf0e10cSrcweir 
237cdf0e10cSrcweir         if(pStateSet)
238cdf0e10cSrcweir         {
239cdf0e10cSrcweir             // Merge current FOCUSED state from edit engine.
240cdf0e10cSrcweir             if (mpText != NULL)
241cdf0e10cSrcweir 			{
242cdf0e10cSrcweir 				if (mpText->HaveFocus())
243cdf0e10cSrcweir                     pStateSet->AddState (AccessibleStateType::FOCUSED);
244cdf0e10cSrcweir                 else
245cdf0e10cSrcweir                     pStateSet->RemoveState (AccessibleStateType::FOCUSED);
246cdf0e10cSrcweir 			}
247*9b8096d0SSteve Yin 			// Set the invisible state for merged cell
248*9b8096d0SSteve Yin 			if (mxCell.is() && mxCell->isMerged())
249*9b8096d0SSteve Yin 				pStateSet->RemoveState(AccessibleStateType::VISIBLE);
250*9b8096d0SSteve Yin 			else
251*9b8096d0SSteve Yin 				pStateSet->AddState(AccessibleStateType::VISIBLE);
252*9b8096d0SSteve Yin 
253*9b8096d0SSteve Yin 
254*9b8096d0SSteve Yin 			//Sym2_6167, IAccessibility2 Implementation 2009-----
255*9b8096d0SSteve Yin 			//Solution:Just when the parent table is not read-only,set states EDITABLE,RESIZABLE,MOVEABLE
256*9b8096d0SSteve Yin 		    ::com::sun::star::uno::Reference<XAccessible> xTempAcc = getAccessibleParent();
257*9b8096d0SSteve Yin 		    if( xTempAcc.is() )
258*9b8096d0SSteve Yin 		    {
259*9b8096d0SSteve Yin 		    	::com::sun::star::uno::Reference<XAccessibleContext>
260*9b8096d0SSteve Yin 		    							xTempAccContext = xTempAcc->getAccessibleContext();
261*9b8096d0SSteve Yin 		    	if( xTempAccContext.is() )
262*9b8096d0SSteve Yin 		    	{
263*9b8096d0SSteve Yin 		    		::com::sun::star::uno::Reference<XAccessibleStateSet> rState =
264*9b8096d0SSteve Yin 		    			xTempAccContext->getAccessibleStateSet();
265*9b8096d0SSteve Yin 		    		if( rState.is() )    		{
266*9b8096d0SSteve Yin 						com::sun::star::uno::Sequence<short> pStates = rState->getStates();
267*9b8096d0SSteve Yin 						int count = pStates.getLength();
268*9b8096d0SSteve Yin 						for( int iIndex = 0;iIndex < count;iIndex++ )
269*9b8096d0SSteve Yin 						{
270*9b8096d0SSteve Yin 							if( pStates[iIndex] == AccessibleStateType::EDITABLE )
271*9b8096d0SSteve Yin 							{
272*9b8096d0SSteve Yin 								pStateSet->AddState (AccessibleStateType::EDITABLE);
273*9b8096d0SSteve Yin 							    pStateSet->AddState (AccessibleStateType::RESIZABLE);
274*9b8096d0SSteve Yin 							    pStateSet->AddState (AccessibleStateType::MOVEABLE);
275*9b8096d0SSteve Yin 								break;
276*9b8096d0SSteve Yin 							}
277*9b8096d0SSteve Yin 						}
278*9b8096d0SSteve Yin 					}
279*9b8096d0SSteve Yin 				}
280*9b8096d0SSteve Yin 		    }
281*9b8096d0SSteve Yin 			//-----IAccessibility2 Implementation 2009
282cdf0e10cSrcweir             // Create a copy of the state set that may be modified by the
283cdf0e10cSrcweir             // caller without affecting the current state set.
284cdf0e10cSrcweir             xStateSet = Reference<XAccessibleStateSet>(new ::utl::AccessibleStateSetHelper (*pStateSet));
285cdf0e10cSrcweir         }
286cdf0e10cSrcweir     }
287cdf0e10cSrcweir 
288cdf0e10cSrcweir     return xStateSet;
289cdf0e10cSrcweir }
290cdf0e10cSrcweir 
291cdf0e10cSrcweir // --------------------------------------------------------------------
292cdf0e10cSrcweir // XAccessibleComponent
293cdf0e10cSrcweir // --------------------------------------------------------------------
294cdf0e10cSrcweir 
295cdf0e10cSrcweir sal_Bool SAL_CALL AccessibleCell::containsPoint( const ::com::sun::star::awt::Point& aPoint) throw (::com::sun::star::uno::RuntimeException)
296cdf0e10cSrcweir {
297cdf0e10cSrcweir 	return AccessibleComponentBase::containsPoint( aPoint );
298cdf0e10cSrcweir }
299cdf0e10cSrcweir 
300cdf0e10cSrcweir /** The implementation below is at the moment straightforward.  It iterates
301cdf0e10cSrcweir     over all children (and thereby instances all children which have not
302cdf0e10cSrcweir     been already instatiated) until a child covering the specifed point is
303cdf0e10cSrcweir     found.
304cdf0e10cSrcweir     This leaves room for improvement.  For instance, first iterate only over
305cdf0e10cSrcweir     the already instantiated children and only if no match is found
306cdf0e10cSrcweir     instantiate the remaining ones.
307cdf0e10cSrcweir */
308cdf0e10cSrcweir Reference<XAccessible > SAL_CALL  AccessibleCell::getAccessibleAtPoint ( const ::com::sun::star::awt::Point& aPoint) throw(RuntimeException)
309cdf0e10cSrcweir {
310cdf0e10cSrcweir     ::vos::OGuard aSolarGuard (::Application::GetSolarMutex());
311cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
312cdf0e10cSrcweir 
313cdf0e10cSrcweir     sal_Int32 nChildCount = getAccessibleChildCount ();
314cdf0e10cSrcweir     for (sal_Int32 i=0; i<nChildCount; ++i)
315cdf0e10cSrcweir     {
316cdf0e10cSrcweir         Reference<XAccessible> xChild (getAccessibleChild (i));
317cdf0e10cSrcweir         if (xChild.is())
318cdf0e10cSrcweir         {
319cdf0e10cSrcweir             Reference<XAccessibleComponent> xChildComponent (xChild->getAccessibleContext(), uno::UNO_QUERY);
320cdf0e10cSrcweir             if (xChildComponent.is())
321cdf0e10cSrcweir             {
322cdf0e10cSrcweir                 awt::Rectangle aBBox (xChildComponent->getBounds());
323cdf0e10cSrcweir                 if ( (aPoint.X >= aBBox.X)
324cdf0e10cSrcweir                     && (aPoint.Y >= aBBox.Y)
325cdf0e10cSrcweir                     && (aPoint.X < aBBox.X+aBBox.Width)
326cdf0e10cSrcweir                     && (aPoint.Y < aBBox.Y+aBBox.Height) )
327cdf0e10cSrcweir                     return xChild;
328cdf0e10cSrcweir             }
329cdf0e10cSrcweir         }
330cdf0e10cSrcweir     }
331cdf0e10cSrcweir 
332cdf0e10cSrcweir     // Have not found a child under the given point.  Returning empty
333cdf0e10cSrcweir     // reference to indicate this.
334cdf0e10cSrcweir     return uno::Reference<XAccessible>();
335cdf0e10cSrcweir }
336cdf0e10cSrcweir 
337cdf0e10cSrcweir // --------------------------------------------------------------------
338cdf0e10cSrcweir 
339cdf0e10cSrcweir ::com::sun::star::awt::Rectangle SAL_CALL AccessibleCell::getBounds(void) throw(RuntimeException)
340cdf0e10cSrcweir {
341cdf0e10cSrcweir     ::vos::OGuard aSolarGuard (::Application::GetSolarMutex());
342cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
343cdf0e10cSrcweir 
344cdf0e10cSrcweir     ThrowIfDisposed ();
345cdf0e10cSrcweir 	::com::sun::star::awt::Rectangle aBoundingBox;
346cdf0e10cSrcweir 	if( mxCell.is() )
347cdf0e10cSrcweir 	{
348cdf0e10cSrcweir 		// Get the cell's bounding box in internal coordinates (in 100th of mm)
349cdf0e10cSrcweir 		const ::Rectangle aCellRect( mxCell->getCellRect() );
350cdf0e10cSrcweir 
351cdf0e10cSrcweir 		// Transform coordinates from internal to pixel.
352cdf0e10cSrcweir 		if (maShapeTreeInfo.GetViewForwarder() == NULL)
353cdf0e10cSrcweir 			throw uno::RuntimeException (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AccessibleCell has no valid view forwarder")),static_cast<uno::XWeak*>(this));
354cdf0e10cSrcweir 
355cdf0e10cSrcweir 		::Size aPixelSize( maShapeTreeInfo.GetViewForwarder()->LogicToPixel(::Size(aCellRect.GetWidth(), aCellRect.GetHeight())) );
356cdf0e10cSrcweir 		::Point aPixelPosition( maShapeTreeInfo.GetViewForwarder()->LogicToPixel( aCellRect.TopLeft() ));
357cdf0e10cSrcweir 
358cdf0e10cSrcweir 		// Clip the shape's bounding box with the bounding box of its parent.
359cdf0e10cSrcweir 		Reference<XAccessibleComponent> xParentComponent ( getAccessibleParent(), uno::UNO_QUERY);
360cdf0e10cSrcweir 		if (xParentComponent.is())
361cdf0e10cSrcweir 		{
362cdf0e10cSrcweir 			// Make the coordinates relative to the parent.
363cdf0e10cSrcweir 			awt::Point aParentLocation (xParentComponent->getLocationOnScreen());
364cdf0e10cSrcweir 			int x = aPixelPosition.getX() - aParentLocation.X;
365cdf0e10cSrcweir 			int y = aPixelPosition.getY() - aParentLocation.Y;
366cdf0e10cSrcweir 
367cdf0e10cSrcweir 			// Clip with parent (with coordinates relative to itself).
368cdf0e10cSrcweir 			::Rectangle aBBox ( x, y, x + aPixelSize.getWidth(), y + aPixelSize.getHeight());
369cdf0e10cSrcweir 			awt::Size aParentSize (xParentComponent->getSize());
370cdf0e10cSrcweir 			::Rectangle aParentBBox (0,0, aParentSize.Width, aParentSize.Height);
371cdf0e10cSrcweir 			aBBox = aBBox.GetIntersection (aParentBBox);
372cdf0e10cSrcweir 			aBoundingBox = awt::Rectangle (	aBBox.getX(), aBBox.getY(), aBBox.getWidth(), aBBox.getHeight());
373cdf0e10cSrcweir 		}
374cdf0e10cSrcweir 		else
375cdf0e10cSrcweir 		{
376cdf0e10cSrcweir 			OSL_TRACE ("parent does not support component");
377cdf0e10cSrcweir 			aBoundingBox = awt::Rectangle (aPixelPosition.getX(), aPixelPosition.getY(),aPixelSize.getWidth(), aPixelSize.getHeight());
378cdf0e10cSrcweir 		}
379cdf0e10cSrcweir 	}
380cdf0e10cSrcweir 
381cdf0e10cSrcweir     return aBoundingBox;
382cdf0e10cSrcweir }
383cdf0e10cSrcweir 
384cdf0e10cSrcweir // --------------------------------------------------------------------
385cdf0e10cSrcweir 
386cdf0e10cSrcweir ::com::sun::star::awt::Point SAL_CALL AccessibleCell::getLocation(void) throw (RuntimeException)
387cdf0e10cSrcweir {
388cdf0e10cSrcweir     ThrowIfDisposed ();
389cdf0e10cSrcweir 	::com::sun::star::awt::Rectangle aBoundingBox(getBounds());
390cdf0e10cSrcweir     return ::com::sun::star::awt::Point(aBoundingBox.X, aBoundingBox.Y);
391cdf0e10cSrcweir }
392cdf0e10cSrcweir 
393cdf0e10cSrcweir // --------------------------------------------------------------------
394cdf0e10cSrcweir 
395cdf0e10cSrcweir ::com::sun::star::awt::Point SAL_CALL AccessibleCell::getLocationOnScreen(void) throw(RuntimeException)
396cdf0e10cSrcweir {
397cdf0e10cSrcweir     ThrowIfDisposed ();
398cdf0e10cSrcweir 
399cdf0e10cSrcweir     // Get relative position...
400cdf0e10cSrcweir     ::com::sun::star::awt::Point aLocation(getLocation ());
401cdf0e10cSrcweir 
402cdf0e10cSrcweir     // ... and add absolute position of the parent.
403cdf0e10cSrcweir     Reference<XAccessibleComponent> xParentComponent( getAccessibleParent(), uno::UNO_QUERY);
404cdf0e10cSrcweir     if(xParentComponent.is())
405cdf0e10cSrcweir     {
406cdf0e10cSrcweir         ::com::sun::star::awt::Point aParentLocation(xParentComponent->getLocationOnScreen());
407cdf0e10cSrcweir         aLocation.X += aParentLocation.X;
408cdf0e10cSrcweir         aLocation.Y += aParentLocation.Y;
409cdf0e10cSrcweir     }
410cdf0e10cSrcweir     else
411cdf0e10cSrcweir 	{
412cdf0e10cSrcweir         OSL_TRACE ("getLocation: parent does not support XAccessibleComponent");
413cdf0e10cSrcweir 	}
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 	return aLocation;
416cdf0e10cSrcweir }
417cdf0e10cSrcweir 
418cdf0e10cSrcweir // --------------------------------------------------------------------
419cdf0e10cSrcweir 
420cdf0e10cSrcweir awt::Size SAL_CALL AccessibleCell::getSize (void) throw (RuntimeException)
421cdf0e10cSrcweir {
422cdf0e10cSrcweir     ThrowIfDisposed ();
423cdf0e10cSrcweir     awt::Rectangle aBoundingBox (getBounds());
424cdf0e10cSrcweir     return awt::Size (aBoundingBox.Width, aBoundingBox.Height);
425cdf0e10cSrcweir }
426cdf0e10cSrcweir 
427cdf0e10cSrcweir // --------------------------------------------------------------------
428cdf0e10cSrcweir 
429cdf0e10cSrcweir void SAL_CALL AccessibleCell::addFocusListener ( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& xListener) throw (::com::sun::star::uno::RuntimeException)
430cdf0e10cSrcweir {
431cdf0e10cSrcweir 	AccessibleComponentBase::addFocusListener( xListener );
432cdf0e10cSrcweir }
433cdf0e10cSrcweir 
434cdf0e10cSrcweir // --------------------------------------------------------------------
435cdf0e10cSrcweir 
436cdf0e10cSrcweir void SAL_CALL AccessibleCell::removeFocusListener (const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
437cdf0e10cSrcweir {
438cdf0e10cSrcweir 	AccessibleComponentBase::removeFocusListener( xListener );
439cdf0e10cSrcweir }
440cdf0e10cSrcweir 
441cdf0e10cSrcweir // --------------------------------------------------------------------
442cdf0e10cSrcweir 
443cdf0e10cSrcweir void SAL_CALL AccessibleCell::grabFocus (void) throw (::com::sun::star::uno::RuntimeException)
444cdf0e10cSrcweir {
445cdf0e10cSrcweir 	AccessibleComponentBase::grabFocus();
446cdf0e10cSrcweir }
447cdf0e10cSrcweir 
448cdf0e10cSrcweir // --------------------------------------------------------------------
449cdf0e10cSrcweir 
450cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleCell::getForeground(void) throw (RuntimeException)
451cdf0e10cSrcweir {
452cdf0e10cSrcweir     ThrowIfDisposed ();
453cdf0e10cSrcweir     sal_Int32 nColor (0x0ffffffL);
454cdf0e10cSrcweir 
455cdf0e10cSrcweir 	// todo
456cdf0e10cSrcweir     return nColor;
457cdf0e10cSrcweir }
458cdf0e10cSrcweir 
459cdf0e10cSrcweir // --------------------------------------------------------------------
460cdf0e10cSrcweir 
461cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleCell::getBackground (void) throw (RuntimeException)
462cdf0e10cSrcweir {
463cdf0e10cSrcweir     ThrowIfDisposed ();
464cdf0e10cSrcweir     sal_Int32 nColor (0L);
465cdf0e10cSrcweir 
466cdf0e10cSrcweir 	// todo
467cdf0e10cSrcweir     return nColor;
468cdf0e10cSrcweir }
469cdf0e10cSrcweir 
470cdf0e10cSrcweir // --------------------------------------------------------------------
471cdf0e10cSrcweir // XAccessibleExtendedComponent
472cdf0e10cSrcweir // --------------------------------------------------------------------
473cdf0e10cSrcweir 
474cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFont > SAL_CALL AccessibleCell::getFont (void) throw (::com::sun::star::uno::RuntimeException)
475cdf0e10cSrcweir {
476cdf0e10cSrcweir //todo
477cdf0e10cSrcweir 	return AccessibleComponentBase::getFont();
478cdf0e10cSrcweir }
479cdf0e10cSrcweir 
480cdf0e10cSrcweir // --------------------------------------------------------------------
481cdf0e10cSrcweir 
482cdf0e10cSrcweir ::rtl::OUString SAL_CALL AccessibleCell::getTitledBorderText (void) throw (::com::sun::star::uno::RuntimeException)
483cdf0e10cSrcweir {
484cdf0e10cSrcweir 	return AccessibleComponentBase::getTitledBorderText();
485cdf0e10cSrcweir }
486cdf0e10cSrcweir 
487cdf0e10cSrcweir // --------------------------------------------------------------------
488cdf0e10cSrcweir 
489cdf0e10cSrcweir ::rtl::OUString SAL_CALL AccessibleCell::getToolTipText (void) throw (::com::sun::star::uno::RuntimeException)
490cdf0e10cSrcweir {
491cdf0e10cSrcweir 	return AccessibleComponentBase::getToolTipText();
492cdf0e10cSrcweir }
493cdf0e10cSrcweir 
494cdf0e10cSrcweir // --------------------------------------------------------------------
495cdf0e10cSrcweir // XAccessibleEventBroadcaster
496cdf0e10cSrcweir // --------------------------------------------------------------------
497cdf0e10cSrcweir 
498cdf0e10cSrcweir void SAL_CALL AccessibleCell::addEventListener( const Reference<XAccessibleEventListener >& rxListener)  throw (RuntimeException)
499cdf0e10cSrcweir {
500cdf0e10cSrcweir     ::vos::OGuard aSolarGuard (::Application::GetSolarMutex());
501cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
502cdf0e10cSrcweir 	if (rBHelper.bDisposed || rBHelper.bInDispose)
503cdf0e10cSrcweir 	{
504cdf0e10cSrcweir 		Reference<XInterface> xSource( static_cast<XComponent *>(this) );
505cdf0e10cSrcweir 		lang::EventObject aEventObj(xSource);
506cdf0e10cSrcweir 		rxListener->disposing(aEventObj);
507cdf0e10cSrcweir 	}
508cdf0e10cSrcweir     else
509cdf0e10cSrcweir     {
510cdf0e10cSrcweir         AccessibleContextBase::addEventListener (rxListener);
511cdf0e10cSrcweir         if (mpText != NULL)
512cdf0e10cSrcweir             mpText->AddEventListener (rxListener);
513cdf0e10cSrcweir     }
514cdf0e10cSrcweir }
515cdf0e10cSrcweir 
516cdf0e10cSrcweir // --------------------------------------------------------------------
517cdf0e10cSrcweir 
518cdf0e10cSrcweir void SAL_CALL AccessibleCell::removeEventListener( const Reference<XAccessibleEventListener >& rxListener) throw (RuntimeException)
519cdf0e10cSrcweir {
520cdf0e10cSrcweir     ::vos::OGuard aSolarGuard (::Application::GetSolarMutex());
521cdf0e10cSrcweir     AccessibleContextBase::removeEventListener(rxListener);
522cdf0e10cSrcweir     if (mpText != NULL)
523cdf0e10cSrcweir         mpText->RemoveEventListener (rxListener);
524cdf0e10cSrcweir }
525cdf0e10cSrcweir 
526cdf0e10cSrcweir // --------------------------------------------------------------------
527cdf0e10cSrcweir // XServiceInfo
528cdf0e10cSrcweir // --------------------------------------------------------------------
529cdf0e10cSrcweir 
530cdf0e10cSrcweir OUString SAL_CALL AccessibleCell::getImplementationName(void) throw (RuntimeException)
531cdf0e10cSrcweir {
532cdf0e10cSrcweir 	return OUString(RTL_CONSTASCII_USTRINGPARAM("AccessibleCell"));
533cdf0e10cSrcweir }
534cdf0e10cSrcweir 
535cdf0e10cSrcweir // --------------------------------------------------------------------
536cdf0e10cSrcweir 
537cdf0e10cSrcweir Sequence<OUString> SAL_CALL AccessibleCell::getSupportedServiceNames(void) throw (RuntimeException)
538cdf0e10cSrcweir {
539cdf0e10cSrcweir     ThrowIfDisposed ();
540cdf0e10cSrcweir 
541cdf0e10cSrcweir 	// Get list of supported service names from base class...
542cdf0e10cSrcweir     uno::Sequence<OUString> aServiceNames = AccessibleContextBase::getSupportedServiceNames();
543cdf0e10cSrcweir     sal_Int32 nCount (aServiceNames.getLength());
544cdf0e10cSrcweir 
545cdf0e10cSrcweir     // ...and add additional names.
546cdf0e10cSrcweir     aServiceNames.realloc (nCount + 1);
547cdf0e10cSrcweir     static const OUString sAdditionalServiceName (RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.AccessibleCell"));
548cdf0e10cSrcweir     aServiceNames[nCount] = sAdditionalServiceName;
549cdf0e10cSrcweir 
550cdf0e10cSrcweir     return aServiceNames;
551cdf0e10cSrcweir }
552cdf0e10cSrcweir 
553cdf0e10cSrcweir // --------------------------------------------------------------------
554cdf0e10cSrcweir // IAccessibleViewForwarderListener
555cdf0e10cSrcweir // --------------------------------------------------------------------
556cdf0e10cSrcweir 
557cdf0e10cSrcweir void AccessibleCell::ViewForwarderChanged (ChangeType /*aChangeType*/, const IAccessibleViewForwarder* /*pViewForwarder*/)
558cdf0e10cSrcweir {
559cdf0e10cSrcweir     // Inform all listeners that the graphical representation (i.e. size
560cdf0e10cSrcweir     // and/or position) of the shape has changed.
561cdf0e10cSrcweir     CommitChange(AccessibleEventId::VISIBLE_DATA_CHANGED, Any(), Any());
562cdf0e10cSrcweir 
563cdf0e10cSrcweir     // update our children that our screen position might have changed
564cdf0e10cSrcweir     if( mpText )
565cdf0e10cSrcweir         mpText->UpdateChildren();
566cdf0e10cSrcweir }
567cdf0e10cSrcweir 
568cdf0e10cSrcweir // --------------------------------------------------------------------
569cdf0e10cSrcweir // protected
570cdf0e10cSrcweir // --------------------------------------------------------------------
571cdf0e10cSrcweir 
572cdf0e10cSrcweir void AccessibleCell::disposing (void)
573cdf0e10cSrcweir {
574cdf0e10cSrcweir     ::vos::OGuard aSolarGuard (::Application::GetSolarMutex());
575cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
576cdf0e10cSrcweir 
577cdf0e10cSrcweir     // Make sure to send an event that this object looses the focus in the
578cdf0e10cSrcweir     // case that it has the focus.
579cdf0e10cSrcweir     ::utl::AccessibleStateSetHelper* pStateSet = static_cast< ::utl::AccessibleStateSetHelper*>(mxStateSet.get());
580cdf0e10cSrcweir     if (pStateSet != NULL)
581cdf0e10cSrcweir         pStateSet->RemoveState(AccessibleStateType::FOCUSED);
582cdf0e10cSrcweir 
583cdf0e10cSrcweir     if (mpText != NULL)
584cdf0e10cSrcweir     {
585cdf0e10cSrcweir         mpText->Dispose();
586cdf0e10cSrcweir         delete mpText;
587cdf0e10cSrcweir         mpText = NULL;
588cdf0e10cSrcweir     }
589cdf0e10cSrcweir 
590cdf0e10cSrcweir     // Cleanup.  Remove references to objects to allow them to be
591cdf0e10cSrcweir     // destroyed.
592cdf0e10cSrcweir     mxCell.clear();
593cdf0e10cSrcweir     maShapeTreeInfo = AccessibleShapeTreeInfo();
594cdf0e10cSrcweir 
595cdf0e10cSrcweir     // Call base classes.
596cdf0e10cSrcweir     AccessibleContextBase::dispose ();
597cdf0e10cSrcweir }
598cdf0e10cSrcweir 
599cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleCell::getAccessibleIndexInParent (void) throw (RuntimeException)
600cdf0e10cSrcweir {
601cdf0e10cSrcweir     ThrowIfDisposed ();
602cdf0e10cSrcweir     return mnIndexInParent;
603cdf0e10cSrcweir }
604cdf0e10cSrcweir 
605*9b8096d0SSteve Yin // SD table ACC----, added by Steve Yin
606*9b8096d0SSteve Yin sdr::table::CellRef AccessibleCell::getCellRef()
607*9b8096d0SSteve Yin {
608*9b8096d0SSteve Yin 	return mxCell;
609*9b8096d0SSteve Yin }
610*9b8096d0SSteve Yin ::rtl::OUString AccessibleCell::getCellName( sal_Int32 nCol, sal_Int32 nRow )
611*9b8096d0SSteve Yin {
612*9b8096d0SSteve Yin     rtl::OUStringBuffer aBuf;
613*9b8096d0SSteve Yin 
614*9b8096d0SSteve Yin     if (nCol < 26*26)
615*9b8096d0SSteve Yin     {
616*9b8096d0SSteve Yin         if (nCol < 26)
617*9b8096d0SSteve Yin             aBuf.append( static_cast<sal_Unicode>( 'A' +
618*9b8096d0SSteve Yin                         static_cast<sal_uInt16>(nCol)));
619*9b8096d0SSteve Yin         else
620*9b8096d0SSteve Yin         {
621*9b8096d0SSteve Yin             aBuf.append( static_cast<sal_Unicode>( 'A' +
622*9b8096d0SSteve Yin                         (static_cast<sal_uInt16>(nCol) / 26) - 1));
623*9b8096d0SSteve Yin             aBuf.append( static_cast<sal_Unicode>( 'A' +
624*9b8096d0SSteve Yin                         (static_cast<sal_uInt16>(nCol) % 26)));
625*9b8096d0SSteve Yin         }
626*9b8096d0SSteve Yin     }
627*9b8096d0SSteve Yin     else
628*9b8096d0SSteve Yin     {
629*9b8096d0SSteve Yin         String aStr;
630*9b8096d0SSteve Yin         while (nCol >= 26)
631*9b8096d0SSteve Yin         {
632*9b8096d0SSteve Yin             sal_Int32 nC = nCol % 26;
633*9b8096d0SSteve Yin             aStr += static_cast<sal_Unicode>( 'A' +
634*9b8096d0SSteve Yin                     static_cast<sal_uInt16>(nC));
635*9b8096d0SSteve Yin             nCol = nCol - nC;
636*9b8096d0SSteve Yin             nCol = nCol / 26 - 1;
637*9b8096d0SSteve Yin         }
638*9b8096d0SSteve Yin         aStr += static_cast<sal_Unicode>( 'A' +
639*9b8096d0SSteve Yin                 static_cast<sal_uInt16>(nCol));
640*9b8096d0SSteve Yin         aStr.Reverse();
641*9b8096d0SSteve Yin         aBuf.append( aStr);
642*9b8096d0SSteve Yin     }
643*9b8096d0SSteve Yin     aBuf.append( OUString::valueOf(nRow+1) );
644*9b8096d0SSteve Yin     return aBuf.makeStringAndClear();
645*9b8096d0SSteve Yin }
646*9b8096d0SSteve Yin ::rtl::OUString SAL_CALL AccessibleCell::getAccessibleName (void) throw (::com::sun::star::uno::RuntimeException)
647*9b8096d0SSteve Yin {
648*9b8096d0SSteve Yin     ThrowIfDisposed ();
649*9b8096d0SSteve Yin     ::vos::OGuard aSolarGuard (::Application::GetSolarMutex());
650*9b8096d0SSteve Yin 
651*9b8096d0SSteve Yin     if( pAccTable )
652*9b8096d0SSteve Yin 	try
653*9b8096d0SSteve Yin     {
654*9b8096d0SSteve Yin         sal_Int32 nRow = 0, nCol = 0;
655*9b8096d0SSteve Yin         pAccTable->getColumnAndRow(mnIndexInParent, nCol, nRow);
656*9b8096d0SSteve Yin         return getCellName( nCol, nRow );
657*9b8096d0SSteve Yin     }
658*9b8096d0SSteve Yin     catch( Exception& )
659*9b8096d0SSteve Yin     {
660*9b8096d0SSteve Yin     }
661*9b8096d0SSteve Yin 
662*9b8096d0SSteve Yin     return AccessibleCellBase::getAccessibleName();
663*9b8096d0SSteve Yin }
664*9b8096d0SSteve Yin void AccessibleCell::UpdateChildren()
665*9b8096d0SSteve Yin {
666*9b8096d0SSteve Yin 	if (mpText)
667*9b8096d0SSteve Yin 		mpText->UpdateChildren();
668*9b8096d0SSteve Yin }
669*9b8096d0SSteve Yin // ----SD table ACC
670*9b8096d0SSteve Yin 
671*9b8096d0SSteve Yin /* MT: Above getAccessibleName was introduced with IA2 CWS, while below was introduce in 3.3 meanwhile. Check which one is correct
672*9b8096d0SSteve Yin If this is correct, we also don't need 	sdr::table::CellRef getCellRef(), UpdateChildren(), getCellName( sal_Int32 nCol, sal_Int32 nRow ) above
673*9b8096d0SSteve Yin 
674cdf0e10cSrcweir ::rtl::OUString SAL_CALL AccessibleCell::getAccessibleName (void) throw (::com::sun::star::uno::RuntimeException)
675cdf0e10cSrcweir {
676cdf0e10cSrcweir     ThrowIfDisposed ();
677cdf0e10cSrcweir     ::vos::OGuard aSolarGuard (::Application::GetSolarMutex());
678cdf0e10cSrcweir 
679cdf0e10cSrcweir     if( mxCell.is() )
680cdf0e10cSrcweir         return mxCell->getName();
681cdf0e10cSrcweir 
682cdf0e10cSrcweir     return AccessibleCellBase::getAccessibleName();
683cdf0e10cSrcweir }
684*9b8096d0SSteve Yin */
685cdf0e10cSrcweir 
686cdf0e10cSrcweir } // end of namespace accessibility
687