| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 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/. |
| 8 |
* |
| 9 |
* This file incorporates work covered by the following license notice: |
| 10 |
* |
| 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 . |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <controls/table/AccessibleGridControl.hxx> |
| 21 |
#include <controls/table/AccessibleGridControlTable.hxx> |
| 22 |
#include <controls/table/AccessibleGridControlHeader.hxx> |
| 23 |
|
| 24 |
#include <com/sun/star/accessibility/AccessibleEventId.hpp> |
| 25 |
#include <com/sun/star/accessibility/AccessibleRole.hpp> |
| 26 |
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp> |
| 27 |
#include <utility> |
| 28 |
#include <vcl/svapp.hxx> |
| 29 |
#include <vcl/unohelp.hxx> |
| 30 |
|
| 31 |
namespace accessibility |
| 32 |
{ |
| 33 |
|
| 34 |
using namespace ::com::sun::star::uno; |
| 35 |
using namespace ::com::sun::star; |
| 36 |
using namespace ::com::sun::star::lang; |
| 37 |
using namespace ::com::sun::star::accessibility; |
| 38 |
using namespace ::vcl; |
| 39 |
|
| 40 |
AccessibleGridControl::AccessibleGridControl( |
| 41 |
const css::uno::Reference< css::accessibility::XAccessible >& _rxParent, |
| 42 |
svt::table::TableControl& _rTable) |
| 43 |
: AccessibleGridControlBase(_rxParent, _rTable, AccessibleTableControlObjType::GRIDCONTROL) |
| 44 |
{ |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
void SAL_CALL AccessibleGridControl::disposing() |
| 49 |
{ |
| 50 |
SolarMutexGuard g; |
| 51 |
|
| 52 |
if ( m_xTable.is() ) |
| 53 |
{ |
| 54 |
m_xTable->dispose(); |
| 55 |
m_xTable.clear(); |
| 56 |
} |
| 57 |
if ( m_xRowHeaderBar.is() ) |
| 58 |
{ |
| 59 |
m_xRowHeaderBar->dispose(); |
| 60 |
m_xRowHeaderBar.clear(); |
| 61 |
} |
| 62 |
if ( m_xColumnHeaderBar.is() ) |
| 63 |
{ |
| 64 |
m_xColumnHeaderBar->dispose(); |
| 65 |
m_xColumnHeaderBar.clear(); |
| 66 |
} |
| 67 |
AccessibleGridControlBase::disposing(); |
| 68 |
} |
| 69 |
|
| 70 |
sal_Int64 AccessibleGridControl::implGetAccessibleChildCount() |
| 71 |
{ |
| 72 |
return m_aTable.GetAccessibleControlCount(); |
| 73 |
} |
| 74 |
|
| 75 |
// css::accessibility::XAccessibleContext --------------------------------------------------------- |
| 76 |
|
| 77 |
|
| 78 |
sal_Int64 SAL_CALL AccessibleGridControl::getAccessibleChildCount() |
| 79 |
{ |
| 80 |
SolarMutexGuard aSolarGuard; |
| 81 |
ensureAlive(); |
| 82 |
return implGetAccessibleChildCount(); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
css::uno::Reference< css::accessibility::XAccessible > SAL_CALL |
| 87 |
AccessibleGridControl::getAccessibleChild( sal_Int64 nChildIndex ) |
| 88 |
{ |
| 89 |
SolarMutexGuard aSolarGuard; |
| 90 |
|
| 91 |
if (nChildIndex<0 || nChildIndex>=implGetAccessibleChildCount()) |
| 92 |
throw IndexOutOfBoundsException(); |
| 93 |
|
| 94 |
css::uno::Reference< css::accessibility::XAccessible > xChild; |
| 95 |
if (isAlive()) |
| 96 |
{ |
| 97 |
if(nChildIndex == 0 && m_aTable.HasColHeader()) |
| 98 |
{ |
| 99 |
if(!m_xColumnHeaderBar.is()) |
| 100 |
{ |
| 101 |
m_xColumnHeaderBar = new AccessibleGridControlHeader( |
| 102 |
this, m_aTable, AccessibleTableControlObjType::COLUMNHEADERBAR); |
| 103 |
} |
| 104 |
xChild = m_xColumnHeaderBar.get(); |
| 105 |
} |
| 106 |
else if(m_aTable.HasRowHeader() && (nChildIndex == 1 || nChildIndex == 0)) |
| 107 |
{ |
| 108 |
if(!m_xRowHeaderBar.is()) |
| 109 |
{ |
| 110 |
m_xRowHeaderBar = new AccessibleGridControlHeader( |
| 111 |
this, m_aTable, AccessibleTableControlObjType::ROWHEADERBAR); |
| 112 |
} |
| 113 |
xChild = m_xRowHeaderBar.get(); |
| 114 |
} |
| 115 |
else |
| 116 |
{ |
| 117 |
if(!m_xTable.is()) |
| 118 |
{ |
| 119 |
m_xTable = new AccessibleGridControlTable(this, m_aTable); |
| 120 |
} |
| 121 |
xChild = m_xTable.get(); |
| 122 |
} |
| 123 |
} |
| 124 |
return xChild; |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
sal_Int16 SAL_CALL AccessibleGridControl::getAccessibleRole() |
| 129 |
{ |
| 130 |
SolarMutexGuard g; |
| 131 |
|
| 132 |
ensureAlive(); |
| 133 |
return AccessibleRole::PANEL; |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
// css::accessibility::XAccessibleComponent ------------------------------------------------------- |
| 138 |
|
| 139 |
css::uno::Reference< css::accessibility::XAccessible > SAL_CALL |
| 140 |
AccessibleGridControl::getAccessibleAtPoint( const awt::Point& rPoint ) |
| 141 |
{ |
| 142 |
SolarMutexGuard aSolarGuard; |
| 143 |
ensureAlive(); |
| 144 |
|
| 145 |
// try whether point is in one of the fixed children |
| 146 |
// (table, header bars, corner control) |
| 147 |
Point aPoint(vcl::unohelper::ConvertToVCLPoint(rPoint)); |
| 148 |
const sal_Int64 nChildCount = implGetAccessibleChildCount(); |
| 149 |
for (sal_Int64 nIndex = 0; nIndex < nChildCount; ++nIndex) |
| 150 |
{ |
| 151 |
css::uno::Reference<css::accessibility::XAccessible> xCurrChild = getAccessibleChild(nIndex); |
| 152 |
css::uno::Reference<css::accessibility::XAccessibleComponent> xCurrChildComp( |
| 153 |
xCurrChild, uno::UNO_QUERY); |
| 154 |
|
| 155 |
if (xCurrChildComp.is() |
| 156 |
&& vcl::unohelper::ConvertToVCLRect(xCurrChildComp->getBounds()).Contains(aPoint)) |
| 157 |
return xCurrChild; |
| 158 |
} |
| 159 |
return nullptr; |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
void SAL_CALL AccessibleGridControl::grabFocus() |
| 164 |
{ |
| 165 |
SolarMutexGuard aSolarGuard; |
| 166 |
ensureAlive(); |
| 167 |
m_aTable.GrabFocus(); |
| 168 |
} |
| 169 |
|
| 170 |
// XServiceInfo --------------------------------------------------------------- |
| 171 |
OUString SAL_CALL AccessibleGridControl::getImplementationName() |
| 172 |
{ |
| 173 |
return u"com.sun.star.accessibility.AccessibleGridControl"_ustr; |
| 174 |
} |
| 175 |
|
| 176 |
// internal virtual methods --------------------------------------------------- |
| 177 |
|
| 178 |
AbsoluteScreenPixelRectangle AccessibleGridControl::implGetBoundingBoxOnScreen() |
| 179 |
{ |
| 180 |
return m_aTable.GetWindowExtentsAbsolute(); |
| 181 |
} |
| 182 |
|
| 183 |
// internal helper methods ---------------------------------------------------- |
| 184 |
|
| 185 |
void AccessibleGridControl::commitCellEvent(sal_Int16 _nEventId,const Any& _rNewValue,const Any& _rOldValue) |
| 186 |
{ |
| 187 |
sal_Int64 nChildCount = implGetAccessibleChildCount(); |
| 188 |
assert(nChildCount != 0); |
| 189 |
for (sal_Int64 i = 0; i < nChildCount; i++) |
| 190 |
{ |
| 191 |
css::uno::Reference<css::accessibility::XAccessible> xAccessible = getAccessibleChild(i); |
| 192 |
if (css::uno::Reference<css::accessibility::XAccessible>(m_xTable) == xAccessible) |
| 193 |
{ |
| 194 |
Reference<XAccessible> xCell = m_xTable->getAccessibleCellAt( |
| 195 |
m_aTable.GetCurrentRow(), m_aTable.GetCurrentColumn()); |
| 196 |
AccessibleGridControlTableCell* pCell |
| 197 |
= static_cast<AccessibleGridControlTableCell*>(xCell.get()); |
| 198 |
pCell->commitEvent(_nEventId, _rNewValue, _rOldValue); |
| 199 |
} |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
void AccessibleGridControl::commitTableEvent(sal_Int16 _nEventId,const Any& _rNewValue,const Any& _rOldValue) |
| 204 |
{ |
| 205 |
if ( !m_xTable.is() ) |
| 206 |
return; |
| 207 |
|
| 208 |
if(_nEventId == AccessibleEventId::ACTIVE_DESCENDANT_CHANGED) |
| 209 |
{ |
| 210 |
const sal_Int32 nCurrentRow = m_aTable.GetCurrentRow(); |
| 211 |
const sal_Int32 nCurrentCol = m_aTable.GetCurrentColumn(); |
| 212 |
css::uno::Reference< css::accessibility::XAccessible > xChild; |
| 213 |
if (nCurrentRow > -1 && nCurrentCol > -1) |
| 214 |
xChild = m_xTable->getAccessibleCellAt(nCurrentRow, nCurrentCol); |
| 215 |
|
| 216 |
m_xTable->commitEvent(_nEventId, Any(xChild),_rOldValue); |
| 217 |
} |
| 218 |
else |
| 219 |
m_xTable->commitEvent(_nEventId,_rNewValue,_rOldValue); |
| 220 |
} |
| 221 |
|
| 222 |
} // namespace accessibility |
| 223 |
|
| 224 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |