File: htmlboxtextlinkaccessible.c

package info (click to toggle)
claws-mail-extra-plugins 3.5.0-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 35,040 kB
  • ctags: 10,917
  • sloc: ansic: 86,223; sh: 15,775; makefile: 4,400; perl: 983; yacc: 219; lex: 168
file content (224 lines) | stat: -rw-r--r-- 6,709 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
 * Copyright 2004 Sun Microsystems Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <string.h>
#include <libgtkhtml/gtkhtml.h>
#include "layout/htmlboxtext.h"
#include "layout/htmlboxinline.h"
#include "htmlboxtextlinkaccessible.h"
#include "htmllinkaccessible.h"

static void     html_box_text_link_accessible_class_init      (HtmlBoxTextAccessibleClass *klass);
static void     html_box_text_link_accessible_finalize        (GObject   *object);
static void     html_box_text_link_accessible_real_initialize (AtkObject *object,
                                                               gpointer  data);

static void     html_box_text_link_accessible_hypertext_interface_init (AtkHypertextIface	  *iface);

static AtkHyperlink* html_box_text_link_accessible_get_link    (AtkHypertext *hypertext,
                                                         	gint         link_index);
static gint          html_box_text_link_accessible_get_n_links (AtkHypertext *hypertext);
static gint          html_box_text_link_accessible_get_link_index  (AtkHypertext *hypertext,
                                                                    gint         char_index);

static gpointer parent_class = NULL;

/*
 * This data structure is here in case we need to maintain any data for
 * a HtmlBoxTextLinkAccessible.
 */
struct _HtmlBoxTextLinkAccessiblePrivate
{
	gpointer tmp;
};

static const gchar *link_hyperlink = "atk-hyperlink";

GType
html_box_text_link_accessible_get_type (void)
{
	static GType type = 0;

	if (!type) {
		 static const GTypeInfo tinfo = {
			sizeof (HtmlBoxTextLinkAccessibleClass),
			(GBaseInitFunc) NULL, /* base init */
			(GBaseFinalizeFunc) NULL, /* base finalize */
			(GClassInitFunc) html_box_text_link_accessible_class_init,
			(GClassFinalizeFunc) NULL, /* class finalize */
			NULL, /* class data */
			sizeof (HtmlBoxTextLinkAccessible),
			0, /* nb preallocs */
			(GInstanceInitFunc) NULL, /* instance init */
			NULL /* value table */
		};

		static const GInterfaceInfo atk_hypertext_info = {
       			(GInterfaceInitFunc) html_box_text_link_accessible_hypertext_interface_init,
			(GInterfaceFinalizeFunc) NULL,
			NULL
		};
		type = g_type_register_static (HTML_TYPE_BOX_TEXT_ACCESSIBLE, "HtmlBoxTextLinkAccessible", &tinfo, 0);
       		g_type_add_interface_static (type, ATK_TYPE_HYPERTEXT, &atk_hypertext_info);
	}

	return type;
}

AtkObject*
html_box_text_link_accessible_new (GObject *obj)
{
	GObject *object;
	AtkObject *atk_object;

	object = g_object_new (HTML_TYPE_BOX_TEXT_LINK_ACCESSIBLE, NULL);
	atk_object = ATK_OBJECT (object);
	atk_object_initialize (atk_object, obj);
	atk_object->role = ATK_ROLE_TEXT;
	return atk_object;
}

static void
html_box_text_link_accessible_class_init (HtmlBoxTextAccessibleClass *klass)
{
	GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
	AtkObjectClass *class = ATK_OBJECT_CLASS (klass);

	parent_class = g_type_class_peek_parent (klass);

	gobject_class->finalize = html_box_text_link_accessible_finalize;
	class->initialize = html_box_text_link_accessible_real_initialize;
}

static void
html_box_text_link_accessible_finalize (GObject *object)
{
	HtmlBoxTextLinkAccessible *text;

	text = HTML_BOX_TEXT_LINK_ACCESSIBLE (object);
	g_free (text->priv);
	G_OBJECT_CLASS (parent_class)->finalize (object);
}

static void
html_box_text_link_accessible_real_initialize (AtkObject *object,
                                                gpointer  data)
{
	HtmlBoxTextLinkAccessible *text;

	ATK_OBJECT_CLASS (parent_class)->initialize (object, data);

	text = HTML_BOX_TEXT_LINK_ACCESSIBLE (object);
	text->priv = g_new0 (HtmlBoxTextLinkAccessiblePrivate, 1); 
}

static void
html_box_text_link_accessible_hypertext_interface_init (AtkHypertextIface *iface)
{
 	g_return_if_fail (iface != NULL);

	iface->get_link = html_box_text_link_accessible_get_link;
	iface->get_n_links = html_box_text_link_accessible_get_n_links;
	iface->get_link_index = html_box_text_link_accessible_get_link_index;
}

static void
box_link_destroyed (gpointer data)
{
	HtmlLinkAccessible *link;

	link = HTML_LINK_ACCESSIBLE (data);
	link->box = NULL;
	g_object_unref (link);
}

static AtkHyperlink*
html_box_text_link_accessible_get_link (AtkHypertext *hypertext,
	                                gint         link_index)
{
	AtkGObjectAccessible *atk_gobj;
	GObject *g_obj;
	HtmlBox *box;
	HtmlBox *box_link;
	HtmlLinkAccessible *link;
	AtkHyperlink *hyperlink;
	HtmlBox *parent;
	gpointer data;

	atk_gobj = ATK_GOBJECT_ACCESSIBLE (hypertext);
	g_obj = atk_gobject_accessible_get_object (atk_gobj);
	if (g_obj == NULL)
		return NULL;

	if (link_index != 0)
		return NULL;
		
	box = HTML_BOX (g_obj);
	box_link = box->parent;
	if (!box_link)
		return NULL;

	hyperlink = g_object_get_data (G_OBJECT (box_link), link_hyperlink);
	if (!hyperlink) {
		hyperlink = html_link_accessible_new (ATK_OBJECT (hypertext));
		link = HTML_LINK_ACCESSIBLE (hyperlink);
		link->box = box_link;
		link->index = 0;
		g_object_weak_ref (G_OBJECT (box_link),
				   (GWeakNotify) box_link_destroyed,
				   hyperlink);
		g_object_set_data (G_OBJECT (box_link), link_hyperlink, hyperlink);
		/* Store HtmlView on box_link */
		parent = box_link->parent;
		data = g_object_get_data (G_OBJECT (parent), "view");
		if (data)
			g_object_set_data (G_OBJECT (box_link), "view", data);

	}
	return hyperlink;
}

static gint
html_box_text_link_accessible_get_n_links (AtkHypertext *hypertext)
{
	AtkGObjectAccessible *atk_gobj;
	GObject *g_obj;

	atk_gobj = ATK_GOBJECT_ACCESSIBLE (hypertext);
	g_obj = atk_gobject_accessible_get_object (atk_gobj);
	if (g_obj == NULL)
		return 0;
		
	return 1;
}

static gint
html_box_text_link_accessible_get_link_index (AtkHypertext *hypertext,
                                              gint         char_index)
{
	AtkGObjectAccessible *atk_gobj;
	GObject *g_obj;

	atk_gobj = ATK_GOBJECT_ACCESSIBLE (hypertext);
	g_obj = atk_gobject_accessible_get_object (atk_gobj);
	if (g_obj == NULL)
		return -1;
		
	return 0;
}