comparison finch/libgnt/gntlabel.c @ 15817:0e3a8505ebbe

renamed gaim-text to finch
author Sean Egan <seanegan@gmail.com>
date Sun, 18 Mar 2007 19:38:15 +0000
parents
children 8410511f4dbb
comparison
equal deleted inserted replaced
15816:317e7613e581 15817:0e3a8505ebbe
1 #include "gntlabel.h"
2 #include "gntutils.h"
3
4 #include <string.h>
5
6 enum
7 {
8 SIGS = 1,
9 };
10
11 static GntWidgetClass *parent_class = NULL;
12
13 static void
14 gnt_label_destroy(GntWidget *widget)
15 {
16 GntLabel *label = GNT_LABEL(widget);
17 g_free(label->text);
18 }
19
20 static void
21 gnt_label_draw(GntWidget *widget)
22 {
23 GntLabel *label = GNT_LABEL(widget);
24 chtype flag = gnt_text_format_flag_to_chtype(label->flags);
25
26 wbkgdset(widget->window, '\0' | flag);
27 mvwaddstr(widget->window, 0, 0, label->text);
28
29 GNTDEBUG;
30 }
31
32 static void
33 gnt_label_size_request(GntWidget *widget)
34 {
35 GntLabel *label = GNT_LABEL(widget);
36
37 gnt_util_get_text_bound(label->text,
38 &widget->priv.width, &widget->priv.height);
39 }
40
41 static void
42 gnt_label_class_init(GntLabelClass *klass)
43 {
44 parent_class = GNT_WIDGET_CLASS(klass);
45 parent_class->destroy = gnt_label_destroy;
46 parent_class->draw = gnt_label_draw;
47 parent_class->map = NULL;
48 parent_class->size_request = gnt_label_size_request;
49
50 GNTDEBUG;
51 }
52
53 static void
54 gnt_label_init(GTypeInstance *instance, gpointer class)
55 {
56 GntWidget *widget = GNT_WIDGET(instance);
57 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X);
58 widget->priv.minw = 3;
59 widget->priv.minh = 1;
60 GNTDEBUG;
61 }
62
63 /******************************************************************************
64 * GntLabel API
65 *****************************************************************************/
66 GType
67 gnt_label_get_gtype(void)
68 {
69 static GType type = 0;
70
71 if(type == 0)
72 {
73 static const GTypeInfo info = {
74 sizeof(GntLabelClass),
75 NULL, /* base_init */
76 NULL, /* base_finalize */
77 (GClassInitFunc)gnt_label_class_init,
78 NULL, /* class_finalize */
79 NULL, /* class_data */
80 sizeof(GntLabel),
81 0, /* n_preallocs */
82 gnt_label_init, /* instance_init */
83 NULL /* value_table */
84 };
85
86 type = g_type_register_static(GNT_TYPE_WIDGET,
87 "GntLabel",
88 &info, 0);
89 }
90
91 return type;
92 }
93
94 GntWidget *gnt_label_new(const char *text)
95 {
96 return gnt_label_new_with_format(text, 0);
97 }
98
99 GntWidget *gnt_label_new_with_format(const char *text, GntTextFormatFlags flags)
100 {
101 GntWidget *widget = g_object_new(GNT_TYPE_LABEL, NULL);
102 GntLabel *label = GNT_LABEL(widget);
103
104 label->text = gnt_util_onscreen_fit_string(text, -1);
105 label->flags = flags;
106 gnt_widget_set_take_focus(widget, FALSE);
107 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW);
108
109 return widget;
110 }
111
112 void gnt_label_set_text(GntLabel *label, const char *text)
113 {
114 g_free(label->text);
115 label->text = gnt_util_onscreen_fit_string(text, -1);
116
117 if (GNT_WIDGET(label)->window)
118 {
119 gnt_widget_hide(GNT_WIDGET(label));
120 gnt_label_size_request(GNT_WIDGET(label));
121 gnt_widget_draw(GNT_WIDGET(label));
122 }
123 }
124