LibreOffice Module sw (master) 1
acccell.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/log.hxx>
21#include <com/sun/star/accessibility/AccessibleRole.hpp>
22#include <com/sun/star/accessibility/AccessibleStateType.hpp>
23#include <com/sun/star/accessibility/AccessibleEventId.hpp>
26#include <vcl/svapp.hxx>
27#include <cellfrm.hxx>
28#include <tabfrm.hxx>
29#include <swtable.hxx>
30#include <crsrsh.hxx>
31#include <viscrs.hxx>
32#include "accfrmobj.hxx"
33#include "accfrmobjslist.hxx"
34#include <frmfmt.hxx>
35#include <cellatr.hxx>
36#include <accmap.hxx>
37#include "acccell.hxx"
38
39#include <cfloat>
40#include <string_view>
41
42#include <editeng/brushitem.hxx>
43#include <swatrset.hxx>
44#include <frmatr.hxx>
45#include "acctable.hxx"
46
47using namespace ::com::sun::star;
48using namespace ::com::sun::star::accessibility;
49using namespace sw::access;
50
51constexpr OUStringLiteral sImplementationName = u"com.sun.star.comp.Writer.SwAccessibleCellView";
52
54{
55 bool bRet = false;
56
57 assert(GetMap());
58 const SwViewShell *pVSh = GetMap()->GetShell();
59 assert(pVSh);
60 if( auto pCSh = dynamic_cast<const SwCursorShell*>(pVSh) )
61 {
62 if( pCSh->IsTableMode() )
63 {
64 const SwCellFrame *pCFrame =
65 static_cast< const SwCellFrame * >( GetFrame() );
66 SwTableBox *pBox =
67 const_cast< SwTableBox *>( pCFrame->GetTabBox() );
68 SwSelBoxes const& rBoxes(pCSh->GetTableCursor()->GetSelectedBoxes());
69 bRet = rBoxes.find(pBox) != rBoxes.end();
70 }
71 }
72
73 return bRet;
74}
75
76void SwAccessibleCell::GetStates( sal_Int64& rStateSet )
77{
79
80 // SELECTABLE
81 const SwViewShell *pVSh = GetMap()->GetShell();
82 assert(pVSh);
83 if( dynamic_cast<const SwCursorShell*>( pVSh) != nullptr )
84 rStateSet |= AccessibleStateType::SELECTABLE;
85 //Add resizable state to table cell.
86 rStateSet |= AccessibleStateType::RESIZABLE;
87
88 if (IsDisposing()) // tdf#135098
89 return;
90
91 // SELECTED
92 if( IsSelected() )
93 {
94 rStateSet |= AccessibleStateType::SELECTED;
95 SAL_WARN_IF(!m_bIsSelected, "sw.a11y", "bSelected out of sync");
97 GetMap()->SetCursorContext( xThis );
98 }
99}
100
101SwAccessibleCell::SwAccessibleCell(std::shared_ptr<SwAccessibleMap> const& pInitMap,
102 const SwCellFrame *pCellFrame )
103 : SwAccessibleContext( pInitMap, AccessibleRole::TABLE_CELL, pCellFrame )
104 , m_aSelectionHelper( *this )
105 , m_bIsSelected( false )
106{
107 OUString sBoxName( pCellFrame->GetTabBox()->GetName() );
108 SetName( sBoxName );
109
111
112 css::uno::Reference<css::accessibility::XAccessible> xTableReference(
114 css::uno::Reference<css::accessibility::XAccessibleContext> xContextTable(
115 xTableReference, css::uno::UNO_QUERY);
117 (!xContextTable.is()
118 || xContextTable->getAccessibleRole() != AccessibleRole::TABLE),
119 "sw.a11y", "bad accessible context");
120 m_pAccTable = static_cast<SwAccessibleTable *>(xTableReference.get());
121}
122
124{
125 bool bNew = IsSelected();
126 bool bOld;
127 {
128 std::scoped_lock aGuard( m_Mutex );
129 bOld = m_bIsSelected;
130 m_bIsSelected = bNew;
131 }
132 if( bNew )
133 {
134 // remember that object as the one that has the caret. This is
135 // necessary to notify that object if the cursor leaves it.
137 GetMap()->SetCursorContext( xThis );
138 }
139
140 bool bChanged = bOld != bNew;
141 if( bChanged )
142 {
143 FireStateChangedEvent( AccessibleStateType::SELECTED, bNew );
144 if (m_pAccTable.is())
145 {
146 m_pAccTable->AddSelectionCell(this,bNew);
147 }
148 }
149 return bChanged;
150}
151
153{
154 bool bChanged = false;
155
156 const SwAccessibleChildSList aVisList( GetVisArea(), *pFrame, *GetMap() );
158 while( aIter != aVisList.end() )
159 {
160 const SwAccessibleChild& rLower = *aIter;
161 const SwFrame *pLower = rLower.GetSwFrame();
162 if( pLower )
163 {
164 if( rLower.IsAccessible( GetMap()->GetShell()->IsPreview() ) )
165 {
167 GetMap()->GetContextImpl( pLower, false ) );
168 if( xAccImpl.is() )
169 {
170 assert(xAccImpl->GetFrame()->IsCellFrame());
171 bChanged = static_cast< SwAccessibleCell *>(
172 xAccImpl.get() )->InvalidateMyCursorPos();
173 }
174 else
175 bChanged = true; // If the context is not know we
176 // don't know whether the selection
177 // changed or not.
178 }
179 else
180 {
181 // This is a box with sub rows.
182 bChanged |= InvalidateChildrenCursorPos( pLower );
183 }
184 }
185 ++aIter;
186 }
187
188 return bChanged;
189}
190
192{
193 if (IsSelected())
194 {
195 const SwAccessibleChild aChild( GetChild( *(GetMap()), 0 ) );
196 if( aChild.IsValid() && aChild.GetSwFrame() )
197 {
198 ::rtl::Reference < SwAccessibleContext > xChildImpl( GetMap()->GetContextImpl( aChild.GetSwFrame()) );
199 if (xChildImpl.is())
200 {
201 AccessibleEventObject aEvent;
202 aEvent.EventId = AccessibleEventId::STATE_CHANGED;
203 aEvent.NewValue <<= AccessibleStateType::FOCUSED;
204 xChildImpl->FireAccessibleEvent( aEvent );
205 }
206 }
207 }
208
210 assert(pParent->IsTabFrame());
211 const SwTabFrame *pTabFrame = static_cast< const SwTabFrame * >( pParent );
212 if( pTabFrame->IsFollow() )
213 pTabFrame = pTabFrame->FindMaster();
214
215 while( pTabFrame )
216 {
217 InvalidateChildrenCursorPos( pTabFrame );
218 pTabFrame = pTabFrame->GetFollow();
219 }
220 if (m_pAccTable.is())
221 {
222 m_pAccTable->FireSelectionEvent();
223 }
224}
225
227{
228 std::scoped_lock aGuard( m_Mutex );
229 return m_bIsSelected;
230}
231
233{
234}
235
237{
238 return GetName();
239}
240
242{
243 return sImplementationName;
244}
245
246sal_Bool SAL_CALL SwAccessibleCell::supportsService(const OUString& sTestServiceName)
247{
248 return cppu::supportsService(this, sTestServiceName);
249}
250
251uno::Sequence< OUString > SAL_CALL SwAccessibleCell::getSupportedServiceNames()
252{
253 return { "com.sun.star.table.AccessibleCellView", sAccessibleServiceName };
254}
255
256void SwAccessibleCell::Dispose(bool bRecursive, bool bCanSkipInvisible)
257{
260 GetMap()->GetContextImpl( pParent, false ) );
261 if( xAccImpl.is() )
262 xAccImpl->DisposeChild(SwAccessibleChild(GetFrame()), bRecursive, bCanSkipInvisible);
263 SwAccessibleContext::Dispose( bRecursive );
264}
265
267{
270 GetMap()->GetContextImpl( pParent, false ) );
271 if( xAccImpl.is() )
272 xAccImpl->InvalidateChildPosOrSize( SwAccessibleChild(GetFrame()), rOldBox );
274}
275
276// XAccessibleInterface
277
279{
281 {
282 uno::Any aR;
283 aR <<= uno::Reference<XAccessibleExtendedAttributes>(this);
284 return aR;
285 }
286
288 {
289 uno::Any aR;
290 aR <<= uno::Reference<XAccessibleSelection>(this);
291 return aR;
292 }
294 {
295 uno::Reference<XAccessibleValue> xValue = this;
296 uno::Any aRet;
297 aRet <<= xValue;
298 return aRet;
299 }
300 else
301 {
302 return SwAccessibleContext::queryInterface( rType );
303 }
304}
305
306// XTypeProvider
307uno::Sequence< uno::Type > SAL_CALL SwAccessibleCell::getTypes()
308{
311 SwAccessibleContext::getTypes() ).getTypes();
312}
313
314uno::Sequence< sal_Int8 > SAL_CALL SwAccessibleCell::getImplementationId()
315{
316 return css::uno::Sequence<sal_Int8>();
317}
318
319// XAccessibleValue
320
322{
323 assert(GetFrame());
324 assert(GetFrame()->IsCellFrame());
325
326 const SwCellFrame* pCellFrame = static_cast<const SwCellFrame*>( GetFrame() );
327 return pCellFrame->GetTabBox()->GetFrameFormat();
328}
329
330//Implement TableCell currentValue
332{
333 SolarMutexGuard aGuard;
334
336
337 return uno::Any( GetTableBoxFormat()->GetTableBoxValue().GetValue() );
338}
339
341{
342 SolarMutexGuard aGuard;
343
345
346 double fValue = 0;
347 bool bValid = (aNumber >>= fValue);
348 if( bValid )
349 {
350 SwTableBoxValue aValue( fValue );
351 GetTableBoxFormat()->SetFormatAttr( aValue );
352 }
353 return bValid;
354}
355
357{
358 return uno::Any(DBL_MAX);
359}
360
362{
363 return uno::Any(-DBL_MAX);
364}
365
367{
368 return uno::Any();
369}
370
372{
374
375 css::uno::Any strRet;
376 SwFrameFormat *pFrameFormat = GetTableBoxFormat();
377 assert(pFrameFormat);
378
379 const SwTableBoxFormula& tbl_formula = pFrameFormat->GetTableBoxFormula();
380
381 OUString strFormula = tbl_formula.GetFormula()
382 .replaceAll(u"\\", u"\\\\")
383 .replaceAll(u";", u"\\;")
384 .replaceAll(u"=", u"\\=")
385 .replaceAll(u",", u"\\,")
386 .replaceAll(u":", u"\\:");
387 OUString strFor = "Formula:" + strFormula + ";";
388 strRet <<= strFor;
389
390 return strRet;
391}
392
394{
396
397 const SvxBrushItem &rBack = GetFrame()->GetAttrSet()->GetBackground();
398 Color crBack = rBack.GetColor();
399
400 if (COL_AUTO == crBack)
401 {
402 uno::Reference<XAccessible> xAccDoc = getAccessibleParent();
403 if (xAccDoc.is())
404 {
405 uno::Reference<XAccessibleComponent> xComponentDoc(xAccDoc, uno::UNO_QUERY);
406 if (xComponentDoc.is())
407 {
408 crBack = Color(ColorTransparency, xComponentDoc->getBackground());
409 }
410 }
411 }
412 return sal_Int32(crBack);
413}
414
415// XAccessibleSelection
417 sal_Int64 nChildIndex )
418{
420}
421
423 sal_Int64 nChildIndex )
424{
426}
427
429{
430}
431
433{
435}
436
438{
440}
441
443 sal_Int64 nSelectedChildIndex )
444{
445 return m_aSelectionHelper.getSelectedAccessibleChild(nSelectedChildIndex);
446}
447
449 sal_Int64 nSelectedChildIndex )
450{
451 m_aSelectionHelper.deselectAccessibleChild(nSelectedChildIndex);
452}
453
454/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral sImplementationName
Definition: acccell.cxx:51
constexpr OUStringLiteral sAccessibleServiceName
Definition: acccontext.hxx:42
AnyEventRef aEvent
const Color & GetColor() const
virtual css::uno::Any SAL_CALL getMinimumValue() override
Definition: acccell.cxx:361
SwFrameFormat * GetTableBoxFormat() const
Definition: acccell.cxx:321
sal_Int32 SAL_CALL getBackground() override
Definition: acccell.cxx:393
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getSelectedAccessibleChild(sal_Int64 nSelectedChildIndex) override
Definition: acccell.cxx:442
virtual void InvalidatePosOrSize(const SwRect &rFrame) override
Definition: acccell.cxx:266
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &aType) override
Definition: acccell.cxx:278
virtual css::uno::Any SAL_CALL getMinimumIncrement() override
Definition: acccell.cxx:366
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: acccell.cxx:251
bool InvalidateChildrenCursorPos(const SwFrame *pFrame)
Definition: acccell.cxx:152
virtual ~SwAccessibleCell() override
Definition: acccell.cxx:232
bool IsSelected()
Definition: acccell.cxx:53
virtual sal_Int64 SAL_CALL getSelectedAccessibleChildCount() override
Definition: acccell.cxx:437
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
Definition: acccell.cxx:314
SwAccessibleCell(std::shared_ptr< SwAccessibleMap > const &pInitMap, const SwCellFrame *pCellFrame)
Definition: acccell.cxx:101
virtual sal_Bool SAL_CALL setCurrentValue(const css::uno::Any &aNumber) override
Definition: acccell.cxx:340
virtual void SAL_CALL selectAccessibleChild(sal_Int64 nChildIndex) override
Definition: acccell.cxx:416
virtual void SAL_CALL clearAccessibleSelection() override
Definition: acccell.cxx:428
virtual OUString SAL_CALL getAccessibleDescription() override
Return this object's description.
Definition: acccell.cxx:236
virtual void Dispose(bool bRecursive, bool bCanSkipInvisible=true) override
Definition: acccell.cxx:256
virtual css::uno::Any SAL_CALL getCurrentValue() override
Definition: acccell.cxx:331
virtual OUString SAL_CALL getImplementationName() override
Definition: acccell.cxx:241
virtual void SAL_CALL selectAllAccessibleChildren() override
Definition: acccell.cxx:432
SwAccessibleSelectionHelper m_aSelectionHelper
Definition: acccell.hxx:36
css::uno::Any SAL_CALL getExtendedAttributes() override
Definition: acccell.cxx:371
virtual void GetStates(sal_Int64 &rStateSet) override
Definition: acccell.cxx:76
rtl::Reference< SwAccessibleTable > m_pAccTable
Definition: acccell.hxx:44
virtual sal_Bool SAL_CALL isAccessibleChildSelected(sal_Int64 nChildIndex) override
Definition: acccell.cxx:422
bool InvalidateMyCursorPos()
Definition: acccell.cxx:123
virtual void SAL_CALL deselectAccessibleChild(sal_Int64 nSelectedChildIndex) override
Definition: acccell.cxx:448
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Definition: acccell.cxx:307
virtual void InvalidateCursorPos_() override
Definition: acccell.cxx:191
virtual css::uno::Any SAL_CALL getMaximumValue() override
Definition: acccell.cxx:356
virtual bool HasCursor() override
Definition: acccell.cxx:226
bool m_bIsSelected
Definition: acccell.hxx:37
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
Return whether the specified service is supported by this class.
Definition: acccell.cxx:246
const_iterator end() const
const_iterator begin() const
virtual void Dispose(bool bRecursive, bool bCanSkipInvisible=true)
const OUString & GetName() const
Definition: acccontext.hxx:334
void FireStateChangedEvent(sal_Int64 nState, bool bNewState)
Definition: acccontext.cxx:467
void SetName(const OUString &rName)
Definition: acccontext.hxx:99
bool IsDisposing() const
Definition: acccontext.hxx:109
virtual void GetStates(sal_Int64 &rStateSet)
Definition: acccontext.cxx:481
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override
Definition: acccontext.cxx:693
SwAccessibleMap * GetMap()
Definition: acccontext.hxx:112
std::mutex m_Mutex
Definition: acccontext.hxx:64
SwViewShell * GetShell()
convenience method to get the SwViewShell through accessibility map
Definition: acccontext.hxx:116
virtual void InvalidatePosOrSize(const SwRect &rFrame)
css::uno::Reference< css::accessibility::XAccessible > getAccessibleParentImpl()
Definition: acccontext.cxx:671
bool IsInPagePreview() const
Definition: accframe.hxx:86
static sw::access::SwAccessibleChild GetChild(SwAccessibleMap &rAccMap, const SwRect &rVisArea, const SwFrame &rFrame, sal_Int32 &rPos, bool bInPagePreview)
Definition: accframe.cxx:71
const SwFrame * GetFrame() const
Definition: accframe.hxx:102
const SwFrame * GetParent() const
Definition: accframe.hxx:154
const SwRect & GetVisArea() const
Definition: accframe.hxx:135
void SetCursorContext(const ::rtl::Reference< SwAccessibleContext > &rCursorContext)
Definition: accmap.cxx:2732
SwViewShell * GetShell() const
Definition: accmap.hxx:173
bool isAccessibleChildSelected(sal_Int64 nChildIndex)
void selectAccessibleChild(sal_Int64 nChildIndex)
css::uno::Reference< css::accessibility::XAccessible > getSelectedAccessibleChild(sal_Int64 nSelectedChildIndex)
void deselectAccessibleChild(sal_Int64 nChildIndex)
const SvxBrushItem & GetBackground(bool=true) const
Definition: frmatr.hxx:70
SwCellFrame is one table cell in the document layout.
Definition: cellfrm.hxx:31
const SwTableBox * GetTabBox() const
Definition: cellfrm.hxx:52
const SwTableBoxFormula & GetTableBoxFormula(bool=true) const
Definition: cellatr.hxx:124
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:447
Style of a layout element.
Definition: frmfmt.hxx:72
Base class of the Writer layout elements.
Definition: frame.hxx:315
bool IsTabFrame() const
Definition: frame.hxx:1224
const SwAttrSet * GetAttrSet() const
WARNING: this may not return correct RES_PAGEDESC/RES_BREAK items for SwTextFrame,...
Definition: findfrm.cxx:762
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
SwTabFrame is one table in the document layout, containing rows (which contain cells).
Definition: tabfrm.hxx:49
SwTabFrame * FindMaster(bool bFirstMaster=false) const
Definition: flowfrm.cxx:798
const SwTabFrame * GetFollow() const
Definition: tabfrm.hxx:255
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:443
OUString GetName() const
Definition: swtable.cxx:2189
SwFrameFormat * GetFrameFormat()
Definition: swtable.hxx:481
const OUString & GetFormula() const
Definition: cellfml.hxx:137
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes()
const_iterator find(const Value &x) const
const_iterator end() const
bool IsAccessible(bool bPagePreview) const
Definition: accfrmobj.cxx:120
const SwFrame * GetSwFrame() const
Definition: accfrmobj.hxx:63
ColorTransparency
constexpr ::Color COL_AUTO(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
float u
#define SAL_WARN_IF(condition, area, stream)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
const char GetValue[]
unsigned char sal_Bool