Update ooo320-m1
[ooovba.git] / vcl / unx / gtk / a11y / atkhypertext.cxx
blobfd2bac798c27cc0b5e542ad89b596d91cf5f25cc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: atkhypertext.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
34 #include "atkwrapper.hxx"
36 #include <com/sun/star/accessibility/XAccessibleHypertext.hpp>
38 #include <stdio.h>
40 using namespace ::com::sun::star;
43 // ---------------------- AtkHyperlink ----------------------
45 typedef struct {
46 AtkHyperlink atk_hyper_link;
48 uno::Reference< accessibility::XAccessibleHyperlink > xLink;
49 } HyperLink;
51 static uno::Reference< accessibility::XAccessibleHyperlink >
52 getHyperlink( AtkHyperlink *pHyperlink )
54 HyperLink *pLink = (HyperLink *) pHyperlink;
55 return pLink->xLink;
58 static GObjectClass *hyper_parent_class = NULL;
60 extern "C" {
62 static void
63 hyper_link_finalize (GObject *obj)
65 HyperLink *hl = (HyperLink *) obj;
66 hl->xLink.clear();
67 hyper_parent_class->finalize (obj);
70 static gchar *
71 hyper_link_get_uri( AtkHyperlink *pLink,
72 gint i )
74 try {
75 uno::Any aAny = getHyperlink( pLink )->getAccessibleActionObject( i );
76 rtl::OUString aUri = aAny.get< rtl::OUString > ();
77 return OUStringToGChar(aUri);
79 catch(const uno::Exception& e) {
80 g_warning( "Exception in hyper_link_get_uri" );
82 return NULL;
85 static AtkObject *
86 hyper_link_get_object( AtkHyperlink *pLink,
87 gint i)
89 try {
90 uno::Any aAny = getHyperlink( pLink )->getAccessibleActionObject( i );
91 uno::Reference< accessibility::XAccessible > xObj( aAny, uno::UNO_QUERY_THROW );
92 return atk_object_wrapper_ref( xObj );
94 catch(const uno::Exception& e) {
95 g_warning( "Exception in hyper_link_get_object" );
97 return NULL;
99 static gint
100 hyper_link_get_end_index( AtkHyperlink *pLink )
102 try {
103 return getHyperlink( pLink )->getEndIndex();
105 catch(const uno::Exception& e) {
107 return -1;
109 static gint
110 hyper_link_get_start_index( AtkHyperlink *pLink )
112 try {
113 return getHyperlink( pLink )->getStartIndex();
115 catch(const uno::Exception& e) {
117 return -1;
119 static gboolean
120 hyper_link_is_valid( AtkHyperlink *pLink )
122 try {
123 return getHyperlink( pLink )->isValid();
125 catch(const uno::Exception& e) {
127 return FALSE;
129 static gint
130 hyper_link_get_n_anchors( AtkHyperlink *pLink )
132 try {
133 return getHyperlink( pLink )->getAccessibleActionCount();
135 catch(const uno::Exception& e) {
137 return 0;
140 static guint
141 hyper_link_link_state( AtkHyperlink * )
143 g_warning( "FIXME: hyper_link_link_state unimplemented" );
144 return 0;
146 static gboolean
147 hyper_link_is_selected_link( AtkHyperlink * )
149 g_warning( "FIXME: hyper_link_is_selected_link unimplemented" );
150 return FALSE;
153 static void
154 hyper_link_class_init (AtkHyperlinkClass *klass)
156 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
158 gobject_class->finalize = hyper_link_finalize;
160 hyper_parent_class = (GObjectClass *)g_type_class_peek_parent (klass);
162 klass->get_uri = hyper_link_get_uri;
163 klass->get_object = hyper_link_get_object;
164 klass->get_end_index = hyper_link_get_end_index;
165 klass->get_start_index = hyper_link_get_start_index;
166 klass->is_valid = hyper_link_is_valid;
167 klass->get_n_anchors = hyper_link_get_n_anchors;
168 klass->link_state = hyper_link_link_state;
169 klass->is_selected_link = hyper_link_is_selected_link;
172 static GType
173 hyper_link_get_type (void)
175 static GType type = 0;
177 if (!type) {
178 static const GTypeInfo tinfo = {
179 sizeof (AtkHyperlinkClass),
180 NULL, /* base init */
181 NULL, /* base finalize */
182 (GClassInitFunc) hyper_link_class_init,
183 NULL, /* class finalize */
184 NULL, /* class data */
185 sizeof (HyperLink), /* instance size */
186 0, /* nb preallocs */
187 NULL, /* instance init */
188 NULL /* value table */
191 static const GInterfaceInfo atk_action_info = {
192 (GInterfaceInitFunc) actionIfaceInit,
193 (GInterfaceFinalizeFunc) NULL,
194 NULL
197 type = g_type_register_static (ATK_TYPE_HYPERLINK,
198 "OOoAtkObjHyperLink", &tinfo,
199 (GTypeFlags)0);
200 g_type_add_interface_static (type, ATK_TYPE_ACTION,
201 &atk_action_info);
204 return type;
207 // ---------------------- AtkHyperText ----------------------
209 static accessibility::XAccessibleHypertext*
210 getHypertext( AtkHypertext *pHypertext ) throw (uno::RuntimeException)
212 AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER( pHypertext );
213 if( pWrap )
215 if( !pWrap->mpHypertext && pWrap->mpContext )
217 uno::Any any = pWrap->mpContext->queryInterface( accessibility::XAccessibleHypertext::static_type(NULL) );
218 pWrap->mpHypertext = reinterpret_cast< accessibility::XAccessibleHypertext * > (any.pReserved);
219 pWrap->mpHypertext->acquire();
222 return pWrap->mpHypertext;
225 return NULL;
229 static AtkHyperlink *
230 hypertext_get_link( AtkHypertext *hypertext,
231 gint link_index)
233 try {
234 accessibility::XAccessibleHypertext* pHypertext = getHypertext( hypertext );
235 if( pHypertext )
237 HyperLink *pLink = (HyperLink *)g_object_new( hyper_link_get_type(), NULL );
238 pLink->xLink = pHypertext->getHyperLink( link_index );
239 if( !pLink->xLink.is() ) {
240 g_object_unref( G_OBJECT( pLink ) );
241 pLink = NULL;
243 return ATK_HYPERLINK( pLink );
246 catch(const uno::Exception& e) {
247 g_warning( "Exception in getHyperLink()" );
250 return NULL;
253 static gint
254 hypertext_get_n_links( AtkHypertext *hypertext )
256 try {
257 accessibility::XAccessibleHypertext* pHypertext = getHypertext( hypertext );
258 if( pHypertext )
259 return pHypertext->getHyperLinkCount();
261 catch(const uno::Exception& e) {
262 g_warning( "Exception in getHyperLinkCount()" );
265 return 0;
268 static gint
269 hypertext_get_link_index( AtkHypertext *hypertext,
270 gint index)
272 try {
273 accessibility::XAccessibleHypertext* pHypertext = getHypertext( hypertext );
274 if( pHypertext )
275 return pHypertext->getHyperLinkIndex( index );
277 catch(const uno::Exception& e) {
278 g_warning( "Exception in getHyperLinkIndex()" );
281 return 0;
284 } // extern "C"
286 void
287 hypertextIfaceInit (AtkHypertextIface *iface)
289 g_return_if_fail (iface != NULL);
291 iface->get_link = hypertext_get_link;
292 iface->get_n_links = hypertext_get_n_links;
293 iface->get_link_index = hypertext_get_link_index;