annotate console/libgnt/gnttextview.c @ 14815:49450a1bc58e

[gaim-migrate @ 17581] Check to make sure UI ops exist for network_connected and network_disconnected before calling them. Thanks to plaes on #gaim who says this fixes some gaim-text crashes. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Wed, 25 Oct 2006 12:51:22 +0000
parents b7e145ea9076
children 955798236bf4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
14371
f3137c1faebe [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14343
diff changeset
165 int pos = 0;
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);
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
183 GNT_WIDGET_SET_FLAGS(GNT_WIDGET(view), GNT_WIDGET_DRAWING);
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
184
14371
f3137c1faebe [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14343
diff changeset
185 for (; back; back = back->prev) {
f3137c1faebe [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14343
diff changeset
186 line = back->data;
14383
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
187 if (back->next && !line->soft) {
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
188 GList *llist = g_list_first(view->list);
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
189 llist = g_list_prepend(llist, g_new0(GntTextLine, 1));
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
190 }
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
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);
f3137c1faebe [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14343
diff changeset
206 while (pos--) {
f3137c1faebe [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14343
diff changeset
207 while (((GntTextLine*)list->data)->soft)
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 list = list->next;
f3137c1faebe [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14343
diff changeset
210 }
f3137c1faebe [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14343
diff changeset
211 view->list = list;
14383
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
212 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
213 gnt_widget_draw(GNT_WIDGET(view));
14383
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
214 g_string_free(string, TRUE);
14371
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
f3137c1faebe [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14343
diff changeset
217 static void
f3137c1faebe [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14343
diff changeset
218 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
219 {
f3137c1faebe [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14343
diff changeset
220 if (w != widget->priv.width) {
f3137c1faebe [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14343
diff changeset
221 gnt_text_view_reflow(GNT_TEXT_VIEW(widget));
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
f3137c1faebe [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14343
diff changeset
225 static void
13882
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
226 gnt_text_view_class_init(GntTextViewClass *klass)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
227 {
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
228 parent_class = GNT_WIDGET_CLASS(klass);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
229 parent_class->destroy = gnt_text_view_destroy;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
230 parent_class->draw = gnt_text_view_draw;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
231 parent_class->map = gnt_text_view_map;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
232 parent_class->size_request = gnt_text_view_size_request;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
233 parent_class->key_pressed = gnt_text_view_key_pressed;
14343
0387a167f342 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14311
diff changeset
234 parent_class->clicked = gnt_text_view_clicked;
14371
f3137c1faebe [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14343
diff changeset
235 parent_class->size_changed = gnt_text_view_size_changed;
13882
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
236
14432
3ac156db9cb6 [gaim-migrate @ 17146]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14399
diff changeset
237 GNTDEBUG;
13882
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
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
240 static void
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
241 gnt_text_view_init(GTypeInstance *instance, gpointer class)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
242 {
13943
25be562aaca8 [gaim-migrate @ 16480]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13931
diff changeset
243 GntWidget *widget = GNT_WIDGET(instance);
25be562aaca8 [gaim-migrate @ 16480]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13931
diff changeset
244
14371
f3137c1faebe [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14343
diff changeset
245 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
246
25be562aaca8 [gaim-migrate @ 16480]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13931
diff changeset
247 widget->priv.minw = 5;
14123
f8ab496671fa [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14107
diff changeset
248 widget->priv.minh = 2;
14432
3ac156db9cb6 [gaim-migrate @ 17146]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14399
diff changeset
249 GNTDEBUG;
13882
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 /******************************************************************************
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
253 * GntTextView API
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 GType
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
256 gnt_text_view_get_gtype(void)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
257 {
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
258 static GType type = 0;
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 if(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 static const GTypeInfo info = {
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
263 sizeof(GntTextViewClass),
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
264 NULL, /* base_init */
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
265 NULL, /* base_finalize */
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
266 (GClassInitFunc)gnt_text_view_class_init,
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
267 NULL, /* class_finalize */
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
268 NULL, /* class_data */
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
269 sizeof(GntTextView),
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
270 0, /* n_preallocs */
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
271 gnt_text_view_init, /* instance_init */
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
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
274 type = g_type_register_static(GNT_TYPE_WIDGET,
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
275 "GntTextView",
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
276 &info, 0);
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
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
279 return type;
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
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
282 GntWidget *gnt_text_view_new()
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 *widget = g_object_new(GNT_TYPE_TEXTVIEW, NULL);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
285 GntTextView *view = GNT_TEXT_VIEW(widget);
13896
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
286 GntTextLine *line = g_new0(GntTextLine, 1);
13882
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
287
13927
9309d27d780c [gaim-migrate @ 16447]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13896
diff changeset
288 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
289
14383
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
290 view->string = g_string_new(NULL);
13896
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
291 view->list = g_list_append(view->list, line);
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
292
13882
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
293 return widget;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
294 }
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
295
13931
917a71dd02eb [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13930
diff changeset
296 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
297 {
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
298 GntWidget *widget = GNT_WIDGET(view);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
299 int fl = 0;
14383
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
300 const char *start, *end;
13896
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
301 GList *list = view->list;
14383
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
302 GntTextLine *line;
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
303 int len;
13882
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
304
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
305 if (text == NULL || *text == '\0')
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
306 return;
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
307
13952
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
308 fl = gnt_text_format_flag_to_chtype(flags);
13896
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
309
14383
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
310 len = view->string->len;
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
311 g_string_append(view->string, text);
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
312
13896
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
313 view->list = g_list_first(view->list);
13882
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
314
14383
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
315 start = end = view->string->str + len;
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
316
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
317 while (*start) {
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
318 GntTextSegment *seg;
13896
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
319
14383
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
320 if (*end == '\n' || *end == '\r') {
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
321 end++;
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
322 start = end;
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
323 gnt_text_view_next_line(view);
14398
2377498b4698 [gaim-migrate @ 17106]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14397
diff changeset
324 view->list = g_list_first(view->list);
14383
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
325 continue;
14010
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
326 }
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
327
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13971
diff changeset
328 line = view->list->data;
14397
70f52ff1caec [gaim-migrate @ 17105]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14383
diff changeset
329 if ((end = strchr(start, '\n')) != NULL ||
70f52ff1caec [gaim-migrate @ 17105]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14383
diff changeset
330 (end = strchr(start, '\r')) != NULL) {
14398
2377498b4698 [gaim-migrate @ 17106]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14397
diff changeset
331 len = gnt_util_onscreen_width(start, end - 1);
2377498b4698 [gaim-migrate @ 17106]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14397
diff changeset
332 if (len >= widget->priv.width - line->length - 1) {
14397
70f52ff1caec [gaim-migrate @ 17105]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14383
diff changeset
333 end = NULL;
70f52ff1caec [gaim-migrate @ 17105]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14383
diff changeset
334 }
70f52ff1caec [gaim-migrate @ 17105]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14383
diff changeset
335 }
70f52ff1caec [gaim-migrate @ 17105]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14383
diff changeset
336
70f52ff1caec [gaim-migrate @ 17105]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14383
diff changeset
337 if (end == NULL)
70f52ff1caec [gaim-migrate @ 17105]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14383
diff changeset
338 end = gnt_util_onscreen_width_to_pointer(start,
70f52ff1caec [gaim-migrate @ 17105]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14383
diff changeset
339 widget->priv.width - line->length - 1, &len);
13896
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
340
14383
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
341 seg = g_new0(GntTextSegment, 1);
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
342 seg->start = start - view->string->str;
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
343 seg->end = end - view->string->str;
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
344 seg->tvflag = flags;
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
345 seg->flags = fl;
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
346 line->segments = g_list_append(line->segments, seg);
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
347 line->length += len;
14311
fda9dc44807d [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14222
diff changeset
348
14383
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
349 start = end;
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
350 if (*end && *end != '\n' && *end != '\r') {
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
351 line = g_new0(GntTextLine, 1);
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
352 line->soft = TRUE;
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
353 view->list = g_list_prepend(view->list, line);
13896
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
354 }
13882
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
355 }
13896
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
356
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
357 view->list = list;
13882
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
358
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
359 gnt_widget_draw(widget);
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
360 }
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
361
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
362 void gnt_text_view_scroll(GntTextView *view, int scroll)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
363 {
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
364 if (scroll == 0)
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
365 {
13896
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
366 view->list = g_list_first(view->list);
13882
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
367 }
13896
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
368 else if (scroll > 0)
13882
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
369 {
13896
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
370 GList *list = g_list_nth_prev(view->list, scroll);
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
371 if (list == NULL)
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
372 list = g_list_first(view->list);
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
373 view->list = list;
13882
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
374 }
13896
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
375 else if (scroll < 0)
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
376 {
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
377 GList *list = g_list_nth(view->list, -scroll);
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
378 if (list == NULL)
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
379 list = g_list_last(view->list);
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
380 view->list = list;
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
381 }
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
382
13882
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
383 gnt_widget_draw(GNT_WIDGET(view));
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
384 }
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
385
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
386 void gnt_text_view_next_line(GntTextView *view)
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 GntTextLine *line = g_new0(GntTextLine, 1);
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
389 GList *list = view->list;
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
390
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
391 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
392 view->list = list;
a621329e8c85 [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13888
diff changeset
393 gnt_widget_draw(GNT_WIDGET(view));
13882
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
394 }
5c750626eaa5 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
395
13952
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
396 chtype gnt_text_format_flag_to_chtype(GntTextFormatFlags flags)
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
397 {
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
398 chtype fl = 0;
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
399
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
400 if (flags & GNT_TEXT_FLAG_BOLD)
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
401 fl |= A_BOLD;
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
402 if (flags & GNT_TEXT_FLAG_UNDERLINE)
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
403 fl |= A_UNDERLINE;
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
404 if (flags & GNT_TEXT_FLAG_BLINK)
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
405 fl |= A_BLINK;
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
406
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
407 if (flags & GNT_TEXT_FLAG_DIM)
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
408 fl |= (A_DIM | COLOR_PAIR(GNT_COLOR_DISABLED));
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
409 else if (flags & GNT_TEXT_FLAG_HIGHLIGHT)
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
410 fl |= (A_DIM | COLOR_PAIR(GNT_COLOR_HIGHLIGHT));
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
411 else
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
412 fl |= COLOR_PAIR(GNT_COLOR_NORMAL);
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
413
841a5ffbfee4 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13943
diff changeset
414 return fl;
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
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
417 void gnt_text_view_clear(GntTextView *view)
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
418 {
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
419 GntTextLine *line;
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
420
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
421 g_list_foreach(view->list, free_text_line, NULL);
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
422 g_list_free(view->list);
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
423 view->list = NULL;
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
424
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
425 line = g_new0(GntTextLine, 1);
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
426 view->list = g_list_append(view->list, line);
14383
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
427 if (view->string)
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
428 g_string_free(view->string, TRUE);
5f3058c7a7df [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14371
diff changeset
429 view->string = g_string_new(NULL);
13971
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
430
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
431 if (GNT_WIDGET(view)->window)
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
432 gnt_widget_draw(GNT_WIDGET(view));
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
433 }
df8183b7fa2c [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 13952
diff changeset
434
14030
0e70bb6d32fd [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
435 int gnt_text_view_get_lines_below(GntTextView *view)
0e70bb6d32fd [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
436 {
0e70bb6d32fd [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
437 int below = 0;
0e70bb6d32fd [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
438 GList *list = view->list;
0e70bb6d32fd [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
439 while ((list = list->prev))
0e70bb6d32fd [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
440 ++below;
0e70bb6d32fd [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
441 return below;
0e70bb6d32fd [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
442 }
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 int gnt_text_view_get_lines_above(GntTextView *view)
0e70bb6d32fd [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
445 {
0e70bb6d32fd [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
446 int above = 0;
0e70bb6d32fd [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
447 GList *list = view->list;
0e70bb6d32fd [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
448 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
449 if (!list)
0e70bb6d32fd [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
450 return 0;
0e70bb6d32fd [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
451 while ((list = list->next))
0e70bb6d32fd [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
452 ++above;
0e70bb6d32fd [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14010
diff changeset
453 return above;
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