bump product version to 5.0.4.1
[LibreOffice.git] / vcl / unx / gtk / a11y / atkhypertext.cxx
blob9b01e6b5bf5effb7ff4cba5a027a271756568562
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 #include <stdio.h>
26 using namespace ::com::sun::star;
28 // ---------------------- AtkHyperlink ----------------------
30 typedef struct {
31 AtkHyperlink atk_hyper_link;
33 uno::Reference< accessibility::XAccessibleHyperlink > xLink;
34 } HyperLink;
36 static uno::Reference< accessibility::XAccessibleHyperlink >
37 getHyperlink( AtkHyperlink *pHyperlink )
39 HyperLink *pLink = reinterpret_cast<HyperLink *>(pHyperlink);
40 return pLink->xLink;
43 static GObjectClass *hyper_parent_class = NULL;
45 extern "C" {
47 static void
48 hyper_link_finalize (GObject *obj)
50 HyperLink *hl = reinterpret_cast<HyperLink *>(obj);
51 hl->xLink.clear();
52 hyper_parent_class->finalize (obj);
55 static gchar *
56 hyper_link_get_uri( AtkHyperlink *pLink,
57 gint i )
59 try {
60 uno::Any aAny = getHyperlink( pLink )->getAccessibleActionObject( i );
61 OUString aUri = aAny.get< OUString > ();
62 return OUStringToGChar(aUri);
64 catch(const uno::Exception&) {
65 g_warning( "Exception in hyper_link_get_uri" );
67 return NULL;
70 static AtkObject *
71 hyper_link_get_object( AtkHyperlink *pLink,
72 gint i)
74 try {
75 uno::Any aAny = getHyperlink( pLink )->getAccessibleActionObject( i );
76 uno::Reference< accessibility::XAccessible > xObj( aAny, uno::UNO_QUERY_THROW );
77 return atk_object_wrapper_ref( xObj );
79 catch(const uno::Exception&) {
80 g_warning( "Exception in hyper_link_get_object" );
82 return NULL;
84 static gint
85 hyper_link_get_end_index( AtkHyperlink *pLink )
87 try {
88 return getHyperlink( pLink )->getEndIndex();
90 catch(const uno::Exception&) {
92 return -1;
94 static gint
95 hyper_link_get_start_index( AtkHyperlink *pLink )
97 try {
98 return getHyperlink( pLink )->getStartIndex();
100 catch(const uno::Exception&) {
102 return -1;
104 static gboolean
105 hyper_link_is_valid( AtkHyperlink *pLink )
107 try {
108 return getHyperlink( pLink )->isValid();
110 catch(const uno::Exception&) {
112 return FALSE;
114 static gint
115 hyper_link_get_n_anchors( AtkHyperlink *pLink )
117 try {
118 return getHyperlink( pLink )->getAccessibleActionCount();
120 catch(const uno::Exception&) {
122 return 0;
125 static guint
126 hyper_link_link_state( AtkHyperlink * )
128 g_warning( "FIXME: hyper_link_link_state unimplemented" );
129 return 0;
131 static gboolean
132 hyper_link_is_selected_link( AtkHyperlink * )
134 g_warning( "FIXME: hyper_link_is_selected_link unimplemented" );
135 return FALSE;
138 static void
139 hyper_link_class_init (AtkHyperlinkClass *klass)
141 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
143 gobject_class->finalize = hyper_link_finalize;
145 hyper_parent_class = static_cast<GObjectClass *>(g_type_class_peek_parent (klass));
147 klass->get_uri = hyper_link_get_uri;
148 klass->get_object = hyper_link_get_object;
149 klass->get_end_index = hyper_link_get_end_index;
150 klass->get_start_index = hyper_link_get_start_index;
151 klass->is_valid = hyper_link_is_valid;
152 klass->get_n_anchors = hyper_link_get_n_anchors;
153 klass->link_state = hyper_link_link_state;
154 klass->is_selected_link = hyper_link_is_selected_link;
157 static GType
158 hyper_link_get_type()
160 static GType type = 0;
162 if (!type) {
163 static const GTypeInfo tinfo = {
164 sizeof (AtkHyperlinkClass),
165 NULL, /* base init */
166 NULL, /* base finalize */
167 reinterpret_cast<GClassInitFunc>(hyper_link_class_init),
168 NULL, /* class finalize */
169 NULL, /* class data */
170 sizeof (HyperLink), /* instance size */
171 0, /* nb preallocs */
172 NULL, /* instance init */
173 NULL /* value table */
176 static const GInterfaceInfo atk_action_info = {
177 reinterpret_cast<GInterfaceInitFunc>(actionIfaceInit),
178 (GInterfaceFinalizeFunc) NULL,
179 NULL
182 type = g_type_register_static (ATK_TYPE_HYPERLINK,
183 "OOoAtkObjHyperLink", &tinfo,
184 (GTypeFlags)0);
185 g_type_add_interface_static (type, ATK_TYPE_ACTION,
186 &atk_action_info);
189 return type;
192 // ---------------------- AtkHyperText ----------------------
194 static accessibility::XAccessibleHypertext*
195 getHypertext( AtkHypertext *pHypertext ) throw (uno::RuntimeException)
197 AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER( pHypertext );
198 if( pWrap )
200 if( !pWrap->mpHypertext && pWrap->mpContext )
202 uno::Any any = pWrap->mpContext->queryInterface( cppu::UnoType<accessibility::XAccessibleHypertext>::get() );
203 pWrap->mpHypertext = static_cast< accessibility::XAccessibleHypertext * > (any.pReserved);
204 pWrap->mpHypertext->acquire();
207 return pWrap->mpHypertext;
210 return NULL;
213 static AtkHyperlink *
214 hypertext_get_link( AtkHypertext *hypertext,
215 gint link_index)
217 try {
218 accessibility::XAccessibleHypertext* pHypertext = getHypertext( hypertext );
219 if( pHypertext )
221 HyperLink *pLink = static_cast<HyperLink *>(g_object_new( hyper_link_get_type(), NULL ));
222 pLink->xLink = pHypertext->getHyperLink( link_index );
223 if( !pLink->xLink.is() ) {
224 g_object_unref( G_OBJECT( pLink ) );
225 pLink = NULL;
227 return ATK_HYPERLINK( pLink );
230 catch(const uno::Exception&) {
231 g_warning( "Exception in getHyperLink()" );
234 return NULL;
237 static gint
238 hypertext_get_n_links( AtkHypertext *hypertext )
240 try {
241 accessibility::XAccessibleHypertext* pHypertext = getHypertext( hypertext );
242 if( pHypertext )
243 return pHypertext->getHyperLinkCount();
245 catch(const uno::Exception&) {
246 g_warning( "Exception in getHyperLinkCount()" );
249 return 0;
252 static gint
253 hypertext_get_link_index( AtkHypertext *hypertext,
254 gint index)
256 try {
257 accessibility::XAccessibleHypertext* pHypertext = getHypertext( hypertext );
258 if( pHypertext )
259 return pHypertext->getHyperLinkIndex( index );
261 catch(const uno::Exception&) {
262 g_warning( "Exception in getHyperLinkIndex()" );
265 return 0;
268 } // extern "C"
270 void
271 hypertextIfaceInit (AtkHypertextIface *iface)
273 g_return_if_fail (iface != NULL);
275 iface->get_link = hypertext_get_link;
276 iface->get_n_links = hypertext_get_n_links;
277 iface->get_link_index = hypertext_get_link_index;
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */