Update ooo320-m1
[ooovba.git] / sc / source / ui / Accessibility / AccessiblePreviewHeaderCell.cxx
bloba6028238610513b534e9b6e5466bafab42d06aff
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessiblePreviewHeaderCell.cxx,v $
10 * $Revision: 1.26 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
33 #include "scitems.hxx"
34 #include <svx/eeitem.hxx>
35 #include <tools/gen.hxx>
36 #include "AccessibleText.hxx"
37 #include "editsrc.hxx"
38 #include <svx/AccessibleTextHelper.hxx>
39 #include "AccessiblePreviewHeaderCell.hxx"
40 #include "AccessibilityHints.hxx"
41 #include "prevwsh.hxx"
42 #include "unoguard.hxx"
43 #include "miscuno.hxx"
44 #include "prevloc.hxx"
45 #include "scresid.hxx"
46 #ifndef SC_SC_HRC
47 #include "sc.hrc"
48 #endif
50 #include <com/sun/star/accessibility/AccessibleRole.hpp>
51 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
53 #include <vcl/window.hxx>
54 #include <svtools/smplhint.hxx>
55 #include <unotools/accessiblestatesethelper.hxx>
56 #include <comphelper/sequence.hxx>
57 #include <toolkit/helper/convert.hxx>
59 using namespace ::com::sun::star;
60 using namespace ::com::sun::star::accessibility;
62 //===== internal ============================================================
64 ScAccessiblePreviewHeaderCell::ScAccessiblePreviewHeaderCell( const ::com::sun::star::uno::Reference<
65 ::com::sun::star::accessibility::XAccessible>& rxParent,
66 ScPreviewShell* pViewShell,
67 const ScAddress& rCellPos, sal_Bool bIsColHdr, sal_Bool bIsRowHdr,
68 sal_Int32 nIndex ) :
69 ScAccessibleContextBase( rxParent, AccessibleRole::TABLE_CELL ),
70 mpViewShell( pViewShell ),
71 mpTextHelper( NULL ),
72 mnIndex( nIndex ),
73 maCellPos( rCellPos ),
74 mbColumnHeader( bIsColHdr ),
75 mbRowHeader( bIsRowHdr ),
76 mpTableInfo( NULL )
78 if (mpViewShell)
79 mpViewShell->AddAccessibilityObject(*this);
82 ScAccessiblePreviewHeaderCell::~ScAccessiblePreviewHeaderCell()
84 if (mpViewShell)
85 mpViewShell->RemoveAccessibilityObject(*this);
88 void SAL_CALL ScAccessiblePreviewHeaderCell::disposing()
90 ScUnoGuard aGuard;
91 if (mpViewShell)
93 mpViewShell->RemoveAccessibilityObject(*this);
94 mpViewShell = NULL;
97 if (mpTableInfo)
98 DELETEZ (mpTableInfo);
100 ScAccessibleContextBase::disposing();
103 //===== SfxListener =====================================================
105 void ScAccessiblePreviewHeaderCell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
107 if (rHint.ISA( SfxSimpleHint ))
109 const SfxSimpleHint& rRef = (const SfxSimpleHint&)rHint;
110 ULONG nId = rRef.GetId();
111 if (nId == SC_HINT_ACC_VISAREACHANGED)
113 if (mpTextHelper)
114 mpTextHelper->UpdateChildren();
116 else if ( nId == SFX_HINT_DATACHANGED )
118 // column / row layout may change with any document change,
119 // so it must be invalidated
120 DELETEZ( mpTableInfo );
124 ScAccessibleContextBase::Notify(rBC, rHint);
127 //===== XInterface =====================================================
129 uno::Any SAL_CALL ScAccessiblePreviewHeaderCell::queryInterface( uno::Type const & rType )
130 throw (uno::RuntimeException)
132 uno::Any aAny (ScAccessiblePreviewHeaderCellImpl::queryInterface(rType));
133 return aAny.hasValue() ? aAny : ScAccessibleContextBase::queryInterface(rType);
136 void SAL_CALL ScAccessiblePreviewHeaderCell::acquire()
137 throw ()
139 ScAccessibleContextBase::acquire();
142 void SAL_CALL ScAccessiblePreviewHeaderCell::release()
143 throw ()
145 ScAccessibleContextBase::release();
148 //===== XAccessibleValue ================================================
150 uno::Any SAL_CALL ScAccessiblePreviewHeaderCell::getCurrentValue() throw (uno::RuntimeException)
152 ScUnoGuard aGuard;
153 IsObjectValid();
155 double fValue(0.0);
156 if (mbColumnHeader)
157 fValue = maCellPos.Col();
158 else
159 fValue = maCellPos.Row();
161 uno::Any aAny;
162 aAny <<= fValue;
163 return aAny;
166 sal_Bool SAL_CALL ScAccessiblePreviewHeaderCell::setCurrentValue( const uno::Any& /* aNumber */ )
167 throw (uno::RuntimeException)
169 // it is not possible to set a value
170 return sal_False;
173 uno::Any SAL_CALL ScAccessiblePreviewHeaderCell::getMaximumValue() throw (uno::RuntimeException)
175 ScUnoGuard aGuard;
176 IsObjectValid();
178 double fValue(0.0);
179 if (mbColumnHeader)
180 fValue = MAXCOL;
181 else
182 fValue = MAXROW;
183 uno::Any aAny;
184 aAny <<= fValue;
185 return aAny;
188 uno::Any SAL_CALL ScAccessiblePreviewHeaderCell::getMinimumValue() throw (uno::RuntimeException)
190 double fValue(0.0);
191 uno::Any aAny;
192 aAny <<= fValue;
193 return aAny;
196 //===== XAccessibleComponent ============================================
198 uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleAtPoint( const awt::Point& rPoint )
199 throw (uno::RuntimeException)
201 uno::Reference<XAccessible> xRet;
202 if (containsPoint(rPoint))
204 ScUnoGuard aGuard;
205 IsObjectValid();
207 if(!mpTextHelper)
208 CreateTextHelper();
210 xRet = mpTextHelper->GetAt(rPoint);
213 return xRet;
216 void SAL_CALL ScAccessiblePreviewHeaderCell::grabFocus() throw (uno::RuntimeException)
218 ScUnoGuard aGuard;
219 IsObjectValid();
220 if (getAccessibleParent().is())
222 uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
223 if (xAccessibleComponent.is())
224 xAccessibleComponent->grabFocus();
228 //===== XAccessibleContext ==============================================
230 sal_Int32 SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleChildCount() throw(uno::RuntimeException)
232 ScUnoGuard aGuard;
233 IsObjectValid();
234 if (!mpTextHelper)
235 CreateTextHelper();
236 return mpTextHelper->GetChildCount();
239 uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleChild(sal_Int32 nIndex)
240 throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
242 ScUnoGuard aGuard;
243 IsObjectValid();
244 if (!mpTextHelper)
245 CreateTextHelper();
246 return mpTextHelper->GetChild(nIndex);
249 sal_Int32 SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleIndexInParent() throw (uno::RuntimeException)
251 return mnIndex;
254 uno::Reference<XAccessibleStateSet> SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleStateSet()
255 throw(uno::RuntimeException)
257 ScUnoGuard aGuard;
259 uno::Reference<XAccessibleStateSet> xParentStates;
260 if (getAccessibleParent().is())
262 uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
263 xParentStates = xParentContext->getAccessibleStateSet();
265 utl::AccessibleStateSetHelper* pStateSet = new utl::AccessibleStateSetHelper();
266 if (IsDefunc(xParentStates))
267 pStateSet->AddState(AccessibleStateType::DEFUNC);
268 else
270 pStateSet->AddState(AccessibleStateType::ENABLED);
271 pStateSet->AddState(AccessibleStateType::MULTI_LINE);
272 if (isShowing())
273 pStateSet->AddState(AccessibleStateType::SHOWING);
274 pStateSet->AddState(AccessibleStateType::TRANSIENT);
275 if (isVisible())
276 pStateSet->AddState(AccessibleStateType::VISIBLE);
278 return pStateSet;
281 //===== XServiceInfo ====================================================
283 rtl::OUString SAL_CALL ScAccessiblePreviewHeaderCell::getImplementationName() throw(uno::RuntimeException)
285 return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScAccessiblePreviewHeaderCell"));
288 uno::Sequence<rtl::OUString> SAL_CALL ScAccessiblePreviewHeaderCell::getSupportedServiceNames()
289 throw(uno::RuntimeException)
291 uno::Sequence< ::rtl::OUString > aSequence = ScAccessibleContextBase::getSupportedServiceNames();
292 sal_Int32 nOldSize(aSequence.getLength());
293 aSequence.realloc(nOldSize + 1);
294 ::rtl::OUString* pNames = aSequence.getArray();
296 pNames[nOldSize] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.table.AccessibleCellView"));
298 return aSequence;
301 //===== XTypeProvider =======================================================
303 uno::Sequence< uno::Type > SAL_CALL ScAccessiblePreviewHeaderCell::getTypes()
304 throw (uno::RuntimeException)
306 return comphelper::concatSequences(ScAccessiblePreviewHeaderCellImpl::getTypes(), ScAccessibleContextBase::getTypes());
309 uno::Sequence<sal_Int8> SAL_CALL
310 ScAccessiblePreviewHeaderCell::getImplementationId(void)
311 throw (uno::RuntimeException)
313 ScUnoGuard aGuard;
314 IsObjectValid();
315 static uno::Sequence<sal_Int8> aId;
316 if (aId.getLength() == 0)
318 aId.realloc (16);
319 rtl_createUuid (reinterpret_cast<sal_uInt8 *>(aId.getArray()), 0, sal_True);
321 return aId;
324 //==== internal =========================================================
326 Rectangle ScAccessiblePreviewHeaderCell::GetBoundingBoxOnScreen() const throw (uno::RuntimeException)
328 Rectangle aCellRect;
330 FillTableInfo();
332 if (mpTableInfo)
334 const ScPreviewColRowInfo& rColInfo = mpTableInfo->GetColInfo()[maCellPos.Col()];
335 const ScPreviewColRowInfo& rRowInfo = mpTableInfo->GetRowInfo()[maCellPos.Row()];
337 aCellRect = Rectangle( rColInfo.nPixelStart, rRowInfo.nPixelStart, rColInfo.nPixelEnd, rRowInfo.nPixelEnd );
340 if (mpViewShell)
342 Window* pWindow = mpViewShell->GetWindow();
343 if (pWindow)
345 Rectangle aRect = pWindow->GetWindowExtentsRelative(NULL);
346 aCellRect.setX(aCellRect.getX() + aRect.getX());
347 aCellRect.setY(aCellRect.getY() + aRect.getY());
350 return aCellRect;
353 Rectangle ScAccessiblePreviewHeaderCell::GetBoundingBox() const throw (uno::RuntimeException)
355 FillTableInfo();
357 if (mpTableInfo)
359 const ScPreviewColRowInfo& rColInfo = mpTableInfo->GetColInfo()[maCellPos.Col()];
360 const ScPreviewColRowInfo& rRowInfo = mpTableInfo->GetRowInfo()[maCellPos.Row()];
362 Rectangle aCellRect( rColInfo.nPixelStart, rRowInfo.nPixelStart, rColInfo.nPixelEnd, rRowInfo.nPixelEnd );
363 uno::Reference<XAccessible> xAccParent = const_cast<ScAccessiblePreviewHeaderCell*>(this)->getAccessibleParent();
364 if (xAccParent.is())
366 uno::Reference<XAccessibleContext> xAccParentContext = xAccParent->getAccessibleContext();
367 uno::Reference<XAccessibleComponent> xAccParentComp (xAccParentContext, uno::UNO_QUERY);
368 if (xAccParentComp.is())
370 Rectangle aParentRect (VCLRectangle(xAccParentComp->getBounds()));
371 aCellRect.setX(aCellRect.getX() - aParentRect.getX());
372 aCellRect.setY(aCellRect.getY() - aParentRect.getY());
375 return aCellRect;
377 return Rectangle();
380 rtl::OUString SAL_CALL ScAccessiblePreviewHeaderCell::createAccessibleDescription() throw(uno::RuntimeException)
382 rtl::OUString sDescription = String(ScResId(STR_ACC_HEADERCELL_DESCR));
383 return sDescription;
386 rtl::OUString SAL_CALL ScAccessiblePreviewHeaderCell::createAccessibleName() throw(uno::RuntimeException)
388 rtl::OUString sName = String(ScResId(STR_ACC_HEADERCELL_NAME));
390 if ( mbColumnHeader )
392 if ( mbRowHeader )
394 //! name for corner cell?
396 // sName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Column/Row Header"));
398 else
400 // name of column header
401 sName += ScColToAlpha( maCellPos.Col() );
404 else
406 // name of row header
407 sName += rtl::OUString::valueOf( (sal_Int32) ( maCellPos.Row() + 1 ) );
410 return sName;
413 sal_Bool ScAccessiblePreviewHeaderCell::IsDefunc( const uno::Reference<XAccessibleStateSet>& rxParentStates )
415 return ScAccessibleContextBase::IsDefunc() || (mpViewShell == NULL) || !getAccessibleParent().is() ||
416 (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
419 void ScAccessiblePreviewHeaderCell::CreateTextHelper()
421 if (!mpTextHelper)
423 ::std::auto_ptr < ScAccessibleTextData > pAccessiblePreviewHeaderCellTextData
424 (new ScAccessiblePreviewHeaderCellTextData(mpViewShell, String(getAccessibleName()), maCellPos, mbColumnHeader, mbRowHeader));
425 ::std::auto_ptr< SvxEditSource > pEditSource (new ScAccessibilityEditSource(pAccessiblePreviewHeaderCellTextData));
427 mpTextHelper = new ::accessibility::AccessibleTextHelper(pEditSource );
428 mpTextHelper->SetEventSource(this);
432 void ScAccessiblePreviewHeaderCell::FillTableInfo() const
434 if ( mpViewShell && !mpTableInfo )
436 Size aOutputSize;
437 Window* pWindow = mpViewShell->GetWindow();
438 if ( pWindow )
439 aOutputSize = pWindow->GetOutputSizePixel();
440 Point aPoint;
441 Rectangle aVisRect( aPoint, aOutputSize );
443 mpTableInfo = new ScPreviewTableInfo;
444 mpViewShell->GetLocationData().GetTableInfo( aVisRect, *mpTableInfo );