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) 2000 Jonas Borgström <jonas_b@bitsmart.com>. |
---|
5 | |
---|
6 | This library is free software; you can redistribute it and/or |
---|
7 | modify it under the terms of the GNU Library General Public |
---|
8 | License as published by the Free Software Foundation; either |
---|
9 | version 2 of the License, or (at your option) any later version. |
---|
10 | |
---|
11 | This library is distributed in the hope that it will be useful, |
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
14 | Library General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU Library General Public License |
---|
17 | along with this library; see the file COPYING.LIB. If not, write to |
---|
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
19 | Boston, MA 02111-1307, USA. |
---|
20 | */ |
---|
21 | |
---|
22 | #include <config.h> |
---|
23 | #include "htmlimageinput.h" |
---|
24 | #include "htmlform.h" |
---|
25 | #include <string.h> |
---|
26 | |
---|
27 | |
---|
28 | HTMLImageInputClass html_imageinput_class; |
---|
29 | static HTMLEmbeddedClass *parent_class; |
---|
30 | |
---|
31 | |
---|
32 | static void |
---|
33 | destroy (HTMLObject *o) |
---|
34 | { |
---|
35 | html_object_destroy (HTML_OBJECT (HTML_IMAGEINPUT (o)->image)); |
---|
36 | |
---|
37 | HTML_OBJECT_CLASS (parent_class)->destroy (o); |
---|
38 | } |
---|
39 | |
---|
40 | static void |
---|
41 | copy (HTMLObject *self, |
---|
42 | HTMLObject *dest) |
---|
43 | { |
---|
44 | HTMLObject *duplicate_image; |
---|
45 | |
---|
46 | (* HTML_OBJECT_CLASS (parent_class)->copy) (self, dest); |
---|
47 | |
---|
48 | HTML_IMAGEINPUT (dest)->m_x = HTML_IMAGEINPUT (self)->m_x; |
---|
49 | HTML_IMAGEINPUT (dest)->m_y = HTML_IMAGEINPUT (self)->m_y; |
---|
50 | |
---|
51 | duplicate_image = html_object_dup (HTML_OBJECT (HTML_IMAGEINPUT (self)->image)); |
---|
52 | HTML_IMAGEINPUT (dest)->image = HTML_IMAGE (duplicate_image); |
---|
53 | } |
---|
54 | |
---|
55 | static void |
---|
56 | draw (HTMLObject *o, |
---|
57 | HTMLPainter *p, |
---|
58 | gint x, gint y, |
---|
59 | gint width, gint height, |
---|
60 | gint tx, gint ty) |
---|
61 | { |
---|
62 | HTML_OBJECT (HTML_IMAGEINPUT (o)->image)->x = o->x; |
---|
63 | HTML_OBJECT (HTML_IMAGEINPUT (o)->image)->y = o->y; |
---|
64 | |
---|
65 | html_object_draw (HTML_OBJECT (HTML_IMAGEINPUT (o)->image), |
---|
66 | p, |
---|
67 | x, y, |
---|
68 | width, height, |
---|
69 | tx, ty); |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | /* Even if it's an HTMLEmbeddable, HTMLImageInput does not use a |
---|
74 | widget, so we need to implement these methods ourselves instead of |
---|
75 | using the HTMLEmbeddable default implementations. */ |
---|
76 | |
---|
77 | static gint |
---|
78 | calc_min_width (HTMLObject *self, |
---|
79 | HTMLPainter *painter) |
---|
80 | { |
---|
81 | HTMLImageInput *image_input; |
---|
82 | |
---|
83 | image_input = HTML_IMAGEINPUT (self); |
---|
84 | |
---|
85 | return html_object_calc_min_width (HTML_OBJECT (image_input->image), |
---|
86 | painter); |
---|
87 | } |
---|
88 | |
---|
89 | static gboolean |
---|
90 | calc_size (HTMLObject *self, HTMLPainter *painter, GList **changed_objs) |
---|
91 | { |
---|
92 | HTMLImageInput *image_input; |
---|
93 | HTMLObject *image_object; |
---|
94 | gboolean retval; |
---|
95 | |
---|
96 | image_input = HTML_IMAGEINPUT (self); |
---|
97 | image_object = HTML_OBJECT (image_input->image); |
---|
98 | |
---|
99 | retval = html_object_calc_size (image_object, painter, changed_objs); |
---|
100 | |
---|
101 | self->width = image_object->width; |
---|
102 | self->ascent = image_object->ascent; |
---|
103 | self->descent = image_object->descent; |
---|
104 | |
---|
105 | return retval; |
---|
106 | } |
---|
107 | |
---|
108 | |
---|
109 | static gchar * |
---|
110 | encode (HTMLEmbedded *e) |
---|
111 | { |
---|
112 | GString *encoding = g_string_new (""); |
---|
113 | gchar *ptr; |
---|
114 | |
---|
115 | if(strlen (e->name)) { |
---|
116 | ptr = html_embedded_encode_string (e->name); |
---|
117 | encoding = g_string_assign (encoding, ptr); |
---|
118 | g_free (ptr); |
---|
119 | |
---|
120 | ptr = g_strdup_printf(".x=%d&", HTML_IMAGEINPUT(e)->m_x); |
---|
121 | encoding = g_string_append (encoding, ptr); |
---|
122 | g_free (ptr); |
---|
123 | |
---|
124 | ptr = html_embedded_encode_string (e->name); |
---|
125 | encoding = g_string_append (encoding, ptr); |
---|
126 | g_free (ptr); |
---|
127 | |
---|
128 | ptr = g_strdup_printf(".y=%d", HTML_IMAGEINPUT(e)->m_y); |
---|
129 | encoding = g_string_append (encoding, ptr); |
---|
130 | g_free (ptr); |
---|
131 | } |
---|
132 | |
---|
133 | ptr = encoding->str; |
---|
134 | g_string_free(encoding, FALSE); |
---|
135 | |
---|
136 | return ptr; |
---|
137 | } |
---|
138 | |
---|
139 | |
---|
140 | void |
---|
141 | html_imageinput_type_init (void) |
---|
142 | { |
---|
143 | html_imageinput_class_init (&html_imageinput_class, HTML_TYPE_IMAGEINPUT, sizeof (HTMLImageInput)); |
---|
144 | } |
---|
145 | |
---|
146 | void |
---|
147 | html_imageinput_class_init (HTMLImageInputClass *klass, |
---|
148 | HTMLType type, |
---|
149 | guint size) |
---|
150 | { |
---|
151 | HTMLEmbeddedClass *element_class; |
---|
152 | HTMLObjectClass *object_class; |
---|
153 | |
---|
154 | element_class = HTML_EMBEDDED_CLASS (klass); |
---|
155 | object_class = HTML_OBJECT_CLASS (klass); |
---|
156 | |
---|
157 | html_embedded_class_init (element_class, type, size); |
---|
158 | |
---|
159 | /* HTMLEmbedded methods. */ |
---|
160 | element_class->encode = encode; |
---|
161 | |
---|
162 | /* HTMLObject methods. */ |
---|
163 | object_class->destroy = destroy; |
---|
164 | object_class->copy = copy; |
---|
165 | object_class->draw = draw; |
---|
166 | object_class->calc_min_width = calc_min_width; |
---|
167 | object_class->calc_size = calc_size; |
---|
168 | |
---|
169 | parent_class = &html_embedded_class; |
---|
170 | } |
---|
171 | |
---|
172 | void |
---|
173 | html_imageinput_init (HTMLImageInput *img, |
---|
174 | HTMLImageInputClass *klass, |
---|
175 | HTMLImageFactory *imf, |
---|
176 | gchar *name, gchar *url) |
---|
177 | { |
---|
178 | HTMLEmbedded *element; |
---|
179 | HTMLObject *object; |
---|
180 | |
---|
181 | element = HTML_EMBEDDED (img); |
---|
182 | object = HTML_OBJECT (img); |
---|
183 | |
---|
184 | html_embedded_init (element, HTML_EMBEDDED_CLASS (klass), NULL, name, NULL); |
---|
185 | |
---|
186 | object->width = object->ascent = 32; |
---|
187 | |
---|
188 | img->image = HTML_IMAGE (html_image_new (imf, |
---|
189 | url, NULL, NULL, |
---|
190 | -1, -1, FALSE, FALSE, 0, |
---|
191 | NULL, |
---|
192 | HTML_VALIGN_BOTTOM, FALSE)); |
---|
193 | |
---|
194 | object->ascent = 32; |
---|
195 | object->width = 0; |
---|
196 | object->descent = 0; |
---|
197 | } |
---|
198 | |
---|
199 | HTMLObject * |
---|
200 | html_imageinput_new (HTMLImageFactory *imf, |
---|
201 | gchar *name, |
---|
202 | gchar *url) |
---|
203 | { |
---|
204 | HTMLImageInput *img; |
---|
205 | |
---|
206 | img = g_new0 (HTMLImageInput, 1); |
---|
207 | html_imageinput_init (img, &html_imageinput_class, imf, name, url); |
---|
208 | |
---|
209 | return HTML_OBJECT (img); |
---|
210 | } |
---|