Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "scitems.hxx"
30 : : #include <editeng/eeitem.hxx>
31 : : #include <tools/gen.hxx>
32 : : #include "AccessibleText.hxx"
33 : : #include "editsrc.hxx"
34 : : #include <svx/AccessibleTextHelper.hxx>
35 : : #include "AccessiblePreviewHeaderCell.hxx"
36 : : #include "AccessibilityHints.hxx"
37 : : #include "prevwsh.hxx"
38 : : #include "miscuno.hxx"
39 : : #include "prevloc.hxx"
40 : : #include "scresid.hxx"
41 : : #include "sc.hrc"
42 : :
43 : : #include <com/sun/star/accessibility/AccessibleRole.hpp>
44 : : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
45 : :
46 : : #include <vcl/window.hxx>
47 : : #include <vcl/svapp.hxx>
48 : : #include <svl/smplhint.hxx>
49 : : #include <unotools/accessiblestatesethelper.hxx>
50 : : #include <comphelper/sequence.hxx>
51 : : #include <comphelper/servicehelper.hxx>
52 : : #include <toolkit/helper/convert.hxx>
53 : :
54 : : using namespace ::com::sun::star;
55 : : using namespace ::com::sun::star::accessibility;
56 : :
57 : : //===== internal ============================================================
58 : :
59 : 14 : ScAccessiblePreviewHeaderCell::ScAccessiblePreviewHeaderCell( const ::com::sun::star::uno::Reference<
60 : : ::com::sun::star::accessibility::XAccessible>& rxParent,
61 : : ScPreviewShell* pViewShell,
62 : : const ScAddress& rCellPos, sal_Bool bIsColHdr, sal_Bool bIsRowHdr,
63 : : sal_Int32 nIndex ) :
64 : : ScAccessibleContextBase( rxParent, AccessibleRole::TABLE_CELL ),
65 : : mpViewShell( pViewShell ),
66 : : mpTextHelper( NULL ),
67 : : mnIndex( nIndex ),
68 : : maCellPos( rCellPos ),
69 : : mbColumnHeader( bIsColHdr ),
70 : : mbRowHeader( bIsRowHdr ),
71 : 14 : mpTableInfo( NULL )
72 : : {
73 [ + - ]: 14 : if (mpViewShell)
74 [ + - ]: 14 : mpViewShell->AddAccessibilityObject(*this);
75 : 14 : }
76 : :
77 : 3 : ScAccessiblePreviewHeaderCell::~ScAccessiblePreviewHeaderCell()
78 : : {
79 [ - + ]: 3 : if (mpViewShell)
80 [ # # ]: 0 : mpViewShell->RemoveAccessibilityObject(*this);
81 [ - + ]: 6 : }
82 : :
83 : 14 : void SAL_CALL ScAccessiblePreviewHeaderCell::disposing()
84 : : {
85 [ + - ]: 14 : SolarMutexGuard aGuard;
86 [ + - ]: 14 : if (mpViewShell)
87 : : {
88 [ + - ]: 14 : mpViewShell->RemoveAccessibilityObject(*this);
89 : 14 : mpViewShell = NULL;
90 : : }
91 : :
92 [ + + ]: 14 : if (mpTableInfo)
93 [ + - ][ + - ]: 10 : DELETEZ (mpTableInfo);
94 : :
95 [ + - ][ + - ]: 14 : ScAccessibleContextBase::disposing();
96 : 14 : }
97 : :
98 : : //===== SfxListener =====================================================
99 : :
100 : 14 : void ScAccessiblePreviewHeaderCell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
101 : : {
102 [ - + ]: 14 : if (rHint.ISA( SfxSimpleHint ))
103 : : {
104 : 0 : const SfxSimpleHint& rRef = (const SfxSimpleHint&)rHint;
105 : 0 : sal_uLong nId = rRef.GetId();
106 [ # # ]: 0 : if (nId == SC_HINT_ACC_VISAREACHANGED)
107 : : {
108 [ # # ]: 0 : if (mpTextHelper)
109 : 0 : mpTextHelper->UpdateChildren();
110 : : }
111 [ # # ]: 0 : else if ( nId == SFX_HINT_DATACHANGED )
112 : : {
113 : : // column / row layout may change with any document change,
114 : : // so it must be invalidated
115 [ # # ]: 0 : DELETEZ( mpTableInfo );
116 : : }
117 : : }
118 : :
119 : 14 : ScAccessibleContextBase::Notify(rBC, rHint);
120 : 14 : }
121 : :
122 : : //===== XInterface =====================================================
123 : :
124 : 57 : uno::Any SAL_CALL ScAccessiblePreviewHeaderCell::queryInterface( uno::Type const & rType )
125 : : throw (uno::RuntimeException)
126 : : {
127 [ + - ]: 57 : uno::Any aAny (ScAccessiblePreviewHeaderCellImpl::queryInterface(rType));
128 [ + + ][ + - ]: 57 : return aAny.hasValue() ? aAny : ScAccessibleContextBase::queryInterface(rType);
129 : : }
130 : :
131 : 349 : void SAL_CALL ScAccessiblePreviewHeaderCell::acquire()
132 : : throw ()
133 : : {
134 : 349 : ScAccessibleContextBase::acquire();
135 : 349 : }
136 : :
137 : 338 : void SAL_CALL ScAccessiblePreviewHeaderCell::release()
138 : : throw ()
139 : : {
140 : 338 : ScAccessibleContextBase::release();
141 : 338 : }
142 : :
143 : : //===== XAccessibleValue ================================================
144 : :
145 : 2 : uno::Any SAL_CALL ScAccessiblePreviewHeaderCell::getCurrentValue() throw (uno::RuntimeException)
146 : : {
147 [ + - ]: 2 : SolarMutexGuard aGuard;
148 [ + - ]: 2 : IsObjectValid();
149 : :
150 : 2 : double fValue(0.0);
151 [ + - ]: 2 : if (mbColumnHeader)
152 : 2 : fValue = maCellPos.Col();
153 : : else
154 : 0 : fValue = maCellPos.Row();
155 : :
156 : 2 : uno::Any aAny;
157 [ + - ]: 2 : aAny <<= fValue;
158 [ + - ]: 2 : return aAny;
159 : : }
160 : :
161 : 2 : sal_Bool SAL_CALL ScAccessiblePreviewHeaderCell::setCurrentValue( const uno::Any& /* aNumber */ )
162 : : throw (uno::RuntimeException)
163 : : {
164 : : // it is not possible to set a value
165 : 2 : return false;
166 : : }
167 : :
168 : 2 : uno::Any SAL_CALL ScAccessiblePreviewHeaderCell::getMaximumValue() throw (uno::RuntimeException)
169 : : {
170 [ + - ]: 2 : SolarMutexGuard aGuard;
171 [ + - ]: 2 : IsObjectValid();
172 : :
173 : 2 : double fValue(0.0);
174 [ + - ]: 2 : if (mbColumnHeader)
175 : 2 : fValue = MAXCOL;
176 : : else
177 : 0 : fValue = MAXROW;
178 : 2 : uno::Any aAny;
179 [ + - ]: 2 : aAny <<= fValue;
180 [ + - ]: 2 : return aAny;
181 : : }
182 : :
183 : 2 : uno::Any SAL_CALL ScAccessiblePreviewHeaderCell::getMinimumValue() throw (uno::RuntimeException)
184 : : {
185 : 2 : double fValue(0.0);
186 : 2 : uno::Any aAny;
187 [ + - ]: 2 : aAny <<= fValue;
188 : 2 : return aAny;
189 : : }
190 : :
191 : : //===== XAccessibleComponent ============================================
192 : :
193 : 2 : uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleAtPoint( const awt::Point& rPoint )
194 : : throw (uno::RuntimeException)
195 : : {
196 : 2 : uno::Reference<XAccessible> xRet;
197 [ + + ][ + - ]: 2 : if (containsPoint(rPoint))
198 : : {
199 [ + - ]: 1 : SolarMutexGuard aGuard;
200 [ + - ]: 1 : IsObjectValid();
201 : :
202 [ - + ]: 1 : if(!mpTextHelper)
203 [ # # ]: 0 : CreateTextHelper();
204 : :
205 [ + - ][ + - ]: 1 : xRet = mpTextHelper->GetAt(rPoint);
[ + - ]
206 : : }
207 : :
208 : 2 : return xRet;
209 : : }
210 : :
211 : 1 : void SAL_CALL ScAccessiblePreviewHeaderCell::grabFocus() throw (uno::RuntimeException)
212 : : {
213 [ + - ]: 1 : SolarMutexGuard aGuard;
214 [ + - ]: 1 : IsObjectValid();
215 [ + - ][ + - ]: 1 : if (getAccessibleParent().is())
216 : : {
217 [ + - ][ + - ]: 1 : uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
[ + - ][ + - ]
218 [ + - ]: 1 : if (xAccessibleComponent.is())
219 [ + - ][ + - ]: 1 : xAccessibleComponent->grabFocus();
220 [ + - ]: 1 : }
221 : 1 : }
222 : :
223 : : //===== XAccessibleContext ==============================================
224 : :
225 : 26 : sal_Int32 SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleChildCount() throw(uno::RuntimeException)
226 : : {
227 [ + - ]: 26 : SolarMutexGuard aGuard;
228 [ + - ]: 26 : IsObjectValid();
229 [ + + ]: 26 : if (!mpTextHelper)
230 [ + - ]: 11 : CreateTextHelper();
231 [ + - ][ + - ]: 26 : return mpTextHelper->GetChildCount();
232 : : }
233 : :
234 : 11 : uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleChild(sal_Int32 nIndex)
235 : : throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
236 : : {
237 [ + - ]: 11 : SolarMutexGuard aGuard;
238 [ + - ]: 11 : IsObjectValid();
239 [ - + ]: 11 : if (!mpTextHelper)
240 [ # # ]: 0 : CreateTextHelper();
241 [ + - ][ + - ]: 11 : return mpTextHelper->GetChild(nIndex);
242 : : }
243 : :
244 : 1 : sal_Int32 SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleIndexInParent() throw (uno::RuntimeException)
245 : : {
246 : 1 : return mnIndex;
247 : : }
248 : :
249 : 11 : uno::Reference<XAccessibleStateSet> SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleStateSet()
250 : : throw(uno::RuntimeException)
251 : : {
252 [ + - ]: 11 : SolarMutexGuard aGuard;
253 : :
254 : 11 : uno::Reference<XAccessibleStateSet> xParentStates;
255 [ + - ][ + - ]: 11 : if (getAccessibleParent().is())
256 : : {
257 [ + - ][ + - ]: 11 : uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
[ + - ]
258 [ + - ][ + - ]: 11 : xParentStates = xParentContext->getAccessibleStateSet();
[ + - ]
259 : : }
260 [ + - ]: 11 : utl::AccessibleStateSetHelper* pStateSet = new utl::AccessibleStateSetHelper();
261 [ + - ][ - + ]: 11 : if (IsDefunc(xParentStates))
262 [ # # ]: 0 : pStateSet->AddState(AccessibleStateType::DEFUNC);
263 : : else
264 : : {
265 [ + - ]: 11 : pStateSet->AddState(AccessibleStateType::ENABLED);
266 [ + - ]: 11 : pStateSet->AddState(AccessibleStateType::MULTI_LINE);
267 [ + - ][ - + ]: 11 : if (isShowing())
268 [ # # ]: 0 : pStateSet->AddState(AccessibleStateType::SHOWING);
269 [ + - ]: 11 : pStateSet->AddState(AccessibleStateType::TRANSIENT);
270 [ + - ][ + - ]: 11 : if (isVisible())
271 [ + - ]: 11 : pStateSet->AddState(AccessibleStateType::VISIBLE);
272 : : }
273 [ + - ][ + - ]: 11 : return pStateSet;
[ + - ]
274 : : }
275 : :
276 : : //===== XServiceInfo ====================================================
277 : :
278 : 5 : rtl::OUString SAL_CALL ScAccessiblePreviewHeaderCell::getImplementationName() throw(uno::RuntimeException)
279 : : {
280 : 5 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScAccessiblePreviewHeaderCell"));
281 : : }
282 : :
283 : 0 : uno::Sequence<rtl::OUString> SAL_CALL ScAccessiblePreviewHeaderCell::getSupportedServiceNames()
284 : : throw(uno::RuntimeException)
285 : : {
286 : 0 : uno::Sequence< ::rtl::OUString > aSequence = ScAccessibleContextBase::getSupportedServiceNames();
287 : 0 : sal_Int32 nOldSize(aSequence.getLength());
288 [ # # ]: 0 : aSequence.realloc(nOldSize + 1);
289 [ # # ]: 0 : ::rtl::OUString* pNames = aSequence.getArray();
290 : :
291 [ # # ]: 0 : pNames[nOldSize] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.table.AccessibleCellView"));
292 : :
293 : 0 : return aSequence;
294 : : }
295 : :
296 : : //===== XTypeProvider =======================================================
297 : :
298 : 0 : uno::Sequence< uno::Type > SAL_CALL ScAccessiblePreviewHeaderCell::getTypes()
299 : : throw (uno::RuntimeException)
300 : : {
301 [ # # ][ # # ]: 0 : return comphelper::concatSequences(ScAccessiblePreviewHeaderCellImpl::getTypes(), ScAccessibleContextBase::getTypes());
[ # # ]
302 : : }
303 : :
304 : : namespace
305 : : {
306 : : class theScAccessiblePreviewHeaderCellImplementationId : public rtl::Static< UnoTunnelIdInit, theScAccessiblePreviewHeaderCellImplementationId > {};
307 : : }
308 : :
309 : : uno::Sequence<sal_Int8> SAL_CALL
310 : 0 : ScAccessiblePreviewHeaderCell::getImplementationId(void)
311 : : throw (uno::RuntimeException)
312 : : {
313 : 0 : return theScAccessiblePreviewHeaderCellImplementationId::get().getSeq();
314 : : }
315 : :
316 : : //==== internal =========================================================
317 : :
318 : 1 : Rectangle ScAccessiblePreviewHeaderCell::GetBoundingBoxOnScreen() const throw (uno::RuntimeException)
319 : : {
320 : 1 : Rectangle aCellRect;
321 : :
322 : 1 : FillTableInfo();
323 : :
324 [ + - ]: 1 : if (mpTableInfo)
325 : : {
326 : 1 : const ScPreviewColRowInfo& rColInfo = mpTableInfo->GetColInfo()[maCellPos.Col()];
327 : 1 : const ScPreviewColRowInfo& rRowInfo = mpTableInfo->GetRowInfo()[maCellPos.Row()];
328 : :
329 : 1 : aCellRect = Rectangle( rColInfo.nPixelStart, rRowInfo.nPixelStart, rColInfo.nPixelEnd, rRowInfo.nPixelEnd );
330 : : }
331 : :
332 [ + - ]: 1 : if (mpViewShell)
333 : : {
334 : 1 : Window* pWindow = mpViewShell->GetWindow();
335 [ + - ]: 1 : if (pWindow)
336 : : {
337 [ + - ]: 1 : Rectangle aRect = pWindow->GetWindowExtentsRelative(NULL);
338 : 1 : aCellRect.setX(aCellRect.getX() + aRect.getX());
339 : 1 : aCellRect.setY(aCellRect.getY() + aRect.getY());
340 : : }
341 : : }
342 : 1 : return aCellRect;
343 : : }
344 : :
345 : 74 : Rectangle ScAccessiblePreviewHeaderCell::GetBoundingBox() const throw (uno::RuntimeException)
346 : : {
347 : 74 : FillTableInfo();
348 : :
349 [ + - ]: 74 : if (mpTableInfo)
350 : : {
351 : 74 : const ScPreviewColRowInfo& rColInfo = mpTableInfo->GetColInfo()[maCellPos.Col()];
352 : 74 : const ScPreviewColRowInfo& rRowInfo = mpTableInfo->GetRowInfo()[maCellPos.Row()];
353 : :
354 [ + - ]: 74 : Rectangle aCellRect( rColInfo.nPixelStart, rRowInfo.nPixelStart, rColInfo.nPixelEnd, rRowInfo.nPixelEnd );
355 [ + - ]: 74 : uno::Reference<XAccessible> xAccParent = const_cast<ScAccessiblePreviewHeaderCell*>(this)->getAccessibleParent();
356 [ + - ]: 74 : if (xAccParent.is())
357 : : {
358 [ + - ][ + - ]: 74 : uno::Reference<XAccessibleContext> xAccParentContext = xAccParent->getAccessibleContext();
359 [ + - ]: 74 : uno::Reference<XAccessibleComponent> xAccParentComp (xAccParentContext, uno::UNO_QUERY);
360 [ + - ]: 74 : if (xAccParentComp.is())
361 : : {
362 [ + - ][ + - ]: 74 : Rectangle aParentRect (VCLRectangle(xAccParentComp->getBounds()));
[ + - ]
363 : 74 : aCellRect.setX(aCellRect.getX() - aParentRect.getX());
364 : 74 : aCellRect.setY(aCellRect.getY() - aParentRect.getY());
365 : 74 : }
366 : : }
367 : 74 : return aCellRect;
368 : : }
369 : 74 : return Rectangle();
370 : : }
371 : :
372 : 21 : rtl::OUString SAL_CALL ScAccessiblePreviewHeaderCell::createAccessibleDescription() throw(uno::RuntimeException)
373 : : {
374 [ + - ][ + - ]: 21 : rtl::OUString sDescription = String(ScResId(STR_ACC_HEADERCELL_DESCR));
[ + - ]
375 : 21 : return sDescription;
376 : : }
377 : :
378 : 26 : rtl::OUString SAL_CALL ScAccessiblePreviewHeaderCell::createAccessibleName() throw(uno::RuntimeException)
379 : : {
380 [ + - ][ + - ]: 26 : rtl::OUString sName = String(ScResId(STR_ACC_HEADERCELL_NAME));
[ + - ]
381 : :
382 [ + + ]: 26 : if ( mbColumnHeader )
383 : : {
384 [ + + ]: 23 : if ( mbRowHeader )
385 : : {
386 : : //! name for corner cell?
387 : :
388 : : // sName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Column/Row Header"));
389 : : }
390 : : else
391 : : {
392 : : // name of column header
393 [ + - ][ + - ]: 3 : sName += ScColToAlpha( maCellPos.Col() );
[ + - ]
394 : : }
395 : : }
396 : : else
397 : : {
398 : : // name of row header
399 : 3 : sName += rtl::OUString::valueOf( (sal_Int32) ( maCellPos.Row() + 1 ) );
400 : : }
401 : :
402 : 26 : return sName;
403 : : }
404 : :
405 : 11 : sal_Bool ScAccessiblePreviewHeaderCell::IsDefunc( const uno::Reference<XAccessibleStateSet>& rxParentStates )
406 : : {
407 [ + - ][ + - ]: 33 : return ScAccessibleContextBase::IsDefunc() || (mpViewShell == NULL) || !getAccessibleParent().is() ||
[ # # ]
408 [ + - + - ]: 33 : (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
[ + - ][ + - ]
[ + - ][ - + ]
[ + - ]
409 : : }
410 : :
411 : 11 : void ScAccessiblePreviewHeaderCell::CreateTextHelper()
412 : : {
413 [ + - ]: 11 : if (!mpTextHelper)
414 : : {
415 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
416 : : ::std::auto_ptr < ScAccessibleTextData > pAccessiblePreviewHeaderCellTextData
417 [ + - ][ + - ]: 11 : (new ScAccessiblePreviewHeaderCellTextData(mpViewShell, String(getAccessibleName()), maCellPos, mbColumnHeader, mbRowHeader));
[ + - ][ + - ]
[ + - ]
418 [ + - ][ + - ]: 11 : ::std::auto_ptr< SvxEditSource > pEditSource (new ScAccessibilityEditSource(pAccessiblePreviewHeaderCellTextData));
[ + - ]
419 : : SAL_WNODEPRECATED_DECLARATIONS_POP
420 : :
421 [ + - ][ + - ]: 11 : mpTextHelper = new ::accessibility::AccessibleTextHelper(pEditSource );
[ + - ]
422 [ + - ][ + - ]: 11 : mpTextHelper->SetEventSource(this);
[ + - ][ + - ]
423 : : }
424 : 11 : }
425 : :
426 : 75 : void ScAccessiblePreviewHeaderCell::FillTableInfo() const
427 : : {
428 [ + - ][ + + ]: 75 : if ( mpViewShell && !mpTableInfo )
429 : : {
430 : 10 : Size aOutputSize;
431 : 10 : Window* pWindow = mpViewShell->GetWindow();
432 [ + - ]: 10 : if ( pWindow )
433 : 10 : aOutputSize = pWindow->GetOutputSizePixel();
434 : 10 : Point aPoint;
435 [ + - ]: 10 : Rectangle aVisRect( aPoint, aOutputSize );
436 : :
437 [ + - ][ + - ]: 10 : mpTableInfo = new ScPreviewTableInfo;
438 [ + - ][ + - ]: 10 : mpViewShell->GetLocationData().GetTableInfo( aVisRect, *mpTableInfo );
439 : : }
440 : 75 : }
441 : :
442 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|