Mercurial > pidgin
annotate finch/libgnt/gnttextview.c @ 19169:3432d37a4a77
propagate from branch 'tmpbranch' (head fb9ec433650ff4b1b7f84319be7937cb6ab45e71)
to branch 'im.pidgin.soc.2007.finchfeat' (head 76272d72e7b7f9fd0c866c8f4f1385868ec195f8)
author | Eric Polino <aluink@pidgin.im> |
---|---|
date | Mon, 16 Jul 2007 20:21:14 +0000 |
parents | 841670dd24e1 |
children | 09db6fec9dce |
rev | line source |
---|---|
18049
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
1 /** |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
3 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
4 * GNT is the legal property of its developers, whose names are too numerous |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
6 * source distribution. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
7 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
8 * This library is free software; you can redistribute it and/or modify |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
11 * (at your option) any later version. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
12 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
16 * GNU General Public License for more details. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
17 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
21 */ |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16124
diff
changeset
|
22 |
18426
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
23 #include "gntstyle.h" |
15817 | 24 #include "gnttextview.h" |
25 #include "gntutils.h" | |
26 | |
18426
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
27 #include <stdlib.h> |
15817 | 28 #include <string.h> |
29 | |
30 enum | |
31 { | |
32 SIGS = 1, | |
33 }; | |
34 | |
35 typedef struct | |
36 { | |
37 GntTextFormatFlags tvflag; | |
38 chtype flags; | |
39 int start; | |
40 int end; /* This is the next byte of the last character of this segment */ | |
41 } GntTextSegment; | |
42 | |
43 typedef struct | |
44 { | |
45 GList *segments; /* A list of GntTextSegments */ | |
46 int length; /* The current length of the line so far (ie. onscreen width) */ | |
47 gboolean soft; /* TRUE if it's an overflow from prev. line */ | |
48 } GntTextLine; | |
49 | |
50 typedef struct | |
51 { | |
52 char *name; | |
53 int start; | |
54 int end; | |
55 } GntTextTag; | |
56 | |
57 static GntWidgetClass *parent_class = NULL; | |
58 | |
59 static gchar *select_start; | |
60 static gchar *select_end; | |
61 static gboolean double_click; | |
62 | |
63 static void | |
64 gnt_text_view_draw(GntWidget *widget) | |
65 { | |
66 GntTextView *view = GNT_TEXT_VIEW(widget); | |
67 int i = 0; | |
68 GList *lines; | |
69 int rows, scrcol; | |
18315
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
70 gboolean has_scroll = !(view->flags & GNT_TEXT_VIEW_NO_SCROLL); |
15817 | 71 |
15928
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
72 wbkgd(widget->window, COLOR_PAIR(GNT_COLOR_NORMAL)); |
15817 | 73 werase(widget->window); |
74 | |
75 for (i = 0, lines = view->list; i < widget->priv.height && lines; i++, lines = lines->next) | |
76 { | |
77 GList *iter; | |
78 GntTextLine *line = lines->data; | |
79 | |
80 wmove(widget->window, widget->priv.height - 1 - i, 0); | |
81 | |
82 for (iter = line->segments; iter; iter = iter->next) | |
83 { | |
84 GntTextSegment *seg = iter->data; | |
85 char *end = view->string->str + seg->end; | |
86 char back = *end; | |
87 chtype fl = seg->flags; | |
88 *end = '\0'; | |
89 if (select_start < view->string->str + seg->start && select_end > view->string->str + seg->end) { | |
90 fl |= A_REVERSE; | |
91 wattrset(widget->window, fl); | |
92 wprintw(widget->window, "%s", (view->string->str + seg->start)); | |
93 } else if (select_start && select_end && | |
94 ((select_start >= view->string->str + seg->start && select_start <= view->string->str + seg->end) || | |
95 (select_end <= view->string->str + seg->end && select_start <= view->string->str + seg->start))) { | |
96 char *cur = view->string->str + seg->start; | |
97 while (*cur != '\0') { | |
98 gchar *last = g_utf8_next_char(cur); | |
99 gchar *str; | |
100 if (cur >= select_start && cur <= select_end) | |
101 fl |= A_REVERSE; | |
102 else | |
103 fl = seg->flags; | |
104 str = g_strndup(cur, last - cur); | |
105 wattrset(widget->window, fl); | |
106 waddstr(widget->window, str); | |
107 g_free(str); | |
108 cur = g_utf8_next_char(cur); | |
109 } | |
110 } else { | |
111 wattrset(widget->window, fl); | |
112 wprintw(widget->window, "%s", (view->string->str + seg->start)); | |
113 } | |
114 *end = back; | |
115 } | |
116 wattroff(widget->window, A_UNDERLINE | A_BLINK | A_REVERSE); | |
18315
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
117 whline(widget->window, ' ', widget->priv.width - line->length - has_scroll); |
15817 | 118 } |
119 | |
120 scrcol = widget->priv.width - 1; | |
121 rows = widget->priv.height - 2; | |
18315
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
122 if (has_scroll && rows > 0) |
15817 | 123 { |
124 int total = g_list_length(g_list_first(view->list)); | |
125 int showing, position, up, down; | |
126 | |
127 showing = rows * rows / total + 1; | |
128 showing = MIN(rows, showing); | |
129 | |
130 total -= rows; | |
131 up = g_list_length(lines); | |
132 down = total - up; | |
133 | |
134 position = (rows - showing) * up / MAX(1, up + down); | |
135 position = MAX((lines != NULL), position); | |
136 | |
137 if (showing + position > rows) | |
138 position = rows - showing; | |
139 | |
140 if (showing + position == rows && view->list && view->list->prev) | |
141 position = MAX(1, rows - 1 - showing); | |
142 else if (showing + position < rows && view->list && !view->list->prev) | |
143 position = rows - showing; | |
144 | |
145 mvwvline(widget->window, position + 1, scrcol, | |
146 ACS_CKBOARD | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D), showing); | |
147 } | |
148 | |
18315
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
149 if (has_scroll) { |
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
150 mvwaddch(widget->window, 0, scrcol, |
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
151 (lines ? ACS_UARROW : ' ') | COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D)); |
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
152 mvwaddch(widget->window, widget->priv.height - 1, scrcol, |
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
153 ((view->list && view->list->prev) ? ACS_DARROW : ' ') | |
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
154 COLOR_PAIR(GNT_COLOR_HIGHLIGHT_D)); |
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
155 } |
15817 | 156 |
157 GNTDEBUG; | |
158 } | |
159 | |
160 static void | |
161 gnt_text_view_size_request(GntWidget *widget) | |
162 { | |
163 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_MAPPED)) | |
164 { | |
165 gnt_widget_set_size(widget, 64, 20); | |
166 } | |
167 } | |
168 | |
169 static void | |
170 gnt_text_view_map(GntWidget *widget) | |
171 { | |
172 if (widget->priv.width == 0 || widget->priv.height == 0) | |
173 gnt_widget_size_request(widget); | |
174 GNTDEBUG; | |
175 } | |
176 | |
177 static gboolean | |
178 gnt_text_view_key_pressed(GntWidget *widget, const char *text) | |
179 { | |
180 return FALSE; | |
181 } | |
182 | |
183 static void | |
184 free_text_segment(gpointer data, gpointer null) | |
185 { | |
186 GntTextSegment *seg = data; | |
187 g_free(seg); | |
188 } | |
189 | |
190 static void | |
191 free_text_line(gpointer data, gpointer null) | |
192 { | |
193 GntTextLine *line = data; | |
194 g_list_foreach(line->segments, free_text_segment, NULL); | |
195 g_list_free(line->segments); | |
196 g_free(line); | |
197 } | |
198 | |
199 static void | |
200 free_tag(gpointer data, gpointer null) | |
201 { | |
202 GntTextTag *tag = data; | |
203 g_free(tag->name); | |
204 g_free(tag); | |
205 } | |
206 | |
207 static void | |
208 gnt_text_view_destroy(GntWidget *widget) | |
209 { | |
210 GntTextView *view = GNT_TEXT_VIEW(widget); | |
211 view->list = g_list_first(view->list); | |
212 g_list_foreach(view->list, free_text_line, NULL); | |
213 g_list_free(view->list); | |
214 g_list_foreach(view->tags, free_tag, NULL); | |
215 g_list_free(view->tags); | |
216 g_string_free(view->string, TRUE); | |
217 } | |
218 | |
219 static char * | |
220 gnt_text_view_get_p(GntTextView *view, int x, int y) | |
221 { | |
222 int i = 0; | |
223 GntWidget *wid = GNT_WIDGET(view); | |
224 GntTextLine *line; | |
225 GList *lines; | |
226 GList *segs; | |
227 GntTextSegment *seg; | |
228 gchar *pos; | |
229 | |
230 y = wid->priv.height - y; | |
231 if (g_list_length(view->list) < y) { | |
232 x = 0; | |
233 y = g_list_length(view->list) - 1; | |
234 } | |
235 | |
236 lines = g_list_nth(view->list, y - 1); | |
237 if (!lines) | |
238 return NULL; | |
239 do { | |
240 line = lines->data; | |
241 lines = lines->next; | |
242 } while (line && !line->segments && lines); | |
243 | |
244 if (!line || !line->segments) /* no valid line */ | |
245 return NULL; | |
246 segs = line->segments; | |
247 seg = (GntTextSegment *)segs->data; | |
248 pos = view->string->str + seg->start; | |
249 x = MIN(x, line->length); | |
250 while (++i <= x) { | |
251 gunichar *u; | |
252 pos = g_utf8_next_char(pos); | |
253 u = g_utf8_to_ucs4(pos, -1, NULL, NULL, NULL); | |
254 if (u && g_unichar_iswide(*u)) | |
255 i++; | |
256 g_free(u); | |
257 } | |
258 return pos; | |
259 } | |
260 | |
261 static GString * | |
262 select_word_text(GntTextView *view, gchar *c) | |
263 { | |
264 gchar *start = c; | |
265 gchar *end = c; | |
266 gchar *t, *endsize; | |
267 while ((t = g_utf8_prev_char(start))) { | |
268 if (!g_ascii_isspace(*t)) { | |
269 if (start == view->string->str) | |
270 break; | |
271 start = t; | |
272 } else | |
273 break; | |
274 } | |
275 while ((t = g_utf8_next_char(end))) { | |
276 if (!g_ascii_isspace(*t)) | |
277 end = t; | |
278 else | |
279 break; | |
280 } | |
281 select_start = start; | |
282 select_end = end; | |
283 endsize = g_utf8_next_char(select_end); /* End at the correct byte */ | |
284 return g_string_new_len(start, endsize - start); | |
285 } | |
286 | |
287 static gboolean too_slow(gpointer n) | |
288 { | |
289 double_click = FALSE; | |
290 return FALSE; | |
291 } | |
292 | |
293 static gboolean | |
294 gnt_text_view_clicked(GntWidget *widget, GntMouseEvent event, int x, int y) | |
295 { | |
296 if (event == GNT_MOUSE_SCROLL_UP) { | |
297 gnt_text_view_scroll(GNT_TEXT_VIEW(widget), -1); | |
298 } else if (event == GNT_MOUSE_SCROLL_DOWN) { | |
299 gnt_text_view_scroll(GNT_TEXT_VIEW(widget), 1); | |
300 } else if (event == GNT_LEFT_MOUSE_DOWN) { | |
301 select_start = gnt_text_view_get_p(GNT_TEXT_VIEW(widget), x - widget->priv.x, y - widget->priv.y); | |
302 g_timeout_add(500, too_slow, NULL); | |
303 } else if (event == GNT_MOUSE_UP) { | |
304 if (select_start) { | |
305 GString *clip; | |
306 select_end = gnt_text_view_get_p(GNT_TEXT_VIEW(widget), x - widget->priv.x, y - widget->priv.y); | |
307 if (select_end < select_start) { | |
308 gchar *t = select_start; | |
309 select_start = select_end; | |
310 select_end = t; | |
311 } | |
312 if (select_start == select_end) { | |
313 if (double_click) { | |
314 clip = select_word_text(GNT_TEXT_VIEW(widget), select_start); | |
315 double_click = FALSE; | |
316 } else { | |
317 double_click = TRUE; | |
318 select_start = 0; | |
319 select_end = 0; | |
320 gnt_widget_draw(widget); | |
321 return TRUE; | |
322 } | |
323 } else { | |
324 gchar *endsize = g_utf8_next_char(select_end); /* End at the correct byte */ | |
325 clip = g_string_new_len(select_start, endsize - select_start); | |
326 } | |
327 gnt_widget_draw(widget); | |
328 gnt_set_clipboard_string(clip->str); | |
329 g_string_free(clip, TRUE); | |
330 } | |
331 } else | |
332 return FALSE; | |
333 return TRUE; | |
334 } | |
335 | |
336 static void | |
337 gnt_text_view_reflow(GntTextView *view) | |
338 { | |
339 /* This is pretty ugly, and inefficient. Someone do something about it. */ | |
340 GntTextLine *line; | |
341 GList *back, *iter, *list; | |
342 GString *string; | |
343 int pos = 0; /* no. of 'real' lines */ | |
344 | |
345 list = view->list; | |
346 while (list->prev) { | |
347 line = list->data; | |
348 if (!line->soft) | |
349 pos++; | |
350 list = list->prev; | |
351 } | |
352 | |
353 back = g_list_last(view->list); | |
354 view->list = NULL; | |
355 | |
356 string = view->string; | |
357 view->string = NULL; | |
358 gnt_text_view_clear(view); | |
359 | |
360 view->string = g_string_set_size(view->string, string->len); | |
361 view->string->len = 0; | |
362 GNT_WIDGET_SET_FLAGS(GNT_WIDGET(view), GNT_WIDGET_DRAWING); | |
363 | |
364 for (; back; back = back->prev) { | |
365 line = back->data; | |
366 if (back->next && !line->soft) { | |
367 gnt_text_view_append_text_with_flags(view, "\n", GNT_TEXT_FLAG_NORMAL); | |
368 } | |
369 | |
370 for (iter = line->segments; iter; iter = iter->next) { | |
371 GntTextSegment *seg = iter->data; | |
372 char *start = string->str + seg->start; | |
373 char *end = string->str + seg->end; | |
374 char back = *end; | |
375 *end = '\0'; | |
376 gnt_text_view_append_text_with_flags(view, start, seg->tvflag); | |
377 *end = back; | |
378 } | |
379 free_text_line(line, NULL); | |
380 } | |
381 g_list_free(list); | |
382 | |
383 list = view->list = g_list_first(view->list); | |
384 /* Go back to the line that was in view before resizing started */ | |
385 while (pos--) { | |
386 while (((GntTextLine*)list->data)->soft) | |
387 list = list->next; | |
388 list = list->next; | |
389 } | |
390 view->list = list; | |
391 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(view), GNT_WIDGET_DRAWING); | |
392 if (GNT_WIDGET(view)->window) | |
393 gnt_widget_draw(GNT_WIDGET(view)); | |
394 g_string_free(string, TRUE); | |
395 } | |
396 | |
397 static void | |
398 gnt_text_view_size_changed(GntWidget *widget, int w, int h) | |
399 { | |
400 if (w != widget->priv.width) { | |
401 gnt_text_view_reflow(GNT_TEXT_VIEW(widget)); | |
402 } | |
403 } | |
404 | |
405 static void | |
406 gnt_text_view_class_init(GntTextViewClass *klass) | |
407 { | |
408 parent_class = GNT_WIDGET_CLASS(klass); | |
409 parent_class->destroy = gnt_text_view_destroy; | |
410 parent_class->draw = gnt_text_view_draw; | |
411 parent_class->map = gnt_text_view_map; | |
412 parent_class->size_request = gnt_text_view_size_request; | |
413 parent_class->key_pressed = gnt_text_view_key_pressed; | |
414 parent_class->clicked = gnt_text_view_clicked; | |
415 parent_class->size_changed = gnt_text_view_size_changed; | |
416 | |
417 GNTDEBUG; | |
418 } | |
419 | |
420 static void | |
421 gnt_text_view_init(GTypeInstance *instance, gpointer class) | |
422 { | |
423 GntWidget *widget = GNT_WIDGET(instance); | |
424 | |
425 GNT_WIDGET_SET_FLAGS(GNT_WIDGET(instance), GNT_WIDGET_GROW_Y | GNT_WIDGET_GROW_X); | |
426 | |
427 widget->priv.minw = 5; | |
428 widget->priv.minh = 2; | |
429 GNTDEBUG; | |
430 } | |
431 | |
432 /****************************************************************************** | |
433 * GntTextView API | |
434 *****************************************************************************/ | |
435 GType | |
436 gnt_text_view_get_gtype(void) | |
437 { | |
438 static GType type = 0; | |
439 | |
440 if(type == 0) | |
441 { | |
442 static const GTypeInfo info = { | |
443 sizeof(GntTextViewClass), | |
444 NULL, /* base_init */ | |
445 NULL, /* base_finalize */ | |
446 (GClassInitFunc)gnt_text_view_class_init, | |
447 NULL, /* class_finalize */ | |
448 NULL, /* class_data */ | |
449 sizeof(GntTextView), | |
450 0, /* n_preallocs */ | |
451 gnt_text_view_init, /* instance_init */ | |
452 NULL /* value_table */ | |
453 }; | |
454 | |
455 type = g_type_register_static(GNT_TYPE_WIDGET, | |
456 "GntTextView", | |
457 &info, 0); | |
458 } | |
459 | |
460 return type; | |
461 } | |
462 | |
463 GntWidget *gnt_text_view_new() | |
464 { | |
15928
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
465 GntWidget *widget = g_object_new(GNT_TYPE_TEXT_VIEW, NULL); |
15817 | 466 GntTextView *view = GNT_TEXT_VIEW(widget); |
467 GntTextLine *line = g_new0(GntTextLine, 1); | |
468 | |
469 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW); | |
470 | |
471 view->string = g_string_new(NULL); | |
472 view->list = g_list_append(view->list, line); | |
473 | |
474 return widget; | |
475 } | |
476 | |
477 void gnt_text_view_append_text_with_flags(GntTextView *view, const char *text, GntTextFormatFlags flags) | |
478 { | |
479 gnt_text_view_append_text_with_tag(view, text, flags, NULL); | |
480 } | |
481 | |
482 void gnt_text_view_append_text_with_tag(GntTextView *view, const char *text, | |
483 GntTextFormatFlags flags, const char *tagname) | |
484 { | |
485 GntWidget *widget = GNT_WIDGET(view); | |
486 int fl = 0; | |
487 const char *start, *end; | |
488 GList *list = view->list; | |
489 GntTextLine *line; | |
490 int len; | |
18315
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
491 gboolean has_scroll = !(view->flags & GNT_TEXT_VIEW_NO_SCROLL); |
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
492 gboolean wrap_word = !(view->flags & GNT_TEXT_VIEW_WRAP_CHAR); |
15817 | 493 |
494 if (text == NULL || *text == '\0') | |
495 return; | |
496 | |
497 fl = gnt_text_format_flag_to_chtype(flags); | |
498 | |
499 len = view->string->len; | |
500 view->string = g_string_append(view->string, text); | |
501 | |
502 if (tagname) { | |
503 GntTextTag *tag = g_new0(GntTextTag, 1); | |
504 tag->name = g_strdup(tagname); | |
505 tag->start = len; | |
506 tag->end = view->string->len; | |
507 view->tags = g_list_append(view->tags, tag); | |
508 } | |
509 | |
510 view->list = g_list_first(view->list); | |
511 | |
512 start = end = view->string->str + len; | |
513 | |
514 while (*start) { | |
16011
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
515 GntTextLine *oldl; |
15817 | 516 GntTextSegment *seg = NULL; |
517 | |
518 if (*end == '\n' || *end == '\r') { | |
16011
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
519 if (!strncmp(end, "\r\n", 2)) |
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
520 end++; |
15817 | 521 end++; |
522 start = end; | |
523 gnt_text_view_next_line(view); | |
524 view->list = g_list_first(view->list); | |
525 continue; | |
526 } | |
527 | |
528 line = view->list->data; | |
18315
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
529 if (line->length == widget->priv.width - has_scroll) { |
15817 | 530 /* The last added line was exactly the same width as the widget */ |
531 line = g_new0(GntTextLine, 1); | |
532 line->soft = TRUE; | |
533 view->list = g_list_prepend(view->list, line); | |
534 } | |
535 | |
16011
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
536 if ((end = strchr(start, '\r')) != NULL || |
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
537 (end = strchr(start, '\n')) != NULL) { |
18315
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
538 len = gnt_util_onscreen_width(start, end - has_scroll); |
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
539 if (len >= widget->priv.width - line->length - has_scroll) { |
15817 | 540 end = NULL; |
541 } | |
542 } | |
543 | |
544 if (end == NULL) | |
545 end = gnt_util_onscreen_width_to_pointer(start, | |
18315
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
546 widget->priv.width - line->length - has_scroll, &len); |
15817 | 547 |
548 /* Try to append to the previous segment if possible */ | |
549 if (line->segments) { | |
550 seg = g_list_last(line->segments)->data; | |
551 if (seg->flags != fl) | |
552 seg = NULL; | |
553 } | |
554 | |
555 if (seg == NULL) { | |
556 seg = g_new0(GntTextSegment, 1); | |
557 seg->start = start - view->string->str; | |
558 seg->tvflag = flags; | |
559 seg->flags = fl; | |
560 line->segments = g_list_append(line->segments, seg); | |
561 } | |
562 | |
16011
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
563 oldl = line; |
18315
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
564 if (wrap_word && *end && *end != '\n' && *end != '\r') { |
16011
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
565 const char *tmp = end; |
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
566 while (end && *end != '\n' && *end != '\r' && !g_ascii_isspace(*end)) { |
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
567 end = g_utf8_find_prev_char(seg->start + view->string->str, end); |
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
568 } |
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
569 if (!end || !g_ascii_isspace(*end)) |
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
570 end = tmp; |
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
571 else |
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
572 end++; /* Remove the space */ |
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
573 |
15817 | 574 line = g_new0(GntTextLine, 1); |
575 line->soft = TRUE; | |
576 view->list = g_list_prepend(view->list, line); | |
577 } | |
16011
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
578 seg->end = end - view->string->str; |
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
579 oldl->length += len; |
1f24fd9a6237
word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
580 start = end; |
15817 | 581 } |
582 | |
583 view->list = list; | |
584 | |
585 gnt_widget_draw(widget); | |
586 } | |
587 | |
588 void gnt_text_view_scroll(GntTextView *view, int scroll) | |
589 { | |
590 if (scroll == 0) | |
591 { | |
592 view->list = g_list_first(view->list); | |
593 } | |
594 else if (scroll > 0) | |
595 { | |
596 GList *list = g_list_nth_prev(view->list, scroll); | |
597 if (list == NULL) | |
598 list = g_list_first(view->list); | |
599 view->list = list; | |
600 } | |
601 else if (scroll < 0) | |
602 { | |
603 GList *list = g_list_nth(view->list, -scroll); | |
604 if (list == NULL) | |
605 list = g_list_last(view->list); | |
606 view->list = list; | |
607 } | |
608 | |
609 gnt_widget_draw(GNT_WIDGET(view)); | |
610 } | |
611 | |
612 void gnt_text_view_next_line(GntTextView *view) | |
613 { | |
614 GntTextLine *line = g_new0(GntTextLine, 1); | |
615 GList *list = view->list; | |
616 | |
617 view->list = g_list_prepend(g_list_first(view->list), line); | |
618 view->list = list; | |
619 gnt_widget_draw(GNT_WIDGET(view)); | |
620 } | |
621 | |
622 chtype gnt_text_format_flag_to_chtype(GntTextFormatFlags flags) | |
623 { | |
624 chtype fl = 0; | |
625 | |
626 if (flags & GNT_TEXT_FLAG_BOLD) | |
627 fl |= A_BOLD; | |
628 if (flags & GNT_TEXT_FLAG_UNDERLINE) | |
629 fl |= A_UNDERLINE; | |
630 if (flags & GNT_TEXT_FLAG_BLINK) | |
631 fl |= A_BLINK; | |
632 | |
633 if (flags & GNT_TEXT_FLAG_DIM) | |
634 fl |= (A_DIM | COLOR_PAIR(GNT_COLOR_DISABLED)); | |
635 else if (flags & GNT_TEXT_FLAG_HIGHLIGHT) | |
636 fl |= (A_DIM | COLOR_PAIR(GNT_COLOR_HIGHLIGHT)); | |
637 else | |
638 fl |= COLOR_PAIR(GNT_COLOR_NORMAL); | |
639 | |
640 return fl; | |
641 } | |
642 | |
643 void gnt_text_view_clear(GntTextView *view) | |
644 { | |
645 GntTextLine *line; | |
646 | |
647 g_list_foreach(view->list, free_text_line, NULL); | |
648 g_list_free(view->list); | |
649 view->list = NULL; | |
650 | |
651 line = g_new0(GntTextLine, 1); | |
652 view->list = g_list_append(view->list, line); | |
653 if (view->string) | |
654 g_string_free(view->string, TRUE); | |
655 view->string = g_string_new(NULL); | |
656 | |
657 if (GNT_WIDGET(view)->window) | |
658 gnt_widget_draw(GNT_WIDGET(view)); | |
659 } | |
660 | |
661 int gnt_text_view_get_lines_below(GntTextView *view) | |
662 { | |
663 int below = 0; | |
664 GList *list = view->list; | |
665 while ((list = list->prev)) | |
666 ++below; | |
667 return below; | |
668 } | |
669 | |
670 int gnt_text_view_get_lines_above(GntTextView *view) | |
671 { | |
672 int above = 0; | |
673 GList *list = view->list; | |
674 list = g_list_nth(view->list, GNT_WIDGET(view)->priv.height); | |
675 if (!list) | |
676 return 0; | |
677 while ((list = list->next)) | |
678 ++above; | |
679 return above; | |
680 } | |
681 | |
682 /** | |
683 * XXX: There are quite possibly more than a few bugs here. | |
684 */ | |
685 int gnt_text_view_tag_change(GntTextView *view, const char *name, const char *text, gboolean all) | |
686 { | |
687 GList *alllines = g_list_first(view->list); | |
688 GList *list, *next, *iter, *inext; | |
689 const int text_length = text ? strlen(text) : 0; | |
690 int count = 0; | |
691 for (list = view->tags; list; list = next) { | |
692 GntTextTag *tag = list->data; | |
693 next = list->next; | |
694 if (strcmp(tag->name, name) == 0) { | |
695 int change; | |
696 char *before, *after; | |
697 | |
698 count++; | |
699 | |
700 before = g_strndup(view->string->str, tag->start); | |
701 after = g_strdup(view->string->str + tag->end); | |
702 change = (tag->end - tag->start) - text_length; | |
703 | |
704 g_string_printf(view->string, "%s%s%s", before, text ? text : "", after); | |
705 g_free(before); | |
706 g_free(after); | |
707 | |
708 /* Update the offsets of the next tags */ | |
709 for (iter = next; iter; iter = iter->next) { | |
710 GntTextTag *t = iter->data; | |
711 t->start -= change; | |
712 t->end -= change; | |
713 } | |
714 | |
715 /* Update the offsets of the segments */ | |
716 for (iter = alllines; iter; iter = inext) { | |
717 GList *segs, *snext; | |
718 GntTextLine *line = iter->data; | |
719 inext = iter->next; | |
720 for (segs = line->segments; segs; segs = snext) { | |
721 GntTextSegment *seg = segs->data; | |
722 snext = segs->next; | |
723 if (seg->start >= tag->end) { | |
724 /* The segment is somewhere after the tag */ | |
725 seg->start -= change; | |
726 seg->end -= change; | |
727 } else if (seg->end <= tag->start) { | |
728 /* This segment is somewhere in front of the tag */ | |
729 } else if (seg->start >= tag->start) { | |
730 /* This segment starts in the middle of the tag */ | |
731 if (text == NULL) { | |
732 free_text_segment(seg, NULL); | |
733 line->segments = g_list_delete_link(line->segments, segs); | |
734 if (line->segments == NULL) { | |
735 free_text_line(line, NULL); | |
736 if (view->list == iter) { | |
737 if (inext) | |
738 view->list = inext; | |
739 else | |
740 view->list = iter->prev; | |
741 } | |
742 alllines = g_list_delete_link(alllines, iter); | |
743 } | |
744 } else { | |
745 /* XXX: (null) */ | |
746 seg->start = tag->start; | |
747 seg->end = tag->end - change; | |
748 } | |
749 line->length -= change; | |
750 /* XXX: Make things work if the tagged text spans over several lines. */ | |
751 } else { | |
752 /* XXX: handle the rest of the conditions */ | |
753 g_printerr("WTF! This needs to be handled properly!!\n"); | |
754 } | |
755 } | |
756 } | |
757 if (text == NULL) { | |
758 /* Remove the tag */ | |
759 view->tags = g_list_delete_link(view->tags, list); | |
760 free_tag(tag, NULL); | |
761 } else { | |
762 tag->end -= change; | |
763 } | |
764 if (!all) | |
765 break; | |
766 } | |
767 } | |
768 return count; | |
769 } | |
770 | |
16124
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
771 static gboolean |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
772 scroll_tv(GntWidget *wid, const char *key, GntTextView *tv) |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
773 { |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
774 if (strcmp(key, GNT_KEY_PGUP) == 0) { |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
775 gnt_text_view_scroll(tv, -(GNT_WIDGET(tv)->priv.height - 2)); |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
776 } else if (strcmp(key, GNT_KEY_PGDOWN) == 0) { |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
777 gnt_text_view_scroll(tv, GNT_WIDGET(tv)->priv.height - 2); |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
778 } else if (strcmp(key, GNT_KEY_DOWN) == 0) { |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
779 gnt_text_view_scroll(tv, 1); |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
780 } else if (strcmp(key, GNT_KEY_UP) == 0) { |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
781 gnt_text_view_scroll(tv, -1); |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
782 } else { |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
783 return FALSE; |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
784 } |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
785 return TRUE; |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
786 } |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
787 |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
788 void gnt_text_view_attach_scroll_widget(GntTextView *view, GntWidget *widget) |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
789 { |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
790 g_signal_connect(G_OBJECT(widget), "key_pressed", G_CALLBACK(scroll_tv), view); |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
791 } |
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16011
diff
changeset
|
792 |
18315
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
793 void gnt_text_view_set_flag(GntTextView *view, GntTextViewFlag flag) |
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
794 { |
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
795 view->flags |= flag; |
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
796 } |
e659842fe66d
Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18049
diff
changeset
|
797 |
18426
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
798 static gboolean |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
799 check_for_pager_cb(GntWidget *widget, const char *key, GntTextView *view) |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
800 { |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
801 static const char *combin = NULL; |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
802 char *argv[] = {NULL, NULL, NULL}; |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
803 static char path[1024]; |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
804 static int len = -1; |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
805 FILE *file; |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
806 |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
807 if (combin == NULL) { |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
808 combin = gnt_key_translate(gnt_style_get_from_name("pager", "key")); |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
809 if (combin == NULL) |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
810 combin = "\033" "v"; |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
811 len = g_snprintf(path, sizeof(path), "%s" G_DIR_SEPARATOR_S "gnt", g_get_tmp_dir()); |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
812 } else { |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
813 g_snprintf(path + len, sizeof(path) - len, "XXXXXX"); |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
814 } |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
815 |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
816 if (strcmp(key, combin)) { |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
817 return FALSE; |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
818 } |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
819 |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
820 file = fdopen(g_mkstemp(path), "wb"); |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
821 if (!file) |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
822 return FALSE; |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
823 |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
824 fprintf(file, "%s", view->string->str); |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
825 fclose(file); |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
826 argv[0] = gnt_style_get_from_name("pager", "path"); |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
827 argv[0] = argv[0] ? argv[0] : getenv("PAGER"); |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
828 argv[0] = argv[0] ? argv[0] : "less"; |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
829 argv[1] = path; |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
830 return gnt_giveup_console(NULL, argv, NULL, NULL, NULL, NULL); |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
831 } |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
832 |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
833 void gnt_text_view_attach_pager_widget(GntTextView *view, GntWidget *pager) |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
834 { |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
835 g_signal_connect(pager, "key_pressed", G_CALLBACK(check_for_pager_cb), view); |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
836 } |
841670dd24e1
Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18315
diff
changeset
|
837 |