Mercurial > pidgin
annotate finch/libgnt/gntlabel.c @ 19532:e2411ff184ba
Add Resiak as CPW too
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Wed, 29 Aug 2007 19:59:07 +0000 |
parents | 7066896f6628 |
children | 44b4e8bd759b |
rev | line source |
---|---|
18049
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
1 /** |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
3 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
4 * GNT is the legal property of its developers, whose names are too numerous |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
6 * source distribution. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
7 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
8 * This library is free software; you can redistribute it and/or modify |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
11 * (at your option) any later version. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
12 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
16 * GNU General Public License for more details. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
17 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
21 */ |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
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:
18049
diff
changeset
|
141 werase(GNT_WIDGET(label)->window); |
15817 | 142 gnt_widget_draw(GNT_WIDGET(label)); |
143 } | |
144 } | |
145 |