Mercurial > pidgin
annotate console/libgnt/gnttextview.c @ 14393:81932c1ec6cf
[gaim-migrate @ 17101]
This shouldn't be necessary, but I don't see how it's happening just yet
committer: Tailor Script <tailor@pidgin.im>
author | Ethan Blanton <elb@pidgin.im> |
---|---|
date | Thu, 31 Aug 2006 21:50:55 +0000 |
parents | 5f3058c7a7df |
children | 70f52ff1caec |
rev | line source |
---|---|
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
1 #include "gnttextview.h" |
14311
fda9dc44807d
[gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14222
diff
changeset
|
2 #include "gntutils.h" |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
3 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
4 enum |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
5 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
6 SIGS = 1, |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
7 }; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
8 |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
9 typedef struct |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
10 { |
14371
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
11 GntTextFormatFlags tvflag; |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
12 chtype flags; |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
13 int start; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
14 int end; /* This is the next byte of the last character of this segment */ |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
15 } GntTextSegment; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
16 |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
17 typedef struct |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
18 { |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
19 GList *segments; /* A list of GntTextSegments */ |
14311
fda9dc44807d
[gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14222
diff
changeset
|
20 int length; /* The current length of the line so far (ie. onscreen width) */ |
14371
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
21 gboolean soft; /* TRUE if it's an overflow from prev. line */ |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
22 } GntTextLine; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
23 |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
24 static GntWidgetClass *parent_class = NULL; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
25 static guint signals[SIGS] = { 0 }; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
26 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
27 static void |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
28 gnt_text_view_draw(GntWidget *widget) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
29 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
30 GntTextView *view = GNT_TEXT_VIEW(widget); |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
31 int i = 0; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
32 GList *lines; |
14131
db2311999862
[gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14123
diff
changeset
|
33 int rows, scrcol; |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
34 |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
35 werase(widget->window); |
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 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
|
38 { |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
39 GList *iter; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
40 GntTextLine *line = lines->data; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
41 |
14222
8c13a650cef5
[gaim-migrate @ 16903]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14221
diff
changeset
|
42 wmove(widget->window, widget->priv.height - 1 - i, 0); |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
43 |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
44 for (iter = line->segments; iter; iter = iter->next) |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
45 { |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
46 GntTextSegment *seg = iter->data; |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
47 char *end = view->string->str + seg->end; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
48 char back = *end; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
49 *end = '\0'; |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
50 wattrset(widget->window, seg->flags); |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
51 wprintw(widget->window, "%s", (view->string->str + seg->start)); |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
52 if (!iter->next) |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
53 whline(widget->window, ' ' | seg->flags, widget->priv.width - line->length - 1); |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
54 *end = back; |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
55 } |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
56 } |
14123
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
57 |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
58 scrcol = widget->priv.width - 1; |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
59 rows = widget->priv.height - 2; |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
60 if (rows > 0) |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
61 { |
14131
db2311999862
[gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14123
diff
changeset
|
62 int total = g_list_length(g_list_first(view->list)); |
db2311999862
[gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14123
diff
changeset
|
63 int showing, position, up, down; |
14123
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
64 |
14131
db2311999862
[gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14123
diff
changeset
|
65 showing = rows * rows / total + 1; |
14123
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
66 showing = MIN(rows, showing); |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
67 |
14131
db2311999862
[gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14123
diff
changeset
|
68 total -= rows; |
db2311999862
[gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14123
diff
changeset
|
69 up = g_list_length(lines); |
db2311999862
[gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14123
diff
changeset
|
70 down = total - up; |
db2311999862
[gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14123
diff
changeset
|
71 |
db2311999862
[gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14123
diff
changeset
|
72 position = (rows - showing) * up / MAX(1, up + down); |
14123
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
73 position = MAX((lines != NULL), position); |
14107
c0ee28af3ca2
[gaim-migrate @ 16741]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14032
diff
changeset
|
74 |
14123
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
75 if (showing + position > rows) |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
76 position = rows - showing; |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
77 |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
78 if (showing + position == rows && view->list && view->list->prev) |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
79 position = MAX(1, rows - 1 - showing); |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
80 else if (showing + position < rows && view->list && !view->list->prev) |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
81 position = rows - showing; |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
82 |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
83 mvwvline(widget->window, position + 1, scrcol, |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
84 ACS_CKBOARD | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D), showing); |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
85 } |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
86 |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
87 mvwaddch(widget->window, 0, scrcol, |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
88 (lines ? ACS_UARROW : ' ') | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D)); |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
89 mvwaddch(widget->window, widget->priv.height - 1, scrcol, |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
90 ((view->list && view->list->prev) ? ACS_DARROW : ' ') | |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
91 COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D)); |
14107
c0ee28af3ca2
[gaim-migrate @ 16741]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14032
diff
changeset
|
92 |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
93 DEBUG; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
94 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
95 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
96 static void |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
97 gnt_text_view_size_request(GntWidget *widget) |
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 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_MAPPED)) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
100 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
101 gnt_widget_set_size(widget, 64, 24); |
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 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
104 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
105 static void |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
106 gnt_text_view_map(GntWidget *widget) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
107 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
108 if (widget->priv.width == 0 || widget->priv.height == 0) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
109 gnt_widget_size_request(widget); |
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 gboolean |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
114 gnt_text_view_key_pressed(GntWidget *widget, const char *text) |
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 return FALSE; |
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 static void |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
120 free_text_segment(gpointer data, gpointer null) |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
121 { |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
122 GntTextSegment *seg = data; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
123 g_free(seg); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
124 } |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
125 |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
126 static void |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
127 free_text_line(gpointer data, gpointer null) |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
128 { |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
129 GntTextLine *line = data; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
130 g_list_foreach(line->segments, free_text_segment, NULL); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
131 g_list_free(line->segments); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
132 g_free(line); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
133 } |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
134 |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
135 static void |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
136 gnt_text_view_destroy(GntWidget *widget) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
137 { |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
138 GntTextView *view = GNT_TEXT_VIEW(widget); |
14030
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
139 view->list = g_list_first(view->list); |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
140 g_list_foreach(view->list, free_text_line, NULL); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
141 g_list_free(view->list); |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
142 g_string_free(view->string, TRUE); |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
143 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
144 |
14343
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
145 static gboolean |
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
146 gnt_text_view_clicked(GntWidget *widget, GntMouseEvent event, int x, int y) |
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
147 { |
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
148 if (event == GNT_MOUSE_SCROLL_UP) { |
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
149 gnt_text_view_scroll(GNT_TEXT_VIEW(widget), -1); |
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
150 } else if (event == GNT_MOUSE_SCROLL_DOWN) { |
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
151 gnt_text_view_scroll(GNT_TEXT_VIEW(widget), 1); |
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
152 } else |
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
153 return FALSE; |
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
154 return TRUE; |
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
155 } |
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
156 |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
157 static void |
14371
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
158 gnt_text_view_reflow(GntTextView *view) |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
159 { |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
160 /* This is pretty ugly, and inefficient. Someone do something about it. */ |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
161 GntTextLine *line; |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
162 GList *back, *iter, *list; |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
163 GString *string; |
14371
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
164 int pos = 0; |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
165 |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
166 list = view->list; |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
167 while (list->prev) { |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
168 line = list->data; |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
169 if (!line->soft) |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
170 pos++; |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
171 list = list->prev; |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
172 } |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
173 |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
174 back = g_list_last(view->list); |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
175 view->list = NULL; |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
176 |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
177 string = view->string; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
178 view->string = NULL; |
14371
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
179 gnt_text_view_clear(view); |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
180 |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
181 view->string = g_string_set_size(view->string, string->len); |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
182 GNT_WIDGET_SET_FLAGS(GNT_WIDGET(view), GNT_WIDGET_DRAWING); |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
183 |
14371
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
184 for (; back; back = back->prev) { |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
185 line = back->data; |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
186 if (back->next && !line->soft) { |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
187 GList *llist = g_list_first(view->list); |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
188 llist = g_list_prepend(llist, g_new0(GntTextLine, 1)); |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
189 } |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
190 |
14371
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
191 for (iter = line->segments; iter; iter = iter->next) { |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
192 GntTextSegment *seg = iter->data; |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
193 char *start = string->str + seg->start; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
194 char *end = string->str + seg->end; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
195 char back = *end; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
196 *end = '\0'; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
197 gnt_text_view_append_text_with_flags(view, start, seg->tvflag); |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
198 *end = back; |
14371
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
199 } |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
200 free_text_line(line, NULL); |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
201 } |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
202 g_list_free(list); |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
203 |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
204 list = view->list = g_list_first(view->list); |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
205 while (pos--) { |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
206 while (((GntTextLine*)list->data)->soft) |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
207 list = list->next; |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
208 list = list->next; |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
209 } |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
210 view->list = list; |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
211 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(view), GNT_WIDGET_DRAWING); |
14371
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
212 gnt_widget_draw(GNT_WIDGET(view)); |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
213 g_string_free(string, TRUE); |
14371
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
214 } |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
215 |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
216 static void |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
217 gnt_text_view_size_changed(GntWidget *widget, int w, int h) |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
218 { |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
219 if (w != widget->priv.width) { |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
220 gnt_text_view_reflow(GNT_TEXT_VIEW(widget)); |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
221 } |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
222 } |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
223 |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
224 static void |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
225 gnt_text_view_class_init(GntTextViewClass *klass) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
226 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
227 parent_class = GNT_WIDGET_CLASS(klass); |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
228 parent_class->destroy = gnt_text_view_destroy; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
229 parent_class->draw = gnt_text_view_draw; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
230 parent_class->map = gnt_text_view_map; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
231 parent_class->size_request = gnt_text_view_size_request; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
232 parent_class->key_pressed = gnt_text_view_key_pressed; |
14343
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
233 parent_class->clicked = gnt_text_view_clicked; |
14371
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
234 parent_class->size_changed = gnt_text_view_size_changed; |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
235 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
236 DEBUG; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
237 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
238 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
239 static void |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
240 gnt_text_view_init(GTypeInstance *instance, gpointer class) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
241 { |
13943
25be562aaca8
[gaim-migrate @ 16480]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13931
diff
changeset
|
242 GntWidget *widget = GNT_WIDGET(instance); |
25be562aaca8
[gaim-migrate @ 16480]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13931
diff
changeset
|
243 |
14371
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
244 GNT_WIDGET_SET_FLAGS(GNT_WIDGET(instance), GNT_WIDGET_GROW_Y | GNT_WIDGET_GROW_X); |
13943
25be562aaca8
[gaim-migrate @ 16480]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13931
diff
changeset
|
245 |
25be562aaca8
[gaim-migrate @ 16480]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13931
diff
changeset
|
246 widget->priv.minw = 5; |
14123
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
247 widget->priv.minh = 2; |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
248 DEBUG; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
249 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
250 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
251 /****************************************************************************** |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
252 * GntTextView API |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
253 *****************************************************************************/ |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
254 GType |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
255 gnt_text_view_get_gtype(void) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
256 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
257 static GType type = 0; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
258 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
259 if(type == 0) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
260 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
261 static const GTypeInfo info = { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
262 sizeof(GntTextViewClass), |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
263 NULL, /* base_init */ |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
264 NULL, /* base_finalize */ |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
265 (GClassInitFunc)gnt_text_view_class_init, |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
266 NULL, /* class_finalize */ |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
267 NULL, /* class_data */ |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
268 sizeof(GntTextView), |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
269 0, /* n_preallocs */ |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
270 gnt_text_view_init, /* instance_init */ |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
271 }; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
272 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
273 type = g_type_register_static(GNT_TYPE_WIDGET, |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
274 "GntTextView", |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
275 &info, 0); |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
276 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
277 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
278 return type; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
279 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
280 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
281 GntWidget *gnt_text_view_new() |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
282 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
283 GntWidget *widget = g_object_new(GNT_TYPE_TEXTVIEW, NULL); |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
284 GntTextView *view = GNT_TEXT_VIEW(widget); |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
285 GntTextLine *line = g_new0(GntTextLine, 1); |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
286 |
13927
9309d27d780c
[gaim-migrate @ 16447]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
287 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
288 |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
289 view->string = g_string_new(NULL); |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
290 view->list = g_list_append(view->list, line); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
291 |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
292 return widget; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
293 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
294 |
13931
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
295 void gnt_text_view_append_text_with_flags(GntTextView *view, const char *text, GntTextFormatFlags flags) |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
296 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
297 GntWidget *widget = GNT_WIDGET(view); |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
298 int fl = 0; |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
299 const char *start, *end; |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
300 GList *list = view->list; |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
301 GntTextLine *line; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
302 int len; |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
303 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
304 if (text == NULL || *text == '\0') |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
305 return; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
306 |
13952
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
307 fl = gnt_text_format_flag_to_chtype(flags); |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
308 |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
309 len = view->string->len; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
310 g_string_append(view->string, text); |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
311 |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
312 view->list = g_list_first(view->list); |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
313 |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
314 start = end = view->string->str + len; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
315 |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
316 while (*start) { |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
317 GntTextSegment *seg; |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
318 |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
319 if (*end == '\n' || *end == '\r') { |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
320 end++; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
321 start = end; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
322 gnt_text_view_next_line(view); |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
323 continue; |
14010
7573bd40a190
[gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13971
diff
changeset
|
324 } |
7573bd40a190
[gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13971
diff
changeset
|
325 |
7573bd40a190
[gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13971
diff
changeset
|
326 line = view->list->data; |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
327 end = gnt_util_onscreen_width_to_pointer(start, |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
328 widget->priv.width - line->length - 1, &len); |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
329 |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
330 seg = g_new0(GntTextSegment, 1); |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
331 seg->start = start - view->string->str; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
332 seg->end = end - view->string->str; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
333 seg->tvflag = flags; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
334 seg->flags = fl; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
335 line->segments = g_list_append(line->segments, seg); |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
336 line->length += len; |
14311
fda9dc44807d
[gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14222
diff
changeset
|
337 |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
338 start = end; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
339 if (*end && *end != '\n' && *end != '\r') { |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
340 line = g_new0(GntTextLine, 1); |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
341 line->soft = TRUE; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
342 view->list = g_list_prepend(view->list, line); |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
343 } |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
344 } |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
345 |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
346 view->list = list; |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
347 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
348 gnt_widget_draw(widget); |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
349 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
350 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
351 void gnt_text_view_scroll(GntTextView *view, int scroll) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
352 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
353 if (scroll == 0) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
354 { |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
355 view->list = g_list_first(view->list); |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
356 } |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
357 else if (scroll > 0) |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
358 { |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
359 GList *list = g_list_nth_prev(view->list, scroll); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
360 if (list == NULL) |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
361 list = g_list_first(view->list); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
362 view->list = list; |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
363 } |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
364 else if (scroll < 0) |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
365 { |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
366 GList *list = g_list_nth(view->list, -scroll); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
367 if (list == NULL) |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
368 list = g_list_last(view->list); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
369 view->list = list; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
370 } |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
371 |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
372 gnt_widget_draw(GNT_WIDGET(view)); |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
373 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
374 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
375 void gnt_text_view_next_line(GntTextView *view) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
376 { |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
377 GntTextLine *line = g_new0(GntTextLine, 1); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
378 GList *list = view->list; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
379 |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
380 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
|
381 view->list = list; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
382 gnt_widget_draw(GNT_WIDGET(view)); |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
383 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
384 |
13952
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
385 chtype gnt_text_format_flag_to_chtype(GntTextFormatFlags flags) |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
386 { |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
387 chtype fl = 0; |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
388 |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
389 if (flags & GNT_TEXT_FLAG_BOLD) |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
390 fl |= A_BOLD; |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
391 if (flags & GNT_TEXT_FLAG_UNDERLINE) |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
392 fl |= A_UNDERLINE; |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
393 if (flags & GNT_TEXT_FLAG_BLINK) |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
394 fl |= A_BLINK; |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
395 |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
396 if (flags & GNT_TEXT_FLAG_DIM) |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
397 fl |= (A_DIM | COLOR_PAIR(GNT_COLOR_DISABLED)); |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
398 else if (flags & GNT_TEXT_FLAG_HIGHLIGHT) |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
399 fl |= (A_DIM | COLOR_PAIR(GNT_COLOR_HIGHLIGHT)); |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
400 else |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
401 fl |= COLOR_PAIR(GNT_COLOR_NORMAL); |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
402 |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
403 return fl; |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
404 } |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
405 |
13971
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
406 void gnt_text_view_clear(GntTextView *view) |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
407 { |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
408 GntTextLine *line; |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
409 |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
410 g_list_foreach(view->list, free_text_line, NULL); |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
411 g_list_free(view->list); |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
412 view->list = NULL; |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
413 |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
414 line = g_new0(GntTextLine, 1); |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
415 view->list = g_list_append(view->list, line); |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
416 if (view->string) |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
417 g_string_free(view->string, TRUE); |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
418 view->string = g_string_new(NULL); |
13971
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
419 |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
420 if (GNT_WIDGET(view)->window) |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
421 gnt_widget_draw(GNT_WIDGET(view)); |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
422 } |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
423 |
14030
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
424 int gnt_text_view_get_lines_below(GntTextView *view) |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
425 { |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
426 int below = 0; |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
427 GList *list = view->list; |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
428 while ((list = list->prev)) |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
429 ++below; |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
430 return below; |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
431 } |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
432 |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
433 int gnt_text_view_get_lines_above(GntTextView *view) |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
434 { |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
435 int above = 0; |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
436 GList *list = view->list; |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
437 list = g_list_nth(view->list, GNT_WIDGET(view)->priv.height); |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
438 if (!list) |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
439 return 0; |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
440 while ((list = list->next)) |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
441 ++above; |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
442 return above; |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
443 } |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
444 |