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., 59 Temple Place - Suite 330, |
---|
21 | Boston, MA 02111-1307, 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 |
---|
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 |
---|
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 * |
---|
57 | find_anchor (HTMLObject *o, const char *name, gint *x, gint *y) |
---|
58 | { |
---|
59 | if (strcmp (name, HTML_ANCHOR(o)->name->str) == 0) { |
---|
60 | *x += o->x; |
---|
61 | *y += o->y; |
---|
62 | |
---|
63 | return HTML_ANCHOR (o); |
---|
64 | } |
---|
65 | return NULL; |
---|
66 | } |
---|
67 | |
---|
68 | static HTMLObject * |
---|
69 | check_point (HTMLObject *self, |
---|
70 | HTMLPainter *painter, |
---|
71 | gint x, gint y, |
---|
72 | guint *offset_return, |
---|
73 | gboolean for_cursor) |
---|
74 | { |
---|
75 | return NULL; |
---|
76 | } |
---|
77 | |
---|
78 | static gboolean |
---|
79 | html_anchor_real_calc_size (HTMLObject *self, HTMLPainter *painter, GList **changed_objs) |
---|
80 | { |
---|
81 | self->width = 0; |
---|
82 | self->ascent = 1; |
---|
83 | self->descent = 0; |
---|
84 | |
---|
85 | return FALSE; |
---|
86 | } |
---|
87 | |
---|
88 | void |
---|
89 | html_anchor_type_init (void) |
---|
90 | { |
---|
91 | html_anchor_class_init (&html_anchor_class, HTML_TYPE_ANCHOR, sizeof (HTMLAnchor)); |
---|
92 | } |
---|
93 | |
---|
94 | void |
---|
95 | html_anchor_class_init (HTMLAnchorClass *klass, |
---|
96 | HTMLType type, |
---|
97 | guint object_size) |
---|
98 | { |
---|
99 | HTMLObjectClass *object_class; |
---|
100 | |
---|
101 | object_class = HTML_OBJECT_CLASS (klass); |
---|
102 | |
---|
103 | html_object_class_init (object_class, type, object_size); |
---|
104 | |
---|
105 | object_class->destroy = destroy; |
---|
106 | object_class->copy = copy; |
---|
107 | object_class->find_anchor = find_anchor; |
---|
108 | object_class->check_point = check_point; |
---|
109 | object_class->calc_size = html_anchor_real_calc_size; |
---|
110 | |
---|
111 | parent_class = &html_object_class; |
---|
112 | } |
---|
113 | |
---|
114 | void |
---|
115 | html_anchor_init (HTMLAnchor *anchor, |
---|
116 | HTMLAnchorClass *klass, |
---|
117 | const gchar *name) |
---|
118 | { |
---|
119 | html_object_init (HTML_OBJECT (anchor), HTML_OBJECT_CLASS (klass)); |
---|
120 | |
---|
121 | anchor->name = g_string_new (name); |
---|
122 | } |
---|
123 | |
---|
124 | HTMLObject * |
---|
125 | html_anchor_new (const gchar *name) |
---|
126 | { |
---|
127 | HTMLAnchor *anchor; |
---|
128 | |
---|
129 | anchor = g_new (HTMLAnchor, 1); |
---|
130 | html_anchor_init (anchor, &html_anchor_class, name); |
---|
131 | |
---|
132 | return HTML_OBJECT (anchor); |
---|
133 | } |
---|
134 | |
---|
135 | |
---|
136 | const gchar * |
---|
137 | html_anchor_get_name (HTMLAnchor *anchor) |
---|
138 | { |
---|
139 | return anchor->name->str; |
---|
140 | } |
---|