Mercurial > pidgin
annotate finch/libgnt/gntlabel.c @ 21098:7e200a629109
explicit merge of '8f24e3576448fefbc861e06f1e8d5fe17db2e71a'
and '49d0219884ede2c6c571f2df73e29dffa86f54ad'
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Sun, 14 Oct 2007 02:13:14 +0000 |
parents | 44b4e8bd759b |
children | a14c663152cc |
rev | line source |
---|---|
17928
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
1 /** |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
3 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
4 * GNT is the legal property of its developers, whose names are too numerous |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
6 * source distribution. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
7 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
8 * This library is free software; you can redistribute it and/or modify |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
11 * (at your option) any later version. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
12 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
16 * GNU General Public License for more details. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
17 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
19681
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18873
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
17928
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
21 */ |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15817
diff
changeset
|
22 |
15817 | 23 #include "gntlabel.h" |
24 #include "gntutils.h" | |
25 | |
26 #include <string.h> | |
27 | |
28 enum | |
29 { | |
30 SIGS = 1, | |
31 }; | |
32 | |
33 static GntWidgetClass *parent_class = NULL; | |
34 | |
35 static void | |
36 gnt_label_destroy(GntWidget *widget) | |
37 { | |
38 GntLabel *label = GNT_LABEL(widget); | |
39 g_free(label->text); | |
40 } | |
41 | |
42 static void | |
43 gnt_label_draw(GntWidget *widget) | |
44 { | |
45 GntLabel *label = GNT_LABEL(widget); | |
46 chtype flag = gnt_text_format_flag_to_chtype(label->flags); | |
47 | |
48 wbkgdset(widget->window, '\0' | flag); | |
49 mvwaddstr(widget->window, 0, 0, label->text); | |
50 | |
51 GNTDEBUG; | |
52 } | |
53 | |
54 static void | |
55 gnt_label_size_request(GntWidget *widget) | |
56 { | |
57 GntLabel *label = GNT_LABEL(widget); | |
58 | |
59 gnt_util_get_text_bound(label->text, | |
60 &widget->priv.width, &widget->priv.height); | |
61 } | |
62 | |
63 static void | |
64 gnt_label_class_init(GntLabelClass *klass) | |
65 { | |
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; | |
71 | |
72 GNTDEBUG; | |
73 } | |
74 | |
75 static void | |
76 gnt_label_init(GTypeInstance *instance, gpointer class) | |
77 { | |
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; | |
83 } | |
84 | |
85 /****************************************************************************** | |
86 * GntLabel API | |
87 *****************************************************************************/ | |
88 GType | |
89 gnt_label_get_gtype(void) | |
90 { | |
91 static GType type = 0; | |
92 | |
93 if(type == 0) | |
94 { | |
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 */ | |
106 }; | |
107 | |
108 type = g_type_register_static(GNT_TYPE_WIDGET, | |
109 "GntLabel", | |
110 &info, 0); | |
111 } | |
112 | |
113 return type; | |
114 } | |
115 | |
116 GntWidget *gnt_label_new(const char *text) | |
117 { | |
118 return gnt_label_new_with_format(text, 0); | |
119 } | |
120 | |
121 GntWidget *gnt_label_new_with_format(const char *text, GntTextFormatFlags flags) | |
122 { | |
123 GntWidget *widget = g_object_new(GNT_TYPE_LABEL, NULL); | |
124 GntLabel *label = GNT_LABEL(widget); | |
125 | |
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); | |
130 | |
131 return widget; | |
132 } | |
133 | |
134 void gnt_label_set_text(GntLabel *label, const char *text) | |
135 { | |
136 g_free(label->text); | |
137 label->text = gnt_util_onscreen_fit_string(text, -1); | |
138 | |
139 if (GNT_WIDGET(label)->window) | |
140 { | |
18351
4f66226418e3
Erase the old text when the text in a label changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
141 werase(GNT_WIDGET(label)->window); |
15817 | 142 gnt_widget_draw(GNT_WIDGET(label)); |
143 } | |
144 } | |
145 |