Mercurial > pidgin.yaz
comparison console/libgnt/gntlabel.c @ 13850:0e1e59770cb0
[gaim-migrate @ 16308]
This is my first commit here. So don't yell at me if things get borked.
Also, I haven't looked at the auto-thingies yet. So don't puke at the
Makefiles.
Files in console/libgnt/ are for the 'Gaim/GObjectified Ncurses Toolkit'
library. Files in console/ uses libgaim and libgnt. Currently, only the
buddylist-ui is 'functional', ie. the buddy-list updates when someone
logs on or logs off. It still needs a lot of work.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Thu, 22 Jun 2006 08:33:54 +0000 |
parents | |
children | c1e3f7c75c3f |
comparison
equal
deleted
inserted
replaced
13849:8d1c55309e3c | 13850:0e1e59770cb0 |
---|---|
1 #include "gntlabel.h" | |
2 | |
3 #include <string.h> | |
4 | |
5 enum | |
6 { | |
7 SIGS = 1, | |
8 }; | |
9 | |
10 static GntWidgetClass *parent_class = NULL; | |
11 static guint signals[SIGS] = { 0 }; | |
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 | |
25 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
26 mvwprintw(widget->window, 0, 0, label->text); | |
27 wrefresh(widget->window); | |
28 | |
29 DEBUG; | |
30 } | |
31 | |
32 static void | |
33 gnt_label_size_request(GntWidget *widget) | |
34 { | |
35 GntLabel *label = GNT_LABEL(widget); | |
36 char *s = label->text, *last = s; | |
37 int count = 1; | |
38 int max = 0; | |
39 | |
40 /* XXX: ew ... everyone look away */ | |
41 while (*s) | |
42 { | |
43 if (*s == '\n' || *s == '\r') | |
44 { | |
45 count++; | |
46 if (max < s - last + 1) | |
47 max = s - last + 1; | |
48 last = s + 1; | |
49 } | |
50 s++; | |
51 } | |
52 if (max < s - last + 1) | |
53 max = s - last + 1; | |
54 widget->priv.height = count; | |
55 | |
56 widget->priv.width = max; | |
57 } | |
58 | |
59 static void | |
60 gnt_label_class_init(GntWidgetClass *klass) | |
61 { | |
62 GObjectClass *obj_class = G_OBJECT_CLASS(klass); | |
63 | |
64 parent_class = GNT_WIDGET_CLASS(klass); | |
65 parent_class->destroy = gnt_label_destroy; | |
66 parent_class->draw = gnt_label_draw; | |
67 parent_class->map = NULL; | |
68 parent_class->size_request = gnt_label_size_request; | |
69 | |
70 DEBUG; | |
71 } | |
72 | |
73 static void | |
74 gnt_label_init(GTypeInstance *instance, gpointer class) | |
75 { | |
76 DEBUG; | |
77 } | |
78 | |
79 /****************************************************************************** | |
80 * GntLabel API | |
81 *****************************************************************************/ | |
82 GType | |
83 gnt_label_get_gtype(void) | |
84 { | |
85 static GType type = 0; | |
86 | |
87 if(type == 0) | |
88 { | |
89 static const GTypeInfo info = { | |
90 sizeof(GntLabelClass), | |
91 NULL, /* base_init */ | |
92 NULL, /* base_finalize */ | |
93 (GClassInitFunc)gnt_label_class_init, | |
94 NULL, /* class_finalize */ | |
95 NULL, /* class_data */ | |
96 sizeof(GntLabel), | |
97 0, /* n_preallocs */ | |
98 gnt_label_init, /* instance_init */ | |
99 }; | |
100 | |
101 type = g_type_register_static(GNT_TYPE_WIDGET, | |
102 "GntLabel", | |
103 &info, 0); | |
104 } | |
105 | |
106 return type; | |
107 } | |
108 | |
109 GntWidget *gnt_label_new(const char *text) | |
110 { | |
111 GntWidget *widget = g_object_new(GNT_TYPE_LABEL, NULL); | |
112 GntLabel *label = GNT_LABEL(widget); | |
113 | |
114 label->text = g_strdup(text); | |
115 gnt_widget_set_take_focus(widget, FALSE); | |
116 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); | |
117 | |
118 return widget; | |
119 } | |
120 |