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
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
33 static GntWidgetClass
*parent_class
= NULL
;
36 gnt_label_destroy(GntWidget
*widget
)
38 GntLabel
*label
= GNT_LABEL(widget
);
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
);
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
);
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
;
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;
85 /******************************************************************************
87 *****************************************************************************/
89 gnt_label_get_gtype(void)
91 static GType type
= 0;
95 static const GTypeInfo info
= {
96 sizeof(GntLabelClass
),
98 NULL
, /* base_finalize */
99 (GClassInitFunc
)gnt_label_class_init
,
100 NULL
, /* class_finalize */
101 NULL
, /* class_data */
104 gnt_label_init
, /* instance_init */
105 NULL
/* value_table */
108 type
= g_type_register_static(GNT_TYPE_WIDGET
,
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
);
134 void gnt_label_set_text(GntLabel
*label
, const char *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
));