fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / Accessibility / AccessiblePreviewHeaderCell.cxx
blob90e5e91bbd31b1998affcf4ab688c9b1bde8eff3
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 <memory>
23 #include <utility>
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.
32 #ifdef indices
33 #undef indices
34 #endif
35 #define indices dummy2_indices
37 #ifdef extents
38 #undef extents
39 #endif
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"
54 #include "sc.hrc"
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>
67 #ifdef indices
68 #undef indices
69 #endif
71 #ifdef extents
72 #undef extents
73 #endif
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,
84 sal_Int32 nIndex ) :
85 ScAccessibleContextBase( rxParent, AccessibleRole::TABLE_CELL ),
86 mpViewShell( pViewShell ),
87 mpTextHelper( NULL ),
88 mnIndex( nIndex ),
89 maCellPos( rCellPos ),
90 mbColumnHeader( bIsColHdr ),
91 mbRowHeader( bIsRowHdr ),
92 mpTableInfo( NULL )
94 if (mpViewShell)
95 mpViewShell->AddAccessibilityObject(*this);
98 ScAccessiblePreviewHeaderCell::~ScAccessiblePreviewHeaderCell()
100 if (mpViewShell)
101 mpViewShell->RemoveAccessibilityObject(*this);
104 void SAL_CALL ScAccessiblePreviewHeaderCell::disposing()
106 SolarMutexGuard aGuard;
107 if (mpViewShell)
109 mpViewShell->RemoveAccessibilityObject(*this);
110 mpViewShell = NULL;
113 if (mpTableInfo)
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);
124 if (pSimpleHint)
126 sal_uLong nId = pSimpleHint->GetId();
127 if (nId == SC_HINT_ACC_VISAREACHANGED)
129 if (mpTextHelper)
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()
153 throw ()
155 ScAccessibleContextBase::acquire();
158 void SAL_CALL ScAccessiblePreviewHeaderCell::release()
159 throw ()
161 ScAccessibleContextBase::release();
164 //===== XAccessibleValue ================================================
166 uno::Any SAL_CALL ScAccessiblePreviewHeaderCell::getCurrentValue() throw (uno::RuntimeException, std::exception)
168 SolarMutexGuard aGuard;
169 IsObjectValid();
171 double fValue(0.0);
172 if (mbColumnHeader)
173 fValue = maCellPos.Col();
174 else
175 fValue = maCellPos.Row();
177 uno::Any aAny;
178 aAny <<= fValue;
179 return aAny;
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
186 return false;
189 uno::Any SAL_CALL ScAccessiblePreviewHeaderCell::getMaximumValue() throw (uno::RuntimeException, std::exception)
191 SolarMutexGuard aGuard;
192 IsObjectValid();
194 double fValue(0.0);
195 if (mbColumnHeader)
196 fValue = MAXCOL;
197 else
198 fValue = MAXROW;
199 uno::Any aAny;
200 aAny <<= fValue;
201 return aAny;
204 uno::Any SAL_CALL ScAccessiblePreviewHeaderCell::getMinimumValue() throw (uno::RuntimeException, std::exception)
206 double fValue(0.0);
207 uno::Any aAny;
208 aAny <<= fValue;
209 return aAny;
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;
221 IsObjectValid();
223 if(!mpTextHelper)
224 CreateTextHelper();
226 xRet = mpTextHelper->GetAt(rPoint);
229 return xRet;
232 void SAL_CALL ScAccessiblePreviewHeaderCell::grabFocus() throw (uno::RuntimeException, std::exception)
234 SolarMutexGuard aGuard;
235 IsObjectValid();
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;
249 IsObjectValid();
250 if (!mpTextHelper)
251 CreateTextHelper();
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;
259 IsObjectValid();
260 if (!mpTextHelper)
261 CreateTextHelper();
262 return mpTextHelper->GetChild(nIndex);
265 sal_Int32 SAL_CALL ScAccessiblePreviewHeaderCell::getAccessibleIndexInParent() throw (uno::RuntimeException, std::exception)
267 return mnIndex;
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);
284 else
286 pStateSet->AddState(AccessibleStateType::ENABLED);
287 pStateSet->AddState(AccessibleStateType::MULTI_LINE);
288 if (isShowing())
289 pStateSet->AddState(AccessibleStateType::SHOWING);
290 pStateSet->AddState(AccessibleStateType::TRANSIENT);
291 if (isVisible())
292 pStateSet->AddState(AccessibleStateType::VISIBLE);
294 return pStateSet;
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";
313 return aSequence;
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)
335 Rectangle aCellRect;
337 FillTableInfo();
339 if (mpTableInfo)
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 );
347 if (mpViewShell)
349 vcl::Window* pWindow = mpViewShell->GetWindow();
350 if (pWindow)
352 Rectangle aRect = pWindow->GetWindowExtentsRelative(NULL);
353 aCellRect.setX(aCellRect.getX() + aRect.getX());
354 aCellRect.setY(aCellRect.getY() + aRect.getY());
357 return aCellRect;
360 Rectangle ScAccessiblePreviewHeaderCell::GetBoundingBox() const throw (uno::RuntimeException, std::exception)
362 FillTableInfo();
364 if (mpTableInfo)
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();
371 if (xAccParent.is())
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());
382 return aCellRect;
384 return Rectangle();
387 OUString SAL_CALL ScAccessiblePreviewHeaderCell::createAccessibleDescription() throw(uno::RuntimeException)
389 OUString sDescription = OUString(ScResId(STR_ACC_HEADERCELL_DESCR));
390 return sDescription;
393 OUString SAL_CALL ScAccessiblePreviewHeaderCell::createAccessibleName() throw(uno::RuntimeException, std::exception)
395 OUString sName = OUString(ScResId(STR_ACC_HEADERCELL_NAME));
397 if ( mbColumnHeader )
399 if ( mbRowHeader )
401 //! name for corner cell?
403 // sName = "Column/Row Header";
405 else
407 // name of column header
408 sName += ScColToAlpha( maCellPos.Col() );
411 else
413 // name of row header
414 sName += OUString::number( ( maCellPos.Row() + 1 ) );
417 return sName;
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()
428 if (!mpTextHelper)
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 )
443 Size aOutputSize;
444 vcl::Window* pWindow = mpViewShell->GetWindow();
445 if ( pWindow )
446 aOutputSize = pWindow->GetOutputSizePixel();
447 Point aPoint;
448 Rectangle aVisRect( aPoint, aOutputSize );
450 mpTableInfo = new ScPreviewTableInfo;
451 mpViewShell->GetLocationData().GetTableInfo( aVisRect, *mpTableInfo );
455 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */