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>
31#include <editeng/brushitem.hxx>
32#include <vcl/window.hxx>
33#include <vcl/svapp.hxx>
35#include <com/sun/star/accessibility/AccessibleStateType.hpp>
37
38using namespace ::com::sun::star;
39using namespace ::com::sun::star::accessibility;
40
41//===== internal ============================================================
42
43ScAccessiblePreviewCell::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
92uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewCell::getAccessibleAtPoint( const awt::Point& rPoint )
93{
94 uno::Reference<XAccessible> xRet;
95 if (containsPoint(rPoint))
96 {
97 SolarMutexGuard aGuard;
99
100 if(!mpTextHelper)
102
103 xRet = mpTextHelper->GetAt(rPoint);
104 }
105
106 return xRet;
107}
108
110{
111 SolarMutexGuard aGuard;
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;
127 if (!mpTextHelper)
129 return mpTextHelper->GetChildCount();
130}
131
132uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewCell::getAccessibleChild(sal_Int64 nIndex)
133{
134 SolarMutexGuard aGuard;
136 if (!mpTextHelper)
138 return mpTextHelper->GetChild(nIndex);
139}
140
142{
143 SolarMutexGuard aGuard;
144
145 sal_Int64 nParentStates = 0;
146 if (getAccessibleParent().is())
147 {
148 uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
149 nParentStates = xParentContext->getAccessibleStateSet();
150 }
151 sal_Int64 nStateSet = 0;
152 if (IsDefunc(nParentStates))
153 nStateSet |= AccessibleStateType::DEFUNC;
154 else
155 {
156 nStateSet |= AccessibleStateType::ENABLED;
157 nStateSet |= AccessibleStateType::MULTI_LINE;
158 if (IsOpaque())
159 nStateSet |= AccessibleStateType::OPAQUE;
160 if (isShowing())
161 nStateSet |= AccessibleStateType::SHOWING;
162 nStateSet |= AccessibleStateType::TRANSIENT;
163 if (isVisible())
164 nStateSet |= AccessibleStateType::VISIBLE;
165 // MANAGES_DESCENDANTS (for paragraphs)
166 nStateSet |= AccessibleStateType::MANAGES_DESCENDANTS;
167 }
168 return nStateSet;
169}
170
171//===== XServiceInfo ====================================================
172
174{
175 return "ScAccessiblePreviewCell";
176}
177
179{
180 const css::uno::Sequence<OUString> vals { "com.sun.star.table.AccessibleCellView" };
182}
183
184//===== XTypeProvider =======================================================
185
186uno::Sequence<sal_Int8> SAL_CALL
188{
189 return css::uno::Sequence<sal_Int8>();
190}
191
192//==== internal =========================================================
193
195{
196 tools::Rectangle aCellRect;
197 if (mpViewShell)
198 {
200 vcl::Window* pWindow = mpViewShell->GetWindow();
201 if (pWindow)
202 {
203 tools::Rectangle aRect = pWindow->GetWindowExtentsRelative(nullptr);
204 aCellRect.Move(aRect.Left(), aRect.Top());
205 }
206 }
207 return aCellRect;
208}
209
211{
212 tools::Rectangle aCellRect;
213 if (mpViewShell)
214 {
216 uno::Reference<XAccessible> xAccParent = const_cast<ScAccessiblePreviewCell*>(this)->getAccessibleParent();
217 if (xAccParent.is())
218 {
219 uno::Reference<XAccessibleContext> xAccParentContext = xAccParent->getAccessibleContext();
220 uno::Reference<XAccessibleComponent> xAccParentComp (xAccParentContext, uno::UNO_QUERY);
221 if (xAccParentComp.is())
222 {
223 tools::Rectangle aParentRect (VCLRectangle(xAccParentComp->getBounds()));
224 aCellRect.Move(-aParentRect.Left(), -aParentRect.Top());
225 }
226 }
227 }
228 return aCellRect;
229}
230
231bool ScAccessiblePreviewCell::IsDefunc(sal_Int64 nParentStates)
232{
233 return ScAccessibleContextBase::IsDefunc() || (mpDoc == nullptr) || (mpViewShell == nullptr) || !getAccessibleParent().is() ||
234 (nParentStates & AccessibleStateType::DEFUNC);
235}
236
237bool ScAccessiblePreviewCell::IsEditable(sal_Int64 /* nParentStates */)
238{
239 return false;
240}
241
243{
244 // test whether there is a background color
246
247 bool bOpaque(true);
248 if (mpDoc)
249 {
251 if (pItem)
252 bOpaque = pItem->GetColor() != COL_TRANSPARENT;
253 }
254 return bOpaque;
255}
256
258{
259 if (mpTextHelper)
260 return;
261
262 mpTextHelper.reset( new ::accessibility::AccessibleTextHelper(
263 std::make_unique<ScAccessibilityEditSource>(
264 std::make_unique<ScAccessiblePreviewCellTextData>(
266 mpTextHelper->SetEventSource( this );
267
268 // paragraphs in preview are transient
269 mpTextHelper->SetAdditionalChildStates( AccessibleStateType::TRANSIENT );
270}
271
272/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool isVisible() override
virtual sal_Bool SAL_CALL containsPoint(const css::awt::Point &rPoint) override
===== XAccessibleComponent ============================================
virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext() override
===== XAccessible =====================================================
virtual void SAL_CALL disposing() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Returns a list of all supported services.
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
===== SfxListener =====================================================
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override
Return a reference to the parent.
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.
std::unique_ptr< accessibility::AccessibleTextHelper > mpTextHelper
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
===== SfxListener =====================================================
virtual ~ScAccessiblePreviewCell() override
ScAccessiblePreviewCell(const css::uno::Reference< css::accessibility::XAccessible > &rxParent, ScPreviewShell *pViewShell, const ScAddress &rCellAddress, sal_Int32 nIndex)
virtual void SAL_CALL grabFocus() override
virtual tools::Rectangle GetBoundingBox() const override
Return the object's current bounding box relative to the parent object.
virtual sal_Int64 SAL_CALL getAccessibleStateSet() override
Return the set of current states.
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int64 i) override
Return the specified child or NULL if index is invalid.
virtual OUString SAL_CALL getImplementationName() override
===== XServiceInfo ====================================================
virtual tools::Rectangle GetBoundingBoxOnScreen() const override
Return the object's current bounding box relative to the desktop.
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
===== XTypeProvider ===================================================
virtual bool IsEditable(sal_Int64 nParentStates) override
virtual sal_Int64 SAL_CALL getAccessibleChildCount() override
===== XAccessibleContext ==============================================
SC_DLLPUBLIC const SfxPoolItem * GetAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt16 nWhich) const
Definition: document.cxx:4777
void GetCellPosition(const ScAddress &rCellPos, tools::Rectangle &rCellRect) const
Definition: prevloc.cxx:309
const ScPreviewLocationData & GetLocationData()
Definition: prevwsh.cxx:1171
void AddAccessibilityObject(SfxListener &rObject)
Definition: prevwsh.cxx:1142
void RemoveAccessibilityObject(SfxListener &rObject)
Definition: prevwsh.cxx:1150
SfxHintId GetId() const
vcl::Window * GetWindow() const
const Color & GetColor() const
constexpr tools::Long Top() const
void Move(tools::Long nHorzMoveDelta, tools::Long nVertMoveDelta)
constexpr tools::Long Left() const
tools::Rectangle GetWindowExtentsRelative(const vcl::Window *pRelativeWindow) const
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
inline ::tools::Rectangle VCLRectangle(const css::awt::Rectangle &rAWTRect)
ULONG m_refCount
sal_Int32 nIndex
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &... rSn)
void dispose()
constexpr TypedWhichId< SvxBrushItem > ATTR_BACKGROUND(148)