| 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ |
| 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 <QtAccessibleWidget.hxx> |
| 21 | #include <QtAccessibleWidget.moc> |
| 22 | |
| 23 | #include <QtGui/QAccessibleInterface> |
| 24 | |
| 25 | #include <QtAccessibleEventListener.hxx> |
| 26 | #include <QtAccessibleRegistry.hxx> |
| 27 | #include <QtFrame.hxx> |
| 28 | #include <QtTools.hxx> |
| 29 | #include <QtWidget.hxx> |
| 30 | #include <QtXAccessible.hxx> |
| 31 | |
| 32 | #include <com/sun/star/accessibility/AccessibleRelationType.hpp> |
| 33 | #include <com/sun/star/accessibility/AccessibleRole.hpp> |
| 34 | #include <com/sun/star/accessibility/AccessibleScrollType.hpp> |
| 35 | #include <com/sun/star/accessibility/AccessibleStateType.hpp> |
| 36 | #include <com/sun/star/accessibility/AccessibleTextType.hpp> |
| 37 | #include <com/sun/star/accessibility/XAccessible.hpp> |
| 38 | #include <com/sun/star/accessibility/XAccessibleAction.hpp> |
| 39 | #include <com/sun/star/accessibility/XAccessibleComponent.hpp> |
| 40 | #include <com/sun/star/accessibility/XAccessibleContext.hpp> |
| 41 | #include <com/sun/star/accessibility/XAccessibleContext2.hpp> |
| 42 | #include <com/sun/star/accessibility/XAccessibleEditableText.hpp> |
| 43 | #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp> |
| 44 | #include <com/sun/star/accessibility/XAccessibleEventListener.hpp> |
| 45 | #include <com/sun/star/accessibility/XAccessibleExtendedAttributes.hpp> |
| 46 | #include <com/sun/star/accessibility/XAccessibleKeyBinding.hpp> |
| 47 | #include <com/sun/star/accessibility/XAccessibleRelationSet.hpp> |
| 48 | #include <com/sun/star/accessibility/XAccessibleSelection.hpp> |
| 49 | #include <com/sun/star/accessibility/XAccessibleTable.hpp> |
| 50 | #include <com/sun/star/accessibility/XAccessibleTableSelection.hpp> |
| 51 | #include <com/sun/star/accessibility/XAccessibleText.hpp> |
| 52 | #include <com/sun/star/accessibility/XAccessibleValue.hpp> |
| 53 | #include <com/sun/star/lang/DisposedException.hpp> |
| 54 | #include <com/sun/star/uno/Sequence.hxx> |
| 55 | |
| 56 | #include <comphelper/AccessibleImplementationHelper.hxx> |
| 57 | #include <sal/log.hxx> |
| 58 | #include <vcl/accessibility/AccessibleTextAttributeHelper.hxx> |
| 59 | #include <vcl/qt/QtUtils.hxx> |
| 60 | |
| 61 | using namespace css; |
| 62 | using namespace css::accessibility; |
| 63 | using namespace css::uno; |
| 64 | |
| 65 | // property used to specify the QtAccessibleWidget* that should be used as the |
| 66 | // custom accessible interface for an object |
| 67 | const char* const PROPERTY_ACCESSIBLE = "accessible-interface"; |
| 68 | |
| 69 | QtAccessibleWidget::QtAccessibleWidget(const Reference<XAccessible>& xAccessible, QObject& rObject) |
| 70 | : m_xAccessible(xAccessible) |
| 71 | , m_rObject(rObject) |
| 72 | { |
| 73 | Reference<XAccessibleContext> xContext = xAccessible->getAccessibleContext(); |
| 74 | Reference<XAccessibleEventBroadcaster> xBroadcaster(xContext, UNO_QUERY); |
| 75 | if (xBroadcaster.is()) |
| 76 | { |
| 77 | Reference<XAccessibleEventListener> xListener(new QtAccessibleEventListener(this)); |
| 78 | xBroadcaster->addAccessibleEventListener(xListener); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | void QtAccessibleWidget::invalidate() |
| 83 | { |
| 84 | QtAccessibleRegistry::remove(m_xAccessible); |
| 85 | m_xAccessible.clear(); |
| 86 | } |
| 87 | |
| 88 | Reference<XAccessibleContext> QtAccessibleWidget::getAccessibleContextImpl() const |
| 89 | { |
| 90 | Reference<XAccessibleContext> xAc; |
| 91 | |
| 92 | if (m_xAccessible.is()) |
| 93 | { |
| 94 | try |
| 95 | { |
| 96 | xAc = m_xAccessible->getAccessibleContext(); |
| 97 | } |
| 98 | catch (css::lang::DisposedException /*ex*/) |
| 99 | { |
| 100 | SAL_WARN("vcl.qt", "Accessible context disposed already"); |
| 101 | } |
| 102 | // sometimes getAccessibleContext throws also RuntimeException if context is no longer alive |
| 103 | catch (css::uno::RuntimeException /*ex*/) |
| 104 | { |
| 105 | // so let's catch it here, cuz otherwise soffice falls flat on its face |
| 106 | // with FatalError and nothing else |
| 107 | SAL_WARN("vcl.qt", "Accessible context no longer alive"); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | return xAc; |
| 112 | } |
| 113 | |
| 114 | css::uno::Reference<css::accessibility::XAccessibleTable> |
| 115 | QtAccessibleWidget::getAccessibleTableForParent() const |
| 116 | { |
| 117 | Reference<XAccessibleContext> xAcc = getAccessibleContextImpl(); |
| 118 | if (!xAcc.is()) |
| 119 | return nullptr; |
| 120 | |
| 121 | Reference<XAccessible> xParent = xAcc->getAccessibleParent(); |
| 122 | if (!xParent.is()) |
| 123 | return nullptr; |
| 124 | |
| 125 | Reference<XAccessibleContext> xParentContext = xParent->getAccessibleContext(); |
| 126 | if (!xParentContext.is()) |
| 127 | return nullptr; |
| 128 | |
| 129 | return Reference<XAccessibleTable>(xParentContext, UNO_QUERY); |
| 130 | } |
| 131 | |
| 132 | QWindow* QtAccessibleWidget::window() const |
| 133 | { |
| 134 | if (m_rObject.isWidgetType()) |
| 135 | { |
| 136 | QWidget& rWidget = static_cast<QWidget&>(m_rObject); |
| 137 | QWidget* pWindow = rWidget.window(); |
| 138 | if (pWindow) |
| 139 | return pWindow->windowHandle(); |
| 140 | } |
| 141 | |
| 142 | QAccessibleInterface* pParent = parent(); |
| 143 | if (pParent) |
| 144 | return pParent->window(); |
| 145 | |
| 146 | return nullptr; |
| 147 | } |
| 148 | |
| 149 | int QtAccessibleWidget::childCount() const |
| 150 | { |
| 151 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 152 | if (!xAc.is()) |
| 153 | return 0; |
| 154 | |
| 155 | sal_Int64 nChildCount = xAc->getAccessibleChildCount(); |
| 156 | if (nChildCount > std::numeric_limits<int>::max()) |
| 157 | { |
| 158 | SAL_WARN("vcl.qt", "QtAccessibleWidget::childCount: Child count exceeds maximum int value, " |
| 159 | "returning max int."); |
| 160 | nChildCount = std::numeric_limits<int>::max(); |
| 161 | } |
| 162 | |
| 163 | return nChildCount; |
| 164 | } |
| 165 | |
| 166 | int QtAccessibleWidget::indexOfChild(const QAccessibleInterface* pChild) const |
| 167 | { |
| 168 | const QtAccessibleWidget* pAccessibleWidget = dynamic_cast<const QtAccessibleWidget*>(pChild); |
| 169 | if (!pAccessibleWidget) |
| 170 | { |
| 171 | SAL_WARN( |
| 172 | "vcl.qt", |
| 173 | "QtAccessibleWidget::indexOfChild called with child that is no QtAccessibleWidget"); |
| 174 | return -1; |
| 175 | } |
| 176 | |
| 177 | Reference<XAccessibleContext> xContext = pAccessibleWidget->getAccessibleContextImpl(); |
| 178 | if (!xContext.is()) |
| 179 | return -1; |
| 180 | |
| 181 | sal_Int64 nChildIndex = xContext->getAccessibleIndexInParent(); |
| 182 | if (nChildIndex > std::numeric_limits<int>::max()) |
| 183 | { |
| 184 | // use -2 when the child index is too large to fit into 32 bit to neither use the |
| 185 | // valid index of another child nor -1, which would e.g. make the Orca screen reader |
| 186 | // interpret the object as being a zombie |
| 187 | SAL_WARN("vcl.qt", |
| 188 | "QtAccessibleWidget::indexOfChild: Child index exceeds maximum int value, " |
| 189 | "returning -2."); |
| 190 | nChildIndex = -2; |
| 191 | } |
| 192 | return nChildIndex; |
| 193 | } |
| 194 | |
| 195 | namespace |
| 196 | { |
| 197 | sal_Int16 lcl_matchQtTextBoundaryType(QAccessible::TextBoundaryType boundaryType) |
| 198 | { |
| 199 | switch (boundaryType) |
| 200 | { |
| 201 | case QAccessible::CharBoundary: |
| 202 | return css::accessibility::AccessibleTextType::CHARACTER; |
| 203 | case QAccessible::WordBoundary: |
| 204 | return css::accessibility::AccessibleTextType::WORD; |
| 205 | case QAccessible::SentenceBoundary: |
| 206 | return css::accessibility::AccessibleTextType::SENTENCE; |
| 207 | case QAccessible::ParagraphBoundary: |
| 208 | return css::accessibility::AccessibleTextType::PARAGRAPH; |
| 209 | case QAccessible::LineBoundary: |
| 210 | return css::accessibility::AccessibleTextType::LINE; |
| 211 | case QAccessible::NoBoundary: |
| 212 | // assert here, better handle it directly at call site |
| 213 | assert(false |
| 214 | && "No match for QAccessible::NoBoundary, handle it separately at call site."); |
| 215 | break; |
| 216 | default: |
| 217 | break; |
| 218 | } |
| 219 | |
| 220 | SAL_WARN("vcl.qt", "Unmatched text boundary type: " << boundaryType); |
| 221 | return -1; |
| 222 | } |
| 223 | |
| 224 | QAccessible::Relation lcl_matchUnoRelation(AccessibleRelationType eRelationType) |
| 225 | { |
| 226 | // Qt semantics is the other way around |
| 227 | switch (eRelationType) |
| 228 | { |
| 229 | #if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0) |
| 230 | case AccessibleRelationType_CONTENT_FLOWS_FROM: |
| 231 | return QAccessible::FlowsTo; |
| 232 | case AccessibleRelationType_CONTENT_FLOWS_TO: |
| 233 | return QAccessible::FlowsFrom; |
| 234 | #endif |
| 235 | case AccessibleRelationType_CONTROLLED_BY: |
| 236 | return QAccessible::Controller; |
| 237 | case AccessibleRelationType_CONTROLLER_FOR: |
| 238 | return QAccessible::Controlled; |
| 239 | #if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0) |
| 240 | case AccessibleRelationType_DESCRIBED_BY: |
| 241 | return QAccessible::DescriptionFor; |
| 242 | #endif |
| 243 | case AccessibleRelationType_LABELED_BY: |
| 244 | return QAccessible::Label; |
| 245 | case AccessibleRelationType_LABEL_FOR: |
| 246 | return QAccessible::Labelled; |
| 247 | case AccessibleRelationType_INVALID: |
| 248 | case AccessibleRelationType_MEMBER_OF: |
| 249 | case AccessibleRelationType_SUB_WINDOW_OF: |
| 250 | case AccessibleRelationType_NODE_CHILD_OF: |
| 251 | default: |
| 252 | SAL_WARN("vcl.qt", "Unmatched relation: " << static_cast<int>(eRelationType)); |
| 253 | return {}; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | void lcl_appendRelation(QVector<QPair<QAccessibleInterface*, QAccessible::Relation>>* relations, |
| 258 | AccessibleRelation aRelation, QAccessible::Relation match) |
| 259 | { |
| 260 | QAccessible::Relation aQRelation = lcl_matchUnoRelation(aRelation.RelationType); |
| 261 | // skip in case there's no Qt relation matching the filter |
| 262 | if (!(aQRelation & match)) |
| 263 | return; |
| 264 | |
| 265 | sal_uInt32 nTargetCount = aRelation.TargetSet.getLength(); |
| 266 | |
| 267 | for (sal_uInt32 i = 0; i < nTargetCount; i++) |
| 268 | { |
| 269 | Reference<XAccessible> xAccessible = aRelation.TargetSet[i]; |
| 270 | relations->append( |
| 271 | { QAccessible::queryAccessibleInterface(QtAccessibleRegistry::getQObject(xAccessible)), |
| 272 | aQRelation }); |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | QVector<QPair<QAccessibleInterface*, QAccessible::Relation>> |
| 278 | QtAccessibleWidget::relations(QAccessible::Relation match) const |
| 279 | { |
| 280 | QVector<QPair<QAccessibleInterface*, QAccessible::Relation>> relations; |
| 281 | |
| 282 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 283 | if (!xAc.is()) |
| 284 | return relations; |
| 285 | |
| 286 | Reference<XAccessibleRelationSet> xRelationSet = xAc->getAccessibleRelationSet(); |
| 287 | if (xRelationSet.is()) |
| 288 | { |
| 289 | int count = xRelationSet->getRelationCount(); |
| 290 | for (int i = 0; i < count; i++) |
| 291 | { |
| 292 | AccessibleRelation aRelation = xRelationSet->getRelation(i); |
| 293 | lcl_appendRelation(&relations, aRelation, match); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | return relations; |
| 298 | } |
| 299 | |
| 300 | QAccessibleInterface* QtAccessibleWidget::focusChild() const |
| 301 | { |
| 302 | /* if (m_pWindow->HasChildPathFocus()) |
| 303 | return QAccessible::queryAccessibleInterface( |
| 304 | new QtXAccessible(m_xAccessible->getAccessibleContext()->getAccessibleChild(index))); */ |
| 305 | return QAccessible::queryAccessibleInterface(object()); |
| 306 | } |
| 307 | |
| 308 | QRect QtAccessibleWidget::rect() const |
| 309 | { |
| 310 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 311 | if (!xAc.is()) |
| 312 | return QRect(); |
| 313 | |
| 314 | Reference<XAccessibleComponent> xAccessibleComponent(xAc, UNO_QUERY); |
| 315 | awt::Point aPoint = xAccessibleComponent->getLocationOnScreen(); |
| 316 | awt::Size aSize = xAccessibleComponent->getSize(); |
| 317 | |
| 318 | return QRect(aPoint.X, aPoint.Y, aSize.Width, aSize.Height); |
| 319 | } |
| 320 | |
| 321 | QAccessibleInterface* QtAccessibleWidget::parent() const |
| 322 | { |
| 323 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 324 | if (!xAc.is()) |
| 325 | return nullptr; |
| 326 | |
| 327 | if (xAc->getAccessibleParent().is()) |
| 328 | return QAccessible::queryAccessibleInterface( |
| 329 | QtAccessibleRegistry::getQObject(xAc->getAccessibleParent())); |
| 330 | |
| 331 | // go via the QObject hierarchy; a11y objects like the application object |
| 332 | // and native weld::Widgets are handled solely by Qt and have |
| 333 | // no LO-internal a11y objects associated with them |
| 334 | QObject* pObj = object(); |
| 335 | if (pObj && pObj->parent()) |
| 336 | return QAccessible::queryAccessibleInterface(pObj->parent()); |
| 337 | |
| 338 | // return app as parent for top-level objects |
| 339 | return QAccessible::queryAccessibleInterface(qApp); |
| 340 | } |
| 341 | |
| 342 | QAccessibleInterface* QtAccessibleWidget::child(int index) const |
| 343 | { |
| 344 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 345 | if (!xAc.is()) |
| 346 | return nullptr; |
| 347 | |
| 348 | if (index < 0 || index >= xAc->getAccessibleChildCount()) |
| 349 | { |
| 350 | SAL_WARN("vcl.qt", "QtAccessibleWidget::child called with invalid index: " << index); |
| 351 | return nullptr; |
| 352 | } |
| 353 | |
| 354 | return QAccessible::queryAccessibleInterface( |
| 355 | QtAccessibleRegistry::getQObject(xAc->getAccessibleChild(index))); |
| 356 | } |
| 357 | |
| 358 | QString QtAccessibleWidget::text(QAccessible::Text text) const |
| 359 | { |
| 360 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 361 | if (!xAc.is()) |
| 362 | return QString(); |
| 363 | |
| 364 | switch (text) |
| 365 | { |
| 366 | case QAccessible::Name: |
| 367 | return toQString(xAc->getAccessibleName()); |
| 368 | case QAccessible::Description: |
| 369 | case QAccessible::DebugDescription: |
| 370 | return toQString(xAc->getAccessibleDescription()); |
| 371 | #if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) |
| 372 | case QAccessible::Identifier: |
| 373 | { |
| 374 | Reference<XAccessibleContext2> xContext(getAccessibleContextImpl(), UNO_QUERY); |
| 375 | if (!xContext.is()) |
| 376 | return QString(); |
| 377 | return toQString(xContext->getAccessibleId()); |
| 378 | } |
| 379 | #endif |
| 380 | case QAccessible::Value: |
| 381 | case QAccessible::Help: |
| 382 | case QAccessible::Accelerator: |
| 383 | case QAccessible::UserText: |
| 384 | default: |
| 385 | return QString(); |
| 386 | } |
| 387 | } |
| 388 | QAccessible::Role QtAccessibleWidget::role() const |
| 389 | { |
| 390 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 391 | if (!xAc.is()) |
| 392 | return QAccessible::NoRole; |
| 393 | |
| 394 | switch (xAc->getAccessibleRole()) |
| 395 | { |
| 396 | case AccessibleRole::UNKNOWN: |
| 397 | return QAccessible::NoRole; |
| 398 | case AccessibleRole::ALERT: |
| 399 | return QAccessible::AlertMessage; |
| 400 | case AccessibleRole::BLOCK_QUOTE: |
| 401 | #if QT_VERSION >= QT_VERSION_CHECK(6, 9, 0) |
| 402 | return QAccessible::BlockQuote; |
| 403 | #else |
| 404 | return QAccessible::Paragraph; |
| 405 | #endif |
| 406 | case AccessibleRole::COLUMN_HEADER: |
| 407 | return QAccessible::ColumnHeader; |
| 408 | case AccessibleRole::CANVAS: |
| 409 | return QAccessible::Canvas; |
| 410 | case AccessibleRole::CHECK_BOX: |
| 411 | return QAccessible::CheckBox; |
| 412 | case AccessibleRole::CHECK_MENU_ITEM: |
| 413 | return QAccessible::MenuItem; |
| 414 | case AccessibleRole::COLOR_CHOOSER: |
| 415 | return QAccessible::ColorChooser; |
| 416 | case AccessibleRole::COMBO_BOX: |
| 417 | return QAccessible::ComboBox; |
| 418 | case AccessibleRole::DATE_EDITOR: |
| 419 | return QAccessible::EditableText; |
| 420 | case AccessibleRole::DESKTOP_ICON: |
| 421 | return QAccessible::Graphic; |
| 422 | case AccessibleRole::DESKTOP_PANE: |
| 423 | case AccessibleRole::DIRECTORY_PANE: |
| 424 | return QAccessible::Pane; |
| 425 | case AccessibleRole::DIALOG: |
| 426 | return QAccessible::Dialog; |
| 427 | case AccessibleRole::DOCUMENT: |
| 428 | return QAccessible::Document; |
| 429 | case AccessibleRole::EMBEDDED_OBJECT: |
| 430 | return QAccessible::UserRole; |
| 431 | case AccessibleRole::END_NOTE: |
| 432 | return QAccessible::Note; |
| 433 | case AccessibleRole::FILE_CHOOSER: |
| 434 | return QAccessible::Dialog; |
| 435 | case AccessibleRole::FILLER: |
| 436 | return QAccessible::Whitespace; |
| 437 | case AccessibleRole::FONT_CHOOSER: |
| 438 | return QAccessible::UserRole; |
| 439 | case AccessibleRole::FOOTER: |
| 440 | return QAccessible::Footer; |
| 441 | case AccessibleRole::FOOTNOTE: |
| 442 | return QAccessible::Note; |
| 443 | case AccessibleRole::FRAME: |
| 444 | // report Pane instead of Window role for a frame that's not actually |
| 445 | // an accessible frame (top-level window with title bar) itself, |
| 446 | // but a child of the real top-level |
| 447 | if (QAccessibleInterface* pParent = parent()) |
| 448 | { |
| 449 | const QAccessible::Role eParentRole = pParent->role(); |
| 450 | if (eParentRole == QAccessible::Window || eParentRole == QAccessible::Dialog) |
| 451 | return QAccessible::Pane; |
| 452 | } |
| 453 | return QAccessible::Window; |
| 454 | case AccessibleRole::GLASS_PANE: |
| 455 | return QAccessible::UserRole; |
| 456 | case AccessibleRole::GRAPHIC: |
| 457 | return QAccessible::Graphic; |
| 458 | case AccessibleRole::GROUP_BOX: |
| 459 | return QAccessible::Grouping; |
| 460 | case AccessibleRole::HEADER: |
| 461 | return QAccessible::UserRole; |
| 462 | case AccessibleRole::HEADING: |
| 463 | return QAccessible::Heading; |
| 464 | case AccessibleRole::HYPER_LINK: |
| 465 | return QAccessible::Link; |
| 466 | case AccessibleRole::ICON: |
| 467 | return QAccessible::Graphic; |
| 468 | case AccessibleRole::INTERNAL_FRAME: |
| 469 | return QAccessible::UserRole; |
| 470 | case AccessibleRole::LABEL: |
| 471 | return QAccessible::StaticText; |
| 472 | case AccessibleRole::LAYERED_PANE: |
| 473 | return QAccessible::Pane; |
| 474 | case AccessibleRole::LIST: |
| 475 | return QAccessible::List; |
| 476 | case AccessibleRole::LIST_ITEM: |
| 477 | return QAccessible::ListItem; |
| 478 | case AccessibleRole::MENU: |
| 479 | case AccessibleRole::MENU_BAR: |
| 480 | return QAccessible::MenuBar; |
| 481 | case AccessibleRole::MENU_ITEM: |
| 482 | return QAccessible::MenuItem; |
| 483 | case AccessibleRole::NOTIFICATION: |
| 484 | return QAccessible::Notification; |
| 485 | case AccessibleRole::OPTION_PANE: |
| 486 | return QAccessible::Pane; |
| 487 | case AccessibleRole::PAGE_TAB: |
| 488 | return QAccessible::PageTab; |
| 489 | case AccessibleRole::PAGE_TAB_LIST: |
| 490 | return QAccessible::PageTabList; |
| 491 | case AccessibleRole::PANEL: |
| 492 | return QAccessible::Pane; |
| 493 | case AccessibleRole::PARAGRAPH: |
| 494 | return QAccessible::Paragraph; |
| 495 | case AccessibleRole::PASSWORD_TEXT: |
| 496 | // Qt API doesn't have a separate role to distinguish password edits, |
| 497 | // but a 'passwordEdit' state |
| 498 | return QAccessible::EditableText; |
| 499 | case AccessibleRole::POPUP_MENU: |
| 500 | return QAccessible::PopupMenu; |
| 501 | case AccessibleRole::PUSH_BUTTON: |
| 502 | return QAccessible::Button; |
| 503 | case AccessibleRole::PROGRESS_BAR: |
| 504 | return QAccessible::ProgressBar; |
| 505 | case AccessibleRole::RADIO_BUTTON: |
| 506 | return QAccessible::RadioButton; |
| 507 | case AccessibleRole::RADIO_MENU_ITEM: |
| 508 | return QAccessible::MenuItem; |
| 509 | case AccessibleRole::ROW_HEADER: |
| 510 | return QAccessible::RowHeader; |
| 511 | case AccessibleRole::ROOT_PANE: |
| 512 | return QAccessible::Pane; |
| 513 | case AccessibleRole::SCROLL_BAR: |
| 514 | return QAccessible::ScrollBar; |
| 515 | case AccessibleRole::SCROLL_PANE: |
| 516 | return QAccessible::Pane; |
| 517 | case AccessibleRole::SHAPE: |
| 518 | return QAccessible::Graphic; |
| 519 | case AccessibleRole::SEPARATOR: |
| 520 | return QAccessible::Separator; |
| 521 | case AccessibleRole::SLIDER: |
| 522 | return QAccessible::Slider; |
| 523 | case AccessibleRole::SPIN_BOX: |
| 524 | return QAccessible::SpinBox; |
| 525 | case AccessibleRole::SPLIT_PANE: |
| 526 | return QAccessible::Pane; |
| 527 | case AccessibleRole::STATUS_BAR: |
| 528 | return QAccessible::StatusBar; |
| 529 | case AccessibleRole::TABLE: |
| 530 | return QAccessible::Table; |
| 531 | case AccessibleRole::TABLE_CELL: |
| 532 | return QAccessible::Cell; |
| 533 | case AccessibleRole::TEXT: |
| 534 | return QAccessible::EditableText; |
| 535 | case AccessibleRole::TEXT_FRAME: |
| 536 | return QAccessible::Pane; |
| 537 | case AccessibleRole::TOGGLE_BUTTON: |
| 538 | return QAccessible::Button; |
| 539 | case AccessibleRole::TOOL_BAR: |
| 540 | return QAccessible::ToolBar; |
| 541 | case AccessibleRole::TOOL_TIP: |
| 542 | return QAccessible::ToolTip; |
| 543 | case AccessibleRole::TREE: |
| 544 | return QAccessible::Tree; |
| 545 | case AccessibleRole::VIEW_PORT: |
| 546 | return QAccessible::UserRole; |
| 547 | case AccessibleRole::BUTTON_DROPDOWN: |
| 548 | return QAccessible::ButtonDropDown; |
| 549 | case AccessibleRole::BUTTON_MENU: |
| 550 | return QAccessible::ButtonMenu; |
| 551 | case AccessibleRole::CAPTION: |
| 552 | return QAccessible::StaticText; |
| 553 | case AccessibleRole::CHART: |
| 554 | return QAccessible::Chart; |
| 555 | case AccessibleRole::EDIT_BAR: |
| 556 | return QAccessible::Equation; |
| 557 | case AccessibleRole::FORM: |
| 558 | return QAccessible::Form; |
| 559 | case AccessibleRole::IMAGE_MAP: |
| 560 | return QAccessible::Graphic; |
| 561 | case AccessibleRole::NOTE: |
| 562 | return QAccessible::Note; |
| 563 | case AccessibleRole::RULER: |
| 564 | return QAccessible::UserRole; |
| 565 | case AccessibleRole::SECTION: |
| 566 | return QAccessible::Section; |
| 567 | case AccessibleRole::TREE_ITEM: |
| 568 | return QAccessible::TreeItem; |
| 569 | case AccessibleRole::TREE_TABLE: |
| 570 | return QAccessible::Tree; |
| 571 | case AccessibleRole::COMMENT: |
| 572 | return QAccessible::Note; |
| 573 | case AccessibleRole::COMMENT_END: |
| 574 | return QAccessible::UserRole; |
| 575 | case AccessibleRole::DOCUMENT_PRESENTATION: |
| 576 | return QAccessible::Document; |
| 577 | case AccessibleRole::DOCUMENT_SPREADSHEET: |
| 578 | return QAccessible::Document; |
| 579 | case AccessibleRole::DOCUMENT_TEXT: |
| 580 | return QAccessible::Document; |
| 581 | case AccessibleRole::STATIC: |
| 582 | return QAccessible::StaticText; |
| 583 | case AccessibleRole::WINDOW: // top-level window without title bar |
| 584 | return QAccessible::Window; |
| 585 | } |
| 586 | |
| 587 | SAL_WARN("vcl.qt", "Unmapped role: " << getAccessibleContextImpl()->getAccessibleRole()); |
| 588 | return QAccessible::NoRole; |
| 589 | } |
| 590 | |
| 591 | namespace |
| 592 | { |
| 593 | void lcl_addState(QAccessible::State* state, sal_Int64 nState) |
| 594 | { |
| 595 | switch (nState) |
| 596 | { |
| 597 | case AccessibleStateType::INVALID: |
| 598 | state->invalid = true; |
| 599 | break; |
| 600 | case AccessibleStateType::ACTIVE: |
| 601 | state->active = true; |
| 602 | break; |
| 603 | case AccessibleStateType::ARMED: |
| 604 | // No match |
| 605 | break; |
| 606 | case AccessibleStateType::BUSY: |
| 607 | state->busy = true; |
| 608 | break; |
| 609 | case AccessibleStateType::CHECKABLE: |
| 610 | state->checkable = true; |
| 611 | break; |
| 612 | case AccessibleStateType::CHECKED: |
| 613 | state->checked = true; |
| 614 | break; |
| 615 | case AccessibleStateType::EDITABLE: |
| 616 | state->editable = true; |
| 617 | break; |
| 618 | case AccessibleStateType::ENABLED: |
| 619 | state->disabled = false; |
| 620 | break; |
| 621 | case AccessibleStateType::EXPANDABLE: |
| 622 | state->expandable = true; |
| 623 | break; |
| 624 | case AccessibleStateType::EXPANDED: |
| 625 | state->expanded = true; |
| 626 | break; |
| 627 | case AccessibleStateType::FOCUSABLE: |
| 628 | state->focusable = true; |
| 629 | break; |
| 630 | case AccessibleStateType::FOCUSED: |
| 631 | state->focused = true; |
| 632 | break; |
| 633 | case AccessibleStateType::HORIZONTAL: |
| 634 | // No match |
| 635 | break; |
| 636 | case AccessibleStateType::ICONIFIED: |
| 637 | // No match |
| 638 | break; |
| 639 | case AccessibleStateType::INDETERMINATE: |
| 640 | state->checkStateMixed = true; |
| 641 | break; |
| 642 | case AccessibleStateType::MANAGES_DESCENDANTS: |
| 643 | // No match |
| 644 | break; |
| 645 | case AccessibleStateType::MODAL: |
| 646 | state->modal = true; |
| 647 | break; |
| 648 | case AccessibleStateType::MOVEABLE: |
| 649 | state->movable = true; |
| 650 | break; |
| 651 | case AccessibleStateType::MULTI_LINE: |
| 652 | state->multiLine = true; |
| 653 | break; |
| 654 | case AccessibleStateType::OPAQUE: |
| 655 | // No match |
| 656 | break; |
| 657 | case AccessibleStateType::PRESSED: |
| 658 | state->pressed = true; |
| 659 | break; |
| 660 | case AccessibleStateType::RESIZABLE: |
| 661 | state->sizeable = true; |
| 662 | break; |
| 663 | case AccessibleStateType::SELECTABLE: |
| 664 | state->selectable = true; |
| 665 | break; |
| 666 | case AccessibleStateType::SELECTED: |
| 667 | state->selected = true; |
| 668 | break; |
| 669 | case AccessibleStateType::SENSITIVE: |
| 670 | // No match |
| 671 | break; |
| 672 | case AccessibleStateType::SHOWING: |
| 673 | // No match |
| 674 | break; |
| 675 | case AccessibleStateType::SINGLE_LINE: |
| 676 | // No match |
| 677 | break; |
| 678 | case AccessibleStateType::STALE: |
| 679 | // No match |
| 680 | break; |
| 681 | case AccessibleStateType::TRANSIENT: |
| 682 | // No match |
| 683 | break; |
| 684 | case AccessibleStateType::VERTICAL: |
| 685 | // No match |
| 686 | break; |
| 687 | case AccessibleStateType::VISIBLE: |
| 688 | state->invisible = false; |
| 689 | break; |
| 690 | case AccessibleStateType::DEFAULT: |
| 691 | // No match |
| 692 | break; |
| 693 | case AccessibleStateType::DEFUNC: |
| 694 | state->invalid = true; |
| 695 | break; |
| 696 | case AccessibleStateType::MULTI_SELECTABLE: |
| 697 | state->multiSelectable = true; |
| 698 | break; |
| 699 | default: |
| 700 | SAL_WARN("vcl.qt", "Unmapped state: " << nState); |
| 701 | break; |
| 702 | } |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | QAccessible::State QtAccessibleWidget::state() const |
| 707 | { |
| 708 | QAccessible::State state; |
| 709 | |
| 710 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 711 | if (!xAc.is()) |
| 712 | return state; |
| 713 | |
| 714 | sal_Int64 nStateSet(xAc->getAccessibleStateSet()); |
| 715 | |
| 716 | for (int i = 0; i < 63; ++i) |
| 717 | { |
| 718 | sal_Int64 nState = sal_Int64(1) << i; |
| 719 | if (nStateSet & nState) |
| 720 | lcl_addState(&state, nState); |
| 721 | } |
| 722 | |
| 723 | if (xAc->getAccessibleRole() == AccessibleRole::PASSWORD_TEXT) |
| 724 | state.passwordEdit = true; |
| 725 | |
| 726 | return state; |
| 727 | } |
| 728 | |
| 729 | QColor QtAccessibleWidget::foregroundColor() const |
| 730 | { |
| 731 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 732 | if (!xAc.is()) |
| 733 | return QColor(); |
| 734 | |
| 735 | Reference<XAccessibleComponent> xAccessibleComponent(xAc, UNO_QUERY); |
| 736 | return toQColor(Color(ColorTransparency, xAccessibleComponent->getForeground())); |
| 737 | } |
| 738 | |
| 739 | QColor QtAccessibleWidget::backgroundColor() const |
| 740 | { |
| 741 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 742 | if (!xAc.is()) |
| 743 | return QColor(); |
| 744 | |
| 745 | Reference<XAccessibleComponent> xAccessibleComponent(xAc, UNO_QUERY); |
| 746 | return toQColor(Color(ColorTransparency, xAccessibleComponent->getBackground())); |
| 747 | } |
| 748 | |
| 749 | void* QtAccessibleWidget::interface_cast(QAccessible::InterfaceType t) |
| 750 | { |
| 751 | if (t == QAccessible::ActionInterface && accessibleProvidesInterface<XAccessibleAction>()) |
| 752 | return static_cast<QAccessibleActionInterface*>(this); |
| 753 | if (t == QAccessible::TextInterface && accessibleProvidesInterface<XAccessibleText>()) |
| 754 | return static_cast<QAccessibleTextInterface*>(this); |
| 755 | if (t == QAccessible::EditableTextInterface |
| 756 | && accessibleProvidesInterface<XAccessibleEditableText>()) |
| 757 | return static_cast<QAccessibleEditableTextInterface*>(this); |
| 758 | if (t == QAccessible::ValueInterface && accessibleProvidesInterface<XAccessibleValue>()) |
| 759 | return static_cast<QAccessibleValueInterface*>(this); |
| 760 | if (t == QAccessible::TableCellInterface) |
| 761 | { |
| 762 | // parent must be a table |
| 763 | Reference<XAccessibleTable> xTable = getAccessibleTableForParent(); |
| 764 | if (xTable.is()) |
| 765 | return static_cast<QAccessibleTableCellInterface*>(this); |
| 766 | } |
| 767 | if (t == QAccessible::TableInterface && accessibleProvidesInterface<XAccessibleTable>()) |
| 768 | return static_cast<QAccessibleTableInterface*>(this); |
| 769 | #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) |
| 770 | if (t == QAccessible::SelectionInterface && accessibleProvidesInterface<XAccessibleSelection>()) |
| 771 | return static_cast<QAccessibleSelectionInterface*>(this); |
| 772 | #endif |
| 773 | #if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) |
| 774 | if (t == QAccessible::AttributesInterface) |
| 775 | return static_cast<QAccessibleAttributesInterface*>(this); |
| 776 | #endif |
| 777 | return nullptr; |
| 778 | } |
| 779 | |
| 780 | bool QtAccessibleWidget::isValid() const |
| 781 | { |
| 782 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 783 | return xAc.is(); |
| 784 | } |
| 785 | |
| 786 | QObject* QtAccessibleWidget::object() const { return &m_rObject; } |
| 787 | |
| 788 | void QtAccessibleWidget::setText(QAccessible::Text /* t */, const QString& /* text */) {} |
| 789 | |
| 790 | QAccessibleInterface* QtAccessibleWidget::childAt(int x, int y) const |
| 791 | { |
| 792 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 793 | if (!xAc.is()) |
| 794 | return nullptr; |
| 795 | |
| 796 | Reference<XAccessibleComponent> xAccessibleComponent(xAc, UNO_QUERY); |
| 797 | // convert from screen to local coordinates |
| 798 | QPoint aLocalCoords = QPoint(x, y) - rect().topLeft(); |
| 799 | return QAccessible::queryAccessibleInterface( |
| 800 | QtAccessibleRegistry::getQObject(xAccessibleComponent->getAccessibleAtPoint( |
| 801 | awt::Point(aLocalCoords.x(), aLocalCoords.y())))); |
| 802 | } |
| 803 | |
| 804 | QAccessibleInterface* QtAccessibleWidget::customFactory(const QString& classname, QObject* pObject) |
| 805 | { |
| 806 | if (!pObject) |
| 807 | return nullptr; |
| 808 | |
| 809 | const QVariant aAccVariant = pObject->property(PROPERTY_ACCESSIBLE); |
| 810 | if (aAccVariant.isValid() && aAccVariant.canConvert<QtAccessibleWidget*>()) |
| 811 | { |
| 812 | QtAccessibleWidget* pAccessibleWidget = aAccVariant.value<QtAccessibleWidget*>(); |
| 813 | QtAccessibleRegistry::insert(pAccessibleWidget->m_xAccessible, pObject); |
| 814 | return pAccessibleWidget; |
| 815 | } |
| 816 | |
| 817 | if (classname == QLatin1String("QtWidget") && pObject->isWidgetType()) |
| 818 | { |
| 819 | QtWidget* pWidget = static_cast<QtWidget*>(pObject); |
| 820 | vcl::Window* pWindow = pWidget->frame().GetWindow(); |
| 821 | |
| 822 | if (pWindow) |
| 823 | { |
| 824 | rtl::Reference<comphelper::OAccessible> pAcc = pWindow->GetAccessible(); |
| 825 | // insert into registry so the association between the XAccessible and the QtWidget |
| 826 | // is remembered rather than creating a different QtXAccessible when a QObject is needed later |
| 827 | QtAccessibleRegistry::insert(pAcc, pObject); |
| 828 | return new QtAccessibleWidget(pAcc, *pObject); |
| 829 | } |
| 830 | } |
| 831 | if (classname == QLatin1String("QtXAccessible")) |
| 832 | { |
| 833 | QtXAccessible* pXAccessible = static_cast<QtXAccessible*>(pObject); |
| 834 | if (pXAccessible->m_xAccessible.is()) |
| 835 | { |
| 836 | QtAccessibleWidget* pRet |
| 837 | = new QtAccessibleWidget(pXAccessible->m_xAccessible, *pObject); |
| 838 | // clear the reference in the QtXAccessible, no longer needed now that the QtAccessibleWidget holds one |
| 839 | pXAccessible->m_xAccessible.clear(); |
| 840 | return pRet; |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | return nullptr; |
| 845 | } |
| 846 | |
| 847 | void QtAccessibleWidget::setCustomAccessible( |
| 848 | QObject& rObject, const rtl::Reference<comphelper::OAccessible>& rAccessible) |
| 849 | { |
| 850 | assert(rAccessible.is()); |
| 851 | |
| 852 | // unset/delete the current/default accessible of the object |
| 853 | QAccessibleInterface* pOldAccessible = QAccessible::queryAccessibleInterface(&rObject); |
| 854 | const QAccessible::Id nId = QAccessible::uniqueId(pOldAccessible); |
| 855 | QAccessible::deleteAccessibleInterface(nId); |
| 856 | |
| 857 | // let QtAccessibleWidget::customFactory set the custom accessible |
| 858 | rObject.setProperty(PROPERTY_ACCESSIBLE, |
| 859 | QVariant::fromValue(new QtAccessibleWidget(rAccessible, rObject))); |
| 860 | QAccessible::queryAccessibleInterface(&rObject); |
| 861 | } |
| 862 | |
| 863 | // QAccessibleActionInterface |
| 864 | QStringList QtAccessibleWidget::actionNames() const |
| 865 | { |
| 866 | QStringList actionNames; |
| 867 | Reference<XAccessibleAction> xAccessibleAction(getAccessibleContextImpl(), UNO_QUERY); |
| 868 | if (!xAccessibleAction.is()) |
| 869 | return actionNames; |
| 870 | |
| 871 | int count = xAccessibleAction->getAccessibleActionCount(); |
| 872 | for (int i = 0; i < count; i++) |
| 873 | { |
| 874 | OUString desc = xAccessibleAction->getAccessibleActionDescription(i); |
| 875 | actionNames.append(toQString(desc)); |
| 876 | } |
| 877 | return actionNames; |
| 878 | } |
| 879 | |
| 880 | void QtAccessibleWidget::doAction(const QString& actionName) |
| 881 | { |
| 882 | Reference<XAccessibleAction> xAccessibleAction(getAccessibleContextImpl(), UNO_QUERY); |
| 883 | if (!xAccessibleAction.is()) |
| 884 | return; |
| 885 | |
| 886 | int index = actionNames().indexOf(actionName); |
| 887 | if (index == -1) |
| 888 | return; |
| 889 | xAccessibleAction->doAccessibleAction(index); |
| 890 | } |
| 891 | |
| 892 | QStringList QtAccessibleWidget::keyBindingsForAction(const QString& actionName) const |
| 893 | { |
| 894 | QStringList keyBindings; |
| 895 | Reference<XAccessibleAction> xAccessibleAction(getAccessibleContextImpl(), UNO_QUERY); |
| 896 | if (!xAccessibleAction.is()) |
| 897 | return keyBindings; |
| 898 | |
| 899 | int index = actionNames().indexOf(actionName); |
| 900 | if (index == -1) |
| 901 | return keyBindings; |
| 902 | |
| 903 | Reference<XAccessibleKeyBinding> xKeyBinding |
| 904 | = xAccessibleAction->getAccessibleActionKeyBinding(index); |
| 905 | |
| 906 | if (!xKeyBinding.is()) |
| 907 | return keyBindings; |
| 908 | |
| 909 | int count = xKeyBinding->getAccessibleKeyBindingCount(); |
| 910 | for (int i = 0; i < count; i++) |
| 911 | { |
| 912 | Sequence<awt::KeyStroke> keyStroke = xKeyBinding->getAccessibleKeyBinding(i); |
| 913 | keyBindings.append(toQString(comphelper::GetkeyBindingStrByXkeyBinding(keyStroke))); |
| 914 | } |
| 915 | return keyBindings; |
| 916 | } |
| 917 | |
| 918 | #if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) |
| 919 | |
| 920 | // QAccessibleAttributesInterface helpers |
| 921 | namespace |
| 922 | { |
| 923 | void lcl_insertAttribute(QHash<QAccessible::Attribute, QVariant>& rQtAttrs, const OUString& rName, |
| 924 | const OUString& rValue) |
| 925 | { |
| 926 | if (rName == u"level"_ustr) |
| 927 | { |
| 928 | rQtAttrs.insert(QAccessible::Attribute::Level, |
| 929 | QVariant::fromValue(static_cast<int>(rValue.toInt32()))); |
| 930 | } |
| 931 | else |
| 932 | { |
| 933 | // for now, leave not explicitly handled attributes as they are and report |
| 934 | // via QAccessible::Attribute::Custom, but should consider suggesting to |
| 935 | // add more specific attributes on Qt side and use those instead |
| 936 | const QVariant aVariant = rQtAttrs.value(QAccessible::Attribute::Custom, |
| 937 | QVariant::fromValue(QHash<QString, QString>())); |
| 938 | assert((aVariant.canConvert<QHash<QString, QString>>())); |
| 939 | QHash<QString, QString> aAttrs = aVariant.value<QHash<QString, QString>>(); |
| 940 | aAttrs.insert(toQString(rName), toQString(rValue)); |
| 941 | rQtAttrs.insert(QAccessible::Attribute::Custom, QVariant::fromValue(aAttrs)); |
| 942 | } |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | QHash<QAccessible::Attribute, QVariant> QtAccessibleWidget::attributes() const |
| 947 | { |
| 948 | Reference<XAccessibleContext> xContext = getAccessibleContextImpl(); |
| 949 | if (!xContext.is()) |
| 950 | return {}; |
| 951 | |
| 952 | QHash<QAccessible::Attribute, QVariant> aQtAttrs; |
| 953 | |
| 954 | #if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0) |
| 955 | const css::lang::Locale aLocale = xContext->getLocale(); |
| 956 | const QLocale aQLocale(toQString(aLocale.Language + u"_" + aLocale.Country)); |
| 957 | aQtAttrs.insert(QAccessible::Attribute::Locale, aQLocale); |
| 958 | #endif |
| 959 | |
| 960 | #if QT_VERSION >= QT_VERSION_CHECK(6, 11, 0) |
| 961 | const sal_Int64 nStates = xContext->getAccessibleStateSet(); |
| 962 | if (nStates & css::accessibility::AccessibleStateType::HORIZONTAL) |
| 963 | aQtAttrs.insert(QAccessible::Attribute::Orientation, Qt::Horizontal); |
| 964 | else if (nStates & css::accessibility::AccessibleStateType::VERTICAL) |
| 965 | aQtAttrs.insert(QAccessible::Attribute::Orientation, Qt::Vertical); |
| 966 | #endif |
| 967 | |
| 968 | Reference<XAccessibleExtendedAttributes> xAttributes(xContext, UNO_QUERY); |
| 969 | if (!xAttributes.is()) |
| 970 | return aQtAttrs; |
| 971 | |
| 972 | const OUString sAttrs = xAttributes->getExtendedAttributes(); |
| 973 | sal_Int32 nIndex = 0; |
| 974 | do |
| 975 | { |
| 976 | const OUString sAttribute = sAttrs.getToken(0, ';', nIndex); |
| 977 | sal_Int32 nColonPos = 0; |
| 978 | const OUString sName = sAttribute.getToken(0, ':', nColonPos); |
| 979 | const OUString sValue = sAttribute.getToken(0, ':', nColonPos); |
| 980 | assert(nColonPos == -1 |
| 981 | && "Too many colons in attribute that should have \"name:value\" syntax"); |
| 982 | if (!sName.isEmpty()) |
| 983 | lcl_insertAttribute(aQtAttrs, sName, sValue); |
| 984 | } while (nIndex >= 0); |
| 985 | |
| 986 | return aQtAttrs; |
| 987 | } |
| 988 | |
| 989 | // QAccessibleAttributesInterface |
| 990 | QList<QAccessible::Attribute> QtAccessibleWidget::attributeKeys() const |
| 991 | { |
| 992 | const QHash<QAccessible::Attribute, QVariant> aAttributes = attributes(); |
| 993 | return aAttributes.keys(); |
| 994 | } |
| 995 | |
| 996 | QVariant QtAccessibleWidget::attributeValue(QAccessible::Attribute eAttribute) const |
| 997 | { |
| 998 | const QHash<QAccessible::Attribute, QVariant> aAllAttributes = attributes(); |
| 999 | return aAllAttributes.value(eAttribute); |
| 1000 | } |
| 1001 | #endif |
| 1002 | |
| 1003 | // QAccessibleTextInterface |
| 1004 | void QtAccessibleWidget::addSelection(int startOffset, int endOffset) |
| 1005 | { |
| 1006 | // only single selection supported currently |
| 1007 | if (selectionCount() > 0) |
| 1008 | return; |
| 1009 | |
| 1010 | Reference<XAccessibleText> xText(getAccessibleContextImpl(), UNO_QUERY); |
| 1011 | if (!xText.is()) |
| 1012 | return; |
| 1013 | |
| 1014 | const sal_Int32 nTextLength = xText->getCharacterCount(); |
| 1015 | if (startOffset < 0 || startOffset > nTextLength || endOffset < 0 || endOffset > nTextLength) |
| 1016 | { |
| 1017 | SAL_WARN("vcl.qt", "QtAccessibleWidget::addSelection called with invalid offset."); |
| 1018 | return; |
| 1019 | } |
| 1020 | |
| 1021 | xText->setSelection(startOffset, endOffset); |
| 1022 | } |
| 1023 | |
| 1024 | // Text attributes are returned in format specified in IAccessible2 spec, since that |
| 1025 | // is what Qt handles: |
| 1026 | // https://wiki.linuxfoundation.org/accessibility/iaccessible2/textattributes |
| 1027 | QString QtAccessibleWidget::attributes(int offset, int* startOffset, int* endOffset) const |
| 1028 | { |
| 1029 | if (startOffset == nullptr || endOffset == nullptr) |
| 1030 | return QString(); |
| 1031 | |
| 1032 | *startOffset = -1; |
| 1033 | *endOffset = -1; |
| 1034 | |
| 1035 | Reference<XAccessibleText> xText(getAccessibleContextImpl(), UNO_QUERY); |
| 1036 | if (!xText.is()) |
| 1037 | return QString(); |
| 1038 | |
| 1039 | // handle special values for offset the same way base class's QAccessibleTextWidget::attributes does |
| 1040 | // (as defined in IAccessible 2: -1 -> length, -2 -> cursor position) |
| 1041 | if (offset == -2) |
| 1042 | offset = cursorPosition(); |
| 1043 | |
| 1044 | const int nTextLength = characterCount(); |
| 1045 | if (offset == -1 || offset == nTextLength) |
| 1046 | offset = nTextLength - 1; |
| 1047 | |
| 1048 | if (offset < 0 || offset > nTextLength) |
| 1049 | { |
| 1050 | SAL_WARN("vcl.qt", "QtAccessibleWidget::attributes called with invalid offset: " << offset); |
| 1051 | return QString(); |
| 1052 | } |
| 1053 | |
| 1054 | // Qt doesn't have the strict separation into text and object attributes, but also |
| 1055 | // supports text-specific attributes that are object attributes according to the |
| 1056 | // IAccessible2 spec. |
| 1057 | sal_Int32 nStart = 0; |
| 1058 | sal_Int32 nEnd = 0; |
| 1059 | const OUString aRet = AccessibleTextAttributeHelper::GetIAccessible2TextAttributes( |
| 1060 | xText, IA2AttributeType::TextAttributes | IA2AttributeType::ObjectAttributes, |
| 1061 | static_cast<sal_Int32>(offset), nStart, nEnd); |
| 1062 | *startOffset = static_cast<int>(nStart); |
| 1063 | *endOffset = static_cast<int>(nEnd); |
| 1064 | return toQString(aRet); |
| 1065 | } |
| 1066 | |
| 1067 | int QtAccessibleWidget::characterCount() const |
| 1068 | { |
| 1069 | Reference<XAccessibleText> xText(getAccessibleContextImpl(), UNO_QUERY); |
| 1070 | if (xText.is()) |
| 1071 | return xText->getCharacterCount(); |
| 1072 | return 0; |
| 1073 | } |
| 1074 | |
| 1075 | QRect QtAccessibleWidget::characterRect(int nOffset) const |
| 1076 | { |
| 1077 | Reference<XAccessibleText> xText(getAccessibleContextImpl(), UNO_QUERY); |
| 1078 | if (!xText.is()) |
| 1079 | return QRect(); |
| 1080 | |
| 1081 | if (nOffset < 0 || nOffset > xText->getCharacterCount()) |
| 1082 | { |
| 1083 | SAL_WARN("vcl.qt", |
| 1084 | "QtAccessibleWidget::characterRect called with invalid offset: " << nOffset); |
| 1085 | return QRect(); |
| 1086 | } |
| 1087 | |
| 1088 | const awt::Rectangle aBounds = xText->getCharacterBounds(nOffset); |
| 1089 | const QRect aRect(aBounds.X, aBounds.Y, aBounds.Width, aBounds.Height); |
| 1090 | // convert to screen coordinates |
| 1091 | const QRect aScreenPos = rect(); |
| 1092 | return aRect.translated(aScreenPos.x(), aScreenPos.y()); |
| 1093 | } |
| 1094 | |
| 1095 | int QtAccessibleWidget::cursorPosition() const |
| 1096 | { |
| 1097 | Reference<XAccessibleText> xText(getAccessibleContextImpl(), UNO_QUERY); |
| 1098 | if (xText.is()) |
| 1099 | return xText->getCaretPosition(); |
| 1100 | return 0; |
| 1101 | } |
| 1102 | |
| 1103 | int QtAccessibleWidget::offsetAtPoint(const QPoint& rPoint) const |
| 1104 | { |
| 1105 | Reference<XAccessibleText> xText(getAccessibleContextImpl(), UNO_QUERY); |
| 1106 | if (!xText.is()) |
| 1107 | return -1; |
| 1108 | |
| 1109 | // convert from screen to local coordinates |
| 1110 | QPoint aLocalCoords = rPoint - rect().topLeft(); |
| 1111 | awt::Point aPoint(aLocalCoords.x(), aLocalCoords.y()); |
| 1112 | return xText->getIndexAtPoint(aPoint); |
| 1113 | } |
| 1114 | |
| 1115 | void QtAccessibleWidget::removeSelection(int selectionIndex) |
| 1116 | { |
| 1117 | if (selectionIndex < 0 || selectionIndex >= selectionCount()) |
| 1118 | { |
| 1119 | SAL_WARN("vcl.qt", "QtAccessibleWidget::removeSelection called with invalid index"); |
| 1120 | return; |
| 1121 | } |
| 1122 | |
| 1123 | Reference<XAccessibleText> xText(getAccessibleContextImpl(), UNO_QUERY); |
| 1124 | if (!xText.is()) |
| 1125 | return; |
| 1126 | |
| 1127 | // only single selection supported at the moment (s.a. seleciontCount(); |
| 1128 | // code below needs adjustment if that changes |
| 1129 | assert(selectionIndex == 0); |
| 1130 | |
| 1131 | const sal_Int32 nCaretPos = xText->getCaretPosition(); |
| 1132 | xText->setSelection(nCaretPos, nCaretPos); |
| 1133 | } |
| 1134 | |
| 1135 | void QtAccessibleWidget::scrollToSubstring(int startIndex, int endIndex) |
| 1136 | { |
| 1137 | Reference<XAccessibleText> xText(getAccessibleContextImpl(), UNO_QUERY); |
| 1138 | if (!xText.is()) |
| 1139 | return; |
| 1140 | |
| 1141 | sal_Int32 nTextLength = xText->getCharacterCount(); |
| 1142 | if (startIndex < 0 || startIndex > nTextLength || endIndex < 0 || endIndex > nTextLength) |
| 1143 | { |
| 1144 | SAL_WARN("vcl.qt", "QtAccessibleWidget::scrollToSubstring called with invalid offset."); |
| 1145 | return; |
| 1146 | } |
| 1147 | |
| 1148 | xText->scrollSubstringTo(startIndex, endIndex, AccessibleScrollType_SCROLL_ANYWHERE); |
| 1149 | } |
| 1150 | |
| 1151 | void QtAccessibleWidget::selection(int selectionIndex, int* startOffset, int* endOffset) const |
| 1152 | { |
| 1153 | if (!startOffset && !endOffset) |
| 1154 | return; |
| 1155 | |
| 1156 | Reference<XAccessibleText> xText; |
| 1157 | if (selectionIndex == 0) |
| 1158 | xText = Reference<XAccessibleText>(getAccessibleContextImpl(), UNO_QUERY); |
| 1159 | |
| 1160 | if (startOffset) |
| 1161 | *startOffset = xText.is() ? xText->getSelectionStart() : 0; |
| 1162 | if (endOffset) |
| 1163 | *endOffset = xText.is() ? xText->getSelectionEnd() : 0; |
| 1164 | } |
| 1165 | |
| 1166 | int QtAccessibleWidget::selectionCount() const |
| 1167 | { |
| 1168 | Reference<XAccessibleText> xText(getAccessibleContextImpl(), UNO_QUERY); |
| 1169 | if (xText.is() && !xText->getSelectedText().isEmpty()) |
| 1170 | return 1; // Only 1 selection supported atm |
| 1171 | return 0; |
| 1172 | } |
| 1173 | |
| 1174 | void QtAccessibleWidget::setCursorPosition(int position) |
| 1175 | { |
| 1176 | Reference<XAccessibleText> xText(getAccessibleContextImpl(), UNO_QUERY); |
| 1177 | if (!xText.is()) |
| 1178 | return; |
| 1179 | |
| 1180 | if (position < 0 || position > xText->getCharacterCount()) |
| 1181 | { |
| 1182 | SAL_WARN("vcl.qt", |
| 1183 | "QtAccessibleWidget::setCursorPosition called with invalid offset: " << position); |
| 1184 | return; |
| 1185 | } |
| 1186 | |
| 1187 | xText->setCaretPosition(position); |
| 1188 | } |
| 1189 | |
| 1190 | void QtAccessibleWidget::setSelection(int /* selectionIndex */, int startOffset, int endOffset) |
| 1191 | { |
| 1192 | Reference<XAccessibleText> xText(getAccessibleContextImpl(), UNO_QUERY); |
| 1193 | if (!xText.is()) |
| 1194 | return; |
| 1195 | |
| 1196 | sal_Int32 nTextLength = xText->getCharacterCount(); |
| 1197 | if (startOffset < 0 || startOffset > nTextLength || endOffset < 0 || endOffset > nTextLength) |
| 1198 | { |
| 1199 | SAL_WARN("vcl.qt", "QtAccessibleWidget::setSelection called with invalid offset."); |
| 1200 | return; |
| 1201 | } |
| 1202 | |
| 1203 | xText->setSelection(startOffset, endOffset); |
| 1204 | } |
| 1205 | |
| 1206 | QString QtAccessibleWidget::text(int startOffset, int endOffset) const |
| 1207 | { |
| 1208 | Reference<XAccessibleText> xText(getAccessibleContextImpl(), UNO_QUERY); |
| 1209 | if (!xText.is()) |
| 1210 | return QString(); |
| 1211 | |
| 1212 | sal_Int32 nTextLength = xText->getCharacterCount(); |
| 1213 | if (startOffset < 0 || startOffset > nTextLength || endOffset < 0 || endOffset > nTextLength) |
| 1214 | { |
| 1215 | SAL_WARN("vcl.qt", "QtAccessibleWidget::text called with invalid offset."); |
| 1216 | return QString(); |
| 1217 | } |
| 1218 | |
| 1219 | return toQString(xText->getTextRange(startOffset, endOffset)); |
| 1220 | } |
| 1221 | |
| 1222 | QString QtAccessibleWidget::textAfterOffset(int nOffset, |
| 1223 | QAccessible::TextBoundaryType eBoundaryType, |
| 1224 | int* pStartOffset, int* pEndOffset) const |
| 1225 | { |
| 1226 | if (pStartOffset == nullptr || pEndOffset == nullptr) |
| 1227 | return QString(); |
| 1228 | |
| 1229 | *pStartOffset = -1; |
| 1230 | *pEndOffset = -1; |
| 1231 | |
| 1232 | Reference<XAccessibleText> xText(getAccessibleContextImpl(), UNO_QUERY); |
| 1233 | if (!xText.is()) |
| 1234 | return QString(); |
| 1235 | |
| 1236 | const int nCharCount = characterCount(); |
| 1237 | // -1 is special value for text length |
| 1238 | if (nOffset == -1) |
| 1239 | nOffset = nCharCount; |
| 1240 | else if (nOffset < -1 || nOffset > nCharCount) |
| 1241 | { |
| 1242 | SAL_WARN("vcl.qt", |
| 1243 | "QtAccessibleWidget::textAfterOffset called with invalid offset: " << nOffset); |
| 1244 | return QString(); |
| 1245 | } |
| 1246 | |
| 1247 | if (eBoundaryType == QAccessible::NoBoundary) |
| 1248 | { |
| 1249 | if (nOffset == nCharCount) |
| 1250 | return QString(); |
| 1251 | *pStartOffset = nOffset + 1; |
| 1252 | *pEndOffset = nCharCount; |
| 1253 | return text(nOffset + 1, nCharCount); |
| 1254 | } |
| 1255 | |
| 1256 | sal_Int16 nUnoBoundaryType = lcl_matchQtTextBoundaryType(eBoundaryType); |
| 1257 | assert(nUnoBoundaryType > 0); |
| 1258 | const TextSegment aSegment = xText->getTextBehindIndex(nOffset, nUnoBoundaryType); |
| 1259 | *pStartOffset = aSegment.SegmentStart; |
| 1260 | *pEndOffset = aSegment.SegmentEnd; |
| 1261 | return toQString(aSegment.SegmentText); |
| 1262 | } |
| 1263 | |
| 1264 | QString QtAccessibleWidget::textAtOffset(int offset, QAccessible::TextBoundaryType boundaryType, |
| 1265 | int* startOffset, int* endOffset) const |
| 1266 | { |
| 1267 | if (startOffset == nullptr || endOffset == nullptr) |
| 1268 | return QString(); |
| 1269 | |
| 1270 | const int nCharCount = characterCount(); |
| 1271 | if (boundaryType == QAccessible::NoBoundary) |
| 1272 | { |
| 1273 | *startOffset = 0; |
| 1274 | *endOffset = nCharCount; |
| 1275 | return text(0, nCharCount); |
| 1276 | } |
| 1277 | |
| 1278 | Reference<XAccessibleText> xText(getAccessibleContextImpl(), UNO_QUERY); |
| 1279 | if (!xText.is()) |
| 1280 | return QString(); |
| 1281 | |
| 1282 | sal_Int16 nUnoBoundaryType = lcl_matchQtTextBoundaryType(boundaryType); |
| 1283 | assert(nUnoBoundaryType > 0); |
| 1284 | |
| 1285 | // special value of -1 for offset means text length |
| 1286 | if (offset == -1) |
| 1287 | offset = nCharCount; |
| 1288 | |
| 1289 | if (offset < 0 || offset > nCharCount) |
| 1290 | { |
| 1291 | SAL_WARN("vcl.qt", |
| 1292 | "QtAccessibleWidget::textAtOffset called with invalid offset: " << offset); |
| 1293 | return QString(); |
| 1294 | } |
| 1295 | |
| 1296 | const TextSegment segment = xText->getTextAtIndex(offset, nUnoBoundaryType); |
| 1297 | *startOffset = segment.SegmentStart; |
| 1298 | *endOffset = segment.SegmentEnd; |
| 1299 | return toQString(segment.SegmentText); |
| 1300 | } |
| 1301 | |
| 1302 | QString QtAccessibleWidget::textBeforeOffset(int nOffset, |
| 1303 | QAccessible::TextBoundaryType eBoundaryType, |
| 1304 | int* pStartOffset, int* pEndOffset) const |
| 1305 | { |
| 1306 | if (pStartOffset == nullptr || pEndOffset == nullptr) |
| 1307 | return QString(); |
| 1308 | |
| 1309 | *pStartOffset = -1; |
| 1310 | *pEndOffset = -1; |
| 1311 | |
| 1312 | Reference<XAccessibleText> xText(getAccessibleContextImpl(), UNO_QUERY); |
| 1313 | if (!xText.is()) |
| 1314 | return QString(); |
| 1315 | |
| 1316 | const int nCharCount = characterCount(); |
| 1317 | // -1 is special value for text length |
| 1318 | if (nOffset == -1) |
| 1319 | nOffset = nCharCount; |
| 1320 | else if (nOffset < -1 || nOffset > nCharCount) |
| 1321 | { |
| 1322 | SAL_WARN("vcl.qt", |
| 1323 | "QtAccessibleWidget::textBeforeOffset called with invalid offset: " << nOffset); |
| 1324 | return QString(); |
| 1325 | } |
| 1326 | |
| 1327 | if (eBoundaryType == QAccessible::NoBoundary) |
| 1328 | { |
| 1329 | *pStartOffset = 0; |
| 1330 | *pEndOffset = nOffset; |
| 1331 | return text(0, nOffset); |
| 1332 | } |
| 1333 | |
| 1334 | sal_Int16 nUnoBoundaryType = lcl_matchQtTextBoundaryType(eBoundaryType); |
| 1335 | assert(nUnoBoundaryType > 0); |
| 1336 | const TextSegment aSegment = xText->getTextBeforeIndex(nOffset, nUnoBoundaryType); |
| 1337 | *pStartOffset = aSegment.SegmentStart; |
| 1338 | *pEndOffset = aSegment.SegmentEnd; |
| 1339 | return toQString(aSegment.SegmentText); |
| 1340 | } |
| 1341 | |
| 1342 | // QAccessibleEditableTextInterface |
| 1343 | |
| 1344 | void QtAccessibleWidget::deleteText(int startOffset, int endOffset) |
| 1345 | { |
| 1346 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1347 | if (!xAc.is()) |
| 1348 | return; |
| 1349 | |
| 1350 | Reference<XAccessibleEditableText> xEditableText(xAc, UNO_QUERY); |
| 1351 | if (!xEditableText.is()) |
| 1352 | return; |
| 1353 | |
| 1354 | sal_Int32 nTextLength = xEditableText->getCharacterCount(); |
| 1355 | if (startOffset < 0 || startOffset > nTextLength || endOffset < 0 || endOffset > nTextLength) |
| 1356 | { |
| 1357 | SAL_WARN("vcl.qt", "QtAccessibleWidget::deleteText called with invalid offset."); |
| 1358 | return; |
| 1359 | } |
| 1360 | |
| 1361 | xEditableText->deleteText(startOffset, endOffset); |
| 1362 | } |
| 1363 | |
| 1364 | void QtAccessibleWidget::insertText(int offset, const QString& text) |
| 1365 | { |
| 1366 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1367 | if (!xAc.is()) |
| 1368 | return; |
| 1369 | |
| 1370 | Reference<XAccessibleEditableText> xEditableText(xAc, UNO_QUERY); |
| 1371 | if (!xEditableText.is()) |
| 1372 | return; |
| 1373 | |
| 1374 | if (offset < 0 || offset > xEditableText->getCharacterCount()) |
| 1375 | { |
| 1376 | SAL_WARN("vcl.qt", "QtAccessibleWidget::insertText called with invalid offset: " << offset); |
| 1377 | return; |
| 1378 | } |
| 1379 | |
| 1380 | xEditableText->insertText(toOUString(text), offset); |
| 1381 | } |
| 1382 | |
| 1383 | void QtAccessibleWidget::replaceText(int startOffset, int endOffset, const QString& text) |
| 1384 | { |
| 1385 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1386 | if (!xAc.is()) |
| 1387 | return; |
| 1388 | |
| 1389 | Reference<XAccessibleEditableText> xEditableText(xAc, UNO_QUERY); |
| 1390 | if (!xEditableText.is()) |
| 1391 | return; |
| 1392 | |
| 1393 | sal_Int32 nTextLength = xEditableText->getCharacterCount(); |
| 1394 | if (startOffset < 0 || startOffset > nTextLength || endOffset < 0 || endOffset > nTextLength) |
| 1395 | { |
| 1396 | SAL_WARN("vcl.qt", "QtAccessibleWidget::replaceText called with invalid offset."); |
| 1397 | return; |
| 1398 | } |
| 1399 | |
| 1400 | xEditableText->replaceText(startOffset, endOffset, toOUString(text)); |
| 1401 | } |
| 1402 | |
| 1403 | // QAccessibleValueInterface |
| 1404 | QVariant QtAccessibleWidget::currentValue() const |
| 1405 | { |
| 1406 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1407 | if (!xAc.is()) |
| 1408 | return QVariant(); |
| 1409 | |
| 1410 | Reference<XAccessibleValue> xValue(xAc, UNO_QUERY); |
| 1411 | if (!xValue.is()) |
| 1412 | return QVariant(); |
| 1413 | double aDouble = 0; |
| 1414 | xValue->getCurrentValue() >>= aDouble; |
| 1415 | return QVariant(aDouble); |
| 1416 | } |
| 1417 | |
| 1418 | QVariant QtAccessibleWidget::maximumValue() const |
| 1419 | { |
| 1420 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1421 | if (!xAc.is()) |
| 1422 | return QVariant(); |
| 1423 | |
| 1424 | Reference<XAccessibleValue> xValue(xAc, UNO_QUERY); |
| 1425 | if (!xValue.is()) |
| 1426 | return QVariant(); |
| 1427 | double aDouble = 0; |
| 1428 | xValue->getMaximumValue() >>= aDouble; |
| 1429 | return QVariant(aDouble); |
| 1430 | } |
| 1431 | |
| 1432 | QVariant QtAccessibleWidget::minimumStepSize() const |
| 1433 | { |
| 1434 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1435 | if (!xAc.is()) |
| 1436 | return QVariant(); |
| 1437 | |
| 1438 | Reference<XAccessibleValue> xValue(xAc, UNO_QUERY); |
| 1439 | if (!xValue.is()) |
| 1440 | return QVariant(); |
| 1441 | double dMinStep = 0; |
| 1442 | xValue->getMinimumIncrement() >>= dMinStep; |
| 1443 | return QVariant(dMinStep); |
| 1444 | } |
| 1445 | |
| 1446 | QVariant QtAccessibleWidget::minimumValue() const |
| 1447 | { |
| 1448 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1449 | if (!xAc.is()) |
| 1450 | return QVariant(); |
| 1451 | |
| 1452 | Reference<XAccessibleValue> xValue(xAc, UNO_QUERY); |
| 1453 | if (!xValue.is()) |
| 1454 | return QVariant(); |
| 1455 | double aDouble = 0; |
| 1456 | xValue->getMinimumValue() >>= aDouble; |
| 1457 | return QVariant(aDouble); |
| 1458 | } |
| 1459 | |
| 1460 | void QtAccessibleWidget::setCurrentValue(const QVariant& value) |
| 1461 | { |
| 1462 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1463 | if (!xAc.is()) |
| 1464 | return; |
| 1465 | |
| 1466 | Reference<XAccessibleValue> xValue(xAc, UNO_QUERY); |
| 1467 | if (!xValue.is()) |
| 1468 | return; |
| 1469 | |
| 1470 | // Different types of numerical values for XAccessibleValue are possible. |
| 1471 | // If current value has an integer type, also use that for the new value, to make |
| 1472 | // sure underlying implementations expecting that can handle the value properly. |
| 1473 | const Any aCurrentValue = xValue->getCurrentValue(); |
| 1474 | if (aCurrentValue.getValueTypeClass() == css::uno::TypeClass::TypeClass_LONG) |
| 1475 | xValue->setCurrentValue(Any(static_cast<sal_Int32>(value.toInt()))); |
| 1476 | else if (aCurrentValue.getValueTypeClass() == css::uno::TypeClass::TypeClass_HYPER) |
| 1477 | xValue->setCurrentValue(Any(static_cast<sal_Int64>(value.toLongLong()))); |
| 1478 | else |
| 1479 | xValue->setCurrentValue(Any(value.toDouble())); |
| 1480 | } |
| 1481 | |
| 1482 | // QAccessibleTableInterface |
| 1483 | QAccessibleInterface* QtAccessibleWidget::caption() const |
| 1484 | { |
| 1485 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1486 | if (!xAc.is()) |
| 1487 | return nullptr; |
| 1488 | |
| 1489 | Reference<XAccessibleTable> xTable(xAc, UNO_QUERY); |
| 1490 | if (!xTable.is()) |
| 1491 | return nullptr; |
| 1492 | return QAccessible::queryAccessibleInterface( |
| 1493 | QtAccessibleRegistry::getQObject(xTable->getAccessibleCaption())); |
| 1494 | } |
| 1495 | |
| 1496 | QAccessibleInterface* QtAccessibleWidget::cellAt(int row, int column) const |
| 1497 | { |
| 1498 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1499 | if (!xAc.is()) |
| 1500 | return nullptr; |
| 1501 | |
| 1502 | Reference<XAccessibleTable> xTable(xAc, UNO_QUERY); |
| 1503 | if (!xTable.is()) |
| 1504 | return nullptr; |
| 1505 | |
| 1506 | if (row < 0 || row >= xTable->getAccessibleRowCount() || column < 0 |
| 1507 | || column >= xTable->getAccessibleColumnCount()) |
| 1508 | { |
| 1509 | SAL_WARN("vcl.qt", "QtAccessibleWidget::cellAt called with invalid row/column index (" |
| 1510 | << row << ", " << column << ")"); |
| 1511 | return nullptr; |
| 1512 | } |
| 1513 | |
| 1514 | return QAccessible::queryAccessibleInterface( |
| 1515 | QtAccessibleRegistry::getQObject(xTable->getAccessibleCellAt(row, column))); |
| 1516 | } |
| 1517 | |
| 1518 | int QtAccessibleWidget::columnCount() const |
| 1519 | { |
| 1520 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1521 | if (!xAc.is()) |
| 1522 | return 0; |
| 1523 | |
| 1524 | Reference<XAccessibleTable> xTable(xAc, UNO_QUERY); |
| 1525 | if (!xTable.is()) |
| 1526 | return 0; |
| 1527 | return xTable->getAccessibleColumnCount(); |
| 1528 | } |
| 1529 | |
| 1530 | QString QtAccessibleWidget::columnDescription(int column) const |
| 1531 | { |
| 1532 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1533 | if (!xAc.is()) |
| 1534 | return QString(); |
| 1535 | |
| 1536 | Reference<XAccessibleTable> xTable(xAc, UNO_QUERY); |
| 1537 | if (!xTable.is()) |
| 1538 | return QString(); |
| 1539 | return toQString(xTable->getAccessibleColumnDescription(column)); |
| 1540 | } |
| 1541 | |
| 1542 | bool QtAccessibleWidget::isColumnSelected(int nColumn) const |
| 1543 | { |
| 1544 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1545 | if (!xAc.is()) |
| 1546 | return false; |
| 1547 | |
| 1548 | Reference<XAccessibleTable> xTable(xAc, UNO_QUERY); |
| 1549 | if (!xTable.is()) |
| 1550 | return false; |
| 1551 | |
| 1552 | if (nColumn < 0 || nColumn >= xTable->getAccessibleColumnCount()) |
| 1553 | { |
| 1554 | SAL_WARN("vcl.qt", "QtAccessibleWidget::isColumnSelected called with invalid column index " |
| 1555 | << nColumn); |
| 1556 | return false; |
| 1557 | } |
| 1558 | |
| 1559 | return xTable->isAccessibleColumnSelected(nColumn); |
| 1560 | } |
| 1561 | |
| 1562 | bool QtAccessibleWidget::isRowSelected(int nRow) const |
| 1563 | { |
| 1564 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1565 | if (!xAc.is()) |
| 1566 | return false; |
| 1567 | |
| 1568 | Reference<XAccessibleTable> xTable(xAc, UNO_QUERY); |
| 1569 | if (!xTable.is()) |
| 1570 | return false; |
| 1571 | |
| 1572 | if (nRow < 0 || nRow >= xTable->getAccessibleRowCount()) |
| 1573 | { |
| 1574 | SAL_WARN("vcl.qt", |
| 1575 | "QtAccessibleWidget::isRowSelected called with invalid row index " << nRow); |
| 1576 | return false; |
| 1577 | } |
| 1578 | |
| 1579 | return xTable->isAccessibleRowSelected(nRow); |
| 1580 | } |
| 1581 | |
| 1582 | void QtAccessibleWidget::modelChange(QAccessibleTableModelChangeEvent*) {} |
| 1583 | |
| 1584 | int QtAccessibleWidget::rowCount() const |
| 1585 | { |
| 1586 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1587 | if (!xAc.is()) |
| 1588 | return 0; |
| 1589 | |
| 1590 | Reference<XAccessibleTable> xTable(xAc, UNO_QUERY); |
| 1591 | if (!xTable.is()) |
| 1592 | return 0; |
| 1593 | return xTable->getAccessibleRowCount(); |
| 1594 | } |
| 1595 | |
| 1596 | QString QtAccessibleWidget::rowDescription(int row) const |
| 1597 | { |
| 1598 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1599 | if (!xAc.is()) |
| 1600 | return QString(); |
| 1601 | |
| 1602 | Reference<XAccessibleTable> xTable(xAc, UNO_QUERY); |
| 1603 | if (!xTable.is()) |
| 1604 | return QString(); |
| 1605 | return toQString(xTable->getAccessibleRowDescription(row)); |
| 1606 | } |
| 1607 | |
| 1608 | bool QtAccessibleWidget::selectColumn(int column) |
| 1609 | { |
| 1610 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1611 | if (!xAc.is()) |
| 1612 | return false; |
| 1613 | |
| 1614 | if (column < 0 || column >= columnCount()) |
| 1615 | { |
| 1616 | SAL_WARN("vcl.qt", |
| 1617 | "QtAccessibleWidget::selectColumn called with invalid column index " << column); |
| 1618 | return false; |
| 1619 | } |
| 1620 | |
| 1621 | Reference<XAccessibleTableSelection> xTableSelection(xAc, UNO_QUERY); |
| 1622 | if (!xTableSelection.is()) |
| 1623 | return false; |
| 1624 | return xTableSelection->selectColumn(column); |
| 1625 | } |
| 1626 | |
| 1627 | bool QtAccessibleWidget::selectRow(int row) |
| 1628 | { |
| 1629 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1630 | if (!xAc.is()) |
| 1631 | return false; |
| 1632 | |
| 1633 | if (row < 0 || row >= rowCount()) |
| 1634 | { |
| 1635 | SAL_WARN("vcl.qt", "QtAccessibleWidget::selectRow called with invalid row index " << row); |
| 1636 | return false; |
| 1637 | } |
| 1638 | |
| 1639 | Reference<XAccessibleTableSelection> xTableSelection(xAc, UNO_QUERY); |
| 1640 | if (!xTableSelection.is()) |
| 1641 | return false; |
| 1642 | return xTableSelection->selectRow(row); |
| 1643 | } |
| 1644 | |
| 1645 | int QtAccessibleWidget::selectedCellCount() const { return selectedItemCount(); } |
| 1646 | |
| 1647 | QList<QAccessibleInterface*> QtAccessibleWidget::selectedCells() const { return selectedItems(); } |
| 1648 | |
| 1649 | int QtAccessibleWidget::selectedColumnCount() const |
| 1650 | { |
| 1651 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1652 | if (!xAc.is()) |
| 1653 | return 0; |
| 1654 | |
| 1655 | Reference<XAccessibleTable> xTable(xAc, UNO_QUERY); |
| 1656 | if (!xTable.is()) |
| 1657 | return 0; |
| 1658 | return xTable->getSelectedAccessibleColumns().getLength(); |
| 1659 | } |
| 1660 | |
| 1661 | QList<int> QtAccessibleWidget::selectedColumns() const |
| 1662 | { |
| 1663 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1664 | if (!xAc.is()) |
| 1665 | return QList<int>(); |
| 1666 | |
| 1667 | Reference<XAccessibleTable> xTable(xAc, UNO_QUERY); |
| 1668 | if (!xTable.is()) |
| 1669 | return QList<int>(); |
| 1670 | return toQList(xTable->getSelectedAccessibleColumns()); |
| 1671 | } |
| 1672 | |
| 1673 | int QtAccessibleWidget::selectedRowCount() const |
| 1674 | { |
| 1675 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1676 | if (!xAc.is()) |
| 1677 | return 0; |
| 1678 | |
| 1679 | Reference<XAccessibleTable> xTable(xAc, UNO_QUERY); |
| 1680 | if (!xTable.is()) |
| 1681 | return 0; |
| 1682 | return xTable->getSelectedAccessibleRows().getLength(); |
| 1683 | } |
| 1684 | |
| 1685 | QList<int> QtAccessibleWidget::selectedRows() const |
| 1686 | { |
| 1687 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1688 | if (!xAc.is()) |
| 1689 | return QList<int>(); |
| 1690 | |
| 1691 | Reference<XAccessibleTable> xTable(xAc, UNO_QUERY); |
| 1692 | if (!xTable.is()) |
| 1693 | return QList<int>(); |
| 1694 | return toQList(xTable->getSelectedAccessibleRows()); |
| 1695 | } |
| 1696 | |
| 1697 | QAccessibleInterface* QtAccessibleWidget::summary() const |
| 1698 | { |
| 1699 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1700 | if (!xAc.is()) |
| 1701 | return nullptr; |
| 1702 | |
| 1703 | Reference<XAccessibleTable> xTable(xAc, UNO_QUERY); |
| 1704 | if (!xTable.is()) |
| 1705 | return nullptr; |
| 1706 | return QAccessible::queryAccessibleInterface( |
| 1707 | QtAccessibleRegistry::getQObject(xTable->getAccessibleSummary())); |
| 1708 | } |
| 1709 | |
| 1710 | bool QtAccessibleWidget::unselectColumn(int column) |
| 1711 | { |
| 1712 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1713 | if (!xAc.is()) |
| 1714 | return false; |
| 1715 | |
| 1716 | Reference<XAccessibleTableSelection> xTableSelection(xAc, UNO_QUERY); |
| 1717 | if (!xTableSelection.is()) |
| 1718 | return false; |
| 1719 | return xTableSelection->unselectColumn(column); |
| 1720 | } |
| 1721 | |
| 1722 | bool QtAccessibleWidget::unselectRow(int row) |
| 1723 | { |
| 1724 | Reference<XAccessibleContext> xAc = getAccessibleContextImpl(); |
| 1725 | if (!xAc.is()) |
| 1726 | return false; |
| 1727 | |
| 1728 | Reference<XAccessibleTableSelection> xTableSelection(xAc, UNO_QUERY); |
| 1729 | if (!xTableSelection.is()) |
| 1730 | return false; |
| 1731 | return xTableSelection->unselectRow(row); |
| 1732 | } |
| 1733 | |
| 1734 | // QAccessibleTableCellInterface |
| 1735 | QList<QAccessibleInterface*> QtAccessibleWidget::columnHeaderCells() const |
| 1736 | { |
| 1737 | Reference<XAccessibleTable> xTable = getAccessibleTableForParent(); |
| 1738 | if (!xTable.is()) |
| 1739 | return QList<QAccessibleInterface*>(); |
| 1740 | |
| 1741 | Reference<XAccessibleTable> xHeaders = xTable->getAccessibleColumnHeaders(); |
| 1742 | if (!xHeaders.is()) |
| 1743 | return QList<QAccessibleInterface*>(); |
| 1744 | |
| 1745 | const sal_Int32 nCol = columnIndex(); |
| 1746 | QList<QAccessibleInterface*> aHeaderCells; |
| 1747 | for (sal_Int32 nRow = 0; nRow < xHeaders->getAccessibleRowCount(); nRow++) |
| 1748 | { |
| 1749 | Reference<XAccessible> xCell = xHeaders->getAccessibleCellAt(nRow, nCol); |
| 1750 | QAccessibleInterface* pInterface |
| 1751 | = QAccessible::queryAccessibleInterface(QtAccessibleRegistry::getQObject(xCell)); |
| 1752 | aHeaderCells.push_back(pInterface); |
| 1753 | } |
| 1754 | return aHeaderCells; |
| 1755 | } |
| 1756 | |
| 1757 | int QtAccessibleWidget::columnIndex() const |
| 1758 | { |
| 1759 | Reference<XAccessibleContext> xAcc = getAccessibleContextImpl(); |
| 1760 | if (!xAcc.is()) |
| 1761 | return -1; |
| 1762 | |
| 1763 | Reference<XAccessibleTable> xTable = getAccessibleTableForParent(); |
| 1764 | if (!xTable.is()) |
| 1765 | return -1; |
| 1766 | |
| 1767 | const sal_Int64 nIndexInParent = xAcc->getAccessibleIndexInParent(); |
| 1768 | return xTable->getAccessibleColumn(nIndexInParent); |
| 1769 | } |
| 1770 | |
| 1771 | bool QtAccessibleWidget::isSelected() const |
| 1772 | { |
| 1773 | Reference<XAccessibleContext> xAcc = getAccessibleContextImpl(); |
| 1774 | if (!xAcc.is()) |
| 1775 | return false; |
| 1776 | |
| 1777 | Reference<XAccessibleTable> xTable = getAccessibleTableForParent(); |
| 1778 | if (!xTable.is()) |
| 1779 | return false; |
| 1780 | |
| 1781 | const sal_Int32 nColumn = columnIndex(); |
| 1782 | const sal_Int32 nRow = rowIndex(); |
| 1783 | return xTable->isAccessibleSelected(nRow, nColumn); |
| 1784 | } |
| 1785 | |
| 1786 | int QtAccessibleWidget::columnExtent() const |
| 1787 | { |
| 1788 | Reference<XAccessibleContext> xAcc = getAccessibleContextImpl(); |
| 1789 | if (!xAcc.is()) |
| 1790 | return -1; |
| 1791 | |
| 1792 | Reference<XAccessibleTable> xTable = getAccessibleTableForParent(); |
| 1793 | if (!xTable.is()) |
| 1794 | return -1; |
| 1795 | |
| 1796 | const sal_Int32 nColumn = columnIndex(); |
| 1797 | const sal_Int32 nRow = rowIndex(); |
| 1798 | return xTable->getAccessibleColumnExtentAt(nRow, nColumn); |
| 1799 | } |
| 1800 | |
| 1801 | QList<QAccessibleInterface*> QtAccessibleWidget::rowHeaderCells() const |
| 1802 | { |
| 1803 | Reference<XAccessibleTable> xTable = getAccessibleTableForParent(); |
| 1804 | if (!xTable.is()) |
| 1805 | return QList<QAccessibleInterface*>(); |
| 1806 | |
| 1807 | Reference<XAccessibleTable> xHeaders = xTable->getAccessibleRowHeaders(); |
| 1808 | if (!xHeaders.is()) |
| 1809 | return QList<QAccessibleInterface*>(); |
| 1810 | |
| 1811 | const sal_Int32 nRow = rowIndex(); |
| 1812 | QList<QAccessibleInterface*> aHeaderCells; |
| 1813 | for (sal_Int32 nCol = 0; nCol < xHeaders->getAccessibleColumnCount(); nCol++) |
| 1814 | { |
| 1815 | Reference<XAccessible> xCell = xHeaders->getAccessibleCellAt(nRow, nCol); |
| 1816 | QAccessibleInterface* pInterface |
| 1817 | = QAccessible::queryAccessibleInterface(QtAccessibleRegistry::getQObject(xCell)); |
| 1818 | aHeaderCells.push_back(pInterface); |
| 1819 | } |
| 1820 | return aHeaderCells; |
| 1821 | } |
| 1822 | |
| 1823 | int QtAccessibleWidget::rowExtent() const |
| 1824 | { |
| 1825 | Reference<XAccessibleContext> xAcc = getAccessibleContextImpl(); |
| 1826 | if (!xAcc.is()) |
| 1827 | return -1; |
| 1828 | |
| 1829 | Reference<XAccessibleTable> xTable = getAccessibleTableForParent(); |
| 1830 | if (!xTable.is()) |
| 1831 | return -1; |
| 1832 | |
| 1833 | const sal_Int32 nColumn = columnIndex(); |
| 1834 | const sal_Int32 nRow = rowIndex(); |
| 1835 | return xTable->getAccessibleRowExtentAt(nRow, nColumn); |
| 1836 | } |
| 1837 | |
| 1838 | int QtAccessibleWidget::rowIndex() const |
| 1839 | { |
| 1840 | Reference<XAccessibleContext> xAcc = getAccessibleContextImpl(); |
| 1841 | if (!xAcc.is()) |
| 1842 | return -1; |
| 1843 | |
| 1844 | Reference<XAccessibleTable> xTable = getAccessibleTableForParent(); |
| 1845 | if (!xTable.is()) |
| 1846 | return -1; |
| 1847 | |
| 1848 | const sal_Int64 nIndexInParent = xAcc->getAccessibleIndexInParent(); |
| 1849 | return xTable->getAccessibleRow(nIndexInParent); |
| 1850 | } |
| 1851 | |
| 1852 | QAccessibleInterface* QtAccessibleWidget::table() const |
| 1853 | { |
| 1854 | Reference<XAccessibleTable> xTable = getAccessibleTableForParent(); |
| 1855 | if (!xTable.is()) |
| 1856 | return nullptr; |
| 1857 | |
| 1858 | Reference<XAccessible> xTableAcc(xTable, UNO_QUERY); |
| 1859 | if (!xTableAcc.is()) |
| 1860 | return nullptr; |
| 1861 | |
| 1862 | return QAccessible::queryAccessibleInterface(QtAccessibleRegistry::getQObject(xTableAcc)); |
| 1863 | } |
| 1864 | |
| 1865 | // QAccessibleSelectionInterface |
| 1866 | int QtAccessibleWidget::selectedItemCount() const |
| 1867 | { |
| 1868 | Reference<XAccessibleContext> xAcc = getAccessibleContextImpl(); |
| 1869 | if (!xAcc.is()) |
| 1870 | return 0; |
| 1871 | |
| 1872 | Reference<XAccessibleSelection> xSelection(xAcc, UNO_QUERY); |
| 1873 | if (!xSelection.is()) |
| 1874 | return 0; |
| 1875 | |
| 1876 | sal_Int64 nSelected = xSelection->getSelectedAccessibleChildCount(); |
| 1877 | if (nSelected > std::numeric_limits<int>::max()) |
| 1878 | { |
| 1879 | SAL_WARN("vcl.qt", |
| 1880 | "QtAccessibleWidget::selectedItemCount: Cell count exceeds maximum int value, " |
| 1881 | "using max int."); |
| 1882 | nSelected = std::numeric_limits<int>::max(); |
| 1883 | } |
| 1884 | return nSelected; |
| 1885 | } |
| 1886 | |
| 1887 | QList<QAccessibleInterface*> QtAccessibleWidget::selectedItems() const |
| 1888 | { |
| 1889 | Reference<XAccessibleContext> xAcc = getAccessibleContextImpl(); |
| 1890 | if (!xAcc.is()) |
| 1891 | return QList<QAccessibleInterface*>(); |
| 1892 | |
| 1893 | Reference<XAccessibleSelection> xSelection(xAcc, UNO_QUERY); |
| 1894 | if (!xSelection.is()) |
| 1895 | return QList<QAccessibleInterface*>(); |
| 1896 | |
| 1897 | QList<QAccessibleInterface*> aSelectedItems; |
| 1898 | sal_Int64 nSelected = xSelection->getSelectedAccessibleChildCount(); |
| 1899 | if (nSelected > std::numeric_limits<int>::max()) |
| 1900 | { |
| 1901 | SAL_WARN("vcl.qt", |
| 1902 | "QtAccessibleWidget::selectedItems: Cell count exceeds maximum int value, " |
| 1903 | "using max int."); |
| 1904 | nSelected = std::numeric_limits<int>::max(); |
| 1905 | } |
| 1906 | for (sal_Int64 i = 0; i < nSelected; i++) |
| 1907 | { |
| 1908 | Reference<XAccessible> xChild = xSelection->getSelectedAccessibleChild(i); |
| 1909 | QAccessibleInterface* pInterface |
| 1910 | = QAccessible::queryAccessibleInterface(QtAccessibleRegistry::getQObject(xChild)); |
| 1911 | aSelectedItems.push_back(pInterface); |
| 1912 | } |
| 1913 | return aSelectedItems; |
| 1914 | } |
| 1915 | |
| 1916 | #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) |
| 1917 | QAccessibleInterface* QtAccessibleWidget::selectedItem(int nSelectionIndex) const |
| 1918 | { |
| 1919 | Reference<XAccessibleContext> xAcc = getAccessibleContextImpl(); |
| 1920 | if (!xAcc.is()) |
| 1921 | return nullptr; |
| 1922 | |
| 1923 | Reference<XAccessibleSelection> xSelection(xAcc, UNO_QUERY); |
| 1924 | if (!xSelection.is()) |
| 1925 | return nullptr; |
| 1926 | |
| 1927 | if (nSelectionIndex < 0 || nSelectionIndex >= xSelection->getSelectedAccessibleChildCount()) |
| 1928 | { |
| 1929 | SAL_WARN("vcl.qt", |
| 1930 | "QtAccessibleWidget::selectedItem called with invalid index: " << nSelectionIndex); |
| 1931 | return nullptr; |
| 1932 | } |
| 1933 | |
| 1934 | Reference<XAccessible> xChild = xSelection->getSelectedAccessibleChild(nSelectionIndex); |
| 1935 | if (!xChild) |
| 1936 | return nullptr; |
| 1937 | |
| 1938 | return QAccessible::queryAccessibleInterface(QtAccessibleRegistry::getQObject(xChild)); |
| 1939 | } |
| 1940 | |
| 1941 | bool QtAccessibleWidget::isSelected(QAccessibleInterface* pItem) const |
| 1942 | { |
| 1943 | Reference<XAccessibleContext> xAcc = getAccessibleContextImpl(); |
| 1944 | if (!xAcc.is()) |
| 1945 | return false; |
| 1946 | |
| 1947 | Reference<XAccessibleSelection> xSelection(xAcc, UNO_QUERY); |
| 1948 | if (!xSelection.is()) |
| 1949 | return false; |
| 1950 | |
| 1951 | int nChildIndex = indexOfChild(pItem); |
| 1952 | if (nChildIndex < 0) |
| 1953 | return false; |
| 1954 | |
| 1955 | return xSelection->isAccessibleChildSelected(nChildIndex); |
| 1956 | } |
| 1957 | |
| 1958 | bool QtAccessibleWidget::select(QAccessibleInterface* pItem) |
| 1959 | { |
| 1960 | Reference<XAccessibleContext> xAcc = getAccessibleContextImpl(); |
| 1961 | if (!xAcc.is()) |
| 1962 | return false; |
| 1963 | |
| 1964 | Reference<XAccessibleSelection> xSelection(xAcc, UNO_QUERY); |
| 1965 | if (!xSelection.is()) |
| 1966 | return false; |
| 1967 | |
| 1968 | int nChildIndex = indexOfChild(pItem); |
| 1969 | if (nChildIndex < 0) |
| 1970 | return false; |
| 1971 | |
| 1972 | xSelection->selectAccessibleChild(nChildIndex); |
| 1973 | return true; |
| 1974 | } |
| 1975 | |
| 1976 | bool QtAccessibleWidget::unselect(QAccessibleInterface* pItem) |
| 1977 | { |
| 1978 | Reference<XAccessibleContext> xAcc = getAccessibleContextImpl(); |
| 1979 | if (!xAcc.is()) |
| 1980 | return false; |
| 1981 | |
| 1982 | Reference<XAccessibleSelection> xSelection(xAcc, UNO_QUERY); |
| 1983 | if (!xSelection.is()) |
| 1984 | return false; |
| 1985 | |
| 1986 | int nChildIndex = indexOfChild(pItem); |
| 1987 | if (nChildIndex < 0) |
| 1988 | return false; |
| 1989 | |
| 1990 | xSelection->deselectAccessibleChild(nChildIndex); |
| 1991 | return true; |
| 1992 | } |
| 1993 | |
| 1994 | bool QtAccessibleWidget::selectAll() |
| 1995 | { |
| 1996 | Reference<XAccessibleContext> xAcc = getAccessibleContextImpl(); |
| 1997 | if (!xAcc.is()) |
| 1998 | return false; |
| 1999 | |
| 2000 | Reference<XAccessibleSelection> xSelection(xAcc, UNO_QUERY); |
| 2001 | if (!xSelection.is()) |
| 2002 | return false; |
| 2003 | |
| 2004 | xSelection->selectAllAccessibleChildren(); |
| 2005 | return true; |
| 2006 | } |
| 2007 | |
| 2008 | bool QtAccessibleWidget::clear() |
| 2009 | { |
| 2010 | Reference<XAccessibleContext> xAcc = getAccessibleContextImpl(); |
| 2011 | if (!xAcc.is()) |
| 2012 | return false; |
| 2013 | |
| 2014 | Reference<XAccessibleSelection> xSelection(xAcc, UNO_QUERY); |
| 2015 | if (!xSelection.is()) |
| 2016 | return false; |
| 2017 | |
| 2018 | xSelection->clearAccessibleSelection(); |
| 2019 | return true; |
| 2020 | } |
| 2021 | #endif |
| 2022 | |
| 2023 | /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |