annotate src/gtkspell.c @ 2461:0edec72bc72f

[gaim-migrate @ 2474] be more assertive. this was a bug in gtkspell even before my patch, i think; it's just easier to check with my patch ;) committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Tue, 09 Oct 2001 19:24:16 +0000
parents e6b9246b33fd
children 9cee43e4903d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1 /* gtkspell - a spell-checking addon for GtkText
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2 * Copyright (c) 2000 Evan Martin.
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3 * vim: ts=4 sw=4
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4 * This library is free software; you can redistribute it and/or
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
5 * modify it under the terms of the GNU Lesser General Public
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
6 * License as published by the Free Software Foundation; either
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7 * version 2 of the License, or (at your option) any later version.
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8 *
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9 * This library is distributed in the hope that it will be useful,
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12 * Lesser General Public License for more details.
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
13 *
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
14 * You should have received a copy of the GNU Lesser General Public
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15 * License along with this library; if not, write to the Free Software
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
17 */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
18
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
19 #include <gtk/gtk.h>
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
20
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
21 #include <sys/types.h>
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
22 #include <sys/wait.h>
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
23 #include <sys/time.h>
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
24 #include <unistd.h>
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
25 #include <stdio.h>
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
26 #include <signal.h>
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
27 #include <ctype.h>
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
28 #include <string.h>
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
29 #include <stdlib.h>
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
30 #include <errno.h>
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
31
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
32 /* TODO:
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
33 * handle dictionary changes
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
34 * asynchronous lookups
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35 */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37 /* size of the text buffer used in various word-processing routines. */
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
38 /* #define BUFSIZE 1024 */
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
39 /* number of suggestions to display on each menu. */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
40 #define MENUCOUNT 10
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
41 #define BUGEMAIL "gtkspell-devel@lists.sourceforge.net"
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
42
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
43 /* because we keep only one copy of the spell program running,
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
44 * all ispell-related variables can be static.
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
45 */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
46 static pid_t spell_pid = -1;
1496
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
47 static int fd_write[2] = {0}, fd_read[2] = {0};
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
48 static int signal_set_up = 0;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50 /* FIXME? */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
51 static GdkColor highlight = { 0, 255*256, 0, 0 };
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
53 static void entry_insert_cb(GtkText *gtktext,
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
54 gchar *newtext, guint len, guint *ppos, gpointer d);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
55 static void set_up_signal();
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
56
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
57 int gtkspell_running() {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
58 return (spell_pid > 0);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
59 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
60
1794
60b3fd819cce [gaim-migrate @ 1804]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1496
diff changeset
61 /*
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
62 static void error_print(const char *fmt, ...) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
63 va_list ap;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
64 va_start(ap, fmt);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
65 fprintf(stderr, "gtkspell: ");
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
66 vfprintf(stderr, fmt, ap);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
67 va_end(ap);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
68 }
1794
60b3fd819cce [gaim-migrate @ 1804]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1496
diff changeset
69 */
1815
f15d449b3167 [gaim-migrate @ 1825]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1794
diff changeset
70 extern void debug_printf(char *, ...);
1794
60b3fd819cce [gaim-migrate @ 1804]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1496
diff changeset
71 #define error_print debug_printf
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
72
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
73 /* functions to interface with pipe */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
74 static void writetext(char *text) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
75 write(fd_write[1], text, strlen(text));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
76 }
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
77
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
78 static char *readline() {
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
79 int len = 1024;
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
80 gchar *buf = g_malloc(len);
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
81 int pos = 0;
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
82 do {
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
83 int val = read(fd_read[0], buf + pos, 1);
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
84 if (val <= 0) {
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
85 error_print("read: %s\n", strerror(errno));
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
86 g_free(buf);
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
87 return NULL;
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
88 }
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
89 pos += val;
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
90 if (pos == len) {
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
91 len *= 2;
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
92 buf = g_realloc(buf, len);
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
93 }
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
94 } while (buf[pos - 1] != '\n');
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
95
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
96 buf = g_realloc(buf, pos + 1);
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
97 buf[pos] = 0;
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
98 return buf;
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
99 }
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
100
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
101 static char *readresponse() {
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
102 char *r1, *r2, *result;
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
103
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
104 r1 = readline();
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
105 if (!r1)
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
106 return NULL;
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
107 if (*r1 == '\n') {
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
108 g_strchomp(r1);
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
109 return r1;
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
110 }
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
111 r2 = readline();
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
112 if (!r2) {
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
113 g_free(r1);
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
114 return NULL;
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
115 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
116
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
117 while (r2 && *r2 != '\n') {
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
118 char *tmp = r1;
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
119 r1 = g_strconcat(tmp, r2, NULL);
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
120 g_free(tmp);
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
121 g_free(r2);
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
122 r2 = readline();
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
123 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
124
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
125 if (!r2) {
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
126 g_free(r1);
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
127 return NULL;
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
128 }
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
129
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
130 result = g_strconcat(r1, r2, NULL);
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
131 g_free(r1);
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
132 g_free(r2);
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
133 g_strchomp(result);
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
134 return result;
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
135 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
136
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
137
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
138 void gtkspell_stop() {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
139 if (gtkspell_running()) {
1415
3dfd2a83fb5e [gaim-migrate @ 1425]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1127
diff changeset
140 kill(spell_pid, SIGHUP);
1496
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
141 spell_pid = 0;
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
142 close(fd_read[0]);
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
143 close(fd_write[1]);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
144 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
145 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
146
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
147 int gtkspell_start(char *path, char * args[]) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
148 int fd_error[2];
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
149
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
150 if (gtkspell_running()) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
151 error_print("gtkspell_start called while already running.\n");
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
152 gtkspell_stop();
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
153 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
154
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
155 if (!signal_set_up) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
156 set_up_signal();
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
157 signal_set_up = 1;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
158 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
159
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
160 pipe(fd_write);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
161 pipe(fd_read);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
162 pipe(fd_error);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
163
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
164 spell_pid = fork();
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
165 if (spell_pid < 0) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
166 error_print("fork: %s\n", strerror(errno));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
167 return -1;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
168 } else if (spell_pid == 0) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
169 dup2(fd_write[0], 0);
1496
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
170 close(fd_write[0]);
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
171 close(fd_write[1]);
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
172
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
173 dup2(fd_read[1], 1);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
174 close(fd_read[0]);
1496
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
175 close(fd_read[1]);
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
176
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
177 dup2(fd_error[1], 2);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
178 close(fd_error[0]);
1496
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
179 close(fd_error[1]);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
180
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
181 if (path == NULL) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
182 if (execvp(args[0], args) < 0)
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
183 error_print("execvp('%s'): %s\n", args[0], strerror(errno));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
184 } else {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
185 if (execv(path, args) < 0)
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
186 error_print("execv('%s'): %s\n", path, strerror(errno));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
187 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
188 /* if we get here, we failed.
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
189 * send some text on the pipe to indicate status.
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
190 */
1496
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
191 write(0, "!", 1); /* stdout _is_ the pipe. */
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
192
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
193 _exit(0);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
194 } else {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
195 /* there are at least two ways to fail:
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
196 * - the exec() can fail
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
197 * - the exec() can succeed, but the program can dump the help screen
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
198 * we must check for both.
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
199 */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
200 fd_set rfds;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
201 struct timeval tv;
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
202 char *buf;
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
203
1496
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
204 close(fd_write[0]);
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
205 close(fd_read[1]);
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
206
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
207 FD_ZERO(&rfds);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
208 FD_SET(fd_error[0], &rfds);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
209 FD_SET(fd_read[0], &rfds);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
210 tv.tv_sec = 2;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
211 tv.tv_usec = 0;
1496
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
212
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
213 if (select(MAX(fd_error[0], fd_read[0])+1,
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
214 &rfds, NULL, NULL, &tv) < 0) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
215 /* FIXME: is this needed? */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
216 error_print("Timed out waiting for spell command.\n");
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
217 gtkspell_stop();
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
218 return -1;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
219 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
220
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
221 if (FD_ISSET(fd_error[0], &rfds)) { /* stderr readable? */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
222 error_print("Spell command printed on stderr -- probably failed.\n");
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
223 gtkspell_stop();
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
224 return -1;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
225 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
226
1496
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
227 /* we're done with stderr, now. */
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
228 close(fd_error[0]);
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
229 close(fd_error[1]);
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
230
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
231 /* otherwise, fd_read[0] is set. */
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
232 buf = readline();
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
233
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
234 /* ispell should print something like this:
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
235 * @(#) International Ispell Version 3.1.20 10/10/95
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
236 * if it doesn't, it's an error. */
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
237 if (!buf || buf[0] != '@') {
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
238 if (buf)
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
239 g_free(buf);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
240 gtkspell_stop();
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
241 return -1;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
242 }
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
243 g_free(buf);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
244 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
245
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
246 /* put ispell into terse mode.
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
247 * this makes it not respond on correctly spelled words. */
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
248 writetext("!\n");
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
249 return 0;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
250 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
251
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
252 static GList* misspelled_suggest(char *word) {
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
253 char *buf;
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
254 char *newword;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
255 GList *l = NULL;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
256 int count;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
257
2461
0edec72bc72f [gaim-migrate @ 2474]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2457
diff changeset
258 if (!word)
0edec72bc72f [gaim-migrate @ 2474]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2457
diff changeset
259 return NULL;
0edec72bc72f [gaim-migrate @ 2474]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2457
diff changeset
260
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
261 buf = g_strdup_printf("^%s\n", word); /* guard against ispell control chars */
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
262 writetext(buf);
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
263 g_free(buf);
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
264 buf = readresponse();
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
265
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
266 if (!buf)
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
267 return NULL;
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
268
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
269 switch (buf[0]) { /* first char is ispell command. */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
270 case 0: /* no response: word is ok. */
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
271 g_free(buf);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
272 return NULL;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
273 case '&': /* misspelled, with suggestions */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
274 /* & <orig> <count> <ofs>: <miss>, <miss>, <guess>, ... */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
275 strtok(buf, " "); /* & */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
276 newword = strtok(NULL, " "); /* orig */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
277 l = g_list_append(l, g_strdup(newword));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
278 newword = strtok(NULL, " "); /* count */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
279 count = atoi(newword);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
280 strtok(NULL, " "); /* ofs: */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
281
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
282 while ((newword = strtok(NULL, ",")) != NULL) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
283 int len = strlen(newword);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
284 if (newword[len-1] == ' ' || newword[len-1] == '\n')
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
285 newword[len-1] = 0;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
286 if (count == 0) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
287 g_list_append(l, NULL); /* signal the "suggestions" */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
288 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
289 /* add it to the list, skipping the initial space. */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
290 l = g_list_append(l,
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
291 g_strdup(newword[0] == ' ' ? newword+1 : newword));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
292
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
293 count--;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
294 }
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
295 g_free(buf);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
296 return l;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
297
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
298 case '#': /* misspelled, no suggestions */
1467
7f7857c5036e [gaim-migrate @ 1477]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1415
diff changeset
299 case '?': /* ispell is guessing. */
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
300 /* # <orig> <ofs> */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
301 strtok(buf, " "); /* & */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
302 newword = strtok(NULL, " "); /* orig */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
303 l = g_list_append(l, g_strdup(newword));
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
304 g_free(buf);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
305 return l;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
306 default:
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
307 error_print("Unsupported spell command '%c'.\n"
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
308 "This is a bug; mail " BUGEMAIL " about it.\n", buf[0]);
1467
7f7857c5036e [gaim-migrate @ 1477]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1415
diff changeset
309 error_print("Input [%s]\nOutput [%s]\n", word, buf);
7f7857c5036e [gaim-migrate @ 1477]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1415
diff changeset
310
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
311 }
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
312 g_free(buf);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
313 return NULL;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
314 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
315
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
316 static int misspelled_test(char *word) {
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
317 char *buf;
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
318 buf = g_strdup_printf("^%s\n", word); /* guard against ispell control chars */
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
319 writetext(buf);
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
320 g_free(buf);
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
321 buf = readresponse();
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
322
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
323 if (!buf)
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
324 return 0;
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
325
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
326 if (buf[0] == 0) {
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
327 g_free(buf);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
328 return 0;
1467
7f7857c5036e [gaim-migrate @ 1477]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1415
diff changeset
329 } else if (buf[0] == '&' || buf[0] == '#' || buf[0] == '?') {
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
330 g_free(buf);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
331 return 1;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
332 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
333
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
334 error_print("Unsupported spell command '%c'.\n"
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
335 "This is a bug; mail " BUGEMAIL " about it.\n", buf[0]);
1467
7f7857c5036e [gaim-migrate @ 1477]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1415
diff changeset
336 error_print("Input [%s]\nOutput [%s]\n", word, buf);
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
337 g_free(buf);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
338 return -1;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
339 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
340
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
341 static gboolean iswordsep(char c) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
342 return !isalpha(c) && c != '\'';
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
343 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
344
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
345 static gboolean get_word_from_pos(GtkText* gtktext, int pos, char** buf,
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
346 int *pstart, int *pend) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
347 gint start, end;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
348
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
349 if (iswordsep(GTK_TEXT_INDEX(gtktext, pos))) return FALSE;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
350
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
351 for (start = pos; start >= 0; --start) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
352 if (iswordsep(GTK_TEXT_INDEX(gtktext, start))) break;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
353 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
354 start++;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
355
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
356 for (end = pos; end <= gtk_text_get_length(gtktext); end++) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
357 if (iswordsep(GTK_TEXT_INDEX(gtktext, end))) break;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
358 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
359
2457
e6b9246b33fd [gaim-migrate @ 2470]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2456
diff changeset
360 if (buf && (end - start + 1 > 0)) {
e6b9246b33fd [gaim-migrate @ 2470]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2456
diff changeset
361 *buf = g_malloc(end - start + 1);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
362 for (pos = start; pos < end; pos++)
2457
e6b9246b33fd [gaim-migrate @ 2470]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2456
diff changeset
363 (*buf)[pos-start] = GTK_TEXT_INDEX(gtktext, pos);
e6b9246b33fd [gaim-migrate @ 2470]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2456
diff changeset
364 (*buf)[pos-start] = 0;
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
365 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
366
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
367 if (pstart) *pstart = start;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
368 if (pend) *pend = end;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
369
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
370 return TRUE;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
371 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
372
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
373 static gboolean get_curword(GtkText* gtktext, char** buf,
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
374 int *pstart, int *pend) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
375 int pos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
376 return get_word_from_pos(gtktext, pos, buf, pstart, pend);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
377 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
378
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
379 static void change_color(GtkText *gtktext,
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
380 int start, int end, GdkColor *color) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
381 char *newtext = gtk_editable_get_chars(GTK_EDITABLE(gtktext), start, end);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
382 gtk_text_freeze(gtktext);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
383 gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext),
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
384 GTK_SIGNAL_FUNC(entry_insert_cb), NULL);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
385
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
386 gtk_text_set_point(gtktext, start);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
387 gtk_text_forward_delete(gtktext, end-start);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
388
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
389 if (newtext && end-start > 0)
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
390 gtk_text_insert(gtktext, NULL, color, NULL, newtext, end-start);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
391
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
392 gtk_signal_handler_unblock_by_func(GTK_OBJECT(gtktext),
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
393 GTK_SIGNAL_FUNC(entry_insert_cb), NULL);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
394 gtk_text_thaw(gtktext);
1415
3dfd2a83fb5e [gaim-migrate @ 1425]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1127
diff changeset
395 g_free(newtext);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
396 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
397
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
398 static gboolean check_at(GtkText *gtktext, int from_pos) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
399 int start, end;
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
400 char *buf = NULL;
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
401
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
402 if (!get_word_from_pos(gtktext, from_pos, &buf, &start, &end)) {
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
403 if (buf)
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
404 g_free(buf);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
405 return FALSE;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
406 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
407
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
408 if (misspelled_test(buf)) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
409 if (highlight.pixel == 0) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
410 /* add an entry for the highlight in the color map. */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
411 GdkColormap *gc = gtk_widget_get_colormap(GTK_WIDGET(gtktext));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
412 gdk_colormap_alloc_color(gc, &highlight, FALSE, TRUE);;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
413 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
414 change_color(gtktext, start, end, &highlight);
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
415 if (buf)
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
416 g_free(buf);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
417 return TRUE;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
418 } else {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
419 change_color(gtktext, start, end,
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
420 &(GTK_WIDGET(gtktext)->style->fg[0]));
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
421 if (buf)
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
422 g_free(buf);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
423 return FALSE;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
424 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
425 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
426
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
427 void gtkspell_check_all(GtkText *gtktext) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
428 guint origpos;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
429 guint pos = 0;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
430 guint len;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
431 float adj_value;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
432
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
433 if (!gtkspell_running()) return;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
434
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
435 len = gtk_text_get_length(gtktext);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
436
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
437 adj_value = gtktext->vadj->value;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
438 gtk_text_freeze(gtktext);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
439 origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
440 while (pos < len) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
441 while (pos < len && iswordsep(GTK_TEXT_INDEX(gtktext, pos)))
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
442 pos++;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
443 while (pos < len && !iswordsep(GTK_TEXT_INDEX(gtktext, pos)))
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
444 pos++;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
445 if (pos > 0)
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
446 check_at(gtktext, pos-1);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
447 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
448 gtk_text_thaw(gtktext);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
449 gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
450 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
451
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
452 static void entry_insert_cb(GtkText *gtktext,
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
453 gchar *newtext, guint len, guint *ppos, gpointer d) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
454 int origpos;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
455
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
456 if (!gtkspell_running()) return;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
457
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
458 gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext),
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
459 GTK_SIGNAL_FUNC(entry_insert_cb),
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
460 NULL);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
461 gtk_text_insert(GTK_TEXT(gtktext), NULL,
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
462 &(GTK_WIDGET(gtktext)->style->fg[0]), NULL, newtext, len);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
463 gtk_signal_handler_unblock_by_func(GTK_OBJECT(gtktext),
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
464 GTK_SIGNAL_FUNC(entry_insert_cb),
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
465 NULL);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
466 gtk_signal_emit_stop_by_name(GTK_OBJECT(gtktext), "insert-text");
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
467 *ppos += len;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
468
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
469 origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
470
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
471 if (iswordsep(newtext[0])) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
472 /* did we just end a word? */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
473 if (*ppos >= 2) check_at(gtktext, *ppos-2);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
474
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
475 /* did we just split a word? */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
476 if (*ppos < gtk_text_get_length(gtktext))
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
477 check_at(gtktext, *ppos+1);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
478 } else {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
479 /* check as they type, *except* if they're typing at the end (the most
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
480 * common case.
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
481 */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
482 if (*ppos < gtk_text_get_length(gtktext) &&
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
483 !iswordsep(GTK_TEXT_INDEX(gtktext, *ppos)))
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
484 check_at(gtktext, *ppos-1);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
485 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
486
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
487 gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos);
1496
d33bf6548543 [gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1467
diff changeset
488 gtk_editable_select_region(GTK_EDITABLE(gtktext), origpos, origpos);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
489 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
490
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
491 static void entry_delete_cb(GtkText *gtktext,
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
492 gint start, gint end, gpointer d) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
493 int origpos;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
494
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
495 if (!gtkspell_running()) return;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
496
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
497 origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
498 check_at(gtktext, start-1);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
499 gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
500 gtk_editable_select_region(GTK_EDITABLE(gtktext), origpos, origpos);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
501 /* this is to *UNDO* the selection, in case they were holding shift
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
502 * while hitting backspace. */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
503 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
504
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
505 static void replace_word(GtkWidget *w, gpointer d) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
506 int start, end;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
507 char *newword;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
508
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
509 /* we don't save their position,
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
510 * because the cursor is moved by the click. */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
511
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
512 gtk_text_freeze(GTK_TEXT(d));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
513
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
514 gtk_label_get(GTK_LABEL(GTK_BIN(w)->child), &newword);
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
515 get_curword(GTK_TEXT(d), NULL, &start, &end);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
516
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
517 gtk_text_set_point(GTK_TEXT(d), end);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
518 gtk_text_backward_delete(GTK_TEXT(d), end-start);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
519 gtk_text_insert(GTK_TEXT(d), NULL, NULL, NULL, newword, strlen(newword));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
520
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
521 gtk_text_thaw(GTK_TEXT(d));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
522 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
523
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
524 static GtkMenu *make_menu(GList *l, GtkText *gtktext) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
525 GtkWidget *menu, *item;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
526 char *caption;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
527 menu = gtk_menu_new(); {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
528 caption = g_strdup_printf("Not in dictionary: %s", (char*)l->data);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
529 item = gtk_menu_item_new_with_label(caption);
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
530 g_free(caption);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
531 /* I'd like to make it so this item is never selectable, like
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
532 * the menu titles in the GNOME panel... unfortunately, the GNOME
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
533 * panel creates their own custom widget to do this! */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
534 gtk_widget_show(item);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
535 gtk_menu_append(GTK_MENU(menu), item);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
536
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
537 item = gtk_menu_item_new();
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
538 gtk_widget_show(item);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
539 gtk_menu_append(GTK_MENU(menu), item);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
540
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
541 l = l->next;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
542 if (l == NULL) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
543 item = gtk_menu_item_new_with_label("(no suggestions)");
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
544 gtk_widget_show(item);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
545 gtk_menu_append(GTK_MENU(menu), item);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
546 } else {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
547 GtkWidget *curmenu = menu;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
548 int count = 0;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
549 do {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
550 if (l->data == NULL && l->next != NULL) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
551 count = 0;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
552 curmenu = gtk_menu_new();
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
553 item = gtk_menu_item_new_with_label("Other Possibilities...");
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
554 gtk_widget_show(item);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
555 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), curmenu);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
556 gtk_menu_append(GTK_MENU(curmenu), item);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
557 l = l->next;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
558 } else if (count > MENUCOUNT) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
559 count -= MENUCOUNT;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
560 item = gtk_menu_item_new_with_label("More...");
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
561 gtk_widget_show(item);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
562 gtk_menu_append(GTK_MENU(curmenu), item);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
563 curmenu = gtk_menu_new();
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
564 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), curmenu);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
565 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
566 item = gtk_menu_item_new_with_label((char*)l->data);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
567 gtk_signal_connect(GTK_OBJECT(item), "activate",
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
568 GTK_SIGNAL_FUNC(replace_word), gtktext);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
569 gtk_widget_show(item);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
570 gtk_menu_append(GTK_MENU(curmenu), item);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
571 count++;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
572 } while ((l = l->next) != NULL);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
573 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
574 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
575 return GTK_MENU(menu);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
576 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
577
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
578 static void popup_menu(GtkText *gtktext, GdkEventButton *eb) {
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
579 char *buf = NULL;
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
580 GList *list, *l;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
581
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
582 get_curword(gtktext, &buf, NULL, NULL);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
583
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
584 list = misspelled_suggest(buf);
2454
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
585 if (buf)
64e20158271e [gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
586 g_free(buf);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
587 if (list != NULL) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
588 gtk_menu_popup(make_menu(list, gtktext), NULL, NULL, NULL, NULL,
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
589 eb->button, eb->time);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
590 for (l = list; l != NULL; l = l->next)
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
591 g_free(l->data);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
592 g_list_free(list);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
593 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
594 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
595
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
596 /* ok, this is pretty wacky:
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
597 * we need to let the right-mouse-click go through, so it moves the cursor,
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
598 * but we *can't* let it go through, because GtkText interprets rightclicks as
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
599 * weird selection modifiers.
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
600 *
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
601 * so what do we do? forge rightclicks as leftclicks, then popup the menu.
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
602 * HACK HACK HACK.
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
603 */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
604 static gint button_press_intercept_cb(GtkText *gtktext, GdkEvent *e, gpointer d) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
605 GdkEventButton *eb;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
606 gboolean retval;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
607
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
608 if (!gtkspell_running()) return FALSE;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
609
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
610 if (e->type != GDK_BUTTON_PRESS) return FALSE;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
611 eb = (GdkEventButton*) e;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
612
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
613 if (eb->button != 3) return FALSE;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
614
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
615 /* forge the leftclick */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
616 eb->button = 1;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
617
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
618 gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext),
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
619 GTK_SIGNAL_FUNC(button_press_intercept_cb), d);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
620 gtk_signal_emit_by_name(GTK_OBJECT(gtktext), "button-press-event",
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
621 e, &retval);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
622 gtk_signal_handler_unblock_by_func(GTK_OBJECT(gtktext),
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
623 GTK_SIGNAL_FUNC(button_press_intercept_cb), d);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
624 gtk_signal_emit_stop_by_name(GTK_OBJECT(gtktext), "button-press-event");
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
625
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
626 /* now do the menu wackiness */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
627 popup_menu(gtktext, eb);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
628 return TRUE;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
629 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
630
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
631 void gtkspell_uncheck_all(GtkText *gtktext) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
632 int origpos;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
633 char *text;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
634 float adj_value;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
635
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
636 adj_value = gtktext->vadj->value;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
637 gtk_text_freeze(gtktext);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
638 origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
639 text = gtk_editable_get_chars(GTK_EDITABLE(gtktext), 0, -1);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
640 gtk_text_set_point(gtktext, 0);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
641 gtk_text_forward_delete(gtktext, gtk_text_get_length(gtktext));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
642 gtk_text_insert(gtktext, NULL, NULL, NULL, text, strlen(text));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
643 gtk_text_thaw(gtktext);
1794
60b3fd819cce [gaim-migrate @ 1804]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1496
diff changeset
644 g_free(text);
1117
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
645
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
646 gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
647 gtk_adjustment_set_value(gtktext->vadj, adj_value);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
648 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
649
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
650 void gtkspell_attach(GtkText *gtktext) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
651 gtk_signal_connect(GTK_OBJECT(gtktext), "insert-text",
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
652 GTK_SIGNAL_FUNC(entry_insert_cb), NULL);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
653 gtk_signal_connect_after(GTK_OBJECT(gtktext), "delete-text",
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
654 GTK_SIGNAL_FUNC(entry_delete_cb), NULL);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
655 gtk_signal_connect(GTK_OBJECT(gtktext), "button-press-event",
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
656 GTK_SIGNAL_FUNC(button_press_intercept_cb), NULL);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
657 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
658
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
659 void gtkspell_detach(GtkText *gtktext) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
660 gtk_signal_disconnect_by_func(GTK_OBJECT(gtktext),
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
661 GTK_SIGNAL_FUNC(entry_insert_cb), NULL);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
662 gtk_signal_disconnect_by_func(GTK_OBJECT(gtktext),
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
663 GTK_SIGNAL_FUNC(entry_delete_cb), NULL);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
664 gtk_signal_disconnect_by_func(GTK_OBJECT(gtktext),
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
665 GTK_SIGNAL_FUNC(button_press_intercept_cb), NULL);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
666
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
667 gtkspell_uncheck_all(gtktext);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
668 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
669
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
670 static void sigchld(int param) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
671 if (gtkspell_running() &&
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
672 (waitpid(spell_pid, NULL, WNOHANG) == spell_pid)) {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
673 spell_pid = 0;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
674 } else {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
675 /* a default SIGCHLD handler.
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
676 * what else to do here? */
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
677 waitpid(-1, NULL, WNOHANG);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
678 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
679 }
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
680
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
681 static void set_up_signal() {
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
682 struct sigaction sigact;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
683 memset(&sigact, 0, sizeof(struct sigaction));
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
684
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
685 sigact.sa_handler = sigchld;
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
686 sigaction(SIGCHLD, &sigact, NULL);
f3e0f41beddb [gaim-migrate @ 1127]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
687 }