tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / Accessibility / AccessiblePreviewCell.cxx
blobc0aefc808cc8b45ac28f5e676025b8b22994f075
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 <scitems.hxx>
23 #include <tools/gen.hxx>
24 #include <AccessibleText.hxx>
25 #include <editsrc.hxx>
26 #include <AccessiblePreviewCell.hxx>
27 #include <prevwsh.hxx>
28 #include <prevloc.hxx>
29 #include <document.hxx>
30 #include <svx/AccessibleTextHelper.hxx>
31 #include <editeng/brushitem.hxx>
32 #include <vcl/window.hxx>
33 #include <vcl/svapp.hxx>
34 #include <vcl/unohelp.hxx>
35 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
36 #include <comphelper/sequence.hxx>
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::accessibility;
41 //===== internal ============================================================
43 ScAccessiblePreviewCell::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 )
50 if (mpViewShell)
51 mpViewShell->AddAccessibilityObject(*this);
54 ScAccessiblePreviewCell::~ScAccessiblePreviewCell()
56 if (!ScAccessibleContextBase::IsDefunc() && !rBHelper.bInDispose)
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();
65 void SAL_CALL ScAccessiblePreviewCell::disposing()
67 SolarMutexGuard aGuard;
68 if (mpViewShell)
70 mpViewShell->RemoveAccessibilityObject(*this);
71 mpViewShell = nullptr;
74 mpTextHelper.reset();
76 ScAccessibleCellBase::disposing();
79 void ScAccessiblePreviewCell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
81 if (rHint.GetId() == SfxHintId::ScAccVisAreaChanged)
83 if (mpTextHelper)
84 mpTextHelper->UpdateChildren();
87 ScAccessibleContextBase::Notify(rBC, rHint);
90 //===== XAccessibleComponent ============================================
92 uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewCell::getAccessibleAtPoint( const awt::Point& rPoint )
94 uno::Reference<XAccessible> xRet;
95 if (containsPoint(rPoint))
97 SolarMutexGuard aGuard;
98 IsObjectValid();
100 if(!mpTextHelper)
101 CreateTextHelper();
103 xRet = mpTextHelper->GetAt(rPoint);
106 return xRet;
109 void SAL_CALL ScAccessiblePreviewCell::grabFocus()
111 SolarMutexGuard aGuard;
112 IsObjectValid();
113 if (getAccessibleParent().is())
115 uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
116 if (xAccessibleComponent.is())
117 xAccessibleComponent->grabFocus();
121 //===== XAccessibleContext ==============================================
123 sal_Int64 SAL_CALL ScAccessiblePreviewCell::getAccessibleChildCount()
125 SolarMutexGuard aGuard;
126 IsObjectValid();
127 if (!mpTextHelper)
128 CreateTextHelper();
129 return mpTextHelper->GetChildCount();
132 uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewCell::getAccessibleChild(sal_Int64 nIndex)
134 SolarMutexGuard aGuard;
135 IsObjectValid();
136 if (!mpTextHelper)
137 CreateTextHelper();
138 return mpTextHelper->GetChild(nIndex);
141 sal_Int64 SAL_CALL ScAccessiblePreviewCell::getAccessibleStateSet()
143 SolarMutexGuard aGuard;
145 sal_Int64 nParentStates = 0;
146 if (getAccessibleParent().is())
148 uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
149 nParentStates = xParentContext->getAccessibleStateSet();
151 sal_Int64 nStateSet = 0;
152 if (IsDefunc(nParentStates))
153 nStateSet |= AccessibleStateType::DEFUNC;
154 else
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;
168 return nStateSet;
171 //===== XServiceInfo ====================================================
173 OUString SAL_CALL ScAccessiblePreviewCell::getImplementationName()
175 return u"ScAccessiblePreviewCell"_ustr;
178 uno::Sequence<OUString> SAL_CALL ScAccessiblePreviewCell::getSupportedServiceNames()
180 const css::uno::Sequence<OUString> vals { u"com.sun.star.table.AccessibleCellView"_ustr };
181 return comphelper::concatSequences(ScAccessibleContextBase::getSupportedServiceNames(), vals);
184 //===== XTypeProvider =======================================================
186 uno::Sequence<sal_Int8> SAL_CALL
187 ScAccessiblePreviewCell::getImplementationId()
189 return css::uno::Sequence<sal_Int8>();
192 //==== internal =========================================================
194 AbsoluteScreenPixelRectangle ScAccessiblePreviewCell::GetBoundingBoxOnScreen() const
196 tools::Rectangle aCellRect;
197 if (mpViewShell)
199 mpViewShell->GetLocationData().GetCellPosition( maCellAddress, aCellRect );
200 vcl::Window* pWindow = mpViewShell->GetWindow();
201 if (pWindow)
203 AbsoluteScreenPixelRectangle aRect = pWindow->GetWindowExtentsAbsolute();
204 aCellRect.Move(aRect.Left(), aRect.Top());
207 return AbsoluteScreenPixelRectangle(aCellRect);
210 tools::Rectangle ScAccessiblePreviewCell::GetBoundingBox() const
212 tools::Rectangle aCellRect;
213 if (mpViewShell)
215 mpViewShell->GetLocationData().GetCellPosition( maCellAddress, aCellRect );
216 uno::Reference<XAccessible> xAccParent = const_cast<ScAccessiblePreviewCell*>(this)->getAccessibleParent();
217 if (xAccParent.is())
219 uno::Reference<XAccessibleContext> xAccParentContext = xAccParent->getAccessibleContext();
220 uno::Reference<XAccessibleComponent> xAccParentComp (xAccParentContext, uno::UNO_QUERY);
221 if (xAccParentComp.is())
223 tools::Rectangle aParentRect(
224 vcl::unohelper::ConvertToVCLRect(xAccParentComp->getBounds()));
225 aCellRect.Move(-aParentRect.Left(), -aParentRect.Top());
229 return aCellRect;
232 bool ScAccessiblePreviewCell::IsDefunc(sal_Int64 nParentStates)
234 return ScAccessibleContextBase::IsDefunc() || (mpDoc == nullptr) || (mpViewShell == nullptr) || !getAccessibleParent().is() ||
235 (nParentStates & AccessibleStateType::DEFUNC);
238 bool ScAccessiblePreviewCell::IsEditable(sal_Int64 /* nParentStates */)
240 return false;
243 bool ScAccessiblePreviewCell::IsOpaque() const
245 // test whether there is a background color
246 //! could be moved to ScAccessibleCellBase
248 bool bOpaque(true);
249 if (mpDoc)
251 const SvxBrushItem* pItem = mpDoc->GetAttr(maCellAddress, ATTR_BACKGROUND);
252 if (pItem)
253 bOpaque = pItem->GetColor() != COL_TRANSPARENT;
255 return bOpaque;
258 void ScAccessiblePreviewCell::CreateTextHelper()
260 if (mpTextHelper)
261 return;
263 mpTextHelper.reset( new ::accessibility::AccessibleTextHelper(
264 std::make_unique<ScAccessibilityEditSource>(
265 std::make_unique<ScAccessiblePreviewCellTextData>(
266 mpViewShell, maCellAddress))) );
267 mpTextHelper->SetEventSource( this );
269 // paragraphs in preview are transient
270 mpTextHelper->SetAdditionalChildStates( AccessibleStateType::TRANSIENT );
273 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */