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 | |
---|
69 | void |
---|
70 | html_anchor_type_init (void) |
---|
71 | { |
---|
72 | html_anchor_class_init (&html_anchor_class, HTML_TYPE_ANCHOR, sizeof (HTMLAnchor)); |
---|
73 | } |
---|
74 | |
---|
75 | void |
---|
76 | html_anchor_class_init (HTMLAnchorClass *klass, |
---|
77 | HTMLType type, |
---|
78 | guint object_size) |
---|
79 | { |
---|
80 | HTMLObjectClass *object_class; |
---|
81 | |
---|
82 | object_class = HTML_OBJECT_CLASS (klass); |
---|
83 | |
---|
84 | html_object_class_init (object_class, type, object_size); |
---|
85 | |
---|
86 | object_class->destroy = destroy; |
---|
87 | object_class->copy = copy; |
---|
88 | object_class->find_anchor = find_anchor; |
---|
89 | |
---|
90 | parent_class = &html_object_class; |
---|
91 | } |
---|
92 | |
---|
93 | void |
---|
94 | html_anchor_init (HTMLAnchor *anchor, |
---|
95 | HTMLAnchorClass *klass, |
---|
96 | const gchar *name) |
---|
97 | { |
---|
98 | html_object_init (HTML_OBJECT (anchor), HTML_OBJECT_CLASS (klass)); |
---|
99 | |
---|
100 | anchor->name = g_string_new (name); |
---|
101 | } |
---|
102 | |
---|
103 | HTMLObject * |
---|
104 | html_anchor_new (const gchar *name) |
---|
105 | { |
---|
106 | HTMLAnchor *anchor; |
---|
107 | |
---|
108 | anchor = g_new (HTMLAnchor, 1); |
---|
109 | html_anchor_init (anchor, &html_anchor_class, name); |
---|
110 | |
---|
111 | return HTML_OBJECT (anchor); |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | const gchar * |
---|
116 | html_anchor_get_name (HTMLAnchor *anchor) |
---|
117 | { |
---|
118 | return anchor->name->str; |
---|
119 | } |
---|