LibreOffice Module sc (master)  1
AccessiblePreviewHeaderCell.cxx
Go to the documentation of this file.
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 <sal/config.h>
21 
22 #include <tools/gen.hxx>
23 #include <AccessibleText.hxx>
24 #include <editsrc.hxx>
27 #include <prevwsh.hxx>
28 #include <prevloc.hxx>
29 #include <strings.hxx>
30 
31 #include <com/sun/star/accessibility/AccessibleRole.hpp>
32 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
33 
34 #include <vcl/window.hxx>
35 #include <vcl/svapp.hxx>
36 #include <svl/hint.hxx>
38 #include <comphelper/sequence.hxx>
40 
41 #ifdef indices
42 #undef indices
43 #endif
44 
45 #ifdef extents
46 #undef extents
47 #endif
48 
49 using namespace ::com::sun::star;
50 using namespace ::com::sun::star::accessibility;
51 
52 //===== internal ============================================================
53 
54 ScAccessiblePreviewHeaderCell::ScAccessiblePreviewHeaderCell( const css::uno::Reference<css::accessibility::XAccessible>& rxParent,
55  ScPreviewShell* pViewShell,
56  const ScAddress& rCellPos, bool bIsColHdr, bool bIsRowHdr,
57  sal_Int32 nIndex ) :
58  ScAccessibleContextBase( rxParent, AccessibleRole::TABLE_CELL ),
59  mpViewShell( pViewShell ),
60  mpTextHelper( nullptr ),
61  mnIndex( nIndex ),
62  maCellPos( rCellPos ),
63  mbColumnHeader( bIsColHdr ),
64  mbRowHeader( bIsRowHdr )
65 {
66  if (mpViewShell)
68 }
69 
71 {
72  if (mpViewShell)
74 }
75 
77 {
78  SolarMutexGuard aGuard;
79  if (mpViewShell)
80  {
82  mpViewShell = nullptr;
83  }
84 
85  mpTableInfo.reset();
86 
88 }
89 
90 //===== SfxListener =====================================================
91 
93 {
94  const SfxHintId nId = rHint.GetId();
95  if (nId == SfxHintId::ScAccVisAreaChanged)
96  {
97  if (mpTextHelper)
99  }
100  else if ( nId == SfxHintId::DataChanged )
101  {
102  // column / row layout may change with any document change,
103  // so it must be invalidated
104  mpTableInfo.reset();
105  }
106 
108 }
109 
110 //===== XInterface =====================================================
111 
113 {
115  return aAny.hasValue() ? aAny : ScAccessibleContextBase::queryInterface(rType);
116 }
117 
119  throw ()
120 {
122 }
123 
125  throw ()
126 {
128 }
129 
130 //===== XAccessibleValue ================================================
131 
133 {
134  SolarMutexGuard aGuard;
135  IsObjectValid();
136 
137  double fValue(0.0);
138  if (mbColumnHeader)
139  fValue = maCellPos.Col();
140  else
141  fValue = maCellPos.Row();
142 
143  return uno::Any(fValue);
144 }
145 
147 {
148  // it is not possible to set a value
149  return false;
150 }
151 
153 {
154  SolarMutexGuard aGuard;
155  IsObjectValid();
156 
157  double fValue(0.0);
159  if (mbColumnHeader)
160  fValue = rDoc.MaxCol();
161  else
162  fValue = rDoc.MaxRow();
163  return uno::Any(fValue);
164 }
165 
167 {
168  return uno::Any(0.0);
169 }
170 
171 //===== XAccessibleComponent ============================================
172 
173 uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleAtPoint( const awt::Point& rPoint )
174 {
175  uno::Reference<XAccessible> xRet;
176  if (containsPoint(rPoint))
177  {
178  SolarMutexGuard aGuard;
179  IsObjectValid();
180 
181  if(!mpTextHelper)
183 
184  xRet = mpTextHelper->GetAt(rPoint);
185  }
186 
187  return xRet;
188 }
189 
191 {
192  SolarMutexGuard aGuard;
193  IsObjectValid();
194  if (getAccessibleParent().is())
195  {
196  uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
197  if (xAccessibleComponent.is())
198  xAccessibleComponent->grabFocus();
199  }
200 }
201 
202 //===== XAccessibleContext ==============================================
203 
205 {
206  SolarMutexGuard aGuard;
207  IsObjectValid();
208  if (!mpTextHelper)
210  return mpTextHelper->GetChildCount();
211 }
212 
213 uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleChild(sal_Int32 nIndex)
214 {
215  SolarMutexGuard aGuard;
216  IsObjectValid();
217  if (!mpTextHelper)
219  return mpTextHelper->GetChild(nIndex);
220 }
221 
223 {
224  return mnIndex;
225 }
226 
227 uno::Reference<XAccessibleStateSet> SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleStateSet()
228 {
229  SolarMutexGuard aGuard;
230 
231  uno::Reference<XAccessibleStateSet> xParentStates;
232  if (getAccessibleParent().is())
233  {
234  uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
235  xParentStates = xParentContext->getAccessibleStateSet();
236  }
238  if (IsDefunc(xParentStates))
239  pStateSet->AddState(AccessibleStateType::DEFUNC);
240  else
241  {
242  pStateSet->AddState(AccessibleStateType::ENABLED);
243  pStateSet->AddState(AccessibleStateType::MULTI_LINE);
244  if (isShowing())
245  pStateSet->AddState(AccessibleStateType::SHOWING);
246  pStateSet->AddState(AccessibleStateType::TRANSIENT);
247  if (isVisible())
248  pStateSet->AddState(AccessibleStateType::VISIBLE);
249  }
250  return pStateSet;
251 }
252 
253 //===== XServiceInfo ====================================================
254 
256 {
257  return "ScAccessiblePreviewHeaderCell";
258 }
259 
261 {
262  uno::Sequence< OUString > aSequence = ScAccessibleContextBase::getSupportedServiceNames();
263  sal_Int32 nOldSize(aSequence.getLength());
264  aSequence.realloc(nOldSize + 1);
265 
266  aSequence[nOldSize] = "com.sun.star.table.AccessibleCellView";
267 
268  return aSequence;
269 }
270 
271 //===== XTypeProvider =======================================================
272 
273 uno::Sequence< uno::Type > SAL_CALL ScAccessiblePreviewHeaderCell::getTypes()
274 {
276 }
277 
278 uno::Sequence<sal_Int8> SAL_CALL
280 {
281  return css::uno::Sequence<sal_Int8>();
282 }
283 
284 //==== internal =========================================================
285 
287 {
288  tools::Rectangle aCellRect;
289 
290  FillTableInfo();
291 
292  if (mpTableInfo)
293  {
294  const ScPreviewColRowInfo& rColInfo = mpTableInfo->GetColInfo()[maCellPos.Col()];
295  const ScPreviewColRowInfo& rRowInfo = mpTableInfo->GetRowInfo()[maCellPos.Row()];
296 
297  aCellRect = tools::Rectangle( rColInfo.nPixelStart, rRowInfo.nPixelStart, rColInfo.nPixelEnd, rRowInfo.nPixelEnd );
298  }
299 
300  if (mpViewShell)
301  {
302  vcl::Window* pWindow = mpViewShell->GetWindow();
303  if (pWindow)
304  {
305  tools::Rectangle aRect = pWindow->GetWindowExtentsRelative(nullptr);
306  aCellRect.setX(aCellRect.getX() + aRect.getX());
307  aCellRect.setY(aCellRect.getY() + aRect.getY());
308  }
309  }
310  return aCellRect;
311 }
312 
314 {
315  FillTableInfo();
316 
317  if (mpTableInfo)
318  {
319  const ScPreviewColRowInfo& rColInfo = mpTableInfo->GetColInfo()[maCellPos.Col()];
320  const ScPreviewColRowInfo& rRowInfo = mpTableInfo->GetRowInfo()[maCellPos.Row()];
321 
322  tools::Rectangle aCellRect( rColInfo.nPixelStart, rRowInfo.nPixelStart, rColInfo.nPixelEnd, rRowInfo.nPixelEnd );
323  uno::Reference<XAccessible> xAccParent = const_cast<ScAccessiblePreviewHeaderCell*>(this)->getAccessibleParent();
324  if (xAccParent.is())
325  {
326  uno::Reference<XAccessibleContext> xAccParentContext = xAccParent->getAccessibleContext();
327  uno::Reference<XAccessibleComponent> xAccParentComp (xAccParentContext, uno::UNO_QUERY);
328  if (xAccParentComp.is())
329  {
330  tools::Rectangle aParentRect (VCLRectangle(xAccParentComp->getBounds()));
331  aCellRect.setX(aCellRect.getX() - aParentRect.getX());
332  aCellRect.setY(aCellRect.getY() - aParentRect.getY());
333  }
334  }
335  return aCellRect;
336  }
337  return tools::Rectangle();
338 }
339 
341 {
343 }
344 
346 {
347  OUString sName = STR_ACC_HEADERCELL_NAME;
348 
349  if ( mbColumnHeader )
350  {
351  if ( mbRowHeader )
352  {
354 
355 // sName = "Column/Row Header";
356  }
357  else
358  {
359  // name of column header
360  sName += ScColToAlpha( maCellPos.Col() );
361  }
362  }
363  else
364  {
365  // name of row header
366  sName += OUString::number( ( maCellPos.Row() + 1 ) );
367  }
368 
369  return sName;
370 }
371 
372 bool ScAccessiblePreviewHeaderCell::IsDefunc( const uno::Reference<XAccessibleStateSet>& rxParentStates )
373 {
374  return ScAccessibleContextBase::IsDefunc() || (mpViewShell == nullptr) || !getAccessibleParent().is() ||
375  (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
376 }
377 
379 {
380  if (!mpTextHelper)
381  {
382  mpTextHelper = new ::accessibility::AccessibleTextHelper(
383  std::make_unique<ScAccessibilityEditSource>(
384  std::make_unique<ScAccessiblePreviewHeaderCellTextData>(
388  }
389 }
390 
392 {
393  if ( mpViewShell && !mpTableInfo )
394  {
395  Size aOutputSize;
396  vcl::Window* pWindow = mpViewShell->GetWindow();
397  if ( pWindow )
398  aOutputSize = pWindow->GetOutputSizePixel();
399  tools::Rectangle aVisRect( Point(), aOutputSize );
400 
401  mpTableInfo.reset( new ScPreviewTableInfo );
403  }
404 }
405 
406 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual OUString createAccessibleDescription() override
Return this object's description.
const ScPreviewLocationData & GetLocationData()
Definition: prevwsh.cxx:1177
virtual void SAL_CALL acquire() override
void AddAccessibilityObject(SfxListener &rObject)
Definition: prevwsh.cxx:1148
SfxHintId
bool hasValue()
virtual void SAL_CALL disposing() override
SCROW Row() const
Definition: address.hxx:262
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
Returns an implementation id.
css::uno::Reference< css::accessibility::XAccessible > GetAt(const css::awt::Point &aPoint)
virtual css::uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet() override
Return the set of current states.
void ScColToAlpha(OUStringBuffer &rBuf, SCCOL nCol)
append alpha representation of column to buffer
Definition: address.cxx:1921
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Returns a list of all supported services.
sal_Int16 nId
virtual tools::Rectangle GetBoundingBoxOnScreen() const override
Return the object's current bounding box relative to the desktop.
virtual css::uno::Any SAL_CALL getMaximumValue() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override
Return a reference to the parent.
virtual OUString SAL_CALL getAccessibleName() override
Return the object's current name.
virtual void SAL_CALL release() override
long getY() const
virtual sal_Bool SAL_CALL containsPoint(const css::awt::Point &rPoint) override
===== XAccessibleComponent ============================================
SfxHintId GetId() const
virtual sal_Int32 SAL_CALL getAccessibleChildCount() override
===== XAccessibleContext ==============================================
virtual css::uno::Any SAL_CALL getMinimumValue() override
virtual OUString SAL_CALL getImplementationName() override
===== XServiceInfo ====================================================
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
===== XTypeProvider ===================================================
virtual OUString createAccessibleName() override
Return the object's current name.
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:873
virtual sal_Int32 SAL_CALL getAccessibleIndexInParent() override
Return this objects index among the parents children.
#define STR_ACC_HEADERCELL_DESCR
Definition: strings.hxx:19
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
===== SfxListener =====================================================
long getX() const
const char * sName
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Returns a list of all supported services.
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:872
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) override
===== XInterface =====================================================
void setY(long y)
ScAccessiblePreviewHeaderCell(const css::uno::Reference< css::accessibility::XAccessible > &rxParent, ScPreviewShell *pViewShell, const ScAddress &rCellPos, bool bIsColHdr, bool bIsRowHdr, sal_Int32 nIndex)
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
===== XTypeProvider ===================================================
virtual tools::Rectangle GetBoundingBox() const override
Return the object's current bounding box relative to the parent object.
std::unique_ptr< ScPreviewTableInfo > mpTableInfo
inline::tools::Rectangle VCLRectangle(const css::awt::Rectangle &rAWTRect)
void SetEventSource(const css::uno::Reference< css::accessibility::XAccessible > &rInterface)
unsigned char sal_Bool
Size GetOutputSizePixel() const
virtual void SAL_CALL grabFocus() override
#define STR_ACC_HEADERCELL_NAME
Definition: strings.hxx:18
virtual void SAL_CALL acquire() override
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &...rSn)
virtual void SAL_CALL release() override
SCCOL Col() const
Definition: address.hxx:267
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) SAL_OVERRIDE
virtual sal_Bool SAL_CALL setCurrentValue(const css::uno::Any &aNumber) override
virtual void SAL_CALL disposing() override
void RemoveAccessibilityObject(SfxListener &rObject)
Definition: prevwsh.cxx:1156
accessibility::AccessibleTextHelper * mpTextHelper
virtual css::uno::Any SAL_CALL getCurrentValue() override
ScDocument & GetDocument()
Definition: prevwsh.cxx:1182
vcl::Window * GetWindow() const
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point &aPoint) override
void setX(long x)
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int32 i) override
Return the specified child or NULL if index is invalid.
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) override
===== XInterface =====================================================
int mnIndex
void AddState(sal_Int16 aState)
void GetTableInfo(const tools::Rectangle &rVisiblePixel, ScPreviewTableInfo &rInfo) const
Definition: prevloc.cxx:444
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() SAL_OVERRIDE
tools::Rectangle GetWindowExtentsRelative(vcl::Window *pRelativeWindow) const
css::uno::Reference< css::accessibility::XAccessible > GetChild(sal_Int32 i)
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
===== SfxListener =====================================================
virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext() override
===== XAccessible =====================================================