Add to git.
[monolith.git] / src / ml_image.c
1 /* Monolith image class.
2  * - by Richard W.M. Jones <rich@annexia.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the Free
16  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  *
18  * $Id: ml_image.c,v 1.2 2002/10/30 21:03:03 rich Exp $
19  */
20
21 #include "config.h"
22
23 #include <pthr_iolib.h>
24
25 #include "monolith.h"
26 #include "ml_widget.h"
27 #include "ml_image.h"
28
29 static void repaint (void *, ml_session, const char *, io_handle);
30 static struct ml_widget_property properties[];
31
32 struct ml_widget_operations image_ops =
33   {
34     repaint: repaint,
35     properties: properties,
36   };
37
38 struct ml_image
39 {
40   struct ml_widget_operations *ops;
41   pool pool;                    /* Pool for allocations. */
42   const char *src;              /* Source for the image. */
43 };
44
45 static struct ml_widget_property properties[] =
46   {
47     { name: "image",
48       offset: ml_offsetof (struct ml_image, src),
49       type: ML_PROP_STRING },
50     { 0 }
51   };
52
53 ml_image
54 new_ml_image (pool pool, const char *src)
55 {
56   ml_image w = pmalloc (pool, sizeof *w);
57
58   w->ops = &image_ops;
59   w->pool = pool;
60   w->src = src;
61
62   return w;
63 }
64
65 static void
66 repaint (void *vw, ml_session session, const char *windowid, io_handle io)
67 {
68   ml_image w = (ml_image) vw;
69
70   if (w->src)
71     {
72       io_fprintf (io, "<img src=\"%s\" />", w->src);
73     }
74 }