tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / Accessibility / AccessiblePreviewHeaderCell.cxx
blob670d45ff0cb9eeb49e6a5f3857059aa5a8ea9179
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <tools/gen.hxx>
23 #include <AccessibleText.hxx>
24 #include <editsrc.hxx>
25 #include <svx/AccessibleTextHelper.hxx>
26 #include <AccessiblePreviewHeaderCell.hxx>
27 #include <prevwsh.hxx>
28 #include <prevloc.hxx>
29 #include <strings.hxx>
31 #include <com/sun/star/accessibility/AccessibleRole.hpp>
32 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
33 #include <comphelper/sequence.hxx>
35 #include <vcl/window.hxx>
36 #include <vcl/svapp.hxx>
37 #include <vcl/unohelp.hxx>
38 #include <svl/hint.hxx>
39 #include <toolkit/helper/vclunohelper.hxx>
41 #ifdef indices
42 #undef indices
43 #endif
45 #ifdef extents
46 #undef extents
47 #endif
49 using namespace ::com::sun::star;
50 using namespace ::com::sun::star::accessibility;
52 //===== internal ============================================================
54 ScAccessiblePreviewHeaderCell::ScAccessiblePreviewHeaderCell( const css::uno::Reference<css::accessibility::XAccessible>& rxParent,
55 ScPreviewShell* pViewShell,
56 const ScAddress& rCellPos, bool bIsColHdr, bool bIsRowHdr,
57 sal_Int32 nIndex ) :
58 ScAccessibleContextBase( rxParent, AccessibleRole::TABLE_CELL ),
59 mpViewShell( pViewShell ),
60 mnIndex( nIndex ),
61 maCellPos( rCellPos ),
62 mbColumnHeader( bIsColHdr ),
63 mbRowHeader( bIsRowHdr )
65 if (mpViewShell)
66 mpViewShell->AddAccessibilityObject(*this);
69 ScAccessiblePreviewHeaderCell::~ScAccessiblePreviewHeaderCell()
71 if (mpViewShell)
72 mpViewShell->RemoveAccessibilityObject(*this);
75 void SAL_CALL ScAccessiblePreviewHeaderCell::disposing()
77 SolarMutexGuard aGuard;
78 if (mpViewShell)
80 mpViewShell->RemoveAccessibilityObject(*this);
81 mpViewShell = nullptr;
84 mpTableInfo.reset();
86 ScAccessibleContextBase::disposing();
89 //===== SfxListener =====================================================
91 void ScAccessiblePreviewHeaderCell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
93 const SfxHintId nId = rHint.GetId();
94 if (nId == SfxHintId::ScAccVisAreaChanged)
96 if (mxTextHelper)
97 mxTextHelper->UpdateChildren();
99 else if ( nId == SfxHintId::DataChanged )
101 // column / row layout may change with any document change,
102 // so it must be invalidated
103 mpTableInfo.reset();
106 ScAccessibleContextBase::Notify(rBC, rHint);
109 //===== XInterface =====================================================
111 uno::Any SAL_CALL ScAccessiblePreviewHeaderCell::queryInterface( uno::Type const & rType )
113 uno::Any aAny (ScAccessiblePreviewHeaderCellImpl::queryInterface(rType));
114 return aAny.hasValue() ? aAny : ScAccessibleContextBase::queryInterface(rType);
117 void SAL_CALL ScAccessiblePreviewHeaderCell::acquire()
118 noexcept
120 ScAccessibleContextBase::acquire();
123 void SAL_CALL ScAccessiblePreviewHeaderCell::release()
124 noexcept
126 ScAccessibleContextBase::release();
129 //===== XAccessibleValue ================================================
131 uno::Any SAL_CALL ScAccessiblePreviewHeaderCell::getCurrentValue()
133 SolarMutexGuard aGuard;
134 IsObjectValid();
136 double fValue(0.0);
137 if (mbColumnHeader)
138 fValue = maCellPos.Col();
139 else
140 fValue = maCellPos.Row();
142 return uno::Any(fValue);
145 sal_Bool SAL_CALL ScAccessiblePreviewHeaderCell::setCurrentValue( const uno::Any& /* aNumber */ )
147 // it is not possible to set a value
148 return false;
151 uno::Any SAL_CALL ScAccessiblePreviewHeaderCell::getMaximumValue()
153 SolarMutexGuard aGuard;
154 IsObjectValid();
156 double fValue(0.0);
157 ScDocument& rDoc = mpViewShell->GetDocument();
158 if (mbColumnHeader)
159 fValue = rDoc.MaxCol();
160 else
161 fValue = rDoc.MaxRow();
162 return uno::Any(fValue);
165 uno::Any SAL_CALL ScAccessiblePreviewHeaderCell::getMinimumValue()
167 return uno::Any(0.0);
170 uno::Any SAL_CALL ScAccessiblePreviewHeaderCell::getMinimumIncrement()
172 // value can't be changed, s. 'setCurrentValue'
173 return uno::Any();
176 //===== XAccessibleComponent ============================================
178 uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleAtPoint( const awt::Point& rPoint )
180 uno::Reference<XAccessible> xRet;
181 if (containsPoint(rPoint))
183 SolarMutexGuard aGuard;
184 IsObjectValid();
186 if(!mxTextHelper)
187 CreateTextHelper();
189 xRet = mxTextHelper->GetAt(rPoint);
192 return xRet;
195 void SAL_CALL ScAccessiblePreviewHeaderCell::grabFocus()
197 SolarMutexGuard aGuard;
198 IsObjectValid();
199 if (getAccessibleParent().is())
201 uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
202 if (xAccessibleComponent.is())
203 xAccessibleComponent->grabFocus();
207 //===== XAccessibleContext ==============================================
209 sal_Int64 SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleChildCount()
211 SolarMutexGuard aGuard;
212 IsObjectValid();
213 if (!mxTextHelper)
214 CreateTextHelper();
215 return mxTextHelper->GetChildCount();
218 uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleChild(sal_Int64 nIndex)
220 SolarMutexGuard aGuard;
221 IsObjectValid();
222 if (!mxTextHelper)
223 CreateTextHelper();
224 return mxTextHelper->GetChild(nIndex);
227 sal_Int64 SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleIndexInParent()
229 return mnIndex;
232 sal_Int64 SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleStateSet()
234 SolarMutexGuard aGuard;
236 sal_Int64 nParentStates = 0;
237 if (getAccessibleParent().is())
239 uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
240 nParentStates = xParentContext->getAccessibleStateSet();
242 sal_Int64 nStateSet = 0;
243 if (IsDefunc(nParentStates))
244 nStateSet |= AccessibleStateType::DEFUNC;
245 else
247 nStateSet |= AccessibleStateType::ENABLED;
248 nStateSet |= AccessibleStateType::MULTI_LINE;
249 if (isShowing())
250 nStateSet |= AccessibleStateType::SHOWING;
251 nStateSet |= AccessibleStateType::TRANSIENT;
252 if (isVisible())
253 nStateSet |= AccessibleStateType::VISIBLE;
255 return nStateSet;
258 //===== XServiceInfo ====================================================
260 OUString SAL_CALL ScAccessiblePreviewHeaderCell::getImplementationName()
262 return u"ScAccessiblePreviewHeaderCell"_ustr;
265 uno::Sequence<OUString> SAL_CALL ScAccessiblePreviewHeaderCell::getSupportedServiceNames()
267 const css::uno::Sequence<OUString> vals { u"com.sun.star.table.AccessibleCellView"_ustr };
268 return comphelper::concatSequences(ScAccessibleContextBase::getSupportedServiceNames(), vals);
271 //===== XTypeProvider =======================================================
273 uno::Sequence< uno::Type > SAL_CALL ScAccessiblePreviewHeaderCell::getTypes()
275 return comphelper::concatSequences(ScAccessiblePreviewHeaderCellImpl::getTypes(), ScAccessibleContextBase::getTypes());
278 uno::Sequence<sal_Int8> SAL_CALL
279 ScAccessiblePreviewHeaderCell::getImplementationId()
281 return css::uno::Sequence<sal_Int8>();
284 //==== internal =========================================================
286 AbsoluteScreenPixelRectangle ScAccessiblePreviewHeaderCell::GetBoundingBoxOnScreen() const
288 tools::Rectangle aCellRect;
290 FillTableInfo();
292 if (mpTableInfo)
294 const ScPreviewColRowInfo& rColInfo = mpTableInfo->GetColInfo()[maCellPos.Col()];
295 const ScPreviewColRowInfo& rRowInfo = mpTableInfo->GetRowInfo()[maCellPos.Row()];
297 aCellRect = tools::Rectangle( rColInfo.nPixelStart, rRowInfo.nPixelStart, rColInfo.nPixelEnd, rRowInfo.nPixelEnd );
300 if (mpViewShell)
302 vcl::Window* pWindow = mpViewShell->GetWindow();
303 if (pWindow)
305 AbsoluteScreenPixelRectangle aRect = pWindow->GetWindowExtentsAbsolute();
306 aCellRect.Move(aRect.Left(), aRect.Top());
309 return AbsoluteScreenPixelRectangle(aCellRect);
312 tools::Rectangle ScAccessiblePreviewHeaderCell::GetBoundingBox() const
314 FillTableInfo();
316 if (mpTableInfo)
318 const ScPreviewColRowInfo& rColInfo = mpTableInfo->GetColInfo()[maCellPos.Col()];
319 const ScPreviewColRowInfo& rRowInfo = mpTableInfo->GetRowInfo()[maCellPos.Row()];
321 tools::Rectangle aCellRect( rColInfo.nPixelStart, rRowInfo.nPixelStart, rColInfo.nPixelEnd, rRowInfo.nPixelEnd );
322 uno::Reference<XAccessible> xAccParent = const_cast<ScAccessiblePreviewHeaderCell*>(this)->getAccessibleParent();
323 if (xAccParent.is())
325 uno::Reference<XAccessibleContext> xAccParentContext = xAccParent->getAccessibleContext();
326 uno::Reference<XAccessibleComponent> xAccParentComp (xAccParentContext, uno::UNO_QUERY);
327 if (xAccParentComp.is())
329 tools::Rectangle aParentRect(
330 vcl::unohelper::ConvertToVCLRect(xAccParentComp->getBounds()));
331 aCellRect.Move(-aParentRect.Left(), -aParentRect.Top());
334 return aCellRect;
336 return tools::Rectangle();
339 OUString ScAccessiblePreviewHeaderCell::createAccessibleDescription()
341 return STR_ACC_HEADERCELL_DESCR;
344 OUString ScAccessiblePreviewHeaderCell::createAccessibleName()
346 OUString sName = STR_ACC_HEADERCELL_NAME;
348 if ( mbColumnHeader )
350 if ( mbRowHeader )
352 //! name for corner cell?
354 // sName = "Column/Row Header";
356 else
358 // name of column header
359 sName += ScColToAlpha( maCellPos.Col() );
362 else
364 // name of row header
365 sName += OUString::number( maCellPos.Row() + 1 );
368 return sName;
371 bool ScAccessiblePreviewHeaderCell::IsDefunc( sal_Int64 nParentStates )
373 return ScAccessibleContextBase::IsDefunc() || (mpViewShell == nullptr) || !getAccessibleParent().is() ||
374 (nParentStates & AccessibleStateType::DEFUNC);
377 void ScAccessiblePreviewHeaderCell::CreateTextHelper()
379 if (!mxTextHelper)
381 mxTextHelper.reset( new ::accessibility::AccessibleTextHelper(
382 std::make_unique<ScAccessibilityEditSource>(
383 std::make_unique<ScAccessiblePreviewHeaderCellTextData>(
384 mpViewShell, getAccessibleName(), maCellPos,
385 mbColumnHeader, mbRowHeader))) );
386 mxTextHelper->SetEventSource(this);
390 void ScAccessiblePreviewHeaderCell::FillTableInfo() const
392 if ( mpViewShell && !mpTableInfo )
394 Size aOutputSize;
395 vcl::Window* pWindow = mpViewShell->GetWindow();
396 if ( pWindow )
397 aOutputSize = pWindow->GetOutputSizePixel();
398 tools::Rectangle aVisRect( Point(), aOutputSize );
400 mpTableInfo.reset( new ScPreviewTableInfo );
401 mpViewShell->GetLocationData().GetTableInfo( aVisRect, *mpTableInfo );
405 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */