Mercurial > pidgin
annotate console/libgnt/gnttextview.c @ 15117:1f0db03dd165
[gaim-migrate @ 17903]
Update the Changelog.API. Thanks to ari for noticing.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Wed, 06 Dec 2006 23:05:51 +0000 |
parents | 5228f8cf2a6a |
children | a00712d0522e |
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 |
14398
2377498b4698
[gaim-migrate @ 17106]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14397
diff
changeset
|
4 #include <string.h> |
2377498b4698
[gaim-migrate @ 17106]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14397
diff
changeset
|
5 |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
6 enum |
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 SIGS = 1, |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
9 }; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
10 |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
11 typedef struct |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
12 { |
14371
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
13 GntTextFormatFlags tvflag; |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
14 chtype flags; |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
15 int start; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
16 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
|
17 } GntTextSegment; |
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 typedef struct |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
20 { |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
21 GList *segments; /* A list of GntTextSegments */ |
14311
fda9dc44807d
[gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14222
diff
changeset
|
22 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
|
23 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
|
24 } GntTextLine; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
25 |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
26 static GntWidgetClass *parent_class = NULL; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
27 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
28 static void |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
29 gnt_text_view_draw(GntWidget *widget) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
30 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
31 GntTextView *view = GNT_TEXT_VIEW(widget); |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
32 int i = 0; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
33 GList *lines; |
14131
db2311999862
[gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14123
diff
changeset
|
34 int rows, scrcol; |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
35 |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
36 werase(widget->window); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
37 |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
38 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
|
39 { |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
40 GList *iter; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
41 GntTextLine *line = lines->data; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
42 |
14222
8c13a650cef5
[gaim-migrate @ 16903]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14221
diff
changeset
|
43 wmove(widget->window, widget->priv.height - 1 - i, 0); |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
44 |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
45 for (iter = line->segments; iter; iter = iter->next) |
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 GntTextSegment *seg = iter->data; |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
48 char *end = view->string->str + seg->end; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
49 char back = *end; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
50 *end = '\0'; |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
51 wattrset(widget->window, seg->flags); |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
52 wprintw(widget->window, "%s", (view->string->str + seg->start)); |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
53 *end = back; |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
54 } |
14727
9baeeaa365d1
[gaim-migrate @ 17482]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14432
diff
changeset
|
55 wattroff(widget->window, A_UNDERLINE | A_BLINK | A_REVERSE); |
9baeeaa365d1
[gaim-migrate @ 17482]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14432
diff
changeset
|
56 whline(widget->window, ' ', widget->priv.width - line->length - 1); |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
57 } |
14123
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
58 |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
59 scrcol = widget->priv.width - 1; |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
60 rows = widget->priv.height - 2; |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
61 if (rows > 0) |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
62 { |
14131
db2311999862
[gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14123
diff
changeset
|
63 int total = g_list_length(g_list_first(view->list)); |
db2311999862
[gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14123
diff
changeset
|
64 int showing, position, up, down; |
14123
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
65 |
14131
db2311999862
[gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14123
diff
changeset
|
66 showing = rows * rows / total + 1; |
14123
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
67 showing = MIN(rows, showing); |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
68 |
14131
db2311999862
[gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14123
diff
changeset
|
69 total -= rows; |
db2311999862
[gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14123
diff
changeset
|
70 up = g_list_length(lines); |
db2311999862
[gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14123
diff
changeset
|
71 down = total - up; |
db2311999862
[gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14123
diff
changeset
|
72 |
db2311999862
[gaim-migrate @ 16773]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14123
diff
changeset
|
73 position = (rows - showing) * up / MAX(1, up + down); |
14123
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
74 position = MAX((lines != NULL), position); |
14107
c0ee28af3ca2
[gaim-migrate @ 16741]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14032
diff
changeset
|
75 |
14123
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
76 if (showing + position > rows) |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
77 position = rows - showing; |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
78 |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
79 if (showing + position == rows && view->list && view->list->prev) |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
80 position = MAX(1, rows - 1 - showing); |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
81 else if (showing + position < rows && view->list && !view->list->prev) |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
82 position = rows - showing; |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
83 |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
84 mvwvline(widget->window, position + 1, scrcol, |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
85 ACS_CKBOARD | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D), showing); |
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 |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
88 mvwaddch(widget->window, 0, scrcol, |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
89 (lines ? ACS_UARROW : ' ') | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D)); |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
90 mvwaddch(widget->window, widget->priv.height - 1, scrcol, |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
91 ((view->list && view->list->prev) ? ACS_DARROW : ' ') | |
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
92 COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D)); |
14107
c0ee28af3ca2
[gaim-migrate @ 16741]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14032
diff
changeset
|
93 |
14432
3ac156db9cb6
[gaim-migrate @ 17146]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14399
diff
changeset
|
94 GNTDEBUG; |
13882
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 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
97 static void |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
98 gnt_text_view_size_request(GntWidget *widget) |
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 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_MAPPED)) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
101 { |
14399
28baa42b5ac2
[gaim-migrate @ 17107]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14398
diff
changeset
|
102 gnt_widget_set_size(widget, 64, 20); |
13882
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 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
106 static void |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
107 gnt_text_view_map(GntWidget *widget) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
108 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
109 if (widget->priv.width == 0 || widget->priv.height == 0) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
110 gnt_widget_size_request(widget); |
14432
3ac156db9cb6
[gaim-migrate @ 17146]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14399
diff
changeset
|
111 GNTDEBUG; |
13882
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 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
114 static gboolean |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
115 gnt_text_view_key_pressed(GntWidget *widget, const char *text) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
116 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
117 return FALSE; |
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 static void |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
121 free_text_segment(gpointer data, gpointer null) |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
122 { |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
123 GntTextSegment *seg = data; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
124 g_free(seg); |
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 |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
127 static void |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
128 free_text_line(gpointer data, gpointer null) |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
129 { |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
130 GntTextLine *line = data; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
131 g_list_foreach(line->segments, free_text_segment, NULL); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
132 g_list_free(line->segments); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
133 g_free(line); |
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 |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
136 static void |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
137 gnt_text_view_destroy(GntWidget *widget) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
138 { |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
139 GntTextView *view = GNT_TEXT_VIEW(widget); |
14030
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
140 view->list = g_list_first(view->list); |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
141 g_list_foreach(view->list, free_text_line, NULL); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
142 g_list_free(view->list); |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
143 g_string_free(view->string, TRUE); |
13882
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 |
14343
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
146 static gboolean |
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
147 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
|
148 { |
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
149 if (event == GNT_MOUSE_SCROLL_UP) { |
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
150 gnt_text_view_scroll(GNT_TEXT_VIEW(widget), -1); |
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
151 } else if (event == GNT_MOUSE_SCROLL_DOWN) { |
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
152 gnt_text_view_scroll(GNT_TEXT_VIEW(widget), 1); |
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
153 } else |
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
154 return FALSE; |
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
155 return TRUE; |
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
156 } |
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
157 |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
158 static void |
14371
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
159 gnt_text_view_reflow(GntTextView *view) |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
160 { |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
161 /* 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
|
162 GntTextLine *line; |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
163 GList *back, *iter, *list; |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
164 GString *string; |
14826
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
165 int pos = 0; /* no. of 'real' lines */ |
14371
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
166 |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
167 list = view->list; |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
168 while (list->prev) { |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
169 line = list->data; |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
170 if (!line->soft) |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
171 pos++; |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
172 list = list->prev; |
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 |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
175 back = g_list_last(view->list); |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
176 view->list = NULL; |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
177 |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
178 string = view->string; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
179 view->string = NULL; |
14371
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
180 gnt_text_view_clear(view); |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
181 |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
182 view->string = g_string_set_size(view->string, string->len); |
14826
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
183 view->string->len = 0; |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
184 GNT_WIDGET_SET_FLAGS(GNT_WIDGET(view), GNT_WIDGET_DRAWING); |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
185 |
14371
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
186 for (; back; back = back->prev) { |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
187 line = back->data; |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
188 if (back->next && !line->soft) { |
14826
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
189 gnt_text_view_append_text_with_flags(view, "\n", GNT_TEXT_FLAG_NORMAL); |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
190 } |
14826
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
191 |
14371
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
192 for (iter = line->segments; iter; iter = iter->next) { |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
193 GntTextSegment *seg = iter->data; |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
194 char *start = string->str + seg->start; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
195 char *end = string->str + seg->end; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
196 char back = *end; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
197 *end = '\0'; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
198 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
|
199 *end = back; |
14371
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
200 } |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
201 free_text_line(line, NULL); |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
202 } |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
203 g_list_free(list); |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
204 |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
205 list = view->list = g_list_first(view->list); |
14826
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
206 /* Go back to the line that was in view before resizing started */ |
14371
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
207 while (pos--) { |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
208 while (((GntTextLine*)list->data)->soft) |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
209 list = list->next; |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
210 list = list->next; |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
211 } |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
212 view->list = list; |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
213 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(view), GNT_WIDGET_DRAWING); |
14881
5228f8cf2a6a
[gaim-migrate @ 17650]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14826
diff
changeset
|
214 if (GNT_WIDGET(view)->window) |
5228f8cf2a6a
[gaim-migrate @ 17650]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14826
diff
changeset
|
215 gnt_widget_draw(GNT_WIDGET(view)); |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
216 g_string_free(string, TRUE); |
14371
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
217 } |
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 static void |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
220 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
|
221 { |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
222 if (w != widget->priv.width) { |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
223 gnt_text_view_reflow(GNT_TEXT_VIEW(widget)); |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
224 } |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
225 } |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
226 |
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
227 static void |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
228 gnt_text_view_class_init(GntTextViewClass *klass) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
229 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
230 parent_class = GNT_WIDGET_CLASS(klass); |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
231 parent_class->destroy = gnt_text_view_destroy; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
232 parent_class->draw = gnt_text_view_draw; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
233 parent_class->map = gnt_text_view_map; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
234 parent_class->size_request = gnt_text_view_size_request; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
235 parent_class->key_pressed = gnt_text_view_key_pressed; |
14343
0387a167f342
[gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14311
diff
changeset
|
236 parent_class->clicked = gnt_text_view_clicked; |
14371
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
237 parent_class->size_changed = gnt_text_view_size_changed; |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
238 |
14432
3ac156db9cb6
[gaim-migrate @ 17146]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14399
diff
changeset
|
239 GNTDEBUG; |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
240 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
241 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
242 static void |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
243 gnt_text_view_init(GTypeInstance *instance, gpointer class) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
244 { |
13943
25be562aaca8
[gaim-migrate @ 16480]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13931
diff
changeset
|
245 GntWidget *widget = GNT_WIDGET(instance); |
25be562aaca8
[gaim-migrate @ 16480]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13931
diff
changeset
|
246 |
14371
f3137c1faebe
[gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14343
diff
changeset
|
247 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
|
248 |
25be562aaca8
[gaim-migrate @ 16480]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13931
diff
changeset
|
249 widget->priv.minw = 5; |
14123
f8ab496671fa
[gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14107
diff
changeset
|
250 widget->priv.minh = 2; |
14432
3ac156db9cb6
[gaim-migrate @ 17146]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14399
diff
changeset
|
251 GNTDEBUG; |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
252 } |
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 /****************************************************************************** |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
255 * GntTextView API |
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 GType |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
258 gnt_text_view_get_gtype(void) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
259 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
260 static GType type = 0; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
261 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
262 if(type == 0) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
263 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
264 static const GTypeInfo info = { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
265 sizeof(GntTextViewClass), |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
266 NULL, /* base_init */ |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
267 NULL, /* base_finalize */ |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
268 (GClassInitFunc)gnt_text_view_class_init, |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
269 NULL, /* class_finalize */ |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
270 NULL, /* class_data */ |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
271 sizeof(GntTextView), |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
272 0, /* n_preallocs */ |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
273 gnt_text_view_init, /* instance_init */ |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
274 }; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
275 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
276 type = g_type_register_static(GNT_TYPE_WIDGET, |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
277 "GntTextView", |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
278 &info, 0); |
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 return type; |
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 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
284 GntWidget *gnt_text_view_new() |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
285 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
286 GntWidget *widget = g_object_new(GNT_TYPE_TEXTVIEW, NULL); |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
287 GntTextView *view = GNT_TEXT_VIEW(widget); |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
288 GntTextLine *line = g_new0(GntTextLine, 1); |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
289 |
13927
9309d27d780c
[gaim-migrate @ 16447]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13896
diff
changeset
|
290 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
|
291 |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
292 view->string = g_string_new(NULL); |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
293 view->list = g_list_append(view->list, line); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
294 |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
295 return widget; |
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 |
13931
917a71dd02eb
[gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13930
diff
changeset
|
298 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
|
299 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
300 GntWidget *widget = GNT_WIDGET(view); |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
301 int fl = 0; |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
302 const char *start, *end; |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
303 GList *list = view->list; |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
304 GntTextLine *line; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
305 int len; |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
306 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
307 if (text == NULL || *text == '\0') |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
308 return; |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
309 |
13952
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
310 fl = gnt_text_format_flag_to_chtype(flags); |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
311 |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
312 len = view->string->len; |
14826
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
313 view->string = g_string_append(view->string, text); |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
314 |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
315 view->list = g_list_first(view->list); |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
316 |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
317 start = end = view->string->str + len; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
318 |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
319 while (*start) { |
14826
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
320 GntTextSegment *seg = NULL; |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
321 |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
322 if (*end == '\n' || *end == '\r') { |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
323 end++; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
324 start = end; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
325 gnt_text_view_next_line(view); |
14398
2377498b4698
[gaim-migrate @ 17106]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14397
diff
changeset
|
326 view->list = g_list_first(view->list); |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
327 continue; |
14010
7573bd40a190
[gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13971
diff
changeset
|
328 } |
7573bd40a190
[gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13971
diff
changeset
|
329 |
7573bd40a190
[gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13971
diff
changeset
|
330 line = view->list->data; |
14826
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
331 if (line->length == widget->priv.width - 1) { |
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
332 /* The last added line was exactly the same width as the widget */ |
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
333 line = g_new0(GntTextLine, 1); |
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
334 line->soft = TRUE; |
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
335 view->list = g_list_prepend(view->list, line); |
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
336 } |
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
337 |
14397
70f52ff1caec
[gaim-migrate @ 17105]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14383
diff
changeset
|
338 if ((end = strchr(start, '\n')) != NULL || |
70f52ff1caec
[gaim-migrate @ 17105]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14383
diff
changeset
|
339 (end = strchr(start, '\r')) != NULL) { |
14398
2377498b4698
[gaim-migrate @ 17106]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14397
diff
changeset
|
340 len = gnt_util_onscreen_width(start, end - 1); |
2377498b4698
[gaim-migrate @ 17106]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14397
diff
changeset
|
341 if (len >= widget->priv.width - line->length - 1) { |
14397
70f52ff1caec
[gaim-migrate @ 17105]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14383
diff
changeset
|
342 end = NULL; |
70f52ff1caec
[gaim-migrate @ 17105]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14383
diff
changeset
|
343 } |
70f52ff1caec
[gaim-migrate @ 17105]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14383
diff
changeset
|
344 } |
70f52ff1caec
[gaim-migrate @ 17105]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14383
diff
changeset
|
345 |
70f52ff1caec
[gaim-migrate @ 17105]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14383
diff
changeset
|
346 if (end == NULL) |
70f52ff1caec
[gaim-migrate @ 17105]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14383
diff
changeset
|
347 end = gnt_util_onscreen_width_to_pointer(start, |
70f52ff1caec
[gaim-migrate @ 17105]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14383
diff
changeset
|
348 widget->priv.width - line->length - 1, &len); |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
349 |
14826
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
350 /* Try to append to the previous segment if possible */ |
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
351 if (line->segments) { |
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
352 seg = g_list_last(line->segments)->data; |
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
353 if (seg->flags != fl) |
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
354 seg = NULL; |
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
355 } |
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
356 |
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
357 if (seg == NULL) { |
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
358 seg = g_new0(GntTextSegment, 1); |
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
359 seg->start = start - view->string->str; |
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
360 seg->tvflag = flags; |
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
361 seg->flags = fl; |
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
362 line->segments = g_list_append(line->segments, seg); |
955798236bf4
[gaim-migrate @ 17593]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14729
diff
changeset
|
363 } |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
364 seg->end = end - view->string->str; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
365 line->length += len; |
14311
fda9dc44807d
[gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14222
diff
changeset
|
366 |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
367 start = end; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
368 if (*end && *end != '\n' && *end != '\r') { |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
369 line = g_new0(GntTextLine, 1); |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
370 line->soft = TRUE; |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
371 view->list = g_list_prepend(view->list, line); |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
372 } |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
373 } |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
374 |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
375 view->list = list; |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
376 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
377 gnt_widget_draw(widget); |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
378 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
379 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
380 void gnt_text_view_scroll(GntTextView *view, int scroll) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
381 { |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
382 if (scroll == 0) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
383 { |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
384 view->list = g_list_first(view->list); |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
385 } |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
386 else if (scroll > 0) |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
387 { |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
388 GList *list = g_list_nth_prev(view->list, scroll); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
389 if (list == NULL) |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
390 list = g_list_first(view->list); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
391 view->list = list; |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
392 } |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
393 else if (scroll < 0) |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
394 { |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
395 GList *list = g_list_nth(view->list, -scroll); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
396 if (list == NULL) |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
397 list = g_list_last(view->list); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
398 view->list = list; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
399 } |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
400 |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
401 gnt_widget_draw(GNT_WIDGET(view)); |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
402 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
403 |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
404 void gnt_text_view_next_line(GntTextView *view) |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
405 { |
13896
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
406 GntTextLine *line = g_new0(GntTextLine, 1); |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
407 GList *list = view->list; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
408 |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
409 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
|
410 view->list = list; |
a621329e8c85
[gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13888
diff
changeset
|
411 gnt_widget_draw(GNT_WIDGET(view)); |
13882
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
412 } |
5c750626eaa5
[gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff
changeset
|
413 |
13952
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
414 chtype gnt_text_format_flag_to_chtype(GntTextFormatFlags flags) |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
415 { |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
416 chtype fl = 0; |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
417 |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
418 if (flags & GNT_TEXT_FLAG_BOLD) |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
419 fl |= A_BOLD; |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
420 if (flags & GNT_TEXT_FLAG_UNDERLINE) |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
421 fl |= A_UNDERLINE; |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
422 if (flags & GNT_TEXT_FLAG_BLINK) |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
423 fl |= A_BLINK; |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
424 |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
425 if (flags & GNT_TEXT_FLAG_DIM) |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
426 fl |= (A_DIM | COLOR_PAIR(GNT_COLOR_DISABLED)); |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
427 else if (flags & GNT_TEXT_FLAG_HIGHLIGHT) |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
428 fl |= (A_DIM | COLOR_PAIR(GNT_COLOR_HIGHLIGHT)); |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
429 else |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
430 fl |= COLOR_PAIR(GNT_COLOR_NORMAL); |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
431 |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
432 return fl; |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
433 } |
841a5ffbfee4
[gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13943
diff
changeset
|
434 |
13971
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
435 void gnt_text_view_clear(GntTextView *view) |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
436 { |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
437 GntTextLine *line; |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
438 |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
439 g_list_foreach(view->list, free_text_line, NULL); |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
440 g_list_free(view->list); |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
441 view->list = NULL; |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
442 |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
443 line = g_new0(GntTextLine, 1); |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
444 view->list = g_list_append(view->list, line); |
14383
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
445 if (view->string) |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
446 g_string_free(view->string, TRUE); |
5f3058c7a7df
[gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14371
diff
changeset
|
447 view->string = g_string_new(NULL); |
13971
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
448 |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
449 if (GNT_WIDGET(view)->window) |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
450 gnt_widget_draw(GNT_WIDGET(view)); |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
451 } |
df8183b7fa2c
[gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
13952
diff
changeset
|
452 |
14030
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
453 int gnt_text_view_get_lines_below(GntTextView *view) |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
454 { |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
455 int below = 0; |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
456 GList *list = view->list; |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
457 while ((list = list->prev)) |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
458 ++below; |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
459 return below; |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
460 } |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
461 |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
462 int gnt_text_view_get_lines_above(GntTextView *view) |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
463 { |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
464 int above = 0; |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
465 GList *list = view->list; |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
466 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
|
467 if (!list) |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
468 return 0; |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
469 while ((list = list->next)) |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
470 ++above; |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
471 return above; |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
472 } |
0e70bb6d32fd
[gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
14010
diff
changeset
|
473 |