annotate finch/libgnt/gntlabel.c @ 28860:49f881831eb9

*** Plucked rev f39cd1fed08fe5f5e3165a087fcc36ed984a6eee (f05c54b03e6bbfdbff38c01697fbd353a969e05e): oscar: Avoid a printf(\"%s\", NULL) crash when creating an AIM room. Both of these strings appear to be optional in parseinfo_create(), so we can't rely on their being non-NULL.
author Daniel Atallah <daniel.atallah@gmail.com>
date Thu, 07 Jan 2010 23:44:05 +0000
parents a18f421696dc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
28604
a18f421696dc Fix showing umlauts etc. on non-utf8 locales.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21489
diff changeset
23 #include "gntinternal.h"
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
24 #include "gntlabel.h"
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25 #include "gntutils.h"
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27 #include <string.h>
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
28
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29 enum
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30 {
21282
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
31 PROP_0,
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
32 PROP_TEXT,
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
33 PROP_TEXT_FLAG
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
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
36 enum
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
37 {
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
38 SIGS = 1,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39 };
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
41 static GntWidgetClass *parent_class = NULL;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
43 static void
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
44 gnt_label_destroy(GntWidget *widget)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
45 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
46 GntLabel *label = GNT_LABEL(widget);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47 g_free(label->text);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
48 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
49
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
50 static void
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
51 gnt_label_draw(GntWidget *widget)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
52 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53 GntLabel *label = GNT_LABEL(widget);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54 chtype flag = gnt_text_format_flag_to_chtype(label->flags);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56 wbkgdset(widget->window, '\0' | flag);
28604
a18f421696dc Fix showing umlauts etc. on non-utf8 locales.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21489
diff changeset
57 mvwaddstr(widget->window, 0, 0, C_(label->text));
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
59 GNTDEBUG;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
60 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
61
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
62 static void
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63 gnt_label_size_request(GntWidget *widget)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
64 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65 GntLabel *label = GNT_LABEL(widget);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
66
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
67 gnt_util_get_text_bound(label->text,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
68 &widget->priv.width, &widget->priv.height);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
69 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
70
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
71 static void
21282
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
72 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
73 GParamSpec *spec)
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
74 {
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
75 GntLabel *label = GNT_LABEL(obj);
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
76 switch (prop_id) {
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
77 case PROP_TEXT:
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
78 g_free(label->text);
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
79 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
80 break;
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
81 case PROP_TEXT_FLAG:
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
82 label->flags = g_value_get_int(value);
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
83 break;
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
84 default:
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
85 g_return_if_reached();
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
86 break;
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
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
90 static void
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
91 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
92 GParamSpec *spec)
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
93 {
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
94 GntLabel *label = GNT_LABEL(obj);
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
95 switch (prop_id) {
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
96 case PROP_TEXT:
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
97 g_value_set_string(value, label->text);
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
98 break;
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
99 case PROP_TEXT_FLAG:
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
100 g_value_set_int(value, label->flags);
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
101 break;
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
102 default:
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
103 break;
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
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
107 static void
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
108 gnt_label_class_init(GntLabelClass *klass)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
109 {
21282
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
110 GObjectClass *gclass = G_OBJECT_CLASS(klass);
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
111
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
112 parent_class = GNT_WIDGET_CLASS(klass);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
113 parent_class->destroy = gnt_label_destroy;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
114 parent_class->draw = gnt_label_draw;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
115 parent_class->map = NULL;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
116 parent_class->size_request = gnt_label_size_request;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
117
21282
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
118 gclass->set_property = gnt_label_set_property;
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
119 gclass->get_property = gnt_label_get_property;
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
120
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
121 g_object_class_install_property(gclass,
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
122 PROP_TEXT,
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
123 g_param_spec_string("text", "Text",
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
124 "The text for the label.",
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
125 NULL,
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
126 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
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
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
130 g_object_class_install_property(gclass,
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
131 PROP_TEXT_FLAG,
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
132 g_param_spec_int("text-flag", "Text flag",
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
133 "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
134 GNT_TEXT_FLAG_NORMAL,
6e8fc8272d3e Fix the max value for gntlabel's text-flag property
Richard Nelson <wabz@pidgin.im>
parents: 21282
diff changeset
135 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
136 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
137 GNT_TEXT_FLAG_NORMAL,
21282
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
138 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
139 )
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
140 );
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
141 GNTDEBUG;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
142 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
143
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
144 static void
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
145 gnt_label_init(GTypeInstance *instance, gpointer class)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
146 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
147 GntWidget *widget = GNT_WIDGET(instance);
21282
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
148 gnt_widget_set_take_focus(widget, FALSE);
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
149 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
150 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
151 widget->priv.minw = 3;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
152 widget->priv.minh = 1;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
153 GNTDEBUG;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
154 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
155
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
156 /******************************************************************************
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
157 * GntLabel API
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
158 *****************************************************************************/
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
159 GType
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
160 gnt_label_get_gtype(void)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
161 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
162 static GType type = 0;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
163
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
164 if(type == 0)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
165 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
166 static const GTypeInfo info = {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
167 sizeof(GntLabelClass),
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
168 NULL, /* base_init */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
169 NULL, /* base_finalize */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
170 (GClassInitFunc)gnt_label_class_init,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
171 NULL, /* class_finalize */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
172 NULL, /* class_data */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
173 sizeof(GntLabel),
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
174 0, /* n_preallocs */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
175 gnt_label_init, /* instance_init */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
176 NULL /* value_table */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
177 };
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
178
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
179 type = g_type_register_static(GNT_TYPE_WIDGET,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
180 "GntLabel",
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
181 &info, 0);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
182 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
183
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
184 return type;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
185 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
186
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
187 GntWidget *gnt_label_new(const char *text)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
188 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
189 return gnt_label_new_with_format(text, 0);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
190 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
191
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
192 GntWidget *gnt_label_new_with_format(const char *text, GntTextFormatFlags flags)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
193 {
21282
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
194 GntWidget *widget = g_object_new(GNT_TYPE_LABEL, "text-flag", flags, "text", text, NULL);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
195 return widget;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
196 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
197
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
198 void gnt_label_set_text(GntLabel *label, const char *text)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
199 {
21282
a14c663152cc Use gobject properties for labels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
200 g_object_set(label, "text", text, NULL);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
201
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
202 if (GNT_WIDGET(label)->window)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
203 {
18351
4f66226418e3 Erase the old text when the text in a label changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17928
diff changeset
204 werase(GNT_WIDGET(label)->window);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
205 gnt_widget_draw(GNT_WIDGET(label));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
206 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
207 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
208