summaryrefslogtreecommitdiffstats
path: root/vcl/unx/gtk3/a11y/gtk3atkhypertext.cxx
blob: 83f6817fc9e20f1776e0bbf88d3093866392b999 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include "atkwrapper.hxx"

#include <com/sun/star/accessibility/XAccessibleHypertext.hpp>

using namespace ::com::sun::star;

// ---------------------- AtkHyperlink ----------------------

namespace {

struct HyperLink {
    AtkHyperlink const atk_hyper_link;

    uno::Reference< accessibility::XAccessibleHyperlink > xLink;
};

}

static uno::Reference< accessibility::XAccessibleHyperlink > const &
    getHyperlink( AtkHyperlink *pHyperlink )
{
    HyperLink *pLink = reinterpret_cast<HyperLink *>(pHyperlink);
    return pLink->xLink;
}

static GObjectClass *hyper_parent_class = nullptr;

extern "C" {

static void
hyper_link_finalize (GObject *obj)
{
    HyperLink *hl = reinterpret_cast<HyperLink *>(obj);
    hl->xLink.clear();
    hyper_parent_class->finalize (obj);
}

static gchar *
hyper_link_get_uri( AtkHyperlink *pLink,
                    gint          i )
{
    try {
        uno::Any aAny = getHyperlink( pLink )->getAccessibleActionObject( i );
        OUString aUri = aAny.get< OUString > ();
        return OUStringToGChar(aUri);
    }
    catch(const uno::Exception&) {
        g_warning( "Exception in hyper_link_get_uri" );
    }
    return nullptr;
}

static AtkObject *
hyper_link_get_object( AtkHyperlink *,
                       gint          )
{
    g_warning( "FIXME: hyper_link_get_object unimplemented" );
    return nullptr;
}
static gint
hyper_link_get_end_index( AtkHyperlink *pLink )
{
    try {
        return getHyperlink( pLink )->getEndIndex();
    }
    catch(const uno::Exception&) {
    }
    return -1;
}
static gint
hyper_link_get_start_index( AtkHyperlink *pLink )
{
    try {
        return getHyperlink( pLink )->getStartIndex();
    }
    catch(const uno::Exception&) {
    }
    return -1;
}
static gboolean
hyper_link_is_valid( AtkHyperlink *pLink )
{
    try {
        return getHyperlink( pLink )->isValid();
    }
    catch(const uno::Exception&) {
    }
    return FALSE;
}
static gint
hyper_link_get_n_anchors( AtkHyperlink *pLink )
{
    try {
        return getHyperlink( pLink )->getAccessibleActionCount();
    }
    catch(const uno::Exception&) {
    }
    return 0;
}

static guint
hyper_link_link_state( AtkHyperlink * )
{
    g_warning( "FIXME: hyper_link_link_state unimplemented" );
    return 0;
}
static gboolean
hyper_link_is_selected_link( AtkHyperlink * )
{
    g_warning( "FIXME: hyper_link_is_selected_link unimplemented" );
    return FALSE;
}

static void
hyper_link_class_init (AtkHyperlinkClass *klass)
{
    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);

    gobject_class->finalize = hyper_link_finalize;

    hyper_parent_class = static_cast<GObjectClass *>(g_type_class_peek_parent (klass));

    klass->get_uri = hyper_link_get_uri;
    klass->get_object = hyper_link_get_object;
    klass->get_end_index = hyper_link_get_end_index;
    klass->get_start_index = hyper_link_get_start_index;
    klass->is_valid = hyper_link_is_valid;
    klass->get_n_anchors = hyper_link_get_n_anchors;
    klass->link_state = hyper_link_link_state;
    klass->is_selected_link = hyper_link_is_selected_link;
}

static GType
hyper_link_get_type()
{
    static GType type = 0;

    if (!type) {
        static const GTypeInfo tinfo = {
            sizeof (AtkHyperlinkClass),
            nullptr,               /* base init */
            nullptr,               /* base finalize */
            reinterpret_cast<GClassInitFunc>(hyper_link_class_init),
            nullptr,               /* class finalize */
            nullptr,               /* class data */
            sizeof (HyperLink), /* instance size */
            0,                  /* nb preallocs */
            nullptr,               /* instance init */
            nullptr                /* value table */
        };

        static const GInterfaceInfo atk_action_info = {
            reinterpret_cast<GInterfaceInitFunc>(actionIfaceInit),
            nullptr,
            nullptr
        };

        type = g_type_register_static (ATK_TYPE_HYPERLINK,
                                       "OOoAtkObjHyperLink", &tinfo,
                                       GTypeFlags(0));
        g_type_add_interface_static (type, ATK_TYPE_ACTION,
                                     &atk_action_info);
    }

    return type;
}

// ---------------------- AtkHyperText ----------------------

/// @throws uno::RuntimeException
static css::uno::Reference<css::accessibility::XAccessibleHypertext>
    getHypertext( AtkHypertext *pHypertext )
{
    AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER( pHypertext );
    if( pWrap )
    {
        if( !pWrap->mpHypertext.is() )
        {
            pWrap->mpHypertext.set(pWrap->mpContext, css::uno::UNO_QUERY);
        }

        return pWrap->mpHypertext;
    }

    return css::uno::Reference<css::accessibility::XAccessibleHypertext>();
}

static AtkHyperlink *
hypertext_get_link( AtkHypertext *hypertext,
                    gint          link_index)
{
    try {
        css::uno::Reference<css::accessibility::XAccessibleHypertext> pHypertext
            = getHypertext( hypertext );
        if( pHypertext.is() )
        {
            HyperLink *pLink = static_cast<HyperLink *>(g_object_new( hyper_link_get_type(), nullptr ));
            pLink->xLink = pHypertext->getHyperLink( link_index );
            if( !pLink->xLink.is() ) {
                g_object_unref( G_OBJECT( pLink ) );
                pLink = nullptr;
            }
            return ATK_HYPERLINK( pLink );
        }
    }
    catch(const uno::Exception&) {
        g_warning( "Exception in getHyperLink()" );
    }

    return nullptr;
}

static gint
hypertext_get_n_links( AtkHypertext *hypertext )
{
    try {
        css::uno::Reference<css::accessibility::XAccessibleHypertext> pHypertext
            = getHypertext( hypertext );
        if( pHypertext.is() )
            return pHypertext->getHyperLinkCount();
    }
    catch(const uno::Exception&) {
        g_warning( "Exception in getHyperLinkCount()" );
    }

    return 0;
}

static gint
hypertext_get_link_index( AtkHypertext *hypertext,
                          gint          index)
{
    try {
        css::uno::Reference<css::accessibility::XAccessibleHypertext> pHypertext
            = getHypertext( hypertext );
        if( pHypertext.is() )
            return pHypertext->getHyperLinkIndex( index );
    }
    catch(const uno::Exception&) {
        g_warning( "Exception in getHyperLinkIndex()" );
    }

    return 0;
}

} // extern "C"

void
hypertextIfaceInit (AtkHypertextIface *iface)
{
  g_return_if_fail (iface != nullptr);

  iface->get_link = hypertext_get_link;
  iface->get_n_links = hypertext_get_n_links;
  iface->get_link_index = hypertext_get_link_index;
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */