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