xref: /trunk/main/svx/source/table/accessiblecell.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
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
10cdf0e10cSrcweir  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
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.
19cdf0e10cSrcweir  *
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 
AccessibleCell(const::com::sun::star::uno::Reference<::com::sun::star::accessibility::XAccessible> & rxParent,const sdr::table::CellRef & rCell,sal_Int32 nIndex,const AccessibleShapeTreeInfo & rShapeTreeInfo)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 {
639b8096d0SSteve Yin     //Init the pAccTable var
649b8096d0SSteve Yin     pAccTable = dynamic_cast <AccessibleTableShape *> (rxParent.get());
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir // --------------------------------------------------------------------
68cdf0e10cSrcweir 
~AccessibleCell(void)69cdf0e10cSrcweir AccessibleCell::~AccessibleCell (void)
70cdf0e10cSrcweir {
71cdf0e10cSrcweir     DBG_ASSERT( mpText == 0, "svx::AccessibleCell::~AccessibleCell(), not disposed!?" );
72cdf0e10cSrcweir }
73cdf0e10cSrcweir 
74cdf0e10cSrcweir // --------------------------------------------------------------------
75cdf0e10cSrcweir 
Init(void)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 
SetState(sal_Int16 aState)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 
ResetState(sal_Int16 aState)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 
GetState(sal_Int16 aState)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 
operator ==(const AccessibleCell & rAccessibleCell)159cdf0e10cSrcweir bool AccessibleCell::operator== (const AccessibleCell& rAccessibleCell)
160cdf0e10cSrcweir {
161cdf0e10cSrcweir     return this == &rAccessibleCell;
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir //-----------------------------------------------------------------------------
165cdf0e10cSrcweir // XInterface
166cdf0e10cSrcweir //-----------------------------------------------------------------------------
167cdf0e10cSrcweir 
queryInterface(const Type & aType)168cdf0e10cSrcweir Any SAL_CALL AccessibleCell::queryInterface( const Type& aType ) throw (RuntimeException)
169cdf0e10cSrcweir {
170cdf0e10cSrcweir     return AccessibleCellBase::queryInterface( aType );
171cdf0e10cSrcweir }
172cdf0e10cSrcweir 
173cdf0e10cSrcweir //-----------------------------------------------------------------------------
174cdf0e10cSrcweir 
acquire()175cdf0e10cSrcweir void SAL_CALL AccessibleCell::acquire(  ) throw ()
176cdf0e10cSrcweir {
177cdf0e10cSrcweir     AccessibleCellBase::acquire();
178cdf0e10cSrcweir }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir //-----------------------------------------------------------------------------
181cdf0e10cSrcweir 
release()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 */
getAccessibleChildCount()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 */
getAccessibleChild(sal_Int32 nIndex)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 */
getAccessibleStateSet(void)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             }
2479b8096d0SSteve Yin             // Set the invisible state for merged cell
2489b8096d0SSteve Yin             if (mxCell.is() && mxCell->isMerged())
2499b8096d0SSteve Yin                 pStateSet->RemoveState(AccessibleStateType::VISIBLE);
2509b8096d0SSteve Yin             else
2519b8096d0SSteve Yin                 pStateSet->AddState(AccessibleStateType::VISIBLE);
252cdf0e10cSrcweir 
2539b8096d0SSteve Yin 
2549b8096d0SSteve Yin             //Solution:Just when the parent table is not read-only,set states EDITABLE,RESIZABLE,MOVEABLE
2559b8096d0SSteve Yin             ::com::sun::star::uno::Reference<XAccessible> xTempAcc = getAccessibleParent();
2569b8096d0SSteve Yin             if( xTempAcc.is() )
2579b8096d0SSteve Yin             {
2589b8096d0SSteve Yin                 ::com::sun::star::uno::Reference<XAccessibleContext>
2599b8096d0SSteve Yin                                         xTempAccContext = xTempAcc->getAccessibleContext();
2609b8096d0SSteve Yin                 if( xTempAccContext.is() )
2619b8096d0SSteve Yin                 {
2629b8096d0SSteve Yin                     ::com::sun::star::uno::Reference<XAccessibleStateSet> rState =
2639b8096d0SSteve Yin                         xTempAccContext->getAccessibleStateSet();
2649b8096d0SSteve Yin                     if( rState.is() )           {
2659b8096d0SSteve Yin                         com::sun::star::uno::Sequence<short> pStates = rState->getStates();
2669b8096d0SSteve Yin                         int count = pStates.getLength();
2679b8096d0SSteve Yin                         for( int iIndex = 0;iIndex < count;iIndex++ )
2689b8096d0SSteve Yin                         {
2699b8096d0SSteve Yin                             if( pStates[iIndex] == AccessibleStateType::EDITABLE )
2709b8096d0SSteve Yin                             {
2719b8096d0SSteve Yin                                 pStateSet->AddState (AccessibleStateType::EDITABLE);
2729b8096d0SSteve Yin                                 pStateSet->AddState (AccessibleStateType::RESIZABLE);
2739b8096d0SSteve Yin                                 pStateSet->AddState (AccessibleStateType::MOVEABLE);
2749b8096d0SSteve Yin                                 break;
2759b8096d0SSteve Yin                             }
2769b8096d0SSteve Yin                         }
2779b8096d0SSteve Yin                     }
2789b8096d0SSteve Yin                 }
2799b8096d0SSteve Yin             }
280cdf0e10cSrcweir             // Create a copy of the state set that may be modified by the
281cdf0e10cSrcweir             // caller without affecting the current state set.
282cdf0e10cSrcweir             xStateSet = Reference<XAccessibleStateSet>(new ::utl::AccessibleStateSetHelper (*pStateSet));
283cdf0e10cSrcweir         }
284cdf0e10cSrcweir     }
285cdf0e10cSrcweir 
286cdf0e10cSrcweir     return xStateSet;
287cdf0e10cSrcweir }
288cdf0e10cSrcweir 
289cdf0e10cSrcweir // --------------------------------------------------------------------
290cdf0e10cSrcweir // XAccessibleComponent
291cdf0e10cSrcweir // --------------------------------------------------------------------
292cdf0e10cSrcweir 
containsPoint(const::com::sun::star::awt::Point & aPoint)293cdf0e10cSrcweir sal_Bool SAL_CALL AccessibleCell::containsPoint( const ::com::sun::star::awt::Point& aPoint) throw (::com::sun::star::uno::RuntimeException)
294cdf0e10cSrcweir {
295cdf0e10cSrcweir     return AccessibleComponentBase::containsPoint( aPoint );
296cdf0e10cSrcweir }
297cdf0e10cSrcweir 
298cdf0e10cSrcweir /** The implementation below is at the moment straightforward.  It iterates
299cdf0e10cSrcweir     over all children (and thereby instances all children which have not
300*e4384c19SJohn Bampton     been already instantiated) until a child covering the specified point is
301cdf0e10cSrcweir     found.
302cdf0e10cSrcweir     This leaves room for improvement.  For instance, first iterate only over
303cdf0e10cSrcweir     the already instantiated children and only if no match is found
304cdf0e10cSrcweir     instantiate the remaining ones.
305cdf0e10cSrcweir */
getAccessibleAtPoint(const::com::sun::star::awt::Point & aPoint)306cdf0e10cSrcweir Reference<XAccessible > SAL_CALL  AccessibleCell::getAccessibleAtPoint ( const ::com::sun::star::awt::Point& aPoint) throw(RuntimeException)
307cdf0e10cSrcweir {
308cdf0e10cSrcweir     ::vos::OGuard aSolarGuard (::Application::GetSolarMutex());
309cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
310cdf0e10cSrcweir 
311cdf0e10cSrcweir     sal_Int32 nChildCount = getAccessibleChildCount ();
312cdf0e10cSrcweir     for (sal_Int32 i=0; i<nChildCount; ++i)
313cdf0e10cSrcweir     {
314cdf0e10cSrcweir         Reference<XAccessible> xChild (getAccessibleChild (i));
315cdf0e10cSrcweir         if (xChild.is())
316cdf0e10cSrcweir         {
317cdf0e10cSrcweir             Reference<XAccessibleComponent> xChildComponent (xChild->getAccessibleContext(), uno::UNO_QUERY);
318cdf0e10cSrcweir             if (xChildComponent.is())
319cdf0e10cSrcweir             {
320cdf0e10cSrcweir                 awt::Rectangle aBBox (xChildComponent->getBounds());
321cdf0e10cSrcweir                 if ( (aPoint.X >= aBBox.X)
322cdf0e10cSrcweir                     && (aPoint.Y >= aBBox.Y)
323cdf0e10cSrcweir                     && (aPoint.X < aBBox.X+aBBox.Width)
324cdf0e10cSrcweir                     && (aPoint.Y < aBBox.Y+aBBox.Height) )
325cdf0e10cSrcweir                     return xChild;
326cdf0e10cSrcweir             }
327cdf0e10cSrcweir         }
328cdf0e10cSrcweir     }
329cdf0e10cSrcweir 
330cdf0e10cSrcweir     // Have not found a child under the given point.  Returning empty
331cdf0e10cSrcweir     // reference to indicate this.
332cdf0e10cSrcweir     return uno::Reference<XAccessible>();
333cdf0e10cSrcweir }
334cdf0e10cSrcweir 
335cdf0e10cSrcweir // --------------------------------------------------------------------
336cdf0e10cSrcweir 
getBounds(void)337cdf0e10cSrcweir ::com::sun::star::awt::Rectangle SAL_CALL AccessibleCell::getBounds(void) throw(RuntimeException)
338cdf0e10cSrcweir {
339cdf0e10cSrcweir     ::vos::OGuard aSolarGuard (::Application::GetSolarMutex());
340cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
341cdf0e10cSrcweir 
342cdf0e10cSrcweir     ThrowIfDisposed ();
343cdf0e10cSrcweir     ::com::sun::star::awt::Rectangle aBoundingBox;
344cdf0e10cSrcweir     if( mxCell.is() )
345cdf0e10cSrcweir     {
346cdf0e10cSrcweir         // Get the cell's bounding box in internal coordinates (in 100th of mm)
347cdf0e10cSrcweir         const ::Rectangle aCellRect( mxCell->getCellRect() );
348cdf0e10cSrcweir 
349cdf0e10cSrcweir         // Transform coordinates from internal to pixel.
350cdf0e10cSrcweir         if (maShapeTreeInfo.GetViewForwarder() == NULL)
351cdf0e10cSrcweir             throw uno::RuntimeException (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AccessibleCell has no valid view forwarder")),static_cast<uno::XWeak*>(this));
352cdf0e10cSrcweir 
353cdf0e10cSrcweir         ::Size aPixelSize( maShapeTreeInfo.GetViewForwarder()->LogicToPixel(::Size(aCellRect.GetWidth(), aCellRect.GetHeight())) );
354cdf0e10cSrcweir         ::Point aPixelPosition( maShapeTreeInfo.GetViewForwarder()->LogicToPixel( aCellRect.TopLeft() ));
355cdf0e10cSrcweir 
356cdf0e10cSrcweir         // Clip the shape's bounding box with the bounding box of its parent.
357cdf0e10cSrcweir         Reference<XAccessibleComponent> xParentComponent ( getAccessibleParent(), uno::UNO_QUERY);
358cdf0e10cSrcweir         if (xParentComponent.is())
359cdf0e10cSrcweir         {
360cdf0e10cSrcweir             // Make the coordinates relative to the parent.
361cdf0e10cSrcweir             awt::Point aParentLocation (xParentComponent->getLocationOnScreen());
362cdf0e10cSrcweir             int x = aPixelPosition.getX() - aParentLocation.X;
363cdf0e10cSrcweir             int y = aPixelPosition.getY() - aParentLocation.Y;
364cdf0e10cSrcweir 
365cdf0e10cSrcweir             // Clip with parent (with coordinates relative to itself).
366cdf0e10cSrcweir             ::Rectangle aBBox ( x, y, x + aPixelSize.getWidth(), y + aPixelSize.getHeight());
367cdf0e10cSrcweir             awt::Size aParentSize (xParentComponent->getSize());
368cdf0e10cSrcweir             ::Rectangle aParentBBox (0,0, aParentSize.Width, aParentSize.Height);
369cdf0e10cSrcweir             aBBox = aBBox.GetIntersection (aParentBBox);
370cdf0e10cSrcweir             aBoundingBox = awt::Rectangle ( aBBox.getX(), aBBox.getY(), aBBox.getWidth(), aBBox.getHeight());
371cdf0e10cSrcweir         }
372cdf0e10cSrcweir         else
373cdf0e10cSrcweir         {
374cdf0e10cSrcweir             OSL_TRACE ("parent does not support component");
375cdf0e10cSrcweir             aBoundingBox = awt::Rectangle (aPixelPosition.getX(), aPixelPosition.getY(),aPixelSize.getWidth(), aPixelSize.getHeight());
376cdf0e10cSrcweir         }
377cdf0e10cSrcweir     }
378cdf0e10cSrcweir 
379cdf0e10cSrcweir     return aBoundingBox;
380cdf0e10cSrcweir }
381cdf0e10cSrcweir 
382cdf0e10cSrcweir // --------------------------------------------------------------------
383cdf0e10cSrcweir 
getLocation(void)384cdf0e10cSrcweir ::com::sun::star::awt::Point SAL_CALL AccessibleCell::getLocation(void) throw (RuntimeException)
385cdf0e10cSrcweir {
386cdf0e10cSrcweir     ThrowIfDisposed ();
387cdf0e10cSrcweir     ::com::sun::star::awt::Rectangle aBoundingBox(getBounds());
388cdf0e10cSrcweir     return ::com::sun::star::awt::Point(aBoundingBox.X, aBoundingBox.Y);
389cdf0e10cSrcweir }
390cdf0e10cSrcweir 
391cdf0e10cSrcweir // --------------------------------------------------------------------
392cdf0e10cSrcweir 
getLocationOnScreen(void)393cdf0e10cSrcweir ::com::sun::star::awt::Point SAL_CALL AccessibleCell::getLocationOnScreen(void) throw(RuntimeException)
394cdf0e10cSrcweir {
395cdf0e10cSrcweir     ThrowIfDisposed ();
396cdf0e10cSrcweir 
397cdf0e10cSrcweir     // Get relative position...
398cdf0e10cSrcweir     ::com::sun::star::awt::Point aLocation(getLocation ());
399cdf0e10cSrcweir 
400cdf0e10cSrcweir     // ... and add absolute position of the parent.
401cdf0e10cSrcweir     Reference<XAccessibleComponent> xParentComponent( getAccessibleParent(), uno::UNO_QUERY);
402cdf0e10cSrcweir     if(xParentComponent.is())
403cdf0e10cSrcweir     {
404cdf0e10cSrcweir         ::com::sun::star::awt::Point aParentLocation(xParentComponent->getLocationOnScreen());
405cdf0e10cSrcweir         aLocation.X += aParentLocation.X;
406cdf0e10cSrcweir         aLocation.Y += aParentLocation.Y;
407cdf0e10cSrcweir     }
408cdf0e10cSrcweir     else
409cdf0e10cSrcweir     {
410cdf0e10cSrcweir         OSL_TRACE ("getLocation: parent does not support XAccessibleComponent");
411cdf0e10cSrcweir     }
412cdf0e10cSrcweir 
413cdf0e10cSrcweir     return aLocation;
414cdf0e10cSrcweir }
415cdf0e10cSrcweir 
416cdf0e10cSrcweir // --------------------------------------------------------------------
417cdf0e10cSrcweir 
getSize(void)418cdf0e10cSrcweir awt::Size SAL_CALL AccessibleCell::getSize (void) throw (RuntimeException)
419cdf0e10cSrcweir {
420cdf0e10cSrcweir     ThrowIfDisposed ();
421cdf0e10cSrcweir     awt::Rectangle aBoundingBox (getBounds());
422cdf0e10cSrcweir     return awt::Size (aBoundingBox.Width, aBoundingBox.Height);
423cdf0e10cSrcweir }
424cdf0e10cSrcweir 
425cdf0e10cSrcweir // --------------------------------------------------------------------
426cdf0e10cSrcweir 
addFocusListener(const::com::sun::star::uno::Reference<::com::sun::star::awt::XFocusListener> & xListener)427cdf0e10cSrcweir void SAL_CALL AccessibleCell::addFocusListener ( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& xListener) throw (::com::sun::star::uno::RuntimeException)
428cdf0e10cSrcweir {
429cdf0e10cSrcweir     AccessibleComponentBase::addFocusListener( xListener );
430cdf0e10cSrcweir }
431cdf0e10cSrcweir 
432cdf0e10cSrcweir // --------------------------------------------------------------------
433cdf0e10cSrcweir 
removeFocusListener(const::com::sun::star::uno::Reference<::com::sun::star::awt::XFocusListener> & xListener)434cdf0e10cSrcweir void SAL_CALL AccessibleCell::removeFocusListener (const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
435cdf0e10cSrcweir {
436cdf0e10cSrcweir     AccessibleComponentBase::removeFocusListener( xListener );
437cdf0e10cSrcweir }
438cdf0e10cSrcweir 
439cdf0e10cSrcweir // --------------------------------------------------------------------
440cdf0e10cSrcweir 
grabFocus(void)441cdf0e10cSrcweir void SAL_CALL AccessibleCell::grabFocus (void) throw (::com::sun::star::uno::RuntimeException)
442cdf0e10cSrcweir {
443cdf0e10cSrcweir     AccessibleComponentBase::grabFocus();
444cdf0e10cSrcweir }
445cdf0e10cSrcweir 
446cdf0e10cSrcweir // --------------------------------------------------------------------
447cdf0e10cSrcweir 
getForeground(void)448cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleCell::getForeground(void) throw (RuntimeException)
449cdf0e10cSrcweir {
450cdf0e10cSrcweir     ThrowIfDisposed ();
451cdf0e10cSrcweir     sal_Int32 nColor (0x0ffffffL);
452cdf0e10cSrcweir 
453cdf0e10cSrcweir     // todo
454cdf0e10cSrcweir     return nColor;
455cdf0e10cSrcweir }
456cdf0e10cSrcweir 
457cdf0e10cSrcweir // --------------------------------------------------------------------
458cdf0e10cSrcweir 
getBackground(void)459cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleCell::getBackground (void) throw (RuntimeException)
460cdf0e10cSrcweir {
461cdf0e10cSrcweir     ThrowIfDisposed ();
462cdf0e10cSrcweir     sal_Int32 nColor (0L);
463cdf0e10cSrcweir 
464cdf0e10cSrcweir     // todo
465cdf0e10cSrcweir     return nColor;
466cdf0e10cSrcweir }
467cdf0e10cSrcweir 
468cdf0e10cSrcweir // --------------------------------------------------------------------
469cdf0e10cSrcweir // XAccessibleExtendedComponent
470cdf0e10cSrcweir // --------------------------------------------------------------------
471cdf0e10cSrcweir 
getFont(void)472cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFont > SAL_CALL AccessibleCell::getFont (void) throw (::com::sun::star::uno::RuntimeException)
473cdf0e10cSrcweir {
474cdf0e10cSrcweir //todo
475cdf0e10cSrcweir     return AccessibleComponentBase::getFont();
476cdf0e10cSrcweir }
477cdf0e10cSrcweir 
478cdf0e10cSrcweir // --------------------------------------------------------------------
479cdf0e10cSrcweir 
getTitledBorderText(void)480cdf0e10cSrcweir ::rtl::OUString SAL_CALL AccessibleCell::getTitledBorderText (void) throw (::com::sun::star::uno::RuntimeException)
481cdf0e10cSrcweir {
482cdf0e10cSrcweir     return AccessibleComponentBase::getTitledBorderText();
483cdf0e10cSrcweir }
484cdf0e10cSrcweir 
485cdf0e10cSrcweir // --------------------------------------------------------------------
486cdf0e10cSrcweir 
getToolTipText(void)487cdf0e10cSrcweir ::rtl::OUString SAL_CALL AccessibleCell::getToolTipText (void) throw (::com::sun::star::uno::RuntimeException)
488cdf0e10cSrcweir {
489cdf0e10cSrcweir     return AccessibleComponentBase::getToolTipText();
490cdf0e10cSrcweir }
491cdf0e10cSrcweir 
492cdf0e10cSrcweir // --------------------------------------------------------------------
493cdf0e10cSrcweir // XAccessibleEventBroadcaster
494cdf0e10cSrcweir // --------------------------------------------------------------------
495cdf0e10cSrcweir 
addEventListener(const Reference<XAccessibleEventListener> & rxListener)496cdf0e10cSrcweir void SAL_CALL AccessibleCell::addEventListener( const Reference<XAccessibleEventListener >& rxListener)  throw (RuntimeException)
497cdf0e10cSrcweir {
498cdf0e10cSrcweir     ::vos::OGuard aSolarGuard (::Application::GetSolarMutex());
499cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
500cdf0e10cSrcweir     if (rBHelper.bDisposed || rBHelper.bInDispose)
501cdf0e10cSrcweir     {
502cdf0e10cSrcweir         Reference<XInterface> xSource( static_cast<XComponent *>(this) );
503cdf0e10cSrcweir         lang::EventObject aEventObj(xSource);
504cdf0e10cSrcweir         rxListener->disposing(aEventObj);
505cdf0e10cSrcweir     }
506cdf0e10cSrcweir     else
507cdf0e10cSrcweir     {
508cdf0e10cSrcweir         AccessibleContextBase::addEventListener (rxListener);
509cdf0e10cSrcweir         if (mpText != NULL)
510cdf0e10cSrcweir             mpText->AddEventListener (rxListener);
511cdf0e10cSrcweir     }
512cdf0e10cSrcweir }
513cdf0e10cSrcweir 
514cdf0e10cSrcweir // --------------------------------------------------------------------
515cdf0e10cSrcweir 
removeEventListener(const Reference<XAccessibleEventListener> & rxListener)516cdf0e10cSrcweir void SAL_CALL AccessibleCell::removeEventListener( const Reference<XAccessibleEventListener >& rxListener) throw (RuntimeException)
517cdf0e10cSrcweir {
518cdf0e10cSrcweir     ::vos::OGuard aSolarGuard (::Application::GetSolarMutex());
519cdf0e10cSrcweir     AccessibleContextBase::removeEventListener(rxListener);
520cdf0e10cSrcweir     if (mpText != NULL)
521cdf0e10cSrcweir         mpText->RemoveEventListener (rxListener);
522cdf0e10cSrcweir }
523cdf0e10cSrcweir 
524cdf0e10cSrcweir // --------------------------------------------------------------------
525cdf0e10cSrcweir // XServiceInfo
526cdf0e10cSrcweir // --------------------------------------------------------------------
527cdf0e10cSrcweir 
getImplementationName(void)528cdf0e10cSrcweir OUString SAL_CALL AccessibleCell::getImplementationName(void) throw (RuntimeException)
529cdf0e10cSrcweir {
530cdf0e10cSrcweir     return OUString(RTL_CONSTASCII_USTRINGPARAM("AccessibleCell"));
531cdf0e10cSrcweir }
532cdf0e10cSrcweir 
533cdf0e10cSrcweir // --------------------------------------------------------------------
534cdf0e10cSrcweir 
getSupportedServiceNames(void)535cdf0e10cSrcweir Sequence<OUString> SAL_CALL AccessibleCell::getSupportedServiceNames(void) throw (RuntimeException)
536cdf0e10cSrcweir {
537cdf0e10cSrcweir     ThrowIfDisposed ();
538cdf0e10cSrcweir 
539cdf0e10cSrcweir     // Get list of supported service names from base class...
540cdf0e10cSrcweir     uno::Sequence<OUString> aServiceNames = AccessibleContextBase::getSupportedServiceNames();
541cdf0e10cSrcweir     sal_Int32 nCount (aServiceNames.getLength());
542cdf0e10cSrcweir 
543cdf0e10cSrcweir     // ...and add additional names.
544cdf0e10cSrcweir     aServiceNames.realloc (nCount + 1);
545cdf0e10cSrcweir     static const OUString sAdditionalServiceName (RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.AccessibleCell"));
546cdf0e10cSrcweir     aServiceNames[nCount] = sAdditionalServiceName;
547cdf0e10cSrcweir 
548cdf0e10cSrcweir     return aServiceNames;
549cdf0e10cSrcweir }
550cdf0e10cSrcweir 
551cdf0e10cSrcweir // --------------------------------------------------------------------
552cdf0e10cSrcweir // IAccessibleViewForwarderListener
553cdf0e10cSrcweir // --------------------------------------------------------------------
554cdf0e10cSrcweir 
ViewForwarderChanged(ChangeType,const IAccessibleViewForwarder *)555cdf0e10cSrcweir void AccessibleCell::ViewForwarderChanged (ChangeType /*aChangeType*/, const IAccessibleViewForwarder* /*pViewForwarder*/)
556cdf0e10cSrcweir {
557cdf0e10cSrcweir     // Inform all listeners that the graphical representation (i.e. size
558cdf0e10cSrcweir     // and/or position) of the shape has changed.
559cdf0e10cSrcweir     CommitChange(AccessibleEventId::VISIBLE_DATA_CHANGED, Any(), Any());
560cdf0e10cSrcweir 
561cdf0e10cSrcweir     // update our children that our screen position might have changed
562cdf0e10cSrcweir     if( mpText )
563cdf0e10cSrcweir         mpText->UpdateChildren();
564cdf0e10cSrcweir }
565cdf0e10cSrcweir 
566cdf0e10cSrcweir // --------------------------------------------------------------------
567cdf0e10cSrcweir // protected
568cdf0e10cSrcweir // --------------------------------------------------------------------
569cdf0e10cSrcweir 
disposing(void)570cdf0e10cSrcweir void AccessibleCell::disposing (void)
571cdf0e10cSrcweir {
572cdf0e10cSrcweir     ::vos::OGuard aSolarGuard (::Application::GetSolarMutex());
573cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
574cdf0e10cSrcweir 
575cdf0e10cSrcweir     // Make sure to send an event that this object looses the focus in the
576cdf0e10cSrcweir     // case that it has the focus.
577cdf0e10cSrcweir     ::utl::AccessibleStateSetHelper* pStateSet = static_cast< ::utl::AccessibleStateSetHelper*>(mxStateSet.get());
578cdf0e10cSrcweir     if (pStateSet != NULL)
579cdf0e10cSrcweir         pStateSet->RemoveState(AccessibleStateType::FOCUSED);
580cdf0e10cSrcweir 
581cdf0e10cSrcweir     if (mpText != NULL)
582cdf0e10cSrcweir     {
583cdf0e10cSrcweir         mpText->Dispose();
584cdf0e10cSrcweir         delete mpText;
585cdf0e10cSrcweir         mpText = NULL;
586cdf0e10cSrcweir     }
587cdf0e10cSrcweir 
588cdf0e10cSrcweir     // Cleanup.  Remove references to objects to allow them to be
589cdf0e10cSrcweir     // destroyed.
590cdf0e10cSrcweir     mxCell.clear();
591cdf0e10cSrcweir     maShapeTreeInfo = AccessibleShapeTreeInfo();
592cdf0e10cSrcweir 
593cdf0e10cSrcweir     // Call base classes.
594cdf0e10cSrcweir     AccessibleContextBase::dispose ();
595cdf0e10cSrcweir }
596cdf0e10cSrcweir 
getAccessibleIndexInParent(void)597cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleCell::getAccessibleIndexInParent (void) throw (RuntimeException)
598cdf0e10cSrcweir {
599cdf0e10cSrcweir     ThrowIfDisposed ();
600cdf0e10cSrcweir     return mnIndexInParent;
601cdf0e10cSrcweir }
602cdf0e10cSrcweir 
getCellRef()6039b8096d0SSteve Yin sdr::table::CellRef AccessibleCell::getCellRef()
6049b8096d0SSteve Yin {
6059b8096d0SSteve Yin     return mxCell;
6069b8096d0SSteve Yin }
getCellName(sal_Int32 nCol,sal_Int32 nRow)6079b8096d0SSteve Yin ::rtl::OUString AccessibleCell::getCellName( sal_Int32 nCol, sal_Int32 nRow )
6089b8096d0SSteve Yin {
6099b8096d0SSteve Yin     rtl::OUStringBuffer aBuf;
6109b8096d0SSteve Yin 
6119b8096d0SSteve Yin     if (nCol < 26*26)
6129b8096d0SSteve Yin     {
6139b8096d0SSteve Yin         if (nCol < 26)
6149b8096d0SSteve Yin             aBuf.append( static_cast<sal_Unicode>( 'A' +
6159b8096d0SSteve Yin                         static_cast<sal_uInt16>(nCol)));
6169b8096d0SSteve Yin         else
6179b8096d0SSteve Yin         {
6189b8096d0SSteve Yin             aBuf.append( static_cast<sal_Unicode>( 'A' +
6199b8096d0SSteve Yin                         (static_cast<sal_uInt16>(nCol) / 26) - 1));
6209b8096d0SSteve Yin             aBuf.append( static_cast<sal_Unicode>( 'A' +
6219b8096d0SSteve Yin                         (static_cast<sal_uInt16>(nCol) % 26)));
6229b8096d0SSteve Yin         }
6239b8096d0SSteve Yin     }
6249b8096d0SSteve Yin     else
6259b8096d0SSteve Yin     {
6269b8096d0SSteve Yin         String aStr;
6279b8096d0SSteve Yin         while (nCol >= 26)
6289b8096d0SSteve Yin         {
6299b8096d0SSteve Yin             sal_Int32 nC = nCol % 26;
6309b8096d0SSteve Yin             aStr += static_cast<sal_Unicode>( 'A' +
6319b8096d0SSteve Yin                     static_cast<sal_uInt16>(nC));
6329b8096d0SSteve Yin             nCol = nCol - nC;
6339b8096d0SSteve Yin             nCol = nCol / 26 - 1;
6349b8096d0SSteve Yin         }
6359b8096d0SSteve Yin         aStr += static_cast<sal_Unicode>( 'A' +
6369b8096d0SSteve Yin                 static_cast<sal_uInt16>(nCol));
6379b8096d0SSteve Yin         aStr.Reverse();
6389b8096d0SSteve Yin         aBuf.append( aStr);
6399b8096d0SSteve Yin     }
6409b8096d0SSteve Yin     aBuf.append( OUString::valueOf(nRow+1) );
6419b8096d0SSteve Yin     return aBuf.makeStringAndClear();
6429b8096d0SSteve Yin }
getAccessibleName(void)6439b8096d0SSteve Yin ::rtl::OUString SAL_CALL AccessibleCell::getAccessibleName (void) throw (::com::sun::star::uno::RuntimeException)
6449b8096d0SSteve Yin {
6459b8096d0SSteve Yin     ThrowIfDisposed ();
6469b8096d0SSteve Yin     ::vos::OGuard aSolarGuard (::Application::GetSolarMutex());
6479b8096d0SSteve Yin 
6489b8096d0SSteve Yin     if( pAccTable )
6499b8096d0SSteve Yin     try
6509b8096d0SSteve Yin     {
6519b8096d0SSteve Yin         sal_Int32 nRow = 0, nCol = 0;
6529b8096d0SSteve Yin         pAccTable->getColumnAndRow(mnIndexInParent, nCol, nRow);
6539b8096d0SSteve Yin         return getCellName( nCol, nRow );
6549b8096d0SSteve Yin     }
6559b8096d0SSteve Yin     catch( Exception& )
6569b8096d0SSteve Yin     {
6579b8096d0SSteve Yin     }
6589b8096d0SSteve Yin 
6599b8096d0SSteve Yin     return AccessibleCellBase::getAccessibleName();
6609b8096d0SSteve Yin }
UpdateChildren()6619b8096d0SSteve Yin void AccessibleCell::UpdateChildren()
6629b8096d0SSteve Yin {
6639b8096d0SSteve Yin     if (mpText)
6649b8096d0SSteve Yin         mpText->UpdateChildren();
6659b8096d0SSteve Yin }
6669b8096d0SSteve Yin 
6679b8096d0SSteve Yin /* MT: Above getAccessibleName was introduced with IA2 CWS, while below was introduce in 3.3 meanwhile. Check which one is correct
6689b8096d0SSteve Yin If this is correct, we also don't need  sdr::table::CellRef getCellRef(), UpdateChildren(), getCellName( sal_Int32 nCol, sal_Int32 nRow ) above
6699b8096d0SSteve Yin 
670cdf0e10cSrcweir ::rtl::OUString SAL_CALL AccessibleCell::getAccessibleName (void) throw (::com::sun::star::uno::RuntimeException)
671cdf0e10cSrcweir {
672cdf0e10cSrcweir     ThrowIfDisposed ();
673cdf0e10cSrcweir     ::vos::OGuard aSolarGuard (::Application::GetSolarMutex());
674cdf0e10cSrcweir 
675cdf0e10cSrcweir     if( mxCell.is() )
676cdf0e10cSrcweir         return mxCell->getName();
677cdf0e10cSrcweir 
678cdf0e10cSrcweir     return AccessibleCellBase::getAccessibleName();
679cdf0e10cSrcweir }
6809b8096d0SSteve Yin */
681cdf0e10cSrcweir 
682cdf0e10cSrcweir } // end of namespace accessibility
683