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 #include <comphelper/sequence.hxx>
38 
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::accessibility;
41 
42 //===== internal ============================================================
43 
44 ScAccessiblePreviewCell::ScAccessiblePreviewCell( const css::uno::Reference<css::accessibility::XAccessible>& rxParent,
45  ScPreviewShell* pViewShell,
46  const ScAddress& rCellAddress,
47  sal_Int32 nIndex ) :
48  ScAccessibleCellBase( rxParent, ( pViewShell ? &pViewShell->GetDocument() : nullptr ), rCellAddress, nIndex ),
49  mpViewShell( pViewShell )
50 {
51  if (mpViewShell)
53 }
54 
56 {
57  if (!ScAccessibleContextBase::IsDefunc() && !rBHelper.bInDispose)
58  {
59  // increment refcount to prevent double call off dtor
60  osl_atomic_increment( &m_refCount );
61  // call dispose to inform object which have a weak reference to this object
62  dispose();
63  }
64 }
65 
67 {
68  SolarMutexGuard aGuard;
69  if (mpViewShell)
70  {
72  mpViewShell = nullptr;
73  }
74 
75  mpTextHelper.reset();
76 
78 }
79 
81 {
82  if (rHint.GetId() == SfxHintId::ScAccVisAreaChanged)
83  {
84  if (mpTextHelper)
85  mpTextHelper->UpdateChildren();
86  }
87 
89 }
90 
91 //===== XAccessibleComponent ============================================
92 
93 uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewCell::getAccessibleAtPoint( const awt::Point& rPoint )
94 {
95  uno::Reference<XAccessible> xRet;
96  if (containsPoint(rPoint))
97  {
98  SolarMutexGuard aGuard;
99  IsObjectValid();
100 
101  if(!mpTextHelper)
103 
104  xRet = mpTextHelper->GetAt(rPoint);
105  }
106 
107  return xRet;
108 }
109 
111 {
112  SolarMutexGuard aGuard;
113  IsObjectValid();
114  if (getAccessibleParent().is())
115  {
116  uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
117  if (xAccessibleComponent.is())
118  xAccessibleComponent->grabFocus();
119  }
120 }
121 
122 //===== XAccessibleContext ==============================================
123 
125 {
126  SolarMutexGuard aGuard;
127  IsObjectValid();
128  if (!mpTextHelper)
130  return mpTextHelper->GetChildCount();
131 }
132 
133 uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewCell::getAccessibleChild(sal_Int32 nIndex)
134 {
135  SolarMutexGuard aGuard;
136  IsObjectValid();
137  if (!mpTextHelper)
139  return mpTextHelper->GetChild(nIndex);
140 }
141 
142 uno::Reference<XAccessibleStateSet> SAL_CALL ScAccessiblePreviewCell::getAccessibleStateSet()
143 {
144  SolarMutexGuard aGuard;
145 
146  uno::Reference<XAccessibleStateSet> xParentStates;
147  if (getAccessibleParent().is())
148  {
149  uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
150  xParentStates = xParentContext->getAccessibleStateSet();
151  }
153  if (IsDefunc(xParentStates))
154  pStateSet->AddState(AccessibleStateType::DEFUNC);
155  else
156  {
157  pStateSet->AddState(AccessibleStateType::ENABLED);
158  pStateSet->AddState(AccessibleStateType::MULTI_LINE);
159  if (IsOpaque())
160  pStateSet->AddState(AccessibleStateType::OPAQUE);
161  if (isShowing())
162  pStateSet->AddState(AccessibleStateType::SHOWING);
163  pStateSet->AddState(AccessibleStateType::TRANSIENT);
164  if (isVisible())
165  pStateSet->AddState(AccessibleStateType::VISIBLE);
166  // MANAGES_DESCENDANTS (for paragraphs)
167  pStateSet->AddState(AccessibleStateType::MANAGES_DESCENDANTS);
168  }
169  return pStateSet;
170 }
171 
172 //===== XServiceInfo ====================================================
173 
175 {
176  return "ScAccessiblePreviewCell";
177 }
178 
179 uno::Sequence<OUString> SAL_CALL ScAccessiblePreviewCell::getSupportedServiceNames()
180 {
181  const css::uno::Sequence<OUString> vals { "com.sun.star.table.AccessibleCellView" };
183 }
184 
185 //===== XTypeProvider =======================================================
186 
187 uno::Sequence<sal_Int8> SAL_CALL
189 {
190  return css::uno::Sequence<sal_Int8>();
191 }
192 
193 //==== internal =========================================================
194 
196 {
197  tools::Rectangle aCellRect;
198  if (mpViewShell)
199  {
201  vcl::Window* pWindow = mpViewShell->GetWindow();
202  if (pWindow)
203  {
204  tools::Rectangle aRect = pWindow->GetWindowExtentsRelative(nullptr);
205  aCellRect.setX(aCellRect.getX() + aRect.getX());
206  aCellRect.setY(aCellRect.getY() + aRect.getY());
207  }
208  }
209  return aCellRect;
210 }
211 
213 {
214  tools::Rectangle aCellRect;
215  if (mpViewShell)
216  {
218  uno::Reference<XAccessible> xAccParent = const_cast<ScAccessiblePreviewCell*>(this)->getAccessibleParent();
219  if (xAccParent.is())
220  {
221  uno::Reference<XAccessibleContext> xAccParentContext = xAccParent->getAccessibleContext();
222  uno::Reference<XAccessibleComponent> xAccParentComp (xAccParentContext, uno::UNO_QUERY);
223  if (xAccParentComp.is())
224  {
225  tools::Rectangle aParentRect (VCLRectangle(xAccParentComp->getBounds()));
226  aCellRect.setX(aCellRect.getX() - aParentRect.getX());
227  aCellRect.setY(aCellRect.getY() - aParentRect.getY());
228  }
229  }
230  }
231  return aCellRect;
232 }
233 
235  const uno::Reference<XAccessibleStateSet>& rxParentStates)
236 {
237  return ScAccessibleContextBase::IsDefunc() || (mpDoc == nullptr) || (mpViewShell == nullptr) || !getAccessibleParent().is() ||
238  (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
239 }
240 
242  const uno::Reference<XAccessibleStateSet>& /* rxParentStates */)
243 {
244  return false;
245 }
246 
248 {
249  // test whether there is a background color
251 
252  bool bOpaque(true);
253  if (mpDoc)
254  {
256  if (pItem)
257  bOpaque = pItem->GetColor() != COL_TRANSPARENT;
258  }
259  return bOpaque;
260 }
261 
263 {
264  if (mpTextHelper)
265  return;
266 
267  mpTextHelper.reset( new ::accessibility::AccessibleTextHelper(
268  std::make_unique<ScAccessibilityEditSource>(
269  std::make_unique<ScAccessiblePreviewCellTextData>(
271  mpTextHelper->SetEventSource( this );
272 
273  // paragraphs in preview are transient
275  aChildStates.push_back( AccessibleStateType::TRANSIENT );
276  mpTextHelper->SetAdditionalChildStates( aChildStates );
277 }
278 
279 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool isVisible() override
const ScPreviewLocationData & GetLocationData()
Definition: prevwsh.cxx:1177
::std::vector< sal_Int16 > VectorOfStates
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.
tools::Long getY() const
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 ====================================================
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)
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)
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:4712
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Returns a list of all supported services.
const Color & GetColor() const
void setY(tools::Long y)
std::unique_ptr< accessibility::AccessibleTextHelper > mpTextHelper
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.
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &...rSn)
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 dispose()
void AddState(sal_Int16 aState)
ScAccessiblePreviewCell(const css::uno::Reference< css::accessibility::XAccessible > &rxParent, ScPreviewShell *pViewShell, const ScAddress &rCellAddress, sal_Int32 nIndex)
virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext() override
===== XAccessible =====================================================