Add to git.
[monolith.git] / src / ml_heading.c
1 /* Monolith heading 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_heading.c,v 1.2 2002/11/23 17:31:01 rich Exp $
19  */
20
21 #include "config.h"
22
23 #ifdef HAVE_STRING_H
24 #include <string.h>
25 #endif
26
27 #include <pthr_iolib.h>
28
29 #include "monolith.h"
30 #include "ml_widget.h"
31 #include "ml_smarttext.h"
32 #include "ml_heading.h"
33
34 static void repaint (void *, ml_session, const char *, io_handle);
35 static struct ml_widget_property properties[];
36
37 struct ml_widget_operations heading_ops =
38   {
39     repaint: repaint,
40     properties: properties,
41   };
42
43 struct ml_heading
44 {
45   struct ml_widget_operations *ops;
46   pool pool;                    /* Pool for allocations. */
47   int level;                    /* Heading level (1 - 6). */
48   const char *text;             /* Text to be displayed. */
49 };
50
51 static struct ml_widget_property properties[] =
52   {
53     { name: "text",
54       offset: ml_offsetof (struct ml_heading, text),
55       type: ML_PROP_STRING },
56     { name: "heading.level",
57       offset: ml_offsetof (struct ml_heading, level),
58       type: ML_PROP_INT },
59     { 0 },
60   };
61
62 ml_heading
63 new_ml_heading (pool pool, int level, const char *text)
64 {
65   ml_heading w = pmalloc (pool, sizeof *w);
66
67   w->ops = &heading_ops;
68   w->pool = pool;
69   w->level = level;
70   w->text = text;
71
72   return w;
73 }
74
75 static void
76 repaint (void *vw, ml_session session, const char *windowid, io_handle io)
77 {
78   ml_heading w = (ml_heading) vw;
79
80   if (w->text)
81     {
82       io_fprintf (io, "<h%d class=\"ml_heading\">", w->level);
83       ml_plaintext_print (io, w->text);
84       io_fprintf (io, "</h%d>", w->level);
85     }
86 }