| 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 <unx/gtk/gtkframe.hxx> |
| 21 | |
| 22 | #include <comphelper/OAccessible.hxx> |
| 23 | #include <vcl/window.hxx> |
| 24 | #include "atkwrapper.hxx" |
| 25 | #include "atkfactory.hxx" |
| 26 | #include "atkregistry.hxx" |
| 27 | |
| 28 | using namespace ::com::sun::star; |
| 29 | |
| 30 | extern "C" { |
| 31 | |
| 32 | /* |
| 33 | * The wrapper factory |
| 34 | */ |
| 35 | |
| 36 | static GType |
| 37 | wrapper_factory_get_accessible_type() |
| 38 | { |
| 39 | return atk_object_wrapper_get_type(); |
| 40 | } |
| 41 | |
| 42 | static AtkObject* |
| 43 | wrapper_factory_create_accessible( GObject *obj ) |
| 44 | { |
| 45 | GtkWidget* pEventBox = gtk_widget_get_parent(GTK_WIDGET(obj)); |
| 46 | assert(pEventBox); |
| 47 | if (!pEventBox) |
| 48 | return nullptr; |
| 49 | |
| 50 | GtkWidget* pTopLevelGrid = gtk_widget_get_parent(pEventBox); |
| 51 | assert(pTopLevelGrid); |
| 52 | if (!pTopLevelGrid) |
| 53 | return nullptr; |
| 54 | |
| 55 | GtkWidget* pTopLevel = gtk_widget_get_parent(pTopLevelGrid); |
| 56 | assert(pTopLevel); |
| 57 | if (!pTopLevel) |
| 58 | return nullptr; |
| 59 | |
| 60 | GtkSalFrame* pFrame = GtkSalFrame::getFromWindow(pTopLevel); |
| 61 | assert(pFrame); |
| 62 | if (!pFrame) |
| 63 | return nullptr; |
| 64 | |
| 65 | vcl::Window* pFrameWindow = pFrame->GetWindow(); |
| 66 | assert(pFrameWindow); |
| 67 | if( pFrameWindow ) |
| 68 | { |
| 69 | vcl::Window* pWindow = pFrameWindow; |
| 70 | |
| 71 | // skip accessible objects already exposed by the frame objects |
| 72 | if( WindowType::BORDERWINDOW == pWindow->GetType() ) |
| 73 | pWindow = pFrameWindow->GetAccessibleChildWindow(0); |
| 74 | |
| 75 | if( pWindow ) |
| 76 | { |
| 77 | rtl::Reference<comphelper::OAccessible> pAccessible = pWindow->GetAccessible(); |
| 78 | if (pAccessible.is()) |
| 79 | { |
| 80 | AtkObject* accessible = ooo_wrapper_registry_get(pAccessible); |
| 81 | |
| 82 | if( accessible ) |
| 83 | g_object_ref( G_OBJECT(accessible) ); |
| 84 | else |
| 85 | accessible |
| 86 | = atk_object_wrapper_new(pAccessible, gtk_widget_get_accessible(pEventBox)); |
| 87 | |
| 88 | return accessible; |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | return nullptr; |
| 94 | } |
| 95 | |
| 96 | AtkObject* ooo_fixed_get_accessible(GtkWidget *obj) |
| 97 | { |
| 98 | return wrapper_factory_create_accessible(G_OBJECT(obj)); |
| 99 | } |
| 100 | |
| 101 | static void |
| 102 | wrapper_factory_class_init( gpointer klass_, gpointer ) |
| 103 | { |
| 104 | auto const klass = static_cast<AtkObjectFactoryClass *>(klass_); |
| 105 | klass->create_accessible = wrapper_factory_create_accessible; |
| 106 | klass->get_accessible_type = wrapper_factory_get_accessible_type; |
| 107 | } |
| 108 | |
| 109 | GType |
| 110 | wrapper_factory_get_type() |
| 111 | { |
| 112 | static GType t = 0; |
| 113 | |
| 114 | if (!t) { |
| 115 | static const GTypeInfo tinfo = |
| 116 | { |
| 117 | sizeof (AtkObjectFactoryClass), |
| 118 | nullptr, nullptr, wrapper_factory_class_init, |
| 119 | nullptr, nullptr, sizeof (AtkObjectFactory), 0, nullptr, nullptr |
| 120 | }; |
| 121 | |
| 122 | t = g_type_register_static ( |
| 123 | ATK_TYPE_OBJECT_FACTORY, "OOoAtkObjectWrapperFactory", |
| 124 | &tinfo, GTypeFlags(0)); |
| 125 | } |
| 126 | |
| 127 | return t; |
| 128 | } |
| 129 | |
| 130 | } // extern C |
| 131 | |
| 132 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |