Revert "Revert "Merge remote-tracking branch 'origin/sandbox/mniesluchow/upstream_2_1...
[platform/upstream/atk.git] / atk / atkhypertext.c
1 /* ATK - The Accessibility Toolkit for GTK+
2  * Copyright 2001, 2002, 2003 Sun Microsystems Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "config.h"
21
22 #include "atkhypertext.h"
23
24 /**
25  * SECTION:atkhypertext
26  * @Short_description: The ATK interface which provides standard
27  *  mechanism for manipulating hyperlinks.
28  * @Title:AtkHypertext
29  *
30  * An interface used for objects which implement linking between
31  * multiple resource or content locations, or multiple 'markers'
32  * within a single document.  A Hypertext instance is associated with
33  * one or more Hyperlinks, which are associated with particular
34  * offsets within the Hypertext's included content.  While this
35  * interface is derived from Text, there is no requirement that
36  * Hypertext instances have textual content; they may implement Image
37  * as well, and Hyperlinks need not have non-zero text offsets.
38  */
39
40 enum {
41   LINK_SELECTED,
42   LAST_SIGNAL
43 };
44
45 static void atk_hypertext_base_init (AtkHypertextIface *class);
46
47 static guint atk_hypertext_signals[LAST_SIGNAL] = { 0 };
48
49
50 GType
51 atk_hypertext_get_type (void)
52 {
53   static GType type = 0;
54
55   if (!type) {
56     static const GTypeInfo tinfo =
57     {
58       sizeof (AtkHypertextIface),
59       (GBaseInitFunc) atk_hypertext_base_init,
60       (GBaseFinalizeFunc) NULL,
61
62     };
63
64     type = g_type_register_static (G_TYPE_INTERFACE, "AtkHypertext", &tinfo, 0);
65   }
66
67   return type;
68 }
69
70 static void
71 atk_hypertext_base_init (AtkHypertextIface *class)
72 {
73   static gboolean initialized = FALSE;
74
75   if (!initialized)
76     {
77       /**
78        * AtkHypertext::link-selected:
79        * @atkhypertext: the object which received the signal.
80        * @arg1: the index of the hyperlink which is selected
81        *
82        * The "link-selected" signal is emitted by an AtkHyperText
83        * object when one of the hyperlinks associated with the object
84        * is selected.
85        */
86       atk_hypertext_signals[LINK_SELECTED] =
87         g_signal_new ("link_selected",
88                       ATK_TYPE_HYPERTEXT,
89                       G_SIGNAL_RUN_LAST,
90                       G_STRUCT_OFFSET (AtkHypertextIface, link_selected),
91                       (GSignalAccumulator) NULL, NULL,
92                       g_cclosure_marshal_VOID__INT,
93                       G_TYPE_NONE,
94                       1, G_TYPE_INT);
95
96       initialized = TRUE;
97     }
98 }
99
100 /**
101  * atk_hypertext_get_link:
102  * @hypertext: an #AtkHypertext
103  * @link_index: an integer specifying the desired link
104  *
105  * Gets the link in this hypertext document at index 
106  * @link_index
107  *
108  * Returns: (transfer none): the link in this hypertext document at
109  * index @link_index
110  **/
111 AtkHyperlink* 
112 atk_hypertext_get_link (AtkHypertext  *hypertext,
113                         gint          link_index)
114 {
115   AtkHypertextIface *iface;
116
117   g_return_val_if_fail (ATK_IS_HYPERTEXT (hypertext), NULL);
118
119   if (link_index < 0)
120     return NULL;
121
122   iface = ATK_HYPERTEXT_GET_IFACE (hypertext);
123
124   if (iface->get_link)
125     return (*(iface->get_link)) (hypertext, link_index);
126   else
127     return NULL;
128 }
129
130 /**
131  * atk_hypertext_get_n_links:
132  * @hypertext: an #AtkHypertext
133  *
134  * Gets the number of links within this hypertext document.
135  *
136  * Returns: the number of links within this hypertext document
137  **/
138 gint 
139 atk_hypertext_get_n_links (AtkHypertext  *hypertext)
140 {
141   AtkHypertextIface *iface;
142
143   g_return_val_if_fail (ATK_IS_HYPERTEXT (hypertext), 0);
144
145   iface = ATK_HYPERTEXT_GET_IFACE (hypertext);
146
147   if (iface->get_n_links)
148     return (*(iface->get_n_links)) (hypertext);
149   else
150     return 0;
151 }
152
153 /**
154  * atk_hypertext_get_link_index:
155  * @hypertext: an #AtkHypertext
156  * @char_index: a character index
157  *
158  * Gets the index into the array of hyperlinks that is associated with
159  * the character specified by @char_index.
160  *
161  * Returns: an index into the array of hyperlinks in @hypertext,
162  * or -1 if there is no hyperlink associated with this character.
163  **/
164 gint 
165 atk_hypertext_get_link_index (AtkHypertext  *hypertext,
166                               gint          char_index)
167 {
168   AtkHypertextIface *iface;
169
170   g_return_val_if_fail (ATK_IS_HYPERTEXT (hypertext), -1);
171
172   if (char_index < 0)
173     return -1;
174
175   iface = ATK_HYPERTEXT_GET_IFACE (hypertext);
176
177   if (iface->get_link_index)
178     return (*(iface->get_link_index)) (hypertext, char_index);
179   else
180     return -1;
181 }