Mercurial > pidgin.yaz
annotate console/libgnt/gnttextview.c @ 13897:eaaf73de9188
[gaim-migrate @ 16382]
I have added a sort of a taskbar, useful in showing the active windows.
I have also readjusted the blue color a little bit, since this is the
one I am using in a few places right now. And also getting rid of some
code-duplication.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sat, 01 Jul 2006 04:24:31 +0000 |
parents | a621329e8c85 |
children | 9309d27d780c |
rev | line source |
---|---|
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
1 #include "gnttextview.h" |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
2 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
3 enum |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
4 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
5 SIGS = 1, |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
6 }; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
7 |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
8 typedef struct |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
9 { |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
10 GntTextViewFlags flags; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
11 char *text; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
12 } GntTextSegment; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
13 |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
14 typedef struct |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
15 { |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
16 GList *segments; /* A list of GntTextSegments */ |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
17 int length; /* The current length of the line so far */ |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
18 } GntTextLine; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
19 |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
20 static GntWidgetClass *parent_class = NULL; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
21 static guint signals[SIGS] = { 0 }; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
22 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
23 static void |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
24 gnt_text_view_draw(GntWidget *widget) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
25 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
26 GntTextView *view = GNT_TEXT_VIEW(widget); |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
27 int i = 0; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
28 GList *lines; |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
29 |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
30 werase(widget->window); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
31 |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
32 for (i = 0, lines = view->list; i < widget->priv.height && lines; i++, lines = lines->next) |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
33 { |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
34 GList *iter; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
35 GntTextLine *line = lines->data; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
36 |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
37 wmove(widget->window, widget->priv.height - 1 - i, 0); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
38 |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
39 for (iter = line->segments; iter; iter = iter->next) |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
40 { |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
41 GntTextSegment *seg = iter->data; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
42 wattrset(widget->window, seg->flags); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
43 wprintw(widget->window, "%s", seg->text); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
44 if (!iter->next) |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
45 whline(widget->window, ' ' | seg->flags, widget->priv.width - line->length - 1); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
46 } |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
47 } |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
48 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
49 DEBUG; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
50 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
51 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
52 static void |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
53 gnt_text_view_size_request(GntWidget *widget) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
54 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
55 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_MAPPED)) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
56 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
57 gnt_widget_set_size(widget, 64, 24); |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
58 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
59 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
60 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
61 static void |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
62 gnt_text_view_map(GntWidget *widget) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
63 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
64 if (widget->priv.width == 0 || widget->priv.height == 0) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
65 gnt_widget_size_request(widget); |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
66 DEBUG; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
67 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
68 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
69 static gboolean |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
70 gnt_text_view_key_pressed(GntWidget *widget, const char *text) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
71 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
72 return FALSE; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
73 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
74 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
75 static void |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
76 free_text_segment(gpointer data, gpointer null) |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
77 { |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
78 GntTextSegment *seg = data; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
79 g_free(seg->text); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
80 g_free(seg); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
81 } |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
82 |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
83 static void |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
84 free_text_line(gpointer data, gpointer null) |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
85 { |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
86 GntTextLine *line = data; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
87 g_list_foreach(line->segments, free_text_segment, NULL); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
88 g_list_free(line->segments); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
89 g_free(line); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
90 } |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
91 |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
92 static void |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
93 gnt_text_view_destroy(GntWidget *widget) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
94 { |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
95 GntTextView *view = GNT_TEXT_VIEW(widget); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
96 g_list_foreach(view->list, free_text_line, NULL); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
97 g_list_free(view->list); |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
98 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
99 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
100 static void |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
101 gnt_text_view_class_init(GntTextViewClass *klass) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
102 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
103 parent_class = GNT_WIDGET_CLASS(klass); |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
104 parent_class->destroy = gnt_text_view_destroy; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
105 parent_class->draw = gnt_text_view_draw; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
106 parent_class->map = gnt_text_view_map; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
107 parent_class->size_request = gnt_text_view_size_request; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
108 parent_class->key_pressed = gnt_text_view_key_pressed; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
109 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
110 DEBUG; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
111 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
112 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
113 static void |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
114 gnt_text_view_init(GTypeInstance *instance, gpointer class) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
115 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
116 DEBUG; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
117 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
118 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
119 /****************************************************************************** |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
120 * GntTextView API |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
121 *****************************************************************************/ |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
122 GType |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
123 gnt_text_view_get_gtype(void) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
124 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
125 static GType type = 0; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
126 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
127 if(type == 0) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
128 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
129 static const GTypeInfo info = { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
130 sizeof(GntTextViewClass), |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
131 NULL, /* base_init */ |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
132 NULL, /* base_finalize */ |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
133 (GClassInitFunc)gnt_text_view_class_init, |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
134 NULL, /* class_finalize */ |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
135 NULL, /* class_data */ |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
136 sizeof(GntTextView), |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
137 0, /* n_preallocs */ |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
138 gnt_text_view_init, /* instance_init */ |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
139 }; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
140 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
141 type = g_type_register_static(GNT_TYPE_WIDGET, |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
142 "GntTextView", |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
143 &info, 0); |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
144 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
145 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
146 return type; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
147 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
148 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
149 GntWidget *gnt_text_view_new() |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
150 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
151 GntWidget *widget = g_object_new(GNT_TYPE_TEXTVIEW, NULL); |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
152 GntTextView *view = GNT_TEXT_VIEW(widget); |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
153 GntTextLine *line = g_new0(GntTextLine, 1); |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
154 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
155 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER); |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
156 |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
157 view->list = g_list_append(view->list, line); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
158 |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
159 return widget; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
160 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
161 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
162 void gnt_text_view_append_text_with_flags(GntTextView *view, const char *text, GntTextViewFlags flags) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
163 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
164 GntWidget *widget = GNT_WIDGET(view); |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
165 int fl = 0; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
166 char **split; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
167 int i; |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
168 GList *list = view->list; |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
169 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
170 if (text == NULL || *text == '\0') |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
171 return; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
172 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
173 if (flags & GNT_TEXT_FLAG_BOLD) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
174 fl |= A_BOLD; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
175 if (flags & GNT_TEXT_FLAG_UNDERLINE) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
176 fl |= A_UNDERLINE; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
177 if (flags & GNT_TEXT_FLAG_BLINK) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
178 fl |= A_BLINK; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
179 |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
180 if (flags & GNT_TEXT_FLAG_DIM) |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
181 fl |= (A_DIM | COLOR_PAIR(GNT_COLOR_DISABLED)); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
182 else if (flags & GNT_TEXT_FLAG_HIGHLIGHT) |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
183 fl |= (A_DIM | COLOR_PAIR(GNT_COLOR_HIGHLIGHT)); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
184 else |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
185 fl |= COLOR_PAIR(GNT_COLOR_NORMAL); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
186 |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
187 view->list = g_list_first(view->list); |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
188 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
189 split = g_strsplit(text, "\n", 0); |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
190 for (i = 0; split[i]; i++) |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
191 { |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
192 GntTextLine *line = view->list->data; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
193 int len = g_utf8_strlen(split[i], -1); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
194 char *iter = split[i]; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
195 int prev = 0; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
196 |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
197 while (iter && *iter) |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
198 { |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
199 GntTextSegment *seg = g_new0(GntTextSegment, 1); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
200 seg->flags = fl; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
201 seg->text = g_new0(char, len); /* XXX: MUST be improved */ |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
202 g_utf8_strncpy(seg->text, iter, widget->priv.width - line->length - 1); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
203 line->segments = g_list_append(line->segments, seg); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
204 |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
205 prev = g_utf8_strlen(seg->text, -1); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
206 line->length += prev; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
207 iter = g_utf8_offset_to_pointer(iter, prev); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
208 if (line->length >= widget->priv.width - 1 && *iter) |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
209 { |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
210 line = g_new0(GntTextLine, 1); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
211 view->list = g_list_prepend(g_list_first(view->list), line); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
212 } |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
213 /*len -= prev;*/ |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
214 } |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
215 } |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
216 |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
217 g_strfreev(split); |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
218 view->list = list; |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
219 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
220 gnt_widget_draw(widget); |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
221 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
222 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
223 void gnt_text_view_scroll(GntTextView *view, int scroll) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
224 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
225 if (scroll == 0) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
226 { |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
227 view->list = g_list_first(view->list); |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
228 } |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
229 else if (scroll > 0) |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
230 { |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
231 GList *list = g_list_nth_prev(view->list, scroll); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
232 if (list == NULL) |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
233 list = g_list_first(view->list); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
234 view->list = list; |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
235 } |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
236 else if (scroll < 0) |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
237 { |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
238 GList *list = g_list_nth(view->list, -scroll); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
239 if (list == NULL) |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
240 list = g_list_last(view->list); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
241 view->list = list; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
242 } |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
243 |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
244 gnt_widget_draw(GNT_WIDGET(view)); |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
245 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
246 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
247 void gnt_text_view_next_line(GntTextView *view) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
248 { |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
249 GntTextLine *line = g_new0(GntTextLine, 1); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
250 GList *list = view->list; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
251 |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
252 view->list = g_list_prepend(g_list_first(view->list), line); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
253 view->list = list; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
254 gnt_widget_draw(GNT_WIDGET(view)); |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
255 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
256 |