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>
25 /* Somehow, under same circumstances, MSVC creates object code for 2
26 * inlined functions. Nobody here uses them, so simply define them away
27 * so that there be no dupplicate symbols anymore.
29 * The symbols "extents" and "indices" come from boost::multi_array.
35 #define indices dummy2_indices
40 #define extents dummy2_extents
42 #include "scitems.hxx"
43 #include <editeng/eeitem.hxx>
44 #include <tools/gen.hxx>
45 #include "AccessibleText.hxx"
46 #include "editsrc.hxx"
47 #include <svx/AccessibleTextHelper.hxx>
48 #include "AccessiblePreviewHeaderCell.hxx"
49 #include "AccessibilityHints.hxx"
50 #include "prevwsh.hxx"
51 #include "miscuno.hxx"
52 #include "prevloc.hxx"
53 #include "scresid.hxx"
56 #include <com/sun/star/accessibility/AccessibleRole.hpp>
57 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
59 #include <vcl/window.hxx>
60 #include <vcl/svapp.hxx>
61 #include <svl/smplhint.hxx>
62 #include <unotools/accessiblestatesethelper.hxx>
63 #include <comphelper/sequence.hxx>
64 #include <comphelper/servicehelper.hxx>
65 #include <toolkit/helper/convert.hxx>
75 using namespace ::com::sun::star
;
76 using namespace ::com::sun::star::accessibility
;
78 //===== internal ============================================================
80 ScAccessiblePreviewHeaderCell::ScAccessiblePreviewHeaderCell( const ::com::sun::star::uno::Reference
<
81 ::com::sun::star::accessibility::XAccessible
>& rxParent
,
82 ScPreviewShell
* pViewShell
,
83 const ScAddress
& rCellPos
, bool bIsColHdr
, bool bIsRowHdr
,
85 ScAccessibleContextBase( rxParent
, AccessibleRole::TABLE_CELL
),
86 mpViewShell( pViewShell
),
89 maCellPos( rCellPos
),
90 mbColumnHeader( bIsColHdr
),
91 mbRowHeader( bIsRowHdr
),
95 mpViewShell
->AddAccessibilityObject(*this);
98 ScAccessiblePreviewHeaderCell::~ScAccessiblePreviewHeaderCell()
101 mpViewShell
->RemoveAccessibilityObject(*this);
104 void SAL_CALL
ScAccessiblePreviewHeaderCell::disposing()
106 SolarMutexGuard aGuard
;
109 mpViewShell
->RemoveAccessibilityObject(*this);
114 DELETEZ (mpTableInfo
);
116 ScAccessibleContextBase::disposing();
119 //===== SfxListener =====================================================
121 void ScAccessiblePreviewHeaderCell::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
123 const SfxSimpleHint
* pSimpleHint
= dynamic_cast<const SfxSimpleHint
*>(&rHint
);
126 sal_uLong nId
= pSimpleHint
->GetId();
127 if (nId
== SC_HINT_ACC_VISAREACHANGED
)
130 mpTextHelper
->UpdateChildren();
132 else if ( nId
== SFX_HINT_DATACHANGED
)
134 // column / row layout may change with any document change,
135 // so it must be invalidated
136 DELETEZ( mpTableInfo
);
140 ScAccessibleContextBase::Notify(rBC
, rHint
);
143 //===== XInterface =====================================================
145 uno::Any SAL_CALL
ScAccessiblePreviewHeaderCell::queryInterface( uno::Type
const & rType
)
146 throw (uno::RuntimeException
, std::exception
)
148 uno::Any
aAny (ScAccessiblePreviewHeaderCellImpl::queryInterface(rType
));
149 return aAny
.hasValue() ? aAny
: ScAccessibleContextBase::queryInterface(rType
);
152 void SAL_CALL
ScAccessiblePreviewHeaderCell::acquire()
155 ScAccessibleContextBase::acquire();
158 void SAL_CALL
ScAccessiblePreviewHeaderCell::release()
161 ScAccessibleContextBase::release();
164 //===== XAccessibleValue ================================================
166 uno::Any SAL_CALL
ScAccessiblePreviewHeaderCell::getCurrentValue() throw (uno::RuntimeException
, std::exception
)
168 SolarMutexGuard aGuard
;
173 fValue
= maCellPos
.Col();
175 fValue
= maCellPos
.Row();
182 sal_Bool SAL_CALL
ScAccessiblePreviewHeaderCell::setCurrentValue( const uno::Any
& /* aNumber */ )
183 throw (uno::RuntimeException
, std::exception
)
185 // it is not possible to set a value
189 uno::Any SAL_CALL
ScAccessiblePreviewHeaderCell::getMaximumValue() throw (uno::RuntimeException
, std::exception
)
191 SolarMutexGuard aGuard
;
204 uno::Any SAL_CALL
ScAccessiblePreviewHeaderCell::getMinimumValue() throw (uno::RuntimeException
, std::exception
)
212 //===== XAccessibleComponent ============================================
214 uno::Reference
< XAccessible
> SAL_CALL
ScAccessiblePreviewHeaderCell::getAccessibleAtPoint( const awt::Point
& rPoint
)
215 throw (uno::RuntimeException
, std::exception
)
217 uno::Reference
<XAccessible
> xRet
;
218 if (containsPoint(rPoint
))
220 SolarMutexGuard aGuard
;
226 xRet
= mpTextHelper
->GetAt(rPoint
);
232 void SAL_CALL
ScAccessiblePreviewHeaderCell::grabFocus() throw (uno::RuntimeException
, std::exception
)
234 SolarMutexGuard aGuard
;
236 if (getAccessibleParent().is())
238 uno::Reference
<XAccessibleComponent
> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY
);
239 if (xAccessibleComponent
.is())
240 xAccessibleComponent
->grabFocus();
244 //===== XAccessibleContext ==============================================
246 sal_Int32 SAL_CALL
ScAccessiblePreviewHeaderCell::getAccessibleChildCount() throw(uno::RuntimeException
, std::exception
)
248 SolarMutexGuard aGuard
;
252 return mpTextHelper
->GetChildCount();
255 uno::Reference
< XAccessible
> SAL_CALL
ScAccessiblePreviewHeaderCell::getAccessibleChild(sal_Int32 nIndex
)
256 throw (uno::RuntimeException
, lang::IndexOutOfBoundsException
, std::exception
)
258 SolarMutexGuard aGuard
;
262 return mpTextHelper
->GetChild(nIndex
);
265 sal_Int32 SAL_CALL
ScAccessiblePreviewHeaderCell::getAccessibleIndexInParent() throw (uno::RuntimeException
, std::exception
)
270 uno::Reference
<XAccessibleStateSet
> SAL_CALL
ScAccessiblePreviewHeaderCell::getAccessibleStateSet()
271 throw(uno::RuntimeException
, std::exception
)
273 SolarMutexGuard aGuard
;
275 uno::Reference
<XAccessibleStateSet
> xParentStates
;
276 if (getAccessibleParent().is())
278 uno::Reference
<XAccessibleContext
> xParentContext
= getAccessibleParent()->getAccessibleContext();
279 xParentStates
= xParentContext
->getAccessibleStateSet();
281 utl::AccessibleStateSetHelper
* pStateSet
= new utl::AccessibleStateSetHelper();
282 if (IsDefunc(xParentStates
))
283 pStateSet
->AddState(AccessibleStateType::DEFUNC
);
286 pStateSet
->AddState(AccessibleStateType::ENABLED
);
287 pStateSet
->AddState(AccessibleStateType::MULTI_LINE
);
289 pStateSet
->AddState(AccessibleStateType::SHOWING
);
290 pStateSet
->AddState(AccessibleStateType::TRANSIENT
);
292 pStateSet
->AddState(AccessibleStateType::VISIBLE
);
297 //===== XServiceInfo ====================================================
299 OUString SAL_CALL
ScAccessiblePreviewHeaderCell::getImplementationName() throw(uno::RuntimeException
, std::exception
)
301 return OUString("ScAccessiblePreviewHeaderCell");
304 uno::Sequence
<OUString
> SAL_CALL
ScAccessiblePreviewHeaderCell::getSupportedServiceNames()
305 throw(uno::RuntimeException
, std::exception
)
307 uno::Sequence
< OUString
> aSequence
= ScAccessibleContextBase::getSupportedServiceNames();
308 sal_Int32
nOldSize(aSequence
.getLength());
309 aSequence
.realloc(nOldSize
+ 1);
311 aSequence
[nOldSize
] = "com.sun.star.table.AccessibleCellView";
316 //===== XTypeProvider =======================================================
318 uno::Sequence
< uno::Type
> SAL_CALL
ScAccessiblePreviewHeaderCell::getTypes()
319 throw (uno::RuntimeException
, std::exception
)
321 return comphelper::concatSequences(ScAccessiblePreviewHeaderCellImpl::getTypes(), ScAccessibleContextBase::getTypes());
324 uno::Sequence
<sal_Int8
> SAL_CALL
325 ScAccessiblePreviewHeaderCell::getImplementationId()
326 throw (uno::RuntimeException
, std::exception
)
328 return css::uno::Sequence
<sal_Int8
>();
331 //==== internal =========================================================
333 Rectangle
ScAccessiblePreviewHeaderCell::GetBoundingBoxOnScreen() const throw (uno::RuntimeException
, std::exception
)
341 const ScPreviewColRowInfo
& rColInfo
= mpTableInfo
->GetColInfo()[maCellPos
.Col()];
342 const ScPreviewColRowInfo
& rRowInfo
= mpTableInfo
->GetRowInfo()[maCellPos
.Row()];
344 aCellRect
= Rectangle( rColInfo
.nPixelStart
, rRowInfo
.nPixelStart
, rColInfo
.nPixelEnd
, rRowInfo
.nPixelEnd
);
349 vcl::Window
* pWindow
= mpViewShell
->GetWindow();
352 Rectangle aRect
= pWindow
->GetWindowExtentsRelative(NULL
);
353 aCellRect
.setX(aCellRect
.getX() + aRect
.getX());
354 aCellRect
.setY(aCellRect
.getY() + aRect
.getY());
360 Rectangle
ScAccessiblePreviewHeaderCell::GetBoundingBox() const throw (uno::RuntimeException
, std::exception
)
366 const ScPreviewColRowInfo
& rColInfo
= mpTableInfo
->GetColInfo()[maCellPos
.Col()];
367 const ScPreviewColRowInfo
& rRowInfo
= mpTableInfo
->GetRowInfo()[maCellPos
.Row()];
369 Rectangle
aCellRect( rColInfo
.nPixelStart
, rRowInfo
.nPixelStart
, rColInfo
.nPixelEnd
, rRowInfo
.nPixelEnd
);
370 uno::Reference
<XAccessible
> xAccParent
= const_cast<ScAccessiblePreviewHeaderCell
*>(this)->getAccessibleParent();
373 uno::Reference
<XAccessibleContext
> xAccParentContext
= xAccParent
->getAccessibleContext();
374 uno::Reference
<XAccessibleComponent
> xAccParentComp (xAccParentContext
, uno::UNO_QUERY
);
375 if (xAccParentComp
.is())
377 Rectangle
aParentRect (VCLRectangle(xAccParentComp
->getBounds()));
378 aCellRect
.setX(aCellRect
.getX() - aParentRect
.getX());
379 aCellRect
.setY(aCellRect
.getY() - aParentRect
.getY());
387 OUString SAL_CALL
ScAccessiblePreviewHeaderCell::createAccessibleDescription() throw(uno::RuntimeException
)
389 OUString sDescription
= OUString(ScResId(STR_ACC_HEADERCELL_DESCR
));
393 OUString SAL_CALL
ScAccessiblePreviewHeaderCell::createAccessibleName() throw(uno::RuntimeException
, std::exception
)
395 OUString sName
= OUString(ScResId(STR_ACC_HEADERCELL_NAME
));
397 if ( mbColumnHeader
)
401 //! name for corner cell?
403 // sName = "Column/Row Header";
407 // name of column header
408 sName
+= ScColToAlpha( maCellPos
.Col() );
413 // name of row header
414 sName
+= OUString::number( ( maCellPos
.Row() + 1 ) );
420 bool ScAccessiblePreviewHeaderCell::IsDefunc( const uno::Reference
<XAccessibleStateSet
>& rxParentStates
)
422 return ScAccessibleContextBase::IsDefunc() || (mpViewShell
== NULL
) || !getAccessibleParent().is() ||
423 (rxParentStates
.is() && rxParentStates
->contains(AccessibleStateType::DEFUNC
));
426 void ScAccessiblePreviewHeaderCell::CreateTextHelper()
430 ::std::unique_ptr
< ScAccessibleTextData
> pAccessiblePreviewHeaderCellTextData
431 (new ScAccessiblePreviewHeaderCellTextData(mpViewShell
, OUString(getAccessibleName()), maCellPos
, mbColumnHeader
, mbRowHeader
));
432 ::std::unique_ptr
< SvxEditSource
> pEditSource (new ScAccessibilityEditSource(std::move(pAccessiblePreviewHeaderCellTextData
)));
434 mpTextHelper
= new ::accessibility::AccessibleTextHelper(std::move(pEditSource
));
435 mpTextHelper
->SetEventSource(this);
439 void ScAccessiblePreviewHeaderCell::FillTableInfo() const
441 if ( mpViewShell
&& !mpTableInfo
)
444 vcl::Window
* pWindow
= mpViewShell
->GetWindow();
446 aOutputSize
= pWindow
->GetOutputSizePixel();
448 Rectangle
aVisRect( aPoint
, aOutputSize
);
450 mpTableInfo
= new ScPreviewTableInfo
;
451 mpViewShell
->GetLocationData().GetTableInfo( aVisRect
, *mpTableInfo
);
455 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */