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>
34
35#include <vcl/window.hxx>
36#include <vcl/svapp.hxx>
37#include <svl/hint.hxx>
39
40#ifdef indices
41#undef indices
42#endif
43
44#ifdef extents
45#undef extents
46#endif
47
48using namespace ::com::sun::star;
49using namespace ::com::sun::star::accessibility;
50
51//===== internal ============================================================
52
53ScAccessiblePreviewHeaderCell::ScAccessiblePreviewHeaderCell( const css::uno::Reference<css::accessibility::XAccessible>& rxParent,
54 ScPreviewShell* pViewShell,
55 const ScAddress& rCellPos, bool bIsColHdr, bool bIsRowHdr,
56 sal_Int32 nIndex ) :
57 ScAccessibleContextBase( rxParent, AccessibleRole::TABLE_CELL ),
58 mpViewShell( pViewShell ),
59 mnIndex( nIndex ),
60 maCellPos( rCellPos ),
61 mbColumnHeader( bIsColHdr ),
62 mbRowHeader( bIsRowHdr )
63{
64 if (mpViewShell)
66}
67
69{
70 if (mpViewShell)
72}
73
75{
76 SolarMutexGuard aGuard;
77 if (mpViewShell)
78 {
80 mpViewShell = nullptr;
81 }
82
83 mpTableInfo.reset();
84
86}
87
88//===== SfxListener =====================================================
89
91{
92 const SfxHintId nId = rHint.GetId();
93 if (nId == SfxHintId::ScAccVisAreaChanged)
94 {
95 if (mxTextHelper)
96 mxTextHelper->UpdateChildren();
97 }
98 else if ( nId == SfxHintId::DataChanged )
99 {
100 // column / row layout may change with any document change,
101 // so it must be invalidated
102 mpTableInfo.reset();
103 }
104
106}
107
108//===== XInterface =====================================================
109
111{
113 return aAny.hasValue() ? aAny : ScAccessibleContextBase::queryInterface(rType);
114}
115
117 noexcept
118{
119 ScAccessibleContextBase::acquire();
120}
121
123 noexcept
124{
125 ScAccessibleContextBase::release();
126}
127
128//===== XAccessibleValue ================================================
129
131{
132 SolarMutexGuard aGuard;
134
135 double fValue(0.0);
136 if (mbColumnHeader)
137 fValue = maCellPos.Col();
138 else
139 fValue = maCellPos.Row();
140
141 return uno::Any(fValue);
142}
143
145{
146 // it is not possible to set a value
147 return false;
148}
149
151{
152 SolarMutexGuard aGuard;
154
155 double fValue(0.0);
157 if (mbColumnHeader)
158 fValue = rDoc.MaxCol();
159 else
160 fValue = rDoc.MaxRow();
161 return uno::Any(fValue);
162}
163
165{
166 return uno::Any(0.0);
167}
168
170{
171 // value can't be changed, s. 'setCurrentValue'
172 return uno::Any();
173}
174
175//===== XAccessibleComponent ============================================
176
177uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleAtPoint( const awt::Point& rPoint )
178{
179 uno::Reference<XAccessible> xRet;
180 if (containsPoint(rPoint))
181 {
182 SolarMutexGuard aGuard;
184
185 if(!mxTextHelper)
187
188 xRet = mxTextHelper->GetAt(rPoint);
189 }
190
191 return xRet;
192}
193
195{
196 SolarMutexGuard aGuard;
198 if (getAccessibleParent().is())
199 {
200 uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
201 if (xAccessibleComponent.is())
202 xAccessibleComponent->grabFocus();
203 }
204}
205
206//===== XAccessibleContext ==============================================
207
209{
210 SolarMutexGuard aGuard;
212 if (!mxTextHelper)
214 return mxTextHelper->GetChildCount();
215}
216
217uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleChild(sal_Int64 nIndex)
218{
219 SolarMutexGuard aGuard;
221 if (!mxTextHelper)
223 return mxTextHelper->GetChild(nIndex);
224}
225
227{
228 return mnIndex;
229}
230
232{
233 SolarMutexGuard aGuard;
234
235 sal_Int64 nParentStates = 0;
236 if (getAccessibleParent().is())
237 {
238 uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
239 nParentStates = xParentContext->getAccessibleStateSet();
240 }
241 sal_Int64 nStateSet = 0;
242 if (IsDefunc(nParentStates))
243 nStateSet |= AccessibleStateType::DEFUNC;
244 else
245 {
246 nStateSet |= AccessibleStateType::ENABLED;
247 nStateSet |= AccessibleStateType::MULTI_LINE;
248 if (isShowing())
249 nStateSet |= AccessibleStateType::SHOWING;
250 nStateSet |= AccessibleStateType::TRANSIENT;
251 if (isVisible())
252 nStateSet |= AccessibleStateType::VISIBLE;
253 }
254 return nStateSet;
255}
256
257//===== XServiceInfo ====================================================
258
260{
261 return "ScAccessiblePreviewHeaderCell";
262}
263
265{
266 const css::uno::Sequence<OUString> vals { "com.sun.star.table.AccessibleCellView" };
268}
269
270//===== XTypeProvider =======================================================
271
272uno::Sequence< uno::Type > SAL_CALL ScAccessiblePreviewHeaderCell::getTypes()
273{
274 return comphelper::concatSequences(ScAccessiblePreviewHeaderCellImpl::getTypes(), ScAccessibleContextBase::getTypes());
275}
276
277uno::Sequence<sal_Int8> SAL_CALL
279{
280 return css::uno::Sequence<sal_Int8>();
281}
282
283//==== internal =========================================================
284
286{
287 tools::Rectangle aCellRect;
288
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 {
305 aCellRect.Move(aRect.Left(), aRect.Top());
306 }
307 }
308 return aCellRect;
309}
310
312{
314
315 if (mpTableInfo)
316 {
317 const ScPreviewColRowInfo& rColInfo = mpTableInfo->GetColInfo()[maCellPos.Col()];
318 const ScPreviewColRowInfo& rRowInfo = mpTableInfo->GetRowInfo()[maCellPos.Row()];
319
320 tools::Rectangle aCellRect( rColInfo.nPixelStart, rRowInfo.nPixelStart, rColInfo.nPixelEnd, rRowInfo.nPixelEnd );
321 uno::Reference<XAccessible> xAccParent = const_cast<ScAccessiblePreviewHeaderCell*>(this)->getAccessibleParent();
322 if (xAccParent.is())
323 {
324 uno::Reference<XAccessibleContext> xAccParentContext = xAccParent->getAccessibleContext();
325 uno::Reference<XAccessibleComponent> xAccParentComp (xAccParentContext, uno::UNO_QUERY);
326 if (xAccParentComp.is())
327 {
328 tools::Rectangle aParentRect (VCLRectangle(xAccParentComp->getBounds()));
329 aCellRect.Move(-aParentRect.Left(), -aParentRect.Top());
330 }
331 }
332 return aCellRect;
333 }
334 return tools::Rectangle();
335}
336
338{
340}
341
343{
345
346 if ( mbColumnHeader )
347 {
348 if ( mbRowHeader )
349 {
351
352// sName = "Column/Row Header";
353 }
354 else
355 {
356 // name of column header
358 }
359 }
360 else
361 {
362 // name of row header
363 sName += OUString::number( maCellPos.Row() + 1 );
364 }
365
366 return sName;
367}
368
369bool ScAccessiblePreviewHeaderCell::IsDefunc( sal_Int64 nParentStates )
370{
371 return ScAccessibleContextBase::IsDefunc() || (mpViewShell == nullptr) || !getAccessibleParent().is() ||
372 (nParentStates & AccessibleStateType::DEFUNC);
373}
374
376{
377 if (!mxTextHelper)
378 {
379 mxTextHelper.reset( new ::accessibility::AccessibleTextHelper(
380 std::make_unique<ScAccessibilityEditSource>(
381 std::make_unique<ScAccessiblePreviewHeaderCellTextData>(
384 mxTextHelper->SetEventSource(this);
385 }
386}
387
389{
390 if ( mpViewShell && !mpTableInfo )
391 {
392 Size aOutputSize;
393 vcl::Window* pWindow = mpViewShell->GetWindow();
394 if ( pWindow )
395 aOutputSize = pWindow->GetOutputSizePixel();
396 tools::Rectangle aVisRect( Point(), aOutputSize );
397
398 mpTableInfo.reset( new ScPreviewTableInfo );
400 }
401}
402
403/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void ScColToAlpha(OUStringBuffer &rBuf, SCCOL nCol)
append alpha representation of column to buffer
Definition: address.cxx:1884
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 OUString SAL_CALL getAccessibleName() override
Return the object's current name.
virtual OUString createAccessibleName() override
Return the object's current name.
virtual sal_Bool SAL_CALL setCurrentValue(const css::uno::Any &aNumber) override
virtual css::uno::Any SAL_CALL getMinimumIncrement() override
virtual void SAL_CALL disposing() override
virtual OUString SAL_CALL getImplementationName() override
===== XServiceInfo ====================================================
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point &aPoint) override
std::unique_ptr< accessibility::AccessibleTextHelper > mxTextHelper
virtual void SAL_CALL acquire() noexcept override
virtual void SAL_CALL release() noexcept override
virtual tools::Rectangle GetBoundingBox() const override
Return the object's current bounding box relative to the parent object.
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Returns a list of all supported services.
virtual sal_Int64 SAL_CALL getAccessibleStateSet() override
Return the set of current states.
virtual css::uno::Any SAL_CALL getMaximumValue() override
virtual css::uno::Any SAL_CALL getMinimumValue() override
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 sal_Int64 SAL_CALL getAccessibleChildCount() override
===== XAccessibleContext ==============================================
virtual OUString createAccessibleDescription() override
Return this object's description.
ScAccessiblePreviewHeaderCell(const css::uno::Reference< css::accessibility::XAccessible > &rxParent, ScPreviewShell *pViewShell, const ScAddress &rCellPos, bool bIsColHdr, bool bIsRowHdr, sal_Int32 nIndex)
virtual sal_Int64 SAL_CALL getAccessibleIndexInParent() override
Return this objects index among the parents children.
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) override
===== XInterface =====================================================
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
===== XTypeProvider ===================================================
virtual css::uno::Any SAL_CALL getCurrentValue() override
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
Returns an implementation id.
virtual void SAL_CALL grabFocus() override
std::unique_ptr< ScPreviewTableInfo > mpTableInfo
virtual tools::Rectangle GetBoundingBoxOnScreen() const override
Return the object's current bounding box relative to the desktop.
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
===== SfxListener =====================================================
SCROW Row() const
Definition: address.hxx:274
SCCOL Col() const
Definition: address.hxx:279
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:892
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:893
void GetTableInfo(const tools::Rectangle &rVisiblePixel, ScPreviewTableInfo &rInfo) const
Definition: prevloc.cxx:443
const ScPreviewLocationData & GetLocationData()
Definition: prevwsh.cxx:1171
void AddAccessibilityObject(SfxListener &rObject)
Definition: prevwsh.cxx:1142
ScDocument & GetDocument()
Definition: prevwsh.cxx:1176
void RemoveAccessibilityObject(SfxListener &rObject)
Definition: prevwsh.cxx:1150
SfxHintId GetId() const
vcl::Window * GetWindow() const
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) SAL_OVERRIDE
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() SAL_OVERRIDE
constexpr tools::Long Top() const
void Move(tools::Long nHorzMoveDelta, tools::Long nVertMoveDelta)
constexpr tools::Long Left() const
tools::Rectangle GetWindowExtentsAbsolute() const
Size GetOutputSizePixel() const
inline ::tools::Rectangle VCLRectangle(const css::awt::Rectangle &rAWTRect)
OUString sName
SfxHintId
sal_Int32 nIndex
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &... rSn)
sal_Int16 nId
constexpr OUStringLiteral STR_ACC_HEADERCELL_DESCR
Definition: strings.hxx:21
constexpr OUStringLiteral STR_ACC_HEADERCELL_NAME
Definition: strings.hxx:20
tools::Long nPixelStart
Definition: prevloc.hxx:47
tools::Long nPixelEnd
Definition: prevloc.hxx:48
bool hasValue()
sal_uInt32 mnIndex
unsigned char sal_Bool