Move setting of LD_LIBRARY_PATH closer to invocation of cppunittester
[LibreOffice.git] / vcl / unx / gtk3 / a11y / atkhypertext.cxx
blobc7f9b84b5550117f681a6efbb343b39161417aff
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "atkwrapper.hxx"
22 #include <com/sun/star/accessibility/XAccessibleHypertext.hpp>
24 using namespace ::com::sun::star;
26 // ---------------------- AtkHyperlink ----------------------
28 namespace {
30 struct HyperLink {
31 AtkHyperlink const atk_hyper_link;
33 uno::Reference< accessibility::XAccessibleHyperlink > xLink;
38 static uno::Reference< accessibility::XAccessibleHyperlink > const &
39 getHyperlink( AtkHyperlink *pHyperlink )
41 HyperLink *pLink = reinterpret_cast<HyperLink *>(pHyperlink);
42 return pLink->xLink;
45 static GObjectClass *hyper_parent_class = nullptr;
47 extern "C" {
49 static void
50 hyper_link_finalize (GObject *obj)
52 HyperLink *hl = reinterpret_cast<HyperLink *>(obj);
53 hl->xLink.clear();
54 hyper_parent_class->finalize (obj);
57 static gchar *
58 hyper_link_get_uri( AtkHyperlink *pLink,
59 gint i )
61 try {
62 uno::Any aAny = getHyperlink( pLink )->getAccessibleActionObject( i );
63 OUString aUri = aAny.get< OUString > ();
64 return OUStringToGChar(aUri);
66 catch(const uno::Exception&) {
67 g_warning( "Exception in hyper_link_get_uri" );
69 return nullptr;
72 static AtkObject *
73 hyper_link_get_object( AtkHyperlink *,
74 gint )
76 g_warning( "FIXME: hyper_link_get_object unimplemented" );
77 return nullptr;
79 static gint
80 hyper_link_get_end_index( AtkHyperlink *pLink )
82 try {
83 return getHyperlink( pLink )->getEndIndex();
85 catch(const uno::Exception&) {
87 return -1;
89 static gint
90 hyper_link_get_start_index( AtkHyperlink *pLink )
92 try {
93 return getHyperlink( pLink )->getStartIndex();
95 catch(const uno::Exception&) {
97 return -1;
99 static gboolean
100 hyper_link_is_valid( AtkHyperlink *pLink )
102 try {
103 return getHyperlink( pLink )->isValid();
105 catch(const uno::Exception&) {
107 return FALSE;
109 static gint
110 hyper_link_get_n_anchors( AtkHyperlink *pLink )
112 try {
113 return getHyperlink( pLink )->getAccessibleActionCount();
115 catch(const uno::Exception&) {
117 return 0;
120 static guint
121 hyper_link_link_state( AtkHyperlink * )
123 g_warning( "FIXME: hyper_link_link_state unimplemented" );
124 return 0;
126 static gboolean
127 hyper_link_is_selected_link( AtkHyperlink * )
129 g_warning( "FIXME: hyper_link_is_selected_link unimplemented" );
130 return FALSE;
133 static void
134 hyper_link_class_init (gpointer klass_, gpointer)
136 auto const klass = static_cast<AtkHyperlinkClass *>(klass_);
137 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
139 gobject_class->finalize = hyper_link_finalize;
141 hyper_parent_class = static_cast<GObjectClass *>(g_type_class_peek_parent (klass));
143 klass->get_uri = hyper_link_get_uri;
144 klass->get_object = hyper_link_get_object;
145 klass->get_end_index = hyper_link_get_end_index;
146 klass->get_start_index = hyper_link_get_start_index;
147 klass->is_valid = hyper_link_is_valid;
148 klass->get_n_anchors = hyper_link_get_n_anchors;
149 klass->link_state = hyper_link_link_state;
150 klass->is_selected_link = hyper_link_is_selected_link;
153 static GType
154 hyper_link_get_type()
156 static GType type = 0;
158 if (!type) {
159 static const GTypeInfo tinfo = {
160 sizeof (AtkHyperlinkClass),
161 nullptr, /* base init */
162 nullptr, /* base finalize */
163 hyper_link_class_init,
164 nullptr, /* class finalize */
165 nullptr, /* class data */
166 sizeof (HyperLink), /* instance size */
167 0, /* nb preallocs */
168 nullptr, /* instance init */
169 nullptr /* value table */
172 static const GInterfaceInfo atk_action_info = {
173 actionIfaceInit,
174 nullptr,
175 nullptr
178 type = g_type_register_static (ATK_TYPE_HYPERLINK,
179 "OOoAtkObjHyperLink", &tinfo,
180 GTypeFlags(0));
181 g_type_add_interface_static (type, ATK_TYPE_ACTION,
182 &atk_action_info);
185 return type;
188 // ---------------------- AtkHyperText ----------------------
190 /// @throws uno::RuntimeException
191 static css::uno::Reference<css::accessibility::XAccessibleHypertext>
192 getHypertext( AtkHypertext *pHypertext )
194 AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER( pHypertext );
195 if( pWrap )
197 if( !pWrap->mpHypertext.is() )
199 pWrap->mpHypertext.set(pWrap->mpContext, css::uno::UNO_QUERY);
202 return pWrap->mpHypertext;
205 return css::uno::Reference<css::accessibility::XAccessibleHypertext>();
208 static AtkHyperlink *
209 hypertext_get_link( AtkHypertext *hypertext,
210 gint link_index)
212 try {
213 css::uno::Reference<css::accessibility::XAccessibleHypertext> pHypertext
214 = getHypertext( hypertext );
215 if( pHypertext.is() )
217 HyperLink *pLink = static_cast<HyperLink *>(g_object_new( hyper_link_get_type(), nullptr ));
218 pLink->xLink = pHypertext->getHyperLink( link_index );
219 if( !pLink->xLink.is() ) {
220 g_object_unref( G_OBJECT( pLink ) );
221 pLink = nullptr;
223 return ATK_HYPERLINK( pLink );
226 catch(const uno::Exception&) {
227 g_warning( "Exception in getHyperLink()" );
230 return nullptr;
233 static gint
234 hypertext_get_n_links( AtkHypertext *hypertext )
236 try {
237 css::uno::Reference<css::accessibility::XAccessibleHypertext> pHypertext
238 = getHypertext( hypertext );
239 if( pHypertext.is() )
240 return pHypertext->getHyperLinkCount();
242 catch(const uno::Exception&) {
243 g_warning( "Exception in getHyperLinkCount()" );
246 return 0;
249 static gint
250 hypertext_get_link_index( AtkHypertext *hypertext,
251 gint index)
253 try {
254 css::uno::Reference<css::accessibility::XAccessibleHypertext> pHypertext
255 = getHypertext( hypertext );
256 if( pHypertext.is() )
257 return pHypertext->getHyperLinkIndex( index );
259 catch(const uno::Exception&) {
260 g_warning( "Exception in getHyperLinkIndex()" );
263 return 0;
266 } // extern "C"
268 void
269 hypertextIfaceInit (gpointer iface_, gpointer)
271 auto const iface = static_cast<AtkHypertextIface *>(iface_);
272 g_return_if_fail (iface != nullptr);
274 iface->get_link = hypertext_get_link;
275 iface->get_n_links = hypertext_get_n_links;
276 iface->get_link_index = hypertext_get_link_index;
279 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */