1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* This file is part of the GtkHTML library.
3  *
4  * Copyright (C) 1997 Martin Jones (mjones@kde.org)
5  * Copyright (C) 1997 Torben Weis (weis@kde.org)
6  * Copyright (C) 1999, 2000 Helix Code, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB.  If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22 */
23 
24 #include <config.h>
25 #include <string.h> /* strcmp() */
26 #include "htmlanchor.h"
27 
28 
29 HTMLAnchorClass html_anchor_class;
30 static HTMLObjectClass *parent_class = NULL;
31 
32 
33 /* HTMLObject methods.  */
34 
35 static void
destroy(HTMLObject * object)36 destroy (HTMLObject *object)
37 {
38 	HTMLAnchor *anchor;
39 
40 	anchor = HTML_ANCHOR (object);
41 
42 	g_string_free (anchor->name, TRUE);
43 
44 	HTML_OBJECT_CLASS (parent_class)->destroy (object);
45 }
46 
47 static void
copy(HTMLObject * self,HTMLObject * dest)48 copy (HTMLObject *self,
49       HTMLObject *dest)
50 {
51 	(* HTML_OBJECT_CLASS (parent_class)->copy) (self, dest);
52 
53 	HTML_ANCHOR (dest)->name = g_string_new (HTML_ANCHOR (self)->name->str);
54 }
55 
56 static HTMLAnchor *
find_anchor(HTMLObject * o,const gchar * name,gint * x,gint * y)57 find_anchor (HTMLObject *o,
58              const gchar *name,
59              gint *x,
60              gint *y)
61 {
62 	if (strcmp (name, HTML_ANCHOR (o)->name->str) == 0) {
63 		*x += o->x;
64 		*y += o->y;
65 
66 		return HTML_ANCHOR (o);
67 	}
68 	return NULL;
69 }
70 
71 static HTMLObject *
check_point(HTMLObject * self,HTMLPainter * painter,gint x,gint y,guint * offset_return,gboolean for_cursor)72 check_point (HTMLObject *self,
73              HTMLPainter *painter,
74              gint x,
75              gint y,
76              guint *offset_return,
77              gboolean for_cursor)
78 {
79 	return NULL;
80 }
81 
82 static gboolean
html_anchor_real_calc_size(HTMLObject * self,HTMLPainter * painter,GList ** changed_objs)83 html_anchor_real_calc_size (HTMLObject *self,
84                             HTMLPainter *painter,
85                             GList **changed_objs)
86 {
87 	self->width = 0;
88 	self->ascent = 1;
89 	self->descent = 0;
90 
91 	return FALSE;
92 }
93 
94 void
html_anchor_type_init(void)95 html_anchor_type_init (void)
96 {
97 	html_anchor_class_init (&html_anchor_class, HTML_TYPE_ANCHOR, sizeof (HTMLAnchor));
98 }
99 
100 void
html_anchor_class_init(HTMLAnchorClass * klass,HTMLType type,guint object_size)101 html_anchor_class_init (HTMLAnchorClass *klass,
102                         HTMLType type,
103                         guint object_size)
104 {
105 	HTMLObjectClass *object_class;
106 
107 	object_class = HTML_OBJECT_CLASS (klass);
108 
109 	html_object_class_init (object_class, type, object_size);
110 
111 	object_class->destroy = destroy;
112 	object_class->copy = copy;
113 	object_class->find_anchor = find_anchor;
114 	object_class->check_point = check_point;
115 	object_class->calc_size = html_anchor_real_calc_size;
116 
117 	parent_class = &html_object_class;
118 }
119 
120 void
html_anchor_init(HTMLAnchor * anchor,HTMLAnchorClass * klass,const gchar * name)121 html_anchor_init (HTMLAnchor *anchor,
122                   HTMLAnchorClass *klass,
123                   const gchar *name)
124 {
125 	html_object_init (HTML_OBJECT (anchor), HTML_OBJECT_CLASS (klass));
126 
127 	anchor->name = g_string_new (name);
128 }
129 
130 HTMLObject *
html_anchor_new(const gchar * name)131 html_anchor_new (const gchar *name)
132 {
133 	HTMLAnchor *anchor;
134 
135 	anchor = g_new (HTMLAnchor, 1);
136 	html_anchor_init (anchor, &html_anchor_class, name);
137 
138 	return HTML_OBJECT (anchor);
139 }
140 
141 
142 const gchar *
html_anchor_get_name(HTMLAnchor * anchor)143 html_anchor_get_name (HTMLAnchor *anchor)
144 {
145 	return anchor->name->str;
146 }
147