Mercurial > pidgin
annotate finch/libgnt/gntlabel.c @ 27443:8983eefa62c5
Remove an unused variable
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Fri, 10 Jul 2009 01:31:29 +0000 |
parents | 6e8fc8272d3e |
children | a18f421696dc |
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 { | |
21282
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
30 PROP_0, |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
31 PROP_TEXT, |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
32 PROP_TEXT_FLAG |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
33 }; |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
34 |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
35 enum |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
36 { |
15817 | 37 SIGS = 1, |
38 }; | |
39 | |
40 static GntWidgetClass *parent_class = NULL; | |
41 | |
42 static void | |
43 gnt_label_destroy(GntWidget *widget) | |
44 { | |
45 GntLabel *label = GNT_LABEL(widget); | |
46 g_free(label->text); | |
47 } | |
48 | |
49 static void | |
50 gnt_label_draw(GntWidget *widget) | |
51 { | |
52 GntLabel *label = GNT_LABEL(widget); | |
53 chtype flag = gnt_text_format_flag_to_chtype(label->flags); | |
54 | |
55 wbkgdset(widget->window, '\0' | flag); | |
56 mvwaddstr(widget->window, 0, 0, label->text); | |
57 | |
58 GNTDEBUG; | |
59 } | |
60 | |
61 static void | |
62 gnt_label_size_request(GntWidget *widget) | |
63 { | |
64 GntLabel *label = GNT_LABEL(widget); | |
65 | |
66 gnt_util_get_text_bound(label->text, | |
67 &widget->priv.width, &widget->priv.height); | |
68 } | |
69 | |
70 static void | |
21282
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
71 gnt_label_set_property(GObject *obj, guint prop_id, const GValue *value, |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
72 GParamSpec *spec) |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
73 { |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
74 GntLabel *label = GNT_LABEL(obj); |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
75 switch (prop_id) { |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
76 case PROP_TEXT: |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
77 g_free(label->text); |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
78 label->text = gnt_util_onscreen_fit_string(g_value_get_string(value), -1); |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
79 break; |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
80 case PROP_TEXT_FLAG: |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
81 label->flags = g_value_get_int(value); |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
82 break; |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
83 default: |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
84 g_return_if_reached(); |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
85 break; |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
86 } |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
87 } |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
88 |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
89 static void |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
90 gnt_label_get_property(GObject *obj, guint prop_id, GValue *value, |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
91 GParamSpec *spec) |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
92 { |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
93 GntLabel *label = GNT_LABEL(obj); |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
94 switch (prop_id) { |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
95 case PROP_TEXT: |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
96 g_value_set_string(value, label->text); |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
97 break; |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
98 case PROP_TEXT_FLAG: |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
99 g_value_set_int(value, label->flags); |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
100 break; |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
101 default: |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
102 break; |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
103 } |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
104 } |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
105 |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
106 static void |
15817 | 107 gnt_label_class_init(GntLabelClass *klass) |
108 { | |
21282
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
109 GObjectClass *gclass = G_OBJECT_CLASS(klass); |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
110 |
15817 | 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; | |
116 | |
21282
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
117 gclass->set_property = gnt_label_set_property; |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
118 gclass->get_property = gnt_label_get_property; |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
119 |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
120 g_object_class_install_property(gclass, |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
121 PROP_TEXT, |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
122 g_param_spec_string("text", "Text", |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
123 "The text for the label.", |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
124 NULL, |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
125 G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
126 ) |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
127 ); |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
128 |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
129 g_object_class_install_property(gclass, |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
130 PROP_TEXT_FLAG, |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
131 g_param_spec_int("text-flag", "Text flag", |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
132 "Text attribute to use when displaying the text in the label.", |
21489
6e8fc8272d3e
Fix the max value for gntlabel's text-flag property
Richard Nelson <wabz@pidgin.im>
parents:
21282
diff
changeset
|
133 GNT_TEXT_FLAG_NORMAL, |
6e8fc8272d3e
Fix the max value for gntlabel's text-flag property
Richard Nelson <wabz@pidgin.im>
parents:
21282
diff
changeset
|
134 GNT_TEXT_FLAG_NORMAL|GNT_TEXT_FLAG_BOLD|GNT_TEXT_FLAG_UNDERLINE| |
6e8fc8272d3e
Fix the max value for gntlabel's text-flag property
Richard Nelson <wabz@pidgin.im>
parents:
21282
diff
changeset
|
135 GNT_TEXT_FLAG_BLINK|GNT_TEXT_FLAG_DIM|GNT_TEXT_FLAG_HIGHLIGHT, |
6e8fc8272d3e
Fix the max value for gntlabel's text-flag property
Richard Nelson <wabz@pidgin.im>
parents:
21282
diff
changeset
|
136 GNT_TEXT_FLAG_NORMAL, |
21282
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
137 G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
138 ) |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
139 ); |
15817 | 140 GNTDEBUG; |
141 } | |
142 | |
143 static void | |
144 gnt_label_init(GTypeInstance *instance, gpointer class) | |
145 { | |
146 GntWidget *widget = GNT_WIDGET(instance); | |
21282
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
147 gnt_widget_set_take_focus(widget, FALSE); |
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
148 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); |
15817 | 149 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X); |
150 widget->priv.minw = 3; | |
151 widget->priv.minh = 1; | |
152 GNTDEBUG; | |
153 } | |
154 | |
155 /****************************************************************************** | |
156 * GntLabel API | |
157 *****************************************************************************/ | |
158 GType | |
159 gnt_label_get_gtype(void) | |
160 { | |
161 static GType type = 0; | |
162 | |
163 if(type == 0) | |
164 { | |
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 */ | |
172 sizeof(GntLabel), | |
173 0, /* n_preallocs */ | |
174 gnt_label_init, /* instance_init */ | |
175 NULL /* value_table */ | |
176 }; | |
177 | |
178 type = g_type_register_static(GNT_TYPE_WIDGET, | |
179 "GntLabel", | |
180 &info, 0); | |
181 } | |
182 | |
183 return type; | |
184 } | |
185 | |
186 GntWidget *gnt_label_new(const char *text) | |
187 { | |
188 return gnt_label_new_with_format(text, 0); | |
189 } | |
190 | |
191 GntWidget *gnt_label_new_with_format(const char *text, GntTextFormatFlags flags) | |
192 { | |
21282
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
193 GntWidget *widget = g_object_new(GNT_TYPE_LABEL, "text-flag", flags, "text", text, NULL); |
15817 | 194 return widget; |
195 } | |
196 | |
197 void gnt_label_set_text(GntLabel *label, const char *text) | |
198 { | |
21282
a14c663152cc
Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
199 g_object_set(label, "text", text, NULL); |
15817 | 200 |
201 if (GNT_WIDGET(label)->window) | |
202 { | |
18351
4f66226418e3
Erase the old text when the text in a label changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
203 werase(GNT_WIDGET(label)->window); |
15817 | 204 gnt_widget_draw(GNT_WIDGET(label)); |
205 } | |
206 } | |
207 |