1 /* Monolith text label class.
2 * - by Richard W.M. Jones <rich@annexia.org>
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.
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.
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.
18 * $Id: ml_text_label.c,v 1.6 2002/11/23 17:31:01 rich Exp $
27 #include <pthr_iolib.h>
30 #include "ml_widget.h"
31 #include "ml_smarttext.h"
32 #include "ml_text_label.h"
34 static void repaint (void *, ml_session, const char *, io_handle);
35 static struct ml_widget_property properties[];
37 struct ml_widget_operations text_label_ops =
40 properties: properties,
45 struct ml_widget_operations *ops;
46 pool pool; /* Pool for allocations. */
47 const char *text; /* Text to be displayed. */
49 /* Various style information. */
50 const char *text_align;
52 const char *font_weight;
53 const char *font_size;
56 static struct ml_widget_property properties[] =
59 offset: ml_offsetof (struct ml_text_label, text),
60 type: ML_PROP_STRING },
62 offset: ml_offsetof (struct ml_text_label, text_align),
63 type: ML_PROP_STRING },
65 offset: ml_offsetof (struct ml_text_label, colour),
66 type: ML_PROP_STRING },
67 { name: "font.weight",
68 offset: ml_offsetof (struct ml_text_label, font_weight),
69 type: ML_PROP_STRING },
71 offset: ml_offsetof (struct ml_text_label, font_size),
72 type: ML_PROP_STRING },
77 new_ml_text_label (pool pool, const char *text)
79 ml_text_label w = pmalloc (pool, sizeof *w);
81 w->ops = &text_label_ops;
85 w->text_align = 0; /* NULL means default for all these. */
94 repaint (void *vw, ml_session session, const char *windowid, io_handle io)
96 ml_text_label w = (ml_text_label) vw;
100 if (w->text_align || w->colour || w->font_weight || w->font_size)
102 io_fprintf (io, "<span style=\"");
104 io_fprintf (io, "text-align: %s;", w->text_align);
106 io_fprintf (io, "color: %s;", w->colour);
108 io_fprintf (io, "font-weight: %s;", w->font_weight);
110 io_fprintf (io, "font-size: %s;", w->font_size);
111 io_fprintf (io, "\">");
114 ml_plaintext_print (io, w->text);
116 if (w->text_align || w->colour || w->font_weight || w->font_size)
118 io_fprintf (io, "</span>");