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 <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>
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
,
58 ScAccessibleContextBase( rxParent
, AccessibleRole::TABLE_CELL
),
59 mpViewShell( pViewShell
),
61 maCellPos( rCellPos
),
62 mbColumnHeader( bIsColHdr
),
63 mbRowHeader( bIsRowHdr
)
66 mpViewShell
->AddAccessibilityObject(*this);
69 ScAccessiblePreviewHeaderCell::~ScAccessiblePreviewHeaderCell()
72 mpViewShell
->RemoveAccessibilityObject(*this);
75 void SAL_CALL
ScAccessiblePreviewHeaderCell::disposing()
77 SolarMutexGuard aGuard
;
80 mpViewShell
->RemoveAccessibilityObject(*this);
81 mpViewShell
= nullptr;
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
)
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
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()
120 ScAccessibleContextBase::acquire();
123 void SAL_CALL
ScAccessiblePreviewHeaderCell::release()
126 ScAccessibleContextBase::release();
129 //===== XAccessibleValue ================================================
131 uno::Any SAL_CALL
ScAccessiblePreviewHeaderCell::getCurrentValue()
133 SolarMutexGuard aGuard
;
138 fValue
= maCellPos
.Col();
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
151 uno::Any SAL_CALL
ScAccessiblePreviewHeaderCell::getMaximumValue()
153 SolarMutexGuard aGuard
;
157 ScDocument
& rDoc
= mpViewShell
->GetDocument();
159 fValue
= rDoc
.MaxCol();
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'
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
;
189 xRet
= mxTextHelper
->GetAt(rPoint
);
195 void SAL_CALL
ScAccessiblePreviewHeaderCell::grabFocus()
197 SolarMutexGuard aGuard
;
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
;
215 return mxTextHelper
->GetChildCount();
218 uno::Reference
< XAccessible
> SAL_CALL
ScAccessiblePreviewHeaderCell::getAccessibleChild(sal_Int64 nIndex
)
220 SolarMutexGuard aGuard
;
224 return mxTextHelper
->GetChild(nIndex
);
227 sal_Int64 SAL_CALL
ScAccessiblePreviewHeaderCell::getAccessibleIndexInParent()
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
;
247 nStateSet
|= AccessibleStateType::ENABLED
;
248 nStateSet
|= AccessibleStateType::MULTI_LINE
;
250 nStateSet
|= AccessibleStateType::SHOWING
;
251 nStateSet
|= AccessibleStateType::TRANSIENT
;
253 nStateSet
|= AccessibleStateType::VISIBLE
;
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
;
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
);
302 vcl::Window
* pWindow
= mpViewShell
->GetWindow();
305 AbsoluteScreenPixelRectangle aRect
= pWindow
->GetWindowExtentsAbsolute();
306 aCellRect
.Move(aRect
.Left(), aRect
.Top());
309 return AbsoluteScreenPixelRectangle(aCellRect
);
312 tools::Rectangle
ScAccessiblePreviewHeaderCell::GetBoundingBox() const
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();
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());
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
)
352 //! name for corner cell?
354 // sName = "Column/Row Header";
358 // name of column header
359 sName
+= ScColToAlpha( maCellPos
.Col() );
364 // name of row header
365 sName
+= OUString::number( maCellPos
.Row() + 1 );
371 bool ScAccessiblePreviewHeaderCell::IsDefunc( sal_Int64 nParentStates
)
373 return ScAccessibleContextBase::IsDefunc() || (mpViewShell
== nullptr) || !getAccessibleParent().is() ||
374 (nParentStates
& AccessibleStateType::DEFUNC
);
377 void ScAccessiblePreviewHeaderCell::CreateTextHelper()
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
)
395 vcl::Window
* pWindow
= mpViewShell
->GetWindow();
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: */