| 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 <com/sun/star/uno/Any.hxx> |
| 21 | #include <com/sun/star/uno/Type.hxx> |
| 22 | #include <com/sun/star/uno/Sequence.hxx> |
| 23 | #include <com/sun/star/accessibility/AccessibleRole.hpp> |
| 24 | #include <com/sun/star/accessibility/AccessibleRelation.hpp> |
| 25 | #include <com/sun/star/accessibility/AccessibleRelationType.hpp> |
| 26 | #include <com/sun/star/accessibility/AccessibleStateType.hpp> |
| 27 | #include <com/sun/star/accessibility/XAccessible.hpp> |
| 28 | #include <com/sun/star/accessibility/XAccessibleText.hpp> |
| 29 | #include <com/sun/star/accessibility/XAccessibleValue.hpp> |
| 30 | #include <com/sun/star/accessibility/XAccessibleAction.hpp> |
| 31 | #include <com/sun/star/accessibility/XAccessibleContext.hpp> |
| 32 | #include <com/sun/star/accessibility/XAccessibleContext2.hpp> |
| 33 | #include <com/sun/star/accessibility/XAccessibleComponent.hpp> |
| 34 | #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp> |
| 35 | #include <com/sun/star/accessibility/XAccessibleRelationSet.hpp> |
| 36 | #include <com/sun/star/accessibility/XAccessibleTable.hpp> |
| 37 | #include <com/sun/star/accessibility/XAccessibleEditableText.hpp> |
| 38 | #include <com/sun/star/accessibility/XAccessibleExtendedAttributes.hpp> |
| 39 | #include <com/sun/star/accessibility/XAccessibleImage.hpp> |
| 40 | #include <com/sun/star/accessibility/XAccessibleHypertext.hpp> |
| 41 | #include <com/sun/star/accessibility/XAccessibleSelection.hpp> |
| 42 | #include <com/sun/star/awt/XWindow.hpp> |
| 43 | |
| 44 | #include <rtl/strbuf.hxx> |
| 45 | #include <osl/diagnose.h> |
| 46 | #include <comphelper/diagnose_ex.hxx> |
| 47 | #include <vcl/accessibility/vclxaccessiblecomponent.hxx> |
| 48 | #include <vcl/syschild.hxx> |
| 49 | #include <vcl/sysdata.hxx> |
| 50 | #include <vcl/svapp.hxx> |
| 51 | |
| 52 | #include "atkwrapper.hxx" |
| 53 | #include "atkregistry.hxx" |
| 54 | #include "atklistener.hxx" |
| 55 | #include "atktextattributes.hxx" |
| 56 | |
| 57 | #include <vector> |
| 58 | #include <dlfcn.h> |
| 59 | |
| 60 | using namespace ::com::sun::star; |
| 61 | |
| 62 | constexpr const char* PROPERTY_LOCALE = "locale"; |
| 63 | |
| 64 | static GObjectClass *parent_class = nullptr; |
| 65 | |
| 66 | static AtkRelationType mapRelationType(accessibility::AccessibleRelationType eRelation) |
| 67 | { |
| 68 | switch (eRelation) |
| 69 | { |
| 70 | case accessibility::AccessibleRelationType_CONTENT_FLOWS_FROM: |
| 71 | return ATK_RELATION_FLOWS_FROM; |
| 72 | case accessibility::AccessibleRelationType_CONTENT_FLOWS_TO: |
| 73 | return ATK_RELATION_FLOWS_TO; |
| 74 | case accessibility::AccessibleRelationType_CONTROLLED_BY: |
| 75 | return ATK_RELATION_CONTROLLED_BY; |
| 76 | case accessibility::AccessibleRelationType_CONTROLLER_FOR: |
| 77 | return ATK_RELATION_CONTROLLER_FOR; |
| 78 | case accessibility::AccessibleRelationType_DESCRIBED_BY: |
| 79 | return ATK_RELATION_DESCRIBED_BY; |
| 80 | case accessibility::AccessibleRelationType_LABEL_FOR: |
| 81 | return ATK_RELATION_LABEL_FOR; |
| 82 | case accessibility::AccessibleRelationType_LABELED_BY: |
| 83 | return ATK_RELATION_LABELLED_BY; |
| 84 | case accessibility::AccessibleRelationType_MEMBER_OF: |
| 85 | return ATK_RELATION_MEMBER_OF; |
| 86 | case accessibility::AccessibleRelationType_SUB_WINDOW_OF: |
| 87 | return ATK_RELATION_SUBWINDOW_OF; |
| 88 | case accessibility::AccessibleRelationType_NODE_CHILD_OF: |
| 89 | return ATK_RELATION_NODE_CHILD_OF; |
| 90 | default: |
| 91 | return ATK_RELATION_NULL; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | AtkStateType mapAtkState( sal_Int64 nState ) |
| 96 | { |
| 97 | AtkStateType type = ATK_STATE_INVALID; |
| 98 | |
| 99 | // A perfect / complete mapping ... |
| 100 | switch( nState ) |
| 101 | { |
| 102 | #define MAP_DIRECT( a ) \ |
| 103 | case accessibility::AccessibleStateType::a: \ |
| 104 | type = ATK_STATE_##a; break |
| 105 | |
| 106 | MAP_DIRECT( INVALID ); |
| 107 | MAP_DIRECT( ACTIVE ); |
| 108 | MAP_DIRECT( ARMED ); |
| 109 | MAP_DIRECT( BUSY ); |
| 110 | MAP_DIRECT( CHECKABLE ); |
| 111 | MAP_DIRECT( CHECKED ); |
| 112 | MAP_DIRECT( EDITABLE ); |
| 113 | MAP_DIRECT( ENABLED ); |
| 114 | MAP_DIRECT( EXPANDABLE ); |
| 115 | MAP_DIRECT( EXPANDED ); |
| 116 | MAP_DIRECT( FOCUSABLE ); |
| 117 | MAP_DIRECT( FOCUSED ); |
| 118 | MAP_DIRECT( HORIZONTAL ); |
| 119 | MAP_DIRECT( ICONIFIED ); |
| 120 | MAP_DIRECT( INDETERMINATE ); |
| 121 | MAP_DIRECT( MANAGES_DESCENDANTS ); |
| 122 | MAP_DIRECT( MODAL ); |
| 123 | MAP_DIRECT( MULTI_LINE ); |
| 124 | MAP_DIRECT( OPAQUE ); |
| 125 | MAP_DIRECT( PRESSED ); |
| 126 | MAP_DIRECT( RESIZABLE ); |
| 127 | MAP_DIRECT( SELECTABLE ); |
| 128 | MAP_DIRECT( SELECTED ); |
| 129 | MAP_DIRECT( SENSITIVE ); |
| 130 | MAP_DIRECT( SHOWING ); |
| 131 | MAP_DIRECT( SINGLE_LINE ); |
| 132 | MAP_DIRECT( STALE ); |
| 133 | MAP_DIRECT( TRANSIENT ); |
| 134 | MAP_DIRECT( VERTICAL ); |
| 135 | MAP_DIRECT( VISIBLE ); |
| 136 | MAP_DIRECT( DEFAULT ); |
| 137 | // a spelling error ... |
| 138 | case accessibility::AccessibleStateType::DEFUNC: |
| 139 | type = ATK_STATE_DEFUNCT; break; |
| 140 | case accessibility::AccessibleStateType::MULTI_SELECTABLE: |
| 141 | type = ATK_STATE_MULTISELECTABLE; break; |
| 142 | default: |
| 143 | //Mis-use ATK_STATE_LAST_DEFINED to check if a state is unmapped |
| 144 | //NOTE! Do not report it |
| 145 | type = ATK_STATE_LAST_DEFINED; |
| 146 | break; |
| 147 | } |
| 148 | |
| 149 | return type; |
| 150 | } |
| 151 | |
| 152 | static AtkRole mapToAtkRole(sal_Int16 nRole, sal_Int64 nStates) |
| 153 | { |
| 154 | switch (nRole) |
| 155 | { |
| 156 | case accessibility::AccessibleRole::UNKNOWN: |
| 157 | return ATK_ROLE_UNKNOWN; |
| 158 | case accessibility::AccessibleRole::ALERT: |
| 159 | return ATK_ROLE_ALERT; |
| 160 | case accessibility::AccessibleRole::BLOCK_QUOTE: |
| 161 | return ATK_ROLE_BLOCK_QUOTE; |
| 162 | case accessibility::AccessibleRole::COLUMN_HEADER: |
| 163 | return ATK_ROLE_COLUMN_HEADER; |
| 164 | case accessibility::AccessibleRole::CANVAS: |
| 165 | return ATK_ROLE_CANVAS; |
| 166 | case accessibility::AccessibleRole::CHECK_BOX: |
| 167 | return ATK_ROLE_CHECK_BOX; |
| 168 | case accessibility::AccessibleRole::CHECK_MENU_ITEM: |
| 169 | return ATK_ROLE_CHECK_MENU_ITEM; |
| 170 | case accessibility::AccessibleRole::COLOR_CHOOSER: |
| 171 | return ATK_ROLE_COLOR_CHOOSER; |
| 172 | case accessibility::AccessibleRole::COMBO_BOX: |
| 173 | return ATK_ROLE_COMBO_BOX; |
| 174 | case accessibility::AccessibleRole::DATE_EDITOR: |
| 175 | return ATK_ROLE_DATE_EDITOR; |
| 176 | case accessibility::AccessibleRole::DESKTOP_ICON: |
| 177 | return ATK_ROLE_DESKTOP_ICON; |
| 178 | case accessibility::AccessibleRole::DESKTOP_PANE: |
| 179 | return ATK_ROLE_DESKTOP_FRAME; |
| 180 | case accessibility::AccessibleRole::DIRECTORY_PANE: |
| 181 | return ATK_ROLE_DIRECTORY_PANE; |
| 182 | case accessibility::AccessibleRole::DIALOG: |
| 183 | return ATK_ROLE_DIALOG; |
| 184 | case accessibility::AccessibleRole::DOCUMENT: |
| 185 | return ATK_ROLE_DOCUMENT_FRAME; |
| 186 | case accessibility::AccessibleRole::EMBEDDED_OBJECT: |
| 187 | return ATK_ROLE_EMBEDDED; |
| 188 | case accessibility::AccessibleRole::END_NOTE: |
| 189 | return ATK_ROLE_FOOTNOTE; |
| 190 | case accessibility::AccessibleRole::FILE_CHOOSER: |
| 191 | return ATK_ROLE_FILE_CHOOSER; |
| 192 | case accessibility::AccessibleRole::FILLER: |
| 193 | return ATK_ROLE_FILLER; |
| 194 | case accessibility::AccessibleRole::FONT_CHOOSER: |
| 195 | return ATK_ROLE_FONT_CHOOSER; |
| 196 | case accessibility::AccessibleRole::FOOTER: |
| 197 | return ATK_ROLE_FOOTER; |
| 198 | case accessibility::AccessibleRole::FOOTNOTE: |
| 199 | return ATK_ROLE_FOOTNOTE; |
| 200 | case accessibility::AccessibleRole::FRAME: |
| 201 | return ATK_ROLE_FRAME; |
| 202 | case accessibility::AccessibleRole::GLASS_PANE: |
| 203 | return ATK_ROLE_GLASS_PANE; |
| 204 | case accessibility::AccessibleRole::GRAPHIC: |
| 205 | return ATK_ROLE_IMAGE; |
| 206 | case accessibility::AccessibleRole::GROUP_BOX: |
| 207 | return ATK_ROLE_GROUPING; |
| 208 | case accessibility::AccessibleRole::HEADER: |
| 209 | return ATK_ROLE_HEADER; |
| 210 | case accessibility::AccessibleRole::HEADING: |
| 211 | return ATK_ROLE_HEADING; |
| 212 | case accessibility::AccessibleRole::HYPER_LINK: |
| 213 | return ATK_ROLE_LINK; |
| 214 | case accessibility::AccessibleRole::ICON: |
| 215 | return ATK_ROLE_ICON; |
| 216 | case accessibility::AccessibleRole::INTERNAL_FRAME: |
| 217 | return ATK_ROLE_INTERNAL_FRAME; |
| 218 | case accessibility::AccessibleRole::LABEL: |
| 219 | return ATK_ROLE_LABEL; |
| 220 | case accessibility::AccessibleRole::LAYERED_PANE: |
| 221 | return ATK_ROLE_LAYERED_PANE; |
| 222 | case accessibility::AccessibleRole::LIST: |
| 223 | return ATK_ROLE_LIST; |
| 224 | case accessibility::AccessibleRole::LIST_ITEM: |
| 225 | return ATK_ROLE_LIST_ITEM; |
| 226 | case accessibility::AccessibleRole::MENU: |
| 227 | return ATK_ROLE_MENU; |
| 228 | case accessibility::AccessibleRole::MENU_BAR: |
| 229 | return ATK_ROLE_MENU_BAR; |
| 230 | case accessibility::AccessibleRole::MENU_ITEM: |
| 231 | return ATK_ROLE_MENU_ITEM; |
| 232 | case accessibility::AccessibleRole::OPTION_PANE: |
| 233 | return ATK_ROLE_OPTION_PANE; |
| 234 | case accessibility::AccessibleRole::PAGE_TAB: |
| 235 | return ATK_ROLE_PAGE_TAB; |
| 236 | case accessibility::AccessibleRole::PAGE_TAB_LIST: |
| 237 | return ATK_ROLE_PAGE_TAB_LIST; |
| 238 | case accessibility::AccessibleRole::PANEL: |
| 239 | return ATK_ROLE_PANEL; |
| 240 | case accessibility::AccessibleRole::PARAGRAPH: |
| 241 | return ATK_ROLE_PARAGRAPH; |
| 242 | case accessibility::AccessibleRole::PASSWORD_TEXT: |
| 243 | return ATK_ROLE_PASSWORD_TEXT; |
| 244 | case accessibility::AccessibleRole::POPUP_MENU: |
| 245 | return ATK_ROLE_POPUP_MENU; |
| 246 | case accessibility::AccessibleRole::PUSH_BUTTON: |
| 247 | return ATK_ROLE_PUSH_BUTTON; |
| 248 | case accessibility::AccessibleRole::PROGRESS_BAR: |
| 249 | return ATK_ROLE_PROGRESS_BAR; |
| 250 | case accessibility::AccessibleRole::RADIO_BUTTON: |
| 251 | return ATK_ROLE_RADIO_BUTTON; |
| 252 | case accessibility::AccessibleRole::RADIO_MENU_ITEM: |
| 253 | return ATK_ROLE_RADIO_MENU_ITEM; |
| 254 | case accessibility::AccessibleRole::ROW_HEADER: |
| 255 | return ATK_ROLE_ROW_HEADER; |
| 256 | case accessibility::AccessibleRole::ROOT_PANE: |
| 257 | return ATK_ROLE_ROOT_PANE; |
| 258 | case accessibility::AccessibleRole::SCROLL_BAR: |
| 259 | return ATK_ROLE_SCROLL_BAR; |
| 260 | case accessibility::AccessibleRole::SCROLL_PANE: |
| 261 | return ATK_ROLE_SCROLL_PANE; |
| 262 | case accessibility::AccessibleRole::SHAPE: |
| 263 | return ATK_ROLE_PANEL; |
| 264 | case accessibility::AccessibleRole::SEPARATOR: |
| 265 | return ATK_ROLE_SEPARATOR; |
| 266 | case accessibility::AccessibleRole::SLIDER: |
| 267 | return ATK_ROLE_SLIDER; |
| 268 | case accessibility::AccessibleRole::SPIN_BOX: |
| 269 | return ATK_ROLE_SPIN_BUTTON; |
| 270 | case accessibility::AccessibleRole::SPLIT_PANE: |
| 271 | return ATK_ROLE_SPLIT_PANE; |
| 272 | case accessibility::AccessibleRole::STATUS_BAR: |
| 273 | return ATK_ROLE_STATUSBAR; |
| 274 | case accessibility::AccessibleRole::TABLE: |
| 275 | return ATK_ROLE_TABLE; |
| 276 | case accessibility::AccessibleRole::TABLE_CELL: |
| 277 | return ATK_ROLE_TABLE_CELL; |
| 278 | case accessibility::AccessibleRole::TEXT: |
| 279 | return ATK_ROLE_TEXT; |
| 280 | case accessibility::AccessibleRole::TEXT_FRAME: |
| 281 | return ATK_ROLE_PANEL; |
| 282 | case accessibility::AccessibleRole::TOGGLE_BUTTON: |
| 283 | return ATK_ROLE_TOGGLE_BUTTON; |
| 284 | case accessibility::AccessibleRole::TOOL_BAR: |
| 285 | return ATK_ROLE_TOOL_BAR; |
| 286 | case accessibility::AccessibleRole::TOOL_TIP: |
| 287 | return ATK_ROLE_TOOL_TIP; |
| 288 | case accessibility::AccessibleRole::TREE: |
| 289 | return ATK_ROLE_TREE; |
| 290 | case accessibility::AccessibleRole::VIEW_PORT: |
| 291 | return ATK_ROLE_VIEWPORT; |
| 292 | case accessibility::AccessibleRole::WINDOW: |
| 293 | return ATK_ROLE_WINDOW; |
| 294 | case accessibility::AccessibleRole::BUTTON_DROPDOWN: |
| 295 | { |
| 296 | if (nStates & css::accessibility::AccessibleStateType::CHECKABLE) |
| 297 | return ATK_ROLE_TOGGLE_BUTTON; |
| 298 | return ATK_ROLE_PUSH_BUTTON; |
| 299 | } |
| 300 | case accessibility::AccessibleRole::BUTTON_MENU: |
| 301 | #if ATK_CHECK_VERSION(2, 46, 0) |
| 302 | return ATK_ROLE_PUSH_BUTTON_MENU; |
| 303 | #else |
| 304 | return ATK_ROLE_PUSH_BUTTON; |
| 305 | #endif |
| 306 | case accessibility::AccessibleRole::CAPTION: |
| 307 | return ATK_ROLE_CAPTION; |
| 308 | case accessibility::AccessibleRole::CHART: |
| 309 | return ATK_ROLE_CHART; |
| 310 | case accessibility::AccessibleRole::EDIT_BAR: |
| 311 | return ATK_ROLE_EDITBAR; |
| 312 | case accessibility::AccessibleRole::FORM: |
| 313 | return ATK_ROLE_FORM; |
| 314 | case accessibility::AccessibleRole::IMAGE_MAP: |
| 315 | return ATK_ROLE_IMAGE_MAP; |
| 316 | case accessibility::AccessibleRole::NOTE: |
| 317 | return ATK_ROLE_COMMENT; |
| 318 | case accessibility::AccessibleRole::PAGE: |
| 319 | return ATK_ROLE_PAGE; |
| 320 | case accessibility::AccessibleRole::RULER: |
| 321 | return ATK_ROLE_RULER; |
| 322 | case accessibility::AccessibleRole::SECTION: |
| 323 | return ATK_ROLE_SECTION; |
| 324 | case accessibility::AccessibleRole::TREE_ITEM: |
| 325 | return ATK_ROLE_TREE_ITEM; |
| 326 | case accessibility::AccessibleRole::TREE_TABLE: |
| 327 | return ATK_ROLE_TREE_TABLE; |
| 328 | case accessibility::AccessibleRole::COMMENT: |
| 329 | return ATK_ROLE_COMMENT; |
| 330 | case accessibility::AccessibleRole::COMMENT_END: |
| 331 | return ATK_ROLE_UNKNOWN; |
| 332 | case accessibility::AccessibleRole::DOCUMENT_PRESENTATION: |
| 333 | return ATK_ROLE_DOCUMENT_PRESENTATION; |
| 334 | case accessibility::AccessibleRole::DOCUMENT_SPREADSHEET: |
| 335 | return ATK_ROLE_DOCUMENT_SPREADSHEET; |
| 336 | case accessibility::AccessibleRole::DOCUMENT_TEXT: |
| 337 | return ATK_ROLE_DOCUMENT_TEXT; |
| 338 | case accessibility::AccessibleRole::STATIC: |
| 339 | return ATK_ROLE_STATIC; |
| 340 | case accessibility::AccessibleRole::NOTIFICATION: |
| 341 | return ATK_ROLE_NOTIFICATION; |
| 342 | default: |
| 343 | SAL_WARN("vcl.gtk", "Unmapped accessible role: " << nRole); |
| 344 | return ATK_ROLE_UNKNOWN; |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | /*****************************************************************************/ |
| 349 | |
| 350 | extern "C" { |
| 351 | |
| 352 | /*****************************************************************************/ |
| 353 | |
| 354 | static const gchar* |
| 355 | wrapper_get_name( AtkObject *atk_obj ) |
| 356 | { |
| 357 | AtkObjectWrapper *obj = ATK_OBJECT_WRAPPER (atk_obj); |
| 358 | |
| 359 | if( obj->mpContext.is() ) |
| 360 | { |
| 361 | try { |
| 362 | OString aName = |
| 363 | OUStringToOString( |
| 364 | obj->mpContext->getAccessibleName(), |
| 365 | RTL_TEXTENCODING_UTF8); |
| 366 | |
| 367 | int nCmp = atk_obj->name ? rtl_str_compare( atk_obj->name, aName.getStr() ) : -1; |
| 368 | if( nCmp != 0 ) |
| 369 | { |
| 370 | if( atk_obj->name ) |
| 371 | g_free(atk_obj->name); |
| 372 | atk_obj->name = g_strdup(aName.getStr()); |
| 373 | |
| 374 | return atk_obj->name; |
| 375 | } |
| 376 | } |
| 377 | catch(const uno::Exception&) { |
| 378 | g_warning( "Exception in getAccessibleName()" ); |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | return ATK_OBJECT_CLASS (parent_class)->get_name(atk_obj); |
| 383 | } |
| 384 | |
| 385 | /*****************************************************************************/ |
| 386 | |
| 387 | static const gchar* |
| 388 | wrapper_get_description( AtkObject *atk_obj ) |
| 389 | { |
| 390 | AtkObjectWrapper *obj = ATK_OBJECT_WRAPPER (atk_obj); |
| 391 | |
| 392 | if( obj->mpContext.is() ) |
| 393 | { |
| 394 | try { |
| 395 | OString aDescription = |
| 396 | OUStringToOString( |
| 397 | obj->mpContext->getAccessibleDescription(), |
| 398 | RTL_TEXTENCODING_UTF8); |
| 399 | |
| 400 | g_free(atk_obj->description); |
| 401 | atk_obj->description = g_strdup(aDescription.getStr()); |
| 402 | |
| 403 | return atk_obj->description; |
| 404 | } |
| 405 | catch(const uno::Exception&) { |
| 406 | g_warning( "Exception in getAccessibleDescription()" ); |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | return ATK_OBJECT_CLASS (parent_class)->get_description(atk_obj); |
| 411 | |
| 412 | } |
| 413 | |
| 414 | static const char* wrapper_get_object_locale(AtkObject* pAtkObject) |
| 415 | { |
| 416 | AtkObjectWrapper* pWrapper = ATK_OBJECT_WRAPPER(pAtkObject); |
| 417 | |
| 418 | if (!pWrapper->mpContext.is()) |
| 419 | return ATK_OBJECT_CLASS(parent_class)->get_object_locale(pAtkObject); |
| 420 | |
| 421 | const css::lang::Locale aLocale = pWrapper->mpContext->getLocale(); |
| 422 | |
| 423 | const char* pCharset; |
| 424 | g_get_charset(&pCharset); |
| 425 | |
| 426 | const OUString sLocale |
| 427 | = aLocale.Language + u"_" + aLocale.Country + u"." + OUString::fromUtf8(pCharset); |
| 428 | char* pLocale = g_strdup(sLocale.toUtf8().getStr()); |
| 429 | // set pLocale as object data so it can be freed in atk_object_wrapper_finalize |
| 430 | g_free(g_object_get_data(G_OBJECT(pWrapper), PROPERTY_LOCALE)); |
| 431 | g_object_set_data(G_OBJECT(pWrapper), PROPERTY_LOCALE, pLocale); |
| 432 | return pLocale; |
| 433 | } |
| 434 | |
| 435 | static AtkAttributeSet * |
| 436 | wrapper_get_attributes( AtkObject *atk_obj ) |
| 437 | { |
| 438 | AtkObjectWrapper *obj = ATK_OBJECT_WRAPPER( atk_obj ); |
| 439 | AtkAttributeSet *pSet = nullptr; |
| 440 | |
| 441 | try |
| 442 | { |
| 443 | uno::Reference< accessibility::XAccessibleExtendedAttributes > |
| 444 | xExtendedAttrs( obj->mpContext, uno::UNO_QUERY ); |
| 445 | if( xExtendedAttrs.is() ) |
| 446 | pSet = attribute_set_new_from_extended_attributes( xExtendedAttrs ); |
| 447 | } |
| 448 | catch(const uno::Exception&) |
| 449 | { |
| 450 | g_warning( "Exception in getAccessibleAttributes()" ); |
| 451 | } |
| 452 | |
| 453 | return pSet; |
| 454 | } |
| 455 | |
| 456 | /*****************************************************************************/ |
| 457 | |
| 458 | static gint |
| 459 | wrapper_get_n_children( AtkObject *atk_obj ) |
| 460 | { |
| 461 | AtkObjectWrapper *obj = ATK_OBJECT_WRAPPER (atk_obj); |
| 462 | |
| 463 | if (obj->mpSysObjChild) |
| 464 | return 1; |
| 465 | |
| 466 | gint n = 0; |
| 467 | |
| 468 | if( obj->mpContext.is() ) |
| 469 | { |
| 470 | try { |
| 471 | sal_Int64 nChildCount = obj->mpContext->getAccessibleChildCount(); |
| 472 | if (nChildCount > std::numeric_limits<gint>::max()) |
| 473 | { |
| 474 | SAL_WARN("vcl.gtk", "wrapper_get_n_children: Child count exceeds maximum gint value, " |
| 475 | "returning max gint."); |
| 476 | nChildCount = std::numeric_limits<gint>::max(); |
| 477 | } |
| 478 | else if (nChildCount < std::numeric_limits<gint>::min()) |
| 479 | { |
| 480 | SAL_WARN("vcl.gtk", "wrapper_get_n_children: Child count exceeds minimum gint value, " |
| 481 | "returning min gint."); |
| 482 | nChildCount = std::numeric_limits<gint>::min(); |
| 483 | } |
| 484 | n = nChildCount; |
| 485 | } |
| 486 | catch(const uno::Exception&) { |
| 487 | TOOLS_WARN_EXCEPTION( "vcl", "Exception" ); |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | return n; |
| 492 | } |
| 493 | |
| 494 | /*****************************************************************************/ |
| 495 | |
| 496 | static AtkObject * |
| 497 | wrapper_ref_child( AtkObject *atk_obj, |
| 498 | gint i ) |
| 499 | { |
| 500 | SolarMutexGuard aGuard; |
| 501 | |
| 502 | AtkObjectWrapper *obj = ATK_OBJECT_WRAPPER (atk_obj); |
| 503 | |
| 504 | if (obj->mpSysObjChild) |
| 505 | { |
| 506 | g_object_ref(obj->mpSysObjChild); |
| 507 | return obj->mpSysObjChild; |
| 508 | } |
| 509 | |
| 510 | AtkObject* child = nullptr; |
| 511 | |
| 512 | if( obj->mpContext.is() ) |
| 513 | { |
| 514 | try { |
| 515 | uno::Reference< accessibility::XAccessible > xAccessible = |
| 516 | obj->mpContext->getAccessibleChild( i ); |
| 517 | |
| 518 | child = atk_object_wrapper_ref( xAccessible ); |
| 519 | } |
| 520 | catch(const uno::Exception&) { |
| 521 | TOOLS_WARN_EXCEPTION( "vcl", "getAccessibleChild"); |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | return child; |
| 526 | } |
| 527 | |
| 528 | /*****************************************************************************/ |
| 529 | |
| 530 | static gint |
| 531 | wrapper_get_index_in_parent( AtkObject *atk_obj ) |
| 532 | { |
| 533 | SolarMutexGuard aGuard; |
| 534 | |
| 535 | AtkObjectWrapper *obj = ATK_OBJECT_WRAPPER (atk_obj); |
| 536 | |
| 537 | //if we're a native GtkDrawingArea with custom a11y, use the default toolkit a11y |
| 538 | if (obj->mpOrig) |
| 539 | return atk_object_get_index_in_parent(obj->mpOrig); |
| 540 | |
| 541 | gint i = -1; |
| 542 | |
| 543 | if( obj->mpContext.is() ) |
| 544 | { |
| 545 | try { |
| 546 | sal_Int64 nIndex = obj->mpContext->getAccessibleIndexInParent(); |
| 547 | if (nIndex > std::numeric_limits<gint>::max() || |
| 548 | nIndex < std::numeric_limits<gint>::min()) |
| 549 | { |
| 550 | // use -2 when the child index is too large to fit into 32 bit to neither use the |
| 551 | // valid index of another child nor -1, which would e.g. make Orca interpret the |
| 552 | // object as being a zombie |
| 553 | SAL_WARN("vcl.gtk", "wrapper_get_index_in_parent: Child index exceeds maximum gint value, " |
| 554 | "returning -2."); |
| 555 | nIndex = -2; |
| 556 | } |
| 557 | i = nIndex; |
| 558 | } |
| 559 | catch(const uno::Exception&) { |
| 560 | g_warning( "Exception in getAccessibleIndexInParent()" ); |
| 561 | } |
| 562 | } |
| 563 | return i; |
| 564 | } |
| 565 | |
| 566 | /*****************************************************************************/ |
| 567 | |
| 568 | AtkRelation* |
| 569 | atk_object_wrapper_relation_new(const accessibility::AccessibleRelation& rRelation) |
| 570 | { |
| 571 | sal_uInt32 nTargetCount = rRelation.TargetSet.getLength(); |
| 572 | |
| 573 | std::vector<AtkObject*> aTargets; |
| 574 | |
| 575 | for (const uno::Reference<accessibility::XAccessible>& xTarget : rRelation.TargetSet) |
| 576 | { |
| 577 | aTargets.push_back(atk_object_wrapper_ref(xTarget)); |
| 578 | } |
| 579 | |
| 580 | AtkRelation *pRel = |
| 581 | atk_relation_new( |
| 582 | aTargets.data(), nTargetCount, |
| 583 | mapRelationType( rRelation.RelationType ) |
| 584 | ); |
| 585 | |
| 586 | return pRel; |
| 587 | } |
| 588 | |
| 589 | static AtkRelationSet * |
| 590 | wrapper_ref_relation_set( AtkObject *atk_obj ) |
| 591 | { |
| 592 | AtkObjectWrapper *obj = ATK_OBJECT_WRAPPER (atk_obj); |
| 593 | |
| 594 | //if we're a native GtkDrawingArea with custom a11y, use the default toolkit relation set impl |
| 595 | if (obj->mpOrig) |
| 596 | return atk_object_ref_relation_set(obj->mpOrig); |
| 597 | |
| 598 | AtkRelationSet *pSet = atk_relation_set_new(); |
| 599 | |
| 600 | if( obj->mpContext.is() ) |
| 601 | { |
| 602 | try { |
| 603 | uno::Reference< accessibility::XAccessibleRelationSet > xRelationSet( |
| 604 | obj->mpContext->getAccessibleRelationSet() |
| 605 | ); |
| 606 | |
| 607 | sal_Int32 nRelations = xRelationSet.is() ? xRelationSet->getRelationCount() : 0; |
| 608 | for( sal_Int32 n = 0; n < nRelations; n++ ) |
| 609 | { |
| 610 | AtkRelation *pRel = atk_object_wrapper_relation_new(xRelationSet->getRelation(n)); |
| 611 | atk_relation_set_add(pSet, pRel); |
| 612 | g_object_unref(pRel); |
| 613 | } |
| 614 | } |
| 615 | catch(const uno::Exception &) { |
| 616 | g_object_unref( G_OBJECT( pSet ) ); |
| 617 | pSet = nullptr; |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | return pSet; |
| 622 | } |
| 623 | |
| 624 | static AtkStateSet * |
| 625 | wrapper_ref_state_set( AtkObject *atk_obj ) |
| 626 | { |
| 627 | AtkObjectWrapper *obj = ATK_OBJECT_WRAPPER (atk_obj); |
| 628 | AtkStateSet *pSet = atk_state_set_new(); |
| 629 | |
| 630 | if( obj->mpContext.is() ) |
| 631 | { |
| 632 | try { |
| 633 | sal_Int64 nStateSet = obj->mpContext->getAccessibleStateSet(); |
| 634 | for (int i = 0; i < 63; ++i) |
| 635 | { |
| 636 | // ATK_STATE_LAST_DEFINED is used to check if the state |
| 637 | // is unmapped, do not report it to Atk |
| 638 | sal_Int64 nState = sal_Int64(1) << i; |
| 639 | if ((nStateSet & nState) && mapAtkState(nState) != ATK_STATE_LAST_DEFINED) |
| 640 | atk_state_set_add_state(pSet, mapAtkState(nState)); |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | catch(const uno::Exception &) { |
| 645 | g_warning( "Exception in wrapper_ref_state_set" ); |
| 646 | atk_state_set_add_state( pSet, ATK_STATE_DEFUNCT ); |
| 647 | } |
| 648 | } |
| 649 | else |
| 650 | atk_state_set_add_state( pSet, ATK_STATE_DEFUNCT ); |
| 651 | |
| 652 | return pSet; |
| 653 | } |
| 654 | |
| 655 | /*****************************************************************************/ |
| 656 | |
| 657 | static void |
| 658 | atk_object_wrapper_finalize (GObject *obj) |
| 659 | { |
| 660 | AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER (obj); |
| 661 | |
| 662 | if( pWrap->mpAccessible.is() ) |
| 663 | { |
| 664 | ooo_wrapper_registry_remove( pWrap->mpAccessible ); |
| 665 | SolarMutexGuard aGuard; |
| 666 | pWrap->mpAccessible.clear(); |
| 667 | } |
| 668 | |
| 669 | // free string if allocated in atk_wrapper_get_object_locale |
| 670 | g_free(g_object_get_data(obj, PROPERTY_LOCALE)); |
| 671 | |
| 672 | atk_object_wrapper_dispose( pWrap ); |
| 673 | |
| 674 | if (pWrap->mpOrig) |
| 675 | g_object_unref(pWrap->mpOrig); |
| 676 | |
| 677 | parent_class->finalize( obj ); |
| 678 | } |
| 679 | |
| 680 | static void |
| 681 | atk_object_wrapper_class_init (gpointer klass_, gpointer) |
| 682 | { |
| 683 | auto const klass = static_cast<AtkObjectWrapperClass *>(klass_); |
| 684 | GObjectClass *gobject_class = G_OBJECT_CLASS( klass ); |
| 685 | AtkObjectClass *atk_class = ATK_OBJECT_CLASS( klass ); |
| 686 | |
| 687 | parent_class = static_cast<GObjectClass *>(g_type_class_peek_parent (klass)); |
| 688 | |
| 689 | // GObject methods |
| 690 | gobject_class->finalize = atk_object_wrapper_finalize; |
| 691 | |
| 692 | // AtkObject methods |
| 693 | atk_class->get_name = wrapper_get_name; |
| 694 | atk_class->get_description = wrapper_get_description; |
| 695 | atk_class->get_object_locale = wrapper_get_object_locale; |
| 696 | atk_class->get_attributes = wrapper_get_attributes; |
| 697 | atk_class->get_n_children = wrapper_get_n_children; |
| 698 | atk_class->ref_child = wrapper_ref_child; |
| 699 | atk_class->get_index_in_parent = wrapper_get_index_in_parent; |
| 700 | atk_class->ref_relation_set = wrapper_ref_relation_set; |
| 701 | atk_class->ref_state_set = wrapper_ref_state_set; |
| 702 | |
| 703 | AtkObjectClass* orig_atk_klass = static_cast<AtkObjectClass*>(g_type_class_ref(ATK_TYPE_OBJECT)); |
| 704 | // tdf#150496 we want to inherit from GtkAccessible because gtk assumes it can cast to GtkAccessible |
| 705 | // but we want the original behaviour we got from atk_object_real_get_parent when we inherited |
| 706 | // from AtkObject |
| 707 | atk_class->get_parent = orig_atk_klass->get_parent; |
| 708 | // and likewise for focus_event |
| 709 | atk_class->focus_event = orig_atk_klass->focus_event; |
| 710 | g_type_class_unref(orig_atk_klass); |
| 711 | } |
| 712 | |
| 713 | static void |
| 714 | atk_object_wrapper_init (AtkObjectWrapper *wrapper, |
| 715 | AtkObjectWrapperClass*) |
| 716 | { |
| 717 | wrapper->mpAction = nullptr; |
| 718 | wrapper->mpComponent = nullptr; |
| 719 | wrapper->mpEditableText = nullptr; |
| 720 | wrapper->mpHypertext = nullptr; |
| 721 | wrapper->mpImage = nullptr; |
| 722 | wrapper->mpSelection = nullptr; |
| 723 | wrapper->mpTable = nullptr; |
| 724 | wrapper->mpTableSelection = nullptr; |
| 725 | wrapper->mpText = nullptr; |
| 726 | wrapper->mpValue = nullptr; |
| 727 | } |
| 728 | |
| 729 | } // extern "C" |
| 730 | |
| 731 | GType |
| 732 | atk_object_wrapper_get_type() |
| 733 | { |
| 734 | static GType type = 0; |
| 735 | |
| 736 | if (!type) |
| 737 | { |
| 738 | static const GTypeInfo typeInfo = |
| 739 | { |
| 740 | sizeof (AtkObjectWrapperClass), |
| 741 | nullptr, |
| 742 | nullptr, |
| 743 | atk_object_wrapper_class_init, |
| 744 | nullptr, |
| 745 | nullptr, |
| 746 | sizeof (AtkObjectWrapper), |
| 747 | 0, |
| 748 | reinterpret_cast<GInstanceInitFunc>(atk_object_wrapper_init), |
| 749 | nullptr |
| 750 | } ; |
| 751 | type = g_type_register_static (GTK_TYPE_WIDGET_ACCESSIBLE, |
| 752 | "OOoAtkObj", |
| 753 | &typeInfo, GTypeFlags(0)) ; |
| 754 | } |
| 755 | return type; |
| 756 | } |
| 757 | |
| 758 | static bool |
| 759 | isOfType( uno::XInterface *pInterface, const uno::Type & rType ) |
| 760 | { |
| 761 | g_return_val_if_fail( pInterface != nullptr, false ); |
| 762 | |
| 763 | bool bIs = false; |
| 764 | try { |
| 765 | uno::Any aRet = pInterface->queryInterface( rType ); |
| 766 | |
| 767 | bIs = ( ( typelib_TypeClass_INTERFACE == aRet.pType->eTypeClass ) && |
| 768 | ( aRet.pReserved != nullptr ) ); |
| 769 | } catch( const uno::Exception &) { } |
| 770 | |
| 771 | return bIs; |
| 772 | } |
| 773 | |
| 774 | // Whether AtkTableCell can be supported for the interface. |
| 775 | // Returns true if the corresponding XAccessible has role TABLE_CELL |
| 776 | // and an XAccessibleTable as parent. |
| 777 | static bool isTableCell(uno::XInterface* pInterface) |
| 778 | { |
| 779 | g_return_val_if_fail(pInterface != nullptr, false); |
| 780 | |
| 781 | try { |
| 782 | auto aType = cppu::UnoType<accessibility::XAccessible>::get().getTypeLibType(); |
| 783 | uno::Any aAcc = pInterface->queryInterface(aType); |
| 784 | |
| 785 | css::uno::Reference<css::accessibility::XAccessible> xAcc; |
| 786 | aAcc >>= xAcc; |
| 787 | if (!xAcc.is()) |
| 788 | return false; |
| 789 | |
| 790 | css::uno::Reference<css::accessibility::XAccessibleContext> xContext = xAcc->getAccessibleContext(); |
| 791 | if (!xContext.is() || !(xContext->getAccessibleRole() == accessibility::AccessibleRole::TABLE_CELL)) |
| 792 | return false; |
| 793 | |
| 794 | css::uno::Reference<css::accessibility::XAccessible> xParent = xContext->getAccessibleParent(); |
| 795 | if (!xParent.is()) |
| 796 | return false; |
| 797 | css::uno::Reference<css::accessibility::XAccessibleContext> xParentContext = xParent->getAccessibleContext(); |
| 798 | if (!xParentContext.is()) |
| 799 | return false; |
| 800 | |
| 801 | css::uno::Reference<css::accessibility::XAccessibleTable> xTable(xParentContext, uno::UNO_QUERY); |
| 802 | return xTable.is(); |
| 803 | } |
| 804 | catch(const uno::Exception &) |
| 805 | { |
| 806 | g_warning("Exception in isTableCell()"); |
| 807 | } |
| 808 | |
| 809 | return false; |
| 810 | } |
| 811 | |
| 812 | extern "C" { |
| 813 | typedef GType (* GetGIfaceType ) (); |
| 814 | } |
| 815 | constexpr struct { |
| 816 | OString sName; |
| 817 | GInterfaceInitFunc const aInit; |
| 818 | GetGIfaceType const aGetGIfaceType; |
| 819 | const uno::Type & (*aGetUnoType) (); |
| 820 | } aTypeTable[] = { |
| 821 | // re-location heaven: |
| 822 | { |
| 823 | "Comp"_ostr, componentIfaceInit, |
| 824 | atk_component_get_type, |
| 825 | cppu::UnoType<accessibility::XAccessibleComponent>::get |
| 826 | }, |
| 827 | { |
| 828 | "Act"_ostr, actionIfaceInit, |
| 829 | atk_action_get_type, |
| 830 | cppu::UnoType<accessibility::XAccessibleAction>::get |
| 831 | }, |
| 832 | { |
| 833 | "Txt"_ostr, textIfaceInit, |
| 834 | atk_text_get_type, |
| 835 | cppu::UnoType<accessibility::XAccessibleText>::get |
| 836 | }, |
| 837 | { |
| 838 | "Val"_ostr, valueIfaceInit, |
| 839 | atk_value_get_type, |
| 840 | cppu::UnoType<accessibility::XAccessibleValue>::get |
| 841 | }, |
| 842 | { |
| 843 | "Tab"_ostr, tableIfaceInit, |
| 844 | atk_table_get_type, |
| 845 | cppu::UnoType<accessibility::XAccessibleTable>::get |
| 846 | }, |
| 847 | { |
| 848 | "Cell"_ostr, tablecellIfaceInit, |
| 849 | atk_table_cell_get_type, |
| 850 | // there is no UNO a11y interface for table cells, so this case is handled separately below |
| 851 | nullptr |
| 852 | }, |
| 853 | { |
| 854 | "Edt"_ostr, editableTextIfaceInit, |
| 855 | atk_editable_text_get_type, |
| 856 | cppu::UnoType<accessibility::XAccessibleEditableText>::get |
| 857 | }, |
| 858 | { |
| 859 | "Img"_ostr, imageIfaceInit, |
| 860 | atk_image_get_type, |
| 861 | cppu::UnoType<accessibility::XAccessibleImage>::get |
| 862 | }, |
| 863 | { |
| 864 | "Hyp"_ostr, hypertextIfaceInit, |
| 865 | atk_hypertext_get_type, |
| 866 | cppu::UnoType<accessibility::XAccessibleHypertext>::get |
| 867 | }, |
| 868 | { |
| 869 | "Sel"_ostr, selectionIfaceInit, |
| 870 | atk_selection_get_type, |
| 871 | cppu::UnoType<accessibility::XAccessibleSelection>::get |
| 872 | } |
| 873 | // AtkDocument is a nastily broken interface (so far) |
| 874 | // we could impl. get_document_type perhaps though. |
| 875 | }; |
| 876 | |
| 877 | const int aTypeTableSize = G_N_ELEMENTS( aTypeTable ); |
| 878 | |
| 879 | static GType |
| 880 | ensureTypeFor( uno::XInterface *pAccessible ) |
| 881 | { |
| 882 | int i; |
| 883 | bool bTypes[ aTypeTableSize ] = { false, }; |
| 884 | OStringBuffer aTypeNameBuf( "OOoAtkObj" ); |
| 885 | |
| 886 | for( i = 0; i < aTypeTableSize; i++ ) |
| 887 | { |
| 888 | if (aTypeTable[i].sName == "Cell") |
| 889 | { |
| 890 | // there is no UNO interface for table cells, but AtkTableCell can be supported |
| 891 | // for table cells via the methods of the parent that is a table |
| 892 | if (isTableCell(pAccessible)) |
| 893 | { |
| 894 | aTypeNameBuf.append(aTypeTable[i].sName); |
| 895 | bTypes[i] = true; |
| 896 | } |
| 897 | } |
| 898 | else if (isOfType( pAccessible, aTypeTable[i].aGetUnoType() ) ) |
| 899 | { |
| 900 | aTypeNameBuf.append(aTypeTable[i].sName); |
| 901 | bTypes[i] = true; |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | OString aTypeName = aTypeNameBuf.makeStringAndClear(); |
| 906 | GType nType = g_type_from_name( aTypeName.getStr() ); |
| 907 | if( nType == G_TYPE_INVALID ) |
| 908 | { |
| 909 | GTypeInfo aTypeInfo = { |
| 910 | sizeof( AtkObjectWrapperClass ), |
| 911 | nullptr, nullptr, nullptr, nullptr, nullptr, |
| 912 | sizeof( AtkObjectWrapper ), |
| 913 | 0, nullptr, nullptr |
| 914 | } ; |
| 915 | nType = g_type_register_static( ATK_TYPE_OBJECT_WRAPPER, |
| 916 | aTypeName.getStr(), &aTypeInfo, |
| 917 | GTypeFlags(0) ) ; |
| 918 | |
| 919 | for( int j = 0; j < aTypeTableSize; j++ ) |
| 920 | if( bTypes[j] ) |
| 921 | { |
| 922 | GInterfaceInfo aIfaceInfo = { nullptr, nullptr, nullptr }; |
| 923 | aIfaceInfo.interface_init = aTypeTable[j].aInit; |
| 924 | g_type_add_interface_static (nType, aTypeTable[j].aGetGIfaceType(), |
| 925 | &aIfaceInfo); |
| 926 | } |
| 927 | } |
| 928 | return nType; |
| 929 | } |
| 930 | |
| 931 | AtkObject * |
| 932 | atk_object_wrapper_ref( const uno::Reference< accessibility::XAccessible > &rxAccessible, bool create ) |
| 933 | { |
| 934 | g_return_val_if_fail( bool(rxAccessible), nullptr ); |
| 935 | |
| 936 | AtkObject *obj = ooo_wrapper_registry_get(rxAccessible); |
| 937 | if( obj ) |
| 938 | { |
| 939 | g_object_ref( obj ); |
| 940 | return obj; |
| 941 | } |
| 942 | |
| 943 | if( create ) |
| 944 | return atk_object_wrapper_new( rxAccessible ); |
| 945 | |
| 946 | return nullptr; |
| 947 | } |
| 948 | |
| 949 | AtkObject * |
| 950 | atk_object_wrapper_new( const css::uno::Reference< css::accessibility::XAccessible >& rxAccessible, |
| 951 | AtkObject* parent, AtkObject* orig ) |
| 952 | { |
| 953 | g_return_val_if_fail( bool(rxAccessible), nullptr ); |
| 954 | |
| 955 | AtkObjectWrapper *pWrap = nullptr; |
| 956 | |
| 957 | try { |
| 958 | uno::Reference< accessibility::XAccessibleContext > xContext(rxAccessible->getAccessibleContext()); |
| 959 | |
| 960 | g_return_val_if_fail( bool(xContext), nullptr ); |
| 961 | |
| 962 | GType nType = ensureTypeFor( xContext.get() ); |
| 963 | gpointer obj = g_object_new( nType, nullptr); |
| 964 | |
| 965 | pWrap = ATK_OBJECT_WRAPPER( obj ); |
| 966 | pWrap->mpAccessible = rxAccessible; |
| 967 | |
| 968 | pWrap->mpContext = xContext; |
| 969 | pWrap->mpOrig = orig; |
| 970 | if (pWrap->mpOrig) |
| 971 | g_object_ref(pWrap->mpOrig); |
| 972 | |
| 973 | AtkObject* atk_obj = ATK_OBJECT(pWrap); |
| 974 | atk_obj->role = mapToAtkRole(xContext->getAccessibleRole(), xContext->getAccessibleStateSet()); |
| 975 | atk_obj->accessible_parent = parent; |
| 976 | |
| 977 | ooo_wrapper_registry_add( rxAccessible, atk_obj ); |
| 978 | |
| 979 | if( parent ) |
| 980 | g_object_ref( atk_obj->accessible_parent ); |
| 981 | else |
| 982 | { |
| 983 | /* gail_focus_tracker remembers the focused object at the first |
| 984 | * parent in the hierarchy that is a Gtk+ widget, but at the time the |
| 985 | * event gets processed (at idle), it may be too late to create the |
| 986 | * hierarchy, so doing it now .. |
| 987 | */ |
| 988 | uno::Reference< accessibility::XAccessible > xParent( xContext->getAccessibleParent() ); |
| 989 | |
| 990 | if( xParent.is() ) |
| 991 | atk_obj->accessible_parent = atk_object_wrapper_ref( xParent ); |
| 992 | } |
| 993 | |
| 994 | // Attach a listener to the UNO object if it's not TRANSIENT |
| 995 | sal_Int64 nStateSet( xContext->getAccessibleStateSet() ); |
| 996 | if( ! (nStateSet & accessibility::AccessibleStateType::TRANSIENT ) ) |
| 997 | { |
| 998 | uno::Reference< accessibility::XAccessibleEventBroadcaster > xBroadcaster(xContext, uno::UNO_QUERY); |
| 999 | if( xBroadcaster.is() ) |
| 1000 | { |
| 1001 | uno::Reference<accessibility::XAccessibleEventListener> xListener(new AtkListener(pWrap)); |
| 1002 | xBroadcaster->addAccessibleEventListener(xListener); |
| 1003 | } |
| 1004 | else |
| 1005 | OSL_ASSERT( false ); |
| 1006 | } |
| 1007 | |
| 1008 | css::uno::Reference<css::accessibility::XAccessibleContext2> xContext2(xContext, |
| 1009 | css::uno::UNO_QUERY); |
| 1010 | if (xContext2.is()) |
| 1011 | { |
| 1012 | OString aId = OUStringToOString(xContext2->getAccessibleId(), RTL_TEXTENCODING_UTF8); |
| 1013 | atk_object_set_accessible_id(atk_obj, aId.getStr()); |
| 1014 | } |
| 1015 | |
| 1016 | // tdf#141197 if we have a sysobj child then include that in the hierarchy |
| 1017 | if (VCLXAccessibleComponent* pVCLAccComponent |
| 1018 | = dynamic_cast<VCLXAccessibleComponent*>(rxAccessible.get())) |
| 1019 | { |
| 1020 | VclPtr<vcl::Window> xWindow = pVCLAccComponent->GetWindow(); |
| 1021 | if (xWindow && xWindow->GetType() == WindowType::SYSTEMCHILDWINDOW) |
| 1022 | { |
| 1023 | const SystemEnvData* pEnvData = static_cast<SystemChildWindow*>(xWindow.get())->GetSystemData(); |
| 1024 | if (GtkWidget *pSysObj = pEnvData ? static_cast<GtkWidget*>(pEnvData->pWidget) : nullptr) |
| 1025 | { |
| 1026 | pWrap->mpSysObjChild = gtk_widget_get_accessible(pSysObj); |
| 1027 | AtkObject* pParent = atk_object_wrapper_ref(xWindow->GetAccessible()); |
| 1028 | if (pParent) |
| 1029 | { |
| 1030 | atk_object_set_parent(pWrap->mpSysObjChild, pParent); |
| 1031 | g_object_unref(pParent); |
| 1032 | } |
| 1033 | } |
| 1034 | } |
| 1035 | } |
| 1036 | |
| 1037 | return ATK_OBJECT( pWrap ); |
| 1038 | } |
| 1039 | catch (const uno::Exception &) |
| 1040 | { |
| 1041 | if( pWrap ) |
| 1042 | g_object_unref( pWrap ); |
| 1043 | |
| 1044 | return nullptr; |
| 1045 | } |
| 1046 | } |
| 1047 | |
| 1048 | /*****************************************************************************/ |
| 1049 | |
| 1050 | void atk_object_wrapper_add_child(AtkObjectWrapper* wrapper, AtkObject *child, gint index) |
| 1051 | { |
| 1052 | AtkObject *atk_obj = ATK_OBJECT( wrapper ); |
| 1053 | |
| 1054 | atk_object_set_parent( child, atk_obj ); |
| 1055 | g_signal_emit_by_name( atk_obj, "children_changed::add", index, child, nullptr ); |
| 1056 | } |
| 1057 | |
| 1058 | /*****************************************************************************/ |
| 1059 | |
| 1060 | void atk_object_wrapper_remove_child(AtkObjectWrapper* wrapper, AtkObject *child, gint index) |
| 1061 | { |
| 1062 | g_signal_emit_by_name( ATK_OBJECT( wrapper ), "children_changed::remove", index, child, nullptr ); |
| 1063 | } |
| 1064 | |
| 1065 | /*****************************************************************************/ |
| 1066 | |
| 1067 | void atk_object_wrapper_set_role(AtkObjectWrapper* wrapper, sal_Int16 role, sal_Int64 nStates) |
| 1068 | { |
| 1069 | AtkObject *atk_obj = ATK_OBJECT( wrapper ); |
| 1070 | atk_object_set_role(atk_obj, mapToAtkRole(role, nStates)); |
| 1071 | } |
| 1072 | |
| 1073 | /*****************************************************************************/ |
| 1074 | |
| 1075 | void atk_object_wrapper_dispose(AtkObjectWrapper* wrapper) |
| 1076 | { |
| 1077 | wrapper->mpContext.clear(); |
| 1078 | wrapper->mpAction.clear(); |
| 1079 | wrapper->mpComponent.clear(); |
| 1080 | wrapper->mpEditableText.clear(); |
| 1081 | wrapper->mpHypertext.clear(); |
| 1082 | wrapper->mpImage.clear(); |
| 1083 | wrapper->mpSelection.clear(); |
| 1084 | wrapper->mpMultiLineText.clear(); |
| 1085 | wrapper->mpTable.clear(); |
| 1086 | wrapper->mpTableSelection.clear(); |
| 1087 | wrapper->mpText.clear(); |
| 1088 | wrapper->mpTextMarkup.clear(); |
| 1089 | wrapper->mpTextAttributes.clear(); |
| 1090 | wrapper->mpValue.clear(); |
| 1091 | } |
| 1092 | |
| 1093 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |