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  mnIndex( nIndex ),
61  maCellPos( rCellPos ),
62  mbColumnHeader( bIsColHdr ),
63  mbRowHeader( bIsRowHdr )
64 {
65  if (mpViewShell)
67 }
68 
70 {
71  if (mpViewShell)
73 }
74 
76 {
77  SolarMutexGuard aGuard;
78  if (mpViewShell)
79  {
81  mpViewShell = nullptr;
82  }
83 
84  mpTableInfo.reset();
85 
87 }
88 
89 //===== SfxListener =====================================================
90 
92 {
93  const SfxHintId nId = rHint.GetId();
94  if (nId == SfxHintId::ScAccVisAreaChanged)
95  {
96  if (mxTextHelper)
97  mxTextHelper->UpdateChildren();
98  }
99  else if ( nId == SfxHintId::DataChanged )
100  {
101  // column / row layout may change with any document change,
102  // so it must be invalidated
103  mpTableInfo.reset();
104  }
105 
107 }
108 
109 //===== XInterface =====================================================
110 
112 {
114  return aAny.hasValue() ? aAny : ScAccessibleContextBase::queryInterface(rType);
115 }
116 
118  throw ()
119 {
121 }
122 
124  throw ()
125 {
127 }
128 
129 //===== XAccessibleValue ================================================
130 
132 {
133  SolarMutexGuard aGuard;
134  IsObjectValid();
135 
136  double fValue(0.0);
137  if (mbColumnHeader)
138  fValue = maCellPos.Col();
139  else
140  fValue = maCellPos.Row();
141 
142  return uno::Any(fValue);
143 }
144 
146 {
147  // it is not possible to set a value
148  return false;
149 }
150 
152 {
153  SolarMutexGuard aGuard;
154  IsObjectValid();
155 
156  double fValue(0.0);
158  if (mbColumnHeader)
159  fValue = rDoc.MaxCol();
160  else
161  fValue = rDoc.MaxRow();
162  return uno::Any(fValue);
163 }
164 
166 {
167  return uno::Any(0.0);
168 }
169 
170 //===== XAccessibleComponent ============================================
171 
172 uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleAtPoint( const awt::Point& rPoint )
173 {
174  uno::Reference<XAccessible> xRet;
175  if (containsPoint(rPoint))
176  {
177  SolarMutexGuard aGuard;
178  IsObjectValid();
179 
180  if(!mxTextHelper)
182 
183  xRet = mxTextHelper->GetAt(rPoint);
184  }
185 
186  return xRet;
187 }
188 
190 {
191  SolarMutexGuard aGuard;
192  IsObjectValid();
193  if (getAccessibleParent().is())
194  {
195  uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
196  if (xAccessibleComponent.is())
197  xAccessibleComponent->grabFocus();
198  }
199 }
200 
201 //===== XAccessibleContext ==============================================
202 
204 {
205  SolarMutexGuard aGuard;
206  IsObjectValid();
207  if (!mxTextHelper)
209  return mxTextHelper->GetChildCount();
210 }
211 
212 uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleChild(sal_Int32 nIndex)
213 {
214  SolarMutexGuard aGuard;
215  IsObjectValid();
216  if (!mxTextHelper)
218  return mxTextHelper->GetChild(nIndex);
219 }
220 
222 {
223  return mnIndex;
224 }
225 
226 uno::Reference<XAccessibleStateSet> SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleStateSet()
227 {
228  SolarMutexGuard aGuard;
229 
230  uno::Reference<XAccessibleStateSet> xParentStates;
231  if (getAccessibleParent().is())
232  {
233  uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
234  xParentStates = xParentContext->getAccessibleStateSet();
235  }
237  if (IsDefunc(xParentStates))
238  pStateSet->AddState(AccessibleStateType::DEFUNC);
239  else
240  {
241  pStateSet->AddState(AccessibleStateType::ENABLED);
242  pStateSet->AddState(AccessibleStateType::MULTI_LINE);
243  if (isShowing())
244  pStateSet->AddState(AccessibleStateType::SHOWING);
245  pStateSet->AddState(AccessibleStateType::TRANSIENT);
246  if (isVisible())
247  pStateSet->AddState(AccessibleStateType::VISIBLE);
248  }
249  return pStateSet;
250 }
251 
252 //===== XServiceInfo ====================================================
253 
255 {
256  return "ScAccessiblePreviewHeaderCell";
257 }
258 
260 {
261  uno::Sequence< OUString > aSequence = ScAccessibleContextBase::getSupportedServiceNames();
262  sal_Int32 nOldSize(aSequence.getLength());
263  aSequence.realloc(nOldSize + 1);
264 
265  aSequence[nOldSize] = "com.sun.star.table.AccessibleCellView";
266 
267  return aSequence;
268 }
269 
270 //===== XTypeProvider =======================================================
271 
272 uno::Sequence< uno::Type > SAL_CALL ScAccessiblePreviewHeaderCell::getTypes()
273 {
275 }
276 
277 uno::Sequence<sal_Int8> SAL_CALL
279 {
280  return css::uno::Sequence<sal_Int8>();
281 }
282 
283 //==== internal =========================================================
284 
286 {
287  tools::Rectangle aCellRect;
288 
289  FillTableInfo();
290 
291  if (mpTableInfo)
292  {
293  const ScPreviewColRowInfo& rColInfo = mpTableInfo->GetColInfo()[maCellPos.Col()];
294  const ScPreviewColRowInfo& rRowInfo = mpTableInfo->GetRowInfo()[maCellPos.Row()];
295 
296  aCellRect = tools::Rectangle( rColInfo.nPixelStart, rRowInfo.nPixelStart, rColInfo.nPixelEnd, rRowInfo.nPixelEnd );
297  }
298 
299  if (mpViewShell)
300  {
301  vcl::Window* pWindow = mpViewShell->GetWindow();
302  if (pWindow)
303  {
304  tools::Rectangle aRect = pWindow->GetWindowExtentsRelative(nullptr);
305  aCellRect.setX(aCellRect.getX() + aRect.getX());
306  aCellRect.setY(aCellRect.getY() + aRect.getY());
307  }
308  }
309  return aCellRect;
310 }
311 
313 {
314  FillTableInfo();
315 
316  if (mpTableInfo)
317  {
318  const ScPreviewColRowInfo& rColInfo = mpTableInfo->GetColInfo()[maCellPos.Col()];
319  const ScPreviewColRowInfo& rRowInfo = mpTableInfo->GetRowInfo()[maCellPos.Row()];
320 
321  tools::Rectangle aCellRect( rColInfo.nPixelStart, rRowInfo.nPixelStart, rColInfo.nPixelEnd, rRowInfo.nPixelEnd );
322  uno::Reference<XAccessible> xAccParent = const_cast<ScAccessiblePreviewHeaderCell*>(this)->getAccessibleParent();
323  if (xAccParent.is())
324  {
325  uno::Reference<XAccessibleContext> xAccParentContext = xAccParent->getAccessibleContext();
326  uno::Reference<XAccessibleComponent> xAccParentComp (xAccParentContext, uno::UNO_QUERY);
327  if (xAccParentComp.is())
328  {
329  tools::Rectangle aParentRect (VCLRectangle(xAccParentComp->getBounds()));
330  aCellRect.setX(aCellRect.getX() - aParentRect.getX());
331  aCellRect.setY(aCellRect.getY() - aParentRect.getY());
332  }
333  }
334  return aCellRect;
335  }
336  return tools::Rectangle();
337 }
338 
340 {
342 }
343 
345 {
346  OUString sName = STR_ACC_HEADERCELL_NAME;
347 
348  if ( mbColumnHeader )
349  {
350  if ( mbRowHeader )
351  {
353 
354 // sName = "Column/Row Header";
355  }
356  else
357  {
358  // name of column header
359  sName += ScColToAlpha( maCellPos.Col() );
360  }
361  }
362  else
363  {
364  // name of row header
365  sName += OUString::number( ( maCellPos.Row() + 1 ) );
366  }
367 
368  return sName;
369 }
370 
371 bool ScAccessiblePreviewHeaderCell::IsDefunc( const uno::Reference<XAccessibleStateSet>& rxParentStates )
372 {
373  return ScAccessibleContextBase::IsDefunc() || (mpViewShell == nullptr) || !getAccessibleParent().is() ||
374  (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
375 }
376 
378 {
379  if (!mxTextHelper)
380  {
381  mxTextHelper.reset( new ::accessibility::AccessibleTextHelper(
382  std::make_unique<ScAccessibilityEditSource>(
383  std::make_unique<ScAccessiblePreviewHeaderCellTextData>(
386  mxTextHelper->SetEventSource(this);
387  }
388 }
389 
391 {
392  if ( mpViewShell && !mpTableInfo )
393  {
394  Size aOutputSize;
395  vcl::Window* pWindow = mpViewShell->GetWindow();
396  if ( pWindow )
397  aOutputSize = pWindow->GetOutputSizePixel();
398  tools::Rectangle aVisRect( Point(), aOutputSize );
399 
400  mpTableInfo.reset( new ScPreviewTableInfo );
402  }
403 }
404 
405 /* 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.
tools::Long nPixelStart
Definition: prevloc.hxx:48
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:1917
tools::Long getY() const
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
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 =====================================================
tools::Long getX() const
tools::Rectangle GetWindowExtentsRelative(const vcl::Window *pRelativeWindow) const
void setX(tools::Long x)
const char * sName
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Returns a list of all supported services.
void setY(tools::Long y)
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:872
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) override
===== XInterface =====================================================
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)
unsigned char sal_Bool
tools::Long nPixelEnd
Definition: prevloc.hxx:49
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
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
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
std::unique_ptr< accessibility::AccessibleTextHelper > mxTextHelper
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
===== SfxListener =====================================================
virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext() override
===== XAccessible =====================================================