finch/libgnt/gnttextview.c

Thu, 31 Jan 2008 07:53:22 +0000

author
Mark Doliner <markdoliner@pidgin.im>
date
Thu, 31 Jan 2008 07:53:22 +0000
changeset 22362
cb8ef3599f3d
parent 22104
56970903b8e9
child 24816
bd870d9ff0ab
permissions
-rw-r--r--

Fix some minor 'make docs' errors. For some reason the callback
parameters for the functions in pidgi/pidgintooltip.c have different
names than those in pidgin/pidgintooltip.h, but I left it.

17586
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16186
diff changeset
1 /**
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16186
diff changeset
2 * GNT - The GLib Ncurses Toolkit
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16186
diff changeset
3 *
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16186
diff changeset
4 * GNT is the legal property of its developers, whose names are too numerous
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16186
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16186
diff changeset
6 * source distribution.
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16186
diff changeset
7 *
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16186
diff changeset
8 * This library is free software; you can redistribute it and/or modify
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16186
diff changeset
9 * it under the terms of the GNU General Public License as published by
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16186
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16186
diff changeset
11 * (at your option) any later version.
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16186
diff changeset
12 *
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16186
diff changeset
13 * This program is distributed in the hope that it will be useful,
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16186
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16186
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16186
diff changeset
16 * GNU General Public License for more details.
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16186
diff changeset
17 *
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16186
diff changeset
18 * You should have received a copy of the GNU General Public License
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16186
diff changeset
19 * along with this program; if not, write to the Free Software
19859
71d37b57eff2 The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19556
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
17586
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16186
diff changeset
21 */
5beb8d987e84 applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16186
diff changeset
22
18604
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
23 #include "gntstyle.h"
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
24 #include "gnttextview.h"
14373
609c902d20f5 [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14284
diff changeset
25 #include "gntutils.h"
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
26
18604
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
27 #include <stdlib.h>
14460
ec99f8f548a7 [gaim-migrate @ 17106]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14459
diff changeset
28 #include <string.h>
18778
7cf5400593b8 Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18604
diff changeset
29 #include <unistd.h>
14460
ec99f8f548a7 [gaim-migrate @ 17106]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14459
diff changeset
30
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
31 enum
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
32 {
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
33 SIGS = 1,
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
34 };
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
35
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
36 typedef struct
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
37 {
14433
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
38 GntTextFormatFlags tvflag;
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
39 chtype flags;
14445
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
40 int start;
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
41 int end; /* This is the next byte of the last character of this segment */
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
42 } GntTextSegment;
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
43
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
44 typedef struct
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
45 {
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
46 GList *segments; /* A list of GntTextSegments */
14373
609c902d20f5 [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14284
diff changeset
47 int length; /* The current length of the line so far (ie. onscreen width) */
14433
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
48 gboolean soft; /* TRUE if it's an overflow from prev. line */
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
49 } GntTextLine;
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
50
15233
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
51 typedef struct
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
52 {
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
53 char *name;
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
54 int start;
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
55 int end;
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
56 } GntTextTag;
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
57
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
58 static GntWidgetClass *parent_class = NULL;
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
59
15814
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
60 static gchar *select_start;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
61 static gchar *select_end;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
62 static gboolean double_click;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
63
21473
ecbc011dbe22 Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21240
diff changeset
64 static void reset_text_view(GntTextView *view);
ecbc011dbe22 Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21240
diff changeset
65
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
66 static void
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
67 gnt_text_view_draw(GntWidget *widget)
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
68 {
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
69 GntTextView *view = GNT_TEXT_VIEW(widget);
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
70 int i = 0;
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
71 GList *lines;
14193
fcfd3eea2160 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14185
diff changeset
72 int rows, scrcol;
19183
aee7b7ad425e New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19174
diff changeset
73 int comp = 0; /* Used for top-aligned text */
18368
ffeff952aa09 Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17586
diff changeset
74 gboolean has_scroll = !(view->flags & GNT_TEXT_VIEW_NO_SCROLL);
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
75
21240
b78eaddaae02 Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19859
diff changeset
76 wbkgd(widget->window, gnt_color_pair(GNT_COLOR_NORMAL));
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
77 werase(widget->window);
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
78
19183
aee7b7ad425e New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19174
diff changeset
79 if ((view->flags & GNT_TEXT_VIEW_TOP_ALIGN) &&
aee7b7ad425e New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19174
diff changeset
80 g_list_length(view->list) < widget->priv.height) {
aee7b7ad425e New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19174
diff changeset
81 GList *now = view->list;
aee7b7ad425e New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19174
diff changeset
82 comp = widget->priv.height - g_list_length(view->list);
aee7b7ad425e New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19174
diff changeset
83 view->list = g_list_nth_prev(view->list, comp);
aee7b7ad425e New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19174
diff changeset
84 if (!view->list) {
aee7b7ad425e New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19174
diff changeset
85 view->list = g_list_first(now);
aee7b7ad425e New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19174
diff changeset
86 comp = widget->priv.height - g_list_length(view->list);
aee7b7ad425e New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19174
diff changeset
87 } else {
aee7b7ad425e New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19174
diff changeset
88 comp = 0;
aee7b7ad425e New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19174
diff changeset
89 }
aee7b7ad425e New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19174
diff changeset
90 }
aee7b7ad425e New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19174
diff changeset
91
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
92 for (i = 0, lines = view->list; i < widget->priv.height && lines; i++, lines = lines->next)
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
93 {
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
94 GList *iter;
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
95 GntTextLine *line = lines->data;
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
96
19183
aee7b7ad425e New flag to show text top-aligned in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19174
diff changeset
97 wmove(widget->window, widget->priv.height - 1 - i - comp, 0);
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
98
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
99 for (iter = line->segments; iter; iter = iter->next)
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
100 {
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
101 GntTextSegment *seg = iter->data;
14445
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
102 char *end = view->string->str + seg->end;
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
103 char back = *end;
15814
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
104 chtype fl = seg->flags;
14445
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
105 *end = '\0';
15814
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
106 if (select_start < view->string->str + seg->start && select_end > view->string->str + seg->end) {
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
107 fl |= A_REVERSE;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
108 wattrset(widget->window, fl);
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
109 wprintw(widget->window, "%s", (view->string->str + seg->start));
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
110 } else if (select_start && select_end &&
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
111 ((select_start >= view->string->str + seg->start && select_start <= view->string->str + seg->end) ||
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
112 (select_end <= view->string->str + seg->end && select_start <= view->string->str + seg->start))) {
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
113 char *cur = view->string->str + seg->start;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
114 while (*cur != '\0') {
15837
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
115 gchar *last = g_utf8_next_char(cur);
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
116 gchar *str;
15814
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
117 if (cur >= select_start && cur <= select_end)
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
118 fl |= A_REVERSE;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
119 else
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
120 fl = seg->flags;
15837
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
121 str = g_strndup(cur, last - cur);
15814
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
122 wattrset(widget->window, fl);
15837
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
123 waddstr(widget->window, str);
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
124 g_free(str);
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
125 cur = g_utf8_next_char(cur);
15814
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
126 }
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
127 } else {
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
128 wattrset(widget->window, fl);
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
129 wprintw(widget->window, "%s", (view->string->str + seg->start));
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
130 }
14445
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
131 *end = back;
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
132 }
14789
393afacddb71 [gaim-migrate @ 17482]
Richard Nelson <wabz@pidgin.im>
parents: 14494
diff changeset
133 wattroff(widget->window, A_UNDERLINE | A_BLINK | A_REVERSE);
18368
ffeff952aa09 Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17586
diff changeset
134 whline(widget->window, ' ', widget->priv.width - line->length - has_scroll);
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
135 }
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
136
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
137 scrcol = widget->priv.width - 1;
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
138 rows = widget->priv.height - 2;
18368
ffeff952aa09 Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17586
diff changeset
139 if (has_scroll && rows > 0)
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
140 {
14193
fcfd3eea2160 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14185
diff changeset
141 int total = g_list_length(g_list_first(view->list));
fcfd3eea2160 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14185
diff changeset
142 int showing, position, up, down;
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
143
14193
fcfd3eea2160 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14185
diff changeset
144 showing = rows * rows / total + 1;
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
145 showing = MIN(rows, showing);
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
146
14193
fcfd3eea2160 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14185
diff changeset
147 total -= rows;
fcfd3eea2160 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14185
diff changeset
148 up = g_list_length(lines);
fcfd3eea2160 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14185
diff changeset
149 down = total - up;
fcfd3eea2160 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14185
diff changeset
150
fcfd3eea2160 [gaim-migrate @ 16773]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14185
diff changeset
151 position = (rows - showing) * up / MAX(1, up + down);
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
152 position = MAX((lines != NULL), position);
14169
90d1d4697e23 [gaim-migrate @ 16741]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14094
diff changeset
153
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
154 if (showing + position > rows)
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
155 position = rows - showing;
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
156
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
157 if (showing + position == rows && view->list && view->list->prev)
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
158 position = MAX(1, rows - 1 - showing);
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
159 else if (showing + position < rows && view->list && !view->list->prev)
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
160 position = rows - showing;
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
161
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
162 mvwvline(widget->window, position + 1, scrcol,
21240
b78eaddaae02 Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19859
diff changeset
163 ACS_CKBOARD | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D), showing);
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
164 }
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
165
18368
ffeff952aa09 Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17586
diff changeset
166 if (has_scroll) {
ffeff952aa09 Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17586
diff changeset
167 mvwaddch(widget->window, 0, scrcol,
21240
b78eaddaae02 Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19859
diff changeset
168 (lines ? ACS_UARROW : ' ') | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D));
18368
ffeff952aa09 Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17586
diff changeset
169 mvwaddch(widget->window, widget->priv.height - 1, scrcol,
ffeff952aa09 Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17586
diff changeset
170 ((view->list && view->list->prev) ? ACS_DARROW : ' ') |
21240
b78eaddaae02 Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19859
diff changeset
171 gnt_color_pair(GNT_COLOR_HIGHLIGHT_D));
18368
ffeff952aa09 Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17586
diff changeset
172 }
14169
90d1d4697e23 [gaim-migrate @ 16741]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14094
diff changeset
173
14494
3575eac3a518 [gaim-migrate @ 17146]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14461
diff changeset
174 GNTDEBUG;
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
175 }
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
176
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
177 static void
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
178 gnt_text_view_size_request(GntWidget *widget)
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
179 {
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
180 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_MAPPED))
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
181 {
14461
ed494fb68279 [gaim-migrate @ 17107]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14460
diff changeset
182 gnt_widget_set_size(widget, 64, 20);
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
183 }
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
184 }
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
185
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
186 static void
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
187 gnt_text_view_map(GntWidget *widget)
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
188 {
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
189 if (widget->priv.width == 0 || widget->priv.height == 0)
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
190 gnt_widget_size_request(widget);
14494
3575eac3a518 [gaim-migrate @ 17146]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14461
diff changeset
191 GNTDEBUG;
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
192 }
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
193
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
194 static gboolean
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
195 gnt_text_view_key_pressed(GntWidget *widget, const char *text)
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
196 {
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
197 return FALSE;
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
198 }
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
199
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
200 static void
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
201 free_text_segment(gpointer data, gpointer null)
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
202 {
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
203 GntTextSegment *seg = data;
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
204 g_free(seg);
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
205 }
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
206
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
207 static void
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
208 free_text_line(gpointer data, gpointer null)
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
209 {
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
210 GntTextLine *line = data;
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
211 g_list_foreach(line->segments, free_text_segment, NULL);
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
212 g_list_free(line->segments);
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
213 g_free(line);
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
214 }
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
215
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
216 static void
15233
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
217 free_tag(gpointer data, gpointer null)
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
218 {
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
219 GntTextTag *tag = data;
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
220 g_free(tag->name);
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
221 g_free(tag);
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
222 }
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
223
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
224 static void
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
225 gnt_text_view_destroy(GntWidget *widget)
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
226 {
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
227 GntTextView *view = GNT_TEXT_VIEW(widget);
14092
191e12cbe464 [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
228 view->list = g_list_first(view->list);
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
229 g_list_foreach(view->list, free_text_line, NULL);
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
230 g_list_free(view->list);
15233
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
231 g_list_foreach(view->tags, free_tag, NULL);
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
232 g_list_free(view->tags);
14445
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
233 g_string_free(view->string, TRUE);
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
234 }
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
235
15814
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
236 static char *
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
237 gnt_text_view_get_p(GntTextView *view, int x, int y)
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
238 {
15837
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
239 int i = 0;
15814
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
240 GntWidget *wid = GNT_WIDGET(view);
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
241 GntTextLine *line;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
242 GList *lines;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
243 GList *segs;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
244 GntTextSegment *seg;
15837
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
245 gchar *pos;
15814
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
246
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
247 y = wid->priv.height - y;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
248 if (g_list_length(view->list) < y) {
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
249 x = 0;
15837
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
250 y = g_list_length(view->list) - 1;
15814
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
251 }
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
252
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
253 lines = g_list_nth(view->list, y - 1);
15837
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
254 if (!lines)
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
255 return NULL;
15824
94b08838e069 Cute little mod.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15814
diff changeset
256 do {
94b08838e069 Cute little mod.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15814
diff changeset
257 line = lines->data;
94b08838e069 Cute little mod.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15814
diff changeset
258 lines = lines->next;
15826
273b7247786b Fix a crash when selecting text in an empty TV.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15824
diff changeset
259 } while (line && !line->segments && lines);
15814
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
260
15826
273b7247786b Fix a crash when selecting text in an empty TV.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15824
diff changeset
261 if (!line || !line->segments) /* no valid line */
15814
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
262 return NULL;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
263 segs = line->segments;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
264 seg = (GntTextSegment *)segs->data;
15837
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
265 pos = view->string->str + seg->start;
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
266 x = MIN(x, line->length);
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
267 while (++i <= x) {
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
268 gunichar *u;
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
269 pos = g_utf8_next_char(pos);
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
270 u = g_utf8_to_ucs4(pos, -1, NULL, NULL, NULL);
15866
3f58d8094334 g_unichar_iswide_cjk() is only in glib 2.12 and newer, and I suspect
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15837
diff changeset
271 if (u && g_unichar_iswide(*u))
15837
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
272 i++;
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
273 g_free(u);
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
274 }
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
275 return pos;
15814
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
276 }
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
277
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
278 static GString *
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
279 select_word_text(GntTextView *view, gchar *c)
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
280 {
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
281 gchar *start = c;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
282 gchar *end = c;
15837
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
283 gchar *t, *endsize;
15874
46df7421a1b5 Enable DEBUG_CFLAGS in libgnt and fix up a number of compile warnings and
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15866
diff changeset
284 while ((t = g_utf8_prev_char(start))) {
15814
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
285 if (!g_ascii_isspace(*t)) {
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
286 if (start == view->string->str)
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
287 break;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
288 start = t;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
289 } else
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
290 break;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
291 }
15874
46df7421a1b5 Enable DEBUG_CFLAGS in libgnt and fix up a number of compile warnings and
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15866
diff changeset
292 while ((t = g_utf8_next_char(end))) {
15814
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
293 if (!g_ascii_isspace(*t))
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
294 end = t;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
295 else
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
296 break;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
297 }
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
298 select_start = start;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
299 select_end = end;
15837
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
300 endsize = g_utf8_next_char(select_end); /* End at the correct byte */
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
301 return g_string_new_len(start, endsize - start);
15814
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
302 }
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
303
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
304 static gboolean too_slow(gpointer n)
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
305 {
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
306 double_click = FALSE;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
307 return FALSE;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
308 }
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
309
14405
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14373
diff changeset
310 static gboolean
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14373
diff changeset
311 gnt_text_view_clicked(GntWidget *widget, GntMouseEvent event, int x, int y)
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14373
diff changeset
312 {
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14373
diff changeset
313 if (event == GNT_MOUSE_SCROLL_UP) {
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14373
diff changeset
314 gnt_text_view_scroll(GNT_TEXT_VIEW(widget), -1);
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14373
diff changeset
315 } else if (event == GNT_MOUSE_SCROLL_DOWN) {
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14373
diff changeset
316 gnt_text_view_scroll(GNT_TEXT_VIEW(widget), 1);
15814
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
317 } else if (event == GNT_LEFT_MOUSE_DOWN) {
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
318 select_start = gnt_text_view_get_p(GNT_TEXT_VIEW(widget), x - widget->priv.x, y - widget->priv.y);
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
319 g_timeout_add(500, too_slow, NULL);
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
320 } else if (event == GNT_MOUSE_UP) {
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
321 if (select_start) {
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
322 GString *clip;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
323 select_end = gnt_text_view_get_p(GNT_TEXT_VIEW(widget), x - widget->priv.x, y - widget->priv.y);
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
324 if (select_end < select_start) {
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
325 gchar *t = select_start;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
326 select_start = select_end;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
327 select_end = t;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
328 }
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
329 if (select_start == select_end) {
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
330 if (double_click) {
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
331 clip = select_word_text(GNT_TEXT_VIEW(widget), select_start);
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
332 double_click = FALSE;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
333 } else {
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
334 double_click = TRUE;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
335 select_start = 0;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
336 select_end = 0;
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
337 gnt_widget_draw(widget);
15874
46df7421a1b5 Enable DEBUG_CFLAGS in libgnt and fix up a number of compile warnings and
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15866
diff changeset
338 return TRUE;
15814
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
339 }
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
340 } else {
15837
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
341 gchar *endsize = g_utf8_next_char(select_end); /* End at the correct byte */
7718f3b6f643 Display selected double-width cell chars properly and select the correct number of bytes when these characters are on a selection line.
Richard Nelson <wabz@pidgin.im>
parents: 15826
diff changeset
342 clip = g_string_new_len(select_start, endsize - select_start);
15814
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
343 }
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
344 gnt_widget_draw(widget);
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
345 gnt_set_clipboard_string(clip->str);
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
346 g_string_free(clip, TRUE);
2db42c6a13fa Add a gntclipboard. You can select text in a textview with the mouse, and paste it in an entry with ctrl-v (or rebind GntEntry's clipboard-paste).
Richard Nelson <wabz@pidgin.im>
parents: 15397
diff changeset
347 }
14405
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14373
diff changeset
348 } else
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14373
diff changeset
349 return FALSE;
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14373
diff changeset
350 return TRUE;
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14373
diff changeset
351 }
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14373
diff changeset
352
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
353 static void
14433
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
354 gnt_text_view_reflow(GntTextView *view)
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
355 {
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
356 /* This is pretty ugly, and inefficient. Someone do something about it. */
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
357 GntTextLine *line;
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
358 GList *back, *iter, *list;
14445
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
359 GString *string;
14888
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
360 int pos = 0; /* no. of 'real' lines */
14433
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
361
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
362 list = view->list;
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
363 while (list->prev) {
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
364 line = list->data;
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
365 if (!line->soft)
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
366 pos++;
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
367 list = list->prev;
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
368 }
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
369
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
370 back = g_list_last(view->list);
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
371 view->list = NULL;
14445
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
372
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
373 string = view->string;
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
374 view->string = NULL;
21473
ecbc011dbe22 Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21240
diff changeset
375 reset_text_view(view);
14433
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
376
14445
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
377 view->string = g_string_set_size(view->string, string->len);
14888
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
378 view->string->len = 0;
14445
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
379 GNT_WIDGET_SET_FLAGS(GNT_WIDGET(view), GNT_WIDGET_DRAWING);
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
380
14433
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
381 for (; back; back = back->prev) {
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
382 line = back->data;
14445
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
383 if (back->next && !line->soft) {
14888
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
384 gnt_text_view_append_text_with_flags(view, "\n", GNT_TEXT_FLAG_NORMAL);
14445
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
385 }
14888
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
386
14433
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
387 for (iter = line->segments; iter; iter = iter->next) {
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
388 GntTextSegment *seg = iter->data;
14445
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
389 char *start = string->str + seg->start;
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
390 char *end = string->str + seg->end;
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
391 char back = *end;
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
392 *end = '\0';
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
393 gnt_text_view_append_text_with_flags(view, start, seg->tvflag);
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
394 *end = back;
14433
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
395 }
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
396 free_text_line(line, NULL);
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
397 }
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
398 g_list_free(list);
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
399
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
400 list = view->list = g_list_first(view->list);
14888
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
401 /* Go back to the line that was in view before resizing started */
14433
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
402 while (pos--) {
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
403 while (((GntTextLine*)list->data)->soft)
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
404 list = list->next;
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
405 list = list->next;
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
406 }
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
407 view->list = list;
14445
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
408 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(view), GNT_WIDGET_DRAWING);
14943
ffd493362a87 [gaim-migrate @ 17650]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14888
diff changeset
409 if (GNT_WIDGET(view)->window)
ffd493362a87 [gaim-migrate @ 17650]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14888
diff changeset
410 gnt_widget_draw(GNT_WIDGET(view));
14445
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
411 g_string_free(string, TRUE);
14433
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
412 }
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
413
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
414 static void
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
415 gnt_text_view_size_changed(GntWidget *widget, int w, int h)
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
416 {
19174
fdbcb1c0c449 Initialize the gobject in a more appropriate place. And fix an error message.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18791
diff changeset
417 if (w != widget->priv.width && GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_MAPPED)) {
14433
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
418 gnt_text_view_reflow(GNT_TEXT_VIEW(widget));
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
419 }
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
420 }
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
421
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
422 static void
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
423 gnt_text_view_class_init(GntTextViewClass *klass)
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
424 {
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
425 parent_class = GNT_WIDGET_CLASS(klass);
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
426 parent_class->destroy = gnt_text_view_destroy;
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
427 parent_class->draw = gnt_text_view_draw;
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
428 parent_class->map = gnt_text_view_map;
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
429 parent_class->size_request = gnt_text_view_size_request;
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
430 parent_class->key_pressed = gnt_text_view_key_pressed;
14405
4398121ce889 [gaim-migrate @ 17044]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14373
diff changeset
431 parent_class->clicked = gnt_text_view_clicked;
14433
69975e91d8ca [gaim-migrate @ 17077]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14405
diff changeset
432 parent_class->size_changed = gnt_text_view_size_changed;
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
433
14494
3575eac3a518 [gaim-migrate @ 17146]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14461
diff changeset
434 GNTDEBUG;
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
435 }
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
436
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
437 static void
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
438 gnt_text_view_init(GTypeInstance *instance, gpointer class)
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
439 {
14005
198d1658b390 [gaim-migrate @ 16480]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13993
diff changeset
440 GntWidget *widget = GNT_WIDGET(instance);
19174
fdbcb1c0c449 Initialize the gobject in a more appropriate place. And fix an error message.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18791
diff changeset
441 GntTextView *view = GNT_TEXT_VIEW(widget);
fdbcb1c0c449 Initialize the gobject in a more appropriate place. And fix an error message.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18791
diff changeset
442 GntTextLine *line = g_new0(GntTextLine, 1);
14005
198d1658b390 [gaim-migrate @ 16480]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13993
diff changeset
443
19174
fdbcb1c0c449 Initialize the gobject in a more appropriate place. And fix an error message.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18791
diff changeset
444 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW |
fdbcb1c0c449 Initialize the gobject in a more appropriate place. And fix an error message.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18791
diff changeset
445 GNT_WIDGET_GROW_Y | GNT_WIDGET_GROW_X);
14005
198d1658b390 [gaim-migrate @ 16480]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13993
diff changeset
446 widget->priv.minw = 5;
14185
394aa8aa00a3 [gaim-migrate @ 16761]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14169
diff changeset
447 widget->priv.minh = 2;
19174
fdbcb1c0c449 Initialize the gobject in a more appropriate place. And fix an error message.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18791
diff changeset
448 view->string = g_string_new(NULL);
fdbcb1c0c449 Initialize the gobject in a more appropriate place. And fix an error message.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18791
diff changeset
449 view->list = g_list_append(view->list, line);
fdbcb1c0c449 Initialize the gobject in a more appropriate place. And fix an error message.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18791
diff changeset
450
14494
3575eac3a518 [gaim-migrate @ 17146]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14461
diff changeset
451 GNTDEBUG;
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
452 }
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
453
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
454 /******************************************************************************
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
455 * GntTextView API
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
456 *****************************************************************************/
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
457 GType
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
458 gnt_text_view_get_gtype(void)
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
459 {
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
460 static GType type = 0;
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
461
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
462 if(type == 0)
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
463 {
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
464 static const GTypeInfo info = {
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
465 sizeof(GntTextViewClass),
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
466 NULL, /* base_init */
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
467 NULL, /* base_finalize */
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
468 (GClassInitFunc)gnt_text_view_class_init,
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
469 NULL, /* class_finalize */
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
470 NULL, /* class_data */
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
471 sizeof(GntTextView),
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
472 0, /* n_preallocs */
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
473 gnt_text_view_init, /* instance_init */
15874
46df7421a1b5 Enable DEBUG_CFLAGS in libgnt and fix up a number of compile warnings and
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15866
diff changeset
474 NULL /* value_table */
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
475 };
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
476
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
477 type = g_type_register_static(GNT_TYPE_WIDGET,
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
478 "GntTextView",
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
479 &info, 0);
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
480 }
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
481
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
482 return type;
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
483 }
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
484
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
485 GntWidget *gnt_text_view_new()
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
486 {
15991
1efb6bd8ba3f Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15906
diff changeset
487 GntWidget *widget = g_object_new(GNT_TYPE_TEXT_VIEW, NULL);
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
488
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
489 return widget;
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
490 }
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
491
13993
8c12e7d15b40 [gaim-migrate @ 16458]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13992
diff changeset
492 void gnt_text_view_append_text_with_flags(GntTextView *view, const char *text, GntTextFormatFlags flags)
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
493 {
15233
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
494 gnt_text_view_append_text_with_tag(view, text, flags, NULL);
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
495 }
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
496
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
497 void gnt_text_view_append_text_with_tag(GntTextView *view, const char *text,
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
498 GntTextFormatFlags flags, const char *tagname)
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
499 {
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
500 GntWidget *widget = GNT_WIDGET(view);
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
501 int fl = 0;
14445
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
502 const char *start, *end;
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
503 GList *list = view->list;
14445
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
504 GntTextLine *line;
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
505 int len;
18368
ffeff952aa09 Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17586
diff changeset
506 gboolean has_scroll = !(view->flags & GNT_TEXT_VIEW_NO_SCROLL);
ffeff952aa09 Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17586
diff changeset
507 gboolean wrap_word = !(view->flags & GNT_TEXT_VIEW_WRAP_CHAR);
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
508
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
509 if (text == NULL || *text == '\0')
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
510 return;
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
511
14014
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
512 fl = gnt_text_format_flag_to_chtype(flags);
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
513
14445
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
514 len = view->string->len;
14888
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
515 view->string = g_string_append(view->string, text);
14445
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
516
15233
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
517 if (tagname) {
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
518 GntTextTag *tag = g_new0(GntTextTag, 1);
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
519 tag->name = g_strdup(tagname);
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
520 tag->start = len;
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
521 tag->end = view->string->len;
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
522 view->tags = g_list_append(view->tags, tag);
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
523 }
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
524
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
525 view->list = g_list_first(view->list);
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
526
14445
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
527 start = end = view->string->str + len;
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
528
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
529 while (*start) {
16072
4902da58e498 word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents: 15991
diff changeset
530 GntTextLine *oldl;
14888
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
531 GntTextSegment *seg = NULL;
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
532
14445
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
533 if (*end == '\n' || *end == '\r') {
16072
4902da58e498 word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents: 15991
diff changeset
534 if (!strncmp(end, "\r\n", 2))
4902da58e498 word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents: 15991
diff changeset
535 end++;
14445
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
536 end++;
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
537 start = end;
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
538 gnt_text_view_next_line(view);
14460
ec99f8f548a7 [gaim-migrate @ 17106]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14459
diff changeset
539 view->list = g_list_first(view->list);
14445
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
540 continue;
14072
4e64a4f18686 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
541 }
4e64a4f18686 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
542
4e64a4f18686 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14033
diff changeset
543 line = view->list->data;
18368
ffeff952aa09 Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17586
diff changeset
544 if (line->length == widget->priv.width - has_scroll) {
14888
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
545 /* The last added line was exactly the same width as the widget */
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
546 line = g_new0(GntTextLine, 1);
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
547 line->soft = TRUE;
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
548 view->list = g_list_prepend(view->list, line);
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
549 }
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
550
16072
4902da58e498 word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents: 15991
diff changeset
551 if ((end = strchr(start, '\r')) != NULL ||
4902da58e498 word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents: 15991
diff changeset
552 (end = strchr(start, '\n')) != NULL) {
18368
ffeff952aa09 Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17586
diff changeset
553 len = gnt_util_onscreen_width(start, end - has_scroll);
19556
f0d09f854e6f Fix #2642 (GntTextView Multiline append goes weird)
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19235
diff changeset
554 if (widget->priv.width > 0 &&
f0d09f854e6f Fix #2642 (GntTextView Multiline append goes weird)
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19235
diff changeset
555 len >= widget->priv.width - line->length - has_scroll) {
14459
d2e639b92d79 [gaim-migrate @ 17105]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14445
diff changeset
556 end = NULL;
d2e639b92d79 [gaim-migrate @ 17105]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14445
diff changeset
557 }
d2e639b92d79 [gaim-migrate @ 17105]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14445
diff changeset
558 }
d2e639b92d79 [gaim-migrate @ 17105]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14445
diff changeset
559
d2e639b92d79 [gaim-migrate @ 17105]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14445
diff changeset
560 if (end == NULL)
d2e639b92d79 [gaim-migrate @ 17105]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14445
diff changeset
561 end = gnt_util_onscreen_width_to_pointer(start,
18368
ffeff952aa09 Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17586
diff changeset
562 widget->priv.width - line->length - has_scroll, &len);
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
563
14888
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
564 /* Try to append to the previous segment if possible */
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
565 if (line->segments) {
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
566 seg = g_list_last(line->segments)->data;
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
567 if (seg->flags != fl)
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
568 seg = NULL;
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
569 }
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
570
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
571 if (seg == NULL) {
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
572 seg = g_new0(GntTextSegment, 1);
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
573 seg->start = start - view->string->str;
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
574 seg->tvflag = flags;
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
575 seg->flags = fl;
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
576 line->segments = g_list_append(line->segments, seg);
aff7c674ca0f [gaim-migrate @ 17593]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14791
diff changeset
577 }
14373
609c902d20f5 [gaim-migrate @ 17001]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14284
diff changeset
578
16072
4902da58e498 word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents: 15991
diff changeset
579 oldl = line;
18368
ffeff952aa09 Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17586
diff changeset
580 if (wrap_word && *end && *end != '\n' && *end != '\r') {
16072
4902da58e498 word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents: 15991
diff changeset
581 const char *tmp = end;
4902da58e498 word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents: 15991
diff changeset
582 while (end && *end != '\n' && *end != '\r' && !g_ascii_isspace(*end)) {
4902da58e498 word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents: 15991
diff changeset
583 end = g_utf8_find_prev_char(seg->start + view->string->str, end);
4902da58e498 word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents: 15991
diff changeset
584 }
4902da58e498 word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents: 15991
diff changeset
585 if (!end || !g_ascii_isspace(*end))
4902da58e498 word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents: 15991
diff changeset
586 end = tmp;
4902da58e498 word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents: 15991
diff changeset
587 else
4902da58e498 word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents: 15991
diff changeset
588 end++; /* Remove the space */
4902da58e498 word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents: 15991
diff changeset
589
14445
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
590 line = g_new0(GntTextLine, 1);
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
591 line->soft = TRUE;
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
592 view->list = g_list_prepend(view->list, line);
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
593 }
16072
4902da58e498 word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents: 15991
diff changeset
594 seg->end = end - view->string->str;
4902da58e498 word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents: 15991
diff changeset
595 oldl->length += len;
4902da58e498 word wrapping, fix \r\n newlines
Richard Nelson <wabz@pidgin.im>
parents: 15991
diff changeset
596 start = end;
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
597 }
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
598
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
599 view->list = list;
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
600
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
601 gnt_widget_draw(widget);
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
602 }
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
603
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
604 void gnt_text_view_scroll(GntTextView *view, int scroll)
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
605 {
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
606 if (scroll == 0)
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
607 {
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
608 view->list = g_list_first(view->list);
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
609 }
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
610 else if (scroll > 0)
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
611 {
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
612 GList *list = g_list_nth_prev(view->list, scroll);
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
613 if (list == NULL)
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
614 list = g_list_first(view->list);
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
615 view->list = list;
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
616 }
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
617 else if (scroll < 0)
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
618 {
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
619 GList *list = g_list_nth(view->list, -scroll);
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
620 if (list == NULL)
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
621 list = g_list_last(view->list);
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
622 view->list = list;
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
623 }
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
624
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
625 gnt_widget_draw(GNT_WIDGET(view));
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
626 }
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
627
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
628 void gnt_text_view_next_line(GntTextView *view)
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
629 {
13958
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
630 GntTextLine *line = g_new0(GntTextLine, 1);
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
631 GList *list = view->list;
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
632
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
633 view->list = g_list_prepend(g_list_first(view->list), line);
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
634 view->list = list;
bd1c3bb3f33d [gaim-migrate @ 16381]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 13950
diff changeset
635 gnt_widget_draw(GNT_WIDGET(view));
13944
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
636 }
2269d17043b1 [gaim-migrate @ 16362]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
637
14014
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
638 chtype gnt_text_format_flag_to_chtype(GntTextFormatFlags flags)
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
639 {
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
640 chtype fl = 0;
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
641
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
642 if (flags & GNT_TEXT_FLAG_BOLD)
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
643 fl |= A_BOLD;
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
644 if (flags & GNT_TEXT_FLAG_UNDERLINE)
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
645 fl |= A_UNDERLINE;
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
646 if (flags & GNT_TEXT_FLAG_BLINK)
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
647 fl |= A_BLINK;
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
648
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
649 if (flags & GNT_TEXT_FLAG_DIM)
21240
b78eaddaae02 Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19859
diff changeset
650 fl |= (A_DIM | gnt_color_pair(GNT_COLOR_DISABLED));
14014
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
651 else if (flags & GNT_TEXT_FLAG_HIGHLIGHT)
21240
b78eaddaae02 Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 19859
diff changeset
652 fl |= (A_DIM | gnt_color_pair(GNT_COLOR_HIGHLIGHT));
21823
7ffc28701e1c Do not reset the color if there's something already specified. This should
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21473
diff changeset
653 else if ((flags & A_COLOR) == 0)
7ffc28701e1c Do not reset the color if there's something already specified. This should
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21473
diff changeset
654 fl |= gnt_color_pair(GNT_COLOR_NORMAL);
14014
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
655 else
21823
7ffc28701e1c Do not reset the color if there's something already specified. This should
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21473
diff changeset
656 fl |= (flags & A_COLOR);
14014
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
657
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
658 return fl;
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
659 }
223d99ce2f06 [gaim-migrate @ 16500]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14005
diff changeset
660
21473
ecbc011dbe22 Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21240
diff changeset
661 static void reset_text_view(GntTextView *view)
14033
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
662 {
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
663 GntTextLine *line;
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
664
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
665 g_list_foreach(view->list, free_text_line, NULL);
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
666 g_list_free(view->list);
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
667 view->list = NULL;
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
668
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
669 line = g_new0(GntTextLine, 1);
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
670 view->list = g_list_append(view->list, line);
14445
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
671 if (view->string)
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
672 g_string_free(view->string, TRUE);
69f18df58bbf [gaim-migrate @ 17089]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14433
diff changeset
673 view->string = g_string_new(NULL);
21473
ecbc011dbe22 Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21240
diff changeset
674 }
ecbc011dbe22 Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21240
diff changeset
675
ecbc011dbe22 Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21240
diff changeset
676 void gnt_text_view_clear(GntTextView *view)
ecbc011dbe22 Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21240
diff changeset
677 {
ecbc011dbe22 Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21240
diff changeset
678 reset_text_view(view);
ecbc011dbe22 Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21240
diff changeset
679
ecbc011dbe22 Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21240
diff changeset
680 g_list_foreach(view->tags, free_tag, NULL);
ecbc011dbe22 Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21240
diff changeset
681 view->tags = NULL;
14033
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
682
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
683 if (GNT_WIDGET(view)->window)
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
684 gnt_widget_draw(GNT_WIDGET(view));
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
685 }
127990de806d [gaim-migrate @ 16529]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14014
diff changeset
686
14092
191e12cbe464 [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
687 int gnt_text_view_get_lines_below(GntTextView *view)
191e12cbe464 [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
688 {
191e12cbe464 [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
689 int below = 0;
191e12cbe464 [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
690 GList *list = view->list;
191e12cbe464 [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
691 while ((list = list->prev))
191e12cbe464 [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
692 ++below;
191e12cbe464 [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
693 return below;
191e12cbe464 [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
694 }
191e12cbe464 [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
695
191e12cbe464 [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
696 int gnt_text_view_get_lines_above(GntTextView *view)
191e12cbe464 [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
697 {
191e12cbe464 [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
698 int above = 0;
191e12cbe464 [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
699 GList *list = view->list;
191e12cbe464 [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
700 list = g_list_nth(view->list, GNT_WIDGET(view)->priv.height);
191e12cbe464 [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
701 if (!list)
191e12cbe464 [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
702 return 0;
191e12cbe464 [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
703 while ((list = list->next))
191e12cbe464 [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
704 ++above;
191e12cbe464 [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
705 return above;
191e12cbe464 [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
706 }
191e12cbe464 [gaim-migrate @ 16632]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14072
diff changeset
707
15233
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
708 /**
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
709 * XXX: There are quite possibly more than a few bugs here.
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
710 */
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
711 int gnt_text_view_tag_change(GntTextView *view, const char *name, const char *text, gboolean all)
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
712 {
15375
42b08c34496b [gaim-migrate @ 18104]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15372
diff changeset
713 GList *alllines = g_list_first(view->list);
15233
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
714 GList *list, *next, *iter, *inext;
15397
2a5e63b97a2b [gaim-migrate @ 18127]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15396
diff changeset
715 const int text_length = text ? strlen(text) : 0;
15233
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
716 int count = 0;
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
717 for (list = view->tags; list; list = next) {
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
718 GntTextTag *tag = list->data;
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
719 next = list->next;
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
720 if (strcmp(tag->name, name) == 0) {
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
721 int change;
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
722 char *before, *after;
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
723
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
724 count++;
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
725
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
726 before = g_strndup(view->string->str, tag->start);
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
727 after = g_strdup(view->string->str + tag->end);
15396
a5938aa3f6c9 [gaim-migrate @ 18126]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15375
diff changeset
728 change = (tag->end - tag->start) - text_length;
15233
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
729
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
730 g_string_printf(view->string, "%s%s%s", before, text ? text : "", after);
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
731 g_free(before);
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
732 g_free(after);
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
733
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
734 /* Update the offsets of the next tags */
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
735 for (iter = next; iter; iter = iter->next) {
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
736 GntTextTag *t = iter->data;
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
737 t->start -= change;
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
738 t->end -= change;
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
739 }
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
740
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
741 /* Update the offsets of the segments */
15375
42b08c34496b [gaim-migrate @ 18104]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15372
diff changeset
742 for (iter = alllines; iter; iter = inext) {
15233
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
743 GList *segs, *snext;
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
744 GntTextLine *line = iter->data;
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
745 inext = iter->next;
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
746 for (segs = line->segments; segs; segs = snext) {
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
747 GntTextSegment *seg = segs->data;
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
748 snext = segs->next;
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
749 if (seg->start >= tag->end) {
15372
d89caf014964 [gaim-migrate @ 18101]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15233
diff changeset
750 /* The segment is somewhere after the tag */
15233
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
751 seg->start -= change;
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
752 seg->end -= change;
15372
d89caf014964 [gaim-migrate @ 18101]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15233
diff changeset
753 } else if (seg->end <= tag->start) {
d89caf014964 [gaim-migrate @ 18101]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15233
diff changeset
754 /* This segment is somewhere in front of the tag */
d89caf014964 [gaim-migrate @ 18101]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15233
diff changeset
755 } else if (seg->start >= tag->start) {
d89caf014964 [gaim-migrate @ 18101]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15233
diff changeset
756 /* This segment starts in the middle of the tag */
d89caf014964 [gaim-migrate @ 18101]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15233
diff changeset
757 if (text == NULL) {
d89caf014964 [gaim-migrate @ 18101]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15233
diff changeset
758 free_text_segment(seg, NULL);
d89caf014964 [gaim-migrate @ 18101]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15233
diff changeset
759 line->segments = g_list_delete_link(line->segments, segs);
d89caf014964 [gaim-migrate @ 18101]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15233
diff changeset
760 if (line->segments == NULL) {
d89caf014964 [gaim-migrate @ 18101]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15233
diff changeset
761 free_text_line(line, NULL);
15375
42b08c34496b [gaim-migrate @ 18104]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15372
diff changeset
762 if (view->list == iter) {
42b08c34496b [gaim-migrate @ 18104]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15372
diff changeset
763 if (inext)
42b08c34496b [gaim-migrate @ 18104]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15372
diff changeset
764 view->list = inext;
42b08c34496b [gaim-migrate @ 18104]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15372
diff changeset
765 else
42b08c34496b [gaim-migrate @ 18104]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15372
diff changeset
766 view->list = iter->prev;
42b08c34496b [gaim-migrate @ 18104]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15372
diff changeset
767 }
42b08c34496b [gaim-migrate @ 18104]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15372
diff changeset
768 alllines = g_list_delete_link(alllines, iter);
15372
d89caf014964 [gaim-migrate @ 18101]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15233
diff changeset
769 }
d89caf014964 [gaim-migrate @ 18101]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15233
diff changeset
770 } else {
d89caf014964 [gaim-migrate @ 18101]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15233
diff changeset
771 /* XXX: (null) */
d89caf014964 [gaim-migrate @ 18101]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15233
diff changeset
772 seg->start = tag->start;
d89caf014964 [gaim-migrate @ 18101]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15233
diff changeset
773 seg->end = tag->end - change;
d89caf014964 [gaim-migrate @ 18101]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15233
diff changeset
774 }
d89caf014964 [gaim-migrate @ 18101]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15233
diff changeset
775 line->length -= change;
d89caf014964 [gaim-migrate @ 18101]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15233
diff changeset
776 /* XXX: Make things work if the tagged text spans over several lines. */
d89caf014964 [gaim-migrate @ 18101]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15233
diff changeset
777 } else {
d89caf014964 [gaim-migrate @ 18101]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15233
diff changeset
778 /* XXX: handle the rest of the conditions */
d89caf014964 [gaim-migrate @ 18101]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15233
diff changeset
779 g_printerr("WTF! This needs to be handled properly!!\n");
15233
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
780 }
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
781 }
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
782 }
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
783 if (text == NULL) {
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
784 /* Remove the tag */
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
785 view->tags = g_list_delete_link(view->tags, list);
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
786 free_tag(tag, NULL);
15372
d89caf014964 [gaim-migrate @ 18101]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15233
diff changeset
787 } else {
d89caf014964 [gaim-migrate @ 18101]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 15233
diff changeset
788 tag->end -= change;
15233
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
789 }
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
790 if (!all)
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
791 break;
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
792 }
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
793 }
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
794 return count;
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
795 }
fdd9e78534ad [gaim-migrate @ 17957]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 14943
diff changeset
796
16186
73cb5b43aaf9 Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16072
diff changeset
797 static gboolean
73cb5b43aaf9 Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16072
diff changeset
798 scroll_tv(GntWidget *wid, const char *key, GntTextView *tv)
73cb5b43aaf9 Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16072
diff changeset
799 {
73cb5b43aaf9 Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16072
diff changeset
800 if (strcmp(key, GNT_KEY_PGUP) == 0) {
73cb5b43aaf9 Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16072
diff changeset
801 gnt_text_view_scroll(tv, -(GNT_WIDGET(tv)->priv.height - 2));
73cb5b43aaf9 Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16072
diff changeset
802 } else if (strcmp(key, GNT_KEY_PGDOWN) == 0) {
73cb5b43aaf9 Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16072
diff changeset
803 gnt_text_view_scroll(tv, GNT_WIDGET(tv)->priv.height - 2);
73cb5b43aaf9 Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16072
diff changeset
804 } else if (strcmp(key, GNT_KEY_DOWN) == 0) {
73cb5b43aaf9 Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16072
diff changeset
805 gnt_text_view_scroll(tv, 1);
73cb5b43aaf9 Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16072
diff changeset
806 } else if (strcmp(key, GNT_KEY_UP) == 0) {
73cb5b43aaf9 Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16072
diff changeset
807 gnt_text_view_scroll(tv, -1);
73cb5b43aaf9 Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16072
diff changeset
808 } else {
73cb5b43aaf9 Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16072
diff changeset
809 return FALSE;
73cb5b43aaf9 Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16072
diff changeset
810 }
73cb5b43aaf9 Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16072
diff changeset
811 return TRUE;
73cb5b43aaf9 Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16072
diff changeset
812 }
73cb5b43aaf9 Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16072
diff changeset
813
73cb5b43aaf9 Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16072
diff changeset
814 void gnt_text_view_attach_scroll_widget(GntTextView *view, GntWidget *widget)
73cb5b43aaf9 Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16072
diff changeset
815 {
73cb5b43aaf9 Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16072
diff changeset
816 g_signal_connect(G_OBJECT(widget), "key_pressed", G_CALLBACK(scroll_tv), view);
73cb5b43aaf9 Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16072
diff changeset
817 }
73cb5b43aaf9 Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 16072
diff changeset
818
18368
ffeff952aa09 Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17586
diff changeset
819 void gnt_text_view_set_flag(GntTextView *view, GntTextViewFlag flag)
ffeff952aa09 Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17586
diff changeset
820 {
ffeff952aa09 Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17586
diff changeset
821 view->flags |= flag;
ffeff952aa09 Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17586
diff changeset
822 }
ffeff952aa09 Add flags to a textview to decide whether to show scrollbars, and whether
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 17586
diff changeset
823
18791
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
824 /* Pager and editor setups */
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
825 struct
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
826 {
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
827 GntTextView *tv;
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
828 char *file;
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
829 } pageditor;
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
830
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
831
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
832 static void
22104
56970903b8e9 Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@pidgin.im>
parents: 21823
diff changeset
833 cleanup_pageditor(void)
18791
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
834 {
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
835 unlink(pageditor.file);
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
836 g_free(pageditor.file);
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
837
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
838 pageditor.file = NULL;
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
839 pageditor.tv = NULL;
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
840 }
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
841
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
842 static void
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
843 editor_end_cb(int status, gpointer data)
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
844 {
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
845 if (status == 0) {
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
846 char *text = NULL;
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
847 if (g_file_get_contents(pageditor.file, &text, NULL, NULL)) {
21473
ecbc011dbe22 Clear the tags when the textview is cleared.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 21240
diff changeset
848 reset_text_view(pageditor.tv);
18791
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
849 gnt_text_view_append_text_with_flags(pageditor.tv, text, GNT_TEXT_FLAG_NORMAL);
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
850 gnt_text_view_scroll(GNT_TEXT_VIEW(pageditor.tv), 0);
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
851 g_free(text);
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
852 }
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
853 }
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
854 cleanup_pageditor();
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
855 }
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
856
18778
7cf5400593b8 Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18604
diff changeset
857 static void
7cf5400593b8 Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18604
diff changeset
858 pager_end_cb(int status, gpointer data)
7cf5400593b8 Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18604
diff changeset
859 {
18791
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
860 cleanup_pageditor();
18778
7cf5400593b8 Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18604
diff changeset
861 }
7cf5400593b8 Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18604
diff changeset
862
18604
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
863 static gboolean
18791
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
864 check_for_ext_cb(GntWidget *widget, const char *key, GntTextView *view)
18604
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
865 {
18791
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
866 static const char *pager = NULL;
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
867 static const char *editor = NULL;
18604
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
868 char *argv[] = {NULL, NULL, NULL};
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
869 static char path[1024];
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
870 static int len = -1;
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
871 FILE *file;
18778
7cf5400593b8 Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18604
diff changeset
872 gboolean ret;
18791
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
873 gboolean pg;
18604
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
874
18791
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
875 if (pager == NULL) {
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
876 pager = gnt_key_translate(gnt_style_get_from_name("pager", "key"));
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
877 if (pager == NULL)
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
878 pager = "\033" "v";
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
879 editor = gnt_key_translate(gnt_style_get_from_name("editor", "key"));
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
880 if (editor == NULL)
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
881 editor = "\033" "e";
18604
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
882 len = g_snprintf(path, sizeof(path), "%s" G_DIR_SEPARATOR_S "gnt", g_get_tmp_dir());
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
883 } else {
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
884 g_snprintf(path + len, sizeof(path) - len, "XXXXXX");
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
885 }
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
886
18791
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
887 if (strcmp(key, pager) == 0) {
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
888 if (g_object_get_data(G_OBJECT(widget), "pager-for") != view)
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
889 return FALSE;
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
890 pg = TRUE;
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
891 } else if (strcmp(key, editor) == 0) {
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
892 if (g_object_get_data(G_OBJECT(widget), "editor-for") != view)
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
893 return FALSE;
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
894 pg = FALSE;
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
895 } else {
18604
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
896 return FALSE;
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
897 }
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
898
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
899 file = fdopen(g_mkstemp(path), "wb");
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
900 if (!file)
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
901 return FALSE;
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
902 fprintf(file, "%s", view->string->str);
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
903 fclose(file);
18791
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
904
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
905 pageditor.tv = view;
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
906 pageditor.file = g_strdup(path);
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
907
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
908 argv[0] = gnt_style_get_from_name(pg ? "pager" : "editor", "path");
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
909 argv[0] = argv[0] ? argv[0] : getenv(pg ? "PAGER" : "EDITOR");
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
910 argv[0] = argv[0] ? argv[0] : (pg ? "less" : "vim");
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
911 argv[1] = path;
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
912 ret = gnt_giveup_console(NULL, argv, NULL, NULL, NULL, NULL, pg ? pager_end_cb : editor_end_cb, NULL);
18778
7cf5400593b8 Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18604
diff changeset
913 return ret;
18604
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
914 }
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
915
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
916 void gnt_text_view_attach_pager_widget(GntTextView *view, GntWidget *pager)
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
917 {
18791
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
918 g_signal_connect(pager, "key_pressed", G_CALLBACK(check_for_ext_cb), view);
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
919 g_object_set_data(G_OBJECT(pager), "pager-for", view);
18604
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
920 }
2ff126dbae16 Utility function to start the pager with the contents of a textview.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18368
diff changeset
921
18791
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
922 void gnt_text_view_attach_editor_widget(GntTextView *view, GntWidget *wid)
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
923 {
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
924 g_signal_connect(wid, "key_pressed", G_CALLBACK(check_for_ext_cb), view);
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
925 g_object_set_data(G_OBJECT(wid), "editor-for", view);
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
926 }
12003d1b25bf Allow changing the content of a textview using $EDITOR.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18778
diff changeset
927

mercurial