LibreOffice Module sc (master)  1
AccessiblePreviewCell.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 <scitems.hxx>
23 #include <tools/gen.hxx>
24 #include <AccessibleText.hxx>
25 #include <editsrc.hxx>
27 #include <prevwsh.hxx>
28 #include <prevloc.hxx>
29 #include <document.hxx>
32 #include <editeng/brushitem.hxx>
33 #include <vcl/window.hxx>
34 #include <vcl/svapp.hxx>
36 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
37 
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::accessibility;
40 
41 //===== internal ============================================================
42 
43 ScAccessiblePreviewCell::ScAccessiblePreviewCell( const css::uno::Reference<css::accessibility::XAccessible>& rxParent,
44  ScPreviewShell* pViewShell,
45  const ScAddress& rCellAddress,
46  sal_Int32 nIndex ) :
47  ScAccessibleCellBase( rxParent, ( pViewShell ? &pViewShell->GetDocument() : nullptr ), rCellAddress, nIndex ),
48  mpViewShell( pViewShell )
49 {
50  if (mpViewShell)
52 }
53 
55 {
56  if (!ScAccessibleContextBase::IsDefunc() && !rBHelper.bInDispose)
57  {
58  // increment refcount to prevent double call off dtor
59  osl_atomic_increment( &m_refCount );
60  // call dispose to inform object which have a weak reference to this object
61  dispose();
62  }
63 }
64 
66 {
67  SolarMutexGuard aGuard;
68  if (mpViewShell)
69  {
71  mpViewShell = nullptr;
72  }
73 
74  mpTextHelper.reset();
75 
77 }
78 
80 {
81  if (rHint.GetId() == SfxHintId::ScAccVisAreaChanged)
82  {
83  if (mpTextHelper)
84  mpTextHelper->UpdateChildren();
85  }
86 
88 }
89 
90 //===== XAccessibleComponent ============================================
91 
92 uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewCell::getAccessibleAtPoint( const awt::Point& rPoint )
93 {
94  uno::Reference<XAccessible> xRet;
95  if (containsPoint(rPoint))
96  {
97  SolarMutexGuard aGuard;
98  IsObjectValid();
99 
100  if(!mpTextHelper)
102 
103  xRet = mpTextHelper->GetAt(rPoint);
104  }
105 
106  return xRet;
107 }
108 
110 {
111  SolarMutexGuard aGuard;
112  IsObjectValid();
113  if (getAccessibleParent().is())
114  {
115  uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
116  if (xAccessibleComponent.is())
117  xAccessibleComponent->grabFocus();
118  }
119 }
120 
121 //===== XAccessibleContext ==============================================
122 
124 {
125  SolarMutexGuard aGuard;
126  IsObjectValid();
127  if (!mpTextHelper)
129  return mpTextHelper->GetChildCount();
130 }
131 
132 uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewCell::getAccessibleChild(sal_Int32 nIndex)
133 {
134  SolarMutexGuard aGuard;
135  IsObjectValid();
136  if (!mpTextHelper)
138  return mpTextHelper->GetChild(nIndex);
139 }
140 
141 uno::Reference<XAccessibleStateSet> SAL_CALL ScAccessiblePreviewCell::getAccessibleStateSet()
142 {
143  SolarMutexGuard aGuard;
144 
145  uno::Reference<XAccessibleStateSet> xParentStates;
146  if (getAccessibleParent().is())
147  {
148  uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
149  xParentStates = xParentContext->getAccessibleStateSet();
150  }
152  if (IsDefunc(xParentStates))
153  pStateSet->AddState(AccessibleStateType::DEFUNC);
154  else
155  {
156  pStateSet->AddState(AccessibleStateType::ENABLED);
157  pStateSet->AddState(AccessibleStateType::MULTI_LINE);
158  if (IsOpaque())
159  pStateSet->AddState(AccessibleStateType::OPAQUE);
160  if (isShowing())
161  pStateSet->AddState(AccessibleStateType::SHOWING);
162  pStateSet->AddState(AccessibleStateType::TRANSIENT);
163  if (isVisible())
164  pStateSet->AddState(AccessibleStateType::VISIBLE);
165  // MANAGES_DESCENDANTS (for paragraphs)
166  pStateSet->AddState(AccessibleStateType::MANAGES_DESCENDANTS);
167  }
168  return pStateSet;
169 }
170 
171 //===== XServiceInfo ====================================================
172 
174 {
175  return "ScAccessiblePreviewCell";
176 }
177 
178 uno::Sequence<OUString> SAL_CALL ScAccessiblePreviewCell::getSupportedServiceNames()
179 {
180  uno::Sequence< OUString > aSequence = ScAccessibleContextBase::getSupportedServiceNames();
181  sal_Int32 nOldSize(aSequence.getLength());
182  aSequence.realloc(nOldSize + 1);
183 
184  aSequence[nOldSize] = "com.sun.star.table.AccessibleCellView";
185 
186  return aSequence;
187 }
188 
189 //===== XTypeProvider =======================================================
190 
191 uno::Sequence<sal_Int8> SAL_CALL
193 {
194  return css::uno::Sequence<sal_Int8>();
195 }
196 
197 //==== internal =========================================================
198 
200 {
201  tools::Rectangle aCellRect;
202  if (mpViewShell)
203  {
205  vcl::Window* pWindow = mpViewShell->GetWindow();
206  if (pWindow)
207  {
208  tools::Rectangle aRect = pWindow->GetWindowExtentsRelative(nullptr);
209  aCellRect.setX(aCellRect.getX() + aRect.getX());
210  aCellRect.setY(aCellRect.getY() + aRect.getY());
211  }
212  }
213  return aCellRect;
214 }
215 
217 {
218  tools::Rectangle aCellRect;
219  if (mpViewShell)
220  {
222  uno::Reference<XAccessible> xAccParent = const_cast<ScAccessiblePreviewCell*>(this)->getAccessibleParent();
223  if (xAccParent.is())
224  {
225  uno::Reference<XAccessibleContext> xAccParentContext = xAccParent->getAccessibleContext();
226  uno::Reference<XAccessibleComponent> xAccParentComp (xAccParentContext, uno::UNO_QUERY);
227  if (xAccParentComp.is())
228  {
229  tools::Rectangle aParentRect (VCLRectangle(xAccParentComp->getBounds()));
230  aCellRect.setX(aCellRect.getX() - aParentRect.getX());
231  aCellRect.setY(aCellRect.getY() - aParentRect.getY());
232  }
233  }
234  }
235  return aCellRect;
236 }
237 
239  const uno::Reference<XAccessibleStateSet>& rxParentStates)
240 {
241  return ScAccessibleContextBase::IsDefunc() || (mpDoc == nullptr) || (mpViewShell == nullptr) || !getAccessibleParent().is() ||
242  (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
243 }
244 
246  const uno::Reference<XAccessibleStateSet>& /* rxParentStates */)
247 {
248  return false;
249 }
250 
252 {
253  // test whether there is a background color
255 
256  bool bOpaque(true);
257  if (mpDoc)
258  {
260  if (pItem)
261  bOpaque = pItem->GetColor() != COL_TRANSPARENT;
262  }
263  return bOpaque;
264 }
265 
267 {
268  if (mpTextHelper)
269  return;
270 
271  mpTextHelper.reset( new ::accessibility::AccessibleTextHelper(
272  std::make_unique<ScAccessibilityEditSource>(
273  std::make_unique<ScAccessiblePreviewCellTextData>(
275  mpTextHelper->SetEventSource( this );
276 
277  // paragraphs in preview are transient
279  aChildStates.push_back( AccessibleStateType::TRANSIENT );
280  mpTextHelper->SetAdditionalChildStates( aChildStates );
281 }
282 
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool isVisible() override
const ScPreviewLocationData & GetLocationData()
Definition: prevwsh.cxx:1177
void AddAccessibilityObject(SfxListener &rObject)
Definition: prevwsh.cxx:1148
virtual ~ScAccessiblePreviewCell() override
ULONG m_refCount
virtual tools::Rectangle GetBoundingBoxOnScreen() const override
Return the object's current bounding box relative to the desktop.
void GetCellPosition(const ScAddress &rCellPos, tools::Rectangle &rCellRect) const
Definition: prevloc.cxx:308
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override
Return a reference to the parent.
virtual OUString SAL_CALL getImplementationName() override
===== XServiceInfo ====================================================
long getY() const
virtual sal_Bool SAL_CALL containsPoint(const css::awt::Point &rPoint) override
===== XAccessibleComponent ============================================
SfxHintId GetId() const
virtual css::uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet() override
Return the set of current states.
constexpr::Color COL_TRANSPARENT(0xFF, 0xFF, 0xFF, 0xFF)
::std::vector< sal_Int16 > VectorOfStates
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
===== SfxListener =====================================================
long getX() const
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
===== XTypeProvider ===================================================
SC_DLLPUBLIC const SfxPoolItem * GetAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt16 nWhich) const
Definition: document.cxx:4717
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Returns a list of all supported services.
const Color & GetColor() const
std::unique_ptr< accessibility::AccessibleTextHelper > mpTextHelper
void setY(long y)
inline::tools::Rectangle VCLRectangle(const css::awt::Rectangle &rAWTRect)
virtual tools::Rectangle GetBoundingBox() const override
Return the object's current bounding box relative to the parent object.
virtual sal_Int32 SAL_CALL getAccessibleChildCount() override
===== XAccessibleContext ==============================================
virtual bool IsEditable(const css::uno::Reference< css::accessibility::XAccessibleStateSet > &rxParentStates) override
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
===== SfxListener =====================================================
virtual void SAL_CALL disposing() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point &aPoint) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Returns a list of all supported services.
constexpr TypedWhichId< SvxBrushItem > ATTR_BACKGROUND(148)
virtual void SAL_CALL disposing() 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.
void RemoveAccessibilityObject(SfxListener &rObject)
Definition: prevwsh.cxx:1156
virtual void SAL_CALL grabFocus() override
vcl::Window * GetWindow() const
void setX(long x)
void dispose()
void AddState(sal_Int16 aState)
ScAccessiblePreviewCell(const css::uno::Reference< css::accessibility::XAccessible > &rxParent, ScPreviewShell *pViewShell, const ScAddress &rCellAddress, sal_Int32 nIndex)
tools::Rectangle GetWindowExtentsRelative(vcl::Window *pRelativeWindow) const
virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext() override
===== XAccessible =====================================================