1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <unotools/accessiblestatesethelper.hxx>
32 #include <editeng/brushitem.hxx>
33 #include <vcl/window.hxx>
34 #include <vcl/svapp.hxx>
35 #include <toolkit/helper/convert.hxx>
36 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
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
,
47 ScAccessibleCellBase( rxParent
, ( pViewShell
? &pViewShell
->GetDocument() : nullptr ), rCellAddress
, nIndex
),
48 mpViewShell( pViewShell
)
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
65 void SAL_CALL
ScAccessiblePreviewCell::disposing()
67 SolarMutexGuard aGuard
;
70 mpViewShell
->RemoveAccessibilityObject(*this);
71 mpViewShell
= nullptr;
76 ScAccessibleCellBase::disposing();
79 void ScAccessiblePreviewCell::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
81 if (rHint
.GetId() == SfxHintId::ScAccVisAreaChanged
)
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
;
103 xRet
= mpTextHelper
->GetAt(rPoint
);
109 void SAL_CALL
ScAccessiblePreviewCell::grabFocus()
111 SolarMutexGuard aGuard
;
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_Int32 SAL_CALL
ScAccessiblePreviewCell::getAccessibleChildCount()
125 SolarMutexGuard aGuard
;
129 return mpTextHelper
->GetChildCount();
132 uno::Reference
< XAccessible
> SAL_CALL
ScAccessiblePreviewCell::getAccessibleChild(sal_Int32 nIndex
)
134 SolarMutexGuard aGuard
;
138 return mpTextHelper
->GetChild(nIndex
);
141 uno::Reference
<XAccessibleStateSet
> SAL_CALL
ScAccessiblePreviewCell::getAccessibleStateSet()
143 SolarMutexGuard aGuard
;
145 uno::Reference
<XAccessibleStateSet
> xParentStates
;
146 if (getAccessibleParent().is())
148 uno::Reference
<XAccessibleContext
> xParentContext
= getAccessibleParent()->getAccessibleContext();
149 xParentStates
= xParentContext
->getAccessibleStateSet();
151 utl::AccessibleStateSetHelper
* pStateSet
= new utl::AccessibleStateSetHelper();
152 if (IsDefunc(xParentStates
))
153 pStateSet
->AddState(AccessibleStateType::DEFUNC
);
156 pStateSet
->AddState(AccessibleStateType::ENABLED
);
157 pStateSet
->AddState(AccessibleStateType::MULTI_LINE
);
159 pStateSet
->AddState(AccessibleStateType::OPAQUE
);
161 pStateSet
->AddState(AccessibleStateType::SHOWING
);
162 pStateSet
->AddState(AccessibleStateType::TRANSIENT
);
164 pStateSet
->AddState(AccessibleStateType::VISIBLE
);
165 // MANAGES_DESCENDANTS (for paragraphs)
166 pStateSet
->AddState(AccessibleStateType::MANAGES_DESCENDANTS
);
171 //===== XServiceInfo ====================================================
173 OUString SAL_CALL
ScAccessiblePreviewCell::getImplementationName()
175 return "ScAccessiblePreviewCell";
178 uno::Sequence
<OUString
> SAL_CALL
ScAccessiblePreviewCell::getSupportedServiceNames()
180 uno::Sequence
< OUString
> aSequence
= ScAccessibleContextBase::getSupportedServiceNames();
181 sal_Int32
nOldSize(aSequence
.getLength());
182 aSequence
.realloc(nOldSize
+ 1);
184 aSequence
[nOldSize
] = "com.sun.star.table.AccessibleCellView";
189 //===== XTypeProvider =======================================================
191 uno::Sequence
<sal_Int8
> SAL_CALL
192 ScAccessiblePreviewCell::getImplementationId()
194 return css::uno::Sequence
<sal_Int8
>();
197 //==== internal =========================================================
199 tools::Rectangle
ScAccessiblePreviewCell::GetBoundingBoxOnScreen() const
201 tools::Rectangle aCellRect
;
204 mpViewShell
->GetLocationData().GetCellPosition( maCellAddress
, aCellRect
);
205 vcl::Window
* pWindow
= mpViewShell
->GetWindow();
208 tools::Rectangle aRect
= pWindow
->GetWindowExtentsRelative(nullptr);
209 aCellRect
.setX(aCellRect
.getX() + aRect
.getX());
210 aCellRect
.setY(aCellRect
.getY() + aRect
.getY());
216 tools::Rectangle
ScAccessiblePreviewCell::GetBoundingBox() const
218 tools::Rectangle aCellRect
;
221 mpViewShell
->GetLocationData().GetCellPosition( maCellAddress
, aCellRect
);
222 uno::Reference
<XAccessible
> xAccParent
= const_cast<ScAccessiblePreviewCell
*>(this)->getAccessibleParent();
225 uno::Reference
<XAccessibleContext
> xAccParentContext
= xAccParent
->getAccessibleContext();
226 uno::Reference
<XAccessibleComponent
> xAccParentComp (xAccParentContext
, uno::UNO_QUERY
);
227 if (xAccParentComp
.is())
229 tools::Rectangle
aParentRect (VCLRectangle(xAccParentComp
->getBounds()));
230 aCellRect
.setX(aCellRect
.getX() - aParentRect
.getX());
231 aCellRect
.setY(aCellRect
.getY() - aParentRect
.getY());
238 bool ScAccessiblePreviewCell::IsDefunc(
239 const uno::Reference
<XAccessibleStateSet
>& rxParentStates
)
241 return ScAccessibleContextBase::IsDefunc() || (mpDoc
== nullptr) || (mpViewShell
== nullptr) || !getAccessibleParent().is() ||
242 (rxParentStates
.is() && rxParentStates
->contains(AccessibleStateType::DEFUNC
));
245 bool ScAccessiblePreviewCell::IsEditable(
246 const uno::Reference
<XAccessibleStateSet
>& /* rxParentStates */)
251 bool ScAccessiblePreviewCell::IsOpaque() const
253 // test whether there is a background color
254 //! could be moved to ScAccessibleCellBase
259 const SvxBrushItem
* pItem
= mpDoc
->GetAttr(maCellAddress
, ATTR_BACKGROUND
);
261 bOpaque
= pItem
->GetColor() != COL_TRANSPARENT
;
266 void ScAccessiblePreviewCell::CreateTextHelper()
271 mpTextHelper
.reset( new ::accessibility::AccessibleTextHelper(
272 std::make_unique
<ScAccessibilityEditSource
>(
273 std::make_unique
<ScAccessiblePreviewCellTextData
>(
274 mpViewShell
, maCellAddress
))) );
275 mpTextHelper
->SetEventSource( this );
277 // paragraphs in preview are transient
278 ::accessibility::AccessibleTextHelper::VectorOfStates aChildStates
;
279 aChildStates
.push_back( AccessibleStateType::TRANSIENT
);
280 mpTextHelper
->SetAdditionalChildStates( aChildStates
);
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */