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