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 #include <comphelper/sequence.hxx>
34 
35 #include <vcl/window.hxx>
36 #include <vcl/svapp.hxx>
37 #include <svl/hint.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  noexcept
119 {
121 }
122 
124  noexcept
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 
171 {
172  // value can't be changed, s. 'setCurrentValue'
173  return uno::Any();
174 }
175 
176 //===== XAccessibleComponent ============================================
177 
178 uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleAtPoint( const awt::Point& rPoint )
179 {
180  uno::Reference<XAccessible> xRet;
181  if (containsPoint(rPoint))
182  {
183  SolarMutexGuard aGuard;
184  IsObjectValid();
185 
186  if(!mxTextHelper)
188 
189  xRet = mxTextHelper->GetAt(rPoint);
190  }
191 
192  return xRet;
193 }
194 
196 {
197  SolarMutexGuard aGuard;
198  IsObjectValid();
199  if (getAccessibleParent().is())
200  {
201  uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
202  if (xAccessibleComponent.is())
203  xAccessibleComponent->grabFocus();
204  }
205 }
206 
207 //===== XAccessibleContext ==============================================
208 
210 {
211  SolarMutexGuard aGuard;
212  IsObjectValid();
213  if (!mxTextHelper)
215  return mxTextHelper->GetChildCount();
216 }
217 
218 uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleChild(sal_Int32 nIndex)
219 {
220  SolarMutexGuard aGuard;
221  IsObjectValid();
222  if (!mxTextHelper)
224  return mxTextHelper->GetChild(nIndex);
225 }
226 
228 {
229  return mnIndex;
230 }
231 
232 uno::Reference<XAccessibleStateSet> SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleStateSet()
233 {
234  SolarMutexGuard aGuard;
235 
236  uno::Reference<XAccessibleStateSet> xParentStates;
237  if (getAccessibleParent().is())
238  {
239  uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
240  xParentStates = xParentContext->getAccessibleStateSet();
241  }
243  if (IsDefunc(xParentStates))
244  pStateSet->AddState(AccessibleStateType::DEFUNC);
245  else
246  {
247  pStateSet->AddState(AccessibleStateType::ENABLED);
248  pStateSet->AddState(AccessibleStateType::MULTI_LINE);
249  if (isShowing())
250  pStateSet->AddState(AccessibleStateType::SHOWING);
251  pStateSet->AddState(AccessibleStateType::TRANSIENT);
252  if (isVisible())
253  pStateSet->AddState(AccessibleStateType::VISIBLE);
254  }
255  return pStateSet;
256 }
257 
258 //===== XServiceInfo ====================================================
259 
261 {
262  return "ScAccessiblePreviewHeaderCell";
263 }
264 
266 {
267  const css::uno::Sequence<OUString> vals { "com.sun.star.table.AccessibleCellView" };
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.Move(aRect.Left(), aRect.Top());
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.Move(-aParentRect.Left(), -aParentRect.Top());
331  }
332  }
333  return aCellRect;
334  }
335  return tools::Rectangle();
336 }
337 
339 {
341 }
342 
344 {
345  OUString sName = STR_ACC_HEADERCELL_NAME;
346 
347  if ( mbColumnHeader )
348  {
349  if ( mbRowHeader )
350  {
352 
353 // sName = "Column/Row Header";
354  }
355  else
356  {
357  // name of column header
358  sName += ScColToAlpha( maCellPos.Col() );
359  }
360  }
361  else
362  {
363  // name of row header
364  sName += OUString::number( maCellPos.Row() + 1 );
365  }
366 
367  return sName;
368 }
369 
370 bool ScAccessiblePreviewHeaderCell::IsDefunc( const uno::Reference<XAccessibleStateSet>& rxParentStates )
371 {
372  return ScAccessibleContextBase::IsDefunc() || (mpViewShell == nullptr) || !getAccessibleParent().is() ||
373  (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
374 }
375 
377 {
378  if (!mxTextHelper)
379  {
380  mxTextHelper.reset( new ::accessibility::AccessibleTextHelper(
381  std::make_unique<ScAccessibilityEditSource>(
382  std::make_unique<ScAccessiblePreviewHeaderCellTextData>(
385  mxTextHelper->SetEventSource(this);
386  }
387 }
388 
390 {
391  if ( mpViewShell && !mpTableInfo )
392  {
393  Size aOutputSize;
394  vcl::Window* pWindow = mpViewShell->GetWindow();
395  if ( pWindow )
396  aOutputSize = pWindow->GetOutputSizePixel();
397  tools::Rectangle aVisRect( Point(), aOutputSize );
398 
399  mpTableInfo.reset( new ScPreviewTableInfo );
401  }
402 }
403 
404 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual OUString createAccessibleDescription() override
Return this object's description.
const ScPreviewLocationData & GetLocationData()
Definition: prevwsh.cxx:1178
void AddAccessibilityObject(SfxListener &rObject)
Definition: prevwsh.cxx:1149
SfxHintId
bool hasValue()
virtual void SAL_CALL disposing() override
SCROW Row() const
Definition: address.hxx:261
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
Returns an implementation id.
tools::Long nPixelStart
Definition: prevloc.hxx:47
constexpr tools::Long Left() const
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:1926
virtual css::uno::Any SAL_CALL getMinimumIncrement() override
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 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:872
virtual sal_Int32 SAL_CALL getAccessibleIndexInParent() override
Return this objects index among the parents children.
virtual void SAL_CALL acquire() noexcept override
#define STR_ACC_HEADERCELL_DESCR
Definition: strings.hxx:19
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
===== SfxListener =====================================================
tools::Rectangle GetWindowExtentsRelative(const vcl::Window *pRelativeWindow) 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:871
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
virtual void SAL_CALL acquire() noexcept override
constexpr tools::Long Top() const
tools::Long nPixelEnd
Definition: prevloc.hxx:48
virtual void SAL_CALL release() noexcept override
virtual void SAL_CALL grabFocus() override
#define STR_ACC_HEADERCELL_NAME
Definition: strings.hxx:18
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &...rSn)
SCCOL Col() const
Definition: address.hxx:266
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 release() noexcept override
virtual void SAL_CALL disposing() override
void RemoveAccessibilityObject(SfxListener &rObject)
Definition: prevwsh.cxx:1157
virtual css::uno::Any SAL_CALL getCurrentValue() override
ScDocument & GetDocument()
Definition: prevwsh.cxx:1183
vcl::Window * GetWindow() const
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point &aPoint) override
Size GetOutputSizePixel() const
void Move(tools::Long nHorzMoveDelta, tools::Long nVertMoveDelta)
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 GetTableInfo(const tools::Rectangle &rVisiblePixel, ScPreviewTableInfo &rInfo) const
Definition: prevloc.cxx:445
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 =====================================================