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
40 static GntWidgetClass
*parent_class
= NULL
;
43 gnt_label_destroy(GntWidget
*widget
)
45 GntLabel
*label
= GNT_LABEL(widget
);
50 gnt_label_draw(GntWidget
*widget
)
52 GntLabel
*label
= GNT_LABEL(widget
);
53 chtype flag
= gnt_text_format_flag_to_chtype(label
->flags
);
55 wbkgdset(widget
->window
, '\0' | flag
);
56 mvwaddstr(widget
->window
, 0, 0, label
->text
);
62 gnt_label_size_request(GntWidget
*widget
)
64 GntLabel
*label
= GNT_LABEL(widget
);
66 gnt_util_get_text_bound(label
->text
,
67 &widget
->priv
.width
, &widget
->priv
.height
);
71 gnt_label_set_property(GObject
*obj
, guint prop_id
, const GValue
*value
,
74 GntLabel
*label
= GNT_LABEL(obj
);
78 label
->text
= gnt_util_onscreen_fit_string(g_value_get_string(value
), -1);
81 label
->flags
= g_value_get_int(value
);
84 g_return_if_reached();
90 gnt_label_get_property(GObject
*obj
, guint prop_id
, GValue
*value
,
93 GntLabel
*label
= GNT_LABEL(obj
);
96 g_value_set_string(value
, label
->text
);
99 g_value_set_int(value
, label
->flags
);
107 gnt_label_class_init(GntLabelClass
*klass
)
109 GObjectClass
*gclass
= G_OBJECT_CLASS(klass
);
111 parent_class
= GNT_WIDGET_CLASS(klass
);
112 parent_class
->destroy
= gnt_label_destroy
;
113 parent_class
->draw
= gnt_label_draw
;
114 parent_class
->map
= NULL
;
115 parent_class
->size_request
= gnt_label_size_request
;
117 gclass
->set_property
= gnt_label_set_property
;
118 gclass
->get_property
= gnt_label_get_property
;
120 g_object_class_install_property(gclass
,
122 g_param_spec_string("text", "Text",
123 "The text for the label.",
125 G_PARAM_READWRITE
|G_PARAM_STATIC_NAME
|G_PARAM_STATIC_NICK
|G_PARAM_STATIC_BLURB
129 g_object_class_install_property(gclass
,
131 g_param_spec_int("text-flag", "Text flag",
132 "Text attribute to use when displaying the text in the label.",
133 GNT_TEXT_FLAG_NORMAL
,
134 GNT_TEXT_FLAG_NORMAL
|GNT_TEXT_FLAG_BOLD
|GNT_TEXT_FLAG_UNDERLINE
|
135 GNT_TEXT_FLAG_BLINK
|GNT_TEXT_FLAG_DIM
|GNT_TEXT_FLAG_HIGHLIGHT
,
136 GNT_TEXT_FLAG_NORMAL
,
137 G_PARAM_READWRITE
|G_PARAM_STATIC_NAME
|G_PARAM_STATIC_NICK
|G_PARAM_STATIC_BLURB
144 gnt_label_init(GTypeInstance
*instance
, gpointer
class)
146 GntWidget
*widget
= GNT_WIDGET(instance
);
147 gnt_widget_set_take_focus(widget
, FALSE
);
148 GNT_WIDGET_SET_FLAGS(widget
, GNT_WIDGET_NO_BORDER
| GNT_WIDGET_NO_SHADOW
);
149 GNT_WIDGET_SET_FLAGS(widget
, GNT_WIDGET_GROW_X
);
150 widget
->priv
.minw
= 3;
151 widget
->priv
.minh
= 1;
155 /******************************************************************************
157 *****************************************************************************/
159 gnt_label_get_gtype(void)
161 static GType type
= 0;
165 static const GTypeInfo info
= {
166 sizeof(GntLabelClass
),
167 NULL
, /* base_init */
168 NULL
, /* base_finalize */
169 (GClassInitFunc
)gnt_label_class_init
,
170 NULL
, /* class_finalize */
171 NULL
, /* class_data */
174 gnt_label_init
, /* instance_init */
175 NULL
/* value_table */
178 type
= g_type_register_static(GNT_TYPE_WIDGET
,
186 GntWidget
*gnt_label_new(const char *text
)
188 return gnt_label_new_with_format(text
, 0);
191 GntWidget
*gnt_label_new_with_format(const char *text
, GntTextFormatFlags flags
)
193 GntWidget
*widget
= g_object_new(GNT_TYPE_LABEL
, "text-flag", flags
, "text", text
, NULL
);
197 void gnt_label_set_text(GntLabel
*label
, const char *text
)
199 g_object_set(label
, "text", text
, NULL
);
201 if (GNT_WIDGET(label
)->window
)
203 werase(GNT_WIDGET(label
)->window
);
204 gnt_widget_draw(GNT_WIDGET(label
));