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
 * AtkHypertext:
26
 *
27
 * The ATK interface which provides standard mechanism for manipulating hyperlinks.
28
 *
29
 * An interface used for objects which implement linking between
30
 * multiple resource or content locations, or multiple 'markers'
31
 * within a single document.  A Hypertext instance is associated with
32
 * one or more Hyperlinks, which are associated with particular
33
 * offsets within the Hypertext's included content.  While this
34
 * interface is derived from Text, there is no requirement that
35
 * Hypertext instances have textual content; they may implement Image
36
 * as well, and Hyperlinks need not have non-zero text offsets.
37
 */
38

            
39
enum
40
{
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
GType
50
1922
atk_hypertext_get_type (void)
51
{
52
  static GType type = 0;
53

            
54
1922
  if (!type)
55
    {
56
      static const GTypeInfo tinfo = {
57
        sizeof (AtkHypertextIface),
58
        (GBaseInitFunc) atk_hypertext_base_init,
59
        (GBaseFinalizeFunc) NULL,
60

            
61
      };
62

            
63
161
      type = g_type_register_static (G_TYPE_INTERFACE, "AtkHypertext", &tinfo, 0);
64
    }
65

            
66
1922
  return type;
67
}
68

            
69
static void
70
332
atk_hypertext_base_init (AtkHypertextIface *class)
71
{
72
  static gboolean initialized = FALSE;
73

            
74
332
  if (!initialized)
75
    {
76
      /**
77
       * AtkHypertext::link-selected:
78
       * @atkhypertext: the object which received the signal.
79
       * @arg1: the index of the hyperlink which is selected
80
       *
81
       * The "link-selected" signal is emitted by an AtkHyperText
82
       * object when one of the hyperlinks associated with the object
83
       * is selected.
84
       */
85
161
      atk_hypertext_signals[LINK_SELECTED] =
86
161
          g_signal_new ("link_selected",
87
                        ATK_TYPE_HYPERTEXT,
88
                        G_SIGNAL_RUN_LAST,
89
                        G_STRUCT_OFFSET (AtkHypertextIface, link_selected),
90
                        (GSignalAccumulator) NULL, NULL,
91
                        g_cclosure_marshal_VOID__INT,
92
                        G_TYPE_NONE,
93
                        1, G_TYPE_INT);
94

            
95
161
      initialized = TRUE;
96
    }
97
332
}
98

            
99
/**
100
 * atk_hypertext_get_link:
101
 * @hypertext: an #AtkHypertext
102
 * @link_index: an integer specifying the desired link
103
 *
104
 * Gets the link in this hypertext document at index
105
 * @link_index
106
 *
107
 * Returns: (transfer none): the link in this hypertext document at
108
 * index @link_index
109
 **/
110
AtkHyperlink *
111
9
atk_hypertext_get_link (AtkHypertext *hypertext,
112
                        gint link_index)
113
{
114
  AtkHypertextIface *iface;
115

            
116
9
  g_return_val_if_fail (ATK_IS_HYPERTEXT (hypertext), NULL);
117

            
118
9
  if (link_index < 0)
119
    return NULL;
120

            
121
9
  iface = ATK_HYPERTEXT_GET_IFACE (hypertext);
122

            
123
9
  if (iface->get_link)
124
9
    return (*(iface->get_link)) (hypertext, link_index);
125
  else
126
    return NULL;
127
}
128

            
129
/**
130
 * atk_hypertext_get_n_links:
131
 * @hypertext: an #AtkHypertext
132
 *
133
 * Gets the number of links within this hypertext document.
134
 *
135
 * Returns: the number of links within this hypertext document
136
 **/
137
gint
138
1
atk_hypertext_get_n_links (AtkHypertext *hypertext)
139
{
140
  AtkHypertextIface *iface;
141

            
142
1
  g_return_val_if_fail (ATK_IS_HYPERTEXT (hypertext), 0);
143

            
144
1
  iface = ATK_HYPERTEXT_GET_IFACE (hypertext);
145

            
146
1
  if (iface->get_n_links)
147
1
    return (*(iface->get_n_links)) (hypertext);
148
  else
149
    return 0;
150
}
151

            
152
/**
153
 * atk_hypertext_get_link_index:
154
 * @hypertext: an #AtkHypertext
155
 * @char_index: a character index
156
 *
157
 * Gets the index into the array of hyperlinks that is associated with
158
 * the character specified by @char_index.
159
 *
160
 * Returns: an index into the array of hyperlinks in @hypertext,
161
 * or -1 if there is no hyperlink associated with this character.
162
 **/
163
gint
164
3
atk_hypertext_get_link_index (AtkHypertext *hypertext,
165
                              gint char_index)
166
{
167
  AtkHypertextIface *iface;
168

            
169
3
  g_return_val_if_fail (ATK_IS_HYPERTEXT (hypertext), -1);
170

            
171
3
  if (char_index < 0)
172
    return -1;
173

            
174
3
  iface = ATK_HYPERTEXT_GET_IFACE (hypertext);
175

            
176
3
  if (iface->get_link_index)
177
3
    return (*(iface->get_link_index)) (hypertext, char_index);
178
  else
179
    return -1;
180
}