Add configure.ac
[gnt.git] / gntlabel.c
blobcd99fbe414a11482bd4a21cf4feca792c7e68439
1 /**
2 * GNT - The GLib Ncurses Toolkit
4 * GNT is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * source distribution.
8 * This library is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program 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
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23 #include "gntlabel.h"
24 #include "gntutils.h"
26 #include <string.h>
28 enum
30 SIGS = 1,
33 static GntWidgetClass *parent_class = NULL;
35 static void
36 gnt_label_destroy(GntWidget *widget)
38 GntLabel *label = GNT_LABEL(widget);
39 g_free(label->text);
42 static void
43 gnt_label_draw(GntWidget *widget)
45 GntLabel *label = GNT_LABEL(widget);
46 chtype flag = gnt_text_format_flag_to_chtype(label->flags);
48 wbkgdset(widget->window, '\0' | flag);
49 mvwaddstr(widget->window, 0, 0, label->text);
51 GNTDEBUG;
54 static void
55 gnt_label_size_request(GntWidget *widget)
57 GntLabel *label = GNT_LABEL(widget);
59 gnt_util_get_text_bound(label->text,
60 &widget->priv.width, &widget->priv.height);
63 static void
64 gnt_label_class_init(GntLabelClass *klass)
66 parent_class = GNT_WIDGET_CLASS(klass);
67 parent_class->destroy = gnt_label_destroy;
68 parent_class->draw = gnt_label_draw;
69 parent_class->map = NULL;
70 parent_class->size_request = gnt_label_size_request;
72 GNTDEBUG;
75 static void
76 gnt_label_init(GTypeInstance *instance, gpointer class)
78 GntWidget *widget = GNT_WIDGET(instance);
79 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X);
80 widget->priv.minw = 3;
81 widget->priv.minh = 1;
82 GNTDEBUG;
85 /******************************************************************************
86 * GntLabel API
87 *****************************************************************************/
88 GType
89 gnt_label_get_gtype(void)
91 static GType type = 0;
93 if(type == 0)
95 static const GTypeInfo info = {
96 sizeof(GntLabelClass),
97 NULL, /* base_init */
98 NULL, /* base_finalize */
99 (GClassInitFunc)gnt_label_class_init,
100 NULL, /* class_finalize */
101 NULL, /* class_data */
102 sizeof(GntLabel),
103 0, /* n_preallocs */
104 gnt_label_init, /* instance_init */
105 NULL /* value_table */
108 type = g_type_register_static(GNT_TYPE_WIDGET,
109 "GntLabel",
110 &info, 0);
113 return type;
116 GntWidget *gnt_label_new(const char *text)
118 return gnt_label_new_with_format(text, 0);
121 GntWidget *gnt_label_new_with_format(const char *text, GntTextFormatFlags flags)
123 GntWidget *widget = g_object_new(GNT_TYPE_LABEL, NULL);
124 GntLabel *label = GNT_LABEL(widget);
126 label->text = gnt_util_onscreen_fit_string(text, -1);
127 label->flags = flags;
128 gnt_widget_set_take_focus(widget, FALSE);
129 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW);
131 return widget;
134 void gnt_label_set_text(GntLabel *label, const char *text)
136 g_free(label->text);
137 label->text = gnt_util_onscreen_fit_string(text, -1);
139 if (GNT_WIDGET(label)->window)
141 werase(GNT_WIDGET(label)->window);
142 gnt_widget_draw(GNT_WIDGET(label));