2001-11-19 Michael Meeks <michael@ximian.com>
[platform/core/uifw/at-spi2-atk.git] / libspi / hyperlink.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2001 Sun Microsystems Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 /*
24  * component.c : bonobo wrapper for accessible component implementation
25  *
26  */
27 #include <config.h>
28 #include <bonobo/Bonobo.h>
29
30 #include <stdio.h>
31
32 /*
33  * This pulls the CORBA definitions for the "Accessibility::Accessible" server
34  */
35 #include <libspi/Accessibility.h>
36
37 /*
38  * This pulls the definition of the hyperlink bonobo object
39  */
40 #include "hyperlink.h"
41 #include "accessible.h"
42
43 /*
44  * Static function declarations
45  */
46
47 static void
48 spi_hyperlink_class_init (SpiHyperlinkClass *klass);
49 static void
50 spi_hyperlink_init (SpiHyperlink *hyperlink);
51 static void
52 spi_hyperlink_finalize (GObject *obj);
53 static CORBA_string
54 impl_getURI (PortableServer_Servant _servant,
55              const CORBA_long i, CORBA_Environment * ev);
56 static CORBA_short
57 impl__get_n_anchors (PortableServer_Servant _servant,
58                      CORBA_Environment * ev);
59 static CORBA_long
60 impl__get_startIndex (PortableServer_Servant _servant,
61                       CORBA_Environment * ev);
62 static CORBA_long
63 impl__get_endIndex (PortableServer_Servant _servant,
64                     CORBA_Environment * ev);
65 static Accessibility_Accessible
66 impl_getObject (PortableServer_Servant _servant,
67                 const CORBA_long i,
68                 CORBA_Environment * ev);
69 static CORBA_boolean
70 impl_isValid (PortableServer_Servant _servant,
71               CORBA_Environment * ev);
72
73 static GObjectClass *parent_class;
74
75
76 BONOBO_TYPE_FUNC_FULL (SpiHyperlink,
77                        Accessibility_Hyperlink,
78                        BONOBO_OBJECT_TYPE,
79                        spi_hyperlink);
80
81 static void
82 spi_hyperlink_class_init (SpiHyperlinkClass *klass)
83 {
84   GObjectClass * object_class = (GObjectClass *) klass;
85   POA_Accessibility_Hyperlink__epv *epv = &klass->epv;
86   parent_class = g_type_class_peek_parent (klass);
87
88   object_class->finalize = spi_hyperlink_finalize;
89
90   /* Initialize epv table */
91
92   epv->_get_nAnchors = impl__get_n_anchors;
93   epv->getURI = impl_getURI;
94   epv->_get_startIndex = impl__get_startIndex;
95   epv->_get_endIndex = impl__get_endIndex;
96   epv->getObject = impl_getObject;
97   epv->isValid = impl_isValid;
98 }
99
100 static void
101 spi_hyperlink_init (SpiHyperlink *hyperlink)
102 {
103 }
104
105 static void
106 spi_hyperlink_finalize (GObject *obj)
107 {
108   SpiHyperlink *hyperlink = SPI_HYPERLINK(obj);
109   g_object_unref (hyperlink->hyperlink);
110   hyperlink->hyperlink = NULL;
111   parent_class->finalize (obj);
112 }
113
114 SpiHyperlink *
115 spi_hyperlink_new (AtkHyperlink *hyperlink)
116 {
117   SpiHyperlink *new_hyperlink = 
118     SPI_HYPERLINK(g_object_new (SPI_HYPERLINK_TYPE, NULL));
119   g_object_ref (hyperlink);
120   new_hyperlink->hyperlink = hyperlink;
121   return new_hyperlink;
122 }
123
124
125
126 static CORBA_short
127 impl__get_n_anchors (PortableServer_Servant _servant,
128                      CORBA_Environment * ev)
129 {
130   SpiHyperlink *link = SPI_HYPERLINK(bonobo_object_from_servant(_servant));
131   return (CORBA_short) atk_hyperlink_get_n_anchors (ATK_HYPERLINK(link->hyperlink));
132 }
133
134
135
136 static CORBA_long
137 impl__get_startIndex (PortableServer_Servant _servant,
138                       CORBA_Environment * ev)
139 {
140   SpiHyperlink *link = SPI_HYPERLINK(bonobo_object_from_servant(_servant));
141   return (CORBA_long) atk_hyperlink_get_start_index (ATK_HYPERLINK(link->hyperlink));
142 }
143
144
145
146 static CORBA_long
147 impl__get_endIndex (PortableServer_Servant _servant,
148                     CORBA_Environment * ev)
149 {
150   SpiHyperlink *link = SPI_HYPERLINK(bonobo_object_from_servant(_servant));
151   return (CORBA_long) atk_hyperlink_get_end_index (ATK_HYPERLINK(link->hyperlink));
152 }
153
154
155
156 static CORBA_string
157 impl_getURI (PortableServer_Servant _servant,
158   const CORBA_long i, CORBA_Environment * ev)
159 {
160   SpiHyperlink *link = SPI_HYPERLINK(bonobo_object_from_servant(_servant));
161   gchar *uri;
162   CORBA_char *rv;
163   uri = atk_hyperlink_get_uri (ATK_HYPERLINK(link->hyperlink), (gint) i);
164   if (uri)
165     {
166       rv = CORBA_string_dup (uri);
167       g_free (uri);
168       }
169   else
170     rv = CORBA_string_dup ("");
171   return rv;
172
173
174
175
176 static Accessibility_Accessible
177 impl_getObject (PortableServer_Servant _servant,
178                 const CORBA_long i,
179                 CORBA_Environment * ev)
180 {
181   SpiHyperlink *link = SPI_HYPERLINK(bonobo_object_from_servant(_servant));
182   AtkObject *atk_object;
183   Accessibility_Accessible rv;
184   atk_object = atk_hyperlink_get_object (ATK_HYPERLINK(link->hyperlink), (gint) i);
185   rv = bonobo_object_corba_objref (BONOBO_OBJECT(spi_accessible_new(atk_object)));
186   return rv;
187 }
188
189
190
191 static CORBA_boolean
192 impl_isValid (PortableServer_Servant _servant,
193               CORBA_Environment * ev)
194 {
195   SpiHyperlink *link = SPI_HYPERLINK(bonobo_object_from_servant(_servant));
196   return (CORBA_boolean) atk_hyperlink_is_valid (ATK_HYPERLINK(link->hyperlink));
197 }
198
199